Skip to content

Commit bf5f287

Browse files
committed
patch 8.2.3365: Vim9: cannot use option for all operations
Problem: Vim9: cannot use option for all operations. Solution: Recognize more operations. (closes #8779)
1 parent bebf069 commit bf5f287

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
lines changed

src/ex_docmd.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,12 +3425,26 @@ find_ex_command(
34253425
{
34263426
char_u *pskip = skip_option_env_lead(eap->cmd);
34273427

3428-
if (vim_strchr((char_u *)"{('[\"@", *p) != NULL
3428+
if (vim_strchr((char_u *)"{('[\"@&", *p) != NULL
34293429
|| ((p = to_name_const_end(pskip)) > eap->cmd && *p != NUL))
34303430
{
34313431
int oplen;
34323432
int heredoc;
3433-
char_u *swp = skipwhite(p);
3433+
char_u *swp;
3434+
3435+
if (*eap->cmd == '&')
3436+
{
3437+
p = to_name_end(eap->cmd + 1, FALSE);
3438+
if (ends_excmd(*skipwhite(p)))
3439+
{
3440+
// "&option <NL>" is the start of an expression.
3441+
eap->cmdidx = CMD_eval;
3442+
return eap->cmd;
3443+
}
3444+
// "&option" can be followed by "->" or "=", check below
3445+
}
3446+
3447+
swp = skipwhite(p);
34343448

34353449
if (
34363450
// "(..." is an expression.
@@ -3530,10 +3544,14 @@ find_ex_command(
35303544

35313545
// Recognize an assignment if we recognize the variable name:
35323546
// "g:var = expr"
3547+
// "@r = expr"
3548+
// "&opt = expr"
35333549
// "var = expr" where "var" is a variable name or we are skipping
35343550
// (variable declaration might have been skipped).
35353551
if (*eap->cmd == '@')
35363552
p = eap->cmd + 2;
3553+
else if (*eap->cmd == '&')
3554+
p = skiptowhite_esc(eap->cmd + 1);
35373555
oplen = assignment_len(skipwhite(p), &heredoc);
35383556
if (oplen > 0)
35393557
{

src/proto/vim9compile.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ imported_T *find_imported(char_u *name, size_t len, cctx_T *cctx);
88
imported_T *find_imported_in_script(char_u *name, size_t len, int sid);
99
char_u *peek_next_line_from_context(cctx_T *cctx);
1010
char_u *next_line_from_context(cctx_T *cctx, int skip_comment);
11+
char_u *to_name_end(char_u *arg, int use_namespace);
1112
char_u *to_name_const_end(char_u *arg);
1213
int get_lambda_tv_and_compile(char_u **arg, typval_T *rettv, int types_optional, evalarg_T *evalarg);
1314
exprtype_T get_compare_type(char_u *p, int *len, int *type_is);

src/testdir/test_vim9_cmd.vim

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,22 @@ def Test_method_and_user_command()
521521
CheckScriptSuccess(lines)
522522
enddef
523523

524+
def Test_option_use_linebreak()
525+
var lines =<< trim END
526+
new
527+
&matchpairs = '(:)'
528+
&matchpairs->setline(1)
529+
&matchpairs = '[:]'
530+
&matchpairs ->setline(2)
531+
&matchpairs = '{:}'
532+
&matchpairs
533+
->setline(3)
534+
assert_equal(['(:)', '[:]', '{:}'], getline(1, '$'))
535+
bwipe!
536+
END
537+
CheckDefAndScriptSuccess(lines)
538+
enddef
539+
524540
def Test_skipped_expr_linebreak()
525541
if 0
526542
var x = []

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3365,
758760
/**/
759761
3364,
760762
/**/

src/vim9compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3579,7 +3579,7 @@ compile_call(
35793579
* Return a pointer to just after the name. Equal to "arg" if there is no
35803580
* valid name.
35813581
*/
3582-
static char_u *
3582+
char_u *
35833583
to_name_end(char_u *arg, int use_namespace)
35843584
{
35853585
char_u *p;

0 commit comments

Comments
 (0)