From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#32790: 27.0.50; point jumps unexpectedly after delete-window Date: Sun, 25 Nov 2018 23:01:34 +0200 Organization: LINKOV.NET Message-ID: <87bm6can2p.fsf@mail.linkov.net> References: <87efdnsp2k.fsf@mail.linkov.net> <87r2foa8gq.fsf@mail.linkov.net> <5BEBDDCB.6090608@gmx.at> <87va4zfapq.fsf@mail.linkov.net> <5BED38A6.6020206@gmx.at> <87ftw2q74g.fsf@mail.linkov.net> <5BEE85A5.2070309@gmx.at> <878t1ruz4m.fsf@mail.linkov.net> <5BF12FB6.20203@gmx.at> <87o9am3smz.fsf@mail.linkov.net> <5BF2858C.40207@gmx.at> <87va4szo8n.fsf@mail.linkov.net> <5BF3D3D4.1080106@gmx.at> <87pnuzz2vf.fsf@mail.linkov.net> <5BF5151B.5000201@gmx.at> <87ftvu9f20.fsf@mail.linkov.net> <5BF65D56.9020806@gmx.at> <87pnuwenpk.fsf@mail.linkov.net> <5BF7AEC5.60808@gmx.at> <87va4mdoya.fsf@mail.linkov.net> <5BFA5BF3.50505@gmx.at> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1543180734 22810 195.159.176.226 (25 Nov 2018 21:18:54 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 25 Nov 2018 21:18:54 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 32790@debbugs.gnu.org To: martin rudalics Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Nov 25 22:18:49 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1gR1nl-0005q9-Jj for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Nov 2018 22:18:49 +0100 Original-Received: from localhost ([::1]:33132 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gR1pr-0002Zi-VN for geb-bug-gnu-emacs@m.gmane.org; Sun, 25 Nov 2018 16:21:00 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gR1gI-00026E-PS for bug-gnu-emacs@gnu.org; Sun, 25 Nov 2018 16:11:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gR1gE-0008R3-Ny for bug-gnu-emacs@gnu.org; Sun, 25 Nov 2018 16:11:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:43405) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gR1gE-0008Qy-JQ for bug-gnu-emacs@gnu.org; Sun, 25 Nov 2018 16:11:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gR1gE-0008TD-EX for bug-gnu-emacs@gnu.org; Sun, 25 Nov 2018 16:11:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 25 Nov 2018 21:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32790 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 32790-submit@debbugs.gnu.org id=B32790.154318022732507 (code B ref 32790); Sun, 25 Nov 2018 21:11:02 +0000 Original-Received: (at 32790) by debbugs.gnu.org; 25 Nov 2018 21:10:27 +0000 Original-Received: from localhost ([127.0.0.1]:47662 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gR1ff-0008SF-61 for submit@debbugs.gnu.org; Sun, 25 Nov 2018 16:10:27 -0500 Original-Received: from goldenrod.birch.relay.mailchannels.net ([23.83.209.74]:31761) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gR1fd-0008S6-Mb for 32790@debbugs.gnu.org; Sun, 25 Nov 2018 16:10:26 -0500 X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 85E0B5C492C; Sun, 25 Nov 2018 21:10:24 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a3.g.dreamhost.com (unknown [100.96.35.77]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 368D25C4926; Sun, 25 Nov 2018 21:10:24 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|jurta@jurta.org Original-Received: from pdx1-sub0-mail-a3.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.16.2); Sun, 25 Nov 2018 21:10:24 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Reaction-Supply: 10dcb61b3f2f51f0_1543180224347_4044298686 X-MC-Loop-Signature: 1543180224347:4036069892 X-MC-Ingress-Time: 1543180224346 Original-Received: from pdx1-sub0-mail-a3.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a3.g.dreamhost.com (Postfix) with ESMTP id F120681053; Sun, 25 Nov 2018 13:10:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=trIQYmO8MxZabJVngiXGWuAMm0I=; b= IZJ+KIbjH9mfCzQ3NpZkaUo4H6IkxNg2oSfKuSrbx21+nFHgANdlfrHJsaIccxVV OyjKVoywRZc3R5t6TgjL5Irugoi6MrUTbHlaODCUCjmzAjCStEscKa39SfSRwN6m ztfVvs57ClnLWZ4PRqQ1V5ATCX6+Mg8Nd4qC/II0OXE= Original-Received: from mail.jurta.org (m91-129-107-242.cust.tele2.ee [91.129.107.242]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a3.g.dreamhost.com (Postfix) with ESMTPSA id D892981054; Sun, 25 Nov 2018 13:10:21 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a3 In-Reply-To: <5BFA5BF3.50505@gmx.at> (martin rudalics's message of "Sun, 25 Nov 2018 09:23:15 +0100") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedrudduhedgudehtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucggtfgfnhhsuhgsshgtrhhisggvpdfftffgtefojffquffvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvffuohhfffgjkfgfgggtsehmtderredtredtnecuhfhrohhmpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqnecukfhppeeluddruddvledruddtjedrvdegvdenucfrrghrrghmpehmohguvgepshhmthhppdhhvghlohepmhgrihhlrdhjuhhrthgrrdhorhhgpdhinhgvthepledurdduvdelrddutdejrddvgedvpdhrvghtuhhrnhdqphgrthhhpefluhhrihcunfhinhhkohhvuceojhhurhhisehlihhnkhhovhdrnhgvtheqpdhmrghilhhfrhhomhepjhhurhhisehlihhnkhhovhdrnhgvthdpnhhrtghpthhtoheprhhuuggrlhhitghssehgmhigrdgrthenucevlhhushhtvghrufhiiigvpedt X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:152771 Archived-At: --=-=-= Content-Type: text/plain > - ((eq buffer (window-buffer))) > + ((and (eq buffer (window-buffer)) > + (not switch-to-buffer-pop-to))) > > This would show the buffer twice even when it already appears in the > same window, right? Are you sure that this is TRT? Unconditionally? This change is intentional. If the user requests to display the same buffer in another window, we have to follow user's request - it's a normal wish to display the same buffer in two different windows. > BTW your patch does not apply here well due to some whitespace > mismatches. Sorry, I created the previous patch ignoring whitespace changes, so it would be easier for you to see differences. But now it should apply properly with this new patch that takes into account all your comments: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=switch-to-buffer-pop.2.patch diff --git a/lisp/window.el b/lisp/window.el index 43a742b2d8..60daa9f070 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -7779,6 +7779,13 @@ switch-to-buffer-in-dedicated-window :group 'windows :version "25.1") +(defcustom switch-to-buffer-pop nil + "If non-nil, have `switch-to-buffer' run `pop-to-buffer-same-window'. +This allows customization of actions for `display-buffer'." + :type 'boolean + :group 'windows + :version "27.1") + (defun switch-to-buffer (buffer-or-name &optional norecord force-same-window) "Display buffer BUFFER-OR-NAME in the selected window. @@ -7820,29 +7827,32 @@ switch-to-buffer Return the buffer switched to." (interactive (let ((force-same-window - (cond - ((window-minibuffer-p) nil) - ((not (eq (window-dedicated-p) t)) 'force-same-window) - ((pcase switch-to-buffer-in-dedicated-window - (`nil (user-error - "Cannot switch buffers in a dedicated window")) - (`prompt - (if (y-or-n-p - (format "Window is dedicated to %s; undedicate it" - (window-buffer))) - (progn - (set-window-dedicated-p nil nil) - 'force-same-window) - (user-error - "Cannot switch buffers in a dedicated window"))) - (`pop nil) - (_ (set-window-dedicated-p nil nil) 'force-same-window)))))) + (unless switch-to-buffer-pop + (cond + ((window-minibuffer-p) nil) + ((not (eq (window-dedicated-p) t)) 'force-same-window) + ((pcase switch-to-buffer-in-dedicated-window + (`nil (user-error + "Cannot switch buffers in a dedicated window")) + (`prompt + (if (y-or-n-p + (format "Window is dedicated to %s; undedicate it" + (window-buffer))) + (progn + (set-window-dedicated-p nil nil) + 'force-same-window) + (user-error + "Cannot switch buffers in a dedicated window"))) + (`pop nil) + (_ (set-window-dedicated-p nil nil) 'force-same-window))))))) (list (read-buffer-to-switch "Switch to buffer: ") nil force-same-window))) - (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name))) + (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)) + (set-window-start-and-point (not switch-to-buffer-pop))) (cond ;; Don't call set-window-buffer if it's not needed since it ;; might signal an error (e.g. if the window is dedicated). - ((eq buffer (window-buffer))) + ((and (eq buffer (window-buffer)) + (not switch-to-buffer-pop))) ((window-minibuffer-p) (if force-same-window (user-error "Cannot switch buffers in minibuffer window") @@ -7852,18 +7862,25 @@ switch-to-buffer (user-error "Cannot switch buffers in a dedicated window") (pop-to-buffer buffer norecord))) (t - (let* ((entry (assq buffer (window-prev-buffers))) - (displayed (and (eq switch-to-buffer-preserve-window-point - 'already-displayed) - (get-buffer-window buffer 0)))) - (set-window-buffer nil buffer) - (when (and entry - (or (eq switch-to-buffer-preserve-window-point t) - displayed)) - ;; Try to restore start and point of buffer in the selected - ;; window (Bug#4041). - (set-window-start (selected-window) (nth 1 entry) t) - (set-window-point nil (nth 2 entry)))))) + (when switch-to-buffer-pop + (let ((selected-window (selected-window))) + (pop-to-buffer-same-window buffer norecord) + (when (eq (selected-window) selected-window) + (setq set-window-start-and-point t)))) + + (when set-window-start-and-point + (let* ((entry (assq buffer (window-prev-buffers))) + (displayed (and (eq switch-to-buffer-preserve-window-point + 'already-displayed) + (get-buffer-window buffer 0)))) + (set-window-buffer nil buffer) + (when (and entry + (or (eq switch-to-buffer-preserve-window-point t) + displayed)) + ;; Try to restore start and point of buffer in the selected + ;; window (Bug#4041). + (set-window-start (selected-window) (nth 1 entry) t) + (set-window-point nil (nth 2 entry))))))) (unless norecord (select-window (selected-window))) --=-=-=--