clojure-mode
clojure-mode copied to clipboard
Enabling https://tonsky.me/blog/clojurefmt easily
Because of two hard-coded always-align calls in clojure-indent-function it is not as simple as (setq clojure-indent-style 'always-indent) to get the desired effect. As undesirable as that effect may be for some ;-)
It would be useful to have just one setting for this.
I worked around it by overriding lisp-indent-function this way: https://github.com/danieroux/emacs/commit/09403e601a1d0d0e33fe0d2c3238e77bef1c53b6
Changing these two always-align to always-indent also gets the desired/undesired formatting: https://github.com/clojure-emacs/clojure-mode/blob/a9cbe6a37f51da1c37035390d43500b437e8bff2/clojure-mode.el#L1499 and https://github.com/clojure-emacs/clojure-mode/blob/a9cbe6a37f51da1c37035390d43500b437e8bff2/clojure-mode.el#L1513
Looking at the code it seems to me that @Malabarba did so intentionally, but he'll have to tell us more about his reasoning.
Yes, it's intentional.
The reasoning is that the clojure-indent-style variable is designed to configure the indentation of function forms or macro froms without special configuration.
- The first hardcoded
always-alignis for indenting macros with indent-specs.- I think this one can be overriden most easily by redefining the
clojure--find-indent-specfunction to always returnnil. A configuration variable to disable this function could also be inserted here.
- I think this one can be overriden most easily by redefining the
- The second hardcoded
always-alignis for the keyword args ofnsforms. (Notably, I think it also affects regular keyword calls, which can be considered a bug).- If you'd like to make this part configurable, you can insert an extra clause inside the
and.
- If you'd like to make this part configurable, you can insert an extra clause inside the
Any updates?
I wonder if it's this a thing that's really worth having/fostering. Isn't the formatting situation already fairly messy? Different formatters/editors, each with its own idiosyncracies.
I wonder if it's this a thing that's really worth having/fostering. Isn't the formatting situation already fairly messy? Different formatters/editors, each with its own idiosyncracies.

Let a thousand flowers bloom 😃
I'm preparing a patch for this since I just started on a project where they use tonsky style formatting. I'm not a fan, I think the whole thing is misguided, but I'm in no position to argue about this on this project, and it's something that should at least be possible without monkey patching.
Proposing two new defcustoms:
clojure-enable-indent-spec, defaultt, set this tonilto ignore indent specsclojure-indent-keyword-style, likeclojure-indent-style, but for list forms starting with a keyword, the case which is currently hard-coded. default:always-align, set toalways-indentto get tonsky-style.
That seems a legitimate need, OTOH even from legitimate instance can have an effect that is greater than originally intended, i.e. we get a messier / more fragmented landscape.
Would you find it an ok intermediate solution to make it particularly easy to plug in a format-on-save external command? It could be cljfmt, cljstyle, or so on.
The point being that we don't really complicate clojure-mode or condone a formatting that isn't quite widespread.
Perhaps with JVM native images format-on-save is snappy enough that it isn't a nuisance.
No, I do not find that a satisfactory solution. For one it will lead to a fight between the indenter and aggressive-indent-mode.