Fork me on GitHub
#cursive
<
2022-02-13
>
imre08:02:03

That's good stuff. Will there also be an option to add a linebreaks after :require and :import? Or is there one already?

cfleming21:02:00

There isn’t at the moment, no - currently Cursive never touches linebreaks. I’m planning to revamp all the formatting shortly which will make all that more configurable. What exactly do you want to happen there, just to be clear?

imre06:02:00

my preference is exactly how it's in the summary at https://stuartsierra.com/2016/clojure-how-to-ns.html - one linebreak after :require and :import

imre06:02:24

That also seems to be the direction cider's refactor-nrepl adopted in 3.x: https://github.com/clojure-emacs/refactor-nrepl/blob/master/CHANGELOG.md#310-2021-11-09

imre06:02:35

Having this formatting/organization happen automatically on requiring/importing something would also be good to have

imre06:02:54

However, for me it would be important to be able to turn auto-formatting and adding newlines off for specific projects. Normally when I submit a patch to a 3rd party project, I want to make the least amount of changes. However for our internal ones where I'm (partially) in control of formatting I'll want to clean stuff up as I go.

cfleming09:02:16

Sure, when adding new namespaces and imports, Cursive always adds a newline at the moment. If you have two in the same line though, it won’t insert a newline when formatting.

cfleming09:02:52

Right now there isn’t a global “don’t do anything” switch, I’ll add one for that use case.

cfleming09:02:21

And yes, once this is all done and working, it will allow me to finally add things like moving stuff between namespaces, proper namespace renames, etc.

imre09:02:22

keep going Colin

cfleming06:02:24

I was thinking about the global disable switch, and I don’t think it’s actually required. Right now, the ns will only be modified when you invoke the Optimise Imports action. The only place that would happen automatically is if you had configured it to happen on format, on commit, or maybe some other places that IntelliJ lets you invoke it automatically. So I’m assuming that for other people’s projects, you just wouldn’t configure that, and wouldn’t invoke the action.

cfleming06:02:52

What I’m planning to do for the require insertion on completion is to scan through the requires, and insert the new clause before the first one that is lexicographically greater than the new one. So if your clauses are in order that should be maintained, and if they’re not you’re no worse off than you are now.

cfleming06:02:46

For some operations like moving things from one namespace to another, the Optimise operation will probably be invoked automatically by default on the namespace you’re moving things from, to tidy it up, and at that point it will probably make sense to have a “don’t do that” switch, even though I suspect that you will still want it in most cases anyway.