X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/84eb0351d8be4811897c8cf62a69757ff5d14001..fb6ea014512973f2e8d291b2f6672fbb56c3fe61:/lisp/whitespace.el diff --git a/lisp/whitespace.el b/lisp/whitespace.el index 8d25a161b4..e2a726f426 100644 --- a/lisp/whitespace.el +++ b/lisp/whitespace.el @@ -1,11 +1,11 @@ ;;; whitespace.el --- minor mode to visualize TAB, (HARD) SPACE, NEWLINE -;; Copyright (C) 2000-2011 Free Software Foundation, Inc. +;; Copyright (C) 2000-2013 Free Software Foundation, Inc. ;; Author: Vinicius Jose Latorre ;; Maintainer: Vinicius Jose Latorre ;; Keywords: data, wp -;; Version: 13.2 +;; Version: 13.2.2 ;; X-URL: http://www.emacswiki.org/cgi-bin/wiki/ViniciusJoseLatorre ;; This file is part of GNU Emacs. @@ -165,10 +165,10 @@ ;; There are also the following useful commands: ;; ;; `whitespace-newline-mode' -;; Toggle NEWLINE minor mode visualization ("nl" on modeline). +;; Toggle NEWLINE minor mode visualization ("nl" on mode line). ;; ;; `global-whitespace-newline-mode' -;; Toggle NEWLINE global minor mode visualization ("NL" on modeline). +;; Toggle NEWLINE global minor mode visualization ("NL" on mode line). ;; ;; `whitespace-report' ;; Report some blank problems in buffer. @@ -309,8 +309,11 @@ ;; buffer is visited or written. ;; ;; -;; Acknowledgements -;; ---------------- +;; Acknowledgments +;; --------------- +;; +;; Thanks to felix (EmacsWiki) for keeping highlight when switching between +;; major modes on a file. ;; ;; Thanks to David Reitter for suggesting a ;; `whitespace-newline' initialization with low contrast relative to @@ -522,7 +525,7 @@ 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." @@ -562,10 +565,10 @@ Used when `whitespace-style' includes the value `spaces'." (defface whitespace-space '((((class color) (background dark)) - (:background "grey20" :foreground "darkgray")) + :background "grey20" :foreground "darkgray") (((class color) (background light)) - (:background "LightYellow" :foreground "lightgray")) - (t (:inverse-video t))) + :background "LightYellow" :foreground "lightgray") + (t :inverse-video t)) "Face used to visualize SPACE." :group 'whitespace) @@ -580,10 +583,10 @@ Used when `whitespace-style' includes the value `spaces'." (defface whitespace-hspace ; 'nobreak-space '((((class color) (background dark)) - (:background "grey24" :foreground "darkgray")) + :background "grey24" :foreground "darkgray") (((class color) (background light)) - (:background "LemonChiffon3" :foreground "lightgray")) - (t (:inverse-video t))) + :background "LemonChiffon3" :foreground "lightgray") + (t :inverse-video t)) "Face used to visualize HARD SPACE." :group 'whitespace) @@ -598,10 +601,10 @@ Used when `whitespace-style' includes the value `tabs'." (defface whitespace-tab '((((class color) (background dark)) - (:background "grey22" :foreground "darkgray")) + :background "grey22" :foreground "darkgray") (((class color) (background light)) - (:background "beige" :foreground "lightgray")) - (t (:inverse-video t))) + :background "beige" :foreground "lightgray") + (t :inverse-video t)) "Face used to visualize TAB." :group 'whitespace) @@ -618,11 +621,13 @@ and `newline'." (defface whitespace-newline - '((((class color) (background dark)) - (:foreground "darkgray" :bold nil)) - (((class color) (background light)) - (:foreground "lightgray" :bold nil)) - (t (:underline t :bold nil))) + '((default :weight normal) + (((class color) (background dark)) :foreground "darkgray") + (((class color) (min-colors 88) (background light)) :foreground "lightgray") + ;; Displays with 16 colors use lightgray as background, so using a + ;; lightgray foreground makes the newline mark invisible. + (((class color) (background light)) :foreground "brown") + (t :underline t)) "Face used to visualize NEWLINE char mapping. See `whitespace-display-mappings'." @@ -638,8 +643,9 @@ Used when `whitespace-style' includes the value `trailing'." (defface whitespace-trailing ; 'trailing-whitespace - '((((class mono)) (:inverse-video t :bold t :underline t)) - (t (:background "red1" :foreground "yellow" :bold t))) + '((default :weight bold) + (((class mono)) :inverse-video t :underline t) + (t :background "red1" :foreground "yellow")) "Face used to visualize trailing blanks." :group 'whitespace) @@ -655,8 +661,8 @@ Used when `whitespace-style' includes the value `line'." (defface whitespace-line - '((((class mono)) (:inverse-video t :bold t :underline t)) - (t (:background "gray20" :foreground "violet"))) + '((((class mono)) :inverse-video t :weight bold :underline t) + (t :background "gray20" :foreground "violet")) "Face used to visualize \"long\" lines. See `whitespace-line-column'." @@ -672,8 +678,8 @@ Used when `whitespace-style' includes the value `space-before-tab'." (defface whitespace-space-before-tab - '((((class mono)) (:inverse-video t :bold t :underline t)) - (t (:background "DarkOrange" :foreground "firebrick"))) + '((((class mono)) :inverse-video t :weight bold :underline t) + (t :background "DarkOrange" :foreground "firebrick")) "Face used to visualize SPACEs before TAB." :group 'whitespace) @@ -687,8 +693,8 @@ Used when `whitespace-style' includes the value `indentation'." (defface whitespace-indentation - '((((class mono)) (:inverse-video t :bold t :underline t)) - (t (:background "yellow" :foreground "firebrick"))) + '((((class mono)) :inverse-video t :weight bold :underline t) + (t :background "yellow" :foreground "firebrick")) "Face used to visualize 8 or more SPACEs at beginning of line." :group 'whitespace) @@ -702,8 +708,8 @@ Used when `whitespace-style' includes the value `empty'." (defface whitespace-empty - '((((class mono)) (:inverse-video t :bold t :underline t)) - (t (:background "yellow" :foreground "firebrick"))) + '((((class mono)) :inverse-video t :weight bold :underline t) + (t :background "yellow" :foreground "firebrick")) "Face used to visualize empty lines at beginning and/or end of buffer." :group 'whitespace) @@ -717,8 +723,8 @@ Used when `whitespace-style' includes the value `space-after-tab'." (defface whitespace-space-after-tab - '((((class mono)) (:inverse-video t :bold t :underline t)) - (t (:background "yellow" :foreground "firebrick"))) + '((((class mono)) :inverse-video t :weight bold :underline t) + (t :background "yellow" :foreground "firebrick")) "Face used to visualize 8 or more SPACEs after TAB." :group 'whitespace) @@ -797,13 +803,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. @@ -922,17 +927,13 @@ Used when `whitespace-style' includes `lines' or `lines-tail'." '( (space-mark ?\ [?\u00B7] [?.]) ; space - centered dot (space-mark ?\xA0 [?\u00A4] [?_]) ; hard space - currency - (space-mark ?\x8A0 [?\x8A4] [?_]) ; hard space - currency - (space-mark ?\x920 [?\x924] [?_]) ; hard space - currency - (space-mark ?\xE20 [?\xE24] [?_]) ; hard space - currency - (space-mark ?\xF20 [?\xF24] [?_]) ; hard space - currency ;; NEWLINE is displayed using the face `whitespace-newline' (newline-mark ?\n [?$ ?\n]) ; eol - dollar sign ;; (newline-mark ?\n [?\u21B5 ?\n] [?$ ?\n]) ; eol - downwards arrow ;; (newline-mark ?\n [?\u00B6 ?\n] [?$ ?\n]) ; eol - pilcrow - ;; (newline-mark ?\n [?\x8AF ?\n] [?$ ?\n]) ; eol - overscore - ;; (newline-mark ?\n [?\x8AC ?\n] [?$ ?\n]) ; eol - negation - ;; (newline-mark ?\n [?\x8B0 ?\n] [?$ ?\n]) ; eol - grade + ;; (newline-mark ?\n [?\u00AF ?\n] [?$ ?\n]) ; eol - overscore + ;; (newline-mark ?\n [?\u00AC ?\n] [?$ ?\n]) ; eol - negation + ;; (newline-mark ?\n [?\u00B0 ?\n] [?$ ?\n]) ; eol - degrees ;; ;; WARNING: the mapping below has a problem. ;; When a TAB occupies exactly one column, it will display the @@ -1062,11 +1063,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'." @@ -1086,11 +1086,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 @@ -1103,9 +1102,10 @@ See also `whitespace-newline' and `whitespace-display-mappings'." :global nil :group 'whitespace (let ((whitespace-style '(face newline-mark newline))) - (whitespace-mode whitespace-newline-mode) - ;; sync states (running a batch job) - (setq whitespace-newline-mode whitespace-mode))) + (whitespace-mode (if whitespace-newline-mode + 1 -1))) + ;; sync states (running a batch job) + (setq whitespace-newline-mode whitespace-mode)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1114,11 +1114,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'." @@ -1130,15 +1129,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 @@ -1170,11 +1171,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 @@ -1521,15 +1521,14 @@ 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 (when (memq 'empty whitespace-style) (let (overwrite-mode) ; enforce no overwrite (goto-char (point-min)) - (when (re-search-forward - (concat "\\`" whitespace-empty-at-bob-regexp) nil t) + (when (looking-at whitespace-empty-at-bob-regexp) (delete-region (match-beginning 1) (match-end 1))) (when (re-search-forward (concat whitespace-empty-at-eob-regexp "\\'") nil t) @@ -1593,7 +1592,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 @@ -1865,7 +1864,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)) @@ -2046,7 +2045,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) @@ -2407,9 +2406,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)) @@ -2423,9 +2421,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)) @@ -2436,9 +2432,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))) @@ -2494,7 +2488,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)) @@ -2577,7 +2571,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)))