0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out

Problem:    Vim9: checking for Vim9 syntax is spread out.
Solution:   Use in_vim9script().
This commit is contained in:
Bram Moolenaar 2020-07-12 17:07:05 +02:00
parent 8af81d656a
commit eb6880b6eb
9 changed files with 26 additions and 28 deletions

View File

@ -803,7 +803,7 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
dictitem_T *item; dictitem_T *item;
char_u *start = skipwhite(*arg + 1); char_u *start = skipwhite(*arg + 1);
char_u buf[NUMBUFLEN]; char_u buf[NUMBUFLEN];
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9; int vim9script = in_vim9script();
int had_comma; int had_comma;
/* /*

View File

@ -393,7 +393,7 @@ skip_expr_concatenate(
{ {
typval_T rettv; typval_T rettv;
int res; int res;
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9; int vim9script = in_vim9script();
garray_T *gap = &evalarg->eval_ga; garray_T *gap = &evalarg->eval_ga;
int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags; int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags;
@ -820,7 +820,7 @@ get_lval(
{ {
lp->ll_name = name; lp->ll_name = name;
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 && *p == ':') if (in_vim9script() && *p == ':')
{ {
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
char_u *tp = skipwhite(p + 1); char_u *tp = skipwhite(p + 1);
@ -1643,8 +1643,7 @@ next_for_item(void *fi_void, char_u *arg)
{ {
forinfo_T *fi = (forinfo_T *)fi_void; forinfo_T *fi = (forinfo_T *)fi_void;
int result; int result;
int flag = current_sctx.sc_version == SCRIPT_VERSION_VIM9 ? int flag = in_vim9script() ? LET_NO_COMMAND : 0;
LET_NO_COMMAND : 0;
listitem_T *item; listitem_T *item;
if (fi->fi_blob != NULL) if (fi->fi_blob != NULL)
@ -1910,7 +1909,7 @@ eval_func(
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;
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 if (in_vim9script()
&& evalarg != NULL && evalarg != NULL
&& (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL) && (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL)
&& (*arg == NUL || (VIM_ISWHITE(arg[-1]) && (*arg == NUL || (VIM_ISWHITE(arg[-1])
@ -4918,7 +4917,7 @@ find_name_end(
int br_nest = 0; int br_nest = 0;
char_u *p; char_u *p;
int len; int len;
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9; int vim9script = in_vim9script();
if (expr_start != NULL) if (expr_start != NULL)
{ {

View File

@ -729,7 +729,7 @@ ex_let(exarg_T *eap)
emsg(_("E985: .= is not supported with script version 2")); emsg(_("E985: .= is not supported with script version 2"));
else if (!ends_excmd2(eap->cmd, arg)) else if (!ends_excmd2(eap->cmd, arg))
{ {
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9) if (in_vim9script())
{ {
// Vim9 declaration ":let var: type" // Vim9 declaration ":let var: type"
arg = vim9_declare_scriptvar(eap, arg); arg = vim9_declare_scriptvar(eap, arg);
@ -993,7 +993,7 @@ skip_var_one(char_u *arg, int include_type)
return arg + 2; return arg + 2;
end = find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg, end = find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg,
NULL, NULL, FNE_INCL_BR | FNE_CHECK_START); NULL, NULL, FNE_INCL_BR | FNE_CHECK_START);
if (include_type && current_sctx.sc_version == SCRIPT_VERSION_VIM9) if (include_type && in_vim9script())
{ {
// "a: type" is declaring variable "a" with a type, not "a:". // "a: type" is declaring variable "a" with a type, not "a:".
if (end == arg + 2 && end[-1] == ':') if (end == arg + 2 && end[-1] == ':')
@ -1212,8 +1212,7 @@ ex_let_one(
emsg(_("E996: Cannot lock an environment variable")); emsg(_("E996: Cannot lock an environment variable"));
return NULL; return NULL;
} }
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 if (in_vim9script() && (flags & LET_NO_COMMAND) == 0)
&& (flags & LET_NO_COMMAND) == 0)
{ {
vim9_declare_error(arg); vim9_declare_error(arg);
return NULL; return NULL;
@ -1576,8 +1575,7 @@ do_unlet(char_u *name, int forceit)
dict_T *d; dict_T *d;
dictitem_T *di; dictitem_T *di;
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 if (in_vim9script() && check_vim9_unlet(name) == FAIL)
&& check_vim9_unlet(name) == FAIL)
return FAIL; return FAIL;
ht = find_var_ht(name, &varname); ht = find_var_ht(name, &varname);
@ -2392,8 +2390,7 @@ eval_variable(
*dip = v; *dip = v;
} }
if (tv == NULL && (current_sctx.sc_version == SCRIPT_VERSION_VIM9 if (tv == NULL && (in_vim9script() || STRNCMP(name, "s:", 2) == 0))
|| STRNCMP(name, "s:", 2) == 0))
{ {
imported_T *import; imported_T *import;
char_u *p = STRNCMP(name, "s:", 2) == 0 ? name + 2 : name; char_u *p = STRNCMP(name, "s:", 2) == 0 ? name + 2 : name;
@ -2634,7 +2631,7 @@ find_var_ht(char_u *name, char_u **varname)
return ht; // local variable return ht; // local variable
// in Vim9 script items at the script level are script-local // in Vim9 script items at the script level are script-local
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9) if (in_vim9script())
{ {
ht = get_script_local_ht(); ht = get_script_local_ht();
if (ht != NULL) if (ht != NULL)
@ -2897,7 +2894,7 @@ set_var_const(
} }
is_script_local = ht == get_script_local_ht(); is_script_local = ht == get_script_local_ht();
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 if (in_vim9script()
&& !is_script_local && !is_script_local
&& (flags & LET_NO_COMMAND) == 0 && (flags & LET_NO_COMMAND) == 0
&& name[1] == ':') && name[1] == ':')
@ -2926,8 +2923,7 @@ set_var_const(
return; return;
} }
if (is_script_local if (is_script_local && in_vim9script())
&& current_sctx.sc_version == SCRIPT_VERSION_VIM9)
{ {
if ((flags & LET_NO_COMMAND) == 0) if ((flags & LET_NO_COMMAND) == 0)
{ {
@ -3023,7 +3019,7 @@ set_var_const(
if (flags & LET_IS_CONST) if (flags & LET_IS_CONST)
di->di_flags |= DI_FLAGS_LOCK; di->di_flags |= DI_FLAGS_LOCK;
if (is_script_local && current_sctx.sc_version == SCRIPT_VERSION_VIM9) if (is_script_local && in_vim9script())
{ {
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);

View File

@ -1765,7 +1765,7 @@ do_one_cmd(
ea.cmd = skipwhite(ea.cmd + 1); ea.cmd = skipwhite(ea.cmd + 1);
#ifdef FEAT_EVAL #ifdef FEAT_EVAL
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 && !starts_with_colon) if (in_vim9script() && !starts_with_colon)
{ {
if (ea.cmd > cmd) if (ea.cmd > cmd)
{ {

View File

@ -1167,7 +1167,7 @@ eval_list(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int do_error)
list_T *l = NULL; list_T *l = NULL;
typval_T tv; typval_T tv;
listitem_T *item; listitem_T *item;
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9; int vim9script = in_vim9script();
int had_comma; int had_comma;
if (evaluate) if (evaluate)

View File

@ -1876,7 +1876,7 @@ ex_scriptversion(exarg_T *eap UNUSED)
emsg(_("E984: :scriptversion used outside of a sourced file")); emsg(_("E984: :scriptversion used outside of a sourced file"));
return; return;
} }
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9) if (in_vim9script())
{ {
emsg(_("E1040: Cannot use :scriptversion after :vim9script")); emsg(_("E1040: Cannot use :scriptversion after :vim9script"));
return; return;

View File

@ -2388,8 +2388,7 @@ trans_function_name(
} }
// In Vim9 script a user function is script-local by default. // In Vim9 script a user function is script-local by default.
vim9script = ASCII_ISUPPER(*start) vim9script = ASCII_ISUPPER(*start) && in_vim9script();
&& current_sctx.sc_version == SCRIPT_VERSION_VIM9;
/* /*
* Copy the function name to allocated memory. * Copy the function name to allocated memory.
@ -2469,7 +2468,7 @@ untrans_function_name(char_u *name)
{ {
char_u *p; char_u *p;
if (*name == K_SPECIAL && current_sctx.sc_version == SCRIPT_VERSION_VIM9) if (*name == K_SPECIAL && in_vim9script())
{ {
p = vim_strchr(name, '_'); p = vim_strchr(name, '_');
if (p != NULL) if (p != NULL)

View File

@ -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 */
/**/
1190,
/**/ /**/
1189, 1189,
/**/ /**/

View File

@ -22,7 +22,9 @@ static char e_needs_vim9[] = N_("E1042: export can only be used in vim9script");
int int
in_vim9script(void) in_vim9script(void)
{ {
// TODO: go up the stack? // Do not go up the stack, a ":function" inside vim9script uses legacy
// syntax. "sc_version" is also set when compiling a ":def" function in
// legacy script.
return current_sctx.sc_version == SCRIPT_VERSION_VIM9; return current_sctx.sc_version == SCRIPT_VERSION_VIM9;
} }
@ -67,7 +69,7 @@ ex_vim9script(exarg_T *eap)
void void
ex_export(exarg_T *eap) ex_export(exarg_T *eap)
{ {
if (current_sctx.sc_version != SCRIPT_VERSION_VIM9) if (!in_vim9script())
{ {
emsg(_(e_needs_vim9)); emsg(_(e_needs_vim9));
return; return;