GNU bug report logs -
#66113
Apply the entire diff buffer
Previous Next
Reported by: Juri Linkov <juri <at> linkov.net>
Date: Wed, 20 Sep 2023 06:51:01 UTC
Severity: normal
Fixed in version 30.0.50
Done: Juri Linkov <juri <at> linkov.net>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
After discussing on emacs-devel, here is a complete patch for the feature
of applying the entire diff buffer:
[diff-apply-buffer.patch (text/x-diff, inline)]
diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index d776375d681..4633d5896a7 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -216,6 +216,7 @@ diff-mode-map
"C-x 4 A" #'diff-add-change-log-entries-other-window
;; Misc operations.
"C-c C-a" #'diff-apply-hunk
+ "C-c C-m a" #'diff-apply-buffer
"C-c C-e" #'diff-ediff-patch
"C-c C-n" #'diff-restrict-view
"C-c C-s" #'diff-split-hunk
@@ -2054,6 +2055,40 @@ diff-kill-applied-hunks
(diff-hunk-kill)
(diff-hunk-next)))))
+(defun diff-apply-buffer ()
+ "Apply the diff in the entire diff buffer.
+When applying all hunks was successful, then save the changed buffers."
+ (interactive)
+ (let ((buffers nil)
+ (failures 0)
+ (diff-refine nil))
+ (save-excursion
+ (goto-char (point-min))
+ (diff-beginning-of-hunk t)
+ (while (pcase-let ((`(,buf ,line-offset ,pos ,_src ,dst ,switched)
+ (diff-find-source-location nil nil)))
+ (cond ((and line-offset (not switched))
+ (with-current-buffer buf
+ (goto-char (car pos))
+ (delete-region (car pos) (cdr pos))
+ (insert (car dst))
+ (when buffer-file-name
+ (push (current-buffer) buffers))))
+ (t (setq failures (1+ failures))))
+ (not (or (eq (prog1 (point) (diff-hunk-next)) (point))
+ (eobp))))))
+ (setq buffers (delete-dups buffers))
+ (cond ((zerop failures)
+ (dolist (buf (reverse buffers))
+ (with-current-buffer buf
+ (save-buffer)))
+ (message "Saved %d buffers" (length buffers)))
+ (t
+ (dolist (buf buffers)
+ (with-current-buffer buf
+ (display-buffer buf)))
+ (message "%d hunks failed; no buffers saved" failures)))))
+
(defalias 'diff-mouse-goto-source #'diff-goto-source)
(defun diff-goto-source (&optional other-file event)
This bug report was last modified 1 year and 232 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.