Permalink
Browse files

Make the special functions available from the ClojureScript REPL conf…

…igurable.
  • Loading branch information...
1 parent 916a07c commit 986ef5807bd1ce6e8d9f98f297923db7898dd89d @brentonashworth brentonashworth committed Feb 20, 2012
Showing with 13 additions and 10 deletions.
  1. +13 −10 src/clj/cljs/repl.clj
View
@@ -131,14 +131,23 @@
(println (.getMessage e))
{:status :error})))
+(def default-special-fns
+ (let [load-file-fn (fn [repl-env file] (load-file repl-env file))]
+ {'in-ns (fn [_ quoted-ns] (set! comp/*cljs-ns* (second quoted-ns)))
+ 'load-file load-file-fn
+ 'clojure.core/load-file load-file-fn
+ 'load-namespace (fn [repl-env ns] (load-namespace repl-env ns))}))
+
(defn repl
"Note - repl will reload core.cljs every time, even if supplied old repl-env"
- [repl-env & {:keys [verbose warn-on-undeclared]}]
+ [repl-env & {:keys [verbose warn-on-undeclared special-fns]}]
(prn "Type: " :cljs/quit " to quit")
(binding [comp/*cljs-ns* 'cljs.user
*cljs-verbose* verbose
comp/*cljs-warn-on-undeclared* warn-on-undeclared]
- (let [env {:context :statement :locals {}}]
+ (let [env {:context :statement :locals {}}
+ special-fns (merge default-special-fns special-fns)
+ is-special-fn? (set (keys special-fns))]
(-setup repl-env)
(loop []
(print (str "ClojureScript:" comp/*cljs-ns* "> "))
@@ -149,14 +158,8 @@
(= status :error) (recur)
- (and (seq? form) (= (first form) 'in-ns))
- (do (set! comp/*cljs-ns* (second (second form))) (newline) (recur))
-
- (and (seq? form) ('#{load-file clojure.core/load-file} (first form)))
- (do (load-file repl-env (second form)) (newline) (recur))
-
- (and (seq? form) ('#{load-namespace} (first form)))
- (do (load-namespace repl-env (second form)) (newline) (recur))
+ (and (seq? form) (is-special-fn? (first form)))
+ (do (apply (get special-fns (first form)) repl-env (rest form)) (newline) (recur))
:else
(do (eval-and-print repl-env env form) (recur)))))

0 comments on commit 986ef58

Please sign in to comment.