clojure-mode icon indicating copy to clipboard operation
clojure-mode copied to clipboard

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

Open danieroux opened this issue 6 years ago • 8 comments

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

danieroux avatar May 19 '19 21:05 danieroux

Looking at the code it seems to me that @Malabarba did so intentionally, but he'll have to tell us more about his reasoning.

bbatsov avatar Jul 09 '19 14:07 bbatsov

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-align is for indenting macros with indent-specs.
    • I think this one can be overriden most easily by redefining the clojure--find-indent-spec function to always return nil. A configuration variable to disable this function could also be inserted here.
  • The second hardcoded always-align is for the keyword args of ns forms. (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.

Malabarba avatar Jul 13 '19 23:07 Malabarba

Any updates?

darkleaf avatar Sep 18 '19 16:09 darkleaf

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.

vemv avatar Aug 09 '21 21:08 vemv

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 😃

expez avatar Aug 09 '21 22:08 expez

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, default t, set this to nil to ignore indent specs
  • clojure-indent-keyword-style, like clojure-indent-style, but for list forms starting with a keyword, the case which is currently hard-coded. default: always-align, set to always-indent to get tonsky-style.

plexus avatar Jan 03 '22 16:01 plexus

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.

vemv avatar Jan 03 '22 16:01 vemv

No, I do not find that a satisfactory solution. For one it will lead to a fight between the indenter and aggressive-indent-mode.

plexus avatar Jan 03 '22 16:01 plexus