Skip to content

Commit 1735bc9

Browse files
committed
patch 7.4.1559
Problem: Passing cookie to a callback is clumsy. Solution: Change function() to take arguments and return a partial.
1 parent 9cdf86b commit 1735bc9

12 files changed

Lines changed: 486 additions & 69 deletions

File tree

runtime/doc/eval.txt

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*eval.txt* For Vim version 7.4. Last change: 2016 Mar 13
1+
*eval.txt* For Vim version 7.4. Last change: 2016 Mar 14
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1895,7 +1895,8 @@ foldlevel( {lnum}) Number fold level at {lnum}
18951895
foldtext() String line displayed for closed fold
18961896
foldtextresult( {lnum}) String text for closed fold at {lnum}
18971897
foreground() Number bring the Vim window to the foreground
1898-
function( {name}) Funcref reference to function {name}
1898+
function({name} [, {arglist}] [, {dict}])
1899+
Funcref reference to function {name}
18991900
garbagecollect( [{atexit}]) none free memory, breaking cyclic references
19001901
get( {list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
19011902
get( {dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
@@ -3568,10 +3569,46 @@ foreground() Move the Vim window to the foreground. Useful when sent from
35683569
Win32 console version}
35693570

35703571

3571-
function({name}) *function()* *E700*
3572+
*function()* *E700* *E922* *E923*
3573+
function({name} [, {arglist}] [, {dict}])
35723574
Return a |Funcref| variable that refers to function {name}.
35733575
{name} can be a user defined function or an internal function.
35743576

3577+
When {arglist} or {dict} is present this creates a partial.
3578+
That mans the argument list and/or the dictionary is stored in
3579+
the Funcref and will be used when the Funcref is called.
3580+
3581+
The arguments are passed to the function in front of other
3582+
arguments. Example: >
3583+
func Callback(arg1, arg2, name)
3584+
...
3585+
let Func = function('Callback', ['one', 'two'])
3586+
...
3587+
call Func('name')
3588+
< Invokes the function as with: >
3589+
call Callback('one', 'two', 'name')
3590+
3591+
< The Dictionary is only useful when calling a "dict" function.
3592+
In that case the {dict} is passed in as "self". Example: >
3593+
function Callback() dict
3594+
echo "called for " . self.name
3595+
endfunction
3596+
...
3597+
let context = {"name": "example"}
3598+
let Func = function('Callback', context)
3599+
...
3600+
call Func() " will echo: called for example
3601+
3602+
< The argument list and the Dictionary can be combined: >
3603+
function Callback(arg1, count) dict
3604+
...
3605+
let context = {"name": "example"}
3606+
let Func = function('Callback', ['one'], context)
3607+
...
3608+
call Func(500)
3609+
< Invokes the function as with: >
3610+
call context.Callback('one', 500)
3611+
35753612
35763613
garbagecollect([{atexit}]) *garbagecollect()*
35773614
Cleanup unused |Lists| and |Dictionaries| that have circular

0 commit comments

Comments
 (0)