Subject: bug#15895: describe-package inserts invalid buffer when readme buffer killed in after-save-hook

From: Glenn Morris <[email-masked]>
Date: Sat, 16 Nov 2013 17:49:05 -0500

Kazuhiro NISHIYAMA wrote:

> I use delete-file-if-no-contents in after-save-hook, and open
> git-gutter-fringe or git-gutter-fringe+ from *Packages* buffer, the
> hook asks me "Delete file and kill buffer?". When I answer "y", the
> buffer for *-readme.txt killed, and buffer-string after save-buffer in
> describe-package-1 returns from invalid buffer's content.

I'm going to say: "don't do that then". There are ~ 200 calls to
save-buffer in the Emacs sources, and I imagine none of them expect
save-buffer to kill the buffer in question. Maybe some of them should be
using something lower-level like write-region, but I'm not going to
bother to check them.

I suggest you make your delete-file-if-no-contents thing only take
effect in _interactive_ calls to save-buffer.

> I think that buffer-string should be before save-buffer.

Then it would not get the (minor) benefit of require-final-newline.
Obviously, we could reimplement that, but I don't think we should have
to bother.