emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: recenter-top-bottom


From: Drew Adams
Subject: RE: recenter-top-bottom
Date: Wed, 14 Nov 2007 13:57:58 -0800

> I am still interested in your original design, which I think is good.

I think the version below combines the best of each and should satisfy most
people. It is the same as the original design, except that the cycling order
is appropriate for where you start out.

1. An explicit arg (plain `C-u' or numeric) is always respected, whenever it
is used.

2. Otherwise, the first `C-l' always recenters.

3. Otherwise, successive `C-l' cycles among top, middle, and bottom (top and
bottom are modulo `scroll-conservatively'). The initial position (top,
middle, or bottom third of the window) determines the cycling order:
middle -> bottom -> top versus middle -> top -> bottom.

#1 and #2 mean that unless you repeat `C-l' you get the normal `recenter'
behavior.

#3 means that cycling never repeats the same destination twice in a row -
the order fits the initial cursor position.

(defun recenter-top-bottom (&optional arg)
  "Move current line to window center, top, and bottom, successively.
With a prefix argument, this is the same as `recenter':
 With numeric prefix ARG, move current line to window-line ARG.
 With plain `C-u', move current line to window center.

Otherwise move current line to window center on first call, and to
top, middle, or bottom on successive calls.

The starting position of the window determines the cycling order:
 If initially in the top or middle third: top -> middle -> bottom.
 If initially in the bottom third: bottom -> middle -> top.

Top and bottom destinations are actually `scroll-conservatively' lines
from true window top and bottom."
  (interactive "P")
  (if arg ; Always respect ARG.
      (recenter arg)
    (case last-command
      (recenter-tb-top ; Top -> middle -> bottom
       (setq this-command 'recenter-tb-middle)
       (recenter))
      (recenter-tb-middle
       (setq this-command 'recenter-tb-bottom)
       (recenter (1- (- scroll-conservatively))))
      (recenter-tb-bottom
       (setq this-command 'recenter-tb-top)
       (recenter scroll-conservatively))
      (recenter-tb-bottom-1 ; Bottom -> middle -> top
       (setq this-command 'recenter-tb-middle-1)
       (recenter))
      (recenter-tb-middle-1
       (setq this-command 'recenter-tb-top-1)
       (recenter scroll-conservatively))
      (recenter-tb-top-1
       (setq this-command 'recenter-tb-bottom-1)
       (recenter (1- (- scroll-conservatively))))
      (otherwise ; First time - save mode and recenter.
       (let ((bottom (1+ (count-lines 1 (window-end))))
             (current (1+ (count-lines 1 (point))))
             (total (window-height)))
         (if (< (- bottom current) (/ total 3))
             (setq this-command 'recenter-tb-middle-1)
           (setq this-command 'recenter-tb-middle)))
       (recenter)))))








reply via email to

[Prev in Thread] Current Thread [Next in Thread]