Mats Lidell avatar Mats Lidell committed c6b1500

recenter-top-bottom synced from GNU and new default for C-l

Partial implementation of recenter-top-bottom. GNU has support for
scroll-margin that is not in XEmacs so that is left out.

lisp/ChangeLog:

2012-09-18 Mats Lidell <matsl@xemacs.org>;

* window-xemacs.el (recenter-positions): New defcustom.
(recenter-top-bottom): New command.
(recenter-last-op): New defvar.

* replace.el (perform-replace): Let-bind recenter-last-op to nil.
For def=recenter, replace `recenter' with `recenter-top-bottom'
that is called with `this-command' and `last-command' let-bound to
`recenter-top-bottom'. When the last `def' was not `recenter',
set `recenter-last-op' to nil.

* keydefs.el (global-map): Make recenter-top-bottom new default
for C-l.

etc/ChangeLog:

2012-09-18 Mats Lidell <matsl@xemacs.org>;

* TUTORIAL: Updated due to recenter-top-bottom

man/ChangeLog:

2012-09-18 Mats Lidell <matsl@xemacs.org>;

* lispref/windows.texi (Vertical Scrolling): Added
recenter-top-bottom and recenter-positions

* xemacs/display.texi (Display): Rearranged and added
documentation due to new function recenter-top-bottom.

Comments (0)

Files changed (9)

+2012-09-18  Mats Lidell  <matsl@xemacs.org>
+
+	* TUTORIAL: Updated due to recenter-top-bottom
+
 2012-08-02  Stephen J. Turnbull  <stephen@xemacs.org>
 
 	* XEmacs 21.5.32 "habanero" is released.
 		 to the center of the window.
 		 (That's CONTROL-L, not CONTROL-1.)
 
->> Find the cursor, and note what text is near it.
-   Then type C-l.
-   Find the cursor again and notice that the same text
-   is near the cursor now.
-
+>> Find the cursor, and note what text is near it. Then type C-l.
+   Find the cursor again and notice that the same text is still near
+   the cursor, but now it is in the center of the screen.
+   If you press C-l again, this piece of text will move to the top of
+   the screen.  Press C-l again, and it moves to the bottom.
 
 * SOME TERMINOLOGY
 ------------------
 COPYRIGHTS, COPYING, ORIGINS
 ----------------------------
 
-Copyright (c) 1985, 1996 Free Software Foundation.
+Copyright (c) 1985, 1996, 2012 Free Software Foundation.
 Copyright (c) 2001 Ben Wing.
 This tutorial is synched with FSF 21.0.106.
 
+2012-09-18  Mats Lidell  <matsl@xemacs.org>
+
+	* window-xemacs.el (recenter-positions): New defcustom.
+	(recenter-top-bottom): New command.
+	(recenter-last-op): New defvar.
+
+	* replace.el (perform-replace): Let-bind recenter-last-op to nil.
+	For def=recenter, replace `recenter' with `recenter-top-bottom'
+	that is called with `this-command' and `last-command' let-bound to
+	`recenter-top-bottom'.  When the last `def' was not `recenter',
+	set `recenter-last-op' to nil.
+
+	* keydefs.el (global-map): Make recenter-top-bottom new default
+	for C-l.
+
 2012-09-08  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* simple.el:
 ;;; keydefs.el --- Define standard keybindings.
 
-;; Copyright (C) 1992-4, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1992-4, 1997, 2012 Free Software Foundation, Inc.
 ;; Copyright (C) 2000, 2001, 2002 Ben Wing.
 
 ;; Maintainer: XEmacs Development Team
 ; meta-shift-V, that is.
 (define-key global-map '(meta V) 'scroll-other-window-down)
 
-(define-key global-map "\C-l" 'recenter)
+(define-key global-map "\C-l" 'recenter-top-bottom)
 (define-key global-map "\M-r" 'move-to-window-line)
 
 ;; FSFmacs window.el
 ;;; replace.el --- search and replace commands for XEmacs.
 
-;; Copyright (C) 1985-7, 1992, 1994, 1997, 2003 Free Software Foundation, Inc.
+;; Copyright (C) 1985-7, 1992, 1994, 1997, 2003, 2012 Free Software Foundation, Inc.
 
 ;; Maintainer: XEmacs Development Team
 ;; Keywords: dumped, matching
 	 ;; stop.
 	 (limit nil)
 	 (match-again t)
+	 (recenter-last-op nil) ; Start cycling order with initial position.
 	 ;; XEmacs addition
 	 (qr-case-fold-search
 	  (if (and case-fold-search search-caps-disable-folding)
 		      ((eq def 'skip)
 		       (setq done t))
 		      ((eq def 'recenter)
-		       (recenter nil))
+		       ;; `this-command' has the value `query-replace',
+		       ;; so we need to bind it to `recenter-top-bottom'
+		       ;; to allow it to detect a sequence of `C-l'.
+		       (let ((this-command 'recenter-top-bottom)
+			     (last-command 'recenter-top-bottom))
+			 (recenter-top-bottom)))
 		      ((eq def 'edit)
 		       (store-match-data
 			(prog1 (match-data)
 		       (setq unread-command-events
 			     (cons event unread-command-events))
 		       (setq done t))))
+	      (unless (eq def 'recenter)
+		;; Reset recenter cycling order to initial position.
+		(setq recenter-last-op nil))
 	      ;; Record previous position for ^ when we move on.
 	      ;; Change markers to numbers in the match data
 	      ;; since lots of markers slow down editing.

lisp/window-xemacs.el

 ;;; window-xemacs.el --- XEmacs window commands aside from those written in C.
 
-;; Copyright (C) 1985, 1989, 1993-94, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1989, 1993-94, 1997, 2012 Free Software Foundation, Inc.
 ;; Copyright (C) 1995, 1996 Ben Wing.
 
 ;; Maintainer: XEmacs Development Team
 ;; You should have received a copy of the GNU General Public License
 ;; along with XEmacs.  If not, see <http://www.gnu.org/licenses/>.
 
-;;; Synched up with: Not synched.
+;;; Synched up with: Not synched except for partial sync of
+;;; recenter-top-bottom
 
 ;;; Commentary:
 
   (when (null n)
     (redraw-frame (window-frame window) t)))
 
+(defvar recenter-last-op nil
+  "Indicates the last recenter operation performed.
+Possible values: `top', `middle', `bottom', integer or float numbers.")
+
+;; Merged from FSF 23.2 with use of scroll-margin for top and bottom
+;; destinations removed. We don't support scroll-margin.
+(defcustom recenter-positions '(middle top bottom)
+  "Cycling order for `recenter-top-bottom'.
+A list of elements with possible values `top', `middle', `bottom',
+integer or float numbers that define the cycling order for
+the command `recenter-top-bottom'.
+
+Top and bottom destinations are the window top and bottom.  Middle
+redraws the frame and centers point vertically within the window.
+Integer number moves current line to the specified absolute
+window-line.  Float number between 0.0 and 1.0 means the percentage of
+the screen space from the top.  The default cycling order is middle ->
+top -> bottom."
+  :type '(repeat (choice
+		  (const :tag "Top" top)
+		  (const :tag "Middle" middle)
+		  (const :tag "Bottom" bottom)
+		  (integer :tag "Line number")
+		  (float :tag "Percentage")))
+  :version "23.2"
+  :group 'windows)
+
+(defun recenter-top-bottom (&optional arg)
+  "Move current buffer line to the specified window line.
+With no prefix argument, successive calls place point according
+to the cycling order defined by `recenter-positions'.
+
+A prefix argument is handled like `recenter':
+ With numeric prefix ARG, move current line to window-line ARG.
+ With plain `C-u', move current line to window center."
+  (interactive "P")
+  (cond
+   (arg (recenter arg))			; Always respect ARG.
+   (t
+    (setq recenter-last-op
+	  (if (eq this-command last-command)
+	      (car (or (cdr (member recenter-last-op recenter-positions))
+		       recenter-positions))
+	    (car recenter-positions)))
+    (cond ((eq recenter-last-op 'middle)
+	   (recenter))
+	  ((eq recenter-last-op 'top)
+	   (recenter 0))
+	  ((eq recenter-last-op 'bottom)
+	   (recenter -1))
+	  ((integerp recenter-last-op)
+	   (recenter recenter-last-op))
+	  ((floatp recenter-last-op)
+	   (recenter (round (* recenter-last-op (window-height)))))))))
+
 (defun backward-other-window (count &optional which-frames which-devices)
   "Select the COUNT'th different window on this frame, going backwards.
 This is just like calling `other-window' with COUNT negated."
+2012-09-18  Mats Lidell  <matsl@xemacs.org>
+
+	* lispref/windows.texi (Vertical Scrolling): Added
+	recenter-top-bottom and recenter-positions
+
+	* xemacs/display.texi (Display): Rearranged and added
+	documentation due to new function recenter-top-bottom.
+
 2012-08-06  Aidan Kehoe  <kehoea@parhasard.net>
 
 	* lispref/symbols.texi (Symbol Components):

man/lispref/windows.texi

 @c -*-texinfo-*-
 @c This is part of the XEmacs Lisp Reference Manual.
-@c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
+@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 2012 Free Software Foundation, Inc.
 @c See the file lispref.texi for copying conditions.
 @setfilename ../../info/windows.info
 @node Windows, Frames, Buffers, Top
 @end example
 @end deffn
 
+@deffn Command recenter-top-bottom &optional count
+This command, which is the default binding for @kbd{C-l}, acts like
+@code{recenter}, except if called with no argument.  In that case,
+successive calls place point according to the cycling order defined
+by the variable @code{recenter-positions}.
+@end deffn
+
+@defopt recenter-positions
+This variable controls how @code{recenter-top-bottom} behaves when
+called with no argument.  The default value is @code{(middle top
+bottom)}, which means that successive calls of
+@code{recenter-top-bottom} with no argument cycle between placing
+point at the middle, top, and bottom of the window.
+@end defopt
+
+
 @node Horizontal Scrolling
 @section Horizontal Scrolling
 @cindex horizontal scrolling

man/xemacs/display.texi

 @table @kbd
 @item C-l
 Clear frame and redisplay, scrolling the selected window to center
-point vertically within it (@code{recenter}).
+point vertically within it (@code{recenter-top-bottom}).
 @item C-v
 @itemx pgdn
 @itemx next
 
 @menu
 * Scrolling::	           Moving text up and down in a window.
+* Recentering::            A scroll command that centers the current line.
+* Automatic Scrolling::    Redisplay scrolls text automatically when needed.
 * Horizontal Scrolling::   Moving text left and right in a window.
 * Selective Display::      Hiding lines with lots of indentation.
 * Display Vars::           Information on variables for customizing display.
 @end menu
 
-@node Scrolling, Horizontal Scrolling, Display, Display
+@node Scrolling, Recentering, Display, Display
 @section Scrolling
 
   If a buffer contains text that is too large to fit entirely within the
 
 @ifinfo
 @table @kbd
-@item C-l
-Clear frame and redisplay, scrolling the selected window to center
-point vertically within it (@code{recenter}).
 @item C-v
 @itemx pgdn
 @itemx next
 @itemx pgup
 @itemx prior
 Scroll backward (@code{scroll-down}).
-@item @var{arg} C-l
-Scroll so point is on line @var{arg} (@code{recenter}).
 @end table
 @end ifinfo
 
-@kindex C-l
-@findex recenter
-  The most basic scrolling command is @kbd{C-l} (@code{recenter}) with no
-argument.  It clears the entire frame and redisplays all windows.  In
-addition, it scrolls the selected window so that point is halfway down
-from the top of the window.
-
 @kindex C-v
 @kindex M-v
 @kindex pgup
 across a @kbd{C-v} or @kbd{M-v} is controlled by the variable
 @code{next-screen-context-lines}; by default, it is two.
 
-  Another way to scroll is using @kbd{C-l} with a numeric argument.
-@kbd{C-l} does not clear the frame when given an argument; it only
-scrolls the selected window.  With a positive argument @var{n}, @kbd{C-l}
-repositions text to put point @var{n} lines down from the top.  An
-argument of zero puts point on the very top line.  Point does not move
-with respect to the text; rather, the text and point move rigidly on the
-frame.  @kbd{C-l} with a negative argument puts point that many lines
-from the bottom of the window.  For example, @kbd{C-u - 1 C-l} puts
-point on the bottom line, and @kbd{C-u - 5 C-l} puts it five lines from
-the bottom.  Just @kbd{C-u} as argument, as in @kbd{C-u C-l}, scrolls
-point to the center of the frame.
+@node Recentering, Automatic Scrolling, Scrolling, Display
+@section Recentering
+
+@table @kbd
+@item C-l
+Scroll the selected window so the current line is the center-most text
+line; on subsequent consecutive invocations, make the current line the
+top line, the bottom line, and so on in cyclic order.  Possibly
+redisplay the screen too (@code{recenter-top-bottom}).
+
+@item M-x recenter
+Scroll the selected window so the current line is the center-most text
+line.  Possibly redisplay the screen too.
+
+@item C-M-l
+Scroll heuristically to bring useful information onto the screen
+(@code{reposition-window}).
+@end table
+
+@kindex C-l
+@findex recenter-top-bottom
+  The @kbd{C-l} (@code{recenter-top-bottom}) command @dfn{recenters}
+the selected window, scrolling it so that the current screen line is
+exactly in the center of the window, or as close to the center as
+possible.
+
+  Typing @kbd{C-l} twice in a row (@kbd{C-l C-l}) scrolls the window
+so that point is on the topmost screen line.  Typing a third @kbd{C-l}
+scrolls the window so that point is on the bottom-most screen line.
+Each successive @kbd{C-l} cycles through these three positions.
+
+@vindex recenter-positions
+  You can change the cycling order by customizing the list variable
+@code{recenter-positions}.  Each list element should be the symbol
+@code{top}, @code{middle}, or @code{bottom}, or a number; an integer
+means to move the line to the specified screen line, while a
+floating-point number between 0.0 and 1.0 specifies a percentage of
+the screen space from the top of the window.  The default,
+@code{(middle top bottom)}, is the cycling order described above.
+Furthermore, if you change the variable @code{scroll-margin} to a
+non-zero value @var{n}, @kbd{C-l} always leaves at least @var{n}
+screen lines between point and the top or bottom of the window
+(@pxref{Automatic Scrolling}).
+
+  You can also give @kbd{C-l} a prefix argument.  A plain prefix
+argument, @kbd{C-u C-l}, simply recenters point.  A positive argument
+@var{n} puts point @var{n} lines down from the top of the window.  An
+argument of zero puts point on the topmost line.  A negative argument
+@var{-n} puts point @var{n} lines from the bottom of the window.  When
+given an argument, @kbd{C-l} does not clear the screen or cycle
+through different screen positions.
+
+@findex recenter
+  The more primitive command @kbd{M-x recenter} behaves like
+@code{recenter-top-bottom}, but does not cycle among screen positions.
+
+@node Automatic Scrolling, Horizontal Scrolling, Recentering, Display
+@section Automatic Scrolling
 
 @vindex scroll-step
   Scrolling happens automatically if point has moved out of the visible
 @code{scroll-conservatively} to a small value, which will have the
 result of overriding the redisplay preemption.
 
-@node Horizontal Scrolling,, Scrolling, Display
+@node Horizontal Scrolling, Selective Display, Automatic Scrolling, Display
 @section Horizontal Scrolling
 
 @ifinfo
 the right once it is displaying normally (with each line starting at the
 window's left margin); attempting to do so has no effect.
 
-@node Selective Display, Display Vars, Display, Display
+@node Selective Display, Display Vars, Horizontal Scrolling, Display
 @section Selective Display
 @findex set-selective-display
 @kindex C-x $
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.