Sublime Forum

What can <args> be in `run` of `sublime_plugin.TextCommand`?

#1

I have just started learning about plugins and I can find no information about what <args> can be, which are mentioned here.

Could someone link a resource?

0 Likes

How to know which package is running in my sublime text 3?
#2

<args> can be anything you want. For instance,

class FooCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        # invoke in the console with 
        # view.run_command("foo")
        print("FooCommand")

class BarCommand(sublime_plugin.TextCommand):
    def run(self, edit, do_the_thing):
        # invoke in the console with
        # view.run_command("bar", {"do_the_thing": True})
        print("BarCommand:", do_the_thing)

class BazCommand(sublime_plugin.TextCommand):
    def run(self, edit, arg1, arg2):
        # invoke in the console with
        # view.run_command("baz", {"arg1": "Hello", "arg2": "World"})
        print("BazCommand:", arg1, arg2)

class QuxCommand(sublime_plugin.TextCommand):
    def run(self, edit, **kwargs):
        # invoke with any named parameters, .e.g.
        # view.run_command("qux", {"foo": 1, "bar": "bla", "baz": True})
        print("QuxCommand:", kwargs)

That said, unfortunately there’s a JSON translation layer in-between calling a command and receiving the arguments in the command, so, you cannot pass around Python objects between commands, except when they’re JSON-(de)serializable.

2 Likes

#3

Oh, I am sorry.

While looking through other plugins to learn from, I misread a function. All is clear now!

2 Likes