emacs-devel
[Top][All Lists]
Advanced

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

Re: whitespace-cleanup from /etc/TODO


From: Yoni Rabkin Katzenell
Subject: Re: whitespace-cleanup from /etc/TODO
Date: Wed, 16 Aug 2006 13:51:26 +0300
User-agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.50 (gnu/linux)

"Stuart D. Herring" <address@hidden> writes:

>> + (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))))
>
> This presumably works, but it's the long way around.  Just add an argument
> REGION to `whitespace-cleanup-internal' instead of defining a new
> top-level symbol.  Then invoke it from `whitespace-cleanup-region' with
> that argument non-nil.  If there's some reason that doesn't work, at least
> `let'-bind the variable rather than just setting it.

You are right. Here is a patch to solve the problem as you suggest:

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.000000000 +0300
--- /home/yrk/devel/sandbox/emacs-hacking/whitespace.el 2006-08-15 
21:27:15.066569112 +0300
***************
*** 524,530 ****
        (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.
    (whitespace-check-whitespace-mode current-prefix-arg)
    (if (and buffer-file-name whitespace-mode)
--- 524,530 ----
        (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)
***************
*** 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))))
  
--- 569,580 ----
        ;; 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 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))))
  
***************
*** 582,588 ****
    (save-excursion
      (save-restriction
        (narrow-to-region s e)
!       (whitespace-cleanup-internal))
      (whitespace-buffer t)))
  
  (defun whitespace-buffer-leading ()
--- 585,591 ----
    (save-excursion
      (save-restriction
        (narrow-to-region s e)
!       (whitespace-cleanup-internal t))
      (whitespace-buffer t)))
  
  (defun whitespace-buffer-leading ()

Diff finished.  Tue Aug 15 21:30:17 2006

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





reply via email to

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