Thursday, April 23, 2015

Re: Build amenu from Funcref

On Thursday, April 23, 2015 at 4:42:40 AM UTC-5, Ni Va wrote:
> Even if I replace call by exe, the func is not called by pressing button on my toolbar's menu.
>

STOP and think a minute. You *cannot* replace "call" with "exe" because you MUST "call" a function, unless you want to evaluate the function and execute the string result it returns as if it were an ex command.

> exe 'anoremenu '.m.getMenuPath().'.'.foo.' :call funcref#Call("'.string(Fn).'")<CR>'
>

This should work fine. You say Vim just displays the command...but there is no "echo" anywhere. Are you sure you tried this exact command?

I experimented as follows and everything works as expected:

function! MyFunc(num)
echo "number is " a:num
endfun
silent! unmenu Plugin.foo
exe 'anoremenu '."Plugin".'.'."foo".' :call MyFunc("'."12345".'")<CR>'

I get a "foo" item in my "Plugin" menu, and when I click on it, I see "number is 12345" echoed on the screen.

> replaced by
>
> exe 'anoremenu '.m.getMenuPath().'.'.foo.' :exe funcref#Call("'.string(Fn).'")<CR>'

As discussed above, this will not work. "exe" means "take this string and use it like an ex command". "call" is what you want.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment