]> code.delx.au - gnu-emacs/blobdiff - lisp/whitespace.el
* lisp/version.el (emacs-bzr-version-bzr): Fix typo.
[gnu-emacs] / lisp / whitespace.el
index 0346d17954acbbf741e2e6e968f671823b7c1929..7630ffbdb9c3894767a81fec898179a0ebde7c0e 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
@@ -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)
 
 
@@ -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,12 +1869,6 @@ 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 the value `whitespace-color-on' adds to `font-lock-keywords'.")
 
@@ -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,8 +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))
     ;; save current point and refontify when necessary
     (set (make-local-variable 'whitespace-point)
         (point))
@@ -2172,10 +2166,6 @@ 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.
     (setq
      whitespace-font-lock-keywords
@@ -2257,22 +2247,19 @@ resultant list will be returned."
                  (whitespace-space-after-tab-regexp 'space)))
               1 whitespace-space-after-tab t)))))
     (font-lock-add-keywords nil whitespace-font-lock-keywords t)
-    ;; Now turn on font lock and highlight blanks.
-    (font-lock-mode 1)))
+    (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-remove-keywords nil whitespace-font-lock-keywords)
-    ;; restore original font lock state
-    (font-lock-mode whitespace-font-lock-mode)))
+    (when font-lock-mode
+      (font-lock-fontify-buffer))))
 
 
 (defun whitespace-trailing-regexp (limit)