* net/tramp.el (tramp-read-passwd): Suspend the timers while reading
[bpt/emacs.git] / lisp / whitespace.el
index 382d6f4..83bd4e0 100644 (file)
@@ -1,6 +1,6 @@
 ;;; whitespace.el --- minor mode to visualize TAB, (HARD) SPACE, NEWLINE
 
-;; Copyright (C) 2000-2013 Free Software Foundation, Inc.
+;; Copyright (C) 2000-2014 Free Software Foundation, Inc.
 
 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
 ;; Thanks to Andreas Roehler <andreas.roehler@easy-emacs.de> for
 ;; indicating defface byte-compilation warnings.
 ;;
-;; Thanks to TimOCallaghan (EmacsWiki) for the idea about highlight
+;; Thanks to Tim O'Callaghan (EmacsWiki) for the idea about highlight
 ;; "long" lines.  See EightyColumnRule (EmacsWiki).
 ;;
 ;; Thanks to Yanghui Bian <yanghuibian@gmail.com> for indicating a new
@@ -557,7 +557,7 @@ See also `whitespace-display-mappings' for documentation."
 (defvar whitespace-space 'whitespace-space
   "Symbol face used to visualize SPACE.
 Used when `whitespace-style' includes the value `spaces'.")
-(make-obsolete-variable 'whitespace-space "use the face instead" "24.4")
+(make-obsolete-variable 'whitespace-space "use the face instead." "24.4")
 
 
 (defface whitespace-space
@@ -573,7 +573,7 @@ Used when `whitespace-style' includes the value `spaces'.")
 (defvar whitespace-hspace 'whitespace-hspace
   "Symbol face used to visualize HARD SPACE.
 Used when `whitespace-style' includes the value `spaces'.")
-(make-obsolete-variable 'whitespace-hspace "use the face instead" "24.4")
+(make-obsolete-variable 'whitespace-hspace "use the face instead." "24.4")
 
 (defface whitespace-hspace             ; 'nobreak-space
   '((((class color) (background dark))
@@ -588,7 +588,7 @@ Used when `whitespace-style' includes the value `spaces'.")
 (defvar whitespace-tab 'whitespace-tab
   "Symbol face used to visualize TAB.
 Used when `whitespace-style' includes the value `tabs'.")
-(make-obsolete-variable 'whitespace-tab "use the face instead" "24.4")
+(make-obsolete-variable 'whitespace-tab "use the face instead." "24.4")
 
 (defface whitespace-tab
   '((((class color) (background dark))
@@ -605,7 +605,7 @@ Used when `whitespace-style' includes the value `tabs'.")
 See `whitespace-display-mappings'.
 Used when `whitespace-style' includes the values `newline-mark'
 and `newline'.")
-(make-obsolete-variable 'whitespace-newline "use the face instead" "24.4")
+(make-obsolete-variable 'whitespace-newline "use the face instead." "24.4")
 
 (defface whitespace-newline
   '((default :weight normal)
@@ -624,7 +624,7 @@ See `whitespace-display-mappings'."
 (defvar whitespace-trailing 'whitespace-trailing
   "Symbol face used to visualize trailing blanks.
 Used when `whitespace-style' includes the value `trailing'.")
-(make-obsolete-variable 'whitespace-trailing "use the face instead" "24.4")
+(make-obsolete-variable 'whitespace-trailing "use the face instead." "24.4")
 
 (defface whitespace-trailing           ; 'trailing-whitespace
   '((default :weight bold)
@@ -638,7 +638,7 @@ Used when `whitespace-style' includes the value `trailing'.")
   "Symbol face used to visualize \"long\" lines.
 See `whitespace-line-column'.
 Used when `whitespace-style' includes the value `line'.")
-(make-obsolete-variable 'whitespace-line "use the face instead" "24.4")
+(make-obsolete-variable 'whitespace-line "use the face instead." "24.4")
 
 (defface whitespace-line
   '((((class mono)) :inverse-video t :weight bold :underline t)
@@ -653,7 +653,7 @@ See `whitespace-line-column'."
   "Symbol face used to visualize SPACEs before TAB.
 Used when `whitespace-style' includes the value `space-before-tab'.")
 (make-obsolete-variable 'whitespace-space-before-tab
-                        "use the face instead" "24.4")
+                        "use the face instead." "24.4")
 
 (defface whitespace-space-before-tab
   '((((class mono)) :inverse-video t :weight bold :underline t)
@@ -665,7 +665,7 @@ Used when `whitespace-style' includes the value `space-before-tab'.")
 (defvar whitespace-indentation 'whitespace-indentation
   "Symbol face used to visualize 8 or more SPACEs at beginning of line.
 Used when `whitespace-style' includes the value `indentation'.")
-(make-obsolete-variable 'whitespace-indentation "use the face instead" "24.4")
+(make-obsolete-variable 'whitespace-indentation "use the face instead." "24.4")
 
 (defface whitespace-indentation
   '((((class mono)) :inverse-video t :weight bold :underline t)
@@ -677,7 +677,7 @@ Used when `whitespace-style' includes the value `indentation'.")
 (defvar whitespace-empty 'whitespace-empty
   "Symbol face used to visualize empty lines at beginning and/or end of buffer.
 Used when `whitespace-style' includes the value `empty'.")
-(make-obsolete-variable 'whitespace-empty "use the face instead" "24.4")
+(make-obsolete-variable 'whitespace-empty "use the face instead." "24.4")
 
 (defface whitespace-empty
   '((((class mono)) :inverse-video t :weight bold :underline t)
@@ -690,7 +690,7 @@ Used when `whitespace-style' includes the value `empty'.")
   "Symbol face used to visualize 8 or more SPACEs after TAB.
 Used when `whitespace-style' includes the value `space-after-tab'.")
 (make-obsolete-variable 'whitespace-space-after-tab
-                        "use the face instead" "24.4")
+                        "use the face instead." "24.4")
 
 (defface whitespace-space-after-tab
   '((((class mono)) :inverse-video t :weight bold :underline t)
@@ -803,8 +803,8 @@ and the cons cdr is used for TABs visualization.
 
 Used when `whitespace-style' includes `indentation',
 `indentation::tab' or  `indentation::space'."
-  :type '(cons (regexp :tag "Indentation SPACEs")
-              (regexp :tag "Indentation TABs"))
+  :type '(cons (string :tag "Indentation SPACEs")
+              (string :tag "Indentation TABs"))
   :group 'whitespace)
 
 
@@ -834,7 +834,8 @@ and the cons cdr is used for TABs visualization.
 
 Used when `whitespace-style' includes `space-after-tab',
 `space-after-tab::tab' or `space-after-tab::space'."
-  :type '(regexp :tag "SPACEs After TAB")
+  :type '(cons (string :tag "SPACEs After TAB")
+              string)
   :group 'whitespace)
 
 
@@ -1083,7 +1084,7 @@ See also `whitespace-style', `whitespace-newline' and
                (not (memq major-mode (cdr whitespace-global-modes)))
              (memq major-mode whitespace-global-modes)))
           (t nil))
-         ;; ...we have a display (we're running a batch job)
+         ;; ...we have a display (not running a batch job)
          (not noninteractive)
          ;; ...the buffer is not internal (name starts with a space)
          (not (eq (aref (buffer-name) 0) ?\ ))
@@ -1470,6 +1471,12 @@ documentation."
     ;; PROBLEM 6: 8 or more SPACEs after TAB
     (whitespace-cleanup-region (point-min) (point-max)))))
 
+(defun whitespace-ensure-local-variables ()
+  "Set `whitespace-indent-tabs-mode' and `whitespace-tab-width' locally."
+  (set (make-local-variable 'whitespace-indent-tabs-mode)
+       indent-tabs-mode)
+  (set (make-local-variable 'whitespace-tab-width)
+       tab-width))
 
 ;;;###autoload
 (defun whitespace-cleanup-region (start end)
@@ -1516,6 +1523,7 @@ documentation."
       ;; read-only buffer
       (whitespace-warn-read-only "cleanup region")
     ;; non-read-only buffer
+    (whitespace-ensure-local-variables)
     (let ((rstart           (min start end))
          (rend             (copy-marker (max start end)))
          (indent-tabs-mode whitespace-indent-tabs-mode)
@@ -1861,14 +1869,8 @@ cleaning up these problems."
 ;;;; Internal functions
 
 
-(defvar whitespace-font-lock-mode nil
-  "Used to remember whether a buffer had font lock mode on or not.")
-
-(defvar whitespace-font-lock nil
-  "Used to remember whether a buffer initially had font lock on or not.")
-
 (defvar whitespace-font-lock-keywords nil
-  "Used to save locally `font-lock-keywords' value.")
+  "Used to save the value `whitespace-color-on' adds to `font-lock-keywords'.")
 
 
 (defconst whitespace-help-text
@@ -2100,14 +2102,11 @@ resultant list will be returned."
 (defvar whitespace-display-table-was-local nil
   "Used to remember whether a buffer initially had a local display table.")
 
-
 (defun whitespace-turn-on ()
   "Turn on whitespace visualization."
   ;; prepare local hooks
   (add-hook 'write-file-functions 'whitespace-write-file-hook nil t)
   ;; create whitespace local buffer environment
-  (set (make-local-variable 'whitespace-font-lock-mode) nil)
-  (set (make-local-variable 'whitespace-font-lock) nil)
   (set (make-local-variable 'whitespace-font-lock-keywords) nil)
   (set (make-local-variable 'whitespace-display-table) nil)
   (set (make-local-variable 'whitespace-display-table-was-local) nil)
@@ -2115,10 +2114,7 @@ resultant list will be returned."
        (if (listp whitespace-style)
           whitespace-style
         (list whitespace-style)))
-  (set (make-local-variable 'whitespace-indent-tabs-mode)
-       indent-tabs-mode)
-  (set (make-local-variable 'whitespace-tab-width)
-       tab-width)
+  (whitespace-ensure-local-variables)
   ;; turn on whitespace
   (when whitespace-active-style
     (whitespace-color-on)
@@ -2157,10 +2153,6 @@ resultant list will be returned."
 (defun whitespace-color-on ()
   "Turn on color visualization."
   (when (whitespace-style-face-p)
-    (unless whitespace-font-lock
-      (setq whitespace-font-lock t
-           whitespace-font-lock-keywords
-           (copy-sequence font-lock-keywords)))
     ;; save current point and refontify when necessary
     (set (make-local-variable 'whitespace-point)
         (point))
@@ -2174,13 +2166,9 @@ resultant list will be returned."
         nil)
     (add-hook 'post-command-hook #'whitespace-post-command-hook nil t)
     (add-hook 'before-change-functions #'whitespace-buffer-changed nil t)
-    ;; turn off font lock
-    (set (make-local-variable 'whitespace-font-lock-mode)
-        font-lock-mode)
-    (font-lock-mode 0)
     ;; Add whitespace-mode color into font lock.
-    (font-lock-add-keywords
-     nil
+    (setq
+     whitespace-font-lock-keywords
      `(
        ,@(when (memq 'spaces whitespace-active-style)
            ;; Show SPACEs.
@@ -2257,24 +2245,21 @@ resultant list will be returned."
                 ((memq 'space-after-tab::space whitespace-active-style)
                  ;; Show SPACEs after TAB (TABs).
                  (whitespace-space-after-tab-regexp 'space)))
-              1 whitespace-space-after-tab t))))
-     t)
-    ;; Now turn on font lock and highlight blanks.
-    (font-lock-mode 1)))
+              1 whitespace-space-after-tab t)))))
+    (font-lock-add-keywords nil whitespace-font-lock-keywords t)
+    (when font-lock-mode
+      (font-lock-fontify-buffer))))
 
 
 (defun whitespace-color-off ()
   "Turn off color visualization."
   ;; turn off font lock
   (when (whitespace-style-face-p)
-    (font-lock-mode 0)
     (remove-hook 'post-command-hook #'whitespace-post-command-hook t)
     (remove-hook 'before-change-functions #'whitespace-buffer-changed t)
-    (when whitespace-font-lock
-      (setq whitespace-font-lock nil
-           font-lock-keywords   whitespace-font-lock-keywords))
-    ;; restore original font lock state
-    (font-lock-mode whitespace-font-lock-mode)))
+    (font-lock-remove-keywords nil whitespace-font-lock-keywords)
+    (when font-lock-mode
+      (font-lock-fontify-buffer))))
 
 
 (defun whitespace-trailing-regexp (limit)