Visual structural editing for Guix (and Schemes in general)

by Jonathan Frederickson — Sat 21 September 2024

I've been noodling on structural editing for a while now. I'm fully bought into Lisps myself, but most of my friends and coworkers are skeptical, and I think a lot of their skepticism has to do (as usual) with all the parens. One of the points I make frequently is that with Lisp code being written as a nested data structure, the textual representation is just one of many possible representations. But it can be hard to get across what that means without concrete examples.

A few years back, I ran across Fructure for Racket. To this day, it's still the structural editor with the most appealing visual display to me. But Fructure itself has a few drawbacks for my purposes:

In addition to these, I've been wanting a way to make Guix configuration as easy and painless as possible for new users. Having a sort of "command palette" available seems like it might be a good way to accomplish this.

So recently, I did a quick initial sketch of what such a system might look like:

Pencil mockup of a structural s-expression editor for Schemes, showing a Guix operating-system record. There is an expression palette that can be used to search for expressions and drag them into the structural editor.

I have a few initial use cases in mind:

Obviously given the fact that there are two styles of very different interfaces here, this has to involve some sort of runtime checking. And we probably can't entirely infer which to use based solely on the source code, so there's probably some per-project editor configuration needed for this to work. But... I think this might be doable.

I need to look into this some more, but a good starting point might be the nREPL protocol. It seems pretty extensible, and already has support for symbol lookups and such. But need to look into this all some more!