forked from aniani/vim
patch 8.1.1807: more functions can be used as a method
Problem: More functions can be used as a method.
Solution: Add append(), appendbufline(), assert_equal(), etc.
Also add the :eval command.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
*eval.txt* For Vim version 8.1. Last change: 2019 Jul 30
|
||||
*eval.txt* For Vim version 8.1. Last change: 2019 Aug 04
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -840,12 +840,14 @@ Expression syntax summary, from least to most significant:
|
||||
expr8[expr1 : expr1] substring of a String or sublist of a |List|
|
||||
expr8.name entry in a |Dictionary|
|
||||
expr8(expr1, ...) function call with |Funcref| variable
|
||||
expr8->name(expr1, ...) |method| call
|
||||
|
||||
|expr9| number number constant
|
||||
"string" string constant, backslash is special
|
||||
'string' string constant, ' is doubled
|
||||
[expr1, ...] |List|
|
||||
{expr1: expr1, ...} |Dictionary|
|
||||
#{key: expr1, ...} |Dictionary|
|
||||
&option option value
|
||||
(expr1) nested expression
|
||||
variable internal variable
|
||||
@@ -1111,10 +1113,10 @@ expr8 *expr8*
|
||||
-----
|
||||
This expression is either |expr9| or a sequence of the alternatives below,
|
||||
in any order. E.g., these are all possible:
|
||||
expr9[expr1].name
|
||||
expr9.name[expr1]
|
||||
expr9(expr1, ...)[expr1].name
|
||||
expr9->(expr1, ...)[expr1]
|
||||
expr8[expr1].name
|
||||
expr8.name[expr1]
|
||||
expr8(expr1, ...)[expr1].name
|
||||
expr8->(expr1, ...)[expr1]
|
||||
Evaluation is always from left to right.
|
||||
|
||||
|
||||
@@ -1217,10 +1219,17 @@ When expr8 is a |Funcref| type variable, invoke the function it refers to.
|
||||
|
||||
expr8->name([args]) method call *method*
|
||||
|
||||
For global methods this is the same as: >
|
||||
For methods that are also available as global functions this is the same as: >
|
||||
name(expr8 [, args])
|
||||
There can also be methods specifically for the type of "expr8".
|
||||
|
||||
"->name(" must not contain white space. There can be white space before "->"
|
||||
and after the "(".
|
||||
|
||||
This allows for chaining, using the type that the method returns: >
|
||||
mylist->filter(filterexpr)->map(mapexpr)->sort()->join()
|
||||
<
|
||||
|
||||
*expr9*
|
||||
number
|
||||
------
|
||||
@@ -2906,6 +2915,10 @@ append({lnum}, {text}) *append()*
|
||||
:let failed = append(line('$'), "# THE END")
|
||||
:let failed = append(0, ["Chapter 1", "the beginning"])
|
||||
|
||||
< Can also be used as a |method| after a List: >
|
||||
mylist->append(lnum)
|
||||
|
||||
|
||||
appendbufline({expr}, {lnum}, {text}) *appendbufline()*
|
||||
Like |append()| but append the text in buffer {expr}.
|
||||
|
||||
@@ -2921,8 +2934,11 @@ appendbufline({expr}, {lnum}, {text}) *appendbufline()*
|
||||
error message is given. Example: >
|
||||
:let failed = appendbufline(13, 0, "# THE START")
|
||||
<
|
||||
*argc()*
|
||||
argc([{winid}])
|
||||
Can also be used as a |method| after a List: >
|
||||
mylist->appendbufline(buf, lnum)
|
||||
|
||||
|
||||
argc([{winid}]) *argc()*
|
||||
The result is the number of files in the argument list. See
|
||||
|arglist|.
|
||||
If {winid} is not supplied, the argument list of the current
|
||||
@@ -3762,6 +3778,9 @@ eval({string}) Evaluate {string} and return the result. Especially useful to
|
||||
of them. Also works for |Funcref|s that refer to existing
|
||||
functions.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
argv->join()->eval()
|
||||
|
||||
eventhandler() *eventhandler()*
|
||||
Returns 1 when inside an event handler. That is that Vim got
|
||||
interrupted while waiting for the user to type a character,
|
||||
@@ -4115,7 +4134,12 @@ filereadable({file}) *filereadable()*
|
||||
expression, which is used as a String.
|
||||
If you don't care about the file being readable you can use
|
||||
|glob()|.
|
||||
*file_readable()*
|
||||
{file} is used as-is, you may want to expand wildcards first: >
|
||||
echo filereadable('~/.vimrc')
|
||||
0
|
||||
echo filereadable(expand('~/.vimrc'))
|
||||
1
|
||||
< *file_readable()*
|
||||
Obsolete name: file_readable().
|
||||
|
||||
|
||||
@@ -7998,9 +8022,9 @@ sha256({string}) *sha256()*
|
||||
|
||||
shellescape({string} [, {special}]) *shellescape()*
|
||||
Escape {string} for use as a shell command argument.
|
||||
On MS-Windows and MS-DOS, when 'shellslash' is not set, it
|
||||
will enclose {string} in double quotes and double all double
|
||||
quotes within {string}.
|
||||
On MS-Windows, when 'shellslash' is not set, it will enclose
|
||||
{string} in double quotes and double all double quotes within
|
||||
{string}.
|
||||
Otherwise it will enclose {string} in single quotes and
|
||||
replace all "'" with "'\''".
|
||||
|
||||
@@ -10047,6 +10071,10 @@ This function can then be called with: >
|
||||
The recursiveness of user functions is restricted with the |'maxfuncdepth'|
|
||||
option.
|
||||
|
||||
It is also possible to use `:eval`. It does not support a range, but does
|
||||
allow for method chaining, e.g.: >
|
||||
eval GetList()->Filter()->append('$')
|
||||
|
||||
|
||||
AUTOMATICALLY LOADING FUNCTIONS ~
|
||||
*autoload-functions*
|
||||
@@ -10498,6 +10526,20 @@ text...
|
||||
Unlock the internal variable {name}. Does the
|
||||
opposite of |:lockvar|.
|
||||
|
||||
*:eval*
|
||||
:eval {expr} Evaluate {expr} and discard the result. Example: >
|
||||
:eval Getlist()->Filter()->append('$')
|
||||
|
||||
< The expression is supposed to have a side effect,
|
||||
since the resulting value is not used. In the example
|
||||
the `append()` call appends the List with text to the
|
||||
buffer. This is similar to `:call` but works with any
|
||||
expression.
|
||||
|
||||
The command can be shortened to `:ev` or `:eva`, but
|
||||
these are hard to recognize and therefore not to be
|
||||
used.
|
||||
|
||||
|
||||
:if {expr1} *:if* *:end* *:endif* *:en* *E171* *E579* *E580*
|
||||
:en[dif] Execute the commands until the next matching ":else"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
*testing.txt* For Vim version 8.1. Last change: 2019 Jul 28
|
||||
*testing.txt* For Vim version 8.1. Last change: 2019 Aug 04
|
||||
|
||||
|
||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||
@@ -222,7 +222,11 @@ assert_equal({expected}, {actual} [, {msg}])
|
||||
< Will result in a string to be added to |v:errors|:
|
||||
test.vim line 12: Expected 'foo' but got 'bar' ~
|
||||
|
||||
*assert_equalfile()*
|
||||
Can also be used as a |method|: >
|
||||
mylist->assert_equal([1, 2, 3])
|
||||
|
||||
|
||||
< *assert_equalfile()*
|
||||
assert_equalfile({fname-one}, {fname-two})
|
||||
When the files {fname-one} and {fname-two} do not contain
|
||||
exactly the same text an error message is added to |v:errors|.
|
||||
@@ -294,7 +298,10 @@ assert_notequal({expected}, {actual} [, {msg}])
|
||||
|v:errors| when {expected} and {actual} are equal.
|
||||
Also see |assert-return|.
|
||||
|
||||
*assert_notmatch()*
|
||||
Can also be used as a |method|: >
|
||||
mylist->assert_notequal([1, 2, 3])
|
||||
|
||||
< *assert_notmatch()*
|
||||
assert_notmatch({pattern}, {actual} [, {msg}])
|
||||
The opposite of `assert_match()`: add an error message to
|
||||
|v:errors| when {pattern} matches {actual}.
|
||||
|
||||
Reference in New Issue
Block a user