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

Provide ability to customise cljfmt code formatting #2907

Closed
BrunoBonacci opened this issue Oct 10, 2020 · 5 comments
Closed

Provide ability to customise cljfmt code formatting #2907

BrunoBonacci opened this issue Oct 10, 2020 · 5 comments
Labels
feature request good first issue A simple tasks suitable for first-time contributors

Comments

@BrunoBonacci
Copy link

Describe the solution you'd like

It should be possible to provide a custom formatting configuration for cider-nrepl/cljfmt.
The cljfmt configuration format is described here:

https://github.com/weavejester/cljfmt#configuration

The desired solution should have a defcustom variable where the configuration can be provided.

Describe alternatives you've considered

A workaround to this solution is to use an after-save-hook as described here:

https://github.com/dzer6/cljfmt-graalvm

However, in this case, the two formatters (cider, external cljfmt) will keep fighting each other causing an awful user experience.

@bbatsov bbatsov added feature request good first issue A simple tasks suitable for first-time contributors labels Oct 10, 2020
@bbatsov
Copy link
Member

bbatsov commented Oct 10, 2020

However, in this case, the two formatters (cider, external cljfmt) will keep fighting each other causing an awful user experience.

How come? Unless you trigger manually cljfmt in CIDER it won't be invoked. Keep in mind that the default indentation engine is actually written in Emacs Lisp.

As mentioned in the chat solving this issue is not particularly complex. Seems we already added the ability to pass configuration to the middleware op responsible for invoking cljfmt, but we never implemented this in the client.

@BrunoBonacci
Copy link
Author

So I guess it is fighting against the (elisp) Indentation engine.
Is there any way I can control/customise the behaviour of that one?

The issue I have is that the indentation works differently depending on whether you are connected to the repl or not.
If you are connected to the REPL and you have evaluated the namespace then things like :style/indent are respected;
while if the repl isn't running or the namespace isn't evaluated the indentation doesn't know about the :style/indent
value, so for obvious reasons, it will indent the forms differently.
If you add things like aggressive-indent-mode then the behaviour is even more bizarre. Forms start jumping left or right based on whether the engine has evaluated that form or not.

I'd like to replace the current behaviour with something that is a bit more deterministic and it works the same whether the repl has evaluated a form or not.

@bbatsov
Copy link
Member

bbatsov commented Oct 10, 2020

You can just disable dynamic (REPL-powered) indentation if you don't rely on it https://docs.cider.mx/cider/0.26/config/indentation.html Alternative you can completely override the indentation logic of clojure-mode and provide whatever implementation you want. CIDER simply hooks into it and adds new indentation rules there dynamically when connected.

@BrunoBonacci
Copy link
Author

Thanks for the link. I'll see if I can achieve what want with the configuration described there.

However, I still think that this ticket stands. Having the possibility to configure the cljfmt indentation rules is a nice-to-have feature.

@bbatsov
Copy link
Member

bbatsov commented Oct 10, 2020

Yeah, I agree.

iarenaza added a commit to iarenaza/cider that referenced this issue Feb 16, 2021
**Describe the solution you'd like**

It should be possible to provide a custom formatting configuration for
cider-nrepl/cljfmt. The cljfmt configuration format is described here:

  https://github.com/weavejester/cljfmt#configuration

The desired solution should have a defcustom variable where the
configuration can be provided.

**Describe alternatives you've considered**

A workaround to this solution is to use an after-save-hook as
described here:

https://github.com/dzer6/cljfmt-graalvm

However, in this case, the two formatters (cider, external cljfmt)
will keep fighting each other causing an awful user experience.

**Additional context**

In clojure-emacs#2907 Bozhidar Batsov
commented:

 > You can just disable dynamic (REPL-powered) indentation if you
 > don't rely on it
 > https://docs.cider.mx/cider/0.26/config/indentation.html
 > Alternative you can completely override the indentation logic of
 > clojure-mode and provide whatever implementation you want. CIDER
 > simply hooks into it and adds new indentation rules there
 > dynamically when connected.

To which Brunno Bonacci responded:

  > However, I still think that this ticket stands. Having the
  > possibility to configure the cljfmt indentation rules is a
  > nice-to-have feature.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request good first issue A simple tasks suitable for first-time contributors
Projects
None yet
Development

No branches or pull requests

2 participants