Compare commits
No commits in common. "35ca0f7b7a4cb1a198dcd62f22b42a56d97be6bc" and "6ece79006bcc9c5099085fca8466cff7ba0c0e2f" have entirely different histories.
35ca0f7b7a
...
6ece79006b
@ -140,7 +140,7 @@ local servers = {
|
|||||||
},
|
},
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
-- get it to stop complaining about luasnip
|
-- get it to stop complaining about luasnip
|
||||||
globals = {'s', 'f', 't', "fmt", "c", "sn", "i", "rep", "d", "k", "events"},
|
globals = {'s', 'f', 't', "fmt", "c", "sn", "i", "rep", "d", "k"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,91 +23,22 @@ local function rep_node(args, snip)
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--------------------------------
|
|
||||||
-- fbox snippet helper functions
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
---format box sides
|
|
||||||
---@param style_code string?
|
|
||||||
---@param side string
|
|
||||||
---@param sz integer
|
|
||||||
---@param width integer?
|
|
||||||
---@return string
|
|
||||||
local function box_line(style_code, side, sz, width)
|
|
||||||
local shorthand = {
|
|
||||||
r = "round",
|
|
||||||
h = "heavy",
|
|
||||||
s = "sharp",
|
|
||||||
}
|
|
||||||
local styles = {
|
|
||||||
round = "╭─╮││╰─╯",
|
|
||||||
heavy = "┏━┓┃┃┗━┛",
|
|
||||||
sharp = "┌─┐││└─┘",
|
|
||||||
}
|
|
||||||
|
|
||||||
type = shorthand[style_code] or "round"
|
|
||||||
|
|
||||||
-- array of characters (because lua strings are not c-strings 😔)
|
|
||||||
-- nor does nvim lua have utf-8 support 😔
|
|
||||||
-- https://stackoverflow.com/a/27941567
|
|
||||||
local style = {}
|
|
||||||
for code in styles[type]:gmatch("[%z\1-\127\194-\244][\128-\191]*") do
|
|
||||||
table.insert(style, code)
|
|
||||||
end
|
|
||||||
|
|
||||||
if side == "left" then
|
|
||||||
return style[4]
|
|
||||||
elseif side == "right" then
|
|
||||||
return string.rep(" ", (width or sz) - sz) .. style[5]
|
|
||||||
end
|
|
||||||
|
|
||||||
-- offset into the style
|
|
||||||
local o = 1
|
|
||||||
|
|
||||||
if side == "top" then o = 1 end
|
|
||||||
if side == "bottom" then o = 6 end
|
|
||||||
|
|
||||||
-- +2 for padding
|
|
||||||
return style[o] .. string.rep(style[o + 1], sz) .. style[o + 2]
|
|
||||||
end
|
|
||||||
local function box_fct(args, snip, side)
|
|
||||||
local content = args[1] or { "" }
|
|
||||||
local content_width = 0
|
|
||||||
for _, line in ipairs(content) do
|
|
||||||
content_width = math.max(content_width, string.len(line))
|
|
||||||
end
|
|
||||||
return box_line(snip.captures[1], side, content_width - 6)
|
|
||||||
end
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
--------------------------------
|
--------------------------------
|
||||||
--------------------------------
|
--------------------------------
|
||||||
-- date and timekeeping snippets
|
-- date and timekeeping snippets
|
||||||
--------------------------------
|
--------------------------------
|
||||||
--------------------------------
|
--------------------------------
|
||||||
s({
|
s({ trig = "today", desc = "YYYY-MM-DD date of today" }, f(function()
|
||||||
trig = "today",
|
|
||||||
name = "Today date format",
|
|
||||||
desc = "YYYY-MM-DD date of today"
|
|
||||||
}, f(function()
|
|
||||||
return os.date("%Y-%m-%d")
|
return os.date("%Y-%m-%d")
|
||||||
end)),
|
end)),
|
||||||
|
|
||||||
s({
|
s({ trig = "yesterday", desc = "YYYY-MM-DD date of yesterday" }, f(function()
|
||||||
trig = "yesterday",
|
|
||||||
name = "Yesterday date format",
|
|
||||||
desc = "YYYY-MM-DD date of yesterday"
|
|
||||||
}, f(function()
|
|
||||||
local t = os.date("*t")
|
local t = os.date("*t")
|
||||||
return os.date("%Y-%m-%d", os.time { year = t.year, month = t.month, day = t.day - 1 })
|
return os.date("%Y-%m-%d", os.time { year = t.year, month = t.month, day = t.day - 1 })
|
||||||
end)),
|
end)),
|
||||||
|
|
||||||
s({
|
s({ trig = "timestamp", desc = "Unix day timestamp (locked to midnight)" }, f(function()
|
||||||
trig = "timestamp",
|
|
||||||
name = "Unix day timestamp",
|
|
||||||
desc = "Unix time for today (locked to midnight)"
|
|
||||||
}, f(function()
|
|
||||||
local t = os.date("*t")
|
local t = os.date("*t")
|
||||||
return tostring(os.time { year = t.year, month = t.month, day = t.day, hour = 0 })
|
return tostring(os.time { year = t.year, month = t.month, day = t.day, hour = 0 })
|
||||||
end)),
|
end)),
|
||||||
@ -115,10 +46,9 @@ return {
|
|||||||
s(
|
s(
|
||||||
{
|
{
|
||||||
trig = "datestamp (%d-)-(%d-)-(%d-)",
|
trig = "datestamp (%d-)-(%d-)-(%d-)",
|
||||||
name = "Unix timestamp based on date",
|
|
||||||
regTrig = true,
|
regTrig = true,
|
||||||
desc =
|
desc =
|
||||||
"YYYY-MM-DD to Unix day timestamp conversion (locked to midnight)"
|
"YYYY-MM-DD to Unix day timestamp (locked to midnight)"
|
||||||
}, f(function(_, snip)
|
}, f(function(_, snip)
|
||||||
return tostring(os.time { year = snip.captures[1], month = snip.captures[2], day = snip.captures[3], hour = 0 })
|
return tostring(os.time { year = snip.captures[1], month = snip.captures[2], day = snip.captures[3], hour = 0 })
|
||||||
end)),
|
end)),
|
||||||
@ -128,17 +58,14 @@ return {
|
|||||||
-- miscellaneous snippets
|
-- miscellaneous snippets
|
||||||
--------------------------------
|
--------------------------------
|
||||||
--------------------------------
|
--------------------------------
|
||||||
s({
|
s({ trig = "shrug", desc = "shrug emoticon (not escaped)" }, t("¯\\_(ツ)_/¯")),
|
||||||
trig = "shrug",
|
|
||||||
desc = "shrug emoticon (not escaped)"
|
|
||||||
}, t("¯\\_(ツ)_/¯")),
|
|
||||||
|
|
||||||
s(
|
s(
|
||||||
{
|
{
|
||||||
trig = "(%d*)segm(%d-)",
|
trig = "(%d*)segm(%d-)",
|
||||||
regTrig = true,
|
regTrig = true,
|
||||||
name = "section/segment header title comment.",
|
|
||||||
desc = {
|
desc = {
|
||||||
|
"section/segment header title comment.", "",
|
||||||
"number in front is height (default 1), second number is width.",
|
"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.",
|
"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",
|
"see also: https://www.pathsensitive.com/2023/12/should-you-split-that-file.html",
|
||||||
@ -169,41 +96,4 @@ return {
|
|||||||
cont = i(2),
|
cont = i(2),
|
||||||
surr2 = f(rep_node, { 1 })
|
surr2 = f(rep_node, { 1 })
|
||||||
})),
|
})),
|
||||||
|
|
||||||
s(
|
|
||||||
{
|
|
||||||
trig = "fbox(%a?)",
|
|
||||||
regTrig = true,
|
|
||||||
name = "format box",
|
|
||||||
desc = { "draw a unicode box around some text.", "use fboxs for sharp corners (round default), fboxh for heavy" }
|
|
||||||
},
|
|
||||||
fmt([[
|
|
||||||
{surr1}
|
|
||||||
{content}
|
|
||||||
{surr2}
|
|
||||||
]],
|
|
||||||
{
|
|
||||||
content = i(1, "contents", {
|
|
||||||
node_callbacks = {
|
|
||||||
[events.leave] = function(node)
|
|
||||||
local t = node:get_text()
|
|
||||||
local width = 0
|
|
||||||
for _, line in ipairs(t) do
|
|
||||||
width = math.max(width, string.len(line))
|
|
||||||
end
|
|
||||||
local new_t = {}
|
|
||||||
for _, l in ipairs(t) do
|
|
||||||
local sz = string.len(l)
|
|
||||||
local style_code = node.parent.captures[1]
|
|
||||||
table.insert(new_t,
|
|
||||||
box_line(style_code, "left", sz, width) ..
|
|
||||||
" " .. l .. " " .. box_line(style_code, "right", sz, width))
|
|
||||||
end
|
|
||||||
node:set_text(new_t)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
surr1 = f(box_fct, { 1 }, { user_args = { "top" } }),
|
|
||||||
surr2 = f(box_fct, { 1 }, { user_args = { "bottom" } }),
|
|
||||||
})),
|
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
return {
|
return {
|
||||||
s({
|
s({ trig = "snipf", desc = "meta snippet (snippet for making snippets)" }, fmt([[
|
||||||
trig = "snipf",
|
s({{trig="{}", desc="{}"}}, {}),
|
||||||
desc = "meta snippet (snippet for making snippets)"
|
]], { i(1, "trigger"), i(2, "human-readable description"), i(3, "<body nodes>") }))
|
||||||
}, fmt([[
|
|
||||||
s({{
|
|
||||||
trig="{}",
|
|
||||||
name="{}",
|
|
||||||
desc="{}",
|
|
||||||
}},
|
|
||||||
{}
|
|
||||||
),
|
|
||||||
]], { i(1, "trigger"), i(2, "human-readable name"), i(3, "human-readable description"), i(4, "body") }))
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user