clojure-emacs / clj-refactor.el

A CIDER extension that provides powerful commands for refactoring Clojure code.
GNU General Public License v3.0
771 stars 111 forks source link

Pass :always-return-ns-form true to clean-ns #558

Closed DerGuteMoritz closed 6 months ago

DerGuteMoritz commented 6 months ago

This allows for cleaning up whitespace even if there are no structural changes.

Note that I went with always replacing the ns form even if there were no whitespace changes because there's no function for only extracting the current ns form for comparison (in other words: there's only clojure-delete-and-extract-sexp but no clojure-extract-sexp). It's probably fine!

Depends on https://github.com/clojure-emacs/refactor-nrepl/pull/407 and a corresponding update of cljr-injected-middleware-version once released.

DerGuteMoritz commented 6 months ago

Unfortunately this doesn't seem ideal as it can needlessly touch the underlying file - might be wasteful for misc other tools.

Ah yes, point taken!

Note that there's defun cljr--maybe-eval-ns-form. Jumping to definition from there you can find inspiration.

Took clojure-delete-and-extract-sexp as inspiration instead. Not too happy about the string-trim-right which is necessary because the string returned by refactor-nrepl comes with a trailing newline. Could of course also be changed on that end but oh well!

vemv commented 6 months ago

Very nice!

LGTM.

Let me release refactor-nrepl first so that merging this will work.

vemv commented 6 months ago

I've released https://clojars.org/refactor-nrepl/versions/3.10.0

Please cherry-pick this commit https://github.com/clojure-emacs/clj-refactor.el/commit/282a43c3139e8f2aadb102616d2839adeab11a67 and test out the changes for about a week!

Cheers - V

DerGuteMoritz commented 6 months ago

Works as intended so far :+1:

vemv commented 6 months ago

Thanks much!

I've cut 3.12.0, to be melpa-visible in a bit.