Calling xptemplate functions from a vim function?

20 views
Skip to first unread message

Ouroubouros

unread,
Jan 30, 2011, 1:04:42 PM1/30/11
to xptemplate
I'd like to make the call to the Build() function you showed me in our
previous discussion a little more easy to read, so I've made this
wrapper function:

let s:f = g:XPTfuncs()

fun! s:f.include_choice( choices )
s:choice = s:f.Build( '`:' . ( ( a:choices )[ s:f.V() ] ) . ':^' )
return s:choice
endfunction

And here's an example of it being used:

XPT foo
111

XPT bar
222

XPT mymenu
`_mymenu_popup^
XSET _mymenu_popup=Choose([ 'a', 'b' ])
XSET _mymenu_popup|post=include_choice( { "a" : "foo", "b" :
"bar" } ) )

Unfortunately, (due probably to my inexperience with vimscript), it
doesn't work.

When I select "a" from the popup in the "mymenu" snippet, I get this
error:

Error detected while processing function
XPTforceForward..<SNR>134_FinishCurrent..<SNR>134_ApplyPostFilter..<SNR>134_EvalPostFilter..<SNR>134_Ev
alFilter..<SNR>134_Eval..<SNR>123_Warn..Log_core:
line 19:
['xfunc.include_choice( { "a" : "foo", "b" :
"bar" } ).'' )''^@Vim(substitute):E488: Trailing characters']

Sorry to keep bothering you about these trivial matters, but could you
maybe give me a pointer as to what I'm doing wrong here?

Thanks again!

Ouroubouros

unread,
Jan 30, 2011, 1:11:54 PM1/30/11
to xptemplate
Oops. Looks like I forgot to use "let" when assigning a value to
s:choices.

The "fixed" function now looks like this:

fun! s:f.include_choice( choices )
let s:choice = s:f.Build( '`:' . ( ( a:choices )[ s:f.V() ] ) .
':^' )
return s:choice
endfunction

I no longer get an error, but instead of returning "111" when I choose
"a", I see a literal: include_choice( { "a" : "foo", "b" : "bar" } ) )

dr-dr xp

unread,
Jan 31, 2011, 7:36:43 AM1/31/11
to xptem...@googlegroups.com
Seem that you have too many quotes:?
 include_choice( { "a" : "foo", "b" : "bar" } )


--
You received this message because you are subscribed to the Google Groups "xptemplate" group.
To post to this group, send email to xptem...@googlegroups.com.
To unsubscribe from this group, send email to xptemplate+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/xptemplate?hl=en.




--
要了几天饱饭就不记得西北风啥味了

Ouroubouros

unread,
Jan 31, 2011, 9:51:10 AM1/31/11
to xptemplate
Gah! I can't believe I missed that. An extra parenthesis.

Thanks. It works great now.
Reply all
Reply to author
Forward
0 new messages