Function: smerge-refine-regions

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

Signature

(smerge-refine-regions BEG1 END1 BEG2 END2 PROPS-C &optional PREPROC PROPS-R PROPS-A)

Documentation

Show fine differences in the two regions BEG1..END1 and BEG2..END2.

PROPS-C is an alist of properties to put (via overlays) on the changes. PROPS-R is an alist of properties to put on removed characters. PROPS-A is an alist of properties to put on added characters. If PROPS-R and PROPS-A are nil, put PROPS-C on all changes. If PROPS-C is nil, but PROPS-R and PROPS-A are non-nil, put PROPS-A on added characters, PROPS-R on removed characters. If PROPS-C, PROPS-R and PROPS-A are non-nil, put PROPS-C on changed characters, PROPS-A on added characters, and PROPS-R on removed characters.

If non-nil, PREPROC is called with no argument in a buffer that contains a copy of a region, just before preparing it to for diff. It can be used to replace chars to try and eliminate some spurious differences. The two regions can be in different buffers (in which case, BEG1 and BEG2 need to be markers to indicate the corresponding buffers).

Probably introduced at or before Emacs version 26.1.

Aliases

smerge-refine-subst (obsolete since 26.1)

Source Code

;; Defined in /usr/src/emacs/lisp/vc/smerge-mode.el.gz
;;;###autoload
(defun smerge-refine-regions (beg1 end1 beg2 end2 props-c &optional preproc props-r props-a)
  "Show fine differences in the two regions BEG1..END1 and BEG2..END2.
PROPS-C is an alist of properties to put (via overlays) on the changes.
PROPS-R is an alist of properties to put on removed characters.
PROPS-A is an alist of properties to put on added characters.
If PROPS-R and PROPS-A are nil, put PROPS-C on all changes.
If PROPS-C is nil, but PROPS-R and PROPS-A are non-nil,
put PROPS-A on added characters, PROPS-R on removed characters.
If PROPS-C, PROPS-R and PROPS-A are non-nil, put PROPS-C on changed characters,
PROPS-A on added characters, and PROPS-R on removed characters.

If non-nil, PREPROC is called with no argument in a buffer that contains
a copy of a region, just before preparing it to for `diff'.  It can be
used to replace chars to try and eliminate some spurious differences.
The two regions can be in different buffers (in which case, BEG1 and BEG2
need to be markers to indicate the corresponding buffers)."
  (pcase-let*
      ;; Cover the two regions with one `smerge--refine-region' overlay each.
      ((ol1 (make-overlay beg1 end1 (if (markerp beg1) (marker-buffer beg1))
                          ;; Make it shrink rather than spread when editing.
                          'front-advance nil))
       (ol2 (make-overlay beg2 end2 (if (markerp beg2) (marker-buffer beg2))
                          ;; Make it shrink rather than spread when editing.
                          'front-advance nil))
       (`(,file1 ,file2) (smerge--refine-prepare-regions ol1 ol2 preproc)))
    (smerge--refine-set-overlay-props ol1 ol2 props-c props-r props-a)

    ;; Call diff on those files.
    (with-temp-buffer
      ;; Allow decoding the EOL format, as on MS-Windows the Diff
      ;; utility might produce CR-LF EOLs.
      (let ((coding-system-for-read 'utf-8-emacs))
        (unwind-protect
            (call-process diff-command nil t nil
                          (if (and smerge-refine-ignore-whitespace
                                   (not smerge-refine-weight-hack))
                              ;; Pass -a so diff treats it as a text file even
                              ;; if it contains \0 and such.
                              ;; Pass -d so as to get the smallest change, but
                              ;; also and more importantly because otherwise it
                              ;; may happen that diff doesn't behave like
                              ;; smerge-refine-weight-hack expects it to.
                              ;; See https://lists.gnu.org/r/emacs-devel/2007-11/msg00401.html
                              "-awd" "-ad")
                          file1 file2)
          (delete-file file1)
          (delete-file file2)))
      ;; Process diff's output.
      (smerge--refine-apply-diff (current-buffer) ol1 ol2
                                 props-c props-r props-a))))