8

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.

dshepherd
  • 1,281
  • 6
  • 18
  • What's your Emacs version and which JS major mode are you using? –  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

3 Answers3

9

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
  • 1,281
  • 6
  • 18
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.

PythonNut
  • 10,243
  • 2
  • 29
  • 75
3

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

Dmitry
  • 3,508
  • 15
  • 20