1
0
forked from aniani/vim

patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.

Problem:    Vim9: cannot use heredoc in :def function for :python, :lua, etc.
Solution:   Concatenate the heredoc lines and pass them in the ISN_EXEC_SPLIT
            instruction.
This commit is contained in:
Bram Moolenaar
2021-06-06 17:02:53 +02:00
parent c64ed2b714
commit 2067733b5c
7 changed files with 182 additions and 15 deletions

View File

@@ -8668,6 +8668,29 @@ theend:
return nextcmd;
}
/*
* A script command with heredoc, e.g.
* ruby << EOF
* command
* EOF
* Has been turned into one long line with NL characters by
* get_function_body():
* ruby << EOF<NL> command<NL>EOF
*/
static char_u *
compile_script(char_u *line, cctx_T *cctx)
{
if (cctx->ctx_skip != SKIP_YES)
{
isn_T *isn;
if ((isn = generate_instr(cctx, ISN_EXEC_SPLIT)) == NULL)
return NULL;
isn->isn_arg.string = vim_strsave(line);
}
return (char_u *)"";
}
/*
* :s/pat/repl/
@@ -9480,18 +9503,28 @@ compile_def_function(
line = (char_u *)"";
break;
default:
if (cctx.ctx_skip == SKIP_YES)
{
// We don't check for a next command here.
line = (char_u *)"";
}
else
{
// Not recognized, execute with do_cmdline_cmd().
ea.arg = p;
case CMD_lua:
case CMD_mzscheme:
case CMD_perl:
case CMD_py3:
case CMD_python3:
case CMD_python:
case CMD_pythonx:
case CMD_ruby:
case CMD_tcl:
ea.arg = p;
if (vim_strchr(line, '\n') == NULL)
line = compile_exec(line, &ea, &cctx);
}
else
// heredoc lines have been concatenated with NL
// characters in get_function_body()
line = compile_script(line, &cctx);
break;
default:
// Not recognized, execute with do_cmdline_cmd().
ea.arg = p;
line = compile_exec(line, &ea, &cctx);
break;
}
nextline:
@@ -9674,6 +9707,7 @@ delete_instr(isn_T *isn)
{
case ISN_DEF:
case ISN_EXEC:
case ISN_EXEC_SPLIT:
case ISN_LEGACY_EVAL:
case ISN_LOADAUTO:
case ISN_LOADB: