Function: smerge--refine-apply-diff-1

smerge--refine-apply-diff-1 is a byte-compiled function defined in smerge-mode.el.gz.

Signature

(smerge--refine-apply-diff-1 DIFFBUF OL1 OL2 PROPS-C PROPS-R PROPS-A)

Source Code

;; Defined in /usr/src/emacs/lisp/vc/smerge-mode.el.gz
(defun smerge--refine-apply-diff-1 ( diffbuf ol1 ol2
                                   props-c props-r props-a)
  (with-current-buffer diffbuf
    (goto-char (point-min))
    (let ((last1 nil)
          (last2 nil)
          (end1 (overlay-end ol1))
          (end2 (overlay-end ol2)))
      (while (not (eobp))
        (if (not (looking-at "\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?\\([acd]\\)\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)?$"))
            (error "Unexpected patch hunk header: %s"
                   (buffer-substring (point) (line-end-position))))
        (let ((op (char-after (match-beginning 3)))
              (m1 (match-string 1))
              (m2 (match-string 2))
              (m4 (match-string 4))
              (m5 (match-string 5)))
          (setq last1
                (smerge--refine-highlight-change
		 ol1 m1 (if (eq op ?a) t m2)
		 ;; Try to use props-c only for changed chars,
		 ;; fallback to props-r for changed/removed chars,
		 ;; but if props-r is nil then fallback to props-c.
		 (or (and (eq op '?c) props-c) props-r props-c)))
          (setq last2
                (smerge--refine-highlight-change
		 ol2 m4 (if (eq op ?d) t m5)
		 ;; Same logic as for removed chars above.
		 (or (and (eq op '?c) props-c) props-a props-c))))
        (overlay-put last1 'smerge--refine-other last2)
        (overlay-put last2 'smerge--refine-other last1)
        (forward-line 1)                            ;Skip hunk header.
        (and (re-search-forward "^[0-9]" nil 'move) ;Skip hunk body.
             (goto-char (match-beginning 0))))
      ;; (cl-assert (or (null last1) (< (overlay-start last1) end1)))
      ;; (cl-assert (or (null last2) (< (overlay-start last2) end2)))
      (if smerge-refine-weight-hack
          (progn
            ;; (cl-assert (or (null last1) (<= (overlay-end last1) end1)))
            ;; (cl-assert (or (null last2) (<= (overlay-end last2) end2)))
            )
        ;; smerge-refine-forward-function when calling in chopup may
        ;; have stopped because it bumped into EOB whereas in
        ;; smerge-refine-weight-hack it may go a bit further.
        (if (and last1 (> (overlay-end last1) end1))
            (move-overlay last1 (overlay-start last1) end1))
        (if (and last2 (> (overlay-end last2) end2))
            (move-overlay last2 (overlay-start last2) end2))
        ))))