]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't push to Xref history when search ends with error
authorDmitry Gutov <dmitry@gutov.dev>
Fri, 1 Sep 2023 01:37:40 +0000 (04:37 +0300)
committerDmitry Gutov <dmitry@gutov.dev>
Fri, 1 Sep 2023 01:37:54 +0000 (04:37 +0300)
* lisp/progmodes/xref.el (xref--push-markers):
Add new arguments (bug#65631).
(xref--show-xrefs, xref--show-defs): Use them.

lisp/progmodes/xref.el

index dbafa00c3ad8ca1c62f5451c3fe09b966c70afcf..9b64ef4de108b6f6c8d3797b55a5b5fc740b6d01 100644 (file)
@@ -1468,7 +1468,6 @@ The meanings of both arguments are the same as documented in
   (xref--show-xrefs fetcher display-action))
 
 (defun xref--show-xrefs (fetcher display-action &optional _always-show-list)
-  (xref--push-markers)
   (unless (functionp fetcher)
     ;; Old convention.
     (let ((xrefs fetcher))
@@ -1479,21 +1478,30 @@ The meanings of both arguments are the same as documented in
                 (prog1
                     xrefs
                   (setq xrefs 'called-already)))))))
-  (funcall xref-show-xrefs-function fetcher
-           `((window . ,(selected-window))
-             (display-action . ,display-action)
-             (auto-jump . ,xref-auto-jump-to-first-xref))))
+  (let ((cb (current-buffer))
+        (pt (point)))
+    (funcall xref-show-xrefs-function fetcher
+             `((window . ,(selected-window))
+               (display-action . ,display-action)
+               (auto-jump . ,xref-auto-jump-to-first-xref)))
+    (xref--push-markers cb pt)))
 
 (defun xref--show-defs (xrefs display-action)
-  (xref--push-markers)
-  (funcall xref-show-definitions-function xrefs
-           `((window . ,(selected-window))
-             (display-action . ,display-action)
-             (auto-jump . ,xref-auto-jump-to-first-definition))))
-
-(defun xref--push-markers ()
-  (unless (region-active-p) (push-mark nil t))
-  (xref-push-marker-stack))
+  (let ((cb (current-buffer))
+        (pt (point)))
+    (funcall xref-show-definitions-function xrefs
+             `((window . ,(selected-window))
+               (display-action . ,display-action)
+               (auto-jump . ,xref-auto-jump-to-first-definition)))
+    (xref--push-markers cb pt)))
+
+(defun xref--push-markers (buf pt)
+  (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))))
 
 (defun xref--prompt-p (command)
   (or (eq xref-prompt-for-identifier t)