1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-30 12:21:25 -08:00

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.
This commit is contained in:
Dmitry Gutov 2024-11-27 03:43:22 +02:00
parent 298bbf3cd7
commit 0624fe6f84
2 changed files with 23 additions and 6 deletions

View file

@ -781,6 +781,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

View file

@ -513,6 +513,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.
@ -523,8 +526,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)))))
@ -538,8 +541,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)))))
@ -612,7 +615,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))
@ -688,7 +691,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)