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.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 573fa43..0c73433 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -8668,6 +8668,29 @@
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 @@
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 @@
{
case ISN_DEF:
case ISN_EXEC:
+ case ISN_EXEC_SPLIT:
case ISN_LEGACY_EVAL:
case ISN_LOADAUTO:
case ISN_LOADB: