comparison lisp/hscroll.el @ 24922:ebff04ce5d74

(hscroll-window-maybe): Do nothing in the minibuffer. (hscroll-mode): Make it a permanent local. (hscroll-mode): Don't cancel the timer if HScroll mode is enabled in some other buffer.
author Richard M. Stallman <rms@gnu.org>
date Mon, 05 Jul 1999 05:42:30 +0000
parents 563d3e9af0fd
children db6ed843d5e8
comparison
equal deleted inserted replaced
24921:036b2fb4944f 24922:ebff04ce5d74
107 ;;; 107 ;;;
108 108
109 (defvar hscroll-mode nil 109 (defvar hscroll-mode nil
110 "Non-nil if HScroll mode is enabled.") 110 "Non-nil if HScroll mode is enabled.")
111 (make-variable-buffer-local 'hscroll-mode) 111 (make-variable-buffer-local 'hscroll-mode)
112 ;; Make it a permanent local
113 ;; so it will only turn off when WE turn it off.
114 (put 'hscroll-mode 'permanent-local t)
112 115
113 (defvar hscroll-timer nil 116 (defvar hscroll-timer nil
114 "Timer used by HScroll mode.") 117 "Timer used by HScroll mode.")
115 118
116 (defvar hscroll-old-truncate-local nil) 119 (defvar hscroll-old-truncate-local nil)
140 (let ((newmode (if (null arg) 143 (let ((newmode (if (null arg)
141 (not hscroll-mode) 144 (not hscroll-mode)
142 (> (prefix-numeric-value arg) 0)))) 145 (> (prefix-numeric-value arg) 0))))
143 146
144 (if newmode 147 (if newmode
145 ;; turn it on 148 ;; Turn it on.
146 (if (not hscroll-mode) 149 (if (not hscroll-mode)
147 ;; it was off 150 ;; It was off.
148 (let ((localp (local-variable-p 'truncate-lines))) 151 (let ((localp (local-variable-p 'truncate-lines)))
149 (if localp 152 (if localp
150 (setq hscroll-old-truncate-local truncate-lines)) 153 (setq hscroll-old-truncate-local truncate-lines))
151 (setq hscroll-old-truncate-was-global (not localp)) 154 (setq hscroll-old-truncate-was-global (not localp))
152 (setq truncate-lines t) 155 (setq truncate-lines t)
153 (setq hscroll-timer 156 (setq hscroll-timer
154 (run-with-idle-timer 0 t 'hscroll-window-maybe)))) 157 (run-with-idle-timer 0 t 'hscroll-window-maybe))))
155 ;; turn it off 158 ;; Turn it off.
156 (if hscroll-mode 159 (if hscroll-mode
157 ;; it was on 160 ;; It was on.
158 (progn 161 (progn
159 (if hscroll-old-truncate-was-global 162 (if hscroll-old-truncate-was-global
160 (kill-local-variable 'truncate-lines) 163 (kill-local-variable 'truncate-lines)
161 (setq truncate-lines hscroll-old-truncate-local)) 164 (setq truncate-lines hscroll-old-truncate-local))
162 (if (not truncate-lines) 165 (if (not truncate-lines)
163 (set-window-hscroll (selected-window) 0)) 166 (set-window-hscroll (selected-window) 0))
164 (cancel-timer hscroll-timer)))) 167 ;; If hscroll is not enabled in any buffer now,
168 ;; turn off the timer.
169 (unless (memq t (mapcar (lambda (buffer)
170 (with-current-buffer buffer
171 hscroll-mode))
172 (buffer-list)))
173 (cancel-timer hscroll-timer)))))
165 174
166 (setq hscroll-mode newmode) 175 (setq hscroll-mode newmode)
167 (force-mode-line-update nil))) 176 (force-mode-line-update nil)))
168 177
169 178
170 ;;;###autoload 179 ;;;###autoload
171 (defun hscroll-global-mode (&optional arg) 180 (defun hscroll-global-mode (&optional arg)
172 "Toggle HScroll mode in all buffers. 181 "Toggle HScroll mode in all buffers (excepting minibuffers).
173 With ARG, turn HScroll mode on if ARG is positive, off otherwise. 182 With ARG, turn HScroll mode on if ARG is positive, off otherwise.
174 If a buffer ever has HScroll mode set locally (via \\[hscroll-mode]), 183 If a buffer ever has HScroll mode set locally (via \\[hscroll-mode]),
175 it will forever use the local value (i.e., \\[hscroll-global-mode] 184 it will forever use the local value (i.e., \\[hscroll-global-mode]
176 will have no effect on it). 185 will have no effect on it).
177 See also \\[hscroll-mode]." 186 See also \\[hscroll-mode]."
202 (force-mode-line-update t))) 211 (force-mode-line-update t)))
203 212
204 (defun hscroll-window-maybe () 213 (defun hscroll-window-maybe ()
205 "Scroll horizontally if point is off or nearly off the edge of the window. 214 "Scroll horizontally if point is off or nearly off the edge of the window.
206 This is called automatically when in HScroll mode, but it can be explicitly 215 This is called automatically when in HScroll mode, but it can be explicitly
207 invoked as well (i.e., it can be bound to a key)." 216 invoked as well (i.e., it can be bound to a key).
217 This does nothing in the minibuffer."
208 (interactive) 218 (interactive)
209 ;; Only consider scrolling if truncate-lines is true, 219 ;; Only consider scrolling if truncate-lines is true,
210 ;; the window is already scrolled or partial-widths is true and this is 220 ;; the window is already scrolled or partial-widths is true and this is
211 ;; a partial width window. See display_text_line() in xdisp.c. 221 ;; a partial width window. See display_text_line in xdisp.c.
212 (if (and hscroll-mode 222 (if (and hscroll-mode
223 (not (window-minibuffer-p (selected-window)))
213 (or truncate-lines 224 (or truncate-lines
214 (not (zerop (window-hscroll))) 225 (not (zerop (window-hscroll)))
215 (and truncate-partial-width-windows 226 (and truncate-partial-width-windows
216 (< (window-width) (frame-width))))) 227 (< (window-width) (frame-width)))))
217 (let ((linelen (save-excursion (end-of-line) (current-column))) 228 (let ((linelen (save-excursion (end-of-line) (current-column)))