Function: ediff-extract-diffs
ediff-extract-diffs is a byte-compiled function defined in
ediff-diff.el.gz.
Signature
(ediff-extract-diffs DIFF-BUFFER WORD-MODE &optional BOUNDS)
Source Code
;; Defined in /usr/src/emacs/lisp/vc/ediff-diff.el.gz
;; BOUNDS specifies visibility bounds to use.
;; WORD-MODE tells whether we are in the word-mode or not.
;; If WORD-MODE, also construct vector of diffs using word numbers.
;; Else, use point values.
;; This function handles diff-2 jobs including the case of
;; merging buffers and files without ancestor.
(defun ediff-extract-diffs (diff-buffer word-mode &optional bounds)
(let ((A-buffer ediff-buffer-A)
(B-buffer ediff-buffer-B)
(C-buffer ediff-buffer-C)
(a-prev 1) ; this is needed to set the first diff line correctly
(a-prev-pt nil)
(b-prev 1)
(b-prev-pt nil)
(c-prev 1)
(c-prev-pt nil)
diff-list shift-A shift-B
)
;; diff list contains word numbers, unless changed later
(setq diff-list (cons (if word-mode 'words 'points)
diff-list))
;; we don't use visibility bounds for buffer C when merging
(if bounds
(setq shift-A
(ediff-overlay-start
(ediff-get-value-according-to-buffer-type 'A bounds))
shift-B
(ediff-overlay-start
(ediff-get-value-according-to-buffer-type 'B bounds))))
;; reset point in buffers A/B/C
(ediff-with-current-buffer A-buffer
(goto-char (if shift-A shift-A (point-min))))
(ediff-with-current-buffer B-buffer
(goto-char (if shift-B shift-B (point-min))))
(if (ediff-buffer-live-p C-buffer)
(ediff-with-current-buffer C-buffer
(goto-char (point-min))))
(ediff-with-current-buffer diff-buffer
(goto-char (point-min))
(while (re-search-forward ediff-match-diff-line nil t)
(let* ((a-begin (string-to-number (buffer-substring (match-beginning 1)
(match-end 1))))
(a-end (let ((b (match-beginning 3))
(e (match-end 3)))
(if b
(string-to-number (buffer-substring b e))
a-begin)))
(diff-type (buffer-substring (match-beginning 4) (match-end 4)))
(b-begin (string-to-number (buffer-substring (match-beginning 5)
(match-end 5))))
(b-end (let ((b (match-beginning 7))
(e (match-end 7)))
(if b
(string-to-number (buffer-substring b e))
b-begin)))
a-begin-pt a-end-pt b-begin-pt b-end-pt
c-begin c-end c-begin-pt c-end-pt)
;; fix the beginning and end numbers, because diff is somewhat
;; strange about how it numbers lines
(if (string-equal diff-type "a")
(setq b-end (1+ b-end)
a-begin (1+ a-begin)
a-end a-begin)
(if (string-equal diff-type "d")
(setq a-end (1+ a-end)
b-begin (1+ b-begin)
b-end b-begin)
;; (string-equal diff-type "c")
(setq a-end (1+ a-end)
b-end (1+ b-end))))
(if (eq ediff-default-variant 'default-B)
(setq c-begin b-begin
c-end b-end)
(setq c-begin a-begin
c-end a-end))
;; compute main diff vector
(if word-mode
;; make diff-list contain word numbers
(setq diff-list
(nconc diff-list
(list
(if (ediff-buffer-live-p C-buffer)
(vector (- a-begin a-prev) (- a-end a-begin)
(- b-begin b-prev) (- b-end b-begin)
(- c-begin c-prev) (- c-end c-begin)
nil nil ; dummy ancestor
nil ; state of diff
nil ; state of merge
nil ; state of ancestor
)
(vector (- a-begin a-prev) (- a-end a-begin)
(- b-begin b-prev) (- b-end b-begin)
nil nil ; dummy buf C
nil nil ; dummy ancestor
nil ; state of diff
nil ; state of merge
nil ; state of ancestor
))
))
a-prev a-end
b-prev b-end
c-prev c-end)
;; else convert lines to points
(ediff-with-current-buffer A-buffer
(goto-char (or a-prev-pt shift-A (point-min)))
(forward-line (- a-begin a-prev))
(setq a-begin-pt (point))
(forward-line (- a-end a-begin))
(setq a-end-pt (point)
a-prev a-end
a-prev-pt a-end-pt))
(ediff-with-current-buffer B-buffer
(goto-char (or b-prev-pt shift-B (point-min)))
(forward-line (- b-begin b-prev))
(setq b-begin-pt (point))
(forward-line (- b-end b-begin))
(setq b-end-pt (point)
b-prev b-end
b-prev-pt b-end-pt))
(if (ediff-buffer-live-p C-buffer)
(ediff-with-current-buffer C-buffer
(goto-char (or c-prev-pt (point-min)))
(forward-line (- c-begin c-prev))
(setq c-begin-pt (point))
(forward-line (- c-end c-begin))
(setq c-end-pt (point)
c-prev c-end
c-prev-pt c-end-pt)))
(setq diff-list
(nconc
diff-list
(list
(if (ediff-buffer-live-p C-buffer)
(vector
a-begin-pt a-end-pt b-begin-pt b-end-pt
c-begin-pt c-end-pt
nil nil ; dummy ancestor
;; state of diff
;; shows which buff is different from the other two
(if (eq ediff-default-variant 'default-B) 'A 'B)
ediff-default-variant ; state of merge
nil ; state of ancestor
)
(vector a-begin-pt a-end-pt
b-begin-pt b-end-pt
nil nil ; dummy buf C
nil nil ; dummy ancestor
nil nil ; dummy state of diff & merge
nil ; dummy state of ancestor
)))
)))
))) ; end ediff-with-current-buffer
diff-list
))