From 521e45f2a8c0619335288accdda0f0aaa1fc6513 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Mon, 24 Oct 2016 23:53:07 -0700 Subject: vim-patch:7.4.1559 Problem: Passing cookie to a callback is clumsy. Solution: Change function() to take arguments and return a partial. https://github.com/vim/vim/commit/1735bc988c546cc962c5f94792815b4d7cb79710 --- runtime/doc/eval.txt | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 53f14c7d47..f377ebdf31 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1913,7 +1913,8 @@ foldlevel({lnum}) Number fold level at {lnum} foldtext() String line displayed for closed fold foldtextresult({lnum}) String text for closed fold at {lnum} foreground() Number bring the Vim window to the foreground -function({name}) Funcref reference to function {name} +function({name} [, {arglist}] [, {dict}]) + Funcref reference to function {name} garbagecollect([{atexit}]) none free memory, breaking cyclic references get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def} get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def} @@ -3483,10 +3484,46 @@ foreground() Move the Vim window to the foreground. Useful when sent from {only in the Win32 GUI and console version} -function({name}) *function()* *E700* + *function()* *E700* *E922* *E929* +function({name} [, {arglist}] [, {dict}]) Return a |Funcref| variable that refers to function {name}. {name} can be a user defined function or an internal function. + When {arglist} or {dict} is present this creates a partial. + That mans the argument list and/or the dictionary is stored in + the Funcref and will be used when the Funcref is called. + + The arguments are passed to the function in front of other + arguments. Example: > + func Callback(arg1, arg2, name) + ... + let Func = function('Callback', ['one', 'two']) + ... + call Func('name') +< Invokes the function as with: > + call Callback('one', 'two', 'name') + +< The Dictionary is only useful when calling a "dict" function. + In that case the {dict} is passed in as "self". Example: > + function Callback() dict + echo "called for " . self.name + endfunction + ... + let context = {"name": "example"} + let Func = function('Callback', context) + ... + call Func() " will echo: called for example + +< The argument list and the Dictionary can be combined: > + function Callback(arg1, count) dict + ... + let context = {"name": "example"} + let Func = function('Callback', ['one'], context) + ... + call Func(500) +< Invokes the function as with: > + call context.Callback('one', 500) + garbagecollect([{atexit}]) *garbagecollect()* Cleanup unused |Lists| and |Dictionaries| that have circular -- cgit From c82dc7a6fd4987fee72320133579b008815b28d1 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Fri, 28 Oct 2016 12:38:36 -0700 Subject: vim-patch:7.4.1836 Problem: When using a partial on a dictionary it always gets bound to that dictionary. Solution: Make a difference between binding a function to a dictionary explicitly or automatically. https://github.com/vim/vim/commit/1d429610bf9e99a6252be8abbc910d6667e4d1da --- runtime/doc/eval.txt | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index f377ebdf31..133f35990c 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,6 +1,5 @@ *eval.txt* For Vim version 7.4. Last change: 2016 Jun 04 - VIM REFERENCE MANUAL by Bram Moolenaar @@ -49,6 +48,9 @@ String A NUL terminated string of 8-bit unsigned characters (bytes). Funcref A reference to a function |Funcref|. Example: function("strlen") + It can be bound to a dictionary and arguments, it then works + like a Partial. + Example: function("Callback", [arg], myDict) List An ordered sequence of items |List|. Example: [1, 2, ['a', 'b']] @@ -139,6 +141,43 @@ The name of the referenced function can be obtained with |string()|. > You can use |call()| to invoke a Funcref and use a list variable for the arguments: > :let r = call(Fn, mylist) +< + *Partial* +A Funcref optionally binds a Dictionary and/or arguments. This is also called +a Partial. This is created by passing the Dictionary and/or arguments to +function(). When calling the function the Dictionary and/or arguments will be +passed to the function. Example: > + + let Cb = function('Callback', ['foo'], myDict) + call Cb() + +This will invoke the function as if using: > + call myDict.Callback('foo') + +This is very useful when passing a function around, e.g. in the arguments of +|ch_open()|. + +Note that binding a function to a Dictionary also happens when the function is +a member of the Dictionary: > + + let myDict.myFunction = MyFunction + call myDict.myFunction() + +Here MyFunction() will get myDict passed as "self". This happens when the +"myFunction" member is accessed. When making assigning "myFunction" to +otherDict and calling it, it will be bound to otherDict: > + + let otherDict.myFunction = myDict.myFunction + call otherDict.myFunction() + +Now "self" will be "otherDict". But when the dictionary was bound explicitly +this won't happen: > + + let myDict.myFunction = function(MyFunction, myDict) + let otherDict.myFunction = myDict.myFunction + call otherDict.myFunction() + +Here "self" will be "myDict", because it was bound explitly. 1.3 Lists ~ -- cgit From 02c58d8a07a6d7ed450c8c7146c93f4dca665ba2 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Fri, 28 Oct 2016 12:49:28 -0700 Subject: vim-patch:7.4.1839 Problem: Cannot get the items stored in a partial. Solution: Support using get() on a partial. https://github.com/vim/vim/commit/2bbf8eff6fab16d86e7bcfc0da1962d31bec7891 --- runtime/doc/eval.txt | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 133f35990c..05dcc62903 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -3586,6 +3586,12 @@ get({dict}, {key} [, {default}]) Get item with key {key} from |Dictionary| {dict}. When this item is not available return {default}. Return zero when {default} is omitted. +get({partial}, {what}) + Get an item with from Funcref {partial}. Possible values for + {what} are: + 'func' The function + 'dict' The dictionary + 'args' The list with arguments *getbufline()* getbufline({expr}, {lnum} [, {end}]) -- cgit From c52856af2c5f3b12b89671d91c35689fb2f84a70 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Fri, 28 Oct 2016 22:58:11 -0700 Subject: vim-patch:7.4.1842 Problem: get() works for Partial but not for Funcref. Solution: Accept Funcref. Also return the function itself. (Nikolai Pavlov) https://github.com/vim/vim/commit/03e19a04ac2ca55643663b97b6ab94043233dcbd --- runtime/doc/eval.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 05dcc62903..fd1c1f2cf2 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1957,6 +1957,7 @@ function({name} [, {arglist}] [, {dict}]) garbagecollect([{atexit}]) none free memory, breaking cyclic references get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def} get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def} +get({func}, {what}) any get property of funcref/partial {func} getbufline({expr}, {lnum} [, {end}]) List lines {lnum} to {end} of buffer {expr} getbufvar({expr}, {varname} [, {def}]) @@ -3586,9 +3587,10 @@ get({dict}, {key} [, {default}]) Get item with key {key} from |Dictionary| {dict}. When this item is not available return {default}. Return zero when {default} is omitted. -get({partial}, {what}) - Get an item with from Funcref {partial}. Possible values for +get({func}, {what}) + Get an item with from Funcref {func}. Possible values for {what} are: + 'name' The function name 'func' The function 'dict' The dictionary 'args' The list with arguments -- cgit From 2c4e92abea2244e033be0c7534685485cfb5ddc9 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Thu, 3 Nov 2016 12:09:22 -0700 Subject: vim-patch:7.4.1731 Mark as NA Leave a note in vim_diff.txt about it. --- runtime/doc/vim_diff.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 7ccdfd2bdd..cdd616b6c1 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -235,7 +235,7 @@ Additional differences: These legacy Vim features may be implemented in the future, but they are not planned for the current milestone. -- vim.bindeval() (new feature in Vim 7.4 Python interface) +- |if_py|: vim.bindeval() and vim.Function() are not supported - |if_lua| - |if_perl| - |if_mzscheme| -- cgit From a21c687661eac61702fe492264a3c9036bc62f41 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Sat, 29 Oct 2016 14:55:53 -0700 Subject: Fixes. --- runtime/doc/eval.txt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index fd1c1f2cf2..585b016c7d 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -154,9 +154,6 @@ passed to the function. Example: > This will invoke the function as if using: > call myDict.Callback('foo') -This is very useful when passing a function around, e.g. in the arguments of -|ch_open()|. - Note that binding a function to a Dictionary also happens when the function is a member of the Dictionary: > @@ -164,8 +161,8 @@ a member of the Dictionary: > call myDict.myFunction() Here MyFunction() will get myDict passed as "self". This happens when the -"myFunction" member is accessed. When making assigning "myFunction" to -otherDict and calling it, it will be bound to otherDict: > +"myFunction" member is accessed. When assigning "myFunction" to otherDict +and calling it, it will be bound to otherDict: > let otherDict.myFunction = myDict.myFunction call otherDict.myFunction() @@ -3588,7 +3585,7 @@ get({dict}, {key} [, {default}]) item is not available return {default}. Return zero when {default} is omitted. get({func}, {what}) - Get an item with from Funcref {func}. Possible values for + Get item {what} from Funcref {func}. Possible values for {what} are: 'name' The function name 'func' The function -- cgit From 5e4eb18eb0242794c0b3a622f7acf0d3e6856c05 Mon Sep 17 00:00:00 2001 From: Michael Ennen Date: Fri, 11 Nov 2016 13:13:55 -0700 Subject: Add some tests and cleanup. --- runtime/doc/eval.txt | 1 + 1 file changed, 1 insertion(+) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 585b016c7d..367f64df9b 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1,5 +1,6 @@ *eval.txt* For Vim version 7.4. Last change: 2016 Jun 04 + VIM REFERENCE MANUAL by Bram Moolenaar -- cgit