Emacs Syntax Classes

This is sort of a note to myself. I sometimes need to know the character designation of a syntax class. Most often this is for use with the \sC syntax in a regexp. For example

(looking-at "^\\s-*$\\|\\s-*;")

asks if we’re looking at a line containing only whitespace or a line with possible leading whitespace and then a ;. (It’s used to recognize lines in a Scheme program file with no executable code.)

The problem is I always have a hard time finding the Syntax Class Table in the Elisp manual. Xah Lee has helpfully provided a bunch of pages like HTML/XML Entities List, Unicode Space Symbols, and a Regexp Cheat Sheet that I’ve bookmarked for easy reference but nothing for the syntax table. Therefore, I’m making this short table mostly so I can bookmark it.

The characters in a given syntax class usually depend on the current major mode so the table doesn’t give the full story. For that you need to look at the Syntax Class Table node of the Elisp manual.

Syntax Class Character Designation
Whitespace Character - (hyphen) or ␠
Word Constituent w
Symbol Constituent _ (underscore)
Punctuation Character .
Open Parenthesis (
Close Parenthesis )
String Quote "
Escape-Syntax Character \
Character Quote /
Paired Delimeter (TeX $) $
Expression Prefix '
Comment Starter <
Comment Ender >
Inherit Standard Syntax @
Generic Comment Delimiter !
Generic String Delimiter |

Update: Designated hyphen and underscore explicitly.

This entry was posted in Programming and tagged , . Bookmark the permalink.