Sublime Forum

Can you add commands dynamically?

#1

I’m wring a sublime text plugin with the goal of adding gradle tasks as commands so you can execute your build tasks from the editor. So I want to create commands dynamically based on the result of parsing the output of a foreign script.

a. Is this possible? I went as far as generating classes in python and compiling them but they theoretically would not get picked up until the plugin is reloaded (at which time they don’t exist in memory as the plugin is being reloaded thus they don’t actually get picked up). Needless to say, this doesn’t work. It does look like I could add the commands to the list of window commands in maintained in sublime_api.py, but how would I notify sublime that new commands exist?

b. I’ve noticed build systems are static (so I wrote an accompanying plugin for gradle that generates a sublime text 3 project file with all the tasks as build variants). I also want to make sure I’m not clashing on a philosophical level wanting to generate a bunch of build commands dynamically. Are there any issues with this approach?

0 Likes

#2

its sure possible to add sublime comands dynamically, but maybee it’s more realiable to show a dynamic menu with options and create one Text-/Window-Command with arguments instead of generating command classes.

Check out show_popup_menu on sublimetext.com/docs/3/api_reference.html

0 Likes