summaryrefslogtreecommitdiff
path: root/lisp/info.el
diff options
context:
space:
mode:
authorJuri Linkov <juri@jurta.org>2012-12-27 22:42:02 +0200
committerJuri Linkov <juri@jurta.org>2012-12-27 22:42:02 +0200
commit313f39aa03cc40ddc4faea08636c74bfa52ec099 (patch)
tree2b8066dc0bd728aaf3247a1a136304811f95d5b9 /lisp/info.el
parenta45b76475ee930497cca375432b44aa0def77fa0 (diff)
downloademacs-313f39aa03cc40ddc4faea08636c74bfa52ec099.tar.gz
emacs-313f39aa03cc40ddc4faea08636c74bfa52ec099.tar.bz2
emacs-313f39aa03cc40ddc4faea08636c74bfa52ec099.zip
* lisp/info.el (Info-file-completions): New variable.
(Info-read-node-name-1): Complete node names in the Info file when a file name is given. Call `Info-build-node-completions' with a file name. (Info-build-node-completions): Add new arg `file'. When it is non-nil, visit it in a temporary buffer and cache its completions in `Info-current-file-completions'. Move most of the function body to `Info-build-node-completions-1'. (Info-build-node-completions-1): New function with the body from `Info-build-node-completions'. Fixes: debbugs:12456
Diffstat (limited to 'lisp/info.el')
-rw-r--r--lisp/info.el105
1 files changed, 65 insertions, 40 deletions
diff --git a/lisp/info.el b/lisp/info.el
index 4c7bb981afc..19f9212f88a 100644
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -397,6 +397,10 @@ Marker points nowhere if file has no tag table.")
(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.")
@@ -1771,12 +1775,20 @@ See `completing-read' for a description of arguments and usage."
(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))))
@@ -1793,41 +1805,54 @@ in the current Info file, or \"(FILENAME)NODENAME\"."
(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))
+
(defun Info-restore-point (hl)
"If this node has been visited, restore the point value when we left."