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/vim9execute.c b/src/vim9execute.c
index e870a27..1f2f735 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1214,6 +1214,37 @@
}
/*
+ * Function passed to do_cmdline() for splitting a script joined by NL
+ * characters.
+ */
+ static char_u *
+get_split_sourceline(
+ int c UNUSED,
+ void *cookie,
+ int indent UNUSED,
+ getline_opt_T options UNUSED)
+{
+ source_cookie_T *sp = (source_cookie_T *)cookie;
+ char_u *p;
+ char_u *line;
+
+ if (*sp->nextline == NUL)
+ return NULL;
+ p = vim_strchr(sp->nextline, '\n');
+ if (p == NULL)
+ {
+ line = vim_strsave(sp->nextline);
+ sp->nextline += STRLEN(sp->nextline);
+ }
+ else
+ {
+ line = vim_strnsave(sp->nextline, p - sp->nextline);
+ sp->nextline = p + 1;
+ }
+ return line;
+}
+
+/*
* Execute a function by "name".
* This can be a builtin function, user function or a funcref.
* "iptr" can be used to replace the instruction with a more efficient one.
@@ -1425,6 +1456,24 @@
}
break;
+ // execute Ex command line split at NL characters.
+ case ISN_EXEC_SPLIT:
+ {
+ source_cookie_T cookie;
+
+ SOURCING_LNUM = iptr->isn_lnum;
+ CLEAR_FIELD(cookie);
+ cookie.sourcing_lnum = iptr->isn_lnum - 1;
+ cookie.nextline = iptr->isn_arg.string;
+ if (do_cmdline(get_split_sourceline(0, &cookie, 0, 0),
+ get_split_sourceline, &cookie,
+ DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED)
+ == FAIL
+ || did_emsg)
+ goto on_error;
+ }
+ break;
+
// Evaluate an expression with legacy syntax, push it onto the
// stack.
case ISN_LEGACY_EVAL:
@@ -4536,6 +4585,9 @@
case ISN_EXEC:
smsg("%s%4d EXEC %s", pfx, current, iptr->isn_arg.string);
break;
+ case ISN_EXEC_SPLIT:
+ smsg("%s%4d EXEC_SPLIT %s", pfx, current, iptr->isn_arg.string);
+ break;
case ISN_LEGACY_EVAL:
smsg("%s%4d EVAL legacy %s", pfx, current,
iptr->isn_arg.string);