# HG changeset patch # User Bram Moolenaar # Date 1594566903 -7200 # Node ID 8d1d11afd8c8207a8ac37763dc08b1d884035e5e # Parent acefabf736a36bc0d9599a1ca311d75b0ea2453e patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out Commit: https://github.com/vim/vim/commit/eb6880b6eb7c4631f6103575c0d1336b149348c1 Author: Bram Moolenaar Date: Sun Jul 12 17:07:05 2020 +0200 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(). diff --git a/src/dict.c b/src/dict.c --- a/src/dict.c +++ b/src/dict.c @@ -803,7 +803,7 @@ eval_dict(char_u **arg, typval_T *rettv, 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 --- 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 --- 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_ty 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 **varna 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 --- 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 --- a/src/list.c +++ b/src/list.c @@ -1167,7 +1167,7 @@ eval_list(char_u **arg, typval_T *rettv, 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 --- 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 --- 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 --- 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 --- a/src/vim9script.c +++ b/src/vim9script.c @@ -22,7 +22,9 @@ static char e_needs_vim9[] = N_("E1042: 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;