# HG changeset patch # User Bram Moolenaar # Date 1628342102 -7200 # Node ID 2ae1d5a4ae5cfe19f28af18837415aa6ffbac60e # Parent 94ba2bb5b3576a3f6cfffabcccbcec21e4a62438 patch 8.2.3307: Vim9: :echoconsole cannot access local variables Commit: https://github.com/vim/vim/commit/7de62623735d228c8f81f6ac8309fe4922822cb2 Author: Bram Moolenaar Date: Sat Aug 7 15:05:47 2021 +0200 patch 8.2.3307: Vim9: :echoconsole cannot access local variables Problem: Vim9: :echoconsole cannot access local variables. Solution: Handle like other :echo commands. (closes https://github.com/vim/vim/issues/8708) diff --git a/src/testdir/test_vim9_disassemble.vim b/src/testdir/test_vim9_disassemble.vim --- 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 --- 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 --- 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 --- 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 --- 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 cmdid 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 --- 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 *inst 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: {