From e7d49dc909623c0618b3e5cfaecb09fb0b38e1fa Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 5 Jan 2020 08:17:55 -0500 Subject: [PATCH 1/5] vim-patch:8.0.1786: no test for 'termwinkey' Problem: No test for 'termwinkey'. Solution: Add a test. Make feedkeys() handle terminal_loop() returning before characters are consumed. https://github.com/vim/vim/commit/b2ac14c0b5e23f8ab97c5c784bcd83e13ba8ded3 --- src/nvim/getchar.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index f582670141..b82839103f 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1562,7 +1562,7 @@ int vpeekc(void) { if (old_char != -1) return old_char; - return vgetorpeek(FALSE); + return vgetorpeek(false); } /* @@ -1615,20 +1615,20 @@ vungetc ( /* unget one character (can only be done once!) */ /// Also stores the result of mappings. /// Also used for the ":normal" command. /// 3. from the user -/// This may do a blocking wait if "advance" is TRUE. +/// This may do a blocking wait if "advance" is true. /// -/// if "advance" is TRUE (vgetc()): +/// if "advance" is true (vgetc()): /// Really get the character. /// KeyTyped is set to TRUE in the case the user typed the key. /// KeyStuffed is TRUE if the character comes from the stuff buffer. -/// if "advance" is FALSE (vpeekc()): +/// if "advance" is false (vpeekc()): /// Just look whether there is a character available. /// Return NUL if not. /// /// When `no_mapping` (global) is zero, checks for mappings in the current mode. /// Only returns one byte (of a multi-byte character). /// K_SPECIAL and CSI may be escaped, need to get two more bytes then. -static int vgetorpeek(int advance) +static int vgetorpeek(bool advance) { int c, c1; int keylen; @@ -1721,7 +1721,7 @@ static int vgetorpeek(int advance) // flush all input c = inchar(typebuf.tb_buf, typebuf.tb_buflen - 1, 0L); // If inchar() returns TRUE (script file was active) or we - // are inside a mapping, get out of insert mode. + // are inside a mapping, get out of Insert mode. // Otherwise we behave like having gotten a CTRL-C. // As a result typing CTRL-C in insert mode will // really insert a CTRL-C. @@ -2324,7 +2324,7 @@ static int vgetorpeek(int advance) } /* for (;;) */ } /* if (!character from stuffbuf) */ - /* if advance is FALSE don't loop on NULs */ + // if advance is false don't loop on NULs } while (c < 0 || (advance && c == NUL)); /* From 3a3fb0860248b42e05de6591d4b7727453efdef2 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Fri, 3 Jan 2020 22:58:09 -0500 Subject: [PATCH 2/5] vim-patch:8.1.0851: feedkeys() with "L" does not work properly Problem: feedkeys() with "L" does not work properly. Solution: Do not set typebuf_was_filled when using "L". (Ozaki Kiichi, closes vim/vim#3885) https://github.com/vim/vim/commit/8d4ce56a19ed14d13332f94ad592fff2d9a715d5 --- src/nvim/api/vim.c | 8 ++++---- src/nvim/testdir/test_autocmd.vim | 2 +- src/nvim/testdir/test_mapping.vim | 2 +- src/nvim/testdir/test_timers.vim | 5 ++--- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index a649eab97c..d35d04cdb3 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -241,15 +241,15 @@ void nvim_feedkeys(String keys, String mode, Boolean escape_csi) keys_esc = keys.data; } ins_typebuf((char_u *)keys_esc, (remap ? REMAP_YES : REMAP_NONE), - insert ? 0 : typebuf.tb_len, !typed, false); + insert ? 0 : typebuf.tb_len, !typed, false); + if (vgetc_busy) { + typebuf_was_filled = true; + } if (escape_csi) { xfree(keys_esc); } - if (vgetc_busy) { - typebuf_was_filled = true; - } if (execute) { int save_msg_scroll = msg_scroll; diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 275b053bc9..e3547aea5b 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -52,7 +52,7 @@ if has('timers') au CursorHoldI * let g:triggered += 1 set updatetime=500 call job_start(has('win32') ? 'cmd /c echo:' : 'echo', - \ {'exit_cb': {j, s -> timer_start(1000, 'ExitInsertMode')}}) + \ {'exit_cb': {-> timer_start(1000, 'ExitInsertMode')}}) call feedkeys('a', 'x!') call assert_equal(1, g:triggered) unlet g:triggered diff --git a/src/nvim/testdir/test_mapping.vim b/src/nvim/testdir/test_mapping.vim index 34e62e80e8..f14f292a92 100644 --- a/src/nvim/testdir/test_mapping.vim +++ b/src/nvim/testdir/test_mapping.vim @@ -287,7 +287,7 @@ func Test_map_timeout_with_timer_interrupt() set timeout timeoutlen=200 func ExitCb(job, status) - let g:timer = timer_start(1, {_ -> feedkeys("3\", 't')}) + let g:timer = timer_start(1, {-> feedkeys("3\", 't')}) endfunc call job_start([&shell, &shellcmdflag, 'echo'], {'exit_cb': 'ExitCb'}) diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index 6c336e6fa6..c4d74222a4 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -254,15 +254,14 @@ func Test_peek_and_get_char() endfunc func Test_getchar_zero() - if has('win32') + if has('win32') && !has('gui_running') " Console: no low-level input - " GUI: somehow doesn't work return endif " Measure the elapsed time to avoid a hang when it fails. let start = reltime() - let id = timer_start(20, {id -> feedkeys('x', 'L')}) + let id = timer_start(20, {-> feedkeys('x', 'L')}) let c = 0 while c == 0 && reltimefloat(reltime(start)) < 0.2 let c = getchar(0) From 1aacab49ea0e5cff94bd89595737b6af677f4490 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 5 Jan 2020 10:40:02 -0500 Subject: [PATCH 3/5] vim-patch:8.1.1579: dict and list could be GC'ed while displaying error Problem: Dict and list could be GC'ed while displaying error in a timer. (Yasuhiro Matsumoto) Solution: Block garbage collection when executing a timer. Add test_garbagecollect_soon(). Add "no_wait_return" to test_override(). (closes vim/vim#4571) https://github.com/vim/vim/commit/adc6714aac20f5462a0ecec50ab4806b2f3ab0db --- src/nvim/eval.c | 2 +- src/nvim/eval/typval.c | 2 +- src/nvim/getchar.c | 2 +- src/nvim/globals.h | 2 +- src/nvim/testdir/test_timers.vim | 26 ++++++++++++++++++++++++++ test/unit/eval/helpers.lua | 2 +- 6 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index cf4d3af232..5c19ce4047 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5920,7 +5920,7 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate) if (**arg != '}') { EMSG2(_("E723: Missing end of Dictionary '}': %s"), *arg); failret: - if (evaluate) { + if (d != NULL) { tv_dict_free(d); } return FAIL; diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 728e3a7fa3..da97eccc65 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1306,7 +1306,7 @@ void tv_dict_item_remove(dict_T *const dict, dictitem_T *const item) dict_T *tv_dict_alloc(void) FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT { - dict_T *const d = xmalloc(sizeof(dict_T)); + dict_T *const d = xcalloc(1, sizeof(dict_T)); // Add the dict to the list of dicts for garbage collection. if (gc_first_dict != NULL) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index b82839103f..81666bf5d6 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1518,7 +1518,7 @@ int vgetc(void) * collection in the first next vgetc(). It's disabled after that to * avoid internally used Lists and Dicts to be freed. */ - may_garbage_collect = FALSE; + may_garbage_collect = false; return c; } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 148ab0a02b..4741778c14 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -325,7 +325,7 @@ EXTERN except_T *caught_stack INIT(= NULL); /// we do garbage collection before waiting for a char at the toplevel. /// "garbage_collect_at_exit" indicates garbagecollect(1) was called. /// -EXTERN int may_garbage_collect INIT(= false); +EXTERN bool may_garbage_collect INIT(= false); EXTERN int want_garbage_collect INIT(= false); EXTERN int garbage_collect_at_exit INIT(= false); diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index c4d74222a4..3043103270 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -313,4 +313,30 @@ func Test_restore_count() call delete('Xtrctext') endfunc +" Test that the garbage collector isn't triggered if a timer callback invokes +" vgetc(). +func Test_nocatch_garbage_collect() + " skipped: Nvim does not support test_garbagecollect_soon(), test_override() + return + " 'uptimetime. must be bigger than the timer timeout + set ut=200 + call test_garbagecollect_soon() + call test_override('no_wait_return', 0) + func CauseAnError(id) + " This will show an error and wait for Enter. + let a = {'foo', 'bar'} + endfunc + func FeedChar(id) + call feedkeys('x', 't') + endfunc + call timer_start(300, 'FeedChar') + call timer_start(100, 'CauseAnError') + let x = getchar() + + set ut& + call test_override('no_wait_return', 1) + delfunc CauseAnError + delfunc FeedChar +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 3d1c42c3a0..bcd7c750c5 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -406,7 +406,7 @@ end local alloc_logging_helpers = { list = function(l) return {func='calloc', args={1, ffi.sizeof('list_T')}, ret=void(l)} end, li = function(li) return {func='malloc', args={ffi.sizeof('listitem_T')}, ret=void(li)} end, - dict = function(d) return {func='malloc', args={ffi.sizeof('dict_T')}, ret=void(d)} end, + dict = function(d) return {func='calloc', args={1, ffi.sizeof('dict_T')}, ret=void(d)} end, di = function(di, size) size = alloc_len(size, function() return di.di_key end) return {func='malloc', args={ffi.offsetof('dictitem_T', 'di_key') + size + 1}, ret=void(di)} From 3c764aabb5d4be71a5ea0d50bf8dae0a7285677f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 5 Jan 2020 22:51:49 -0500 Subject: [PATCH 4/5] vim-patch:8.1.1308: the Normal highlight is not defined when compiled with GUI Problem: The Normal highlight is not defined when compiled with GUI. Solution: Always define Normal. (Christian Brabandt, closes vim/vim#4072) https://github.com/vim/vim/commit/f90b6e03a983b62b66564fc449e32724d6456769 --- runtime/doc/syntax.txt | 2 ++ src/nvim/syntax.c | 3 +-- src/nvim/testdir/test_highlight.vim | 7 +++++++ test/functional/ui/screen_basic_spec.lua | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 5424ad00ec..30ccb699cd 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -4920,6 +4920,8 @@ Conceal placeholder characters substituted for concealed text (see 'conceallevel') *hl-Cursor* Cursor character under the cursor +lCursor the character under the cursor when |language-mapping| + is used (see 'guicursor') *hl-CursorIM* CursorIM like Cursor, but used when in IME mode |CursorIM| *hl-CursorColumn* diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 61ee225eba..bcf133afda 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -5959,6 +5959,7 @@ static const char *highlight_init_both[] = { "IncSearch cterm=reverse gui=reverse", "ModeMsg cterm=bold gui=bold", "NonText ctermfg=Blue gui=bold guifg=Blue", + "Normal cterm=NONE gui=NONE", "PmenuSbar ctermbg=Grey guibg=Grey", "StatusLine cterm=reverse,bold gui=reverse,bold", "StatusLineNC cterm=reverse gui=reverse", @@ -6010,7 +6011,6 @@ static const char *highlight_init_light[] = { "Title ctermfg=DarkMagenta gui=bold guifg=Magenta", "Visual guibg=LightGrey", "WarningMsg ctermfg=DarkRed guifg=Red", - "Normal gui=NONE", NULL }; @@ -6044,7 +6044,6 @@ static const char *highlight_init_dark[] = { "Title ctermfg=LightMagenta gui=bold guifg=Magenta", "Visual guibg=DarkGrey", "WarningMsg ctermfg=LightRed guifg=Red", - "Normal gui=NONE", NULL }; diff --git a/src/nvim/testdir/test_highlight.vim b/src/nvim/testdir/test_highlight.vim index d94eb7c3a2..b9aeff0907 100644 --- a/src/nvim/testdir/test_highlight.vim +++ b/src/nvim/testdir/test_highlight.vim @@ -591,3 +591,10 @@ func Test_cursorline_with_visualmode() call StopVimInTerminal(buf) call delete('Xtest_cursorline_with_visualmode') endfunc + +func Test_1_highlight_Normalgroup_exists() + " This test must come before the Test_cursorline test, as it appears this + " defines the Normal highlighting group anyway. + let hlNormal = HighlightArgs('Normal') + call assert_match('hi Normal\s*clear', hlNormal) +endfunc diff --git a/test/functional/ui/screen_basic_spec.lua b/test/functional/ui/screen_basic_spec.lua index 150ee2a103..ff9f30d0a1 100644 --- a/test/functional/ui/screen_basic_spec.lua +++ b/test/functional/ui/screen_basic_spec.lua @@ -987,7 +987,7 @@ describe('Screen default colors', function() it('can be set to light', function() startup(true, false) screen:expect{condition=function() - eq({rgb_bg=Screen.colors.White, rgb_fg=0, rgb_sp=Screen.colors.Red, + eq({rgb_fg=Screen.colors.White, rgb_bg=0, rgb_sp=Screen.colors.Red, cterm_bg=0, cterm_fg=0}, screen.default_colors) end} end) From 83083dd47b0c2880e4e1401f1c751013c533d57f Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 5 Jan 2020 23:03:51 -0500 Subject: [PATCH 5/5] vim-patch:8.1.1309: test for Normal highlight fails on MS-Windows GUI Problem: Test for Normal highlight fails on MS-Windows GUI. Solution: Skip the test for MS-Windows GUI. https://github.com/vim/vim/commit/6b528fa062a5ac6bb5d8bd3abc26f32c65691d00 --- src/nvim/testdir/test_highlight.vim | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/nvim/testdir/test_highlight.vim b/src/nvim/testdir/test_highlight.vim index b9aeff0907..a320e8edc8 100644 --- a/src/nvim/testdir/test_highlight.vim +++ b/src/nvim/testdir/test_highlight.vim @@ -592,9 +592,12 @@ func Test_cursorline_with_visualmode() call delete('Xtest_cursorline_with_visualmode') endfunc +" This test must come before the Test_cursorline test, as it appears this +" defines the Normal highlighting group anyway. func Test_1_highlight_Normalgroup_exists() - " This test must come before the Test_cursorline test, as it appears this - " defines the Normal highlighting group anyway. - let hlNormal = HighlightArgs('Normal') - call assert_match('hi Normal\s*clear', hlNormal) + " MS-Windows GUI sets the font + if !has('win32') || !has('gui_running') + let hlNormal = HighlightArgs('Normal') + call assert_match('hi Normal\s*clear', hlNormal) + endif endfunc