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