Elisp: Create Syntax Table

By Xah Lee. Date: . Last updated: .

Create Syntax Table

Here's typical way to create a syntax table.

;; typical way to create and set syntax table

(defvar xx-syntax-table nil "Syntax table for `xx'.")

(setq xx-syntax-table
      (let ((synTable (make-syntax-table)))
        ;; modify each char's class
        (modify-syntax-entry ?# "<" synTable)
        (modify-syntax-entry ?\n ">" synTable)
        ;; more here

        ;; return it
        synTable))

;; set syntax table for the current buffer
(set-syntax-table xx-syntax-table)

Modify Syntax Entry

modify-syntax-entry

(modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE)

modify a char's entry in a sytax table.

Set Syntax Table to Buffer

set-syntax-table

(set-syntax-table TABLE)

set a syntax table for the current buffer.

Emacs Lisp, character and syntax table