nvim: add more snippets

- shrug
- section header comment (i like this one)
This commit is contained in:
dogeystamp 2024-04-03 16:03:15 -04:00
parent c5a061a49a
commit 5fb723ee29
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
2 changed files with 81 additions and 5 deletions

View File

@ -137,7 +137,11 @@ local servers = {
library = {
vim.env.VIMRUNTIME,
},
}
},
diagnostics = {
-- get it to stop complaining about luasnip
globals = {'s', 'f', 't', "fmt", "c", "sn", "i", "rep", "d"},
},
}
}
},

View File

@ -1,12 +1,38 @@
--------------------------------
--------------------------------
-- utility functions
--------------------------------
--------------------------------
-- if nil or empty, use placeholder
local function get_str(str, placeholder)
if not str or str == "" then
return placeholder
else
return str
end
end
-- repeat i() node some amount of times
local function rep_node(args, snip)
local ret = {}
local line = string.rep(args[1][1], get_str(snip.captures[2], 16))
for _ = 1, get_str(snip.captures[1], 1) do
table.insert(ret, line)
end
return ret
end
return {
--------------------------------
--------------------------------
--------------------------------
--------------------------------
-- date and timekeeping snippets
--------------------------------
--------------------------------
--------------------------------
--------------------------------
s({ trig = "today", desc = "YYYY-MM-DD date of today" }, f(function()
return os.date("%Y-%m-%d")
end)),
s({ trig = "yesterday", desc = "YYYY-MM-DD date of yesterday" }, f(function()
local t = os.date("*t")
return os.date("%Y-%m-%d", os.time { year = t.year, month = t.month, day = t.day - 1 })
@ -16,6 +42,7 @@ return {
local t = os.date("*t")
return tostring(os.time { year = t.year, month = t.month, day = t.day, hour = 0 })
end)),
s(
{
trig = "datestamp (%d-)-(%d-)-(%d-)",
@ -25,4 +52,49 @@ return {
}, f(function(_, snip)
return tostring(os.time { year = snip.captures[1], month = snip.captures[2], day = snip.captures[3], hour = 0 })
end)),
--------------------------------
--------------------------------
-- miscellaneous snippets
--------------------------------
--------------------------------
s({ trig = "shrug", desc = "shrug emoticon (not escaped)" }, t("¯\\_(ツ)_/¯")),
s(
{
trig = "(%d*)segm(%d-)",
regTrig = true,
desc = {
"section/segment header title comment.", "",
"number in front is height (default 1), second number is width.",
"to use this, type the comment symbol (e.g. # or //) then TAB, then the section title.",
"see also: https://www.pathsensitive.com/2023/12/should-you-split-that-file.html",
}
}, fmt([[
{surr1}
{comm} {cont}
{surr2}
]], {
surr1 = f(rep_node, { 1 }),
comm = d(1, function()
local ft = vim.bo.filetype
local ft_table = {
c = "//",
cpp = "//",
rust = "//",
lua = "--",
python = "##",
}
local comm = ft_table[ft]
if not comm then
return sn(nil, { i(1) })
end
return sn(nil, { t(comm) })
end),
cont = i(2),
surr2 = f(rep_node, { 1 })
})),
}