(NB: In this post, I will use expressions like "a buffer's underlying file" to mean, in the Emacs' documentation's terminology, "the file a buffer is visiting", i.e. the value of
(buffer-file-name SOME-BUFFER) for the buffer
Sometimes it happens that a buffer's underlying file gets modified on disk by some other process.
If one tries to modify such a buffer, Emacs warns of the on-disk change, and requests confirmation; e.g. (in the minibuffer):
one_really_busy_file changed on disk; really edit the buffer? (y, n, r or C-h)
Furthermore, if after responding
y to such a confirmation request, one modifies such a buffer, and then attempts to save the modified buffer, then Emacs once again issues a warning and a confirmation request; e.g.:
one_really_busy_file has changed since visited or saved. Save anyway? (y or n)
To be sure, Emacs does not regard all modifications to a buffer's underlying file as being equally worthy of all this fuss. Changes to the underlying file's permissions, for example, do not elicit any of this.
Strangely enough, according to out-of-the-box Emacs, a buffer's underlying file's disappearance also fails to warrant such a response!
To be more specific, Emacs remains perfectly quiet if one modifies a buffer whose underlying file has disappeared, and—even more surprising—, it remains equally silent when one then saves (
C-x C-s) the modified buffer (thereby re-creating the underlying file).
Q: How can I get Emacs to issue a warning and a confirmation request also when one attempts to modify a buffer whose underlying file has disappeared?