From 99940106b40b1e0ac57b2138db425ea83ace8c7f Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Wed, 27 Nov 2024 03:43:22 +0200 Subject: [PATCH] Make Xref commands follow 'display-buffer' customizations * lisp/progmodes/xref.el (xref--show-pos-in-buf): Append '(category . xref-jump)' to display-buffer action argument, when the target window or frame is not made explicit by the command. (xref--switch-to-buffer): New function (bug#74361). Do the switch through 'pop-to-buffer' and use the new category. (xref-go-back, xref-go-forward, xref-pop-to-location): Use it. * etc/NEWS: Describe the change. (cherry picked from commit 0624fe6f8497a677ae354da0a604dbf82e69400a) --- etc/NEWS | 11 +++++++++++ lisp/progmodes/xref.el | 18 ++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 37964bbd178..6d458701af5 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -656,6 +656,17 @@ removing packages. When invoked with a prefix argument, 'package-install-selected-packages' will not prompt the user for confirmation before installing packages. +** Xref + +The commands that jump to some location use 'display-buffer' and specify +the category 'xref-jump'. As a result you can customize how the +destination window is chosen using 'display-buffer-alist'. Example: + + (setq display-buffer-alist '(((category . xref) + (display-buffer-reuse-window + display-buffer-use-some-window) + (some-window . mru)))) + * New Modes and Packages in Emacs 31.1 diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index 7e9987d0cc9..12ea6a3fe95 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -533,6 +533,9 @@ Erase the stack slots following this one." ;;;###autoload (define-obsolete-function-alias 'xref-pop-marker-stack #'xref-go-back "29.1") +(defun xref--switch-to-buffer (buf) + (pop-to-buffer buf '((display-buffer-same-window) (category . xref-jump)))) + ;;;###autoload (defun xref-go-back () "Go back to the previous position in xref history. @@ -543,8 +546,8 @@ To undo, use \\[xref-go-forward]." (user-error "At start of xref history") (let ((marker (pop (car history)))) (xref--push-forward (point-marker)) - (switch-to-buffer (or (marker-buffer marker) - (user-error "The marked buffer has been deleted"))) + (xref--switch-to-buffer (or (marker-buffer marker) + (user-error "The marked buffer has been deleted"))) (goto-char (marker-position marker)) (set-marker marker nil nil) (run-hooks 'xref-after-return-hook))))) @@ -558,8 +561,8 @@ To undo, use \\[xref-go-forward]." (user-error "At end of xref history") (let ((marker (pop (cdr history)))) (xref--push-backward (point-marker)) - (switch-to-buffer (or (marker-buffer marker) - (user-error "The marked buffer has been deleted"))) + (xref--switch-to-buffer (or (marker-buffer marker) + (user-error "The marked buffer has been deleted"))) (goto-char (marker-position marker)) (set-marker marker nil nil) (run-hooks 'xref-after-return-hook))))) @@ -632,7 +635,7 @@ If SELECT is non-nil, select the target window." (xref-location-marker (xref-item-location item)))) (buf (marker-buffer marker))) (cl-ecase action - ((nil) (switch-to-buffer buf)) + ((nil) (xref--switch-to-buffer buf)) (window (pop-to-buffer buf t)) (frame (let ((pop-up-frames t)) (pop-to-buffer buf t)))) (xref--goto-char marker)) @@ -725,7 +728,10 @@ and finally return the window." (or (not (window-dedicated-p xref--original-window)) (eq (window-buffer xref--original-window) buf))) `((xref--display-buffer-in-window) - (window . ,xref--original-window)))))) + (category . xref-jump) + (window . ,xref--original-window))) + (t + '(nil (category . xref-jump)))))) (with-selected-window (display-buffer buf action) (xref--goto-char pos) (run-hooks 'xref-after-jump-hook) -- 2.39.2