feat(client): add per-subgroup Vim mapping opt-out globals
The plain-Vim ftplugin only exposed a whole-layer
g:nuwiki_no_default_mappings gate, so Vim users could not drop a single
keymap group the way Neovim users can via mappings.<group> = false. Add
g:nuwiki_no_{wiki_prefix,links,lists,headers,table_editing,diary,
html_export,text_objects}_mappings, each wrapping its group block, to
reach parity with lua/nuwiki/keymaps.lua. Cover them with a dedicated
opt-out harness and document them in the README and help file.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
" development/tests/test-keymaps-vim-optout.vim — driven by
|
||||
" development/tests/test-keymaps-vim.sh.
|
||||
"
|
||||
" Per-subgroup mapping opt-out regression. The shell driver sets a subset
|
||||
" of `g:nuwiki_no_<group>_mappings = 1` globals *before* the ftplugin loads,
|
||||
" so this harness asserts that the disabled groups leave no buffer-local
|
||||
" mappings while the still-enabled groups keep theirs. Mirrors the Lua-side
|
||||
" subgroup toggles in lua/nuwiki/keymaps.lua.
|
||||
|
||||
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
|
||||
|
||||
" Groups the driver disabled (g:nuwiki_no_<group>_mappings = 1): every
|
||||
" representative LHS below must be ABSENT.
|
||||
let s:disabled = [
|
||||
\ ['wiki_prefix', '<Leader>ww', 'n'],
|
||||
\ ['wiki_prefix', '<Leader>w<Leader>w', 'n'],
|
||||
\ ['links', '<CR>', 'n'],
|
||||
\ ['links', '+', 'n'],
|
||||
\ ['links', '<Leader>wr', 'n'],
|
||||
\ ['headers', '=', 'n'],
|
||||
\ ['headers', ']]', 'n'],
|
||||
\ ['headers', ']u', 'n'],
|
||||
\ ['text_objects', 'ah', 'x'],
|
||||
\ ['text_objects', 'il', 'o'],
|
||||
\ ]
|
||||
for s:e in s:disabled
|
||||
let s:ok = !s:has_map(s:e[1], s:e[2])
|
||||
call s:record(s:ok ? 1 : 0, 'optout.' . s:e[0] . '.' . s:e[2] . '.' . s:e[1],
|
||||
\ s:ok ? '' : s:e[1] . ' (' . s:e[2] . ') still mapped despite opt-out')
|
||||
endfor
|
||||
|
||||
" Groups left enabled: every representative LHS must still be PRESENT.
|
||||
let s:enabled = [
|
||||
\ ['lists', 'gln', 'n'],
|
||||
\ ['lists', 'gnt', 'n'],
|
||||
\ ['lists', '<C-Space>', 'n'],
|
||||
\ ['diary', '<C-Down>', 'n'],
|
||||
\ ['table_editing', 'gqq', 'n'],
|
||||
\ ['table_editing', '<A-Left>', 'n'],
|
||||
\ ['html_export', '<Leader>wh', 'n'],
|
||||
\ ['html_export', '<Leader>wha', 'n'],
|
||||
\ ]
|
||||
for s:e in s:enabled
|
||||
let s:ok = s:has_map(s:e[1], s:e[2])
|
||||
call s:record(s:ok ? 1 : 0, 'kept.' . s:e[0] . '.' . s:e[2] . '.' . s:e[1],
|
||||
\ s:ok ? '' : s:e[1] . ' (' . s:e[2] . ') unexpectedly absent')
|
||||
endfor
|
||||
|
||||
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!')
|
||||
@@ -59,7 +59,44 @@ fi
|
||||
|
||||
cat "$RESULTS"
|
||||
|
||||
if grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS"; then
|
||||
if ! grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS"; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# ===== Per-subgroup opt-out run =====
|
||||
# Fresh Vim instance with a subset of g:nuwiki_no_<group>_mappings set
|
||||
# *before* the ftplugin loads, so we can assert the disabled groups drop
|
||||
# their bindings while the rest survive.
|
||||
|
||||
VIMRC_OPTOUT="$TMP/vimrc-optout"
|
||||
cat > "$VIMRC_OPTOUT" <<EOF
|
||||
set nocompatible
|
||||
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
|
||||
let g:nuwiki_no_wiki_prefix_mappings = 1
|
||||
let g:nuwiki_no_links_mappings = 1
|
||||
let g:nuwiki_no_headers_mappings = 1
|
||||
let g:nuwiki_no_text_objects_mappings = 1
|
||||
filetype plugin indent on
|
||||
syntax enable
|
||||
EOF
|
||||
|
||||
RESULTS_OPTOUT="$TMP/results-optout.txt"
|
||||
|
||||
log "running opt-out harness…"
|
||||
NUWIKI_KEYMAP_RESULTS="$RESULTS_OPTOUT" \
|
||||
timeout 30 vim -e -s -u "$VIMRC_OPTOUT" -c "edit $SEED" -c "source $REPO_ROOT/development/tests/test-keymaps-vim-optout.vim" \
|
||||
</dev/null >"$TMP/vim-optout.log" 2>&1 || true
|
||||
|
||||
if [[ ! -f "$RESULTS_OPTOUT" ]]; then
|
||||
echo 'keymap opt-out harness produced no output' >&2
|
||||
echo '--- vim log ---' >&2
|
||||
cat "$TMP/vim-optout.log" >&2 || true
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cat "$RESULTS_OPTOUT"
|
||||
|
||||
if grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS_OPTOUT"; then
|
||||
exit 0
|
||||
fi
|
||||
exit 1
|
||||
|
||||
Reference in New Issue
Block a user