Subject: bug#46119: 28.0.50; this-error-recenter

From: Tino Calancha <[email-masked]>
Date: Sat, 30 Jan 2021 16:01:40 +0100

Juri Linkov <[email-masked]> writes:

>> +(defun this-error-recenter (&optional arg)
>> +  "Recenter the current displayed error in the `next-error' buffer."
>> +  (interactive "P")
>> +  (if (not (or (eq major-mode 'occur-mode)
>> +               (derived-mode-p 'compilation-mode)))
>> +      (user-error "This command is for *Occur* or *Grep* buffers")
>> +    (funcall next-error-function 0 nil)
>> +    (recenter-top-bottom arg)
>> +    (pop-to-buffer next-error-last-buffer)))
>
> I wonder why restrict this only to occur and compilation?
I think because I was blindly looking only to my particular use case: Occur/Grep.

> Like C-M-v/C-M-S-v and M-PgUp/M-PgDown can scroll up/down other window
> in any mode, you can use such code to recenter other window everywhere:
>
>   (with-selected-window (other-window-for-scrolling) (recenter-top-bottom))

Yeah, it makes sense.  The only thing is that it makes harder to find
the right name for this command;  I think by improving the docstring
makes more clear what is this about.
How does it look now?:

(defun this-error-recenter (&optional arg)
  "Recenter the current displayed error in the `next-error' buffer.
If called not from a `next-error' buffer, then it just calls
`recenter-top-bottom' in the other window."
  (interactive "P")
  (if (not (or (eq major-mode 'occur-mode) (derived-mode-p 'compilation-mode)))
      (with-selected-window (other-window-for-scrolling) (recenter-top-bottom arg))
    (funcall next-error-function 0 nil)
    (recenter-top-bottom arg)
    (pop-to-buffer next-error-last-buffer)))