aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-04-29 10:07:51 +0800
committerGitHub <noreply@github.com>2023-04-29 10:07:51 +0800
commit3287fc2ba9284d48e945ab0008b7844e1ec40eec (patch)
tree2844deffee1f539d8bf933654dda276bcb55bc9c /src
parent129012172258a08efa87cbab927cdd3e4da7db90 (diff)
parent7b6d041baed712b071acfa8bb71727a5f5e27561 (diff)
downloadrneovim-3287fc2ba9284d48e945ab0008b7844e1ec40eec.tar.gz
rneovim-3287fc2ba9284d48e945ab0008b7844e1ec40eec.tar.bz2
rneovim-3287fc2ba9284d48e945ab0008b7844e1ec40eec.zip
Merge pull request #23386 from zeertzjq/vim-8.2.0551
vim-patch:8.2.{0551,0578,0672}: heredoc for interfaces does not support "trim"
Diffstat (limited to 'src')
-rw-r--r--src/nvim/eval/userfunc.c9
-rw-r--r--src/nvim/eval/vars.c32
-rw-r--r--src/nvim/ex_getln.c27
-rw-r--r--src/nvim/lua/executor.c2
4 files changed, 44 insertions, 26 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
index 0e22cf54cf..1f5a6eaec4 100644
--- a/src/nvim/eval/userfunc.c
+++ b/src/nvim/eval/userfunc.c
@@ -2571,11 +2571,18 @@ void ex_function(exarg_T *eap)
&& (!ASCII_ISALPHA(p[2]) || p[2] == 's')))) {
// ":python <<" continues until a dot, like ":append"
p = skipwhite(arg + 2);
+ if (strncmp(p, "trim", 4) == 0) {
+ // Ignore leading white space.
+ p = skipwhite(p + 4);
+ heredoc_trimmed = xstrnsave(theline, (size_t)(skipwhite(theline) - theline));
+ }
if (*p == NUL) {
skip_until = xstrdup(".");
} else {
- skip_until = xstrdup(p);
+ skip_until = xstrnsave(p, (size_t)(skiptowhite(p) - p));
}
+ do_concat = false;
+ is_heredoc = true;
}
// Check for ":let v =<< [trim] EOF"
diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c
index 593ba9f6c3..de6c4bab60 100644
--- a/src/nvim/eval/vars.c
+++ b/src/nvim/eval/vars.c
@@ -155,14 +155,18 @@ char *eval_all_expr_in_str(char *str)
/// marker, then the leading indentation before the lines (matching the
/// indentation in the 'cmd' line) is stripped.
///
+/// When getting lines for an embedded script (e.g. python, lua, perl, ruby,
+/// tcl, mzscheme), "script_get" is set to true. In this case, if the marker is
+/// missing, then '.' is accepted as a marker.
+///
/// @return a List with {lines} or NULL on failure.
-static list_T *heredoc_get(exarg_T *eap, char *cmd)
+list_T *heredoc_get(exarg_T *eap, char *cmd, bool script_get)
{
char *marker;
- char *p;
int marker_indent_len = 0;
int text_indent_len = 0;
char *text_indent = NULL;
+ char dot[] = ".";
if (eap->getline == NULL) {
emsg(_("E991: cannot use =<< here"));
@@ -182,7 +186,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
// The amount of indentation trimmed is the same as the indentation
// of the first line after the :let command line. To find the end
// marker the indent of the :let command line is trimmed.
- p = *eap->cmdlinep;
+ char *p = *eap->cmdlinep;
while (ascii_iswhite(*p)) {
p++;
marker_indent_len++;
@@ -203,19 +207,25 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
// The marker is the next word.
if (*cmd != NUL && *cmd != '"') {
marker = skipwhite(cmd);
- p = skiptowhite(marker);
+ char *p = skiptowhite(marker);
if (*skipwhite(p) != NUL && *skipwhite(p) != '"') {
semsg(_(e_trailing_arg), p);
return NULL;
}
*p = NUL;
- if (islower((uint8_t)(*marker))) {
+ if (!script_get && islower((uint8_t)(*marker))) {
emsg(_("E221: Marker cannot start with lower case letter"));
return NULL;
}
} else {
- emsg(_("E172: Missing marker"));
- return NULL;
+ // When getting lines for an embedded script, if the marker is missing,
+ // accept '.' as the marker.
+ if (script_get) {
+ marker = dot;
+ } else {
+ emsg(_("E172: Missing marker"));
+ return NULL;
+ }
}
char *theline = NULL;
@@ -227,7 +237,9 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
xfree(theline);
theline = eap->getline(NUL, eap->cookie, 0, false);
if (theline == NULL) {
- semsg(_("E990: Missing end marker '%s'"), marker);
+ if (!script_get) {
+ semsg(_("E990: Missing end marker '%s'"), marker);
+ }
break;
}
@@ -249,7 +261,7 @@ static list_T *heredoc_get(exarg_T *eap, char *cmd)
if (text_indent_len == -1 && *theline != NUL) {
// set the text indent from the first line.
- p = theline;
+ char *p = theline;
text_indent_len = 0;
while (ascii_iswhite(*p)) {
p++;
@@ -353,7 +365,7 @@ void ex_let(exarg_T *eap)
if (expr[0] == '=' && expr[1] == '<' && expr[2] == '<') {
// HERE document
- list_T *l = heredoc_get(eap, expr + 3);
+ list_T *l = heredoc_get(eap, expr + 3, false);
if (l != NULL) {
tv_list_set_ret(&rettv, l);
if (!eap->skip) {
diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c
index c0c8a5605b..5018c9268b 100644
--- a/src/nvim/ex_getln.c
+++ b/src/nvim/ex_getln.c
@@ -29,6 +29,7 @@
#include "nvim/edit.h"
#include "nvim/eval.h"
#include "nvim/eval/typval.h"
+#include "nvim/eval/vars.h"
#include "nvim/ex_cmds.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_docmd.h"
@@ -4561,39 +4562,37 @@ bool is_in_cmdwin(void)
char *script_get(exarg_T *const eap, size_t *const lenp)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC
{
- const char *const cmd = eap->arg;
+ char *cmd = eap->arg;
if (cmd[0] != '<' || cmd[1] != '<' || eap->getline == NULL) {
*lenp = strlen(eap->arg);
return eap->skip ? NULL : xmemdupz(eap->arg, *lenp);
}
+ cmd += 2;
garray_T ga = { .ga_data = NULL, .ga_len = 0 };
+
+ list_T *const l = heredoc_get(eap, cmd, true);
+ if (l == NULL) {
+ return NULL;
+ }
+
if (!eap->skip) {
ga_init(&ga, 1, 0x400);
}
- const char *const end_pattern = (cmd[2] != NUL ? skipwhite(cmd + 2) : ".");
- while (true) {
- char *const theline = eap->getline(eap->cstack->cs_looplevel > 0 ? -1 : NUL, eap->cookie, 0,
- true);
-
- if (theline == NULL || strcmp(end_pattern, theline) == 0) {
- xfree(theline);
- break;
- }
-
+ TV_LIST_ITER_CONST(l, li, {
if (!eap->skip) {
- ga_concat(&ga, theline);
+ ga_concat(&ga, tv_get_string(TV_LIST_ITEM_TV(li)));
ga_append(&ga, '\n');
}
- xfree(theline);
- }
+ });
*lenp = (size_t)ga.ga_len; // Set length without trailing NUL.
if (!eap->skip) {
ga_append(&ga, NUL);
}
+ tv_list_free(l);
return (char *)ga.ga_data;
}
diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c
index 1c1f68b68d..9586b56f3c 100644
--- a/src/nvim/lua/executor.c
+++ b/src/nvim/lua/executor.c
@@ -1619,7 +1619,7 @@ void ex_lua(exarg_T *const eap)
{
size_t len;
char *code = script_get(eap, &len);
- if (eap->skip) {
+ if (eap->skip || code == NULL) {
xfree(code);
return;
}