Mercurial > vim
diff src/vim9execute.c @ 24826:a8d64f1a223b v8.2.2951
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Commit: https://github.com/vim/vim/commit/2067733b5c76e996238af938af36b8196366b7ce
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 6 17:02:53 2021 +0200
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 06 Jun 2021 17:15:03 +0200 |
parents | 1bed37e82c2e |
children | f7445dcba17f |
line wrap: on
line diff
--- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -1214,6 +1214,37 @@ get_script_svar(scriptref_T *sref, ectx_ } /* + * 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 @@ exec_instructions(ectx_T *ectx) } 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 @@ list_instructions(char *pfx, isn_T *inst 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);