Function: cider-ns-clean

cider-ns-clean is an autoloaded, interactive and byte-compiled function defined in cider-ns.el.

Signature

(cider-ns-clean &optional INTERACTIVE)

Documentation

Remove the requires, refers and imports that the code doesn't use.

Ask the REPL what the code after the ns form doesn't use, judging by reading the code, without loading anything. A name counts as used wherever it comes up, including comment forms and quoted forms, and these always count as used:

- a require with no alias and nothing to refer, which might be there
  for its side effects;
- :refer :all and :rename, which need the namespace loaded to judge;
- prefix lists, and what's in reader conditionals.

A libspec whose namespace is still used fully qualified, or defines a class that gets imported, stays without what it doesn't need. Everything else in the ns form stays as it's written, comments included.

After a change, do what cider-ns-edit-actions asks for.

When INTERACTIVE is nil, as it is in before-save-hook, do nothing without a REPL that can tell what's unused, and report problems in the echo area, so that saving goes on.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/cider-20261106.1225/cider-ns.el
;;;###autoload
(defun cider-ns-clean (&optional interactive)
  "Remove the requires, refers and imports that the code doesn't use.
Ask the REPL what the code after the ns form doesn't use, judging by
reading the code, without loading anything.  A name counts as used
wherever it comes up, including comment forms and quoted forms, and
these always count as used:

- a require with no alias and nothing to refer, which might be there
  for its side effects;
- `:refer :all' and `:rename', which need the namespace loaded to judge;
- prefix lists, and what's in reader conditionals.

A libspec whose namespace is still used fully qualified, or defines a
class that gets imported, stays without what it doesn't need.
Everything else in the ns form stays as it's written, comments included.

After a change, do what `cider-ns-edit-actions' asks for.

When INTERACTIVE is nil, as it is in `before-save-hook', do nothing
without a REPL that can tell what's unused, and report problems in the
echo area, so that saving goes on."
  (interactive (list t))
  (cond
   (interactive
    (unless (cider-ns-edit--clean-buffer)
      (message "Nothing to clean in the ns form")))
   ((and (when-let* ((repl (cider-current-repl 'infer)))
           (nrepl-op-supported-p "cider/clean-ns" repl))
         (cider-ns-edit--ns-form-start))
    (condition-case err
        (cider-ns-edit--clean-buffer)
      (error (message "Didn't clean the ns form: %s" (error-message-string err)))))))