Mercurial > emacs
comparison lisp/whitespace.el @ 83353:532e0a9335a9
Merged in changes from CVS trunk. Plus added lisp/term tweaks.
Patches applied:
* lorentey@elte.hu--2004/emacs--cvs-trunk--0--base-0
tag of miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-474
* lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-1
Add CVS metadata files.
* lorentey@elte.hu--2004/emacs--cvs-trunk--0--patch-2
Update from CVS.
git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-393
author | Karoly Lorentey <lorentey@elte.hu> |
---|---|
date | Sun, 04 Sep 2005 03:48:17 +0000 |
parents | 6c13700d1c13 41bb365f41c4 |
children | b31326248cf6 |
comparison
equal
deleted
inserted
replaced
83352:b258b3492423 | 83353:532e0a9335a9 |
---|---|
1 ;;; whitespace.el --- warn about and clean bogus whitespaces in the file | 1 ;;; whitespace.el --- warn about and clean bogus whitespaces in the file |
2 | 2 |
3 ;; Copyright (C) 1999, 2000, 2005 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004, |
4 ;; 2005 Free Software Foundation, Inc. | |
4 | 5 |
5 ;; Author: Rajesh Vaidheeswarran <rv@gnu.org> | 6 ;; Author: Rajesh Vaidheeswarran <rv@gnu.org> |
6 ;; Keywords: convenience | 7 ;; Keywords: convenience |
7 | 8 |
8 ;; This file is part of GNU Emacs. | 9 ;; This file is part of GNU Emacs. |
107 "String to display in the mode line for Whitespace mode.") | 108 "String to display in the mode line for Whitespace mode.") |
108 (make-variable-buffer-local 'whitespace-mode-line) | 109 (make-variable-buffer-local 'whitespace-mode-line) |
109 (put 'whitespace-mode-line 'permanent-local nil) | 110 (put 'whitespace-mode-line 'permanent-local nil) |
110 | 111 |
111 (defvar whitespace-check-buffer-leading nil | 112 (defvar whitespace-check-buffer-leading nil |
112 "Test leading whitespace for file in current buffer if t") | 113 "Test leading whitespace for file in current buffer if t.") |
113 (make-variable-buffer-local 'whitespace-check-buffer-leading) | 114 (make-variable-buffer-local 'whitespace-check-buffer-leading) |
114 (put 'whitespace-check-buffer-leading 'permanent-local nil) | 115 (put 'whitespace-check-buffer-leading 'permanent-local nil) |
115 | 116 |
116 (defvar whitespace-check-buffer-trailing nil | 117 (defvar whitespace-check-buffer-trailing nil |
117 "Test trailing whitespace for file in current buffer if t") | 118 "Test trailing whitespace for file in current buffer if t.") |
118 (make-variable-buffer-local 'whitespace-check-buffer-trailing) | 119 (make-variable-buffer-local 'whitespace-check-buffer-trailing) |
119 (put 'whitespace-check-buffer-trailing 'permanent-local nil) | 120 (put 'whitespace-check-buffer-trailing 'permanent-local nil) |
120 | 121 |
121 (defvar whitespace-check-buffer-indent nil | 122 (defvar whitespace-check-buffer-indent nil |
122 "Test indentation whitespace for file in current buffer if t") | 123 "Test indentation whitespace for file in current buffer if t.") |
123 (make-variable-buffer-local 'whitespace-check-buffer-indent) | 124 (make-variable-buffer-local 'whitespace-check-buffer-indent) |
124 (put 'whitespace-check-buffer-indent 'permanent-local nil) | 125 (put 'whitespace-check-buffer-indent 'permanent-local nil) |
125 | 126 |
126 (defvar whitespace-check-buffer-spacetab nil | 127 (defvar whitespace-check-buffer-spacetab nil |
127 "Test Space-followed-by-TABS whitespace for file in current buffer if t") | 128 "Test Space-followed-by-TABS whitespace for file in current buffer if t.") |
128 (make-variable-buffer-local 'whitespace-check-buffer-spacetab) | 129 (make-variable-buffer-local 'whitespace-check-buffer-spacetab) |
129 (put 'whitespace-check-buffer-spacetab 'permanent-local nil) | 130 (put 'whitespace-check-buffer-spacetab 'permanent-local nil) |
130 | 131 |
131 (defvar whitespace-check-buffer-ateol nil | 132 (defvar whitespace-check-buffer-ateol nil |
132 "Test end-of-line whitespace for file in current buffer if t") | 133 "Test end-of-line whitespace for file in current buffer if t.") |
133 (make-variable-buffer-local 'whitespace-check-buffer-ateol) | 134 (make-variable-buffer-local 'whitespace-check-buffer-ateol) |
134 (put 'whitespace-check-buffer-ateol 'permanent-local nil) | 135 (put 'whitespace-check-buffer-ateol 'permanent-local nil) |
135 | 136 |
136 (defvar whitespace-highlighted-space nil | 137 (defvar whitespace-highlighted-space nil |
137 "The variable to store the extent to highlight") | 138 "The variable to store the extent to highlight.") |
138 (make-variable-buffer-local 'whitespace-highlighted-space) | 139 (make-variable-buffer-local 'whitespace-highlighted-space) |
139 (put 'whitespace-highlighted-space 'permanent-local nil) | 140 (put 'whitespace-highlighted-space 'permanent-local nil) |
140 | 141 |
141 ;; For flavors of Emacs which don't define `defgroup' and `defcustom'. | 142 ;; For flavors of Emacs which don't define `defgroup' and `defcustom'. |
142 (eval-when-compile | 143 (eval-when-compile |
143 (if (not (fboundp 'defgroup)) | 144 (if (not (fboundp 'defgroup)) |
144 (defmacro defgroup (sym memb doc &rest args) | 145 (defmacro defgroup (sym memb doc &rest args) |
145 "Null macro for defgroup in all versions of Emacs that don't define | 146 "Null macro for `defgroup' in all versions of Emacs that don't define it." |
146 defgroup" | |
147 t)) | 147 t)) |
148 (if (not (fboundp 'defcustom)) | 148 (if (not (fboundp 'defcustom)) |
149 (defmacro defcustom (sym val doc &rest args) | 149 (defmacro defcustom (sym val doc &rest args) |
150 "Macro to alias defcustom to defvar in all versions of Emacs that | 150 "Macro to alias `defcustom' to `defvar' in all versions of Emacs that |
151 don't define defcustom" | 151 don't define it." |
152 `(defvar ,sym ,val ,doc)))) | 152 `(defvar ,sym ,val ,doc)))) |
153 | 153 |
154 (if (fboundp 'make-overlay) | 154 (defalias 'whitespace-make-overlay |
155 (progn | 155 (if (featurep 'xemacs) 'make-extent 'make-overlay)) |
156 (defalias 'whitespace-make-overlay 'make-overlay) | 156 (defalias 'whitespace-overlay-put |
157 (defalias 'whitespace-overlay-put 'overlay-put) | 157 (if (featurep 'xemacs) 'set-extent-property 'overlay-put)) |
158 (defalias 'whitespace-delete-overlay 'delete-overlay) | 158 (defalias 'whitespace-delete-overlay |
159 (defalias 'whitespace-overlay-start 'overlay-start) | 159 (if (featurep 'xemacs) 'delete-extent 'delete-overlay)) |
160 (defalias 'whitespace-overlay-end 'overlay-end) | 160 (defalias 'whitespace-overlay-start |
161 (defalias 'whitespace-mode-line-update 'force-mode-line-update)) | 161 (if (featurep 'xemacs) 'extent-start 'overlay-start)) |
162 (defalias 'whitespace-make-overlay 'make-extent) | 162 (defalias 'whitespace-overlay-end |
163 (defalias 'whitespace-overlay-put 'set-extent-property) | 163 (if (featurep 'xemacs) 'extent-end 'overlay-end)) |
164 (defalias 'whitespace-delete-overlay 'delete-extent) | 164 (defalias 'whitespace-mode-line-update |
165 (defalias 'whitespace-overlay-start 'extent-start) | 165 (if (featurep 'xemacs) 'redraw-modeline 'force-mode-line-update)) |
166 (defalias 'whitespace-overlay-end 'extent-end) | 166 |
167 (defalias 'whitespace-mode-line-update 'redraw-modeline)) | |
168 | |
169 (if (featurep 'xemacs) | |
170 (defgroup whitespace nil | |
171 "Check for and fix five different types of whitespaces in source code." | |
172 ;; Since XEmacs doesn't have a 'convenience group, use the next best group | |
173 ;; which is 'editing? | |
174 :link '(emacs-commentary-link "whitespace.el") | |
175 :group 'editing) | |
176 (defgroup whitespace nil | 167 (defgroup whitespace nil |
177 "Check for and fix five different types of whitespaces in source code." | 168 "Check for and fix five different types of whitespaces in source code." |
178 :version "21.1" | 169 :version "21.1" |
179 :link '(emacs-commentary-link "whitespace.el") | 170 :link '(emacs-commentary-link "whitespace.el") |
180 :group 'convenience)) | 171 ;; Since XEmacs doesn't have a 'convenience group, use the next best group |
172 ;; which is 'editing? | |
173 :group (if (featurep 'xemacs) 'editing 'convenience)) | |
181 | 174 |
182 (defcustom whitespace-check-leading-whitespace t | 175 (defcustom whitespace-check-leading-whitespace t |
183 "Flag to check leading whitespace. This is the global for the system. | 176 "Flag to check leading whitespace. This is the global for the system. |
184 It can be overriden by setting a buffer local variable | 177 It can be overriden by setting a buffer local variable |
185 `whitespace-check-buffer-leading'" | 178 `whitespace-check-buffer-leading'." |
186 :type 'boolean | 179 :type 'boolean |
187 :group 'whitespace) | 180 :group 'whitespace) |
188 | 181 |
189 (defcustom whitespace-check-trailing-whitespace t | 182 (defcustom whitespace-check-trailing-whitespace t |
190 "Flag to check trailing whitespace. This is the global for the system. | 183 "Flag to check trailing whitespace. This is the global for the system. |
191 It can be overriden by setting a buffer local variable | 184 It can be overriden by setting a buffer local variable |
192 `whitespace-check-buffer-trailing'" | 185 `whitespace-check-buffer-trailing'." |
193 :type 'boolean | 186 :type 'boolean |
194 :group 'whitespace) | 187 :group 'whitespace) |
195 | 188 |
196 (defcustom whitespace-check-spacetab-whitespace t | 189 (defcustom whitespace-check-spacetab-whitespace t |
197 "Flag to check space followed by a TAB. This is the global for the system. | 190 "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 | 191 It can be overriden by setting a buffer local variable |
199 `whitespace-check-buffer-spacetab'" | 192 `whitespace-check-buffer-spacetab'." |
200 :type 'boolean | 193 :type 'boolean |
201 :group 'whitespace) | 194 :group 'whitespace) |
202 | 195 |
203 (defcustom whitespace-spacetab-regexp "[ ]+\t" | 196 (defcustom whitespace-spacetab-regexp "[ ]+\t" |
204 "Regexp to match a space followed by a TAB." | 197 "Regexp to match a space followed by a TAB." |
205 :type 'regexp | 198 :type 'regexp |
206 :group 'whitespace) | 199 :group 'whitespace) |
207 | 200 |
208 (defcustom whitespace-check-indent-whitespace indent-tabs-mode | 201 (defcustom whitespace-check-indent-whitespace indent-tabs-mode |
209 "Flag to check indentation whitespace. This is the global for the system. | 202 "Flag to check indentation whitespace. This is the global for the system. |
210 It can be overriden by setting a buffer local variable | 203 It can be overriden by setting a buffer local variable |
211 `whitespace-check-buffer-indent'" | 204 `whitespace-check-buffer-indent'." |
212 :type 'boolean | 205 :type 'boolean |
213 :group 'whitespace) | 206 :group 'whitespace) |
214 | 207 |
215 (defcustom whitespace-indent-regexp (concat "^\\(\t*\\) " " ") | 208 (defcustom whitespace-indent-regexp (concat "^\\(\t*\\) " " ") |
216 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line." | 209 "Regexp to match (any TABS followed by) 8/more whitespaces at start of line." |
217 :type 'regexp | 210 :type 'regexp |
218 :group 'whitespace) | 211 :group 'whitespace) |
219 | 212 |
220 (defcustom whitespace-check-ateol-whitespace t | 213 (defcustom whitespace-check-ateol-whitespace t |
221 "Flag to check end-of-line whitespace. This is the global for the system. | 214 "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 | 215 It can be overriden by setting a buffer local variable |
223 `whitespace-check-buffer-ateol'" | 216 `whitespace-check-buffer-ateol'." |
224 :type 'boolean | 217 :type 'boolean |
225 :group 'whitespace) | 218 :group 'whitespace) |
226 | 219 |
227 ;; (defcustom whitespace-ateol-regexp "[ \t]$" | 220 ;; (defcustom whitespace-ateol-regexp "[ \t]$" |
228 (defcustom whitespace-ateol-regexp "[ \t]+$" | 221 (defcustom whitespace-ateol-regexp "[ \t]+$" |
240 determines a file to be clean." | 233 determines a file to be clean." |
241 :type 'string | 234 :type 'string |
242 :group 'whitespace) | 235 :group 'whitespace) |
243 | 236 |
244 (defcustom whitespace-abort-on-error nil | 237 (defcustom whitespace-abort-on-error nil |
245 "While writing a file, abort if the file is unclean. If | 238 "While writing a file, abort if the file is unclean. |
246 `whitespace-auto-cleanup' is set, that takes precedence over this | 239 If `whitespace-auto-cleanup' is set, that takes precedence over |
247 variable." | 240 this variable." |
248 :type 'boolean | 241 :type 'boolean |
249 :group 'whitespace) | 242 :group 'whitespace) |
250 | 243 |
251 (defcustom whitespace-auto-cleanup nil | 244 (defcustom whitespace-auto-cleanup nil |
252 "Cleanup a buffer automatically on finding it whitespace unclean." | 245 "Cleanup a buffer automatically on finding it whitespace unclean." |
275 python-mode scheme-mode sgml-mode | 268 python-mode scheme-mode sgml-mode |
276 sh-mode shell-script-mode simula-mode | 269 sh-mode shell-script-mode simula-mode |
277 tcl-mode tex-mode texinfo-mode | 270 tcl-mode tex-mode texinfo-mode |
278 vrml-mode xml-mode) | 271 vrml-mode xml-mode) |
279 | 272 |
280 "Major Modes in which we turn on whitespace checking. | 273 "Major modes in which we turn on whitespace checking. |
281 | 274 |
282 These are mostly programming and documentation modes. But you may add other | 275 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 | 276 modes that you want whitespaces checked in by adding something like the |
284 following to your `.emacs': | 277 following to your `.emacs': |
285 | 278 |
606 nil)))) | 599 nil)))) |
607 | 600 |
608 (defun whitespace-buffer-leading-cleanup () | 601 (defun whitespace-buffer-leading-cleanup () |
609 "Remove any empty lines at the top of the file." | 602 "Remove any empty lines at the top of the file." |
610 (save-excursion | 603 (save-excursion |
611 (let ((pmin nil) | 604 (goto-char (point-min)) |
612 (pmax nil)) | 605 (skip-chars-forward "\n") |
613 (goto-char (point-min)) | 606 (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 | 607 |
623 (defun whitespace-buffer-trailing () | 608 (defun whitespace-buffer-trailing () |
624 "Check to see if are is more than one empty line at the bottom." | 609 "Check to see if are is more than one empty line at the bottom." |
625 (save-excursion | 610 (save-excursion |
626 (let ((pmin nil) | 611 (let ((pmin nil) |
645 nil)))) | 630 nil)))) |
646 | 631 |
647 (defun whitespace-buffer-trailing-cleanup () | 632 (defun whitespace-buffer-trailing-cleanup () |
648 "Delete all the empty lines at the bottom." | 633 "Delete all the empty lines at the bottom." |
649 (save-excursion | 634 (save-excursion |
650 (let ((pmin nil) | 635 (goto-char (point-max)) |
651 (pmax nil)) | 636 (skip-chars-backward "\n") |
652 (goto-char (point-max)) | 637 (if (not (bolp)) |
653 (beginning-of-line) | 638 (forward-char 1)) |
654 (setq pmin (point)) | 639 (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 | 640 |
671 (defun whitespace-buffer-search (regexp) | 641 (defun whitespace-buffer-search (regexp) |
672 "Search for any given whitespace REGEXP." | 642 "Search for any given whitespace REGEXP." |
673 (let ((whitespace-retval "")) | 643 (let ((whitespace-retval "")) |
674 (save-excursion | 644 (save-excursion |