From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#11331: Emacs unnecessarily leaves behind stale auto-save files after crash recovery Date: Fri, 16 Jul 2021 13:29:57 +0200 Message-ID: <874kcubioa.fsf@gnus.org> References: <1335295842.80989.YahooMailClassic@web121501.mail.ne1.yahoo.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9698"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 11331@debbugs.gnu.org To: Kelly Dean Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Jul 16 13:31:17 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4M3p-0002Mu-09 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 16 Jul 2021 13:31:17 +0200 Original-Received: from localhost ([::1]:59884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m4M3o-00038D-02 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 16 Jul 2021 07:31:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m4M3b-0002wp-Ir for bug-gnu-emacs@gnu.org; Fri, 16 Jul 2021 07:31:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:39082) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m4M3a-0001yh-NG for bug-gnu-emacs@gnu.org; Fri, 16 Jul 2021 07:31:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m4M3a-00053t-D0 for bug-gnu-emacs@gnu.org; Fri, 16 Jul 2021 07:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 16 Jul 2021 11:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11331 X-GNU-PR-Package: emacs Original-Received: via spool by 11331-submit@debbugs.gnu.org id=B11331.162643500816113 (code B ref 11331); Fri, 16 Jul 2021 11:31:02 +0000 Original-Received: (at 11331) by debbugs.gnu.org; 16 Jul 2021 11:30:08 +0000 Original-Received: from localhost ([127.0.0.1]:50622 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m4M2i-0004BF-AS for submit@debbugs.gnu.org; Fri, 16 Jul 2021 07:30:08 -0400 Original-Received: from quimby.gnus.org ([95.216.78.240]:40024) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m4M2g-00042Q-GK for 11331@debbugs.gnu.org; Fri, 16 Jul 2021 07:30:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnus.org; s=20200322; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date: References:Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=CLS25E7PHGFz2hm2w34zcf3dhrnNcO3FyIRKQ9jez+s=; b=KghjpfqBgz3FBw6+UliW1qAUTD WQNIdJ19sZlN8nt0sCL1WU1bN9SPR0TIndtXX35rkt8zisSQg2KKmXx4i9FZN0dOtDGM6XXsD2ABI AosuaEwb6VkdTqRl4RkJ5vPu32L7VrYzEKpMCSjr0n1OqmUB9Lw9aKSE1esPcL7I9HuM=; Original-Received: from cm-84.212.220.105.getinternet.no ([84.212.220.105] helo=elva) by quimby.gnus.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m4M2X-0003jI-Td; Fri, 16 Jul 2021 13:30:00 +0200 X-Now-Playing: Charli XCX's _Pop 2_: "Porsche (feat. M+)" 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)") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:210083 Archived-At: Kelly Dean 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