emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

make whitespace-cleanup work in a region if the region is active


From: Dan Nicolaescu
Subject: make whitespace-cleanup work in a region if the region is active
Date: Sat, 06 May 2006 10:45:25 -0700

It would be nice if whitespace-cleanup only cleaned up the region iff
the region was active. (like replace-string, undo, etc etc do)

It seems that it is quite trivial to implement this. Just move the
bulk of the whitespace-cleanup function to a new function and call it
if the region is not active, otherwise call
whitespace-cleanup-region. 

Should I check this in? 


*** whitespace.el       14 Feb 2006 10:12:41 -0800      1.43
--- whitespace.el       06 May 2006 09:58:08 -0700      
***************
*** 430,436 ****
              (if buffer-read-only
                  (if (not quiet)
                      (message "Can't cleanup: %s is read-only" (buffer-name)))
!               (whitespace-cleanup))
            (let ((whitespace-leading (if whitespace-check-buffer-leading
                                          (whitespace-buffer-leading)
                                        nil))
--- 430,436 ----
              (if buffer-read-only
                  (if (not quiet)
                      (message "Can't cleanup: %s is read-only" (buffer-name)))
!               (whitespace-cleanup-1))
            (let ((whitespace-leading (if whitespace-check-buffer-leading
                                          (whitespace-buffer-leading)
                                        nil))
***************
*** 520,525 ****
--- 520,531 ----
    "Cleanup the five different kinds of whitespace problems.
  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-1)))
+ 
+ 
+ (defun whitespace-cleanup-1 ()
    ;; 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,569 ****
  
        ;; Call this recursively till everything is taken care of
        (if whitespace-any
!           (whitespace-cleanup)
          (progn
            (if (not whitespace-silent)
                (message "%s clean" buffer-file-name))
--- 569,575 ----
  
        ;; Call this recursively till everything is taken care of
        (if whitespace-any
!           (whitespace-cleanup-1)
          (progn
            (if (not whitespace-silent)
                (message "%s clean" buffer-file-name))
***************
*** 577,583 ****
    (save-excursion
      (save-restriction
        (narrow-to-region s e)
!       (whitespace-cleanup))
      (whitespace-buffer t)))
  
  (defun whitespace-buffer-leading ()
--- 583,589 ----
    (save-excursion
      (save-restriction
        (narrow-to-region s e)
!       (whitespace-cleanup-1))
      (whitespace-buffer t)))
  
  (defun whitespace-buffer-leading ()
***************
*** 760,766 ****
                    (if whitespace-auto-cleanup
                        (progn
                          ;;(message "cleaning up whitespace in %s" bufname)
!                         (whitespace-cleanup))
                      (progn
                        ;;(message "whitespace-buffer %s." (buffer-name))
                        (whitespace-buffer t))))
--- 766,772 ----
                    (if whitespace-auto-cleanup
                        (progn
                          ;;(message "cleaning up whitespace in %s" bufname)
!                         (whitespace-cleanup-1))
                      (progn
                        ;;(message "whitespace-buffer %s." (buffer-name))
                        (whitespace-buffer t))))
***************
*** 806,812 ****
    (interactive)
    (let ((werr nil))
      (if whitespace-auto-cleanup
!       (whitespace-cleanup)
        (setq werr (whitespace-buffer)))
      (if (and whitespace-abort-on-error werr)
        (error (concat "Abort write due to whitespaces in "
--- 812,818 ----
    (interactive)
    (let ((werr nil))
      (if whitespace-auto-cleanup
!       (whitespace-cleanup-1)
        (setq werr (whitespace-buffer)))
      (if (and whitespace-abort-on-error werr)
        (error (concat "Abort write due to whitespaces in "




reply via email to

[Prev in Thread] Current Thread [Next in Thread]