The code I'm talking about is near the beginning of the definition of
basic-save-buffer-2' in files.el:
Thanks.
I'm not (yet) proposing a change. I'm simply asking what the rationale is
for calling `yes-or-no-p' and making the user confirm that s/he wants to try
to save the file.
I'm not sure what was the intention, but I know that this code is
triggered in cases such as:
- running as root: write will always succeed.
- saving to a read-only file that you own: while `write' will fail,
you can make it succeed by changing the access rights (which is what
tempsetmodes is for).
- saving to a read-only file in a writable dir: write will fail, but
you can make it succeed by calling unlink first [Not sure if this
works in Emacs right now].
In all these cases, Emacs is able to write the file, but the read-only
bit expresses an intention not to modify the file so it makes sense to
ask for confirmation.
But other than for the "running as root" case, the above two cases could
replace the `file-writable-p' test with a `write-region' test:
file-writable-p is documented (via POSIX's documentation of `access') to
be an approximation, whereas `write-region' should reliably tell us
whether we can write to the file.