aboutsummaryrefslogtreecommitdiffstats
path: root/lsp/markdown_oxide.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lsp/markdown_oxide.lua')
-rw-r--r--lsp/markdown_oxide.lua36
1 files changed, 20 insertions, 16 deletions
diff --git a/lsp/markdown_oxide.lua b/lsp/markdown_oxide.lua
index 8f2697bf..317bd433 100644
--- a/lsp/markdown_oxide.lua
+++ b/lsp/markdown_oxide.lua
@@ -8,25 +8,29 @@
--- Inspired by and compatible with Obsidian.
---
--- Check the readme to see how to properly setup.
+
+---@param client vim.lsp.Client
+---@param bufnr integer
+---@param cmd string
+local function command_factory(client, bufnr, cmd)
+ return client:exec_cmd({
+ title = ('Markdown-Oxide-%s'):format(cmd),
+ command = 'jump',
+ arguments = { cmd },
+ }, { bufnr = bufnr })
+end
+
return {
root_markers = { '.git', '.obsidian', '.moxide.toml' },
filetypes = { 'markdown' },
cmd = { 'markdown-oxide' },
- on_attach = function(_, bufnr)
- vim.api.nvim_buf_create_user_command(bufnr, 'LspToday', function()
- vim.lsp.buf.execute_command { command = 'jump', arguments = { 'today' } }
- end, {
- desc = "Open today's daily note",
- })
- vim.api.nvim_buf_create_user_command(bufnr, 'LspTomorrow', function()
- vim.lsp.buf.execute_command { command = 'jump', arguments = { 'tomorrow' } }
- end, {
- desc = "Open tomorrow's daily note",
- })
- vim.api.nvim_buf_create_user_command(bufnr, 'LspYesterday', function()
- vim.lsp.buf.execute_command { command = 'jump', arguments = { 'yesterday' } }
- end, {
- desc = "Open yesterday's daily note",
- })
+ on_attach = function(client, bufnr)
+ for _, cmd in ipairs({ 'today', 'tomorrow', 'yesterday' }) do
+ vim.api.nvim_buf_create_user_command(bufnr, 'Lsp' .. ('%s'):format(cmd:gsub('^%l', string.upper)), function()
+ command_factory(client, bufnr, cmd)
+ end, {
+ desc = ('Open %s daily note'):format(cmd),
+ })
+ end
end,
}