mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 05:24:24 -05:00
refactor(snip): syntax of line prepended snippets
This commit is contained in:
@@ -68,18 +68,22 @@ function M.ri(insert_node_id)
|
|||||||
return luasnip.function_node(function(args) return args[1][1] end, insert_node_id)
|
return luasnip.function_node(function(args) return args[1][1] end, insert_node_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.snip(trigger, expand, insert, condition, priority, trigOptions)
|
function M.snip(trigger, expand, insert, condition, priority, options)
|
||||||
priority = priority or 1000
|
priority = priority or 1000
|
||||||
trigOptions = vim.tbl_deep_extend('force', {
|
options = vim.tbl_deep_extend('force', {
|
||||||
maxTrigLength = nil,
|
maxTrigLength = nil,
|
||||||
wordTrig = true,
|
wordTrig = true,
|
||||||
blacklist = {},
|
blacklist = {},
|
||||||
}, trigOptions or {})
|
prepend = nil,
|
||||||
|
}, options or {})
|
||||||
|
if options.prepend ~= nil then
|
||||||
|
expand, insert = M.blocktransform(expand, insert, options.prepend, true)
|
||||||
|
end
|
||||||
return luasnip.snippet(
|
return luasnip.snippet(
|
||||||
{
|
{
|
||||||
trig = trigger,
|
trig = trigger,
|
||||||
trigEngine = M.engine,
|
trigEngine = M.engine,
|
||||||
trigEngineOpts = vim.tbl_deep_extend('keep', { condition = condition }, trigOptions),
|
trigEngineOpts = vim.tbl_deep_extend('keep', { condition = condition }, options),
|
||||||
wordTrig = false,
|
wordTrig = false,
|
||||||
priority = priority,
|
priority = priority,
|
||||||
snippetType = 'autosnippet',
|
snippetType = 'autosnippet',
|
||||||
@@ -91,8 +95,8 @@ function M.snip(trigger, expand, insert, condition, priority, trigOptions)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.start_snip(trigger, expand, insert, condition, priority, trigOptions)
|
function M.start_snip(trigger, expand, insert, condition, priority, options)
|
||||||
return M.snip('^(\\s*)' .. trigger, '<>' .. expand, { M.cap(1), unpack(insert) }, condition, priority, trigOptions)
|
return M.snip('^(\\s*)' .. trigger, '<>' .. expand, { M.cap(1), unpack(insert) }, condition, priority, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Allows to pass expand string and insert table to either indent each line
|
-- Allows to pass expand string and insert table to either indent each line
|
||||||
@@ -151,41 +155,25 @@ function M.blocktransform(expand, insert, prepend, indent)
|
|||||||
return modified_expand, modified_insert
|
return modified_expand, modified_insert
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.snip_after_transform(trigger, expand, insert, condition, priority, prependlines, trigOptions)
|
function M.start_snip_in_newl(trigger, expand, insert, condition, priority, options)
|
||||||
local expand, insert = M.blocktransform(expand, insert, prependlines, true)
|
|
||||||
return M.snip(
|
return M.snip(
|
||||||
trigger,
|
|
||||||
expand,
|
|
||||||
insert,
|
|
||||||
condition,
|
|
||||||
priority,
|
|
||||||
vim.tbl_deep_extend('keep', { wordTrig = false }, trigOptions or {})
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.start_snip_in_newl(trigger, expand, insert, condition, priority, prepend, prependlines, trigOptions)
|
|
||||||
prepend = prepend or ''
|
|
||||||
return M.snip_after_transform(
|
|
||||||
'([^\\s]\\s+)' .. trigger,
|
'([^\\s]\\s+)' .. trigger,
|
||||||
'<><>\n' .. expand,
|
'<>\n' .. expand,
|
||||||
{ M.cap(1), prepend, unpack(insert) },
|
{ M.cap(1), unpack(insert) },
|
||||||
condition,
|
condition,
|
||||||
priority,
|
priority,
|
||||||
prependlines,
|
options
|
||||||
trigOptions
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.bulletpoint_snip(trigger, expand, insert, condition, priority, prepend, prependlines, trigOptions)
|
function M.bulletpoint_snip(trigger, expand, insert, condition, priority, options)
|
||||||
prepend = prepend or ''
|
return M.snip(
|
||||||
return M.snip_after_transform(
|
|
||||||
'(^\\s*\\-\\s+.*\\s*)' .. trigger,
|
'(^\\s*\\-\\s+.*\\s*)' .. trigger,
|
||||||
'<><>' .. expand,
|
'<>' .. expand,
|
||||||
{ M.cap(1), prepend, unpack(insert) },
|
{ M.cap(1), unpack(insert) },
|
||||||
condition,
|
condition,
|
||||||
priority,
|
priority,
|
||||||
prependlines,
|
options
|
||||||
trigOptions
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
start('dm', '$\n<>\n<>$', { indent_visual(1), cap(1) }, markup),
|
start('dm', '$\n<>\n<>$', { indent_visual(1), cap(1) }, markup),
|
||||||
helper.start_snip_in_newl('dm', '$\n\t<>\n$ <>', { helper.visual(1), i(2) }, markup, 999),
|
helper.start_snip_in_newl('dm', '$\n\t<>\n$ <>', { helper.visual(1), i(2) }, markup, nil, { wordTrig = false }),
|
||||||
helper.bulletpoint_snip('dm', '\n$\n\t<>\n$ <>', { helper.visual(1), i(2) }, markup, 1001, '', '\t'),
|
helper.bulletpoint_snip('dm', '\n$\n\t<>\n$ <>', { helper.visual(1), i(2) }, markup, 1100, { prepend = '\t' }),
|
||||||
start('fla', '#flashcard(0)[<>][\n<>\n<>]', { i(1, 'flashcard'), indent_visual(2), cap(1) }, markup),
|
start('fla', '#flashcard(0)[<>][\n<>\n<>]', { i(1, 'flashcard'), indent_visual(2), cap(1) }, markup),
|
||||||
start('flA', '#flashcard(0, "<>")[\n<>\n<>]', { i(1, 'flashcard'), indent_visual(2), cap(1) }, markup),
|
start('flA', '#flashcard(0, "<>")[\n<>\n<>]', { i(1, 'flashcard'), indent_visual(2), cap(1) }, markup),
|
||||||
snip('IMP', '$==>>$ ', {}, markup),
|
snip('IMP', '$==>>$ ', {}, markup),
|
||||||
|
|||||||
Reference in New Issue
Block a user