   stop: ->
     for repl in @repls
       repl.stop()
+    @destroyRepl()
+    @repls = {}
+
+  activateRepl: (repl) ->
+    @activeRepl = repl
+    console.log repl
+    @activeRepl.unsubscriber = repl.emit.subscribe (event) =>
+      @handleReplEvent(event)
+
+  destroyRepl: () ->
+    @activeRepl?.unsubscriber()
     @activeRepl = null
-    @repls = {}
+
+  handleReplEvent: (event) ->
+    error = event.value()
+    if error.index == 0
+      @openToSyntaxError(error.file, error.line, error.char)
 
   openPostWindow: (uri) ->
     repl = @repls[uri]
 
     if repl
-      @activeRepl = repl
+      @activateRepl repl
     else
       fileOpener = (event) =>
         target = event.originalEvent.target

          # offset syntax error by position of selected text in file
          row = range.getRows()[0] + error.error.syntaxErrors.line - 1
          col = error.error.syntaxErrors.charPos
          @openFile(path, null, row, col)

      # dbug = JSON.stringify(error, undefined, 2)
      # console.log dbug
      # @bus.push "<div class='pre debug'>#{dbug}</div>"

    if @activeRepl
      # if stuck in compile error

        .then () =>
          @activeRepl.eval(expression, false, path)
            .then(null, onError)

  openToSyntaxError: (path, line, char) ->
    @openFile(path, null, line, char)

  openHelpFile: ->
    unless @editorIsSC()
