Elisp: Syntax Table
What is Syntax Table
Syntax table is a lookup table. It store info about character's class, such as whitespace, word, symbol (programing language identifier), punctuations, bracket, etc.
Where is Syntax Table Used
Syntax table is heavily used in emacs. For example,
- Most cursor movement commands rely on syntax table. For example, when you
forward-word【Alt+f】, emacs moves cursor until it reaches a character that's not in the “word” class. - Syntax coloring of strings and comments rely on syntax table. 〔see Elisp: Syntax Color Comments〕
- Lisp mode's parenthesis navigation depends on syntax table. 〔see Emacs: Navigate Lisp Code as Tree〕
Syntax Table is Local to Buffer
Each buffer has its own syntax table.
Typically, when a Major Mode is activated, it changes the current buffer's syntax table.
Standard Syntax Table
- Standard syntax table is the syntax table used by Fundamental Mode.
- Every syntax table is derived from standard syntax table.
The function standard-syntax-table returns the standard syntax table.
Syntax Table Inheritance
Emacs syntax table has inheritance. That is, each syntax table you create inherits a parent syntax table. You do not need to set every character's syntax class. When a syntax table does not have entry for a character, it uses the parent table.
Syntax table commands have optional parameter for a table name of a parent table. When not specified, the parent syntax table is the standard syntax table.
Create a Syntax Table
Reference
Elisp, character and syntax table
Elisp, font lock, syntax coloring
Elisp, writing a major mode. Essentials
- Elisp: Write a Major Mode for Syntax Coloring
- Elisp: Font Lock Mode
- Elisp: Syntax Color Comments
- Elisp: Write Comment/Uncomment Command
- Elisp: Keyword Completion
- Elisp: Create Keymap (keybinding)
- Elisp: Create Function Templates
- Emacs: Command to Lookup Doc on Web 📜
- Elisp: Create a Hook
- Elisp: Major Mode Names
- Elisp: provide, require, features
- Elisp: load, load-file, autoload
- Elisp: Syntax Table