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: Mon, 03 Dec 2018 02:45:35 +0200 Organization: LINKOV.NET Message-ID: <87sgzftohw.fsf@mail.linkov.net> References: <87efdnsp2k.fsf@mail.linkov.net> <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> <87tvjz8pmt.fsf@mail.linkov.net> <5C00F336.8010406@gmx.at> <878t18eumi.fsf@mail.linkov.net> <5C039907.5030104@gmx.at> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1543800473 14504 195.159.176.226 (3 Dec 2018 01:27:53 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 3 Dec 2018 01:27:53 +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 Mon Dec 03 02:27: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 1gTd1X-0003ec-6S for geb-bug-gnu-emacs@m.gmane.org; Mon, 03 Dec 2018 02:27:47 +0100 Original-Received: from localhost ([::1]:46373 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTd3d-0006nj-Ju for geb-bug-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 20:29:57 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTd2s-0006Mf-Ka for bug-gnu-emacs@gnu.org; Sun, 02 Dec 2018 20:29:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTd2m-0002Gg-D1 for bug-gnu-emacs@gnu.org; Sun, 02 Dec 2018 20:29:10 -0500 Original-Received: from debbugs.gnu.org ([208.118.235.43]:54295) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gTd2l-0002FA-0U for bug-gnu-emacs@gnu.org; Sun, 02 Dec 2018 20:29:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gTd2k-0005C0-Sr for bug-gnu-emacs@gnu.org; Sun, 02 Dec 2018 20:29: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: Mon, 03 Dec 2018 01:29: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.154380053319910 (code B ref 32790); Mon, 03 Dec 2018 01:29:02 +0000 Original-Received: (at 32790) by debbugs.gnu.org; 3 Dec 2018 01:28:53 +0000 Original-Received: from localhost ([127.0.0.1]:58548 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gTd2a-0005Az-Il for submit@debbugs.gnu.org; Sun, 02 Dec 2018 20:28:52 -0500 Original-Received: from eastern.maple.relay.mailchannels.net ([23.83.214.55]:22481) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gTd2Z-0005Ap-Dv for 32790@debbugs.gnu.org; Sun, 02 Dec 2018 20:28:52 -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 083EF40744; Mon, 3 Dec 2018 01:28:50 +0000 (UTC) Original-Received: from pdx1-sub0-mail-a3.g.dreamhost.com (unknown [100.96.20.98]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id B643D409A6; Mon, 3 Dec 2018 01:28:49 +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); Mon, 03 Dec 2018 01:28:49 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|jurta@jurta.org X-MailChannels-Auth-Id: dreamhost X-Occur-Trail: 7504a2a00f5864e8_1543800529895_1296626443 X-MC-Loop-Signature: 1543800529894:2040318408 X-MC-Ingress-Time: 1543800529894 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 7F98980247; Sun, 2 Dec 2018 17:28:49 -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=O68faCOJCPCg2tg605ow/wbfPB4=; b= jDphvZRsQLG7Kh4Adk7TdHDzQbIjfkXVcrX2r50/N1KUFyHl8qBKvcmbP6WVQ9gE pMflOB2eW11u0qpuYUwInshKuz6D6DM3visxbcW1mOt/h0QCACju3c3gWKT9wTzC 5F79JJts14NOGHt8jxigAhkEu+LfsryVySY66qMCDl0= 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 0FF148023F; Sun, 2 Dec 2018 17:28:46 -0800 (PST) X-DH-BACKEND: pdx1-sub0-mail-a3 In-Reply-To: <5C039907.5030104@gmx.at> (martin rudalics's message of "Sun, 02 Dec 2018 09:34:15 +0100") X-VR-OUT-STATUS: OK X-VR-OUT-SCORE: -100 X-VR-OUT-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedtkedrudeftddgtdehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpffftgfetoffjqffuvfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufhofhffjgfkfgggtgesmhdtreertdertdenucfhrhhomheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqeenucfkphepledurdduvdelrddutdejrddvgedvnecurfgrrhgrmhepmhhouggvpehsmhhtphdphhgvlhhopehmrghilhdrjhhurhhtrgdrohhrghdpihhnvghtpeeluddruddvledruddtjedrvdegvddprhgvthhurhhnqdhprghthheplfhurhhiucfnihhnkhhovhcuoehjuhhriheslhhinhhkohhvrdhnvghtqedpmhgrihhlfhhrohhmpehjuhhriheslhhinhhkohhvrdhnvghtpdhnrhgtphhtthhopehruhgurghlihgtshesghhmgidrrghtnecuvehluhhsthgvrhfuihiivgepud 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:153014 Archived-At: --=-=-= Content-Type: text/plain >>> These ones stupefied me when I tried to study your patch yesterday. >>> When 'switch-to-buffer-obey-display-actions' is non-nil you do not >>> reset 'force-same-window' so you can get an error when this is t and >>> you're either in the minibuffer or the window is strongly dedicated. >>> Right? >> >> I don't understand how 'force-same-window' can be non-nil if there is >> a condition "unless switch-to-buffer-obey-display-actions" in the >> interactive spec. But if some code calls 'switch-to-buffer' >> non-interactively with non-nil 'force-same-window', should it >> signal an error when 'pop-to-buffer-same-window' displays the buffer >> in another window? > > The non-interactive case is the one I had in mind. I think we mean to > say that FORCE-SAME-WINDOW has no impact in that case and We already added this to the docstring two patches ago. This was the part of that change: 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. > 'switch-to-buffer' should not signal an error when the window is > dedicated or the minibuffer window but try to automatically display > the buffer in a window of its choice instead. Do you think this is right? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=switch-to-buffer-obey-display-actions.3.patch diff --git a/lisp/window.el b/lisp/window.el index 2634955a75..8313f71b54 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -7743,8 +7743,10 @@ switch-to-buffer-preserve-window-point position in the selected window. This variable is ignored if the buffer is already displayed in -the selected window or never appeared in it before, or if -`switch-to-buffer' calls `pop-to-buffer' to display the buffer." +the selected window, or never appeared in it before, or if +`switch-to-buffer' calls `pop-to-buffer' to display the buffer, +or non-nil `switch-to-buffer-obey-display-actions' displays it +in another window." :type '(choice (const :tag "Never" nil) (const :tag "If already displayed elsewhere" already-displayed) @@ -7779,6 +7781,16 @@ switch-to-buffer-in-dedicated-window :group 'windows :version "25.1") +(defcustom switch-to-buffer-obey-display-actions nil + "If non-nil, `switch-to-buffer' runs `pop-to-buffer-same-window' instead. +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,59 +7823,83 @@ 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))) - ((window-minibuffer-p) + ((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))) + ((and (window-minibuffer-p) + (not switch-to-buffer-obey-display-actions)) (if force-same-window (user-error "Cannot switch buffers in minibuffer window") (pop-to-buffer buffer norecord))) - ((eq (window-dedicated-p) t) + ((and (eq (window-dedicated-p) t) + (not switch-to-buffer-obey-display-actions)) (if force-same-window (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))) --=-=-=--