Currently I need to run a self defined WindowCommand from within my plugin with arguments.
From the console I can run window.run_command("yet_another_launcher", {"category": "file+sys"})
, but how would I do that from within a Sublime plugin?
Currently I need to run a self defined WindowCommand from within my plugin with arguments.
From the console I can run window.run_command("yet_another_launcher", {"category": "file+sys"})
, but how would I do that from within a Sublime plugin?
There are several ways, depending on the context you mean by saying “my plugin”:
# First way - always available
import sublime
sublime.active_window().run_command(...)
# Second way - within a TextCommand
import sublime_plugin
class DoSomethingCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.window().run_command(..)
The general technick is to get hold of a window object. Then you just invoke run_command()
.
I recommend you to have a look at Sublime Text 3 API Reference to achieve exactly what you need.
Thanks, the first one did the trick. I also read the API first. But I am new to programming and APIs and only a hobby programmer that tries to scratch his own itch with that simple Yet Another Launcher plugin.
I used it to recursively call my own WindowCommand again.
Lines 204 & 206 in https://github.com/dahanbn/Yet-Another-Launcher/blob/development/YetAnotherLauncher.py
For what it’s worth, from within a WindowCommand
, you can get the window you’re running in via self.window
as well. It works out to the same thing as what you’re doing here anyway, though.