mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.1065: Vim9: no line break allowed inside a list
Problem: Vim9: no line break allowed inside a list. Solution: Handle line break inside a list in Vim9 script.
This commit is contained in:
@@ -1771,7 +1771,7 @@ eval_func(
|
|||||||
* Otherwise just return "arg" unmodified and set "getnext" to FALSE.
|
* Otherwise just return "arg" unmodified and set "getnext" to FALSE.
|
||||||
* "arg" must point somewhere inside a line, not at the start.
|
* "arg" must point somewhere inside a line, not at the start.
|
||||||
*/
|
*/
|
||||||
static char_u *
|
char_u *
|
||||||
eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
|
eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
|
||||||
{
|
{
|
||||||
*getnext = FALSE;
|
*getnext = FALSE;
|
||||||
@@ -1796,7 +1796,7 @@ eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
|
|||||||
/*
|
/*
|
||||||
* To be called when eval_next_non_blank() sets "getnext" to TRUE.
|
* To be called when eval_next_non_blank() sets "getnext" to TRUE.
|
||||||
*/
|
*/
|
||||||
static char_u *
|
char_u *
|
||||||
eval_next_line(evalarg_T *evalarg)
|
eval_next_line(evalarg_T *evalarg)
|
||||||
{
|
{
|
||||||
vim_free(evalarg->eval_tofree);
|
vim_free(evalarg->eval_tofree);
|
||||||
@@ -2773,7 +2773,7 @@ eval7(
|
|||||||
/*
|
/*
|
||||||
* List: [expr, expr]
|
* List: [expr, expr]
|
||||||
*/
|
*/
|
||||||
case '[': ret = get_list_tv(arg, rettv, flags, TRUE);
|
case '[': ret = get_list_tv(arg, rettv, evalarg, TRUE);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
30
src/list.c
30
src/list.c
@@ -1156,19 +1156,19 @@ f_join(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate a variable for a List and fill it from "*arg".
|
* Allocate a variable for a List and fill it from "*arg".
|
||||||
|
* "*arg" points to the "[".
|
||||||
* Return OK or FAIL.
|
* Return OK or FAIL.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
get_list_tv(char_u **arg, typval_T *rettv, int flags, int do_error)
|
get_list_tv(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int do_error)
|
||||||
{
|
{
|
||||||
int evaluate = flags & EVAL_EVALUATE;
|
int evaluate = evalarg == NULL ? FALSE
|
||||||
|
: evalarg->eval_flags & EVAL_EVALUATE;
|
||||||
|
int getnext;
|
||||||
list_T *l = NULL;
|
list_T *l = NULL;
|
||||||
typval_T tv;
|
typval_T tv;
|
||||||
listitem_T *item;
|
listitem_T *item;
|
||||||
evalarg_T evalarg;
|
int had_comma;
|
||||||
|
|
||||||
CLEAR_FIELD(evalarg);
|
|
||||||
evalarg.eval_flags = flags;
|
|
||||||
|
|
||||||
if (evaluate)
|
if (evaluate)
|
||||||
{
|
{
|
||||||
@@ -1178,9 +1178,12 @@ get_list_tv(char_u **arg, typval_T *rettv, int flags, int do_error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
*arg = skipwhite(*arg + 1);
|
*arg = skipwhite(*arg + 1);
|
||||||
|
eval_next_non_blank(*arg, evalarg, &getnext);
|
||||||
|
if (getnext)
|
||||||
|
*arg = eval_next_line(evalarg);
|
||||||
while (**arg != ']' && **arg != NUL)
|
while (**arg != ']' && **arg != NUL)
|
||||||
{
|
{
|
||||||
if (eval1(arg, &tv, &evalarg) == FAIL) // recursive!
|
if (eval1(arg, &tv, evalarg) == FAIL) // recursive!
|
||||||
goto failret;
|
goto failret;
|
||||||
if (evaluate)
|
if (evaluate)
|
||||||
{
|
{
|
||||||
@@ -1195,15 +1198,24 @@ get_list_tv(char_u **arg, typval_T *rettv, int flags, int do_error)
|
|||||||
clear_tv(&tv);
|
clear_tv(&tv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the comma must comma after the value
|
||||||
|
had_comma = **arg == ',';
|
||||||
|
if (had_comma)
|
||||||
|
*arg = skipwhite(*arg + 1);
|
||||||
|
|
||||||
|
// the "]" can be on the next line
|
||||||
|
eval_next_non_blank(*arg, evalarg, &getnext);
|
||||||
|
if (getnext)
|
||||||
|
*arg = eval_next_line(evalarg);
|
||||||
if (**arg == ']')
|
if (**arg == ']')
|
||||||
break;
|
break;
|
||||||
if (**arg != ',')
|
|
||||||
|
if (!had_comma)
|
||||||
{
|
{
|
||||||
if (do_error)
|
if (do_error)
|
||||||
semsg(_("E696: Missing comma in List: %s"), *arg);
|
semsg(_("E696: Missing comma in List: %s"), *arg);
|
||||||
goto failret;
|
goto failret;
|
||||||
}
|
}
|
||||||
*arg = skipwhite(*arg + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (**arg != ']')
|
if (**arg != ']')
|
||||||
|
@@ -26,6 +26,8 @@ int next_for_item(void *fi_void, char_u *arg);
|
|||||||
void free_for_info(void *fi_void);
|
void free_for_info(void *fi_void);
|
||||||
void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx);
|
void set_context_for_expression(expand_T *xp, char_u *arg, cmdidx_T cmdidx);
|
||||||
int pattern_match(char_u *pat, char_u *text, int ic);
|
int pattern_match(char_u *pat, char_u *text, int ic);
|
||||||
|
char_u *eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext);
|
||||||
|
char_u *eval_next_line(evalarg_T *evalarg);
|
||||||
int eval0(char_u *arg, typval_T *rettv, exarg_T *eap, evalarg_T *evalarg);
|
int eval0(char_u *arg, typval_T *rettv, exarg_T *eap, evalarg_T *evalarg);
|
||||||
int eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
|
int eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg);
|
||||||
void eval_addblob(typval_T *tv1, typval_T *tv2);
|
void eval_addblob(typval_T *tv1, typval_T *tv2);
|
||||||
|
@@ -39,7 +39,7 @@ void vimlist_remove(list_T *l, listitem_T *item, listitem_T *item2);
|
|||||||
char_u *list2string(typval_T *tv, int copyID, int restore_copyID);
|
char_u *list2string(typval_T *tv, int copyID, int restore_copyID);
|
||||||
int list_join(garray_T *gap, list_T *l, char_u *sep, int echo_style, int restore_copyID, int copyID);
|
int list_join(garray_T *gap, list_T *l, char_u *sep, int echo_style, int restore_copyID, int copyID);
|
||||||
void f_join(typval_T *argvars, typval_T *rettv);
|
void f_join(typval_T *argvars, typval_T *rettv);
|
||||||
int get_list_tv(char_u **arg, typval_T *rettv, int flags, int do_error);
|
int get_list_tv(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int do_error);
|
||||||
int write_list(FILE *fd, list_T *list, int binary);
|
int write_list(FILE *fd, list_T *list, int binary);
|
||||||
void init_static_list(staticList10_T *sl);
|
void init_static_list(staticList10_T *sl);
|
||||||
void f_list2str(typval_T *argvars, typval_T *rettv);
|
void f_list2str(typval_T *argvars, typval_T *rettv);
|
||||||
|
@@ -175,6 +175,7 @@ func Test_argument()
|
|||||||
|
|
||||||
let save_columns = &columns
|
let save_columns = &columns
|
||||||
let &columns = 79
|
let &columns = 79
|
||||||
|
try
|
||||||
exe 'args ' .. join(range(1, 81))
|
exe 'args ' .. join(range(1, 81))
|
||||||
call assert_equal(join([
|
call assert_equal(join([
|
||||||
\ '',
|
\ '',
|
||||||
@@ -190,7 +191,9 @@ func Test_argument()
|
|||||||
let long_arg = repeat('X', 81)
|
let long_arg = repeat('X', 81)
|
||||||
exe 'args ' .. long_arg
|
exe 'args ' .. long_arg
|
||||||
call assert_equal("\n[".long_arg.']', execute('args'))
|
call assert_equal("\n[".long_arg.']', execute('args'))
|
||||||
|
finally
|
||||||
let &columns = save_columns
|
let &columns = save_columns
|
||||||
|
endtry
|
||||||
|
|
||||||
" Setting argument list should fail when the current buffer has unsaved
|
" Setting argument list should fail when the current buffer has unsaved
|
||||||
" changes
|
" changes
|
||||||
|
@@ -974,7 +974,7 @@ def Test_expr7_list()
|
|||||||
" list
|
" list
|
||||||
assert_equal(g:list_empty, [])
|
assert_equal(g:list_empty, [])
|
||||||
assert_equal(g:list_empty, [ ])
|
assert_equal(g:list_empty, [ ])
|
||||||
assert_equal(g:list_mixed, [1, 'b', false])
|
assert_equal(g:list_mixed, [1, 'b', false,])
|
||||||
assert_equal('b', g:list_mixed[1])
|
assert_equal('b', g:list_mixed[1])
|
||||||
|
|
||||||
call CheckDefExecFailure(["let x = g:anint[3]"], 'E714:')
|
call CheckDefExecFailure(["let x = g:anint[3]"], 'E714:')
|
||||||
@@ -984,6 +984,26 @@ def Test_expr7_list()
|
|||||||
call CheckDefExecFailure(["let x = g:list_empty[3]"], 'E684:')
|
call CheckDefExecFailure(["let x = g:list_empty[3]"], 'E684:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_expr7_list_vim9script()
|
||||||
|
let lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
let l = [
|
||||||
|
11,
|
||||||
|
22,
|
||||||
|
]
|
||||||
|
assert_equal([11, 22], l)
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
let l = [11,
|
||||||
|
22]
|
||||||
|
assert_equal([11, 22], l)
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_expr7_lambda()
|
def Test_expr7_lambda()
|
||||||
" lambda
|
" lambda
|
||||||
let La = { -> 'result'}
|
let La = { -> 'result'}
|
||||||
|
@@ -754,6 +754,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 */
|
||||||
|
/**/
|
||||||
|
1065,
|
||||||
/**/
|
/**/
|
||||||
1064,
|
1064,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -2989,7 +2989,7 @@ to_name_const_end(char_u *arg)
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Can be "[1, 2, 3]->Func()".
|
// Can be "[1, 2, 3]->Func()".
|
||||||
if (get_list_tv(&p, &rettv, 0, FALSE) == FAIL)
|
if (get_list_tv(&p, &rettv, NULL, FALSE) == FAIL)
|
||||||
p = arg;
|
p = arg;
|
||||||
}
|
}
|
||||||
else if (p == arg && *arg == '#' && arg[1] == '{')
|
else if (p == arg && *arg == '#' && arg[1] == '{')
|
||||||
|
Reference in New Issue
Block a user