     if path = @buffer.getPath()
       @diffs[path] = git?.getLineDiffs(path, @buffer.getText())
 
-  removeDiffs: ->
+  removeDiffs: =>
     if @gutter.hasGitLineDiffs
       @gutter.find('.line-number').removeClass('git-line-added git-line-modified git-line-removed')
       @gutter.hasGitLineDiffs = false
 
-  renderDiffs: ->
+  renderDiffs: =>
     return unless @gutter.isVisible()
 
     @removeDiffs()


  beforeRemove: ->
    @unsubscribe()

  subscribeToBuffer: ->
    if @buffer?
      @removeDiffs()
      delete @diffs[@buffer.getPath()] if @buffer.destroyed
      @buffer.off '.git-diff'
      @buffer = null

    if @buffer = @editor.getBuffer()
      @scheduleUpdate() unless @diffs[@buffer.getPath()]?
      @buffer.on 'contents-modified.git-diff', => @updateDiffs()

  scheduleUpdate: ->
    _.nextTick => @updateDiffs()

  updateDiffs: ->
    @generateDiffs()
    @renderDiffs()


    @gutter = @editor.gutter
    @diffs = {}

    @subscribe @editor, 'editor:path-changed', @subscribeToBuffer
    @subscribe @editor, 'editor:display-updated', @renderDiffs
    @subscribe git, 'statuses-changed', =>
      @diffs = {}
      @scheduleUpdate()
