diff options
-rw-r--r-- | runtime/doc/options.txt | 4 | ||||
-rw-r--r-- | runtime/pack/dist/opt/termdebug/plugin/termdebug.vim | 109 | ||||
-rw-r--r-- | src/nvim/buffer.c | 18 | ||||
-rw-r--r-- | src/nvim/options.lua | 8 | ||||
-rw-r--r-- | src/nvim/testdir/setup.vim | 3 | ||||
-rw-r--r-- | test/functional/options/num_options_spec.lua | 4 |
6 files changed, 124 insertions, 22 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index bf75bebb80..b6ea63449d 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -3134,7 +3134,7 @@ A jump table for the options with a short description can be found at |Q_op|. may change in later releases. *'iminsert'* *'imi'* -'iminsert' 'imi' number (default 0, 2 when an input method is supported) +'iminsert' 'imi' number (default 0) local to buffer Specifies whether :lmap or an Input Method (IM) is to be used in Insert mode. Valid values: @@ -3154,7 +3154,7 @@ A jump table for the options with a short description can be found at |Q_op|. It is also used for the argument of commands like "r" and "f". *'imsearch'* *'ims'* -'imsearch' 'ims' number (default 0, 2 when an input method is supported) +'imsearch' 'ims' number (default -1) local to buffer Specifies whether :lmap or an Input Method (IM) is to be used when entering a search pattern. Valid values: diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim index b002cad4c6..506179297a 100644 --- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim +++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim @@ -1,40 +1,133 @@ -" Debugger commands. +" Debugger plugin using gdb. " " WORK IN PROGRESS - much doesn't work yet " -" Open two terminal windows: +" Open two visible terminal windows: " 1. run a pty, as with ":term NONE" " 2. run gdb, passing the pty -" The current window is used to edit source code and follows gdb. +" The current window is used to view source code and follows gdb. +" +" A third terminal window is hidden, it is used for communication with gdb. +" +" The communication with gdb uses GDB/MI. See: +" https://sourceware.org/gdb/current/onlinedocs/gdb/GDB_002fMI.html " " Author: Bram Moolenaar -" Copyright: Vim license applies +" Copyright: Vim license applies, see ":help license" " In case this gets loaded twice. if exists(':Termdebug') finish endif +" The command that starts debugging, e.g. ":Termdebug vim". +" To end type "quit" in the gdb window. command -nargs=* -complete=file Termdebug call s:StartDebug(<q-args>) +" Name of the gdb command, defaults to "gdb". if !exists('debugger') let debugger = 'gdb' endif +" Sign used to highlight the line where the program has stopped. +sign define debugPC linehl=debugPC +if &background == 'light' + hi debugPC term=reverse ctermbg=lightblue guibg=lightblue +else + hi debugPC term=reverse ctermbg=darkblue guibg=darkblue +endif +let s:pc_id = 12 + func s:StartDebug(cmd) + let s:startwin = win_getid(winnr()) + let s:startsigncolumn = &signcolumn + " Open a terminal window without a job, to run the debugged program - let s:ptybuf = term_start('NONE', {}) - let pty = job_info(term_getjob(s:ptybuf))['tty'] + let s:ptybuf = term_start('NONE', { + \ 'term_name': 'gdb program', + \ }) + if s:ptybuf == 0 + echoerr 'Failed to open the program terminal window' + return + endif + let pty = job_info(term_getjob(s:ptybuf))['tty_out'] + + " Create a hidden terminal window to communicate with gdb + let s:commbuf = term_start('NONE', { + \ 'term_name': 'gdb communication', + \ 'out_cb': function('s:CommOutput'), + \ 'hidden': 1, + \ }) + if s:commbuf == 0 + echoerr 'Failed to open the communication terminal window' + exe 'bwipe! ' . s:ptybuf + return + endif + let commpty = job_info(term_getjob(s:commbuf))['tty_out'] " Open a terminal window to run the debugger. let cmd = [g:debugger, '-tty', pty, a:cmd] echomsg 'executing "' . join(cmd) . '"' let gdbbuf = term_start(cmd, { \ 'exit_cb': function('s:EndDebug'), - \ 'term_finish': 'close' + \ 'term_finish': 'close', \ }) + if gdbbuf == 0 + echoerr 'Failed to open the gdb terminal window' + exe 'bwipe! ' . s:ptybuf + exe 'bwipe! ' . s:commbuf + return + endif + + " Connect gdb to the communication pty, using the GDB/MI interface + call term_sendkeys(gdbbuf, 'new-ui mi ' . commpty . "\r") endfunc func s:EndDebug(job, status) - exe 'bwipe! ' . s:ptybuf + exe 'bwipe! ' . s:ptybuf + exe 'bwipe! ' . s:commbuf + call setwinvar(s:startwin, '&signcolumn', s:startsigncolumn) +endfunc + +" Handle a message received from gdb on the GDB/MI interface. +func s:CommOutput(chan, msg) + let msgs = split(a:msg, "\r") + + for msg in msgs + " remove prefixed NL + if msg[0] == "\n" + let msg = msg[1:] + endif + if msg != '' + if msg =~ '^\*\(stopped\|running\)' + let wid = win_getid(winnr()) + + if win_gotoid(s:startwin) + if msg =~ '^\*stopped' + " TODO: proper parsing + let fname = substitute(msg, '.*fullname="\([^"]*\)".*', '\1', '') + let lnum = substitute(msg, '.*line="\([^"]*\)".*', '\1', '') + if lnum =~ '^[0-9]*$' + if expand('%:h') != fname + if &modified + " TODO: find existing window + exe 'split ' . fnameescape(fname) + let s:startwin = win_getid(winnr()) + else + exe 'edit ' . fnameescape(fname) + endif + endif + exe lnum + exe 'sign place ' . s:pc_id . ' line=' . lnum . ' name=debugPC file=' . fnameescape(fname) + setlocal signcolumn=yes + endif + else + exe 'sign unplace ' . s:pc_id + endif + + call win_gotoid(wid) + endif + endif + endif + endfor endfunc diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 7b90cbe4f4..802eba06a5 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -3224,6 +3224,9 @@ int build_stl_str_hl( #define TMPLEN 70 char_u tmp[TMPLEN]; char_u *usefmt = fmt; + const int save_must_redraw = must_redraw; + const int save_redr_type = curwin->w_redr_type; + const int save_highlight_shcnaged = need_highlight_changed; // When the format starts with "%!" then evaluate it as an expression and // use the result as the actual format string. @@ -3632,16 +3635,16 @@ int build_stl_str_hl( vim_snprintf((char *)tmp, sizeof(tmp), "%d", curbuf->b_fnum); set_internal_string_var((char_u *)"g:actual_curbuf", tmp); - buf_T *o_curbuf = curbuf; - win_T *o_curwin = curwin; + buf_T *const save_curbuf = curbuf; + win_T *const save_curwin = curwin; curwin = wp; curbuf = wp->w_buffer; // Note: The result stored in `t` is unused. str = eval_to_string_safe(out_p, &t, use_sandbox); - curwin = o_curwin; - curbuf = o_curbuf; + curwin = save_curwin; + curbuf = save_curbuf; // Remove the variable we just stored do_unlet(S_LEN("g:actual_curbuf"), true); @@ -4262,6 +4265,13 @@ int build_stl_str_hl( cur_tab_rec->def.func = NULL; } + // We do not want redrawing a stausline, ruler, title, etc. to trigger + // another redraw, it may cause an endless loop. This happens when a + // statusline changes a highlight group. + must_redraw = save_must_redraw; + curwin->w_redr_type = save_redr_type; + need_highlight_changed = save_highlight_shcnaged; + return width; } diff --git a/src/nvim/options.lua b/src/nvim/options.lua index c3aff87bbf..222ec5457b 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -1173,9 +1173,7 @@ return { vi_def=true, varname='p_iminsert', pv_name='p_imi', defaults={ - condition='B_IMODE_IM', - if_true={vi=macros('B_IMODE_IM')}, - if_false={vi=macros('B_IMODE_NONE')}, + if_true={vi=macros('B_IMODE_NONE')}, } }, { @@ -1184,9 +1182,7 @@ return { vi_def=true, varname='p_imsearch', pv_name='p_ims', defaults={ - condition='B_IMODE_IM', - if_true={vi=macros('B_IMODE_IM')}, - if_false={vi=macros('B_IMODE_NONE')}, + if_true={vi=macros('B_IMODE_USE_INSERT')}, } }, { diff --git a/src/nvim/testdir/setup.vim b/src/nvim/testdir/setup.vim index c7c3b378cc..011433f19e 100644 --- a/src/nvim/testdir/setup.vim +++ b/src/nvim/testdir/setup.vim @@ -24,6 +24,9 @@ let $NVIM_LOG_FILE = exists($NVIM_LOG_FILE) ? $NVIM_LOG_FILE : 'Xnvim.log' set rtp=$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after let &packpath = &rtp +" Avoid storing shell history. +let $HISTFILE = "" + " Make sure $HOME does not get read or written. let $HOME = expand(getcwd() . '/XfakeHOME') if !isdirectory($HOME) diff --git a/test/functional/options/num_options_spec.lua b/test/functional/options/num_options_spec.lua index fb0559054d..88e554c86f 100644 --- a/test/functional/options/num_options_spec.lua +++ b/test/functional/options/num_options_spec.lua @@ -32,9 +32,9 @@ describe(':setlocal', function() eq(0, meths.get_option('iminsert')) feed_command('setlocal iminsert=1') eq(0, meths.get_option('iminsert')) - eq(0, meths.get_option('imsearch')) + eq(-1, meths.get_option('imsearch')) feed_command('setlocal imsearch=1') - eq(0, meths.get_option('imsearch')) + eq(-1, meths.get_option('imsearch')) end) end) |