7

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 tell emacs that backticks are string delimiters?

I'm using emacs version 24.5, and the built in js-mode.

  • What's your Emacs version and which JS major mode are you using? – lunaryorn May 12 '16 at 16:59
  • @lunaryorn I edited to add the information, but tbh I only opened this question as a google-friendly way to provide the answer for other people. My answer below works for me, but stack overflow won't let me accept it yet. Hope I didn't waste your time! – dshepherd May 12 '16 at 18:41
7

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.

7

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.

3

Or you just wait for Emacs 25.1 to come out. It's fixed there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.