emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: isearch-forward and Info-search


From: Juri Linkov
Subject: Re: isearch-forward and Info-search
Date: Sat, 12 Mar 2005 04:23:19 +0200
User-agent: Gnus/5.110002 (No Gnus v0.2) Emacs/22.0.50 (gnu/linux)

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 "]")
            "")))
 
 
@@ -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))
 
 (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/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]