comparison lisp/whitespace.el @ 90201:fbb2bea03df9

Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-69 Merge from emacs--cvs-trunk--0 Patches applied: * emacs--cvs-trunk--0 (patch 474-484) - Update from CVS - Merge from gnus--rel--5.10 * gnus--rel--5.10 (patch 88-91) - Merge from emacs--cvs-trunk--0 - Update FSF's address in GPL notices - Update from CVS
author Miles Bader <miles@gnu.org>
date Thu, 14 Jul 2005 08:02:00 +0000
parents f9a65d7ebd29 f44bd79f483b
children 187d6a1f84f7
comparison
equal deleted inserted replaced
90200:f9a65d7ebd29 90201:fbb2bea03df9
107 "String to display in the mode line for Whitespace mode.") 107 "String to display in the mode line for Whitespace mode.")
108 (make-variable-buffer-local 'whitespace-mode-line) 108 (make-variable-buffer-local 'whitespace-mode-line)
109 (put 'whitespace-mode-line 'permanent-local nil) 109 (put 'whitespace-mode-line 'permanent-local nil)
110 110
111 (defvar whitespace-check-buffer-leading nil 111 (defvar whitespace-check-buffer-leading nil
112 "Test leading whitespace for file in current buffer if t") 112 "Test leading whitespace for file in current buffer if t.")
113 (make-variable-buffer-local 'whitespace-check-buffer-leading) 113 (make-variable-buffer-local 'whitespace-check-buffer-leading)
114 (put 'whitespace-check-buffer-leading 'permanent-local nil) 114 (put 'whitespace-check-buffer-leading 'permanent-local nil)
115 115
116 (defvar whitespace-check-buffer-trailing nil 116 (defvar whitespace-check-buffer-trailing nil
117 "Test trailing whitespace for file in current buffer if t") 117 "Test trailing whitespace for file in current buffer if t.")
118 (make-variable-buffer-local 'whitespace-check-buffer-trailing) 118 (make-variable-buffer-local 'whitespace-check-buffer-trailing)
119 (put 'whitespace-check-buffer-trailing 'permanent-local nil) 119 (put 'whitespace-check-buffer-trailing 'permanent-local nil)
120 120
121 (defvar whitespace-check-buffer-indent nil 121 (defvar whitespace-check-buffer-indent nil
122 "Test indentation whitespace for file in current buffer if t") 122 "Test indentation whitespace for file in current buffer if t.")
123 (make-variable-buffer-local 'whitespace-check-buffer-indent) 123 (make-variable-buffer-local 'whitespace-check-buffer-indent)
124 (put 'whitespace-check-buffer-indent 'permanent-local nil) 124 (put 'whitespace-check-buffer-indent 'permanent-local nil)
125 125
126 (defvar whitespace-check-buffer-spacetab nil 126 (defvar whitespace-check-buffer-spacetab nil
127 "Test Space-followed-by-TABS whitespace for file in current buffer if t") 127 "Test Space-followed-by-TABS whitespace for file in current buffer if t.")
128 (make-variable-buffer-local 'whitespace-check-buffer-spacetab) 128 (make-variable-buffer-local 'whitespace-check-buffer-spacetab)
129 (put 'whitespace-check-buffer-spacetab 'permanent-local nil) 129 (put 'whitespace-check-buffer-spacetab 'permanent-local nil)
130 130
131 (defvar whitespace-check-buffer-ateol nil 131 (defvar whitespace-check-buffer-ateol nil
132 "Test end-of-line whitespace for file in current buffer if t") 132 "Test end-of-line whitespace for file in current buffer if t.")
133 (make-variable-buffer-local 'whitespace-check-buffer-ateol) 133 (make-variable-buffer-local 'whitespace-check-buffer-ateol)
134 (put 'whitespace-check-buffer-ateol 'permanent-local nil) 134 (put 'whitespace-check-buffer-ateol 'permanent-local nil)
135 135
136 (defvar whitespace-highlighted-space nil 136 (defvar whitespace-highlighted-space nil
137 "The variable to store the extent to highlight") 137 "The variable to store the extent to highlight.")
138 (make-variable-buffer-local 'whitespace-highlighted-space) 138 (make-variable-buffer-local 'whitespace-highlighted-space)
139 (put 'whitespace-highlighted-space 'permanent-local nil) 139 (put 'whitespace-highlighted-space 'permanent-local nil)
140 140
141 ;; For flavors of Emacs which don't define `defgroup' and `defcustom'. 141 ;; For flavors of Emacs which don't define `defgroup' and `defcustom'.
142 (eval-when-compile 142 (eval-when-compile
143 (if (not (fboundp 'defgroup)) 143 (if (not (fboundp 'defgroup))
144 (defmacro defgroup (sym memb doc &rest args) 144 (defmacro defgroup (sym memb doc &rest args)
145 "Null macro for defgroup in all versions of Emacs that don't define 145 "Null macro for `defgroup' in all versions of Emacs that don't define it."
146 defgroup"
147 t)) 146 t))
148 (if (not (fboundp 'defcustom)) 147 (if (not (fboundp 'defcustom))
149 (defmacro defcustom (sym val doc &rest args) 148 (defmacro defcustom (sym val doc &rest args)
150 "Macro to alias defcustom to defvar in all versions of Emacs that 149 "Macro to alias `defcustom' to `defvar' in all versions of Emacs that
151 don't define defcustom" 150 don't define it."
152 `(defvar ,sym ,val ,doc)))) 151 `(defvar ,sym ,val ,doc))))
153 152
154 (if (fboundp 'make-overlay) 153 (if (fboundp 'make-overlay)
155 (progn 154 (progn
156 (defalias 'whitespace-make-overlay 'make-overlay) 155 (defalias 'whitespace-make-overlay 'make-overlay)
178 :version "21.1" 177 :version "21.1"
179 :link '(emacs-commentary-link "whitespace.el") 178 :link '(emacs-commentary-link "whitespace.el")
180 :group 'convenience)) 179 :group 'convenience))
181 180
182 (defcustom whitespace-check-leading-whitespace t 181 (defcustom whitespace-check-leading-whitespace t
183 "Flag to check leading whitespace. This is the global for the system. 182 "Flag to check leading whitespace. This is the global for the system.
184 It can be overriden by setting a buffer local variable 183 It can be overriden by setting a buffer local variable
185 `whitespace-check-buffer-leading'" 184 `whitespace-check-buffer-leading'."
186 :type 'boolean 185 :type 'boolean
187 :group 'whitespace) 186 :group 'whitespace)
188 187
189 (defcustom whitespace-check-trailing-whitespace t 188 (defcustom whitespace-check-trailing-whitespace t
190 "Flag to check trailing whitespace. This is the global for the system. 189 "Flag to check trailing whitespace. This is the global for the system.
191 It can be overriden by setting a buffer local variable 190 It can be overriden by setting a buffer local variable
192 `whitespace-check-buffer-trailing'" 191 `whitespace-check-buffer-trailing'."
193 :type 'boolean 192 :type 'boolean
194 :group 'whitespace) 193 :group 'whitespace)
195 194
196 (defcustom whitespace-check-spacetab-whitespace t 195 (defcustom whitespace-check-spacetab-whitespace t
197 "Flag to check space followed by a TAB. This is the global for the system. 196 "Flag to check space followed by a TAB. This is the global for the system.
198 It can be overriden by setting a buffer local variable 197 It can be overriden by setting a buffer local variable
199 `whitespace-check-buffer-spacetab'" 198 `whitespace-check-buffer-spacetab'."
200 :type 'boolean 199 :type 'boolean
201 :group 'whitespace) 200 :group 'whitespace)
202 201
203 (defcustom whitespace-spacetab-regexp "[ ]+\t" 202 (defcustom whitespace-spacetab-regexp "[ ]+\t"
204 "Regexp to match a space followed by a TAB." 203 "Regexp to match a space followed by a TAB."
205 :type 'regexp 204 :type 'regexp
206 :group 'whitespace) 205 :group 'whitespace)
207 206
208 (defcustom whitespace-check-indent-whitespace indent-tabs-mode 207 (defcustom whitespace-check-indent-whitespace indent-tabs-mode
209 "Flag to check indentation whitespace. This is the global for the system. 208 "Flag to check indentation whitespace. This is the global for the system.
210 It can be overriden by setting a buffer local variable 209 It can be overriden by setting a buffer local variable
211 `whitespace-check-buffer-indent'" 210 `whitespace-check-buffer-indent'."
212 :type 'boolean 211 :type 'boolean
213 :group 'whitespace) 212 :group 'whitespace)
214 213
215 (defcustom whitespace-indent-regexp (concat "^\\(\t*\\) " " ") 214 (defcustom whitespace-indent-regexp (concat "^\\(\t*\\) " " ")
216 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line." 215 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line."
217 :type 'regexp 216 :type 'regexp
218 :group 'whitespace) 217 :group 'whitespace)
219 218
220 (defcustom whitespace-check-ateol-whitespace t 219 (defcustom whitespace-check-ateol-whitespace t
221 "Flag to check end-of-line whitespace. This is the global for the system. 220 "Flag to check end-of-line whitespace. This is the global for the system.
222 It can be overriden by setting a buffer local variable 221 It can be overriden by setting a buffer local variable
223 `whitespace-check-buffer-ateol'" 222 `whitespace-check-buffer-ateol'."
224 :type 'boolean 223 :type 'boolean
225 :group 'whitespace) 224 :group 'whitespace)
226 225
227 ;; (defcustom whitespace-ateol-regexp "[ \t]$" 226 ;; (defcustom whitespace-ateol-regexp "[ \t]$"
228 (defcustom whitespace-ateol-regexp "[ \t]+$" 227 (defcustom whitespace-ateol-regexp "[ \t]+$"
240 determines a file to be clean." 239 determines a file to be clean."
241 :type 'string 240 :type 'string
242 :group 'whitespace) 241 :group 'whitespace)
243 242
244 (defcustom whitespace-abort-on-error nil 243 (defcustom whitespace-abort-on-error nil
245 "While writing a file, abort if the file is unclean. If 244 "While writing a file, abort if the file is unclean.
246 `whitespace-auto-cleanup' is set, that takes precedence over this 245 If `whitespace-auto-cleanup' is set, that takes precedence over
247 variable." 246 this variable."
248 :type 'boolean 247 :type 'boolean
249 :group 'whitespace) 248 :group 'whitespace)
250 249
251 (defcustom whitespace-auto-cleanup nil 250 (defcustom whitespace-auto-cleanup nil
252 "Cleanup a buffer automatically on finding it whitespace unclean." 251 "Cleanup a buffer automatically on finding it whitespace unclean."
275 python-mode scheme-mode sgml-mode 274 python-mode scheme-mode sgml-mode
276 sh-mode shell-script-mode simula-mode 275 sh-mode shell-script-mode simula-mode
277 tcl-mode tex-mode texinfo-mode 276 tcl-mode tex-mode texinfo-mode
278 vrml-mode xml-mode) 277 vrml-mode xml-mode)
279 278
280 "Major Modes in which we turn on whitespace checking. 279 "Major modes in which we turn on whitespace checking.
281 280
282 These are mostly programming and documentation modes. But you may add other 281 These are mostly programming and documentation modes. But you may add other
283 modes that you want whitespaces checked in by adding something like the 282 modes that you want whitespaces checked in by adding something like the
284 following to your `.emacs': 283 following to your `.emacs':
285 284
606 nil)))) 605 nil))))
607 606
608 (defun whitespace-buffer-leading-cleanup () 607 (defun whitespace-buffer-leading-cleanup ()
609 "Remove any empty lines at the top of the file." 608 "Remove any empty lines at the top of the file."
610 (save-excursion 609 (save-excursion
611 (let ((pmin nil) 610 (goto-char (point-min))
612 (pmax nil)) 611 (skip-chars-forward "\n")
613 (goto-char (point-min)) 612 (delete-region (point-min) (point))))
614 (beginning-of-line)
615 (setq pmin (point))
616 (end-of-line)
617 (setq pmax (point))
618 (if (equal pmin pmax)
619 (progn
620 (kill-line)
621 (whitespace-buffer-leading-cleanup))))))
622 613
623 (defun whitespace-buffer-trailing () 614 (defun whitespace-buffer-trailing ()
624 "Check to see if are is more than one empty line at the bottom." 615 "Check to see if are is more than one empty line at the bottom."
625 (save-excursion 616 (save-excursion
626 (let ((pmin nil) 617 (let ((pmin nil)
645 nil)))) 636 nil))))
646 637
647 (defun whitespace-buffer-trailing-cleanup () 638 (defun whitespace-buffer-trailing-cleanup ()
648 "Delete all the empty lines at the bottom." 639 "Delete all the empty lines at the bottom."
649 (save-excursion 640 (save-excursion
650 (let ((pmin nil) 641 (goto-char (point-max))
651 (pmax nil)) 642 (skip-chars-backward "\n")
652 (goto-char (point-max)) 643 (if (not (bolp))
653 (beginning-of-line) 644 (forward-char 1))
654 (setq pmin (point)) 645 (delete-region (point) (point-max))))
655 (end-of-line)
656 (setq pmax (point))
657 (if (equal pmin pmax)
658 (progn
659 (goto-char (1- pmin))
660 (beginning-of-line)
661 (setq pmin (point))
662 (end-of-line)
663 (setq pmax (point))
664 (if (equal pmin pmax)
665 (progn
666 (goto-char (1- (point-max)))
667 (beginning-of-line)
668 (kill-line)
669 (whitespace-buffer-trailing-cleanup))))))))
670 646
671 (defun whitespace-buffer-search (regexp) 647 (defun whitespace-buffer-search (regexp)
672 "Search for any given whitespace REGEXP." 648 "Search for any given whitespace REGEXP."
673 (let ((whitespace-retval "")) 649 (let ((whitespace-retval ""))
674 (save-excursion 650 (save-excursion