Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to get uniform indentation #607

Merged
merged 1 commit into from
Feb 13, 2024
Merged

Conversation

plexus
Copy link
Contributor

@plexus plexus commented Jan 3, 2022

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 checkdoc and 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!

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)
```
@plexus
Copy link
Contributor Author

plexus commented Jan 3, 2022

Will let this sit here for a bit while I dogfood it.

@bbatsov
Copy link
Member

bbatsov commented Jan 3, 2022

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.

@kommen
Copy link
Contributor

kommen commented Feb 11, 2024

FWIW, clojure-ts-mode implements it and calls it just fixed https://github.com/clojure-emacs/clojure-ts-mode?tab=readme-ov-file#indentation

@bbatsov
Copy link
Member

bbatsov commented Feb 12, 2024

@plexus Should we merge the PR? I guess by now you had enough time to test it.

@plexus
Copy link
Contributor Author

plexus commented Feb 12, 2024

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?

@vemv
Copy link
Member

vemv commented Feb 12, 2024

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?

@bbatsov
Copy link
Member

bbatsov commented Feb 12, 2024

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 - e3ef390) 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.

@bbatsov bbatsov merged commit e201ed6 into master Feb 13, 2024
@bbatsov bbatsov deleted the arne/tonsky-support branch February 13, 2024 09:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enabling https://tonsky.me/blog/clojurefmt easily
4 participants