FIFO buffers

First-In-First-Out buffers are a thing I’ve never used before using kakoune. I saw them being used by cargo.kak to print cargo output to a buffer active in kakoune.

How to use

  • Make a FIFO buffer: mkfifo /tmp/myfifo
  • Open the buffer in kakoune: :edit -fifo /tmp/myfifo -scroll *myfifo*
  • Run a command in another shell: echo "hello!" > /tmp/myfifo

This will result in "hello!" appearing in your buffer in kakoune.

Why

Some projects I’m working on have a build or watch command that is running in a different shell. This way you keep an eye on it while developing. Instead of echoing hello you can also run a watch command like fswatch -xn . to keep an eye on changed files (and pipe them to a build command.) I don’t know. Possibilities are endless!

Adding commands to your own FIFO buffer

Some output will result in errors with file numbers. You can add a filetype to a buffer with set-option buffer filetype myfifo.

# Add hook to add key map on filetype:
hook global WinSetOption filetype=myfifo%{
    map -docstring "Jump to position" buffer normal <ret> %{:myfifo-jump<ret>}
}
# Add hook to remove key map on filetype:
hook global WinSetOption filetype=(?!myfifo).* %{
    unmap buffer normal <ret> %{:myfifo-jump<ret>}
}

# command to run when enter is pressed on a line in your fifo buffer
define-command myfifo-jump %{

}