Build amenu from Funcref

74 views
Skip to first unread message

Ni Va

unread,
Apr 22, 2015, 5:03:07 AM4/22/15
to vim...@googlegroups.com
Hi all,

I got some scriptPsexec#function('ddddd') to refer to but I don't happen to call it :
1- directly
2- mapped into amenu command


let m = psexec#machine()
call m.configure(machine,cce,level)
for foo in m.getCmdList()
let Fn = copy(m[foo])
"1- exe funcref#Call( Fn )
"2-exe 'anoremenu '.m.getMenuPath().'.'.foo.' :funcref#Call("'.string(Fn).'")<CR>'
endfor


The funcref#Call echoes me an error:
E492: unknown command: call funcref#Call("function('3210')")

Can you help me to call correctly the funcref please ?
Thank you


Ben Fritz

unread,
Apr 22, 2015, 10:03:41 AM4/22/15
to vim...@googlegroups.com
Are you sure that's the exact error message? I don't see a "call funcref#Call" anywhere in your script, and it looks like that would be the fix you need. I.e. rather than "exe funcref..." you need "call funcref...".

Ni Va

unread,
Apr 22, 2015, 10:54:27 AM4/22/15
to vim...@googlegroups.com
Ok with these line code

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

1- The first one call the func.
2- The second one display call funcref#Call('21446')
no error message effectively but I would like to execute the func ref 21446

Ni Va

unread,
Apr 23, 2015, 5:42:40 AM4/23/15
to vim...@googlegroups.com
Even if I replace call by exe, the func is not called by pressing button on my toolbar's menu.

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

replaced by

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

Ben Fritz

unread,
Apr 23, 2015, 10:43:43 AM4/23/15
to vim...@googlegroups.com
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.
Message has been deleted
Message has been deleted

Ni Va

unread,
Apr 27, 2015, 2:43:00 AM4/27/15
to vim...@googlegroups.com
Hi Ben

I knew that call was different from exe and I supposed that I bad explained the probleme.


Calling and building a local func like you do is easier than calling a func declared as "object method" in a dedicated vimscript.

You can see in attached file that I have wrote similar object as described here : http://bling.github.io/blog/2013/08/16/modularizing-vimscript/

Although, I got E488 error when I use the button menu the script buildt.
PsExec.vim

Ben Fritz

unread,
Apr 27, 2015, 10:51:39 AM4/27/15
to vim...@googlegroups.com
On Monday, April 27, 2015 at 1:43:00 AM UTC-5, Ni Va wrote:
>
>
> Hi Ben
>
> I knew that call was different from exe and I supposed that I bad explained the probleme.
>
>
> Calling and building a local func like you do is easier than calling a func declared as "object method" in a dedicated vimscript.
>
> You can see in attached file that I have wrote similar object as described here : http://bling.github.io/blog/2013/08/16/modularizing-vimscript/
>
> Although, I got E488 error when I use the button menu the script buildt.

Can you attach a small self-contained test case demonstrating the problem in just a few lines, please? I don't have time to go through your script to figure out what it is TRYING to accomplish.

I thought from your previous messages you were trying to call actual functions. If this is the case, I don't know if this will work without a simpler example, but it may help to re-interpret the string function name as a function before calling it:

exe 'anoremenu PfiTest.'.foo.' :call function('.string(m[foo]).')()<CR><CR>'


This still throws errors when I edit your script as above, however, I don't have the slightest idea what the script is trying to do in the first place, so perhaps that is a different problem.

Ni Va

unread,
Apr 28, 2015, 3:01:47 AM4/28/15
to vim...@googlegroups.com
Hi Ben,

I have added a selft-contained test case to show :
1- the standalone call to the func is working
2- the call to the func from menu entry added is not working. this is my goal. to call a func or funcref retrieved from object (psexec).

Thank you for your help
PsExec.vim

Ben Fritz

unread,
Apr 28, 2015, 11:22:55 AM4/28/15
to vim...@googlegroups.com
On Tuesday, April 28, 2015 at 2:01:47 AM UTC-5, Ni Va wrote:
> Hi Ben,
>
> I have added a selft-contained test case to show :
> 1- the standalone call to the func is working
> 2- the call to the func from menu entry added is not working. this is my goal. to call a func or funcref retrieved from object (psexec).
>
> Thank you for your help

I'm not looking through 300 lines of undocumented Vimscript to try to figure out what is going on or even where the problem lines are.

You should be able to create a 5-15 line file to demonstrate your problem without confusing the issue with a full-blown plugin script.

Ni Va

unread,
Apr 28, 2015, 12:11:22 PM4/28/15
to vim...@googlegroups.com
Ok I have clean up some unused lines and add comment . You just have to push PfiTest.echo to see errors.
PsExec.vim
Reply all
Reply to author
Forward
0 new messages