Compare commits

...

5 Commits

5 changed files with 396 additions and 378 deletions

View File

@ -20,8 +20,7 @@ local f = ls.function_node
local copy = utils.copy local copy = utils.copy
ls.snippets = { ls.add_snippets( "c", {
c = {
s("main", { s("main", {
t({ "int main(int argc, char* argv[])" }), t({ "int main(int argc, char* argv[])" }),
t({ "", "{", "\t" }), t({ "", "{", "\t" }),
@ -47,5 +46,6 @@ ls.snippets = {
t({ "", "\treturn 0;"}), t({ "", "\treturn 0;"}),
t({ "", "}"}), t({ "", "}"}),
}), }),
}, }, {
} key = "c"
})

View File

@ -10,13 +10,13 @@ opt.formatoptions = "trq1jp"
opt.tabstop = 4 opt.tabstop = 4
-- Caps -- Caps
utils.map("i", "AA", "À") vim.keymap.set("i", "AA", "À")
utils.map("i", "CC", "Ç") vim.keymap.set("i", "CC", "Ç")
utils.map("i", "EE", "É") vim.keymap.set("i", "EE", "É")
-- Unbreakable spaces -- Unbreakable spaces
utils.map("i", "<Space>etc", "\\,etc.") vim.keymap.set("i", "<Space>etc", "\\,etc.")
utils.map("i", "<Space>:", "\\,:") vim.keymap.set("i", "<Space>:", "\\,:")
-- Snippets -- Snippets
local ls = require("luasnip") local ls = require("luasnip")
@ -44,8 +44,7 @@ local function rec_ls()
) )
end end
ls.snippets = { ls.add_snippets("tex", {
tex = {
-- rec_ls is self-referencing. That makes this snippet 'infinite' eg. have as many -- rec_ls is self-referencing. That makes this snippet 'infinite' eg. have as many
-- \item as necessary by utilizing a choiceNode. -- \item as necessary by utilizing a choiceNode.
s("ls", { s("ls", {
@ -125,5 +124,6 @@ ls.snippets = {
i(1), i(1),
t({ "}"}), t({ "}"}),
}), }),
}, }, {
} key = "tex"
})

View File

@ -7,7 +7,7 @@ local cmp = require("cmp")
local luasnip = require("luasnip") local luasnip = require("luasnip")
local cmp_autopairs = require('nvim-autopairs.completion.cmp') local cmp_autopairs = require('nvim-autopairs.completion.cmp')
local check_backspace = function() local has_words_before = function()
local line, col = unpack(vim.api.nvim_win_get_cursor(0)) local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]: vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:
@ -62,9 +62,9 @@ cmp.setup {
["<Tab>"] = cmp.mapping(function(fallback) ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then if cmp.visible() then
cmp.select_next_item() cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then elseif luasnip.expand_or_locally_jumpable() then
luasnip.expand_or_jump() luasnip.expand_or_jump()
elseif check_backspace() then elseif has_words_before() then
cmp.complete() cmp.complete()
else else
fallback() fallback()

View File

@ -31,7 +31,26 @@ ls.config.set_config({
ext_opts = { ext_opts = {
[types.choiceNode] = { [types.choiceNode] = {
active = { active = {
virt_text = { { "choiceNode", "Comment" } }, virt_text = { { "", "LuaSnipChoice" } },
},
inactive = {
virt_text = { { "", "LuaSnipInactive" } },
},
},
[types.functionNode] = {
active = {
virt_text = { { "", "LuaSnipFunction" } },
},
inactive = {
virt_text = { { "", "LuaSnipInactive" } },
},
},
[types.insertNode] = {
active = {
virt_text = { { "", "LuaSnipInsert" } },
},
inactive = {
virt_text = { { "", "LuaSnipInactive" } },
}, },
}, },
}, },
@ -59,15 +78,13 @@ local function date_input(fmt)
return sn(nil, i(1, os.date(fmt))) return sn(nil, i(1, os.date(fmt)))
end end
ls.snippets = { -- snippets are added via ls.add_snippets(filetype, snippets[, opts]), where
-- When trying to expand a snippet, luasnip first searches the tables for -- opts may specify the `type` of the snippets ("snippets" or "autosnippets",
-- each filetype specified in 'filetype' followed by 'all'. -- for snippets that should expand directly after the trigger is typed).
-- If ie. the filetype is 'lua.c' --
-- - luasnip.lua -- opts can also specify a key. By passing an unique key to each add_snippets, it's possible to reload snippets by
-- - luasnip.c -- re-`:luafile`ing the file in which they are defined (eg. this one).
-- - luasnip.all ls.add_snippets( "all", {
-- are searched in that order.
all = {
-- trigger is fn. -- trigger is fn.
s("fn", { s("fn", {
-- Simple static text. -- Simple static text.
@ -321,8 +338,9 @@ ls.snippets = {
"fmt6", "fmt6",
fmt("use {} only", { t("this"), t("not this") }, { strict = false }) fmt("use {} only", { t("this"), t("not this") }, { strict = false })
), ),
}, }, {
} key = "all",
})
-- autotriggered snippets have to be defined in a separate table, luasnip.autosnippets. -- autotriggered snippets have to be defined in a separate table, luasnip.autosnippets.
ls.autosnippets = { ls.autosnippets = {

@ -1 +1 @@
Subproject commit d77e1cfe127418ab00c6d5fb076f89cdf9b49e94 Subproject commit 9b46e0fa3d2bfca3b376961d822eb5d965da48ed