Permalink
Browse files

implement read-line support

(swank.core/with-read-line-support
   (print "got from Emacs: " (read-line)))
  • Loading branch information...
1 parent 64e2c98 commit f4a1eebc4d34f2ff473c4e5350f889ec356f5168 @tavisrudd tavisrudd committed Jan 9, 2012
Showing with 22 additions and 0 deletions.
  1. +22 −0 src/swank/core.clj
View
@@ -357,7 +357,22 @@ values."
(= id :repl-thread) (find-or-spawn-repl-thread conn)
:else (find-thread id))))
+
+;;; read-line support
+(defonce pending-read-line-promise (atom (promise)))
+(defn read-line-from-emacs []
+ (swap! pending-read-line-promise (fn [_] (promise)))
+ (send-to-emacs `(:read-string :repl-thread "repl-read-line"))
+ (deref (deref pending-read-line-promise)))
+
+(defmacro with-read-line-support
+ "Rebind `read-line` to work within slime."
+ [body]
+ `(binding [read-line read-line-from-emacs]
+ ~body))
+
;; Handle control
+
(defn read-loop
"A loop that reads from the socket (will block when no message
available) and dispatches the message to the control thread."
@@ -397,6 +412,13 @@ values."
(= action :write-string)
(write-to-connection conn ev)
+ (= action :read-string)
+ (write-to-connection conn ev)
+
+ (= action :emacs-return-string)
+ (let [[_thread _tag string] args]
+ (deliver (deref pending-read-line-promise) string))
+
(one-of? action
:debug :debug-condition :debug-activate :debug-return)
(let [[thread & args] args]

0 comments on commit f4a1eeb

Please sign in to comment.