Plugin Porting Guide Version:
Sublime Text 3 contains some important differences from Sublime Text 2 when itcomes to plugins, and most plugins will require at least a small amount portingto work. The changes are:
Python 3.3🔗
Sublime Text 3 uses Python 3.3, while Sublime Text 2 used Python 2.6.Furthermore, on Mac, the system build of Python is no longer used, insteadSublime Text is bundled with its own version. Windows and Linux are alsobundled with their own version, as they were previously.
Out of Process Plugins🔗
Plugins are now run in a separate process,plugin_host. From a pluginauthors perspective, there should be no observable difference, except that acrash in the plugin host will no longer bring down the main application.
Asynchronous Events🔗
In Sublime Text 2, only theset_timeout() method was thread-safe. In SublimeText 3, every API method is thread-safe. Furthermore, there are nowasynchronous event handlers, to make writing non-blocking code easier:
on_modified_async()on_selection_modified_async()on_pre_save_async()on_post_save_async()on_activated_async()on_deactivated_async()on_new_async()on_load_async()on_clone_async()set_timeout_async()
When writing threaded code, keep in mind that the buffer will be changingunderneath you as your function runs.
Restrictedbegin_edit() andend_edit()🔗
begin_end() andend_edit() are no longer directly accessible, except insome special circumstances. The only way to get a valid instance of ansublime.Edit object is to place your code in asublime_plugin.TextCommandsubclass. In general, most code can be refactored by placing the code betweenbegin_edit() andend_edit() in asublime_plugin.TextCommand, and thenrunning the command viarun_command().
This approach removes the issue of danglingsublime.Edit objects, and ensuresthe repeat command and macros work as they should.
Zipped Packages🔗
Packages in Sublime Text 3 are able to be run from.sublime-package(i.e., renamed.zip files) files directly, in contrast to Sublime Text2, which unzipped them prior to running.
While in most changes this should lead to no differences, it is important tokeep this in mind if you are accessing files in your package.
Importing Modules🔗
Importing other plugins is simpler and more robust in Sublime Text 3, and can bedone with a regular import statement, e.g.,importDefault.comment willimportPackages/Default/Comment.py.
Restricted API Usage at Startup🔗
Due to theplugin_host loading asynchronously, it is not possible to use theAPI at import time. This means that all top-level statements in your modulemust not call any functions from thesublime module. During startup, the APIis in a dormant state, and will silently ignore any requests made.