Function: cider-ns-edit--clean-libspec
cider-ns-edit--clean-libspec is a byte-compiled function defined in
cider-ns.el.
Signature
(cider-ns-edit--clean-libspec NS-START UNUSED)
Documentation
Remove from the ns form at NS-START what UNUSED says a libspec can lose.
UNUSED is one of the "libspecs" dicts of cider-sync-request:clean-ns. Return (CLAUSE . REMOVED), CLAUSE being the start of the libspec's clause and REMOVED descriptions of what got removed, or nil when there's no such libspec.
Source Code
;; Defined in ~/.emacs.d/elpa/cider-20261106.1225/cider-ns.el
(defun cider-ns-edit--clean-libspec (ns-start unused)
"Remove from the ns form at NS-START what UNUSED says a libspec can lose.
UNUSED is one of the \"libspecs\" dicts of `cider-sync-request:clean-ns'.
Return (CLAUSE . REMOVED), CLAUSE being the start of the libspec's clause
and REMOVED descriptions of what got removed, or nil when there's no such
libspec."
(nrepl-dbind-response unused (ns clause remove as as-alias refer refer-macros)
(pcase (cider-ns-edit--locate ns-start (concat ":" clause)
(lambda (pos)
(and (cider-ns-edit--seq-p pos)
(equal (cider-ns-edit--libspec-ns pos) ns))))
(`(,clause-start ,index ,pos)
(if remove
(progn
(cider-ns-edit--delete-elements clause-start (list index))
(list clause-start ns))
(let (drop aliases names)
;; The names first, within their list.
(pcase-dolist (`(,option . ,unused-names) `((":refer" . ,refer)
(":refer-macros" . ,refer-macros)))
(when-let* ((referred (and unused-names (cider-ns-edit--libspec-option pos option)))
((cider-ns-edit--seq-p referred)))
(let* ((texts (mapcar #'cider-ns-edit--text (cider-ns-edit--elements referred)))
(indices (seq-filter (lambda (i) (member (nth i texts) unused-names))
(number-sequence 0 (1- (length texts))))))
(when indices
(setq names (append names (seq-uniq (mapcar (lambda (i) (nth i texts)) indices))))
(if (= (length indices) (length texts))
(push option drop)
(cider-ns-edit--delete-elements referred indices))))))
(pcase-dolist (`(,option . ,alias) `((":as" . ,as) (":as-alias" . ,as-alias)))
(when-let* ((value (and alias (cider-ns-edit--libspec-option pos option)))
((equal (cider-ns-edit--text value) alias)))
(push option drop)
(push (concat option " " alias) aliases)))
(when drop
(cider-ns-edit--delete-elements pos (cider-ns-edit--option-indices pos drop)))
(cons clause-start (append (nreverse aliases) names))))))))