Elisp: Syntax Table
What is Syntax Table
Syntax Table is a lookup table. It classify each character into a class, for all unicode characters.
Classes are: letters, punctuations, brackets, programing language identifiers, comment character, string delimiters, etc.
Each Buffer Has Its Own Value of Syntax Table
Typically, when a Major Mode is activated, it changes the current buffer's syntax table.
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〕
Summary of Syntax Table
- Syntax table is a lookup table. It group characters into classes, such as whitespace, word, symbol (programing language identifier), punctuations, bracket, etc. 〔see Elisp: Syntax Class〕
- To create a syntax table, use
make-syntax-table
and others. 〔see Elisp: Create Syntax Table〕 - Each buffer has its own syntax table. (it's like Buffer Local Variable, but there is no variable.)
- Use
set-syntax-table
to set a syntax table for current buffer.
Elisp, character and syntax table
Elisp, font lock, syntax coloring
Emacs lisp, 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
- Elisp: Command to Lookup Doc
- Elisp: Create a Hook
- Elisp: Major Mode Names
- Elisp: provide, require, features
- Elisp: load, load-file, autoload
- Elisp: Syntax Table