Skip to content

Add a command that removes unused destructured keys - #708

Merged
bbatsov merged 1 commit into
masterfrom
remove-unused-keys
Nov 3, 2026
Merged

bbatsov merged 1 commit into
masterfrom
remove-unused-keys

Conversation

@bbatsov

@bbatsov bbatsov commented Nov 1, 2026

Copy link
Copy Markdown
Member

The same command as clojure-emacs/clojure-ts-mode#169. clojure-mode has no syntax tree, so a small reader builds one for the form at point, and the rest matches the clojure-ts-mode version. Both give the same results over cider-nrepl, orchard and refactor-nrepl.

clojure-remove-unused-keys (C-c C-r k) removes what the top-level form
at point destructures from maps but never uses: names in :keys, :strs
and :syms, :as names and names bound to keys, along with their :or
defaults. It covers the arglists of fn, defn, defmethod, letfn and
methods, and the bindings of let-like forms. A map with nothing left
becomes _. Comments and #_ forms among the names stay, and a map that
still has one isn't empty.

A name counts as used when any unqualified symbol with that name
appears in its scope. That ignores shadowing, so it can only miss a
removal. Names starting with _ stay, as do positional args and vector
destructuring. A map left with only :as stays a map, as map
destructuring turns a seq into a map and the bare name wouldn't. Quoted
and syntax-quoted forms are left alone, being data or a macro's
template.

With no syntax tree to go by, a small reader turns the form into one,
which keeps the rest the same as in clojure-ts-mode.
@bbatsov
bbatsov force-pushed the remove-unused-keys branch from 108a3e7 to baa7b31 Compare November 3, 2026 07:28
@bbatsov
bbatsov merged commit d864d6f into master Nov 3, 2026
7 checks passed
@bbatsov
bbatsov deleted the remove-unused-keys branch November 3, 2026 13:03
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