fix: snippet spacing

This commit is contained in:
arne314
2024-11-23 19:58:11 +01:00
parent b03004d44c
commit 759b4f7c17
4 changed files with 23 additions and 18 deletions

View File

@@ -1,12 +1,12 @@
local M = {} local M = {}
local cfg = require('typstar.config').config.snippets local cfg = require('typstar.config').config.snippets
local luasnip = require('luasnip') local luasnip = require('luasnip')
local fmta = require("luasnip.extras.fmt").fmta local fmta = require('luasnip.extras.fmt').fmta
M.in_math = function() return vim.api.nvim_eval("typst#in_math()") == 1 end M.in_math = function() return vim.api.nvim_eval('typst#in_math()') == 1 end
M.in_markup = function() return vim.api.nvim_eval("typst#in_markup()") == 1 end M.in_markup = function() return vim.api.nvim_eval('typst#in_markup()') == 1 end
M.in_code = function() return vim.api.nvim_eval("typst#in_code()") == 1 end M.in_code = function() return vim.api.nvim_eval('typst#in_code()') == 1 end
M.in_comment = function() return vim.api.nvim_eval("typst#in_comment()") == 1 end M.in_comment = function() return vim.api.nvim_eval('typst#in_comment()') == 1 end
M.not_in_math = function() return not M.in_math() end M.not_in_math = function() return not M.in_math() end
M.not_in_markup = function() return not M.in_markup() end M.not_in_markup = function() return not M.in_markup() end
M.not_in_code = function() return not M.in_code() end M.not_in_code = function() return not M.in_code() end

View File

@@ -29,6 +29,6 @@ end
return { return {
start('dm', '$\n\t<>\n$', { i(1) }, markup), start('dm', '$\n\t<>\n$', { i(1) }, markup),
snip('ll', ' $<>$ ', { i(1, '1+1') }, markup), snip('ll', ' $<>$', { i(1, '1+1') }, markup),
unpack(document_snippets), unpack(document_snippets),
} }

View File

