diff lisp/simple.el @ 2597:562d2dea4f05

(hscroll-step): New variable. (hscroll-point-visible): New function. (left-arrow, right-arrow): These use hscroll-point-visible for better auto- scrolling behavior.
author Eric S. Raymond <esr@snark.thyrsus.com>
date Tue, 27 Apr 1993 22:01:32 +0000
parents b28675709d41
children cd5e799be39b
line wrap: on
line diff
--- a/lisp/simple.el	Tue Apr 27 21:59:59 1993 +0000
+++ b/lisp/simple.el	Tue Apr 27 22:01:32 1993 +0000
@@ -1387,28 +1387,47 @@
 	     goal-column))
   nil)
 
+;;; Partial support for horizontal autoscrolling.  Someday, this feature
+;;; will be built into the C level and all the (hscroll-point-visible) calls
+;;; will go away.
+
+(defvar hscroll-step 0
+   "*The number of columns to try scrolling a window by when point moves out.
+If that fails to bring point back on frame, point is centered instead.
+If this is zero, point is always centered after it moves off frame.")
+
+(defun hscroll-point-visible ()
+  "Scrolls the window horizontally to make point visible."
+  (let*  ((min (window-hscroll))
+          (max (- (+ min (window-width)) 2))
+          (here (current-column))
+          (delta (if (zerop hscroll-step) (/ (window-width) 2) hscroll-step))
+          )
+    (if (< here min)
+        (scroll-right (max 0 (+ (- min here) delta)))
+      (if (>= here  max)
+          (scroll-left (- (- here min) delta))
+        ))))
+  
 ;;; Make arrow keys do the right thing for improved terminal support
 ;;; When we implement true horizontal autoscrolling, right-arrow and
 ;;; left-arrow can lose the (if truncate-lines ...) clause and become
-;;; aliases.
+;;; aliases.  These functions are bound to the corresponding keyboard
+;;; events in loaddefs.el.
 
 (defun right-arrow (arg)
   "Move right one character on the screen (with prefix ARG, that many chars).
 Scroll right if needed to keep point horizontally onscreen."
   (interactive "P")
   (forward-char arg)
-  (if truncate-lines
-      (let ((x (current-column)) (w (- (window-width) 2)))
-	(set-window-hscroll (selected-window) (- x (% x w)) ))))
+  (hscroll-point-visible))
 
 (defun left-arrow (arg)
   "Move left one character on the screen (with prefix ARG, that many chars).
 Scroll left if needed to keep point horizontally onscreen."
   (interactive "P")
   (backward-char arg)
-  (if truncate-lines
-      (let ((x (current-column)) (w (- (window-width) 2)))
-	(set-window-hscroll (selected-window) (- x (% x w)) ))))
+  (hscroll-point-visible))
 
 (defun down-arrow (arg)
   "Move down one line on the screen (with prefix ARG, that many lines).