all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Lars Ingebrigtsen <larsi@gnus.org>
To: Kelly Dean <kellydeanch@yahoo.com>
Cc: 11331@debbugs.gnu.org
Subject: bug#11331: Emacs unnecessarily leaves behind stale auto-save files after crash recovery
Date: Fri, 16 Jul 2021 13:29:57 +0200	[thread overview]
Message-ID: <874kcubioa.fsf@gnus.org> (raw)
In-Reply-To: <1335295842.80989.YahooMailClassic@web121501.mail.ne1.yahoo.com> (Kelly Dean's message of "Tue, 24 Apr 2012 12:30:42 -0700 (PDT)")

Kelly Dean <kellydeanch@yahoo.com> writes:

> Notice that the auto-save file remains, permanently, unless the buffer
> is later modified (which might not ever happen) and another auto-save
> operation overwrites the old auto-save file (which won't happen even
> if the buffer is modified, if the user saves the file before the
> auto-save timeout).

This is still the case in Emacs 28:

(defun basic-save-buffer (&optional called-interactively)
[...]
	(let ((recent-save (recent-auto-save-p))
[...]
            ;; If the auto-save file was recent before this command,
	    ;; delete it now.
	    (delete-auto-save-file-if-necessary recent-save))

`recent-auto-save-p' will return nil here, so FORCE to
`delete-auto-save-file-if-necessary' is nil.  If I'm reading the code
correctly, just passing in a t here would fix this issue.

(defun delete-auto-save-file-if-necessary (&optional force)
  "Delete auto-save file for current buffer if `delete-auto-save-files' is t.
Normally delete only if the file was written by this Emacs since
the last real save, but optional arg FORCE non-nil means delete anyway."

So this is on purpose (presumably to avoid deleting other instances'
auto-save files or something)...  but when we've just recovered from the
auto-save file, then it definitely should be deleted, I think.

I think...  fixing this would entail `recover-file' setting something.
Either a buffer-local variable, or setting auto_save_modified...  Hm!
`set-buffer-auto-saved'!

The following patch fixes the problem.

Does anybody have any comments to this approach?

diff --git a/lisp/files.el b/lisp/files.el
index ad02d373fd..be57763646 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -6508,7 +6508,8 @@ recover-file
 		 (coding-system-for-read 'auto-save-coding))
 	     (erase-buffer)
 	     (insert-file-contents file-name nil)
-	     (set-buffer-file-coding-system coding-system))
+	     (set-buffer-file-coding-system coding-system)
+             (set-buffer-auto-saved))
 	   (after-find-file nil nil t))
 	  (t (user-error "Recover-file canceled")))))
 


-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





  parent reply	other threads:[~2021-07-16 11:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-24 19:30 bug#11331: Emacs unnecessarily leaves behind stale auto-save files after crash recovery Kelly Dean
2012-06-02 21:34 ` Kelly Dean
2021-07-16 11:29 ` Lars Ingebrigtsen [this message]
2021-07-30 12:07   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874kcubioa.fsf@gnus.org \
    --to=larsi@gnus.org \
    --cc=11331@debbugs.gnu.org \
    --cc=kellydeanch@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.