diff options
| author | Oscar Fuentes | 2012-08-08 00:41:35 -0400 |
|---|---|---|
| committer | Dan Nicolaescu | 2012-08-08 00:41:35 -0400 |
| commit | 2c2d9c9cd0a409778ebc3618888fc9795c2a9135 (patch) | |
| tree | fe32fb9c57d5c23590a1059a297cc22f0b6347f1 | |
| parent | 2d79ec42a2955c3c9ecce804576c624d75e08e19 (diff) | |
| download | emacs-2c2d9c9cd0a409778ebc3618888fc9795c2a9135.tar.gz emacs-2c2d9c9cd0a409778ebc3618888fc9795c2a9135.zip | |
* vc/diff-mode.el (diff-remove-trailing-whitespace): New function.
| -rw-r--r-- | lisp/ChangeLog | 4 | ||||
| -rw-r--r-- | lisp/vc/diff-mode.el | 41 |
2 files changed, 45 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9a94a37af69..479fee02027 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2012-08-08 Óscar Fuentes <ofv@wanadoo.es> | ||
| 2 | |||
| 3 | * vc/diff-mode.el (diff-remove-trailing-whitespace): New function. | ||
| 4 | |||
| 1 | 2012-08-08 Fabián Ezequiel Gallina <fgallina@cuca> | 5 | 2012-08-08 Fabián Ezequiel Gallina <fgallina@cuca> |
| 2 | 6 | ||
| 3 | * progmodes/python.el Fixed defsubst warning. | 7 | * progmodes/python.el Fixed defsubst warning. |
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el index a9d124700b8..d3d9878c5ad 100644 --- a/lisp/vc/diff-mode.el +++ b/lisp/vc/diff-mode.el | |||
| @@ -2016,6 +2016,47 @@ I.e. like `add-change-log-entry-other-window' but applied to all hunks." | |||
| 2016 | ;; When there's no more hunks, diff-hunk-next signals an error. | 2016 | ;; When there's no more hunks, diff-hunk-next signals an error. |
| 2017 | (error nil)))) | 2017 | (error nil)))) |
| 2018 | 2018 | ||
| 2019 | (defun diff-remove-trailing-whitespace () | ||
| 2020 | "When on a buffer that contains a diff, inspects the | ||
| 2021 | differences and removes trailing whitespace (spaces, tabs) from | ||
| 2022 | the lines modified or introduced by this diff. Shows a message | ||
| 2023 | with the name of the altered buffers, which are unsaved. If a | ||
| 2024 | file referenced on the diff has no buffer and needs to be fixed, | ||
| 2025 | a buffer visiting that file is created." | ||
| 2026 | (interactive) | ||
| 2027 | (goto-char (point-min)) | ||
| 2028 | (let | ||
| 2029 | ;; We assume that the diff header has no trailing whitespace. | ||
| 2030 | ((modified-buffers nil) | ||
| 2031 | (white-positions nil)) | ||
| 2032 | (while (re-search-forward "^[+!>].*[ \t]+$" (point-max) t) | ||
| 2033 | (save-excursion | ||
| 2034 | (cl-destructuring-bind (buf line-offset pos src _dst &optional _switched) | ||
| 2035 | (diff-find-source-location t t) | ||
| 2036 | (when line-offset | ||
| 2037 | (set-buffer buf) | ||
| 2038 | (save-excursion | ||
| 2039 | (goto-char (+ (car pos) (cdr src))) | ||
| 2040 | (beginning-of-line) | ||
| 2041 | (when (re-search-forward "\\([ \t]+\\)$" (line-end-position) t) | ||
| 2042 | (when (not (member buf modified-buffers)) | ||
| 2043 | (push buf modified-buffers)) | ||
| 2044 | (goto-char (match-end 0)) | ||
| 2045 | (push (point-marker) white-positions) | ||
| 2046 | (goto-char (match-beginning 0)) | ||
| 2047 | (push (point-marker) white-positions) | ||
| 2048 | (push buf white-positions))))))) | ||
| 2049 | (while white-positions | ||
| 2050 | (save-excursion | ||
| 2051 | (set-buffer (pop white-positions)) | ||
| 2052 | (delete-region (pop white-positions) (pop white-positions)))) | ||
| 2053 | (if modified-buffers | ||
| 2054 | (let ((msg "Deleted new trailing whitespace from:")) | ||
| 2055 | (dolist (f modified-buffers) | ||
| 2056 | (setq msg (concat msg " `" (buffer-name f) "'"))) | ||
| 2057 | (message "%s" msg)) | ||
| 2058 | (message "No trailing whitespace fixes needed.")))) | ||
| 2059 | |||
| 2019 | ;; provide the package | 2060 | ;; provide the package |
| 2020 | (provide 'diff-mode) | 2061 | (provide 'diff-mode) |
| 2021 | 2062 | ||