-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better handling of \\)
in nested environments
#2311
Comments
I think this is fixed now, please test. |
Actually the old behaviour is arguably better for practical purposes even though it is technically not correctly parsing the latex. The new behaviour makes the rest of the document's syntax highlight change if you type a command at the end of inline math. What I was requesting is if it is possible for this new behaviour to only apply when it is nested inside another environment. |
I'm sorry, but I really don't understand what you are trying to say. |
I either don't understand or don't agree. I believe the syntax highlighting should be technically correct as long as that is possible, and I believe my commit fixed an issue where your example ended up highlighted wrong because the syntax rules were technically incorrect.
I don't understand. Can you show an example and explain further? |
Basically, I use a snippet for entering and leaving math mode, which leaves me with I actually over estimated the impact of this change because I used To be fair this is an issue with basically any programming language that has strings anyways. But most languages don't allow regular strings to span more than one line so the effect is more localized. |
Ah, I see now. Ok. And your initial proposal makes more sense as well. However, this seems very hard. By design, environments do not necessarily create nested syntax groups. Thus it is hard to separate the nested and top-level situation. And I don't have any other good ideas on how to solve this. One possibility could be to rely on the cursor position, but that's too "hacky" even for me. I believe the best solution is to select either to have @clason You tend to have opinions on matters like these - what do you think? |
You make it sound like it's a good thing... I think making this context-sensitive is impossible to get right, since you can (Actually, my first thoughts on reading the issue were a) yet another reason to use |
And regarding the extra space, that gets deleted on I think the best thing to do probably if detecting nesting is too hacky is to make the behaviour of |
Haha, yes :)
Exactly, that's also my thought.
Sorry, but this is unclear to me. I proposed to either a) keep the currently implemented "greedy" and "technically correct" implementation, or b) revert to the less greedy variant that would fail in some rare cases. The benefit of b) is that it would more or less avoid the flashing stuff. Which of a) and b) did you find to be most useful?
Yes, I agree with this @xsrvmy - however I don't see a good way to avoid it - except perhaps to not use a snippet/auto-closing-delimiter type plugin. I personally just write
This is also hard. Not impossible, but then I think it is quite hacky and perhaps better to implement as a user customisation.
Ah, yes. It's more of an syntax "artifact" than a separate issue. One thing I could do is to restrict both |
I think making
Yes, I'd say anything that allows "short-circuiting" syntax elements (without breaking valid syntax) would be a good idea (also for performance reasons, even if the gains should be insignificant in most situations.) |
Unfortunately the following is valid code: \(
\begin{bmatrix}
\end{bmatrix}
\) This would also break syntax highlighting while typing when inline math is split over multiple lines (due to long commands or matrices). |
Ok, I stand corrected - you can have empty lines in inline math. Although I really don't like it. Annoying, because I liked the idea of short circuiting. Well then, IMHO, there's nothing more to do. I don't see any way to improve this without also making it somehow worse. Thus I propose to not make any further changes. |
The current behaviour of
\\)
is to group the\
with\)
. Although this is not technically correct, it is actually the desirable behaviour since it prevents the rest of the document from being rehighlighted/reconcealed when entering commands in math mode.However consider the following:
Here
\\)
is intended to insert a new line. However this instead breaks syntax highlighting.I am proposing the following behaviour:
\\)
appears in the top-level of an inline math expression, highlight it as\
and\)
, as using\\
in inline math is very rare, and the user's cursor is likely between the two\
's.\\)
appears in an environment nested inside inline math, highlight it as\\
and)
.(Note: I don't know how vim's highlighter does tokenizing/parsing, so if this is not possible please close the issue.)
The text was updated successfully, but these errors were encountered: