comparison runtime/doc/eval.txt @ 9723:80ac9cf77c9b v7.4.2137

commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c Author: Bram Moolenaar <Bram@vim.org> Date: Mon Aug 1 15:40:54 2016 +0200 patch 7.4.2137 Problem: Using function() with a name will find another function when it is redefined. Solution: Add funcref(). Refer to lambda using a partial. Fix several reference counting issues.
author Christian Brabandt <cb@256bit.org>
date Mon, 01 Aug 2016 15:45:07 +0200
parents 2ea935bdd1a1
children 35ce559b8553
comparison
equal deleted inserted replaced
9722:1557241fd3a7 9723:80ac9cf77c9b
1 *eval.txt* For Vim version 7.4. Last change: 2016 Jul 29 1 *eval.txt* For Vim version 7.4. Last change: 2016 Jul 31
2 2
3 3
4 VIM REFERENCE MANUAL by Bram Moolenaar 4 VIM REFERENCE MANUAL by Bram Moolenaar
5 5
6 6
1238 : return {x -> x + i - a:arg} 1238 : return {x -> x + i - a:arg}
1239 :endfunction 1239 :endfunction
1240 :let Bar = Foo(4) 1240 :let Bar = Foo(4)
1241 :echo Bar(6) 1241 :echo Bar(6)
1242 < 5 1242 < 5
1243 See also |:func-closure|. 1243
1244 See also |:func-closure|. Lambda and closure support can be checked with: >
1245 if has('lambda')
1244 1246
1245 Examples for using a lambda expression with |sort()|, |map()| and |filter()|: > 1247 Examples for using a lambda expression with |sort()|, |map()| and |filter()|: >
1246 :echo map([1, 2, 3], {idx, val -> val + 1}) 1248 :echo map([1, 2, 3], {idx, val -> val + 1})
1247 < [2, 3, 4] > 1249 < [2, 3, 4] >
1248 :echo sort([3,7,2,1,4], {a, b -> a - b}) 1250 :echo sort([3,7,2,1,4], {a, b -> a - b})
2069 foldclosedend({lnum}) Number last line of fold at {lnum} if closed 2071 foldclosedend({lnum}) Number last line of fold at {lnum} if closed
2070 foldlevel({lnum}) Number fold level at {lnum} 2072 foldlevel({lnum}) Number fold level at {lnum}
2071 foldtext() String line displayed for closed fold 2073 foldtext() String line displayed for closed fold
2072 foldtextresult({lnum}) String text for closed fold at {lnum} 2074 foldtextresult({lnum}) String text for closed fold at {lnum}
2073 foreground() Number bring the Vim window to the foreground 2075 foreground() Number bring the Vim window to the foreground
2076 funcref({name} [, {arglist}] [, {dict}])
2077 Funcref reference to function {name}
2074 function({name} [, {arglist}] [, {dict}]) 2078 function({name} [, {arglist}] [, {dict}])
2075 Funcref reference to function {name} 2079 Funcref named reference to function {name}
2076 garbagecollect([{atexit}]) none free memory, breaking cyclic references 2080 garbagecollect([{atexit}]) none free memory, breaking cyclic references
2077 get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def} 2081 get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
2078 get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def} 2082 get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
2079 get({func}, {what}) any get property of funcref/partial {func} 2083 get({func}, {what}) any get property of funcref/partial {func}
2080 getbufline({expr}, {lnum} [, {end}]) 2084 getbufline({expr}, {lnum} [, {end}])
3848 allow a window to bring itself to the foreground. Use 3852 allow a window to bring itself to the foreground. Use
3849 |remote_foreground()| instead. 3853 |remote_foreground()| instead.
3850 {only in the Win32, Athena, Motif and GTK GUI versions and the 3854 {only in the Win32, Athena, Motif and GTK GUI versions and the
3851 Win32 console version} 3855 Win32 console version}
3852 3856
3857 *funcref()*
3858 funcref({name} [, {arglist}] [, {dict}])
3859 Just like |function()|, but the returned Funcref will lookup
3860 the function by reference, not by name. This matters when the
3861 function {name} is redefined later.
3862
3863 Unlike |function()|, {name} must be an existing user function.
3864 Also for autoloaded functions. {name} cannot be a builtin
3865 function.
3853 3866
3854 *function()* *E700* *E922* *E923* 3867 *function()* *E700* *E922* *E923*
3855 function({name} [, {arglist}] [, {dict}]) 3868 function({name} [, {arglist}] [, {dict}])
3856 Return a |Funcref| variable that refers to function {name}. 3869 Return a |Funcref| variable that refers to function {name}.
3857 {name} can be the name of a user defined function or an 3870 {name} can be the name of a user defined function or an
3858 internal function. 3871 internal function.
3859 3872
3860 {name} can also be a Funcref, also a partial. When it is a 3873 {name} can also be a Funcref or a partial. When it is a
3861 partial the dict stored in it will be used and the {dict} 3874 partial the dict stored in it will be used and the {dict}
3862 argument is not allowed. E.g.: > 3875 argument is not allowed. E.g.: >
3863 let FuncWithArg = function(dict.Func, [arg]) 3876 let FuncWithArg = function(dict.Func, [arg])
3864 let Broken = function(dict.Func, [arg], dict) 3877 let Broken = function(dict.Func, [arg], dict)
3865 < 3878 <
3879 When using the Funcref the function will be found by {name},
3880 also when it was redefined later. Use |funcref()| to keep the
3881 same function.
3882
3866 When {arglist} or {dict} is present this creates a partial. 3883 When {arglist} or {dict} is present this creates a partial.
3867 That means the argument list and/or the dictionary is stored in 3884 That means the argument list and/or the dictionary is stored in
3868 the Funcref and will be used when the Funcref is called. 3885 the Funcref and will be used when the Funcref is called.
3869 3886
3870 The arguments are passed to the function in front of other 3887 The arguments are passed to the function in front of other
6189 < 6206 <
6190 screenrow() *screenrow()* 6207 screenrow() *screenrow()*
6191 The result is a Number, which is the current screen row of the 6208 The result is a Number, which is the current screen row of the
6192 cursor. The top line has number one. 6209 cursor. The top line has number one.
6193 This function is mainly used for testing. 6210 This function is mainly used for testing.
6211 Alternatively you can use |winline()|.
6194 6212
6195 Note: Same restrictions as with |screencol()|. 6213 Note: Same restrictions as with |screencol()|.
6196 6214
6197 search({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *search()* 6215 search({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *search()*
6198 Search for regexp pattern {pattern}. The search starts at the 6216 Search for regexp pattern {pattern}. The search starts at the
8037 iconv Can use iconv() for conversion. 8055 iconv Can use iconv() for conversion.
8038 insert_expand Compiled with support for CTRL-X expansion commands in 8056 insert_expand Compiled with support for CTRL-X expansion commands in
8039 Insert mode. 8057 Insert mode.
8040 jumplist Compiled with |jumplist| support. 8058 jumplist Compiled with |jumplist| support.
8041 keymap Compiled with 'keymap' support. 8059 keymap Compiled with 'keymap' support.
8060 lambda Compiled with |lambda| support.
8042 langmap Compiled with 'langmap' support. 8061 langmap Compiled with 'langmap' support.
8043 libcall Compiled with |libcall()| support. 8062 libcall Compiled with |libcall()| support.
8044 linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and 8063 linebreak Compiled with 'linebreak', 'breakat', 'showbreak' and
8045 'breakindent' support. 8064 'breakindent' support.
8046 lispindent Compiled with support for lisp indenting. 8065 lispindent Compiled with support for lisp indenting.
8292 8311
8293 *:endf* *:endfunction* *E126* *E193* 8312 *:endf* *:endfunction* *E126* *E193*
8294 :endf[unction] The end of a function definition. Must be on a line 8313 :endf[unction] The end of a function definition. Must be on a line
8295 by its own, without other commands. 8314 by its own, without other commands.
8296 8315
8297 *:delf* *:delfunction* *E130* *E131* 8316 *:delf* *:delfunction* *E130* *E131* *E933*
8298 :delf[unction] {name} Delete function {name}. 8317 :delf[unction] {name} Delete function {name}.
8299 {name} can also be a |Dictionary| entry that is a 8318 {name} can also be a |Dictionary| entry that is a
8300 |Funcref|: > 8319 |Funcref|: >
8301 :delfunc dict.init 8320 :delfunc dict.init
8302 < This will remove the "init" entry from "dict". The 8321 < This will remove the "init" entry from "dict". The