Skip to content

Commit

Permalink
Misc node and web REPL fixes/cleanup.
Browse files Browse the repository at this point in the history
- Save last exception as noderepl/*e or webrepl/*e.
- Split ep function out of pep in webrepl to match noderepl.
- Don't throw EOF error in noderepl when line is blank.
  • Loading branch information
kanaka committed Dec 15, 2012
1 parent e7338a6 commit 3c3cbbe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
8 changes: 5 additions & 3 deletions src/cljs/noderepl.cljs
Expand Up @@ -5,6 +5,7 @@
[cljs.reader :as reader]))

(def ^:dynamic *debug* false)
(def ^:dynamic *e nil)

(defn prompt [] (str ana/*cljs-ns* "=> "))

Expand All @@ -23,8 +24,8 @@
(when *debug* (println "emit:" res))
(repl-print (pr-str (js/eval res)) "rtn"))
(catch js/Error e
(repl-print (.-stack e) "err")
#_(set! *e e))))
(repl-print (.-stack e) "err")
(set! *e e))))

(defn pep [text]
(postexpr text)
Expand All @@ -46,7 +47,8 @@
(.setPrompt rl (prompt))
(.prompt rl)
(.on rl "line" (fn [line]
(ep line)
(when (seq (filter #(not= " " %) line))
(ep line))
(.setPrompt rl (prompt))
(.prompt rl)))
(.on rl "close" (fn [] (.exit js/process 0)))))
Expand Down
29 changes: 10 additions & 19 deletions src/cljs/webrepl.cljs
Expand Up @@ -5,6 +5,7 @@
[cljs.reader :as reader]))

(def ^:dynamic *debug* false)
(def ^:dynamic *e nil)

(defn prompt [] (str ana/*cljs-ns* "=> "))

Expand All @@ -28,9 +29,6 @@
(.appendChild parent i))
parent)

(def *print-class* nil)
(def *e nil)

(defn repl-print [log text cls]
(doseq [line (.split (str text) #"\n")]
(append-dom log
Expand All @@ -48,25 +46,18 @@
[:td {:class "cg"} (prompt)]
[:td (.replace text #"\n$" "")]]]]))

#_(defmacro print-with-class [c m]
`(binding [*print-class* ~c]
(println ~m)))

;;(set! *print-length* 103)

#_(defmacro let-elem-ids [ids & body]
`(let ~(vec (mapcat #(list % (list '.getElementById 'document (str %))) ids))
~@body))
(defn ep [log text]
(try
(let [res (comp/emit-str (ana/analyze js/env (reader/read-string text)))]
(when *debug* (println "emit:" res))
(repl-print log (pr-str (js/eval res)) "rtn"))
(catch js/Error e
(repl-print log (.-stack e) "err")
(set! *e e))))

(defn pep [log text]
(postexpr log text)
(try
(let [res (comp/emit-str (ana/analyze js/env (reader/read-string text)))]
(when *debug* (println "emit:" res))
(repl-print log (pr-str (js/eval res)) "rtn"))
(catch js/Error e
(repl-print log (.-stack e) "err")
#_(set! *e e))))
(ep log text))

(set! (.-onload js/window) (fn []
(let [log (.getElementById js/document "log")
Expand Down

0 comments on commit 3c3cbbe

Please sign in to comment.