[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#24896: JSX prop indentation after fat arrow
From: |
Dmitry Gutov |
Subject: |
bug#24896: JSX prop indentation after fat arrow |
Date: |
Wed, 25 Jan 2017 04:59:59 +0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:51.0) Gecko/20100101 Thunderbird/51.0 |
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.