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

From: Visuwesh <[email-masked]>
Date: Sun, 10 Dec 2023 18:57:56 +0530

[சனி டிசம்பர் 09, 2023] Eli Zaretskii wrote:

>> From: Visuwesh <[email-masked]>
>> Date: Thu, 07 Dec 2023 11:02:28 +0530
>> 
>> I didn't notice that recover-file was covered in the Emacs manual, I
>> have now updated the manual and marked the NEWS entry accordingly in the
>> attached patch.
>
> Thanks, I have a few comments:

Thanks for the review.

>> diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
>> index 917e937d32d..c791a6f1c98 100644
>> --- a/doc/emacs/files.texi
>> +++ b/doc/emacs/files.texi
>> @@ -1325,9 +1325,11 @@ Recover
>>  @end example
>>  
>>    Before asking for confirmation, @kbd{M-x recover-file} displays a
>> -directory listing describing the specified file and the auto-save file,
>> -so you can compare their sizes and dates.  If the auto-save file
>> -is older, @kbd{M-x recover-file} does not offer to read it.
>> +directory listing describing the specified file and the auto-save
>> +file, so you can compare their sizes and dates.  If you answer
>> +@kbd{diff}, it shows the diff between @var{file} and its auto-save
>> +file @file{#@var{file}#}.  If the auto-save file is older, @kbd{M-x
>> +recover-file} does not offer to read it.
>
> It is better to make the documentation of the 'diff' response separate
> from the rest, since the original text doesn't describe the responses
> at all, it only mentions the need for confirmation.
>
> So I suggest to leave the text starting at "Before asking for
> confirmation" alone, and add a new paragraph after that one, like
> this:
>
>   When @kbd{M-x recover-file} asks for confirmation, if you respond
>   with @kbd{diff} or @kbd{=}, it shows the diffs between ...

OK, I made it into a separate paragraph and added that it reprompts for
confirmation.

>> ++++
>> +** 'recover-file' can show diff between auto save file and current file.
>                               ^^^^
> We use "diffs", plural.
>
>> +When answering the prompt with "diff" or "=", it now shows the diff
>                                                                   ^^^^
> Same here.

Done.

>> +between the auto save file and the current file.
>> +                            (choices
>> +                             '(("yes" ?y "recover auto save file")
>> +                               ("no" ?n "don't recover auto save file")
>> +                               ("diff" ?= "diff auto save file with current file")))
>                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Maybe a better text would be
>
>    show changes between auto save file and current file

Thank you, that is indeed clear.  I have now changed the help text to
your suggestion.

>From 49105b0b98c6cccfda028f2ed52fe3cbd403028b 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)

* doc/emacs/files.texi (Recover): Document the new feature.

* etc/NEWS: Announce the new feature.
---
 doc/emacs/files.texi |  8 ++++++--
 etc/NEWS             |  5 +++++
 lisp/files.el        | 10 +++++++++-
 3 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi
index 917e937d32d..2fc1550de61 100644
--- a/doc/emacs/files.texi
+++ b/doc/emacs/files.texi
@@ -1325,10 +1325,14 @@ Recover
 @end example
 
   Before asking for confirmation, @kbd{M-x recover-file} displays a
-directory listing describing the specified file and the auto-save file,
-so you can compare their sizes and dates.  If the auto-save file
+directory listing describing the specified file and the auto-save
+file, so you can compare their sizes and dates.  If the auto-save file
 is older, @kbd{M-x recover-file} does not offer to read it.
 
+When @kbd{M-x recover-file} asks for confirmation, if you answer with
+@kbd{diff} or @kbd{=}, it shows the diffs between @var{file} and its
+auto-save file @file{#@var{file}#} and reprompts you for confirmation.
+
 @findex recover-session
   If Emacs or the computer crashes, you can recover all the files you
 were editing from their auto save files with the command @kbd{M-x
diff --git a/etc/NEWS b/etc/NEWS
index 29f4e5c0b66..39708d866d3 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -258,6 +258,11 @@ 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-file' can show diffs between auto save file and current file.
+When answering the prompt with "diff" or "=", it now shows the diffs
+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..83534e0080c 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" ?= "show changes between auto save file and 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