From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel 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 Message-ID: References: <83inpg9ib5.fsf@gnu.org> <83d1fn9dio.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1484663290 24811 195.159.176.226 (17 Jan 2017 14:28:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 17 Jan 2017 14:28:10 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 17 15:28:02 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cTUjt-00055C-Gw for ged-emacs-devel@m.gmane.org; Tue, 17 Jan 2017 15:27:57 +0100 Original-Received: from localhost ([::1]:35812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cTUju-0006MF-T5 for ged-emacs-devel@m.gmane.org; Tue, 17 Jan 2017 09:27:58 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44459) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cTUjH-0006M9-KV for emacs-devel@gnu.org; Tue, 17 Jan 2017 09:27:20 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cTUjC-0003qG-GB for emacs-devel@gnu.org; Tue, 17 Jan 2017 09:27:19 -0500 Original-Received: from [195.159.176.226] (port=51793 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cTUjC-0003pn-96 for emacs-devel@gnu.org; Tue, 17 Jan 2017 09:27:14 -0500 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cTUiw-0000pr-RZ for emacs-devel@gnu.org; Tue, 17 Jan 2017 15:26:58 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 52 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:lWVvILbbWKuLw/X/hBm+m3IRy8Q= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:211347 Archived-At: > 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;