Skip to content

Commit a001267

Browse files
committedApr 23, 2021
Add undef-all op
1 parent e6f18dd commit a001267

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed
 

‎src/cider/nrepl.clj

+5-2
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@
473473
(def ops-that-can-eval
474474
"Set of nREPL ops that can lead to code being evaluated."
475475
#{"eval" "load-file" "refresh" "refresh-all" "refresh-clear"
476-
"toggle-trace-var" "toggle-trace-ns" "undef"})
476+
"toggle-trace-var" "toggle-trace-ns" "undef" "undef-all"})
477477

478478
(def-wrapper wrap-tracker cider.nrepl.middleware.track-state/handle-tracker
479479
ops-that-can-eval
@@ -492,7 +492,10 @@
492492
{"undef" {:doc "Undefine a symbol"
493493
:requires {"sym" "The symbol to undefine"
494494
"ns" "The namespace is which to resolve sym (falls back to *ns* if not specified)"}
495-
:returns {"status" "done"}}}})
495+
:returns {"status" "done"}}
496+
"undef-all" {:doc "Undefine all aliases and symbols in a namespace"
497+
:requires {"ns" "The namespace to operate on"}
498+
:returns {"status" "done"}}}})
496499

497500
(def-wrapper wrap-version cider.nrepl.middleware.version/handle-version
498501
{:doc "Provides CIDER-nREPL version information."

‎src/cider/nrepl/middleware/undef.clj

+16-1
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,25 @@
2727
(ns-unmap ns sym-name)))
2828
sym))
2929

30+
(defn undef-all
31+
"Undefines all symbol mappings and aliases in the namespace."
32+
[{:keys [ns]}]
33+
(let [ns (misc/as-sym ns)]
34+
(doseq [[sym _] (ns-map ns)]
35+
(ns-unmap ns sym))
36+
(doseq [[sym _] (ns-aliases ns)]
37+
(ns-unalias ns sym))
38+
ns))
39+
3040
(defn undef-reply
3141
[msg]
3242
{:undef (undef msg)})
3343

44+
(defn undef-all-reply
45+
[msg]
46+
{:undef-all (undef-all msg)})
47+
3448
(defn handle-undef [handler msg]
3549
(with-safe-transport handler msg
36-
"undef" undef-reply))
50+
"undef" undef-reply
51+
"undef-all" undef-all-reply))

0 commit comments

Comments
 (0)