clojure-mode
clojure-mode copied to clipboard
Make it possible to get uniform indentation
While Emacs and clojure-mode have good support for "lisp-style" indentation, and provided fine-grained customization via indent-specs, some prefer "dumb" indentation where every single form gets the same level of indent, regardless of whether it's a macro, whether there are arguments on the same line as the function name, etc.
Currently this is not possible without redefining certain functions because of
hard-coded values that handle specific cases, namely the indent-spec case, and
the keyword invocation case ((:require ...)).
This introduces two new defcustoms, one allows completely disabling the indent-spec handling, so the first hard-coded case is skipped, the second allows specifically customizing the second case.
This should allow "tonsky style" formatting with
(setq clojure-indent-style 'always-indent
clojure-indent-keyword-style 'always-indent
clojure-enable-indent-specs nil)
Closes #526
Replace this placeholder text with a summary of the changes in your PR.
Before submitting a PR mark the checkboxes for the items you've done (if you think a checkbox does not apply, then leave it unchecked):
- [ ] The commits are consistent with our contribution guidelines.
- [ ] You've added tests (if possible) to cover your change(s). Bugfix, indentation, and font-lock tests are extremely important!
- [ ] You've run
M-x checkdocand fixed any warnings in the code you've written. - [ ] You've updated the changelog (if adding/changing user-visible functionality).
- [ ] You've updated the readme (if adding/changing user-visible functionality).
Thanks!
Will let this sit here for a bit while I dogfood it.
I assume the people who like fixed indentation don't care about this level of granularity, so this can be just a an extra clojure-indent-style named fixed/tonsky/whatever. That's how I planned to implement this in the past, but admittedly I dropped the ball on this.
FWIW, clojure-ts-mode implements it and calls it just fixed https://github.com/clojure-emacs/clojure-ts-mode?tab=readme-ov-file#indentation
@plexus Should we merge the PR? I guess by now you had enough time to test it.
Sure, if folks are happy with it. I don't generally like or use this style of indentation, except that one time a few years ago when a client project was using it. I don't remember much about this PR, but I guess it works?
From memory, the only reason why @dannyfreeman made that style available in clojure-ts-mode is because it was simpler to implement, in the context of bootstrapping a functional solution.
Maybe we can use whatever influence we have to avoid a proliferation of styles. All formatters default to something traditionally emacs-y anyway. And Cursive can be trivially configured to follow the same style.
Tools have only become more handy since the infamous blog post that suggested the idea of a style that really didn't take off but still is requested from time to time. I mean, by now cljfmt can be invoked in many, instantaneous ways (via clojure-lsp, cider, a graalvm binary) - besides from the editor-native formatting that will typically match cljfmt.
What problem are we solving?
That some people like this formatting and don't care about the alternatives? 😉
To be fair some people liked this even before the famous blog post by Nikita - that's why clojure-mode supported something similar almost from day 1. (here's a bit of historical context - https://github.com/clojure-emacs/clojure-mode/commit/e3ef390fab132cac50831caab42654fef41c0da3) The style because popular not because of the blog post, but because in many teams people used different tools and this was the only style that all tools would agree on back then. But I've always considered it inferior to semantic/standard indentation and never used it myself.