lin-edi-table is a readtable & syntax library suited for line editing of Lisp code.
lin-edi-table stems from my (aartaka) desire to edit Lisp in line-based environment.
This is hard.
The code needs big adjustments or heavy syntax changes.
Thus the need for new reader macros.
I cannot use them in open source libraries without packaging them into a library of their own, though.
So here’s the library with macros for Lisp line editing, packaged in a named readtable: lin-edi-table!
Here’s how a factorial function looks with hash-slash macro provided by lin-edi-table, for example:
;; Useful for macros like with and whether
(use-package :lin-edi-table)
;; For syntax like #/ and []
(named-readtables:in-readtable lin-edi-table:table)
(defun factorial [n]
(if #/ < n 2
1
#/ * n #/ factorial #/ 1- n))
Getting Started
Library user setup
If you want to use the library without hacking on it, clone the Git repository to where ASDF can find it:
git clone https://codeberg.org/aartaka/lin-edi-table ~/.local/share/common-lisp/source/
And then load "lin-edi-table" in the REPL:
(asdf:load-system "lin-edi-table")
;; or, if you use Quicklisp
(ql:quickload "lin-edi-table")
Using it after that is either adding a form to the top of each code file:
(named-readtables:in-readtable lin-edi-table:table)
or merging the lin-edi-table with the standard readtable
(named-readtables:merge-readtables-into *readtable* lin-edi-table:table)
You can also :use the :lin-edi-table package to get macros like with and whether:
(defpackage your-package
(:use :cl :lin-edi-table))
;; Or, dynamically
(use-package :lin-edi-table)
Contributor/developer setup
In case you want to hack on lin-edi-table, all the dependencies are bundled as submodules, you need to do a recursive clone
git clone --recursive https://codeberg.org/aartaka/lin-edi-table
In case you initially cloned the repository without submodules, do
git submodule update --init -- deps/
After that, you can run
- an Emacs-friendly development server
make slynkormake swank-
REPL with all the dependencies and
lin-edi-tablepreloaded make repl- tests
(asdf:test-system "lin-edi-table")or runmake checkfrom CLI.
Provided utilities
Non-syntax utilities provided by lin-edi-table:
withmacro as a less verbose version oflet*removing unnecessary level of parens around binding. Stolen from Clojure let.whethermacro as a less parenthesized version ofcond. Every pair of forms is a condition+clause pair. To get the regularcondbehavior, one would have to wrap multiple forms inprogn, but such is the price. Idea stolen from Clojure cond, again.
Provided Syntax
Overall, see tests for what the syntax expands to and how it might be used. But here’s an overview.
#^ lambdas
Shorter anonymous functions #^v.(fn arg1 arg2) to save on all the parentheses needed for lambda.
The syntax is vars.body.
Where vars is a non-delimited string of up to three single-char vars (abc is a, b, and c vars)
to be bound to optional ignorable lambda args.
And body is any Lisp form.
#/ hash-slash operator
Behaves like Wisp’s inline colon operator, reading the form until the end of the line or end of wrapping form, as a parenthesized list. I.e.
(+ 1 #/ * 2 3 #/ - 4 5)
;; Is the same as
(+ 1 (* 2 3 (- 4 5)))
Note that this syntax is newline-sensitive, and adding a newline nullifies/closes any stack of hash-slashes you had. This is unlike Wisp, where colon sometimes can stretch for multiple lines when augmented with indentation. Also note that indentation doesn’t influence hash-slash!
(+ 1 #/ * 2 #/ + 3
(- 4 5))
;; Is the same as
(+ 1 (* 2 (+ 3))
;; Notice this form is not part of the * 2 above
(- 4 5))
Square bracket [1 2 3] lists
This is stolen from Scheme, where square brackets are roughly equivalent to parentheses.
It’s useful for e.g. let bindings to disambiguate separate bindings:
(let ([a 3]
[b 4])
(+ a b))
While this syntax addition might seem orthogonal to line editing, it isn’t. Having a varied set of delimiters means regex in line-based editors (like ed) can easier manipulate forms. Thus the addition.
Contributing
See the CONTRIBUTING.md for nice-to-have things in your contribution.