Previously, the only ways to send text to a REPL in a buffer were to use the repl-buffer-send-text
command (usually to send text from a different buffer), or repl-buffer-prompt
, which asked for input in Kakoune’s prompt line and sent that to the REPL… which was kind of like typing at the prompt, but not really. After last month’s dicussion about Plan 9 and the Acme editor, it occurred to me that I might be able to do something similar inside Kakoune - it’s a text editor, isn’t it? You can type into the buffer, can’t you? So why not send the text you type?
It turns out there were some minor bugs with the BufReadFifo
hook in Kakoune, but those have been sorted out in the latest trunk versions, so if you build Kakoune from source you should be able to try out the latest version of kakoune-repl-buffer and type into the buffer:
The way it works is:
- as each chunk of output is received from the REPL, the plugin keeps track of where that chunk ended
- when you hit
<ret>
, it checks to see if the cursor is after the end of the last chunk (so you can type annotations earlier in the buffer without causing problems) - if the cursor is after the end of the last chunk, all the text from the end of the chunk up to the cursor is sent to the REPL as input
So you can type as normal and hit <ret>
to send a command; you can <esc>
back to Normal mode and edit the command with the full power of Kakoune, you can even paste several lines, edit them, then send them.
The current limitations are:
- Currently, after typing a command, a copy of the command is printed before it executes
- Since the “normal” method of interaction involves sending text from another buffer, the plugin defaults to echoing sent text
- I’m thinking of removing this behaviour entirely, since “type in buffer” doesn’t need it
- Kakoune does not permit “undo” in FIFO buffers, until the FIFO is closed (in this case, when the REPL exits)
- This can be annoying, if you paste the wrong thing at the prompt, you can’t undo the paste
I think this is going to be pretty cool, but I need to use it more to find the rough spots. If you’re interested in testing it out, I’d be interested to hear about any problems you encounter.