Elisp: How to Find Syntax of a Character?
How to find emacs syntax table classification of a character?
Place cursor on a character, then Alt+x
For example, type -, place cursor on it (or place ibeam to the left of it), Alt+x
describe-char. Emacs displays this:
By Emacs Lisp Programatically
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
describe-syntax【Ctrl+h s】 to see the value of current buffer's syntax table.
- In lisp code, the function
syntax-tablereturns 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
So, to find a character's syntax class in standard syntax table, first Alt+x
fundamental-mode to switch to fundamental mode.
Writing Major Mode
- How to Write a Emacs Major Mode for Syntax Coloring
- Elisp: html6-mode
- Elisp: Font Lock Mode Basics
- Elisp: How to Define Face
- Elisp: How to Color Comment in Major Mode
- Elisp: How to Write Comment Command in Major Mode
- Elisp: How to Write Your Own Comment Command from Scratch
- Elisp: How to Write Keyword Completion Command
- Elisp: How to Create Keymap for Major Mode
- Elisp: Abbrev, Template, for Major Mode
- Elisp: Text Properties
- Elisp: Overlay Highlighting
- Emacs: Lookup Google, Dictionary, Documentation
- Elisp: Syntax Table Tutorial
If you have a question, put $5 at patreon and message me.