mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.1.1188: not all Vim variables require the v: prefix
Problem: Not all Vim variables require the v: prefix. Solution: When scriptversion is 3 all Vim variables can only be used with the v: prefix. (Ken Takata, closes #4274)
This commit is contained in:
@@ -1688,7 +1688,8 @@ v:count The count given for the last Normal mode command. Can be used
|
|||||||
When there are two counts, as in "3d2w", they are multiplied,
|
When there are two counts, as in "3d2w", they are multiplied,
|
||||||
just like what happens in the command, "d6w" for the example.
|
just like what happens in the command, "d6w" for the example.
|
||||||
Also used for evaluating the 'formatexpr' option.
|
Also used for evaluating the 'formatexpr' option.
|
||||||
"count" also works, for backwards compatibility.
|
"count" also works, for backwards compatibility, unless
|
||||||
|
|scriptversion| is 3 or higher.
|
||||||
|
|
||||||
*v:count1* *count1-variable*
|
*v:count1* *count1-variable*
|
||||||
v:count1 Just like "v:count", but defaults to one when no count is
|
v:count1 Just like "v:count", but defaults to one when no count is
|
||||||
@@ -1720,7 +1721,8 @@ v:errmsg Last given error message. It's allowed to set this variable.
|
|||||||
:silent! next
|
:silent! next
|
||||||
:if v:errmsg != ""
|
:if v:errmsg != ""
|
||||||
: ... handle error
|
: ... handle error
|
||||||
< "errmsg" also works, for backwards compatibility.
|
< "errmsg" also works, for backwards compatibility, unless
|
||||||
|
|scriptversion| is 3 or higher.
|
||||||
|
|
||||||
*v:errors* *errors-variable* *assert-return*
|
*v:errors* *errors-variable* *assert-return*
|
||||||
v:errors Errors found by assert functions, such as |assert_true()|.
|
v:errors Errors found by assert functions, such as |assert_true()|.
|
||||||
@@ -2023,7 +2025,8 @@ v:shell_error Result of the last shell command. When non-zero, the last
|
|||||||
:if v:shell_error
|
:if v:shell_error
|
||||||
: echo 'could not rename "foo" to "bar"!'
|
: echo 'could not rename "foo" to "bar"!'
|
||||||
:endif
|
:endif
|
||||||
< "shell_error" also works, for backwards compatibility.
|
< "shell_error" also works, for backwards compatibility, unless
|
||||||
|
|scriptversion| is 3 or higher.
|
||||||
|
|
||||||
*v:statusmsg* *statusmsg-variable*
|
*v:statusmsg* *statusmsg-variable*
|
||||||
v:statusmsg Last given status message. It's allowed to set this variable.
|
v:statusmsg Last given status message. It's allowed to set this variable.
|
||||||
@@ -2123,7 +2126,8 @@ v:testing Must be set before using `test_garbagecollect_now()`.
|
|||||||
v:this_session Full filename of the last loaded or saved session file. See
|
v:this_session Full filename of the last loaded or saved session file. See
|
||||||
|:mksession|. It is allowed to set this variable. When no
|
|:mksession|. It is allowed to set this variable. When no
|
||||||
session file has been saved, this variable is empty.
|
session file has been saved, this variable is empty.
|
||||||
"this_session" also works, for backwards compatibility.
|
"this_session" also works, for backwards compatibility, unless
|
||||||
|
|scriptversion| is 3 or higher
|
||||||
|
|
||||||
*v:throwpoint* *throwpoint-variable*
|
*v:throwpoint* *throwpoint-variable*
|
||||||
v:throwpoint The point where the exception most recently caught and not
|
v:throwpoint The point where the exception most recently caught and not
|
||||||
@@ -2154,7 +2158,7 @@ v:val Value of the current item of a |List| or |Dictionary|. Only
|
|||||||
v:version Version number of Vim: Major version number times 100 plus
|
v:version Version number of Vim: Major version number times 100 plus
|
||||||
minor version number. Version 5.0 is 500. Version 5.1 (5.01)
|
minor version number. Version 5.0 is 500. Version 5.1 (5.01)
|
||||||
is 501. Read-only. "version" also works, for backwards
|
is 501. Read-only. "version" also works, for backwards
|
||||||
compatibility.
|
compatibility, unless |scriptversion| is 3 or higher.
|
||||||
Use |has()| to check if a certain patch was included, e.g.: >
|
Use |has()| to check if a certain patch was included, e.g.: >
|
||||||
if has("patch-7.4.123")
|
if has("patch-7.4.123")
|
||||||
< Note that patch numbers are specific to the version, thus both
|
< Note that patch numbers are specific to the version, thus both
|
||||||
|
12
src/eval.c
12
src/eval.c
@@ -7672,10 +7672,14 @@ find_var_ht(char_u *name, char_u **varname)
|
|||||||
return NULL;
|
return NULL;
|
||||||
*varname = name;
|
*varname = name;
|
||||||
|
|
||||||
/* "version" is "v:version" in all scopes */
|
// "version" is "v:version" in all scopes if scriptversion < 3.
|
||||||
hi = hash_find(&compat_hashtab, name);
|
// Same for a few other variables marked with VV_COMPAT.
|
||||||
if (!HASHITEM_EMPTY(hi))
|
if (current_sctx.sc_version < 3)
|
||||||
return &compat_hashtab;
|
{
|
||||||
|
hi = hash_find(&compat_hashtab, name);
|
||||||
|
if (!HASHITEM_EMPTY(hi))
|
||||||
|
return &compat_hashtab;
|
||||||
|
}
|
||||||
|
|
||||||
ht = get_funccal_local_ht();
|
ht = get_funccal_local_ht();
|
||||||
if (ht == NULL)
|
if (ht == NULL)
|
||||||
|
@@ -5127,7 +5127,7 @@ ex_scriptversion(exarg_T *eap UNUSED)
|
|||||||
nr = getdigits(&eap->arg);
|
nr = getdigits(&eap->arg);
|
||||||
if (nr == 0 || *eap->arg != NUL)
|
if (nr == 0 || *eap->arg != NUL)
|
||||||
emsg(_(e_invarg));
|
emsg(_(e_invarg));
|
||||||
else if (nr > 2)
|
else if (nr > 3)
|
||||||
semsg(_("E999: scriptversion not supported: %d"), nr);
|
semsg(_("E999: scriptversion not supported: %d"), nr);
|
||||||
else
|
else
|
||||||
current_sctx.sc_version = nr;
|
current_sctx.sc_version = nr;
|
||||||
|
@@ -154,6 +154,22 @@ func Test_string_concat_scriptversion1()
|
|||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
scriptversion 3
|
||||||
|
func Test_vvar_scriptversion3()
|
||||||
|
call assert_fails('echo version', 'E121:')
|
||||||
|
call assert_false(exists('version'))
|
||||||
|
let version = 1
|
||||||
|
call assert_equal(1, version)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
scriptversion 2
|
||||||
|
func Test_vvar_scriptversion2()
|
||||||
|
call assert_true(exists('version'))
|
||||||
|
echo version
|
||||||
|
call assert_fails('let version = 1', 'E46:')
|
||||||
|
call assert_equal(v:version, version)
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_scriptversion()
|
func Test_scriptversion()
|
||||||
call writefile(['scriptversion 9'], 'Xversionscript')
|
call writefile(['scriptversion 9'], 'Xversionscript')
|
||||||
call assert_fails('source Xversionscript', 'E999:')
|
call assert_fails('source Xversionscript', 'E999:')
|
||||||
|
@@ -771,6 +771,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1188,
|
||||||
/**/
|
/**/
|
||||||
1187,
|
1187,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user