Sublime Forum

Completions: direct access to the drop-down menu?

#1

Hi,

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

Thanks!
M

0 Likes

#2

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.

0 Likes

#3

Don’t know. We’ll see what form the quick panel API takes.

0 Likes

#4

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

0 Likes

#5

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.

0 Likes

#6

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!!!

0 Likes