diff options
author | Sean Dewar <seandewar@users.noreply.github.com> | 2021-08-06 17:09:47 +0100 |
---|---|---|
committer | Sean Dewar <seandewar@users.noreply.github.com> | 2021-08-12 22:35:20 +0100 |
commit | 003c8acc8a9863932430bfb51bee8403b964c19b (patch) | |
tree | c7f47d87cbc6152a25dbaeffea225842ffc8306b /runtime | |
parent | e6be6c307a832d661d2a6269ad2d322e4bf5e9cc (diff) | |
download | rneovim-003c8acc8a9863932430bfb51bee8403b964c19b.tar.gz rneovim-003c8acc8a9863932430bfb51bee8403b964c19b.tar.bz2 rneovim-003c8acc8a9863932430bfb51bee8403b964c19b.zip |
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.
https://github.com/vim/vim/commit/25e42231d3ee27feec2568fa4be2aa2bfba82ae5
:eval is already ported.
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 43 | ||||
-rw-r--r-- | runtime/doc/testing.txt | 10 |
2 files changed, 41 insertions, 12 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index eee401baa1..070c94da3b 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -669,12 +669,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 @@ -939,10 +941,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. @@ -1047,10 +1049,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 ------ @@ -2637,6 +2646,9 @@ 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}. @@ -2655,8 +2667,10 @@ 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 @@ -3518,6 +3532,9 @@ eval({string}) Evaluate {string} and return the result. Especially useful to 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, @@ -3864,7 +3881,11 @@ 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} is used as-is, you may want to expand wildcards first: > + echo filereadable('~/.vimrc') + 0 + echo filereadable(expand('~/.vimrc')) + 1 filewritable({file}) *filewritable()* The result is a Number, which is 1 when a file with the @@ -10006,7 +10027,9 @@ 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. +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 ~ @@ -10749,7 +10772,7 @@ text... < *:eval* :eval {expr} Evaluate {expr} and discard the result. Example: > - :eval append(Filter(Getlist()), '$') + :eval Getlist()->Filter()->append('$') < The expression is supposed to have a side effect, since the resulting value is not used. In the example diff --git a/runtime/doc/testing.txt b/runtime/doc/testing.txt index ef8d6b5ea9..eca2025ed7 100644 --- a/runtime/doc/testing.txt +++ b/runtime/doc/testing.txt @@ -69,7 +69,10 @@ 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|. @@ -145,7 +148,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}. |