Skip to content

Commit ffa7a43

Browse files
committed
CLJS-1112: :repl-requires option for REPL evaluation environment
support :repl-requires to cljs.repl/repl. If repls supply via IReplEnvOptions concatenate. fix bREPL printing
1 parent d07a3e9 commit ffa7a43

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/clj/cljs/repl.clj

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,8 @@
644644
(.printStackTrace e))))
645645

646646
(defn repl*
647-
[repl-env {:keys [init need-prompt prompt flush read eval print caught reader print-no-newline source-map-inline wrap]
647+
[repl-env {:keys [init need-prompt prompt flush read eval print caught reader
648+
print-no-newline source-map-inline wrap repl-requires]
648649
:or {init #()
649650
need-prompt #(if (readers/indexing-reader? *in*)
650651
(== (readers/get-column-number *in*) 1)
@@ -659,15 +660,18 @@
659660
(PushbackReader. (io/reader *in*))
660661
1 "NO_SOURCE_FILE")
661662
print-no-newline print
662-
source-map-inline true}
663+
source-map-inline true
664+
repl-requires '[[cljs.repl :refer-macros [source doc find-doc apropos dir pst]]]}
663665
:as opts}]
664-
(let [{:keys [analyze-path repl-verbose warn-on-undeclared special-fns static-fns] :as opts
666+
(let [repl-opts (-repl-options repl-env)
667+
repl-requires (into repl-requires (:repl-requires repl-opts))
668+
{:keys [analyze-path repl-verbose warn-on-undeclared special-fns static-fns] :as opts
665669
:or {warn-on-undeclared true}}
666670
(merge
667671
{:cache-analysis true :source-map true}
668672
(cljsc/add-implicit-options
669673
(merge-with (fn [a b] (if (nil? b) a b))
670-
(-repl-options repl-env)
674+
repl-opts
671675
opts
672676
{:init init
673677
:need-prompt prompt
@@ -730,8 +734,8 @@
730734
(analyze-source analyze-path opts))
731735
(evaluate-form repl-env env "<cljs repl>"
732736
(with-meta
733-
'(ns cljs.user
734-
(:require [cljs.repl :refer-macros [source doc find-doc apropos dir pst]]))
737+
`(~'ns ~'cljs.user
738+
(:require ~@repl-requires))
735739
{:line 1 :column 1})
736740
identity opts)
737741
(catch Throwable e

src/clj/cljs/repl/browser.clj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@
122122
(send ordering (fn [_] {:expecting nil :fns {}}))
123123
(send-for-eval conn
124124
(cljsc/-compile
125-
'[(set! *print-fn* clojure.browser.repl/repl-print)] {})
125+
'[(set! *print-fn* clojure.browser.repl/repl-print)
126+
(set! *print-newline* true)] {})
126127
identity))
127128

128129
(defn add-in-order [{:keys [expecting fns]} order f]
@@ -496,6 +497,10 @@ goog.events.getProxy/f<@http://localhost:9000/out/goog/events/events.js:276:16"
496497
repl/IJavaScriptEnv
497498
(-setup [this opts]
498499
(setup this opts))
500+
repl/IReplEnvOptions
501+
(-repl-options [this]
502+
{:repl-requires
503+
'[[clojure.browser.repl]]})
499504
repl/IParseStacktrace
500505
(-parse-stacktrace [this st err opts]
501506
(parse-stacktrace this st err opts))

0 commit comments

Comments
 (0)