]> code.delx.au - gnu-emacs/blobdiff - lisp/whitespace.el
Fix changes in 2012-04-09T18:12:40Z!schwab@linux-m68k.org.
[gnu-emacs] / lisp / whitespace.el
index 0ef41b5a002ea75d30f3b25c93f3542ca0a953d5..e752dc56553c12add488afe5109cb6bcae6c70db 100644 (file)
@@ -1,12 +1,11 @@
 ;;; whitespace.el --- minor mode to visualize TAB, (HARD) SPACE, NEWLINE
 
-;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 2000-2012  Free Software Foundation, Inc.
 
 ;; Author: Vinicius Jose Latorre <viniciusjl@ig.com.br>
 ;; Maintainer: Vinicius Jose Latorre <viniciusjl@ig.com.br>
 ;; Keywords: data, wp
-;; Version: 13.1
+;; Version: 13.2.2
 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre
 
 ;; This file is part of GNU Emacs.
 ;; Acknowledgements
 ;; ----------------
 ;;
+;; Thanks to felix (EmacsWiki) for keeping highlight when switching between
+;; major modes on a file.
+;;
 ;; Thanks to David Reitter <david.reitter@gmail.com> for suggesting a
 ;; `whitespace-newline' initialization with low contrast relative to
 ;; the background color.
@@ -523,12 +525,14 @@ evaluated instead of indentation::space value.
 
 One reason for not visualize spaces via faces (if `face' is not
 included in `whitespace-style') is to use exclusively for
-cleanning up a buffer.  See `whitespace-cleanup' and
+cleaning up a buffer.  See `whitespace-cleanup' and
 `whitespace-cleanup-region' for documentation.
 
 See also `whitespace-display-mappings' for documentation."
   :type '(repeat :tag "Kind of Blank"
                 (choice :tag "Kind of Blank Face"
+                        (const :tag "(Face) Face visualization"
+                               face)
                         (const :tag "(Face) Trailing TABs, SPACEs and HARD SPACEs"
                                trailing)
                         (const :tag "(Face) SPACEs and HARD SPACEs"
@@ -619,8 +623,12 @@ and `newline'."
 (defface whitespace-newline
   '((((class color) (background dark))
      (:foreground "darkgray" :bold nil))
-    (((class color) (background light))
+    (((class color) (min-colors 88) (background light))
      (:foreground "lightgray" :bold nil))
+    ;; Displays with 16 colors use lightgray as background, so using a
+    ;; lightgray foreground makes the newline mark invisible.
+    (((class color) (background light))
+     (:foreground "brown" :bold nil))
     (t (:underline t :bold nil)))
   "Face used to visualize NEWLINE char mapping.
 
