all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Jostein Kjønigsen" <jostein@secure.kjonigsen.net>
To: emacs-devel@gnu.org
Cc: ldd@lddubeau.com
Subject: Regarding Emacs, js.el, template-strings and syntax-tables
Date: Thu, 24 Aug 2017 08:56:07 +0200	[thread overview]
Message-ID: <1503557767.41308.1083341824.4A2103C1@webmail.messagingengine.com> (raw)

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

             reply	other threads:[~2017-08-24  6:56 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24  6:56 Jostein Kjønigsen [this message]
2017-08-24 10:53 ` Regarding Emacs, js.el, template-strings and syntax-tables 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1503557767.41308.1083341824.4A2103C1@webmail.messagingengine.com \
    --to=jostein@secure.kjonigsen.net \
    --cc=emacs-devel@gnu.org \
    --cc=jostein@kjonigsen.net \
    --cc=ldd@lddubeau.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.