diff options
| author | Gerd Moellmann | 1999-10-30 19:21:43 +0000 |
|---|---|---|
| committer | Gerd Moellmann | 1999-10-30 19:21:43 +0000 |
| commit | dd24f431bebaf977d84fbb9c6e0fe69bde7ffbf0 (patch) | |
| tree | 09c8a70d085e2eb79508d39f6a08a46da2f2b2a8 | |
| parent | e8d017d059d234c10805f15ac89ec749d1656e3c (diff) | |
| download | emacs-dd24f431bebaf977d84fbb9c6e0fe69bde7ffbf0.tar.gz emacs-dd24f431bebaf977d84fbb9c6e0fe69bde7ffbf0.zip | |
(whitespace-version): Update to 2.6
(whitespace-display-in-modeline): Add custom
variable to control displaying the whitespace errors on the
modeline based on suggestion from <klaus.berndl@sdm.de>
(whitespace-buffer): Now returns `t' if unclean
and `nil' if clean, to enable using as a hook function, as
suggested by Puneet Goel <puneet@computer.org>
(whitespace-buffer): Fix a subtle bug that cleaned
up only if quiet was not set, even with whitespace-auto-cleanup set.
(whitespace-mode-line): Now uses less modeline
real estate and shows whitespaces as W:<x>!<y> where <x> is any
type of whitespace which is present in the file, and <y> is any
type of whitespace whose check has been suppressed by setting
`whitespace-check-<whitespace-type>' to nil.
(whitespace-unchecked-whitespaces): New function
to return the list of whitespaces for whom checks have been
suppressed.
(whitespace-display-unchecked-whitespaces):
Renamed to `whitespace-update-modeline' to reflect its functionality.
(whitespace-version): Update to 2.5
| -rw-r--r-- | lisp/ChangeLog | 32 | ||||
| -rw-r--r-- | lisp/whitespace.el | 231 |
2 files changed, 159 insertions, 104 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index ec8dc9d3d1b..6003252f187 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,35 @@ | |||
| 1 | 1999-10-30 Rajesh Vaidheeswarran <rv@dsmit.com> | ||
| 2 | |||
| 3 | * whitespace.el (whitespace-version): Update to 2.6 | ||
| 4 | |||
| 5 | * whitespace.el (whitespace-display-in-modeline): Add custom | ||
| 6 | variable to control displaying the whitespace errors on the | ||
| 7 | modeline based on suggestion from <klaus.berndl@sdm.de> | ||
| 8 | |||
| 9 | * whitespace.el (whitespace-buffer): Now returns `t' if unclean | ||
| 10 | and `nil' if clean, to enable using as a hook function, as | ||
| 11 | suggested by Puneet Goel <puneet@computer.org> | ||
| 12 | |||
| 13 | * whitespace.el (whitespace-buffer): Fix a subtle bug that cleaned | ||
| 14 | up only if quiet was not set, even with whitespace-auto-cleanup set. | ||
| 15 | |||
| 16 | * whitespace.el (whitespace-mode-line): Now uses less modeline | ||
| 17 | real estate and shows whitespaces as W:<x>!<y> where <x> is any | ||
| 18 | type of whitespace which is present in the file, and <y> is any | ||
| 19 | type of whitespace whose check has been suppressed by setting | ||
| 20 | `whitespace-check-<whitespace-type>' to nil. | ||
| 21 | |||
| 22 | * whitespace.el (whitespace-unchecked-whitespaces): New function | ||
| 23 | to return the list of whitespaces for whom checks have been | ||
| 24 | suppressed. | ||
| 25 | |||
| 26 | * whitespace.el (whitespace-display-unchecked-whitespaces): | ||
| 27 | Renamed to `whitespace-update-modeline' to reflect its functionality. | ||
| 28 | |||
| 29 | 1999-09-30 Rajesh Vaidheeswarran <rv@dsmit.com> | ||
| 30 | |||
| 31 | * whitespace.el (whitespace-version): Update to 2.5 | ||
| 32 | |||
| 1 | 1999-10-30 Gerd Moellmann <gerd@gnu.org> | 33 | 1999-10-30 Gerd Moellmann <gerd@gnu.org> |
| 2 | 34 | ||
| 3 | * progmodes/compile.el (compilation-error-regexp-alist): | 35 | * progmodes/compile.el (compilation-error-regexp-alist): |
diff --git a/lisp/whitespace.el b/lisp/whitespace.el index 2e648f1b2c8..84e67eaeda2 100644 --- a/lisp/whitespace.el +++ b/lisp/whitespace.el | |||
| @@ -42,7 +42,7 @@ | |||
| 42 | (add-hook 'find-file-hooks 'whitespace-buffer) | 42 | (add-hook 'find-file-hooks 'whitespace-buffer) |
| 43 | (add-hook 'kill-buffer-hook 'whitespace-buffer) | 43 | (add-hook 'kill-buffer-hook 'whitespace-buffer) |
| 44 | 44 | ||
| 45 | (defvar whitespace-version "2.3" "Version of the whitespace library.") | 45 | (defvar whitespace-version "2.6" "Version of the whitespace library.") |
| 46 | ;; Find out what type of Emacs we are running in. | 46 | ;; Find out what type of Emacs we are running in. |
| 47 | (defvar whitespace-running-emacs (if (string-match "XEmacs\\|Lucid" | 47 | (defvar whitespace-running-emacs (if (string-match "XEmacs\\|Lucid" |
| 48 | emacs-version) nil t) | 48 | emacs-version) nil t) |
| @@ -59,6 +59,17 @@ visited by the buffers.") | |||
| 59 | (defvar whitespace-rescan-timer nil | 59 | (defvar whitespace-rescan-timer nil |
| 60 | "Timer object used to rescan the files in buffers that have been modified.") | 60 | "Timer object used to rescan the files in buffers that have been modified.") |
| 61 | 61 | ||
| 62 | ;; Tell Emacs about this new kind of minor mode | ||
| 63 | (defvar whitespace-mode nil | ||
| 64 | "Non-nil when Whitespace mode (a minor mode) is enabled.") | ||
| 65 | (make-variable-buffer-local 'whitespace-mode) | ||
| 66 | (put 'whitespace-mode 'permanent-local nil) | ||
| 67 | |||
| 68 | (defvar whitespace-mode-line nil | ||
| 69 | "String to display in the mode line for Whitespace mode.") | ||
| 70 | (make-variable-buffer-local 'whitespace-mode-line) | ||
| 71 | (put 'whitespace-mode-line 'permanent-local nil) | ||
| 72 | |||
| 62 | ;; For users of Emacs 19.x, defgroup and defcustom are not defined. | 73 | ;; For users of Emacs 19.x, defgroup and defcustom are not defined. |
| 63 | 74 | ||
| 64 | (eval-when-compile | 75 | (eval-when-compile |
| @@ -174,16 +185,10 @@ To disable timer scans, set this to zero." | |||
| 174 | :type 'integer | 185 | :type 'integer |
| 175 | :group 'whitespace) | 186 | :group 'whitespace) |
| 176 | 187 | ||
| 177 | ;; Tell Emacs about this new kind of minor mode | 188 | (defcustom whitespace-display-in-modeline t |
| 178 | (defvar whitespace-mode nil | 189 | "Display whitespace errors on the modeline." |
| 179 | "Non-nil when Whitespace mode (a minor mode) is enabled.") | 190 | :type 'boolean |
| 180 | (make-variable-buffer-local 'whitespace-mode) | 191 | :group 'whitespace) |
| 181 | (put 'whitespace-mode 'permanent-local nil) | ||
| 182 | |||
| 183 | (defvar whitespace-mode-line nil | ||
| 184 | "String to display in the mode line for Whitespace mode.") | ||
| 185 | (make-variable-buffer-local 'whitespace-mode-line) | ||
| 186 | (put 'whitespace-mode-line 'permanent-local nil) | ||
| 187 | 192 | ||
| 188 | (if (not (assoc 'whitespace-mode minor-mode-alist)) | 193 | (if (not (assoc 'whitespace-mode minor-mode-alist)) |
| 189 | (setq minor-mode-alist (cons '(whitespace-mode whitespace-mode-line) | 194 | (setq minor-mode-alist (cons '(whitespace-mode whitespace-mode-line) |
| @@ -212,91 +217,94 @@ and: | |||
| 212 | 1. the major mode is one of the whitespace-modes, or | 217 | 1. the major mode is one of the whitespace-modes, or |
| 213 | 2. `whitespace-buffer' was explicitly called with a prefix argument." | 218 | 2. `whitespace-buffer' was explicitly called with a prefix argument." |
| 214 | (interactive) | 219 | (interactive) |
| 215 | (whitespace-check-whitespace-mode current-prefix-arg) | 220 | (let ((whitespace-error nil)) |
| 216 | (if (and buffer-file-name (> (buffer-size) 0) whitespace-mode) | 221 | (whitespace-check-whitespace-mode current-prefix-arg) |
| 217 | (progn | 222 | (if (and buffer-file-name (> (buffer-size) 0) whitespace-mode) |
| 218 | (whitespace-check-buffer-list (buffer-name) buffer-file-name) | 223 | (progn |
| 219 | (whitespace-tickle-timer) | 224 | (whitespace-check-buffer-list (buffer-name) buffer-file-name) |
| 220 | (if whitespace-auto-cleanup | 225 | (whitespace-tickle-timer) |
| 221 | (if (and (not quiet) buffer-read-only) | 226 | (if whitespace-auto-cleanup |
| 222 | (message "Can't Cleanup: %s is read-only." (buffer-name)) | 227 | (if buffer-read-only |
| 223 | (whitespace-cleanup)) | 228 | (if (not quiet) |
| 224 | (let ((whitespace-leading (if whitespace-check-leading-whitespace | 229 | (message "Can't cleanup: %s is read-only" (buffer-name))) |
| 225 | (whitespace-buffer-leading) | 230 | (whitespace-cleanup)) |
| 226 | nil)) | 231 | (let ((whitespace-leading (if whitespace-check-leading-whitespace |
| 227 | (whitespace-trailing (if whitespace-check-trailing-whitespace | 232 | (whitespace-buffer-leading) |
| 228 | (whitespace-buffer-trailing) | 233 | nil)) |
| 229 | nil)) | 234 | (whitespace-trailing (if whitespace-check-trailing-whitespace |
| 230 | (whitespace-indent (if whitespace-check-indent-whitespace | 235 | (whitespace-buffer-trailing) |
| 231 | (whitespace-buffer-search | 236 | nil)) |
| 232 | whitespace-indent-regexp) | 237 | (whitespace-indent (if whitespace-check-indent-whitespace |
| 233 | nil)) | ||
| 234 | (whitespace-spacetab (if whitespace-check-spacetab-whitespace | ||
| 235 | (whitespace-buffer-search | 238 | (whitespace-buffer-search |
| 236 | whitespace-spacetab-regexp) | 239 | whitespace-indent-regexp) |
| 237 | nil)) | 240 | nil)) |
| 238 | (whitespace-ateol (if whitespace-check-ateol-whitespace | 241 | (whitespace-spacetab (if whitespace-check-spacetab-whitespace |
| 239 | (whitespace-buffer-search | 242 | (whitespace-buffer-search |
| 240 | whitespace-ateol-regexp) | 243 | whitespace-spacetab-regexp) |
| 241 | nil)) | 244 | nil)) |
| 242 | (whitespace-errmsg nil) | 245 | (whitespace-ateol (if whitespace-check-ateol-whitespace |
| 243 | (whitespace-error nil) | 246 | (whitespace-buffer-search |
| 244 | (whitespace-filename buffer-file-name) | 247 | whitespace-ateol-regexp) |
| 245 | (whitespace-this-modeline "")) | 248 | nil)) |
| 246 | 249 | (whitespace-errmsg nil) | |
| 247 | ;; Now let's complain if we found any of the above. | 250 | (whitespace-filename buffer-file-name) |
| 248 | (setq whitespace-error (or whitespace-leading whitespace-indent | 251 | (whitespace-this-modeline "")) |
| 249 | whitespace-spacetab whitespace-ateol | 252 | |
| 250 | whitespace-trailing)) | 253 | ;; Now let's complain if we found any of the above. |
| 251 | 254 | (setq whitespace-error (or whitespace-leading whitespace-indent | |
| 252 | (if whitespace-error | 255 | whitespace-spacetab whitespace-ateol |
| 253 | (progn | 256 | whitespace-trailing)) |
| 254 | (setq whitespace-errmsg | 257 | |
| 255 | (concat whitespace-filename " contains:\n" | 258 | (if whitespace-error |
| 256 | (if whitespace-leading "Leading whitespace\n") | ||
| 257 | (if whitespace-indent | ||
| 258 | (concat "Indentation whitespace" | ||
| 259 | whitespace-indent "\n")) | ||
| 260 | (if whitespace-spacetab | ||
| 261 | (concat "Space followed by Tab" | ||
| 262 | whitespace-spacetab "\n")) | ||
| 263 | (if whitespace-ateol | ||
| 264 | (concat "End-of-line whitespace" | ||
| 265 | whitespace-ateol "\n")) | ||
| 266 | (if whitespace-trailing | ||
| 267 | "Trailing whitespace.\n") | ||
| 268 | "\ntype " | ||
| 269 | "`whitespace-cleanup' to cleanup the file.")) | ||
| 270 | (setq whitespace-this-modeline | ||
| 271 | (concat (if whitespace-ateol "e") | ||
| 272 | (if whitespace-indent "i") | ||
| 273 | (if whitespace-leading "l") | ||
| 274 | (if whitespace-spacetab "s") | ||
| 275 | (if whitespace-trailing "t"))) | ||
| 276 | (setq whitespace-mode-line | ||
| 277 | (concat " W:" whitespace-this-modeline)) | ||
| 278 | (whitespace-force-mode-line-update))) | ||
| 279 | |||
| 280 | ;; Now test and set the whitespaces that are not checked. | ||
| 281 | (whitespace-display-unchecked-whitespaces | ||
| 282 | (if whitespace-error | ||
| 283 | (concat " W:" whitespace-this-modeline))) | ||
| 284 | (save-excursion | ||
| 285 | (get-buffer-create whitespace-errbuf) | ||
| 286 | (kill-buffer whitespace-errbuf) | ||
| 287 | (get-buffer-create whitespace-errbuf) | ||
| 288 | (set-buffer whitespace-errbuf) | ||
| 289 | (if whitespace-errmsg | ||
| 290 | (progn | 259 | (progn |
| 291 | (insert whitespace-errmsg) | 260 | (setq whitespace-errmsg |
| 292 | (if (not (or quiet whitespace-silent)) | 261 | (concat whitespace-filename " contains:\n" |
| 293 | (display-buffer whitespace-errbuf t)) | 262 | (if whitespace-leading |
| 294 | (if (not quiet) | 263 | "Leading whitespace\n") |
| 295 | (message "Whitespaces: [%s] in %s" | 264 | (if whitespace-indent |
| 296 | whitespace-this-modeline | 265 | (concat "Indentation whitespace" |
| 297 | whitespace-filename))) | 266 | whitespace-indent "\n")) |
| 298 | (if (not quiet) | 267 | (if whitespace-spacetab |
| 299 | (message "%s clean" whitespace-filename))))))))) | 268 | (concat "Space followed by Tab" |
| 269 | whitespace-spacetab "\n")) | ||
| 270 | (if whitespace-ateol | ||
| 271 | (concat "End-of-line whitespace" | ||
| 272 | whitespace-ateol "\n")) | ||
| 273 | (if whitespace-trailing | ||
| 274 | "Trailing whitespace\n") | ||
| 275 | "\ntype `M-x whitespace-cleanup' to " | ||
| 276 | "cleanup the file.")) | ||
| 277 | (setq whitespace-this-modeline | ||
| 278 | (concat (if whitespace-ateol "e") | ||
| 279 | (if whitespace-indent "i") | ||
| 280 | (if whitespace-leading "l") | ||
| 281 | (if whitespace-spacetab "s") | ||
| 282 | (if whitespace-trailing "t"))))) | ||
| 283 | (whitespace-update-modeline whitespace-this-modeline) | ||
| 284 | (save-excursion | ||
| 285 | (get-buffer-create whitespace-errbuf) | ||
| 286 | (kill-buffer whitespace-errbuf) | ||
| 287 | (get-buffer-create whitespace-errbuf) | ||
| 288 | (set-buffer whitespace-errbuf) | ||
| 289 | (if whitespace-errmsg | ||
| 290 | (progn | ||
| 291 | (insert whitespace-errmsg) | ||
| 292 | (if (not (or quiet whitespace-silent)) | ||
| 293 | (display-buffer whitespace-errbuf t)) | ||
| 294 | (if (not quiet) | ||
| 295 | (message "Whitespaces: [%s%s] in %s" | ||
| 296 | whitespace-this-modeline | ||
| 297 | (let ((whitespace-unchecked | ||
| 298 | (whitespace-unchecked-whitespaces))) | ||
| 299 | (if whitespace-unchecked | ||
| 300 | (concat "!" whitespace-unchecked) | ||
| 301 | "")) | ||
| 302 | whitespace-filename))) | ||
| 303 | (if (not quiet) | ||
| 304 | (message "%s clean" whitespace-filename)))))))) | ||
| 305 | (if whitespace-error | ||
| 306 | t | ||
| 307 | nil))) | ||
| 300 | 308 | ||
| 301 | ;;;###autoload | 309 | ;;;###autoload |
| 302 | (defun whitespace-region (s e) | 310 | (defun whitespace-region (s e) |
| @@ -360,9 +368,7 @@ whitespace problems." | |||
| 360 | (whitespace-cleanup) | 368 | (whitespace-cleanup) |
| 361 | (progn | 369 | (progn |
| 362 | (message "%s clean" buffer-file-name) | 370 | (message "%s clean" buffer-file-name) |
| 363 | (setq whitespace-mode-line nil) | 371 | (whitespace-update-modeline))) |
| 364 | (whitespace-force-mode-line-update) | ||
| 365 | (whitespace-display-unchecked-whitespaces))) | ||
| 366 | (setq tab-width whitespace-tabwith-saved)))) | 372 | (setq tab-width whitespace-tabwith-saved)))) |
| 367 | 373 | ||
| 368 | ;;;###autoload | 374 | ;;;###autoload |
| @@ -479,18 +485,35 @@ whitespace problems." | |||
| 479 | (delete-region (match-beginning 0) (point)) | 485 | (delete-region (match-beginning 0) (point)) |
| 480 | (indent-to column))))) | 486 | (indent-to column))))) |
| 481 | 487 | ||
| 482 | (defun whitespace-display-unchecked-whitespaces (&optional whitespace-str) | 488 | (defun whitespace-unchecked-whitespaces () |
| 483 | "Update modeline with whitespaces whose testing has been turned off." | 489 | "Return the list of whitespaces whose testing has been suppressed." |
| 484 | (let ((whitespace-this-modeline | 490 | (let ((whitespace-this-modeline |
| 485 | (concat (if (not whitespace-check-ateol-whitespace) "e") | 491 | (concat (if (not whitespace-check-ateol-whitespace) "e") |
| 486 | (if (not whitespace-check-indent-whitespace) "i") | 492 | (if (not whitespace-check-indent-whitespace) "i") |
| 487 | (if (not whitespace-check-leading-whitespace) "l") | 493 | (if (not whitespace-check-leading-whitespace) "l") |
| 488 | (if (not whitespace-check-spacetab-whitespace) "s") | 494 | (if (not whitespace-check-spacetab-whitespace) "s") |
| 489 | (if (not whitespace-check-trailing-whitespace) "t")))) | 495 | (if (not whitespace-check-trailing-whitespace) "t")))) |
| 490 | (setq whitespace-mode-line whitespace-str) | ||
| 491 | (if (not (equal whitespace-this-modeline "")) | 496 | (if (not (equal whitespace-this-modeline "")) |
| 492 | (setq whitespace-mode-line | 497 | whitespace-this-modeline |
| 493 | (concat whitespace-str " Woff:" whitespace-this-modeline))) | 498 | nil))) |
| 499 | |||
| 500 | (defun whitespace-update-modeline (&optional whitespace-err) | ||
| 501 | "Update modeline with whitespace errors and whitespaces whose testing has | ||
| 502 | been turned off." | ||
| 503 | (if whitespace-display-in-modeline | ||
| 504 | (setq whitespace-mode-line nil) | ||
| 505 | ;; Whitespace errors | ||
| 506 | (if (and whitespace-err (not (equal whitespace-err ""))) | ||
| 507 | (setq whitespace-mode-line whitespace-err)) | ||
| 508 | ;; Whitespace suppressed errors | ||
| 509 | (let ((whitespace-unchecked (whitespace-unchecked-whitespaces))) | ||
| 510 | (if whitespace-unchecked | ||
| 511 | (setq whitespace-mode-line | ||
| 512 | (concat whitespace-mode-line "!" whitespace-unchecked)))) | ||
| 513 | ;; Add the whitespace modeline prefix | ||
| 514 | (setq whitespace-mode-line (if whitespace-mode-line | ||
| 515 | (concat " W:" whitespace-mode-line) | ||
| 516 | nil)) | ||
| 494 | (whitespace-force-mode-line-update))) | 517 | (whitespace-force-mode-line-update))) |
| 495 | 518 | ||
| 496 | ;; Force mode line updation for different Emacs versions | 519 | ;; Force mode line updation for different Emacs versions |
| @@ -589,8 +612,8 @@ of whitespace problems that commonly exist in source code. | |||
| 589 | 612 | ||
| 590 | Whitespace errors are reported in a buffer, and on the modeline. | 613 | Whitespace errors are reported in a buffer, and on the modeline. |
| 591 | 614 | ||
| 592 | Modeline will show a W:<x> to denote a particular type of whitespace, where | 615 | Modeline will show a W:<x>!<y> to denote a particular type of whitespace, |
| 593 | `x' can be one (or more) of: | 616 | where `x' and `y' can be one (or more) of: |
| 594 | 617 | ||
| 595 | e - End-of-Line whitespace. | 618 | e - End-of-Line whitespace. |
| 596 | i - Indentation whitespace. | 619 | i - Indentation whitespace. |
| @@ -599,7 +622,7 @@ s - Space followed by Tab. | |||
| 599 | t - Trailing whitespace. | 622 | t - Trailing whitespace. |
| 600 | 623 | ||
| 601 | If any of the whitespace checks is turned off, the modeline will display a | 624 | If any of the whitespace checks is turned off, the modeline will display a |
| 602 | Woff:<x>, where `x' can be one (or more) of the above. | 625 | !<y>. |
| 603 | 626 | ||
| 604 | (since (3) is the most controversial one, here is the rationale: Most | 627 | (since (3) is the most controversial one, here is the rationale: Most |
| 605 | terminal drivers and printer drivers have TAB configured or even | 628 | terminal drivers and printer drivers have TAB configured or even |