Skip to main content
Share Your Experience: Take the 2024 Developer Survey
17 votes

How to treat underscore as part of the word?

The spacemacs FAQ offers the following language-specific solution: ;; For python (add-hook 'python-mode-hook #'(lambda () (modify-syntax-entry ?_ "w"))) ;; For ruby (add-hook 'ruby-mode-hook #'(...
ejoubaud's user avatar
  • 279
12 votes
Accepted

How to 'modify-syntax-entry' for a major mode?

Each major mode has its own syntax and syntax table. If you just put (modify-syntax-entry ?_ "w") in your init file, it gets evaluated in the buffer that is current when your init file is loaded -- ...
Drew's user avatar
  • 77.9k
9 votes
Accepted

How can I make emacs support javascript ES6 template string literals?

You need to add backticks as a string delimiter to the js-mode syntax table like this: (modify-syntax-entry ?` "\"" js-mode-syntax-table) More information here.
dshepherd's user avatar
  • 1,281
7 votes

How can I make emacs support javascript ES6 template string literals?

For the record, ES6 template string literals are supported out-of-the-box in js2-mode, complete with font-locking for the interpolated variables as well.
PythonNut's user avatar
  • 10.4k
5 votes
Accepted

Treat shebang as a comment

Try (modify-syntax-entry ?# ". 1" js-mode-syntax-table) (modify-syntax-entry ?! ". 2b" js-mode-syntax-table) Reference
Michael Vehrs's user avatar
5 votes
Accepted

Get thing-at-point to include periods

What about this. (defun dotted-symbol-at-point () (with-syntax-table (make-syntax-table (syntax-table)) (modify-syntax-entry ?. "_") (thing-at-point 'symbol)))
politza's user avatar
  • 3,346
5 votes

How to 'modify-syntax-entry' for a major mode?

Rather than modifying the syntax tables, you can instead use the built-in superword-mode: Superword mode is a buffer-local minor mode. Enabling it changes the definition of words such that symbols ...
erikstokes's user avatar
  • 12.9k
4 votes
Accepted

add a rule to syntax-propertize-rules

The answer is that you can't do it "right". But you can do the following: (defalias 'my/perl-syntax-propertize-function (syntax-propertize-rules ("\\('\\)[bh]" (1 ".")))) (add-hook 'perl-mode-hook ...
Stefan's user avatar
  • 26.5k
4 votes

Rx: Skip commented out lines

How can I make it to completely skip the commented out line? "Skipping lines" is not an inherent capability of regular expressions. Regexps either do or do not match whatever input they are given. ...
Basil's user avatar
  • 12.5k
4 votes
Accepted

How do I hook fundamental-mode and all modes derived from it for modifying syntax for underscores

1st: Dealing with your actual problem of setting the syntax for ?_ in modes derived from fundamental-mode. There are no commands setting the syntax table in fundamental-mode. Therefore, it uses the (...
Tobias's user avatar
  • 33.3k
4 votes
Accepted

How to use a particular syntax table with arbitrary functions?

You say you don't want to have to "manually create a new table and use with-syntax-table for every function in my config or change the current table using modify-syntax-entry." I think you ...
Drew's user avatar
  • 77.9k
3 votes

Make `thing-at-point` treat dot as a symbol-constituent character?

To supplement what @phils said - Make . have symbol-constituent syntax in the current syntax table, or in a copy of it. Either define your own replacement function for thing-at-point: (defun my-thg-...
Drew's user avatar
  • 77.9k
3 votes

How can I make emacs support javascript ES6 template string literals?

Or you just wait for Emacs 25.1 to come out. It's fixed there.
Dmitry's user avatar
  • 3,793
3 votes
Accepted

modify syntax entry globally?

If you want to do something in every mode then you can use after-change-major-mode-hook to run your code.
phils's user avatar
  • 51.6k
3 votes

How to change comment character from # (hash) to % (percent sign) for Octave major mode

The octave-comment-char was added specifically for your kind of use case, so all you should need is: (setq octave-comment-char ?%) No need to change the syntax table, since % is already recognized ...
Stefan's user avatar
  • 26.5k
3 votes

How to treat underscore as part of the word?

Emacs 24 introduced superword-mode, a minor mode that treats underscores as part of words. evil-mode respects this setting. Here is the documentation: (superword-mode &optional ARG) ...
BallpointBen's user avatar
3 votes
Accepted

syntax table malfunction

Your approach almost works, but you can't only modify the syntax for the opening { if you want that to match the closing }, so you need both of: (modify-syntax-entry ?{ "(}") (modify-syntax-entry ?} "...
phils's user avatar
  • 51.6k
3 votes

Simplest Pattern for matching Identifiers in complex Regular Expressions?

I do not know a shortcut for identifier regexps. Maybe, that is due to the complicated rules that exist for identifiers of some languages. Nevertheless you can define your own format strings and ...
Tobias's user avatar
  • 33.3k
2 votes

How to treat underscore as part of the word?

Doesn't quite answer the OP's question but thought I'd put this here for completeness. I also like evil's default behavior (esp. for python and lisp-dialects where I might only want to change part of ...
Anselm Coogan's user avatar
2 votes
Accepted

modify syntax table for strings in perl modes

So I did some more digging and I was able to find a solution, but not a very clean one. I copied the perl-syntax-propertize-function from perl-mode.el. I then added this to my .emacs and changed the ...
Prgrm.celeritas's user avatar
2 votes
Accepted

Locally modify the syntax-table via text-properties

As mentioned by Tobias, you generally need (set (make-local-variable 'parse-sexp-lookup-properties) t) in order for those properties to have an effect. The reason for it is probably historical and ...
Stefan's user avatar
  • 26.5k
2 votes
Accepted

Changing evil-forward-word behavior by modifying a syntax table

Turns out looking at the syntax table had little merit. The solution that I've found is to just advice the evil-word functions to skip over the dash. (defun skip-dash-backward (n &rest foo) ...
Russ Kiselev's user avatar
2 votes
Accepted

How come newline does not match [[:space:]] in tex-mode and bibtex-mode?

describe-char tells us that the newline has syntax: (...) character: C-j (displayed as C-j) (codepoint 10, #o12, #xa) (...) syntax: &...
T. Verron's user avatar
  • 4,293
2 votes
Accepted

How to set backslash character "\" to be a word constituent in LaTeX-mode syntax tables

Not heavily tested, but the following lines in your init file should do the trick: (defun pglpm/modify-LaTeX-mode-syntax-table () (modify-syntax-entry (string-to-char TeX-esc) ...
Arash Esbati's user avatar
  • 1,975
2 votes

Syntax/indentation problems with Vue mode in Emacs 27 nightly

The problem has been reported as #99 and already fixed in master of mmm-mode, but since there is no new release, you have to install the newest mmm-mode manually, or add the missing setting to mmm-...
Uwe Koloska's user avatar
  • 1,008
2 votes
Accepted

Making Emacs see ♥ as punctuation

Sentence movement functions use the regexp returned by the (sentence-end) function to find the end of a sentence. The (sentence-end) function returns the value of the sentence-end variable if it is ...
Jordon Biondo's user avatar
2 votes

Tex indentation with TAB

Looks like I somehow managed to switch to Tex mode, instead of LaTex mode. Changing to LaTex mode is easy: M-x latex-mode. Many thanks to @vonbrand for telling me to check the mode!
Yair Daon's user avatar
  • 131
2 votes
Accepted

After setting syntax-propertize-function, comment is not being fontified with comment face

The above code will indeed set something for face. @Lindydancer helped me realize that I had set font-lock-defaults with the second parameter (keywords-only) of the list as t). Unsetting keywords-only ...
ackerleytng's user avatar
1 vote
Accepted

How to know what chars are "word constituents" in latex-mode-syntax-table

I think that the loop of the edited version of my question solved my problem. I want to share here the solution temporarily adopted. I'd like to know if there is something better (e.g. a more compact ...
Gabriele's user avatar
  • 1,618

Only top scored, non community-wiki answers of a minimum length are eligible