unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Yoni Rabkin Katzenell <yoni-r@actcom.com>
Subject: whitespace-cleanup from /etc/TODO
Date: Sun, 13 Aug 2006 21:45:46 +0300	[thread overview]
Message-ID: <87zme8tqxx.fsf@actcom.com> (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"

             reply	other threads:[~2006-08-13 18:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-13 18:45 Yoni Rabkin Katzenell [this message]
2006-08-14  5:43 ` whitespace-cleanup from /etc/TODO 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zme8tqxx.fsf@actcom.com \
    --to=yoni-r@actcom.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).