Function: smerge-refine

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

Signature

(smerge-refine &optional PART)

Documentation

Highlight the words of the conflict that are different.

For 3-way conflicts, highlights only two of the three parts. A numeric argument PART can be used to specify which two parts; repeating the command will highlight other two parts.

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-refine (&optional part)
  "Highlight the words of the conflict that are different.
For 3-way conflicts, highlights only two of the three parts.
A numeric argument PART can be used to specify which two parts;
repeating the command will highlight other two parts."
  (interactive
   (if (integerp current-prefix-arg) (list current-prefix-arg)
     (smerge-match-conflict)
     (let* ((prop (get-text-property (match-beginning 0) 'smerge-refine-part))
            (part (if (and (consp prop)
                           (eq (buffer-chars-modified-tick) (car prop)))
                      (cdr prop))))
       ;; If already highlighted, cycle.
       (list (if (integerp part) (1+ (mod part 3)))))))

  (if (and (integerp part) (or (< part 1) (> part 3)))
      (error "No conflict part nb %s" part))
  (smerge-match-conflict)
  (remove-overlays (match-beginning 0) (match-end 0) 'smerge 'refine)
  ;; Ignore `part' if not applicable, and default it if not provided.
  (setq part (cond ((null (match-end 2)) 2)
                   ((eq (match-end 1) (match-end 3)) 1)
                   ((integerp part) part)
                   ;; If one of the parts is empty, any refinement using
                   ;; it will be trivial and uninteresting.
                   ((eq (match-end 1) (match-beginning 1)) 1)
                   ((eq (match-end 3) (match-beginning 3)) 3)
                   (t 2)))
  (let ((n1 (if (eq part 1) 2 1))
        (n2 (if (eq part 3) 2 3))
	(smerge-use-changed-face
	 (and (face-differs-from-default-p 'smerge-refined-change)
	      (not (face-equal 'smerge-refined-change 'smerge-refined-added))
	      (not (face-equal 'smerge-refined-change 'smerge-refined-removed)))))
    (smerge-ensure-match n1)
    (smerge-ensure-match n2)
    (with-silent-modifications
      (put-text-property (match-beginning 0) (1+ (match-beginning 0))
                         'smerge-refine-part
                         (cons (buffer-chars-modified-tick) part)))
    (smerge-refine-regions (match-beginning n1) (match-end n1)
                         (match-beginning n2)  (match-end n2)
                         (if smerge-use-changed-face
			     '((smerge . refine) (font-lock-face . smerge-refined-change)))
			 nil
			 (unless smerge-use-changed-face
			   '((smerge . refine) (font-lock-face . smerge-refined-removed)))
			 (unless smerge-use-changed-face
			   '((smerge . refine) (font-lock-face . smerge-refined-added))))))