Hacking text editors for Runt

2017-01-12

Over the past few weeks, I've been hacking text editors (plural) to work with Runt, my little stack-based interpreter.

Motivations

Mainly live/interactive coding. I've had great joy and success using Sporth to build compositions using my live coding setup with Vim. Runt in many ways is much better suited for interactive coding, so I figured I should make something better than irunt for stuff like that.

I made the choice to hack on existing small text editors instead of building a vim plugin for a few reasons:

Kilo

kilo was originally a simple text editor in less than 1000 lines of code, made by the wonderful antirez. It has a feel that reminds me of the nano text editor. By adding a few lines of code, I modified the program so that hitting CTRL-e would evaluate a line of Runt code.

I said this was a REPL, and part of a REPL is the print aspect. My solution to this was to write all Runt output to a file called "tape". This file could be monitored in another terminal window using "tail -f tape". Tada! Instant REPL.

Leveraging tmux

Using Kilo and tail were well and good for most things, but I realize that if multiple sources were writing to the tape file, tail would sometimes not update. This became a problem when implementing runt-plumber because I needed to instantaneously see error messages from Sporth as well as Runt.

As it turns out, tmux has the ability to send text to other terminal windows it has spawned. This functionality can be used to replace "tail". Before starting Kilo, I ran "ln -s $(tty) tape" in the terminal window where I wanted to see text output. Then, running kilo in another window, I was able to send text to the terminal window instead of to a file. This seemed to solve the issues I was having.

Bonus: Sandy

While Kilo proves to be a highly portable lightweight text editor for Runt, I missed my HJKL vi movements, so I looked into hacking another small text editor.

Sandy is a vi-like text editor I found many years ago. For a while, I was quite enchanted with it's simplicity and DWM-style configuration. It's almost a text editor I'd leave Vim for. (Almost.) After porting Runt to Kilo, Sandy was a natural option 2. Like Kilo, CTRL-E evaluates a line and outputs any results to a file called "tape".