clfmt is a tool that lightly refactors your Common Lisp code.
It mainly aims to reduce extraneous whitespace and newlines, and avoids “being a
hero”, leaving parenthesis management and sexp alignment to the editor.
Staying simple keeps clfmt performant and nimble, compiling to a small executable.
clfmt requires ECL to build.
ecl --load build.lisp
clfmt is available on the AUR and can be installed with tools like Aura:
aura -A clfmt
In general, it should be enough to add:
(add-to-list 'apheleia-formatters '(clfmt . ("clfmt")))
(add-to-list 'apheleia-mode-alist '(lisp-mode . (lisp-indent clfmt)))Provided that apheleia has already been loaded and those lists exist.
Due to how set-formatter! is used by Doom internally, we must:
(after! sly
(after! apheleia
(assq-delete-all 'lisp-mode apheleia-mode-alist)
(add-to-list 'apheleia-mode-alist '(lisp-mode . (lisp-indent clfmt)))))
(after! apheleia-formatters
(add-to-list 'apheleia-formatters '(clfmt . ("clfmt"))))Then, upon saving a Common Lisp buffer, you will get both automatic alignment and whitespace clearing.
Just pass clfmt a file:
clfmt foo.lisp
And its reformatted form will print to STDOUT.
Some editor integrations want to feed input via STDIN. That’s equivalent to:
cat foo.lisp | clfmt
The -i flag will directly overwrite a given file:
clfmt -i foo.lisp
You can reformat all files in a directory too:
clfmt -i src/