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 <yebenmy@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
bennyyip
2025-09-02 20:06:20 +02:00
committed by Christian Brabandt
parent 1c36a85237
commit 884290ebf0
4 changed files with 26 additions and 3 deletions

View File

@ -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`.

View File

@ -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 <ubaldo.tiberi@gmail.com>
# WORK IN PROGRESS - The basics works stable, more to come
@ -139,6 +139,7 @@ var winbar_winids: list<number>
var saved_mousemodel: string
var saved_K_map: dict<any>
var saved_visual_K_map: dict<any>
var saved_plus_map: dict<any>
var saved_minus_map: dict<any>
@ -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<CR>
endif
if !empty(saved_visual_K_map) && !saved_visual_K_map.buffer || empty(saved_visual_K_map)
xnoremap K :Evaluate<CR>
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)

View File

@ -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"<cr>
xnoremap K :<C-U>echom "VK"<cr>
nnoremap - :echom "-"<cr>
nnoremap + :echom "+"<cr>
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<CR>', 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"<cr>', maparg('K', 'n', 0, 1).rhs)
call assert_equal(':<C-U>echom "VK"<cr>', maparg('K', 'x', 0, 1).rhs)
%bw!

View File

@ -724,6 +724,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1728,
/**/
1727,
/**/