;;; whitespace.el --- warn about and clean bogus whitespaces in the file
;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
-;; 2005 Free Software Foundation, Inc.
+;; 2005, 2006 Free Software Foundation, Inc.
;; Author: Rajesh Vaidheeswarran <rv@gnu.org>
;; Keywords: convenience
(if buffer-read-only
(if (not quiet)
(message "Can't cleanup: %s is read-only" (buffer-name)))
- (whitespace-cleanup))
+ (whitespace-cleanup-internal))
(let ((whitespace-leading (if whitespace-check-buffer-leading
(whitespace-buffer-leading)
nil))
;;;###autoload
(defun whitespace-cleanup ()
"Cleanup the five different kinds of whitespace problems.
-
-Use \\[describe-function] whitespace-describe to read a summary of the
-whitespace problems."
+It normally applies to the whole buffer, but in Transient Mark mode
+when the mark is active it applies to the region.
+See `whitespace-buffer' docstring for a summary of the problems."
(interactive)
+ (if (and transient-mark-mode mark-active)
+ (whitespace-cleanup-region (region-beginning) (region-end))
+ (whitespace-cleanup-internal)))
+
+(defun whitespace-cleanup-internal (&optional region-only)
;; If this buffer really contains a file, then run, else quit.
(whitespace-check-whitespace-mode current-prefix-arg)
(if (and buffer-file-name whitespace-mode)
;; Call this recursively till everything is taken care of
(if whitespace-any
- (whitespace-cleanup)
+ (whitespace-cleanup-internal)
+ ;; if we are done, talk to the user
(progn
- (if (not whitespace-silent)
- (message "%s clean" buffer-file-name))
+ (unless whitespace-silent
+ (if region-only
+ (message "The region is now clean")
+ (message "%s is now clean" buffer-file-name)))
(whitespace-update-modeline)))
(setq tab-width whitespace-tabwith-saved))))
(save-excursion
(save-restriction
(narrow-to-region s e)
- (whitespace-cleanup))
+ (whitespace-cleanup-internal t))
(whitespace-buffer t)))
(defun whitespace-buffer-leading ()
(if whitespace-auto-cleanup
(progn
;;(message "cleaning up whitespace in %s" bufname)
- (whitespace-cleanup))
+ (whitespace-cleanup-internal))
(progn
;;(message "whitespace-buffer %s." (buffer-name))
(whitespace-buffer t))))
(interactive)
(let ((werr nil))
(if whitespace-auto-cleanup
- (whitespace-cleanup)
+ (whitespace-cleanup-internal)
(setq werr (whitespace-buffer)))
(if (and whitespace-abort-on-error werr)
(error (concat "Abort write due to whitespaces in "