diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el index e0f5b2d3670..b0bdd62ae98 100644 --- a/lisp/progmodes/xref.el +++ b/lisp/progmodes/xref.el @@ -692,6 +692,10 @@ references displayed in the current *xref* buffer." (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). + (let ((win (get-buffer-window (current-buffer)))) + (and win (set-window-point win (point)))) (xref--show-location (xref-item-location xref) t)) (t (error "No %s xref" (if backward "previous" "next"))))))