Sublime Forum

Newbie Plugin development - Couple of questions

#1

The embedded interpreter is only intended to interact with the plugin API, not for general development.

  1. What does this mean? The way I read it, it is recommended to develop a plugin with my own python interpreter and use the build in for a wrapper to interface with ST API, correct? How does this work?

  2. is there a naming convention for folders within a plugin, like ‘icons’, ‘templates’, et al?

  3. how can I get some user input, as you would when selecting “New Folder” in the sidebar?

thank you

0 Likes

#2

It means that Sublime has a Python interpreter embedded in it, but that Python interpreter is strictly for the use of Plugins in Sublime to extend it’s functionality in some way or other and is not intended to be used to execute arbitrary Python scripts.

Unless you’re developing a plugin that needs a lot of code that doesn’t have anything to do with Sublime directly, you can’t develop your plugin in an external Python interpreter.

For example, if your plugin was trying to scan the file system for all files of a certain type with certain text, you could certainly do that in an external Python interpreter and then later take that code and add it to your plugin (presuming you keep in mind that Sublime’s Python interpreter is Python 3.3.6).

On the other hand, if your plugin was something that needs to look through the contents of files that are open in Sublime to find some text, or something else that interacts with Sublime, that’s not going to work in an external interpreter unless you also replicate the Sublime API yourself for use in that interpreter first.

Note that a plugin is a Python file like my_custom_command.py; the folders in the Packages directory are packages, which are a collection of resource files (and unrelated files if desired, like data files), which include plugins, key bindings, syntax specifications, and other things. I think that’s what you’re referring to here.

As far as I’m aware there is no naming convention per se; depending on the complexity of your package you may choose to lay things out in a particular way if it makes it easier for you to develop and maintain it.

For plugin resources (as above), Sublime will only find and automatically load files at the top level of a package and all plugin files in subdirectories of the package will be ignored unless you manually import them from a file that it did load. That allows you the freedom to do different things based on the OS that Sublime is being run on and so on.

Apart from that restriction, all package resources that Sublime knows about will be found and loaded from within your package no matter what their location in there is, top level or not.

There are two ways to pull something like that off (depending on your version of Sublime).

The first one, which is always available, is window.show_input_panel(). That will open a single line input at the bottom of the window for you to collect input from. I believe this is the one that the side bar command that you mentioned uses.

The other is to use a TextInputHandler, but that is only available in the more recent versions of Sublime (i.e. unless you have restricted yourself to some really old version of Sublime, it should be available to you).

This method allows you (when you execute a command from the command palette) to ask for the input directly in the command palette. An example of this is the Arithmetic command that ships by default (and is an indication as to whether this functionality exists or not).

1 Like

Running scripts wih sublimetext, advice needed