In this section we describe functions for creating, accessing and altering syntax tables.
This function creates a new syntax table. Character codes 0 through 31 and 128 through 255 are set up to inherit from the standard syntax table. The other character codes are set up by copying what the standard syntax table says about them.
Most major mode syntax tables are created in this way.
This function constructs a copy of syntax-table and returns it.
If syntax-table is not supplied (or is
nil), it returns a
copy of the current syntax table. Otherwise, an error is signaled if
syntax-table is not a syntax table.
This function sets the syntax entry for char-range according to
syntax-descriptor. char-range is either a single character
or a range of characters, as used with
put-char-table. The syntax
is changed only for syntax-table, which defaults to the current
buffer’s syntax table, and not in any other syntax table. The argument
syntax-descriptor specifies the desired syntax; this is a string
beginning with a class designator character, and optionally containing a
matching character and flags as well. See Syntax Descriptors.
This function always returns
nil. The old syntax information in
the table for char-range is discarded.
An error is signaled if the first character of the syntax descriptor is not one of the twelve syntax class designator characters.
;; Put the space character in class whitespace. (modify-syntax-entry ?\ " ") ⇒ nil
;; Make ‘$’ an open parenthesis character, ;; with ‘^’ as its matching close. (modify-syntax-entry ?$ "(^") ⇒ nil
;; Make ‘^’ a close parenthesis character, ;; with ‘$’ as its matching open. (modify-syntax-entry ?^ ")$") ⇒ nil
;; Make ‘/’ a punctuation character, ;; the first character of a start-comment sequence, ;; and the second character of an end-comment sequence. ;; This is used in C mode. (modify-syntax-entry ?/ ". 14") ⇒ nil
This function returns the syntax class of character, represented by its mnemonic designator character. This only returns the class, not any matching parenthesis or flags.
An error is signaled if character is not a character.
The characters that correspond to various syntax codes
are listed in the documentation of
Optional second argument syntax-table is the syntax table to be used, and defaults to the current buffer’s syntax table.
The following examples apply to C mode. The first example shows that the syntax class of space is whitespace (represented by a space). The second example shows that the syntax of ‘/’ is punctuation. This does not show the fact that it is also part of comment-start and -end sequences. The third example shows that open parenthesis is in the class of open parentheses. This does not show the fact that it has a matching character, ‘)’.
(char-to-string (char-syntax ?\ )) ⇒ " "
(char-to-string (char-syntax ?/)) ⇒ "."
(char-to-string (char-syntax ?\()) ⇒ "("
This function makes syntax-table the syntax table for buffer, which defaults to the current buffer if omitted. It returns syntax-table.
This function returns the syntax table for buffer, which defaults to the current buffer if omitted.