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: Fri, 30 Nov 2018 00:50:34 +0200 Organization: LINKOV.NET Message-ID: <87tvjz8pmt.fsf@mail.linkov.net> References: <87efdnsp2k.fsf@mail.linkov.net> <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> <87woowrdi9.fsf@mail.linkov.net> <5BFFA3C0.9070102@gmx.at> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1543532058 3377 195.159.176.226 (29 Nov 2018 22:54:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 29 Nov 2018 22:54:18 +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 23:54:14 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 1gSVCG-0000f8-3N for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Nov 2018 23:54:12 +0100 Original-Received: from localhost ([::1]:56986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSVEM-0003k2-GY for geb-bug-gnu-emacs@m.gmane.org; Thu, 29 Nov 2018 17:56:22 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54147) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gSVE6-0003g1-Fd for bug-gnu-emacs@gnu.org; Thu, 29 Nov 2018 17:56:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gSVE3-0002pL-A0 for bug-gnu-emacs@gnu.org; Thu, 29 Nov 2018 17:56:06 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51016) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gSVE3-0002pE-5N for bug-gnu-emacs@gnu.org; Thu, 29 Nov 2018 17:56:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gSVE3-0008Gx-3E for bug-gnu-emacs@gnu.org; Thu, 29 Nov 2018 17:56: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: Thu, 29 Nov 2018 22:56: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.154353215231773 (code B ref 32790); Thu, 29 Nov 2018 22:56:03 +0000 Original-Received: (at 32790) by debbugs.gnu.org; 29 Nov 2018 22:55:52 +0000 Original-Received: from localhost ([127.0.0.1]:55273 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gSVDs-0008GP-9t for submit@debbugs.gnu.org; Thu, 29 Nov 2018 17:55:52 -0500 Original-Received: from cichlid.maple.relay.mailchannels.net ([23.83.214.36]:13164) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gSVDo-0008GF-50 for 32790@debbugs.gnu.org; Thu, 29 Nov 2018 17:55:49 -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 25C9A3E473F; Thu, 29 Nov 2018 22:55:47 +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 D4A2C3E401B; Thu, 29 Nov 2018 22:55:46 +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); Thu, 29 Nov 2018 22:55:47 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Stop-Thread: 5a055cf726374c01_1543532146971_674961800 X-MC-Loop-Signature: 1543532146971:333558470 X-MC-Ingress-Time: 1543532146970 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 9A75D7F6D0; Thu, 29 Nov 2018 14:55:46 -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=gq5AYmcHr6MDbnx75B77u8cnhGI=; b= ab3W4WnRdEUNRHvt8CziF4L598D9gGmnztdLuv4hvK+3gaVERi+a9W4DmHTFiY7A D3/e4JMrNUKNN7cLcjVpvdHauuG258ejcHgx4jUeZo22UaDkMj3vSAETb2WD/2GT ScfemOahNOq3YqFkMgx8YndFa+30jqM2487Ef9I35IE= 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 261257F6CD; Thu, 29 Nov 2018 14:55:43 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a3 In-Reply-To: <5BFFA3C0.9070102@gmx.at> (martin rudalics's message of "Thu, 29 Nov 2018 09:30:56 +0100") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedruddvgedgtdelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesmhdtreertdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrddutdejrddvgedvnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehmrghilhdrjhhurhhtrgdrohhrghdpihhnvghtpeeluddruddvledruddtjedrvdegvddprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopehruhgurghlihgtshesghhmgidrrghtnecuvehluhhsthgvrhfuihiivgepud 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:152906 Archived-At: --=-=-= Content-Type: text/plain >> Is this better? > > I think so but the patch again doesn't apply for some reason. Can you > resend it as attachment, please? Sorry, no code changes were performed, so I thought it would be better to see just documentation changes ignoring whitespace differences. But here it's a complete patch: --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=switch-to-buffer-obey-display-actions.patch 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,38 +7821,53 @@ 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 - (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-obey-display-actions + (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-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,18 +7877,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-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) + (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))) --=-=-=--