feat(config): P3 config batch — group 1 (clean config + plumbing)

Config plumbing for the whole config batch (HtmlConfig + WikiConfig fields,
RawWiki deserialization, From/defaults) plus these behaviors:

- rss_name / rss_max_items: HtmlConfig fields (wired into write_rss in the RSS
  group).
- toc_link_format: build_toc_text emits [[#anchor]] (no description) for 1,
  [[#anchor|title]] for 0.
- generated_links_caption: build_links_text emits [[page|FirstHeading]] from a
  page->heading map (ops::page_captions) when enabled.
- table_reduce_last_col: column_widths clamps the last column to width 1 when
  set; threaded through table_align_edit/table_move_column_edit + commands.
- color_dic now ships a populated default palette (red/green/blue/...).
- commentstring aligned to upstream's no-space `%%%s`.
- auto_chdir (default off): :lcd into the owning wiki root on buffer enter;
  both clients (ftplugin.lua setup_auto_chdir + Vim NuwikiAutoChdir augroup),
  with config.wiki_root_for / nuwiki#commands#wiki_root_for resolvers.

Also seeded HtmlConfig fields for later groups (valid_html_tags,
list/text_ignore_newline, emoji_enable, user_htmls, color_tag_template) and
WikiConfig (create_link, dir_link, bullet_types, cycle_bullets).

Tests: toc_link_format, generated_links_caption, table_reduce_last_col,
config defaults + JSON round-trip for every new key. Full rust suite +
both keymap harnesses green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-03 12:04:36 +00:00
parent 03005d0931
commit b2f2fc88bd
11 changed files with 522 additions and 48 deletions
+17
View File
@@ -70,6 +70,10 @@ M.defaults = {
-- cursor when leaving insert mode.
table_auto_fmt = true,
-- vimwiki `auto_chdir` (default off): `:lcd` into the owning wiki's root
-- when a wiki buffer becomes current.
auto_chdir = false,
-- Broken-link diagnostic severity. Sent to the server, which downgrades
-- or suppresses the diagnostic accordingly.
-- 'off' | 'hint' | 'warn' | 'error'
@@ -125,4 +129,17 @@ function M.wiki_list()
return list
end
-- Absolute root (with trailing slash) of the wiki that owns `path`, or the
-- first configured wiki as a fallback. Used by auto_chdir + search scoping.
function M.wiki_root_for(path)
for _, w in ipairs(M.wiki_list()) do
local wroot = vim.fn.fnamemodify(vim.fn.expand(w.root), ':p')
if path:sub(1, #wroot) == wroot then
return wroot
end
end
local first = M.wiki_list()[1]
return first and vim.fn.fnamemodify(vim.fn.expand(first.root), ':p') or nil
end
return M
+26
View File
@@ -94,6 +94,31 @@ local function setup_table_auto_fmt(bufnr, enabled)
})
end
-- vimwiki `auto_chdir`: `:lcd` into the owning wiki's root while this buffer
-- is current.
local function setup_auto_chdir(bufnr, enabled)
if not enabled then
return
end
if bufnr == 0 then
bufnr = vim.api.nvim_get_current_buf()
end
local function chdir()
local file = vim.api.nvim_buf_get_name(bufnr)
local root = require('nuwiki.config').wiki_root_for(file)
if root then
vim.cmd('lcd ' .. vim.fn.fnameescape(root))
end
end
local grp = vim.api.nvim_create_augroup('nuwiki_chdir_' .. bufnr, { clear = true })
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufWinEnter' }, {
buffer = bufnr,
group = grp,
callback = chdir,
})
chdir()
end
function M.attach(bufnr)
bufnr = bufnr or 0
local config = require('nuwiki.config')
@@ -109,6 +134,7 @@ function M.attach(bufnr)
setup_folding(bufnr, opts.folding or 'lsp')
setup_autowriteall(bufnr, opts.autowriteall ~= false)
setup_table_auto_fmt(bufnr, opts.table_auto_fmt ~= false)
setup_auto_chdir(bufnr, opts.auto_chdir == true)
end
return M