Subject: bug#78866: [PATCH] (Finsert_file_contents): Refine commit d07af40d8826

From: Eli Zaretskii <[email-masked]>
Date: Thu, 26 Jun 2025 12:09:49 +0300

> Cc: <[email-masked]>
> Date: Sun, 22 Jun 2025 22:28:31 -0400
> From:  Stefan Monnier via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> - Start with:
> 
>       % src/emacs -Q BUGS &
>       % echo foo >>BUGS
> 
> - In the Emacs session type:
> 
>       a
> 
>   Notice how Emacs correctly prompts about "changed on disk, really edit".
>   Hit `C-g` so we don't actually edit the buffer.
> 
> - In the Emacs session do:
> 
>       M-: (insert-file-contents "README" nil nil nil t) RET
> 
>   Notice how Emacs just blindly changed the contents of the buffer
>   without prompting about "changed on disk, really edit".
> 
> I think this last step is an error, we should be prompted just as we are
> with any other buffer modification that diverges from the file's contents.
> 
> The patch below does just that,

I agree that we should prompt, but I don't understand the logic behind
the proposed solution.  Why is it OK not to prompt when VISIT is
non-nil?  It is true that in that case we will be reading from
FILENAME, but the contents after the insertion will not necessarily be
identical to FILENAME, because not necessarily the entire contents of
the buffer is erased.  The case where the entire buffer is erased and
its contents replaced by that of FILENAME, in which case the prompt
indeed makes no sense, is a special case, not the general case.

Also note that the prompt, if we issue it here, will not be about
FILENAME, it will be about the file visited by the buffer, which at
this point is still the original buffer-file-name.  In your example
above, it's "BUGS", not "README".  Which is wrong when VISIT is
non-nil, but the correct solution is not just disable the prompt, it's
to issue the prompt about a different file, no?

So I'd prefer to fix this more thoroughly and correctly.