Sublime Forum

How to map a key to SublimeREPL command?

#1

I’d like to map the following SublimeREPL plugin menu command to a key so I can easily execute it:

Tools -> SublimeREPL -> Python -> Python - Run current file

I used the package resource viewer and looked at the key mappings for SublimeREPL, but don’t so how to accomplish this.

-Thanks

0 Likes

#2

SublimeREPL is supposed to have a default binding for “open the current file in a REPL,” I think it’s ctrl+, then f, but if that doesn’t work for some reason, you could try adding this to your regular Sublime Key Configuration file:

{ "keys": ["ctrl+,", "p"], "command": "run_existing_window_command", "args": { "id": "repl_python_run", "file": "config/Python/Main.sublime-menu"} }

(Adjust the binding to your taste.)

SublimeREPL has a fairly complicated command structure; this is taken from the SublimeREPL/config/Python/Default.sublime-commands file, and runs a command defined in Main.sublime-menu in the same directory. There might be a better way to do this, but this worked for me just now.

0 Likes

#3

When I type ctrl+, f, I get the following error message:

“Cannot find REPL for ‘python’”

But if I select from the menu:

Tools -> SublimeREPL -> Python -> Python - Run current file

It works. Any idea why the key binding produce the error?

-Thanks

0 Likes

#4

I don’t use that particular plugin, but if you open the Sublime console with Ctrl+` or View > Show Console, you can enter the command:

sublime.log_commands(True)

That tells Sublime to log all commands as it’s executing them. Running the command via the key binding and via the menu may point out what one of them is doing differently than the other and help you trace why it doesn’t work.

You can run the same command with False instead to turn off command logging when you’re done (or restart Sublime).

0 Likes

#5

Thanks, very useful to know. I get “The handle is invalid” error below. Not sure how to fix it though. I read the docs and run repl from the command console to enable a SublimeREPL:python, but still get the error.

File “C:\Users\bernie\AppData\Roaming\Sublime Text 3\Packages\SublimeREPL\repls\subprocess_repl.py”, line 209, in is_alive
return self.popen.poll() is None
File “./python3.3/subprocess.py”, line 930, in poll
File “./python3.3/subprocess.py”, line 1145, in _internal_poll
OSError: [WinError 6] The handle is invalid
command: drag_select {“event”: {“button”: 1, “x”: 30.5, “y”: 792.5}}

0 Likes