From: "Felipe Ochoa" <felipeochoa0918@gmail.com>
To: "'Dmitry Gutov'" <dgutov@yandex.ru>,
"'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: Mon, 23 Jan 2017 10:26:06 +0100 [thread overview]
Message-ID: <004301d2755a$b9f62b30$2de28190$@gmail.com> (raw)
In-Reply-To: <79cc5841-8480-b2fd-eeb7-ff2bf33a0e68@yandex.ru>
>> There are still issues with greater-than and less-than
>> as binary operators.
> Inside XML literals, you mean?
Yes, exactly.
> How's your experience so far?
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 :(
> 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.
I'm not sure I'm grasping this part entirely. I understand conceptually that using syntax-ppss with incompatible syntax tables could lead to cache problems. 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!). Would introducing this additional incompatibility cause more problems?
> 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).
> ... (the cache is not really a public API)
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?
> 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 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. In js2 and rjsx there is of course the full parser to give us this information.
> This way we don't depend on syntax-ppss internals, 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.
I think we could use a regex like the following to identify JSX start tokens:
(rx (seq (or (any "-+*/%=><?:&")
(seq (or "return" "typeof" "delete" "instanceof") whitespace)
(any "([{,;"))
(* whitespace) ; Should also skip over comments
"<"))
I.e., any "<" after an operator or at the beginning of an expression or statement. We'd have to filter out some false positives (postfix ++ and --, strings, and comments, possibly others), but this would get all the JSX start tags, I think. We could use a similar regex to find the ">" that close JSX tags:
(rx (seq ">"
(* whitespace) ; Should also skip over comments
(or (any "-+*/%=><?:&")
(seq (or "return" "typeof" "delete" "instanceof") whitespace)
(any "(}],;"))
Not sure how to go from there to the "{" and "}" tokens though. Is it possible to run syntax-ppss using different tables for different parts of the buffer?
next prev parent reply other threads:[~2017-01-23 9:26 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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='004301d2755a$b9f62b30$2de28190$@gmail.com' \
--to=felipeochoa0918@gmail.com \
--cc=24896@debbugs.gnu.org \
--cc=dgutov@yandex.ru \
--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 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.