Skip to main content
added caution
Source Link
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 groupswhole 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.

Caution

As @politza points out, changing the syntax table may have unintended consequences. Syntax classes are a pretty fundamental structure in Emacs, and many different functions depend on them, not just movement and deletion commands. So you might find surprising bugs arise as a consequence of such changes.

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.

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.

Caution

As @politza points out, changing the syntax table may have unintended consequences. Syntax classes are a pretty fundamental structure in Emacs, and many different functions depend on them, not just movement and deletion commands. So you might find surprising bugs arise as a consequence of such changes.

added 510 characters in body
Source Link
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.

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") 

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.

Source Link
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")