nvim: migrated typst snippets to luasnip

this was the most absolutely painful experience ever
why did i do this
it was already working with ultisnips
it's literally 20x more convoluted with luasnip than ultisnips
for no benefit at all
https://xkcd.com/1205/
This commit is contained in:
dogeystamp 2024-04-03 19:21:48 -04:00
parent 32c4b99498
commit 4884f144d0
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
4 changed files with 103 additions and 3 deletions

View File

@ -140,7 +140,7 @@ local servers = {
},
diagnostics = {
-- get it to stop complaining about luasnip
globals = {'s', 'f', 't', "fmt", "c", "sn", "i", "rep", "d"},
globals = {'s', 'f', 't', "fmt", "c", "sn", "i", "rep", "d", "k"},
},
}
}

View File

@ -74,7 +74,6 @@ return {
{surr1}
{comm} {cont}
{surr2}
]], {
surr1 = f(rep_node, { 1 }),
comm = d(1, function()

View File

@ -1,5 +1,5 @@
return {
s({ trig = "snip", desc = "meta snippet (snippet for making snippets)" }, fmt([[
s({ trig = "snipf", desc = "meta snippet (snippet for making snippets)" }, fmt([[
s({{trig="{}", desc="{}"}}, {}),
]], { i(1, "trigger"), i(2, "human-readable description"), i(3, "<body nodes>") }))
}

View File

@ -0,0 +1,101 @@
return {
--------------------------------
--------------------------------
-- quick markup utilities
--------------------------------
--------------------------------
s({ trig = "ss", desc = "superscript", wordTrig = false }, fmt("^({}) ", { i(1) })),
s({ trig = "qu", desc = "square (qu-artic) exponent", wordTrig = false }, t("^2 ")),
s({ trig = "cub", desc = "cub-ed exponent", wordTrig = false }, t("^3 ")),
s({ trig = "link", desc = "labelled link" }, fmt('#link("{}{}")[{}]', {
i(1),
f(function(args, _)
-- use clipboard contents as a placeholder
if not args[1][1] or args[1][1] == "" then
return vim.fn.getreg("+")
else
return ""
end
end, { 1 }),
i(2),
})),
--------------------------------
--------------------------------
-- figures
-- (biggest waste of time ever)
-- (supposedly advanced snippet practice)
--------------------------------
--------------------------------
s({ trig = "fig(%a?)", regTrig = true, desc = "create a figure" }, fmt([[
#figure(
{content}
caption: [{caption}],
) <{label}>
]], {
caption = i(2, "Caption"),
label = i(1, "label"),
content = d(3, function(args, snip)
if not snip.captures[1] or snip.captures[1] == "" then
-- regular figure
return sn(nil,
fmt([[
image("{path}.{ext}"),
]], {
path = f(function()
return "fig/" .. vim.fn.expand("%:r") .. "/" .. (args[1][1] or nil)
end),
ext = c(1, { t("svg"), t("jpg") })
})
)
elseif snip.captures[1] == "t" then
return sn(nil,
fmt([[
tablef(
columns: {cols},
table.header{head},
{content}
),
]], {
head = i(1, "[Header][Header]"),
content = i(2, "[Content], [Content],"),
cols = f(function(largs)
-- the number of columns is the number of left brackets [ in the header
local _, cnt = string.gsub(largs[1][1], "%[", "")
-- the error for not converting to string was cryptic
-- wasted 10 minutes on this :(
return tostring(cnt)
end, { 1 })
})
)
end
end, { 1 }),
})),
--------------------------------
--------------------------------
-- document templates
--------------------------------
--------------------------------
s({ trig = "general", desc = "General document template" }, fmt([[
#import "/templates/general.typ": template, lref
#import "/templates/libs.typ": *
#show: template.with(
title: "{}",
prefix: "{}",
suffix: "{}",
)
]], { i(1), i(2), i(3) })),
s({ trig = "problem", desc = "Problem write-up template" }, fmt([[
#import "/templates/problems.typ": template, source_code, status, lref
#import "/templates/libs.typ": *
#show: template.with(
problem_url: "{}",
title: "{}",
stat: "{}",
)
]], { i(1), i(2), i(3, "incomplete") })),
}