summaryrefslogtreecommitdiff
path: root/lisp/vc/diff-mode.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2012-08-13 15:10:35 -0400
committerStefan Monnier <monnier@iro.umontreal.ca>2012-08-13 15:10:35 -0400
commitaa7c6dbeba48522d892cbf011c40a9fef0c369f7 (patch)
tree0f984a2054ada80ca4922a9bc47021a27f264ef6 /lisp/vc/diff-mode.el
parent89660017d14b5c2ca7d621636604f4acab63138c (diff)
downloademacs-aa7c6dbeba48522d892cbf011c40a9fef0c369f7.tar.gz
* lisp/color.el (color-xyz-to-lab, color-lab-to-xyz, color-cie-de2000):
Prefer pcase-let over destructuring-bind. * lisp/vc/diff-mode.el (diff-remove-trailing-whitespace): Same. Also, remove whitespace as we go, rather than after accumulating the various places.
Diffstat (limited to 'lisp/vc/diff-mode.el')
-rw-r--r--lisp/vc/diff-mode.el49
1 files changed, 19 insertions, 30 deletions
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index d3d9878c5ad..3fa7788002e 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -2024,37 +2024,26 @@ 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))
- (let
- ;; We assume that the diff header has no trailing whitespace.
- ((modified-buffers nil)
- (white-positions nil))
- (while (re-search-forward "^[+!>].*[ \t]+$" (point-max) t)
- (save-excursion
- (cl-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))))
+ ;; We assume that the diff header has no trailing whitespace.
+ (let ((modified-buffers nil))
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward "^[+!>].*[ \t]+$" (point-max) t)
+ (pcase-let ((`(,buf ,line-offset ,pos ,src ,_dst ,_switched)
+ (diff-find-source-location t t)))
+ (when line-offset
+ (with-current-buffer buf
+ (save-excursion
+ (goto-char (+ (car pos) (cdr src)))
+ (beginning-of-line)
+ (when (re-search-forward "\\([ \t]+\\)$" (line-end-position) t)
+ (unless (memq buf modified-buffers)
+ (push buf modified-buffers))
+ (replace-match ""))))))))
(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 "Deleted new trailing whitespace from: %s"
+ (mapconcat (lambda (buf) (concat "`" (buffer-name buf) "'"))
+ modified-buffers " "))
(message "No trailing whitespace fixes needed."))))
;; provide the package