Elisp: Syntax Table

By Xah Lee. Date: . Last updated: .

What is Syntax Table

Syntax table is a lookup table. It store info about character's purpose, such as whitespace, word, symbol (programing language identifier), punctuations, bracket, etc. 〔see Elisp: Syntax Class

Where is Syntax Table Used

Syntax table is heavily used in emacs. For example,

Syntax Table is Local to Buffer

Each buffer has its own syntax table. (it's like Buffer Local Variable, but there is no variable.)

Typically, when a Major Mode is activated, it changes the current buffer's syntax table.

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

Emacs Lisp, character and syntax table

Emacs Lisp, font lock, syntax coloring

Emacs Lisp, writing a major mode. Essentials