Emacs Lisp: Find Syntax of a Char
Find Char Syntax by By Emacs Command
How to find Emacs Syntax Table classification of a character?
(info "(elisp) Syntax Class Table")
Find Char Syntax by By Emacs Lisp Code
The function char-syntax
returns a character's syntax class.
(char-syntax (string-to-char "-")) ; returns 95 ;; 95 (#o137, #x5f, ?_) ;; _ means it's in syntax class of symbol
Show Current Syntax Table
- Alt+x
describe-syntax
【Ctrl+h s】 to see the value of current buffer's syntax table. - In lisp code, the function
syntax-table
returns current buffer's syntax table.
Syntax Table is Local to Buffer
Remember, each buffer has its own syntax table, typically set by a major mode.
Emacs has a standard-syntax-table
, which is the syntax table used by fundamental-mode
.
So, to find a character's syntax class in standard syntax table, first Alt+x fundamental-mode
to switch to fundamental mode.