Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### New features

* [#708](https://github.com/clojure-emacs/clojure-mode/pull/708): Add `clojure-remove-unused-keys` (`C-c C-r k`), which removes the names the top-level form at point destructures from maps but never uses, along with their `:or` defaults.

### Changes

* [#705](https://github.com/clojure-emacs/clojure-mode/pull/705): Rename the `#_` toggle commands to `clojure-toggle-discard`, `clojure-toggle-discard-surrounding-form` and `clojure-toggle-discard-defun`, matching Clojure's "discard" terminology (the old `clojure-toggle-ignore*` names remain as obsolete aliases).
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ Here's a summary of the keybindings available in `clojure-mode`:
| `C-c C-r _` | `clojure-toggle-discard-surrounding-form` |
| `C-c C-r P` | `clojure-promote-fn-literal` |
| `C-c C-r a` | `clojure-add-arity` |
| `C-c C-r k` | `clojure-remove-unused-keys` |
| `C-c C-r (` | `clojure-convert-collection-to-list` |
| `C-c C-r '` | `clojure-convert-collection-to-quoted-list` |
| `C-c C-r {` | `clojure-convert-collection-to-map` |
Expand Down Expand Up @@ -645,6 +646,30 @@ without affecting the namespace declaration.

<img width="512" src="/doc/clojure-add-arity.gif">

### Remove unused destructured keys

`clojure-remove-unused-keys`: Remove what the top-level form at point
destructures from maps but doesn't use: names in `:keys`, `:strs` and `:syms`,
`:as` names and names bound to keys, along with their `:or` defaults. That
covers arglists (`defn`, `fn`, `defmethod`, `letfn`, `reify` and the like) and
the bindings of `let`, `loop`, `for`, `doseq` and the like. A map with nothing
left becomes `_`, and one with only its `:as` name left becomes that name.

```clojure
(defn handle [{:keys [id user] :or {user "anon"} :as req}]
(process id))

;; becomes

(defn handle [{:keys [id]}]
(process id))
```

A name stays when a symbol with that name appears anywhere in its scope, even
if it's a local that shadows it, and so does one starting with `_`, which marks
it unused on purpose. Positional args and vector destructuring are left alone,
as removing one would change what the others bind.

## Related packages

- [clojure-mode-extra-font-locking][] provides additional font-locking
Expand Down
Loading
Loading