Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/unrepl/blob-template.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
<BLOB-PAYLOAD>
<<<FIN
(clojure.core/ns user)
(unrepl.repl/start (read))
(unrepl.repl/start (unrepl.repl/read-ext-session-actions))
26 changes: 5 additions & 21 deletions src/unrepl/make_blob.clj
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
regular s))
(str sb)))

(defn- gen-blob [session-actions]
(defn- gen-blob []
(let [template (slurp (io/resource "unrepl/blob-template.clj"))
shaded-code-sb (StringBuilder.)
shaded-libs (shade/shade 'unrepl.repl
Expand All @@ -66,26 +66,10 @@
(str/replace "unrepl.repl"
(str (shaded-libs 'unrepl.repl)))
(str/replace "<BLOB-PAYLOAD>" (str shaded-code-sb)))]
(str (strip-spaces-and-comments code) "\n" session-actions "\n"))) ; newline to force eval by the repl
(str (strip-spaces-and-comments code) "\n"))) ; newline to force eval by the repl

(defn -main
([] (-main "resources/unrepl/blob.clj" "{}"))
([target session-actions]
([] (-main "resources/unrepl/blob.clj"))
([target]
(-> target io/file .getParentFile .mkdirs)
(let [session-actions-source (if (re-find #"^\s*\{" session-actions) session-actions (slurp session-actions))
session-actions-map (edn/read-string {:default (fn [tag data] (tagged-literal 'unrepl-make-blob-unquote (list 'tagged-literal (tagged-literal 'unrepl-make-blob-quote tag) data)))} session-actions-source)]
(if (map? session-actions-map)
(let [session-actions-map (into session-actions-map
(map (fn [[k v]]
[k (tagged-literal 'unrepl-make-blob-syntaxquote
(if (and (seq? v) (symbol? (first v)) (namespace (first v)))
(list 'unrepl.repl/ensure-ns v)
v))]))
session-actions-map)
session-actions (-> session-actions-map pr-str
(str/replace #"#unrepl-make-blob-(?:syntax|un)?quote " {"#unrepl-make-blob-syntaxquote " "`"
"#unrepl-make-blob-unquote " "~"
"#unrepl-make-blob-quote " "'"}))]
(spit target (gen-blob session-actions)))
(println "The arguments must be: a target file name and an EDN map.")))))

(spit target (gen-blob))))
17 changes: 12 additions & 5 deletions src/unrepl/repl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@
eval-id])))))
request-prompt)))

(defn read-ext-session-actions
[]
(->> (edn/read {:default tagged-literal} *in*)
(into {} (map (fn [[k v]]
[k (if (and (seq? v)
(symbol? (first v))
(namespace (first v)))
`(do
(require '~(symbol (namespace (first v))))
~v)
v)])))))

(defn start [ext-session-actions]
(with-local-vars [prompt-vars #{#'*ns* #'*warn-on-reflection*}
current-eval-future nil]
Expand Down Expand Up @@ -416,8 +428,3 @@
(start)
(finally
(.setContextClassLoader (Thread/currentThread) cl)))))

(defmacro ensure-ns [[fully-qualified-var-name & args :as expr]]
`(do
(require '~(symbol (namespace fully-qualified-var-name)))
~expr))