mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-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 vim/vim#4713)
ecaa75b4ce
This commit is contained in:
parent
3b894b1cb1
commit
76f548a476
@ -21297,8 +21297,6 @@ void ex_function(exarg_T *eap)
|
|||||||
bool overwrite = false;
|
bool overwrite = false;
|
||||||
int indent;
|
int indent;
|
||||||
int nesting;
|
int nesting;
|
||||||
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 */
|
||||||
@ -21308,6 +21306,9 @@ void ex_function(exarg_T *eap)
|
|||||||
hashitem_T *hi;
|
hashitem_T *hi;
|
||||||
linenr_T sourcing_lnum_off;
|
linenr_T sourcing_lnum_off;
|
||||||
linenr_T sourcing_lnum_top;
|
linenr_T sourcing_lnum_top;
|
||||||
|
bool is_heredoc = false;
|
||||||
|
char_u *skip_until = NULL;
|
||||||
|
char_u *heredoc_trimmed = NULL;
|
||||||
bool show_block = false;
|
bool show_block = false;
|
||||||
bool do_concat = true;
|
bool do_concat = true;
|
||||||
|
|
||||||
@ -21608,14 +21609,27 @@ void ex_function(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (skip_until != NULL) {
|
if (skip_until != NULL) {
|
||||||
// Between ":append" and "." and between ":python <<EOF" and "EOF"
|
// Don't check for ":endfunc" between
|
||||||
// don't check for ":endfunc".
|
// * ":append" and "."
|
||||||
if (trimmed == NULL || STRNCMP(theline, trimmed, STRLEN(trimmed)) == 0) {
|
// * ":python <<EOF" and "EOF"
|
||||||
p = trimmed == NULL ? theline : theline + STRLEN(trimmed);
|
// * ":let {var-name} =<< [trim] {marker}" and "{marker}"
|
||||||
|
if (heredoc_trimmed == NULL
|
||||||
|
|| (is_heredoc && skipwhite(theline) == theline)
|
||||||
|
|| STRNCMP(theline, heredoc_trimmed,
|
||||||
|
STRLEN(heredoc_trimmed)) == 0) {
|
||||||
|
if (heredoc_trimmed == NULL) {
|
||||||
|
p = theline;
|
||||||
|
} else if (is_heredoc) {
|
||||||
|
p = skipwhite(theline) == theline
|
||||||
|
? theline : theline + STRLEN(heredoc_trimmed);
|
||||||
|
} else {
|
||||||
|
p = theline + STRLEN(heredoc_trimmed);
|
||||||
|
}
|
||||||
if (STRCMP(p, skip_until) == 0) {
|
if (STRCMP(p, skip_until) == 0) {
|
||||||
XFREE_CLEAR(skip_until);
|
XFREE_CLEAR(skip_until);
|
||||||
XFREE_CLEAR(trimmed);
|
XFREE_CLEAR(heredoc_trimmed);
|
||||||
do_concat = true;
|
do_concat = true;
|
||||||
|
is_heredoc = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -21723,19 +21737,16 @@ void ex_function(exarg_T *eap)
|
|||||||
&& ((p[0] == 'l' && p[1] == 'e'
|
&& ((p[0] == 'l' && p[1] == 'e'
|
||||||
&& (!ASCII_ISALNUM(p[2])
|
&& (!ASCII_ISALNUM(p[2])
|
||||||
|| (p[2] == 't' && !ASCII_ISALNUM(p[3])))))) {
|
|| (p[2] == 't' && !ASCII_ISALNUM(p[3])))))) {
|
||||||
// ":let v =<<" continues until a dot
|
|
||||||
p = skipwhite(arg + 3);
|
p = skipwhite(arg + 3);
|
||||||
if (STRNCMP(p, "trim", 4) == 0) {
|
if (STRNCMP(p, "trim", 4) == 0) {
|
||||||
// Ignore leading white space.
|
// Ignore leading white space.
|
||||||
p = skipwhite(p + 4);
|
p = skipwhite(p + 4);
|
||||||
trimmed = vim_strnsave(theline, (int)(skipwhite(theline) - theline));
|
heredoc_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));
|
|
||||||
}
|
}
|
||||||
|
skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p));
|
||||||
do_concat = false;
|
do_concat = false;
|
||||||
|
is_heredoc = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +177,15 @@ func Test_let_heredoc_fails()
|
|||||||
call delete('XheredocBadMarker')
|
call delete('XheredocBadMarker')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_let_heredoc_trim_no_indent_marker()
|
||||||
|
let text =<< trim END
|
||||||
|
Text
|
||||||
|
with
|
||||||
|
indent
|
||||||
|
END
|
||||||
|
call assert_equal(['Text', 'with', 'indent'], text)
|
||||||
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user