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:
parent
8af81d656a
commit
eb6880b6eb
@ -803,7 +803,7 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
|
||||
dictitem_T *item;
|
||||
char_u *start = skipwhite(*arg + 1);
|
||||
char_u buf[NUMBUFLEN];
|
||||
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
|
||||
int vim9script = in_vim9script();
|
||||
int had_comma;
|
||||
|
||||
/*
|
||||
|
11
src/eval.c
11
src/eval.c
@ -393,7 +393,7 @@ skip_expr_concatenate(
|
||||
{
|
||||
typval_T rettv;
|
||||
int res;
|
||||
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
|
||||
int vim9script = in_vim9script();
|
||||
garray_T *gap = &evalarg->eval_ga;
|
||||
int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags;
|
||||
|
||||
@ -820,7 +820,7 @@ get_lval(
|
||||
{
|
||||
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);
|
||||
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;
|
||||
int result;
|
||||
int flag = current_sctx.sc_version == SCRIPT_VERSION_VIM9 ?
|
||||
LET_NO_COMMAND : 0;
|
||||
int flag = in_vim9script() ? LET_NO_COMMAND : 0;
|
||||
listitem_T *item;
|
||||
|
||||
if (fi->fi_blob != NULL)
|
||||
@ -1910,7 +1909,7 @@ eval_func(
|
||||
eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
|
||||
{
|
||||
*getnext = FALSE;
|
||||
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
|
||||
if (in_vim9script()
|
||||
&& evalarg != NULL
|
||||
&& (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL)
|
||||
&& (*arg == NUL || (VIM_ISWHITE(arg[-1])
|
||||
@ -4918,7 +4917,7 @@ find_name_end(
|
||||
int br_nest = 0;
|
||||
char_u *p;
|
||||
int len;
|
||||
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
|
||||
int vim9script = in_vim9script();
|
||||
|
||||
if (expr_start != NULL)
|
||||
{
|
||||
|
@ -729,7 +729,7 @@ ex_let(exarg_T *eap)
|
||||
emsg(_("E985: .= is not supported with script version 2"));
|
||||
else if (!ends_excmd2(eap->cmd, arg))
|
||||
{
|
||||
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9)
|
||||
if (in_vim9script())
|
||||
{
|
||||
// Vim9 declaration ":let var: type"
|
||||
arg = vim9_declare_scriptvar(eap, arg);
|
||||
@ -993,7 +993,7 @@ skip_var_one(char_u *arg, int include_type)
|
||||
return arg + 2;
|
||||
end = find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg,
|
||||
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:".
|
||||
if (end == arg + 2 && end[-1] == ':')
|
||||
@ -1212,8 +1212,7 @@ ex_let_one(
|
||||
emsg(_("E996: Cannot lock an environment variable"));
|
||||
return NULL;
|
||||
}
|
||||
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
|
||||
&& (flags & LET_NO_COMMAND) == 0)
|
||||
if (in_vim9script() && (flags & LET_NO_COMMAND) == 0)
|
||||
{
|
||||
vim9_declare_error(arg);
|
||||
return NULL;
|
||||
@ -1576,8 +1575,7 @@ do_unlet(char_u *name, int forceit)
|
||||
dict_T *d;
|
||||
dictitem_T *di;
|
||||
|
||||
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
|
||||
&& check_vim9_unlet(name) == FAIL)
|
||||
if (in_vim9script() && check_vim9_unlet(name) == FAIL)
|
||||
return FAIL;
|
||||
|
||||
ht = find_var_ht(name, &varname);
|
||||
@ -2392,8 +2390,7 @@ eval_variable(
|
||||
*dip = v;
|
||||
}
|
||||
|
||||
if (tv == NULL && (current_sctx.sc_version == SCRIPT_VERSION_VIM9
|
||||
|| STRNCMP(name, "s:", 2) == 0))
|
||||
if (tv == NULL && (in_vim9script() || STRNCMP(name, "s:", 2) == 0))
|
||||
{
|
||||
imported_T *import;
|
||||
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
|
||||
|
||||
// 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();
|
||||
if (ht != NULL)
|
||||
@ -2897,7 +2894,7 @@ set_var_const(
|
||||
}
|
||||
is_script_local = ht == get_script_local_ht();
|
||||
|
||||
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
|
||||
if (in_vim9script()
|
||||
&& !is_script_local
|
||||
&& (flags & LET_NO_COMMAND) == 0
|
||||
&& name[1] == ':')
|
||||
@ -2926,8 +2923,7 @@ set_var_const(
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_script_local
|
||||
&& current_sctx.sc_version == SCRIPT_VERSION_VIM9)
|
||||
if (is_script_local && in_vim9script())
|
||||
{
|
||||
if ((flags & LET_NO_COMMAND) == 0)
|
||||
{
|
||||
@ -3023,7 +3019,7 @@ set_var_const(
|
||||
if (flags & LET_IS_CONST)
|
||||
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);
|
||||
|
||||
|
@ -1765,7 +1765,7 @@ do_one_cmd(
|
||||
ea.cmd = skipwhite(ea.cmd + 1);
|
||||
|
||||
#ifdef FEAT_EVAL
|
||||
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 && !starts_with_colon)
|
||||
if (in_vim9script() && !starts_with_colon)
|
||||
{
|
||||
if (ea.cmd > cmd)
|
||||
{
|
||||
|
@ -1167,7 +1167,7 @@ eval_list(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int do_error)
|
||||
list_T *l = NULL;
|
||||
typval_T tv;
|
||||
listitem_T *item;
|
||||
int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
|
||||
int vim9script = in_vim9script();
|
||||
int had_comma;
|
||||
|
||||
if (evaluate)
|
||||
|
@ -1876,7 +1876,7 @@ ex_scriptversion(exarg_T *eap UNUSED)
|
||||
emsg(_("E984: :scriptversion used outside of a sourced file"));
|
||||
return;
|
||||
}
|
||||
if (current_sctx.sc_version == SCRIPT_VERSION_VIM9)
|
||||
if (in_vim9script())
|
||||
{
|
||||
emsg(_("E1040: Cannot use :scriptversion after :vim9script"));
|
||||
return;
|
||||
|
@ -2388,8 +2388,7 @@ trans_function_name(
|
||||
}
|
||||
|
||||
// In Vim9 script a user function is script-local by default.
|
||||
vim9script = ASCII_ISUPPER(*start)
|
||||
&& current_sctx.sc_version == SCRIPT_VERSION_VIM9;
|
||||
vim9script = ASCII_ISUPPER(*start) && in_vim9script();
|
||||
|
||||
/*
|
||||
* Copy the function name to allocated memory.
|
||||
@ -2469,7 +2468,7 @@ untrans_function_name(char_u *name)
|
||||
{
|
||||
char_u *p;
|
||||
|
||||
if (*name == K_SPECIAL && current_sctx.sc_version == SCRIPT_VERSION_VIM9)
|
||||
if (*name == K_SPECIAL && in_vim9script())
|
||||
{
|
||||
p = vim_strchr(name, '_');
|
||||
if (p != NULL)
|
||||
|
@ -754,6 +754,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1190,
|
||||
/**/
|
||||
1189,
|
||||
/**/
|
||||
|
@ -22,7 +22,9 @@ static char e_needs_vim9[] = N_("E1042: export can only be used in vim9script");
|
||||
int
|
||||
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;
|
||||
}
|
||||
|
||||
@ -67,7 +69,7 @@ ex_vim9script(exarg_T *eap)
|
||||
void
|
||||
ex_export(exarg_T *eap)
|
||||
{
|
||||
if (current_sctx.sc_version != SCRIPT_VERSION_VIM9)
|
||||
if (!in_vim9script())
|
||||
{
|
||||
emsg(_(e_needs_vim9));
|
||||
return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user