Yegappan wrote:

> > > If you run the below script:
> > >
> > > --------------------------------------------
> > > vim9script
> > > def g:Test1(): void
> > > enddef
> > > echomsg function('g:Test1')
> > > echomsg funcref('g:Test1')
> > > --------------------------------------------
> > >
> > > The following output is produced:
> > >
> > > function('g:Test1')
> > > function('Test1')
> > >
> > > Note that in the second line the scope "g:" is missing. I expected that 
> > > the
> > > same output will be produced by both function() and funcref().
> >
> > With a funcref a pointer to the function is used, thus the scope is not
> > directly relevant.  With function() it stores the name as it was given,
> > to be looked up later.  Thus it should be OK to get a different name.
> >
> > But it would be clearer for the funcref to output funcref('Test1').
> > I wonder what trouble it would cause if we change that now.
> > Unless there is a practical reason, I rather leave it as it is.
> 
> This causes a problem in Vim9 when setting an option like 'omnifunc'
> to a funcref(). I am working on adding the support for setting these
> options to a funcref/lambda in Vim9 (before patch 8.2.3765). When this
> option is set to a global funcref:
> 
>    var Fn: func = funcref('g:Myomnifunc')
>    &omnifunc = Fn
> 
> This fails with the error 'Myomnifunc' function is not found. This works
> if function() is used instead of funcref(). This is because, when funcref()
> is converted to a string (by tv2string()), the scope is not retained.
> In a legacy script this works as the scope is global by default.
> In Vim9, this fails as the default scope is script local and the function
> is a global function. So the function is not found.

Oh, this is not about using funcref() instead of function(), but
prepending "g:".  That should be OK.

-- 
hundred-and-one symptoms of being an internet addict:
18. Your wife drapes a blond wig over your monitor to remind you of what she
    looks like.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20211209164249.C9BFA1C0B28%40moolenaar.net.

Raspunde prin e-mail lui