Emacs Lisp: How to Find Syntax of a Character?

By Xah Lee. Date: .

How to find emacs syntax table classification of a character?

Place cursor on a character, then call describe-char.

For example, type -, place cursor on it (or place ibeam to the left of it), Alt+x describe-char. Emacs displays this:

emacs describe char syntax class 2017 02 13
emacs describe-char output.

〔►see Emacs Lisp: Syntax Table Tutorial

(info "(elisp) Syntax Class Table")

By Emacs Lisp Programatically

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

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 M-x fundamental-mode to switch to fundamental mode.

Syntax Table Topic

  1. Emacs Lisp: Syntax Table Tutorial
  2. Emacs Lisp: How to Find Syntax of a Character?
  3. Emacs Lisp: How to Modify Syntax Table Temporarily
  4. Emacs Lisp: How to Determine If Cursor is Inside String or Comment
  5. Emacs Lisp: Find Matching Bracket Character
Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs