Skip to main content
2 of 3
added 510 characters in body
Tyler
  • 22.8k
  • 1
  • 56
  • 95

Emacs uses syntax tables to decide what is and is not a word. Each major mode will have its own syntax table. Commands that move over or delete words will use the values in this table to determine how far to go.

The key syntax class in this case is the 'word constituent'. Deleting a word in Emacs works by deleting whole groups of adjacent word constituents.

To add characters to the 'word constituent' class you can use modify-syntax-entry. For example, to add the character ), you'd use the following:

(modify-syntax-entry ?) "w") 

By default, this will modify the current syntax table. You'll need to do a bit more to target the syntax table for a particular mode. For example, I have the following in my .init.el:

(eval-after-load "bibtex"
     (modify-syntax-entry ?% "_" bibtex-mode-syntax-table))

This will modify the syntax table for bibtex-mode after it's loaded, changing the % character to a 'symbol constituent'. See the linked manual page for more details on the different syntax classes and how to set them.

Tyler
  • 22.8k
  • 1
  • 56
  • 95