From 49c1e9d1fc3d6bf8748756a8543d8c1b7287940f Mon Sep 17 00:00:00 2001 From: moxie Date: Sun, 15 Mar 2026 06:41:37 +0200 Subject: refactor: move template/mkdir features to user-configured autocmds - Remove auto-mkdir autocmd from init.lua (now user-configured) - Remove template system entirely (now user-configured) - Rename io.lua -> utils.lua - Inline single-use functions (handle_web_link, handle_file_link, etc.) - Remove security warnings for external files - Remove unused config options: use_template, template, date_fmt - Simplify utils.resolve() without wiki root validation - Update all documentation examples BREAKING CHANGE: Users must now add their own autocmds for: - Auto-creating directories on save (BufWritePre) - Applying templates to new files (BufNewFile) See README.md for updated configuration examples. --- README.md | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 56c3ea6..c43671a 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ A lightweight wiki plugin for Neovim using standard markdown syntax. - Standard markdown links `[text](url)` - Multiple wiki directories - External link handlers -- Automatic template for new page - Link navigation with custom keymaps See `:help muwiki` for complete documentation and configuration options. @@ -37,14 +36,16 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim): local muwiki = require('muwiki') muwiki.setup(opts) - local group = vim.api.nvim_create_augroup("MuWikiKeymaps", { clear = true }) + local group = vim.api.nvim_create_augroup("muwiki", { clear = true }) + -- Setup wiki keymaps for markdown files vim.api.nvim_create_autocmd("FileType", { group = group, pattern = "markdown", - callback = function(ev) - if not muwiki.wiki_root(ev.buf) then return end - local keymap_opts = { buffer = ev.buf, silent = true, nowait = true } + callback = function(args) + if not muwiki.wiki_root(args.buf) then return end + + local keymap_opts = { buffer = args.buf, silent = true, nowait = true } vim.keymap.set('n', '', muwiki.open_link, keymap_opts) vim.keymap.set('n', '', muwiki.next_link, keymap_opts) vim.keymap.set('n', '', muwiki.prev_link, keymap_opts) @@ -52,6 +53,23 @@ Using [lazy.nvim](https://github.com/folke/lazy.nvim): vim.keymap.set('n', 'oo', muwiki.open_link_with, keymap_opts) end, }) + + -- Auto-create parent directories when saving files in wiki + vim.api.nvim_create_autocmd("BufWritePre", { + group = group, + callback = function(args) + local wiki_root = muwiki.wiki_root(args.buf) + if not wiki_root then return end + + local file = args.file + if not vim.startswith(file, wiki_root) then return end + + local dir = vim.fn.fnamemodify(file, ":h") + if vim.fn.isdirectory(dir) == 0 then + vim.fn.mkdir(dir, "p") + end + end, + }) end, } ``` -- cgit v1.2.3