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: Fri, 09 May 2008 21:45:44 -0300 Message-ID: <4824F038.9090105@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> <3ap89c5j.fsf@telefonica.net> <48146DF3.3090706@ig.com.br> <48147BC0.6080406@ig.com.br> <4814B81C.8030407@ig.com.br> <4819101D.5010004@ig.com.br> <4820F711.2060502@ig.com.br> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------010602010605000105070702" X-Trace: ger.gmane.org 1210380385 4161 80.91.229.12 (10 May 2008 00:46:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 10 May 2008 00:46:25 +0000 (UTC) Cc: =?ISO-8859-1?Q?=D3scar_Fuentes?= , "GNU Emacs \(devel\)" To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 10 02:47:00 2008 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 1JudEo-000510-UX for ged-emacs-devel@m.gmane.org; Sat, 10 May 2008 02:46:59 +0200 Original-Received: from localhost ([127.0.0.1]:40542 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JudE6-0007iv-Ki for ged-emacs-devel@m.gmane.org; Fri, 09 May 2008 20:46:14 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JudE2-0007iq-Pv for emacs-devel@gnu.org; Fri, 09 May 2008 20:46:10 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JudDz-0007ie-RB for emacs-devel@gnu.org; Fri, 09 May 2008 20:46:09 -0400 Original-Received: from [199.232.76.173] (port=41384 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JudDz-0007ib-M7 for emacs-devel@gnu.org; Fri, 09 May 2008 20:46:07 -0400 Original-Received: from yw-out-1718.google.com ([74.125.46.156]:21099) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JudDz-0006ve-7e for emacs-devel@gnu.org; Fri, 09 May 2008 20:46:07 -0400 Original-Received: by yw-out-1718.google.com with SMTP id 9so1003060ywk.66 for ; Fri, 09 May 2008 17:45:53 -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:sender; bh=mzLzGBP/h+yyTPL0Gn+iSthjh36IXRl8dG4X9rT9JZQ=; b=RY8tCXurl9qA8uzXtmmGxwIclkEZ+KJRUNYUzY08km8Xzjklp5+p7DQ2Ip43RuoxBt6gmZvNTWC0ImeVMjzgifbfAAxU8DixBXgPKZ0QuciecfTJtNVzWuP8by29BByauCUbs2OpkEzEt6qBYgfC/Os1TIZBRviWDbO3F6P1zlc= 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:sender; b=VATI3fLq8UExbhN3fgRKqjRF+UMVcCZfkuVG5RCyWG8/T663VGxC1UNdAmGOHgY4kPlDie997fsv0oisVa+TZTmdSQKa2FGfmRyokypNfjsMzEolaibBDCLO1VgYeWv/LTreVyiA8QLinLAFIjQCwFVBOwwxb8xIe16gKq9cdYs= Original-Received: by 10.150.83.41 with SMTP id g41mr5541344ybb.193.1210380353684; Fri, 09 May 2008 17:45:53 -0700 (PDT) Original-Received: from ?192.168.0.100? ( [201.82.10.179]) by mx.google.com with ESMTPS id 30sm3309656yxk.4.2008.05.09.17.45.50 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 09 May 2008 17:45:52 -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: 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:96915 Archived-At: This is a multi-part message in MIME format. --------------010602010605000105070702 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit >>>> Well, can I install diff-kill-trailing-whitespace >>>> and diff-show-trailing-whitespace into diff-mode? >>>> >>> I haven't had time to look at the code, but assuming it's clean enough, >>> I don't see any problem with it, >>> >> Ok, shouldn't Óscar Fuentes sign papers before >> code installation? >> > > I think so. But I haven't kept track of this thread enough to know > which part of the code is his and which is yours. > Attached there are the following files: original.el --- contains the original proposal from Óscar Fuentes modified.el --- contains the modified proposal by me --------------010602010605000105070702 Content-Type: text/plain; name="original.el" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="original.el" (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."))) --------------010602010605000105070702 Content-Type: text/plain; name="modified.el" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="modified.el" (defun diff-kill-trailing-blanks () "Inspect the current diff and remove trailing whitespace (spaces, tabs). That is, it removes trailing whitespaces 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) (save-excursion ;; We assume that the diff header has no trailing whitespace. (let (modified-buffers white-positions) (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 line-offset (save-excursion (set-buffer buf) (goto-char (+ (car pos) (cdr src))) (beginning-of-line) (when (re-search-forward "\\([ \t]+\\)$" (line-end-position) t) (unless (member buf modified-buffers) (push buf modified-buffers)) (push buf white-positions) (push (match-beginning 0) white-positions) (push (match-end 0) white-positions))))))) (setq white-positions (nreverse white-positions)) (while white-positions (save-excursion (set-buffer (pop white-positions)) (delete-region (pop white-positions) (pop white-positions)))) (if modified-buffers (message "Deleted trailing whitespace from: %s" (mapconcat #'(lambda (buf) (format "`%s'" (buffer-name buf))) modified-buffers " ")) (message "No fixes needed."))))) (defun diff-show-trailing-blanks () "Show trailing blanks in modified lines for diff-mode." (interactive) (let ((whitespace-style '(trailing)) (whitespace-trailing-regexp "^[+!>].*?\\([\t ]+\\)$")) (whitespace-mode 1))) ; display trailing blanks in diff buffer --------------010602010605000105070702--