mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
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.
This commit is contained in:
@@ -152,6 +152,28 @@ func Test_let_utf8_environment()
|
|||||||
call assert_equal('ĀĒĪŌŪあいうえお', $a)
|
call assert_equal('ĀĒĪŌŪあいうえお', $a)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_let_heredoc_fails()
|
||||||
|
call assert_fails('let v =<< marker', 'E991:')
|
||||||
|
|
||||||
|
let text =<< trim END
|
||||||
|
func WrongSyntax()
|
||||||
|
let v =<< that there
|
||||||
|
endfunc
|
||||||
|
END
|
||||||
|
call writefile(text, 'XheredocFail')
|
||||||
|
call assert_fails('source XheredocFail', 'E126:')
|
||||||
|
call delete('XheredocFail')
|
||||||
|
|
||||||
|
let text =<< trim END
|
||||||
|
func MissingEnd()
|
||||||
|
let v =<< END
|
||||||
|
endfunc
|
||||||
|
END
|
||||||
|
call writefile(text, 'XheredocWrong')
|
||||||
|
call assert_fails('source XheredocWrong', 'E126:')
|
||||||
|
call delete('XheredocWrong')
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Test for the setting a variable using the heredoc syntax
|
" Test for the setting a variable using the heredoc syntax
|
||||||
func Test_let_heredoc()
|
func Test_let_heredoc()
|
||||||
let var1 =<< END
|
let var1 =<< END
|
||||||
@@ -193,15 +215,45 @@ END
|
|||||||
.
|
.
|
||||||
call assert_equal([' Line1'], var1)
|
call assert_equal([' Line1'], var1)
|
||||||
|
|
||||||
call assert_fails('let v =<< marker', 'E991:')
|
" ignore "endfunc"
|
||||||
call assert_fails('call WrongSyntax()', 'E488:')
|
let var1 =<< END
|
||||||
call assert_fails('call MissingEnd()', 'E990:')
|
something
|
||||||
endfunc
|
endfunc
|
||||||
|
END
|
||||||
|
call assert_equal(['something', 'endfunc'], var1)
|
||||||
|
|
||||||
func WrongSyntax()
|
" ignore "endfunc" with trim
|
||||||
let fail =<< that there
|
let var1 =<< trim END
|
||||||
endfunc
|
something
|
||||||
|
endfunc
|
||||||
|
END
|
||||||
|
call assert_equal(['something', 'endfunc'], var1)
|
||||||
|
|
||||||
func MissingEnd()
|
" ignore "python << xx"
|
||||||
let fail =<< END
|
let var1 =<<END
|
||||||
|
something
|
||||||
|
python << xx
|
||||||
|
END
|
||||||
|
call assert_equal(['something', 'python << xx'], var1)
|
||||||
|
|
||||||
|
" ignore "python << xx" with trim
|
||||||
|
let var1 =<< trim END
|
||||||
|
something
|
||||||
|
python << xx
|
||||||
|
END
|
||||||
|
call assert_equal(['something', 'python << xx'], var1)
|
||||||
|
|
||||||
|
" ignore "append"
|
||||||
|
let var1 =<<
|
||||||
|
something
|
||||||
|
app
|
||||||
|
.
|
||||||
|
call assert_equal(['something', 'app'], var1)
|
||||||
|
|
||||||
|
" ignore "append" with trim
|
||||||
|
let var1 =<< trim
|
||||||
|
something
|
||||||
|
app
|
||||||
|
.
|
||||||
|
call assert_equal(['something', 'app'], var1)
|
||||||
endfunc
|
endfunc
|
||||||
|
@@ -1979,6 +1979,7 @@ ex_function(exarg_T *eap)
|
|||||||
int indent;
|
int indent;
|
||||||
int nesting;
|
int nesting;
|
||||||
char_u *skip_until = NULL;
|
char_u *skip_until = NULL;
|
||||||
|
char_u *trimmed = NULL;
|
||||||
dictitem_T *v;
|
dictitem_T *v;
|
||||||
funcdict_T fudi;
|
funcdict_T fudi;
|
||||||
static int func_nr = 0; /* number for nameless function */
|
static int func_nr = 0; /* number for nameless function */
|
||||||
@@ -2303,10 +2304,18 @@ ex_function(exarg_T *eap)
|
|||||||
|
|
||||||
if (skip_until != NULL)
|
if (skip_until != NULL)
|
||||||
{
|
{
|
||||||
/* between ":append" and "." and between ":python <<EOF" and "EOF"
|
// Between ":append" and "." and between ":python <<EOF" and "EOF"
|
||||||
* don't check for ":endfunc". */
|
// don't check for ":endfunc".
|
||||||
if (STRCMP(theline, skip_until) == 0)
|
if (trimmed == NULL
|
||||||
VIM_CLEAR(skip_until);
|
|| 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
|
else
|
||||||
{
|
{
|
||||||
@@ -2406,6 +2415,30 @@ ex_function(exarg_T *eap)
|
|||||||
else
|
else
|
||||||
skip_until = vim_strsave(p);
|
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. */
|
/* Add the line to the function. */
|
||||||
|
@@ -767,6 +767,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1356,
|
||||||
/**/
|
/**/
|
||||||
1355,
|
1355,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user