Mercurial > emacs
comparison lisp/info.el @ 23923:950f2c278c9a
(Info-node-at-bob-matching): New function.
(Info-find-node, Info-build-node-completions): Call it.
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Mon, 21 Dec 1998 11:18:29 +0000 |
parents | 74c3c643e90c |
children | bba55b2f2577 |
comparison
equal
deleted
inserted
replaced
23922:81d1dacd379e | 23923:950f2c278c9a |
---|---|
327 (error (send-string-to-terminal | 327 (error (send-string-to-terminal |
328 (format "%s\n" (if (eq (car-safe err) 'error) | 328 (format "%s\n" (if (eq (car-safe err) 'error) |
329 (nth 1 err) err))) | 329 (nth 1 err) err))) |
330 (save-buffers-kill-emacs))) | 330 (save-buffers-kill-emacs))) |
331 (info))) | 331 (info))) |
332 | |
333 ;; See if the the accessible portion of the buffer begins with a node | |
334 ;; delimiter, and the node header line which follows matches REGEXP. | |
335 ;; Typically, this test will be followed by a loop that examines the | |
336 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity | |
337 ;; to have the overhead of this special test inside the loop. | |
338 | |
339 ;; This function changes match-data, but supposedly the caller might | |
340 ;; want to use the results of re-search-backward. | |
341 | |
342 ;; The return value is the value of point at the beginning of matching | |
343 ;; REGERXP, if the function succeeds, nil otherwise. | |
344 (defun Info-node-at-bob-matching (regexp) | |
345 (and (bobp) ; are we at beginning of buffer? | |
346 (looking-at "\^_") ; does it begin with node delimiter? | |
347 (let (beg) | |
348 (forward-line 1) | |
349 (setq beg (point)) | |
350 (forward-line 1) ; does the line after delimiter match REGEXP? | |
351 (re-search-backward regexp beg t)))) | |
332 | 352 |
333 ;; Go to an info node specified as separate filename and nodename. | 353 ;; Go to an info node specified as separate filename and nodename. |
334 ;; no-going-back is non-nil if recovering from an error in this function; | 354 ;; no-going-back is non-nil if recovering from an error in this function; |
335 ;; it says do not attempt further (recursive) error recovery. | 355 ;; it says do not attempt further (recursive) error recovery. |
336 (defun Info-find-node (filename nodename &optional no-going-back) | 356 (defun Info-find-node (filename nodename &optional no-going-back) |
499 (goto-char (max (point-min) | 519 (goto-char (max (point-min) |
500 (- (byte-to-position guesspos) 1000))) | 520 (- (byte-to-position guesspos) 1000))) |
501 ;; Now search from our advised position | 521 ;; Now search from our advised position |
502 ;; (or from beg of buffer) | 522 ;; (or from beg of buffer) |
503 ;; to find the actual node. | 523 ;; to find the actual node. |
504 (catch 'foo | 524 ;; First, check whether the node is right |
505 (if (and (eq (point) (point-min)) | 525 ;; where we are, in case the buffer begins |
506 (looking-at "\^_") | 526 ;; with a node. |
507 (= (forward-line 1) 0)) | 527 (or (Info-node-at-bob-matching regexp) |
508 (let ((beg (point))) | 528 (catch 'foo |
529 (while (search-forward "\n\^_" nil t) | |
509 (forward-line 1) | 530 (forward-line 1) |
510 (if (re-search-backward regexp beg t) | 531 (let ((beg (point))) |
511 (progn | 532 (forward-line 1) |
512 (beginning-of-line) | 533 (if (re-search-backward regexp beg t) |
513 (throw 'foo t))))) | 534 (progn |
514 (while (search-forward "\n\^_" nil t) | 535 (beginning-of-line) |
515 (forward-line 1) | 536 (throw 'foo t))))) |
516 (let ((beg (point))) | 537 (error |
517 (forward-line 1) | 538 "No such anchor in tag table or node in tag table or file: %s" |
518 (if (re-search-backward regexp beg t) | 539 nodename))))) |
519 (progn | |
520 (beginning-of-line) | |
521 (throw 'foo t))))) | |
522 (error | |
523 "No such anchor in tag table or node in tag table or file: %s" | |
524 nodename)))) | |
525 (goto-char (max (point-min) (- guesspos 1000))) | 540 (goto-char (max (point-min) (- guesspos 1000))) |
526 ;; Now search from our advised position (or from beg of buffer) | 541 ;; Now search from our advised position (or from beg of buffer) |
527 ;; to find the actual node. | 542 ;; to find the actual node. |
528 (catch 'foo | 543 ;; First, check whether the node is right where we are, in case |
529 (if (and (eq (point) (point-min)) | 544 ;; the buffer begins with a node. |
530 (looking-at "\^_") | 545 (or (Info-node-at-bob-matching regexp) |
531 (= (forward-line 1) 0)) | 546 (catch 'foo |
532 (let ((beg (point))) | 547 (while (search-forward "\n\^_" nil t) |
533 (forward-line 1) | 548 (forward-line 1) |
534 (if (re-search-backward regexp beg t) | 549 (let ((beg (point))) |
535 (progn | 550 (forward-line 1) |
536 (beginning-of-line) | 551 (if (re-search-backward regexp beg t) |
537 (throw 'foo t))))) | 552 (throw 'foo t)))) |
538 (while (search-forward "\n\^_" nil t) | 553 (error "No such node: %s" nodename))))) |
539 (forward-line 1) | |
540 (let ((beg (point))) | |
541 (forward-line 1) | |
542 (if (re-search-backward regexp beg t) | |
543 (throw 'foo t)))) | |
544 (error "No such node: %s" nodename)))) | |
545 (Info-select-node) | 554 (Info-select-node) |
546 (goto-char (point-min)))) | 555 (goto-char (point-min)))) |
547 ;; If we did not finish finding the specified node, | 556 ;; If we did not finish finding the specified node, |
548 ;; go back to the previous one. | 557 ;; go back to the previous one. |
549 (or Info-current-node no-going-back (null Info-history) | 558 (or Info-current-node no-going-back (null Info-history) |
875 | 884 |
876 (defun Info-build-node-completions () | 885 (defun Info-build-node-completions () |
877 (or Info-current-file-completions | 886 (or Info-current-file-completions |
878 (let ((compl nil) | 887 (let ((compl nil) |
879 ;; Bind this in case the user sets it to nil. | 888 ;; Bind this in case the user sets it to nil. |
880 (case-fold-search t)) | 889 (case-fold-search t) |
890 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]")) | |
881 (save-excursion | 891 (save-excursion |
882 (save-restriction | 892 (save-restriction |
883 (if (marker-buffer Info-tag-table-marker) | 893 (if (marker-buffer Info-tag-table-marker) |
884 (let ((marker Info-tag-table-marker)) | 894 (let ((marker Info-tag-table-marker)) |
885 (set-buffer (marker-buffer marker)) | 895 (set-buffer (marker-buffer marker)) |
890 (cons (list (buffer-substring (match-beginning 1) | 900 (cons (list (buffer-substring (match-beginning 1) |
891 (match-end 1))) | 901 (match-end 1))) |
892 compl)))) | 902 compl)))) |
893 (widen) | 903 (widen) |
894 (goto-char (point-min)) | 904 (goto-char (point-min)) |
895 (if (and (looking-at "\^_") | 905 ;; If the buffer begins with a node header, process that first. |
896 (= (forward-line 1) 0)) | 906 (if (Info-node-at-bob-matching node-regexp) |
897 (let ((beg (point))) | 907 (setq compl (list (buffer-substring (match-beginning 1) |
898 (forward-line 1) | 908 (match-end 1))))) |
899 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]" | 909 ;; Now for the rest of the nodes. |
900 beg t) | |
901 (setq compl | |
902 (list (buffer-substring (match-beginning 1) | |
903 (match-end 1))))))) | |
904 (while (search-forward "\n\^_" nil t) | 910 (while (search-forward "\n\^_" nil t) |
905 (forward-line 1) | 911 (forward-line 1) |
906 (let ((beg (point))) | 912 (let ((beg (point))) |
907 (forward-line 1) | 913 (forward-line 1) |
908 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]" | 914 (if (re-search-backward node-regexp beg t) |
909 beg t) | |
910 (setq compl | 915 (setq compl |
911 (cons (list (buffer-substring (match-beginning 1) | 916 (cons (list (buffer-substring (match-beginning 1) |
912 (match-end 1))) | 917 (match-end 1))) |
913 compl)))))))) | 918 compl)))))))) |
914 (setq Info-current-file-completions compl)))) | 919 (setq Info-current-file-completions compl)))) |