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: Wed, 25 Jan 2017 04:59:59 +0300	[thread overview]
Message-ID: <7c472ad4-7a80-3747-3661-3dcdafce2c04@yandex.ru> (raw)
In-Reply-To: <004301d2755a$b9f62b30$2de28190$@gmail.com>

On 23.01.2017 12:26, Felipe Ochoa wrote:

> It's actually worked very well. I had an issue once where indenting an entire region took several passes to get right, but now I'm not able to reproduce it :(

Unreproducible wonky behavior might be the result of busting syntax-ppss 
cache.

> But it seems to me that the js*-mode and sgml-*-mode syntax tables are already incompatible (namely, "<" and ">", which are causing all this grief!).

Right. For now, we seem to have avoided the problem because 
sgml-indent-line does not call syntax-ppss.

> Would introducing this additional incompatibility cause more problems?

...so if you change the syntax table just around the call to 
sgml-calculate-indent (not the whole js-jsx-indent-line), it shouldn't 
make things worse.

> This sounds like a bit of a headache. E.g., indenting a region would require binding and unbinding the cache carefully as you stepped into and out of JSX. What if we just scrap the syntax-ppss cache altogether? Would the performance penalty be too great?

Let-binding the cache variables to nil around the call to 
sgml-calculate-indent might be fast enough, because multiple calls to 
syntax-ppss (if any) inside that functions will still be amortized.

But this is really going to be more useful when sgml-calculate-indent 
starts using syntax-ppss, which really might never happen. So the 
previous solution (changing the syntax table only where needed) might be 
preferable in the meantime.

> This is based on a rough heuristic that essentially backtracks looking for "[(,]\n *<" (it also handles comments). This misses any JSX which is not at the start of the line, and it only tells us the start of the tag, not the end or where the body ends.

I think sgml-skip-tag-forward could help with the last one.

> In js2 and rjsx there is of course the full parser to give us this information.

Like Jackson mentioned, probably not a good idea.

> I think we could use a regex like the following to identify JSX start tokens:
>
> (rx (seq (or (any "-+*/%=><?:&")

Can all of these (e.g. >) be realistically expected before a JSX literal?

And it seems like the << operator would cause a false positive.

I like the general direction, though.

> We could use a similar regex to find the ">" that close JSX tags:

sgml-skip-tag-forward seems like the more reliable option to me. 
Although it might work worse on invalid code.

> Is it possible to run syntax-ppss using different tables for different parts of the buffer?

If you perform the previously mentioned cache fiddling, yes. If not, 
then the answer is maybe, and that depends on how and when you'll be 
calling it. So maybe you should get into the underlying mechanics first.





  parent reply	other threads:[~2017-01-25  1:59 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
2017-01-23  9:26               ` Felipe Ochoa
2017-01-23 17:07                 ` Jackson Ray Hamilton
2017-01-25  1:59                 ` Dmitry Gutov [this message]
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=7c472ad4-7a80-3747-3661-3dcdafce2c04@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).