From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?windows-1252?Q?=D3scar_Fuentes?= Newsgroups: gmane.emacs.devel Subject: Re: show whitespace problems by default in diff-mode Date: Fri, 17 Jul 2009 02:03:38 +0200 Message-ID: <871vog89b9.fsf@telefonica.net> References: <200907162214.n6GMEo5o025706@godzilla.ics.uci.edu> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1247789059 18475 80.91.229.12 (17 Jul 2009 00:04:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 17 Jul 2009 00:04:19 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 17 02:04:12 2009 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 1MRavr-0008PH-OI for ged-emacs-devel@m.gmane.org; Fri, 17 Jul 2009 02:04:12 +0200 Original-Received: from localhost ([127.0.0.1]:50017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MRavr-0004O3-3z for ged-emacs-devel@m.gmane.org; Thu, 16 Jul 2009 20:04:11 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MRavm-0004Ny-IS for emacs-devel@gnu.org; Thu, 16 Jul 2009 20:04:06 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MRavi-0004NI-3g for emacs-devel@gnu.org; Thu, 16 Jul 2009 20:04:06 -0400 Original-Received: from [199.232.76.173] (port=44082 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MRavh-0004NF-Vu for emacs-devel@gnu.org; Thu, 16 Jul 2009 20:04:02 -0400 Original-Received: from main.gmane.org ([80.91.229.2]:37314 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 1MRavh-0006rt-Cf for emacs-devel@gnu.org; Thu, 16 Jul 2009 20:04:01 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MRavc-0002BM-Ey for emacs-devel@gnu.org; Fri, 17 Jul 2009 00:03:56 +0000 Original-Received: from 184.red-83-53-125.dynamicip.rima-tde.net ([83.53.125.184]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 17 Jul 2009 00:03:56 +0000 Original-Received: from ofv by 184.red-83-53-125.dynamicip.rima-tde.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 17 Jul 2009 00:03:56 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 64 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 184.red-83-53-125.dynamicip.rima-tde.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (gnu/linux) Cancel-Lock: sha1:xN4OXuzIrR4NIuMzg4PZnT6Rqzo= X-detected-operating-system: by monty-python.gnu.org: GNU/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:112583 Archived-At: Dan Nicolaescu writes: > diff-mode is set up to show trailing whitespace problems, but it's not > doing it by default, to enable this one has to do: > > (add-hook 'diff-mode-hook 'whitespace-mode) > > Vinicius also posted a patch to edit files to clean the trailing > whitespace problems based on the diff. > > Why not turn on whitespace-mode by default in diff-mode? It makes > spotting whitespace problems very easy, and will make it also easy to > fix. Time ago I posted a patch for removing new trailing whitespace from files based on their diffs. Vinicius suggested several improvements, so maybe this code is the one that you mention. Aparently the maintainers forgot about it and never was incorporated to Emacs. Just in case, here is the version I'm using now: (defun diff-delete-new-trailing-whitespace () "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 "^[+!>]" (point-max) t) (save-excursion (destructuring-bind (buf line-offset pos src dst &optional switched) (diff-find-source-location t t) (when line-offset (with-current-buffer buf (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 (with-current-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."))) It has a bug: if the last chunk of the diff does not end with a newline (because the original file lacks it) `diff-find-source-location' returns `line-offset' as nil and hence no whitespace is cleaned. No idea why. -- Óscar