From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: RE: recenter-top-bottom Date: Sun, 11 Nov 2007 12:16:46 -0800 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1194812457 26409 80.91.229.12 (11 Nov 2007 20:20:57 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 11 Nov 2007 20:20:57 +0000 (UTC) Cc: Richard Stallman To: "Alan Mackenzie_JWA" , Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Nov 11 21:21:01 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 1IrJIh-00035t-KW for ged-emacs-devel@m.gmane.org; Sun, 11 Nov 2007 21:21:00 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IrJIV-00087J-Eb for ged-emacs-devel@m.gmane.org; Sun, 11 Nov 2007 15:20:47 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IrJGB-0004QB-Mj for emacs-devel@gnu.org; Sun, 11 Nov 2007 15:18:23 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IrJG9-0004N5-Ot for emacs-devel@gnu.org; Sun, 11 Nov 2007 15:18:23 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IrJG9-0004MZ-AK for emacs-devel@gnu.org; Sun, 11 Nov 2007 15:18:21 -0500 Original-Received: from rgminet01.oracle.com ([148.87.113.118]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IrJG2-0007Zg-NX; Sun, 11 Nov 2007 15:18:15 -0500 Original-Received: from agmgw1.us.oracle.com (agmgw1.us.oracle.com [152.68.180.212]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id lABKI8gA031972; Sun, 11 Nov 2007 13:18:09 -0700 Original-Received: from acsmt351.oracle.com (acsmt351.oracle.com [141.146.40.151]) by agmgw1.us.oracle.com (Switch-3.2.0/Switch-3.2.0) with ESMTP id lABJq450025113; Sun, 11 Nov 2007 13:18:07 -0700 Original-Received: from 141.144.89.9 by acsmt350.oracle.com with ESMTP id 3359005651194812200; Sun, 11 Nov 2007 12:16:40 -0800 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-detected-kernel: by monty-python.gnu.org: Linux 2.4-2.6 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:82961 Archived-At: I don't care what happens with the `recenter-top-bottom' suggestion I made - feel free to adapt it or ignore it. There was some interest and some feedback, however, and no one has adapted the code and installed it, so I'll respond a bit. Again, from here on in, please do whatever you like with the idea. It sounds, BTW, as if it might be difficult to please everyone: Juri wants an option to specify the "center" target (e.g. 1/3 vs 1/2 height). Juri wants a toggle between the new behavior and plain `recenter', for redrawing purposes. Alan wants an option (not a toggle) to choose this or plain `recenter'... (Wrt the last: Users can just rebind `C-l' to `recenter' - no need for such an option, IMO.) Below is a new definition that responds to some of the feedback, but not all. I didn't add any options or toggles - feel free to do so. With the new definition: 1. The current window line determines the destination: If within the top third, move to window bottom. If within the middle third, move to top. If within the bottom third, move to center. 2. The `last-command' is no longer relevant. Only the current window position decides the destination. 3. Destinations "top" and "bottom" are in fact `scroll-conservatively' and bottom-minus-`scroll-conservatively', respectively, so you can control how much is kept on screen. The default value of 0 means use absolute top and bottom. I don't think it is worthwhile to have a new, separate option for this, since the purpose of `scroll-conservatively' is about the same - it seems like a good fit. Like the previous definition I sent, an explicit ARG (either plain `C-u' or numeric) always calls `(recenter ARG)'. Alan: > I've had defuns bound to C-S-/ for years, > which move point directly to the top/bottom of the window > without passing Go or collecting $200. If I want to zap > point to BOW, I want it done NOW, atomically, not as a > triple key-sequence. So if you already have a command bound that does that, use it. I don't see your problem with a command that you don't use. The benefit of this suggestion is to get 3 destinations with the same key (C-l). If you prefer to have 3 separate keys for those destinations, go for it. Alan: > Having thought about it, I very rarely use a bare C-l. So, IIUC, (1) you use your own keys/commands to move "NOW" to top or bottom, and (2) you "very rarely use a bare C-l", which moves to the center. So `recenter-top-bottom' should "very rarely" have any effect at all on you. You will remain happy using `C-u C-l' and your C-S-/ commands, as usual. (`C-l' with a prefix arg is the same for `recenter-top-bottom' as for `recenter'.) Alan: > any further functionality on C-l should be optional. >From what you say, you hardly ever use plain `C-l'. If you use `C-l' only with a prefix arg, then you are not affected at all. However, such an option could easily be accommodated, if others agree that it is useful. Personally, I think it's enough for a user to rebind `C-l' to `recenter' - why have an option for that? Alan: > Perhaps its behaviour could be changed so that the > current window line is the criterion for where to go, Good idea. I've done that in the new version, below. Concerning frame redrawing: The Emacs manual says that frame redisplay occurs only for a text terminal. If redrawing for plain `C-l' is an important consideration here ("in case the screen is garbled", which I imagine happens less nowadays), then I propose that `recenter-top-bottom' be bound to `C-l' only when a window manager is used. If redisplay for plain `C-l' is not an obstacle, then I propose that we always bind `C-l' to `recenter-top-bottom'. Alternatively, to allow for redisplay with no movement, we could add an option, as Alan suggested, or a toggle, as Juri suggested. Or we could let plain `C-u' call `(recenter)' to redisplay - in that case, the effect of `C-u' would be opposite what it is for `recenter'. If there is still a need for redisplay without movement but the need is rare, then `C-u C-l' is not too much to ask of users, IMO. And any users who need that often could simply bind `C-l' to `recenter'. BTW, the doc string for `recenter' seems to contradict the Emacs manual (node Scrolling). The manual says that `C-l' with a prefix arg does not redraw the frame - and that is mentioned specifically in the context of a numeric arg. The doc string says that redrawing is inhibited for plain `C-u'; it suggests that redrawing occurs for numeric ARG. Here's the new definition I'd propose: (defun recenter-top-bottom (&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)) (t (recenter scroll-conservatively))))))) Note that this code could be optimized by replacing the multiple `count-lines' calls with a single-traversal pickup of top, bottom and current values. I don't think such optimization is needed here, however.