List of options

Asked by David Fishburn

Looking through the Ultisnips 2.2 documentation I don't see how to do this, but I thought I had seen this capability when I watched one of the videos.

Basically I want to provide a list of options the user can choose from in a drop down.
In some cases, choosing none is an option and in other cases they must choose at least one.
As a final and advanced case, allow them to choose multiple ones.

Thanks,
David

Question information

Language:
English Edit question
Status:
Answered
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

This question was reopened

Revision history for this message
SirVer (sirver) said :
#1

I am not sure what you want to achieve. You can define the same trigger more than once and then select on expansion which one you want.

Revision history for this message
David Fishburn (dfishburn-vim) said :
#2

Here is a simple (though impractical) example.

I want the snippet to trigger when I type CREATE.
Then I want to provide the user (using OMNI completion or something similar) a list of items to create.

CREATE<tab>

The popup list should provide:
TABLE
PROCEDURE
FUNCTION

In many of the SQL completions I plan, there are always a static list of options that I would like to make available to the user as they move through the different tabstops. This would make the completions more valuable.

Here would be a more real life example:

snippet DECLARE ${1:name} {2:parameters, one of the following:
[ NO SCROLL
  | DYNAMIC SCROLL
  | SCROLL
  | INSENSITIVE
  | SENSITIVE
]
}
CURSOR FOR {3:statement}
{4:

So the 2nd parameter would give the user a list of those options to choose from.

Revision history for this message
SirVer (sirver) said :
#3

I am sorry that ultisnips does not offer what you need. I can offer something similar though: Have a look at my screencast about python interpolation in UltiSnips [1], I code a complete function that I use for this very use case you have here. Maybe that is valuable to you?

[1] http://www.youtube.com/watch?v=JJQYwt6Diro

Revision history for this message
David Fishburn (dfishburn-vim) said :
#4

Yes, that was the video I was remembering, but could not remember where.

So, the base case worked ($1, one set of completions).

Next I tried to get somewhat fancier and things start breaking.

global !p
def complete(t, opts):
    if t:
        opts = [ m[len(t):] for m in opts if m.startswith(t) ]
    if len(opts) == 1:
        return opts[0]
    return '(' + '|'.join(opts) + ')'
endglobal

snippet cursor "cursor" !i
    DECLARE $1 $2`!p snip.rv=complete(t[2], [ 'NO SCROLL', 'DYNAMIC SCROLL',
    'SCROLL', 'INSENSITIVE', 'SENSITIVE' ])` CURSOR FOR
    $3
    $4`!p snip.rv=complete(t[4], ['FOR READ ONLY', 'FOR UPDATE', 'FOR UPDATE BY ', 'FOR UPDATE OF $5' ])`
endsnippet

What I want to do is embed another tabstop ($5 in this case) so that if they choose the "FOR UPDATE OF" option, they get another tabstop to <C-J> to.

Is this possible?

Thanks,
David

Revision history for this message
SirVer (sirver) said :
#5

No, programmatically generating new placeholders on the fly is not possible right now. I am sorry.

Revision history for this message
voyeg3r (voyeg3r) said :
#6

here the video link cited --> https://www.youtube.com/watch?v=JJQYwt6Diro

Can you help with this problem?

Provide an answer of your own, or ask David Fishburn for more information if necessary.

To post a message you must log in.