From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Vinicius Jose Latorre Newsgroups: gmane.emacs.devel Subject: Re: Proposal: diff-remove-trailing-blanks Date: Sat, 26 Apr 2008 23:59:37 -0300 Message-ID: <4813EC19.2060901@ig.com.br> 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=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1209265238 23264 80.91.229.12 (27 Apr 2008 03:00:38 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 27 Apr 2008 03:00:38 +0000 (UTC) Cc: emacs-devel@gnu.org To: =?ISO-8859-1?Q?=D3scar_Fuentes?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Apr 27 05:01:13 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 1Jpx8Z-0003vz-31 for ged-emacs-devel@m.gmane.org; Sun, 27 Apr 2008 05:01:11 +0200 Original-Received: from localhost ([127.0.0.1]:60704 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jpx7s-0004wA-Po for ged-emacs-devel@m.gmane.org; Sat, 26 Apr 2008 23:00:28 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jpx7p-0004vo-3b for emacs-devel@gnu.org; Sat, 26 Apr 2008 23:00:25 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jpx7n-0004vE-AF for emacs-devel@gnu.org; Sat, 26 Apr 2008 23:00:24 -0400 Original-Received: from [199.232.76.173] (port=57873 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jpx7n-0004v8-4O for emacs-devel@gnu.org; Sat, 26 Apr 2008 23:00:23 -0400 Original-Received: from yw-out-1718.google.com ([74.125.46.157]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Jpx7m-0002zn-PF for emacs-devel@gnu.org; Sat, 26 Apr 2008 23:00:22 -0400 Original-Received: by yw-out-1718.google.com with SMTP id 9so3251823ywk.66 for ; Sat, 26 Apr 2008 20:00:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; bh=QdGE8nyl2q4HaNt7jF/P+A2Ca0nLO7nKYT+HNhJE+AI=; b=IxWQQTGzxioe3cVjMT8Cp2iiTvM0SoFlyRyEPkzj8G5c2XxtwQ0CIDzpzW1gVm4Jxdmntiw6ykBDvpnQJZcr2PckQk3GeO6Gijh1pCttiizE6iR3xJQuzm+nV5QpH41rhqnW/Y8NrlQaCTEzpobXp33SLBYGHQXHlFIvame7i1I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject:references:in-reply-to:content-type:content-transfer-encoding:sender; b=tervS+U9WRzu0hup/nqPRwL7kpXsHoi2rNZNNwc12Mnwy5h4e5290a4z0rYXYC5oXbsLEE3ELdndtFHfnJ0NOLY8w4GJIUp3AOFoN2oBrAvvpzuD0GMI61QDXIbhTSieCtFm627vEBKY0b1bNiv2CMHomQIo1nFXV7zAebiOusk= Original-Received: by 10.150.82.27 with SMTP id f27mr340717ybb.131.1209265214050; Sat, 26 Apr 2008 20:00:14 -0700 (PDT) Original-Received: from ?192.168.0.100? ( [200.208.45.144]) by mx.google.com with ESMTPS id 6sm7967605ywn.4.2008.04.26.20.00.10 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 26 Apr 2008 20:00:12 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.13) Gecko/20080313 SeaMonkey/1.1.9 In-Reply-To: <4813E542.10802@ig.com.br> X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) 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:95997 Archived-At: >>> Hummm, I'm confused, the original mail said: >>> >>> "When on a buffer that contains a diff, inspects the >>> differences and removes trailing whitespace (spaces, tabs) from >>> the lines modified or introduced by this diff. 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." >>> >>> >>> So, I thought it was to remove trailing whitespaces from a diff buffer. >> >> The "removing" part is accomplished by my function. We are discussing >> the "displaying" part, which shows to the user that there is trailing >> whitespace to be removed. >> >> But I'm afraid I confused things out relating `show-trailing-whitespace' >> to whitespace-mode'. > > 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.")))) A better implementation of function above: (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) (save-excursion ;; We assume that the diff header has no trailing whitespace. (let ((whitespace-style '(trailing)) modified-buffers) (goto-char (point-min)) (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) (when (and line-offset (not (member buf modified-buffers))) (set-buffer buf) (when (re-search-forward "\\([ \t]+\\)$" (point-max) t) (push buf modified-buffers) (whitespace-cleanup)))))) ; cleanup trailing blanks in buf (if modified-buffers (progn (whitespace-mode) ; display trailing blanks in diff buffer (message "Deleted trailing whitespace from: %s" (mapconcat #'(lambda (buf) (format "`%s'" (buffer-name buf))) modified-buffers " "))) (message "No fixes needed.")))))