mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 05:24:24 -05:00
feat(snip): expand into next line with correct indent (#13)
* New snippet type. Expand from nonempty line into next line. * Fix trigger to ' dm' instead of 'dm' * style: format code * minor: improve regex --------- Co-authored-by: arne314 <73391160+arne314@users.noreply.github.com>
This commit is contained in:
@@ -32,6 +32,16 @@ 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.leading_white_spaces(i)
|
||||||
|
-- isolate whitespaces of captured group
|
||||||
|
return luasnip.function_node(function(_, snip)
|
||||||
|
local capture = snip.captures[i] or '' -- Return capture or empty string if nil
|
||||||
|
-- Extract only leading whitespace using pattern matching
|
||||||
|
local whitespace = capture:match('^%s*') or ''
|
||||||
|
return whitespace
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
function M.visual(idx, default)
|
function M.visual(idx, default)
|
||||||
default = default or ''
|
default = default or ''
|
||||||
return luasnip.dynamic_node(idx, function(args, parent)
|
return luasnip.dynamic_node(idx, function(args, parent)
|
||||||
@@ -70,6 +80,17 @@ function M.start_snip(trigger, expand, insert, condition, priority)
|
|||||||
return M.snip('^(\\s*)' .. trigger, '<>' .. expand, { M.cap(1), unpack(insert) }, condition, priority)
|
return M.snip('^(\\s*)' .. trigger, '<>' .. expand, { M.cap(1), unpack(insert) }, condition, priority)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.start_snip_in_newl(trigger, expand, insert, condition, priority)
|
||||||
|
return M.snip(
|
||||||
|
'([^\\s]\\s+)' .. trigger,
|
||||||
|
'<>\n<>' .. expand,
|
||||||
|
{ M.cap(1), M.leading_white_spaces(1), unpack(insert) },
|
||||||
|
condition,
|
||||||
|
priority,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
local alts_regex = '[\\[\\(](.*|.*)[\\)\\]]'
|
local alts_regex = '[\\[\\(](.*|.*)[\\)\\]]'
|
||||||
|
|
||||||
function M.engine(trigger, opts)
|
function M.engine(trigger, opts)
|
||||||
|
|||||||
@@ -43,6 +43,12 @@ end
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
start('dm', '$\n<>\t<>\n<>$', { cap(1), visual(1), cap(1) }, markup),
|
start('dm', '$\n<>\t<>\n<>$', { cap(1), visual(1), cap(1) }, markup),
|
||||||
|
helper.start_snip_in_newl(
|
||||||
|
'dm',
|
||||||
|
'$\n<>\t<>\n<>$',
|
||||||
|
{ helper.leading_white_spaces(1), visual(1), helper.leading_white_spaces(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),
|
||||||
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('IMP', '$==>>$ ', {}, markup),
|
||||||
|
|||||||
Reference in New Issue
Block a user