emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Regarding Emacs, js.el, template-strings and syntax-tables


From: Jostein Kjønigsen
Subject: Regarding Emacs, js.el, template-strings and syntax-tables
Date: Thu, 24 Aug 2017 08:56:07 +0200

Hey everyone.

First off, while the subject of the examples employed in this email are all related to ECMAScript, the kind of syntax-statements discussed is in no way new or unique to ECMAScript. Off hand I know at least TypeScript and C# supports this too, not to mention many web-based templating languages, like Jekyll.

But everyone seems to love _javascript_, so lets use that as an example. Newer version of ECMAScript supports in-string templating. That is, you can escape the string-sequence and insert computational expressions inside the string-literal. This allows a cleaner syntax than composing the string using concatenation.

As an example, instead of:

function getGreeting(name) {
    let greeting = "Hello, " + name + "!";
    return greeting;
}

you can write:

function getGreeting(name) {
    let greeting = `Hello, ${name}!`;
    return greeting;
}

For more details on this feature, MDN has a good write-up.

Now for the problem:

From what I can see js.el does not support this new syntax yet, so that everything inside the string is treated (and highlighted) semantically as a string. Another area where similar problems exist, but with comments (as opposed to string) is JSDoc.

In combination with other minor-modes like flyspell-prog-mode which spell-checks strings and comments, this can quickly get annoying. It also means syntax-based analysis for things like auto-completion will simply not trigger.

This is a problem many major-modes needs to handle (as such I'm here speaking as a package maintainer for MELPA package typescript.el). It would be nice if Emacs at its core had mechanisms which made supporting this kind of syntax easier.

Fundamentally, we would need a way to escape an on-going string or comment, and end that escape-sequence until either we have a new escape-sequence or the original string/comment delimiter to finally terminate the string/comment.

To the best of my knowledge, and please correct me if I'm wrong, this all involves fundamental syntax, and it would be best to handle this with syntax-tables if possible. But last time I read the documentation on syntax-tables, there was no way for to escape ongoing strings or comments using syntax-tables (and again, please correct me if I'm wrong!)

I'm sure if Emacs supported this at its core, it would be much easier in major-mode implementations to support these kind of syntaxes.

Is any work being done to extend syntax-tables to support this?

Is any work being done to support template-strings in js.el?

--
Cheers
Jostein Kjønigsen

address@hidden 🍵 address@hidden
https://jostein.kjonigsen.net



reply via email to

[Prev in Thread] Current Thread [Next in Thread]