aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRajesh Vaidheeswarran2001-12-13 17:34:57 +0000
committerRajesh Vaidheeswarran2001-12-13 17:34:57 +0000
commit5dc2e846a72bedd00655befb685b905ce4c5b3dd (patch)
treea9d086f6ea9433d73a4441d6bc95fab6c1d10368
parent1d8e9a7c5da2f20a7b99a8b7d1d7b5e840baf688 (diff)
downloademacs-5dc2e846a72bedd00655befb685b905ce4c5b3dd.tar.gz
emacs-5dc2e846a72bedd00655befb685b905ce4c5b3dd.zip
Whitespace.el v3.2 for colorized display of bogus whitespaces.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/whitespace.el100
2 files changed, 95 insertions, 16 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 2e29f8405d1..803c0e8c873 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12001-12-13 Rajesh Vaidheeswarran <rv@gnu.org>
2
3 * whitespace.el (whitespace-version): 3.2
4 * whitespace.el (whitespace-force-mode-line-update): Replace with
5 `whitespace-mode-line-update', which is an alias to the correct
6 function in various emacsen.
7 * whitespace.el (whitespace-{un,}highlight-the-space): Add
8 colorized highlighting of the bogus whitespaces in a buffer/file,
9 using the `whitespace-highlight-face' if
10 `whitespace-display-spaces-in-color' is set.
11
12001-12-13 Eli Zaretskii <eliz@is.elta.co.il> 122001-12-13 Eli Zaretskii <eliz@is.elta.co.il>
2 13
3 * international/mule.el (set-auto-coding): Don't search for 14 * international/mule.el (set-auto-coding): Don't search for
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 6f99f07692f..e8c4dd4b9dd 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -5,7 +5,7 @@
5;; Author: Rajesh Vaidheeswarran <rv@gnu.org> 5;; Author: Rajesh Vaidheeswarran <rv@gnu.org>
6;; Keywords: convenience 6;; Keywords: convenience
7 7
8;; $Id: whitespace.el,v 1.17 2001/08/20 10:05:03 gerd Exp $ 8;; $Id: whitespace.el,v 1.18 2001/08/20 20:56:08 rv Exp $
9;; This file is part of GNU Emacs. 9;; This file is part of GNU Emacs.
10 10
11;; GNU Emacs is free software; you can redistribute it and/or modify 11;; GNU Emacs is free software; you can redistribute it and/or modify
@@ -39,7 +39,7 @@
39 39
40;;; Code: 40;;; Code:
41 41
42(defvar whitespace-version "3.1" "Version of the whitespace library.") 42(defvar whitespace-version "3.2" "Version of the whitespace library.")
43 43
44(defvar whitespace-all-buffer-files nil 44(defvar whitespace-all-buffer-files nil
45 "An associated list of buffers and files checked for whitespace cleanliness. 45 "An associated list of buffers and files checked for whitespace cleanliness.
@@ -86,6 +86,11 @@ visited by the buffers.")
86(make-variable-buffer-local 'whitespace-check-buffer-ateol) 86(make-variable-buffer-local 'whitespace-check-buffer-ateol)
87(put 'whitespace-check-buffer-ateol 'permanent-local nil) 87(put 'whitespace-check-buffer-ateol 'permanent-local nil)
88 88
89(defvar whitespace-highlighted-space nil
90 "The variable to store the extent to highlight")
91(make-variable-buffer-local 'whitespace-highlighted-space)
92(put 'whitespace-highlighted-space 'permanent-local nil)
93
89;; For flavors of Emacs which don't define `defgroup' and `defcustom'. 94;; For flavors of Emacs which don't define `defgroup' and `defcustom'.
90(eval-when-compile 95(eval-when-compile
91 (if (not (fboundp 'defgroup)) 96 (if (not (fboundp 'defgroup))
@@ -99,6 +104,21 @@ defgroup"
99don't define defcustom" 104don't define defcustom"
100 `(defvar ,sym ,val ,doc)))) 105 `(defvar ,sym ,val ,doc))))
101 106
107(if (fboundp 'make-overlay)
108 (progn
109 (defalias 'whitespace-make-overlay 'make-overlay)
110 (defalias 'whitespace-overlay-put 'overlay-put)
111 (defalias 'whitespace-delete-overlay 'delete-overlay)
112 (defalias 'whitespace-overlay-start 'overlay-start)
113 (defalias 'whitespace-overlay-end 'overlay-end)
114 (defalias 'whitespace-mode-line-update 'force-mode-line-update))
115 (defalias 'whitespace-make-overlay 'make-extent)
116 (defalias 'whitespace-overlay-put 'set-extent-property)
117 (defalias 'whitespace-delete-overlay 'delete-extent)
118 (defalias 'whitespace-overlay-start 'extent-start)
119 (defalias 'whitespace-overlay-end 'extent-end)
120 (defalias 'whitespace-mode-line-update 'redraw-modeline))
121
102(if (featurep 'xemacs) 122(if (featurep 'xemacs)
103(defgroup whitespace nil 123(defgroup whitespace nil
104 "Check for and fix five different types of whitespaces in source code." 124 "Check for and fix five different types of whitespaces in source code."
@@ -131,7 +151,7 @@ It can be overriden by setting a buffer local variable
131 :type 'boolean 151 :type 'boolean
132 :group 'whitespace) 152 :group 'whitespace)
133 153
134(defcustom whitespace-spacetab-regexp " \t" 154(defcustom whitespace-spacetab-regexp "[ ]+\t"
135 "Regexp to match a space followed by a TAB." 155 "Regexp to match a space followed by a TAB."
136 :type 'regexp 156 :type 'regexp
137 :group 'whitespace) 157 :group 'whitespace)
@@ -155,7 +175,8 @@ It can be overriden by setting a buffer local variable
155 :type 'boolean 175 :type 'boolean
156 :group 'whitespace) 176 :group 'whitespace)
157 177
158(defcustom whitespace-ateol-regexp "[ \t]$" 178;; (defcustom whitespace-ateol-regexp "[ \t]$"
179(defcustom whitespace-ateol-regexp "[ \t]+$"
159 "Regexp to match a TAB or a space at the EOL." 180 "Regexp to match a TAB or a space at the EOL."
160 :type 'regexp 181 :type 'regexp
161 :group 'whitespace) 182 :group 'whitespace)
@@ -230,6 +251,31 @@ To disable timer scans, set this to zero."
230 :type 'boolean 251 :type 'boolean
231 :group 'whitespace) 252 :group 'whitespace)
232 253
254(defcustom whitespace-display-spaces-in-color t
255 "Display the bogus whitespaces by coloring them with
256`whitespace-highlight-face'."
257 :type 'boolean
258 :group 'whitespace)
259
260(defgroup whitespace-faces nil
261 "Faces used in whitespace."
262 :prefix "whitespace-"
263 :group 'whitespace
264 :group 'faces)
265
266(defface whitespace-highlight-face '((((class color) (background light))
267 (:background "green"))
268 (((class color) (background dark))
269 (:background "sea green"))
270 (((class grayscale monochrome)
271 (background light))
272 (:background "black"))
273 (((class grayscale monochrome)
274 (background dark))
275 (:background "white")))
276 "Face used for highlighting the bogus whitespaces that exist in the buffer."
277 :group 'whitespace-faces)
278
233(if (not (assoc 'whitespace-mode minor-mode-alist)) 279(if (not (assoc 'whitespace-mode minor-mode-alist))
234 (setq minor-mode-alist (cons '(whitespace-mode whitespace-mode-line) 280 (setq minor-mode-alist (cons '(whitespace-mode whitespace-mode-line)
235 minor-mode-alist))) 281 minor-mode-alist)))
@@ -329,6 +375,7 @@ and:
329 (progn 375 (progn
330 (whitespace-check-buffer-list (buffer-name) buffer-file-name) 376 (whitespace-check-buffer-list (buffer-name) buffer-file-name)
331 (whitespace-tickle-timer) 377 (whitespace-tickle-timer)
378 (whitespace-unhighlight-the-space)
332 (if whitespace-auto-cleanup 379 (if whitespace-auto-cleanup
333 (if buffer-read-only 380 (if buffer-read-only
334 (if (not quiet) 381 (if (not quiet)
@@ -498,7 +545,9 @@ whitespace problems."
498 (end-of-line) 545 (end-of-line)
499 (setq pmax (point)) 546 (setq pmax (point))
500 (if (equal pmin pmax) 547 (if (equal pmin pmax)
501 t 548 (progn
549 (whitespace-highlight-the-space pmin pmax)
550 t)
502 nil)))) 551 nil))))
503 552
504(defun whitespace-buffer-leading-cleanup () 553(defun whitespace-buffer-leading-cleanup ()
@@ -534,7 +583,9 @@ whitespace problems."
534 (end-of-line) 583 (end-of-line)
535 (setq pmax (point)) 584 (setq pmax (point))
536 (if (equal pmin pmax) 585 (if (equal pmin pmax)
537 t 586 (progn
587 (whitespace-highlight-the-space pmin pmax)
588 t)
538 nil)) 589 nil))
539 nil)))) 590 nil))))
540 591
@@ -568,8 +619,10 @@ whitespace problems."
568 (save-excursion 619 (save-excursion
569 (goto-char (point-min)) 620 (goto-char (point-min))
570 (while (re-search-forward regexp nil t) 621 (while (re-search-forward regexp nil t)
571 (setq whitespace-retval (format "%s %s" whitespace-retval 622 (progn
572 (match-beginning 0)))) 623 (setq whitespace-retval (format "%s %s" whitespace-retval
624 (match-beginning 0)))
625 (whitespace-highlight-the-space (match-beginning 0) (match-end 0))))
573 (if (equal "" whitespace-retval) 626 (if (equal "" whitespace-retval)
574 nil 627 nil
575 whitespace-retval)))) 628 whitespace-retval))))
@@ -621,14 +674,30 @@ Also with whitespaces whose testing has been turned off."
621 (setq whitespace-mode-line (if whitespace-mode-line 674 (setq whitespace-mode-line (if whitespace-mode-line
622 (concat " W:" whitespace-mode-line) 675 (concat " W:" whitespace-mode-line)
623 nil)) 676 nil))
624 (whitespace-force-mode-line-update)))) 677 (whitespace-mode-line-update))))
625 678
626;; Force mode line updation for different Emacs versions 679(defun whitespace-highlight-the-space (b e)
627(defun whitespace-force-mode-line-update () 680 "Highlight the current line, unhighlighting a previously jumped to line."
628 "Force the mode line update for different flavors of Emacs." 681 (if whitespace-display-spaces-in-color
629 (if (fboundp 'redraw-modeline) 682 (progn
630 (redraw-modeline) ; XEmacs 683 (whitespace-unhighlight-the-space)
631 (force-mode-line-update))) ; Emacs 684 (add-to-list 'whitespace-highlighted-space
685 (whitespace-make-overlay b e))
686 (whitespace-overlay-put (whitespace-make-overlay b e) 'face
687 'whitespace-highlight-face))))
688;; (add-hook 'pre-command-hook 'whitespace-unhighlight-the-space))
689
690(defun whitespace-unhighlight-the-space ()
691 "Unhighlight the currently highlight line."
692 (if (and whitespace-display-spaces-in-color whitespace-highlighted-space)
693 (let ((whitespace-this-space nil))
694 (while whitespace-highlighted-space
695 (setq whitespace-this-space (car whitespace-highlighted-space))
696 (setq whitespace-highlighted-space
697 (cdr whitespace-highlighted-space))
698 (whitespace-delete-overlay whitespace-this-space))
699 (setq whitespace-highlighted-space nil))
700 (remove-hook 'pre-command-hook 'whitespace-unhighlight-the-space)))
632 701
633(defun whitespace-check-buffer-list (buf-name buf-file) 702(defun whitespace-check-buffer-list (buf-name buf-file)
634 "Add a buffer and its file to the whitespace monitor list. 703 "Add a buffer and its file to the whitespace monitor list.
@@ -803,5 +872,4 @@ whitespaces during the process of your editing)."
803 (remove-hook 'kill-buffer-hook 'whitespace-buffer)) 872 (remove-hook 'kill-buffer-hook 'whitespace-buffer))
804 873
805(provide 'whitespace) 874(provide 'whitespace)
806
807;;; whitespace.el ends here 875;;; whitespace.el ends here