]> git.eshelyaron.com Git - emacs.git/commitdiff
Make Xref commands follow 'display-buffer' customizations
authorDmitry Gutov <dmitry@gutov.dev>
Wed, 27 Nov 2024 01:43:22 +0000 (03:43 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 27 Nov 2024 19:56:26 +0000 (20:56 +0100)
* 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
lisp/progmodes/xref.el

index 37964bbd178e87f474e2e51c50797dfe18d91533..6d458701af5f53d2ee1d72b6cef35bcae06d9df7 100644 (file)
--- 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))))
+
 \f
 * New Modes and Packages in Emacs 31.1
 
index 7e9987d0cc94849dc7162d0b5b55c98cc16560f3..12ea6a3fe957dbbfdebbcc0108bee3f77a388bf8 100644 (file)
@@ -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)