i've came on emacs from Sublime Text, and there ;[]{}()., etc are counts as word, and when you move in your document with Ctrl+Arrow you never skip these characters. I want make emacs recognize all these characters as separate word. How do i? Is there easy way to do this?

  • You may wish to try (forward-symbol 1) instead of forward-word; and, (forward-symbol -1) instead of backward-word. Doc-string of forward-symbol: "Move point to the next position that is the end of a symbol. A symbol is any sequence of characters that are in either the word constituent or symbol constituent syntax class. With prefix argument ARG, do it ARG times if positive, or move backwards ARG times if negative." Alternatively, you may wish to consider writing up your own custom movement function that mimics other popular text editors and/or word processors. – lawlist Mar 10 '18 at 17:24
  • forward-symbol works even worse – justicecurcian Mar 10 '18 at 18:31

If every character mentioned should compose a single word, try something like this:

(defvar pseudowords (list ?\; ?\[ ?\] ?{ ?} ?\( ?\) ?. ?,))

(defun ar-forward-extended-words ()
  (or (when (member (char-after) pseudowords)
    (progn (forward-char 1)
      ;; regexp below might require some edits
      (< 0 (skip-chars-forward "^[a-z];[]{}\\().,"))
      (forward-char 1)
      (forward-word 1)))

If it's just to extend which character belongs to a specific syntax, this controlled by syntax-tables. There is a function to change the contents of this table. For example if in python-mode the underscore should get word-syntax, write

(modify-syntax-entry ?_ "w" python-mode-syntax-table)

The char behind the question mark will get the syntax according to symbol in next slot, word-syntax here represented by string "w".

  • 1
    If I understand the question correctly, they don't exactly want these punctuation characters to be word-constituent, because they want them to be separate words which would mean that foo() was three words. – phils Mar 10 '18 at 23:05
  • phils is right. – justicecurcian Mar 11 '18 at 8:45

The only way is to create own function. Here you can have implementation that works.

  • So it's about navigating paired delimiteds? – Andreas Röhler Mar 12 '18 at 7: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.