refactor(snip)!: trigger options parameter

This commit is contained in:
arne314
2025-04-29 23:58:45 +02:00
parent b47e98e478
commit 7ffa4efe3c
4 changed files with 30 additions and 19 deletions

View File

@@ -68,14 +68,17 @@ function M.ri(insert_node_id)
return luasnip.function_node(function(args) return args[1][1] end, insert_node_id)
end
function M.snip(trigger, expand, insert, condition, priority, wordTrig, maxTrigLength)
function M.snip(trigger, expand, insert, condition, priority, trigOptions)
priority = priority or 1000
if wordTrig == nil then wordTrig = true end
trigOptions = vim.tbl_deep_extend('force', {
maxTrigLength = nil,
wordTrig = true,
}, trigOptions or {})
return luasnip.snippet(
{
trig = trigger,
trigEngine = M.engine,
trigEngineOpts = { condition = condition, wordTrig = wordTrig, maxTrigLength = maxTrigLength },
trigEngineOpts = vim.tbl_deep_extend('keep', { condition = condition }, trigOptions),
wordTrig = false,
priority = priority,
snippetType = 'autosnippet',

View File

@@ -116,8 +116,7 @@ return {
{ d(1, get_index, {}, { user_args = { 1, 2, false } }), d(2, prepend_space, {}, { user_args = { 3 } }) },
markup,
500,
true,
13
{ maxTrigLength = 13 }
),
snip(
'(' .. trigger_index_pre .. ')' .. '(' .. trigger_index_post .. ')([^\\w])',
@@ -125,14 +124,13 @@ return {
{ d(1, get_index, {}, { user_args = { 1, 2, true } }), d(2, prepend_space, {}, { user_args = { 3 } }) },
math,
200,
true,
10 -- epsilon123
{ maxTrigLength = 10 } -- epsilon123
),
-- series of numbered letters
snip('(' .. trigger_index_pre .. ') ot ', '<>_1, <>_2, ... ', { cap(1), cap(1) }, math), -- a_1, a_2, ...
snip('(' .. trigger_index_pre .. ') ot(\\w+) ', '<> ', { d(1, get_series) }, math, 1000, true, 13), -- a_1, a_2, ... a_j or a_1, a_2, a_2, a_3, a_4, a_5
snip('(' .. trigger_index_pre .. ') ot(\\w+) ', '<> ', { d(1, get_series) }, math, 1000, { maxTrigLength = 13 }), -- a_1, a_2, ... a_j or a_1, a_2, a_2, a_3, a_4, a_5
-- misc
snip('(' .. trigger_index_pre .. ')bl', 'B_<> (<>) ', { cap(1), i(1, 'x_0') }, math, 100, true),
snip('(' .. trigger_index_pre .. ')bl', 'B_<> (<>) ', { cap(1), i(1, 'x_0') }, math, 100),
}

View File

@@ -34,8 +34,8 @@ return {
snip('ge', '>>= ', {}, math),
-- operators
snip('ak([^k ])', '+ <>', { cap(1) }, math, 100, false),
snip('sk([^k ])', '- <>', { cap(1) }, math, 100, false),
snip('ak([^k ])', '+ <>', { cap(1) }, math, 100, { wordTrig = false }),
snip('sk([^k ])', '- <>', { cap(1) }, math, 100, { wordTrig = false }),
snip('oak', 'plus.circle ', {}, math),
snip('bak', 'plus.square ', {}, math),
snip('mak', 'plus.minus ', {}, math),
@@ -45,11 +45,11 @@ return {
snip('ff', '(<>) / (<>) <>', { i(1, 'a'), i(2, 'b'), i(3) }, math),
-- exponents
snip('iv', '^(-1) ', {}, math, 500, false),
snip('sr', '^2 ', {}, math, 500, false),
snip('cb', '^3 ', {}, math, 500, false),
snip('jj', '_(<>) ', { i(1, 'n') }, math, 500, false),
snip('kk', '^(<>) ', { i(1, 'n') }, math, 500, false),
snip('iv', '^(-1) ', {}, math, 500, { wordTrig = false }),
snip('sr', '^2 ', {}, math, 500, { wordTrig = false }),
snip('cb', '^3 ', {}, math, 500, { wordTrig = false }),
snip('jj', '_(<>) ', { i(1, 'n') }, math, 500, { wordTrig = false }),
snip('kk', '^(<>) ', { i(1, 'n') }, math, 500, { wordTrig = false }),
snip('ep', 'exp(<>) ', { i(1, '1') }, math),
-- sets
@@ -73,7 +73,7 @@ return {
snip('Oo', 'compose ', {}, math),
snip('iso', 'tilde.equiv ', {}, math),
snip('cc', 'cases(\n\t<>\n)\\', { i(1, '1') }, math),
snip('([A-Za-z])o([A-Za-z0-9])', '<>(<>) ', { cap(1), cap(2) }, math, 100, true, 3),
snip('([A-Za-z])o([A-Za-z0-9])', '<>(<>) ', { cap(1), cap(2) }, math, 100, { wordTrig = true, maxTrigLength = 3 }),
snip('(K|M|N|Q|R|S|Z)([\\dn]) ', '<><>^<> ', { cap(1), cap(1), cap(2) }, math),
snip('dx', 'dif / (dif <>) ', { i(1, 'x') }, math, 900),
@@ -91,5 +91,12 @@ return {
snip('lm', 'lim ', {}, math),
snip('lim', 'lim_(<> ->> <>) ', { i(1, 'n'), i(2, 'oo') }, math),
snip('lim (sup|inf)', 'lim<> ', { cap(1) }, math),
snip('lim(_\\(\\s?\\w+\\s?->\\s?\\w+\\s?\\)) (sup|inf)', 'lim<><> ', { cap(2), cap(1) }, math, 1000, true, 25),
snip(
'lim(_\\(\\s?\\w+\\s?->\\s?\\w+\\s?\\)) (sup|inf)',
'lim<><> ',
{ cap(2), cap(1) },
math,
1000,
{ maxTrigLength = 25 }
),
}

View File

@@ -82,7 +82,10 @@ local smart_wrap = function(args, parent, old_state, expand)
end
for _, val in pairs(operations) do
table.insert(snippets, snip(val[1], '<>', { d(1, smart_wrap, {}, { user_args = { val } }) }, math, 1500, false))
table.insert(
snippets,
snip(val[1], '<>', { d(1, smart_wrap, {}, { user_args = { val } }) }, math, 1500, { wordTrig = false })
)
end
return {