aboutsummaryrefslogtreecommitdiff
path: root/vim/bundle/vim-addon-mw-utils/doc/funcref.txt
blob: cb366d0e714767e2777d4e8205ffe212587e830e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
*funcref*   create lazier function references. Pass arguments to create closure
            like function calls
                    Author: Marc Weber, marco-oweber@gmx.de

-----------------------------------------------------------------------
HOWTO~

Use *funcref#Function* to create a special dict called
*faked-function-reference* which can be called by *funcref#Call*
>
    { 'faked_function_reference': 'file#FuncName' }
<   passing some arguments and / or self: >
    { 'faked_function_reference': 'MyFunc', 'args': [1,2], 'self' : { a object ] }
<   You can also create lambda like functions which will be evaled: >
    { 'faked_function_reference': 'return ARGS[1]' }

REASONS ~
  Creating a Vim funcref pointing to an autoload function will make Vim source
  that file. This is not lazy enough. (Seems to be no longer true? Has this changed?)

  A Vim function reference neither allows attaching arguments nor self.

  Don't care about case of variables. Normally when using Vim function
  references you have to use variable names starting with an upper case letter
  (E704)

Example: ~
>
  let f = funcref#Function('return ARGS[0].ARGS[1].SELF["key"]',{'args':[3], 'self':{'key': 'value'} })
  echo funcref#Call(f, [2])
  " prints  "32value"

  echo funcref#Call('no value')
< 
  echo funcref#Call(f, [2])