Skip to content

Commit 1d9d9fe

Browse files
committed
feat: add most snippets
1 parent 3756b78 commit 1d9d9fe

File tree

9 files changed

+810
-39
lines changed

9 files changed

+810
-39
lines changed
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
-- [
2+
-- snip_env + autosnippets
3+
-- ]
4+
local ls = require("luasnip")
5+
local s = ls.snippet
6+
local sn = ls.snippet_node
7+
local isn = ls.indent_snippet_node
8+
local t = ls.text_node
9+
local i = ls.insert_node
10+
local f = ls.function_node
11+
local c = ls.choice_node
12+
local d = ls.dynamic_node
13+
local r = ls.restore_node
14+
local events = require("luasnip.util.events")
15+
local ai = require("luasnip.nodes.absolute_indexer")
16+
local extras = require("luasnip.extras")
17+
local l = extras.lambda
18+
local rep = extras.rep
19+
local p = extras.partial
20+
local m = extras.match
21+
local n = extras.nonempty
22+
local dl = extras.dynamic_lambda
23+
local fmt = require("luasnip.extras.fmt").fmt
24+
local fmta = require("luasnip.extras.fmt").fmta
25+
local conds = require("luasnip.extras.expand_conditions")
26+
local postfix = require("luasnip.extras.postfix").postfix
27+
local types = require("luasnip.util.types")
28+
local parse = require("luasnip.util.parser").parse_snippet
29+
local ms = ls.multi_snippet
30+
local autosnippet = ls.extend_decorator.apply(s, { snippetType = "autosnippet" })
31+
32+
--[
33+
-- personal imports
34+
--]
35+
local tex = require("luasnip-latex-snippets.luasnippets.tex.utils.conditions")
36+
local single_command_snippet = require("luasnip-latex-snippets.luasnippets.tex.utils.scaffolding").single_command_snippet
37+
local reference_snippet_table = {
38+
a = "auto",
39+
c = "c",
40+
C = "C",
41+
e = "eq",
42+
r = ""
43+
}
44+
45+
M = {
46+
autosnippet({ trig='alab', name='label', dscr='add a label'},
47+
fmta([[
48+
\label{<>:<>}
49+
]],
50+
{ i(1), i(0) })),
51+
autosnippet({ trig='([acCer])ref', name='(acC|eq)?ref', dscr='add a reference (with autoref, cref, eqref)', regTrig = true, hidden = true},
52+
fmta([[
53+
\<>ref{<>:<>}
54+
]],
55+
{ f(function (_, snip)
56+
return reference_snippet_table[snip.captures[1]]
57+
end),
58+
i(1), i(0) }),
59+
{ condition = tex.in_text, show_condition = tex.in_text }),
60+
}
61+
62+
local single_command_specs = {
63+
sec = {
64+
context = {
65+
name = "section",
66+
dscr = "section",
67+
priority = 250,
68+
},
69+
command = [[\section]],
70+
ext = { label = true, short = "sec" },
71+
},
72+
ssec = {
73+
context = {
74+
name = "subsection",
75+
dscr = "subsection",
76+
priority = 500
77+
},
78+
command = [[\subsection]],
79+
ext = { label = true, short = "subsec" },
80+
},
81+
sssec = {
82+
context = {
83+
name = "subsubsection",
84+
dscr = "subsubsection",
85+
},
86+
command = [[\subsubsection]],
87+
ext = { label = true, short = "sssec" },
88+
},
89+
["sec*"] = {
90+
context = {
91+
name = "section*",
92+
dscr = "section*",
93+
priority = 250,
94+
},
95+
command = [[\section*]],
96+
ext = { label = true, short = "sec" },
97+
},
98+
["ssec*"] = {
99+
context = {
100+
name = "subsection*",
101+
dscr = "subsection*",
102+
priority = 500
103+
},
104+
command = [[\subsection*]],
105+
ext = { label = true, short = "subsec" },
106+
},
107+
["sssec*"] = {
108+
context = {
109+
name = "subsubsection*",
110+
dscr = "subsubsection*",
111+
},
112+
command = [[\subsubsection*]],
113+
ext = { label = true, short = "sssec" },
114+
},
115+
116+
sq = { -- requires csquotes!
117+
context = {
118+
name = "enquote*",
119+
dscr = "single quotes",
120+
},
121+
command = [[\enquote*]],
122+
},
123+
qq = {
124+
context = {
125+
name = "enquote",
126+
dscr = "double quotes",
127+
},
128+
command = [[\enquote]],
129+
},
130+
bf = {
131+
context = {
132+
name = "textbf",
133+
dscr = "bold text",
134+
hidden = true,
135+
},
136+
command = [[\textbf]],
137+
},
138+
it = {
139+
context = {
140+
name = "textit",
141+
dscr = "italic text",
142+
hidden = true,
143+
},
144+
command = [[\textit]],
145+
},
146+
sc = {
147+
context = {
148+
name = "textsc",
149+
dscr = "small caps",
150+
hidden = true,
151+
},
152+
command = [[\textsc]],
153+
},
154+
tu = {
155+
context = {
156+
name = "underline (text)",
157+
dscr = "underlined text in non-math mode",
158+
hidden = true,
159+
},
160+
command = [[\underline]],
161+
},
162+
tov = {
163+
context = {
164+
name = "overline (text)",
165+
dscr = "overline text in non-math mode",
166+
hidden = true,
167+
},
168+
command = [[\overline]],
169+
},
170+
}
171+
172+
local single_command_snippets = {}
173+
for k, v in pairs(single_command_specs) do
174+
table.insert(
175+
single_command_snippets,
176+
single_command_snippet(
177+
vim.tbl_deep_extend("keep", { trig = k }, v.context),
178+
v.command,
179+
v.opt or { condition = tex.in_text },
180+
v.ext or {}
181+
)
182+
)
183+
end
184+
vim.list_extend(M, single_command_snippets)
185+
186+
return M
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
-- [
2+
-- snip_env + autosnippets
3+
-- ]
4+
local ls = require("luasnip")
5+
local s = ls.snippet
6+
local sn = ls.snippet_node
7+
local isn = ls.indent_snippet_node
8+
local t = ls.text_node
9+
local i = ls.insert_node
10+
local f = ls.function_node
11+
local c = ls.choice_node
12+
local d = ls.dynamic_node
13+
local r = ls.restore_node
14+
local events = require("luasnip.util.events")
15+
local ai = require("luasnip.nodes.absolute_indexer")
16+
local extras = require("luasnip.extras")
17+
local l = extras.lambda
18+
local rep = extras.rep
19+
local p = extras.partial
20+
local m = extras.match
21+
local n = extras.nonempty
22+
local dl = extras.dynamic_lambda
23+
local fmt = require("luasnip.extras.fmt").fmt
24+
local fmta = require("luasnip.extras.fmt").fmta
25+
local conds = require("luasnip.extras.expand_conditions")
26+
local postfix = require("luasnip.extras.postfix").postfix
27+
local types = require("luasnip.util.types")
28+
local parse = require("luasnip.util.parser").parse_snippet
29+
local ms = ls.multi_snippet
30+
local autosnippet = ls.extend_decorator.apply(s, { snippetType = "autosnippet" })
31+
32+
--[
33+
-- personal imports
34+
--]
35+
local tex = require("luasnip-latex-snippets.luasnippets.tex.utils.conditions")
36+
local scaffolding = require("luasnip-latex-snippets.luasnippets.tex.utils.scaffolding")
37+
38+
-- brackets
39+
local brackets = {
40+
a = { "\\langle", "\\rangle" },
41+
A = { "Angle", "Angle" },
42+
b = { "brack", "brack" },
43+
B = { "Brack", "Brack" },
44+
c = { "brace", "brace" },
45+
m = { "|", "|" },
46+
p = { "(", ")" },
47+
}
48+
49+
M = {
50+
autosnippet(
51+
{ trig = "lr([aAbBcmp])", name = "left right", dscr = "left right delimiters", regTrig = true, hidden = true },
52+
fmta(
53+
[[
54+
\left<> <> \right<><>
55+
]],
56+
{f(function(_, snip)
57+
cap = snip.captures[1]
58+
if brackets[cap] == nil then
59+
cap = "p"
60+
end -- set default to parentheses
61+
return brackets[cap][1]
62+
end),
63+
d(1, scaffolding.get_visual),
64+
f(function(_, snip)
65+
cap = snip.captures[1]
66+
if brackets[cap] == nil then
67+
cap = "p"
68+
end
69+
return brackets[cap][2]
70+
end),
71+
i(0)}),
72+
{ condition = tex.in_math, show_condition = tex.in_math }),
73+
}
74+
75+
return M
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
-- [
2+
-- snip_env + autosnippets
3+
-- ]
4+
local ls = require("luasnip")
5+
local s = ls.snippet
6+
local sn = ls.snippet_node
7+
local isn = ls.indent_snippet_node
8+
local t = ls.text_node
9+
local i = ls.insert_node
10+
local f = ls.function_node
11+
local c = ls.choice_node
12+
local d = ls.dynamic_node
13+
local r = ls.restore_node
14+
local events = require("luasnip.util.events")
15+
local ai = require("luasnip.nodes.absolute_indexer")
16+
local extras = require("luasnip.extras")
17+
local l = extras.lambda
18+
local rep = extras.rep
19+
local p = extras.partial
20+
local m = extras.match
21+
local n = extras.nonempty
22+
local dl = extras.dynamic_lambda
23+
local fmt = require("luasnip.extras.fmt").fmt
24+
local fmta = require("luasnip.extras.fmt").fmta
25+
local conds = require("luasnip.extras.expand_conditions")
26+
local postfix = require("luasnip.extras.postfix").postfix
27+
local types = require("luasnip.util.types")
28+
local parse = require("luasnip.util.parser").parse_snippet
29+
local ms = ls.multi_snippet
30+
local autosnippet = ls.extend_decorator.apply(s, { snippetType = "autosnippet" })
31+
32+
--[
33+
-- personal imports
34+
--]
35+
local tex = require("luasnip-latex-snippets.luasnippets.tex.utils.conditions")
36+
37+
M = {
38+
s({ trig='beg', name='begin/end', dscr='begin/end environment (generic)'},
39+
fmta([[
40+
\begin{<>}
41+
<>
42+
\end{<>}
43+
]],
44+
{ i(1), i(0), rep(1) }
45+
), { condition = tex.in_text, show_condition = tex.in_text }),
46+
47+
s({ trig = "-i", name = "itemize", dscr = "bullet points (itemize)" },
48+
fmta([[
49+
\begin{itemize}
50+
\item <>
51+
\end{itemize}
52+
]],
53+
{ c(1, { i(0), sn(nil, fmta(
54+
[[
55+
[<>] <>
56+
]],
57+
{ i(1), i(0) })) })
58+
}
59+
),
60+
{ condition = tex.in_text, show_condition = tex.in_text }),
61+
62+
-- requires enumitem
63+
s({ trig = "-e", name = "enumerate", dscr = "numbered list (enumerate)" },
64+
fmta([[
65+
\begin{enumerate}<>
66+
\item <>
67+
\end{enumerate}
68+
]],
69+
{c(1, { t(""), sn(nil, fmta(
70+
[[
71+
[label=<>]
72+
]],
73+
{ c(1, { t("(\\alph*)"), t("(\\roman*)"), i(1) }) })) }),
74+
c(2, { i(0), sn(nil, fmta(
75+
[[
76+
[<>] <>
77+
]],
78+
{ i(1), i(0) })) })
79+
}
80+
),
81+
{ condition = tex.in_text, show_condition = tex.in_text }),
82+
}
83+
84+
return M

0 commit comments

Comments
 (0)