unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Regarding Emacs, js.el, template-strings and syntax-tables
@ 2017-08-24  6:56 Jostein Kjønigsen
  2017-08-24 10:53 ` Stefan Monnier
  0 siblings, 1 reply; 20+ messages in thread
From: Jostein Kjønigsen @ 2017-08-24  6:56 UTC (permalink / raw)
  To: emacs-devel; +Cc: ldd

[-- Attachment #1: Type: text/plain, Size: 2863 bytes --]

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[1]. 

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[2].
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

jostein@kjonigsen.net 🍵 jostein@gmail.com
https://jostein.kjonigsen.net



Links:

  1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
  2. http://usejsdoc.org/about-getting-started.html

[-- Attachment #2: Type: text/html, Size: 4264 bytes --]

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2017-09-05  9:53 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-24  6:56 Regarding Emacs, js.el, template-strings and syntax-tables Jostein Kjønigsen
2017-08-24 10:53 ` Stefan Monnier
2017-08-24 12:13   ` Jostein Kjønigsen
2017-08-24 12:17     ` Jostein Kjønigsen
2017-08-24 13:47       ` Stefan Monnier
2017-08-24 14:04     ` Stefan Monnier
2017-08-24 12:31   ` Anders Lindgren
2017-08-24 14:20     ` Stefan Monnier
2017-08-27 16:37       ` Dmitry Gutov
2017-08-24 14:22     ` Stefan Monnier
2017-08-24 15:19       ` Anders Lindgren
2017-08-29 13:36         ` Stefan Monnier
2017-08-29 13:49           ` Anders Lindgren
2017-08-30  2:22             ` Richard Stallman
2017-09-01 12:14               ` Anders Lindgren
2017-09-04 23:40     ` Dmitry Gutov
2017-09-05  7:00       ` Anders Lindgren
2017-09-05  8:25         ` Dmitry Gutov
2017-09-05  9:30           ` Anders Lindgren
2017-09-05  9:53             ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).