bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#45688: 28.0.50; New action for display-buffer?


From: Juri Linkov
Subject: bug#45688: 28.0.50; New action for display-buffer?
Date: Tue, 19 Jan 2021 19:52:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

> 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)

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))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]