changeset 24632:a6ad37f4f6cb

(Info-find-node): Position properly after finding anchor.
author Karl Heuer <kwzh@gnu.org>
date Mon, 26 Apr 1999 05:58:59 +0000
parents 591cd069cbfa
children c7d905dca6ba
files lisp/info.el
diffstat 1 files changed, 46 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/info.el	Mon Apr 26 05:22:32 1999 +0000
+++ b/lisp/info.el	Mon Apr 26 05:58:59 1999 +0000
@@ -400,7 +400,8 @@
   (setq Info-current-node nil)
   (unwind-protect
       ;; Bind case-fold-search in case the user sets it to nil.
-      (let ((case-fold-search t))
+      (let ((case-fold-search t)
+	    anchorpos)
         ;; Switch files if necessary
         (or (null filename)
             (equal Info-current-file filename)
@@ -465,29 +466,35 @@
           ;; *Or* the same, but in an indirect subfile.
 
           ;; Search file for a suitable node.
-          (let ((guesspos (point-min))
-                (regexp
-                 (concat "\\(Node:\\|Ref:\\) *"
-                         (regexp-quote nodename)
-                         " *[,\t\n\177]")))
+	  (let ((guesspos (point-min))
+		(regexp
+		 (concat "\\(Node:\\|Ref:\\) *\\("
+			 (regexp-quote nodename)
+			 "\\) *[,\t\n\177]"))
+		(nodepos nil))
 
             ;; First, search a tag table, if any
             (if (marker-position Info-tag-table-marker)
-
-                (let (found-in-tag-table
+		(let ((found-in-tag-table t)
 		      found-anchor
-                      found-mode
-                      (m Info-tag-table-marker))
+		      found-mode
+		      (m Info-tag-table-marker))
                   (save-excursion
                     (set-buffer (marker-buffer m))
                     (goto-char m)
                     (beginning-of-line) ; so re-search will work.
 
                     ;; Search tag table
-                    (setq found-in-tag-table
-                          (re-search-forward regexp nil t)
-			  found-anchor
-			  (string-equal "Ref:" (match-string 1)))
+		    (catch 'foo
+		      (while (re-search-forward regexp nil t)
+			(setq found-anchor
+			      (string-equal "Ref:" (match-string 1)))
+			(or nodepos (setq nodepos (point))
+			(if (string-equal (match-string 2) nodename)
+			    (throw 'foo t))))
+		      (if nodepos
+			  (goto-char nodepos)
+			(setq found-in-tag-table nil)))
                     (if found-in-tag-table
                         (setq guesspos (1+ (read (current-buffer)))))
                     (setq found-mode major-mode))
@@ -506,7 +513,8 @@
                             (setq guesspos (Info-read-subfile guesspos)))))
 
                   ;; Handle anchor
-                  (if found-anchor (goto-char guesspos)
+                  (if found-anchor
+		      (goto-char (setq anchorpos guesspos))
 
                     ;; Else we may have a node, which we search for:
 		    (goto-char (max (point-min)
@@ -517,6 +525,7 @@
 		    ;; First, check whether the node is right
 		    ;; where we are, in case the buffer begins
 		    ;; with a node.
+		    (setq nodepos nil)
 		    (or (Info-node-at-bob-matching regexp)
 			(catch 'foo
 			  (while (search-forward "\n\^_" nil t)
@@ -524,17 +533,25 @@
 			    (let ((beg (point)))
 			      (forward-line 1)
 			      (if (re-search-backward regexp beg t)
-				  (progn
-				    (beginning-of-line)
-				    (throw 'foo t)))))
-			  (error
-			   "No such anchor in tag table or node in tag table or file: %s"
-			   nodename)))))
+				  (if (string-equal (match-string 2) nodename)
+				      (progn
+					(beginning-of-line)
+					(throw 'foo t))
+				    (or nodepos
+				      (setq nodepos (point)))))))
+			  (if nodepos
+			      (progn
+				(goto-char nodepos)
+				(beginning-of-line))
+			    (error
+			     "No such anchor in tag table or node in tag table or file: %s"
+			     nodename))))))
 	      (goto-char (max (point-min) (- guesspos 1000)))
 	      ;; Now search from our advised position (or from beg of buffer)
 	      ;; to find the actual node.
 	      ;; First, check whether the node is right where we are, in case
 	      ;; the buffer begins with a node.
+	      (setq nodepos nil)
 	      (or (Info-node-at-bob-matching regexp)
 		  (catch 'foo
 		    (while (search-forward "\n\^_" nil t)
@@ -542,10 +559,15 @@
 		      (let ((beg (point)))
 			(forward-line 1)
 			(if (re-search-backward regexp beg t)
-			    (throw 'foo t))))
-		    (error "No such node: %s" nodename)))))
+			    (if (string-equal (match-string 2) nodename)
+				(throw 'foo t)
+			      (or nodepos
+				  (setq nodepos (point)))))))
+		    (if nodepos
+			(goto-char nodepos)
+		      (error "No such node: %s" nodename))))))
           (Info-select-node)
-	  (goto-char (point-min))))
+	  (goto-char (or anchorpos (point-min)))))
     ;; If we did not finish finding the specified node,
     ;; go back to the previous one.
     (or Info-current-node no-going-back (null Info-history)