is an Emacs Lisp data structure in which each character's syntactic role is defined. Other Emacs facilities, such as font lock, navigation, parsing, etc., scan these syntax tables to determine where words, symbols, and other syntactic constructs begin and end. Syntax tables are unique to every major mode. They are customizable and even overridable with text properties.
Questions tagged [syntax-table]
76 questions
52
votes
8 answers
How to treat underscore as part of the word?
I use Emacs + evil mode.
When I position the cursor on e (in normal state) in a chunk of text such as abc_def_ghi, ciw (change inner word) changes only the def part of the string, while Vim would change the entire abc_def_ghi.
How can I force evil…

Kossak
- 1,159
- 1
- 9
- 18
12
votes
3 answers
How can I detect if the current character is a comment character for that major mode?
I am working on this little function that pulls up the next line to the current line. I want to add a functionality so that if the current line is a line comment and the next line is also a line comment, then the comment characters are removed after…

Kaushal Modi
- 25,203
- 3
- 74
- 179
9
votes
2 answers
How to 'modify-syntax-entry' for a major mode?
Following this answer, when I type (modify-syntax-entry ?_ "w")
and do M-x eval-region, it has the effect I'm looking for, albeit only for that buffer. I've put (modify-syntax-entry ?_ "w") in my .emacs file, however and after restarting, it's not…

Swiss Frank
- 247
- 1
- 10
9
votes
2 answers
What is a string fence or comment fence?
The docstring for modify-syntax-entry says the following:
(modify-syntax-entry CHAR NEWENTRY &optional SYNTAX-TABLE)
...
The first character of NEWENTRY should be one of the following:
...
/ character-quote. @ inherit from parent…

Wilfred Hughes
- 6,890
- 2
- 29
- 59
9
votes
2 answers
How to change comment character from # (hash) to % (percent sign) for Octave major mode
By default, comment-region inserts # for comments in Octave major mode:
# foo
I want to modify the behavior so that it inserts the percent sign
% foo
I used the following
(setq octave-mode-hook
(lambda () (setq octave-comment-char ?%)…

osolmaz
- 435
- 3
- 13
8
votes
3 answers
How can I make emacs support javascript ES6 template string literals?
I want to use ES6 template string literals e.g.:
`string text line 1
string text line 2
string text ${expression}`
However emacs doesn't recognize that their contents are a string, so syntax highlighting, indentation, etc. don't work. How can I…

dshepherd
- 1,281
- 6
- 18
7
votes
1 answer
Parsing parentheses: smie vs syntax table
I am maintaining a mode for a programming language with... let's say
"annoying" syntax constructs.
For example, the angle brackets (no idea if it is the correct word)
< and > are parentheses. However, the word -> is also a valid
token, does not…

T. Verron
- 4,233
- 1
- 22
- 55
7
votes
0 answers
What was syntax-begin-function obsoleted in favour of?
Since Emacs 25.1, syntax-begin-function is obsolete:
syntax-begin-function is a variable defined in ‘syntax.el’.
Its value is nil
This variable is obsolete since 25.1.
This variable may be risky if used as a file-local…

Tim Landscheidt
- 467
- 3
- 8
6
votes
2 answers
Three-characters comment syntax
Emacs supports syntax flags for 1- and 2-characters comment delimiters. Can it be made to recognize and properly highlight 3-characters delimiters?
For example:
In Emacs Lisp:
;;; Headings
In C#:
/// XML Comment
In Java:
/** Javadoc…

Clément
- 3,924
- 1
- 22
- 37
5
votes
1 answer
How to use a particular syntax table with arbitrary functions?
I have an Elisp function which takes a string and performs capitalization (capitalize) on it, and then inserts it into a file. Apparently capitalize doesn't consider the single quote as a "word constituent" and therefore I get results like "I'M A…

sixter
- 113
- 7
5
votes
0 answers
Paired string delimiters?
Red and Rebol have multiline strings that start with { and end with }. Reading through Elisp docs I don't see any simple way to define this in the syntax table. The string quotes class matches the same character only and the generic string…

xificurC
- 151
- 1
5
votes
2 answers
How to keep underscores in Python within a word boundary?
When writing code in python-mode my preference would be to include underscores within a word boundary, so variable_with_underscores is treated as a single word.
How would I limit my word preference only to python-mode?

Jeff Bauer
- 861
- 1
- 10
- 22
5
votes
1 answer
Change character syntax temporarily?
Q: how can I change the syntax of a character for a single function?
In text-mode and its derivatives, the ' character has word syntax rather than, say punctuation or string quote syntax. That's a problem when using abbrev-mode, as I would like the…

Dan
- 32,584
- 6
- 98
- 168
4
votes
0 answers
Help with advanced syntax rules
How can I express syntax rules like "[0-9/.:*+!_'?-] are valid symbol constituent, but not as the first char"?
Or "/ is a valid symbol constituent, but can only appear once and in the middle of a symbol".

expez
- 381
- 2
- 8
3
votes
4 answers
Sorting words with hyphens (e.g. in a Lisp mode)
SortWords in the EmacsWiki suggests this function as a way to sort words:
(defun sort-words (reverse beg end)
"Sort words in region alphabetically, in REVERSE if negative.
When prefixed with negative \\[universal-argument], sorts in
reverse.
…

David J.
- 1,809
- 1
- 13
- 23