style: format lua using stylua

This commit is contained in:
arne314
2025-01-09 01:48:18 +01:00
parent 434dc5c6c4
commit e9824803b5
10 changed files with 114 additions and 143 deletions

View File

@@ -8,7 +8,6 @@ local cap = helper.cap
local math = helper.in_math
local markup = helper.in_markup
local letter_snippets = {}
local greek_letters_map = {
['a'] = 'alpha',
@@ -42,9 +41,7 @@ local trigger_greek = ''
local trigger_index_pre = ''
local trigger_index_post = ''
local upper_first = function(str)
return str:sub(1, 1):upper() .. str:sub(2, -1)
end
local upper_first = function(str) return str:sub(1, 1):upper() .. str:sub(2, -1) end
local greek_full = {}
for latin, greek in pairs(greek_letters_map) do
@@ -65,28 +62,33 @@ trigger_greek = table.concat(greek_keys, '|')
trigger_index_pre = '[A-Za-z]' .. '|' .. table.concat(greek_letters, '|')
trigger_index_post = table.concat(common_indices, '|')
local get_greek = function(_, snippet)
return s(nil, t(greek_letters_map[snippet.captures[1]]))
end
local get_greek = function(_, snippet) return s(nil, t(greek_letters_map[snippet.captures[1]])) end
local get_index = function(_, snippet)
local letter, index = snippet.captures[1], snippet.captures[2]
local trigger = letter .. index
if index_conflicts_set[trigger] then
return s(nil, t(trigger))
end
if index_conflicts_set[trigger] then return s(nil, t(trigger)) end
return s(nil, t(letter .. '_' .. index))
end
table.insert(letter_snippets, snip(':([A-Za-z0-9])', '$<>$ ', { cap(1) }, markup))
table.insert(letter_snippets, snip(';(' .. trigger_greek .. ')', '$<>$ ', { d(1, get_greek) }, markup))
table.insert(letter_snippets, snip(';(' .. trigger_greek .. ')', '<>', { d(1, get_greek) }, math))
table.insert(letter_snippets,
snip('\\$(' .. trigger_index_pre .. ')\\$' .. '(' .. trigger_index_post .. ') ',
'$<>$ ', { d(1, get_index) }, markup, 500))
table.insert(letter_snippets,
snip('(' .. trigger_index_pre .. ')' .. '(' .. trigger_index_post .. ') ', '<> ', { d(1, get_index) }, math, 200))
table.insert(
letter_snippets,
snip(
'\\$(' .. trigger_index_pre .. ')\\$' .. '(' .. trigger_index_post .. ') ',
'$<>$ ',
{ d(1, get_index) },
markup,
500
)
)
table.insert(
letter_snippets,
snip('(' .. trigger_index_pre .. ')' .. '(' .. trigger_index_post .. ') ', '<> ', { d(1, get_index) }, math, 200)
)
return {
unpack(letter_snippets)
unpack(letter_snippets),
}

View File

@@ -8,7 +8,6 @@ local visual = helper.visual
local snip = helper.snip
local start = helper.start_snip
local ctheorems = {
{ 'tem', 'theorem' },
{ 'pro', 'proof' },
@@ -21,9 +20,9 @@ local ctheorems = {
}
local wrappings = {
{ 'll', '$', '$', '1+1' },
{ 'BLD', '*', '*', 'abc' },
{ 'ITL', '_', '_', 'abc' },
{ 'll', '$', '$', '1+1' },
{ 'BLD', '*', '*', 'abc' },
{ 'ITL', '_', '_', 'abc' },
{ 'HIG', '#highlight[', ']', 'abc' },
{ 'UND', '#underline[', ']', 'abc' },
}
@@ -44,8 +43,8 @@ end
return {
start('dm', '$\n<>\t<>\n<>$', { cap(1), visual(1), 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),
start('flA', '#flashcard(0, "<>")[\n<>\t<>\n<>]', { i(1, 'flashcard'), cap(1), visual(2), cap(1) }, markup),
snip('IMP', '$=>>$ ', {}, markup),
snip('IFF', '$<<=>>$ ', {}, markup),
unpack(document_snippets),

View File

@@ -61,9 +61,7 @@ local lmat = function(_, sp)
ins_indx = ins_indx + 1
for k = 2, cols do
table.insert(nodes, t(', '))
if k == cols then
table.insert(nodes, t('dots, '))
end
if k == cols then table.insert(nodes, t('dots, ')) end
if j == k then
table.insert(nodes, r(ins_indx, tostring(j) .. 'x' .. tostring(k), i(1, '1')))
else

View File

@@ -5,35 +5,35 @@ local i = ls.insert_node
local s = ls.snippet_node
local t = ls.text_node
local utils = require('typstar.utils')
local helper = require('typstar.autosnippets')
local utils = require('typstar.utils')
local math = helper.in_math
local snip = helper.snip
local snippets = {}
local operations = { -- first boolean: existing brackets should be kept; second boolean: brackets should be added
{ 'vi', '1/', '', true, false },
{ 'bb', '(', ')', true, false }, -- add round brackets
{ 'sq', '[', ']', true, false }, -- add square brackets
{ 'bB', '(', ')', false, false }, -- replace with round brackets
{ 'sQ', '[', ']', false, false }, -- replace with square brackets
{ 'BB', '', '', false, false }, -- remove brackets
{ 'ss', '"', '"', false, false },
{ 'abs', 'abs', '', true, true },
{ 'ul', 'underline', '', true, true },
{ 'ol', 'overline', '', true, true },
{ 'ub', 'underbrace', '', true, true },
{ 'ob', 'overbrace', '', true, true },
{ 'ht', 'hat', '', true, true },
{ 'br', 'macron', '', true, true },
{ 'dt', 'dot', '', true, true },
{ 'ci', 'circle', '', true, true },
{ 'td', 'tilde', '', true, true },
{ 'nr', 'norm', '', true, true },
{ 'vv', 'vec', '', true, true },
{ 'rt', 'sqrt', '', true, true },
{ 'flo', 'floor', '', true, true },
{ 'cei', 'ceil', '', true, true },
local operations = { -- first boolean: existing brackets should be kept; second boolean: brackets should be added
{ 'vi', '1/', '', true, false },
{ 'bb', '(', ')', true, false }, -- add round brackets
{ 'sq', '[', ']', true, false }, -- add square brackets
{ 'bB', '(', ')', false, false }, -- replace with round brackets
{ 'sQ', '[', ']', false, false }, -- replace with square brackets
{ 'BB', '', '', false, false }, -- remove brackets
{ 'ss', '"', '"', false, false },
{ 'abs', 'abs', '', true, true },
{ 'ul', 'underline', '', true, true },
{ 'ol', 'overline', '', true, true },
{ 'ub', 'underbrace', '', true, true },
{ 'ob', 'overbrace', '', true, true },
{ 'ht', 'hat', '', true, true },
{ 'br', 'macron', '', true, true },
{ 'dt', 'dot', '', true, true },
{ 'ci', 'circle', '', true, true },
{ 'td', 'tilde', '', true, true },
{ 'nr', 'norm', '', true, true },
{ 'vv', 'vec', '', true, true },
{ 'rt', 'sqrt', '', true, true },
{ 'flo', 'floor', '', true, true },
{ 'cei', 'ceil', '', true, true },
}
local ts_wrap_query = ts.query.parse('typst', '[(call) (ident) (letter) (number)] @wrap')
@@ -46,16 +46,11 @@ local process_ts_query = function(bufnr, cursor, query, root, insert1, insert2,
if end_row == cursor[1] and end_col == cursor[2] then
vim.schedule(function() -- to not interfere with luasnip
local cursor_offset = 0
local old_len1, new_len1 = utils.insert_text(
bufnr, start_row, start_col, insert1, 0, cut_offset)
if start_row == cursor[1] then
cursor_offset = cursor_offset + (new_len1 - old_len1)
end
local old_len2, new_len2 = utils.insert_text(
bufnr, end_row, cursor[2] + cursor_offset, insert2, cut_offset, 0)
if end_row == cursor[1] then
cursor_offset = cursor_offset + (new_len2 - old_len2)
end
local old_len1, new_len1 = utils.insert_text(bufnr, start_row, start_col, insert1, 0, cut_offset)
if start_row == cursor[1] then cursor_offset = cursor_offset + (new_len1 - old_len1) end
local old_len2, new_len2 =
utils.insert_text(bufnr, end_row, cursor[2] + cursor_offset, insert2, cut_offset, 0)
if end_row == cursor[1] then cursor_offset = cursor_offset + (new_len2 - old_len2) end
vim.api.nvim_win_set_cursor(0, { cursor[1] + 1, cursor[2] + cursor_offset })
end)
return true
@@ -76,9 +71,7 @@ local smart_wrap = function(args, parent, old_state, expand)
local expand1 = expand[5] and expand[2] .. '(' or expand[2]
local expand2 = expand[5] and expand[3] .. ')' or expand[3]
if process_ts_query(bufnr, cursor, ts_wrap_query, root, expand1, expand2) then
return s(nil, t())
end
if process_ts_query(bufnr, cursor, ts_wrap_query, root, expand1, expand2) then return s(nil, t()) end
if #parent.env.LS_SELECT_RAW > 0 then
return s(nil, t(expand1 .. table.concat(parent.env.LS_SELECT_RAW) .. expand2))
end
@@ -90,5 +83,5 @@ for _, val in pairs(operations) do
end
return {
unpack(snippets)
unpack(snippets),
}