Allow toggling snippet auto expand or not.

main
Joshua Potter 2024-01-25 17:47:12 -07:00
parent 413cd02ae6
commit f64e3f1f55
5 changed files with 52 additions and 9 deletions

View File

@ -151,6 +151,10 @@ return {
{ trig = [[\lr]], wordTrig = false }, { trig = [[\lr]], wordTrig = false },
t('') t('')
), ),
s(
{ trig = [[←r]], wordTrig = false },
t('')
),
s( s(
{ trig = [[\r]], wordTrig = false }, { trig = [[\r]], wordTrig = false },
t('') t('')
@ -192,13 +196,17 @@ return {
-- Other operators -- Other operators
s( s(
{ trig = [[\neg]], wordTrig = false }, { trig = [[\not]], wordTrig = false },
t('¬') t('¬')
), ),
s( s(
{ trig = [[\and]], wordTrig = false }, { trig = [[\and]], wordTrig = false },
t('') t('')
), ),
s(
{ trig = [[αnd]], wordTrig = false },
t('')
),
s( s(
{ trig = [[\or]], wordTrig = false }, { trig = [[\or]], wordTrig = false },
t('') t('')
@ -223,10 +231,18 @@ return {
{ trig = [[\leq]], wordTrig = false }, { trig = [[\leq]], wordTrig = false },
t('') t('')
), ),
s(
{ trig = [[←eq]], wordTrig = false },
t('')
),
s( s(
{ trig = [[\geq]], wordTrig = false }, { trig = [[\geq]], wordTrig = false },
t('') t('')
), ),
s(
{ trig = [[γeq]], wordTrig = false },
t('')
),
s( s(
{ trig = [[\in]], wordTrig = false }, { trig = [[\in]], wordTrig = false },
t('') t('')
@ -235,5 +251,8 @@ return {
{ trig = [[\notin]], wordTrig = false }, { trig = [[\notin]], wordTrig = false },
t('') t('')
), ),
s(
{ trig = [[¬in]], wordTrig = false },
t('')
),
} }

View File

@ -13,7 +13,7 @@ function M.setup()
end, end,
}, },
sources = { sources = {
{ name = 'luasnip' }, { name = 'luasnip', option = { show_autosnippets = true } },
{ name = 'nvim_lsp' }, { name = 'nvim_lsp' },
{ {
name = 'buffer', name = 'buffer',

View File

@ -75,11 +75,24 @@ function M.setup()
end, { silent = true, expr = true, remap = true }) end, { silent = true, expr = true, remap = true })
-- Allow aborting the active snippet at any point in time. -- Allow aborting the active snippet at any point in time.
vim.keymap.set( vim.keymap.set({ 'n', 'i', 's' }, '<c-l>', '<cmd>LuaSnipUnlinkCurrent<cr>')
{ 'n', 'i', 's' },
'<c-l>', -- Allow toggling autoexpansion on and off. This is more or less the intended
'<cmd>LuaSnipUnlinkCurrent<cr>' -- approach: https://github.com/L3MON4D3/LuaSnip/issues/832#issuecomment-1474993417
) luasnip.expand_auto_on = true
local expand_auto = luasnip.expand_auto
local toggle_expand_auto = function()
if luasnip.expand_auto_on then
luasnip.expand_auto = function() end
else
luasnip.expand_auto = expand_auto
end
luasnip.expand_auto_on = not luasnip.expand_auto_on
end
toggle_expand_auto()
vim.keymap.set({ 'n', 'i', 's' }, '', toggle_expand_auto)
end end
return M return M

View File

@ -24,4 +24,12 @@ function M.get_dap_status()
end end
end end
function M.get_autoexpand_status()
if require('luasnip').expand_auto_on then
return "🟢 auto"
else
return "🔴 auto"
end
end
return M return M

View File

@ -20,6 +20,7 @@ let
lualine_y = { lualine_y = {
require('utils.statusline').get_active_lsp, require('utils.statusline').get_active_lsp,
require('utils.statusline').get_dap_status, require('utils.statusline').get_dap_status,
require('utils.statusline').get_autoexpand_status,
}, },
lualine_z = {'%c:%l:%%%p'}, lualine_z = {'%c:%l:%%%p'},
}, },
@ -31,7 +32,9 @@ let
plugin = pkgs.vimPlugins.luasnip; plugin = pkgs.vimPlugins.luasnip;
config = '' config = ''
require('utils.luasnip').setup() require('utils.luasnip').setup()
require('luasnip').add_snippets('all', require('utf8.snippets')) require('luasnip').add_snippets('all', require('utf8.snippets'), {
type = "autosnippets",
})
${config.programs.neovim.nvim-snippets} ${config.programs.neovim.nvim-snippets}
''; '';
}; };