Skip to content

Commit

Permalink
patch 8.2.1756: Vim9: :let will soon be disallowed
Browse files Browse the repository at this point in the history
Problem:    Vim9: :let will soon be disallowed.
Solution:   Add v:disallow_let temporarily.  Fix tests.
  • Loading branch information
brammool committed Sep 27, 2020
1 parent c0e2901 commit cfcd011
Show file tree
Hide file tree
Showing 7 changed files with 240 additions and 213 deletions.
2 changes: 2 additions & 0 deletions src/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,4 +274,6 @@ EXTERN char e_str_cannot_be_used_in_legacy_vim_script[]
INIT(= N_("E1124: \"%s\" cannot be used in legacy Vim script"));
EXTERN char e_final_requires_a_value[]
INIT(= N_("E1125: Final requires a value"));
EXTERN char e_cannot_use_let_in_vim9_script[]
INIT(= N_("E1126: Cannot use :let in Vim9 script"));
#endif
7 changes: 7 additions & 0 deletions src/evalvars.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ static struct vimvar
{VV_NAME("echospace", VAR_NUMBER), VV_RO},
{VV_NAME("argv", VAR_LIST), VV_RO},
{VV_NAME("collate", VAR_STRING), VV_RO},
{VV_NAME("disallow_let", VAR_NUMBER), 0}, // TODO: remove
};

// shorthand
Expand Down Expand Up @@ -734,6 +735,12 @@ ex_let(exarg_T *eap)
ex_finally(eap);
return;
}
if (get_vim_var_nr(VV_DISALLOW_LET)
&& eap->cmdidx == CMD_let && vim9script)
{
emsg(_(e_cannot_use_let_in_vim9_script));
return;
}
if (eap->cmdidx == CMD_const && !vim9script && !eap->forceit)
// In legacy Vim script ":const" works like ":final".
eap->cmdidx = CMD_final;
Expand Down

1 comment on commit cfcd011

@lacygoill
Copy link

@lacygoill lacygoill commented on cfcd011 Sep 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those of you who want to refactor all your lets into vars in your Vim9 scripts, try something like this (untested):

vimgrep /\%^vim9script\_.*\zs\<let\>\s/gj $MYVIMRC ~/.vim/**/*.vim
vimgrepadd /\C^\%(\s*export\s\+\)\=\s*\<def\>\%(\%(enddef\)\@!\_.\)*\zs\<let\>\s/gj $MYVIMRC ~/.vim/**/*.vim
cw
cfdo %s/\C\<let\>/var/gce
cfdo update

After that, if you want a temporary fix for the syntax highlighting, try to add this in ~/.vim/after/syntax/vim.vim:

" Problem: In `var name = 123` (Vim9 script), `var` and `name` are not highlighted correctly.
" Solution: Include `var` in the `vimLet` syntax group.
syn clear vimLet
syn keyword vimLet let var unl[et] skipwhite nextgroup=vimVar,vimFuncVar,vimLetHereDoc
"                      ^^^

Please sign in to comment.