aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Love2000-10-15 17:07:55 +0000
committerDave Love2000-10-15 17:07:55 +0000
commitfc3337909b8ccf65de25a8992913a4c80edabde0 (patch)
tree542a50651dd0cd0ab9fdad23e7ce8283bd1bce89
parentd1268e529b9e762a61e895d99788257b25afd7f3 (diff)
downloademacs-fc3337909b8ccf65de25a8992913a4c80edabde0.tar.gz
emacs-fc3337909b8ccf65de25a8992913a4c80edabde0.zip
Doc fixes.
(top-level): Don't add hooks here. (whitespace-running-emacs): Deleted. (timer): Don't require. (whitespace): Add back :version conditional on xemacs test. (whitespace-spacetab-regexp, whitespace-indent-regexp) (whitespace-ateol-regexp, whitespace-modes): Fix custom type. (whitespace-force-mode-line-update, whitespace-refresh-rescan-list) (whitespace-tickle-timer, whitespace-rescan-files-in-buffers): Avoid specific xemacs test. (whitespace-global-mode): New option. (whitespace-global-mode): New command. (whitespace-unload-hook): New function.
-rw-r--r--lisp/whitespace.el124
1 files changed, 72 insertions, 52 deletions
diff --git a/lisp/whitespace.el b/lisp/whitespace.el
index 5944f270c8e..ca2813985e1 100644
--- a/lisp/whitespace.el
+++ b/lisp/whitespace.el
@@ -38,17 +38,7 @@
38 38
39;;; Code: 39;;; Code:
40 40
41;; add a hook to find-file-hooks and kill-buffer-hook
42(add-hook 'find-file-hooks 'whitespace-buffer)
43(add-hook 'kill-buffer-hook 'whitespace-buffer)
44
45(defvar whitespace-version "2.8" "Version of the whitespace library.") 41(defvar whitespace-version "2.8" "Version of the whitespace library.")
46;; Find out what type of Emacs we are running in.
47(defvar whitespace-running-emacs (if (string-match "XEmacs\\|Lucid"
48 emacs-version) nil t)
49 "If this is Emacs, not XEmacs, this is t.")
50
51(if whitespace-running-emacs (require 'timer))
52 42
53(defvar whitespace-all-buffer-files nil 43(defvar whitespace-all-buffer-files nil
54 "An associated list of buffers and files checked for whitespace cleanliness. 44 "An associated list of buffers and files checked for whitespace cleanliness.
@@ -83,12 +73,16 @@ defgroup"
83don't define defcustom" 73don't define defcustom"
84 `(defvar ,sym ,val ,doc)))) 74 `(defvar ,sym ,val ,doc))))
85 75
76(if (featurep 'xemacs)
86(defgroup whitespace nil 77(defgroup whitespace nil
87 "Check for and fix five different types of whitespaces in source code." 78 "Check for and fix five different types of whitespaces in source code."
88 ;; Since XEmacs doesn't have a 'convenience group, use the next best group 79 ;; Since XEmacs doesn't have a 'convenience group, use the next best group
89 ;; which is 'editing? 80 ;; which is 'editing?
90 ;; :version "21.1" 81 :group 'editing)
91 :group (if whitespace-running-emacs 'convenience 'editing)) 82(defgroup whitespace nil
83 "Check for and fix five different types of whitespaces in source code."
84 :version "21.1"
85 :group 'convenience))
92 86
93(defcustom whitespace-check-leading-whitespace t 87(defcustom whitespace-check-leading-whitespace t
94 "Flag to check leading whitespace." 88 "Flag to check leading whitespace."
@@ -107,7 +101,7 @@ don't define defcustom"
107 101
108(defcustom whitespace-spacetab-regexp " \t" 102(defcustom whitespace-spacetab-regexp " \t"
109 "Regexp to match a space followed by a TAB." 103 "Regexp to match a space followed by a TAB."
110 :type 'string 104 :type 'regexp
111 :group 'whitespace) 105 :group 'whitespace)
112 106
113(defcustom whitespace-check-indent-whitespace t 107(defcustom whitespace-check-indent-whitespace t
@@ -117,7 +111,7 @@ don't define defcustom"
117 111
118(defcustom whitespace-indent-regexp (concat "^\\(\t*\\) " " ") 112(defcustom whitespace-indent-regexp (concat "^\\(\t*\\) " " ")
119 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line." 113 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line."
120 :type 'string 114 :type 'regexp
121 :group 'whitespace) 115 :group 'whitespace)
122 116
123(defcustom whitespace-check-ateol-whitespace t 117(defcustom whitespace-check-ateol-whitespace t
@@ -127,11 +121,11 @@ don't define defcustom"
127 121
128(defcustom whitespace-ateol-regexp "[ \t]$" 122(defcustom whitespace-ateol-regexp "[ \t]$"
129 "Regexp to match a TAB or a space at the EOL." 123 "Regexp to match a TAB or a space at the EOL."
130 :type 'string 124 :type 'regexp
131 :group 'whitespace) 125 :group 'whitespace)
132 126
133(defcustom whitespace-errbuf "*Whitespace Errors*" 127(defcustom whitespace-errbuf "*Whitespace Errors*"
134 "The buffer where whitespace related messages will be logged." 128 "The name of the buffer where whitespace related messages will be logged."
135 :type 'string 129 :type 'string
136 :group 'whitespace) 130 :group 'whitespace)
137 131
@@ -166,7 +160,7 @@ Errors*' buffer before opening (or closing) another file."
166 160
167 "Major Modes in which we turn on whitespace checking. 161 "Major Modes in which we turn on whitespace checking.
168 162
169These are mostly programming and documentation modes. But you may add other 163These are mostly programming and documentation modes. But you may add other
170modes that you want whitespaces checked in by adding something like the 164modes that you want whitespaces checked in by adding something like the
171following to your `.emacs': 165following to your `.emacs':
172 166
@@ -174,6 +168,7 @@ following to your `.emacs':
174 whitespace-modes))\) 168 whitespace-modes))\)
175 169
176Or, alternately, you can use the Emacs `customize' command to set this." 170Or, alternately, you can use the Emacs `customize' command to set this."
171 :type '(repeat symbol)
177 :group 'whitespace) 172 :group 'whitespace)
178 173
179(defcustom whitespace-rescan-timer-time 600 174(defcustom whitespace-rescan-timer-time 600
@@ -206,8 +201,8 @@ To disable timer scans, set this to zero."
206 201
207;;;###autoload 202;;;###autoload
208(defun whitespace-buffer (&optional quiet) 203(defun whitespace-buffer (&optional quiet)
209 "Find five different types of white spaces in buffer: 204 "Find five different types of white spaces in buffer.
210 205These are:
2111. Leading space \(empty lines at the top of a file\). 2061. Leading space \(empty lines at the top of a file\).
2122. Trailing space \(empty lines at the end of a file\). 2072. Trailing space \(empty lines at the end of a file\).
2133. Indentation space \(8 or more spaces, that should be replaced with TABS\). 2083. Indentation space \(8 or more spaces, that should be replaced with TABS\).
@@ -310,7 +305,7 @@ and:
310 305
311;;;###autoload 306;;;###autoload
312(defun whitespace-region (s e) 307(defun whitespace-region (s e)
313 "Check a region specified by point and mark for whitespace errors." 308 "Check the region for whitespace errors."
314 (interactive "r") 309 (interactive "r")
315 (save-excursion 310 (save-excursion
316 (save-restriction 311 (save-restriction
@@ -375,7 +370,7 @@ whitespace problems."
375 370
376;;;###autoload 371;;;###autoload
377(defun whitespace-cleanup-region (s e) 372(defun whitespace-cleanup-region (s e)
378 "Whitespace cleanup on a region specified by point and mark." 373 "Whitespace cleanup on the region."
379 (interactive "r") 374 (interactive "r")
380 (save-excursion 375 (save-excursion
381 (save-restriction 376 (save-restriction
@@ -500,8 +495,8 @@ whitespace problems."
500 nil))) 495 nil)))
501 496
502(defun whitespace-update-modeline (&optional whitespace-err) 497(defun whitespace-update-modeline (&optional whitespace-err)
503 "Update modeline with whitespace errors and whitespaces whose testing has 498 "Update modeline with whitespace errors.
504been turned off." 499Also with whitespaces whose testing has been turned off."
505 (if whitespace-display-in-modeline 500 (if whitespace-display-in-modeline
506 (progn 501 (progn
507 (setq whitespace-mode-line nil) 502 (setq whitespace-mode-line nil)
@@ -522,9 +517,9 @@ been turned off."
522;; Force mode line updation for different Emacs versions 517;; Force mode line updation for different Emacs versions
523(defun whitespace-force-mode-line-update () 518(defun whitespace-force-mode-line-update ()
524 "Force the mode line update for different flavors of Emacs." 519 "Force the mode line update for different flavors of Emacs."
525 (if whitespace-running-emacs 520 (if (fboundp 'redraw-modeline)
526 (force-mode-line-update) ; Emacs 521 (redraw-modeline) ; XEmacs
527 (redraw-modeline))) ; XEmacs 522 (force-mode-line-update))) ; Emacs
528 523
529(defun whitespace-check-buffer-list (buf-name buf-file) 524(defun whitespace-check-buffer-list (buf-name buf-file)
530 "Add a buffer and its file to the whitespace monitor list. 525 "Add a buffer and its file to the whitespace monitor list.
@@ -543,12 +538,9 @@ If timer is not set, then set it to scan the files in
543`whitespace-rescan-timer-time') for whitespace creep." 538`whitespace-rescan-timer-time') for whitespace creep."
544 (if (and whitespace-rescan-timer-time (not whitespace-rescan-timer)) 539 (if (and whitespace-rescan-timer-time (not whitespace-rescan-timer))
545 (setq whitespace-rescan-timer 540 (setq whitespace-rescan-timer
546 (if whitespace-running-emacs 541 (add-timeout whitespace-rescan-timer-time
547 (run-at-time nil whitespace-rescan-timer-time 542 'whitespace-rescan-files-in-buffers nil
548 'whitespace-rescan-files-in-buffers) 543 whitespace-rescan-timer-time))))
549 (add-timeout whitespace-rescan-timer-time
550 'whitespace-rescan-files-in-buffers nil
551 whitespace-rescan-timer-time)))))
552 544
553(defun whitespace-rescan-files-in-buffers (&optional arg) 545(defun whitespace-rescan-files-in-buffers (&optional arg)
554 "Check monitored files for whitespace creep since last scan." 546 "Check monitored files for whitespace creep since last scan."
@@ -556,9 +548,7 @@ If timer is not set, then set it to scan the files in
556 buffile bufname thiselt buf) 548 buffile bufname thiselt buf)
557 (if (not whitespace-all-my-files) 549 (if (not whitespace-all-my-files)
558 (progn 550 (progn
559 (if whitespace-running-emacs 551 (disable-timeout whitespace-rescan-timer)
560 (cancel-timer whitespace-rescan-timer)
561 (disable-timeout whitespace-rescan-timer))
562 (setq whitespace-rescan-timer nil)) 552 (setq whitespace-rescan-timer nil))
563 (while whitespace-all-my-files 553 (while whitespace-all-my-files
564 (setq thiselt (car whitespace-all-my-files)) 554 (setq thiselt (car whitespace-all-my-files))
@@ -588,16 +578,42 @@ If timer is not set, then set it to scan the files in
588(defun whitespace-refresh-rescan-list (buffile bufname) 578(defun whitespace-refresh-rescan-list (buffile bufname)
589 "Refresh the list of files to be rescaned for whitespace creep." 579 "Refresh the list of files to be rescaned for whitespace creep."
590 (if whitespace-all-buffer-files 580 (if whitespace-all-buffer-files
581 (setq whitespace-all-buffer-files
582 (delete (list buffile bufname) whitespace-all-buffer-files))
583 (when whitespace-rescan-timer
584 (disable-timeout whitespace-rescan-timer)
585 (setq whitespace-rescan-timer nil))))
586
587;;;###autoload
588(defcustom whitespace-global-mode nil
589 "Toggle global Whitespace mode.
590
591Setting this variable directly does not take effect;
592use either \\[customize] or the function `whitespace-global-mode'
593\(which see)."
594 :set (lambda (sym val)
595 (whitespace-global-mode (or value 0)))
596 :initialize 'custom-initialize-default
597 :type 'boolean
598 :group 'whitespace
599 :require 'whitespace)
600
601(defun whitespace-global-mode (&optional arg)
602 "Toggle using Whitespace mode in new buffers.
603With ARG, turn the mode on if and only iff ARG is positive.
604
605When this mode is active, `whitespace-buffer' is added to
606`find-file-hooks' and `kill-buffer-hook'."
607 (interactive "P")
608 (setq arg (if arg
609 (> (prefix-numeric-value arg) 0)
610 (not whitespace-global-mode)))
611 (if arg
591 (progn 612 (progn
592 (setq whitespace-all-buffer-files 613 (add-hook 'find-file-hooks 'whitespace-buffer)
593 (delete (list buffile bufname) whitespace-all-buffer-files))) 614 (add-hook 'kill-buffer-hook 'whitespace-buffer))
594 (progn 615 (remove-hook 'find-file-hooks 'whitespace-buffer)
595 (if (and whitespace-running-emacs (timerp whitespace-rescan-timer)) 616 (remove-hook 'kill-buffer-hook 'whitespace-buffer)))
596 (cancel-timer whitespace-rescan-timer))
597 (if (and (not whitespace-running-emacs) whitespace-rescan-timer)
598 (disable-timeout whitespace-rescan-timer))
599 (if whitespace-rescan-timer
600 (setq whitespace-rescan-timer nil)))))
601 617
602;;;###autoload 618;;;###autoload
603(defun whitespace-describe () 619(defun whitespace-describe ()
@@ -610,7 +626,7 @@ of whitespace problems that commonly exist in source code.
6102. Trailing space (empty lines at the end of a file). 6262. Trailing space (empty lines at the end of a file).
6113. Indentation space (8 or more spaces at beginning of line, that should be 6273. Indentation space (8 or more spaces at beginning of line, that should be
612 replaced with TABS). 628 replaced with TABS).
6134. Spaces followed by a TAB. (Almost always, we never want that). 6294. Spaces followed by a TAB. (Almost always, we never want that).
6145. Spaces or TABS at the end of a line. 6305. Spaces or TABS at the end of a line.
615 631
616Whitespace errors are reported in a buffer, and on the modeline. 632Whitespace errors are reported in a buffer, and on the modeline.
@@ -629,18 +645,18 @@ If any of the whitespace checks is turned off, the modeline will display a
629 645
630 (since (3) is the most controversial one, here is the rationale: Most 646 (since (3) is the most controversial one, here is the rationale: Most
631 terminal drivers and printer drivers have TAB configured or even 647 terminal drivers and printer drivers have TAB configured or even
632 hardcoded to be 8 spaces. (Some of them allow configuration, but almost 648 hardcoded to be 8 spaces. (Some of them allow configuration, but almost
633 always they default to 8.) 649 always they default to 8.)
634 650
635 Changing tab-width to other than 8 and editing will cause your code to 651 Changing `tab-width' to other than 8 and editing will cause your code to
636 look different from within Emacs, and say, if you cat it or more it, or 652 look different from within Emacs, and say, if you cat it or more it, or
637 even print it. 653 even print it.
638 654
639 Almost all the popular programming modes let you define an offset (like 655 Almost all the popular programming modes let you define an offset (like
640 c-basic-offset or perl-indent-level) to configure the offset, so you 656 c-basic-offset or perl-indent-level) to configure the offset, so you
641 should never have to set your tab-width to be other than 8 in all these 657 should never have to set your `tab-width' to be other than 8 in all these
642 modes. In fact, with an indent level of say, 4, 2 TABS will cause Emacs 658 modes. In fact, with an indent level of say, 4, 2 TABS will cause Emacs
643 to replace your 8 spaces with one \t (try it). If vi users in your 659 to replace your 8 spaces with one \t (try it). If vi users in your
644 office complain, tell them to use vim, which distinguishes between 660 office complain, tell them to use vim, which distinguishes between
645 tabstop and shiftwidth (vi equivalent of our offsets), and also ask them 661 tabstop and shiftwidth (vi equivalent of our offsets), and also ask them
646 to set smarttab.) 662 to set smarttab.)
@@ -649,12 +665,16 @@ All the above have caused (and will cause) unwanted codeline integration and
649merge problems. 665merge problems.
650 666
651whitespace.el will complain if it detects whitespaces on opening a file, and 667whitespace.el will complain if it detects whitespaces on opening a file, and
652warn you on closing a file also. (if in case you had inserted any 668warn you on closing a file also (in case you had inserted any
653whitespaces during the process of your editing.)" 669whitespaces during the process of your editing)."
654 (interactive) 670 (interactive)
655 (message "Use C-h f whitespace-describe to read about whitespace.el v%s." 671 (message "Use C-h f whitespace-describe to read about whitespace.el v%s."
656 whitespace-version)) 672 whitespace-version))
657 673
674(defun whitespace-unload-hook ()
675 (remove-hook 'find-file-hooks 'whitespace-buffer)
676 (remove-hook 'kill-buffer-hook 'whitespace-buffer))
677
658(provide 'whitespace) 678(provide 'whitespace)
659 679
660;;; whitespace.el ends here 680;;; whitespace.el ends here