77 lines
2.3 KiB
Lua
77 lines
2.3 KiB
Lua
# Global LuaSnip snippets
|
|
|
|
local luasnip = require('luasnip')
|
|
local snip = luasnip.snippet
|
|
-- local sn = luasnip.snippet_node
|
|
local text = luasnip.text_node
|
|
-- local isn = luasnip.indent_snippet_node
|
|
-- local t = luasnip.text_node
|
|
local ins = luasnip.insert_node
|
|
local func = luasnip.function_node
|
|
-- local c = luasnip.choice_node
|
|
-- local d = luasnip.dynamic_node
|
|
-- local r = luasnip.restore_node
|
|
-- local events = require("luasnip.util.events")
|
|
-- local ai = require("luasnip.nodes.absolute_indexer")
|
|
-- local extras = require("luasnip.extras")
|
|
-- local l = extras.lambda
|
|
-- local rep = extras.rep
|
|
-- local p = extras.partial
|
|
-- local m = extras.match
|
|
-- local n = extras.nonempty
|
|
-- local dl = extras.dynamic_lambda
|
|
-- local fmt = require("luasnip.extras.fmt").fmt
|
|
-- local fmta = require("luasnip.extras.fmt").fmta
|
|
-- local conds = require("luasnip.extras.expand_conditions")
|
|
-- local postfix = require("luasnip.extras.postfix").postfix
|
|
-- local types = require("luasnip.util.types")
|
|
-- local parse = require("luasnip.util.parser").parse_snippet
|
|
-- local ms = luasnip.multi_snippet
|
|
-- local k = require("luasnip.nodes.key_indexer").new_key
|
|
|
|
local snippets = {}
|
|
|
|
local function comment_prefix()
|
|
-- Get value of commentstring buffer option
|
|
local split = string.find(vim.bo.commentstring, '%s', 1, true)
|
|
if not split then
|
|
return ''
|
|
end
|
|
-- Slice commentstring prefix
|
|
local prefix = vim.trim(string.sub(vim.bo.commentstring, 1, split - 1))
|
|
local line = vim.api.nvim_get_current_line()
|
|
local cursor = vim.api.nvim_win_get_cursor(vim.api.nvim_get_current_win())
|
|
-- Check if the current line already has prefix before the cursor
|
|
if string.find(string.sub(line, 1, cursor[2] + 1), prefix, 1, true) then
|
|
return ''
|
|
end
|
|
return prefix .. ' '
|
|
end
|
|
|
|
local function comment_suffix()
|
|
-- Get value of commentstring buffer option
|
|
local split = string.find(vim.bo.commentstring, '%s', 1, true)
|
|
if not split then
|
|
return ''
|
|
end
|
|
-- Slice commentstring suffix
|
|
local suffix = vim.trim(string.sub(vim.bo.commentstring, split + 2, -1))
|
|
if string.len(suffix) == 0 then
|
|
return ''
|
|
end
|
|
return ' ' .. suffix
|
|
end
|
|
|
|
for _, name in ipairs({ 'fixme', 'todo', 'hack', 'warn', 'note' }) do
|
|
table.insert(snippets,
|
|
snip(name, {
|
|
func(comment_prefix),
|
|
text(string.upper(name) .. ': '),
|
|
ins(0),
|
|
func(comment_suffix),
|
|
})
|
|
)
|
|
end
|
|
|
|
return snippets
|