aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann2000-06-15 19:49:11 +0000
committerGerd Moellmann2000-06-15 19:49:11 +0000
commit357d11dea14b606f4daa1ae99f97fd1f692f4d0a (patch)
treee2adb0339a5353dd1f8c10ea5c289af5c73426b1
parent366f22ff9743368c4db94e57abe8aabeca2c0712 (diff)
downloademacs-357d11dea14b606f4daa1ae99f97fd1f692f4d0a.tar.gz
emacs-357d11dea14b606f4daa1ae99f97fd1f692f4d0a.zip
(Info-find-in-tag-table-1, Info-find-in-tag-table)
(Info-find-node-in-buffer-1, Info-find-node-in-buffer): New functions. (Info-find-node-2): Try a case-sensitive search first, then do a case-insensitive search.
-rw-r--r--lisp/info.el161
1 files changed, 103 insertions, 58 deletions
diff --git a/lisp/info.el b/lisp/info.el
index 76abc9043f9..78c2193f005 100644
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -430,6 +430,76 @@ else defaults to `Top'."
430 (set (make-local-variable 'Info-current-file) t) 430 (set (make-local-variable 'Info-current-file) t)
431 (Info-find-node-2 nil nodename)) 431 (Info-find-node-2 nil nodename))
432 432
433(defun Info-find-in-tag-table-1 (marker regexp case-fold)
434 "Find a node in a tag table.
435MARKER specifies the buffer and position to start searching at.
436REGEXP is a regular expression matching nodes or references. Its first
437group should match `Node:' or `Ref:'.
438CASE-FOLD t means search for a case-insensitive match.
439If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
440FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
441where the match was found, and MODE is `major-mode' of the buffer in
442which the match was found."
443 (let ((case-fold-search case-fold)
444 found-mode guesspos found-anchor)
445 (save-excursion
446 (set-buffer (marker-buffer marker))
447 (goto-char marker)
448
449 ;; Search tag table
450 (beginning-of-line)
451 (when (re-search-forward regexp nil t)
452 (list (string-equal "Ref:" (match-string 1))
453 (1+ (read (current-buffer)))
454 major-mode)))))
455
456(defun Info-find-in-tag-table (marker regexp)
457 "Find a node in a tag table.
458MARKER specifies the buffer and position to start searching at.
459REGEXP is a regular expression matching nodes or references. Its first
460group should match `Node:' or `Ref:'.
461If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
462FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
463where the match was found, and MODE is `major-mode' of the buffer in
464which the match was found.
465This function tries to find a case-sensitive match first, then a
466case-insensitive match is tried."
467 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
468 (when (null (car result))
469 (setq result (Info-find-in-tag-table-1 marker regexp t)))
470 result))
471
472(defun Info-find-node-in-buffer-1 (regexp case-fold)
473 "Find a node or anchor in the current buffer.
474REGEXP is a regular expression matching nodes or references. Its first
475group should match `Node:' or `Ref:'.
476CASE-FOLD t means search for a case-insensitive match.
477Value is the position at which a match was found, or nil if not found."
478 (let ((case-fold-search case-fold)
479 found)
480 (save-excursion
481 (when (Info-node-at-bob-matching regexp)
482 (setq found (point)))
483 (while (and (not found)
484 (search-forward "\n\^_" nil t))
485 (forward-line 1)
486 (let ((beg (point)))
487 (forward-line 1)
488 (when (re-search-backward regexp beg t)
489 (beginning-of-line)
490 (setq found (point)))))
491 found)))
492
493(defun Info-find-node-in-buffer (regexp)
494 "Find a node or anchor in the current buffer.
495REGEXP is a regular expression matching nodes or references. Its first
496group should match `Node:' or `Ref:'.
497Value is the position at which a match was found, or nil if not found.
498This function looks for a case-sensitive match first. If none is found,
499a case-insensitive match is tried."
500 (or (Info-find-node-in-buffer-1 regexp nil)
501 (Info-find-node-in-buffer-1 regexp t)))
502
433(defun Info-find-node-2 (filename nodename &optional no-going-back) 503(defun Info-find-node-2 (filename nodename &optional no-going-back)
434 (buffer-disable-undo (current-buffer)) 504 (buffer-disable-undo (current-buffer))
435 (or (eq major-mode 'Info-mode) 505 (or (eq major-mode 'Info-mode)
@@ -437,7 +507,6 @@ else defaults to `Top'."
437 (widen) 507 (widen)
438 (setq Info-current-node nil) 508 (setq Info-current-node nil)
439 (unwind-protect 509 (unwind-protect
440 ;; Bind case-fold-search in case the user sets it to nil.
441 (let ((case-fold-search t) 510 (let ((case-fold-search t)
442 anchorpos) 511 anchorpos)
443 ;; Switch files if necessary 512 ;; Switch files if necessary
@@ -505,73 +574,49 @@ else defaults to `Top'."
505 574
506 ;; Search file for a suitable node. 575 ;; Search file for a suitable node.
507 (let ((guesspos (point-min)) 576 (let ((guesspos (point-min))
508 (regexp 577 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
509 (concat "\\(Node:\\|Ref:\\) *\\(" 578 (regexp-quote nodename)
510 (regexp-quote nodename) 579 "\\) *[,\t\n\177]"))
511 "\\) *[,\t\n\177]"))
512 (nodepos nil)) 580 (nodepos nil))
513 581
514 (catch 'foo 582 (catch 'foo
583
515 ;; First, search a tag table, if any 584 ;; First, search a tag table, if any
516 (if (marker-position Info-tag-table-marker) 585 (when (marker-position Info-tag-table-marker)
517 (let (found-in-tag-table 586 (let* ((m Info-tag-table-marker)
518 found-anchor 587 (found (Info-find-in-tag-table m regexp)))
519 found-mode 588
520 (m Info-tag-table-marker)) 589 (when found
521 (save-excursion 590 ;; FOUND is (ANCHOR POS MODE).
522 (set-buffer (marker-buffer m)) 591 (setq guesspos (nth 1 found))
523 (goto-char m) 592
524 (beginning-of-line) ; so re-search will work. 593 ;; If this is an indirect file, determine which
525 594 ;; file really holds this node and read it in.
526 ;; Search tag table 595 (unless (eq (nth 2 found) 'Info-mode)
527 (setq found-in-tag-table 596 ;; Note that the current buffer must be the
528 (re-search-forward regexp nil t) 597 ;; *info* buffer on entry to
529 found-anchor 598 ;; Info-read-subfile. Thus the hackery above.
530 (string-equal "Ref:" (match-string 1))) 599 (setq guesspos (Info-read-subfile guesspos)))
531 (if found-in-tag-table
532 (setq guesspos (1+ (read (current-buffer)))))
533 (setq found-mode major-mode))
534
535 ;; Indirect file among split files
536 (if found-in-tag-table
537 (progn
538 ;; If this is an indirect file, determine
539 ;; which file really holds this node and
540 ;; read it in.
541 (if (not (eq found-mode 'Info-mode))
542 ;; Note that the current buffer must be
543 ;; the *info* buffer on entry to
544 ;; Info-read-subfile. Thus the hackery
545 ;; above.
546 (setq guesspos (Info-read-subfile guesspos)))))
547 600
548 ;; Handle anchor 601 ;; Handle anchor
549 (if found-anchor 602 (when (nth 0 found)
550 (progn 603 (goto-char (setq anchorpos guesspos))
551 (goto-char (setq anchorpos guesspos)) 604 (throw 'foo t)))))
552 (throw 'foo t)))))
553 605
554 ;; Else we may have a node, which we search for: 606 ;; Else we may have a node, which we search for:
555 (goto-char (max (point-min) 607 (goto-char (max (point-min)
556 (- (byte-to-position guesspos) 1000))) 608 (- (byte-to-position guesspos) 1000)))
557 ;; Now search from our advised position 609
558 ;; (or from beg of buffer) 610 ;; Now search from our advised position (or from beg of
559 ;; to find the actual node. 611 ;; buffer) to find the actual node. First, check
560 ;; First, check whether the node is right 612 ;; whether the node is right where we are, in case the
561 ;; where we are, in case the buffer begins 613 ;; buffer begins with a node.
562 ;; with a node. 614 (let ((pos (Info-find-node-in-buffer regexp)))
563 (or (Info-node-at-bob-matching regexp) 615 (when pos
564 (while (search-forward "\n\^_" nil t) 616 (goto-char pos)
565 (forward-line 1) 617 (throw 'foo t))
566 (let ((beg (point))) 618 (error "No such anchor in tag table or node in tag table or file: %s"
567 (forward-line 1) 619 nodename)))
568 (if (re-search-backward regexp beg t)
569 (progn
570 (beginning-of-line)
571 (throw 'foo t)))))
572 (error
573 "No such anchor in tag table or node in tag table or file: %s"
574 nodename)))
575 620
576 (Info-select-node) 621 (Info-select-node)
577 (goto-char (or anchorpos (point-min)))))) 622 (goto-char (or anchorpos (point-min))))))