Snippets and auto-complete have been reworked into a single completion system. They're now combined into a single completion source, and triggered using a combination of the previous keys:
- Tab: Insert the best matching completion
- Ctrl+Space: Display an interactive completion list
Among other things, this means that snippets no longer get key bindings generated for them, instead they're inserted by looking an the contents of the buffer: you can press backspace midway now, for example. If a snippet is currently active, tab will always navigate to the next field, in precedence to inserting a completion. You can still use ctrl+space to insert a completion in this circumstance.
The completions come from 4 sources:
- Plugins responding to the completion API
- .sublime-completions files
- Words from the current buffer
When using tab, snippets will only trigger if the current word exactly matches the tab trigger of the snippet. The other sources are more lax, and will match using the existing approximate matching algorithm.
Here's a quick example plugin:
- Code: Select all
import sublime, sublime_plugin
def on_query_completions(self, view, prefix, locations):
if not view.match_selector(locations, "source.python"):
return [("if", "if $1:\n\t$0"), ("else", "else:\n\t")]
In short, return an array of (trigger,snippet) pairs from the on_query_completions function. For another example, take a look at Packages/HTML/html_completions.py
.sublime-completions files are JSON files that provide a static set of completions, for example:
- Code: Select all
Each completion can either be a string, or a dictionary with "trigger" and "contents" fields, where the contents are a snippet. For an example, take a look at PHP/PHP.sublime-completions and HTML/HTML.sublime-completions.
Included in 2030 are completions for HTML and PHP. PHP has a bunch of functions in its completions, while HTML has tags, as well as a plugin that will expand simple expressions like div.class and div#id. These are there mostly as an example, I'm more than happy to accept patches to expand what's covered. For example, it'd be nice if the PHP completions included arguments for the functions (via the snippet syntax), and if there was an HTML plugin to complete tag attributes.
These are some fairly major changes, and as usual for a dev build, I'd be surprised if haven't broken some things along the way. Personally, I'm just happy I can complete words using tab now.