patch 8.2.3307: Vim9: :echoconsole cannot access local variables
Problem: Vim9: :echoconsole cannot access local variables.
Solution: Handle like other :echo commands. (closes #8708)
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index 1530c90..253fe1b 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -1938,6 +1938,7 @@
def s:Echomsg()
echomsg 'some' 'message'
+ echoconsole 'nothing'
echoerr 'went' .. 'wrong'
enddef
@@ -1948,6 +1949,9 @@
'\d PUSHS "some"\_s*' ..
'\d PUSHS "message"\_s*' ..
'\d ECHOMSG 2\_s*' ..
+ "echoconsole 'nothing'\\_s*" ..
+ '\d PUSHS "nothing"\_s*' ..
+ '\d ECHOCONSOLE 1\_s*' ..
"echoerr 'went' .. 'wrong'\\_s*" ..
'\d PUSHS "wentwrong"\_s*' ..
'\d ECHOERR 1\_s*' ..
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 93dce83..2c5e3e7 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2493,10 +2493,11 @@
enddef
def Test_echoerr_cmd()
+ var local = 'local'
try
- echoerr 'something' 'wrong' # comment
+ echoerr 'something' local 'wrong' # comment
catch
- assert_match('something wrong', v:exception)
+ assert_match('something local wrong', v:exception)
endtry
enddef
@@ -2515,6 +2516,12 @@
CheckScriptSuccess(lines)
enddef
+def Test_echoconsole_cmd()
+ var local = 'local'
+ echoconsole 'something' local # comment
+ # output goes anywhere
+enddef
+
def Test_for_outside_of_function()
var lines =<< trim END
vim9script
diff --git a/src/version.c b/src/version.c
index 652372d..9d5ede5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3307,
+/**/
3306,
/**/
3305,
diff --git a/src/vim9.h b/src/vim9.h
index 0011a5f..da39949 100644
--- a/src/vim9.h
+++ b/src/vim9.h
@@ -16,10 +16,11 @@
ISN_EXECCONCAT, // execute Ex command from isn_arg.number items on stack
ISN_EXEC_SPLIT, // execute Ex command from isn_arg.string split at NL
ISN_LEGACY_EVAL, // evaluate expression isn_arg.string with legacy syntax.
- ISN_ECHO, // echo isn_arg.echo.echo_count items on top of stack
- ISN_EXECUTE, // execute Ex commands isn_arg.number items on top of stack
- ISN_ECHOMSG, // echo Ex commands isn_arg.number items on top of stack
- ISN_ECHOERR, // echo Ex commands isn_arg.number items on top of stack
+ ISN_ECHO, // :echo with isn_arg.echo.echo_count items on top of stack
+ ISN_EXECUTE, // :execute with isn_arg.number items on top of stack
+ ISN_ECHOMSG, // :echomsg with isn_arg.number items on top of stack
+ ISN_ECHOCONSOLE, // :echoconsole with isn_arg.number items on top of stack
+ ISN_ECHOERR, // :echoerr with isn_arg.number items on top of stack
ISN_RANGE, // compute range from isn_arg.string, push to stack
ISN_SUBSTITUTE, // :s command with expression
ISN_INSTR, // instructions compiled from expression
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 9d7af52..5d625e0 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -8754,6 +8754,7 @@
* compile "echo expr"
* compile "echomsg expr"
* compile "echoerr expr"
+ * compile "echoconsole expr"
* compile "execute expr"
*/
static char_u *
@@ -8804,6 +8805,8 @@
generate_MULT_EXPR(cctx, ISN_EXECUTE, count);
else if (cmdidx == CMD_echomsg)
generate_MULT_EXPR(cctx, ISN_ECHOMSG, count);
+ else if (cmdidx == CMD_echoconsole)
+ generate_MULT_EXPR(cctx, ISN_ECHOCONSOLE, count);
else
generate_MULT_EXPR(cctx, ISN_ECHOERR, count);
@@ -9861,7 +9864,7 @@
case CMD_execute:
case CMD_echomsg:
case CMD_echoerr:
- // TODO: "echoconsole"
+ case CMD_echoconsole:
line = compile_mult_expr(p, ea.cmdidx, &cctx);
break;
@@ -10307,6 +10310,7 @@
case ISN_DEBUG:
case ISN_DROP:
case ISN_ECHO:
+ case ISN_ECHOCONSOLE:
case ISN_ECHOERR:
case ISN_ECHOMSG:
case ISN_ENDTRY:
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 19a7a8d..690b7e0 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1869,9 +1869,11 @@
// :execute {string} ...
// :echomsg {string} ...
+ // :echoconsole {string} ...
// :echoerr {string} ...
case ISN_EXECUTE:
case ISN_ECHOMSG:
+ case ISN_ECHOCONSOLE:
case ISN_ECHOERR:
{
int count = iptr->isn_arg.number;
@@ -1941,6 +1943,12 @@
msg_attr(ga.ga_data, echo_attr);
out_flush();
}
+ else if (iptr->isn_type == ISN_ECHOCONSOLE)
+ {
+ ui_write(ga.ga_data, (int)STRLEN(ga.ga_data),
+ TRUE);
+ ui_write((char_u *)"\r\n", 2, TRUE);
+ }
else
{
SOURCING_LNUM = iptr->isn_lnum;
@@ -4900,15 +4908,19 @@
break;
case ISN_EXECUTE:
smsg("%s%4d EXECUTE %lld", pfx, current,
- (varnumber_T)(iptr->isn_arg.number));
+ (varnumber_T)(iptr->isn_arg.number));
break;
case ISN_ECHOMSG:
smsg("%s%4d ECHOMSG %lld", pfx, current,
- (varnumber_T)(iptr->isn_arg.number));
+ (varnumber_T)(iptr->isn_arg.number));
+ break;
+ case ISN_ECHOCONSOLE:
+ smsg("%s%4d ECHOCONSOLE %lld", pfx, current,
+ (varnumber_T)(iptr->isn_arg.number));
break;
case ISN_ECHOERR:
smsg("%s%4d ECHOERR %lld", pfx, current,
- (varnumber_T)(iptr->isn_arg.number));
+ (varnumber_T)(iptr->isn_arg.number));
break;
case ISN_LOAD:
{