Function: ediff-copy-diff
ediff-copy-diff is a byte-compiled function defined in
ediff-util.el.gz.
Signature
(ediff-copy-diff N FROM-BUF-TYPE TO-BUF-TYPE &optional BATCH-INVOCATION REG-TO-COPY)
Source Code
;; Defined in /usr/src/emacs/lisp/vc/ediff-util.el.gz
;; Copy diff N from FROM-BUF-TYPE (given as A, B or C) to TO-BUF-TYPE.
;; If optional DO-NOT-SAVE is non-nil, do not save the old value of the
;; target diff. This is used in merging, when constructing the merged
;; version.
(defun ediff-copy-diff (n from-buf-type to-buf-type
&optional batch-invocation reg-to-copy)
(let* ((to-buf (ediff-get-buffer to-buf-type))
;;(from-buf (if (not reg-to-copy) (ediff-get-buffer from-buf-type)))
(ctrl-buf ediff-control-buffer)
(saved-p t)
(three-way ediff-3way-job)
messg
ediff-verbose-p
reg-to-delete reg-to-delete-beg reg-to-delete-end)
(setq reg-to-delete-beg
(ediff-get-diff-posn to-buf-type 'beg n ctrl-buf))
(setq reg-to-delete-end
(ediff-get-diff-posn to-buf-type 'end n ctrl-buf))
(if reg-to-copy
(setq from-buf-type nil)
(setq reg-to-copy (ediff-get-region-contents n from-buf-type ctrl-buf)))
(setq reg-to-delete (ediff-get-region-contents
n to-buf-type ctrl-buf
reg-to-delete-beg reg-to-delete-end))
(if (string= reg-to-delete reg-to-copy)
(setq saved-p nil) ; don't copy identical buffers
;; seems ok to copy
(if (or batch-invocation (ediff-test-save-region n to-buf-type))
(condition-case conds
(progn
(ediff-with-current-buffer to-buf
;; to prevent flags from interfering if buffer is writable
(let ((inhibit-read-only (null buffer-read-only)))
(goto-char reg-to-delete-end)
(insert reg-to-copy)
(when (> reg-to-delete-end reg-to-delete-beg)
(delete-region reg-to-delete-beg reg-to-delete-end))))
(or batch-invocation
(setq
messg
(ediff-save-diff-region n to-buf-type reg-to-delete))))
(error (message "ediff-copy-diff: %s %s"
(car conds)
(mapconcat #'prin1-to-string (cdr conds) " "))
(beep 1)
(sit-for 2) ; let the user see the error msg
(setq saved-p nil)
)))
)
;; adjust state of difference in case 3-way and diff was copied ok
(if (and saved-p three-way)
(ediff-set-state-of-diff-in-all-buffers n ctrl-buf))
(if batch-invocation
(ediff-clear-fine-differences n)
;; If diff3 job, we should recompute fine diffs so we clear them
;; before reinserting flags (and thus before ediff-recenter).
(if (and saved-p three-way)
(ediff-clear-fine-differences n))
(ediff-refresh-mode-lines)
;; For diff2 jobs, don't recompute fine diffs, since we know there
;; aren't any. So we clear diffs after ediff-recenter.
(if (and saved-p (not three-way))
(ediff-clear-fine-differences n))
;; Make sure that the message about saving and how to restore is seen
;; by the user
(message "%s" messg))
))