 class GhcModiProcess
   editorCount: 0
   process: null
+  commandQueue: []
+  commandRunning: false
 
   constructor: ->
 

  spawnProcess: =>
    return unless atom.config.get('haskell-ghc-mod.enableGhcModi')
    return if @process?
    @modiPath = atom.config.get('haskell-ghc-mod.ghcModiPath')
    @process = CP.spawn(@modiPath,[],@processOptions())
    @process.once 'exit', =>
      @spawnProcess()

  killProcess: =>
    @process?.removeAllListeners? 'exit'
    @process?.stdin?.end?()
    @process=null

  # Tear down any state and detach
  destroy: ->
    @killProcess()

  runCmd: (command, callback) ->
    unless atom.config.get('haskell-ghc-mod.enableGhcModi')
      @runModCmd command, (lines) ->
        callback lines.map (line)->
          replaceAll(line,'\0','\n')
    else
      @spawnProcess() unless @process
      @process.stdout.once 'data', (data)->
        lines = "#{data}".split("\n")
        result = lines[lines.length-2]
        throw new Error("Ghc-modi terminated:\n"+"#{result}")\
          unless result.match(/^OK/)
        lines = lines.slice(0,-2)
        callback lines.map (line)->


  processOptions: ->
    # this is not pretty...
    # TODO: depend on file path
    rootPath = atom.project.getPaths()[0]
    sep = if process.platform=='win32' then ';' else ':'
    env = process.env
