aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1999-09-14 22:30:11 +0000
committerRichard M. Stallman1999-09-14 22:30:11 +0000
commit18d51459aa08c4eb80d90519c1f127965e413028 (patch)
tree5a1310133a3159fe36f275508ad9103fbe68c590
parent2e0a943f5bdf7c344eb239836f65f3fdc40aa6f9 (diff)
downloademacs-18d51459aa08c4eb80d90519c1f127965e413028.tar.gz
emacs-18d51459aa08c4eb80d90519c1f127965e413028.zip
(whitespace-version): Update version to 2.4
Add customization variables to conditionally test any of the five whitespaces. (whitespace-spacetab-regexp): Fix doc string. (whitespace-modes): Add `change-log-mode' to the list of modes to be checked for bogus whitespaces. (whitespace-rescan-timer-time): Update documentation. (whitespace-display-unchecked-whitespaces): new function to update modeline with untested whitespaces. (whitespace-buffer): Test only whitespaces whose checking is turned on, and update modeline using the newly created `whitespace-display-unchecked-whitespaces'. (whitespace-cleanup): Cleanup only whitespaces whose checking is turned on, and update modeline using the newly created `whitespace-display-unchecked-whitespaces'. (whitespace-describe): Update documentation. (whitespace-tickle-timer): Test if `whitespace-rescan-timer-time' is non-zero before tickling timer.
-rw-r--r--lisp/whitespace.el111
1 files changed, 89 insertions, 22 deletions
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 4d417983e4d..459383a17bf 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -77,16 +77,41 @@ visited by the buffers.")
77 ;; which is 'editing? 77 ;; which is 'editing?
78 :group (if whitespace-running-emacs 'convenience 'editing)) 78 :group (if whitespace-running-emacs 'convenience 'editing))
79 79
80(defcustom whitespace-check-leading-whitespace t
81 "Flag to check leading whitespace."
82 :type 'boolean
83 :group 'whitespace)
84
85(defcustom whitespace-check-trailing-whitespace t
86 "Flag to check trailing whitespace."
87 :type 'boolean
88 :group 'whitespace)
89
90(defcustom whitespace-check-spacetab-whitespace t
91 "Flag to check space followed by a TAB."
92 :type 'boolean
93 :group 'whitespace)
94
80(defcustom whitespace-spacetab-regexp " \t" 95(defcustom whitespace-spacetab-regexp " \t"
81 "Regexp to match a TAB followed by a space." 96 "Regexp to match a space followed by a TAB."
82 :type 'string 97 :type 'string
83 :group 'whitespace) 98 :group 'whitespace)
84 99
100(defcustom whitespace-check-indent-whitespace t
101 "Flag to check indentation whitespace."
102 :type 'boolean
103 :group 'whitespace)
104
85(defcustom whitespace-indent-regexp (concat "^\\(\t*\\) " " ") 105(defcustom whitespace-indent-regexp (concat "^\\(\t*\\) " " ")
86 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line." 106 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line."
87 :type 'string 107 :type 'string
88 :group 'whitespace) 108 :group 'whitespace)
89 109
110(defcustom whitespace-check-ateol-whitespace t
111 "Flag to check end-of-line whitespace."
112 :type 'boolean
113 :group 'whitespace)
114
90(defcustom whitespace-ateol-regexp "[ \t]$" 115(defcustom whitespace-ateol-regexp "[ \t]$"
91 "Regexp to match a TAB or a space at the EOL." 116 "Regexp to match a TAB or a space at the EOL."
92 :type 'string 117 :type 'string
@@ -112,7 +137,8 @@ Errors*' buffer before opening (or closing) another file."
112 :group 'whitespace) 137 :group 'whitespace)
113 138
114(defcustom whitespace-modes '(ada-mode asm-mode autoconf-mode awk-mode 139(defcustom whitespace-modes '(ada-mode asm-mode autoconf-mode awk-mode
115 c-mode c++-mode cc-mode cperl-mode 140 c-mode c++-mode cc-mode
141 change-log-mode cperl-mode
116 electric-nroff-mode emacs-lisp-mode 142 electric-nroff-mode emacs-lisp-mode
117 f90-mode fortran-mode html-mode 143 f90-mode fortran-mode html-mode
118 html3-mode java-mode jde-mode 144 html3-mode java-mode jde-mode
@@ -121,9 +147,9 @@ Errors*' buffer before opening (or closing) another file."
121 modula-2-mode nroff-mode objc-mode 147 modula-2-mode nroff-mode objc-mode
122 pascal-mode perl-mode prolog-mode 148 pascal-mode perl-mode prolog-mode
123 python-mode scheme-mode sgml-mode 149 python-mode scheme-mode sgml-mode
124 sh-mode shell-script-mode 150 sh-mode shell-script-mode simula-mode
125 simula-mode tcl-mode tex-mode 151 tcl-mode tex-mode texinfo-mode
126 texinfo-mode vrml-mode xml-mode) 152 vrml-mode xml-mode)
127 153
128 "Major Modes in which we turn on whitespace checking. 154 "Major Modes in which we turn on whitespace checking.
129 155
@@ -142,7 +168,9 @@ Or, alternately, you can use the Emacs `customize' command to set this."
142 168
143This is the period after which the timer will fire causing 169This is the period after which the timer will fire causing
144`whitespace-rescan-files-in-buffers' to check for whitespace creep in 170`whitespace-rescan-files-in-buffers' to check for whitespace creep in
145modified buffers." 171modified buffers.
172
173To disable timer scans, set this to zero."
146 :type 'integer 174 :type 'integer
147 :group 'whitespace) 175 :group 'whitespace)
148 176
@@ -191,14 +219,24 @@ and:
191 (if (and (not quiet) buffer-read-only) 219 (if (and (not quiet) buffer-read-only)
192 (message "Can't Cleanup: %s is read-only." (buffer-name)) 220 (message "Can't Cleanup: %s is read-only." (buffer-name))
193 (whitespace-cleanup)) 221 (whitespace-cleanup))
194 (let ((whitespace-leading (whitespace-buffer-leading)) 222 (let ((whitespace-leading (if whitespace-check-leading-whitespace
195 (whitespace-trailing (whitespace-buffer-trailing)) 223 (whitespace-buffer-leading)
196 (whitespace-indent (whitespace-buffer-search 224 nil))
197 whitespace-indent-regexp)) 225 (whitespace-trailing (if whitespace-check-trailing-whitespace
198 (whitespace-spacetab (whitespace-buffer-search 226 (whitespace-buffer-trailing)
199 whitespace-spacetab-regexp)) 227 nil))
200 (whitespace-ateol (whitespace-buffer-search 228 (whitespace-indent (if whitespace-check-indent-whitespace
201 whitespace-ateol-regexp)) 229 (whitespace-buffer-search
230 whitespace-indent-regexp)
231 nil))
232 (whitespace-spacetab (if whitespace-check-spacetab-whitespace
233 (whitespace-buffer-search
234 whitespace-spacetab-regexp)
235 nil))
236 (whitespace-ateol (if whitespace-check-ateol-whitespace
237 (whitespace-buffer-search
238 whitespace-ateol-regexp)
239 nil))
202 (whitespace-errmsg nil) 240 (whitespace-errmsg nil)
203 (whitespace-error nil) 241 (whitespace-error nil)
204 (whitespace-filename buffer-file-name) 242 (whitespace-filename buffer-file-name)
@@ -236,6 +274,11 @@ and:
236 (setq whitespace-mode-line 274 (setq whitespace-mode-line
237 (concat " W:" whitespace-this-modeline)) 275 (concat " W:" whitespace-this-modeline))
238 (whitespace-force-mode-line-update))) 276 (whitespace-force-mode-line-update)))
277
278 ;; Now test and set the whitespaces that are not checked.
279 (whitespace-display-unchecked-whitespaces
280 (if whitespace-error
281 (concat " W:" whitespace-this-modeline)))
239 (save-excursion 282 (save-excursion
240 (get-buffer-create whitespace-errbuf) 283 (get-buffer-create whitespace-errbuf)
241 (kill-buffer whitespace-errbuf) 284 (kill-buffer whitespace-errbuf)
@@ -280,37 +323,44 @@ whitespace problems."
280 ;; they are displayed. 323 ;; they are displayed.
281 (setq tab-width whitespace-tabwith) 324 (setq tab-width whitespace-tabwith)
282 325
283 (if (whitespace-buffer-leading) 326 (if (and whitespace-check-leading-whitespace
327 (whitespace-buffer-leading))
284 (progn 328 (progn
285 (whitespace-buffer-leading-cleanup) 329 (whitespace-buffer-leading-cleanup)
286 (setq whitespace-any t))) 330 (setq whitespace-any t)))
287 331
288 (if (whitespace-buffer-trailing) 332 (if (and whitespace-check-trailing-whitespace
333 (whitespace-buffer-trailing))
289 (progn 334 (progn
290 (whitespace-buffer-trailing-cleanup) 335 (whitespace-buffer-trailing-cleanup)
291 (setq whitespace-any t))) 336 (setq whitespace-any t)))
292 337
293 (if (whitespace-buffer-search whitespace-indent-regexp) 338 (if (and whitespace-check-indent-whitespace
339 (whitespace-buffer-search whitespace-indent-regexp))
294 (progn 340 (progn
295 (whitespace-indent-cleanup) 341 (whitespace-indent-cleanup)
296 (setq whitespace-any t))) 342 (setq whitespace-any t)))
297 343
298 (if (whitespace-buffer-search whitespace-spacetab-regexp) 344 (if (and whitespace-check-spacetab-whitespace
345 (whitespace-buffer-search whitespace-spacetab-regexp))
299 (progn 346 (progn
300 (whitespace-buffer-cleanup whitespace-spacetab-regexp "\t") 347 (whitespace-buffer-cleanup whitespace-spacetab-regexp "\t")
301 (setq whitespace-any t))) 348 (setq whitespace-any t)))
302 349
303 (if (whitespace-buffer-search whitespace-ateol-regexp) 350 (if (and whitespace-check-ateol-whitespace
351 (whitespace-buffer-search whitespace-ateol-regexp))
304 (progn 352 (progn
305 (whitespace-buffer-cleanup whitespace-ateol-regexp "") 353 (whitespace-buffer-cleanup whitespace-ateol-regexp "")
306 (setq whitespace-any t))) 354 (setq whitespace-any t)))
307 355
308 ;; Call this recursively till everything is taken care of 356 ;; Call this recursively till everything is taken care of
309 (if whitespace-any (whitespace-cleanup) 357 (if whitespace-any
358 (whitespace-cleanup)
310 (progn 359 (progn
311 (message "%s clean" buffer-file-name) 360 (message "%s clean" buffer-file-name)
312 (setq whitespace-mode-line nil) 361 (setq whitespace-mode-line nil)
313 (whitespace-force-mode-line-update))) 362 (whitespace-force-mode-line-update)
363 (whitespace-display-unchecked-whitespaces)))
314 (setq tab-width whitespace-tabwith-saved)))) 364 (setq tab-width whitespace-tabwith-saved))))
315 365
316;;;###autoload 366;;;###autoload
@@ -427,6 +477,20 @@ whitespace problems."
427 (delete-region (match-beginning 0) (point)) 477 (delete-region (match-beginning 0) (point))
428 (indent-to column))))) 478 (indent-to column)))))
429 479
480(defun whitespace-display-unchecked-whitespaces (&optional whitespace-str)
481 "Update modeline with whitespaces whose testing has been turned off."
482 (let ((whitespace-this-modeline
483 (concat (if (not whitespace-check-ateol-whitespace) "e")
484 (if (not whitespace-check-indent-whitespace) "i")
485 (if (not whitespace-check-leading-whitespace) "l")
486 (if (not whitespace-check-spacetab-whitespace) "s")
487 (if (not whitespace-check-trailing-whitespace) "t"))))
488 (setq whitespace-mode-line whitespace-str)
489 (if (not (equal whitespace-this-modeline ""))
490 (setq whitespace-mode-line
491 (concat whitespace-str " Woff:" whitespace-this-modeline)))
492 (whitespace-force-mode-line-update)))
493
430;; Force mode line updation for different Emacs versions 494;; Force mode line updation for different Emacs versions
431(defun whitespace-force-mode-line-update () 495(defun whitespace-force-mode-line-update ()
432 "Force the mode line update for different flavors of Emacs." 496 "Force the mode line update for different flavors of Emacs."
@@ -449,7 +513,7 @@ periodically for whitespace."
449If timer is not set, then set it to scan the files in 513If timer is not set, then set it to scan the files in
450`whitespace-all-buffer-files' periodically (defined by 514`whitespace-all-buffer-files' periodically (defined by
451`whitespace-rescan-timer-time') for whitespace creep." 515`whitespace-rescan-timer-time') for whitespace creep."
452 (if (not whitespace-rescan-timer) 516 (if (and whitespace-rescan-timer-time (not whitespace-rescan-timer))
453 (setq whitespace-rescan-timer 517 (setq whitespace-rescan-timer
454 (if whitespace-running-emacs 518 (if whitespace-running-emacs
455 (run-at-time nil whitespace-rescan-timer-time 519 (run-at-time nil whitespace-rescan-timer-time
@@ -532,6 +596,9 @@ l - Leading whitespace.
532s - Space followed by Tab. 596s - Space followed by Tab.
533t - Trailing whitespace. 597t - Trailing whitespace.
534 598
599If any of the whitespace checks is turned off, the modeline will display a
600Woff:<x>, where `x' can be one (or more) of the above.
601
535 (since (3) is the most controversial one, here is the rationale: Most 602 (since (3) is the most controversial one, here is the rationale: Most
536 terminal drivers and printer drivers have TAB configured or even 603 terminal drivers and printer drivers have TAB configured or even
537 hardcoded to be 8 spaces. (Some of them allow configuration, but almost 604 hardcoded to be 8 spaces. (Some of them allow configuration, but almost