Function: replace-highlight

replace-highlight is a byte-compiled function defined in replace.el.gz.

Signature

(replace-highlight MATCH-BEG MATCH-END RANGE-BEG RANGE-END SEARCH-STRING REGEXP-FLAG DELIMITED-FLAG CASE-FOLD &optional BACKWARD)

Documentation

This function has :before advice: preview--open-for-replace.

Source Code

;; Defined in /usr/src/emacs/lisp/replace.el.gz
(defun replace-highlight (match-beg match-end range-beg range-end
			  search-string regexp-flag delimited-flag
			  case-fold &optional backward)
  (if query-replace-highlight
      (if replace-overlay
	  (move-overlay replace-overlay match-beg match-end (current-buffer))
	(setq replace-overlay (make-overlay match-beg match-end))
	(overlay-put replace-overlay 'priority 1001) ;higher than lazy overlays
	(overlay-put replace-overlay 'face 'query-replace)))

  (when (and query-replace-highlight-submatches regexp-flag)
    (mapc 'delete-overlay replace-submatches-overlays)
    (setq replace-submatches-overlays nil)
    ;; 'cddr' removes whole expression match from match-data
    (let ((submatch-data (cddr (match-data t)))
          (group 0)
          b e ov face)
      (while submatch-data
        (setq b (pop submatch-data)
              e (pop submatch-data))
        (when (and (integer-or-marker-p b)
                   (integer-or-marker-p e))
          (setq ov (make-overlay b e)
                group (1+ group)
                face (intern-soft (format "isearch-group-%d" group)))
          ;; Recycle faces from beginning
          (unless (facep face)
            (setq group 1 face 'isearch-group-1))
          (overlay-put ov 'face face)
          (overlay-put ov 'priority 1002)
          (push ov replace-submatches-overlays)))))

  (if query-replace-lazy-highlight
      (let ((isearch-string search-string)
	    (isearch-regexp regexp-flag)
	    (isearch-regexp-function (or replace-regexp-function
					 delimited-flag
					 (and replace-char-fold
					      (not regexp-flag)
					      #'char-fold-to-regexp)))
	    (isearch-lax-whitespace
	     replace-lax-whitespace)
	    (isearch-regexp-lax-whitespace
	     replace-regexp-lax-whitespace)
	    (isearch-case-fold-search case-fold)
	    (isearch-forward (not backward))
	    (isearch-other-end match-beg)
	    (isearch-error nil)
	    (isearch-lazy-count nil)
	    (lazy-highlight-buffer nil))
	(isearch-lazy-highlight-new-loop range-beg range-end))))