unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
Cc: nickrob@snap.net.nz, emacs-devel@gnu.org
Subject: Re: isearch-forward and Info-search
Date: Sun, 13 Mar 2005 03:00:25 +0200	[thread overview]
Message-ID: <878y4sjlme.fsf@jurta.org> (raw)
In-Reply-To: <87mzt9f05i.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sat, 12 Mar 2005 08:47:36 -0500")

Stefan Monnier <monnier@iro.umontreal.ca> 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 "]")
 	    "")))
 
 \f
@@ -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/

  reply	other threads:[~2005-03-13  1:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-09  7:32 isearch-forward and Info-search Nick Roberts
2005-03-09  7:59 ` Miles Bader
2005-03-10  2:02   ` Richard Stallman
2005-03-10  6:29   ` Juri Linkov
2005-03-10  7:56     ` Nick Roberts
2005-03-10 17:20     ` Drew Adams
2005-03-11  1:48     ` Richard Stallman
2005-03-10  6:33 ` Juri Linkov
2005-03-10 17:19   ` Drew Adams
2005-03-11  7:28     ` Juri Linkov
2005-03-11  8:15       ` Nick Roberts
2005-03-11 14:40       ` Drew Adams
2005-03-12  2:23 ` Juri Linkov
2005-03-12 13:47   ` Stefan Monnier
2005-03-13  1:00     ` Juri Linkov [this message]
2005-03-13 21:15       ` Nick Roberts
2005-03-29 12:17       ` Kai Großjohann
2005-03-29 13:48         ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878y4sjlme.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    --cc=nickrob@snap.net.nz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).