From: Paul Nelson <ultrono@gmail.com>
To: 72866@debbugs.gnu.org
Subject: bug#72866: [PATCH] Add ediff-copy-all-X-to-Y functions
Date: Thu, 29 Aug 2024 08:03:01 +0200 [thread overview]
Message-ID: <CAOA-32NPQsP4R=cNZAgfehaSo-LuWrT-hOP6LVAnb6kzijt4Og@mail.gmail.com> (raw)
[-- 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)
next reply other threads:[~2024-08-29 6:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 6:03 Paul Nelson [this message]
2024-08-31 10:32 ` bug#72866: [PATCH] Add ediff-copy-all-X-to-Y functions 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOA-32NPQsP4R=cNZAgfehaSo-LuWrT-hOP6LVAnb6kzijt4Og@mail.gmail.com' \
--to=ultrono@gmail.com \
--cc=72866@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.