0

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?

Drew
  • 75,699
  • 9
  • 109
  • 225
jpkotta
  • 498
  • 2
  • 11
  • Perhaps there is an Emacs bug here? Should `xref` be an exception in this way? If you think there might be a bug here, consider filing a bug report: `M-x report-emacs-bug`. – Drew Oct 18 '17 at 21:26
  • Are you looking for https://emacs.stackexchange.com/a/32519 ? – phils Oct 18 '17 at 22:26
  • 1
    @phils No, I'm aware of `next-error-recenter` and have it set to `'(4)`. That recenters in the linked-to buffer, I want to recenter in the link buffer (`next-error-last-buffer`). – jpkotta Oct 19 '17 at 21:00

0 Answers0