diff options
author | Ubaldo Tiberi <ubaldo.tiberi@google.com> | 2024-06-18 20:18:20 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2024-06-18 20:24:54 +0200 |
commit | a48637c105ce5ccf6f3296958c889d15dc3faaa4 (patch) | |
tree | 20871867481477aab5e6c89617584ca4e049abad /runtime/pack/dist/opt | |
parent | 9718ed7ab989c0a0be88a0d749f24321eb0e6af1 (diff) |
patch 9.1.0497: termdebug can be further improvedv9.1.0497
Problem: termdebug can be further improved
Solution: refactor save/restore, update docs,
add a new save/restore test (Ubaldo Tiberi)
closes: #15032
Signed-off-by: Ubaldo Tiberi <ubaldo.tiberi@google.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'runtime/pack/dist/opt')
-rw-r--r-- | runtime/pack/dist/opt/termdebug/plugin/termdebug.vim | 156 |
1 files changed, 68 insertions, 88 deletions
diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim index d24ae578c2..4e48ab6890 100644 --- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim +++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @@ -75,9 +75,11 @@ var varbufname: string var asmbufnr: number var asmbufname: string var promptbuf: number -# This is for the "debugged program" thing +# This is for the "debugged-program" thing var ptybufnr: number +var ptybufname: string var commbufnr: number +var commbufname: string var gdbjob: job var gdb_channel: channel @@ -110,7 +112,7 @@ var evalexpr: string # Remember the old value of 'signcolumn' for each buffer that it's set in, so # that we can restore the value for all buffers. var signcolumn_buflist: list<number> -var save_columns: number +var saved_columns: number var allleft: bool # This was s:vertical but I cannot use vertical as variable name @@ -120,9 +122,9 @@ var winbar_winids: list<number> var saved_mousemodel: string -var k_map_saved: dict<any> -var plus_map_saved: dict<any> -var minus_map_saved: dict<any> +var saved_K_map: dict<any> +var saved_plus_map: dict<any> +var saved_minus_map: dict<any> def InitScriptVariables() @@ -155,8 +157,10 @@ def InitScriptVariables() asmbufnr = 0 asmbufname = 'Termdebug-asm-listing' promptbuf = 0 - # This is for the "debugged program" thing + # This is for the "debugged-program" thing + ptybufname = "debugged-program" ptybufnr = 0 + commbufname = "gdb-communication" commbufnr = 0 gdbjob = null_job @@ -190,16 +194,16 @@ def InitScriptVariables() # Remember the old value of 'signcolumn' for each buffer that it's set in, so # that we can restore the value for all buffers. signcolumn_buflist = [bufnr()] - save_columns = 0 + saved_columns = &columns winbar_winids = [] - k_map_saved = null_dict - plus_map_saved = null_dict - minus_map_saved = null_dict + saved_K_map = maparg('K', 'n', 0, 1) + saved_plus_map = maparg('+', 'n', 0, 1) + saved_minus_map = maparg('-', 'n', 0, 1) if has('menu') - saved_mousemodel = null_string + saved_mousemodel = &mousemodel endif enddef # The command that starts debugging, e.g. ":Termdebug vim". @@ -292,7 +296,6 @@ def StartDebug_internal(dict: dict<any>) endif if wide > 0 if &columns < wide - save_columns = &columns &columns = wide # If we make the Vim window wider, use the whole left half for the debug # windows. @@ -328,11 +331,10 @@ enddef # Use when debugger didn't start or ended. def CloseBuffers() - var bufnames = ['debugged\ program', 'gdb\ communication', asmbufname, varbufname] - for bufname in bufnames - var buf_nr = bufnr(bufname) + var buf_numbers = [ptybufnr, commbufnr, asmbufnr, varbufnr] + for buf_nr in buf_numbers if buf_nr > 0 && bufexists(buf_nr) - exe $'bwipe! {bufname}' + exe $'bwipe! {buf_nr}' endif endfor @@ -340,7 +342,6 @@ def CloseBuffers() gdbwin = 0 enddef -# IsGdbRunning(): bool may be a better name? def IsGdbStarted(): bool var gdbproc_status = job_status(term_getjob(gdbbufnr)) if gdbproc_status !=# 'run' @@ -355,7 +356,7 @@ enddef # Open a terminal window without a job, to run the debugged program in. def StartDebug_term(dict: dict<any>) ptybufnr = term_start('NONE', { - term_name: 'debugged program', + term_name: ptybufname, vertical: vvertical}) if ptybufnr == 0 Echoerr('Failed to open the program terminal window') @@ -376,7 +377,7 @@ def StartDebug_term(dict: dict<any>) # Create a hidden terminal window to communicate with gdb commbufnr = term_start('NONE', { - term_name: 'gdb communication', + term_name: commbufname, out_cb: function('CommOutput'), hidden: 1 }) @@ -872,16 +873,12 @@ enddef def EndDebugCommon() var curwinid = win_getid() - - if ptybufnr > 0 && bufexists(ptybufnr) - exe $'bwipe! {ptybufnr}' - endif - if asmbufnr > 0 && bufexists(asmbufnr) - exe $'bwipe! {asmbufnr}' - endif - if varbufnr > 0 && bufexists(varbufnr) - exe $'bwipe! {varbufnr}' - endif + var buf_numbers = [ptybufnr, asmbufnr, varbufnr] + for buf_nr in buf_numbers + if buf_nr > 0 && bufexists(buf_nr) + exe $'bwipe! {buf_nr}' + endif + endfor running = false # Restore 'signcolumn' in all buffers for which it was set. @@ -904,9 +901,7 @@ def EndDebugCommon() win_gotoid(curwinid) - if save_columns > 0 - &columns = save_columns - endif + &columns = saved_columns if has("balloon_eval") || has("balloon_eval_term") set balloonexpr= @@ -1137,8 +1132,7 @@ def InstallCommands() endif if map - k_map_saved = maparg('K', 'n', 0, 1) - if !empty(k_map_saved) && !k_map_saved.buffer || empty(k_map_saved) + if !empty(saved_K_map) && !saved_K_map.buffer || empty(saved_K_map) nnoremap K :Evaluate<CR> endif endif @@ -1148,8 +1142,7 @@ def InstallCommands() map = get(g:termdebug_config, 'map_plus', 1) endif if map - plus_map_saved = maparg('+', 'n', 0, 1) - if !empty(plus_map_saved) && !plus_map_saved.buffer || empty(plus_map_saved) + if !empty(saved_plus_map) && !saved_plus_map.buffer || empty(saved_plus_map) nnoremap <expr> + $'<Cmd>{v:count1}Up<CR>' endif endif @@ -1159,8 +1152,7 @@ def InstallCommands() map = get(g:termdebug_config, 'map_minus', 1) endif if map - minus_map_saved = maparg('-', 'n', 0, 1) - if !empty(minus_map_saved) && !minus_map_saved.buffer || empty(minus_map_saved) + if !empty(saved_minus_map) && !saved_minus_map.buffer || empty(saved_minus_map) nnoremap <expr> - $'<Cmd>{v:count1}Down<CR>' endif endif @@ -1177,7 +1169,6 @@ def InstallCommands() endif if pup - saved_mousemodel = &mousemodel &mousemodel = 'popup_setpos' an 1.200 PopUp.-SEP3- <Nop> an 1.210 PopUp.Set\ breakpoint :Break<CR> @@ -1232,38 +1223,32 @@ def DeleteCommands() delcommand Var delcommand Winbar - if k_map_saved isnot null_dict - if !empty(k_map_saved) && k_map_saved.buffer - # pass - elseif !empty(k_map_saved) && !k_map_saved.buffer - nunmap K - mapset(k_map_saved) - elseif empty(k_map_saved) - silent! nunmap K - endif - k_map_saved = null_dict - endif - if plus_map_saved isnot null_dict - if !empty(plus_map_saved) && plus_map_saved.buffer - # pass - elseif !empty(plus_map_saved) && !plus_map_saved.buffer - nunmap + - mapset(plus_map_saved) - elseif empty(plus_map_saved) - silent! nunmap + - endif - plus_map_saved = null_dict - endif - if minus_map_saved isnot null_dict - if !empty(minus_map_saved) && minus_map_saved.buffer - # pass - elseif !empty(minus_map_saved) && !minus_map_saved.buffer - nunmap - - mapset(minus_map_saved) - elseif empty(minus_map_saved) - silent! nunmap - - endif - minus_map_saved = null_dict + + if !empty(saved_K_map) && saved_K_map.buffer + # pass + elseif !empty(saved_K_map) && !saved_K_map.buffer + nunmap K + mapset(saved_K_map) + elseif empty(saved_K_map) + silent! nunmap K + endif + + if !empty(saved_plus_map) && saved_plus_map.buffer + # pass + elseif !empty(saved_plus_map) && !saved_plus_map.buffer + nunmap + + mapset(saved_plus_map) + elseif empty(saved_plus_map) + silent! nunmap + + endif + + if !empty(saved_minus_map) && saved_minus_map.buffer + # pass + elseif !empty(saved_minus_map) && !saved_minus_map.buffer + nunmap - + mapset(saved_minus_map) + elseif empty(saved_minus_map) + silent! nunmap - endif if has('menu') @@ -1280,21 +1265,18 @@ def DeleteCommands() endif endfor win_gotoid(curwinid) - winbar_winids = [] - - if saved_mousemodel isnot null_string - &mousemodel = saved_mousemodel - saved_mousemodel = null_string - try - aunmenu PopUp.-SEP3- - aunmenu PopUp.Set\ breakpoint - aunmenu PopUp.Clear\ breakpoint - aunmenu PopUp.Run\ until - aunmenu PopUp.Evaluate - catch - # ignore any errors in removing the PopUp menu - endtry - endif + # winbar_winids = [] + + &mousemodel = saved_mousemodel + try + aunmenu PopUp.-SEP3- + aunmenu PopUp.Set\ breakpoint + aunmenu PopUp.Clear\ breakpoint + aunmenu PopUp.Run\ until + aunmenu PopUp.Evaluate + catch + # ignore any errors in removing the PopUp menu + endtry endif sign_unplace('TermDebug') @@ -1342,8 +1324,6 @@ def SetBreakpoint(at: string, tbreak=false) else cmd = $'-break-insert {AT}' endif - # OK - # echom $"cmsd: {cmd}" SendCommand(cmd) if do_continue ContinueCommand() |