(defgroup reftex): Update home page url-link.
[bpt/emacs.git] / lisp / whitespace.el
index 7f3cbd9..bb82927 100644 (file)
@@ -430,7 +430,7 @@ and:
              (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))
@@ -518,8 +518,15 @@ and:
 ;;;###autoload
 (defun whitespace-cleanup ()
   "Cleanup the five different kinds of 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)
@@ -563,10 +570,13 @@ See `whitespace-buffer' docstring for a summary of the problems."
 
        ;; 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))))
 
@@ -577,7 +587,7 @@ See `whitespace-buffer' docstring for a summary of the problems."
   (save-excursion
     (save-restriction
       (narrow-to-region s e)
-      (whitespace-cleanup))
+      (whitespace-cleanup-internal t))
     (whitespace-buffer t)))
 
 (defun whitespace-buffer-leading ()
@@ -760,7 +770,7 @@ If timer is not set, then set it to scan the files in
                    (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))))
@@ -806,7 +816,7 @@ This is meant to be added buffer-locally to `write-file-functions'."
   (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 "