1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-03 11:33:37 +00:00

Do highlighting of alternative matches all at once,

but only do it in the text that's visible in the selected window.

(isearch-lazy-highlight-cleanup): Arg now says
to remove all the current alternative-match highlighting.
If nil, remove only what's outside the current window.
(isearch-lazy-highlight-remove-overlays): Take optional
region within which NOT to remove them.
(isearch-lazy-highlight-new-loop): Greatly simplified.
(isearch-lazy-highlight-update): Find all the other occurrences
visible in the window, in just one call.

(isearch-lazy-highlight-start): Now holds start of region to scan.
(isearch-lazy-highlight-end): Now holds end of region to scan.
(isearch-lazy-highlight-wrapped): Variable deleted.
(isearch-lazy-highlight-search): Function deleted.
This commit is contained in:
Richard M. Stallman 2001-01-03 00:18:53 +00:00
parent eff409bad3
commit 67ecad4e09

View File

@ -641,7 +641,7 @@ is treated as a regexp. See \\[isearch-forward] for more info."
;; (setq pre-command-hook isearch-old-pre-command-hook) ; for lemacs ;; (setq pre-command-hook isearch-old-pre-command-hook) ; for lemacs
(setq minibuffer-message-timeout isearch-original-minibuffer-message-timeout) (setq minibuffer-message-timeout isearch-original-minibuffer-message-timeout)
(isearch-dehighlight t) (isearch-dehighlight t)
(isearch-lazy-highlight-cleanup) (isearch-lazy-highlight-cleanup isearch-lazy-highlight-cleanup)
(let ((found-start (window-start (selected-window))) (let ((found-start (window-start (selected-window)))
(found-point (point))) (found-point (point)))
(if isearch-window-configuration (if isearch-window-configuration
@ -1895,90 +1895,96 @@ If this is nil, extra highlighting can be \"manually\" removed with
(defvar isearch-lazy-highlight-face 'isearch-lazy-highlight-face) (defvar isearch-lazy-highlight-face 'isearch-lazy-highlight-face)
(defvar isearch-lazy-highlight-overlays nil) (defvar isearch-lazy-highlight-overlays nil)
(defvar isearch-lazy-highlight-wrapped nil) (defvar isearch-lazy-highlight-window nil)
(defvar isearch-lazy-highlight-start nil) (defvar isearch-lazy-highlight-start nil)
(defvar isearch-lazy-highlight-end nil) (defvar isearch-lazy-highlight-end nil)
(defvar isearch-lazy-highlight-timer nil) (defvar isearch-lazy-highlight-timer nil)
(defvar isearch-lazy-highlight-last-string nil) (defvar isearch-lazy-highlight-last-string nil)
(defun isearch-lazy-highlight-cleanup (&optional force) (defun isearch-lazy-highlight-cleanup (&optional remove)
"Stop lazy highlighting and remove extra highlighting from current buffer. "Stop lazy highlighting and maybe remove existing highlighting.
FORCE non-nil means do it whether or not `isearch-lazy-highlight-cleanup' REMOVE non-nil means remove all the existing lazy highlighting.
is nil. This function is called when exiting an incremental search if
`isearch-lazy-highlight-cleanup' is non-nil." This function is called when exiting an incremental search."
(interactive '(t)) (interactive '(t))
(if (or force isearch-lazy-highlight-cleanup) (if remove
(isearch-lazy-highlight-remove-overlays)) (isearch-lazy-highlight-remove-overlays))
(if isearch-lazy-highlight-timer (if isearch-lazy-highlight-timer
(progn (progn
(cancel-timer isearch-lazy-highlight-timer) (cancel-timer isearch-lazy-highlight-timer)
(setq isearch-lazy-highlight-timer nil)))) (setq isearch-lazy-highlight-timer nil))))
(defun isearch-lazy-highlight-remove-overlays () (defun isearch-lazy-highlight-remove-overlays (&optional keep-start keep-end)
"Remove lazy highlight overlays from the current buffer." "Remove lazy highlight overlays from the current buffer.
(while isearch-lazy-highlight-overlays With optional arguments KEEP-START and KEEP-END,
(delete-overlay (car isearch-lazy-highlight-overlays)) prserve any overlays in that range."
(setq isearch-lazy-highlight-overlays (let ((tem isearch-lazy-highlight-overlays))
(cdr isearch-lazy-highlight-overlays)))) (while tem
(if (or (null keep-start)
(let ((pos (overlay-start (car tem))))
(or (< pos keep-start) (> pos keep-end))))
(progn
(delete-overlay (car tem))
(setq isearch-lazy-highlight-overlays
(delq (car tem) isearch-lazy-highlight-overlays))))
(setq tem (cdr tem)))))
(defun isearch-lazy-highlight-new-loop () (defun isearch-lazy-highlight-new-loop ()
"Cleanup any previous `isearch-lazy-highlight' loop and begin a new one. "Clear obsolete highlighting, and queue up to do new highlighting.
This happens when `isearch-update' is invoked (which can cause the This happens when `isearch-update' is invoked (which can cause the
search string to change)." search string to change)."
(if (and isearch-lazy-highlight (when (and isearch-lazy-highlight
(not (equal isearch-string isearch-lazy-highlight-last-string))) (not isearch-invalid-regexp)
;; the search string did indeed change (not (equal isearch-string "")))
(progn
(isearch-lazy-highlight-cleanup t) ;kill old loop & remove overlays
(if (and isearch-overlay
(not (overlay-get isearch-overlay 'priority)))
;; make sure the isearch-overlay takes priority
(overlay-put isearch-overlay 'priority 1))
(setq isearch-lazy-highlight-start isearch-opoint
isearch-lazy-highlight-end isearch-opoint
isearch-lazy-highlight-last-string isearch-string
isearch-lazy-highlight-wrapped nil)
(setq isearch-lazy-highlight-timer
(run-with-idle-timer isearch-lazy-highlight-initial-delay nil
'isearch-lazy-highlight-update)))))
(defun isearch-lazy-highlight-search () ;; If the search string has changed, remove all old overlays.
"Search ahead for the next or previous match, for lazy highlighting. (unless (equal isearch-string isearch-lazy-highlight-last-string)
Attempt to do the search exactly the way the pending isearch would." (isearch-lazy-highlight-remove-overlays)
(let ((case-fold-search isearch-case-fold-search)) (setq isearch-lazy-highlight-window nil))
(funcall (cond (isearch-word (if isearch-forward
'word-search-forward (if (and isearch-overlay
'word-search-backward)) (not (overlay-get isearch-overlay 'priority)))
(isearch-regexp (if isearch-forward ;; Make sure the isearch-overlay takes priority
're-search-forward ;; over any other matches.
're-search-backward)) (overlay-put isearch-overlay 'priority 1))
(t (if isearch-forward
'search-forward ;; Queue up to display other matches after a short pause.
'search-backward))) (setq isearch-lazy-highlight-timer
isearch-string (run-with-idle-timer isearch-lazy-highlight-initial-delay nil
(if isearch-forward 'isearch-lazy-highlight-update))))
(if isearch-lazy-highlight-wrapped
isearch-lazy-highlight-start
nil)
(if isearch-lazy-highlight-wrapped
isearch-lazy-highlight-end
nil))
t)))
(defun isearch-lazy-highlight-update () (defun isearch-lazy-highlight-update ()
"Find and highlight the next match in the lazy highlighting loop." "Update highlighting of possible other matchesfor isearch."
(when (and (not isearch-invalid-regexp) (unless (and (eq isearch-lazy-highlight-window (selected-window))
(or (null isearch-lazy-highlight-max) (equal isearch-lazy-highlight-start (window-start)))
(< (length isearch-lazy-highlight-overlays)
isearch-lazy-highlight-max))) ;; The search string or the visible window has changed.
(save-excursion
(save-match-data (setq isearch-lazy-highlight-window (selected-window)
(goto-char (if isearch-forward isearch-lazy-highlight-start (window-start)
isearch-lazy-highlight-end isearch-lazy-highlight-end (window-end nil t)
isearch-lazy-highlight-start)) isearch-lazy-highlight-last-string isearch-string)
(let ((found (isearch-lazy-highlight-search))) ;do search
(if found ;; If the string is the same, the old overlays are still usable
;; found the next match ;; if they are still visible in the window.
(isearch-lazy-highlight-remove-overlays (window-start)
(window-end nil t))
(when (or (null isearch-lazy-highlight-max)
(< (length isearch-lazy-highlight-overlays)
isearch-lazy-highlight-max))
(save-excursion
(save-match-data
(let (found)
(goto-char isearch-lazy-highlight-start)
(while (let ((case-fold-search isearch-case-fold-search))
(funcall (cond (isearch-word 'word-search-forward)
(isearch-regexp 're-search-forward)
(t 'search-forward))
isearch-string
isearch-lazy-highlight-end
t))
;; Found the next match.
(let ((ov (make-overlay (match-beginning 0) (let ((ov (make-overlay (match-beginning 0)
(match-end 0)))) (match-end 0))))
;; If OV overlaps the current isearch overlay, suppress ;; If OV overlaps the current isearch overlay, suppress
@ -1989,26 +1995,10 @@ Attempt to do the search exactly the way the pending isearch would."
(overlay-put ov 'face isearch-lazy-highlight-face)) (overlay-put ov 'face isearch-lazy-highlight-face))
(overlay-put ov 'priority 0) (overlay-put ov 'priority 0)
;; Don't highlight on any other windows.
(overlay-put ov 'window isearch-lazy-highlight-window)
(push ov isearch-lazy-highlight-overlays) (push ov isearch-lazy-highlight-overlays)))))))))
(setq isearch-lazy-highlight-timer
(run-at-time isearch-lazy-highlight-interval nil
'isearch-lazy-highlight-update))
(if isearch-forward
(setq isearch-lazy-highlight-end (point))
(setq isearch-lazy-highlight-start (point))))
;; found no next match
(when (not isearch-lazy-highlight-wrapped)
;; let's try wrapping around the end of the buffer
(setq isearch-lazy-highlight-wrapped t)
(setq isearch-lazy-highlight-timer
(run-at-time isearch-lazy-highlight-interval nil
'isearch-lazy-highlight-update))
(if isearch-forward
(setq isearch-lazy-highlight-end (point-min))
(setq isearch-lazy-highlight-start (point-max))))))))))
(defun isearch-resume (search regexp word forward message case-fold) (defun isearch-resume (search regexp word forward message case-fold)
"Resume an incremental search. "Resume an incremental search.