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?
Asked
Active
Viewed 215 times
1

Drew
- 75,699
- 9
- 109
- 225

justicecurcian
- 21
- 1
-
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
2 Answers
1
If every character mentioned should compose a single word, try something like this:
(defvar pseudowords (list ?\; ?\[ ?\] ?{ ?} ?\( ?\) ?. ?,))
(defun ar-forward-extended-words ()
(interactive)
(or (when (member (char-after) pseudowords)
(progn (forward-char 1)
t))
(when
;; regexp below might require some edits
(< 0 (skip-chars-forward "^[a-z];[]{}\\().,"))
(progn
(forward-char 1)
t))
(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".

Andreas Röhler
- 1,894
- 10
- 10
-
1If 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
-
0
The only way is to create own function. Here you can have implementation that works.

justicecurcian
- 21
- 1