Sublime Forum

auto_complete_triggers with more than one character

#1

Hi,

I am having some issues with the auto_complete_triggers when developing in C++.

Ideally, one would like to trigger autocompletion on characters such as “.”, “::” or “->”.

The problem is that, as of today, Sublime Text only seems to support single characters as triggers.
In my case, this leads to autocompletion being triggered when I press “:” (e.g. at the end of “public:” in a header file) while I would only want ti to appear when typing it twice ("::").

Is that kind of enhancement planned for a feature version?

Thanks.

1 Like

#2

You should be able to do this with a .tmPreferences file and a cancelCompletion regex.

2 Likes

#3

Thanks for the link @FichteFoll, I did not know about that.

I created a tmPreferences file with a regex that should match all possible lines.
No success so far, the completion popup is still showing up.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>name</key>
        <string>C++ Metadata</string>
        <key>scope</key>
        <string>source.c++</string>
        <key>settings</key>
        <dict>
            <key>cancelCompletion</key>
            <string>.*</string>
        </dict>
</dict>
</plist>

The tmPreferences file seems to be loaded as I get an error message if there is a mistake in the XML file.
Is my scope (source.c++) incorrect?

0 Likes

#4

You can check with ctrl+alt+shift+p. I think it’s source.cpp but can’t check right now.

0 Likes

#5

Ctrl+Alt+Shift+P shows “source.c++ meta.class-struct-block.c++” when I am located inside a class.
If I put this whole selector inside the tmPreferences file, it works.

However, this is quite restrictive since it only works for the particular case of the auto-completion inside a class.
Do you know if there is a selector to match anything inside a cpp file?

Thanks.

0 Likes