Hi all,
whenever I want to start a sub-REPL at a Slime REPL, it seems to
terminate immediately.
With "lein repl" it just works:
--8<---------------cut here---------------start------------->8---
user=> (clojure.main/repl :prompt #(print "foo=> "))
foo=> (+ 1 2)
3
foo=> ;; Waiting for another input...
--8<---------------cut here---------------end--------------->8---
With emacs 24 and clojure-mode-1.10.0 (M-x clojure-jack-in), and
swank-clojure-1.4.0-SNAPSHOT (installed with "lein plugin install
swank-clojure 1.4.0-SNAPSHOT", not in my :dev-dependencies):
--8<---------------cut here---------------start------------->8---
user> (clojure.main/repl :prompt #(print "foo=> "))
foo=> nil ;; "foo=> " is immediately printed and nil returned
user> ;; back at the old REPL...
--8<---------------cut here---------------end--------------->8---
So the sub-REPL prints its prompt and instantly terminates returning
nil. This is really annoying, because it makes the use of the really
useful `break' macro shown in The Joy of Clojure's last chapter
impossible. Here's the (slightly modified) code:
--8<---------------cut here---------------start------------->8---
(defn contextual-eval
"Evals expr in the context ctx given as map.
Example: (contextual-eval {'a 1, 'b 2} '(+ a b)) ;; => 3"
[ctx expr]
(eval
`(let [~@(mapcat (fn [[k v]] [k `'~v]) ctx)]
~expr)))
(defn readr
"Reads from *in* with the given promt, returns the given input or exit-code,
if input was :c (continue)."
[prompt exit-code]
(let [input (clojure.main/repl-read prompt exit-code)]
(if (= input :c)
exit-code
input)))
(defmacro local-context
"Grabs the local context and returns it as a map."
[]
(let [symbols (keys &env)]
(zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))
(defmacro break
"Define a breakpoint with optional name s."
[& [s]]
`(clojure.main/repl
:prompt #(print (str "debug"
~(when s (str "(" s ")"))
"=> "))
:read readr
:eval (partial contextual-eval (local-context))))
--8<---------------cut here---------------end--------------->8---
It works just fine in a REPL started with "lein repl":
--8<---------------cut here---------------start------------->8---
user=> (let [a 1] (break))
debug=> (local-context)
{a 1}
debug=> a
1
debug=> :c
nil
user=>
--8<---------------cut here---------------end--------------->8---
However, if I do exactly the same in the Slime REPL in emacs, then the
break directly exits and you have no chance to inspect the local
context.
--8<---------------cut here---------------start------------->8---
user> (let [a 1] (break))
debug=> nil
user>
--8<---------------cut here---------------end--------------->8---
Is there a way to get it working?
Bye,
Tassilo
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en