Parindent
August 5, 2024 ยท View on GitHub
Parindent is just an idea for this discussion on standard clojure indentation, fork it if you believe it warrants further experimenting.
Parindent
Indent Clojure files based on the following discussions:
Current Rules
- ALLOW - 1-space, 2-space, or Arg-alignment (user preference determined by first sibling line)
- ENFORCE - vertically aligned sibling lines
- ENFORCE - indentation after a paren should imply containment
Friction
Staggered indentation of siblings not allowed:
(cond
foo
- bar
+ bar
baz
- qux)
+ qux)
Cannot indent past an open-paren unless contained inside it (Parinfer):
(defn foo
([a b]
- (+ a b))
+ (+ a b))
([a b c]
- (+ a b c)))
+ (+ a b c)))
Install
npm install -g parindent
Try it
To indent all your files in place, run from your project root:
parindent '**/*.{clj,cljs,cljc}' --write
Usage
$ parindent
Usage: parindent [opts] [filename ...]
A minimal indenter for Lisp code (e.g. Clojure)
Available options:
--write Edit the file in-place. (Beware!)
--list-different or -l Print filenames of files that are different from Parindent formatting.
--stdin Read input from stdin.
--version or -v Print Parindent version.