Files
nvim/LuaSnip/typst/env.lua

114 lines
1.9 KiB
Lua
Raw Normal View History

2025-09-21 20:43:38 +10:00
local ls = require("luasnip")
local s = ls.snippet
local sn = ls.snippet_node
local t = ls.text_node
local i = ls.insert_node
local f = ls.function_node
local d = ls.dynamic_node
local fmta = require("luasnip.extras.fmt").fmta
local rep = require("luasnip.extras").rep
local line_begin = require("luasnip.extras.expand_conditions").line_begin
local tex = require("util.latex")
local get_visual = function(args, parent)
if #parent.snippet.env.SELECT_RAW > 0 then
return sn(nil, t(parent.snippet.env.SELECT_RAW))
else -- If SELECT_RAW is empty, return a blank insert node
return sn(nil, i(1))
end
end
return {
s(
{ trig = "mk", snippetType = "autosnippet" },
fmta(
[[
$<>$
]],
{
2025-10-17 20:03:30 +11:00
i(0),
2025-09-21 20:43:38 +10:00
}
),
{ condition = tex.in_text }
),
s(
{ trig = "dm", snippetType = "autosnippet" },
fmta(
[[
$
<>
$
]],
{
2025-10-17 20:03:30 +11:00
i(0),
2025-09-21 20:43:38 +10:00
}
),
{ condition = tex.in_text }
),
s(
2025-09-30 22:59:47 +10:00
{ trig = "#thm", snippetType = "autosnippet" },
2025-09-21 20:43:38 +10:00
fmta(
[[
2025-09-30 22:59:47 +10:00
#theorem(<>)[
2025-09-21 20:43:38 +10:00
<>
2025-09-30 22:59:47 +10:00
]
2025-09-21 20:43:38 +10:00
]],
{
i(1),
i(0),
}
),
{ condition = line_begin }
),
s(
2025-09-30 22:59:47 +10:00
{ trig = "#pf", snippetType = "autosnippet" },
2025-09-21 20:43:38 +10:00
fmta(
[[
2025-09-30 22:59:47 +10:00
#proof[
2025-09-21 20:43:38 +10:00
<>
2025-09-30 22:59:47 +10:00
]
2025-09-21 20:43:38 +10:00
]],
{
i(0),
}
),
2025-09-30 22:59:47 +10:00
{ condition = tex.in_text }
2025-09-21 20:43:38 +10:00
),
s(
2025-09-30 22:59:47 +10:00
{ trig = "#def", snippetType = "autosnippet" },
2025-09-21 20:43:38 +10:00
fmta(
[[
2025-09-30 22:59:47 +10:00
#definition(<>)[
2025-09-21 20:43:38 +10:00
<>
2025-09-30 22:59:47 +10:00
]
2025-09-21 20:43:38 +10:00
]],
{
i(1),
i(0),
}
),
{ condition = line_begin }
),
s(
2025-09-30 22:59:47 +10:00
{ trig = "#exa", snippetType = "autosnippet" },
2025-09-21 20:43:38 +10:00
fmta(
[[
2025-09-30 22:59:47 +10:00
#example[
2025-09-21 20:43:38 +10:00
<>
2025-09-30 22:59:47 +10:00
]
2025-09-21 20:43:38 +10:00
]],
{
i(0),
}
),
{ condition = line_begin }
2025-10-22 14:20:19 +11:00
),
s(
{ trig = "defop" },
fmta("#let <> = math.op(\"<>\")", {
i(1),
rep(1),
}),
{ condition = tex.in_mathzone }
),
2025-09-21 20:43:38 +10:00
}