1

Rescently I am in favor of a Vim plugin called Vundle. a dict named as g:bundle has a item:

{'path': function('1')}

If I call the item.path(), Vundle can invoke "s:bundle.path()" in vundle/config.vim :

func! s:bundle.path()
    return s:expand_path(g:bundle_dir.'/'.self.name)
endf

So, could you tell me the usage about parameter "1" of anonymous function in Vimscript?


Updated:

Thanks for Mr. Karkat.

I use :function {1} command, whose result is:

function 1() dict                                                                                                                                                          
    return s:expand_path(g:bundle_dir.'/'.self.name)
endfunction

the function block is same as s:bundle.path(), it proves that number in braces means Funcref:

The function will then get a nusmber and the value of dict.len is a Funcref that references this function. The function can only be used through a Funcref. It will automatically be deleted when there is no Funcref remaining that refers to it.

Referance:

https://github.com/gmarik/Vundle.vim/blob/master/autoload/vundle/config.vim#L106 http://vimdoc.sourceforge.net/htmldoc/eval.html#Dictionary-function

leiming
  • 494
  • 4
  • 13

1 Answers1

1

What you see is an anonymous Dictionary function. What this means is that for the Dictionary {'path': function('1')} (let's call it foo, and we know that it's an element of g:bundles), there has been defined this:

let foo = {}
function foo.path() dict
    return "foo"
endfunction

You can find out more about the function definition via

:function {1}
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Thinks, but I can't find the `definition function 1() dict` in source, which block is same as `s:bundle.path()`'s. These are related via `{'path': function('1')}` ? – leiming Mar 07 '14 at 08:48
  • I don't see the connection of `s:bundle.path()` to `g:bundles` (with `s`, and a List, not what you've written in your question). – Ingo Karkat Mar 07 '14 at 08:51
  • I add the detail to the body of question just then. – leiming Mar 07 '14 at 09:01