Home Download Buy Blog Forum Support

Completions: direct access to the drop-down menu?

Completions: direct access to the drop-down menu?

Postby Marciano on Thu Mar 10, 2011 7:46 pm

Hi,

is there an API to control the snazzy new drop-down completions menu directly, sort of like view.showCompletions in ST1?

Thanks!
M
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: Completions: direct access to the drop-down menu?

Postby jps on Thu Mar 10, 2011 10:44 pm

There's no equivalent of showCompletions, but you can use on_query_completions to add your own completions to the list. See HTML/html_completions.py for an example.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Completions: direct access to the drop-down menu?

Postby jps on Fri Mar 11, 2011 1:39 am

Don't know. We'll see what form the quick panel API takes.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Completions: direct access to the drop-down menu?

Postby Marciano on Fri Mar 11, 2011 5:31 am

I *did* try the on_query_completions api, but I can't get it to work the way I'd like it to.

I am trying to implement something similar to the automatic label insertion facility I had working in my ST1 LaTeX plugin. There, I was using the showCompletions API. Here, my idea was to have the following functionality: the user types, say "ref", then hits ctrl+space, and the completion pop-up appears, listing all labels in the current file. Upon selecting a label, "ref" is replaced with, say, "\ref{selected_label}"

To do so, I tried returning a list of tuples of the form:

[(expr, "\\ref{first_label}"), (expr, "\\ref{second_label}")...]

where expr is the expression to be expanded (it will contain e.g. "ref"). However, what happens is that the drop-down menu only shows the value of expr in each entry (i.e. "ref"), NOT the suggested completion.

I also tried returning sometihing else, e.g.

[("first_label", "\\ref{first_label}") etc.]

but this does not even work, because the cursor is right after "ref", and of course "first_label" is not a match for it.

So, I guess what I am trying to do is just not possible using on_query_completion. Hence, the need for direct access to a popup. But, I'd love it if it was possible to use on_query_completion some other way! The entire completions system is amazing---I am loving the .sublime-completions file, for instance.

M
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am

Re: Completions: direct access to the drop-down menu?

Postby jps on Fri Mar 11, 2011 6:06 am

Try returning something like [("ref:first_label", "\\ref{first_label}", ...], so that the expr contains both 'ref', and a preview of what will be inserted.
jps
Site Admin
 
Posts: 3067
Joined: Wed Mar 19, 2008 12:33 pm

Re: Completions: direct access to the drop-down menu?

Postby Marciano on Fri Mar 11, 2011 3:31 pm

That works! It's not super-pretty because of course you get other completions in the drop-down menu, but it's a great solution for the time being. Plus, the fact that you are not limited to a fixed number of completions is a huge boon. Thanks!!!
Marciano
 
Posts: 146
Joined: Fri Sep 18, 2009 2:55 am


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 23 guests