Fix the use of xref-window-local-history together with Xref buffer

* lisp/progmodes/xref.el (xref--push-markers): Temporarily
restore the selected window as well, using the value from the
new argument (bug#76565).  Update both callers.
This commit is contained in:
Dmitry Gutov 2025-03-02 05:22:56 +02:00
parent 8091772767
commit 625ed68aea

View file

@ -1516,31 +1516,40 @@ The meanings of both arguments are the same as documented in
xrefs xrefs
(setq xrefs 'called-already))))))) (setq xrefs 'called-already)))))))
(let ((cb (current-buffer)) (let ((cb (current-buffer))
(pt (point))) (pt (point))
(win (selected-window)))
(prog1 (prog1
(funcall xref-show-xrefs-function fetcher (funcall xref-show-xrefs-function fetcher
`((window . ,(selected-window)) `((window . ,win)
(display-action . ,display-action) (display-action . ,display-action)
(auto-jump . ,xref-auto-jump-to-first-xref))) (auto-jump . ,xref-auto-jump-to-first-xref)))
(xref--push-markers cb pt)))) (xref--push-markers cb pt win))))
(defun xref--show-defs (xrefs display-action) (defun xref--show-defs (xrefs display-action)
(let ((cb (current-buffer)) (let ((cb (current-buffer))
(pt (point))) (pt (point))
(win (selected-window)))
(prog1 (prog1
(funcall xref-show-definitions-function xrefs (funcall xref-show-definitions-function xrefs
`((window . ,(selected-window)) `((window . ,win)
(display-action . ,display-action) (display-action . ,display-action)
(auto-jump . ,xref-auto-jump-to-first-definition))) (auto-jump . ,xref-auto-jump-to-first-definition)))
(xref--push-markers cb pt)))) (xref--push-markers cb pt win))))
(defun xref--push-markers (buf pt) (defun xref--push-markers (buf pt win)
(when (buffer-live-p buf) (when (buffer-live-p buf)
(save-excursion ;; This was we support the `xref-history-storage' getter which
(with-no-warnings (set-buffer buf)) ;; depends on the selected window. This is getting pretty complex,
(goto-char pt) ;; though. The alternative approach to try would be to push early
(unless (region-active-p) (push-mark nil t)) ;; but undo the stack insertion and mark-pushing in error handler.
(xref-push-marker-stack)))) (save-window-excursion
(when (window-live-p win)
(select-window win))
(save-excursion
(with-no-warnings (set-buffer buf))
(goto-char pt)
(unless (region-active-p) (push-mark nil t))
(xref-push-marker-stack)))))
(defun xref--prompt-p (command) (defun xref--prompt-p (command)
(or (eq xref-prompt-for-identifier t) (or (eq xref-prompt-for-identifier t)