From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?iso-8859-1?Q?=D3scar_Fuentes?= Newsgroups: gmane.emacs.devel Subject: Re: Proposal: diff-remove-trailing-blanks Date: Sun, 27 Apr 2008 06:04:08 +0200 Message-ID: <3ap89c5j.fsf@telefonica.net> References: <200804261845.m3QIixvX026773@sallyv1.ics.uci.edu> <4813879E.8030700@ig.com.br> <4813A244.4050908@ig.com.br> <8wz09so0.fsf@telefonica.net> <4813E542.10802@ig.com.br> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1209269120 30287 80.91.229.12 (27 Apr 2008 04:05:20 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 27 Apr 2008 04:05:20 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Apr 27 06:05:54 2008 connect(): Connection refused Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Jpy8X-0006OR-Dt for ged-emacs-devel@m.gmane.org; Sun, 27 Apr 2008 06:05:32 +0200 Original-Received: from localhost ([127.0.0.1]:52720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jpy7p-0002qa-Pb for ged-emacs-devel@m.gmane.org; Sun, 27 Apr 2008 00:04:29 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jpy7m-0002qD-6w for emacs-devel@gnu.org; Sun, 27 Apr 2008 00:04:26 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jpy7k-0002q1-Es for emacs-devel@gnu.org; Sun, 27 Apr 2008 00:04:25 -0400 Original-Received: from [199.232.76.173] (port=36613 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jpy7k-0002py-DH for emacs-devel@gnu.org; Sun, 27 Apr 2008 00:04:24 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Jpy7j-0004uc-QZ for emacs-devel@gnu.org; Sun, 27 Apr 2008 00:04:24 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1Jpy7d-0001cN-Ub for emacs-devel@gnu.org; Sun, 27 Apr 2008 04:04:17 +0000 Original-Received: from 112.red-81-38-8.dynamicip.rima-tde.net ([81.38.8.112]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 27 Apr 2008 04:04:17 +0000 Original-Received: from ofv by 112.red-81-38-8.dynamicip.rima-tde.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 27 Apr 2008 04:04:17 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 76 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 112.red-81-38-8.dynamicip.rima-tde.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (windows-nt) Cancel-Lock: sha1:wOmv0rb2NNkABVC4wKuvEmSecuw= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:95999 Archived-At: Vinicius Jose Latorre writes: > Well, both parts, the "removing" part and the "displaying" part, > related with trailing whitespaces can be done by whitespace-mode. > > Does the following function do the job? > > (defun diff-remove-trailing-blanks () > "When on a buffer that contains a diff, inspects the > differences and removes trailing whitespace (spaces, tabs). > Shows a message with the name of the altered buffers, which are > unsaved. If a file referenced on the diff has no buffer and > needs to be fixed, a buffer visiting that file is created." > (interactive) > (goto-char (point-min)) > ;; We assume that the diff header has no trailing whitespace. > (let (modified-buffers) > (while (re-search-forward "^[+!>].*[ \t]+$" (point-max) t) > (save-excursion > (destructuring-bind (buf line-offset pos src dst &optional switched) > (diff-find-source-location t t) > (unless (member buf modified-buffers) > (when line-offset > (set-buffer buf) > (when (re-search-forward "\\([ \t]+\\)$" (point-max) t) > (push buf modified-buffers) > (let ((whitespace-style '(trailing))) > (whitespace-cleanup)))))))) ; cleanup trailing blanks in buf > (if modified-buffers > (let ((bufs (mapconcat #(lambda (buf) > (format "`%s'" (buffer-name buf))) > modified-buffers > " ")) > (whitespace-style '(trailing))) > (whitespace-mode) ; display trailing blanks in diff > buffer > (message "Deleted trailing whitespace from: %s" bufs)) > (message "No fixes needed.")))) > Your function removes trailing whitespace from the buffer, while my function removes it only from the lines that were added or modified. The motivation of my proposed function is this: when working with source code that may contain trailing whitespace, maybe you don't want to create "noise" with changes that just fixes whitespace, but you wish to avoid making things worse introducing new trailing whitespace. My function does this: before committing your changes, do a diff of the modified files, apply the function on the diff buffer, and all trailing whitespace you introduced is gone, leaving the rest of the code intact. >>> What are the relevant parts of the buffer? >> >> Those that correspond to added or modified lines in the diff. > > So, should lines beginning with +, - and ! have a face to display the > change? The topic Dan Nicolaescu introduced was how to make evident that the changes introduce new trailing whitespace. For this, we both use `show-trailing-whitespace', but this has the inconvenience that shows trailing whitespace not only for the changed lines, but for the rest of the diff too, which is a bit annoying. As it is safe to apply `diff-remove-trailing-blanks' to a diff that does not introduce new trailing whitespace, what I do is this: before I commit my changes, I do a diff comprising all the involved source files (which is easy to do with PCL-CVS or psvn, maybe with vc-dired too), apply `diff-remove-trailing-blanks' to the diff buffer, do a C-x s if it fixed whitespace on some buffer, and commit. Hope this clarifies the confusion I caused with my reference to whitespace-mode. -- Oscar