From 1550af9b786cff03d37725c69b53c4b711a9f45c Mon Sep 17 00:00:00 2001
From: Paul Nelson <ultrono@gmail.com>
Date: Thu, 29 Aug 2024 07:50:27 +0200
Subject: [PATCH] Add ediff-copy-all-X-to-Y functions

* lisp/vc/ediff-util.el (ediff--copy-all):
(ediff-copy-all-A-to-B):
(ediff-copy-all-B-to-A):
(ediff-copy-all-A-to-C):
(ediff-copy-all-B-to-C):
(ediff-copy-all-C-to-A):
(ediff-copy-all-C-to-B): New functions.
(ediff-setup-keymap): Bind them.
---
 lisp/vc/ediff-util.el | 64 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)

diff --git a/lisp/vc/ediff-util.el b/lisp/vc/ediff-util.el
index 597d8a5e643..b575eaeca75 100644
--- a/lisp/vc/ediff-util.el
+++ b/lisp/vc/ediff-util.el
@@ -159,6 +159,8 @@ ediff-setup-keymap
 	 ;; In merging, we allow only A->C and B->C copying.
 	 (define-key ediff-mode-map "a" #'ediff-copy-A-to-C)
 	 (define-key ediff-mode-map "b" #'ediff-copy-B-to-C)
+	 (define-key ediff-mode-map "C-c C-a" #'ediff-copy-all-A-to-C)
+	 (define-key ediff-mode-map "C-c C-b" #'ediff-copy-all-B-to-C)
 	 (define-key ediff-mode-map "r" #'ediff-restore-diff-in-merge-buffer)
 	 (define-key ediff-mode-map "s" #'ediff-shrink-window-C)
 	 (define-key ediff-mode-map "+" #'ediff-combine-diffs)
@@ -174,6 +176,12 @@ ediff-setup-keymap
 	 (define-key ediff-mode-map "c" nil)
 	 (define-key ediff-mode-map "ca" #'ediff-copy-C-to-A)
 	 (define-key ediff-mode-map "cb" #'ediff-copy-C-to-B)
+         (define-key ediff-mode-map "C-c C-a C-b" #'ediff-copy-all-A-to-B)
+         (define-key ediff-mode-map "C-c C-b C-a" #'ediff-copy-all-B-to-A)
+         (define-key ediff-mode-map "C-c C-a C-c" #'ediff-copy-all-A-to-C)
+         (define-key ediff-mode-map "C-c C-b C-c" #'ediff-copy-all-B-to-C)
+         (define-key ediff-mode-map "C-c C-c C-a" #'ediff-copy-all-C-to-A)
+         (define-key ediff-mode-map "C-c C-c C-b" #'ediff-copy-all-C-to-B)
 	 (define-key ediff-mode-map "ra" #'ediff-restore-diff)
 	 (define-key ediff-mode-map "rb" #'ediff-restore-diff)
 	 (define-key ediff-mode-map "rc" #'ediff-restore-diff)
@@ -181,6 +189,8 @@ ediff-setup-keymap
 	(t ; 2-way comparison
 	 (define-key ediff-mode-map "a"  #'ediff-copy-A-to-B)
 	 (define-key ediff-mode-map "b"  #'ediff-copy-B-to-A)
+         (define-key ediff-mode-map "C-c C-a" #'ediff-copy-all-A-to-B)
+         (define-key ediff-mode-map "C-c C-b" #'ediff-copy-all-B-to-A)
 	 (define-key ediff-mode-map "ra" #'ediff-restore-diff)
 	 (define-key ediff-mode-map "rb" #'ediff-restore-diff))
 	) ; cond
@@ -1952,6 +1962,60 @@ ediff-copy-C-to-A
   (interactive "P")
   (ediff-diff-to-diff arg "ca"))
 
+(defun ediff--copy-all (source dest)
+  "Copy all changes from SOURCE to DEST in Ediff.
+SOURCE and DEST should each be one of the symbols `A', `B', or `C'."
+  (ediff-barf-if-not-control-buffer)
+  (let ((valid-buffers '(A B C)))
+    (unless (and (memq source valid-buffers)
+                 (memq dest valid-buffers))
+      (error "Buffer arguments should be `A', `B', or `C'")))
+  (unless (eq source dest)
+    (let* ((copy-func-name (format "ediff-copy-%s-to-%s"
+                                   (symbol-name source)
+                                   (symbol-name dest)))
+           (copy-func (intern copy-func-name)))
+      (condition-case err
+          (let ((n 0))
+            (while (ediff-valid-difference-p n)
+              (ediff-jump-to-difference (1+ n))
+              (funcall copy-func nil)
+              (setq n (1+ n)))
+            (message "All changes copied from buffer %s to %s"
+                     (symbol-name source)
+                     (symbol-name dest)))
+        (error
+         (message "Error occurred while copying: %s" (error-message-string err)))))))
+
+(defun ediff-copy-all-A-to-B ()
+  "Copy all changes from buffer A to buffer B in Ediff."
+  (interactive)
+  (ediff--copy-all 'A 'B))
+
+(defun ediff-copy-all-B-to-A ()
+  "Copy all changes from buffer B to buffer A in Ediff."
+  (interactive)
+  (ediff--copy-all 'B 'A))
+
+(defun ediff-copy-all-A-to-C ()
+  "Copy all changes from buffer A to buffer C in Ediff."
+  (interactive)
+  (ediff--copy-all 'A 'C))
+
+(defun ediff-copy-all-B-to-C ()
+  "Copy all changes from buffer B to buffer C in Ediff."
+  (interactive)
+  (ediff--copy-all 'B 'C))
+
+(defun ediff-copy-all-C-to-A ()
+  "Copy all changes from buffer C to buffer A in Ediff."
+  (interactive)
+  (ediff--copy-all 'C 'A))
+
+(defun ediff-copy-all-C-to-B ()
+  "Copy all changes from buffer C to buffer B in Ediff."
+  (interactive)
+  (ediff--copy-all 'C 'B))
 
 
 ;; Copy diff N from FROM-BUF-TYPE (given as A, B or C) to TO-BUF-TYPE.
-- 
2.39.3 (Apple Git-145)

