fix(mappings): respect g:nuwiki_wikis in global entry-point helpers
The global <Leader>ww / diary helpers read g:nuwiki_wiki_root directly, so they always opened the root-level index.wiki even when the user had configured per-wiki roots via g:nuwiki_wikis (e.g. personal_wiki.root = '~/.vimwiki/personal_wiki'). Vim path (autoload): replace the three open_*_path functions with a shared s:wiki_cfg(n) helper that checks g:nuwiki_wikis[n] first, then falls back to the scalar g:nuwiki_* vars and built-in defaults. Lua path (init.lua): replace the separate _wiki_index_path /_diary_path locals with a unified _wiki_cfg() that checks setup() opts.wikis, then vim.g.nuwiki_wikis (for users who configure via VimL rather than setup()), then scalar opts / g: vars. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -348,28 +348,44 @@ endfunction
|
||||
" open their wiki from any buffer. Files are opened directly from config;
|
||||
" the LSP auto-starts via the FileType autocmd once the buffer loads.
|
||||
|
||||
function! nuwiki#commands#open_wiki_path(tab) abort
|
||||
let l:root = expand(get(g:, 'nuwiki_wiki_root', '~/vimwiki'))
|
||||
let l:ext = get(g:, 'nuwiki_file_extension', '.wiki')
|
||||
" Return a dict with {root, ext, idx, diary_rel, diary_idx} for wiki #n
|
||||
" (0-based). Prefers g:nuwiki_wikis[n]; falls back to scalar g:nuwiki_*
|
||||
" vars and finally to built-in defaults.
|
||||
function! s:wiki_cfg(n) abort
|
||||
let l:w = {}
|
||||
if exists('g:nuwiki_wikis') && len(g:nuwiki_wikis) > a:n
|
||||
let l:w = g:nuwiki_wikis[a:n]
|
||||
endif
|
||||
let l:root = expand(get(l:w, 'root',
|
||||
\ get(g:, 'nuwiki_wiki_root', '~/vimwiki')))
|
||||
let l:ext = get(l:w, 'file_extension',
|
||||
\ get(g:, 'nuwiki_file_extension', '.wiki'))
|
||||
if l:ext[0] !=# '.' | let l:ext = '.' . l:ext | endif
|
||||
execute (a:tab ? 'tabedit' : 'edit') . ' ' . fnameescape(l:root . '/index' . l:ext)
|
||||
let l:idx = get(l:w, 'index', 'index')
|
||||
let l:diary_rel = get(l:w, 'diary_rel_path',
|
||||
\ get(g:, 'nuwiki_diary_rel_path', 'diary'))
|
||||
let l:diary_idx = get(l:w, 'diary_index', 'diary')
|
||||
return { 'root': l:root, 'ext': l:ext, 'idx': l:idx,
|
||||
\ 'diary_rel': l:diary_rel, 'diary_idx': l:diary_idx }
|
||||
endfunction
|
||||
|
||||
function! nuwiki#commands#open_wiki_path(tab) abort
|
||||
let l:c = s:wiki_cfg(0)
|
||||
execute (a:tab ? 'tabedit' : 'edit') . ' '
|
||||
\ . fnameescape(l:c.root . '/' . l:c.idx . l:c.ext)
|
||||
endfunction
|
||||
|
||||
function! nuwiki#commands#open_diary_path(day_offset) abort
|
||||
let l:root = expand(get(g:, 'nuwiki_wiki_root', '~/vimwiki'))
|
||||
let l:ext = get(g:, 'nuwiki_file_extension', '.wiki')
|
||||
if l:ext[0] !=# '.' | let l:ext = '.' . l:ext | endif
|
||||
let l:diary = get(g:, 'nuwiki_diary_rel_path', 'diary')
|
||||
let l:date = strftime('%Y-%m-%d', localtime() + a:day_offset * 86400)
|
||||
execute 'edit ' . fnameescape(l:root . '/' . l:diary . '/' . l:date . l:ext)
|
||||
let l:c = s:wiki_cfg(0)
|
||||
let l:date = strftime('%Y-%m-%d', localtime() + a:day_offset * 86400)
|
||||
execute 'edit ' . fnameescape(l:c.root . '/' . l:c.diary_rel
|
||||
\ . '/' . l:date . l:c.ext)
|
||||
endfunction
|
||||
|
||||
function! nuwiki#commands#open_diary_index_path() abort
|
||||
let l:root = expand(get(g:, 'nuwiki_wiki_root', '~/vimwiki'))
|
||||
let l:ext = get(g:, 'nuwiki_file_extension', '.wiki')
|
||||
if l:ext[0] !=# '.' | let l:ext = '.' . l:ext | endif
|
||||
let l:diary = get(g:, 'nuwiki_diary_rel_path', 'diary')
|
||||
execute 'edit ' . fnameescape(l:root . '/' . l:diary . '/diary' . l:ext)
|
||||
let l:c = s:wiki_cfg(0)
|
||||
execute 'edit ' . fnameescape(l:c.root . '/' . l:c.diary_rel
|
||||
\ . '/' . l:c.diary_idx . l:c.ext)
|
||||
endfunction
|
||||
|
||||
" ===== List + heading editing =====
|
||||
|
||||
Reference in New Issue
Block a user