Hacking text editors for Runt
Over the past few weeks, I've been hacking text editors (plural) to work with Runt, my little stack-based interpreter.
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:
- Small text editors are awesome
- I don't know how to make vim plugins
- It would be faster to hack a smaller text editor than make a vim plugin
- Small text editors can be more "integrated" with Runt vs Vim
- Portabiliy and smaller footprint
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.
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.
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".