aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuri Linkov2005-03-15 10:45:25 +0000
committerJuri Linkov2005-03-15 10:45:25 +0000
commitba653a53be2b24701cfa8b7a1ce79bfa9e2fb7f9 (patch)
tree83f053614391ad43cfd41e2db2843a535b43fe15
parent65e7180e36d0d6c8186271f44257df0c17b4fa62 (diff)
downloademacs-ba653a53be2b24701cfa8b7a1ce79bfa9e2fb7f9.tar.gz
emacs-ba653a53be2b24701cfa8b7a1ce79bfa9e2fb7f9.zip
(isearch-error): New variable.
(isearch-invalid-regexp, isearch-within-brackets): Remove. (isearch-error-state): Renamed from `isearch-invalid-regexp-state'. (isearch-within-brackets-state): Remove. (isearch-case-fold-search-state, isearch-pop-fun-state): Decrease frame index. (isearch-mode, isearch-top-state, isearch-push-state) (isearch-edit-string, isearch-abort, isearch-search-and-update) (isearch-fallback, isearch-message-prefix, isearch-message-suffix) (isearch-search, isearch-lazy-highlight-new-loop): Replace `isearch-invalid-regexp' with `isearch-error'. Remove `isearch-within-brackets'. (isearch-search): Add `search-failed' handler to `condition-case'. (isearch-lazy-highlight-search): Add `condition-case' to catch errors and allow `isearch-lazy-highlight-update' to try highlighting from the beginning of the window. (isearch-repeat): Move up code to set isearch-wrapped to t before calling isearch-wrap-function.
-rw-r--r--lisp/isearch.el100
1 files changed, 48 insertions, 52 deletions
diff --git a/lisp/isearch.el b/lisp/isearch.el
index 77208c42ee4..66bf0dc5c20 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -437,9 +437,8 @@ Each set is a vector of the form:
437(defvar isearch-string "") ; The current search string. 437(defvar isearch-string "") ; The current search string.
438(defvar isearch-message "") ; text-char-description version of isearch-string 438(defvar isearch-message "") ; text-char-description version of isearch-string
439 439
440(defvar isearch-success t) ; Searching is currently successful. 440(defvar isearch-success t) ; Searching is currently successful.
441(defvar isearch-invalid-regexp nil) ; Regexp not well formed. 441(defvar isearch-error nil) ; Error message for failed search.
442(defvar isearch-within-brackets nil) ; Regexp has unclosed [.
443(defvar isearch-other-end nil) ; Start (end) of match if forward (backward). 442(defvar isearch-other-end nil) ; Start (end) of match if forward (backward).
444(defvar isearch-wrapped nil) ; Searching restarted from the top (bottom). 443(defvar isearch-wrapped nil) ; Searching restarted from the top (bottom).
445(defvar isearch-barrier 0) 444(defvar isearch-barrier 0)
@@ -640,8 +639,7 @@ is treated as a regexp. See \\[isearch-forward] for more info."
640 isearch-barrier (point) 639 isearch-barrier (point)
641 isearch-adjusted nil 640 isearch-adjusted nil
642 isearch-yank-flag nil 641 isearch-yank-flag nil
643 isearch-invalid-regexp nil 642 isearch-error nil
644 isearch-within-brackets nil
645 isearch-slow-terminal-mode (and (<= baud-rate search-slow-speed) 643 isearch-slow-terminal-mode (and (<= baud-rate search-slow-speed)
646 (> (window-height) 644 (> (window-height)
647 (* 4 645 (* 4
@@ -867,7 +865,7 @@ REGEXP says which ring to use."
867(defsubst isearch-word-state (frame) 865(defsubst isearch-word-state (frame)
868 "Return the search-by-word flag in FRAME." 866 "Return the search-by-word flag in FRAME."
869 (aref frame 6)) 867 (aref frame 6))
870(defsubst isearch-invalid-regexp-state (frame) 868(defsubst isearch-error-state (frame)
871 "Return the regexp error message in FRAME, or nil if its regexp is valid." 869 "Return the regexp error message in FRAME, or nil if its regexp is valid."
872 (aref frame 7)) 870 (aref frame 7))
873(defsubst isearch-wrapped-state (frame) 871(defsubst isearch-wrapped-state (frame)
@@ -876,15 +874,12 @@ REGEXP says which ring to use."
876(defsubst isearch-barrier-state (frame) 874(defsubst isearch-barrier-state (frame)
877 "Return the barrier value in FRAME." 875 "Return the barrier value in FRAME."
878 (aref frame 9)) 876 (aref frame 9))
879(defsubst isearch-within-brackets-state (frame)
880 "Return the in-character-class flag in FRAME."
881 (aref frame 10))
882(defsubst isearch-case-fold-search-state (frame) 877(defsubst isearch-case-fold-search-state (frame)
883 "Return the case-folding flag in FRAME." 878 "Return the case-folding flag in FRAME."
884 (aref frame 11)) 879 (aref frame 10))
885(defsubst isearch-pop-fun-state (frame) 880(defsubst isearch-pop-fun-state (frame)
886 "Return the function restoring the mode-specific isearch state in FRAME." 881 "Return the function restoring the mode-specific isearch state in FRAME."
887 (aref frame 12)) 882 (aref frame 11))
888 883
889(defun isearch-top-state () 884(defun isearch-top-state ()
890 (let ((cmd (car isearch-cmds))) 885 (let ((cmd (car isearch-cmds)))
@@ -894,10 +889,9 @@ REGEXP says which ring to use."
894 isearch-forward (isearch-forward-state cmd) 889 isearch-forward (isearch-forward-state cmd)
895 isearch-other-end (isearch-other-end-state cmd) 890 isearch-other-end (isearch-other-end-state cmd)
896 isearch-word (isearch-word-state cmd) 891 isearch-word (isearch-word-state cmd)
897 isearch-invalid-regexp (isearch-invalid-regexp-state cmd) 892 isearch-error (isearch-error-state cmd)
898 isearch-wrapped (isearch-wrapped-state cmd) 893 isearch-wrapped (isearch-wrapped-state cmd)
899 isearch-barrier (isearch-barrier-state cmd) 894 isearch-barrier (isearch-barrier-state cmd)
900 isearch-within-brackets (isearch-within-brackets-state cmd)
901 isearch-case-fold-search (isearch-case-fold-search-state cmd)) 895 isearch-case-fold-search (isearch-case-fold-search-state cmd))
902 (if (functionp (isearch-pop-fun-state cmd)) 896 (if (functionp (isearch-pop-fun-state cmd))
903 (funcall (isearch-pop-fun-state cmd) cmd)) 897 (funcall (isearch-pop-fun-state cmd) cmd))
@@ -912,8 +906,8 @@ REGEXP says which ring to use."
912 (cons (vector isearch-string isearch-message (point) 906 (cons (vector isearch-string isearch-message (point)
913 isearch-success isearch-forward isearch-other-end 907 isearch-success isearch-forward isearch-other-end
914 isearch-word 908 isearch-word
915 isearch-invalid-regexp isearch-wrapped isearch-barrier 909 isearch-error isearch-wrapped isearch-barrier
916 isearch-within-brackets isearch-case-fold-search 910 isearch-case-fold-search
917 (if isearch-push-state-function 911 (if isearch-push-state-function
918 (funcall isearch-push-state-function))) 912 (funcall isearch-push-state-function)))
919 isearch-cmds))) 913 isearch-cmds)))
@@ -976,8 +970,7 @@ If first char entered is \\[isearch-yank-word-or-char], then do word search inst
976 (isearch-barrier isearch-barrier) 970 (isearch-barrier isearch-barrier)
977 (isearch-adjusted isearch-adjusted) 971 (isearch-adjusted isearch-adjusted)
978 (isearch-yank-flag isearch-yank-flag) 972 (isearch-yank-flag isearch-yank-flag)
979 (isearch-invalid-regexp isearch-invalid-regexp) 973 (isearch-error isearch-error)
980 (isearch-within-brackets isearch-within-brackets)
981 ;;; Don't bind this. We want isearch-search, below, to set it. 974 ;;; Don't bind this. We want isearch-search, below, to set it.
982 ;;; And the old value won't matter after that. 975 ;;; And the old value won't matter after that.
983 ;;; (isearch-other-end isearch-other-end) 976 ;;; (isearch-other-end isearch-other-end)
@@ -1124,7 +1117,7 @@ Use `isearch-exit' to quit without signaling."
1124 (isearch-cancel)) 1117 (isearch-cancel))
1125 ;; If search is failing, or has an incomplete regexp, 1118 ;; If search is failing, or has an incomplete regexp,
1126 ;; rub out until it is once more successful. 1119 ;; rub out until it is once more successful.
1127 (while (or (not isearch-success) isearch-invalid-regexp) 1120 (while (or (not isearch-success) isearch-error)
1128 (isearch-pop-state)) 1121 (isearch-pop-state))
1129 (isearch-update))) 1122 (isearch-update)))
1130 1123
@@ -1146,10 +1139,11 @@ Use `isearch-exit' to quit without signaling."
1146 ;; If already have what to search for, repeat it. 1139 ;; If already have what to search for, repeat it.
1147 (or isearch-success 1140 (or isearch-success
1148 (progn 1141 (progn
1142 ;; Set isearch-wrapped before calling isearch-wrap-function
1143 (setq isearch-wrapped t)
1149 (if isearch-wrap-function 1144 (if isearch-wrap-function
1150 (funcall isearch-wrap-function) 1145 (funcall isearch-wrap-function)
1151 (goto-char (if isearch-forward (point-min) (point-max)))) 1146 (goto-char (if isearch-forward (point-min) (point-max)))))))
1152 (setq isearch-wrapped t))))
1153 ;; C-s in reverse or C-r in forward, change direction. 1147 ;; C-s in reverse or C-r in forward, change direction.
1154 (setq isearch-forward (not isearch-forward))) 1148 (setq isearch-forward (not isearch-forward)))
1155 1149
@@ -1384,8 +1378,7 @@ might return the position of the end of the line."
1384 (min isearch-opoint isearch-barrier)))) 1378 (min isearch-opoint isearch-barrier))))
1385 (progn 1379 (progn
1386 (setq isearch-success t 1380 (setq isearch-success t
1387 isearch-invalid-regexp nil 1381 isearch-error nil
1388 isearch-within-brackets nil
1389 isearch-other-end (match-end 0)) 1382 isearch-other-end (match-end 0))
1390 (if (and (eq isearch-case-fold-search t) search-upper-case) 1383 (if (and (eq isearch-case-fold-search t) search-upper-case)
1391 (setq isearch-case-fold-search 1384 (setq isearch-case-fold-search
@@ -1432,8 +1425,8 @@ barrier."
1432 (not want-backslash)) 1425 (not want-backslash))
1433 ;; We have to check 2 stack frames because the last might be 1426 ;; We have to check 2 stack frames because the last might be
1434 ;; invalid just because of a backslash. 1427 ;; invalid just because of a backslash.
1435 (or (not isearch-invalid-regexp) 1428 (or (not isearch-error)
1436 (not (isearch-invalid-regexp-state (cadr isearch-cmds))) 1429 (not (isearch-error-state (cadr isearch-cmds)))
1437 allow-invalid)) 1430 allow-invalid))
1438 (if to-barrier 1431 (if to-barrier
1439 (progn (goto-char isearch-barrier) 1432 (progn (goto-char isearch-barrier)
@@ -1448,7 +1441,7 @@ barrier."
1448 ;; Also skip over postfix operators -- though horrid, 1441 ;; Also skip over postfix operators -- though horrid,
1449 ;; 'ab?\{5,6\}+\{1,2\}*' is perfectly legal. 1442 ;; 'ab?\{5,6\}+\{1,2\}*' is perfectly legal.
1450 (while (and previous 1443 (while (and previous
1451 (or (isearch-invalid-regexp-state frame) 1444 (or (isearch-error-state frame)
1452 (let* ((string (isearch-string-state frame)) 1445 (let* ((string (isearch-string-state frame))
1453 (lchar (aref string (1- (length string))))) 1446 (lchar (aref string (1- (length string)))))
1454 ;; The operators aren't always operators; check 1447 ;; The operators aren't always operators; check
@@ -1981,11 +1974,10 @@ If there is no completion possible, say so and continue searching."
1981 ;; If about to search, and previous search regexp was invalid, 1974 ;; If about to search, and previous search regexp was invalid,
1982 ;; check that it still is. If it is valid now, 1975 ;; check that it still is. If it is valid now,
1983 ;; let the message we display while searching say that it is valid. 1976 ;; let the message we display while searching say that it is valid.
1984 (and isearch-invalid-regexp ellipsis 1977 (and isearch-error ellipsis
1985 (condition-case () 1978 (condition-case ()
1986 (progn (re-search-forward isearch-string (point) t) 1979 (progn (re-search-forward isearch-string (point) t)
1987 (setq isearch-invalid-regexp nil 1980 (setq isearch-error nil))
1988 isearch-within-brackets nil))
1989 (error nil))) 1981 (error nil)))
1990 ;; If currently failing, display no ellipsis. 1982 ;; If currently failing, display no ellipsis.
1991 (or isearch-success (setq ellipsis nil)) 1983 (or isearch-success (setq ellipsis nil))
@@ -2011,8 +2003,8 @@ If there is no completion possible, say so and continue searching."
2011 2003
2012(defun isearch-message-suffix (&optional c-q-hack ellipsis) 2004(defun isearch-message-suffix (&optional c-q-hack ellipsis)
2013 (concat (if c-q-hack "^Q" "") 2005 (concat (if c-q-hack "^Q" "")
2014 (if isearch-invalid-regexp 2006 (if isearch-error
2015 (concat " [" isearch-invalid-regexp "]") 2007 (concat " [" isearch-error "]")
2016 ""))) 2008 "")))
2017 2009
2018 2010
@@ -2049,8 +2041,7 @@ Can be changed via `isearch-search-fun-function' for special needs."
2049 (case-fold-search isearch-case-fold-search) 2041 (case-fold-search isearch-case-fold-search)
2050 (search-spaces-regexp search-whitespace-regexp) 2042 (search-spaces-regexp search-whitespace-regexp)
2051 (retry t)) 2043 (retry t))
2052 (if isearch-regexp (setq isearch-invalid-regexp nil)) 2044 (setq isearch-error nil)
2053 (setq isearch-within-brackets nil)
2054 (while retry 2045 (while retry
2055 (setq isearch-success 2046 (setq isearch-success
2056 (funcall 2047 (funcall
@@ -2074,16 +2065,19 @@ Can be changed via `isearch-search-fun-function' for special needs."
2074 (setq isearch-success nil)) 2065 (setq isearch-success nil))
2075 2066
2076 (invalid-regexp 2067 (invalid-regexp
2077 (setq isearch-invalid-regexp (car (cdr lossage))) 2068 (setq isearch-error (car (cdr lossage)))
2078 (setq isearch-within-brackets (string-match "\\`Unmatched \\["
2079 isearch-invalid-regexp))
2080 (if (string-match 2069 (if (string-match
2081 "\\`Premature \\|\\`Unmatched \\|\\`Invalid " 2070 "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
2082 isearch-invalid-regexp) 2071 isearch-error)
2083 (setq isearch-invalid-regexp "incomplete input"))) 2072 (setq isearch-error "incomplete input")))
2073
2074 (search-failed
2075 (setq isearch-success nil)
2076 (setq isearch-error (nth 2 lossage)))
2077
2084 (error 2078 (error
2085 ;; stack overflow in regexp search. 2079 ;; stack overflow in regexp search.
2086 (setq isearch-invalid-regexp (format "%s" lossage)))) 2080 (setq isearch-error (format "%s" lossage))))
2087 2081
2088 (if isearch-success 2082 (if isearch-success
2089 nil 2083 nil
@@ -2315,7 +2309,7 @@ since they have special meaning in a regexp."
2315;; `isearch-word' and `isearch-regexp'; 2309;; `isearch-word' and `isearch-regexp';
2316;; - the direction of the current search is expected to be given by 2310;; - the direction of the current search is expected to be given by
2317;; `isearch-forward'; 2311;; `isearch-forward';
2318;; - the variable `isearch-invalid-regexp' is expected to be true 2312;; - the variable `isearch-error' is expected to be true
2319;; iff `isearch-string' is an invalid regexp. 2313;; iff `isearch-string' is an invalid regexp.
2320 2314
2321(defvar isearch-lazy-highlight-overlays nil) 2315(defvar isearch-lazy-highlight-overlays nil)
@@ -2369,7 +2363,7 @@ by other Emacs features."
2369 isearch-lazy-highlight-window-end)))) 2363 isearch-lazy-highlight-window-end))))
2370 ;; something important did indeed change 2364 ;; something important did indeed change
2371 (isearch-lazy-highlight-cleanup t) ;kill old loop & remove overlays 2365 (isearch-lazy-highlight-cleanup t) ;kill old loop & remove overlays
2372 (when (not isearch-invalid-regexp) 2366 (when (not isearch-error)
2373 (setq isearch-lazy-highlight-start-limit beg 2367 (setq isearch-lazy-highlight-start-limit beg
2374 isearch-lazy-highlight-end-limit end) 2368 isearch-lazy-highlight-end-limit end)
2375 (setq isearch-lazy-highlight-window (selected-window) 2369 (setq isearch-lazy-highlight-window (selected-window)
@@ -2391,18 +2385,20 @@ by other Emacs features."
2391Attempt to do the search exactly the way the pending isearch would." 2385Attempt to do the search exactly the way the pending isearch would."
2392 (let ((case-fold-search isearch-case-fold-search) 2386 (let ((case-fold-search isearch-case-fold-search)
2393 (search-spaces-regexp search-whitespace-regexp)) 2387 (search-spaces-regexp search-whitespace-regexp))
2394 (funcall (isearch-search-fun) 2388 (condition-case nil
2395 isearch-string 2389 (funcall (isearch-search-fun)
2396 (if isearch-forward 2390 isearch-string
2397 (min (or isearch-lazy-highlight-end-limit (point-max)) 2391 (if isearch-forward
2398 (if isearch-lazy-highlight-wrapped 2392 (min (or isearch-lazy-highlight-end-limit (point-max))
2399 isearch-lazy-highlight-start 2393 (if isearch-lazy-highlight-wrapped
2400 (window-end))) 2394 isearch-lazy-highlight-start
2401 (max (or isearch-lazy-highlight-start-limit (point-min)) 2395 (window-end)))
2402 (if isearch-lazy-highlight-wrapped 2396 (max (or isearch-lazy-highlight-start-limit (point-min))
2403 isearch-lazy-highlight-end 2397 (if isearch-lazy-highlight-wrapped
2404 (window-start)))) 2398 isearch-lazy-highlight-end
2405 t))) 2399 (window-start))))
2400 t)
2401 (error nil))))
2406 2402
2407(defun isearch-lazy-highlight-update () 2403(defun isearch-lazy-highlight-update ()
2408 "Update highlighting of other matches for current search." 2404 "Update highlighting of other matches for current search."