9

In emacs there are the functions forward-word and backward-word. Are there also functions which move the point to the next/last whitespace?

  • Isn't this for a lot of cases equivalent? What is the use case there a different functionality is needed? – H.-Dirk Schmitt Oct 31 '12 at 15:57
  • 1
    For example if a have a generalized word like \a_command_with_special-characters – Julia Oct 31 '12 at 16:21
7

You can modify the syntactical properties of characters using the modify-syntax-entry function (C-h f modify-syntax-entry in emacs for more info):

For instance, if you are writing .tex documents, you might add the following to your .emacs:

(add-hook
 'TeX-mode-hook
 '(lambda ()
    (modify-syntax-entry ?_ "w")
    (modify-syntax-entry ?- "w")
))

This tells emacs to treat _ and - as "word" characters when you are in TeX mode, thus forward-word and backward-word will do what you want.

9

Use forward-whitespace to advance by spaces, tabs or newlines. Multiple spaces are treated as one delimiter. With a negative argument, go backwards by that number of whitespaces.

  • 1
    Any idea how to advance to the first whitespace after a block of text, without skipping any? forward-whitespace seems to skip to the end of the line when I have trailing spaces on a line. I really just want to find the first trailing space. Thanks for any help. – Dave Nov 13 '15 at 8:03
  • @Dave : (lambda () (forward-whitespace) (forward-whitespace -1)) – Dean Serenevy May 19 '17 at 10:27

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.