;;; 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
(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
(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))
(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))
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)
(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)
"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)
"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)
(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)
(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)
"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)
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)
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)
(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) ?\ ))
;; 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)
;; 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)
;;;; 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
(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)
(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)
(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))
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.
((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)