A few years ago Nikita Tonsky made popular a certain style of formating Clojure code, that became known as “fixed” or “tonsky” indentation in the community.

clojure-mode has long had some support for this via clojure-indent-style:

(setq clojure-indent-style 'always-indent)

However, it was kind of hard to get exactly the same indentation from Nikita’s article, as there was no way to suppress the usage of indent specs and forms starting with a keyword were indented by separate rules from what was set by clojure-indent-style. A recent upstream change made the indentation configuration more granular and now you can get fixed indentation with the following snippet:

(setq clojure-indent-style 'always-indent
      clojure-indent-keyword-style 'always-indent
      clojure-enable-indent-specs nil)

clojure-indent-keyword-style and clojure-enable-indent-specs are the new additions, that made this possible. Here’s how clojure-indent-keyword-style can be used:

  • always-align (default) - All args are vertically aligned with the first arg in case (A), and vertically aligned with the function name in case (B).

     (:require [foo.bar]
               [bar.baz])
     (:require
      [foo.bar]
      [bar.baz])
    
  • always-indent - All args are indented like a macro body.

      (:require [foo.bar]
         [bar.baz])
      (:x
         location
         0)
    
  • align-arguments - Case (A) is indented like always-align, and case (B) is indented like a macro body.

      (:require [foo.bar]
                [bar.baz])
      (:x
         location
         0)
    

By the way, clojure-ts-mode also supports the fixed indentation style:

(setq clojure-ts-indent-style 'fixed)

The configuration here is a lot simpler, as this functionality existed since day 1.

For the record, I still don’t endorse/like fixed indentation1 (and funny enough - neither does Arne, who implemented those changes). Still, I acknowledge that this style is somewhat popular in the Clojure community and I’m all for making it easier for people who like/need it to be able to use it.

That’s all I have for you today. Keep hacking!