Function: smerge-extend

smerge-extend is an interactive and byte-compiled function defined in smerge-mode.el.gz.

Signature

(smerge-extend OTHERPOS)

Documentation

Extend current conflict with some of the surrounding text.

Point should be inside a conflict and OTHERPOS should be either a marker indicating the position until which to extend the conflict (either before or after the current conflict), OTHERPOS can also be an integer indicating the number of lines over which to extend the conflict. If positive, it extends over the lines following the conflict and other, it extends over the lines preceding the conflict. When used interactively, you can specify OTHERPOS either using an active region, or with a numeric prefix. By default it uses a numeric prefix of 1.

Probably introduced at or before Emacs version 31.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/vc/smerge-mode.el.gz
(defun smerge-extend (otherpos)
  "Extend current conflict with some of the surrounding text.
Point should be inside a conflict and OTHERPOS should be either a marker
indicating the position until which to extend the conflict (either before
or after the current conflict),
OTHERPOS can also be an integer indicating the number of lines over which
to extend the conflict.  If positive, it extends over the lines following
the conflict and other, it extends over the lines preceding the conflict.
When used interactively, you can specify OTHERPOS either using an active
region, or with a numeric prefix.  By default it uses a numeric prefix of 1."
  (interactive
   (list (if (use-region-p) (mark-marker)
           (prefix-numeric-value current-prefix-arg))))
  ;; FIXME: If OTHERPOS is inside (or next to) another conflict
  ;; or if there are conflicts between the current conflict and OTHERPOS,
  ;; we end up messing up the conflict markers.  We should merge the
  ;; conflicts instead!
  (condition-case err
      (smerge-match-conflict)
    (error (if (not (markerp otherpos)) (signal (car err) (cdr err))
             (goto-char (prog1 otherpos (setq otherpos (point-marker))))
             (smerge-match-conflict))))
  (let ((beg (match-beginning 0))
        (end (copy-marker (match-end 0)))
        text)
    (when (integerp otherpos)
      (goto-char (if (>= otherpos 0) end beg))
      (setq otherpos (copy-marker (line-beginning-position (+ otherpos 1)))))
    (setq text (cond
                ((<= end otherpos)
                 (buffer-substring end otherpos))
                ((<= otherpos beg)
                 (buffer-substring otherpos beg))
                (t (user-error "The other end should be outside the conflict"))))
    (dotimes (i 3)
      (let* ((mn (- 3 i))
             (me (funcall (if (<= end otherpos) #'match-end #'match-beginning)
                          mn)))
       (when me
        (goto-char me)
        (insert text))))
    (delete-region (if (<= end otherpos) end beg) otherpos)))