aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/eval.c18
-rw-r--r--src/nvim/testdir/setup.vim1
-rw-r--r--src/nvim/testdir/test_execute_func.vim29
-rw-r--r--test/functional/eval/execute_spec.lua135
4 files changed, 181 insertions, 2 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c
index 1640729c94..a4606f76f3 100644
--- a/src/nvim/eval.c
+++ b/src/nvim/eval.c
@@ -8331,6 +8331,8 @@ 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;
+ bool echo_output = false;
if (check_secure()) {
return;
@@ -8343,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++;
}
@@ -8358,6 +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;
+ if (!echo_output) {
+ msg_col = 0; // prevent leading spaces
+ }
if (argvars[0].v_type != VAR_LIST) {
do_cmdline_cmd(tv_get_string(&argvars[0]));
@@ -8376,6 +8384,16 @@ 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.
+ 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/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'
diff --git a/src/nvim/testdir/test_execute_func.vim b/src/nvim/testdir/test_execute_func.vim
index 6f61bede93..eb84a6739d 100644
--- a/src/nvim/testdir/test_execute_func.vim
+++ b/src/nvim/testdir/test_execute_func.vim
@@ -53,3 +53,32 @@ 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
+
+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
diff --git a/test/functional/eval/execute_spec.lua b/test/functional/eval/execute_spec.lua
index af37ab8d55..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}^ |
]], {
@@ -125,9 +125,140 @@ describe('execute()', function()
feed('<CR>')
end)
+ it('places cursor correctly #6035', function()
+ local screen = Screen.new(40, 6)
+ screen:attach()
+ source([=[
+ " test 1: non-silenced output goes as usual
+ function! Test1()
+ echo 1234
+ let x = execute('echon "abcdef"', '')
+ echon 'ABCD'
+ endfunction
+
+ " test 2: silenced output does not affect ui
+ function! Test2()
+ echo 1234
+ let x = execute('echon "abcdef"', 'silent')
+ echon 'ABCD'
+ endfunction
+
+ " test 3: silenced! error does not affect ui
+ function! Test3()
+ echo 1234
+ let x = execute('echoerr "abcdef"', 'silent!')
+ echon 'ABCD'
+ endfunction
+
+ " test 4: silenced echoerr goes as usual
+ " bug here
+ function! Test4()
+ echo 1234
+ let x = execute('echoerr "abcdef"', 'silent')
+ echon 'ABCD'
+ endfunction
+
+ " test 5: silenced! echoerr does not affect ui
+ function! Test5()
+ echo 1234
+ let x = execute('echoerr "abcdef"', 'silent!')
+ echon 'ABCD'
+ endfunction
+
+ " test 6: silenced error goes as usual
+ function! Test6()
+ echo 1234
+ let x = execute('echo undefined', 'silent')
+ echon 'ABCD'
+ endfunction
+
+ " 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 Test1()<cr>]])
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ ABCD |
+ ]])
+
+ feed([[:call Test2()<cr>]])
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ 1234ABCD |
+ ]])
+
+ feed([[:call Test3()<cr>]])
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ 1234ABCD |
+ ]])
+
+ feed([[:call Test4()<cr>]])
+ -- 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([[<cr>]]) -- to clear screen
+ feed([[:call Test5()<cr>]])
+ screen:expect([[
+ ^ |
+ ~ |
+ ~ |
+ ~ |
+ ~ |
+ 1234ABCD |
+ ]])
+
+ feed([[:call Test6()<cr>]])
+ screen:expect([[
+ |
+ Error detected while processing function|
+ Test6: |
+ line 2: |
+ E121ABCD |
+ Press ENTER or type command to continue^ |
+ ]])
+
+ feed([[:call Test7()<cr>]])
+ screen:expect([[
+ Error detected while processing function|
+ Test6: |
+ line 2: |
+ E121ABCD |
+ ABCD |
+ 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)