The story of sift: a voyage of failed attempts, ideas, that eventually came together as a formatter, linter and language server that actually reads Scheme, Racket, Emacs Lisp and Common Lisp.
It’s a solid formatter, highly configurable, got more than 95 lint rules, strong opinions, a WASM browser build, and combines with REPL workflow which makes it all feel like magic if you ask me.
This is the program I’ve been trying to write for years. I finally got it.
Find sift at https://github.com/jjba23/sift, and get a taste of it in your browser at https://jointhefreeworld.org/sift/.
The short version #
I’ve been writing Lisp (the family of languages with all the parentheses) for a few years now, and for most of that time my tooling was a pile of workarounds if I’m being honest with you.
sift is the first tool I’ve built that feels like it understands the Lisp file instead of guessing at it.
It’s built as one Guile program: a formatter, a linter and a language server for four dialects of the mighty Lisp family: Scheme, Racket, Emacs Lisp and Common Lisp. It has right now more than 95 rules. Formatting is idempotent. It runs in your editor, your CLI, in CI (the checks that run on every push), in a container and in a browser tab. It started with a pile of failed attempts.
If you’re new to this: a formatter rewrites whitespace, a linter reports suspicious code, a language server answers an editor’s questions over LSP, and a fixed point means formatting twice gives the same bytes. A docstring is the documentation string attached to a definition. The cool part is that all three are one program, so your editor and CI always agree.
sift lint, sift fix --write, the formatter's diff, and the same file in Emacs with Flymake, Eglot, hover, inlay hints and formatting.That’s the loop: the command line, the fixes, the formatter, then the same file in Emacs. The recording is real. It was captured from a checkout, not drawn by hand.
The problem #
Lisp is a tree of nested lists. The language knows it, and most of the tooling around it pretends otherwise (some with nasty regex magic too).
In Go you have gofmt. In Rust you have rustfmt. Same program on every machine, same answe. In the Lisp world the answer is usually “my editor does it”, “the compiler warns about it”, “we have a fmt task somewhere”, or “run guix style on the package file”.
The cost shows up everywhere. Two editors disagree about indentation. CI formats the code one way and your editor another. A compiler warning is prose: no stable code, no severity, no JSON or SARIF (the data formats editors and code scanners read), no way to suppress it next to the line that caused it, and no fix. A project with Scheme, Emacs Lisp and Common Lisp needs three tools, three configs and three CI steps.
That was my situation. My projects are Guix and Guile, Emacs Lisp and a little Common Lisp; Racket is the fourth dialect sift grew into. My formatting was a maak fmt task running guix style on every .scm file and Emacs’s indent-region on every .el file. Linting was checkdoc, the byte-compiler, guild compile -W3, guix lint, stylelint, and a hand-written checker that read every .el form to prove the config still loaded. Each tool was good at its slice. None of them was the thing I wanted.
The failed attempts #
I didn’t design sift in one go. I kept trying to solve the problem with the tools I had, and each attempt failed in a way that taught me one piece.
The keyboard macro. Before I wrote formatter code, I formatted files with a keyboard macro: tabs to spaces, trailing whitespace gone, indent-region, save, stare at the diff. Then I turned it into a sed script. It was fast, and it felt like magic for about a day. Then I hit a form whose indentation depended on what the form meant, and the script had no idea. The mechanical part is easy. The structural part is the whole problem.
Emacs. The obvious next step was Emacs’s own indentation engine, in batch, over the whole tree. I had a file called batch-indent.el:
(defun indent-file (&optional save) "Format the whole buffer." (indent-region (point-min) (point-max) nil) (untabify (point-min) (point-max)) (delete-trailing-whitespace) (when save (save-buffer)))
For a while this felt like a formatter. Lisp indentation is structural, and Emacs’s modes already encode decades of convention. I kept that.
What didn’t work: it needs Emacs; the answer depends on scheme-mode, Geiser, a project’s indent-rules and the Emacs version; it only indents, so it doesn’t own the printer; it isn’t a fixed point; and it has no lint, no exit status and no report. One machine could format a file one way and another machine another way, and both were “right” according to their setup. That’s not a tool. That’s a local opinion with a batch mode.
guix style. The next try was a canonical tool where one existed. guix style knows how a Guix package definition should look, and it has taste. It also formats Guix package definitions, not Scheme. It doesn’t know your modules, your SXML, your general procedures or your comments. It reflows, so every new idea about line breaks turns every file into a diff. And the .el files still went to Emacs, so the repo had two formatters and a boundary where they disagreed. I kept the ambition of a canonical style and the suspicion that reflowing was the enemy.
The compiler. The third try was to stop writing a linter and use the ones the language already had: checkdoc and the byte-compiler for Emacs Lisp, guild compile -W3 for Scheme, guix lint in Guix buffers, plus a small checker that read every .el form and compared the module list in init.el with the files on disk:
(while (progn (forward-comment (point-max)) (not (eobp))) (read (current-buffer)))
This taught me the most important lesson of the bunch: the language’s own reader and compiler know more than any regex. A file that doesn’t read is a finding. A docstring that doesn’t name its arguments is a convention the byte-compiler cares about. lexical-binding isn’t taste; it’s a header the file needs.
But read throws away the evidence. It discards comments, keeps no positions, and can’t represent a block comment, a datum comment or a reader prefix as a node.
The pretty-printer. Once the tree worked, I thought the next step was a pretty-printer. I wrote one that decided line breaks from the structure, the way Prettier does. The output was beautiful. Then I ran it on a 300-line file and the diff touched every line. git blame turned into a joke, and every future change would be buried under the formatter’s opinions. I reverted the file and never wrote that pretty-printer again. That’s where the no-reflow rule comes from.
read plus a scanner. Before I wrote the reader, I tried to build the linter on Guile’s read plus a line scanner. read gave me forms; the scanner gave me lines; I kept a table to map one to the other. Comments fell through the table. A comment inside a form, a #; datum comment, a string with a semicolon in it: the two representations disagreed and I couldn’t tell which one was right. I gave up and wrote the reader. One representation has to win, and it has to carry positions.
Editor macros. I wrote indent-rules and syntax-propertize functions for my own macros in Emacs. It made my editor nicer. It also made CI disagree with my editor even more, because the editor knew my macros and no other tool did. Conventions have to live in a program, not in one editor’s mode.
The pre-commit hook. I wired guix style and emacs --batch into a pre-commit hook. It was fast and useful, and it caught tabs and trailing whitespace before they landed. But it only caught what the tools caught, it couldn’t fix anything, and every repository had its own copy. The pipeline shape was right. The tool behind it was missing.
One tool per dialect. The obvious next move was one tool per dialect: Racket’s own formatter for Racket, guix style for Scheme, Emacs for Elisp, something else for Common Lisp. It worked, in the sense that each dialect got a tool. It also gave me four tools, four configs, four CI steps and four styles that disagreed at the boundaries.
The idea #
The design is six beliefs, written down in doc/design.org:
- A source file is a parsed, not read as a string. A comment keeps its column, a fix replaces one range, a diff’s hunks are the change.
- Formatting is idempotent, a fixed point, and the property is tested. The suite formats every fixture, then formats the result again, and asserts that the second pass changed nothing.
- You own the program; the tool owns the layout. sift re-indents, re-spaces, re-levels comments and re-brackets a
condclause. It doesn’t rename, reorder or inline a procedure on its own, and it doesn’t introduce a delimiter. - A dialect is a language, not a variant. Common Lisp is not Scheme with longer names. A formatter that infers the dialect will, one day, rewrite Common Lisp as Scheme.
- Answer only where the answer can be justified. The language server answers its table and says “method not found” to the rest. A refusal is a feature when the only alternative is a plausible lie.
- Everything the program says is available as data. A finding is the same finding in five output formats and over LSP. A rule is a record before it’s a document.
Why the name? To sift is to pass something through a sieve and separate what matters from what doesn’t. A source file mixes the program with the layout. sift separates them, checks the program, and puts the layout back the way the style says. It’s a sieve, not a sculptor.
The performance turn is the unsexy part that made it usable and the initial implementation was indeed naive. Three questions dominated the cost of a lint, and each was originally answered by walking something a second time: whether a node is code or data, what a form is called, and where the lines begin. Each is now computed once and carried or kept.
Together they took a lint of the repository from twenty-five seconds to under one, and the allocation from a gigabyte and a half to a hundred and forty megabytes. Guile’s garbage collector stops every thread, so less allocation means better parallelism too. Now we are highly performant and ready for battle.
What sift actually is #
One executable, four dialects #
sift format [OPTIONS] [FILE...] # print the formatted file sift lint [OPTIONS] [FILE...] # report findings sift check [OPTIONS] [FILE...] # print the patch, exit 1 if any sift fix [OPTIONS] [FILE...] # lint --fix sift ci [OPTIONS] [FILE-OR-DIR...] # format check + lint, never writes sift lsp # a language server on stdin/stdout sift doctor # what ran, what it read, what it decided sift list-checkers [--dialect D] # the catalogue as a table sift explain RULE # one rule's reasoning sift config show|explain|trust ... # the settings, and which layer won sift install-hooks [--force] # a pre-commit hook that runs `ci'
Status 0 is clean, 1 is findings, 2 is a usage error or a file that can’t be read.
The dialect is explicit (--dialect), then the extension, then the shebang, then a marker in the first 200 lines: #lang is Racket, defpackage is Common Lisp, define-module is Scheme, lexical-binding is Emacs Lisp. If none answers, it says so. It never guesses. An editor that already resolved the language is better informed, so the LSP takes the identifier the client sends.
A first session is small:
$ cat square.scm (define (square x) (* x x)) $ sift check square.scm --- square.scm +++ square.scm @@ -1,2 +1,2 @@ (define (square x) -(* x x)) + (* x x)) $ echo $? 1
check prints the patch and exits 1. It never modifies your files. To make the change, sift format --write square.scm. The next sift check exits 0.
When the environment and the tool disagree, ask the tool:
$ sift doctor sift 1.41.2 guile 3.0.11 library /home/joe/Hacking/sift/src rules 95 dialects scheme, racket, elisp, cl Compilers scheme available elisp available cl not found Configuration project /home/joe/project/sift.yaml Settings that are not the default brackets: square # /home/joe/project/sift.yaml severity: warning # /home/joe/project/sift.yaml
The reader and the formatter #
The reader’s job is to keep what it read. Every node carries its source location. Comments, blank lines, datum comments and reader prefixes are nodes, not trivia. That’s what lets the formatter preserve them, and what lets a diagnostic point at the exact line and column.
A file with one broken form still gets a tree, because a linter that reports nothing about a file it couldn’t parse fails exactly when it’s needed. A buffer being typed is a buffer with a broken tail, and the language server still reports everything before the break.
The reader knows each dialect’s read syntax rather than a compromise: #\a is a character in Scheme, Racket and Common Lisp; ?a in Emacs Lisp; #:key is an uninterned symbol, :key a keyword; #| ... |# nests; #; comments out the next datum; #lang opens a Racket module; #{ ... }# is a Guile symbol. A square bracket is a vector in Emacs Lisp and a clause delimiter in Scheme. sift doesn’t average the two.
The formatter performs six operations and no others: normalise line endings, normalise spacing, place closing delimiters, compute indentation, optionally align inline comments, and preserve blank lines up to the style’s limits. Everything else is reproduced as written: line breaks, strings, escapes, comments. The function is deterministic and idempotent, and the suite formats every fixture twice.
There are two styles. community trails the closing delimiters:
(define (classify n) (cond [(< n 0) 'negative] [(= n 0) 'zero] [else 'positive]))
dangling puts each closer on its own line for projects that write that way.
Indentation is three rules. A form whose first element is a symbol is looked up in the dialect’s table; a data list or vector aligns under its first element; anything else lines its arguments up under the first argument. With only the operator on its line, the rest goes one column in from the opener. That’s the whole algorithm. The tables exist for the forms where structure alone isn’t enough.
Scheme writes cond clauses with square brackets, as Guile and Guix do:
(cond [(< n 0) 'negative]
[(= n 0) 'zero]
[else 'positive])
It’s a setting: --brackets=parens writes parentheses, --brackets=preserve leaves them as written, and Emacs Lisp and Common Lisp keep what they were given. The clause-brackets rule (SIFT036) reports a file that hasn’t been formatted yet, and its fix swaps the two characters.
The formatter refuses to reflow a long line (the line-length rule warns instead), invent a missing parenthesis, rewrite an expression, or format inside a #; datum comment, a #. form or a #<...> object. sift fix doesn’t reformat, because a fix that moved whitespace would touch every line of the patch it was meant to make readable.
The linter #
A rule is a record: name, code, description, dialects, default severity, procedure and example. The driver reads the file once, runs the rules the dialect applies to, folds in what the reader reported, honours suppression comments, and sorts the findings by file, line, column and rule. There are 95 rules, each with a stable code (SIFT001 through SIFT095), assigned by hand and never reused. sift explain RULE reads the reasoning out of the program, and doc/rules.org is generated from the records.
The catalogue, condensed:
| Where | What it checks |
|---|---|
| all four | whitespace, line length, delimiters, empty bodies, progn, blank lines, comment levels, single-letter names, the if / when / unless family, keyword arguments, complexity |
| Scheme and Racket | internal defines, letrec, quasiquote, clause brackets, docstrings, eta and beta reduction, let simplification |
| Emacs Lisp | docstrings, lexical-binding, interactive, provide, declare, require-cl, save-excursion-set-buffer |
| Common Lisp | package prefixes, double colons, dangling parentheses, LOOP style, identity, ecase-otherwise, mixed-lambda-list |
| Guix | gexps, #$output, with-imported-modules, phase names, sha256, package synopses, inputs |
| SXML | attribute lists, children, empty elements |
The catalogue is data:
$ sift list-checkers --dialect=elisp NAME CODE DIALECTS SEVERITY DESCRIPTION beta-reduction SIFT046 scheme,elisp,cl info A lambda applied in place, where a `let` would say it once docstring-arguments SIFT034 elisp info A docstring that does not mention one of its arguments ...
One rule, read on its own:
$ sift explain if-without-else CODE SIFT012 NAME if-without-else DESCRIPTION `if` with no else branch, where `when` expresses the intent DIALECTS scheme SEVERITY warning FAILING EXAMPLE (if (ready?) (go)) EXPECTED FIX (when (ready?) (go))
A diagnostic and a documentation page are the same record. I love that.
A rule may carry a fix: one range. sift lint --fix applies fixes from the highest offset down, then lints once to show what’s left. There’s no loop. After applying them all, sift reads the result again; if a fix introduced a parse error the file didn’t have, every fix of that run is discarded and the original findings are reported. A file the reader couldn’t finish is refused, because a fix around a missing parenthesis would be a guess. --force is how a caller who knows better says otherwise.
Some rules deliberately have no fix. unmatched-parens won’t guess where a ) belongs. wrap-in-let won’t invent a binding name. The naming rules won’t rename anything. blank-line-in-body won’t delete a line. Deciding how to split or name code is your work.
Suppression is a comment, not a config list:
;; sift:disable-next-line keyword-arguments (make-window a b c d e f g) ;; sift:disable wrap-in-let (define (f x) ...) ;; sift:enable wrap-in-let
disable-next-line covers the next line, disable covers to the end of the top-level form, and enable ends it. An exception list in a config file is a list no review reaches. This one is in the diff.
Fixing isn’t filtered by severity. severity: warning says what fails a build, not what’s worth repairing on request.
The command line and configuration #
format prints, --write writes, check answers with a patch and a status, lint reports, lint --fix fixes, and ci asks both questions without touching the tree. A job that edits the tree it’s judging is a job whose verdict means nothing. ci never writes and never fixes.
The same findings come out as the compile-style line file:line:column: severity: [rule] sentence, JSON, SARIF, GitHub annotations, or null.
--watch re-runs when a file the run read changes. It watches what the run read, not what it was given, so a file created three directories down is noticed. A project run distributes files over the processors and prints in file order. SIFT_JOBS is the only setting.
Settings are sift.yaml, or a sift.scm the project has trusted. They’re layered: defaults, system, user, project, command line. Discovery stops at the repository root. YAML is data and can’t execute anything; Scheme is code and must be trusted explicitly, with --config, SIFT_TRUST_CONFIG=1, or sift config trust sift.scm. An unknown key is refused with a position, and sift config show --verbose names the layer that won.
line-length: 90 brackets: square severity: warning checkers: [trailing-whitespace, docstring-missing] stdlib: true
The language server reads the same files, so sift.yaml is the single place where editor behaviour is written down: inlay hints, hover, completion, stdlib, downloads, compiler diagnostics, import organization.
The language server #
sift lsp speaks LSP over standard input and output. The findings, fixes and formatting are computed once and delivered as text or as LSP responses, so the editor and the pipeline get the same answer.
It answers diagnostics, quickfixes, fix-all, format-this-definition, extract-to-let, extract-to-procedure, extract-a-lambda, inline-a-call, optimize and sort imports, formatting, hover, definition, references, highlights, document and workspace symbols, completion, inlay hints, rename, signature help, and file rename that keeps a Scheme module or an Emacs Lisp provide in step.
It refuses declaration, type definition, implementation, call and type hierarchy, semantic tokens, code lenses, folding ranges, range formatting, format-on-type, pull diagnostics and workspace folder changes. sift models no types, expands no macro, and has no opinion about what to fold. “Method not found” is more useful than a plausible lie.
The project is read in a thread from initialize on. A jump sees the last published snapshot: two thousand files arrive in batches of sixty-four, so the first answer comes after the first batch, and each later batch replaces the snapshot whole. A jump has 100 ms, a reference search 200 ms, and sift/indexStatus says how far the reading has got.
The standard library is indexed from source (Guile’s modules, Emacs’s load-path and package trees, ASDF and SBCL sources, Racket’s collects and pkgs) and from what each implementation says about itself. car is compiled into libguile and no file says where, so the implementation is asked once to write down every name it documents, as source. A jump to car lands in code that reads like the file it’s in. A source archive named in stdlib can be downloaded when the project allows it.
Watching a jump land in Guile’s own source, or in a file an implementation wrote about itself, still feels a little illegal. That’s the LSP work I’m proudest of.
The server can ask the dialect’s compiler for a second opinion on open or save: guild, emacs, sbcl, whichever is installed. A missing compiler is simply not asked, and compiler-diagnostics: false turns it off.
The REPL and the linter #
This is the setup that made me fall in love with editing Scheme.
My Emacs configuration (heks-emacs) puts a Geiser REPL (the interactive prompt that evaluates expressions and shows their values) in the middle of Scheme development. C-c g r starts or switches to the project’s REPL: a guix repl in a package buffer, a plain guile one elsewhere, one per project, with the project root on the load path. C-c g e evaluates the definition at point, C-c g E the region or buffer, C-c g b loads the file, C-c g k interrupts, C-c g x runs the file as a script, C-c g s points the REPL at the module, and C-c g d opens the debugger. Completion and autodoc are Geiser’s.
The two files that arrange it are modules/sift.el and modules/guile.el. The keys below are my config’s, not the package’s defaults: the package uses C-c s, which is the snippets topic here, so sift gets the letters the scheme already promises.
sift runs in the same buffer, at the same time, without asking the REPL for anything:
sift-flymakerunssift lint --stdin --format=jsonon the buffer’s own text, saved or not, and turns findings into Flymake diagnostics with the rule’s code and name. Nothing is written.- The drift backend marks lines
sift formatwould rewrite. That’s whatsift check, and a pipeline runningsift ci, fails over. The formatter runs on a copy; the buffer is untouched. C-c g Hexplains the rule at point.C-c g aapplies its fix.C-c g Aapplies every fix.C-c g fformats the buffer.C-c i fis the historical format key.M-x sift-lintruns the linter in a compilation buffer.- Formatting and fixing use
sift format --stdinandsift lint --fix --stdin, so neither saves the file and both are oneundoaway.
Why is this so nice? Because the REPL and the linter answer different questions.
The REPL answers: what does this program do when I run it? It has the loaded state, the values, the stack, the debugger, the generic methods. It knows the definition you just evaluated.
sift answers: what does this file say, and what would a pipeline say about it? It sees the source, the project, the standard library and the rules. It can tell you that a cond clause after else can never run, that an import is unused, that a docstring doesn’t name its arguments, that a line isn’t formatted the way sift ci will require.
A REPL can’t tell you your file is unformatted, and a formatter can’t tell you what an expression returned. My config makes them cooperate:
- sift is asked first, because it needs nothing but itself.
guild compileandguix lintare the second opinion on save. Geiser is the third, for what only a running image knows. - Navigation asks sift’s LSP first and falls back to Geiser where it has nothing. sift knows the files and the standard library; Geiser knows what the REPL loaded.
M-.is one key over both. - When Eglot manages the buffer, sift’s Flymake backend stands aside because the server publishes the same findings. Format-on-save stands down too, so two formatters don’t write one buffer on one save.
- Formatting doesn’t change semantics, so it’s safe to re-evaluate. The formatter never renames a binding or rewrites an expression.
The loop I do a hundred times a day:
C-c g rstarts the project’s REPL.- I write a one-armed
if. sift reportsSIFT012/if-without-elseon the line, while the buffer is dirty. C-c g Hopens the rule and shows(when (ready?) (go)).C-c g aapplies the fix. One undo, no save.C-c g eevaluates the definition in the REPL, and I see the result.- I notice a
condwritten with parentheses.C-c g aswaps in brackets.C-c g fformats.C-c g breloads, and the REPL has the new definition. - Before I commit,
M-x sift-ciruns the whole-project check. Same program, same answer.
None of that needs a save or a build. The REPL keeps the live state, sift keeps the file honest, and I get both answers in the same buffer. It’s the nicest editing loop I’ve had.
Editors, CI and the browser #
The clients are thin wrappers over the program:
| Editor | What to use |
|---|---|
| Emacs | emacs/sift.el: Flymake and Eglot |
| Neovim | editors/vim/neovim.lua: a vim.lsp.start setup |
| Vim | editors/vim/: :SiftLint, :SiftFormat, :SiftFix, :SiftExplain |
| VS Code | editors/vscode/: no build step, no dependencies |
| Helix | format on save through sift format --stdin |
| the browser | web/: sift compiled to WebAssembly |
In a pipeline, one command asks both questions:
sift ci src/ tests/
It exits 1 if either check finds something, 2 if a file can’t be read or parsed. It never writes.
There’s a reusable GitHub workflow:
name: sift
on: [push, pull_request]
jobs:
sift:
uses: jjba23/sift/.github/workflows/sift.yml@v1.40.5
It annotates the diff and uploads SARIF to code scanning, so an unfixed finding becomes an alert instead of a line in a log. There’s also a composite action, a pre-commit hook, a pre-commit declaration, a dprint process plugin, and a Docker image.
The browser build is the part that sounds like a stunt. It isn’t. web/ is formatting and linting compiled to WebAssembly with Guile Hoot, with an editor page around it. The same reader, formatter and 95 rules are in the tab; the two rules that need a project report nothing. No input leaves the tab.
The whole contract is one procedure of one string to one string:
(web-request "{\"op\":\"lint\",\"source\":\"(if a b)\"}") ;; => "{\"ok\":true,\"result\":{\"warnings\":[…],\"counts\":{…}}}"
The module is 3.4 MB. A screenful formats in 17 ms and lints in 56 ms; 1.2 kB is 52 ms and 145 ms; 6 kB is 780 ms and 1.2 s. The first two rows never reach the 300 ms debounce. Past two kilobytes it’s perceptible, and a checkers list lets a page ask for less work.
The part I love isn’t the number. It’s that the source of truth stayed put. The tab runs the same modules bin/sift runs. Four Guile libraries have stand-ins in web/compat, and SRFI-13 is thirteen procedures with a test that compares the browser’s answers to Guile’s byte for byte. Eight tests hold the dependency one way, so the core doesn’t know a tab exists.
The page is live at https://jointhefreeworld.org/sift/: an editor with the dialect, style and severity as controls, findings linked to the source, an outline, completion, inlay hints and a rules browser. It’s a formatter, a linter and 95 rules in a tab, running the same Scheme as your terminal. I still think that’s wild.
What a run costs #
The suite has teeth, and the benchmark has numbers. On my machine:
lint the tree (28 files, 14896 lines) 337ms, 160.7 MiB allocated check the tree (28 files): format 253ms, 59.0 MiB allocated lint (lsp.scm, every checker) 171ms, 19.2 MiB allocated read the tree (28 files) 143ms, 44.7 MiB allocated
Both numbers matter. A pass that conses per node makes every other pass slower, and the allocation count shows it even when the clock looks good.
The Veritas suite I ran while writing this: 119 suites, 1,160 tests, 2,624 assertions, about a minute. The reader is tested dialect by dialect; the formatter on a golden corpus plus an idempotence pass; each rule with a passing case, a failing case at a known line and column, a case per dialect, and a re-lint after its fix; the CLI as a subprocess; the language server over the wire. The browser build runs in Hoot’s virtual machine. The project formats itself, so maak self-check is a real gate.
The rules and the opinions #
The style #
The style is the common practice of the four communities, written down in doc/style.org. The sources are Riastradh’s Lisp Style Rules, Google’s Common Lisp style guide, the Emacs Lisp manual’s docstring tips, R7RS, and the conventions of Guile and Guix.
The ten choices, in one line each:
- Two columns for every body. It’s the smallest visible step, and it’s what every Lisp of the last thirty years does.
- Arguments align under the first. A data list or vector does the same.
- One blank line between top-level forms. sift never inserts one where there was none.
- Closing delimiters trail.
danglingis there for projects that decided otherwise. - Square brackets for Scheme clauses. A
condclause is a test and a body; the bracket marks the boundary. It’s a setting, not a law. - Keywords line up. They become a column instead of a ragged tail.
- Macro indentation is the project’s rule. No formatter knows what your macro means.
- No reflowing. A line break records where you judged the form to end.
- Reader prefixes glue to their datum. A newline between
'and its datum is a different program. - Comments stay on their line. A comment’s position is part of its meaning.
sift declines some Riastradh rules: a 72 or 80 column limit (the default is 96, or 80 for Emacs Lisp), pages and form feeds (they rewrite every line number below the break), 21-line top-level forms (that’s your judgement), and with- versus call-with- prefixes (that needs to know whether an argument is called).
What it refuses #
The opinions show up in what sift won’t do:
- You own the program; the tool owns the layout. It doesn’t rename, reorder or inline a procedure on its own, and it doesn’t introduce a delimiter.
- A dialect is a language. Never guess.
- A fix that can’t be verified is discarded. Not guessed at, not applied with a warning.
- Lint reports, fix is opt-in, and CI never writes.
- Suppression belongs next to the code.
- Codes never move. A name is the token you type; a code is what an editor and a bug report quote.
- Rules are data first. The catalogue, diagnostics, code actions and browser list are renderings of the same records.
- Configuration is data; code is a decision. YAML can’t execute anything. Scheme can, and must be trusted.
- Few knobs. A formatter with a hundred options has no opinion.
- Refuse what you can’t answer. “Method not found” beats a plausible lie.
- No second implementation. The browser is a compile of the same modules; the editors are thin wrappers.
- MIT. A formatter in other people’s pipelines can’t carry a licensing question.
sift doesn’t expand macros, type-check or know your conventions. It reports; you decide. Where it can be wrong, the rule says so: wrap-in-let is a suggestion, keyword-arguments counts, thresholds are settings. The LSP has two limits: references are matched by name within one dialect, and the project is read in the background, so a jump answers from what’s been read. Range formatting, format-on-type, fold ranges, macro-introduced names, pull diagnostics and a --since REV mode are in scope and not built yet. A limit that’s written down is a limit a contributor can remove.
Where sift fits #
Compared to the neighbours #
| Project | What it is | Where sift differs |
|---|---|---|
| cljfmt | A Clojure formatter | Clojure only, and it reformats from a parsed form; sift asserts its fixed point over a corpus and lints too |
| clj-kondo | A Clojure linter with a checkable macro config and an LSP | Lints only, no formatter; its analysis is Clojure’s |
| rustfmt, gofmt | Canonical formatters for Rust and Go | One language, one style, no linting; their authority is canonical, sift writes the style down |
| clang-format | A configurable C-family formatter | Configuration is its product; sift has few settings and refuses to reflow |
| Prettier | An opinionated multi-language formatter | Closest philosophy, but it reflows and doesn’t preserve every comment and blank line |
| Emacs’s toolchain | indent.el, checkdoc, the byte-compiler, Flymake |
No CLI, CI shape, JSON, SARIF or LSP |
scheme-mode and guild compile -W3 |
Editor indentation and compiler warnings | Nothing between them, and nothing a pipeline can read as one report |
| SLIME, SLY | Common Lisp environments | Indentation specs and xref, but an environment, not a program; answers need a running image |
The neighbours do three things I want to steal: a checkable macro configuration (clj-kondo), answers from real analysis (SLIME, SLY), and the authority of a canonical tool (rustfmt, gofmt). None carries a browser build of the same code, and none treats four dialects in one executable as the premise.
The gap #
Lisp has plenty of tools. The problem is where they stop.
- Scheme has
scheme-mode,guild compile -W3andguix style. None is a general formatter, a project linter or an LSP;guix styleis deliberately about Guix, not Scheme. - Emacs Lisp has
checkdoc, the byte-compiler and Flymake. They know the conventions, but a compiler warning is prose: no stable code, JSON, SARIF, CLI, LSP or fix. - Common Lisp has SLIME and SLY. They’re an environment, not a program a pipeline runs.
- Racket has its own tools, but they’re Racket’s, and a repo with Scheme and Emacs Lisp still needs the others.
- Clojure is the exception: cljfmt and clj-kondo are excellent, and Clojure-only.
sift fills that with one executable, one config and one CI step for four dialects. It also fills the gap inside Guix and Guile: guix style knows package forms; sift knows general Scheme, and it has rules for assoc-ref %outputs, a #$output that makes a file, a use-modules inside a gexp that with-imported-modules doesn’t mark, an unquoted phase name, a sha256 that isn’t (base32 "..."), a synopsis that opens with an article, and inputs written as a labelled alist. Those are the habits of a community, written down as rules with codes and fixes.
Why is it actually useful? It runs where the code runs: CLI, hook, GitHub Action, container, editor, browser tab. It gives the same answer everywhere. It’s adoptable: ci never writes, fix is opt-in, severity is a project decision, suppression is local. It’s fast enough for save (337 ms to lint 28 files, 171 ms for one file with every checker). It’s small: Guile and the standard library, no C, no build step. And it’s MIT.
The best proof is that the project uses itself: maak self-check, maak fixture-check and sift ci are the gates.
Under the hood #
src/sift/ is one module per job. The important ones:
records.scm locations, findings, rule records, codes, AST nodes reader.scm the permissive, location-preserving reader format.scm the pipeline, indentation tables, renderer check/base.scm walking a tree, reading a form, line arithmetic checkers/ one module per family of rules lint.scm run, suppress, filter, sort, fix, re-lint render.scm human, JSON, GitHub, null, SARIF config.scm discovery, merging, provenance, trust analysis.scm the LSP questions that are a function of a buffer lsp.scm diagnostics, actions, formatting, hover, navigation cli.scm args-fold, dispatch, exit codes
records is the vocabulary; reader and format use it; the checkers use records and check/base; lint assembles them; render prints; lsp speaks the protocol; cli wires it up. Nothing in format or a checker knows about ports or exit codes.
The implementation is Guile 3.0 and the standard library. No C dependency, no build step. The launcher is a small POSIX shell script that finds its own symlink chain, puts src/ on the load path, and hands the arguments to (sift cli). The whole program reduces to a use-modules and a sift-main call if you don’t want the launcher.
Install with guix install sift from the guix-jointhefreeworld channel, nix run from the Nix flake, Homebrew from the tap, a container image, or a checkout and ./bin/sift version. The Emacs package is one file with no dependencies beyond Emacs 28.1.
Come help #
The list of Lisp dialects that deserve a better reader is long, and each item is a contribution that can be carried to the end.
- A bug report. Give the input, the output you expected, and
sift versionwith the first section ofsift doctor. A file sift refuses to parse is a bug even when the file is broken; the message must say where. - A rule. One record and one test file. The catalogue, docs and editor integrations follow. The contributing guide has the five steps.
- A dialect detail. An escape, a comment in an odd place, a body that indents by something other than two.
tests/reader-*.scmandtests/format-*.scmhold the behaviour. - An editor integration. Neovim, Vim and VS Code each have a directory and a test in that editor’s tool. A fourth editor is one directory more.
- A sentence in the docs. The README, the style page and the rule descriptions are read by people deciding whether to trust the tool. A sentence that causes hesitation is a defect.
- A bigger piece. The roadmap below has the ones I want most; pick one and open an issue.
A first patch: read doc/style.org, run maak test before changing anything, add the rule or fix with its test under tests/checkers/, then run maak self-check, maak check and maak fixture-check. Send a pull request, or a patch with git format-patch and git send-email. maak test-suite runs the one suite whose file is open in a second.
The AI policy is short: agents may explore, plan, branch, run the build and tests, commit, push, open and merge pull requests, and cut releases. A human is the author of record and must be able to explain and debug every line. TDD is required: failing test, watch it fail, least code, refactor, full suite. Disclose the tool and what it did. A bug report or rule written with an agent is as welcome as one without; the review concerns the code.
Questions are as welcome as issues. If the README doesn’t answer it, that’s a bug in the README.
Where we are going from here #
sift is useful now, but it isn’t finished. The long version is in VISION.md; here’s the short one, roughly in the order I think it can land.
- Range formatting and format-on-type. The formatter indents from column zero, so a fragment lands at the margin. The hard part is an origin column that still produces, for the range it touched, the bytes a whole-buffer run would. It’s the missing piece for editor parity.
- A
--since REVmode. Lint the lines a diff touched, not the whole tree. That’s what lets a large codebase adopt a linter without a mass reformat, and it’s the feature I want most for CI. - Resolution across files. Follow
define-module,#:use-module,defpackageandprovidefar enough that a reference is a binding, not a name. Then a project-wide rename is correct in every file, and a jump lands on the definition rather than a same-named symbol. Project-scale operations stay reviewable too: a rename, a fix-all or a formatting sweep should produce one patch whose hunks are the change. - A declared-macro table. A project declares what its macros bind, so references and rename can see the names a macro introduces. It’s the largest correctness win left, and it needs an argument before a patch.
- The style as a specification. The rules and the corpus are already there. The next step is a document a second implementation can be checked against. If the style is the artefact, the implementation can be replaced, and the conventions outlive it.
- A fifth dialect. Racket was the fourth and cost a table, a dozen rules re-argued and a corpus of its own. Each one after that is more evidence that the reader, formatter and rule records are the general part and the dialect is the detail.
Smaller things on the list: pull diagnostics, fold ranges, and a sift new-rule command that writes the record and the test. None of this is a promise with a date. It’s the direction. If one of them sounds like your afternoon, open an issue and I’ll help you land it.
Closing #
The first attempt taught me that a Lisp file is a tree and its indentation is structural. The second taught me that a community can agree on a style and a program can enforce it. The third taught me that the language’s own reader and compiler know more than any regex. The detours taught me the rest: never reflow, let one representation win, put the conventions in a program, make the pipeline shape real, ship one executable.
What none of them had was the premise: read the file as a datum with positions, and print it back. Once that was true, formatting became a fixed point, a fix became a range, a finding became data, the editor and the pipeline received the same answer, the browser became a compile instead of a rewrite, and the rules became records instead of prose.
The seeds weren’t wasted. They were the reader, the style and the rules, waiting for the thing that would hold them together. The name is the bet: a source file mixes the program with the layout. sift separates them, checks the program, and puts the layout back. It’s a sieve, not a sculptor.
If you have a Lisp dialect that deserves a better reader, a rule your project keeps repeating in review, an editor that should have the server, or a sentence that would have saved you five minutes, that’s a contribution. The seeds are already there. Come and plant one.