A Drupal autocomplete file for Sublime Text 2

tanc's picture

After trying Sublime Text 2 for a day I’ve already fallen in love with its simple but elegant interface.

Screenshot showing main screen of Sublime Text 2

I’m generally a fairly happy user of Komodo IDE but don’t really like its klunky interface, occasional crashes and its often slow response. What I do like about Komodo is its ability to scan through your project and provide autocomplete suggestions, something that Sublime Text 2 doesn’t do.

So I decided to write a script to fill some of this gap in Sublime Text 2. The script simply scans through a specified directory and creates a json formatted sublime-completions file from all the functions it finds.

For Drupal coding I now have a custom Drupal6.sublime-completions file in my ~/Library/Application Support/Sublime Text 2/Packages/User directory which gives me autocomplete suggestions for all the drupal core and the top 100 drupal module’s functions and parameters.

So I can start typing “drupal_get_pa”, hit control + space and Sublime Text will offer me a choice of functions to complete.Screenshot showing autocomplete functionality.

Choosing one and hitting return completes the function declaration, opens the brackets and fills in the parameters the function is expecting (and their default values if they exist).
Screenshot showing parameters in autocomplete.

This is just a start after a couple hours of coding. What I’d really love to see in Sublime Text 2 is the docblock shown for a suggested autocompletion. This is a powerful learning tool in Komodo where you can start typing a function name and see the associated docblock explaining what that function does and which parameters it is expecting.

File: Drupal6.sublime-completions.zip

Decompress the download above and put the Drupal6.sublime-completions in your user directory. Sublime Text will automatically pick it up and start using it in PHP files. You may need to turn autocomplete on in your preferences.

Update: I’ve created a drush based command to generate this file. Get it here.