changeset 23789:7d763e90da82

(hscroll-mode, hscroll-global-mode, hscroll-window-maybe): Use a timer instead of post-command-hook. (hscroll-timer): New variable.
author Richard M. Stallman <rms@gnu.org>
date Tue, 01 Dec 1998 03:58:37 +0000
parents 764497f1c6a0
children c1dbb92db43e
files lisp/hscroll.el
diffstat 1 files changed, 13 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/hscroll.el	Tue Dec 01 00:50:45 1998 +0000
+++ b/lisp/hscroll.el	Tue Dec 01 03:58:37 1998 +0000
@@ -21,7 +21,7 @@
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
-;;; Commentary:a
+;;; Commentary:
 ;;
 ;;    Automatically scroll horizontally when the point moves off the
 ;;    left or right edge of the window.  
@@ -109,6 +109,8 @@
   "Non-nil if HScroll mode is enabled.")
 (make-variable-buffer-local 'hscroll-mode)
 
+(defvar hscroll-timer nil
+  "Timer used by HScroll mode.")
 
 (defvar hscroll-old-truncate-local nil)
 (defvar hscroll-old-truncate-was-global nil)
@@ -134,7 +136,6 @@
 right when point gets near either edge of the window.
   See also \\[hscroll-global-mode]."
   (interactive "P")
-  (make-local-hook 'post-command-hook)
   (let ((newmode (if (null arg)
 		      (not hscroll-mode)
 		    (> (prefix-numeric-value arg) 0))))
@@ -148,9 +149,8 @@
 		  (setq hscroll-old-truncate-local truncate-lines))
 	      (setq hscroll-old-truncate-was-global (not localp))
 	      (setq truncate-lines t)
-	      (add-hook 'post-command-hook 
-			(function hscroll-window-maybe) nil t)
-	      ))
+              (setq hscroll-timer
+                    (run-with-idle-timer 0 t 'hscroll-window-maybe))))
       ;; turn it off
       (if hscroll-mode
 	  ;; it was on
@@ -160,14 +160,10 @@
 	      (setq truncate-lines hscroll-old-truncate-local))
 	    (if (not truncate-lines)
 		(set-window-hscroll (selected-window) 0))
-	    (remove-hook 'post-command-hook
-			 (function hscroll-window-maybe) t)
-	    ))
-      )
+            (cancel-timer hscroll-timer))))
 
     (setq hscroll-mode newmode)
-    (force-mode-line-update nil)
-    ))
+    (force-mode-line-update nil)))
 
 
 ;;;###autoload
@@ -192,20 +188,17 @@
 	      (setq hscroll-old-truncate-default (default-value truncate-lines))
 	      (setq hscroll-old-truncate-was-global t)
 	      (setq-default truncate-lines t)
-	      (add-hook 'post-command-hook (function hscroll-window-maybe))
-	      ))
+              (setq hscroll-timer
+                    (run-with-idle-timer 0 t 'hscroll-window-maybe))))
       ;; turn it off
       (if hscroll-mode
 	  ;; it was on
 	  (progn
 	    (setq-default truncate-lines hscroll-old-truncate-default)
-	    (remove-hook 'post-command-hook (function hscroll-window-maybe))
-	    ))
-      )
+            (cancel-timer hscroll-timer))))
 
     (setq-default hscroll-mode newmode)
-    (force-mode-line-update t)
-    ))
+    (force-mode-line-update t)))
 
 (defun hscroll-window-maybe ()
   "Scroll horizontally if point is off or nearly off the edge of the window.
@@ -221,8 +214,7 @@
 	       (and truncate-partial-width-windows
 		    (< (window-width) (frame-width)))))
       (let ((linelen (save-excursion (end-of-line) (current-column)))
-	    (rightmost-char (+ (window-width) (window-hscroll)))
-	    )
+	    (rightmost-char (+ (window-width) (window-hscroll))))
  	(if (< (current-column) hscroll-snap-threshold)
  	    (set-window-hscroll 
  	     (selected-window) 
@@ -244,9 +236,7 @@
 	      ;; Scroll to the right a proportion of the window's width.
 	      (set-window-hscroll
 	       (selected-window)
-	       (- (current-column) (/ (* (window-width) hscroll-step-percent) 100)))
-	    )))
-	)))
+	       (- (current-column) (/ (* (window-width) hscroll-step-percent) 100)))))))))
 
 ;;; 
 ;;; It's not a bug, it's a *feature*