summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-07-12 17:07:05 +0200
committerBram Moolenaar <Bram@vim.org>2020-07-12 17:07:05 +0200
commiteb6880b6eb7c4631f6103575c0d1336b149348c1 (patch)
tree3ef9e464dfa615794f921e78f14fa6c14fa9a944 /src
parent8af81d656a4c501611f6211b6379ea9dd650c545 (diff)
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread outv8.2.1190
Problem: Vim9: checking for Vim9 syntax is spread out. Solution: Use in_vim9script().
Diffstat (limited to 'src')
-rw-r--r--src/dict.c2
-rw-r--r--src/eval.c11
-rw-r--r--src/evalvars.c22
-rw-r--r--src/ex_docmd.c2
-rw-r--r--src/list.c2
-rw-r--r--src/scriptfile.c2
-rw-r--r--src/userfunc.c5
-rw-r--r--src/version.c2
-rw-r--r--src/vim9script.c6
9 files changed, 26 insertions, 28 deletions
diff --git a/src/dict.c b/src/dict.c
index a549ed71b1..eedaf42686 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -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;
/*
diff --git a/src/eval.c b/src/eval.c
index 9f2c503d3b..065f7853f7 100644
--- a/src/eval.c
+++ b/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)
{
diff --git a/src/evalvars.c b/src/evalvars.c
index 6e67206dc7..197a19dd1d 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -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);
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 5436373e53..64b143be53 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -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)
{
diff --git a/src/list.c b/src/list.c
index e8d5f5f546..9a334ae45b 100644
--- a/src/list.c
+++ b/src/list.c
@@ -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)
diff --git a/src/scriptfile.c b/src/scriptfile.c
index ce4bafadaf..4e7df4d0d3 100644
--- a/src/scriptfile.c
+++ b/src/scriptfile.c
@@ -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;
diff --git a/src/userfunc.c b/src/userfunc.c
index b5b57ec880..467a04601a 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -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)
diff --git a/src/version.c b/src/version.c
index 449d402a83..8ae2f29d58 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1190,
+/**/
1189,
/**/
1188,
diff --git a/src/vim9script.c b/src/vim9script.c
index c191113c84..3c57d341bc 100644
--- a/src/vim9script.c
+++ b/src/vim9script.c
@@ -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;