Function: recenter-top-bottom

recenter-top-bottom is an interactive and byte-compiled function defined in window.el.gz.

Signature

(recenter-top-bottom &optional ARG)

Documentation

Scroll the window so that current line is in the middle of the window.

Successive invocations scroll the window in a cyclical order to put the current line at certain places within the window, as determined by recenter-positions. By default, the second invocation puts the current line at the top-most window line, the third invocation puts it on the bottom-most window line, and then the order is reused in a cyclical manner.

With numeric prefix ARG, move current line ARG lines below the window top. With plain C-u (universal-argument), move current line to window center.

View in manual

Probably introduced at or before Emacs version 23.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/window.el.gz
(defun recenter-top-bottom (&optional arg)
  "Scroll the window so that current line is in the middle of the window.
Successive invocations scroll the window in a cyclical order to put
the current line at certain places within the window, as determined by
`recenter-positions'.  By default, the second invocation puts the
current line at the top-most window line, the third invocation puts it
on the bottom-most window line, and then the order is reused in a
cyclical manner.

With numeric prefix ARG, move current line ARG lines below the window top.
With plain \\[universal-argument], move current line to window center."
  (interactive "P")
  (cond
   (arg (recenter arg t))                 ; Always respect ARG.
   (t
    (setq recenter-last-op
	  (if (eq this-command last-command)
	      (car (or (cdr (member recenter-last-op recenter-positions))
		       recenter-positions))
	    (car recenter-positions)))
    (let ((this-scroll-margin
	   (min (max 0 scroll-margin)
		(truncate (/ (window-body-height) 4.0)))))
      (cond ((eq recenter-last-op 'middle)
	     (recenter nil t))
	    ((eq recenter-last-op 'top)
	     (recenter this-scroll-margin t))
	    ((eq recenter-last-op 'bottom)
	     (recenter (- -1 this-scroll-margin) t))
	    ((integerp recenter-last-op)
	     (recenter recenter-last-op t))
	    ((floatp recenter-last-op)
	     (recenter (round (* recenter-last-op (window-height))) t)))))))