summaryrefslogtreecommitdiff
path: root/ar/.config
diff options
context:
space:
mode:
Diffstat (limited to 'ar/.config')
-rw-r--r--ar/.config/TheSiahxyz/lua/TheSiahxyz/plugins/snippets.lua8
-rw-r--r--ar/.config/TheSiahxyz/lua/TheSiahxyz/snippets/diary.lua45
2 files changed, 27 insertions, 26 deletions
diff --git a/ar/.config/TheSiahxyz/lua/TheSiahxyz/plugins/snippets.lua b/ar/.config/TheSiahxyz/lua/TheSiahxyz/plugins/snippets.lua
index 96c52a7..aff6f62 100644
--- a/ar/.config/TheSiahxyz/lua/TheSiahxyz/plugins/snippets.lua
+++ b/ar/.config/TheSiahxyz/lua/TheSiahxyz/plugins/snippets.lua
@@ -33,25 +33,25 @@ return {
vim.cmd.runtime({ args = { "lua/TheSiahxyz/snippets/*.lua" }, bang = true }) -- load custom snippets
- vim.keymap.set({ "i", "x" }, "<A-L>", function()
+ vim.keymap.set({ "i", "x" }, "<C-L>", function()
if ls.expand_or_jumpable() then
ls.expand_or_jump()
end
end, { silent = true, desc = "Expand snippet or jump to the next snippet node" })
- vim.keymap.set({ "i", "x" }, "<A-H>", function()
+ vim.keymap.set({ "i", "x" }, "<C-H>", function()
if ls.jumpable(-1) then
ls.jump(-1)
end
end, { silent = true, desc = "Previous spot in the snippet" })
- vim.keymap.set({ "i", "x" }, "<A-l>", function()
+ vim.keymap.set({ "i", "s" }, "<C-j>", function()
if ls.choice_active() then
ls.change_choice(1)
end
end, { silent = true, desc = "Next snippet choice" })
- vim.keymap.set({ "i", "x" }, "<A-h>", function()
+ vim.keymap.set({ "i", "s" }, "<C-k>", function()
if ls.choice_active() then
ls.change_choice(-1)
end
diff --git a/ar/.config/TheSiahxyz/lua/TheSiahxyz/snippets/diary.lua b/ar/.config/TheSiahxyz/lua/TheSiahxyz/snippets/diary.lua
index f1c636b..4f233d1 100644
--- a/ar/.config/TheSiahxyz/lua/TheSiahxyz/snippets/diary.lua
+++ b/ar/.config/TheSiahxyz/lua/TheSiahxyz/snippets/diary.lua
@@ -5,37 +5,38 @@ local i = ls.insert_node
local f = ls.function_node
local c = ls.choice_node
local t = ls.text_node
+local d = ls.dynamic_node
+local sn = ls.snippet_node
local fmt = require("luasnip.extras.fmt").fmta
-local function bgm_list()
- local handle = io.popen("ssh root@thesiah.xyz 'ls /var/www/thesiah/bgm/' 2>/dev/null")
- if not handle then
- return nil
- end
+local function bgm_node_generator()
+ return function()
+ local handle = io.popen("ssh root@thesiah.xyz 'ls /var/www/thesiah/bgm/' 2>/dev/null")
+ if not handle then
+ return sn(nil, { i(1, "bgm") })
+ end
- local result = handle:read("*a")
- handle:close()
+ local result = handle:read("*a")
+ handle:close()
- if not result or result == "" then
- return nil
- end
+ if not result or result == "" then
+ return sn(nil, { i(1, "bgm") })
+ end
- local choices = {}
- for filename in result:gmatch("[^\r\n]+") do
- table.insert(choices, t(filename))
- end
+ local choices = {}
+ for filename in result:gmatch("[^\r\n]+") do
+ table.insert(choices, t(filename))
+ end
- if #choices == 0 then
- return nil
- end
+ if #choices == 0 then
+ return sn(nil, { i(1, "bgm") })
+ end
- return choices
+ return sn(nil, { c(1, choices) })
+ end
end
-local bgm_choices = bgm_list()
-local bgm_node = bgm_choices and c(2, bgm_choices) or i(2, "bgm")
-
local diary_snippet = s(
"diary",
fmt(
@@ -52,7 +53,7 @@ bgm: <bgm>
date = f(function()
return os.date("%Y-%m-%d")
end, {}),
- bgm = bgm_node,
+ bgm = d(2, bgm_node_generator(), {}),
story = i(3),
}
)