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: Thu, 29 Nov 2018 01:25:18 +0200 Organization: LINKOV.NET Message-ID: <87woowrdi9.fsf@mail.linkov.net> References: <87efdnsp2k.fsf@mail.linkov.net> <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> <87bm6can2p.fsf@mail.linkov.net> <5BFBBDD4.7050100@gmx.at> <87pnurjt92.fsf@mail.linkov.net> <83lg5fgivk.fsf@gnu.org> <87h8g2m9ii.fsf@mail.linkov.net> <5BFE52CC.4000600@gmx.at> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1543449142 22127 195.159.176.226 (28 Nov 2018 23:52:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 28 Nov 2018 23:52:22 +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 Thu Nov 29 00:52:17 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 1gS9cv-0005cc-7s for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Nov 2018 00:52:17 +0100 Original-Received: from localhost ([::1]:50429 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gS9f1-0005o6-Ex for geb-bug-gnu-emacs@m.gmane.org; Wed, 28 Nov 2018 18:54:27 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47910) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gS9ej-0005k1-T3 for bug-gnu-emacs@gnu.org; Wed, 28 Nov 2018 18:54:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gS9ef-0005I1-Eq for bug-gnu-emacs@gnu.org; Wed, 28 Nov 2018 18:54:09 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:49658) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gS9ed-0005Gt-Tc for bug-gnu-emacs@gnu.org; Wed, 28 Nov 2018 18:54:05 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gS9ed-0003zu-RT for bug-gnu-emacs@gnu.org; Wed, 28 Nov 2018 18:54:03 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 28 Nov 2018 23:54:03 +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.154344924215344 (code B ref 32790); Wed, 28 Nov 2018 23:54:03 +0000 Original-Received: (at 32790) by debbugs.gnu.org; 28 Nov 2018 23:54:02 +0000 Original-Received: from localhost ([127.0.0.1]:53913 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gS9eb-0003zJ-Kt for submit@debbugs.gnu.org; Wed, 28 Nov 2018 18:54:02 -0500 Original-Received: from quail.birch.relay.mailchannels.net ([23.83.209.151]:7657) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gS9eX-0003yw-Sq for 32790@debbugs.gnu.org; Wed, 28 Nov 2018 18:53:58 -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 B2C14283073; Wed, 28 Nov 2018 23:53:56 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a3.g.dreamhost.com (unknown [100.96.30.62]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 71639282FF6; Wed, 28 Nov 2018 23:53:56 +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); Wed, 28 Nov 2018 23:53:56 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Soft-White: 084166db52749ebf_1543449236596_430480849 X-MC-Loop-Signature: 1543449236596:144749023 X-MC-Ingress-Time: 1543449236596 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 3F3F680A2D; Wed, 28 Nov 2018 15:53:56 -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=Z6nIUC4fQKZsfs1gxDYOx2W/uKU=; b= qzbRBhbSS4nb5OpLsNtC2GprOeka9w6iQKF4TazQCgs+cAghRs6LVKLvsItSG4rT HHa1WafOW4wl2mRsdw3/28tc7P1VZ1ySl8dn0d0eCd+ajUPO7O5L+fcgxZXO2N+Z 2nkjNhjyZ5QJjqxmcSOuYGAPVRjjcsNA/AGQImYHdIs= 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 6216980A2C; Wed, 28 Nov 2018 15:53:52 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a3 In-Reply-To: <5BFE52CC.4000600@gmx.at> (martin rudalics's message of "Wed, 28 Nov 2018 09:33:16 +0100") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedruddvvddgudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesthdtredttdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrddutdejrddvgedvnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehmrghilhdrjhhurhhtrgdrohhrghdpihhnvghtpeeluddruddvledruddtjedrvdegvddprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopehruhgurghlihgtshesghhmgidrrghtnecuvehluhhsthgvrhfuihiivgepud 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:152874 Archived-At: > I don't think this is right because 'switch-to-buffer' does not have a > display action it can pass to 'display-buffer'. The behavior is > subject to 'display-buffer-overriding-action', 'display-buffer-alist' > and other related variables alone IIUC. > > Furthermore, the doc-string of 'switch-to-buffer' should be amended > like: > > If the option 'switch-to-buffer-obey-display-actions' is non-nil, run > the function 'pop-to-buffer-same-window' instead. This may display > the buffer in an arbitrary window as specified by > 'display-buffer-overriding-action', 'display-buffer-alist' and other > display related variables. If this results in displaying the buffer > in the selected window, window start and point are adjusted as > prescribed by the option `switch-to-buffer-preserve-window-point'. > Otherwise, these are left alone. > > And the following part of the doc-string > > If optional argument FORCE-SAME-WINDOW is non-nil, the buffer > must be displayed in the selected window when called > non-interactively; if that is impossible, signal an error rather > than calling `pop-to-buffer'. > > is presumably invalid when 'switch-to-buffer-obey-display-actions' is > non-nil. Right? Is this better? diff --git a/lisp/window.el b/lisp/window.el index 2634955a75..bc07300f0c 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -7779,6 +7779,16 @@ switch-to-buffer-in-dedicated-window :group 'windows :version "25.1") +(defcustom switch-to-buffer-obey-display-actions nil + "If non-nil, have `switch-to-buffer' run `pop-to-buffer-same-window'. +This means that when switching the buffer it respects display actions +specified by `display-buffer-overriding-action', `display-buffer-alist' +and other display related variables. So `switch-to-buffer' will display +the buffer in the window specified by the rules from these variables." + :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. @@ -7811,15 +7821,26 @@ switch-to-buffer If optional argument FORCE-SAME-WINDOW is non-nil, the buffer must be displayed in the selected window when called non-interactively; if that is impossible, signal an error rather -than calling `pop-to-buffer'. +than calling `pop-to-buffer'. It has no effect when the option +`switch-to-buffer-obey-display-actions' is non-nil. The option `switch-to-buffer-preserve-window-point' can be used to make the buffer appear at its last position in the selected window. +If the option `switch-to-buffer-obey-display-actions' is non-nil, +run the function `pop-to-buffer-same-window' instead. +This may display the buffer in another window as specified by +`display-buffer-overriding-action', `display-buffer-alist' and +other display related variables. If this results in displaying +the buffer in the selected window, window start and point are adjusted +as prescribed by the option `switch-to-buffer-preserve-window-point'. +Otherwise, these are left alone. + Return the buffer switched to." (interactive (let ((force-same-window + (unless switch-to-buffer-obey-display-actions (cond ((window-minibuffer-p) nil) ((not (eq (window-dedicated-p) t)) 'force-same-window) @@ -7836,13 +7857,17 @@ switch-to-buffer (user-error "Cannot switch buffers in a dedicated window"))) ('pop nil) - (_ (set-window-dedicated-p nil nil) 'force-same-window)))))) + (_ (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-obey-display-actions))) (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)) + ;; pop-to-buffer-same-window might decide to display + ;; the same buffer in another window + (not switch-to-buffer-obey-display-actions))) ((window-minibuffer-p) (if force-same-window (user-error "Cannot switch buffers in minibuffer window") @@ -7852,6 +7877,13 @@ switch-to-buffer (user-error "Cannot switch buffers in a dedicated window") (pop-to-buffer buffer norecord))) (t + (when switch-to-buffer-obey-display-actions + (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) @@ -7863,7 +7895,7 @@ switch-to-buffer ;; 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)))))) + (set-window-point nil (nth 2 entry))))))) (unless norecord (select-window (selected-window)))