diff options
author | Michael Ennen <mike.ennen@gmail.com> | 2016-12-17 16:01:42 -0700 |
---|---|---|
committer | Michael Ennen <mike.ennen@gmail.com> | 2017-02-14 17:38:17 -0700 |
commit | f59321e319ecfc6977f666fb04a52ac50bead09d (patch) | |
tree | 9c98a259e9810ec6f2edc7d020d6164e64bb79e1 /runtime | |
parent | 9f6f7fe26d7caa89083f5d5b00c55bf2046591ca (diff) | |
download | rneovim-f59321e319ecfc6977f666fb04a52ac50bead09d.tar.gz rneovim-f59321e319ecfc6977f666fb04a52ac50bead09d.tar.bz2 rneovim-f59321e319ecfc6977f666fb04a52ac50bead09d.zip |
vim-patch:7.4.2120
Problem: User defined functions can't be a closure.
Solution: Add the "closure" argument. Allow using :unlet on a bound
variable. (Yasuhiro Matsumoto, Ken Takata)
https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/eval.txt | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index fb4ca824a3..dc929238cb 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1207,6 +1207,7 @@ function returns: > :let Bar = Foo(4) :echo Bar(6) < 5 +See also |:func-closure|. Examples for using a lambda expression with |sort()|, |map()| and |filter()|: > :echo map([1, 2, 3], {idx, val -> val + 1}) @@ -8072,7 +8073,7 @@ last defined. Example: > See |:verbose-cmd| for more information. *E124* *E125* *E853* *E884* -:fu[nction][!] {name}([arguments]) [range] [abort] [dict] +:fu[nction][!] {name}([arguments]) [range] [abort] [dict] [closure] Define a new function by the name {name}. The name must be made of alphanumeric characters and '_', and must start with a capital or "s:" (see above). Note @@ -8115,6 +8116,28 @@ See |:verbose-cmd| for more information. be invoked through an entry in a |Dictionary|. The local variable "self" will then be set to the dictionary. See |Dictionary-function|. + *:func-closure* *E932* + When the [closure] argument is added, the function + can access variables and arguments from the outer + scope. This is usually called a closure. In this + example Bar() uses "x" from the scope of Foo(). It + remains referenced even after Foo() returns: > + :function! Foo() + : let x = 0 + : function! Bar() closure + : let x += 1 + : return x + : endfunction + : return function('Bar') + :endfunction + + :let F = Foo() + :echo F() +< 1 > + :echo F() +< 2 > + :echo F() +< 3 *function-search-undo* The last used search pattern and the redo command "." |