Sublime Forum

Snippet's dropdown for LaTeX

#1

Hey there,

I’m using SublimeText 3 with LaTeXTools and I’d like to have a dropdown/pop-up appear for available snippets. For example, if I type “figure”, I want a dropdown to appear, letting me know that I’ve 2 available snippets for that word: “figure” and “bfigure”.

Is there a way to do this? I would expect this to be default behaviour.

0 Likes

#2

I wrote some code a while ago that will display autocompletions for snippets tab triggers:

I guess you’d want to change the if not triggerText.startswith(prefix): to if not prefix in triggerText:, so that your bfigure snippet would show when you type figure. Also, you’d have to add the text.tex scope to your auto_complete_selector setting, otherwise the suggestions would only show when you explicitly trigger autocompletion using the menu or keybinding.

0 Likes

#3

That does not work for me, though truth be told, I’ve no idea what I’m doing.

After changing your script (as you suggested) and saving it in ~/.config/sublime-text-3/Packages/User, what am I supposed to do with it?

Also, I changed

// Controls what scopes auto complete will be triggered in
“auto_complete_selector”: “meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc”,

to

// Controls what scopes auto complete will be triggered in
“auto_complete_selector”: “meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc - text.tex”,

(just added “text.tex”)

Is this correct? Because absolutely nothing changed. Still not getting the dropdown for latex files.

0 Likes

#4

Basically, what I want is to enable auto-complete for latex snippets. Does one really need to get into scripts and all that to do that?

0 Likes

#5

apologies, turns out you shouldn’t need the script. I had thought that snippets aren’t shown by autocompletion automatically, but it seems they are - the script I linked to is related to when the snippet has a tab trigger that isn’t a word, in which case maybe it’s not shown by default.

So it should be enough to change your auto_complete_selector to:
meta.tag - punctuation.definition.tag.begin, source - comment - string.quoted.double.block - string.quoted.single.block - string.unquoted.heredoc, text.tex

note the comma before text.tex. Minus is a “negation”, comma is an “or”.

2 Likes

#6

@kingkeith, thank you. That worked perfectly.

Would be cool if typing “figure” would also have “bfigure” in the dropdown, but it’s good enough as it is.

Thank you again

0 Likes