Fast cljfmt


Update 2023-01-29: I’ve since learned that clojure-lsp also includes a GraalVM-built cljfmt.

I wanted a Clojure code formatter that:

  1. follows the community Clojure style guide and isn’t as agressive as zprint, so weavejester/cljfmt
  2. runs fast enough (<50ms) to use as an editor filter, invoked on save
  3. is up to date - node-cljfmt and several GraalVM packagings of cljfmt are no longer maintained
  4. uses the stdio interface as expected by editor tools like format-all

cljfmt and its GraalVM native-image packaging don’t have #4. So, I made a thing.


To use cljfmt-graalvm, you’ll need:

  1. GraalVM installed locally with GRAALVM_HOME env var set
  2. run script/comile
  3. copy the binary at target/cljfmt to someplace on your path

Full Usage instructions here.


If you are using doom emacs, enable format-all in ~/.doom.d/init.el

(doom! :input
       ;; ...
       (format +onsave)  ; automated prettiness

… and add this to your ~/.doom.d/config.el.

(set-formatter! 'cljfmt "cljfmt stdio")

As of 2023-01-28, Doom emacs has its format module pinned to format-all 0.5.0. If you are using a later version of format-all, use zprint or set zprint.

(set-formatter! 'zprint "cljfmt stdio")

Related tags:

site menu

Back to top