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: Mon, 12 Nov 2007 00:50:45 -0800

> So I think your first suggestion is better, and I am still thinking
> of maybe installing it. If people are very enthusiastic about
> your second suggestion, I will say yes to it.

Just to make it easier for people who might want to try both and compare,
here again are the two definitions. Each is a possible alternative binding
for `C-l'. (I've added the `scroll-conservatively' feature to #1, as well as
#2.)

(defun recenter-top-bottom-1 (&optional arg)
  "Move current line to window center, top, and bottom, successively.
With prefix ARG, move current line to window-line ARG.
Top and bottom destinations are actually `scroll-conservatively' lines
from true top and bottom."
  (interactive "P")
  (cond ((and (eq this-command last-command) (not arg))
         (setq this-command 'recenter-top-bottom-top)
         (recenter scroll-conservatively))
        ((and (eq 'recenter-top-bottom-top last-command) (not arg))
         (setq this-command 'recenter-top-bottom-bottom)
         (recenter (1- (- scroll-conservatively))))
        (t (recenter arg))))

(defun recenter-top-bottom-2 (&optional arg)
  "Move current line to line ARG, window center, top, or bottom.
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, the window starting position determines the next position:
 If in the top third, move to bottom.
 If in middle third,  move to top.
 If in bottom third,  move tocenter.

Top and bottom destinations are actually `scroll-conservatively' lines
from true top and bottom."
  (interactive "P")
  (cond (arg (recenter arg))
        (t
         (let* ((top (1+ (count-lines 1 (window-start))))
                (bottom (1+ (count-lines 1 (window-end))))
                (current (1+ (count-lines 1 (point))))
                (total (window-height)))
           (cond ((< (- current top) (/ total 3))
                  (recenter (1- (- scroll-conservatively))))
                 ((< (- bottom current) (/ total 3)) (recenter '(4)))
                 (t (recenter scroll-conservatively)))))))






reply via email to

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