Function: emerge-trim-difference
emerge-trim-difference is an interactive and byte-compiled function
defined in emerge.el.gz.
Signature
(emerge-trim-difference)
Documentation
Trim lines off top and bottom of difference that are the same.
If lines are the same in both the A and the B versions, strip them off.
(This can happen when the A and B versions have common lines that the
ancestor version does not share.)
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/vc/emerge.el.gz
(defun emerge-trim-difference ()
"Trim lines off top and bottom of difference that are the same.
If lines are the same in both the A and the B versions, strip them off.
\(This can happen when the A and B versions have common lines that the
ancestor version does not share.)"
(interactive)
;; make sure we are in a real difference
(emerge-validate-difference)
;; remove the flags
(emerge-unselect-difference emerge-current-difference)
(let* ((diff (aref emerge-difference-list emerge-current-difference))
(top-a (marker-position (aref diff 0)))
(bottom-a (marker-position (aref diff 1)))
(top-b (marker-position (aref diff 2)))
(bottom-b (marker-position (aref diff 3)))
(top-m (marker-position (aref diff 4)))
(bottom-m (marker-position (aref diff 5)))
size success sa sb sm)
;; move down the tops of the difference regions as much as possible
;; Try advancing comparing 1000 chars at a time.
;; When that fails, go 500 chars at a time, and so on.
(setq size 1000)
(while (> size 0)
(setq success t)
(while success
(setq size (min size (- bottom-a top-a) (- bottom-b top-b)
(- bottom-m top-m)))
(setq sa (with-current-buffer emerge-A-buffer
(buffer-substring top-a
(+ size top-a))))
(setq sb (with-current-buffer emerge-B-buffer
(buffer-substring top-b
(+ size top-b))))
(setq sm (buffer-substring top-m (+ size top-m)))
(setq success (and (> size 0) (equal sa sb) (equal sb sm)))
(if success
(setq top-a (+ top-a size)
top-b (+ top-b size)
top-m (+ top-m size))))
(setq size (/ size 2)))
;; move up the bottoms of the difference regions as much as possible
;; Try advancing comparing 1000 chars at a time.
;; When that fails, go 500 chars at a time, and so on.
(setq size 1000)
(while (> size 0)
(setq success t)
(while success
(setq size (min size (- bottom-a top-a) (- bottom-b top-b)
(- bottom-m top-m)))
(setq sa (with-current-buffer emerge-A-buffer
(buffer-substring (- bottom-a size)
bottom-a)))
(setq sb (with-current-buffer emerge-B-buffer
(buffer-substring (- bottom-b size)
bottom-b)))
(setq sm (buffer-substring (- bottom-m size) bottom-m))
(setq success (and (> size 0) (equal sa sb) (equal sb sm)))
(if success
(setq bottom-a (- bottom-a size)
bottom-b (- bottom-b size)
bottom-m (- bottom-m size))))
(setq size (/ size 2)))
;; {top,bottom}-{a,b,m} are now set at the new beginnings and ends
;; of the difference regions. Move them to the beginning of lines, as
;; appropriate.
(with-current-buffer emerge-A-buffer
(goto-char top-a)
(beginning-of-line)
(aset diff 0 (point-marker))
(goto-char bottom-a)
(beginning-of-line 2)
(aset diff 1 (point-marker)))
(with-current-buffer emerge-B-buffer
(goto-char top-b)
(beginning-of-line)
(aset diff 2 (point-marker))
(goto-char bottom-b)
(beginning-of-line 2)
(aset diff 3 (point-marker)))
(goto-char top-m)
(beginning-of-line)
(aset diff 4 (point-marker))
(goto-char bottom-m)
(beginning-of-line 2)
(aset diff 5 (point-marker))
;; put the flags back in, recenter the display
(emerge-select-difference emerge-current-difference)
(emerge-recenter)))