all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Proposal: diff-remove-trailing-blanks
@ 2008-04-26 14:59 Óscar Fuentes
  2008-04-26 18:44 ` Dan Nicolaescu
  0 siblings, 1 reply; 18+ messages in thread
From: Óscar Fuentes @ 2008-04-26 14:59 UTC (permalink / raw)
  To: emacs-devel

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.")))





^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2008-05-10  0:45 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-26 14:59 Proposal: diff-remove-trailing-blanks Óscar Fuentes
2008-04-26 18:44 ` Dan Nicolaescu
2008-04-26 19:38   ` Óscar Fuentes
2008-04-26 19:50   ` Vinicius Jose Latorre
2008-04-26 20:08     ` Óscar Fuentes
     [not found]       ` <4813A244.4050908@ig.com.br>
2008-04-26 22:07         ` Óscar Fuentes
2008-04-27  2:30           ` Vinicius Jose Latorre
2008-04-27  2:59             ` Vinicius Jose Latorre
2008-04-27  4:04             ` Óscar Fuentes
     [not found]               ` <48146DF3.3090706@ig.com.br>
     [not found]                 ` <48147BC0.6080406@ig.com.br>
2008-04-27 15:15                   ` Óscar Fuentes
2008-04-27 17:30                     ` Vinicius Jose Latorre
2008-04-27 20:05                       ` Óscar Fuentes
2008-05-01  0:34                         ` Vinicius Jose Latorre
2008-05-01  1:04                           ` Óscar Fuentes
2008-05-02 14:22                           ` Stefan Monnier
2008-05-07  0:25                             ` Vinicius Jose Latorre
2008-05-07  2:04                               ` Stefan Monnier
2008-05-10  0:45                                 ` Vinicius Jose Latorre

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.