|
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 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -1895,7 +1895,8 @@ foldlevel( {lnum}) Number fold level at {lnum} |
1895 | 1895 | foldtext() String line displayed for closed fold |
1896 | 1896 | foldtextresult( {lnum}) String text for closed fold at {lnum} |
1897 | 1897 | 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} |
1899 | 1900 | garbagecollect( [{atexit}]) none free memory, breaking cyclic references |
1900 | 1901 | get( {list}, {idx} [, {def}]) any get item {idx} from {list} or {def} |
1901 | 1902 | 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 |
3568 | 3569 | Win32 console version} |
3569 | 3570 |
|
3570 | 3571 |
|
3571 | | -function({name}) *function()* *E700* |
| 3572 | + *function()* *E700* *E922* *E923* |
| 3573 | +function({name} [, {arglist}] [, {dict}]) |
3572 | 3574 | Return a |Funcref| variable that refers to function {name}. |
3573 | 3575 | {name} can be a user defined function or an internal function. |
3574 | 3576 |
|
| 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 | +
|
3575 | 3612 |
|
3576 | 3613 | garbagecollect([{atexit}]) *garbagecollect()* |
3577 | 3614 | Cleanup unused |Lists| and |Dictionaries| that have circular |
|
0 commit comments