feat(config): P3 config batch — group 2 (create_link, dir_link, auto_header)

- create_link (default true): server resolve_target_uri now only synthesises a
  missing-page URI when create_link is set; when off, following a link to a
  non-existent page returns no location (no-op).
- dir_link: a [[dir/]] link now resolves to <dir>/<dir_link><ext> when dir_link
  is set, else opens the directory itself. Uses the already-parsed
  LinkTarget.is_directory.
- auto_header (default off): new wiki pages get a `= Stem =` header derived from
  the filename, skipping the wiki index + diary index. Client-side BufNewFile
  autocmd in both clients (init.lua + plugin/nuwiki.vim), with auto_header
  handlers in both command layers (trailing-slash-robust root matching).

Tests: cmd.auto_header_inserts + cmd.auto_header_skips_diary_index (nvim) /
cmd.auto_header_skips_index (vim). Full rust suite + both harnesses green
(Neovim 307, Vim 301/18/21).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-03 12:19:37 +00:00
parent b2f2fc88bd
commit 87d14310fc
7 changed files with 149 additions and 1 deletions
+31
View File
@@ -285,6 +285,37 @@ function M.show_version()
}, false, {})
end
-- vimwiki `auto_header`: on a new wiki page, insert a level-1 header derived
-- from the filename. Skips the wiki index + diary index pages, and only acts
-- on a genuinely empty buffer. Called from a BufNewFile autocmd.
function M.auto_header(bufnr)
bufnr = bufnr or vim.api.nvim_get_current_buf()
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
if #lines > 1 or (lines[1] or '') ~= '' then
return -- not an empty new buffer
end
local file = vim.api.nvim_buf_get_name(bufnr)
local config = require('nuwiki.config')
for i = 0, 64 do
local c = config.wiki_cfg(i)
if not c then break end
local root = vim.fn.fnamemodify(vim.fn.expand(c.root), ':p')
if root:sub(-1) ~= '/' then root = root .. '/' end
if file:sub(1, #root) == root then
-- Skip the wiki index and the diary index pages.
local index_path = root .. c.idx .. c.ext
local diary_index_path = root .. c.diary_rel .. '/' .. c.diary_idx .. c.ext
if file == index_path or file == diary_index_path then
return
end
break
end
if not (config.options.wikis or vim.g.nuwiki_wikis) then break end
end
local title = vim.fn.fnamemodify(file, ':t:r')
vim.api.nvim_buf_set_lines(bufnr, 0, 1, false, { '= ' .. title .. ' =', '' })
end
-- :VimwikiSearch / :VWS {pattern} — search the current wiki's files (upstream
-- scopes to the wiki, not the editor CWD). Resolves the wiki whose root holds
-- the current file, else the first configured wiki, else CWD. Empty pattern