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:
@@ -305,6 +305,31 @@ vim.defer_fn(function()
|
||||
vim.cmd('bwipeout!')
|
||||
end
|
||||
|
||||
-- auto_header: the function inserts `= Stem =` on an empty new wiki buffer,
|
||||
-- and skips the wiki index page. Operate on dedicated buffer handles so the
|
||||
-- harness's own buffer is untouched.
|
||||
do
|
||||
local wroot = require('nuwiki.config').wiki_cfg(0).root
|
||||
local root = vim.fn.fnamemodify(vim.fn.expand(wroot), ':p')
|
||||
if root:sub(-1) ~= '/' then root = root .. '/' end
|
||||
local function ah_line(name)
|
||||
local buf = vim.api.nvim_create_buf(true, false)
|
||||
vim.api.nvim_buf_set_name(buf, name)
|
||||
require('nuwiki.commands').auto_header(buf)
|
||||
local line = vim.api.nvim_buf_get_lines(buf, 0, 1, false)[1] or ''
|
||||
vim.api.nvim_buf_delete(buf, { force = true })
|
||||
return line
|
||||
end
|
||||
-- A normal page (outside any wiki root) → header inserted.
|
||||
local got = ah_line('/tmp/nuwiki-ah-plain/MyNewPage.wiki')
|
||||
record(got == '= MyNewPage =', 'cmd.auto_header_inserts', 'line1=' .. got)
|
||||
-- The diary index page → skipped (no header). (The wiki index itself is the
|
||||
-- harness's open buffer, so use the diary index to avoid an E95 collision.)
|
||||
local c = require('nuwiki.config').wiki_cfg(0)
|
||||
local idx_line = ah_line(root .. c.diary_rel .. '/' .. c.diary_idx .. '.wiki')
|
||||
record(idx_line == '', 'cmd.auto_header_skips_diary_index', 'line1=' .. idx_line)
|
||||
end
|
||||
|
||||
-- ===== Lists =====
|
||||
|
||||
run('list.toggle_via_C-Space', {
|
||||
|
||||
Reference in New Issue
Block a user