unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
Cc: emacs-devel@gnu.org
Subject: Re: isearch-forward and Info-search
Date: Sat, 12 Mar 2005 04:23:19 +0200	[thread overview]
Message-ID: <87vf7xr1gm.fsf@jurta.org> (raw)
In-Reply-To: <16942.42643.503788.488893@farnswood.snap.net.nz> (Nick Roberts's message of "Wed, 9 Mar 2005 20:32:35 +1300")

Below is an implementation that works as follows:
after an attempt to leave the first Info node,
isearch fails with the following message:

    Failing I-search: search string [failed in current node]

After leaving the first Info node with subsequent C-s or C-r,
isearch doesn't fail more in other Info nodes.  In the end/beginning
of the manual isearch fails with the usual message:

    Failing I-search: search string

After the next C-s/C-r it wraps to the top/final node.

In the implementation below it would be possible to reuse
`isearch-invalid-regexp' to hold the error message, but this is not
a clean solution.  Adding a new special variable `isearch-error' looks
better.  When set to a string value it adds the error message in
square brackets to the end of the echo area.  `isearch-error' is set
in `isearch-search' via the second argument of the `search-failed'
signal (its first argument is the failed search string).

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	12 Mar 2005 02:22:55 -0000
@@ -438,6 +438,7 @@
 (defvar isearch-message "") ; text-char-description version of isearch-string
 
 (defvar isearch-success t)		; Searching is currently successful.
+(defvar isearch-error nil)		; Error message for failed search.
 (defvar isearch-invalid-regexp nil)	; Regexp not well formed.
 (defvar isearch-within-brackets nil)	; Regexp has unclosed [.
 (defvar isearch-other-end nil)	; Start (end) of match if forward (backward).
@@ -1146,10 +1147,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,6 +1386,7 @@
 		     (min isearch-opoint isearch-barrier))))
 	(progn
 	  (setq isearch-success t
+		isearch-error nil
 		isearch-invalid-regexp nil
 		isearch-within-brackets nil
 		isearch-other-end (match-end 0))
@@ -2013,6 +2016,9 @@
   (concat (if c-q-hack "^Q" "")
 	  (if isearch-invalid-regexp
 	      (concat " [" isearch-invalid-regexp "]")
+	    "")
+	  (if (and (not isearch-success) isearch-error)
+	      (concat " [" isearch-error "]")
 	    "")))
 
 \f
@@ -2050,7 +2056,7 @@
 	    (search-spaces-regexp search-whitespace-regexp)
 	    (retry t))
 	(if isearch-regexp (setq isearch-invalid-regexp nil))
-	(setq isearch-within-brackets nil)
+	(setq isearch-within-brackets nil isearch-error nil)
 	(while retry
 	  (setq isearch-success
 		(funcall
@@ -2081,6 +2087,11 @@
 	  "\\`Premature \\|\\`Unmatched \\|\\`Invalid "
 	  isearch-invalid-regexp)
 	 (setq isearch-invalid-regexp "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))))

Index: lisp/info.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/info.el,v
retrieving revision 1.419
diff -u -r1.419 info.el
--- lisp/info.el	12 Mar 2005 02:18:32 -0000	1.419
+++ lisp/info.el	12 Mar 2005 02:22:18 -0000
@@ -1514,6 +1514,13 @@
 		  (setq found (point) beg-found (if backward (match-end 0)
 						  (match-beginning 0)))
 		(setq give-up t))))))
+
+      (when (and Info-isearch-search isearch-mode
+		 (not Info-isearch-first-node)
+		 (or give-up (and found (not (and (> found opoint-min)
+						  (< found opoint-max))))))
+	(signal 'search-failed (list regexp "failed in current node")))
+
       ;; If no subfiles, give error now.
       (if give-up
 	  (if (null Info-current-subfile)
@@ -1650,25 +1657,28 @@
 (defun Info-isearch-search ()
   (if Info-isearch-search
       (lambda (string &optional bound noerror count)
-	(condition-case nil
-	    (if isearch-word
-		(Info-search (concat "\\b" (replace-regexp-in-string
-					    "\\W+" "\\\\W+"
-					    (replace-regexp-in-string
-					     "^\\W+\\|\\W+$" "" string)) "\\b")
-			     bound noerror count
-			     (unless isearch-forward 'backward))
-	      (Info-search (if isearch-regexp string (regexp-quote string))
-			   bound noerror count
-			   (unless isearch-forward 'backward))
-	      (point))
-	  (error nil)))
+	(if isearch-word
+	    (Info-search (concat "\\b" (replace-regexp-in-string
+					"\\W+" "\\\\W+"
+					(replace-regexp-in-string
+					 "^\\W+\\|\\W+$" "" string)) "\\b")
+			 bound noerror count
+			 (unless isearch-forward 'backward))
+	  (Info-search (if isearch-regexp string (regexp-quote string))
+		       bound noerror count
+		       (unless isearch-forward 'backward))
+	  (point)))
     (let ((isearch-search-fun-function nil))
       (isearch-search-fun))))
 
 (defun Info-isearch-wrap ()
-  (when Info-isearch-search
-    (if isearch-forward (Info-top-node) (Info-final-node))
+  (if Info-isearch-search
+      (if Info-isearch-first-node
+	  (progn
+	    (if isearch-forward (Info-top-node) (Info-final-node))
+	    (goto-char (if isearch-forward (point-min) (point-max))))
+	(setq Info-isearch-first-node Info-current-node)
+	(setq isearch-wrapped nil))
     (goto-char (if isearch-forward (point-min) (point-max)))))
 
 (defun Info-isearch-push-state ()
@@ -1680,6 +1690,9 @@
            (string= Info-current-node node))
       (progn (Info-find-node file node) (sit-for 0))))
 
+(defvar Info-isearch-first-node nil)
+(defun Info-isearch-start ()
+  (setq Info-isearch-first-node nil))
 \f
 (defun Info-extract-pointer (name &optional errorname)
   "Extract the value of the node-pointer named NAME.
@@ -3217,6 +3230,7 @@
   (setq desktop-save-buffer 'Info-desktop-buffer-misc-data)
   (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
   (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
+  (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
   (set (make-local-variable 'isearch-search-fun-function)
        'Info-isearch-search)
   (set (make-local-variable 'isearch-wrap-function)

-- 
Juri Linkov
http://www.jurta.org/emacs/

  parent reply	other threads:[~2005-03-12  2:23 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 [this message]
2005-03-12 13:47   ` Stefan Monnier
2005-03-13  1:00     ` Juri Linkov
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=87vf7xr1gm.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    /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).