Add a new argument to 'recenter' to allow finer control of redisplay
* window.c (recenter): Add a new REDISPLAY argument to allow the caller to control the redisplay behavior. 'recenter' will only redisplay the frame if this new arg and 'recenter-redisplay' are both non-nil. (recenter-top-bottom): Pass an extra non-nil argument to 'recenter' to force a redisplay. (Bug#31325)
This commit is contained in:
parent
7edc019651
commit
260768a64b
4 changed files with 28 additions and 19 deletions
|
@ -4138,7 +4138,7 @@ beginning or end of the buffer (depending on scrolling direction);
|
|||
only if point is already on that position do they signal an error.
|
||||
@end defopt
|
||||
|
||||
@deffn Command recenter &optional count
|
||||
@deffn Command recenter &optional count redisplay
|
||||
@cindex centering point
|
||||
This function scrolls the text in the selected window so that point is
|
||||
displayed at a specified vertical position within the window. It does
|
||||
|
@ -4152,8 +4152,9 @@ line in the window.
|
|||
|
||||
If @var{count} is @code{nil} (or a non-@code{nil} list),
|
||||
@code{recenter} puts the line containing point in the middle of the
|
||||
window. If @var{count} is @code{nil}, this function may redraw the
|
||||
frame, according to the value of @code{recenter-redisplay}.
|
||||
window. If @var{count} is @code{nil} and @var{redisplay} is
|
||||
non-@code{nil}, this function may redraw the frame, according to the
|
||||
value of @code{recenter-redisplay}.
|
||||
|
||||
When @code{recenter} is called interactively, @var{count} is the raw
|
||||
prefix argument. Thus, typing @kbd{C-u} as the prefix sets the
|
||||
|
@ -4181,8 +4182,9 @@ respect to the entire window group.
|
|||
|
||||
@defopt recenter-redisplay
|
||||
If this variable is non-@code{nil}, calling @code{recenter} with a
|
||||
@code{nil} argument redraws the frame. The default value is
|
||||
@code{tty}, which means only redraw the frame if it is a tty frame.
|
||||
@code{nil} @var{count} argument and non-@code{nil} @var{redisplay}
|
||||
argument redraws the frame. The default value is @code{tty}, which
|
||||
means only redraw the frame if it is a tty frame.
|
||||
@end defopt
|
||||
|
||||
@deffn Command recenter-top-bottom &optional count
|
||||
|
|
5
etc/NEWS
5
etc/NEWS
|
@ -689,6 +689,11 @@ manual for more details.
|
|||
|
||||
* Lisp Changes in Emacs 27.1
|
||||
|
||||
+++
|
||||
** The function 'recenter' accepts an additional optional argument.
|
||||
If the optional second argument is nil, recenter will not redisplay
|
||||
the frame regardless of the value of 'recenter-redisplay'.
|
||||
|
||||
+++
|
||||
** New functions 'major-mode-suspend' and 'major-mode-restore'.
|
||||
Use them when switching temporarily to another major mode, e.g. for
|
||||
|
|
|
@ -8778,15 +8778,15 @@ A prefix argument is handled like `recenter':
|
|||
(min (max 0 scroll-margin)
|
||||
(truncate (/ (window-body-height) 4.0)))))
|
||||
(cond ((eq recenter-last-op 'middle)
|
||||
(recenter))
|
||||
(recenter nil t))
|
||||
((eq recenter-last-op 'top)
|
||||
(recenter this-scroll-margin))
|
||||
(recenter this-scroll-margin t))
|
||||
((eq recenter-last-op 'bottom)
|
||||
(recenter (- -1 this-scroll-margin)))
|
||||
(recenter (- -1 this-scroll-margin) t))
|
||||
((integerp recenter-last-op)
|
||||
(recenter recenter-last-op))
|
||||
(recenter recenter-last-op t))
|
||||
((floatp recenter-last-op)
|
||||
(recenter (round (* recenter-last-op (window-height))))))))))
|
||||
(recenter (round (* recenter-last-op (window-height))) t)))))))
|
||||
|
||||
(define-key global-map [?\C-l] 'recenter-top-bottom)
|
||||
|
||||
|
|
20
src/window.c
20
src/window.c
|
@ -5896,22 +5896,23 @@ displayed_window_lines (struct window *w)
|
|||
}
|
||||
|
||||
|
||||
DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P",
|
||||
DEFUN ("recenter", Frecenter, Srecenter, 0, 2, "P",
|
||||
doc: /* Center point in selected window and maybe redisplay frame.
|
||||
With a numeric prefix argument ARG, recenter putting point on screen line ARG
|
||||
relative to the selected window. If ARG is negative, it counts up from the
|
||||
bottom of the window. (ARG should be less than the height of the window.)
|
||||
|
||||
If ARG is omitted or nil, then recenter with point on the middle line of
|
||||
the selected window; if the variable `recenter-redisplay' is non-nil,
|
||||
also erase the entire frame and redraw it (when `auto-resize-tool-bars'
|
||||
is set to `grow-only', this resets the tool-bar's height to the minimum
|
||||
height needed); if `recenter-redisplay' has the special value `tty',
|
||||
then only tty frames are redrawn.
|
||||
If ARG is omitted or nil, then recenter with point on the middle line
|
||||
of the selected window; if REDISPLAY & `recenter-redisplay' are
|
||||
non-nil, also erase the entire frame and redraw it (when
|
||||
`auto-resize-tool-bars' is set to `grow-only', this resets the
|
||||
tool-bar's height to the minimum height needed); if
|
||||
`recenter-redisplay' has the special value `tty', then only tty frames
|
||||
are redrawn.
|
||||
|
||||
Just C-u as prefix means put point in the center of the window
|
||||
and redisplay normally--don't erase and redraw the frame. */)
|
||||
(register Lisp_Object arg)
|
||||
(Lisp_Object arg, Lisp_Object redisplay)
|
||||
{
|
||||
struct window *w = XWINDOW (selected_window);
|
||||
struct buffer *buf = XBUFFER (w->contents);
|
||||
|
@ -5931,7 +5932,8 @@ and redisplay normally--don't erase and redraw the frame. */)
|
|||
|
||||
if (NILP (arg))
|
||||
{
|
||||
if (!NILP (Vrecenter_redisplay)
|
||||
if (!NILP (redisplay)
|
||||
&& !NILP (Vrecenter_redisplay)
|
||||
&& (!EQ (Vrecenter_redisplay, Qtty)
|
||||
|| !NILP (Ftty_type (selected_frame))))
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue