all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#72866: [PATCH] Add ediff-copy-all-X-to-Y functions
@ 2024-08-29  6:03 Paul Nelson
  2024-08-31 10:32 ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Nelson @ 2024-08-29  6:03 UTC (permalink / raw)
  To: 72866

[-- Attachment #1: Type: text/plain, Size: 185 bytes --]

This patch binds functions in Ediff that copy all changes from one
buffer to another, without having to manually go through each
difference.  Any feedback welcome.

Thanks, best,

Paul

[-- Attachment #2: 0001-Add-ediff-copy-all-X-to-Y-functions.patch --]
[-- Type: application/octet-stream, Size: 4629 bytes --]

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)


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

end of thread, other threads:[~2024-09-11  8:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-29  6:03 bug#72866: [PATCH] Add ediff-copy-all-X-to-Y functions Paul Nelson
2024-08-31 10:32 ` Eli Zaretskii
2024-09-01  6:59   ` Paul Nelson
2024-09-02 10:32     ` Robert Pluim
2024-09-04  7:30       ` Paul Nelson
2024-09-04 13:01         ` Robert Pluim
2024-09-04 13:10           ` Eli Zaretskii
2024-09-04 13:20             ` Paul Nelson
2024-09-11  8:46               ` Robert Pluim

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.