patch 8.1.1356: some text in heredoc assignment ends the text
Problem: Some text in heredoc assignment ends the text. (Ozaki Kiichi)
Solution: Recognize "let v =<<" and skip until the end.
diff --git a/src/userfunc.c b/src/userfunc.c
index 4959b0d..763903f 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -1979,6 +1979,7 @@
int indent;
int nesting;
char_u *skip_until = NULL;
+ char_u *trimmed = NULL;
dictitem_T *v;
funcdict_T fudi;
static int func_nr = 0; /* number for nameless function */
@@ -2303,10 +2304,18 @@
if (skip_until != NULL)
{
- /* between ":append" and "." and between ":python <<EOF" and "EOF"
- * don't check for ":endfunc". */
- if (STRCMP(theline, skip_until) == 0)
- VIM_CLEAR(skip_until);
+ // Between ":append" and "." and between ":python <<EOF" and "EOF"
+ // don't check for ":endfunc".
+ if (trimmed == NULL
+ || STRNCMP(theline, trimmed, STRLEN(trimmed)) == 0)
+ {
+ p = trimmed == NULL ? theline : theline + STRLEN(trimmed);
+ if (STRCMP(p, skip_until) == 0)
+ {
+ VIM_CLEAR(skip_until);
+ VIM_CLEAR(trimmed);
+ }
+ }
}
else
{
@@ -2406,6 +2415,30 @@
else
skip_until = vim_strsave(p);
}
+
+ // Check for ":let v =<< [trim] EOF"
+ arg = skipwhite(skiptowhite(p));
+ arg = skipwhite(skiptowhite(arg));
+ if (arg[0] == '=' && arg[1] == '<' && arg[2] =='<'
+ && ((p[0] == 'l'
+ && p[1] == 'e'
+ && (!ASCII_ISALNUM(p[2])
+ || (p[2] == 't' && !ASCII_ISALNUM(p[3]))))))
+ {
+ // ":let v =<<" continues until a dot
+ p = skipwhite(arg + 3);
+ if (STRNCMP(p, "trim", 4) == 0)
+ {
+ // Ignore leading white space.
+ p = skipwhite(p + 4);
+ trimmed = vim_strnsave(theline,
+ (int)(skipwhite(theline) - theline));
+ }
+ if (*p == NUL)
+ skip_until = vim_strsave((char_u *)".");
+ else
+ skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p));
+ }
}
/* Add the line to the function. */