   # Public: Sets the encoding for this buffer.
   #
   # * `encoding` The {String} encoding to use such as 'utf8'
-  setEncoding: (@encoding) -> @file?.setEncoding(@encoding)
+  setEncoding: (@encoding) ->
+    if @file?
+      @file.setEncoding(@encoding)
+      @updateCachedDiskContents true, => @onDidFileChange()
 
   # Public: Returns the {String} encoding of this buffer.
   getEncoding: -> @encoding ? @file.getEncoding()

    @fileSubscriptions = new CompositeDisposable

    @fileSubscriptions.add @file.onDidChange =>
      @conflict = true if @isModified()
      previousContents = @cachedDiskContents

      # Synchrounously update the disk contents because the {File} has already cached them. If the
      # contents updated asynchrounously multiple `conlict` events could trigger for the same disk
      # contents.
      @updateCachedDiskContentsSync()
      return if previousContents == @cachedDiskContents

      if @conflict
        @emitter.emit 'did-conflict'
        @emit "contents-conflicted"
      else
        @reload()

    @fileSubscriptions.add @file.onDidDelete =>
      modified = @getText() != @cachedDiskContents

    @cachedDiskContents = @file?.readSync() ? ""

  # Rereads the contents of the file, and stores them in the cache.
  updateCachedDiskContents: (flushCache=false, callback) ->
    Q(@file?.read(flushCache) ? "").then (contents) =>
      @cachedDiskContents = contents
      callback?()

  ###
  Section: Private Utility Methods
