emacs-devel
[Top][All Lists]
Advanced

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

whitespace-cleanup from /etc/TODO


From: Yoni Rabkin Katzenell
Subject: whitespace-cleanup from /etc/TODO
Date: Sun, 13 Aug 2006 21:45:46 +0300
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux)

Hello, I'm running GNU Emacs 22.0.50.1 (i686-pc-linux-gnu, X toolkit,
 Xaw3d scroll bars) of 2006-07-23 on ardbeg.

In /etc/TODO there is the following: "** whitespace-cleanup should work
only on the region if the region is active.".

Looking at whitespace.el I see that `whitespace-cleanup' will work on
the region if (and transient-mark-mode mark-active), otherwise it will
work on the entire buffer. I don't know if this is what you mean by
"...only on the region if the region is active", but it seems to be
already doing the correct thing.

The confusing bit is that `whitespace-cleanup' will always print the
following message when done:

(if (not whitespace-silent)
    (message "%s clean" buffer-file-name))

So if you judge according to the message, you can easily misunderstand
that `whitespace-cleanup' is unconditionally operating on the entire
buffer.

The following trivial patch will print an appropriate message when
`whitespace-cleanup' is run on a region, otherwise it will print that
`whitespace-cleanup' has run on the entire buffer.

diff -c /home/yrk/devel/sandbox/emacs-hacking/whitespace-original.el 
/home/yrk/devel/sandbox/emacs-hacking/whitespace.el
*** /home/yrk/devel/sandbox/emacs-hacking/whitespace-original.el        
2006-08-13 21:23:58.542642560 +0300
--- /home/yrk/devel/sandbox/emacs-hacking/whitespace.el 2006-08-13 
21:12:38.085087832 +0300
***************
*** 139,144 ****
--- 139,148 ----
  (make-variable-buffer-local 'whitespace-highlighted-space)
  (put 'whitespace-highlighted-space 'permanent-local nil)
  
+ (defvar whitespace-region-only nil
+   "Keep track of whether whitespace has been run on a region or buffer.")
+ (make-variable-buffer-local 'whitespace-region-only)
+ 
  ;; For flavors of Emacs which don't define `defgroup' and `defcustom'.
  (eval-when-compile
    (if (not (fboundp 'defgroup))
***************
*** 522,528 ****
    (interactive)
    (if (and transient-mark-mode mark-active)
        (whitespace-cleanup-region (region-beginning) (region-end))
!     (whitespace-cleanup-internal)))
  
  (defun whitespace-cleanup-internal ()
    ;; If this buffer really contains a file, then run, else quit.
--- 526,534 ----
    (interactive)
    (if (and transient-mark-mode mark-active)
        (whitespace-cleanup-region (region-beginning) (region-end))
!     (progn
!       (setq whitespace-region-only nil)
!       (whitespace-cleanup-internal))))
  
  (defun whitespace-cleanup-internal ()
    ;; If this buffer really contains a file, then run, else quit.
***************
*** 569,577 ****
        ;; Call this recursively till everything is taken care of
        (if whitespace-any
            (whitespace-cleanup-internal)
          (progn
!           (if (not whitespace-silent)
!               (message "%s clean" buffer-file-name))
            (whitespace-update-modeline)))
        (setq tab-width whitespace-tabwith-saved))))
  
--- 575,586 ----
        ;; Call this recursively till everything is taken care of
        (if whitespace-any
            (whitespace-cleanup-internal)
+         ;; if we are done, talk to the user
          (progn
!           (unless whitespace-silent
!             (if whitespace-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))))
  
***************
*** 579,584 ****
--- 588,594 ----
  (defun whitespace-cleanup-region (s e)
    "Whitespace cleanup on the region."
    (interactive "r")
+   (setq whitespace-region-only t)
    (save-excursion
      (save-restriction
        (narrow-to-region s e)

Diff finished.  Sun Aug 13 21:24:34 2006

-- 
   "Cut your own wood and it will warm you twice"




reply via email to

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