Function: smerge-match-conflict

smerge-match-conflict is a byte-compiled function defined in smerge-mode.el.gz.

Signature

(smerge-match-conflict)

Documentation

Get info about the conflict. Puts the info in the match-data.

The submatches contain:
 0: the whole conflict.
 1: upper version of the code.
 2: base version of the code.
 3: lower version of the code.
An error is raised if not inside a conflict.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/smerge-mode.el.gz
(defun smerge-match-conflict ()
  "Get info about the conflict.  Puts the info in the `match-data'.
The submatches contain:
 0:  the whole conflict.
 1:  upper version of the code.
 2:  base version of the code.
 3:  lower version of the code.
An error is raised if not inside a conflict."
  (save-excursion
    (condition-case nil
	(let* ((orig-point (point))

	       (_ (forward-line 1))
	       (_ (re-search-backward smerge-begin-re))

	       (start (match-beginning 0))
	       (upper-start (match-end 0))
	       (filename (or (match-string 1) ""))

	       (_ (re-search-forward smerge-end-re))
	       (_ (when (< (match-end 0) orig-point)
                    ;; Point is not within the conflict we found,
                    ;; so this conflict is not ours.
                    (signal 'search-failed (list smerge-begin-re))))

	       (lower-end (match-beginning 0))
	       (end (match-end 0))

	       (_ (re-search-backward smerge-lower-re start))

	       (upper-end (match-beginning 0))
	       (lower-start (match-end 0))

	       base-start base-end)

	  ;; handle the various conflict styles
	  (cond
	   ((save-excursion
	      (goto-char upper-start)
	      (re-search-forward smerge-begin-re end t))
	    ;; There's a nested conflict and we're after the beginning
	    ;; of the outer one but before the beginning of the inner one.
	    ;; Of course, maybe this is not a nested conflict but in that
	    ;; case it can only be something nastier that we don't know how
	    ;; to handle, so may as well arbitrarily decide to treat it as
	    ;; a nested conflict.  --Stef
	    (error "There is a nested conflict"))

	   ((re-search-backward smerge-base-re start t)
	    ;; a 3-parts conflict
            (setq-local smerge-conflict-style 'diff3-A)
	    (setq base-end upper-end)
	    (setq upper-end (match-beginning 0))
	    (setq base-start (match-end 0)))

	   ((string= filename (file-name-nondirectory
			       (or buffer-file-name "")))
	    ;; a 2-parts conflict
            (setq-local smerge-conflict-style 'diff3-E))

	   ((and (not base-start)
		 (or (eq smerge-conflict-style 'diff3-A)
		     (equal filename "ANCESTOR")
		     (string-match "\\`[.0-9]+\\'" filename)))
	    ;; a same-diff conflict
	    (setq base-start upper-start)
	    (setq base-end   upper-end)
	    (setq upper-start lower-start)
	    (setq upper-end   lower-end)))

	  (store-match-data (list start end
				  upper-start upper-end
				  base-start base-end
				  lower-start lower-end
				  (when base-start (1- base-start)) base-start
				  (1- lower-start) lower-start))
	  t)
      (search-failed (user-error "Point not in conflict region")))))