1
0
forked from aniani/vim

patch 8.2.0427: it is not possible to check for a typo in a feature name

Problem:    It is not possible to check for a typo in a feature name.
Solution:   Add an extra argument to has().
This commit is contained in:
Bram Moolenaar
2020-03-22 16:17:14 +01:00
parent 9b9be007e7
commit 7929651e05
5 changed files with 1232 additions and 536 deletions

View File

@@ -1,4 +1,4 @@
*eval.txt* For Vim version 8.2. Last change: 2020 Mar 16 *eval.txt* For Vim version 8.2. Last change: 2020 Mar 22
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@@ -2515,7 +2515,7 @@ glob({expr} [, {nosuf} [, {list} [, {alllinks}]]])
glob2regpat({expr}) String convert a glob pat into a search pat glob2regpat({expr}) String convert a glob pat into a search pat
globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]]) globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
String do glob({expr}) for all dirs in {path} String do glob({expr}) for all dirs in {path}
has({feature}) Number |TRUE| if feature {feature} supported has({feature} [, {check}]) Number |TRUE| if feature {feature} supported
has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key} has_key({dict}, {key}) Number |TRUE| if {dict} has entry {key}
haslocaldir([{winnr} [, {tabnr}]]) haslocaldir([{winnr} [, {tabnr}]])
Number |TRUE| if the window executed |:lcd| Number |TRUE| if the window executed |:lcd|
@@ -4358,8 +4358,8 @@ feedkeys({string} [, {mode}]) *feedkeys()*
'L' Lowlevel input. Only works for Unix or when using the 'L' Lowlevel input. Only works for Unix or when using the
GUI. Keys are used as if they were coming from the GUI. Keys are used as if they were coming from the
terminal. Other flags are not used. *E980* terminal. Other flags are not used. *E980*
When a CTRL-C interrupts it sets the internal When a CTRL-C interrupts and 't' is included it sets
"got_int" flag. the internal "got_int" flag.
'i' Insert the string instead of appending (see above). 'i' Insert the string instead of appending (see above).
'x' Execute commands until typeahead is empty. This is 'x' Execute commands until typeahead is empty. This is
similar to using ":normal!". You can call feedkeys() similar to using ":normal!". You can call feedkeys()
@@ -5828,10 +5828,20 @@ globpath({path}, {expr} [, {nosuf} [, {list} [, {alllinks}]]])
GetExpr()->globpath(&rtp) GetExpr()->globpath(&rtp)
< <
*has()* *has()*
has({feature}) The result is a Number, which is 1 if the feature {feature} is has({feature} [, {check}])
supported, zero otherwise. The {feature} argument is a When {check} is omitted or is zero: The result is a Number,
string. See |feature-list| below. which is 1 if the feature {feature} is supported, zero
otherwise. The {feature} argument is a string, case is
ignored. See |feature-list| below.
When {check} is present and not zero: The result is a Number,
which is 1 if the feature {feature} could ever be supported,
zero otherwise. This is useful to check for a typo in
{feature}. Keep in mind that an older Vim version will not
know about a feature added later.
Also see |exists()|. Also see |exists()|.
Note that to skip code that has a syntax error when the Note that to skip code that has a syntax error when the
feature is not available, Vim may skip the rest of the line feature is not available, Vim may skip the rest of the line
and miss a following `endif`. Therfore put the `endif` on a and miss a following `endif`. Therfore put the `endif` on a

File diff suppressed because it is too large Load Diff

View File

@@ -6,6 +6,9 @@ command -nargs=1 MissingFeature throw 'Skipped: ' .. <args> .. ' feature missing
" Command to check for the presence of a feature. " Command to check for the presence of a feature.
command -nargs=1 CheckFeature call CheckFeature(<f-args>) command -nargs=1 CheckFeature call CheckFeature(<f-args>)
func CheckFeature(name) func CheckFeature(name)
if !has(a:name, 1)
throw 'Checking for non-existent feature ' .. a:name
endif
if !has(a:name) if !has(a:name)
MissingFeature a:name MissingFeature a:name
endif endif

View File

@@ -20,6 +20,14 @@ func Test_00_bufexists()
call assert_equal(0, bufexists('Xfoo')) call assert_equal(0, bufexists('Xfoo'))
endfunc endfunc
func Test_has()
call assert_equal(1, has('eval'))
call assert_equal(1, has('eval', 1))
call assert_equal(0, has('nonexistent'))
call assert_equal(0, has('nonexistent', 1))
endfunc
func Test_empty() func Test_empty()
call assert_equal(1, empty('')) call assert_equal(1, empty(''))
call assert_equal(0, empty('a')) call assert_equal(0, empty('a'))
@@ -1586,7 +1594,7 @@ func Test_confirm()
call assert_equal(2, a) call assert_equal(2, a)
" confirm() should return 0 when pressing CTRL-C. " confirm() should return 0 when pressing CTRL-C.
call feedkeys("\<C-c>", 'L') call feedkeys("\<C-C>", 'L')
let a = confirm('Are you sure?', "&Yes\n&No") let a = confirm('Are you sure?', "&Yes\n&No")
call assert_equal(0, a) call assert_equal(0, a)

View File

@@ -738,6 +738,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 */
/**/
427,
/**/ /**/
426, 426,
/**/ /**/