unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dmitry Gutov <dgutov@yandex.ru>
To: Felipe Ochoa <felipe.nospam.ochoa@gmail.com>
Cc: 24896@debbugs.gnu.org,
	Jackson Ray Hamilton <jackson@jacksonrayhamilton.com>
Subject: bug#24896: JSX prop indentation after fat arrow
Date: Sun, 15 Jan 2017 05:04:51 +0300	[thread overview]
Message-ID: <79cc5841-8480-b2fd-eeb7-ff2bf33a0e68@yandex.ru> (raw)
In-Reply-To: <CAHp7JgiWfFyyzCS+93z+kOAqR+7q=VEeqhUQdscMooTeu23f=g@mail.gmail.com>

On 06.01.2017 20:44, Felipe Ochoa wrote:
> So I've thought about this some more, and realized that this won't fix
> everything. There are still issues with greater-than and less-than as
> binary operators.

Inside XML literals, you mean?

> Maybe a better idea is to give '{' and '}' comment
> syntax ('<' and '>') so that SGML ignores all the bracketed JS stuff.
> I've been trialing this with the following:

How's your experience so far?

> (defvar js-jsx-tag-syntax-table
>   (let ((table (make-syntax-table sgml-tag-syntax-table)))
>     (modify-syntax-entry ?\{ "<" table)
>     (modify-syntax-entry ?\} ">" table)
>     table))
>
> (defun advice-js-jsx-indent-line (orig-fun)
>   (interactive)
>   (let ((sgml-tag-syntax-table js-jsx-tag-syntax-table))
>     (apply orig-fun nil)))

Here's the problem: js-indent-line uses syntax-ppss. sgml-indent-line 
doesn't (for now), but js-jsx-indent-line calls js-indent-line in 
certain contexts.

And this is a problem because calling syntax-ppss in different contexts 
with incompatible (paren-wise) syntax tables will make syntax-ppss cache 
broken, and lead to likewise broken behaviors.

So, one thing we could do here is let-bind the variables that constitute 
syntax-ppss cache around the call to orig-fun (i.e. around the context 
where we modify the syntax table).

Another, somewhat more difficult approach, would be to try to apply the 
"<" and ">" syntax classes in syntax-propertize-function, only to 
occurrences of "{" and "}" inside XML literals.

That would require knowing where the said literals begin and end, but we 
do know that somehow already, seeing as we know which indentation 
function to choose, right?

This way we don't depend on syntax-ppss internals (the cache is not 
really a public API), and reindenting the whole buffer might be faster, 
because we would keep syntax-ppss cache around more. Still, not sure how 
much faster that would be in practice.





  reply	other threads:[~2017-01-15  2:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-07  9:56 bug#24896: JSX prop indentation after fat arrow Felipe Ochoa
2016-11-19 22:47 ` Dmitry Gutov
2016-11-22  5:48   ` Jackson Ray Hamilton
     [not found]     ` <CAHp7JggpF+APETs=BaX-yJMrcX+u55NoXanj_krbfdD-78WRTw@mail.gmail.com>
2016-12-08 11:12       ` Felipe Ochoa
2016-12-09  0:18         ` Dmitry Gutov
2017-01-06 17:44           ` Felipe Ochoa
2017-01-15  2:04             ` Dmitry Gutov [this message]
2017-01-23  9:26               ` Felipe Ochoa
2017-01-23 17:07                 ` Jackson Ray Hamilton
2017-01-25  1:59                 ` Dmitry Gutov
2019-06-05  2:47 ` Jackson Ray Hamilton
2019-06-06  6:59 ` Jackson Ray Hamilton

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=79cc5841-8480-b2fd-eeb7-ff2bf33a0e68@yandex.ru \
    --to=dgutov@yandex.ru \
    --cc=24896@debbugs.gnu.org \
    --cc=felipe.nospam.ochoa@gmail.com \
    --cc=jackson@jacksonrayhamilton.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 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).