Sift: One Lisp tool that finally reads Scheme, Racket, Emacs Lisp and Common Lisp
Sift: The Lisp formatter I kept trying to write (+lint and LSP)
After years of failed attempts—keyboard macros, Emacs batch indentation, guix style, compiler warnings, and a pretty-printer that rewrote every line—the author built sift, a single Guile program that formats, lints, and serves LSP for four Lisp dialects. It has over 95 rules, idempotent formatting, a WASM browser build, and a performance fix that cut lint time from 25 seconds to under one.
That’s not a tool. That’s a local opinion with a batch mode.
- aidenn0
Fun fact: you can run emacs from the command line to format your code. Emacs had good formatting for EL and CL (which is even mentioned in TFA, but dismissed as unsuitable for a pipeline). I don't use scheme, but I assume it has good formatting for scheme/racket as well?
- chriswarbo
A tool I've found really valuable when writing Lisp is https://github.com/shcv/parenmedic
It compares the indentation to the parentheses, and complains if they don't agree. It doesn't care about indentation amount (like I-expressions/Wisp/etc.), only that lines following some opened parens get indented more; lines following some closed parens get indented less; and sibling lines are indented the same amount.
I find this much more accurate at spotting the cause of a problem, compared to simply counting whether the openers and closers balance; e.g. the latter will only spot a missing close parenthesis when it reaches the end of the file. This is especially useful for LLMs, which are terrible at counting parentheses.
Unfortunately, there can be some cases where an auto-indenter (e.g. elisp-autofmt) causes parenmedic to complain. One remedy is to alter the auto-indenter's behaviour by inserting a line-comment; but it's not ideal.
I wonder whether Sift would (knowingly or unknowingly) adhere to the rules parenmedic requires?
- cheshire_cat
Am I getting paranoid or does this text read very LLMish?
- bjoli
I tried to nail down ubiiquitous formatting for a typed nl-like sexpr language I have been mostly vibe coding.
It is surprisingly hard. I ended up mostly copying the algorithm that can be used through raco (the racket command line tool). It is not particularly fast, only about 10lines of code per core-second, but it produces a good enough result. I had to leave some things to the user, but only about 5 forms.
- joshmarlow
I've been tinkering with common lisp again lately (via VSCode) and I've been looking for something like this! Going to play with it this weekend.