From 4710ba03c84d59e36c68e91ddb97410ef70cfc6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Fr=C3=B3es=20Franco?= Date: Sun, 31 May 2026 20:16:10 +0000 Subject: [PATCH] feat(commands): VimwikiListChangeLvl -range -nargs=+ (P3 parity) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upstream is `-range -nargs=+` (change_level(line1, line2, direction, plus_children)); nuwiki was -nargs=? and range-less, so `:1,3VimwikiListChangeLvl increase 0` raised E481/E488 and the level change never spanned a selection. All four defs (Vim+Neovim × Vimwiki+Nuwiki) are now -range -nargs=+ and forward , , . list_change_lvl(line1, line2, direction, [plus_children]) (both clients) parses the required direction + optional subtree flag and applies the change to every list item in the range via the existing over_range helper. Tests: cmd.ListChangeLvl_range_indents (test-keymaps.lua) + cmd.VimwikiListChangeLvl_accepts_range_and_args (test-keymaps-vim.vim). Co-Authored-By: Claude Opus 4.8 (1M context) --- autoload/nuwiki/commands.vim | 14 +++++++++----- development/tests/test-keymaps-vim.vim | 18 ++++++++++++++++++ development/tests/test-keymaps.lua | 15 +++++++++++++++ development/vimwiki-gap.md | 10 +++++++++- ftplugin/vimwiki.vim | 8 ++++---- lua/nuwiki/commands.lua | 11 +++++++---- 6 files changed, 62 insertions(+), 14 deletions(-) diff --git a/autoload/nuwiki/commands.vim b/autoload/nuwiki/commands.vim index e672921..249c404 100644 --- a/autoload/nuwiki/commands.vim +++ b/autoload/nuwiki/commands.vim @@ -800,11 +800,15 @@ function! nuwiki#commands#list_change_level(delta, whole_subtree) abort call s:exec('nuwiki.list.changeLevel', l:args) endfunction -" `:VimwikiListChangeLvl decrease|increase 0` compat entry. -function! nuwiki#commands#list_change_lvl(...) abort - let l:dir = a:0 >= 1 ? a:1 : 'increase' - let l:delta = (l:dir ==# 'increase' || l:dir ==# 'indent') ? 1 : -1 - call nuwiki#commands#list_change_level(l:delta, 0) +" `:[range]VimwikiListChangeLvl {increase|decrease} [plus_children]` — upstream +" is `-range -nargs=+`: direction is required, the optional second arg cascades +" the level change to each item's subtree, and a range applies it to every list +" item in the selection. +function! nuwiki#commands#list_change_lvl(line1, line2, direction, ...) abort + let l:delta = (a:direction ==# 'increase' || a:direction ==# 'indent') ? 1 : -1 + let l:children = a:0 >= 1 ? (str2nr(a:1) != 0) : 0 + call s:over_range(a:line1, a:line2, + \ { -> nuwiki#commands#list_change_level(l:delta, l:children) }) endfunction " Cycle the list marker through vimwiki's canonical order. diff --git a/development/tests/test-keymaps-vim.vim b/development/tests/test-keymaps-vim.vim index 6542f88..3bc7bf4 100644 --- a/development/tests/test-keymaps-vim.vim +++ b/development/tests/test-keymaps-vim.vim @@ -651,6 +651,24 @@ call s:record( \ 'cmd.VimwikiTable_accepts_cols_rows', \ 'err=' . s:tbl_err) +" ===== :VimwikiListChangeLvl -range -nargs=+ ===== +" Was -nargs=? (range-less): `:1,3VimwikiListChangeLvl increase 0` raised E481 +" (no range allowed) and/or E488 (trailing chars). The level change is an LSP +" roundtrip (no server here), so assert only the attribute parse: no E481/E488. +call s:set_buf(['- a', '- b', '- c']) +let s:lcl_err = '' +try + silent 1,3VimwikiListChangeLvl increase 0 +catch /E481\|E488/ + let s:lcl_err = v:exception +catch + " non-attribute error (e.g. no LSP) is expected and fine here. +endtry +call s:record( + \ s:lcl_err ==# '' ? 1 : 0, + \ 'cmd.VimwikiListChangeLvl_accepts_range_and_args', + \ 'err=' . s:lcl_err) + " ===== Wrap up ===== call add(s:results, '') diff --git a/development/tests/test-keymaps.lua b/development/tests/test-keymaps.lua index da28837..ac82176 100644 --- a/development/tests/test-keymaps.lua +++ b/development/tests/test-keymaps.lua @@ -834,6 +834,21 @@ vim.defer_fn(function() error('want 5 table lines (hdr+sep+3 rows), got ' .. #tbl) end end) + -- `:[range]VimwikiListChangeLvl {dir} [plus_children]` — now -range -nargs=+ + -- (was -nargs=?, range-less). A 1,3 range with `increase` must indent the + -- items that have somewhere to nest (the 2nd item under the 1st). + tobj_case('cmd.ListChangeLvl_range_indents', function() + set_buf({ '- a', '- b', '- c' }) + vim.cmd('1,3VimwikiListChangeLvl increase 0') + local done = vim.wait(2000, function() + local l = vim.api.nvim_buf_get_lines(0, 0, -1, false) + return l[2] ~= nil and l[2]:match('^%s%s*%-') ~= nil + end, 30) + if not done then + error('range list-change-lvl did not indent: ' + .. vim.inspect(vim.api.nvim_buf_get_lines(0, 0, -1, false))) + end + end) -- `:VimwikiNormalizeLink 1` (the arg is upstream's visual flag; the command -- is -nargs=? not -range, so no `'<,'>`) wraps the last visual selection. tobj_case('cmd.normalize_link_visual_wraps_selection', function() diff --git a/development/vimwiki-gap.md b/development/vimwiki-gap.md index 27880db..64a1bc2 100644 --- a/development/vimwiki-gap.md +++ b/development/vimwiki-gap.md @@ -183,7 +183,15 @@ fix site. cols/rows). Covered by `cmd.VimwikiTable_passes_cols_and_rows` (`test-keymaps.lua`, asserts a `:VimwikiTable 4 3` → 4-col, 3-row table) and `cmd.VimwikiTable_accepts_cols_rows` (`test-keymaps-vim.vim`, no E488). -- [ ] `VimwikiListChangeLvl` is `-nargs=?` vs upstream `-range -nargs=+`. +- [x] `VimwikiListChangeLvl` was `-nargs=?` (range-less) vs upstream + `-range -nargs=+`. _Fix:_ all four defs are now `-range -nargs=+` passing + `, , `; `list_change_lvl(line1, line2, direction, + [plus_children])` (both clients) parses the required direction + optional + subtree flag and applies the level change to every list item in the range + via the existing `over_range` helper. Covered by + `cmd.ListChangeLvl_range_indents` (`test-keymaps.lua`) and + `cmd.VimwikiListChangeLvl_accepts_range_and_args` (`test-keymaps-vim.vim`, + no E481/E488). - [x] `VimwikiRebuildTags` `-bang` ("rebuild all") — `:…RebuildTags!` now passes `{ all: true }`; the server (`tags_rebuild`) re-indexes **every** configured wiki (via `wikis_snapshot()`) instead of just the current one. `-bang` added to diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index 3f6c7ad..a9b183e 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -87,7 +87,7 @@ if !has('nvim') command! -buffer -bang VimwikiRemoveDone if 0 | call nuwiki#commands#list_remove_done_all() | else | call nuwiki#commands#list_remove_done() | endif command! -buffer -range VimwikiRemoveSingleCB call nuwiki#commands#list_remove_checkbox() command! -buffer VimwikiRemoveCBInList call nuwiki#commands#list_remove_checkbox_in_list() - command! -buffer -nargs=? VimwikiListChangeLvl call nuwiki#commands#list_change_lvl() + command! -buffer -range -nargs=+ VimwikiListChangeLvl call nuwiki#commands#list_change_lvl(, , ) command! -buffer -nargs=? VimwikiNormalizeLink call nuwiki#commands#normalize_link() command! -buffer VimwikiRenumberList call nuwiki#commands#list_renumber() command! -buffer VimwikiRenumberAllLists call nuwiki#commands#list_renumber_all() @@ -172,7 +172,7 @@ if !has('nvim') command! -buffer -bang NuwikiRemoveDone if 0 | call nuwiki#commands#list_remove_done_all() | else | call nuwiki#commands#list_remove_done() | endif command! -buffer -range NuwikiRemoveCheckbox call nuwiki#commands#list_remove_checkbox() command! -buffer NuwikiRemoveCheckboxInList call nuwiki#commands#list_remove_checkbox_in_list() - command! -buffer -nargs=? NuwikiListChangeLvl call nuwiki#commands#list_change_lvl() + command! -buffer -range -nargs=+ NuwikiListChangeLvl call nuwiki#commands#list_change_lvl(, , ) command! -buffer NuwikiListToggle call nuwiki#commands#list_toggle_or_add_checkbox() command! -buffer -range NuwikiIncrementListItem call nuwiki#commands#list_cycle_symbol_range(1, , ) command! -buffer -range NuwikiDecrementListItem call nuwiki#commands#list_cycle_symbol_range(-1, , ) @@ -435,7 +435,7 @@ command! -buffer -nargs=1 VimwikiChangeSymbolInListTo lua require('nuwiki.comman command! -buffer -bang VimwikiRemoveDone lua require('nuwiki.commands')[('' == '!') and 'list_remove_done_all' or 'list_remove_done']() command! -buffer -range VimwikiRemoveSingleCB lua require('nuwiki.commands').list_remove_checkbox() command! -buffer VimwikiRemoveCBInList lua require('nuwiki.commands').list_remove_checkbox_in_list() -command! -buffer -nargs=? VimwikiListChangeLvl lua require('nuwiki.commands').list_change_lvl() +command! -buffer -range -nargs=+ VimwikiListChangeLvl lua require('nuwiki.commands').list_change_lvl(, , ) command! -buffer -nargs=? VimwikiNormalizeLink lua require('nuwiki.commands').normalize_link() command! -buffer VimwikiRenumberList lua require('nuwiki.commands').list_renumber() command! -buffer VimwikiRenumberAllLists lua require('nuwiki.commands').list_renumber_all() @@ -520,7 +520,7 @@ command! -buffer NuwikiTabDropLink lua require('nuwiki.commands').follow_ command! -buffer -bang NuwikiRemoveDone lua require('nuwiki.commands')[('' == '!') and 'list_remove_done_all' or 'list_remove_done']() command! -buffer -range NuwikiRemoveCheckbox lua require('nuwiki.commands').list_remove_checkbox() command! -buffer NuwikiRemoveCheckboxInList lua require('nuwiki.commands').list_remove_checkbox_in_list() -command! -buffer -nargs=? NuwikiListChangeLvl lua require('nuwiki.commands').list_change_lvl() +command! -buffer -range -nargs=+ NuwikiListChangeLvl lua require('nuwiki.commands').list_change_lvl(, , ) command! -buffer NuwikiListToggle lua require('nuwiki.commands').list_toggle_or_add_checkbox() command! -buffer -range NuwikiIncrementListItem lua require('nuwiki.commands').list_cycle_symbol_range(1, , ) command! -buffer -range NuwikiDecrementListItem lua require('nuwiki.commands').list_cycle_symbol_range(-1, , ) diff --git a/lua/nuwiki/commands.lua b/lua/nuwiki/commands.lua index 78237d5..df93b82 100644 --- a/lua/nuwiki/commands.lua +++ b/lua/nuwiki/commands.lua @@ -585,11 +585,14 @@ function M.list_change_level(delta, whole_subtree) exec('nuwiki.list.changeLevel', { args }) end --- Vimwiki's `:VimwikiListChangeLvl decrease|increase 0` keeps a single --- entry point. Forward to changeLevel. -function M.list_change_lvl(direction) +-- `:[range]VimwikiListChangeLvl {increase|decrease} [plus_children]` — upstream +-- is `-range -nargs=+`. Direction is required; the optional second arg cascades +-- to each item's subtree; a range applies it to every list item in the range. +function M.list_change_lvl(line1, line2, direction, plus_children) local delta = (direction == 'increase' or direction == 'indent') and 1 or -1 - M.list_change_level(delta, false) + local n = tonumber(plus_children) + local children = n ~= nil and n ~= 0 + over_range(line1, line2, function() M.list_change_level(delta, children) end) end --- Cycle the list marker forward (`direction = 1`) or backward