(defn repl
"A repl that supports line numbers. For definitions and evaluations made
at the repl, the repl-name and line number will be reported as the
origin. Use set-repl-name and set-repl-prompt to customize the repl name
and prompt. This repl supports all of the keyword arguments documented
for clojure.main/repl with the following change and additions:
- :prompt has a new default
default: #(clojure.core/print (repl-prompt))
- :name-fmt, Name format string
default: the name-fmt of the parent repl, or \"repl-%S\"
- :prompt-fmt, Prompt format string
default: the prompt-fmt of the parent repl, or \"%S:%L %N=> \""
[& options]
(let [{:keys [init need-prompt prompt flush read eval print caught
name-fmt prompt-fmt]
:or {init #()
need-prompt (if (instance? LineNumberingPushbackReader *in*)
#(.atLineStart *in*)
#(identity true))
prompt #(clojure.core/print (repl-prompt))
flush flush
read clojure.main/repl-read
eval eval
print prn
caught clojure.main/repl-caught
name-fmt (*info* :name-fmt)
prompt-fmt (*info* :prompt-fmt)}}
(apply hash-map options)]
(try
(Var/pushThreadBindings
{Compiler/SOURCE (var-get Compiler/SOURCE)
Compiler/LINE (var-get Compiler/LINE)
(var *info*) *info*
(var *private*) {}})
(update *info*
:started (Date.)
:serial (swap! *serial-number* inc)
:thread (.getId (Thread/currentThread))
:depth (inc (*info* :depth)))
(update *private*
:prompt prompt)
(set-repl-name name-fmt)
(set-repl-prompt prompt-fmt)
(clojure.main/repl
:init init
:need-prompt need-prompt
:prompt prompt-hook
:flush flush
:read read
:eval eval
:print print
:caught caught)
(finally
(Var/popThreadBindings)
(prn)))))
Used in 0 other vars
Comments top
No comments for repl. Log in to add a comment.