I have a next-error-hook
to recenter the next-error-last-buffer
, so if the buffer is displayed, it will recenter to the line of the error I just jumped to:
(defun jpk/next-error-hook ()
(let ((win (get-buffer-window next-error-last-buffer))
(buf (buffer-name next-error-last-buffer))
(recenter-redisplay nil))
(when (and win (not (string= "*xref*" buf)))
(with-selected-window win ;; this is what breaks xref
(recenter)))))
(add-hook 'next-error-hook #'jpk/next-error-hook)
Lately I've been trying out xref, and it breaks on the with-selected-window
(hence the hacky check for the buffer name); I can replace the (recenter)
with t
and it breaks in the same way. It seems to only see two matches: the one last clicked on and the next; previous-error
and next-error
cycle between only these two. All other modes that work with next-error
(grep, compile, ggtags, rg, etc.) do not have this problem. This also happens with multiple xref backends (elisp, gxref).
How can I write a next-error-hook
to recenter the *xref*
buffer?