Function: isearch-lazy-highlight-new-loop

isearch-lazy-highlight-new-loop is a byte-compiled function defined in isearch.el.gz.

Signature

(isearch-lazy-highlight-new-loop &optional BEG END)

Documentation

Cleanup any previous lazy-highlight loop and begin a new one.

BEG and END specify the bounds within which highlighting should occur. This is called when isearch-update is invoked (which can cause the search string to change or the window to scroll). It is also used by other Emacs features.

Source Code

;; Defined in /usr/src/emacs/lisp/isearch.el.gz
(defun isearch-lazy-highlight-new-loop (&optional beg end)
  "Cleanup any previous `lazy-highlight' loop and begin a new one.
BEG and END specify the bounds within which highlighting should occur.
This is called when `isearch-update' is invoked (which can cause the
search string to change or the window to scroll).  It is also used
by other Emacs features."
  (when (and (null executing-kbd-macro)
             (sit-for 0)         ;make sure (window-start) is credible
             (or (not (equal isearch-string
                             isearch-lazy-highlight-last-string))
                 (not (memq (selected-window)
                            isearch-lazy-highlight-window-group))
		 (not (eq isearch-lazy-highlight-case-fold-search
			  isearch-case-fold-search))
		 (not (eq isearch-lazy-highlight-regexp
			  isearch-regexp))
		 (not (eq isearch-lazy-highlight-regexp-function
			  isearch-regexp-function))
		 (not (eq isearch-lazy-highlight-lax-whitespace
			  isearch-lax-whitespace))
		 (not (eq isearch-lazy-highlight-regexp-lax-whitespace
			  isearch-regexp-lax-whitespace))
		 (not (eq isearch-forward
			  isearch-lazy-highlight-forward))
		 ;; In case we are recovering from an error.
		 (not (equal isearch-error
			     isearch-lazy-highlight-error))
		 (if lazy-highlight-buffer
		     (not (= (point-min)
			     isearch-lazy-highlight-point-min))
		   (setq isearch-lazy-highlight-window-start-changed
			 (not (= (window-group-start)
                                 isearch-lazy-highlight-window-start))))
		 (if lazy-highlight-buffer
		     (not (= (point-max)
			     isearch-lazy-highlight-point-max))
		   (setq isearch-lazy-highlight-window-end-changed
			 (not (= (window-group-end) ; Window may have been split/joined.
                                 isearch-lazy-highlight-window-end))))))
    ;; something important did indeed change
    (lazy-highlight-cleanup t (not (equal isearch-string ""))) ;stop old timer
    (when (and isearch-lazy-count isearch-mode (null isearch-message-function))
      (when (or (equal isearch-string "")
                ;; Check if this place was reached by a condition above
                ;; other than changed window boundaries (that shouldn't
                ;; reset the counter)
                (and (not isearch-lazy-highlight-window-start-changed)
                     (not isearch-lazy-highlight-window-end-changed))
                ;; Also check for changes in buffer boundaries in
                ;; a possibly narrowed buffer in case lazy-highlight-buffer
                ;; is nil, thus the same check was not performed above
                (not (= (point-min)
                        isearch-lazy-highlight-point-min))
                (not (= (point-max)
                        isearch-lazy-highlight-point-max)))
        ;; Reset old counter before going to count new numbers
        (clrhash isearch-lazy-count-hash)
        (setq isearch-lazy-count-current nil
              isearch-lazy-count-total nil)
        ;; Delay updating the message if possible, to avoid flicker
        (when (string-equal isearch-string "") (isearch-message))))
    (setq isearch-lazy-highlight-window-start-changed nil)
    (setq isearch-lazy-highlight-window-end-changed nil)
    (setq isearch-lazy-highlight-error isearch-error)
    ;; It used to check for `(not isearch-error)' here, but actually
    ;; lazy-highlighting might find matches to highlight even when
    ;; `isearch-error' is non-nil.  (Bug#9918)
    (setq isearch-lazy-highlight-start-limit beg
	  isearch-lazy-highlight-end-limit end)
    (setq isearch-lazy-highlight-window       (selected-window)
          isearch-lazy-highlight-window-group (selected-window-group)
	  isearch-lazy-highlight-window-start (window-group-start)
	  isearch-lazy-highlight-window-end   (window-group-end)
	  isearch-lazy-highlight-point-min    (point-min)
	  isearch-lazy-highlight-point-max    (point-max)
	  isearch-lazy-highlight-buffer       lazy-highlight-buffer
	  ;; Start lazy-highlighting at the beginning of the found
	  ;; match (`isearch-other-end').  If no match, use point.
	  ;; One of the next two variables (depending on search direction)
	  ;; is used to define the starting position of lazy-highlighting
	  ;; and also to remember the current position of point between
	  ;; calls of `isearch-lazy-highlight-update', and another variable
	  ;; is used to define where the wrapped search must stop.
	  isearch-lazy-highlight-start        (or isearch-other-end (point))
	  isearch-lazy-highlight-end          (or isearch-other-end (point))
	  isearch-lazy-highlight-wrapped      nil
	  isearch-lazy-highlight-last-string  isearch-string
	  isearch-lazy-highlight-case-fold-search isearch-case-fold-search
	  isearch-lazy-highlight-regexp       isearch-regexp
	  isearch-lazy-highlight-lax-whitespace   isearch-lax-whitespace
	  isearch-lazy-highlight-regexp-lax-whitespace isearch-regexp-lax-whitespace
	  isearch-lazy-highlight-regexp-function  isearch-regexp-function
	  isearch-lazy-highlight-forward      isearch-forward)
    ;; Extend start/end to match whole string at point (bug#19353)
    (if isearch-lazy-highlight-forward
        (setq isearch-lazy-highlight-start
	      (min (+ isearch-lazy-highlight-start
		      (1- (length isearch-lazy-highlight-last-string)))
		   (point-max)))
      (setq isearch-lazy-highlight-end
	    (max (- isearch-lazy-highlight-end
		    (1- (length isearch-lazy-highlight-last-string)))
		 (point-min))))
    (unless (equal isearch-string "")
      (setq isearch-lazy-highlight-timer
            (run-with-idle-timer (if (>= (length isearch-string)
                                         lazy-highlight-no-delay-length)
                                     0
                                   lazy-highlight-initial-delay)
                                 nil
                                 'isearch-lazy-highlight-start))))
  ;; Update the current match number only in isearch-mode and
  ;; unless isearch-mode is used specially with isearch-message-function
  (when (and isearch-lazy-count isearch-mode (null isearch-message-function))
    ;; Update isearch-lazy-count-current only when it was already set
    ;; at the end of isearch-lazy-highlight-buffer-update
    (when isearch-lazy-count-current
      (setq isearch-lazy-count-current
            (gethash (point) isearch-lazy-count-hash 0))
      (isearch-message))))