Em 23-08-2013 03:04, Tony Mechelynck escreveu: > On 23/08/13 06:01, Nikolay Pavlov wrote: >> >> On Aug 23, 2013 1:24 AM, "Jakson Alves de Aquino" <[email protected] >> <mailto:[email protected]>> wrote: >> > >> > >> > Hi, >> > >> > The documentation of Funcref includes the following statement: >> > >> > A Funcref variable must start with a capital, "s:", "w:", >> > "t:" or "b:". >> > >> > It seems that sentence is incomplete. I think the intention was to >> > write: >> > >> > A Funcref variable must start with a capital letter and both >> > the function being referred to and the Funcref variable must >> > have the same scope, being prefixed by "s:", "w:", "t:" or >> > "b:". >> >> I do not understand. Vim currently has nothing else but global >> functions. There are no scoped ones, s:Fname is simply a shortcut for >> <SNR>N_Fname, where N is current script number. Anonymous functions are >> global ones with just N as their name, N is number of anonymous >> functions defined in this session (i.e. it is just an incremented >> counter). > > The function is global. The _Funcref variable_ is a variable and as such > it can be a global variable, or it can be script-local, buffer-local, > window-local or tabpage-local. Not mentioned is the case where the > variable would be function-local. Such locality just means that the > _variable_ is only visible from within the same scope; it says nothing > about the underlying function which can be called indirectly through the > variable. > > The difference here is between > > function Funcname(arg1, arg2, arg3) > ... > endfunction > > and > > let t:VarFuncRef = function("Funcname") > > Funcname() is the function, and as such it is global. > t:VarFuncRef is a Funcref variable referencing that function, and in > this case the variable is tabpage-local. > > A global function can, however, be defined with s: (or the equivalent > bur more cumbersome SID_) and then it will normally not be visible from > outside the script where it was defined, except maybe via a > non-script-local mapping defined within the same script. In order to use > that s:Function as argument to function() to create a Funcref you must > be within that very same script. > >> >> Thus I have not seen the "must have the same scope" behavior you >> describe. >> >> Also note that using b:Fname (or g:Fname) as function name is >> undocumented. And it is as well NOT a name of buffer-local function. > > See above. > >> >> > But there is other problem in the documentation: although not >> > mentioned, "g:" also works even if it isn't explicitly prefixed in >> > the script, as in the example below where script_b.vim sources >> > script_a.vim. If we do :so % while editing script_b.vim, >> > FunctionA is executed: > [...] > > It is stated elsewhere that g: is implicit for variables used anywhere > except inside a function, where l: is implicit.
Thanks for the explanations, Nikolay Pavlov and Tony Mechelynck! Now it's clear to me. Best regards! -- Jakson Alves de Aquino Federal University of CearĂ¡ Social Sciences Department www.lepem.ufc.br/aquino.php -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
