Sublime Forum

Getting Started?

#1

What’s the latest recommended guide for getting started with plugin development?

The official docs page has a link that’s very temptingly named “How to Create a Sublime Text Plugin”, but sadly it’s just a tease as it points to a 7-year old page about ST2 plugins. The only sticky post in this forum is about ST2 plugins, which also doesn’t seem like the thing that I’m looking for. Am I just looking in all of the wrong places?

I know I’m new here and I shouldn’t be casting aspersions, but I have to ask: Is plugin development dead? Because it sure looks dead.

And while we’re on the subject, the official documentation seems…well…sad, to put it politely. I could see contributing to it as I learn my way around, but I don’t see anywhere to submit said contributions. Am I missing something?

Sorry if I’m being rude. This has been a rage-inducing first foray into ST plugin development. Please help out a frustrated newbie!

0 Likes

#2

TL;DR: I don’t think there is currently a good resource for this, ST2 plugin development is not as different as you might think it is, and it’s doubtful that plugin development is dead based on the number of new packages that are coming out every day. The official documentation is sparse-ish, the unofficial documentation is more detailed, but together they contain the information you need, just not step by step instructions, so you should also look at some practical examples to see how things fit together and help yourself understand better.


I don’t know that there are any official sources short of what you’ve already noticed. I’m currently working on a tutorial video series on the subject, but that’s not likely to help you in the short term. It would be helpful to know what you think is missing or what you’d like to see in this regard, though.

If it helps, the official documentation contains a porting guide that tells you how to port a plugin from Sublime 2 to Sublime 3, which is (paraphrased):

  1. Python 3.3 is used instead of Python 2, so syntax and libraries change accordingly

  2. Plugins are now executed in an external process for isolation so they can’t crash Sublime; this has no practical effect on you as a plugin developer

  3. As part of #2, the API is not immediately available when your .py file is loaded; if you need to do any set up work at load time, define a plugin_loaded() top level function in the module

  4. The API is more threadsafe than it was before, so older code will still work but newer code is easier to write in this regard

  5. Some of the existing events now also have async variants that automatically run in another thread to save you time if you’re doing something lengthy and don’t want to block the UI.

  6. Sublime 3 can run packages from sublime-package (i.e. zip) files instead of having to unpack them first; if you write a plugin that needs to access files within a package, use the API to get at the resource and don’t blindly assume the files will be sitting unpacked on the file system.

  7. You cannot create edit objects at will; define a TextCommand if you need to directly modify a buffer to be given one directly by Sublime.

That is, things are mostly the same except in ways that don’t directly matter to you a lot of the time, presuming you’re familiar enough with Python to be able to convert whatever might be different about Python 2 to Python 3.

On the whole your biggest sticking point is going to be #7, edit objects. You need to pass one to any API functions that modify the contents of a file, and where you used to be able to create them with impunity you now have to rely on Sublime giving you one as part of a TextCommand, so any older code you see would need to be refactored a bit.

To your other questions, is plugin development dead? I highly doubt it. Potentially there’s not a lot of ST3 specific documentation because things more or less work the same as they used to, or nobody has stepped up with a recent set of tutorials because of other reasons. The new packages section of the Package Control website is constantly getting new packages added, for example.

The official documentation isn’t open sourced in a place where contributions can be directly made. On the other hand, the unofficial documentation is definitely open to pull requests.

If you want to get started in plugin/package development my advice would be:

  1. Read through the Unofficial Docs to get a handle on all of the different resource types that a package can contain and what they’re for
  2. Read through the Official Docs, including the API documentation page so you can get a vague sense in your head about what the plugin API is capable of
  3. Use View Package File from the command palette to look at the .py plugins that ship with Sublime to get a sense for how the API fits together.

In short, package development is a complicated topic to describe, document and teach because, more or less, everything relies on you knowing something else before you can fully understand what it is and what it’s for.

As such, there’s not a set of pages where you just read it from the top to the bottom and now you know how to develop plugins. After you read through all of the items above, there’s going to be a bunch of stuff that you don’t fully understand or flat out can’t tell what the hell it’s even talking about.

However as you work through simple plugins, look at samples, and then go back to the documentation, you’ll find that every time you go back you understand more than you thought the first time through.

5 Likes

#3

Thanks for the detailed response. That helps a lot. So much so that your entire response should probably be added to the documentation.

I see now that a lot of info is available scattered about the internet, but I think that’s the general problem: it’s scattered across the internet. Having the official docs be so incomplete, to the point of referencing unofficial docs, is rather off-putting.

The fact that there are two sets of docs that appear to be competing for attention is also odd for a beginner (and in general, I think). It’s even more odd that the “unofficial” docs seem to be more canonical than the official docs. It’s easy to start thinking “there be dragons here”.

As for things to add…

  • It’s good to know that ST2 material is still mostly relevant, but that’s only helpful for someone who knows anything about ST2 plugins, which a beginner wouldn’t. Even neglecting that little issue, the similarity isn’t mentioned anywhere in either set of docs. Well, the Porting Guide mentions it, but I didn’t think to look there because I have nothing to port.

  • Oddly, the official docs never mention that plugins are written in Python. One could infer it from the API reference but it’s never actually mentioned. The unnoficial docs do mention it, although briefly. So at least there’s that.

  • The fact that it’s specifically Python v3.3 isn’t mentioned anywhere that I can see.

  • Your points #1 - #3 would be excellent additions to a top-level paragraph under “Plugin Development” in the official docs. They’d be good adds to the unofficial docs too. #6 and #7 definitely need to be mentioned somewhere. Although I suspect #7 would be harder to incorporate because it sounds like something that won’t make sense until after becoming a plugin expert.

  • Both sets of docs suffer from being very reference-oriented with very little affordance for getting up to speed (ie. learning-oriented). For example, at the top level both are just a list of topics with little, or no, intro material. The official section on plugin development jumps right into Color Schemes without any mention of why that’s useful. ie. nowhere does it mention that a color scheme is a component of a plugin rather than an entire plugin by itself. Does one always begin a new plugin by first creating a color scheme? Granted, that seems nonsensical if one knows that plugins can do more than syntax highlighting, but the structure of the docs seems to imply that you do, and a beginner would be left wondering about it.

  • The unofficial docs are a jumble of user and developer material. A few places mention that “only developers need this” but there’s no clear delineation. From the top-level it appears to be only a user-guide without any developer material. That’s why I initially missed what little info there is.

That’s all that’s coming to mind at the moment, although I feel like I’m forgetting something important. I’ll be sure to bug the list as I muddle through the development process.

Thanks again for taking the time to help. I hope I didn’t come across too strongly at first. After happily using ST for many years I came into this with high expectations. Probably unrealistically so. Thanks for your patience.

0 Likes