@@ -796,13 +804,12 @@ Used when `whitespace-style' includes `tabs'."
 
 
 (defcustom whitespace-trailing-regexp
-  "\\(\\(\t\\| \\|\xA0\\|\x8A0\\|\x920\\|\xE20\\|\xF20\\)+\\)$"
+  "\\([\t \u00A0]+\\)$"
   "Specify trailing characters regexp.
 
 If you're using `mule' package, there may be other characters besides:
 
-   \" \"  \"\\t\"  \"\\xA0\"  \"\\x8A0\"  \"\\x920\"  \"\\xE20\"  \
-\"\\xF20\"
+   \" \"  \"\\t\"  \"\\u00A0\"
 
 that should be considered blank.
 
@@ -1061,11 +1068,10 @@ Any other value is treated as nil."
 
 ;;;###autoload
 (define-minor-mode whitespace-mode
-  "Toggle whitespace minor mode visualization (\"ws\" on modeline).
-
-If ARG is null, toggle whitespace visualization.
-If ARG is a number greater than zero, turn on visualization;
-otherwise, turn off visualization.
+  "Toggle whitespace visualization (Whitespace mode).
+With a prefix argument ARG, enable Whitespace mode if ARG is
+positive, and disable it otherwise.  If called from Lisp, enable
+the mode if ARG is omitted or nil.
 
 See also `whitespace-style', `whitespace-newline' and
 `whitespace-display-mappings'."
@@ -1085,11 +1091,10 @@ See also `whitespace-style', `whitespace-newline' and
 
 ;;;###autoload
 (define-minor-mode whitespace-newline-mode
-  "Toggle NEWLINE minor mode visualization (\"nl\" on modeline).
-
-If ARG is null, toggle NEWLINE visualization.
-If ARG is a number greater than zero, turn on visualization;
-otherwise, turn off visualization.
+  "Toggle newline visualization (Whitespace Newline mode).
+With a prefix argument ARG, enable Whitespace Newline mode if ARG
+is positive, and disable it otherwise.  If called from Lisp,
+enable the mode if ARG is omitted or nil.
 
 Use `whitespace-newline-mode' only for NEWLINE visualization
 exclusively.  For other visualizations, including NEWLINE
@@ -1101,10 +1106,11 @@ See also `whitespace-newline' and `whitespace-display-mappings'."
   :init-value nil
   :global     nil
   :group      'whitespace
-  (let ((whitespace-style '(newline-mark newline)))
-    (whitespace-mode whitespace-newline-mode)
-    ;; sync states (running a batch job)
-    (setq whitespace-newline-mode whitespace-mode)))
+  (let ((whitespace-style '(face newline-mark newline)))
+    (whitespace-mode (if whitespace-newline-mode
+                        1 -1)))
+  ;; sync states (running a batch job)
+  (setq whitespace-newline-mode whitespace-mode))
 
 \f
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1113,11 +1119,10 @@ See also `whitespace-newline' and `whitespace-display-mappings'."
 
 ;;;###autoload
 (define-minor-mode global-whitespace-mode
-  "Toggle whitespace global minor mode visualization (\"WS\" on modeline).
-
-If ARG is null, toggle whitespace visualization.
-If ARG is a number greater than zero, turn on visualization;
-otherwise, turn off visualization.
+  "Toggle whitespace visualization globally (Global Whitespace mode).
+With a prefix argument ARG, enable Global Whitespace mode if ARG
+is positive, and disable it otherwise.  If called from Lisp,
+enable it if ARG is omitted or nil.
 
 See also `whitespace-style', `whitespace-newline' and
 `whitespace-display-mappings'."
@@ -1129,15 +1134,17 @@ See also `whitespace-style', `whitespace-newline' and
    (noninteractive                     ; running a batch job
     (setq global-whitespace-mode nil))
    (global-whitespace-mode             ; global-whitespace-mode on
-    (save-excursion
+    (save-current-buffer
       (add-hook 'find-file-hook 'whitespace-turn-on-if-enabled)
+      (add-hook 'after-change-major-mode-hook 'whitespace-turn-on-if-enabled)
       (dolist (buffer (buffer-list))   ; adjust all local mode
        (set-buffer buffer)
        (unless whitespace-mode
          (whitespace-turn-on-if-enabled)))))
    (t                                  ; global-whitespace-mode off
-    (save-excursion
+    (save-current-buffer
       (remove-hook 'find-file-hook 'whitespace-turn-on-if-enabled)
+      (remove-hook 'after-change-major-mode-hook 'whitespace-turn-on-if-enabled)
       (dolist (buffer (buffer-list))   ; adjust all local mode
        (set-buffer buffer)
        (unless whitespace-mode
@@ -1169,11 +1176,10 @@ See also `whitespace-style', `whitespace-newline' and
 
 ;;;###autoload
 (define-minor-mode global-whitespace-newline-mode
-  "Toggle NEWLINE global minor mode visualization (\"NL\" on modeline).
-
-If ARG is null, toggle NEWLINE visualization.
-If ARG is a number greater than zero, turn on visualization;
-otherwise, turn off visualization.
+  "Toggle global newline visualization (Global Whitespace Newline mode).
+With a prefix argument ARG, enable Global Whitespace Newline mode
+if ARG is positive, and disable it otherwise.  If called from
+Lisp, enable it if ARG is omitted or nil.
 
 Use `global-whitespace-newline-mode' only for NEWLINE
 visualization exclusively.  For other visualizations, including
@@ -1186,7 +1192,8 @@ See also `whitespace-newline' and `whitespace-display-mappings'."
   :global     t
   :group      'whitespace
   (let ((whitespace-style '(newline-mark newline)))
-    (global-whitespace-mode global-whitespace-newline-mode)
+    (global-whitespace-mode (if global-whitespace-newline-mode
+                                1 -1))
     ;; sync states (running a batch job)
     (setq global-whitespace-newline-mode global-whitespace-mode)))
 
@@ -1519,7 +1526,7 @@ documentation."
    ;; whole buffer
    (t
     (save-excursion
-      (save-match-data
+      (save-match-data                ;FIXME: Why?
        ;; PROBLEM 1: empty lines at bob
        ;; PROBLEM 2: empty lines at eob
        ;; ACTION: remove all empty lines at bob and/or eob
@@ -1591,7 +1598,7 @@ documentation."
          overwrite-mode                ; enforce no overwrite
          tmp)
       (save-excursion
-       (save-match-data
+       (save-match-data                ;FIXME: Why?
          ;; PROBLEM 1: 8 or more SPACEs at bol
          (cond
           ;; ACTION: replace 8 or more SPACEs at bol by TABs, if
@@ -1650,12 +1657,12 @@ documentation."
            (whitespace-replace-action
             (if whitespace-indent-tabs-mode 'tabify 'untabify)
             rstart rend whitespace-space-before-tab-regexp
-            (if whitespace-indent-tabs-mode 1 2)))
+            (if whitespace-indent-tabs-mode 0 2)))
           ;; ACTION: replace SPACEs before TAB by TABs.
           ((memq 'space-before-tab::tab whitespace-style)
            (whitespace-replace-action
             'tabify rstart rend
-            whitespace-space-before-tab-regexp 1))
+            whitespace-space-before-tab-regexp 0))
           ;; ACTION: replace TABs by SPACEs.
           ((memq 'space-before-tab::space whitespace-style)
            (whitespace-replace-action
@@ -1863,7 +1870,7 @@ cleaning up these problems."
   (interactive "r")
   (setq force (or current-prefix-arg force))
   (save-excursion
-    (save-match-data
+    (save-match-data                ;FIXME: Why?
       (let* ((has-bogus nil)
             (rstart    (min start end))
             (rend      (max start end))
@@ -2044,7 +2051,7 @@ can't split window to display whitespace toggle options"))
   "Scroll help window, if it exists.
 
 If UP is non-nil, scroll up; otherwise, scroll down."
-  (condition-case data-help
+  (condition-case nil
       (let ((buffer (get-buffer whitespace-help-buffer-name)))
        (if buffer
            (with-selected-window (get-buffer-window buffer)
@@ -2405,9 +2412,8 @@ resultant list will be returned."
   "Match trailing spaces which do not contain the point at end of line."
   (let ((status t))
     (while (if (re-search-forward whitespace-trailing-regexp limit t)
-              (save-match-data
-                (= whitespace-point (match-end 1))) ;; loop if point at eol
-            (setq status nil)))                     ;; end of buffer
+              (= whitespace-point (match-end 1)) ;; loop if point at eol
+            (setq status nil)))                  ;; end of buffer
     status))
 
 
@@ -2421,9 +2427,7 @@ beginning of buffer."
      ((= b 1)
       (setq r (and (/= whitespace-point 1)
                   (looking-at whitespace-empty-at-bob-regexp)))
-      (if r
-         (set-marker whitespace-bob-marker (match-end 1))
-       (set-marker whitespace-bob-marker b)))
+      (set-marker whitespace-bob-marker (if r (match-end 1) b)))
      ;; inside bob empty region
      ((<= limit whitespace-bob-marker)
       (setq r (looking-at whitespace-empty-at-bob-regexp))
@@ -2434,9 +2438,7 @@ beginning of buffer."
      ;; intersection with end of bob empty region
      ((<= b whitespace-bob-marker)
       (setq r (looking-at whitespace-empty-at-bob-regexp))
-      (if r
-         (set-marker whitespace-bob-marker (match-end 1))
-       (set-marker whitespace-bob-marker b)))
+      (set-marker whitespace-bob-marker (if r (match-end 1) b)))
      ;; it is not inside bob empty region
      (t
       (setq r nil)))
@@ -2492,7 +2494,7 @@ buffer."
     r))
 
 
-(defun whitespace-buffer-changed (beg end)
+(defun whitespace-buffer-changed (_beg _end)
   "Set `whitespace-buffer-changed' variable to t."
   (setq whitespace-buffer-changed t))
 
@@ -2575,7 +2577,7 @@ Also refontify when necessary."
        (setq whitespace-display-table-was-local t
              whitespace-display-table
              (copy-sequence buffer-display-table))
-       ;; asure `buffer-display-table' is unique
+       ;; Assure `buffer-display-table' is unique
        ;; when two or more windows are visible.
        (setq buffer-display-table
              (copy-sequence buffer-display-table)))
@@ -2666,5 +2668,4 @@ It should be added buffer-locally to `write-file-functions'."
 (run-hooks 'whitespace-load-hook)
 
 
-;; arch-tag: 1b1e2500-dbd4-4a26-8f7a-5a5edfd3c97e
 ;;; whitespace.el ends here