summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-08-07 15:05:47 +0200
committerBram Moolenaar <Bram@vim.org>2021-08-07 15:05:47 +0200
commit7de62623735d228c8f81f6ac8309fe4922822cb2 (patch)
tree136ce2332059e414aa758d1fab6c0dbf673b9fca
parent1b154ea121d8374a129c3e30d50fa9742cd5faa1 (diff)
downloadvim-git-7de62623735d228c8f81f6ac8309fe4922822cb2.tar.gz
patch 8.2.3307: Vim9: :echoconsole cannot access local variablesv8.2.3307
Problem: Vim9: :echoconsole cannot access local variables. Solution: Handle like other :echo commands. (closes #8708)
-rw-r--r--src/testdir/test_vim9_disassemble.vim4
-rw-r--r--src/testdir/test_vim9_script.vim11
-rw-r--r--src/version.c2
-rw-r--r--src/vim9.h9
-rw-r--r--src/vim9compile.c6
-rw-r--r--src/vim9execute.c18
6 files changed, 40 insertions, 10 deletions
diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index 1530c90a3..253fe1b06 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -1938,6 +1938,7 @@ enddef
def s:Echomsg()
echomsg 'some' 'message'
+ echoconsole 'nothing'
echoerr 'went' .. 'wrong'
enddef
@@ -1948,6 +1949,9 @@ def Test_disassemble_echomsg()
'\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 93dce8339..2c5e3e7da 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2493,10 +2493,11 @@ def Test_echomsg_cmd_vimscript()
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 @@ def Test_echoerr_cmd_vimscript()
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 652372d0f..9d5ede555 100644
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@ static char *(features[]) =
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 0011a5f7a..da39949fa 100644
--- a/src/vim9.h
+++ b/src/vim9.h
@@ -16,10 +16,11 @@ typedef enum {
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 9d7af52a0..5d625e0c7 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -8754,6 +8754,7 @@ compile_eval(char_u *arg, cctx_T *cctx)
* compile "echo expr"
* compile "echomsg expr"
* compile "echoerr expr"
+ * compile "echoconsole expr"
* compile "execute expr"
*/
static char_u *
@@ -8804,6 +8805,8 @@ compile_mult_expr(char_u *arg, int cmdidx, cctx_T *cctx)
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 @@ compile_def_function(
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 @@ delete_instr(isn_T *isn)
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 19a7a8d3e..690b7e0b6 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1869,9 +1869,11 @@ exec_instructions(ectx_T *ectx)
// :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 @@ exec_instructions(ectx_T *ectx)
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 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
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:
{