From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: isearch-forward and Info-search Date: Sun, 13 Mar 2005 03:00:25 +0200 Organization: JURTA Message-ID: <878y4sjlme.fsf@jurta.org> References: <16942.42643.503788.488893@farnswood.snap.net.nz> <87vf7xr1gm.fsf@jurta.org> <87mzt9f05i.fsf-monnier+emacs@gnu.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1110684779 8397 80.91.229.2 (13 Mar 2005 03:32:59 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 13 Mar 2005 03:32:59 +0000 (UTC) Cc: nickrob@snap.net.nz, emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 13 04:32:59 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DAJqS-0006eJ-VV for ged-emacs-devel@m.gmane.org; Sun, 13 Mar 2005 04:32:49 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DAK5r-0004oI-IB for ged-emacs-devel@m.gmane.org; Sat, 12 Mar 2005 22:48:43 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DAK4H-0004Mg-HT for emacs-devel@gnu.org; Sat, 12 Mar 2005 22:47:05 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DAK45-0004II-VY for emacs-devel@gnu.org; Sat, 12 Mar 2005 22:46:59 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DAK44-0004FI-SJ for emacs-devel@gnu.org; Sat, 12 Mar 2005 22:46:52 -0500 Original-Received: from [194.126.101.111] (helo=MXR-5.estpak.ee) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DAJWt-0000QM-HB for emacs-devel@gnu.org; Sat, 12 Mar 2005 22:12:36 -0500 Original-Received: from mail.neti.ee (80-235-34-125-dsl.mus.estpak.ee [80.235.34.125]) by MXR-5.estpak.ee (Postfix) with ESMTP id 4C6E512DAAA; Sun, 13 Mar 2005 05:12:25 +0200 (EET) Original-To: Stefan Monnier In-Reply-To: <87mzt9f05i.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sat, 12 Mar 2005 08:47:36 -0500") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org X-MailScanner-To: ged-emacs-devel@m.gmane.org Xref: news.gmane.org gmane.emacs.devel:34530 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:34530 Stefan Monnier writes: > The implementation looks clean. I just suggest that we should simply > replace isearch-invalid-regexp with isearch-error (there can only be one > error at any given time, either a search failure or an invalid regexp, or > ...). OK. I also removed `isearch-within-brackets' because it is used nowhere within Emacs. And added `condition-case' around the call to `isearch-search-fun' in `isearch-lazy-highlight-search' to return nil in case of error which allows `isearch-lazy-highlight-update' to try to highlight matches from the window beginning (needed for Info isearch). Index: lisp/isearch.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/isearch.el,v retrieving revision 1.256 diff -u -r1.256 isearch.el --- lisp/isearch.el 19 Feb 2005 20:52:47 -0000 1.256 +++ lisp/isearch.el 13 Mar 2005 00:55:45 -0000 @@ -437,9 +437,8 @@ (defvar isearch-string "") ; The current search string. (defvar isearch-message "") ; text-char-description version of isearch-string -(defvar isearch-success t) ; Searching is currently successful. -(defvar isearch-invalid-regexp nil) ; Regexp not well formed. -(defvar isearch-within-brackets nil) ; Regexp has unclosed [. +(defvar isearch-success t) ; Searching is currently successful. +(defvar isearch-error nil) ; Error message for failed search. (defvar isearch-other-end nil) ; Start (end) of match if forward (backward). (defvar isearch-wrapped nil) ; Searching restarted from the top (bottom). (defvar isearch-barrier 0) @@ -640,8 +639,7 @@ isearch-barrier (point) isearch-adjusted nil isearch-yank-flag nil - isearch-invalid-regexp nil - isearch-within-brackets nil + isearch-error nil isearch-slow-terminal-mode (and (<= baud-rate search-slow-speed) (> (window-height) (* 4 @@ -867,7 +865,7 @@ (defsubst isearch-word-state (frame) "Return the search-by-word flag in FRAME." (aref frame 6)) -(defsubst isearch-invalid-regexp-state (frame) +(defsubst isearch-error-state (frame) "Return the regexp error message in FRAME, or nil if its regexp is valid." (aref frame 7)) (defsubst isearch-wrapped-state (frame) @@ -876,15 +874,12 @@ (defsubst isearch-barrier-state (frame) "Return the barrier value in FRAME." (aref frame 9)) -(defsubst isearch-within-brackets-state (frame) - "Return the in-character-class flag in FRAME." - (aref frame 10)) (defsubst isearch-case-fold-search-state (frame) "Return the case-folding flag in FRAME." - (aref frame 11)) + (aref frame 10)) (defsubst isearch-pop-fun-state (frame) "Return the function restoring the mode-specific isearch state in FRAME." - (aref frame 12)) + (aref frame 11)) (defun isearch-top-state () (let ((cmd (car isearch-cmds))) @@ -894,10 +889,9 @@ isearch-forward (isearch-forward-state cmd) isearch-other-end (isearch-other-end-state cmd) isearch-word (isearch-word-state cmd) - isearch-invalid-regexp (isearch-invalid-regexp-state cmd) + isearch-error (isearch-error-state cmd) isearch-wrapped (isearch-wrapped-state cmd) isearch-barrier (isearch-barrier-state cmd) - isearch-within-brackets (isearch-within-brackets-state cmd) isearch-case-fold-search (isearch-case-fold-search-state cmd)) (if (functionp (isearch-pop-fun-state cmd)) (funcall (isearch-pop-fun-state cmd) cmd)) @@ -912,8 +906,8 @@ (cons (vector isearch-string isearch-message (point) isearch-success isearch-forward isearch-other-end isearch-word - isearch-invalid-regexp isearch-wrapped isearch-barrier - isearch-within-brackets isearch-case-fold-search + isearch-error isearch-wrapped isearch-barrier + isearch-case-fold-search (if isearch-push-state-function (funcall isearch-push-state-function))) isearch-cmds))) @@ -976,8 +970,7 @@ (isearch-barrier isearch-barrier) (isearch-adjusted isearch-adjusted) (isearch-yank-flag isearch-yank-flag) - (isearch-invalid-regexp isearch-invalid-regexp) - (isearch-within-brackets isearch-within-brackets) + (isearch-error isearch-error) ;;; Don't bind this. We want isearch-search, below, to set it. ;;; And the old value won't matter after that. ;;; (isearch-other-end isearch-other-end) @@ -1124,7 +1117,7 @@ (isearch-cancel)) ;; If search is failing, or has an incomplete regexp, ;; rub out until it is once more successful. - (while (or (not isearch-success) isearch-invalid-regexp) + (while (or (not isearch-success) isearch-error) (isearch-pop-state)) (isearch-update))) @@ -1146,10 +1139,11 @@ ;; If already have what to search for, repeat it. (or isearch-success (progn + ;; Set isearch-wrapped before calling isearch-wrap-function + (setq isearch-wrapped t) (if isearch-wrap-function (funcall isearch-wrap-function) - (goto-char (if isearch-forward (point-min) (point-max)))) - (setq isearch-wrapped t)))) + (goto-char (if isearch-forward (point-min) (point-max))))))) ;; C-s in reverse or C-r in forward, change direction. (setq isearch-forward (not isearch-forward))) @@ -1384,8 +1378,7 @@ (min isearch-opoint isearch-barrier)))) (progn (setq isearch-success t - isearch-invalid-regexp nil - isearch-within-brackets nil + isearch-error nil isearch-other-end (match-end 0)) (if (and (eq isearch-case-fold-search t) search-upper-case) (setq isearch-case-fold-search @@ -1432,8 +1425,8 @@ (not want-backslash)) ;; We have to check 2 stack frames because the last might be ;; invalid just because of a backslash. - (or (not isearch-invalid-regexp) - (not (isearch-invalid-regexp-state (cadr isearch-cmds))) + (or (not isearch-error) + (not (isearch-error-state (cadr isearch-cmds))) allow-invalid)) (if to-barrier (progn (goto-char isearch-barrier) @@ -1448,7 +1441,7 @@ ;; Also skip over postfix operators -- though horrid, ;; 'ab?\{5,6\}+\{1,2\}*' is perfectly legal. (while (and previous - (or (isearch-invalid-regexp-state frame) + (or (isearch-error-state frame) (let* ((string (isearch-string-state frame)) (lchar (aref string (1- (length string))))) ;; The operators aren't always operators; check @@ -1981,11 +1974,10 @@ ;; If about to search, and previous search regexp was invalid, ;; check that it still is. If it is valid now, ;; let the message we display while searching say that it is valid. - (and isearch-invalid-regexp ellipsis + (and isearch-error ellipsis (condition-case () (progn (re-search-forward isearch-string (point) t) - (setq isearch-invalid-regexp nil - isearch-within-brackets nil)) + (setq isearch-error nil)) (error nil))) ;; If currently failing, display no ellipsis. (or isearch-success (setq ellipsis nil)) @@ -2011,8 +2003,8 @@ (defun isearch-message-suffix (&optional c-q-hack ellipsis) (concat (if c-q-hack "^Q" "") - (if isearch-invalid-regexp - (concat " [" isearch-invalid-regexp "]") + (if isearch-error + (concat " [" isearch-error "]") ""))) @@ -2049,8 +2041,7 @@ (case-fold-search isearch-case-fold-search) (search-spaces-regexp search-whitespace-regexp) (retry t)) - (if isearch-regexp (setq isearch-invalid-regexp nil)) - (setq isearch-within-brackets nil) + (setq isearch-error nil) (while retry (setq isearch-success (funcall @@ -2074,16 +2065,19 @@ (setq isearch-success nil)) (invalid-regexp - (setq isearch-invalid-regexp (car (cdr lossage))) - (setq isearch-within-brackets (string-match "\\`Unmatched \\[" - isearch-invalid-regexp)) + (setq isearch-error (car (cdr lossage))) (if (string-match "\\`Premature \\|\\`Unmatched \\|\\`Invalid " - isearch-invalid-regexp) - (setq isearch-invalid-regexp "incomplete input"))) + isearch-error) + (setq isearch-error "incomplete input"))) + + (search-failed + (setq isearch-success nil) + (setq isearch-error (nth 2 lossage))) + (error ;; stack overflow in regexp search. - (setq isearch-invalid-regexp (format "%s" lossage)))) + (setq isearch-error (format "%s" lossage)))) (if isearch-success nil @@ -2315,7 +2309,7 @@ ;; `isearch-word' and `isearch-regexp'; ;; - the direction of the current search is expected to be given by ;; `isearch-forward'; -;; - the variable `isearch-invalid-regexp' is expected to be true +;; - the variable `isearch-error' is expected to be true ;; iff `isearch-string' is an invalid regexp. (defvar isearch-lazy-highlight-overlays nil) @@ -2369,7 +2363,7 @@ isearch-lazy-highlight-window-end)))) ;; something important did indeed change (isearch-lazy-highlight-cleanup t) ;kill old loop & remove overlays - (when (not isearch-invalid-regexp) + (when (not isearch-error) (setq isearch-lazy-highlight-start-limit beg isearch-lazy-highlight-end-limit end) (setq isearch-lazy-highlight-window (selected-window) @@ -2391,18 +2385,20 @@ Attempt to do the search exactly the way the pending isearch would." (let ((case-fold-search isearch-case-fold-search) (search-spaces-regexp search-whitespace-regexp)) - (funcall (isearch-search-fun) - isearch-string - (if isearch-forward - (min (or isearch-lazy-highlight-end-limit (point-max)) - (if isearch-lazy-highlight-wrapped - isearch-lazy-highlight-start - (window-end))) - (max (or isearch-lazy-highlight-start-limit (point-min)) - (if isearch-lazy-highlight-wrapped - isearch-lazy-highlight-end - (window-start)))) - t))) + (condition-case nil + (funcall (isearch-search-fun) + isearch-string + (if isearch-forward + (min (or isearch-lazy-highlight-end-limit (point-max)) + (if isearch-lazy-highlight-wrapped + isearch-lazy-highlight-start + (window-end))) + (max (or isearch-lazy-highlight-start-limit (point-min)) + (if isearch-lazy-highlight-wrapped + isearch-lazy-highlight-end + (window-start)))) + t) + (error nil)))) (defun isearch-lazy-highlight-update () "Update highlighting of other matches for current search." -- Juri Linkov http://www.jurta.org/emacs/