all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
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	[thread overview]
Message-ID: <jwv7f5t7oja.fsf-monnier+gmane.emacs.devel@gnu.org> (raw)
In-Reply-To: CAFkz2yoQX5jCZc82apBSPwUrNok=Ngqj4ozGEFWoCYvd2G==+w@mail.gmail.com

> 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	other threads:[~2017-01-17 14:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-15 19:32 kill-buffer calls frame's buffer-predicate for all buffers even if the killed buffer was not shown in any window Constantin Kulikov
2017-01-15 20:31 ` Eli Zaretskii
2017-01-16  8:14   ` Constantin Kulikov
2017-01-16 16:26     ` Eli Zaretskii
2017-01-16 16:55       ` Eli Zaretskii
2017-01-16 22:21       ` Constantin Kulikov
2017-01-17 14:26         ` Stefan Monnier [this message]
2017-01-17 14:40         ` Constantin Kulikov
2017-01-18 10:03           ` Constantin Kulikov
2017-01-18 15:43             ` Eli Zaretskii

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=jwv7f5t7oja.fsf-monnier+gmane.emacs.devel@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --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.