40 lines
985 B
Lua
40 lines
985 B
Lua
local ls = require('luasnip')
|
|
local s = ls.snippet
|
|
local i = ls.insert_node
|
|
local f = ls.function_node
|
|
local fmt = require('luasnip.extras.fmt').fmt
|
|
|
|
local function com_string(_, snip, to_multiply)
|
|
local comment_string = vim.bo.commentstring
|
|
local repeats = snip.captures[1]
|
|
local result = comment_string:gsub('%%s', ''):gsub(' ', '')
|
|
|
|
if to_multiply then
|
|
return string.sub(
|
|
string.rep(result, repeats),
|
|
0,
|
|
repeats
|
|
)
|
|
end
|
|
|
|
return result
|
|
end
|
|
|
|
ls.add_snippets('all', {
|
|
s({ name = 'Comment block', trig = '#com(%d+)', regTrig = true },
|
|
fmt([[
|
|
{comment_block}
|
|
{comment} {comment_text}
|
|
{comment_block}
|
|
]],
|
|
{
|
|
comment_block = f(com_string, {}, { user_args = { true } }),
|
|
comment = f(com_string, {}, { user_args = { false } }),
|
|
comment_text = i(1,
|
|
'Comment')
|
|
}
|
|
)
|
|
),
|
|
})
|
|
|