]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix the use of xref-window-local-history together with Xref buffer
authorDmitry Gutov <dmitry@gutov.dev>
Sun, 2 Mar 2025 03:22:56 +0000 (05:22 +0200)
committerEshel Yaron <me@eshelyaron.com>
Tue, 4 Mar 2025 20:58:42 +0000 (21:58 +0100)
* 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.

(cherry picked from commit 625ed68aeaadce4df7bdfd8c08ddfc8ed4f9b01a)

lisp/progmodes/xref.el

index 9aaa119c023051e0abdfbac91fb14f96049ef216..e7f5b2dad4683a545dc2d629639532999d57eafd 100644 (file)
@@ -1624,31 +1624,40 @@ The meanings of both arguments are the same as documented in
                     xrefs
                   (setq xrefs 'called-already)))))))
   (let ((cb (current-buffer))
-        (pt (point)))
+        (pt (point))
+        (win (selected-window)))
     (prog1
         (funcall xref-show-xrefs-function fetcher
-                 `((window . ,(selected-window))
+                 `((window . ,win)
                    (display-action . ,display-action)
                    (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)
   (let ((cb (current-buffer))
-        (pt (point)))
+        (pt (point))
+        (win (selected-window)))
     (prog1
         (funcall xref-show-definitions-function xrefs
-                 `((window . ,(selected-window))
+                 `((window . ,win)
                    (display-action . ,display-action)
                    (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)
-    (save-excursion
-      (with-no-warnings (set-buffer buf))
-      (goto-char pt)
-      (unless (region-active-p) (push-mark nil t))
-      (xref-push-marker-stack))))
+    ;; This was we support the `xref-history-storage' getter which
+    ;; depends on the selected window.  This is getting pretty complex,
+    ;; though. The alternative approach to try would be to push early
+    ;; but undo the stack insertion and mark-pushing in error handler.
+    (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)
   (or (eq xref-prompt-for-identifier t)