       else
         basePath
 
+    originalPane = atom.workspace.getActivePane()
     @activateAdjacentPane(atom.config.get('transformer.split'))
     options = {searchAllPanes: true, activatePane: false}
     atom.workspace.open(filePath, options).then (editor) ->
       editor.setText('') # Clear existing text
       editor.isModified = -> false
+      originalPane.activate()
       editor # pass editor to next Promise::then
 
   runCommand: ({command, args, options, editor}) ->
-    stdout = stderr = (data) -> editor.insertText(data)
+    stdout = stderr = (data) -> editor?.insertText(data)
     exit = (code) -> temp.cleanupSync() if @tempFile
     # console.log [command, args]
     options = {command, args, options, stdout, stderr, exit}

        @editor.save() if @editor.isModified()
        @sourcePath = @editor.getPath()
      else
        @sourcePath = @tempFile = @writeToTempfile(@editor.getSelectedText())
    @cwd = path.dirname(@sourcePath)

  writeToTempfile: (text) ->
    temp.track()
    dir = temp.mkdirSync("transformer")
    filePath = path.join(dir, "tempfile")
    fs.writeFileSync(filePath, text)
    return filePath


      command = @getCommand()
      @args ?= [@sourcePath]
      options = {@cwd}
      @runCommand {command, @args, options, editor}

  compile: ->
    @run()
