Function: consult--highlight-regexps

consult--highlight-regexps is a byte-compiled function defined in consult.el.

Signature

(consult--highlight-regexps REGEXPS IGNORE-CASE STR)

Documentation

Highlight REGEXPS (or single regexp string) in STR.

If a regular expression contains capturing groups, only these are highlighted. If no capturing groups are used highlight the whole match. Case is ignored if IGNORE-CASE is non-nil.

Source Code

;; Defined in ~/.emacs.d/elpa/consult-20260805.1130/consult.el
(defun consult--highlight-regexps (regexps ignore-case str)
  "Highlight REGEXPS (or single regexp string) in STR.
If a regular expression contains capturing groups, only these are highlighted.
If no capturing groups are used highlight the whole match.  Case is ignored
if IGNORE-CASE is non-nil."
  (dolist (re (ensure-list regexps))
    (let ((i 0))
      (while (and (let ((case-fold-search ignore-case))
                    (string-match re str i))
                  ;; Ensure that regexp search made progress (edge case for .*)
                  (> (match-end 0) i))
        ;; Unfortunately there is no way to avoid the allocation of the match
        ;; data, since the number of capturing groups is unknown.
        (let ((m (match-data)))
          (setq i (cadr m) m (or (cddr m) m))
          (while m
            (when (car m)
              (add-face-text-property (car m) (cadr m)
                                      'consult-highlight-match nil str))
            (setq m (cddr m)))))))
  str)