From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#45688: 28.0.50; New action for display-buffer? Date: Tue, 19 Jan 2021 19:52:20 +0200 Organization: LINKOV.NET Message-ID: <87mtx4c04z.fsf@mail.linkov.net> References: <87im8a1dff.fsf@gnus.org> <83y2h6133r.fsf@gnu.org> <8735ze0yp7.fsf@gnus.org> <83o8i20w1f.fsf@gnu.org> <87lfd5yny9.fsf@gnus.org> <87ft3cpoy9.fsf@mail.linkov.net> <6859d73c-da77-af77-481f-3046d5195d53@gmx.at> <87pn2dvxqi.fsf@gnus.org> <87v9c2rpfi.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28295"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu) Cc: 45688@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jan 19 19:36:35 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l1vrm-0007HC-F5 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Jan 2021 19:36:34 +0100 Original-Received: from localhost ([::1]:36642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1vrl-00043P-Do for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Jan 2021 13:36:33 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1vIT-0005XT-Dm for bug-gnu-emacs@gnu.org; Tue, 19 Jan 2021 13:00:05 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:40061) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1vIT-0004sJ-2t for bug-gnu-emacs@gnu.org; Tue, 19 Jan 2021 13:00:05 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l1vIS-0002ap-Vc for bug-gnu-emacs@gnu.org; Tue, 19 Jan 2021 13:00:04 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 19 Jan 2021 18:00:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45688 X-GNU-PR-Package: emacs Original-Received: via spool by 45688-submit@debbugs.gnu.org id=B45688.16110791559741 (code B ref 45688); Tue, 19 Jan 2021 18:00:04 +0000 Original-Received: (at 45688) by debbugs.gnu.org; 19 Jan 2021 17:59:15 +0000 Original-Received: from localhost ([127.0.0.1]:51596 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1vHf-0002X2-8t for submit@debbugs.gnu.org; Tue, 19 Jan 2021 12:59:15 -0500 Original-Received: from relay6-d.mail.gandi.net ([217.70.183.198]:51969) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1vHZ-0002WK-RJ for 45688@debbugs.gnu.org; Tue, 19 Jan 2021 12:59:10 -0500 X-Originating-IP: 91.129.98.64 Original-Received: from mail.gandi.net (m91-129-98-64.cust.tele2.ee [91.129.98.64]) (Authenticated sender: juri@linkov.net) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 2ADB2C0003; Tue, 19 Jan 2021 17:59:01 +0000 (UTC) In-Reply-To: <87v9c2rpfi.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 12 Jan 2021 20:36:33 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:198194 Archived-At: --=-=-= Content-Type: text/plain > One problem is that other display-buffer actions don't set > 'display-buffer-previous-window'. It would be nice to do > this in some low-level function in window.el. If this is impossible to add this to window.el then a workaround is to use such advice that helps to visit grep/xref hits in the window where all previous hits were visited: #+begin_src emacs-lisp (advice-add 'window--display-buffer :around (lambda (orig-fun &rest args) (let ((buffer (current-buffer)) (window (apply orig-fun args))) (with-current-buffer buffer (setq-local display-buffer-previous-window window)) window)) '((name . window--display-buffer-set-previous-window))) (defvar-local display-buffer-previous-window nil) (defun display-buffer-from-grep-p (_buffer-name _action) (with-current-buffer (window-buffer) (derived-mode-p 'compilation-mode))) (add-to-list 'display-buffer-alist '(display-buffer-from-grep-p nil (previous-window . display-buffer-previous-window))) #+end_src The only problem is that display-buffer-in-previous-window doesn't support 'previous-window' as a variable, only as a value, i.e. currently it only supports: `(previous-window . ,display-buffer-previous-window) maybe the following patch could be installed to support also '(previous-window . display-buffer-previous-window) --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=previous-window.patch diff --git a/lisp/window.el b/lisp/window.el index 0a37d16273..d6b3d69b3d 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -8239,6 +8239,7 @@ display-buffer-in-previous-window 0) (display-buffer-reuse-frames 0) (t (last-nonminibuffer-frame)))) + (previous-window (cdr (assq 'previous-window alist))) best-window second-best-window window) ;; Scan windows whether they have shown the buffer recently. (catch 'best @@ -8252,7 +8253,9 @@ display-buffer-in-previous-window (throw 'best t))))) ;; When ALIST has a `previous-window' entry, that entry may override ;; anything we found so far. - (when (and (setq window (cdr (assq 'previous-window alist))) + (when (and previous-window (boundp previous-window)) + (setq previous-window (symbol-value previous-window))) + (when (and (setq window previous-window) (window-live-p window) (or (eq buffer (window-buffer window)) (not (window-dedicated-p window)))) --=-=-=--