aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-12-01 03:58:37 +0000
committerRichard M. Stallman1998-12-01 03:58:37 +0000
commitf1a64115804be490625d21880e0e22f4b382adbd (patch)
tree1c0acf5f74a28790d0f3e5466cc311ac79abf80e
parent2a48d24b3b155514c2f9c9f1cc21faef6a486240 (diff)
downloademacs-f1a64115804be490625d21880e0e22f4b382adbd.tar.gz
emacs-f1a64115804be490625d21880e0e22f4b382adbd.zip
(hscroll-mode, hscroll-global-mode, hscroll-window-maybe):
Use a timer instead of post-command-hook. (hscroll-timer): New variable.
-rw-r--r--lisp/hscroll.el36
1 files changed, 13 insertions, 23 deletions
diff --git a/lisp/hscroll.el b/lisp/hscroll.el
index 0bcac3a1fa0..c6b6cc1c4eb 100644
--- a/lisp/hscroll.el
+++ b/lisp/hscroll.el
@@ -21,7 +21,7 @@
21;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 21;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22;; Boston, MA 02111-1307, USA. 22;; Boston, MA 02111-1307, USA.
23 23
24;;; Commentary:a 24;;; Commentary:
25;; 25;;
26;; Automatically scroll horizontally when the point moves off the 26;; Automatically scroll horizontally when the point moves off the
27;; left or right edge of the window. 27;; left or right edge of the window.
@@ -109,6 +109,8 @@ Set this to nil to conserve valuable mode line space."
109 "Non-nil if HScroll mode is enabled.") 109 "Non-nil if HScroll mode is enabled.")
110(make-variable-buffer-local 'hscroll-mode) 110(make-variable-buffer-local 'hscroll-mode)
111 111
112(defvar hscroll-timer nil
113 "Timer used by HScroll mode.")
112 114
113(defvar hscroll-old-truncate-local nil) 115(defvar hscroll-old-truncate-local nil)
114(defvar hscroll-old-truncate-was-global nil) 116(defvar hscroll-old-truncate-was-global nil)
@@ -134,7 +136,6 @@ In HScroll mode, truncated lines will automatically scroll left or
134right when point gets near either edge of the window. 136right when point gets near either edge of the window.
135 See also \\[hscroll-global-mode]." 137 See also \\[hscroll-global-mode]."
136 (interactive "P") 138 (interactive "P")
137 (make-local-hook 'post-command-hook)
138 (let ((newmode (if (null arg) 139 (let ((newmode (if (null arg)
139 (not hscroll-mode) 140 (not hscroll-mode)
140 (> (prefix-numeric-value arg) 0)))) 141 (> (prefix-numeric-value arg) 0))))
@@ -148,9 +149,8 @@ right when point gets near either edge of the window.
148 (setq hscroll-old-truncate-local truncate-lines)) 149 (setq hscroll-old-truncate-local truncate-lines))
149 (setq hscroll-old-truncate-was-global (not localp)) 150 (setq hscroll-old-truncate-was-global (not localp))
150 (setq truncate-lines t) 151 (setq truncate-lines t)
151 (add-hook 'post-command-hook 152 (setq hscroll-timer
152 (function hscroll-window-maybe) nil t) 153 (run-with-idle-timer 0 t 'hscroll-window-maybe))))
153 ))
154 ;; turn it off 154 ;; turn it off
155 (if hscroll-mode 155 (if hscroll-mode
156 ;; it was on 156 ;; it was on
@@ -160,14 +160,10 @@ right when point gets near either edge of the window.
160 (setq truncate-lines hscroll-old-truncate-local)) 160 (setq truncate-lines hscroll-old-truncate-local))
161 (if (not truncate-lines) 161 (if (not truncate-lines)
162 (set-window-hscroll (selected-window) 0)) 162 (set-window-hscroll (selected-window) 0))
163 (remove-hook 'post-command-hook 163 (cancel-timer hscroll-timer))))
164 (function hscroll-window-maybe) t)
165 ))
166 )
167 164
168 (setq hscroll-mode newmode) 165 (setq hscroll-mode newmode)
169 (force-mode-line-update nil) 166 (force-mode-line-update nil)))
170 ))
171 167
172 168
173;;;###autoload 169;;;###autoload
@@ -192,20 +188,17 @@ will have no effect on it).
192 (setq hscroll-old-truncate-default (default-value truncate-lines)) 188 (setq hscroll-old-truncate-default (default-value truncate-lines))
193 (setq hscroll-old-truncate-was-global t) 189 (setq hscroll-old-truncate-was-global t)
194 (setq-default truncate-lines t) 190 (setq-default truncate-lines t)
195 (add-hook 'post-command-hook (function hscroll-window-maybe)) 191 (setq hscroll-timer
196 )) 192 (run-with-idle-timer 0 t 'hscroll-window-maybe))))
197 ;; turn it off 193 ;; turn it off
198 (if hscroll-mode 194 (if hscroll-mode
199 ;; it was on 195 ;; it was on
200 (progn 196 (progn
201 (setq-default truncate-lines hscroll-old-truncate-default) 197 (setq-default truncate-lines hscroll-old-truncate-default)
202 (remove-hook 'post-command-hook (function hscroll-window-maybe)) 198 (cancel-timer hscroll-timer))))
203 ))
204 )
205 199
206 (setq-default hscroll-mode newmode) 200 (setq-default hscroll-mode newmode)
207 (force-mode-line-update t) 201 (force-mode-line-update t)))
208 ))
209 202
210(defun hscroll-window-maybe () 203(defun hscroll-window-maybe ()
211 "Scroll horizontally if point is off or nearly off the edge of the window. 204 "Scroll horizontally if point is off or nearly off the edge of the window.
@@ -221,8 +214,7 @@ invoked as well (i.e., it can be bound to a key)."
221 (and truncate-partial-width-windows 214 (and truncate-partial-width-windows
222 (< (window-width) (frame-width))))) 215 (< (window-width) (frame-width)))))
223 (let ((linelen (save-excursion (end-of-line) (current-column))) 216 (let ((linelen (save-excursion (end-of-line) (current-column)))
224 (rightmost-char (+ (window-width) (window-hscroll))) 217 (rightmost-char (+ (window-width) (window-hscroll))))
225 )
226 (if (< (current-column) hscroll-snap-threshold) 218 (if (< (current-column) hscroll-snap-threshold)
227 (set-window-hscroll 219 (set-window-hscroll
228 (selected-window) 220 (selected-window)
@@ -244,9 +236,7 @@ invoked as well (i.e., it can be bound to a key)."
244 ;; Scroll to the right a proportion of the window's width. 236 ;; Scroll to the right a proportion of the window's width.
245 (set-window-hscroll 237 (set-window-hscroll
246 (selected-window) 238 (selected-window)
247 (- (current-column) (/ (* (window-width) hscroll-step-percent) 100))) 239 (- (current-column) (/ (* (window-width) hscroll-step-percent) 100)))))))))
248 )))
249 )))
250 240
251;;; 241;;;
252;;; It's not a bug, it's a *feature* 242;;; It's not a bug, it's a *feature*