go to content go to search box go to global site navigation

Tech Blog

Porting Plugins from Sublime Text 2

  • The place to begin is the porting guide, which lists the main changes (python 3.3, asynchronous events, zipped packages, and so on).

  • The plugin API hasn't changed a great deal. There are a couple of restrictions (most functions now can't be called at importing time), and a few new functions.

  • Notably more reliable is the automatic reloading of installed plugins when you edit their sourcefiles. Hooray for plugins being run in a dedicated thread.

determining the root directory of a project:

  def root_directory(self):
      # sublime text 3
      return sublime.active_window().project_data()['folders'][0]['path']
      # sublime text 2
      return sublime.active_window().folders()[0]

importing packages

  • other plugins can now be imported as modules
  • local file imports need to be referenced as a full path:
  # sublime text 2
  from core.machismo import BlazingSaddles

  # sublime text 3
  from MyPlugin.core.machismo import BlazingSaddles

This also means you'll need a (possibly empty) __init__.py within each directory from which you import.

If you want to support both ST2 and ST3, add your plugin to sys.path:

  # to support sublime text 2
  import sys

  from MyPlugin.core.machismo import BlazingSaddles

package control

If you still support Sublime Text 2, it's worth submitting your plugin to Package Control. Package Control for Sublime Text 3 is currently alpha.

References: * Porting Guide * Sublime API * Sublime Technical Forum * Package Control * Thoughts on writing a Sublime Text 2 plugin