From 884290ebf0477ecfaa6a310bdcd16521822abc78 Mon Sep 17 00:00:00 2001 From: bennyyip Date: Tue, 2 Sep 2025 20:06:20 +0200 Subject: [PATCH] patch 9.1.1728: termdebug: cannot evaluate visual selected expression Problem: termdebug: cannot evaluate visual selected expression Solution: Add support for visual mode, mapped to K by default (bennyyip) closes: #18184 Signed-off-by: bennyyip Signed-off-by: Christian Brabandt --- runtime/doc/terminal.txt | 5 +++-- .../pack/dist/opt/termdebug/plugin/termdebug.vim | 13 ++++++++++++- src/testdir/test_plugin_termdebug.vim | 9 +++++++++ src/version.c | 2 ++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/runtime/doc/terminal.txt b/runtime/doc/terminal.txt index 2ca2d4be6f..eda0b8d489 100644 --- a/runtime/doc/terminal.txt +++ b/runtime/doc/terminal.txt @@ -1,4 +1,4 @@ -*terminal.txt* For Vim version 9.1. Last change: 2025 Jul 08 +*terminal.txt* For Vim version 9.1. Last change: 2025 Sep 02 VIM REFERENCE MANUAL by Bram Moolenaar @@ -1467,7 +1467,8 @@ Inspecting variables ~ `:Evaluate` evaluate the expression under the cursor `K` same (see |termdebug_map_K| to disable) `:Evaluate` {expr} evaluate {expr} - `:'<,'>Evaluate` evaluate the Visually selected text + `:'<,'>Evaluate` + `{Visual}K` evaluate the Visually selected text This is similar to using "print" in the gdb window. You can usually shorten `:Evaluate` to `:Ev`. diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim index e96ec749bd..3be4b135fd 100644 --- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim +++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @@ -4,7 +4,7 @@ vim9script # Author: Bram Moolenaar # Copyright: Vim license applies, see ":help license" -# Last Change: 2025 Aug 24 +# Last Change: 2025 Sep 02 # Converted to Vim9: Ubaldo Tiberi # WORK IN PROGRESS - The basics works stable, more to come @@ -139,6 +139,7 @@ var winbar_winids: list var saved_mousemodel: string var saved_K_map: dict +var saved_visual_K_map: dict var saved_plus_map: dict var saved_minus_map: dict @@ -218,6 +219,7 @@ def InitScriptVariables() saved_K_map = maparg('K', 'n', false, true) saved_plus_map = maparg('+', 'n', false, true) saved_minus_map = maparg('-', 'n', false, true) + saved_visual_K_map = maparg('K', 'x', false, true) if has('menu') saved_mousemodel = &mousemodel @@ -1204,6 +1206,9 @@ def InstallCommands() if !empty(saved_K_map) && !saved_K_map.buffer || empty(saved_K_map) nnoremap K :Evaluate endif + if !empty(saved_visual_K_map) && !saved_visual_K_map.buffer || empty(saved_visual_K_map) + xnoremap K :Evaluate + endif endif map = true @@ -1299,6 +1304,12 @@ def DeleteCommands() silent! nunmap K endif + if !empty(saved_visual_K_map) && !saved_visual_K_map.buffer + mapset(saved_visual_K_map) + elseif empty(saved_visual_K_map) + silent! xunmap K + endif + if !empty(saved_plus_map) && !saved_plus_map.buffer mapset(saved_plus_map) elseif empty(saved_plus_map) diff --git a/src/testdir/test_plugin_termdebug.vim b/src/testdir/test_plugin_termdebug.vim index 166f4f8663..fa7dd13bdf 100644 --- a/src/testdir/test_plugin_termdebug.vim +++ b/src/testdir/test_plugin_termdebug.vim @@ -367,6 +367,7 @@ endfunc func Test_termdebug_mapping() %bw! call assert_true(maparg('K', 'n', 0, 1)->empty()) + call assert_true(maparg('K', 'x', 0, 1)->empty()) call assert_true(maparg('-', 'n', 0, 1)->empty()) call assert_true(maparg('+', 'n', 0, 1)->empty()) Termdebug @@ -374,6 +375,7 @@ func Test_termdebug_mapping() call WaitForAssert({-> assert_equal(3, winnr('$'))}) wincmd b call assert_false(maparg('K', 'n', 0, 1)->empty()) + call assert_false(maparg('K', 'x', 0, 1)->empty()) call assert_false(maparg('-', 'n', 0, 1)->empty()) call assert_false(maparg('+', 'n', 0, 1)->empty()) call assert_false(maparg('K', 'n', 0, 1).buffer) @@ -385,11 +387,13 @@ func Test_termdebug_mapping() redraw! call WaitForAssert({-> assert_equal(1, winnr('$'))}) call assert_true(maparg('K', 'n', 0, 1)->empty()) + call assert_true(maparg('K', 'x', 0, 1)->empty()) call assert_true(maparg('-', 'n', 0, 1)->empty()) call assert_true(maparg('+', 'n', 0, 1)->empty()) %bw! nnoremap K :echom "K" + xnoremap K :echom "VK" nnoremap - :echom "-" nnoremap + :echom "+" Termdebug @@ -397,9 +401,11 @@ func Test_termdebug_mapping() call WaitForAssert({-> assert_equal(3, winnr('$'))}) wincmd b call assert_false(maparg('K', 'n', 0, 1)->empty()) + call assert_false(maparg('K', 'x', 0, 1)->empty()) call assert_false(maparg('-', 'n', 0, 1)->empty()) call assert_false(maparg('+', 'n', 0, 1)->empty()) call assert_false(maparg('K', 'n', 0, 1).buffer) + call assert_false(maparg('K', 'x', 0, 1).buffer) call assert_false(maparg('-', 'n', 0, 1).buffer) call assert_false(maparg('+', 'n', 0, 1).buffer) call assert_equal(':Evaluate', maparg('K', 'n', 0, 1).rhs) @@ -408,12 +414,15 @@ func Test_termdebug_mapping() redraw! call WaitForAssert({-> assert_equal(1, winnr('$'))}) call assert_false(maparg('K', 'n', 0, 1)->empty()) + call assert_false(maparg('K', 'x', 0, 1)->empty()) call assert_false(maparg('-', 'n', 0, 1)->empty()) call assert_false(maparg('+', 'n', 0, 1)->empty()) call assert_false(maparg('K', 'n', 0, 1).buffer) + call assert_false(maparg('K', 'x', 0, 1).buffer) call assert_false(maparg('-', 'n', 0, 1).buffer) call assert_false(maparg('+', 'n', 0, 1).buffer) call assert_equal(':echom "K"', maparg('K', 'n', 0, 1).rhs) + call assert_equal(':echom "VK"', maparg('K', 'x', 0, 1).rhs) %bw! diff --git a/src/version.c b/src/version.c index 7221f48235..c26e95b923 100644 --- a/src/version.c +++ b/src/version.c @@ -724,6 +724,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1728, /**/ 1727, /**/