From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: recenter-top-bottom Date: Thu, 15 Nov 2007 10:16:27 -0500 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1195139834 27015 80.91.229.12 (15 Nov 2007 15:17:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 15 Nov 2007 15:17:14 +0000 (UTC) Cc: rms@gnu.org, emacs-devel@gnu.org To: "Drew Adams" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Nov 15 16:17:17 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IsgSg-0007Fv-Ey for ged-emacs-devel@m.gmane.org; Thu, 15 Nov 2007 16:16:58 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IsgST-0003P9-Im for ged-emacs-devel@m.gmane.org; Thu, 15 Nov 2007 10:16:45 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IsgSN-0003OK-DK for emacs-devel@gnu.org; Thu, 15 Nov 2007 10:16:39 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IsgSM-0003NR-3L for emacs-devel@gnu.org; Thu, 15 Nov 2007 10:16:39 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IsgSL-0003N9-ST for emacs-devel@gnu.org; Thu, 15 Nov 2007 10:16:37 -0500 Original-Received: from tomts13.bellnexxia.net ([209.226.175.34] helo=tomts13-srv.bellnexxia.net) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IsgSE-0001We-JH; Thu, 15 Nov 2007 10:16:30 -0500 Original-Received: from ceviche.home ([70.53.194.136]) by tomts13-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20071115151628.FKSD13659.tomts13-srv.bellnexxia.net@ceviche.home>; Thu, 15 Nov 2007 10:16:28 -0500 Original-Received: by ceviche.home (Postfix, from userid 20848) id AE53DB4059; Thu, 15 Nov 2007 10:16:27 -0500 (EST) In-Reply-To: (Drew Adams's message of "Wed, 14 Nov 2007 13:57:58 -0800") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.50 (gnu/linux) X-detected-kernel: by monty-python.gnu.org: Solaris 8 (1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:83274 Archived-At: > (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))))) Looks OK, except I'd rather not fool around with last-command and this-command: (defvar recenter-last-op nil) (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 (if (< (- bottom current) (/ total 3)) 'recenter-tb-middle-1) 'recenter-tb-middle) (recenter))) (t ;; repeat: loop through various options. (ecase recenter-last-op (recenter-tb-top ; Top -> middle -> bottom (setq recenter-last-op 'recenter-tb-middle) (recenter)) (recenter-tb-middle (setq recenter-last-op 'recenter-tb-bottom) (recenter (1- (- scroll-conservatively)))) (recenter-tb-bottom (setq recenter-last-op 'recenter-tb-top) (recenter scroll-conservatively)) (recenter-tb-bottom-1 ; Bottom -> middle -> top (setq recenter-last-op 'recenter-tb-middle-1) (recenter)) (recenter-tb-middle-1 (setq recenter-last-op 'recenter-tb-top-1) (recenter scroll-conservatively)) (recenter-tb-top-1 (setq recenter-last-op 'recenter-tb-bottom-1) (recenter (1- (- scroll-conservatively)))))))) -- Stefan