Elisp: Syntax Descriptor
What is Syntax Descriptor
A syntax descriptor is a lisp string, typically of 1 to 4 chars. e.g."."
.
it specifies:
- First character means the char's Syntax Class (the 1-char code)
- Second character means the char's matching character, or space for none. (used for bracket chars)
- 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.
- A character. 〔see Elisp: Character Type〕
- 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 first character in syntax descriptor is period. It means the slash / character is punctuation class.
- The second character in syntax descriptor is space. Since it's not in bracket class, so there is no matching character, space character is used to mean none.
- The rest characters in syntax descriptor are flags. They are used for comment syntax. Because the comment delimiter characters in programing languages is complex. The char usually have multiple purposes, and also depends on whether the character is repeated, or if it can be nested.
The flags in syntax descriptor is very complex. See elisp manual.
For practical examples of using the syntax flags for comments, see