Sublime Forum

Keybinding can't find command

#1

Hi,

I’m trying to write a little plugin to let me run my program with arguments taken from a popup text box, but I’ve run into problems.

I’ve added a keybinding

{ "keys": "f8"], "command" : "User.run_with_args" },

to Default(OSX).sublime-keymap and my little plugin located at Packages/User/run_with_args.py) currently looks like this:

[code]import sublime, sublime_plugin

class PromptRunWithArgsCommand(sublime_plugin.TextCommand):
def run(self, edit):
sublime.message_dialog(“testing”)
self.window.show_input_panel("Enter arguments: ", “”, self.on_done, None, None)

def on_done(self, text):
	parts = text.split(" ")
	self.window.active_view().run_command("run_with_args", {"args" : parts} )

class RunWithArgsCommand(sublime_plugin.TextCommand):
def run(self, args):
#get build system, run target program[/code]

Now I have two questions.

  1. How do I make the keybinding find my command? If I switch from “run_with_args” to “build” it works fine. And should I split the two commands into two files? I assume that Sublime finds the commands by file name.
  2. How do I make the current build system run the taget program?
0 Likes

#2

First step, your keybinding does not need the “User” portion. It’s not a package.
I would also assume you want it to run your “prompt” command since your run_with_args does nothing:

{ "keys": "f8"], "command" : "prompt_run_with_args" },

Additionally, TextCommand does not have a “window” attribute. You’ll need to do: self.view.window().show_input_panel(...)

I’m not sure why you are executing another command from within your prompt command. Unless you have other plans, you could just put it all into one class. You’ll also want to pass arguments by name when calling run_command, don’t use {“args”:…}, then use keyword arguments in your run method.

0 Likes

#3

Thanks a lot for the help, it’s running the plugin now.

0 Likes