Mercurial > vim
diff runtime/doc/eval.txt @ 17620:072efa9ca875 v8.1.1807
patch 8.1.1807: more functions can be used as a method
commit https://github.com/vim/vim/commit/25e42231d3ee27feec2568fa4be2aa2bfba82ae5
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 4 15:04:10 2019 +0200
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 04 Aug 2019 15:15:06 +0200 |
parents | e259d11e2900 |
children | 4c7097a980a5 |
line wrap: on
line diff
--- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -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 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, 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}) 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 ret 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"