feat(config): vimwiki drop-in config + global per-wiki defaults
CI / cargo fmt --check (push) Successful in 31s
CI / cargo clippy (push) Successful in 32s
CI / cargo test (push) Successful in 41s
CI / editor keymaps (push) Successful in 1m53s

Two related config-ergonomics features for vimwiki migrants, sharing the
same scalar-global machinery.

1. Upstream g:vimwiki_* drop-in (Vim client). When nuwiki isn't configured
   natively, the Vim client reads g:vimwiki_list + g:vimwiki_* globals and
   translates them into nuwiki's schema: per-wiki path->root,
   path_html->html_path, template_*, css_name, auto_export/auto_toc,
   syntax, ext->file_extension, index, diary_*, name. g:nuwiki_* always
   wins. Lets a vimwiki user drop in nuwiki without rewriting config.

2. Global per-wiki defaults (both clients). A display/generation setting
   given once at the top level — g:nuwiki_<key> / setup({<key>=…}) /
   g:vimwiki_<key> — is folded into every wiki as a default; a per-wiki
   value overrides it (vimwiki's model). Covers toc_header(_level),
   toc_link_format, links_header(_level), tags_header(_level),
   html_header_numbering(_sym), links_space_char, list_margin, listsyms,
   listsym_rejected, and the auto_* toggles. Only values the user
   explicitly set fold — built-in defaults don't (added config.user
   tracking on the Lua side so a default toc_header_level=1 isn't pushed
   onto every wiki). User config tables are never mutated.

Both clients kept in lock-step (config-parity golden enforces identical
payloads). New harnesses test-vimwiki-compat-vim (18) and
test-global-shorthand (8), wired into CI. Server test
vimwiki_compat_payload_sets_toc_level_per_wiki. Docs in README +
known-issues.md (drop-in is currently Vim-only). Rust 573 passed, clippy
clean, all harnesses green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 23:37:10 +00:00
parent fc0d74bfbe
commit 9d89e01ed8
11 changed files with 465 additions and 7 deletions
+7
View File
@@ -103,7 +103,14 @@ M.defaults = {
M.options = vim.deepcopy(M.defaults)
-- The raw table the user passed to setup(), kept separate from the
-- defaults-merged `options`. Used to tell an explicitly-set value apart from
-- a built-in default — e.g. so the LSP client only treats a per-wiki key as a
-- global default when the user actually set it.
M.user = {}
function M.apply(user)
M.user = user or {}
M.options = vim.tbl_deep_extend('force', M.defaults, user or {})
end
+50
View File
@@ -14,6 +14,39 @@ local function command()
return { install.expected_path() }
end
-- Per-wiki settings that double as wiki-wide defaults (vimwiki-style global
-- shorthand): set once at the top level — via setup() or `g:nuwiki_<key>` —
-- and every wiki inherits it; a per-wiki value overrides. Mirrors the Vim
-- client's `s:scalar_global_map`.
local SCALAR_GLOBALS = {
'toc_header', 'toc_header_level', 'toc_link_format',
'links_header', 'links_header_level',
'tags_header', 'tags_header_level',
'html_header_numbering', 'html_header_numbering_sym',
'links_space_char', 'list_margin',
'listsyms', 'listsym_rejected',
'auto_export', 'auto_toc',
'auto_generate_links', 'auto_generate_tags', 'auto_diary_index',
}
-- Resolve the global scalar defaults from config the user *explicitly* set:
-- the raw setup() table first, then the `g:nuwiki_<key>` global. Built-in
-- defaults are deliberately excluded so they don't get folded into every wiki
-- (that would diverge from the Vim client and override per-wiki values with a
-- default).
local function scalar_globals()
local user = config.user or {}
local g = {}
for _, key in ipairs(SCALAR_GLOBALS) do
if user[key] ~= nil then
g[key] = user[key]
elseif vim.g['nuwiki_' .. key] ~= nil then
g[key] = vim.g['nuwiki_' .. key]
end
end
return g
end
-- Merge g:nuwiki_wikis (VimL config) into opts.wikis when the user has not
-- passed wikis through setup(). This lets users who configure via a .vim
-- file avoid duplicating the list in their Lua setup() call.
@@ -22,6 +55,23 @@ local function resolved_opts()
if not opts.wikis and vim.g.nuwiki_wikis then
opts = vim.tbl_extend('force', opts, { wikis = vim.g.nuwiki_wikis })
end
local globals = scalar_globals()
if vim.tbl_isempty(globals) then
return opts
end
if opts.wikis then
-- Fold the globals into each wiki as defaults (per-wiki value wins),
-- without mutating the user's setup table.
local folded = {}
for i, w in ipairs(opts.wikis) do
folded[i] = vim.tbl_extend('force', globals, w)
end
opts = vim.tbl_extend('force', opts, { wikis = folded })
else
-- Single-wiki shorthand: ensure the globals (incl. the g:nuwiki_* form)
-- sit at the top level for the server's single-wiki desugaring.
opts = vim.tbl_extend('keep', opts, globals)
end
return opts
end