Files
nuwiki/lua/nuwiki/config.lua
T
gffranco 8dc4050b76
CI / cargo fmt --check (push) Failing after 16s
CI / cargo clippy (push) Successful in 31s
CI / cargo test (push) Successful in 37s
CI / editor keymaps (push) Successful in 1m30s
fix(commands)+docs: even out :NuwikiUISelect; exhaustive subgroup key lists
- ftplugin/vimwiki.vim: add buffer-local :NuwikiUISelect to the Vim path
  (it previously existed only on the Neovim path, contradicting the docs'
  "buffer-local on every .wiki buffer" claim — a global fallback masked it).
  Now symmetric with :VimwikiUISelect.

- Make every keymap subgroup description list all of its bindings instead
  of trailing with "…": the README mappings-subgroups table, the README
  config-example comments, the README g:nuwiki_no_<group>_mappings rows,
  the doc/nuwiki.txt group→keys list, and the lua/nuwiki/config.lua comment.
  Also fixes the doc list that had dropped aH/iH from text_objects and adds
  the mouse group. Each notes that the <Leader>w prefix follows map_prefix.

helptags validates (no dup tags); all keymap suites pass (266+18+21 Vim,
275 Lua); :NuwikiUISelect confirmed defined on a Vim .wiki buffer.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 19:40:06 +00:00

114 lines
4.6 KiB
Lua

-- lua/nuwiki/config.lua — defaults and user-config merge.
--
-- Keep this aligned with `doc/nuwiki.txt`.
local M = {}
M.defaults = {
-- Single-wiki shorthand. The server desugars these into a
-- one-entry `wikis = {…}` list. Use either this or the multi-wiki
-- form below; if both are set, `wikis` wins.
wiki_root = '~/vimwiki',
file_extension = '.wiki',
syntax = 'vimwiki',
log_level = 'warn',
-- Prefix for the global/buffer wiki command family (`<prefix>w`,
-- `<prefix>t`, `<prefix><Leader>w`, …). Mirrors vimwiki's
-- `g:vimwiki_map_prefix`. Vim users set `g:nuwiki_map_prefix` instead.
map_prefix = '<Leader>w',
-- Multi-wiki shape. Each entry honours every per-wiki key the
-- server understands. Leave nil to fall through to the shorthand
-- above.
--
-- Per-wiki keys (all optional, server defaults documented in
-- `doc/nuwiki.txt`):
-- name, root, file_extension, syntax, index
-- diary_rel_path, diary_index, diary_frequency,
-- diary_weekly_style, diary_start_week_day,
-- diary_caption_level, diary_sort, diary_header
-- html_path, template_path, template_default, template_ext,
-- template_date_format, css_name, auto_export, auto_toc,
-- auto_generate_links, auto_generate_tags, auto_diary_index,
-- html_filename_parameterization, exclude_files, color_dic,
-- custom_wiki2html, custom_wiki2html_args, base_url,
-- toc_header, toc_header_level, links_header, links_header_level,
-- tags_header, tags_header_level,
-- listsyms, listsym_rejected, listsyms_propagate, list_margin,
-- links_space_char
wikis = nil,
-- Per-buffer glue. Each subgroup mirrors vimwiki's
-- `g:vimwiki_key_mappings` shape and can be flipped off
-- independently to suppress that group of keymaps.
-- The <Leader>w prefix in wiki_prefix/links/html_export follows map_prefix.
mappings = {
enabled = true,
wiki_prefix = true, -- <Leader>w{w,t,s,i}, <Leader>w<Leader>{w,y,t,m,i}
links = true, -- <CR>, <S-CR>, <C-CR>, <C-S-CR>, <D-CR>, <M-CR>, <BS>, <Tab>, <S-Tab>, + (n/x), <Leader>w{n,d,r}, <Leader>wc (n/x)
lists = true, -- <C-Space>, gnt, gln, glp, glx, glh, gll, gLh, gLl, glr, gLr, gl{-,*,#,1,i,I,a,A}, gL{…}, gl, gL, o, O; insert <C-D>, <C-T>, <C-L><C-J/K/M>, <CR>
headers = true, -- =, -, ]], [[, ]=, [=, ]u, [u
table_editing = true, -- gqq, gq1, gww, gw1, <A-Left>, <A-Right>; insert <Tab>, <S-Tab>
diary = true, -- <C-Down>, <C-Up>
html_export = true, -- <Leader>wh, <Leader>whh, <Leader>wha
text_objects = true, -- ah, ih, aH, iH, al, il, a\, i\, ac, ic
mouse = false, -- <2-LeftMouse>, <S-2-LeftMouse>, <C-2-LeftMouse>, <MiddleMouse>, <RightMouse> (opt-in)
},
-- Folding. `'lsp'` uses the server's `foldingRange`
-- provider (Neovim 0.11+ wires it automatically). `'expr'` falls
-- back to a regex-based `foldexpr`. `'off'` skips folding setup.
folding = 'lsp',
-- Broken-link diagnostic severity. Sent to the server, which downgrades
-- or suppresses the diagnostic accordingly.
-- 'off' | 'hint' | 'warn' | 'error'
diagnostic = {
link_severity = 'warn',
},
}
M.options = vim.deepcopy(M.defaults)
function M.apply(user)
M.options = vim.tbl_deep_extend('force', M.defaults, user or {})
end
-- Resolve the config for wiki #n (0-based) without touching the LSP.
-- Priority: setup() opts.wikis → g:nuwiki_wikis (VimL) → scalar opts/g: vars.
-- Returns { name, root, ext, idx, diary_rel, diary_idx }.
function M.wiki_cfg(n)
local opts = M.options
local wikis = opts.wikis or vim.g.nuwiki_wikis or nil
local w = wikis and wikis[(n or 0) + 1] or nil
local root = (w and w.root) or opts.wiki_root or vim.g.nuwiki_wiki_root or '~/vimwiki'
local ext = (w and w.file_extension) or opts.file_extension or vim.g.nuwiki_file_extension or '.wiki'
if not ext:match('^%.') then ext = '.' .. ext end
return {
name = (w and w.name) or vim.fn.fnamemodify(vim.fn.expand(root), ':t'),
root = root,
ext = ext,
idx = (w and w.index) or 'index',
diary_rel = (w and w.diary_rel_path) or vim.g.nuwiki_diary_rel_path or 'diary',
diary_idx = (w and w.diary_index) or 'diary',
}
end
-- The full list of configured wikis as wiki_cfg dicts. Falls back to a single
-- entry built from the scalar wiki_root config when no list is configured.
function M.wiki_list()
local wikis = M.options.wikis or vim.g.nuwiki_wikis or nil
local list = {}
if type(wikis) == 'table' and #wikis > 0 then
for i = 1, #wikis do
list[i] = M.wiki_cfg(i - 1)
end
else
list[1] = M.wiki_cfg(0)
end
return list
end
return M