2022-01-13 00:18:02 +00:00
|
|
|
local status_ok, ls = pcall(require, "luasnip")
|
2022-01-08 18:08:41 +00:00
|
|
|
if not status_ok then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if vim.g.snippets ~= "luasnip" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-02-10 09:56:02 +00:00
|
|
|
ls.config.set_config {
|
|
|
|
enable_autosnippets = true,
|
|
|
|
history = true,
|
|
|
|
updateevents = "TextChanged,TextChangedI",
|
|
|
|
}
|
|
|
|
|
2022-01-13 00:18:02 +00:00
|
|
|
local snippet = ls.snippet
|
|
|
|
local i = ls.insert_node
|
|
|
|
local t = ls.text_node
|
2022-01-12 09:19:35 +00:00
|
|
|
|
|
|
|
local shortcut = function(val)
|
|
|
|
if type(val) == "string" then
|
|
|
|
return { t { val }, i(0) }
|
|
|
|
end
|
|
|
|
|
|
|
|
if type(val) == "table" then
|
|
|
|
for k, v in ipairs(val) do
|
|
|
|
if type(v) == "string" then
|
|
|
|
val[k] = t { v }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return val
|
|
|
|
end
|
|
|
|
|
2022-02-10 09:56:02 +00:00
|
|
|
local make = function(tbl)
|
2022-01-12 09:19:35 +00:00
|
|
|
local result = {}
|
|
|
|
for k, v in pairs(tbl) do
|
|
|
|
table.insert(result, (snippet({ trig = k, desc = v.desc }, shortcut(v))))
|
|
|
|
end
|
|
|
|
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
|
|
|
local javascript = make(R "opdavies.snippets.ft.javascript")
|
2022-02-10 09:56:02 +00:00
|
|
|
local lua = make(R "opdavies.snippets.ft.lua")
|
2022-01-12 09:19:35 +00:00
|
|
|
local markdown = make(R "opdavies.snippets.ft.markdown")
|
|
|
|
local php = make(R "opdavies.snippets.ft.php")
|
2022-01-12 13:42:33 +00:00
|
|
|
local rst = make(R "opdavies.snippets.ft.rst")
|
2022-01-09 01:08:48 +00:00
|
|
|
|
2022-02-10 09:56:02 +00:00
|
|
|
ls.snippets = {
|
2022-01-09 01:08:48 +00:00
|
|
|
js = javascript,
|
2022-02-10 09:56:02 +00:00
|
|
|
lua = lua,
|
2022-01-10 01:29:21 +00:00
|
|
|
markdown = markdown,
|
2022-01-09 01:08:48 +00:00
|
|
|
php = php,
|
2022-01-12 13:42:33 +00:00
|
|
|
rst = rst,
|
2022-01-09 01:08:48 +00:00
|
|
|
typescript = javascript,
|
|
|
|
vue = javascript,
|
2022-01-08 18:08:41 +00:00
|
|
|
}
|
|
|
|
|
2022-02-10 09:56:02 +00:00
|
|
|
local imap = require("opdavies.keymap").imap
|
|
|
|
local map = require("opdavies.keymap").map
|
|
|
|
local nmap = require("opdavies.keymap").nmap
|
|
|
|
|
|
|
|
local map_opts = { silent = true }
|
|
|
|
|
|
|
|
map {
|
|
|
|
{ "i", "s" },
|
|
|
|
"<c-j>",
|
|
|
|
function()
|
|
|
|
if ls.jumpable(-1) then
|
|
|
|
ls.jump(-1)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
map_opts,
|
|
|
|
}
|
|
|
|
|
|
|
|
map {
|
|
|
|
{ "i", "s" },
|
|
|
|
"<c-k>",
|
|
|
|
function()
|
|
|
|
if ls.expand_or_jumpable() then
|
|
|
|
ls.expand_or_jump()
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
map_opts,
|
|
|
|
}
|
|
|
|
|
|
|
|
imap {
|
|
|
|
"<c-l>",
|
|
|
|
function()
|
|
|
|
if ls.choice_active() then
|
|
|
|
ls.change_choice(1)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
map_opts,
|
|
|
|
}
|
2022-01-08 18:08:41 +00:00
|
|
|
|
2022-02-10 09:56:02 +00:00
|
|
|
nmap { "<leader><leader>s", "<cmd>source ~/.config/nvim/after/plugin/luasnip.lua<CR>", map_opts }
|