Closed smjonas closed 2 years ago
@quangnguyen30192 @jasonkena could one of you quickly test this branch? I tested it better myself this time and it seems to be working fine but I just want to be sure before merging :)
How do I test it 😅 could you provide me the steps?
Yes sure :sweat_smile: One way to test it is to install gillescastel/latex-snippets
https://github.com/gillescastel/latex-snippets and lervag/vimtex
because it uses custom context snippets. Then in a math environment (that is inbetween two $...$
) type sq
, the sqrt
snippet should be shown. Once outside the $
the snippet should not be shown anymore. Previously it was not shown at all.
Or you could simply create the following snippet file (e.g. to test it for a Lua file :UltiSnipsEdit lua
) then type frac
inside $$
:
global !p
def math():
return vim.eval('vimtex#syntax#in_mathzone()') == '1'
endglobal
context "math()"
snippet frac "Fraction"
\\frac{$1}{$2}$0
endsnippet
Thanks, tested, LGTM
@smjonas thank you for your work! Unfortunately, the expansions also work outside the math contexts, the "iA" (auto-trigger) flags on the snippets do not work, and complex pattern matching fails e.g.
context "math()"
snippet "([a-zA-Z])hat" "hat" riA
\hat{`!p snip.rv=match.group(1)`}
endsnippet
Thank you for the feedback, I will check it!
Edit: @jasonkena I could not reproduce your first point, the snippet you provided won't expand in non-math contexts for me. I'll see if I can do something about your second point - by not working you simply mean the snippet is not shown, right? (at least, that's how it behaves for me; this is also the case on the latest commit on the main branch). Or is it now not expanded at all when typing ihat
? For me it still expands in the correct context.
So I think this could be improved in a follow-up PR, I'd suggest to merge this first because it does not seem to break any existing functionality. Of course, let me know if that's not the case!
@smjonas hmm... it's still broken for me. Could you please send a minimal vimrc/luarc?
For example the snippet
frac
will now be shown by cmp when the user is in math mode in a
.tex
file.