2026-05-11 00:38:09 +00:00
|
|
|
-- lua/nuwiki/config.lua — defaults and user-config merge.
|
|
|
|
|
--
|
2026-05-30 18:35:40 +00:00
|
|
|
-- Keep this aligned with `doc/nuwiki.txt`.
|
2026-05-10 16:01:58 +00:00
|
|
|
|
|
|
|
|
local M = {}
|
|
|
|
|
|
2026-05-11 00:38:09 +00:00
|
|
|
M.defaults = {
|
2026-05-30 18:35:40 +00:00
|
|
|
-- Single-wiki shorthand. The server desugars these into a
|
2026-05-12 15:10:27 +00:00
|
|
|
-- one-entry `wikis = {…}` list. Use either this or the multi-wiki
|
|
|
|
|
-- form below; if both are set, `wikis` wins.
|
2026-05-11 00:38:09 +00:00
|
|
|
wiki_root = '~/vimwiki',
|
|
|
|
|
file_extension = '.wiki',
|
|
|
|
|
syntax = 'vimwiki',
|
|
|
|
|
log_level = 'warn',
|
2026-05-11 21:57:05 +00:00
|
|
|
|
2026-05-31 19:18:06 +00:00
|
|
|
-- 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',
|
|
|
|
|
|
2026-05-30 18:35:40 +00:00
|
|
|
-- Multi-wiki shape. Each entry honours every per-wiki key the
|
2026-05-12 15:10:27 +00:00
|
|
|
-- server understands. Leave nil to fall through to the shorthand
|
|
|
|
|
-- above.
|
|
|
|
|
--
|
2026-05-30 18:35:40 +00:00
|
|
|
-- Per-wiki keys (all optional, server defaults documented in
|
|
|
|
|
-- `doc/nuwiki.txt`):
|
2026-05-12 15:10:27 +00:00
|
|
|
-- name, root, file_extension, syntax, index
|
|
|
|
|
-- diary_rel_path, diary_index, diary_frequency,
|
2026-05-31 17:06:09 +00:00
|
|
|
-- diary_weekly_style, diary_start_week_day,
|
2026-05-30 23:12:14 -03:00
|
|
|
-- diary_caption_level, diary_sort, diary_header
|
2026-05-12 15:10:27 +00:00
|
|
|
-- html_path, template_path, template_default, template_ext,
|
|
|
|
|
-- template_date_format, css_name, auto_export, auto_toc,
|
2026-05-31 18:55:51 +00:00
|
|
|
-- auto_generate_links, auto_generate_tags, auto_diary_index,
|
2026-05-31 19:06:42 +00:00
|
|
|
-- html_filename_parameterization, exclude_files, color_dic,
|
|
|
|
|
-- custom_wiki2html, custom_wiki2html_args, base_url,
|
2026-05-31 18:44:35 +00:00
|
|
|
-- toc_header, toc_header_level, links_header, links_header_level,
|
|
|
|
|
-- tags_header, tags_header_level,
|
2026-05-31 18:33:25 +00:00
|
|
|
-- listsyms, listsym_rejected, listsyms_propagate, list_margin,
|
2026-05-30 23:12:14 -03:00
|
|
|
-- links_space_char
|
2026-05-12 15:10:27 +00:00
|
|
|
wikis = nil,
|
|
|
|
|
|
2026-05-30 18:35:40 +00:00
|
|
|
-- Per-buffer glue. Each subgroup mirrors vimwiki's
|
2026-05-12 00:46:40 +00:00
|
|
|
-- `g:vimwiki_key_mappings` shape and can be flipped off
|
|
|
|
|
-- independently to suppress that group of keymaps.
|
2026-05-31 19:40:06 +00:00
|
|
|
-- The <Leader>w prefix in wiki_prefix/links/html_export follows map_prefix.
|
2026-05-11 21:57:05 +00:00
|
|
|
mappings = {
|
|
|
|
|
enabled = true,
|
2026-05-31 19:40:06 +00:00
|
|
|
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>
|
2026-05-12 00:46:40 +00:00
|
|
|
headers = true, -- =, -, ]], [[, ]=, [=, ]u, [u
|
2026-05-31 19:40:06 +00:00
|
|
|
table_editing = true, -- gqq, gq1, gww, gw1, <A-Left>, <A-Right>; insert <Tab>, <S-Tab>
|
2026-05-12 00:46:40 +00:00
|
|
|
diary = true, -- <C-Down>, <C-Up>
|
2026-05-31 19:40:06 +00:00
|
|
|
html_export = true, -- <Leader>wh, <Leader>whh, <Leader>wha
|
2026-05-12 15:10:27 +00:00
|
|
|
text_objects = true, -- ah, ih, aH, iH, al, il, a\, i\, ac, ic
|
2026-05-31 19:40:06 +00:00
|
|
|
mouse = false, -- <2-LeftMouse>, <S-2-LeftMouse>, <C-2-LeftMouse>, <MiddleMouse>, <RightMouse> (opt-in)
|
2026-05-11 21:57:05 +00:00
|
|
|
},
|
|
|
|
|
|
2026-05-30 18:35:40 +00:00
|
|
|
-- Folding. `'lsp'` uses the server's `foldingRange`
|
2026-05-11 21:57:05 +00:00
|
|
|
-- provider (Neovim 0.11+ wires it automatically). `'expr'` falls
|
|
|
|
|
-- back to a regex-based `foldexpr`. `'off'` skips folding setup.
|
|
|
|
|
folding = 'lsp',
|
2026-05-30 21:53:51 -03:00
|
|
|
|
|
|
|
|
-- Broken-link diagnostic severity. Sent to the server, which downgrades
|
|
|
|
|
-- or suppresses the diagnostic accordingly.
|
|
|
|
|
-- 'off' | 'hint' | 'warn' | 'error'
|
|
|
|
|
diagnostic = {
|
|
|
|
|
link_severity = 'warn',
|
|
|
|
|
},
|
2026-05-11 00:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
M.options = vim.deepcopy(M.defaults)
|
|
|
|
|
|
|
|
|
|
function M.apply(user)
|
|
|
|
|
M.options = vim.tbl_deep_extend('force', M.defaults, user or {})
|
|
|
|
|
end
|
|
|
|
|
|
2026-05-28 20:04:31 -03:00
|
|
|
-- 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
|
|
|
|
|
|
2026-05-10 16:01:58 +00:00
|
|
|
return M
|