comparison src/userfunc.c @ 17462:9088fafff9b3 v8.1.1729

patch 8.1.1729: heredoc with trim not properly handled in function commit https://github.com/vim/vim/commit/ecaa75b4cea329a3902b8565e028b32279b8322b Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 21 23:04:21 2019 +0200 patch 8.1.1729: heredoc with trim not properly handled in function Problem: Heredoc with trim not properly handled in function. Solution: Allow for missing indent. (FUJIWARA Takuya, closes https://github.com/vim/vim/issues/4713)
author Bram Moolenaar <Bram@vim.org>
date Sun, 21 Jul 2019 23:15:05 +0200
parents 8f44c630c366
children ff097edaae89
comparison
equal deleted inserted replaced
17461:1fc9ec9b71a0 17462:9088fafff9b3
1998 int flags = 0; 1998 int flags = 0;
1999 ufunc_T *fp; 1999 ufunc_T *fp;
2000 int overwrite = FALSE; 2000 int overwrite = FALSE;
2001 int indent; 2001 int indent;
2002 int nesting; 2002 int nesting;
2003 char_u *skip_until = NULL;
2004 char_u *trimmed = NULL;
2005 dictitem_T *v; 2003 dictitem_T *v;
2006 funcdict_T fudi; 2004 funcdict_T fudi;
2007 static int func_nr = 0; /* number for nameless function */ 2005 static int func_nr = 0; /* number for nameless function */
2008 int paren; 2006 int paren;
2009 hashtab_T *ht; 2007 hashtab_T *ht;
2010 int todo; 2008 int todo;
2011 hashitem_T *hi; 2009 hashitem_T *hi;
2012 int do_concat = TRUE; 2010 int do_concat = TRUE;
2013 linenr_T sourcing_lnum_off; 2011 linenr_T sourcing_lnum_off;
2014 linenr_T sourcing_lnum_top; 2012 linenr_T sourcing_lnum_top;
2013 int is_heredoc = FALSE;
2014 char_u *skip_until = NULL;
2015 char_u *heredoc_trimmed = NULL;
2015 2016
2016 /* 2017 /*
2017 * ":function" without argument: list functions. 2018 * ":function" without argument: list functions.
2018 */ 2019 */
2019 if (ends_excmd(*eap->arg)) 2020 if (ends_excmd(*eap->arg))
2329 else 2330 else
2330 sourcing_lnum_off = 0; 2331 sourcing_lnum_off = 0;
2331 2332
2332 if (skip_until != NULL) 2333 if (skip_until != NULL)
2333 { 2334 {
2334 // Between ":append" and "." and between ":python <<EOF" and "EOF" 2335 // Don't check for ":endfunc" between
2335 // don't check for ":endfunc". 2336 // * ":append" and "."
2336 if (trimmed == NULL 2337 // * ":python <<EOF" and "EOF"
2337 || STRNCMP(theline, trimmed, STRLEN(trimmed)) == 0) 2338 // * ":let {var-name} =<< [trim] {marker}" and "{marker}"
2338 { 2339 if (heredoc_trimmed == NULL
2339 p = trimmed == NULL ? theline : theline + STRLEN(trimmed); 2340 || (is_heredoc && skipwhite(theline) == theline)
2341 || STRNCMP(theline, heredoc_trimmed,
2342 STRLEN(heredoc_trimmed)) == 0)
2343 {
2344 if (heredoc_trimmed == NULL)
2345 p = theline;
2346 else if (is_heredoc)
2347 p = skipwhite(theline) == theline
2348 ? theline : theline + STRLEN(heredoc_trimmed);
2349 else
2350 p = theline + STRLEN(heredoc_trimmed);
2340 if (STRCMP(p, skip_until) == 0) 2351 if (STRCMP(p, skip_until) == 0)
2341 { 2352 {
2342 VIM_CLEAR(skip_until); 2353 VIM_CLEAR(skip_until);
2343 VIM_CLEAR(trimmed); 2354 VIM_CLEAR(heredoc_trimmed);
2344 do_concat = TRUE; 2355 do_concat = TRUE;
2356 is_heredoc = FALSE;
2345 } 2357 }
2346 } 2358 }
2347 } 2359 }
2348 else 2360 else
2349 { 2361 {
2451 && ((p[0] == 'l' 2463 && ((p[0] == 'l'
2452 && p[1] == 'e' 2464 && p[1] == 'e'
2453 && (!ASCII_ISALNUM(p[2]) 2465 && (!ASCII_ISALNUM(p[2])
2454 || (p[2] == 't' && !ASCII_ISALNUM(p[3])))))) 2466 || (p[2] == 't' && !ASCII_ISALNUM(p[3]))))))
2455 { 2467 {
2456 // ":let v =<<" continues until a dot
2457 p = skipwhite(arg + 3); 2468 p = skipwhite(arg + 3);
2458 if (STRNCMP(p, "trim", 4) == 0) 2469 if (STRNCMP(p, "trim", 4) == 0)
2459 { 2470 {
2460 // Ignore leading white space. 2471 // Ignore leading white space.
2461 p = skipwhite(p + 4); 2472 p = skipwhite(p + 4);
2462 trimmed = vim_strnsave(theline, 2473 heredoc_trimmed = vim_strnsave(theline,
2463 (int)(skipwhite(theline) - theline)); 2474 (int)(skipwhite(theline) - theline));
2464 } 2475 }
2465 if (*p == NUL) 2476 skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p));
2466 skip_until = vim_strsave((char_u *)".");
2467 else
2468 skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p));
2469 do_concat = FALSE; 2477 do_concat = FALSE;
2478 is_heredoc = TRUE;
2470 } 2479 }
2471 } 2480 }
2472 2481
2473 /* Add the line to the function. */ 2482 /* Add the line to the function. */
2474 if (ga_grow(&newlines, 1 + sourcing_lnum_off) == FAIL) 2483 if (ga_grow(&newlines, 1 + sourcing_lnum_off) == FAIL)