I am trying to create a plugin that works with SublimeREPL, I would like to be able to press the ENTER-key within my plugin in order to send a command to the console.
Is this possible/How would I do that?
I am trying to create a plugin that works with SublimeREPL, I would like to be able to press the ENTER-key within my plugin in order to send a command to the console.
Is this possible/How would I do that?
The default key binding of enter
calls insert
command.
{ "keys": ["enter"], "command": "insert", "args": {"characters": "\n"} },
I therefore guess you’d need to call
view.run_command("insert", {"characters": "\n"})
Thank you, but this wont work! As I have now found out SublimeREPL uses the “repl_enter” command witch i can trigger with “view.run_command(“repl_enter”)” to send commands to the interpreter.
This means I have found out how to solve my problem, but not really the problem I have proposed in my question (Sending actual keypresses to SublimeText). Thus i will not yet add the [Solved]-Tag my post.
I am a little confused here. You can send your enter command to SulimeREPL. deathaxe’s solution will add a newline at the point where the command is run. What precisely are you attempting to do that you can’t with the two solutions?
I can do everything I want to with the two solutions, however I still think sending Keypresses to Sublime Text with Plugins could be useful for other tasks/other people.
Well I don’t deny there is a small subset of problems that might be addressed by more direct API access to the keystream (either in inserting, or analyzing) however I suspect this is a very small subset. Between API command calls, and keymapping and such, uncontrolled access would have to be very carefully considered.
A key press enters normal text or is mapped to a predefined command. Therefore the proper way is to call a command. Sending a key press would not necessarily cause the desired command to be called as key bindings can be customized by users.
What I posted was just the default binding of “enter”, which is bound to insert("\n")
. Didn’t know REPL binds this key to a different command. But this example proofs my former statement. Sending keys is useless.