Subject: [PATCH] Fix jumping to the current error in xref

From: Felicián Németh <[email-masked]>
Date: Wed, 13 Feb 2019 21:35:46 +0100

I sometimes find useful to return to the current reference after examining
its context. However, xref--next-error-function fails to jump to the
current reference. The following steps reproduce the problem.

emacs -Q lisp/progmodes/xref.el
M-? xref-make RET
n RET
M-<
C-u 0 M-g n

I know next-error + previous-error is a workaround, but the patch fixes the
bug.

Thanks,
Felicián
From c774e643437d4fe7a2a89106032ec377b28ce369 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Felici=C3=A1n=20N=C3=A9meth?= <[email-masked]>
Date: Wed, 13 Feb 2019 21:19:36 +0100
Subject: [PATCH] Fix jumping to the current error in xref

* xref.el (xref--next-error-function): Handle the corner case of
n==0.
---
 lisp/progmodes/xref.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index 9522d7e475..6974d00048 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -694,8 +694,10 @@ xref--next-error-function
   (let ((backward (< n 0))
         (n (abs n))
         (xref nil))
-    (dotimes (_ n)
-      (setq xref (xref--search-property 'xref-item backward)))
+    (if (= n 0)
+        (setq xref (get-text-property (point) 'xref-item))
+      (dotimes (_ n)
+        (setq xref (xref--search-property 'xref-item backward))))
     (cond (xref
            ;; Save the current position (when the buffer is visible,
            ;; it gets reset to that window's point from time to time).
-- 
2.11.0