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

From: Tino Calancha <[email-masked]>
Date: Tue, 02 Feb 2021 22:16:05 +0100

Juri Linkov <[email-masked]> writes:

>>     * lisp/window.el (recenter-other-window): New command.
>>     Bind recenter-other-window to M-C-l.
>
> M-C-l can't be used because M-C-l is already bound to 'reposition-window'.
> Only S-M-C-l is free.
Right, my bad.  Ok, I will use S-M-C-l then.

>>     * lisp/simple.el (this-error-recenter): New command.
>
> Wouldn't a better name be recenter-current-error
> since existing name is compilation-current-error?
Agreed.

>> +(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")
>
> This is bad restriction that needs to be removed.
OK

>> +    (funcall next-error-function 0 nil)
>> +    (recenter-top-bottom arg)
>> +    (pop-to-buffer next-error-last-buffer)))
>
> `(pop-to-buffer next-error-last-buffer)' has problems
> and should be replaced with `save-selected-window'.
>
> Please see the commit 072b4c679dfd5528e74849cad18246730a991933
> and bug#32607 for explanations.

I must set the buffer with the locus current, otherwise `recenter' rises
an error:

(defun recenter-current-error (&optional arg)
  "Recenter the current displayed error in the `next-error' buffer."
  (interactive "P")
  (save-selected-window
    (let ((next-error-highlight next-error-highlight-no-select)
          (display-buffer-overriding-action
           '(nil (inhibit-same-window . t))))
      (next-error 0)
      (set-buffer (window-buffer))
      (recenter-top-bottom arg))))