                       (reset! retained-input (.getText input-widget)))
                     (doto input-widget
                       (.setText (@history (dec (- (count @history) @current-step))))
-                      cursor-at-end))))]
+                      cursor-at-end))))
+        session (repl/client-session repl-client)
+        responses-promise (promise)]
     (.setHistoryActionFn repl-view history-action-fn)
-    (comp (partial eval-expression repl-view log-panel (repl/client-session repl-client))
+    (future (echo-responses repl-view log-panel responses-promise))
+    (comp
+      #(when-not (realized? responses-promise)
+         (deliver responses-promise %))
+      (partial eval-expression repl-view log-panel session)
       (fn [expr add-to-log?]
         (reset! retained-input nil)
         (reset! current-step -1)

(ns ccw.repl.view-helpers
  (:require [clojure.tools.nrepl :as repl]
    [ccw.repl.cmdhistory :as history])
  (:use [clojure.core.incubator :only [-?>]])
  (:import ccw.CCWPlugin
    org.eclipse.ui.PlatformUI
    org.eclipse.swt.SWT

      (str (when (> (count s) 30) "..."))
      (.replaceAll "\\n|\\r" " "))))

(defn- echo-responses
  [repl-view log-component responses]
  (doseq [{:keys [out err value ns status] :as resp} @responses]
    (ui-sync
      (when ns (.setCurrentNamespace repl-view ns))
      (doseq [[k v] (dissoc resp :id :ns :status :session)]
        (if (log-styles k)
          (log log-component v k)
          (CCWPlugin/log (str "Cannot handle REPL response: " k (pr-str resp)))))
      (doseq [status status]
        (case status
          "interrupted" (log log-component (eval-failure-msg status "") :err)
          "need-input" (ui-sync (.getStdIn repl-view))
          nil)))))

(defn- eval-expression
  [repl-view log-component client expr]
  (try
    (client (update-in (if (map? expr)
                        expr
                        {:op :eval :code expr :ns (.getCurrentNamespace repl-view)})
              [:id] #(or % (uuid))))
    (catch Throwable t
      (CCWPlugin/logError (eval-failure-msg nil expr) t)
      (log log-component (eval-failure-msg nil expr) :err))))

(defn configure-repl-view
  [repl-view log-panel repl-client]
