comparison lisp/isearch.el @ 35012:444b43c38978

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.
author Richard M. Stallman <rms@gnu.org>
date Wed, 03 Jan 2001 00:18:53 +0000
parents dab8fe8d55f4
children cfac1ece4f23
comparison
equal deleted inserted replaced
35011:11e866e5a825 35012:444b43c38978
639 ;; If NOPUSH is non-nil, we don't push the string on the search ring. 639 ;; If NOPUSH is non-nil, we don't push the string on the search ring.
640 (setq overriding-terminal-local-map nil) 640 (setq overriding-terminal-local-map nil)
641 ;; (setq pre-command-hook isearch-old-pre-command-hook) ; for lemacs 641 ;; (setq pre-command-hook isearch-old-pre-command-hook) ; for lemacs
642 (setq minibuffer-message-timeout isearch-original-minibuffer-message-timeout) 642 (setq minibuffer-message-timeout isearch-original-minibuffer-message-timeout)
643 (isearch-dehighlight t) 643 (isearch-dehighlight t)
644 (isearch-lazy-highlight-cleanup) 644 (isearch-lazy-highlight-cleanup isearch-lazy-highlight-cleanup)
645 (let ((found-start (window-start (selected-window))) 645 (let ((found-start (window-start (selected-window)))
646 (found-point (point))) 646 (found-point (point)))
647 (if isearch-window-configuration 647 (if isearch-window-configuration
648 (set-window-configuration isearch-window-configuration)) 648 (set-window-configuration isearch-window-configuration))
649 649
1893 "Face for lazy highlighting of matches." 1893 "Face for lazy highlighting of matches."
1894 :group 'isearch-faces) 1894 :group 'isearch-faces)
1895 (defvar isearch-lazy-highlight-face 'isearch-lazy-highlight-face) 1895 (defvar isearch-lazy-highlight-face 'isearch-lazy-highlight-face)
1896 1896
1897 (defvar isearch-lazy-highlight-overlays nil) 1897 (defvar isearch-lazy-highlight-overlays nil)
1898 (defvar isearch-lazy-highlight-wrapped nil) 1898 (defvar isearch-lazy-highlight-window nil)
1899 (defvar isearch-lazy-highlight-start nil) 1899 (defvar isearch-lazy-highlight-start nil)
1900 (defvar isearch-lazy-highlight-end nil) 1900 (defvar isearch-lazy-highlight-end nil)
1901 (defvar isearch-lazy-highlight-timer nil) 1901 (defvar isearch-lazy-highlight-timer nil)
1902 (defvar isearch-lazy-highlight-last-string nil) 1902 (defvar isearch-lazy-highlight-last-string nil)
1903 1903
1904 (defun isearch-lazy-highlight-cleanup (&optional force) 1904 (defun isearch-lazy-highlight-cleanup (&optional remove)
1905 "Stop lazy highlighting and remove extra highlighting from current buffer. 1905 "Stop lazy highlighting and maybe remove existing highlighting.
1906 FORCE non-nil means do it whether or not `isearch-lazy-highlight-cleanup' 1906 REMOVE non-nil means remove all the existing lazy highlighting.
1907 is nil. This function is called when exiting an incremental search if 1907
1908 `isearch-lazy-highlight-cleanup' is non-nil." 1908 This function is called when exiting an incremental search."
1909 (interactive '(t)) 1909 (interactive '(t))
1910 (if (or force isearch-lazy-highlight-cleanup) 1910 (if remove
1911 (isearch-lazy-highlight-remove-overlays)) 1911 (isearch-lazy-highlight-remove-overlays))
1912 (if isearch-lazy-highlight-timer 1912 (if isearch-lazy-highlight-timer
1913 (progn 1913 (progn
1914 (cancel-timer isearch-lazy-highlight-timer) 1914 (cancel-timer isearch-lazy-highlight-timer)
1915 (setq isearch-lazy-highlight-timer nil)))) 1915 (setq isearch-lazy-highlight-timer nil))))
1916 1916
1917 (defun isearch-lazy-highlight-remove-overlays () 1917 (defun isearch-lazy-highlight-remove-overlays (&optional keep-start keep-end)
1918 "Remove lazy highlight overlays from the current buffer." 1918 "Remove lazy highlight overlays from the current buffer.
1919 (while isearch-lazy-highlight-overlays 1919 With optional arguments KEEP-START and KEEP-END,
1920 (delete-overlay (car isearch-lazy-highlight-overlays)) 1920 prserve any overlays in that range."
1921 (setq isearch-lazy-highlight-overlays 1921 (let ((tem isearch-lazy-highlight-overlays))
1922 (cdr isearch-lazy-highlight-overlays)))) 1922 (while tem
1923 (if (or (null keep-start)
1924 (let ((pos (overlay-start (car tem))))
1925 (or (< pos keep-start) (> pos keep-end))))
1926 (progn
1927 (delete-overlay (car tem))
1928 (setq isearch-lazy-highlight-overlays
1929 (delq (car tem) isearch-lazy-highlight-overlays))))
1930 (setq tem (cdr tem)))))
1923 1931
1924 (defun isearch-lazy-highlight-new-loop () 1932 (defun isearch-lazy-highlight-new-loop ()
1925 "Cleanup any previous `isearch-lazy-highlight' loop and begin a new one. 1933 "Clear obsolete highlighting, and queue up to do new highlighting.
1926 This happens when `isearch-update' is invoked (which can cause the 1934 This happens when `isearch-update' is invoked (which can cause the
1927 search string to change)." 1935 search string to change)."
1928 (if (and isearch-lazy-highlight 1936 (when (and isearch-lazy-highlight
1929 (not (equal isearch-string isearch-lazy-highlight-last-string))) 1937 (not isearch-invalid-regexp)
1930 ;; the search string did indeed change 1938 (not (equal isearch-string "")))
1931 (progn 1939
1932 (isearch-lazy-highlight-cleanup t) ;kill old loop & remove overlays 1940 ;; If the search string has changed, remove all old overlays.
1933 (if (and isearch-overlay 1941 (unless (equal isearch-string isearch-lazy-highlight-last-string)
1934 (not (overlay-get isearch-overlay 'priority))) 1942 (isearch-lazy-highlight-remove-overlays)
1935 ;; make sure the isearch-overlay takes priority 1943 (setq isearch-lazy-highlight-window nil))
1936 (overlay-put isearch-overlay 'priority 1)) 1944
1937 (setq isearch-lazy-highlight-start isearch-opoint 1945 (if (and isearch-overlay
1938 isearch-lazy-highlight-end isearch-opoint 1946 (not (overlay-get isearch-overlay 'priority)))
1939 isearch-lazy-highlight-last-string isearch-string 1947 ;; Make sure the isearch-overlay takes priority
1940 isearch-lazy-highlight-wrapped nil) 1948 ;; over any other matches.
1941 (setq isearch-lazy-highlight-timer 1949 (overlay-put isearch-overlay 'priority 1))
1942 (run-with-idle-timer isearch-lazy-highlight-initial-delay nil 1950
1943 'isearch-lazy-highlight-update))))) 1951 ;; Queue up to display other matches after a short pause.
1944 1952 (setq isearch-lazy-highlight-timer
1945 (defun isearch-lazy-highlight-search () 1953 (run-with-idle-timer isearch-lazy-highlight-initial-delay nil
1946 "Search ahead for the next or previous match, for lazy highlighting. 1954 'isearch-lazy-highlight-update))))
1947 Attempt to do the search exactly the way the pending isearch would."
1948 (let ((case-fold-search isearch-case-fold-search))
1949 (funcall (cond (isearch-word (if isearch-forward
1950 'word-search-forward
1951 'word-search-backward))
1952 (isearch-regexp (if isearch-forward
1953 're-search-forward
1954 're-search-backward))
1955 (t (if isearch-forward
1956 'search-forward
1957 'search-backward)))
1958 isearch-string
1959 (if isearch-forward
1960 (if isearch-lazy-highlight-wrapped
1961 isearch-lazy-highlight-start
1962 nil)
1963 (if isearch-lazy-highlight-wrapped
1964 isearch-lazy-highlight-end
1965 nil))
1966 t)))
1967 1955
1968 (defun isearch-lazy-highlight-update () 1956 (defun isearch-lazy-highlight-update ()
1969 "Find and highlight the next match in the lazy highlighting loop." 1957 "Update highlighting of possible other matchesfor isearch."
1970 (when (and (not isearch-invalid-regexp) 1958 (unless (and (eq isearch-lazy-highlight-window (selected-window))
1971 (or (null isearch-lazy-highlight-max) 1959 (equal isearch-lazy-highlight-start (window-start)))
1972 (< (length isearch-lazy-highlight-overlays) 1960
1973 isearch-lazy-highlight-max))) 1961 ;; The search string or the visible window has changed.
1974 (save-excursion 1962
1975 (save-match-data 1963 (setq isearch-lazy-highlight-window (selected-window)
1976 (goto-char (if isearch-forward 1964 isearch-lazy-highlight-start (window-start)
1977 isearch-lazy-highlight-end 1965 isearch-lazy-highlight-end (window-end nil t)
1978 isearch-lazy-highlight-start)) 1966 isearch-lazy-highlight-last-string isearch-string)
1979 (let ((found (isearch-lazy-highlight-search))) ;do search 1967
1980 (if found 1968 ;; If the string is the same, the old overlays are still usable
1981 ;; found the next match 1969 ;; if they are still visible in the window.
1970 (isearch-lazy-highlight-remove-overlays (window-start)
1971 (window-end nil t))
1972
1973 (when (or (null isearch-lazy-highlight-max)
1974 (< (length isearch-lazy-highlight-overlays)
1975 isearch-lazy-highlight-max))
1976 (save-excursion
1977 (save-match-data
1978 (let (found)
1979 (goto-char isearch-lazy-highlight-start)
1980 (while (let ((case-fold-search isearch-case-fold-search))
1981 (funcall (cond (isearch-word 'word-search-forward)
1982 (isearch-regexp 're-search-forward)
1983 (t 'search-forward))
1984 isearch-string
1985 isearch-lazy-highlight-end
1986 t))
1987 ;; Found the next match.
1982 (let ((ov (make-overlay (match-beginning 0) 1988 (let ((ov (make-overlay (match-beginning 0)
1983 (match-end 0)))) 1989 (match-end 0))))
1984 ;; If OV overlaps the current isearch overlay, suppress 1990 ;; If OV overlaps the current isearch overlay, suppress
1985 ;; its face property; otherwise, we sometimes get odd 1991 ;; its face property; otherwise, we sometimes get odd
1986 ;; looking face combinations. 1992 ;; looking face combinations.
1987 (unless (memq isearch-overlay 1993 (unless (memq isearch-overlay
1988 (overlays-at (match-beginning 0))) 1994 (overlays-at (match-beginning 0)))
1989 (overlay-put ov 'face isearch-lazy-highlight-face)) 1995 (overlay-put ov 'face isearch-lazy-highlight-face))
1990 1996
1991 (overlay-put ov 'priority 0) 1997 (overlay-put ov 'priority 0)
1992 1998 ;; Don't highlight on any other windows.
1993 (push ov isearch-lazy-highlight-overlays) 1999 (overlay-put ov 'window isearch-lazy-highlight-window)
1994 2000
1995 (setq isearch-lazy-highlight-timer 2001 (push ov isearch-lazy-highlight-overlays)))))))))
1996 (run-at-time isearch-lazy-highlight-interval nil
1997 'isearch-lazy-highlight-update))
1998 (if isearch-forward
1999 (setq isearch-lazy-highlight-end (point))
2000 (setq isearch-lazy-highlight-start (point))))
2001
2002 ;; found no next match
2003 (when (not isearch-lazy-highlight-wrapped)
2004 ;; let's try wrapping around the end of the buffer
2005 (setq isearch-lazy-highlight-wrapped t)
2006 (setq isearch-lazy-highlight-timer
2007 (run-at-time isearch-lazy-highlight-interval nil
2008 'isearch-lazy-highlight-update))
2009 (if isearch-forward
2010 (setq isearch-lazy-highlight-end (point-min))
2011 (setq isearch-lazy-highlight-start (point-max))))))))))
2012 2002
2013 (defun isearch-resume (search regexp word forward message case-fold) 2003 (defun isearch-resume (search regexp word forward message case-fold)
2014 "Resume an incremental search. 2004 "Resume an incremental search.
2015 SEARCH is the string or regexp searched for. 2005 SEARCH is the string or regexp searched for.
2016 REGEXP non-nil means the resumed search was a regexp search. 2006 REGEXP non-nil means the resumed search was a regexp search.