From 8de5d641691a0d7e29759c5f0fe54875acab124b Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sat, 8 Dec 2018 14:05:07 -0500 Subject: [PATCH 1/6] vim-patch:8.1.0569: execute() always resets display column to zero Problem: Execute() always resets display column to zero. (Sha Liu) Solution: Don't reset it to zero, restore the previous value. (closes vim/vim#3669) https://github.com/vim/vim/commit/10ccaa17ec8b2be1132fd19059e1cd5fb5c902c4 --- src/nvim/eval.c | 5 +++++ src/nvim/testdir/test_execute_func.vim | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 1640729c94..f721d398c6 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -8331,6 +8331,7 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) const bool save_emsg_noredir = emsg_noredir; const bool save_redir_off = redir_off; garray_T *const save_capture_ga = capture_ga; + const int save_msg_col = msg_col; if (check_secure()) { return; @@ -8358,6 +8359,7 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) ga_init(&capture_local, (int)sizeof(char), 80); capture_ga = &capture_local; redir_off = false; + msg_col = 0; // prevent leading spaces if (argvars[0].v_type != VAR_LIST) { do_cmdline_cmd(tv_get_string(&argvars[0])); @@ -8376,6 +8378,9 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) emsg_silent = save_emsg_silent; emsg_noredir = save_emsg_noredir; redir_off = save_redir_off; + // "silent reg" or "silent echo x" leaves msg_col somewhere in the line. + // Put it back where it was, since nothing should have been written. + msg_col = save_msg_col; ga_append(capture_ga, NUL); rettv->v_type = VAR_STRING; diff --git a/src/nvim/testdir/test_execute_func.vim b/src/nvim/testdir/test_execute_func.vim index 6f61bede93..e474e0ce36 100644 --- a/src/nvim/testdir/test_execute_func.vim +++ b/src/nvim/testdir/test_execute_func.vim @@ -53,3 +53,15 @@ func Test_execute_list() call assert_equal("", execute([])) call assert_equal("", execute(v:_null_list)) endfunc + +func Test_execute_does_not_change_col() + echo '' + echon 'abcd' + let x = execute('silent echo 234343') + echon 'xyz' + let text = '' + for col in range(1, 7) + let text .= nr2char(screenchar(&lines, col)) + endfor + call assert_equal('abcdxyz', text) +endfunc From 7443da6f6e819cbe0c4432a44a596de54c64b3d8 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Sun, 9 Dec 2018 08:33:11 -0500 Subject: [PATCH 2/6] vim-patch:8.1.0571: non-silent execute() resets display column to zero Problem: Non-silent execute() resets display column to zero. Solution: Keep the display column as-is. https://github.com/vim/vim/commit/446e7a3cd36b2de7d559f167eb5795d1e1cd3ddb --- src/nvim/eval.c | 19 ++++++++++++++++--- src/nvim/testdir/test_execute_func.vim | 17 +++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/nvim/eval.c b/src/nvim/eval.c index f721d398c6..a4606f76f3 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -8332,6 +8332,7 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) const bool save_redir_off = redir_off; garray_T *const save_capture_ga = capture_ga; const int save_msg_col = msg_col; + bool echo_output = false; if (check_secure()) { return; @@ -8344,6 +8345,9 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (s == NULL) { return; } + if (*s == NUL) { + echo_output = true; + } if (strncmp(s, "silent", 6) == 0) { msg_silent++; } @@ -8359,7 +8363,9 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) ga_init(&capture_local, (int)sizeof(char), 80); capture_ga = &capture_local; redir_off = false; - msg_col = 0; // prevent leading spaces + if (!echo_output) { + msg_col = 0; // prevent leading spaces + } if (argvars[0].v_type != VAR_LIST) { do_cmdline_cmd(tv_get_string(&argvars[0])); @@ -8379,8 +8385,15 @@ static void f_execute(typval_T *argvars, typval_T *rettv, FunPtr fptr) emsg_noredir = save_emsg_noredir; redir_off = save_redir_off; // "silent reg" or "silent echo x" leaves msg_col somewhere in the line. - // Put it back where it was, since nothing should have been written. - msg_col = save_msg_col; + if (echo_output) { + // When not working silently: put it in column zero. A following + // "echon" will overwrite the message, unavoidably. + msg_col = 0; + } else { + // When working silently: Put it back where it was, since nothing + // should have been written. + msg_col = save_msg_col; + } ga_append(capture_ga, NUL); rettv->v_type = VAR_STRING; diff --git a/src/nvim/testdir/test_execute_func.vim b/src/nvim/testdir/test_execute_func.vim index e474e0ce36..eb84a6739d 100644 --- a/src/nvim/testdir/test_execute_func.vim +++ b/src/nvim/testdir/test_execute_func.vim @@ -65,3 +65,20 @@ func Test_execute_does_not_change_col() endfor call assert_equal('abcdxyz', text) endfunc + +func Test_execute_not_silent() + echo '' + echon 'abcd' + let x = execute('echon 234', '') + echo 'xyz' + let text1 = '' + for col in range(1, 8) + let text1 .= nr2char(screenchar(&lines - 1, col)) + endfor + call assert_equal('abcd234 ', text1) + let text2 = '' + for col in range(1, 4) + let text2 .= nr2char(screenchar(&lines, col)) + endfor + call assert_equal('xyz ', text2) +endfunc From 73a2922413b4fd119fc0ec1cca06ba0982ad576a Mon Sep 17 00:00:00 2001 From: Sha Liu Date: Thu, 6 Dec 2018 22:27:25 +0800 Subject: [PATCH 3/6] UI: Fix wrong msg_col after execute() closes #6035 closes #9250 --- test/functional/eval/execute_spec.lua | 134 +++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/test/functional/eval/execute_spec.lua b/test/functional/eval/execute_spec.lua index af37ab8d55..6f82b0d99c 100644 --- a/test/functional/eval/execute_spec.lua +++ b/test/functional/eval/execute_spec.lua @@ -125,9 +125,141 @@ describe('execute()', function() feed('') end) + it('places cursor correctly #6035', function() + local screen = Screen.new(40, 5) + screen:attach() + source([=[ + " test 1 + function! Test1a() + echo 12345678 + let x = execute('echo 1234567890', '') + echon '1234' + endfunction + + function! Test1b() + echo 12345678 + echo 1234567890 + echon '1234' + endfunction + + " test 2 + function! Test2a() + echo 12345678 + let x = execute('echo 1234567890', 'silent') + echon '1234' + endfunction + + function! Test2b() + echo 12345678 + silent echo 1234567890 + echon '1234' + endfunction + + " test 3 + function! Test3a() + echo 12345678 + let x = execute('echoerr 1234567890', 'silent!') + echon '1234' + endfunction + + function! Test3b() + echo 12345678 + silent! echoerr 1234567890 + echon '1234' + endfunction + + " test 4 + function! Test4a() + echo 12345678 + let x = execute('echoerr 1234567890', 'silent') + echon '1234' + endfunction + + function! Test4b() + echo 12345678 + silent echoerr 1234567890 + echon '1234' + endfunction + ]=]) + + feed([[:call Test1a()]]) + screen:expect([[ + | + | + 12345678 | + 12345678901234 | + Press ENTER or type command to continue^ | + ]]) + + feed([[:call Test1b()]]) + screen:expect([[ + 12345678 | + 12345678901234 | + 12345678 | + 12345678901234 | + Press ENTER or type command to continue^ | + ]]) + + feed([[:call Test2a()]]) + screen:expect([[ + 12345678901234 | + 12345678 | + 12345678901234 | + 123456781234 | + Press ENTER or type command to continue^ | + ]]) + + feed([[:call Test2b()]]) + screen:expect([[ + 12345678 | + 12345678901234 | + 123456781234 | + 123456781234 | + Press ENTER or type command to continue^ | + ]]) + + feed([[:call Test3a()]]) + screen:expect([[ + 12345678901234 | + 123456781234 | + 123456781234 | + 123456781234 | + Press ENTER or type command to continue^ | + ]]) + + feed([[:call Test3b()]]) + screen:expect([[ + 123456781234 | + 123456781234 | + 123456781234 | + 123456781234 | + Press ENTER or type command to continue^ | + ]]) + + feed([[:call Test4a()]]) + screen:expect([[ + Error detected while processing function| + Test4a: | + line 2: | + 123456781234 | + Press ENTER or type command to continue^ | + ]]) + + feed([[:call Test4b()]]) + screen:expect([[ + Error detected while processing function| + Test4b: | + line 2: | + 12345678901234 | + Press ENTER or type command to continue^ | + ]]) + + + end) + -- This deviates from vim behavior, but is consistent -- with how nvim currently displays the output. - it('does capture shell-command output', function() + it('captures shell-command output', function() local win_lf = iswin() and '\13' or '' eq('\n:!echo foo\r\n\nfoo'..win_lf..'\n', funcs.execute('!echo foo')) end) From 5a4e7af77d0f819d61604b9440cc2f6376a3186b Mon Sep 17 00:00:00 2001 From: Sha Liu Date: Sat, 8 Dec 2018 17:14:43 +0800 Subject: [PATCH 4/6] update functional test for "places cursor correctly #6035" --- test/functional/eval/execute_spec.lua | 197 +++++++++++++------------- 1 file changed, 98 insertions(+), 99 deletions(-) diff --git a/test/functional/eval/execute_spec.lua b/test/functional/eval/execute_spec.lua index 6f82b0d99c..45664e1060 100644 --- a/test/functional/eval/execute_spec.lua +++ b/test/functional/eval/execute_spec.lua @@ -126,135 +126,134 @@ describe('execute()', function() end) it('places cursor correctly #6035', function() - local screen = Screen.new(40, 5) + local screen = Screen.new(40, 6) screen:attach() source([=[ - " test 1 - function! Test1a() - echo 12345678 - let x = execute('echo 1234567890', '') - echon '1234' + " test 1: non-silenced output goes as usual + function! Test1() + echo 1234 + let x = execute('echon "abcdef"', '') + echon 'ABCD' endfunction - function! Test1b() - echo 12345678 - echo 1234567890 - echon '1234' + " test 2: silenced output does not affect ui + function! Test2() + echo 1234 + let x = execute('echon "abcdef"', 'silent') + echon 'ABCD' endfunction - " test 2 - function! Test2a() - echo 12345678 - let x = execute('echo 1234567890', 'silent') - echon '1234' + " test 3: silenced! error does not affect ui + function! Test3() + echo 1234 + let x = execute('echoerr "abcdef"', 'silent!') + echon 'ABCD' endfunction - function! Test2b() - echo 12345678 - silent echo 1234567890 - echon '1234' + " test 4: silenced echoerr goes as usual + " bug here + function! Test4() + echo 1234 + let x = execute('echoerr "abcdef"', 'silent') + echon 'ABCD' endfunction - " test 3 - function! Test3a() - echo 12345678 - let x = execute('echoerr 1234567890', 'silent!') - echon '1234' + " test 5: silenced! echoerr does not affect ui + function! Test5() + echo 1234 + let x = execute('echoerr "abcdef"', 'silent!') + echon 'ABCD' endfunction - function! Test3b() - echo 12345678 - silent! echoerr 1234567890 - echon '1234' + " test 6: silenced error goes as usual + function! Test6() + echo 1234 + let x = execute('echo undefined', 'silent') + echon 'ABCD' endfunction - " test 4 - function! Test4a() - echo 12345678 - let x = execute('echoerr 1234567890', 'silent') - echon '1234' - endfunction - - function! Test4b() - echo 12345678 - silent echoerr 1234567890 - echon '1234' + " test 7: existing error does not mess the result + function! Test7() + " display from Test6() is still visible + " why does the "abcdef" goes into a newline + let x = execute('echon "abcdef"', '') + echon 'ABCD' endfunction ]=]) - feed([[:call Test1a()]]) + feed([[:call Test1()]]) screen:expect([[ - | - | - 12345678 | - 12345678901234 | + ^ | + ~ | + ~ | + ~ | + ~ | + 1234abcdefABCD | + ]]) + + feed([[:call Test2()]]) + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + 1234ABCD | + ]]) + + feed([[:call Test3()]]) + screen:expect([[ + ^ | + ~ | + ~ | + ~ | + ~ | + 1234ABCD | + ]]) + + feed([[:call Test4()]]) + -- unexpected: need to fix + -- echoerr does not set did_emsg + -- "ef" was overwritten since msg_col was recovered wrongly + screen:expect([[ + 1234 | + Error detected while processing function| + Test4: | + line 2: | + abcdABCD | Press ENTER or type command to continue^ | ]]) - feed([[:call Test1b()]]) + feed([[]]) -- to clear screen + feed([[:call Test5()]]) screen:expect([[ - 12345678 | - 12345678901234 | - 12345678 | - 12345678901234 | + ^ | + ~ | + ~ | + ~ | + ~ | + 1234ABCD | + ]]) + + feed([[:call Test6()]]) + screen:expect([[ + 1234 | + Error detected while processing function| + Test6: | + line 2: | + E121: Undefined variable: undefinedABCD | Press ENTER or type command to continue^ | ]]) - feed([[:call Test2a()]]) - screen:expect([[ - 12345678901234 | - 12345678 | - 12345678901234 | - 123456781234 | - Press ENTER or type command to continue^ | - ]]) - - feed([[:call Test2b()]]) - screen:expect([[ - 12345678 | - 12345678901234 | - 123456781234 | - 123456781234 | - Press ENTER or type command to continue^ | - ]]) - - feed([[:call Test3a()]]) - screen:expect([[ - 12345678901234 | - 123456781234 | - 123456781234 | - 123456781234 | - Press ENTER or type command to continue^ | - ]]) - - feed([[:call Test3b()]]) - screen:expect([[ - 123456781234 | - 123456781234 | - 123456781234 | - 123456781234 | - Press ENTER or type command to continue^ | - ]]) - - feed([[:call Test4a()]]) + feed([[:call Test7()]]) screen:expect([[ Error detected while processing function| - Test4a: | + Test6: | line 2: | - 123456781234 | + E121: Undefined variable: undefinedABCD | + abcdefABCD | Press ENTER or type command to continue^ | ]]) - - feed([[:call Test4b()]]) - screen:expect([[ - Error detected while processing function| - Test4b: | - line 2: | - 12345678901234 | - Press ENTER or type command to continue^ | - ]]) - - end) -- This deviates from vim behavior, but is consistent From f0078c26c2949d9cd2020e0c95dc33eb26a60688 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Tue, 11 Dec 2018 21:29:10 -0500 Subject: [PATCH 5/6] functionaltests: fix new execute() tests --- test/functional/eval/execute_spec.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/functional/eval/execute_spec.lua b/test/functional/eval/execute_spec.lua index 45664e1060..f52ac4e59b 100644 --- a/test/functional/eval/execute_spec.lua +++ b/test/functional/eval/execute_spec.lua @@ -114,7 +114,7 @@ describe('execute()', function() {1:~ }| {1:~ }| {2: }| - :echo execute("hi ErrorMsg") | + | ErrorMsg xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red | {3:Press ENTER or type command to continue}^ | ]], { @@ -188,7 +188,7 @@ describe('execute()', function() ~ | ~ | ~ | - 1234abcdefABCD | + ABCD | ]]) feed([[:call Test2()]]) @@ -237,11 +237,11 @@ describe('execute()', function() feed([[:call Test6()]]) screen:expect([[ - 1234 | + | Error detected while processing function| Test6: | line 2: | - E121: Undefined variable: undefinedABCD | + E121ABCD | Press ENTER or type command to continue^ | ]]) @@ -250,8 +250,8 @@ describe('execute()', function() Error detected while processing function| Test6: | line 2: | - E121: Undefined variable: undefinedABCD | - abcdefABCD | + E121ABCD | + ABCD | Press ENTER or type command to continue^ | ]]) end) From 559401ebe57340fc7fa48ae7dffdf4fa9ddaa6d1 Mon Sep 17 00:00:00 2001 From: Jan Edmund Lazo Date: Mon, 4 Feb 2019 22:53:03 -0500 Subject: [PATCH 6/6] oldtests: set laststatus=1 --- src/nvim/testdir/setup.vim | 1 + 1 file changed, 1 insertion(+) diff --git a/src/nvim/testdir/setup.vim b/src/nvim/testdir/setup.vim index 011433f19e..c75b00d5de 100644 --- a/src/nvim/testdir/setup.vim +++ b/src/nvim/testdir/setup.vim @@ -16,6 +16,7 @@ set nohidden smarttab noautoindent noautoread complete-=i noruler noshowcmd set listchars=eol:$ set fillchars=vert:\|,fold:- set shortmess-=F +set laststatus=1 " Prevent Nvim log from writing to stderr. let $NVIM_LOG_FILE = exists($NVIM_LOG_FILE) ? $NVIM_LOG_FILE : 'Xnvim.log'