Defining the following function

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

and running it while standing at | in the below text


moves it to


Redefining the function as

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

and repeating the same procedure moves the pointer from




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.

1 Answer 1


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 ()
  (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.

  • 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, 2020 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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