9

When I kill emacs (with killall emacs from a shell prompt, for example), and I was editing a file, Emacs restarts with a message

filename has auto save data; consider M-x recover-this-file

If I had recently saved the file, then modified it and then undone the changes, so that it looks just like the saved version, this message is displayed, even though the auto-save file has no changes at all (seen via file size or M-x diff)

How can this be disabled?

I could not find something in either the official documentation, or emacswiki.

serv-inc
  • 816
  • 6
  • 26

1 Answers1

4

I don't think there is a built-in mechanism for this, so you may need to roll your own.

Don't have a direct answer, but I have something similar in my config: I don't want to be prompted for confirmation when killing a file that matches what is on disk. To check this I'm running diff and then scanning the output -- you can probably do something similar for your use case.

(defun my/matches-file-p ()
  "Return t if the current buffer is identical to its associated file."
  (autoload 'diff-no-select "diff")
  (when buffer-file-name
    (diff-no-select buffer-file-name (current-buffer) nil 'noasync)
    (with-current-buffer "*Diff*"
      (search-forward-regexp "^Diff finished \(no differences\)\." (point-max) 'noerror))))

(defun my/kill-buffer ()
  "Kill the current buffer.
Don't prompt for confirmation if the buffer is unmodified or matches its file."
  (interactive)
  (when (my/matches-file-p)
    (set-buffer-modified-p nil))
  (kill-buffer))

Looking more at the auto-revert case. It looks like that prompt comes from after-find-file, which is looking at timestamps (file-newer-than-file-p). I don't see a straightforward way to customize or advise this behavior. Maybe you could advise after-find-file to compare the file with its auto-save file and set the warn argument to nil if things match.

glucas
  • 20,175
  • 1
  • 51
  • 83