comparison src/userfunc.c @ 16708:98393772bddd v8.1.1356

patch 8.1.1356: some text in heredoc assignment ends the text commit https://github.com/vim/vim/commit/8471e57026714c5a0faf89288ceef5231fb88d4f Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 19 21:37:18 2019 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Sun, 19 May 2019 21:45:06 +0200
parents a1ba0bd74e7d
children ef00b6bc186b
comparison
equal deleted inserted replaced
16707:3b3e32ba0c5c 16708:98393772bddd
1977 ufunc_T *fp; 1977 ufunc_T *fp;
1978 int overwrite = FALSE; 1978 int overwrite = FALSE;
1979 int indent; 1979 int indent;
1980 int nesting; 1980 int nesting;
1981 char_u *skip_until = NULL; 1981 char_u *skip_until = NULL;
1982 char_u *trimmed = NULL;
1982 dictitem_T *v; 1983 dictitem_T *v;
1983 funcdict_T fudi; 1984 funcdict_T fudi;
1984 static int func_nr = 0; /* number for nameless function */ 1985 static int func_nr = 0; /* number for nameless function */
1985 int paren; 1986 int paren;
1986 hashtab_T *ht; 1987 hashtab_T *ht;
2301 else 2302 else
2302 sourcing_lnum_off = 0; 2303 sourcing_lnum_off = 0;
2303 2304
2304 if (skip_until != NULL) 2305 if (skip_until != NULL)
2305 { 2306 {
2306 /* between ":append" and "." and between ":python <<EOF" and "EOF" 2307 // Between ":append" and "." and between ":python <<EOF" and "EOF"
2307 * don't check for ":endfunc". */ 2308 // don't check for ":endfunc".
2308 if (STRCMP(theline, skip_until) == 0) 2309 if (trimmed == NULL
2309 VIM_CLEAR(skip_until); 2310 || STRNCMP(theline, trimmed, STRLEN(trimmed)) == 0)
2311 {
2312 p = trimmed == NULL ? theline : theline + STRLEN(trimmed);
2313 if (STRCMP(p, skip_until) == 0)
2314 {
2315 VIM_CLEAR(skip_until);
2316 VIM_CLEAR(trimmed);
2317 }
2318 }
2310 } 2319 }
2311 else 2320 else
2312 { 2321 {
2313 /* skip ':' and blanks*/ 2322 /* skip ':' and blanks*/
2314 for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p) 2323 for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p)
2403 p = skipwhite(arg + 2); 2412 p = skipwhite(arg + 2);
2404 if (*p == NUL) 2413 if (*p == NUL)
2405 skip_until = vim_strsave((char_u *)"."); 2414 skip_until = vim_strsave((char_u *)".");
2406 else 2415 else
2407 skip_until = vim_strsave(p); 2416 skip_until = vim_strsave(p);
2417 }
2418
2419 // Check for ":let v =<< [trim] EOF"
2420 arg = skipwhite(skiptowhite(p));
2421 arg = skipwhite(skiptowhite(arg));
2422 if (arg[0] == '=' && arg[1] == '<' && arg[2] =='<'
2423 && ((p[0] == 'l'
2424 && p[1] == 'e'
2425 && (!ASCII_ISALNUM(p[2])
2426 || (p[2] == 't' && !ASCII_ISALNUM(p[3]))))))
2427 {
2428 // ":let v =<<" continues until a dot
2429 p = skipwhite(arg + 3);
2430 if (STRNCMP(p, "trim", 4) == 0)
2431 {
2432 // Ignore leading white space.
2433 p = skipwhite(p + 4);
2434 trimmed = vim_strnsave(theline,
2435 (int)(skipwhite(theline) - theline));
2436 }
2437 if (*p == NUL)
2438 skip_until = vim_strsave((char_u *)".");
2439 else
2440 skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p));
2408 } 2441 }
2409 } 2442 }
2410 2443
2411 /* Add the line to the function. */ 2444 /* Add the line to the function. */
2412 if (ga_grow(&newlines, 1 + sourcing_lnum_off) == FAIL) 2445 if (ga_grow(&newlines, 1 + sourcing_lnum_off) == FAIL)