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.
  • Phil

    FWIW, provided you can remember that "syntax class" is the phrase you're looking for, it's pretty easy to find in the manual. After:

    `M-x info RET`
    `m elisp RET`

    You can just use `I syntax class RET` to use the index.

    or `g syntax TAB` to list completions...

  • Phil Hudson

    Thanks for sharing this. One suggestion: the distinction between the hyphen and the underscore in different rows of the Character Designation column may not be obvious at a glance. How about pointing it out in some way?

    • jcs

      Good idea. I added explicit labels for hyphen and underscore in the table.