Skip to content

Add a command that removes what the ns form doesn't use - #4219

Merged
bbatsov merged 3 commits into
masterfrom
ns-clean
Oct 27, 2026
Merged

bbatsov merged 3 commits into
masterfrom
ns-clean

Conversation

@bbatsov

@bbatsov bbatsov commented Oct 27, 2026

Copy link
Copy Markdown
Member

cider-ns-clean (C-c M-n c) replaces clj-refactor's cljr-clean-ns, using the cider/clean-ns op from clojure-emacs/cider-nrepl#1063. It removes only what the op reports and leaves the rest of the ns form as it's written, comments included, instead of reprinting it. It's a command rather than an option; the docs show how to run it on save.

A timed-out sync request also stops putting the whole request in its error, which for this op meant the whole file.

The error had the whole request in it, which for a request carrying
code means all of that code in the echo area and *Messages*, and with
a request that sends a whole file, all of the file.
cider-ns-clean (C-c M-n c) takes over from clj-refactor's
cljr-clean-ns. The REPL's cider/clean-ns op reads the code after the
ns form, without loading it, and says which libspecs, aliases, referred
names and imports go unused. CIDER removes exactly those, so the rest
of the ns form stays as it's written, comments included, where
refactor-nrepl reprints the whole form. Then cider-ns-edit-actions
apply, as after any other edit to the ns form.

It's never automatic, since removing a require the code needs is the
worst thing an ns command can do, and requires with no alias and
nothing to refer, which tend to be there for their side effects, never
go. Called from Lisp, as from before-save-hook, it does nothing without
a REPL that has the op and reports problems in the echo area, so
saving goes on.
cider-ns-clean needs its cider/clean-ns op. It also brings orchard
0.47.0, whose Java doc fragments no longer split words at entities and
tags, or lose the type parameters in {@code} and {@link}.
@bbatsov
bbatsov merged commit 11c5c9e into master Oct 27, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant