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: Proposal: diff-remove-trailing-blanks Date: Sat, 26 Apr 2008 16:59:34 +0200 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1209222023 9623 80.91.229.12 (26 Apr 2008 15:00:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 26 Apr 2008 15:00:23 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Apr 26 17:00:58 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 1JpltQ-0003zD-NA for ged-emacs-devel@m.gmane.org; Sat, 26 Apr 2008 17:00:49 +0200 Original-Received: from localhost ([127.0.0.1]:57925 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jplse-0005mY-VM for ged-emacs-devel@m.gmane.org; Sat, 26 Apr 2008 11:00:00 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JplsY-0005id-Um for emacs-devel@gnu.org; Sat, 26 Apr 2008 10:59:54 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JplsW-0005eR-OT for emacs-devel@gnu.org; Sat, 26 Apr 2008 10:59:54 -0400 Original-Received: from [199.232.76.173] (port=54094 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JplsW-0005eC-Gn for emacs-devel@gnu.org; Sat, 26 Apr 2008 10:59:52 -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 1JplsV-0008Is-VV for emacs-devel@gnu.org; Sat, 26 Apr 2008 10:59:52 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JplsO-0004Fs-AG for emacs-devel@gnu.org; Sat, 26 Apr 2008 14:59:44 +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 ; Sat, 26 Apr 2008 14:59:44 +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 ; Sat, 26 Apr 2008 14:59:44 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 43 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:z8MrgQSiVqW7eTZClIk6uOS8w4M= 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:95981 Archived-At: Some time ago Steffan suggested that this function could be a worth addition to diff-mode. If this is ok, I need to sign the copyright papers. (defun diff-remove-trailing-blanks () "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." (interactive) (goto-char (point-min)) ;; We assume that the diff header has no trailing whitespace. (setq modified-buffers nil) (setq white-positions nil) (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 line-offset (set-buffer buf) (save-excursion (goto-char (+ (car pos) (cdr src))) (beginning-of-line) (when (re-search-forward "\\([ \t]+\\)$" (line-end-position) t) (when (not (member buf modified-buffers)) (push buf modified-buffers)) (goto-char (match-end 0)) (push (point-marker) white-positions) (goto-char (match-beginning 0)) (push (point-marker) white-positions) (push buf white-positions))))))) (while white-positions (save-excursion (set-buffer (pop white-positions)) (delete-region (pop white-positions) (pop white-positions)))) (if modified-buffers (let ((msg "Deleted new trailing whitespace from:")) (dolist (f modified-buffers) (setq msg (concat msg " `" (buffer-name f) "'"))) (message "%s" msg)) (message "No fixes needed.")))