Permalink
Browse files

Add support for clearing a namespace when running load-file (C-c C-l)

  • Loading branch information...
1 parent 8fd675c commit 378fe8dc93e0f5e529d4b21afdde319c16da6ed6 @arohner arohner committed Mar 13, 2012
Showing with 18 additions and 3 deletions.
  1. +1 −0 project.clj
  2. +17 −3 src/swank/commands/basic.clj
View
@@ -3,6 +3,7 @@
:url "http://github.com/technomancy/swank-clojure"
:dependencies [[org.clojure/clojure "1.2.1"]
[clj-stacktrace "0.2.4"]
+ [org.clojure/tools.namespace "0.1.0"]
[cdt "1.2.6.2"]]
:dev-dependencies [[lein-multi "1.0.0"]]
:multi-deps {"1.3" [[org.clojure/clojure "1.3.0"]
@@ -6,6 +6,7 @@
(swank.clj-contrib pprint macroexpand))
(:require (swank.util [sys :as sys])
[swank.core.debugger-backends :as dbe]
+ [clojure.tools.namespace :as ns]
[clojure.string]
)
(:import
@@ -131,6 +132,15 @@
:references nil
:short-message ~(.toString t)))
+(defn destroy-ns
+ [ns]
+ (doseq [sym (keys (ns-refers ns))]
+ (ns-unmap ns sym))
+ (doseq [a (keys (ns-aliases ns))]
+ (ns-unalias ns a))
+ (doseq [a (keys (ns-publics ns))]
+ (ns-unmap ns a)))
+
(defn- compile-file-for-emacs*
"Compiles a file for emacs. Because clojure doesn't compile, this is
simple an alias for load file w/ timing and messages. This function
@@ -160,12 +170,16 @@
(defslimefn load-file [file-name]
(let [libs-ref @(resolve 'clojure.core/*loaded-libs*)
- libs @libs-ref]
+ libs @libs-ref
+ ns-form (ns/read-file-ns-decl (java.io.File. file-name))
+ ns (second ns-form)]
(try
+ (when ns
+ (destroy-ns ns))
(dosync (ref-set libs-ref #{}))
(pr-str (clojure.core/load-file file-name))
- (finally
- (dosync (alter libs-ref into libs))))))
+ (finally
+ (dosync (alter libs-ref into libs))))))
(defn- line-at-position [file position]
(try

0 comments on commit 378fe8d

Please sign in to comment.