gillescastel / latex-snippets

Vim + LaTeX snippets setup
MIT License
1.05k stars 201 forks source link

simplify check for math zone to make compatible with new vimtex syntax #14

Closed Konfekt closed 3 years ago

Konfekt commented 3 years ago

See also https://github.com/lervag/vimtex/issues/1880

beinganukul commented 3 years ago

there are bugs in this pull request

some snippets inside math() function refuse to work

163 context "math()"
164 snippet '([A-Za-z])(\d)' "auto subscript" wrA
165 `!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
166 endsnippet

this doesn't work but,

164 snippet '([A-Za-z])(\d)' "auto subscript" wrA
165 `!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
166 endsnippet

this works globally i don't really know how math function works but you guys can take a look and can reproduce this bug hopefully.

Konfekt commented 3 years ago

I cannot reproduce. I have been testing this PR in Vim 8.0.1568 on Linux using this abbreviation

context "math()"
snippet '([A-Za-z])(\d)' "auto subscript" wrA
`!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
endsnippet

and, typing, say a3, in $*$ (where * denotes the cursor position) expands to a_3 whereas in $text{*}$ it stays a3

beinganukul commented 3 years ago

I cannot reproduce. I have been testing this PR in Vim 8.0.1568 on Linux using this abbreviation

context "math()"
snippet '([A-Za-z])(\d)' "auto subscript" wrA
`!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
endsnippet

and, typing, say a3, in $*$ (where * denotes the cursor position) expands to a_3 whereas in $text{*}$ it stays a3

hey thank you for quick response. i reinstalled vimplug with all other plugins and it worked after all without any issue. hope gilles notices this pull request cause the script no longer functions properly in latest vimtex and thank you for your contribution have a nice day :)

rednaz1337 commented 3 years ago

Can confirm that this PR works fine but the original code doesn't.

isakhammer commented 3 years ago

Can also confirm that this pull request works and the current master doesnt.

Thanks for the fix!! Great job

danielfalbo commented 3 years ago

Seems like there's a much simpler solution but I haven't tried it yet:

def math():
    return vim.eval("vimtex#syntax#in_mathzone()") != "0"

. Found here.

Konfekt commented 3 years ago

Yes, evaluating thisvimtex function (from https://github.com/lervag/vimtex/pull/1884 ) achieves the same as this PR , but, well, depends on vimtex.

gillescastel commented 3 years ago

I updated the code a few days ago, making use of the vimtex functions:

https://github.com/gillescastel/latex-snippets/blob/baa1b42ed9558b4a7ba220c50c5046957719f898/tex.snippets#L1-L12

BertrandSim commented 3 years ago

Hello @gillescastel! Thanks for simplifying the code, it looks much cleaner for vimtex users.

In def env(name), I think we're missing a y somewhere in the return statement?