From e5f95df4201af39794848e31b5192edc4da1bdea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20L=C3=BCdecke?= Date: Sun, 8 Jun 2025 12:35:51 +0200 Subject: [PATCH] Added command :Diary to open the AsciiDoc diary and start a new entry --- init.lua | 1 + lua/diary.lua | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 lua/diary.lua diff --git a/init.lua b/init.lua index 74f67df..2af9467 100644 --- a/init.lua +++ b/init.lua @@ -6,3 +6,4 @@ require('plugins') require('colorscheme') require('lsp') require('keybindings') +require('diary') diff --git a/lua/diary.lua b/lua/diary.lua new file mode 100644 index 0000000..f58578f --- /dev/null +++ b/lua/diary.lua @@ -0,0 +1,21 @@ +local diary_open = function(opts) + local date = opts.args ~= '' and opts.args or os.date('%Y-%m-%d') + local year, month = date:match('(%d%d%d%d)-(%d%d)') + local file = string.format('~/.diary/asciidoc/%s/diary-%s-%s.adoc', year, year, month) + print("file is:", file) + vim.cmd('e ' .. file) + vim.cmd('normal! G') + + -- NOTE.2025-06-08 [1] and [2] should be replaced with snippet name, but I + -- don't know how -- neither do grok nor chatgpt ... + local snips = require('luasnip') + local asnippets = snips.get_snippets('asciidoc') + if vim.fn.getfsize(file) == 0 then + snips.snip_expand(asnippets[1]) + vim.cmd('normal! G') + end + snips.snip_expand(asnippets[2]) + +end + +vim.api.nvim_create_user_command("Diary", diary_open, { nargs = '?' })