       d.dispose()
 
   internalChange: (e) ->
+    if @pmutex and @icb.length > 0
+      @internalchanges = @icb.concat(@internalchanges)
+      @icb = []
     for pos in @editor.getCursorBufferPositions()
-      @internalchanges.push {'pos': pos, 'text': text}
+      if @pmutex
+        @internalchanges.push {'pos': pos, 'text': text}
+      else
+        @icb.push {'pos': pos, 'text': text}
 
   externalChange: (e) ->
     lineStartIndex = 0

    console.log e.selection.getText()

  process: ->
    #Fix pos of external changes
    rshift = 0
    for ec, i in @externalchanges #Shift

          @sLines[ec.pos[0]].slice(ec.pos[1])

    @editor.getBuffer().lines = @sLines
    @editor.getBuffer().lineEndings = @sLineEndings
    #Apply internal changes
    for ic in @internalchanges
      @editor.getBuffer().insert(ic.pos, ic.text)

    changes = @internalchanges.slice(0)
    @internalchanges = []
    @externalchanges = []

    #Save state for next round
    @sLines = @editor.getBuffer().getLines()
    @sLineEndings = @editor.getBuffer().lineEndings
    @pmutex = true

    for c, i in changes
      changes[i].pos = changes[i].pos.toArray()

    return changes
