feat(keymaps): configurable map_prefix for the wiki command family (P2)
CI / cargo fmt --check (push) Failing after 33s
CI / cargo clippy (push) Successful in 31s
CI / cargo test (push) Successful in 41s
CI / editor keymaps (push) Successful in 1m49s

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>
This commit is contained in:
2026-05-31 19:18:06 +00:00
parent 23aec3e6c7
commit feedd30c4d
11 changed files with 234 additions and 55 deletions
+35 -1
View File
@@ -96,7 +96,41 @@ fi
cat "$RESULTS_OPTOUT"
if grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS_OPTOUT"; then
if ! grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS_OPTOUT"; then
exit 1
fi
# ===== Custom map_prefix run =====
# Fresh Vim instance with g:nuwiki_map_prefix set *before* the ftplugin
# loads, so we can assert the whole wiki command family relocates under the
# custom prefix and nothing remains under the default <Leader>w*.
VIMRC_PREFIX="$TMP/vimrc-prefix"
cat > "$VIMRC_PREFIX" <<EOF
set nocompatible
let &runtimepath = '$REPO_ROOT' . ',' . &runtimepath
let g:nuwiki_map_prefix = '<Leader>n'
filetype plugin indent on
syntax enable
EOF
RESULTS_PREFIX="$TMP/results-prefix.txt"
log "running custom-prefix harness…"
NUWIKI_KEYMAP_RESULTS="$RESULTS_PREFIX" \
timeout 30 vim -e -s -u "$VIMRC_PREFIX" -c "edit $SEED" -c "source $REPO_ROOT/development/tests/test-keymaps-vim-prefix.vim" \
</dev/null >"$TMP/vim-prefix.log" 2>&1 || true
if [[ ! -f "$RESULTS_PREFIX" ]]; then
echo 'keymap custom-prefix harness produced no output' >&2
echo '--- vim log ---' >&2
cat "$TMP/vim-prefix.log" >&2 || true
exit 1
fi
cat "$RESULTS_PREFIX"
if grep -qE '^SUMMARY: [0-9]+ passed, 0 failed' "$RESULTS_PREFIX"; then
exit 0
fi
exit 1