# Kakoune-repl-buffer, a new way to work with repls

**URL:** <https://discuss.kakoune.com/t/kakoune-repl-buffer-a-new-way-to-work-with-repls/1435>\
**Category:** Plugins\
**Created:** [December 18, 2020, 7:16am UTC](https://discuss.kakoune.com/t/kakoune-repl-buffer-a-new-way-to-work-with-repls/1435 "2020-12-18T07:16:25Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [December 10, 2024, 7:24am UTC](https://discuss.kakoune.com/t/kakoune-repl-buffer-a-new-way-to-work-with-repls/1435/7 "2024-12-10T07:24:46Z")

</div>

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](https://discuss.kakoune.com/t/terminal-inside-kakoune-text-file-terminal/2566), 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:

[![asciicast](https://asciinema.org/a/Y7VdMcQiD01soZZXEsbliydpG.svg)](https://asciinema.org/a/Y7VdMcQiD01soZZXEsbliydpG)

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.

---

_[View the full topic](https://discuss.kakoune.com/t/kakoune-repl-buffer-a-new-way-to-work-with-repls/1435)._
