[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCHv5 1/4] `kill-buffer' runs query functions before checking buffer
From: |
Michal Nazarewicz |
Subject: |
[PATCHv5 1/4] `kill-buffer' runs query functions before checking buffer modification. |
Date: |
Fri, 28 Jun 2013 16:40:52 +0200 |
From: Michal Nazarewicz <address@hidden>
* buffer.c (FKill_buffer): Run `kill-buffer-query-functions'
before checking whether buffer is modified. This lets
`kill-buffer-query-functions' cancel killing of the buffer or save
its content before `kill-buffer' asks user the "Buffer %s
modified; kill anyway?" question.
---
doc/lispref/buffers.texi | 2 +-
src/ChangeLog | 8 ++++++++
src/buffer.c | 28 ++++++++++++++++------------
3 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi
index 7ed1876..e79c86d 100644
--- a/doc/lispref/buffers.texi
+++ b/doc/lispref/buffers.texi
@@ -1064,7 +1064,7 @@ Buffer foo.changed modified; kill anyway? (yes or no)
@kbd{yes}
@end deffn
@defvar kill-buffer-query-functions
-After confirming unsaved changes, @code{kill-buffer} calls the functions
+Before confirming unsaved changes, @code{kill-buffer} calls the functions
in the list @code{kill-buffer-query-functions}, in order of appearance,
with no arguments. The buffer being killed is the current buffer when
they are called. The idea of this feature is that these functions will
diff --git a/src/ChangeLog b/src/ChangeLog
index e404cdb..a3af8d1 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,11 @@
+2013-06-28 Michal Nazarewicz <address@hidden>
+
+ * buffer.c (FKill_buffer): Run `kill-buffer-query-functions'
+ before checking whether buffer is modified. This lets
+ `kill-buffer-query-functions' cancel killing of the buffer or save
+ its content before `kill-buffer' asks user the "Buffer %s
+ modified; kill anyway?" question.
+
2013-06-28 Paul Eggert <address@hidden>
* image.c (x_from_xcolors): Remove unused local.
diff --git a/src/buffer.c b/src/buffer.c
index 08299da..ad670e0 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1734,18 +1734,6 @@ cleaning up all windows currently displaying the buffer
to be killed. */)
if (!BUFFER_LIVE_P (b))
return Qnil;
- /* Query if the buffer is still modified. */
- if (INTERACTIVE && !NILP (BVAR (b, filename))
- && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
- {
- GCPRO1 (buffer);
- tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
- BVAR (b, name), make_number (0)));
- UNGCPRO;
- if (NILP (tem))
- return Qnil;
- }
-
/* Run hooks with the buffer to be killed the current buffer. */
{
ptrdiff_t count = SPECPDL_INDEX ();
@@ -1761,6 +1749,22 @@ cleaning up all windows currently displaying the buffer
to be killed. */)
if (NILP (tem))
return unbind_to (count, Qnil);
+ /* Query if the buffer is still modified. */
+ if (INTERACTIVE && !NILP (BVAR (b, filename))
+ && BUF_MODIFF (b) > BUF_SAVE_MODIFF (b))
+ {
+ GCPRO1 (buffer);
+ tem = do_yes_or_no_p (format2 ("Buffer %s modified; kill anyway? ",
+ BVAR (b, name), make_number (0)));
+ UNGCPRO;
+ if (NILP (tem))
+ return unbind_to (count, Qnil);
+ }
+
+ /* If the hooks have killed the buffer, exit now. */
+ if (!BUFFER_LIVE_P (b))
+ return unbind_to (count, Qt);
+
/* Then run the hooks. */
Frun_hooks (1, &Qkill_buffer_hook);
unbind_to (count, Qnil);
--
1.8.3.1