Elisp: Syntax Descriptor

By Xah Lee. Date: . Last updated: .

What is Syntax Descriptor

A syntax descriptor is a lisp string, typically of 1 to 4 chars. e.g. ".".

it specifies:

  1. First character means the char's Syntax Class (the 1-char code)
  2. Second character means the char's matching character, or space for none. (used for bracket chars)
  3. Rest characters are flags, used to specify comment delimiter syntax of computer languages.

You'll use Syntax Descriptor with the function modify-syntax-entry, when you Create Syntax Table .

Example of Syntax Descriptor

;; make period to have syntax class of symbol
(modify-syntax-entry ?. "_")

Now let's look at the line

(modify-syntax-entry ?. "_")

modify-syntax-entry take 2 required args.

  1. A character. 〔see Elisp: Character Type
  2. A syntax descriptor string.

?. is the character period . (U+2E: FULL STOP).

"_" is the syntax descriptor string. It means the period character is in symbol class.

Example 2

;; make the «French double quote» to be brackets
(modify-syntax-entry"(»")
(modify-syntax-entry")«")

Now let's look at this line:

(modify-syntax-entry ?« "(»")

It means, the character « is in the class of opening bracket, and its matching character is ».

Example 3

;; make char's syntax for C++ style comment “// …”
(modify-syntax-entry ?/ ". 12b")
(modify-syntax-entry ?\n "> b")

Now let's look at this line:

(modify-syntax-entry ?/ ". 12b")

Let's look at the syntax descriptor string ". 12b". It means:

The flags in syntax descriptor is very complex. See elisp manual.

For practical examples of using the syntax flags for comments, see

Emacs Lisp, character and syntax table