mirror of
https://github.com/Ascyii/typstar.git
synced 2026-01-01 05:24:24 -05:00
perf: jsregexp instead of lua pattern matching
This commit is contained in:
@@ -32,7 +32,14 @@ end
|
||||
function M.snip(trigger, expand, insert, condition, priority)
|
||||
priority = priority or 1000
|
||||
return luasnip.snippet(
|
||||
{ trig = trigger, regTrig = true, wordtrig = false, priority = priority, snippetType = 'autosnippet' },
|
||||
{
|
||||
trig = trigger,
|
||||
trigEngine = 'ecma',
|
||||
regTrig = true,
|
||||
wordtrig = false,
|
||||
priority = priority,
|
||||
snippetType = 'autosnippet'
|
||||
},
|
||||
fmta(expand, { unpack(insert) }),
|
||||
{
|
||||
condition = function()
|
||||
@@ -46,7 +53,7 @@ function M.snip(trigger, expand, insert, condition, priority)
|
||||
end
|
||||
|
||||
function M.start_snip(trigger, expand, insert, condition, priority)
|
||||
return M.snip('^%s*' .. trigger, expand, insert, condition, priority)
|
||||
return M.snip('^\\s*' .. trigger, expand, insert, condition, priority)
|
||||
end
|
||||
|
||||
function M.toggle_autosnippets()
|
||||
|
||||
@@ -29,7 +29,7 @@ local greek_letters = {
|
||||
{ 'z', 'zeta' }, { 'Z', 'Zeta' },
|
||||
}
|
||||
local latin_letters = { 'f', 'u', 'v', 'w', 'y' } -- remaining ones are added dynamically
|
||||
local common_indices = { '%d+', 'i', 'j', 'k', 'n' }
|
||||
local common_indices = { '\\d+', 'i', 'j', 'k', 'n' }
|
||||
|
||||
for _, letter in ipairs({ unpack(latin_letters) }) do
|
||||
table.insert(latin_letters, letter:upper())
|
||||
@@ -40,7 +40,7 @@ local generate_index_snippets = function(letter)
|
||||
table.insert(letter_snippets,
|
||||
snip(letter .. '(' .. index .. ') ', letter .. '_(<>) ', { cap(1) }, math, 200))
|
||||
table.insert(letter_snippets,
|
||||
snip('$' .. letter .. '$(' .. index .. ') ', '$' .. letter .. '_(<>)$ ', { cap(1) }, markup, 200))
|
||||
snip('\\$' .. letter .. '\\$(' .. index .. ') ', '$' .. letter .. '_(<>)$ ', { cap(1) }, markup, 200))
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -75,8 +75,6 @@ return {
|
||||
|
||||
snip('lm', 'lim <>', { i(1, 'a_n') }, math),
|
||||
snip('lim', 'lim_(<> ->> <>) <>', { i(1, 'n'), i(2, 'oo'), i(3, 'a_n') }, math),
|
||||
snip('lim sup', 'limsup <>', { i(1, 'a_n') }, math),
|
||||
snip('lim(_.*%-.*) sup', 'limsup<> <>', { cap(1), i(1, 'a_n') }, math),
|
||||
snip('lim inf', 'liminf <>', { i(1, 'a_n') }, math),
|
||||
snip('lim(_.*%-.*) inf', 'liminf<> <>', { cap(1), i(1, 'a_n') }, math),
|
||||
snip('lim (sup|inf)', 'lim<> <>', { cap(1), i(1, 'a_n') }, math),
|
||||
snip('lim(_.*-.*) (sup|inf)', 'lim<><> <>', { cap(2), cap(1), i(1, 'a_n') }, math),
|
||||
}
|
||||
|
||||
@@ -78,6 +78,6 @@ local lmat = function(_, sp)
|
||||
end
|
||||
|
||||
return {
|
||||
snip('(%d)(%d)ma', 'mat(\n\t<>\n)', { d(1, mat) }, math),
|
||||
snip('(%d)(%d)lma', 'mat(\n\t<>\n)', { d(1, lmat) }, math),
|
||||
snip('(\\d)(\\d)ma', 'mat(\n\t<>\n)', { d(1, mat) }, math),
|
||||
snip('(\\d)(\\d)lma', 'mat(\n\t<>\n)', { d(1, lmat) }, math),
|
||||
}
|
||||
|
||||
@@ -61,12 +61,12 @@ end
|
||||
|
||||
for _, val in pairs(operations) do
|
||||
table.insert(snippets, snip(val[1], val[2] .. '<>' .. val[3], { d(1, get_visual) }, math))
|
||||
table.insert(snippets, snip('[%s$]' .. val[1], val[2] .. '<>' .. val[3], { i(1, '1') }, math))
|
||||
table.insert(snippets, snip('[\\s$]' .. val[1], val[2] .. '<>' .. val[3], { i(1, '1') }, math))
|
||||
table.insert(snippets,
|
||||
snip('([%w]+)'
|
||||
snip('([\\w]+)'
|
||||
.. val[1], val[2] .. '<>' .. val[3], { cap(1) }, math, 900))
|
||||
table.insert(snippets,
|
||||
snip('(.*[%)|%]|%}])' .. val[1], '<>', { f(wrap_brackets, {}, { user_args = { val } }), nil }, math, 1100))
|
||||
snip('(.*[\\)|\\]|\\}])' .. val[1], '<>', { f(wrap_brackets, {}, { user_args = { val } }), nil }, math, 1100))
|
||||
end
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user