@@ -10,6 +10,7 @@ return {
snip('fa', 'forall ', {}, math), snip('fa', 'forall ', {}, math),
snip('ex', 'exists ', {}, math), snip('ex', 'exists ', {}, math),
snip('ni', 'in.not ', {}, math), snip('ni', 'in.not ', {}, math),
snip('Sq', 'square', {}, math),
-- logical chunks -- logical chunks
snip('fen', 'forall epsilon>>0 ', {}, math), snip('fen', 'forall epsilon>>0 ', {}, math),
@@ -22,10 +23,10 @@ return {
snip('no', 'not ', {}, math), snip('no', 'not ', {}, math),
-- relations -- relations
snip('el', '=', {}, math), snip('el', '= ', {}, math),
snip('df', ':=', {}, math), snip('df', ':= ', {}, math),
snip('lt', '<<', {}, math), snip('lt', '<< ', {}, math),
snip('gt', '>>', {}, math), snip('gt', '>> ', {}, math),
snip('le', '<<= ', {}, math), snip('le', '<<= ', {}, math),
snip('ne', '!= ', {}, math), snip('ne', '!= ', {}, math),
snip('ge', '>>= ', {}, math), snip('ge', '>>= ', {}, math),
@@ -35,6 +36,7 @@ return {
snip('(.*)ak', '<>-', { cap(1) }, math), snip('(.*)ak', '<>-', { cap(1) }, math),
snip('oak', 'plus.circle ', {}, math, 1100), snip('oak', 'plus.circle ', {}, math, 1100),
snip('bak', 'plus.square ', {}, math, 1100), snip('bak', 'plus.square ', {}, math, 1100),
snip('mak', 'plus.minus ', {}, math, 1100),
snip('xx', 'times ', {}, math), snip('xx', 'times ', {}, math),
snip('oxx', 'times.circle ', {}, math), snip('oxx', 'times.circle ', {}, math),
snip('bxx', 'times.square ', {}, math), snip('bxx', 'times.square ', {}, math),
@@ -42,15 +44,15 @@ return {
-- sets -- sets
snip('set', '{<>}', { i(1) }, math), snip('set', '{<>}', { i(1) }, math),
snip('es', 'emptyset ', {}, math), snip('es', 'emptyset ', {}, math),
snip('ses', '{emptyset}', {}, math), snip('ses', '{emptyset} ', {}, math),
snip('sp', 'supset ', {}, math), snip('sp', 'supset ', {}, math),
snip('sb', 'subset ', {}, math), snip('sb', 'subset ', {}, math),
snip('sep', 'supset.eq ', {}, math), snip('sep', 'supset.eq ', {}, math),
snip('seb', 'subset.eq ', {}, math), snip('seb', 'subset.eq ', {}, math),
snip('nn', 'sect ', {}, math), snip('nn', 'sect ', {}, math),
snip('uu', 'union ', {}, math), snip('uu', 'union ', {}, math),
snip('bnn', 'sect.big', {}, math, 1100), snip('bnn', 'sect.big ', {}, math, 1100),
snip('buu', 'untion.big', {}, math, 1100), snip('buu', 'untion.big ', {}, math, 1100),
snip('swo', 'without ', {}, math), snip('swo', 'without ', {}, math),
-- misc -- misc
@@ -58,7 +60,7 @@ return {
snip('mt', '|->> ', {}, math), snip('mt', '|->> ', {}, math),
snip('Oo', 'compose ', {}, math), snip('Oo', 'compose ', {}, math),
snip('iso', 'tilde.equiv ', {}, math), snip('iso', 'tilde.equiv ', {}, math),
snip('rrn', 'RR^n', {}, math), snip('rrn', 'RR^n ', {}, math),
snip('cc', 'cases(\n\t<>\n)\\', { i(1, '1') }, math), snip('cc', 'cases(\n\t<>\n)\\', { i(1, '1') }, math),
snip('(.*)iv', '<>^(-1)', { cap(1) }, math), snip('(.*)iv', '<>^(-1)', { cap(1) }, math),
snip('(.*)sr', '<>^(2)', { cap(1) }, math), snip('(.*)sr', '<>^(2)', { cap(1) }, math),
@@ -69,6 +71,6 @@ return {
snip('oit', 'integral_(Omega}', {}, math), snip('oit', 'integral_(Omega}', {}, math),
snip('dit', 'integral_{<>}', { i(1, 'Omega') }, math), snip('dit', 'integral_{<>}', { i(1, 'Omega') }, math),
snip('sm', 'sum_(<>)^(<>)', { i(1, 'i=0'), i(2, 'oo') }, math), snip('sm', 'sum_(<>)^(<>)', { i(1, 'i=0'), i(2, 'oo') }, math),
snip('lm', 'lim <> ', { i(1, 'n') }, math), snip('lm', 'lim <>', { i(1, 'a_n') }, math),
snip('lim', 'lim_(<> ->> <>) <> ', { i(1, 'n'), i(2, 'oo'), i(3) }, math), snip('lim', 'lim_(<> ->> <>) <>', { i(1, 'n'), i(2, 'oo'), i(3, 'a_n') }, math),
} }

View File

@@ -60,8 +60,11 @@ local wrap_brackets = function(args, snippet, val)
end end
for _, val in pairs(operations) do for _, val in pairs(operations) do
table.insert(snippets, snip(val[1], val[2] .. '<>' .. val[3], { d(1, get_visual), extra_node }, math)) 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'), extra_node }, math)) table.insert(snippets, snip('[%s$]' .. val[1], val[2] .. '<>' .. val[3], { i(1, '1') }, math))
table.insert(snippets,
snip('([%w]+)'
.. val[1], val[2] .. '<>' .. val[3], { cap(1) }, math, 900))
table.insert(snippets, 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 end