nixvimConfigs/fiesta/setups/snippets: init

This commit is contained in:
Gabriel Arazas 2024-01-28 17:06:26 +08:00
parent 1c08463334
commit 1abadc5841
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
5 changed files with 293 additions and 0 deletions

View File

@ -5,6 +5,7 @@
imports = [ ./modules ];
nixvimConfigs.fiesta.setups = {
snippets.enable = true;
treesitter.enable = true;
debugging.enable = true;
desktop-utils.enable = true;

View File

@ -2,6 +2,7 @@
imports = [
./setups/debugging.nix
./setups/desktop-utils.nix
./setups/snippets
./setups/treesitter.nix
];
}

View File

@ -0,0 +1,90 @@
{ config, lib, ... }:
let
nixvimCfg = config.nixvimConfigs.fiesta;
cfg = nixvimCfg.setups.snippets;
luasnipKeymapConfig = {
lua = true;
mode = [ "i" "s" ];
};
in
{
options.nixvimConfigs.fiesta.setups.snippets.enable =
lib.mkEnableOption "snippets setup";
config = lib.mkIf cfg.enable {
# The main star of the show.
plugins.luasnip.enable = true;
plugins.luasnip.extraConfig = {
keep_roots = true;
link_roots = true;
link_children = true;
enable_autosnippets = false;
};
# Set up this collection of snippets.
plugins.friendly-snippets.enable = true;
# Load all of the custom snippets.
plugins.luasnip.fromLua = [
{
lazyLoad = true;
paths = ./snippets;
}
];
# Set up the keymaps ourselves since LuaSnip doesn't provide one as a
# config option.
keymaps = [
(luasnipKeymapConfig // {
key = "<C-j>";
options.desc = "Jump to next node";
action = ''
function()
ls = require("luasnip")
if ls.jumpable(1) then
ls.jump(1)
end
end
'';
})
(luasnipKeymapConfig // {
key = "<C-k>";
options.desc = "Jump to previous node";
action = ''
function()
ls = require("luasnip")
if ls.jumpable(-1) then
ls.jump(-1)
end
end
'';
})
(luasnipKeymapConfig // {
key = "<C-l>";
options.desc = "Expand or jump to next node";
action = ''
function()
ls = require("luasnip")
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end
'';
})
(luasnipKeymapConfig // {
key = "<C-u>";
options.desc = "Show extra choices";
action = ''
function()
require("luasnip.extras.select_choice")()
end
'';
})
];
};
}

View File

@ -0,0 +1,31 @@
return {
s(
"today",
f(function()
return os.date("%F")
end)
),
s(
"retrieve",
f(function()
return string.format("(retrieved %s)", os.date("%F"))
end)
),
s(
{ trig = 'reldate (-?%d+) "(.+)"', regTrig = true },
f(function(_, snip)
-- The point is in number of days.
local point = 60 * 60 * 24 * snip.captures[1]
local now = os.time()
return os.date(snip.captures[2], now + point)
end)
),
s("#!", fmt("#!{}", i(1, "/usr/bin/env bash"))),
parse("ie", "(i.e., $1)"),
parse("eg", "(e.g., $1)"),
}

View File

@ -0,0 +1,170 @@
function max_asciidoc_header(level)
return math.min(level, 6)
end
return {
parse("bf", "**$1**"),
parse("it", "__$1__"),
parse("sp", "^$1^"),
parse("sb", "~$1~"),
s(
"tt",
fmt("{}{}{}", {
c(1, { t("`"), t("`+") }),
i(2, "TEXT"),
rep(1),
})
),
parse("foot", "footnote:[$1]"),
s(
"link",
fmt("link:{}[{}]", {
i(1, "LINK"),
rep(1),
})
),
parse("var", ":$1: $2"),
parse("audio", "audio::$1[$2]"),
parse("video", "video::$1[$2]"),
s(
"img",
fmt(
[[
.{}
image::{}[{}, {}]
{}
]],
{
i(1, "CAPTION"),
i(2, "IMAGE_PATH"),
i(3, "ALT_TEXT"),
i(4, "width=100%,height=100%"),
i(0),
}
)
),
s(
"fmt",
fmt("{}{}{}", {
c(1, {
t("**"),
t("__"),
t("`"),
}),
i(2),
rep(1),
})
),
s(
"dt",
fmt(
[[
{}::
{}
]],
{
i(1, "TERM"),
i(2, "DEFINITION"),
}
)
),
s(
"src",
fmt(
[[
[source, {}]
----
{}
----
{}
]],
{
i(1, "LANGUAGE"),
i(2, "CODE"),
i(0),
}
)
),
s(
{ trig = "h(%d)", regTrig = true },
fmt(
[[
{} {}
{}
{}
]],
{
f(function(_, snip)
local level = max_asciidoc_header(snip.captures[1])
return string.rep("=", level)
end),
i(1, "CHAPTER"),
d(2, function(_, snip)
local nodes = {}
table.insert(nodes, t(""))
local level = max_asciidoc_header(snip.captures[1])
if level == 1 then
table.insert(nodes, t(":toc:"))
end
local parent = c(1, nodes)
if level > 1 then
parent = t("")
end
return sn(nil, parent)
end, {}),
i(0),
}
)
),
s(
"admon",
fmt("{}: {}", {
c(1, {
t("NOTE"),
t("TIP"),
t("IMPORTANT"),
t("CAUTION"),
t("WARNING"),
}),
i(0),
})
),
s(
"admonB",
fmt(
[[
[{}]
====
{}
====
{}
]],
{
c(1, {
t("NOTE"),
t("TIP"),
t("IMPORTANT"),
t("CAUTION"),
t("WARNING"),
}),
i(2, "BODY"),
i(0),
}
)
),
}