2

Defining the following function

(defun windows-path-backwards ()
  (interactive)
  (skip-chars-backward "a-zA-Z0-9\\\\_-:"))

and running it while standing at | in the below text

C:\this\path|

moves it to

C:|\this\path

Redefining the function as

(defun windows-path-backwards ()
  (interactive)
  (skip-chars-backward "a-zA-Z0-9\\\\_:-"))

and repeating the same procedure moves the pointer from

C:\this\path|

to

|C:\this\path

Why is there difference between these two functions when the only change is the order of the : and - characters in the character class skip-chars-backward takes as an argument.

3

It is because - is used to denote ranges of characters. One will have to escape - for it to not have that meaning when placed between two other characters. See the function definition below:

(defun windows-path-backwards ()
  (interactive)
  (skip-chars-backward "a-zA-Z0-9\\\\_\\-:")) 

In other words, : is not important in itself, it just happened to be one of two characters surrounding a - in the nonfunctioning example given in the question.

| improve this answer | |
  • Although that's valid for skip-chars-*, because you can't escape - like that in a character alternative I'd be more inclined to use the techniques which are consistent between the two scenarios, so that it's less likely to seem like a mistake (as the two are documented as being mostly equivalent). "To include a ‘-’, write ‘-’ as the first or last character of the character alternative, or as the upper bound of a range." Edge cases aside, I think backslash is the only character which always needs to be written differently for skip-chars-*. – phils May 7 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.