diff src/evalvars.c @ 21279:8d1d11afd8c8 v8.2.1190

patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out Commit: https://github.com/vim/vim/commit/eb6880b6eb7c4631f6103575c0d1336b149348c1 Author: Bram Moolenaar <Bram@vim.org> 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().
author Bram Moolenaar <Bram@vim.org>
date Sun, 12 Jul 2020 17:15:03 +0200
parents 7833afe1c66e
children 2c40e60017a8
line wrap: on
line diff
--- 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);