Function: evil-ex-hl-update-highlights
evil-ex-hl-update-highlights is a byte-compiled function defined in
evil-search.el.
Signature
(evil-ex-hl-update-highlights)
Documentation
Update the overlays of all active highlights.
Source Code
;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-search.el
(defun evil-ex-hl-update-highlights ()
"Update the overlays of all active highlights."
(dolist (hl (mapcar #'cdr evil-ex-active-highlights-alist))
(let* ((old-ovs (evil-ex-hl-overlays hl))
new-ovs
(pattern (evil-ex-hl-pattern hl))
(case-fold-search (evil-ex-pattern-ignore-case pattern))
(case-replace case-fold-search)
(face (evil-ex-hl-face hl))
(match-hook (evil-ex-hl-match-hook hl))
result)
(if pattern
;; collect all visible ranges
(let (ranges sranges)
(dolist (win (if (eq evil-ex-interactive-search-highlight
'all-windows)
(get-buffer-window-list (current-buffer) nil t)
(list (evil-ex-hl-window hl))))
(when (window-live-p win)
(let ((beg (max (window-start win)
(or (evil-ex-hl-min hl) (point-min))))
(end (min (window-end win)
(or (evil-ex-hl-max hl) (point-max)))))
(when (< beg end)
(push (cons beg end) ranges)))))
(setq ranges (sort ranges #'car-less-than-car))
(while ranges
(let ((r1 (pop ranges))
(r2 (pop ranges)))
(cond
;; last range
((null r2) (push r1 sranges))
;; ranges overlap, union
((>= (cdr r1) (car r2))
(push (cons (car r1)
(max (cdr r1) (cdr r2)))
ranges))
;; ranges distinct
(t (push r1 sranges)
(push r2 ranges)))))
;; run through all ranges
(condition-case lossage
(save-match-data
(dolist (r sranges)
(let ((beg (car r))
(end (cdr r)))
(save-excursion
(goto-char beg)
;; set the overlays for the current highlight,
;; reusing old overlays (if possible)
(while (and (not (eobp))
(evil-ex-search-find-next-pattern pattern)
(<= (match-end 0) end)
(not (and (= (match-beginning 0) end)
(save-excursion
(goto-char (match-beginning 0))
(bolp)))))
(let ((ov (or (pop old-ovs) (make-overlay 0 0))))
(move-overlay ov (match-beginning 0) (match-end 0))
(overlay-put ov 'face face)
(overlay-put ov 'evil-ex-hl (evil-ex-hl-name hl))
(overlay-put ov 'priority 1000)
(push ov new-ovs)
(when match-hook (funcall match-hook hl ov)))
(cond
((not (or (evil-ex-pattern-whole-line pattern)
(save-excursion
(goto-char (match-beginning 0))
(search-forward "\n" (match-end 0) t))))
(forward-line))
((= (match-beginning 0) (match-end 0))
(forward-char))
(t (goto-char (match-end 0))))))))
(mapc #'delete-overlay old-ovs)
(setf (evil-ex-hl-overlays hl) new-ovs)
(if (or (null pattern) new-ovs)
(setq result t)
;; Maybe the match could just not be found somewhere else?
(save-excursion
(goto-char (or (evil-ex-hl-min hl) (point-min)))
(if (and (evil-ex-search-find-next-pattern pattern)
(< (match-end 0) (or (evil-ex-hl-max hl)
(point-max))))
(setq result (format "Match in line %d"
(line-number-at-pos
(match-beginning 0))))
(setq result "No match")))))
(invalid-regexp (setq result (cadr lossage)))
(search-failed (setq result (nth 2 lossage)))
(error (setq result (format "%s" (cadr lossage))))))
;; no pattern, remove all highlights
(mapc #'delete-overlay old-ovs)
(setf (evil-ex-hl-overlays hl) new-ovs))
(when (evil-ex-hl-update-hook hl)
(funcall (evil-ex-hl-update-hook hl) hl result)))))