Skip to content

Commit 884290e

Browse files
bennyyipchrisbra
authored andcommitted
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>
1 parent 1c36a85 commit 884290e

4 files changed

Lines changed: 26 additions & 3 deletions

File tree

runtime/doc/terminal.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*terminal.txt* For Vim version 9.1. Last change: 2025 Jul 08
1+
*terminal.txt* For Vim version 9.1. Last change: 2025 Sep 02
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1467,7 +1467,8 @@ Inspecting variables ~
14671467
`:Evaluate` evaluate the expression under the cursor
14681468
`K` same (see |termdebug_map_K| to disable)
14691469
`:Evaluate` {expr} evaluate {expr}
1470-
`:'<,'>Evaluate` evaluate the Visually selected text
1470+
`:'<,'>Evaluate`
1471+
`{Visual}K` evaluate the Visually selected text
14711472

14721473
This is similar to using "print" in the gdb window.
14731474
You can usually shorten `:Evaluate` to `:Ev`.

runtime/pack/dist/opt/termdebug/plugin/termdebug.vim

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ vim9script
44

55
# Author: Bram Moolenaar
66
# Copyright: Vim license applies, see ":help license"
7-
# Last Change: 2025 Aug 24
7+
# Last Change: 2025 Sep 02
88
# Converted to Vim9: Ubaldo Tiberi <ubaldo.tiberi@gmail.com>
99

1010
# WORK IN PROGRESS - The basics works stable, more to come
@@ -139,6 +139,7 @@ var winbar_winids: list<number>
139139
var saved_mousemodel: string
140140

141141
var saved_K_map: dict<any>
142+
var saved_visual_K_map: dict<any>
142143
var saved_plus_map: dict<any>
143144
var saved_minus_map: dict<any>
144145

@@ -218,6 +219,7 @@ def InitScriptVariables()
218219
saved_K_map = maparg('K', 'n', false, true)
219220
saved_plus_map = maparg('+', 'n', false, true)
220221
saved_minus_map = maparg('-', 'n', false, true)
222+
saved_visual_K_map = maparg('K', 'x', false, true)
221223

222224
if has('menu')
223225
saved_mousemodel = &mousemodel
@@ -1204,6 +1206,9 @@ def InstallCommands()
12041206
if !empty(saved_K_map) && !saved_K_map.buffer || empty(saved_K_map)
12051207
nnoremap K :Evaluate<CR>
12061208
endif
1209+
if !empty(saved_visual_K_map) && !saved_visual_K_map.buffer || empty(saved_visual_K_map)
1210+
xnoremap K :Evaluate<CR>
1211+
endif
12071212
endif
12081213

12091214
map = true
@@ -1299,6 +1304,12 @@ def DeleteCommands()
12991304
silent! nunmap K
13001305
endif
13011306

1307+
if !empty(saved_visual_K_map) && !saved_visual_K_map.buffer
1308+
mapset(saved_visual_K_map)
1309+
elseif empty(saved_visual_K_map)
1310+
silent! xunmap K
1311+
endif
1312+
13021313
if !empty(saved_plus_map) && !saved_plus_map.buffer
13031314
mapset(saved_plus_map)
13041315
elseif empty(saved_plus_map)

src/testdir/test_plugin_termdebug.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,13 +367,15 @@ endfunc
367367
func Test_termdebug_mapping()
368368
%bw!
369369
call assert_true(maparg('K', 'n', 0, 1)->empty())
370+
call assert_true(maparg('K', 'x', 0, 1)->empty())
370371
call assert_true(maparg('-', 'n', 0, 1)->empty())
371372
call assert_true(maparg('+', 'n', 0, 1)->empty())
372373
Termdebug
373374
call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
374375
call WaitForAssert({-> assert_equal(3, winnr('$'))})
375376
wincmd b
376377
call assert_false(maparg('K', 'n', 0, 1)->empty())
378+
call assert_false(maparg('K', 'x', 0, 1)->empty())
377379
call assert_false(maparg('-', 'n', 0, 1)->empty())
378380
call assert_false(maparg('+', 'n', 0, 1)->empty())
379381
call assert_false(maparg('K', 'n', 0, 1).buffer)
@@ -385,21 +387,25 @@ func Test_termdebug_mapping()
385387
redraw!
386388
call WaitForAssert({-> assert_equal(1, winnr('$'))})
387389
call assert_true(maparg('K', 'n', 0, 1)->empty())
390+
call assert_true(maparg('K', 'x', 0, 1)->empty())
388391
call assert_true(maparg('-', 'n', 0, 1)->empty())
389392
call assert_true(maparg('+', 'n', 0, 1)->empty())
390393

391394
%bw!
392395
nnoremap K :echom "K"<cr>
396+
xnoremap K :<C-U>echom "VK"<cr>
393397
nnoremap - :echom "-"<cr>
394398
nnoremap + :echom "+"<cr>
395399
Termdebug
396400
call WaitForAssert({-> assert_true(get(g:, "termdebug_is_running", v:false))})
397401
call WaitForAssert({-> assert_equal(3, winnr('$'))})
398402
wincmd b
399403
call assert_false(maparg('K', 'n', 0, 1)->empty())
404+
call assert_false(maparg('K', 'x', 0, 1)->empty())
400405
call assert_false(maparg('-', 'n', 0, 1)->empty())
401406
call assert_false(maparg('+', 'n', 0, 1)->empty())
402407
call assert_false(maparg('K', 'n', 0, 1).buffer)
408+
call assert_false(maparg('K', 'x', 0, 1).buffer)
403409
call assert_false(maparg('-', 'n', 0, 1).buffer)
404410
call assert_false(maparg('+', 'n', 0, 1).buffer)
405411
call assert_equal(':Evaluate<CR>', maparg('K', 'n', 0, 1).rhs)
@@ -408,12 +414,15 @@ func Test_termdebug_mapping()
408414
redraw!
409415
call WaitForAssert({-> assert_equal(1, winnr('$'))})
410416
call assert_false(maparg('K', 'n', 0, 1)->empty())
417+
call assert_false(maparg('K', 'x', 0, 1)->empty())
411418
call assert_false(maparg('-', 'n', 0, 1)->empty())
412419
call assert_false(maparg('+', 'n', 0, 1)->empty())
413420
call assert_false(maparg('K', 'n', 0, 1).buffer)
421+
call assert_false(maparg('K', 'x', 0, 1).buffer)
414422
call assert_false(maparg('-', 'n', 0, 1).buffer)
415423
call assert_false(maparg('+', 'n', 0, 1).buffer)
416424
call assert_equal(':echom "K"<cr>', maparg('K', 'n', 0, 1).rhs)
425+
call assert_equal(':<C-U>echom "VK"<cr>', maparg('K', 'x', 0, 1).rhs)
417426

418427
%bw!
419428

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,8 @@ static char *(features[]) =
724724

725725
static int included_patches[] =
726726
{ /* Add new patch number below this line */
727+
/**/
728+
1728,
727729
/**/
728730
1727,
729731
/**/

0 commit comments

Comments
 (0)