Function: minibuffer-lazy-highlight-setup

minibuffer-lazy-highlight-setup is a byte-compiled function defined in isearch.el.gz.

Signature

(minibuffer-lazy-highlight-setup &key (HIGHLIGHT isearch-lazy-highlight) (CLEANUP lazy-highlight-cleanup) (TRANSFORM #'identity) (FILTER nil) (REGEXP isearch-regexp) (REGEXP-FUNCTION isearch-regexp-function) (CASE-FOLD isearch-case-fold-search) (LAX-WHITESPACE (if regexp isearch-regexp-lax-whitespace isearch-lax-whitespace)))

Documentation

Set up minibuffer for lazy highlight of matches in the original window.

This function return a closure intended to be added to minibuffer-setup-hook. It accepts the following keyword arguments, all of which have a default based on the current isearch settings.

HIGHLIGHT: Whether to perform lazy highlight. CLEANUP: Whether to clean up the lazy highlight when the minibuffer exits. TRANSFORM: A function taking one argument, the minibuffer contents, and returning the isearch-string to use for lazy highlighting. FILTER: A function to add to isearch-filter-predicate. REGEXP: The value of isearch-regexp to use for lazy highlighting. REGEXP-FUNCTION: The value of isearch-regexp-function to use for lazy highlighting. CASE-FOLD: The value of isearch-case-fold to use for lazy highlighting. LAX-WHITESPACE: The value of isearch-lax-whitespace and isearch-regexp-lax-whitespace to use for lazy highlighting.

Probably introduced at or before Emacs version 29.1.

Source Code

;; Defined in /usr/src/emacs/lisp/isearch.el.gz
(cl-defun minibuffer-lazy-highlight-setup
    (&key (highlight isearch-lazy-highlight)
          (cleanup lazy-highlight-cleanup)
          (transform #'identity)
          (filter nil)
          (regexp isearch-regexp)
          (regexp-function isearch-regexp-function)
          (case-fold isearch-case-fold-search)
          (lax-whitespace (if regexp
                              isearch-regexp-lax-whitespace
                            isearch-lax-whitespace)))
  "Set up minibuffer for lazy highlight of matches in the original window.

This function return a closure intended to be added to
`minibuffer-setup-hook'.  It accepts the following keyword
arguments, all of which have a default based on the current
isearch settings.

HIGHLIGHT: Whether to perform lazy highlight.
CLEANUP: Whether to clean up the lazy highlight when the minibuffer
exits.
TRANSFORM: A function taking one argument, the minibuffer contents,
and returning the `isearch-string' to use for lazy highlighting.
FILTER: A function to add to `isearch-filter-predicate'.
REGEXP: The value of `isearch-regexp' to use for lazy highlighting.
REGEXP-FUNCTION: The value of `isearch-regexp-function' to use for
lazy highlighting.
CASE-FOLD: The value of `isearch-case-fold' to use for lazy
highlighting.
LAX-WHITESPACE: The value of `isearch-lax-whitespace' and
`isearch-regexp-lax-whitespace' to use for lazy highlighting."
  (if (or (not highlight) (minibufferp))
      #'ignore
    (let ((unwind (make-symbol "minibuffer-lazy-highlight--unwind"))
          (after-change (make-symbol "minibuffer-lazy-highlight--after-change"))
          (display-count (make-symbol "minibuffer-lazy-highlight--display-count"))
          (buffer (current-buffer))
          overlay)
      (fset unwind
            (lambda ()
              (when filter
                (with-current-buffer buffer
                  (remove-function (local 'isearch-filter-predicate) filter)))
              (remove-hook 'lazy-count-update-hook display-count)
              (when overlay (delete-overlay overlay))
              (remove-hook 'after-change-functions after-change t)
              (remove-hook 'minibuffer-exit-hook unwind t)
              (let ((lazy-highlight-cleanup cleanup))
                (lazy-highlight-cleanup))))
      (fset after-change
            (lambda (_beg _end _len)
              (let ((inhibit-redisplay t) ;; Avoid cursor flickering
                    (string (minibuffer-contents)))
                (with-minibuffer-selected-window
                  (let* ((isearch-forward t)
                         (isearch-regexp regexp)
                         (isearch-regexp-function regexp-function)
                         (isearch-case-fold-search case-fold)
                         (isearch-lax-whitespace lax-whitespace)
                         (isearch-regexp-lax-whitespace lax-whitespace)
                         (isearch-string (funcall transform string)))
                    (isearch-lazy-highlight-new-loop))))))
      (fset display-count
            (lambda ()
              (overlay-put overlay 'before-string
                           (and isearch-lazy-count-total
                                (not isearch-error)
                                (format minibuffer-lazy-count-format
                                        isearch-lazy-count-total)))))
      (lambda ()
        (add-hook 'minibuffer-exit-hook unwind nil t)
        (add-hook 'after-change-functions after-change nil t)
        (when minibuffer-lazy-count-format
          (setq overlay (make-overlay (point-min) (point-min) (current-buffer) t))
          (add-hook 'lazy-count-update-hook display-count))
        (when filter
          (with-current-buffer buffer
            (add-function :after-while (local 'isearch-filter-predicate) filter)))
        (funcall after-change nil nil nil)))))