2022-01-08 18:08:41 +00:00
|
|
|
local status_ok, luasnip = pcall(require, "luasnip")
|
|
|
|
if not status_ok then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if vim.g.snippets ~= "luasnip" then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2022-01-12 09:19:35 +00:00
|
|
|
local snippet = luasnip.snippet
|
|
|
|
local i = luasnip.insert_node
|
|
|
|
local t = luasnip.text_node
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
local function make(tbl)
|
|
|
|
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")
|
|
|
|
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
|
|
|
|
|
|
|
local snippets = {
|
|
|
|
js = javascript,
|
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
|
|
|
}
|
|
|
|
|
|
|
|
luasnip.snippets = snippets
|
|
|
|
|
|
|
|
vim.cmd [[
|
|
|
|
imap <silent><expr> <c-k> luasnip#expand_or_jumpable() ? '<Plug>luasnip-expand-or-jump' : ''
|
|
|
|
inoremap <silent> <c-j> <cmd>lua require('luasnip').jump(-1)<CR>
|
|
|
|
imap <silent><expr> <C-l> luasnip#choice_active() ? '<Plug>luasnip-next-choice' : '<C-l>'
|
|
|
|
snoremap <silent> <c-k> <cmd>lua require('luasnip').jump(1)<CR>
|
|
|
|
snoremap <silent> <c-j> <cmd>lua require('luasnip').jump(-1)<CR>
|
|
|
|
]]
|