Browse files

with env locals at repl

  • Loading branch information...
1 parent fcf3328 commit 2a9d02eba8531426e9b09fee176d9dc854043fe9 @hugoduncan hugoduncan committed Mar 10, 2010
Showing with 25 additions and 14 deletions.
  1. +1 −1 src/swank/commands/basic.clj
  2. +24 −13 src/swank/core.clj
View
2 src/swank/commands/basic.clj
@@ -37,7 +37,7 @@
(if (= form rdr)
[value last-form]
(recur (read rdr false rdr)
- (eval form)
+ (eval (with-env-locals form))
form)))))))
(defslimefn interactive-eval-region [string]
View
37 src/swank/core.clj
@@ -55,6 +55,20 @@
(def #^Throwable *current-exception* nil)
+;; Local environment
+(def *current-env* nil)
+
+(let [&env :unavailable]
+ (defmacro local-bindings
+ "Produces a map of the names of local bindings to their values."
+ []
+ (if-not (= &env :unavailable)
+ (let [symbols (keys &env)]
+ (zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))))
+
+(defn local-non-functions [m]
+ (select-keys m (filter #(or (coll? (m %)) (not (ifn? (m %)))) (keys m))))
+
;; Handle Evaluation
(defn send-to-emacs
"Sends a message (msg) to emacs."
@@ -64,6 +78,16 @@
(defn send-repl-results-to-emacs [val]
(send-to-emacs `(:write-string ~(str (pr-str val) "\n") :repl-result)))
+(defn with-env-locals
+ "Evals a form with given locals. The locals should be a map of symbols to
+values."
+ [form]
+ (let [m (local-non-functions *current-env*)]
+ (if (first m)
+ `(let ~(vec (mapcat #(list % (m %)) (keys m)))
+ ~form)
+ form)))
+
(defn eval-in-emacs-package [form]
(with-emacs-package
(eval form)))
@@ -94,19 +118,6 @@
(defn- debug-abort-exception? [t]
(some #(identical? *debug-abort-exception* %) (exception-causes t)))
-(def *current-env* nil)
-
-(let [&env :unavailable]
- (defmacro local-bindings
- "Produces a map of the names of local bindings to their values."
- []
- (if-not (= &env :unavailable)
- (let [symbols (keys &env)]
- (zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))))
-
-(defn local-non-functions [m]
- (select-keys m (filter #(or (coll? (m %)) (not (ifn? (m %)))) (keys m))))
-
(defn exception-stacktrace [t]
(map #(list %1 %2 '(:restartable nil))
(iterate inc 0)

0 comments on commit 2a9d02e

Please sign in to comment.