comparison lisp/info.el @ 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 2d0999df43c7
children a78f0c2654d6
comparison
equal deleted inserted replaced
24631:591cd069cbfa 24632:a6ad37f4f6cb
398 (Info-mode)) 398 (Info-mode))
399 (widen) 399 (widen)
400 (setq Info-current-node nil) 400 (setq Info-current-node nil)
401 (unwind-protect 401 (unwind-protect
402 ;; Bind case-fold-search in case the user sets it to nil. 402 ;; Bind case-fold-search in case the user sets it to nil.
403 (let ((case-fold-search t)) 403 (let ((case-fold-search t)
404 anchorpos)
404 ;; Switch files if necessary 405 ;; Switch files if necessary
405 (or (null filename) 406 (or (null filename)
406 (equal Info-current-file filename) 407 (equal Info-current-file filename)
407 (let ((buffer-read-only nil)) 408 (let ((buffer-read-only nil))
408 (setq Info-current-file nil 409 (setq Info-current-file nil
463 ;; 5. Node *not* in tag table, and *not* in file 464 ;; 5. Node *not* in tag table, and *not* in file
464 ;; 465 ;;
465 ;; *Or* the same, but in an indirect subfile. 466 ;; *Or* the same, but in an indirect subfile.
466 467
467 ;; Search file for a suitable node. 468 ;; Search file for a suitable node.
468 (let ((guesspos (point-min)) 469 (let ((guesspos (point-min))
469 (regexp 470 (regexp
470 (concat "\\(Node:\\|Ref:\\) *" 471 (concat "\\(Node:\\|Ref:\\) *\\("
471 (regexp-quote nodename) 472 (regexp-quote nodename)
472 " *[,\t\n\177]"))) 473 "\\) *[,\t\n\177]"))
474 (nodepos nil))
473 475
474 ;; First, search a tag table, if any 476 ;; First, search a tag table, if any
475 (if (marker-position Info-tag-table-marker) 477 (if (marker-position Info-tag-table-marker)
476 478 (let ((found-in-tag-table t)
477 (let (found-in-tag-table
478 found-anchor 479 found-anchor
479 found-mode 480 found-mode
480 (m Info-tag-table-marker)) 481 (m Info-tag-table-marker))
481 (save-excursion 482 (save-excursion
482 (set-buffer (marker-buffer m)) 483 (set-buffer (marker-buffer m))
483 (goto-char m) 484 (goto-char m)
484 (beginning-of-line) ; so re-search will work. 485 (beginning-of-line) ; so re-search will work.
485 486
486 ;; Search tag table 487 ;; Search tag table
487 (setq found-in-tag-table 488 (catch 'foo
488 (re-search-forward regexp nil t) 489 (while (re-search-forward regexp nil t)
489 found-anchor 490 (setq found-anchor
490 (string-equal "Ref:" (match-string 1))) 491 (string-equal "Ref:" (match-string 1)))
492 (or nodepos (setq nodepos (point))
493 (if (string-equal (match-string 2) nodename)
494 (throw 'foo t))))
495 (if nodepos
496 (goto-char nodepos)
497 (setq found-in-tag-table nil)))
491 (if found-in-tag-table 498 (if found-in-tag-table
492 (setq guesspos (1+ (read (current-buffer))))) 499 (setq guesspos (1+ (read (current-buffer)))))
493 (setq found-mode major-mode)) 500 (setq found-mode major-mode))
494 501
495 ;; Indirect file among split files 502 ;; Indirect file among split files
504 ;; Info-read-subfile. Thus the hackery 511 ;; Info-read-subfile. Thus the hackery
505 ;; above. 512 ;; above.
506 (setq guesspos (Info-read-subfile guesspos))))) 513 (setq guesspos (Info-read-subfile guesspos)))))
507 514
508 ;; Handle anchor 515 ;; Handle anchor
509 (if found-anchor (goto-char guesspos) 516 (if found-anchor
517 (goto-char (setq anchorpos guesspos))
510 518
511 ;; Else we may have a node, which we search for: 519 ;; Else we may have a node, which we search for:
512 (goto-char (max (point-min) 520 (goto-char (max (point-min)
513 (- (byte-to-position guesspos) 1000))) 521 (- (byte-to-position guesspos) 1000)))
514 ;; Now search from our advised position 522 ;; Now search from our advised position
515 ;; (or from beg of buffer) 523 ;; (or from beg of buffer)
516 ;; to find the actual node. 524 ;; to find the actual node.
517 ;; First, check whether the node is right 525 ;; First, check whether the node is right
518 ;; where we are, in case the buffer begins 526 ;; where we are, in case the buffer begins
519 ;; with a node. 527 ;; with a node.
528 (setq nodepos nil)
520 (or (Info-node-at-bob-matching regexp) 529 (or (Info-node-at-bob-matching regexp)
521 (catch 'foo 530 (catch 'foo
522 (while (search-forward "\n\^_" nil t) 531 (while (search-forward "\n\^_" nil t)
523 (forward-line 1) 532 (forward-line 1)
524 (let ((beg (point))) 533 (let ((beg (point)))
525 (forward-line 1) 534 (forward-line 1)
526 (if (re-search-backward regexp beg t) 535 (if (re-search-backward regexp beg t)
527 (progn 536 (if (string-equal (match-string 2) nodename)
528 (beginning-of-line) 537 (progn
529 (throw 'foo t))))) 538 (beginning-of-line)
530 (error 539 (throw 'foo t))
531 "No such anchor in tag table or node in tag table or file: %s" 540 (or nodepos
532 nodename))))) 541 (setq nodepos (point)))))))
542 (if nodepos
543 (progn
544 (goto-char nodepos)
545 (beginning-of-line))
546 (error
547 "No such anchor in tag table or node in tag table or file: %s"
548 nodename))))))
533 (goto-char (max (point-min) (- guesspos 1000))) 549 (goto-char (max (point-min) (- guesspos 1000)))
534 ;; Now search from our advised position (or from beg of buffer) 550 ;; Now search from our advised position (or from beg of buffer)
535 ;; to find the actual node. 551 ;; to find the actual node.
536 ;; First, check whether the node is right where we are, in case 552 ;; First, check whether the node is right where we are, in case
537 ;; the buffer begins with a node. 553 ;; the buffer begins with a node.
554 (setq nodepos nil)
538 (or (Info-node-at-bob-matching regexp) 555 (or (Info-node-at-bob-matching regexp)
539 (catch 'foo 556 (catch 'foo
540 (while (search-forward "\n\^_" nil t) 557 (while (search-forward "\n\^_" nil t)
541 (forward-line 1) 558 (forward-line 1)
542 (let ((beg (point))) 559 (let ((beg (point)))
543 (forward-line 1) 560 (forward-line 1)
544 (if (re-search-backward regexp beg t) 561 (if (re-search-backward regexp beg t)
545 (throw 'foo t)))) 562 (if (string-equal (match-string 2) nodename)
546 (error "No such node: %s" nodename))))) 563 (throw 'foo t)
564 (or nodepos
565 (setq nodepos (point)))))))
566 (if nodepos
567 (goto-char nodepos)
568 (error "No such node: %s" nodename))))))
547 (Info-select-node) 569 (Info-select-node)
548 (goto-char (point-min)))) 570 (goto-char (or anchorpos (point-min)))))
549 ;; If we did not finish finding the specified node, 571 ;; If we did not finish finding the specified node,
550 ;; go back to the previous one. 572 ;; go back to the previous one.
551 (or Info-current-node no-going-back (null Info-history) 573 (or Info-current-node no-going-back (null Info-history)
552 (let ((hist (car Info-history))) 574 (let ((hist (car Info-history)))
553 (setq Info-history (cdr Info-history)) 575 (setq Info-history (cdr Info-history))