mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 05:24:24 -05:00
feat(snip): markup wrapping snippets
This commit is contained in:
@@ -31,12 +31,18 @@ function M.cap(i)
|
|||||||
return luasnip.function_node(function(_, snip) return snip.captures[i] end)
|
return luasnip.function_node(function(_, snip) return snip.captures[i] end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.get_visual(args, parent)
|
function M.visual(idx, default)
|
||||||
|
default = default or ''
|
||||||
|
return luasnip.dynamic_node(
|
||||||
|
idx,
|
||||||
|
function(args, parent)
|
||||||
if (#parent.snippet.env.LS_SELECT_RAW > 0) then
|
if (#parent.snippet.env.LS_SELECT_RAW > 0) then
|
||||||
return luasnip.snippet_node(nil, luasnip.insert_node(1, parent.snippet.env.LS_SELECT_RAW))
|
return luasnip.snippet_node(nil, luasnip.text_node(parent.snippet.env.LS_SELECT_RAW))
|
||||||
else -- If LS_SELECT_RAW is empty, return a blank insert node
|
else -- If LS_SELECT_RAW is empty, return an insert node
|
||||||
return luasnip.snippet_node(nil, luasnip.insert_node(1))
|
return luasnip.snippet_node(nil, luasnip.insert_node(1, default))
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.ri(insert_node_id)
|
function M.ri(insert_node_id)
|
||||||
@@ -62,7 +68,7 @@ function M.snip(trigger, expand, insert, condition, priority, wordTrig)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function M.start_snip(trigger, expand, insert, condition, priority)
|
function M.start_snip(trigger, expand, insert, condition, priority)
|
||||||
return M.snip('^\\s*' .. trigger, expand, insert, condition, priority)
|
return M.snip('^(\\s*)' .. trigger, '<>' .. expand, { M.cap(1), unpack(insert) }, condition, priority)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.engine(trigger, opts)
|
function M.engine(trigger, opts)
|
||||||
|
|||||||
@@ -19,10 +19,10 @@ local default_config = {
|
|||||||
snippets = {
|
snippets = {
|
||||||
enable = true,
|
enable = true,
|
||||||
modules = { -- enable modules from ./snippets
|
modules = { -- enable modules from ./snippets
|
||||||
'document',
|
|
||||||
'letters',
|
'letters',
|
||||||
'math',
|
'math',
|
||||||
'matrix',
|
'matrix',
|
||||||
|
'markup',
|
||||||
'visual',
|
'visual',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
local ls = require('luasnip')
|
|
||||||
local i = ls.insert_node
|
|
||||||
local d = ls.dynamic_node
|
|
||||||
|
|
||||||
local helper = require('typstar.autosnippets')
|
|
||||||
local snip = helper.snip
|
|
||||||
local start = helper.start_snip
|
|
||||||
local markup = helper.in_markup
|
|
||||||
|
|
||||||
|
|
||||||
local ctheorems = {
|
|
||||||
{ 'tem', 'theorem', markup },
|
|
||||||
{ 'pro', 'proof', markup },
|
|
||||||
{ 'axi', 'axiom', markup },
|
|
||||||
{ 'cor', 'corollary', markup },
|
|
||||||
{ 'lem', 'lemma', markup },
|
|
||||||
{ 'def', 'definition', markup },
|
|
||||||
{ 'exa', 'example', markup },
|
|
||||||
{ 'rem', 'remark', markup },
|
|
||||||
}
|
|
||||||
|
|
||||||
local ctheoremsstr = '#%s[\n\t<>\n]'
|
|
||||||
local document_snippets = {}
|
|
||||||
|
|
||||||
for _, val in pairs(ctheorems) do
|
|
||||||
local snippet = start(val[1], string.format(ctheoremsstr, val[2]), { i(1) }, val[3])
|
|
||||||
table.insert(document_snippets, snippet)
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
|
||||||
start('dm', '$\n\t<>\n$', { i(1) }, markup),
|
|
||||||
snip('ll', ' $<>$', { i(1, '1+1') }, markup),
|
|
||||||
start('fla', '#flashcard(0)[<>][\n\t<>\n]', { i(1, "flashcard"), i(2) }, markup),
|
|
||||||
start('flA', '#flashcard(0, "<>")[\n\t<>\n]', { i(1, "flashcard"), i(2) }, markup),
|
|
||||||
unpack(document_snippets),
|
|
||||||
}
|
|
||||||
52
lua/typstar/snippets/markup.lua
Normal file
52
lua/typstar/snippets/markup.lua
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
local ls = require('luasnip')
|
||||||
|
local i = ls.insert_node
|
||||||
|
|
||||||
|
local helper = require('typstar.autosnippets')
|
||||||
|
local cap = helper.cap
|
||||||
|
local markup = helper.in_markup
|
||||||
|
local visual = helper.visual
|
||||||
|
local snip = helper.snip
|
||||||
|
local start = helper.start_snip
|
||||||
|
|
||||||
|
|
||||||
|
local ctheorems = {
|
||||||
|
{ 'tem', 'theorem' },
|
||||||
|
{ 'pro', 'proof' },
|
||||||
|
{ 'axi', 'axiom' },
|
||||||
|
{ 'cor', 'corollary' },
|
||||||
|
{ 'lem', 'lemma' },
|
||||||
|
{ 'def', 'definition' },
|
||||||
|
{ 'exa', 'example' },
|
||||||
|
{ 'rem', 'remark' },
|
||||||
|
}
|
||||||
|
|
||||||
|
local wrappings = {
|
||||||
|
{ 'll', '$', '$', '1+1' },
|
||||||
|
{ 'BLD', '*', '*', 'abc' },
|
||||||
|
{ 'ITL', '_', '_', 'abc' },
|
||||||
|
{ 'HIG', '#highlight[', ']', 'abc' },
|
||||||
|
{ 'UND', '#underline[', ']', 'abc' },
|
||||||
|
}
|
||||||
|
|
||||||
|
local document_snippets = {}
|
||||||
|
local ctheoremsstr = '#%s[\n<>\t<>\n<>]'
|
||||||
|
local wrappingsstr = '%s<>%s'
|
||||||
|
|
||||||
|
for _, val in pairs(ctheorems) do
|
||||||
|
local snippet = start(val[1], string.format(ctheoremsstr, val[2]), { cap(1), visual(1), cap(1) }, markup)
|
||||||
|
table.insert(document_snippets, snippet)
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, val in pairs(wrappings) do
|
||||||
|
local snippet = snip(val[1], string.format(wrappingsstr, val[2], val[3]), { visual(1, val[4]) }, markup)
|
||||||
|
table.insert(document_snippets, snippet)
|
||||||
|
end
|
||||||
|
|
||||||
|
return {
|
||||||
|
start('dm', '$\n<>\t<>\n<>$', { cap(1), visual(1), cap(1) }, markup),
|
||||||
|
start('fla', '#flashcard(0)[<>][\n<>\t<>\n<>]', { i(1, "flashcard"), cap(1), visual(2), cap(1) }, markup),
|
||||||
|
start('flA', '#flashcard(0, "<>")[\n<>\t<>\n<>]', { i(1, "flashcard"), cap(1), visual(2), cap(1) }, markup),
|
||||||
|
snip('IMP', '$=>>$ ', {}, markup),
|
||||||
|
snip('IFF', '$<<=>>$ ', {}, markup),
|
||||||
|
unpack(document_snippets),
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user