Skip to content

Commit

Permalink
Make the special functions available from the ClojureScript REPL conf…
Browse files Browse the repository at this point in the history
…igurable.
  • Loading branch information
Brenton Ashworth committed Feb 20, 2012
1 parent 916a07c commit 986ef58
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/clj/cljs/repl.clj
Expand Up @@ -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* "> "))
Expand All @@ -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)))))
Expand Down

0 comments on commit 986ef58

Please sign in to comment.