Add command to recenter errors from Occur/Grep buffers

To scroll up/down the current displayed occurrence/error
without abandon the Occur/Grep buffer.

Add also a command 'recenter-other-window' to recenter
the other window from any kind of buffer.

* lisp/window.el (recenter-other-window): New command.
Bind recenter-other-window to S-M-C-l (Bug#46119).

* lisp/simple.el (recenter-current-error): New command.
* lisp/progmodes/grep.el (grep-mode-map):
Delete bidings for n and p.

* lisp/progmodes/compile.el (compilation-minor-mode-map):
Move here the n and p bindings.
Bind `recenter-current-error' to l.
* lisp/replace.el (occur-mode-map):
Same.

* doc/emacs/windows.texi (Other Window):
* doc/emacs/display.texi (Recentering):
Document recenter-other-window.

* etc/NEWS (Changes in Specialized Modes and Packages in Emacs 28.1):
Announce the changes.
This commit is contained in:
Tino Calancha 2021-02-07 16:51:07 +01:00
parent 5461808c40
commit 9380a7ed90
8 changed files with 50 additions and 5 deletions

View file

@ -173,6 +173,10 @@ line; on subsequent consecutive invocations, make the current line the
top line, the bottom line, and so on in cyclic order. Possibly
redisplay the screen too (@code{recenter-top-bottom}).
@item C-M-S-l
Scroll the other window; this is equivalent to @kbd{C-l} acting on the
other window.
@item M-x recenter
Scroll the selected window so the current line is the center-most text
line. Possibly redisplay the screen too.

View file

@ -161,6 +161,8 @@ Select another window (@code{other-window}).
Scroll the next window upward (@code{scroll-other-window}).
@item C-M-S-v
Scroll the next window downward (@code{scroll-other-window-down}).
@item C-M-S-l
Recenter the next window (@code{recenter-other-window}).
@item mouse-1
@kbd{mouse-1}, in the text area of a window, selects the window and
moves point to the position clicked. Clicking in the mode line
@ -194,6 +196,8 @@ rebind a command.)
@findex scroll-other-window
@kindex C-M-S-v
@findex scroll-other-window-down
@kindex C-M-S-l
@findex recenter-other-window
The usual scrolling commands (@pxref{Display}) apply to the selected
window only, but there are also commands to scroll the next window.
@kbd{C-M-v} (@code{scroll-other-window}) scrolls the window that
@ -203,7 +207,9 @@ take positive and negative arguments. (In the minibuffer, @kbd{C-M-v}
scrolls the help window associated with the minibuffer, if any, rather
than the next window in the standard cyclic order; @pxref{Minibuffer
Edit}.) @kbd{C-M-S-v} (@code{scroll-other-window-down}) scrolls the
next window downward in a similar way.
next window downward in a similar way. Likewise, @kbd{C-M-S-l}
(@code{recenter-other-window}) behaves like @kbd{C-l}
(@code{recenter-top-bottom}) in the next window.
@vindex mouse-autoselect-window
If you set @code{mouse-autoselect-window} to a non-@code{nil} value,

View file

@ -85,7 +85,11 @@ useful on systems such as FreeBSD which ships only with "etc/termcap".
* Changes in Emacs 28.1
** The new NonGNU ELPA archive is enabled by default alongside GNU ELPA.
+++
** New command 'recenter-other-window', bound to 'S-M-C-l'.
Like 'recenter-top-bottom' acting in the other window.
** The new NonGNU ELPA archive is enabled by default alongside GNU ELPA
** Minibuffer scrolling is now conservative by default.
This is controlled by the new variable 'scroll-minibuffer-conservatively'.
@ -469,9 +473,14 @@ applied when the option 'tab-line-tab-face-functions' is
so-configured. That option may also be used to customize tab-line
faces in other ways.
** New bindings in occur-mode, 'next-error-no-select' bound to 'n' and
** Occur mode
*** New bindings in occur-mode, 'next-error-no-select' bound to 'n' and
'previous-error-no-select' bound to 'p'.
*** The new command 'recenter-current-error', bound to 'l' in Occur or
compilation buffers, recenters the current displayed occurrence/error.
** EIEIO
+++

View file

@ -2069,6 +2069,10 @@ Returns the compilation buffer created."
(define-key map "\M-p" 'compilation-previous-error)
(define-key map "\M-{" 'compilation-previous-file)
(define-key map "\M-}" 'compilation-next-file)
(define-key map "n" 'next-error-no-select)
(define-key map "p" 'previous-error-no-select)
(define-key map "l" 'recenter-current-error)
(define-key map "g" 'recompile) ; revert
;; Set up the menu-bar
(define-key map [menu-bar compilation]

View file

@ -275,8 +275,6 @@ See `compilation-error-screen-columns'."
(define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
(define-key map "\r" 'compile-goto-error) ;; ?
(define-key map "n" 'next-error-no-select)
(define-key map "p" 'previous-error-no-select)
(define-key map "{" 'compilation-previous-file)
(define-key map "}" 'compilation-next-file)
(define-key map "\t" 'compilation-next-error)

View file

@ -1161,6 +1161,7 @@ a previously found match."
(define-key map "\C-o" 'occur-mode-display-occurrence)
(define-key map "n" 'next-error-no-select)
(define-key map "p" 'previous-error-no-select)
(define-key map "l" 'recenter-current-error)
(define-key map "\M-n" 'occur-next)
(define-key map "\M-p" 'occur-prev)
(define-key map "r" 'occur-rename-buffer)

View file

@ -492,6 +492,16 @@ buffer causes automatic display of the corresponding source code location."
(overlay-put ol 'window (get-buffer-window))
(setf next-error--message-highlight-overlay ol)))))
(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))))
;;;

View file

@ -9768,6 +9768,19 @@ With plain \\[universal-argument], move current line to window center."
(define-key global-map [?\C-l] 'recenter-top-bottom)
(defun recenter-other-window (&optional arg)
"Call `recenter-top-bottom' in the other window.
A prefix argument is handled like `recenter':
With numeric prefix ARG, move current line to window-line ARG.
With plain `C-u', move current line to window center."
(interactive "P")
(with-selected-window (other-window-for-scrolling)
(recenter-top-bottom arg)
(pulse-momentary-highlight-one-line (point))))
(define-key global-map [?\S-\M-\C-l] 'recenter-other-window)
(defun move-to-window-line-top-bottom (&optional arg)
"Position point relative to window.