From 7b00a9c449d79528001f8b23632f39a74fe8b696 Mon Sep 17 00:00:00 2001 From: murata Date: Wed, 10 May 2000 12:58:29 +0000 Subject: [PATCH] (wl-count-lines): Count lines. (wl-horizontal-recenter): horizontal recenter. --- wl/wl-util.el | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/wl/wl-util.el b/wl/wl-util.el index 0102e10..135e9ee 100644 --- a/wl/wl-util.el +++ b/wl/wl-util.el @@ -817,4 +817,38 @@ that `read' can handle, whenever this is possible." (defun wl-load-profile () (funcall wl-load-profile-func)) +;;; + +(defmacro wl-count-lines () + (` (save-excursion + (beginning-of-line) + (count-lines 1 (point))))) + +(defun wl-horizontal-recenter () + "Recenter the current buffer horizontally." + (beginning-of-line) + (re-search-forward "[[<]" (point-at-eol) t) + (if (< (current-column) (/ (window-width) 2)) + (set-window-hscroll (get-buffer-window (current-buffer) t) 0) + (let* ((orig (point)) + (end (window-end (get-buffer-window (current-buffer) t))) + (max 0)) + (when end + ;; Find the longest line currently displayed in the window. + (goto-char (window-start)) + (while (and (not (eobp)) + (< (point) end)) + (end-of-line) + (setq max (max max (current-column))) + (forward-line 1)) + (goto-char orig) + ;; Scroll horizontally to center (sort of) the point. + (if (> max (window-width)) + (set-window-hscroll + (get-buffer-window (current-buffer) t) + (min (- (current-column) (/ (window-width) 3)) + (+ 2 (- max (window-width))))) + (set-window-hscroll (get-buffer-window (current-buffer) t) 0)) + max)))) + ;;; wl-util.el ends here -- 1.7.10.4