emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: kill-buffer calls frame's buffer-predicate for all buffers even if t


From: Stefan Monnier
Subject: Re: kill-buffer calls frame's buffer-predicate for all buffers even if the killed buffer was not shown in any window.
Date: Tue, 17 Jan 2017 09:26:37 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

> Ok, here is my attempt to code this:
> https://github.com/Bad-ptr/emacs/commit/cf6b0d9f08dbdc5dd685dbc6a5ef9ff18575e2b2
> This seem to work for my example from the start of discussion(not tested it
> much for now).

Here's an alternative, which reuses the existing `other_buffer_safely`,
and which only modifies the behavior in the case that the buffer is not
displayed in any window.  I included in it an optimization: don't call
replace_buffer_in_windows if the buffer is not displayed.


        Stefan


diff --git a/src/buffer.c b/src/buffer.c
index d62c79df09..418ab3698e 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1642,6 +1642,7 @@ cleaning up all windows currently displaying the buffer 
to be killed.  */)
   struct buffer *b;
   Lisp_Object tem;
   struct Lisp_Marker *m;
+  bool visible;
 
   if (NILP (buffer_or_name))
     buffer = Fcurrent_buffer ();
@@ -1725,11 +1726,14 @@ cleaning up all windows currently displaying the buffer 
to be killed.  */)
        return Qt;
     }
 
+  visible = buffer_window_count (XBUFFER (buffer));
+
   /* Run replace_buffer_in_windows before making another buffer current
      since set-window-buffer-start-and-point will refuse to make another
      buffer current if the selected window does not show the current
      buffer (bug#10114).  */
-  replace_buffer_in_windows (buffer);
+  if (visible)
+    replace_buffer_in_windows (buffer);
 
   /* Exit if replacing the buffer in windows has killed our buffer.  */
   if (!BUFFER_LIVE_P (b))
@@ -1739,7 +1743,8 @@ cleaning up all windows currently displaying the buffer 
to be killed.  */)
      buffer.  */
   if (b == current_buffer)
     {
-      tem = Fother_buffer (buffer, Qnil, Qnil);
+      tem = visible ? Fother_buffer (buffer, Qnil, Qnil)
+            : other_buffer_safely (buffer);
       Fset_buffer (tem);
       if (b == current_buffer)
        return Qnil;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]