feedd30c4d
Mirror vimwiki's g:vimwiki_map_prefix. The whole <Leader>w* family was
hardcoded across the map layer; it is now built from a configurable prefix:
- Neovim: `map_prefix` setup() option (default '<Leader>w'), read by
lua/nuwiki/keymaps.lua (buffer-local) and lua/nuwiki/init.lua (global
entry points).
- Vim: g:nuwiki_map_prefix, applied via :exe in plugin/nuwiki.vim (global)
and ftplugin/vimwiki.vim (buffer-local).
Setting a custom prefix relocates <prefix>{w,t,s,i,n,d,r,c,h,hh,ha} and
<prefix><Leader>{w,y,t,m,i}, leaving nothing under the old <Leader>w*.
Non-prefix maps (<CR>, gl*, headers, …) are untouched.
Tests: new test-keymaps-vim-prefix.vim harness (21 cases, wired into
test-keymaps-vim.sh) + map_prefix.relocates_wiki_family in test-keymaps.lua.
Docs: README, doc/nuwiki.txt, lua config comment, vimwiki-gap.md ticked.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
66 lines
2.4 KiB
VimL
66 lines
2.4 KiB
VimL
" development/tests/test-keymaps-vim-prefix.vim — driven by
|
|
" development/tests/test-keymaps-vim.sh.
|
|
"
|
|
" Custom-prefix regression. The shell driver sets
|
|
" `g:nuwiki_map_prefix = '<Leader>n'` *before* the ftplugin loads, so this
|
|
" harness asserts the whole wiki command family relocates under `<Leader>n*`
|
|
" while nothing remains under the default `<Leader>w*`. Mirrors vimwiki's
|
|
" `g:vimwiki_map_prefix` and the Lua-side `map_prefix` option.
|
|
|
|
let s:results = []
|
|
let s:pass = 0
|
|
let s:fail = 0
|
|
let s:out = $NUWIKI_KEYMAP_RESULTS
|
|
|
|
function! s:record(ok, name, detail) abort
|
|
let l:line = (a:ok ? 'PASS' : 'FAIL') . ' ' . a:name
|
|
if a:detail !=# ''
|
|
let l:line .= ' — ' . a:detail
|
|
endif
|
|
call add(s:results, l:line)
|
|
if a:ok
|
|
let s:pass += 1
|
|
else
|
|
let s:fail += 1
|
|
endif
|
|
endfunction
|
|
|
|
function! s:has_map(lhs, mode) abort
|
|
let l:d = maparg(a:lhs, a:mode, 0, 1)
|
|
return !empty(l:d) && get(l:d, 'buffer', 0)
|
|
endfunction
|
|
|
|
" Every <prefix>* mapping must now live under <Leader>n (prefix = <Leader>n).
|
|
let s:relocated = [
|
|
\ ['<Leader>nw', 'n'], ['<Leader>nt', 'n'], ['<Leader>ns', 'n'], ['<Leader>ni', 'n'],
|
|
\ ['<Leader>n<Leader>w', 'n'], ['<Leader>n<Leader>y', 'n'], ['<Leader>n<Leader>t', 'n'],
|
|
\ ['<Leader>n<Leader>m', 'n'], ['<Leader>n<Leader>i', 'n'],
|
|
\ ['<Leader>nn', 'n'], ['<Leader>nd', 'n'], ['<Leader>nr', 'n'], ['<Leader>nc', 'n'],
|
|
\ ['<Leader>nh', 'n'], ['<Leader>nhh', 'n'], ['<Leader>nha', 'n'],
|
|
\ ]
|
|
for s:e in s:relocated
|
|
let s:ok = s:has_map(s:e[0], s:e[1])
|
|
call s:record(s:ok ? 1 : 0, 'prefix.relocated.' . s:e[1] . '.' . s:e[0],
|
|
\ s:ok ? '' : s:e[0] . ' not bound under custom prefix')
|
|
endfor
|
|
|
|
" The default <Leader>w* family must be GONE (relocated, not duplicated).
|
|
let s:gone = [
|
|
\ ['<Leader>ww', 'n'], ['<Leader>wr', 'n'], ['<Leader>wh', 'n'],
|
|
\ ['<Leader>w<Leader>w', 'n'],
|
|
\ ]
|
|
for s:e in s:gone
|
|
let s:ok = !s:has_map(s:e[0], s:e[1])
|
|
call s:record(s:ok ? 1 : 0, 'prefix.default_gone.' . s:e[1] . '.' . s:e[0],
|
|
\ s:ok ? '' : s:e[0] . ' still mapped despite custom prefix')
|
|
endfor
|
|
|
|
" Non-prefix maps (links group) are unaffected by the prefix change.
|
|
let s:cr = s:has_map('<CR>', 'n')
|
|
call s:record(s:cr ? 1 : 0, 'prefix.cr_unaffected', s:cr ? '' : '<CR> lost')
|
|
|
|
call add(s:results, '')
|
|
call add(s:results, printf('SUMMARY: %d passed, %d failed', s:pass, s:fail))
|
|
call writefile(s:results, s:out)
|
|
execute (s:fail == 0 ? 'qall!' : 'cquit!')
|