Subject: bug#52242: 29.0.50; Feature Request: Offer to run`diff-buffer-with-file' in `recover-this-file' prompt

From: Visuwesh <[email-masked]>
Date: Wed, 06 Dec 2023 13:52:59 +0530

[வியாழன் டிசம்பர் 02, 2021] Visuwesh wrote:

> `recover-this-file' quite helpfully shows the time of creation of the
> auto-save file.  However, this is not always enough to decide whether I
> should recover from said auto-save file since there's no way of knowing
> if the changes in auto-save file are desirable [1] so I end up answering
> yes, then run `diff-buffer-with-file' anyway.  I think having a
> `diff-buffer-with-file' option like `save-some-buffers' would be a
> quality-of-life improvement.

Please find attached path that uses read-answer to present the diff.

>From d64f8a1307ab82216b5f97982494945547810f64 Mon Sep 17 00:00:00 2001
From: Visuwesh <[email-masked]>
Date: Wed, 6 Dec 2023 13:45:03 +0530
Subject: [PATCH] Offer to show diff against auto-save in recover-file

* lisp/files.el (recover-file): Show diff against the selected auto
save file.  bug#52242

* etc/NEWS: Announce the new feature.
---
 etc/NEWS      |  4 ++++
 lisp/files.el | 10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/etc/NEWS b/etc/NEWS
index 29f4e5c0b66..6c2a584c355 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -258,6 +258,10 @@ called in the '--eval' expression, which is useful when those
 arguments contain arbitrary characters that otherwise might require
 elaborate and error-prone escaping (to protect them from the shell).
 
+** 'recover-this-file' can show diff between auto save file and current file.
+When answering the prompt with "diff" or "=", it now shows the diff
+between the auto save file and the current file.
+
 
 * Editing Changes in Emacs 30.1
 
diff --git a/lisp/files.el b/lisp/files.el
index 1cdcec23b11..d70524e4775 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7083,7 +7083,15 @@ recover-file
 	    #'(lambda (window _value)
 		(with-selected-window window
 		  (unwind-protect
-		      (yes-or-no-p (format "Recover auto save file %s? " file-name))
+                      (let ((prompt (format "Recover auto save file %s? " file-name))
+                            (choices
+                             '(("yes" ?y "recover auto save file")
+                               ("no" ?n "don't recover auto save file")
+                               ("diff" ?= "diff auto save file with current file")))
+                            ans)
+                        (while (equal "diff" (setq ans (read-answer prompt choices)))
+                          (diff file file-name))
+                        (equal ans "yes"))
 		    (when (window-live-p window)
 		      (quit-restore-window window 'kill)))))
 	    (with-current-buffer standard-output
-- 
2.42.0