patch 8.0.1562: the terminal debugger can't set a breakpoint with the mouse v8.0.1562
authorBram Moolenaar <Bram@vim.org>
Sat, 3 Mar 2018 19:47:21 +0000 (20:47 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 3 Mar 2018 19:47:21 +0000 (20:47 +0100)
Problem:    The terminal debugger can't set a breakpoint with the mouse.
Solution:   Add popup menu entries.

runtime/doc/terminal.txt
runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
src/version.c

index 9a35341f76bb24d5764a65fb64d770e087110785..4bd0373befafc8f2c048b7213d2daea186d1f625 100644 (file)
@@ -7,8 +7,6 @@
 Terminal window support                                        *terminal*
 
 
-WARNING: THIS IS ONLY PARTLY IMPLEMENTED, ANYTHING CAN STILL CHANGE
-
 The terminal feature is optional, use this to check if your Vim has it: >
        echo has('terminal')
 If the result is "1" you have it.
@@ -40,7 +38,6 @@ If the result is "1" you have it.
 
 {Vi does not have any of these commands}
 {only available when compiled with the |+terminal| feature}
-
 The terminal feature requires the |+multi_byte|, |+job| and |+channel| features.
 
 ==============================================================================
@@ -481,7 +478,7 @@ program window      A terminal window for the executed program.  When "run" is
 
 The current window is used to show the source code.  When gdb pauses the
 source file location will be displayed, if possible.  A sign is used to
-highlight the current position (using highlight group debugPC).         
+highlight the current position, using highlight group debugPC.  
 
 If the buffer in the current window is modified, another window will be opened
 to display the current gdb position.
@@ -506,6 +503,7 @@ You should now have three windows:
     source  - where you started, has a window toolbar with buttons
     gdb            - you can type gdb commands here
     program - the executed program will use this window
+
 You can use CTRL-W CTRL-W or the mouse to move focus between windows.
 Put focus on the gdb window and type: >
        break ex_help
@@ -526,6 +524,8 @@ displayed:
 This way you can inspect the value of local variables.  You can also focus the
 gdb window and use a "print" command, e.g.: >
        print *eap
+If mouse pointer movements are working, Vim will also show a balloon when the
+mouse rests on text that can be evaluated by gdb.
 
 Now go back to the source window and put the cursor on the first line after
 the for loop, then type: >
@@ -561,38 +561,42 @@ Put focus on the gdb window to type commands there.  Some common ones are:
 - frame N      go to the Nth stack frame
 - continue     continue execution
 
-In the window showing the source code these commands can used to control gdb:
:Run [args]       run the program with [args] or the previous arguments
- :Arguments {args}  set arguments for the next :Run
+In the window showing the source code these commands can be used to control gdb:
`:Run` [args]     run the program with [args] or the previous arguments
+ `:Arguments` {args}  set arguments for the next `:Run`
 
:Break                set a breakpoint at the current line; a sign will be displayed
:Delete       delete a breakpoint at the current line
`:Break`      set a breakpoint at the current line; a sign will be displayed
`:Clear`      delete the breakpoint at the current line
 
:Step         execute the gdb "step" command
:Over         execute the gdb "next" command (:Next is a Vim command)
:Finish       execute the gdb "finish" command
:Continue     execute the gdb "continue" command
:Stop         interrupt the program
`:Step`       execute the gdb "step" command
`:Over`       execute the gdb "next" command (`:Next` is a Vim command)
`:Finish`     execute the gdb "finish" command
`:Continue`   execute the gdb "continue" command
`:Stop`       interrupt the program
 
 If 'mouse' is set the plugin adds a window toolbar with these entries:
-  Step         :Step
-  Next         :Over
-  Finish       :Finish
-  Cont         :Continue
-  Stop         :Stop
-  Eval         :Evaluate
+  Step         `:Step`
+  Next         `:Over`
+  Finish       `:Finish`
+  Cont         `:Continue`
+  Stop         `:Stop`
+  Eval         `:Evaluate`
 This way you can use the mouse to perform the most common commands.  You need
 to have the 'mouse' option set to enable mouse clicks.
 
+You can add the window toolbar in other windows you open with: >
+  :Winbar
+
 
 Inspecting variables ~
                                                        *termdebug-variables*
:Evaluate         evaluate the expression under the cursor
K                 same
:Evaluate {expr}   evaluate {expr}
:'<,'>Evaluate            evaluate the Visually selected text
`:Evaluate`       evaluate the expression under the cursor
`K`               same
`:Evaluate` {expr}   evaluate {expr}
`:'<,'>Evaluate`     evaluate the Visually selected text
 
 This is similar to using "print" in the gdb window.
+You can usually shorten `:Evaluate` to `:Ev`.
 
 
 Other commands ~
@@ -609,17 +613,21 @@ will break the debugger.
 
 
 Customizing ~
-                                                       *termdebug-customizing*
+
+GDB command                                             *termdebug-customizing*
+
 To change the name of the gdb command, set the "termdebugger" variable before
 invoking `:Termdebug`: >
        let termdebugger = "mygdb"
-<                                              *gdb-version*
+<                                                      *gdb-version*
 Only debuggers fully compatible with gdb will work.  Vim uses the GDB/MI
 interface.  This probably requires gdb version 7.12.  if you get this error:
        Undefined command: "new-ui". Try "help".~
 Then your gdb is too old.
 
-                                       *hl-debugPC* *hl-debugBreakpoint*
+
+Colors                                         *hl-debugPC* *hl-debugBreakpoint*
+
 The color of the signs can be adjusted with these highlight groups:
 - debugPC              the current position
 - debugBreakpoint      a breakpoint
@@ -632,6 +640,20 @@ When 'background' is "dark":
   hi debugPC term=reverse ctermbg=darkblue guibg=darkblue
   hi debugBreakpoint term=reverse ctermbg=red guibg=red
 
+
+Popup menu                                             *termdebug_popup*
+
+By default the Termdebug plugin sets 'mousemodel' to "popup_setpos" and adds
+these entries to the popup menu:
+       Set breakpoint          `:Break`
+       Clear breakpoint        `:Clear`
+       Evaluate                `:Evaluate`
+If you don't want this then disable it with: >
+       let g:termdebug_popup = 0
+
+
+Vim window width                                               *termdebug_wide*
+
 To change the width of the Vim window when debugging starts, and use a
 vertical split: >
   let g:termdebug_wide = 163
index 84ac0de424950361db279abd94d2b28cbf036d47..add0de981714242b7ede9149243a62439c6a1720 100644 (file)
@@ -201,7 +201,7 @@ endfunc
 " Install commands in the current window to control the debugger.
 func s:InstallCommands()
   command Break call s:SetBreakpoint()
-  command Delete call s:DeleteBreakpoint()
+  command Clear call s:ClearBreakpoint()
   command Step call s:SendCommand('-exec-step')
   command Over call s:SendCommand('-exec-next')
   command Finish call s:SendCommand('-exec-finish')
@@ -212,24 +212,42 @@ func s:InstallCommands()
   command -range -nargs=* Evaluate call s:Evaluate(<range>, <q-args>)
   command Gdb call win_gotoid(s:gdbwin)
   command Program call win_gotoid(s:ptywin)
+  command Winbar call s:InstallWinbar()
 
   " TODO: can the K mapping be restored?
   nnoremap K :Evaluate<CR>
 
   if has('menu') && &mouse != ''
-    nnoremenu WinBar.Step :Step<CR>
-    nnoremenu WinBar.Next :Over<CR>
-    nnoremenu WinBar.Finish :Finish<CR>
-    nnoremenu WinBar.Cont :Continue<CR>
-    nnoremenu WinBar.Stop :Stop<CR>
-    nnoremenu WinBar.Eval :Evaluate<CR>
+    call s:InstallWinbar()
+
+    if !exists('g:termdebug_popup') || g:termdebug_popup != 0
+      let s:saved_mousemodel = &mousemodel
+      let &mousemodel = 'popup_setpos'
+      an 1.200 PopUp.-SEP3-    <Nop>
+      an 1.210 PopUp.Set\ breakpoint   :Break<CR>
+      an 1.220 PopUp.Clear\ breakpoint :Clear<CR>
+      an 1.230 PopUp.Evaluate          :Evaluate<CR>
+    endif
   endif
 endfunc
 
+let s:winbar_winids = []
+
+" Install the window toolbar in the current window.
+func s:InstallWinbar()
+  nnoremenu WinBar.Step   :Step<CR>
+  nnoremenu WinBar.Next   :Over<CR>
+  nnoremenu WinBar.Finish :Finish<CR>
+  nnoremenu WinBar.Cont   :Continue<CR>
+  nnoremenu WinBar.Stop   :Stop<CR>
+  nnoremenu WinBar.Eval   :Evaluate<CR>
+  call add(s:winbar_winids, win_getid(winnr()))
+endfunc
+
 " Delete installed debugger commands in the current window.
 func s:DeleteCommands()
   delcommand Break
-  delcommand Delete
+  delcommand Clear
   delcommand Step
   delcommand Over
   delcommand Finish
@@ -240,16 +258,34 @@ func s:DeleteCommands()
   delcommand Evaluate
   delcommand Gdb
   delcommand Program
+  delcommand Winbar
 
   nunmap K
 
   if has('menu')
-    aunmenu WinBar.Step
-    aunmenu WinBar.Next
-    aunmenu WinBar.Finish
-    aunmenu WinBar.Cont
-    aunmenu WinBar.Stop
-    aunmenu WinBar.Eval
+    " Remove the WinBar entries from all windows where it was added.
+    let curwinid = win_getid(winnr())
+    for winid in s:winbar_winids
+      if win_gotoid(winid)
+       aunmenu WinBar.Step
+       aunmenu WinBar.Next
+       aunmenu WinBar.Finish
+       aunmenu WinBar.Cont
+       aunmenu WinBar.Stop
+       aunmenu WinBar.Eval
+      endif
+    endfor
+    call win_gotoid(curwinid)
+    let s:winbar_winids = []
+
+    if exists('s:saved_mousemodel')
+      let &mousemodel = s:saved_mousemodel
+      unlet s:saved_mousemodel
+      aunmenu PopUp.-SEP3-
+      aunmenu PopUp.Set\ breakpoint
+      aunmenu PopUp.Clear\ breakpoint
+      aunmenu PopUp.Evaluate
+    endif
   endif
 
   exe 'sign unplace ' . s:pc_id
@@ -278,8 +314,8 @@ func s:SetBreakpoint()
   endif
 endfunc
 
-" :Delete - Delete a breakpoint at the cursor position.
-func s:DeleteBreakpoint()
+" :Clear - Delete a breakpoint at the cursor position.
+func s:ClearBreakpoint()
   let fname = fnameescape(expand('%:p'))
   let lnum = line('.')
   for [key, val] in items(s:breakpoints)
index ae51d723e34add04a1089629304a0344bcdb0764..200ed6f2ff048188ef1f3aba6053b24a8486335d 100644 (file)
@@ -778,6 +778,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1562,
 /**/
     1561,
 /**/