From 5c45d954f53a820b25b6e1fadc641d7c991c8506 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Mon, 22 Jun 2026 16:31:09 -0400 Subject: feat: multiple notes directory support added. existing config remains backwards compatible so no worries. --- README.md | 20 ++++++++++ lua/simple-denote.lua | 92 +++++++++++++++++++++++++++++++++++++++++++- lua/simple-denote/config.lua | 1 + 3 files changed, 112 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fea44da..bdcd00b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Example config via [lazy.nvim](https://github.com/folke/lazy.nvim) dir = "~/notes", -- Notes directory (should already exist) add_heading = true, -- Add a md/org heading to new notes retitle_heading = true, -- Replace the first line heading when retitling + directories = {}, -- Optional: multiple notes directories (see below) }, }, ``` @@ -46,6 +47,7 @@ vim.keymap.set({'n','v'}, 'nt', ":Denote title", { desc = "Chang vim.keymap.set({'n','v'}, 'nk', ":Denote keywords", { desc = "Change keywords" }) vim.keymap.set({'n','v'}, 'nz', ":Denote signature", { desc = "Change signature" }) vim.keymap.set({'n','v'}, 'ne', ":Denote extension", { desc = "Change extension" }) +vim.keymap.set({'n','v'}, 'nd', ":Denote dir", { desc = "Switch directory" }) ``` ## Manual Install @@ -89,8 +91,26 @@ require('simple-denote').setup({ " Rename the current file to a new extension :Denote extension + +" Switch active notes directory (requires directories = {...} config) +:Denote dir +``` + +# Multi-Directory Support + +To work with multiple notes directories, add them to `directories`: + +```lua +require('simple-denote').setup({ + dir = "~/notes", -- default active directory + directories = { "~/notes", "~/work", "~/projects" }, +}) ``` +Use `:Denote dir` to select a directory. The active directory is exposed as `vim.g.denote_dir` so other plugins can read it. + +When `directories` is empty (the default), nothing changes and the plugin works identically so I don't break anything for anyone who happens to be using this. + # Credits * [HumanEntity/denote.nvim](https://github.com/HumanEntity/denote.nvim) - This project was based on denote.nvim and modified to suit my personal preference or closer adhere to the original Denote spec. diff --git a/lua/simple-denote.lua b/lua/simple-denote.lua index f7e24f2..98c6ded 100644 --- a/lua/simple-denote.lua +++ b/lua/simple-denote.lua @@ -15,13 +15,15 @@ function M.load_cmd(options) api.signature() elseif opts.fargs[1] == "extension" then api.extension() + elseif opts.fargs[1] == "dir" then + M.switch_dir() else error("Unsupported operation " .. opts.fargs[1]) end end, { nargs = 1, complete = function() - return { "note", "title", "keywords", "signature", "extension" } + return { "note", "title", "keywords", "signature", "extension", "dir" } end, }) end @@ -31,6 +33,14 @@ function M.fix_options() if config.options.dir:sub(-1) ~= "/" then config.options.dir = config.options.dir .. "/" end + for i, d in ipairs(config.options.directories) do + if d:sub(-1) ~= "/" then + config.options.directories[i] = d .. "/" + end + end + if #config.options.directories > 0 then + vim.g.denote_dir = config.options.dir + end if config.options.ext == "md" then config.options.heading_char = "#" elseif config.options.ext == "org" or config.options.ext == "norg" then @@ -38,6 +48,86 @@ function M.fix_options() end end +function M.switch_dir() + local dirs = config.options.directories + if #dirs == 0 then + vim.notify("No directories configured. Add directories = { ... } to your setup.", vim.log.levels.WARN) + return + end + + local current = config.options.dir + local cursor_line = 1 + for i, d in ipairs(dirs) do + if d == current then + cursor_line = i + break + end + end + + local max_width = 0 + for _, d in ipairs(dirs) do + max_width = math.max(max_width, #d) + end + + local buf = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(buf, 0, -1, false, dirs) + vim.api.nvim_buf_set_option(buf, "modifiable", false) + vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe") + + local width = max_width + 2 + local height = #dirs + local row = math.floor((vim.o.lines - height) / 2) + local col = math.floor((vim.o.columns - width) / 2) + + local win = vim.api.nvim_open_win(buf, true, { + relative = "editor", + width = width, + height = height, + row = row, + col = col, + style = "minimal", + border = "single", + }) + + vim.wo[win].cursorline = true + vim.api.nvim_win_set_cursor(win, { cursor_line, 0 }) + + local function select() + local line = vim.api.nvim_win_get_cursor(win)[1] + local choice = dirs[line] + if choice then + config.options.dir = choice + vim.g.denote_dir = choice + vim.notify("Notes directory: " .. choice, vim.log.levels.INFO) + end + vim.api.nvim_win_close(win, true) + end + + local function cancel() + vim.api.nvim_win_close(win, true) + end + + vim.keymap.set("n", "", select, { buffer = buf, nowait = true }) + vim.keymap.set("n", "", cancel, { buffer = buf, nowait = true }) + vim.keymap.set("n", "", cancel, { buffer = buf, nowait = true }) + vim.keymap.set("n", "j", function() + local line = math.min(vim.api.nvim_win_get_cursor(win)[1] + 1, #dirs) + vim.api.nvim_win_set_cursor(win, { line, 0 }) + end, { buffer = buf, nowait = true }) + vim.keymap.set("n", "k", function() + local line = math.max(vim.api.nvim_win_get_cursor(win)[1] - 1, 1) + vim.api.nvim_win_set_cursor(win, { line, 0 }) + end, { buffer = buf, nowait = true }) + vim.keymap.set("n", "", function() + local line = math.min(vim.api.nvim_win_get_cursor(win)[1] + 1, #dirs) + vim.api.nvim_win_set_cursor(win, { line, 0 }) + end, { buffer = buf, nowait = true }) + vim.keymap.set("n", "", function() + local line = math.max(vim.api.nvim_win_get_cursor(win)[1] - 1, 1) + vim.api.nvim_win_set_cursor(win, { line, 0 }) + end, { buffer = buf, nowait = true }) +end + ---@param options? table user configuration function M.setup(options) config.options = vim.tbl_deep_extend("force", config.defaults, options or {}) diff --git a/lua/simple-denote/config.lua b/lua/simple-denote/config.lua index efd69c0..2b82778 100644 --- a/lua/simple-denote/config.lua +++ b/lua/simple-denote/config.lua @@ -3,6 +3,7 @@ local M = {} M.defaults = { ext = "md", dir = "~/notes/", + directories = {}, add_heading = true, retitle_heading = true, heading_char = "" -- This gets set automatically -- cgit v1.2.3