unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* whitespace-cleanup from /etc/TODO
@ 2006-08-13 18:45 Yoni Rabkin Katzenell
  2006-08-14  5:43 ` Adrian Aichner
  2006-08-14 22:53 ` Stuart D. Herring
  0 siblings, 2 replies; 5+ messages in thread
From: Yoni Rabkin Katzenell @ 2006-08-13 18:45 UTC (permalink / raw)



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"

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-08-16 10:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-13 18:45 whitespace-cleanup from /etc/TODO Yoni Rabkin Katzenell
2006-08-14  5:43 ` Adrian Aichner
2006-08-14  8:04   ` Yoni Rabkin Katzenell
2006-08-14 22:53 ` Stuart D. Herring
2006-08-16 10:51   ` Yoni Rabkin Katzenell

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).