Place holder to popup to snippet or second popup?

5 views
Skip to first unread message

Ouroubouros

unread,
Jan 30, 2011, 1:11:11 AM1/30/11
to xptemplate
How can I make it so that when a user hits TAB on a place holder a
popup menu comes up, and the value that is chosen from that popup menu
(let's call that value "foo") gets used to immediately insert another
snippet named "foo"?

Furthermore, I'd also like to sometimes do the same thing as described
above, only have the value that is chosen from the popup menu be used
to immediately open up yet another popup menu (a different popup menu
depending on the value that was chosen), and have the value that's
chosen from the second popup menu be the one that's inserted in place
of the place holder (or perhaps used to call another snippet, as
described above). Is this possible?

dr-dr xp

unread,
Jan 30, 2011, 6:44:58 AM1/30/11
to xptem...@googlegroups.com
I don't know if I got your point clearly. If I didn't, please give me some example:

Tab-triggered popup menu is not possible. The only chance XPT pops up a menu is by setting default value of a place holder:

XPT helloxpt " tips about what this snippet does
XSET x|def=Choose( [ 'abc', 'abd' ] )
=`x^-

Multiple popup on a same place holder is not supported yet.

To transform place holder to some other piece of snippet, you can use post-filter.
XPT helloxpt " tips about what this snippet does
XSET x|def=Choose( [ 'abc', 'abd' ] )
XSET x|post=Build( '`a^-`b^' )
=`x^-

The argument of function "Build" is a plain string which is another piece of snippet. Thus you can also use Inclusion with function "Build" to include another snippet:
XPT helloxpt " tips about what this snippet does
XSET x|def=Choose( [ 'abc', 'abd' ] )
XSET x|post=Build( '`:Date:^' )
=`x^-

Your requirements are enlightening to XPT. Thank you.


Regards


--
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 30, 2011, 9:05:22 AM1/30/11
to xptemplate
On Jan 30, 6:44 am, dr-dr xp <drdr...@gmail.com> wrote:
>
> I don't know if I got your point clearly. If I didn't, please give me some
> example:
>
> Tab-triggered popup menu is not possible. The only chance XPT pops up a menu
> is by setting default value of a place holder:
>
> XPT helloxpt " tips about what this snippet does
> XSET x|def=Choose( [ 'abc', 'abd' ] )
> =`x^-

Right. This is how I've been getting a popup to appear so far.
It's not "tab-triggered" exactly, but the TAB is used to select the
place holder,
and the place holder is transformed in to the popup via the code
above.

> The argument of function "Build" is a plain string which is another piece of
> snippet. Thus you can also use Inclusion with function "Build" to include
> another snippet:
> XPT helloxpt " tips about what this snippet does
> XSET x|def=Choose( [ 'abc', 'abd' ] )
> XSET x|post=Build( '`:Date:^' )
> =`x^-

This is close to what I'm looking for, but not quite. The problem is
that the
user's choice of "abc" or "abd" does not get used to select which
snippet
appears next.

If the user selects "abc" I would like snippet "foo" to be included.
But if the user
selects "abd" I would like snippet "bar" to be included instead.

Of course, ideally either snippet "foo" or "bar" could themselves
immediately
open up popup menus for the user to select further strings or snippets
from. I
understand this is not supported yet, but I am looking forward to the
day when
it is. :)

Thanks for writing xptemplate!

dr-dr xp

unread,
Jan 30, 2011, 9:27:56 AM1/30/11
to xptem...@googlegroups.com
To your last requirement, I think this is what you want:
XPT foo " tips
this is `foo^

XPT helloxpt " tips about what this snippet does
XSET x|post=Build( '`:' . ( ( { "a" : "foo", "b" : "bar" } )[ V() ] ) . ':^' )
-`x^=


function "V()" retrieves the "value" of current place holder. 

But the bad news is that I'd been too lazy(or busy? whatever) to have all the functions in doc. You can find them in ftplugin/_common/common.xpt.vim 


Regards


--
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 30, 2011, 10:19:44 AM1/30/11
to xptemplate
On Jan 30, 9:27 am, dr-dr xp <drdr...@gmail.com> wrote:
>
> To your last requirement, I think this is what you want:
> XPT foo " tips
> this is `foo^
>
> XPT helloxpt " tips about what this snippet does
> XSET x|post=Build( '`:' . ( ( { "a" : "foo", "b" : "bar" } )[ V() ] ) . ':^'
> )
> -`x^=
>
> function "V()" retrieves the "value" of current place holder.

Thank you! That's great! This is just what I was looking for.

Now I can have multiple popups, like so:

XPT foo " tips
`_foo_popup^
XSET _foo_popup=Choose([ '123', '456' ])

XPT bar " tips
`_bar_popup^
XSET _bar_popup=Choose([ '789', '101112' ])

XPT helloxpt " tips about what this snippet does
XSET x|def=Choose([ 'a', 'b' ])
XSET x|post=Build( '`:' . ( ( { "a" : "foo", "b" : "bar" } )
[ V() ] ) . ':^' )
-`x^=

> But the bad news is that I'd been too lazy(or busy? whatever) to have all
> the functions in doc. You can find them in ftplugin/_common/common.xpt.vim

I looked in there. But, unfortunately, those functions have very
little documentation in the comments of common.xpt.vim, and there are
no examples of how to use most of them. And I don't know enough
vimscript or about the internal workings of xptemplate to figure it
out on my own.

The code you gave above showing how Build() and V() could be used to
transform values that the user gave in to a call to include other
snippets is exactly the sort of example that would make the functions
in common.xpt.vim more useful to the average snippet developer. So
thank you for that!
Reply all
Reply to author
Forward
0 new messages