@@ -14,33 +14,31 @@ local default_opts = {
1414M .setup = function (opts )
1515 opts = vim .tbl_deep_extend (" force" , default_opts , opts or {})
1616
17- local is_math = utils .with_opts (utils .is_math , opts .use_treesitter )
18- local not_math = utils .with_opts (utils .not_math , opts .use_treesitter )
19-
2017 ls .config .setup ({ enable_autosnippets = true })
2118
22- ls .add_snippets (" tex" , {
23- ls .parser .parse_snippet (
24- { trig = " pac" , name = " Package" },
25- " \\ usepackage[${1:options}]{${2:package}}$0"
26- ),
27-
28- -- ls.parser.parse_snippet({ trig = "nn", name = "Tikz node" }, {
29- -- "$0",
30- -- -- "\\node[$5] (${1/[^0-9a-zA-Z]//g}${2}) ${3:at (${4:0,0}) }{$${1}$};",
31- -- "\\node[$5] (${1}${2}) ${3:at (${4:0,0}) }{$${1}$};",
32- -- }),
19+ local augroup = vim .api .nvim_create_augroup (" luasnip-latex-snippets" , {})
20+ vim .api .nvim_create_autocmd (" FileType" , {
21+ pattern = " tex" ,
22+ group = augroup ,
23+ once = true ,
24+ callback = function ()
25+ local is_math = utils .with_opts (utils .is_math , opts .use_treesitter )
26+ local not_math = utils .with_opts (utils .not_math , opts .use_treesitter )
27+ M .setup_tex (is_math , not_math )
28+ end ,
3329 })
3430
35- local math_i = require (" luasnip-latex-snippets/math_i" )
36- for _ , snip in ipairs (math_i ) do
37- snip .condition = pipe ({ is_math })
38- snip .show_condition = is_math
39- snip .wordTrig = false
40- end
41-
42- ls .add_snippets (" tex" , math_i , { default_priority = 0 })
31+ vim .api .nvim_create_autocmd (" FileType" , {
32+ pattern = " markdown" ,
33+ group = augroup ,
34+ once = true ,
35+ callback = function ()
36+ M .setup_markdown ()
37+ end ,
38+ })
39+ end
4340
41+ local _autosnippets = function (is_math , not_math )
4442 local autosnippets = {}
4543
4644 for _ , snip in ipairs (require (" luasnip-latex-snippets/math_wRA_no_backslash" )) do
@@ -74,7 +72,7 @@ M.setup = function(opts)
7472
7573 for _ , snip in ipairs (require (" luasnip-latex-snippets/math_iA" )) do
7674 snip .wordTrig = false
77- snip .condition = pipe ({ is_math })
75+ snip .condition = pipe ({ is_math , no_backslash })
7876 table.insert (autosnippets , snip )
7977 end
8078
@@ -94,15 +92,43 @@ M.setup = function(opts)
9492 table.insert (autosnippets , snip )
9593 end
9694
97- ls .add_snippets (" tex" , autosnippets , {
95+ return autosnippets
96+ end
97+
98+ M .setup_tex = function (is_math , not_math )
99+ ls .add_snippets (" tex" , {
100+ ls .parser .parse_snippet (
101+ { trig = " pac" , name = " Package" },
102+ " \\ usepackage[${1:options}]{${2:package}}$0"
103+ ),
104+
105+ -- ls.parser.parse_snippet({ trig = "nn", name = "Tikz node" }, {
106+ -- "$0",
107+ -- -- "\\node[$5] (${1/[^0-9a-zA-Z]//g}${2}) ${3:at (${4:0,0}) }{$${1}$};",
108+ -- "\\node[$5] (${1}${2}) ${3:at (${4:0,0}) }{$${1}$};",
109+ -- }),
110+ })
111+
112+ local math_i = require (" luasnip-latex-snippets/math_i" )
113+ for _ , snip in ipairs (math_i ) do
114+ snip .condition = pipe ({ is_math })
115+ snip .show_condition = is_math
116+ snip .wordTrig = false
117+ end
118+
119+ ls .add_snippets (" tex" , math_i , { default_priority = 0 })
120+
121+ ls .add_snippets (" tex" , _autosnippets (is_math , not_math ), {
98122 type = " autosnippets" ,
99123 default_priority = 0 ,
100124 })
101-
102- M .setup_markdown (autosnippets )
103125end
104126
105- M .setup_markdown = function (autosnippets )
127+ M .setup_markdown = function ()
128+ local is_math = utils .with_opts (utils .is_math , true )
129+ local not_math = utils .with_opts (utils .not_math , true )
130+
131+ local autosnippets = _autosnippets (is_math , not_math )
106132 local trigger_of_snip = function (s )
107133 return s .trigger
108134 end
0 commit comments