Home Download Buy Blog Forum Support

Dev Build 2030

Dev Build 2030

Postby jps on Thu Feb 24, 2011 8:07 am

Dev Build 2030 is out now.

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:
  • Snippets
  • 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.

Completion API

Here's a quick example plugin:

Code: Select all
import sublime, sublime_plugin

class CompletionExample(sublime_plugin.EventListener):

    def on_query_completions(self, view, prefix, locations):
        if not view.match_selector(locations[0], "source.python"):
            return []
        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

Completion Files

.sublime-completions files are JSON files that provide a static set of completions, for example:

Code: Select all
{
   "scope": "source.c",

   "completions":
   [
      "malloc",
      "free",
      "memcpy",
      "memset",
      "memmove"
   ]
}


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.
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Dev Build 2030

Postby stiang on Thu Feb 24, 2011 8:27 am

Looks like a great update, as usual!

jps wrote:
  • Ctrl+Space: Display an interactive completion list

Sorry if I sound like a broken record, but it would be great if you could navigate the completion list with whatever keys are bound to move up/down a line (ctrl+p/ctrl+n for most Emacs converts).
stiang
 
Posts: 39
Joined: Sat Jan 29, 2011 12:34 pm

Re: Dev Build 2030

Postby firefusion on Thu Feb 24, 2011 9:34 am

Just a heads up to anyone about to install this, the auto complete breaks zen coding.
firefusion
 
Posts: 218
Joined: Fri Oct 16, 2009 7:37 am

Re: Dev Build 2030

Postby ilya on Thu Feb 24, 2011 9:35 am

New completion system is very cool!

But wrapping selection with html tags is not working?
ilya
 
Posts: 122
Joined: Fri Sep 11, 2009 8:32 pm

Re: Dev Build 2030

Postby jps on Thu Feb 24, 2011 10:18 am

stiang wrote:Sorry if I sound like a broken record, but it would be great if you could navigate the completion list with whatever keys are bound to move up/down a line (ctrl+p/ctrl+n for most Emacs converts).


Will add for the next build.

sublimator wrote:How do the sublime-completions files work? Can you have more than one scope per file somehow?


If you want the completions in the one file to apply to multiple scopes, you can use a selector like "source.python, source.ruby". If you want different sets of completions for different scopes, then you need to use multiple .sublime-completions files.
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Dev Build 2030

Postby daylerees on Thu Feb 24, 2011 12:19 pm

(on linux version)

Been playing with the autocomplete (from snippets) for PHP hoping to speed my day up, a few of them seem to work, and yet others dont.

For example the php class snippet, (checked the source and tabtrigger is just 'class') doesn't seem to expand for me on tab.

Is anyone else getting the same thing?
daylerees
 
Posts: 22
Joined: Wed Feb 02, 2011 12:12 pm

Re: Dev Build 2030

Postby jps on Thu Feb 24, 2011 12:27 pm

The PHP class snippet is working for me, FWIW. Just to be sure, you're in a PHP file, between <?php .. ?> tokens?
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm

Re: Dev Build 2030

Postby daylerees on Thu Feb 24, 2011 12:30 pm

Aha well caught, I work a lot with CodeIgniter, and the default style guidelines are that you omit the ?> end token, it worked fine when I added it in. Would it be possible for this to work without the PHP termination marker? Not a feature request, just asking! I know you have enough to do as it is right now XD. Thanks again mate.
daylerees
 
Posts: 22
Joined: Wed Feb 02, 2011 12:12 pm

Re: Dev Build 2030

Postby Chortos-2 on Thu Feb 24, 2011 12:49 pm

I may be mistaking features for bugs, but expanding a snippet and deleting the generated text seems to (a) not decrement the field counter in the status bar and (b) make the next snippet expansion only work if I press Tab twice in a row, move the cursor with arrow keys before trying to do the expansion (e. g. before entering the snippet’s trigger or after that but before pressing Tab) or press Ctrl+Space instead of Tab.
Last edited by Chortos-2 on Thu Feb 24, 2011 1:23 pm, edited 1 time in total.
Chortos-2
 
Posts: 16
Joined: Thu May 27, 2010 5:13 pm
Location: Riga, Latvia, the EU, Europe, Eurasia, the Earth, the Solar System, the Milky Way, the Universe

Re: Dev Build 2030

Postby daylerees on Thu Feb 24, 2011 12:52 pm

A more positive comment for you, THANK YOU THANK YOU for making the sidebar autoupdate, I am only one feature away from using it full time now :) (create new file from file tree).
daylerees
 
Posts: 22
Joined: Wed Feb 02, 2011 12:12 pm

Next

Return to General Discussion

Who is online

Users browsing this forum: Exabot [Bot] and 15 guests