GNU bug report logs - #24896
JSX prop indentation after fat arrow

Previous Next

Package: emacs;

Reported by: Felipe Ochoa <felipe.nospam.ochoa <at> gmail.com>

Date: Mon, 7 Nov 2016 16:35:02 UTC

Severity: minor

Merged with 26001, 30225, 32158

Found in versions 26.1, 27.0.50

Done: Dmitry Gutov <dgutov <at> yandex.ru>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Dmitry Gutov <dgutov <at> yandex.ru>
To: 'Felipe Ochoa' <felipe.nospam.ochoa <at> gmail.com>
Cc: 24896 <at> debbugs.gnu.org, 'Jackson Ray Hamilton' <jackson <at> jacksonrayhamilton.com>
Subject: bug#24896: JSX prop indentation after fat arrow
Date: Wed, 25 Jan 2017 04:59:59 +0300
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.




This bug report was last modified 5 years and 352 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.