mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 13:34: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)
|
||||
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)
|
||||
default = default or ''
|
||||
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)
|
||||
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 = '[\\[\\(](.*|.*)[\\)\\]]'
|
||||
|
||||
function M.engine(trigger, opts)
|
||||
|
||||
Reference in New Issue
Block a user