vimtex
vimtex copied to clipboard
Option to allow expl3 syntax for file
Is your feature request related to a problem? Please describe it.
Yes. The syntax highlighter mostly works well for expl3 syntax (thanks!). However, it is quite easily confused. If I move through a file to a different region or switch away and back, it often doesn't realise that expl3 syntax is valid 'here'. Often it is possible to correct this by scrolling up to e.g. \ExplSyntaxOn and then scrolling back, but this gets very tedious, especially in files with a high proportion of expl3.
Describe the solution you'd like
Ideally, the highlighter wouldn't get confused 😉 . In the real world, I would like an option to tell the highlighter to accept expl3 syntax throughout a specific file. This would make it possible to flip the expl3 switch on for files where false positives are more troublesome than false negatives, which may often be the case in .dtx files, for example, when classes or packages make heavy use of expl3. Ideally, it would be possible to toggle this on/off during editing, so it could be enabled when editing the code, say, but not the user documentation. But an option to just enable it in the mode line per file would be fine.
Describe alternatives you've considered
None really. I suppose I could switch highlighting off, but that seems a rather drastic solution.
Additional context
Note that some of the erroneous flags in the screenshot would occur anyway, due to a limitation of the syntax highlighting, but there would be many fewer false positives if that was the only problem:
I believe that all of the red highlighting here is erroneous. This is obviously a problem: the highlighter certainly won't help disabuse me of this notion if I am mistaken! Aside from that, it is just very distracting.
This is won't help you here but mentioning this for the sake of completeness: This (injecting a different language into another) is actually very easy to do with tree-sitter. There's already a latex parser (which is obviously not as powerful as VimTeX's smart package-aware syntax highlighting), but I don't think anybody has looked at an expl3 parser yet...
Yes. The syntax highlighter mostly works well for
expl3syntax (thanks!). However, it is quite easily confused. If I move through a file to a different region or switch away and back, it often doesn't realise thatexpl3syntax is valid 'here'. Often it is possible to correct this by scrolling up to e.g.\ExplSyntaxOnand then scrolling back, but this gets very tedious, especially in files with a high proportion ofexpl3.
This is likely due to the syntax synchronization settings:
https://github.com/lervag/vimtex/blob/9d9f74c3ab073b70bc943279af1aa86075de632c/autoload/vimtex/syntax/core.vim#L809-L810
Perhaps you could test on your end by changing the maxlines to e.g. 5000 and see if that fixes your problem?
I'm not sure I want to make this change, but knowing that this is the cause would be useful. There may be other methods for solving it.
Also, if you were able to provide an example for how to reproduce this it may help.
This is won't help you here but mentioning this for the sake of completeness: This (injecting a different language into another) is actually very easy to do with tree-sitter. There's already a latex parser (which is obviously not as powerful as VimTeX's smart package-aware syntax highlighting), but I don't think anybody has looked at an expl3 parser yet...
Thanks; I would be glad to see someone build a modernized version of VimTeX based on Lua, tree-sitter and similar. Of course, I might go there myself, but that's at best a few years in the future.
In the meantime, I think we can still make relatively cheap but useful improvements to VimTeX. :)