parity(vim): port text objects + folding, fix smart_return textlock
Close the remaining Vim-vs-Neovim functional gaps:
* Text objects — new `autoload/nuwiki/textobjects.vim` mirroring
`lua/nuwiki/textobjects.lua`. All five pairs (ah/ih, aH/iH,
al/il, a\/i\, ac/ic) wired in the Vim path of `ftplugin/vimwiki.vim`
via the classic `:<C-u>call` idiom that works cleanly in both
operator-pending and visual modes.
* Folding — new `autoload/nuwiki/folding.vim` providing a regex
`foldexpr` over headings, plus a tidy `foldtext`. Wired in the
Vim path; opts out via `let g:nuwiki_no_folding = 1`.
* `smart_return` was using `setline()` / `append()` inside an
`<expr>` callback — fine on Neovim but plain Vim's stricter
textlock raised E565. Rewrote as pure keystrokes (matches the
Lua version): table rows insert via `<CR>...<Esc>0li`, empty
list lines break via `<Esc>0DA<CR>`.
* Function-name parity: added
`nuwiki#commands#heading_add_level`,
`nuwiki#commands#heading_remove_level`,
`nuwiki#commands#table_move_column_{left,right}` as thin
aliases over the original short names so the public
`nuwiki#commands#*` surface matches `require('nuwiki.commands').*`.
Test harness:
* `scripts/test-keymaps-vim.vim` extended from 12 to 30 cases:
4 smart_return, 3 smart_tab/<S-Tab>, 3 named-command exists,
4 text-object helpers, 1 `dah` end-to-end, 2 folding, and the
original 12 pure-VimL cases. (Visual-mode mark inspection in
`vim -e -s` stays unreliable, so text objects are exercised
at the helper level plus one operator-pending end-to-end.)
Gates: 456 Rust / 39 Neovim / 30 Vim.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -210,6 +210,40 @@ if !has('nvim')
|
||||
nnoremap <silent><buffer> gw1 :call nuwiki#commands#table_align()<CR>
|
||||
nnoremap <silent><buffer> <A-Left> :call nuwiki#commands#table_move_left()<CR>
|
||||
nnoremap <silent><buffer> <A-Right> :call nuwiki#commands#table_move_right()<CR>
|
||||
|
||||
" Folding — heading-block fold structure (matches lua/nuwiki/folding.lua).
|
||||
" Opt-out via `let g:nuwiki_no_folding = 1` (mirrors the Lua-side
|
||||
" `folding = false` toggle on `setup()`).
|
||||
if !get(g:, 'nuwiki_no_folding', 0)
|
||||
setlocal foldmethod=expr
|
||||
setlocal foldexpr=nuwiki#folding#expr()
|
||||
setlocal foldtext=nuwiki#folding#foldtext()
|
||||
let b:undo_ftplugin .= ' | setlocal foldmethod< foldexpr< foldtext<'
|
||||
endif
|
||||
|
||||
" Text objects — vimwiki parity (matches lua/nuwiki/textobjects.lua).
|
||||
" The `:<C-u>` clears any prefix count and the visual mode; the
|
||||
" autoload function re-establishes the selection at the right range.
|
||||
xnoremap <silent><buffer> ah :<C-u>call nuwiki#textobjects#heading(0, 0)<CR>
|
||||
onoremap <silent><buffer> ah :<C-u>call nuwiki#textobjects#heading(0, 0)<CR>
|
||||
xnoremap <silent><buffer> ih :<C-u>call nuwiki#textobjects#heading(1, 0)<CR>
|
||||
onoremap <silent><buffer> ih :<C-u>call nuwiki#textobjects#heading(1, 0)<CR>
|
||||
xnoremap <silent><buffer> aH :<C-u>call nuwiki#textobjects#heading(0, 1)<CR>
|
||||
onoremap <silent><buffer> aH :<C-u>call nuwiki#textobjects#heading(0, 1)<CR>
|
||||
xnoremap <silent><buffer> iH :<C-u>call nuwiki#textobjects#heading(1, 1)<CR>
|
||||
onoremap <silent><buffer> iH :<C-u>call nuwiki#textobjects#heading(1, 1)<CR>
|
||||
xnoremap <silent><buffer> al :<C-u>call nuwiki#textobjects#list_item(0)<CR>
|
||||
onoremap <silent><buffer> al :<C-u>call nuwiki#textobjects#list_item(0)<CR>
|
||||
xnoremap <silent><buffer> il :<C-u>call nuwiki#textobjects#list_item(1)<CR>
|
||||
onoremap <silent><buffer> il :<C-u>call nuwiki#textobjects#list_item(1)<CR>
|
||||
xnoremap <silent><buffer> a\ :<C-u>call nuwiki#textobjects#table_cell(0)<CR>
|
||||
onoremap <silent><buffer> a\ :<C-u>call nuwiki#textobjects#table_cell(0)<CR>
|
||||
xnoremap <silent><buffer> i\ :<C-u>call nuwiki#textobjects#table_cell(1)<CR>
|
||||
onoremap <silent><buffer> i\ :<C-u>call nuwiki#textobjects#table_cell(1)<CR>
|
||||
xnoremap <silent><buffer> ac :<C-u>call nuwiki#textobjects#table_column(0)<CR>
|
||||
onoremap <silent><buffer> ac :<C-u>call nuwiki#textobjects#table_column(0)<CR>
|
||||
xnoremap <silent><buffer> ic :<C-u>call nuwiki#textobjects#table_column(1)<CR>
|
||||
onoremap <silent><buffer> ic :<C-u>call nuwiki#textobjects#table_column(1)<CR>
|
||||
endif
|
||||
|
||||
finish
|
||||
|
||||
Reference in New Issue
Block a user