5

What is the easiest way to skip forward to the first whitespace character after the current cursor? I used to do it just by searching for a space (when I knew there was one there), but now that seems to behave like forward-whitespace (not sure when this behavior switched, maybe when I transitioned to emacs 24. This is a function I need all the time when defining macros interactively.

Fwiw, forward-whitespace doesn't work for me because it skips to the last whitespace character in the first block of whitespace after the current cursor.

1 Answer 1

6

You can use skip-syntax-forward to skip non-whitespace. Docstring:

(skip-syntax-forward SYNTAX &optional LIM)

Move point forward across chars in specified syntax classes. SYNTAX is a string of syntax code characters. Stop before a char whose syntax is not in SYNTAX, or at position LIM. If SYNTAX starts with ^, skip characters whose syntax is NOT in SYNTAX. This function returns the distance traveled, either zero or positive.

If you want to use it interactively, you can wrap it in an interactive command:

(defun skip-to-next-whitespace ()
  "Move point forward to next whitespace character."
  (interactive)
  (skip-syntax-forward "^\s"))

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.