From: Oliver Taylor <olivertaylor@me.com>
To: emacs-devel@gnu.org
Subject: Variable for Confirming Killing a Buffer
Date: Thu, 2 Dec 2021 13:06:52 -0800 [thread overview]
Message-ID: <9EA40AE1-5B31-45D9-AF71-17BB3C6AB8A3@me.com> (raw)
Emacs asks for confirmation when killing modified file-visiting buffers, but
does not do so for non-file-visiting buffers.
The option `buffer-offer-save' tells Emacs to prompt to you save modified
non-file-visiting buffers when EXITING Emacs, but no such option exists for
killing buffers (as described in the docstring for `buffer-offer-save').
I’ve wanted this feature for a while, and managed to create a working solution
with this:
--------------------------------
(defvar-local buffer-confirm-kill nil
"Non-nil means confirm killing buffer when modified.
Variable is checked by `buffer-confirm-kill-p'.")
(defun buffer-confirm-kill-p ()
"Return nil if buffer is modified and `buffer-confirm-kill' is t.
This function is designed to be called from `kill-buffer-query-functions'."
(if (and (buffer-modified-p)
buffer-confirm-kill)
(yes-or-no-p
(format "Buffer %S is modified; kill anyway? " (buffer-name)))
t))
(add-hook 'kill-buffer-query-functions #'buffer-confirm-kill-p)
--------------------------------
Now, doing (setq-local buffer-confirm-kill t) will prevent accidental data
loss.
It’s been so useful that I wonder if something like this shouldn’t just be
part of Emacs itself.
I just had a new baby so I can’t promise to keep up with responses to this
thread, but I wanted to post a first draft of this now, both to get feedback
on the idea, and to enable anyone who might have the urge to run with the
idea. I’d love to turn it into a proper submission myself, but I might have to
wait until I’m sleeping through the night!
next reply other threads:[~2021-12-02 21:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-02 21:06 Oliver Taylor [this message]
2021-12-02 22:41 ` Variable for Confirming Killing a Buffer Stefan Kangas
2021-12-02 23:17 ` Philip Kaludercic
2021-12-02 23:25 ` Oliver Taylor
2021-12-03 16:58 ` Lars Ingebrigtsen
2021-12-03 19:24 ` Michael Heerdegen
2021-12-03 21:35 ` Lars Ingebrigtsen
2021-12-03 22:27 ` Michael Heerdegen
2021-12-03 22:33 ` Lars Ingebrigtsen
2021-12-03 19:45 ` Oliver Taylor
2021-12-03 21:32 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9EA40AE1-5B31-45D9-AF71-17BB3C6AB8A3@me.com \
--to=olivertaylor@me.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.