]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(termdebug): handle buffer-local mappings properly
authorshane.xb.qian <shane.qian@foxmail.com>
Wed, 8 Nov 2023 20:44:48 +0000 (21:44 +0100)
committerChristian Brabandt <cb@256bit.org>
Wed, 8 Nov 2023 20:46:30 +0000 (21:46 +0100)
closes: #13475

Signed-off-by: shane.xb.qian <shane.qian@foxmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/tags
runtime/doc/terminal.txt
runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
src/testdir/test_termdebug.vim

index f450288fd8df15ee16dce7a125cf9bdde91ed24a..b36843fc53a942239d223df2a20effe62d04306f 100644 (file)
@@ -10434,6 +10434,7 @@ termdebug-customizing   terminal.txt    /*termdebug-customizing*
 termdebug-events       terminal.txt    /*termdebug-events*
 termdebug-example      terminal.txt    /*termdebug-example*
 termdebug-frames       terminal.txt    /*termdebug-frames*
+termdebug-mappings     terminal.txt    /*termdebug-mappings*
 termdebug-prompt       terminal.txt    /*termdebug-prompt*
 termdebug-starting     terminal.txt    /*termdebug-starting*
 termdebug-stepping     terminal.txt    /*termdebug-stepping*
index 70cfd7f9aa045179a65329df9ddb7012863b23f3..f17221ed1ffe64bf58eaa8f556f50a81e234e927 100644 (file)
@@ -1,4 +1,4 @@
-*terminal.txt* For Vim version 9.0.  Last change: 2023 Aug 23
+*terminal.txt* For Vim version 9.0.  Last change: 2023 Nov 08
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -42,6 +42,7 @@ If the result is "1" you have it.
       Other commands                           |termdebug-commands|
       Events                                   |termdebug-events|
       Prompt mode                              |termdebug-prompt|
+      Mappings                                 |termdebug-mappings|
       Communication                            |termdebug-communication|
       Customizing                              |termdebug-customizing|
 
@@ -1461,18 +1462,22 @@ Prompt mode can be used even when the |+terminal| feature is present with: >
 If there is no g:termdebug_config you can use: >
        let g:termdebug_use_prompt = 1
 <
-                                               *termdebug_map_K*
-The K key is normally mapped to |:Evaluate|. If you do not want this use: >
+Mappings ~
+                                       *termdebug_map_K* *termdebug-mappings*
+The K key is normally mapped to |:Evaluate| unless there already exists a
+buffer local mapping to K |map-local|.  If you do not want this use: >
        let g:termdebug_config['map_K'] = 0
 If there is no g:termdebug_config you can use: >
        let g:termdebug_map_K = 0
 <
                                                *termdebug_map_minus*
-The - key is normally mapped to |:Down|. If you do not want this use: >
+The - key is normally mapped to |:Down| unless there already exists a buffer
+local mapping to the - key.  If you do not want this use: >
        let g:termdebug_config['map_minus'] = 0
 <
                                                *termdebug_map_plus*
-The + key is normally mapped to |:Up|. If you do not want this use: >
+The + key is normally mapped to |:Up| unless there already exists a buffer
+local mapping to the + key.  If you do not want this use: >
        let g:termdebug_config['map_plus'] = 0
 <
                                                *termdebug_disasm_window*
index e6126ee6f38ce6986aec5391b2e39a0033947e44..144d083fa81132fba62d332dfcba980977833135 100644 (file)
@@ -2,7 +2,7 @@
 "
 " Author: Bram Moolenaar
 " Copyright: Vim license applies, see ":help license"
-" Last Change: 2023 Aug 23
+" Last Change: 2023 Nov 02
 "
 " WORK IN PROGRESS - The basics works stable, more to come
 " Note: In general you need at least GDB 7.12 because this provides the
@@ -990,7 +990,9 @@ func s:InstallCommands()
   endif
   if map
     let s:k_map_saved = maparg('K', 'n', 0, 1)
-    nnoremap K :Evaluate<CR>
+    if !empty(s:k_map_saved) && !s:k_map_saved.buffer || empty(s:k_map_saved)
+      nnoremap K :Evaluate<CR>
+    endif
   endif
 
   let map = 1
@@ -999,7 +1001,9 @@ func s:InstallCommands()
   endif
   if map
     let s:plus_map_saved = maparg('+', 'n', 0, 1)
-    nnoremap <expr> + $'<Cmd>{v:count1}Up<CR>'
+    if !empty(s:plus_map_saved) && !s:plus_map_saved.buffer || empty(s:plus_map_saved)
+      nnoremap <expr> + $'<Cmd>{v:count1}Up<CR>'
+    endif
   endif
 
   let map = 1
@@ -1008,7 +1012,9 @@ func s:InstallCommands()
   endif
   if map
     let s:minus_map_saved = maparg('-', 'n', 0, 1)
-    nnoremap <expr> - $'<Cmd>{v:count1}Down<CR>'
+    if !empty(s:minus_map_saved) && !s:minus_map_saved.buffer || empty(s:minus_map_saved)
+      nnoremap <expr> - $'<Cmd>{v:count1}Down<CR>'
+    endif
   endif
 
 
@@ -1080,26 +1086,29 @@ func s:DeleteCommands()
   delcommand Winbar
 
   if exists('s:k_map_saved')
-    if empty(s:k_map_saved)
+    if !empty(s:k_map_saved) && !s:k_map_saved.buffer
       nunmap K
-    else
       call mapset(s:k_map_saved)
+    elseif empty(s:k_map_saved)
+      nunmap K
     endif
     unlet s:k_map_saved
   endif
   if exists('s:plus_map_saved')
-    if empty(s:plus_map_saved)
+    if !empty(s:plus_map_saved) && !s:plus_map_saved.buffer
       nunmap +
-    else
       call mapset(s:plus_map_saved)
+    elseif empty(s:plus_map_saved)
+      nunmap +
     endif
     unlet s:plus_map_saved
   endif
   if exists('s:minus_map_saved')
-    if empty(s:minus_map_saved)
+    if !empty(s:minus_map_saved) && !s:minus_map_saved.buffer
       nunmap -
-    else
       call mapset(s:minus_map_saved)
+    elseif empty(s:minus_map_saved)
+      nunmap -
     endif
     unlet s:minus_map_saved
   endif
@@ -1774,3 +1783,5 @@ call s:InitAutocmd()
 
 let &cpo = s:keepcpo
 unlet s:keepcpo
+
+" vim: sw=2 sts=2 et
index eba2a617627cf565e0463e8f9977cb4e08cd8aff..23ec0e828c3a5c6048d3f35d1f2b10426ca07aee 100644 (file)
@@ -83,10 +83,83 @@ func Test_termdebug_basic()
   wincmd t
   quit!
   redraw!
+  call WaitForAssert({-> assert_equal(1, winnr('$'))})
   call assert_equal([], sign_getplaced('', #{group: 'TermDebug'})[0].signs)
 
   call delete('XTD_basic')
   %bw!
 endfunc
 
+func Test_termdebug_mapping()
+  %bw!
+  call assert_equal(maparg('K', 'n', 0, 1)->empty(), 1)
+  call assert_equal(maparg('-', 'n', 0, 1)->empty(), 1)
+  call assert_equal(maparg('+', 'n', 0, 1)->empty(), 1)
+  Termdebug
+  call WaitForAssert({-> assert_equal(3, winnr('$'))})
+  wincmd b
+  call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
+  call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
+  call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
+  call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
+  call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
+  call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
+  call assert_equal(maparg('K', 'n', 0, 1).rhs, ':Evaluate<CR>')
+  wincmd t
+  quit!
+  redraw!
+  call WaitForAssert({-> assert_equal(1, winnr('$'))})
+  call assert_equal(maparg('K', 'n', 0, 1)->empty(), 1)
+  call assert_equal(maparg('-', 'n', 0, 1)->empty(), 1)
+  call assert_equal(maparg('+', 'n', 0, 1)->empty(), 1)
+
+  %bw!
+  nnoremap K :echom "K"<cr>
+  nnoremap - :echom "-"<cr>
+  nnoremap + :echom "+"<cr>
+  Termdebug
+  call WaitForAssert({-> assert_equal(3, winnr('$'))})
+  wincmd b
+  call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
+  call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
+  call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
+  call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
+  call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
+  call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
+  call assert_equal(maparg('K', 'n', 0, 1).rhs, ':Evaluate<CR>')
+  wincmd t
+  quit!
+  redraw!
+  call WaitForAssert({-> assert_equal(1, winnr('$'))})
+  call assert_equal(maparg('K', 'n', 0, 1)->empty(), 0)
+  call assert_equal(maparg('-', 'n', 0, 1)->empty(), 0)
+  call assert_equal(maparg('+', 'n', 0, 1)->empty(), 0)
+  call assert_equal(maparg('K', 'n', 0, 1).buffer, 0)
+  call assert_equal(maparg('-', 'n', 0, 1).buffer, 0)
+  call assert_equal(maparg('+', 'n', 0, 1).buffer, 0)
+  call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "K"<cr>')
+
+  %bw!
+  nnoremap <buffer> K :echom "bK"<cr>
+  nnoremap <buffer> - :echom "b-"<cr>
+  nnoremap <buffer> + :echom "b+"<cr>
+  Termdebug
+  call WaitForAssert({-> assert_equal(3, winnr('$'))})
+  wincmd b
+  call assert_equal(maparg('K', 'n', 0, 1).buffer, 1)
+  call assert_equal(maparg('-', 'n', 0, 1).buffer, 1)
+  call assert_equal(maparg('+', 'n', 0, 1).buffer, 1)
+  call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
+  wincmd t
+  quit!
+  redraw!
+  call WaitForAssert({-> assert_equal(1, winnr('$'))})
+  call assert_equal(maparg('K', 'n', 0, 1).buffer, 1)
+  call assert_equal(maparg('-', 'n', 0, 1).buffer, 1)
+  call assert_equal(maparg('+', 'n', 0, 1).buffer, 1)
+  call assert_equal(maparg('K', 'n', 0, 1).rhs, ':echom "bK"<cr>')
+
+  %bw!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab