summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2007-11-16 18:50:35 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2007-11-16 18:50:35 +0000
commitde8ebf6226a1948e9df250abd9a42b4ccff2a5c7 (patch)
tree889864bd5f2773be368b8efa07fad1ac9f37dfcb /lisp
parentd548715ceb4a2dcbc7d82100a490b9aa2913d4e4 (diff)
downloademacs-de8ebf6226a1948e9df250abd9a42b4ccff2a5c7.tar.gz
(recenter-last-op): New var.
(recenter-top-bottom): New command. (global-map): Bind it to C-l.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/window.el38
2 files changed, 42 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ccd62fa9e36..c17f848c0f4 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
2007-11-16 Stefan Monnier <monnier@iro.umontreal.ca>
+ * window.el (recenter-last-op): New var.
+ (recenter-top-bottom): New command.
+ (global-map): Bind it to C-l.
+
* abbrev.el (abbrev--write): Fix error in transcription from C.
* emulation/pc-select.el (pc-select-shifted-mark): Remove.
diff --git a/lisp/window.el b/lisp/window.el
index 0f6ae8ab763..94e4b48a3a7 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -879,6 +879,44 @@ and the buffer that is killed or buried is the one in that window."
;; Maybe get rid of the window.
(and window (not window-handled) (not window-solitary)
(delete-window window))))
+
+(defvar recenter-last-op nil
+ "Indicates the last recenter operation performed.
+Possible values: `top', `middle', `bottom'.")
+
+(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")
+ (cond
+ (arg (recenter arg)) ; Always respect ARG.
+ ((not (eq this-command last-command))
+ ;; First time - save mode and recenter.
+ (let ((bottom (1+ (count-lines 1 (window-end))))
+ (current (1+ (count-lines 1 (point))))
+ (total (window-height)))
+ (setq recenter-last-op 'middle)
+ (recenter)))
+ (t ;; repeat: loop through various options.
+ (setq recenter-last-op
+ (ecase recenter-last-op
+ (middle (recenter scroll-conservatively) 'top)
+ (top (recenter (1- (- scroll-conservatively))) 'bottom)
+ (bottom (recenter) 'middle))))))
+
+(define-key global-map [?\C-l] 'recenter-top-bottom)
(defvar mouse-autoselect-window-timer nil
"Timer used by delayed window autoselection.")