(defvar Info-current-file-completions nil
"Cached completion list for current Info file.")
+(defvar Info-file-completions nil
+ "Cached completion alist of visited Info files.
+Each element of the alist is (FILE . COMPLETIONS)")
+
(defvar Info-file-supports-index-cookies nil
"Non-nil if current Info file supports index cookies.")
(substring string 1)
predicate
code))
- ;; If a file name was given, then any node is fair game.
- ((string-match "\\`(" string)
- (cond
- ((eq code nil) string)
- ((eq code t) nil)
- (t t)))
+ ;; If a file name was given, complete nodes in the file.
+ ((string-match "\\`(\\([^)]+\\))" string)
+ (let ((file0 (match-string 0 string))
+ (file1 (match-string 1 string))
+ (node (substring string (match-end 0))))
+ (completion-table-with-context
+ file0
+ (apply-partially
+ (lambda (string pred action)
+ (complete-with-action
+ action
+ (Info-build-node-completions (Info-find-file file1))
+ string pred)))
+ node predicate code)))
;; Otherwise use Info-read-node-completion-table.
(t (complete-with-action
code Info-read-node-completion-table string predicate))))
(Info-read-node-name prompt)
nodename)))
-(defun Info-build-node-completions ()
- (or Info-current-file-completions
- (let ((compl nil)
- ;; Bind this in case the user sets it to nil.
- (case-fold-search t)
- (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
- (save-excursion
- (save-restriction
- (or Info-tag-table-marker
- (error "No Info tags found"))
- (if (marker-buffer Info-tag-table-marker)
- (let ((marker Info-tag-table-marker))
- (set-buffer (marker-buffer marker))
- (widen)
- (goto-char marker)
- (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
- (setq compl
- (cons (list (match-string-no-properties 2))
- compl))))
+(defun Info-build-node-completions (&optional file)
+ (if file
+ (or (cdr (assoc file Info-file-completions))
+ (with-temp-buffer
+ (Info-mode)
+ (Info-goto-node (format "(%s)Top" file))
+ (Info-build-node-completions-1)
+ (push (cons file Info-current-file-completions) Info-file-completions)
+ Info-current-file-completions))
+ (or Info-current-file-completions
+ (Info-build-node-completions-1))))
+
+(defun Info-build-node-completions-1 ()
+ (let ((compl nil)
+ ;; Bind this in case the user sets it to nil.
+ (case-fold-search t)
+ (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
+ (save-excursion
+ (save-restriction
+ (or Info-tag-table-marker
+ (error "No Info tags found"))
+ (if (marker-buffer Info-tag-table-marker)
+ (let ((marker Info-tag-table-marker))
+ (set-buffer (marker-buffer marker))
(widen)
- (goto-char (point-min))
- ;; If the buffer begins with a node header, process that first.
- (if (Info-node-at-bob-matching node-regexp)
- (setq compl (list (match-string-no-properties 1))))
- ;; Now for the rest of the nodes.
- (while (search-forward "\n\^_" nil t)
- (forward-line 1)
- (let ((beg (point)))
- (forward-line 1)
- (if (re-search-backward node-regexp beg t)
- (setq compl
- (cons (list (match-string-no-properties 1))
- compl))))))))
- (setq compl (cons '("*") compl))
- (set (make-local-variable 'Info-current-file-completions) compl))))
+ (goto-char marker)
+ (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
+ (setq compl
+ (cons (list (match-string-no-properties 2))
+ compl))))
+ (widen)
+ (goto-char (point-min))
+ ;; If the buffer begins with a node header, process that first.
+ (if (Info-node-at-bob-matching node-regexp)
+ (setq compl (list (match-string-no-properties 1))))
+ ;; Now for the rest of the nodes.
+ (while (search-forward "\n\^_" nil t)
+ (forward-line 1)
+ (let ((beg (point)))
+ (forward-line 1)
+ (if (re-search-backward node-regexp beg t)
+ (setq compl
+ (cons (list (match-string-no-properties 1))
+ compl))))))))
+ (setq compl (cons '("*") (nreverse compl)))
+ (set (make-local-variable 'Info-current-file-completions) compl)
+ compl))
+
\f
(defun Info-restore-point (hl)
"If this node has been visited, restore the point value when we left."