Patch 8.2.1190
Problem: Vim9: checking for Vim9 syntax is spread out.
Solution: Use in_vim9script().
Files: src/vim9script.c, src/dict.c, src/eval.c, src/evalvars.c,
src/ex_docmd.c, src/list.c, src/scriptfile.c, src/userfunc.c
*** ../vim-8.2.1189/src/vim9script.c 2020-07-08 19:35:17.767686401 +0200
--- src/vim9script.c 2020-07-12 17:02:03.894363245 +0200
***************
*** 22,28 ****
int
in_vim9script(void)
{
! // TODO: go up the stack?
return current_sctx.sc_version == SCRIPT_VERSION_VIM9;
}
--- 22,30 ----
int
in_vim9script(void)
{
! // 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,73 ****
void
ex_export(exarg_T *eap)
{
! if (current_sctx.sc_version != SCRIPT_VERSION_VIM9)
{
emsg(_(e_needs_vim9));
return;
--- 69,75 ----
void
ex_export(exarg_T *eap)
{
! if (!in_vim9script())
{
emsg(_(e_needs_vim9));
return;
*** ../vim-8.2.1189/src/dict.c 2020-07-04 14:14:55.633073475 +0200
--- src/dict.c 2020-07-12 16:57:15.547161416 +0200
***************
*** 803,809 ****
dictitem_T *item;
char_u *start = skipwhite(*arg + 1);
char_u buf[NUMBUFLEN];
! int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
int had_comma;
/*
--- 803,809 ----
dictitem_T *item;
char_u *start = skipwhite(*arg + 1);
char_u buf[NUMBUFLEN];
! int vim9script = in_vim9script();
int had_comma;
/*
*** ../vim-8.2.1189/src/eval.c 2020-07-12 16:32:16.163241486 +0200
--- src/eval.c 2020-07-12 16:58:24.626970332 +0200
***************
*** 393,399 ****
{
typval_T rettv;
int res;
! int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
garray_T *gap = &evalarg->eval_ga;
int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags;
--- 393,399 ----
{
typval_T rettv;
int res;
! int vim9script = in_vim9script();
garray_T *gap = &evalarg->eval_ga;
int save_flags = evalarg == NULL ? 0 : evalarg->eval_flags;
***************
*** 820,826 ****
{
lp->ll_name = name;
! if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 && *p == ':')
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
char_u *tp = skipwhite(p + 1);
--- 820,826 ----
{
lp->ll_name = name;
! if (in_vim9script() && *p == ':')
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
char_u *tp = skipwhite(p + 1);
***************
*** 1643,1650 ****
{
forinfo_T *fi = (forinfo_T *)fi_void;
int result;
! int flag = current_sctx.sc_version == SCRIPT_VERSION_VIM9 ?
! LET_NO_COMMAND : 0;
listitem_T *item;
if (fi->fi_blob != NULL)
--- 1643,1649 ----
{
forinfo_T *fi = (forinfo_T *)fi_void;
int result;
! int flag = in_vim9script() ? LET_NO_COMMAND : 0;
listitem_T *item;
if (fi->fi_blob != NULL)
***************
*** 1910,1916 ****
eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
{
*getnext = FALSE;
! if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
&& evalarg != NULL
&& (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL)
&& (*arg == NUL || (VIM_ISWHITE(arg[-1])
--- 1909,1915 ----
eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
{
*getnext = FALSE;
! if (in_vim9script()
&& evalarg != NULL
&& (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL)
&& (*arg == NUL || (VIM_ISWHITE(arg[-1])
***************
*** 4918,4924 ****
int br_nest = 0;
char_u *p;
int len;
! int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
if (expr_start != NULL)
{
--- 4917,4923 ----
int br_nest = 0;
char_u *p;
int len;
! int vim9script = in_vim9script();
if (expr_start != NULL)
{
*** ../vim-8.2.1189/src/evalvars.c 2020-07-11 22:25:53.403842060 +0200
--- src/evalvars.c 2020-07-12 16:59:51.338730391 +0200
***************
*** 729,735 ****
emsg(_("E985: .= is not supported with script version 2"));
else if (!ends_excmd2(eap->cmd, arg))
{
! if (current_sctx.sc_version == SCRIPT_VERSION_VIM9)
{
// Vim9 declaration ":let var: type"
arg = vim9_declare_scriptvar(eap, arg);
--- 729,735 ----
emsg(_("E985: .= is not supported with script version 2"));
else if (!ends_excmd2(eap->cmd, arg))
{
! if (in_vim9script())
{
// Vim9 declaration ":let var: type"
arg = vim9_declare_scriptvar(eap, arg);
***************
*** 993,999 ****
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)
{
// "a: type" is declaring variable "a" with a type, not "a:".
if (end == arg + 2 && end[-1] == ':')
--- 993,999 ----
return arg + 2;
end = find_name_end(*arg == '$' || *arg == '&' ? arg + 1 : arg,
NULL, NULL, FNE_INCL_BR | FNE_CHECK_START);
! if (include_type && in_vim9script())
{
// "a: type" is declaring variable "a" with a type, not "a:".
if (end == arg + 2 && end[-1] == ':')
***************
*** 1212,1219 ****
emsg(_("E996: Cannot lock an environment variable"));
return NULL;
}
! if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
! && (flags & LET_NO_COMMAND) == 0)
{
vim9_declare_error(arg);
return NULL;
--- 1212,1218 ----
emsg(_("E996: Cannot lock an environment variable"));
return NULL;
}
! if (in_vim9script() && (flags & LET_NO_COMMAND) == 0)
{
vim9_declare_error(arg);
return NULL;
***************
*** 1576,1583 ****
dict_T *d;
dictitem_T *di;
! if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
! && check_vim9_unlet(name) == FAIL)
return FAIL;
ht = find_var_ht(name, &varname);
--- 1575,1581 ----
dict_T *d;
dictitem_T *di;
! if (in_vim9script() && check_vim9_unlet(name) == FAIL)
return FAIL;
ht = find_var_ht(name, &varname);
***************
*** 2392,2399 ****
*dip = v;
}
! if (tv == NULL && (current_sctx.sc_version == SCRIPT_VERSION_VIM9
! || STRNCMP(name, "s:", 2) == 0))
{
imported_T *import;
char_u *p = STRNCMP(name, "s:", 2) == 0 ? name + 2 : name;
--- 2390,2396 ----
*dip = v;
}
! 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,2640 ****
return ht; // local variable
// in Vim9 script items at the script level are script-local
! if (current_sctx.sc_version == SCRIPT_VERSION_VIM9)
{
ht = get_script_local_ht();
if (ht != NULL)
--- 2631,2637 ----
return ht; // local variable
// in Vim9 script items at the script level are script-local
! if (in_vim9script())
{
ht = get_script_local_ht();
if (ht != NULL)
***************
*** 2897,2903 ****
}
is_script_local = ht == get_script_local_ht();
! if (current_sctx.sc_version == SCRIPT_VERSION_VIM9
&& !is_script_local
&& (flags & LET_NO_COMMAND) == 0
&& name[1] == ':')
--- 2894,2900 ----
}
is_script_local = ht == get_script_local_ht();
! if (in_vim9script()
&& !is_script_local
&& (flags & LET_NO_COMMAND) == 0
&& name[1] == ':')
***************
*** 2926,2933 ****
return;
}
! if (is_script_local
! && current_sctx.sc_version == SCRIPT_VERSION_VIM9)
{
if ((flags & LET_NO_COMMAND) == 0)
{
--- 2923,2929 ----
return;
}
! if (is_script_local && in_vim9script())
{
if ((flags & LET_NO_COMMAND) == 0)
{
***************
*** 3023,3029 ****
if (flags & LET_IS_CONST)
di->di_flags |= DI_FLAGS_LOCK;
! if (is_script_local && current_sctx.sc_version == SCRIPT_VERSION_VIM9)
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
--- 3019,3025 ----
if (flags & LET_IS_CONST)
di->di_flags |= DI_FLAGS_LOCK;
! if (is_script_local && in_vim9script())
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
*** ../vim-8.2.1189/src/ex_docmd.c 2020-07-11 14:08:01.283533287 +0200
--- src/ex_docmd.c 2020-07-12 17:00:05.030692486 +0200
***************
*** 1765,1771 ****
ea.cmd = skipwhite(ea.cmd + 1);
#ifdef FEAT_EVAL
! if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 && !starts_with_colon)
{
if (ea.cmd > cmd)
{
--- 1765,1771 ----
ea.cmd = skipwhite(ea.cmd + 1);
#ifdef FEAT_EVAL
! if (in_vim9script() && !starts_with_colon)
{
if (ea.cmd > cmd)
{
*** ../vim-8.2.1189/src/list.c 2020-07-04 14:14:55.633073475 +0200
--- src/list.c 2020-07-12 17:00:22.898643016 +0200
***************
*** 1167,1173 ****
list_T *l = NULL;
typval_T tv;
listitem_T *item;
! int vim9script = current_sctx.sc_version == SCRIPT_VERSION_VIM9;
int had_comma;
if (evaluate)
--- 1167,1173 ----
list_T *l = NULL;
typval_T tv;
listitem_T *item;
! int vim9script = in_vim9script();
int had_comma;
if (evaluate)
*** ../vim-8.2.1189/src/scriptfile.c 2020-07-08 15:16:15.534128895 +0200
--- src/scriptfile.c 2020-07-12 17:00:48.098573241 +0200
***************
*** 1876,1882 ****
emsg(_("E984: :scriptversion used outside of a sourced file"));
return;
}
! if (current_sctx.sc_version == SCRIPT_VERSION_VIM9)
{
emsg(_("E1040: Cannot use :scriptversion after :vim9script"));
return;
--- 1876,1882 ----
emsg(_("E984: :scriptversion used outside of a sourced file"));
return;
}
! if (in_vim9script())
{
emsg(_("E1040: Cannot use :scriptversion after :vim9script"));
return;
*** ../vim-8.2.1189/src/userfunc.c 2020-07-11 15:20:43.776269437 +0200
--- src/userfunc.c 2020-07-12 17:01:20.774482746 +0200
***************
*** 2388,2395 ****
}
// In Vim9 script a user function is script-local by default.
! vim9script = ASCII_ISUPPER(*start)
! && current_sctx.sc_version == SCRIPT_VERSION_VIM9;
/*
* Copy the function name to allocated memory.
--- 2388,2394 ----
}
// In Vim9 script a user function is script-local by default.
! vim9script = ASCII_ISUPPER(*start) && in_vim9script();
/*
* Copy the function name to allocated memory.
***************
*** 2469,2475 ****
{
char_u *p;
! if (*name == K_SPECIAL && current_sctx.sc_version == SCRIPT_VERSION_VIM9)
{
p = vim_strchr(name, '_');
if (p != NULL)
--- 2468,2474 ----
{
char_u *p;
! if (*name == K_SPECIAL && in_vim9script())
{
p = vim_strchr(name, '_');
if (p != NULL)
*** ../vim-8.2.1189/src/version.c 2020-07-12 16:32:16.163241486 +0200
--- src/version.c 2020-07-12 17:05:48.761314951 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1190,
/**/
--
hundred-and-one symptoms of being an internet addict:
13. You refer to going to the bathroom as downloading.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///