]> code.delx.au - gnu-emacs/blobdiff - lisp/hscroll.el
(switch_to_buffer_1): New subroutine, taken out from Fswitch_to_buffer.
[gnu-emacs] / lisp / hscroll.el
index fab0258b07f65a6b5b5f50a65917695df4ccdd99..1afce94055632997a5975c6429eef307ba6c6df4 100644 (file)
@@ -61,8 +61,8 @@
 
 (defcustom hscroll-global-mode nil
   "Toggle horizontal scrolling.
 
 (defcustom hscroll-global-mode nil
   "Toggle horizontal scrolling.
-This variable should be set only with \\[customize], which is equivalent
-to using the function `hscroll-global-mode'.
+Setting this variable directly does not take effect;
+use either \\[customize] or the function `hscroll-global-mode'."
   :set (lambda (symbol value)
         (hscroll-global-mode (if value 1 -1)))
   :initialize 'custom-initialize-default
   :set (lambda (symbol value)
         (hscroll-global-mode (if value 1 -1)))
   :initialize 'custom-initialize-default
@@ -109,6 +109,9 @@ Set this to nil to conserve valuable mode line space."
 (defvar hscroll-mode nil 
   "Non-nil if HScroll mode is enabled.")
 (make-variable-buffer-local 'hscroll-mode)
 (defvar hscroll-mode nil 
   "Non-nil if HScroll mode is enabled.")
 (make-variable-buffer-local 'hscroll-mode)
+;; Make it a permanent local
+;; so it will only turn off when WE turn it off.
+(put 'hscroll-mode 'permanent-local t)
 
 (defvar hscroll-timer nil
   "Timer used by HScroll mode.")
 
 (defvar hscroll-timer nil
   "Timer used by HScroll mode.")
@@ -142,9 +145,9 @@ right when point gets near either edge of the window.
                    (> (prefix-numeric-value arg) 0))))
 
     (if newmode
                    (> (prefix-numeric-value arg) 0))))
 
     (if newmode
-       ;; turn it on
+       ;; Turn it on.
        (if (not hscroll-mode)
        (if (not hscroll-mode)
-           ;; it was off
+           ;; It was off.
            (let ((localp (local-variable-p 'truncate-lines)))
              (if localp
                  (setq hscroll-old-truncate-local truncate-lines))
            (let ((localp (local-variable-p 'truncate-lines)))
              (if localp
                  (setq hscroll-old-truncate-local truncate-lines))
@@ -152,16 +155,22 @@ right when point gets near either edge of the window.
              (setq truncate-lines t)
               (setq hscroll-timer
                     (run-with-idle-timer 0 t 'hscroll-window-maybe))))
              (setq truncate-lines t)
               (setq hscroll-timer
                     (run-with-idle-timer 0 t 'hscroll-window-maybe))))
-      ;; turn it off
+      ;; Turn it off.
       (if hscroll-mode
       (if hscroll-mode
-         ;; it was on
+         ;; It was on.
          (progn
            (if hscroll-old-truncate-was-global
                (kill-local-variable 'truncate-lines)
              (setq truncate-lines hscroll-old-truncate-local))
            (if (not truncate-lines)
                (set-window-hscroll (selected-window) 0))
          (progn
            (if hscroll-old-truncate-was-global
                (kill-local-variable 'truncate-lines)
              (setq truncate-lines hscroll-old-truncate-local))
            (if (not truncate-lines)
                (set-window-hscroll (selected-window) 0))
-            (cancel-timer hscroll-timer))))
+           ;; If hscroll is not enabled in any buffer now,
+           ;; turn off the timer.
+           (unless (memq t (mapcar (lambda (buffer)
+                                     (with-current-buffer buffer
+                                       hscroll-mode))
+                                   (buffer-list)))
+             (cancel-timer hscroll-timer)))))
 
     (setq hscroll-mode newmode)
     (force-mode-line-update nil)))
 
     (setq hscroll-mode newmode)
     (force-mode-line-update nil)))
@@ -169,7 +178,7 @@ right when point gets near either edge of the window.
 
 ;;;###autoload
 (defun hscroll-global-mode  (&optional arg)
 
 ;;;###autoload
 (defun hscroll-global-mode  (&optional arg)
-  "Toggle HScroll mode in all buffers.
+  "Toggle HScroll mode in all buffers (excepting minibuffers).
 With ARG, turn HScroll mode on if ARG is positive, off otherwise.
 If a buffer ever has HScroll mode set locally (via \\[hscroll-mode]), 
 it will forever use the local value (i.e., \\[hscroll-global-mode] 
 With ARG, turn HScroll mode on if ARG is positive, off otherwise.
 If a buffer ever has HScroll mode set locally (via \\[hscroll-mode]), 
 it will forever use the local value (i.e., \\[hscroll-global-mode] 
@@ -187,29 +196,36 @@ will have no effect on it).
            ;; it was off
            (progn
              (setq hscroll-old-truncate-default (default-value truncate-lines))
            ;; it was off
            (progn
              (setq hscroll-old-truncate-default (default-value truncate-lines))
-             (setq hscroll-old-truncate-was-global t)
+             (setq-default hscroll-old-truncate-was-global t)
              (setq-default truncate-lines t)
              (setq-default truncate-lines t)
+             (add-hook 'minibuffer-setup-hook 'hscroll-minibuffer-hook)
               (setq hscroll-timer
                     (run-with-idle-timer 0 t 'hscroll-window-maybe))))
       ;; turn it off
       (if hscroll-mode
          ;; it was on
          (progn
               (setq hscroll-timer
                     (run-with-idle-timer 0 t 'hscroll-window-maybe))))
       ;; turn it off
       (if hscroll-mode
          ;; it was on
          (progn
+           (remove-hook 'minibuffer-setup-hook 'hscroll-minibuffer-hook)
            (setq-default truncate-lines hscroll-old-truncate-default)
             (cancel-timer hscroll-timer))))
 
     (setq-default hscroll-mode newmode)
     (force-mode-line-update t)))
 
            (setq-default truncate-lines hscroll-old-truncate-default)
             (cancel-timer hscroll-timer))))
 
     (setq-default hscroll-mode newmode)
     (force-mode-line-update t)))
 
+(defun hscroll-minibuffer-hook ()
+  (setq truncate-lines hscroll-old-truncate-default))
+
 (defun hscroll-window-maybe ()
   "Scroll horizontally if point is off or nearly off the edge of the window.
 This is called automatically when in HScroll mode, but it can be explicitly
 (defun hscroll-window-maybe ()
   "Scroll horizontally if point is off or nearly off the edge of the window.
 This is called automatically when in HScroll mode, but it can be explicitly
-invoked as well (i.e., it can be bound to a key)."
+invoked as well (i.e., it can be bound to a key).
+This does nothing in the minibuffer."
   (interactive)
   ;; Only consider scrolling if truncate-lines is true, 
   ;; the window is already scrolled or partial-widths is true and this is
   (interactive)
   ;; Only consider scrolling if truncate-lines is true, 
   ;; the window is already scrolled or partial-widths is true and this is
-  ;; a partial width window.  See display_text_line() in xdisp.c.
+  ;; a partial width window.  See display_text_line in xdisp.c.
   (if (and hscroll-mode
   (if (and hscroll-mode
+           (not (window-minibuffer-p (selected-window)))
           (or truncate-lines
               (not (zerop (window-hscroll)))
               (and truncate-partial-width-windows
           (or truncate-lines
               (not (zerop (window-hscroll)))
               (and truncate-partial-width-windows