1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-14 16:50:58 +00:00

(Info-complete-next-re, Info-complete-cache): New vars.

(Info-complete-menu-item): Rewrite.  Add the ability to search
several sequential nodes.  Add a simple caching mechanism.
(Info-goto-index): New function extracted from Info-index.
(Info-index): Use it.  Add completion to the interactive spec.
(Info-menu-update): Simplify call to `Info-complete-menu-item'.
This commit is contained in:
Stefan Monnier 2001-11-29 23:20:49 +00:00
parent 75e95a9780
commit e4e8ee638e

View File

@ -1407,49 +1407,56 @@ FOOTNOTENAME may be an abbreviation of the reference name."
;; (setq list (cdr list)))) ;; (setq list (cdr list))))
(defvar Info-complete-menu-buffer) (defvar Info-complete-menu-buffer)
(defvar Info-complete-next-re nil)
(defvar Info-complete-cache nil)
(defun Info-complete-menu-item (string predicate action) (defun Info-complete-menu-item (string predicate action)
(let ((completion-ignore-case t) (save-excursion
(case-fold-search t)) (set-buffer Info-complete-menu-buffer)
(cond ((eq action nil) (let ((completion-ignore-case t)
(let (completions (case-fold-search t)
(pattern (concat "\n\\* +\\(" (orignode Info-current-node)
(regexp-quote string) nextnode)
"[^:\t\n]*\\):"))) (goto-char (point-min))
(save-excursion (search-forward "\n* Menu:")
(set-buffer Info-complete-menu-buffer) (if (not (memq action '(nil t)))
(goto-char (point-min)) (re-search-forward
(search-forward "\n* Menu:") (concat "\n\\* +" (regexp-quote string) ":") nil t)
(while (re-search-forward pattern nil t) (let ((pattern (concat "\n\\* +\\("
(setq completions (regexp-quote string)
(cons (cons (match-string-no-properties 1) "[^:\t\n]*\\):"))
(match-beginning 1)) completions)
completions)))) ;; Check the cache.
(try-completion string completions predicate))) (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
((eq action t) (equal (nth 1 Info-complete-cache) Info-current-node)
(let (completions (equal (nth 2 Info-complete-cache) Info-complete-next-re)
(pattern (concat "\n\\* +\\(" (let ((prev (nth 3 Info-complete-cache)))
(regexp-quote string) (eq t (compare-strings string 0 (length prev)
"[^:\t\n]*\\):"))) prev 0 nil t))))
(save-excursion ;; We can reuse the previous list.
(set-buffer Info-complete-menu-buffer) (setq completions (nth 4 Info-complete-cache))
(goto-char (point-min)) ;; The cache can't be used.
(search-forward "\n* Menu:") (while
(while (re-search-forward pattern nil t) (progn
(setq completions (cons (cons (while (re-search-forward pattern nil t)
(match-string-no-properties 1) (push (cons (match-string-no-properties 1)
(match-beginning 1)) (match-beginning 1))
completions)))) completions))
(all-completions string completions predicate))) ;; Check subsequent nodes if applicable.
(t (and Info-complete-next-re
(save-excursion (setq nextnode (Info-extract-pointer "next" t))
(set-buffer Info-complete-menu-buffer) (string-match Info-complete-next-re nextnode)))
(goto-char (point-min)) (Info-goto-node nextnode))
(search-forward "\n* Menu:") ;; Go back to the start node (for the next completion).
(re-search-forward (concat "\n\\* +" (unless (equal Info-current-node orignode)
(regexp-quote string) (Info-goto-node orignode))
":") ;; Update the cache.
nil t)))))) (setq Info-complete-cache
(list Info-current-file Info-current-node
Info-complete-next-re string completions)))
(if action
(all-completions string completions predicate)
(try-completion string completions predicate)))))))
(defun Info-menu (menu-item &optional fork) (defun Info-menu (menu-item &optional fork)
@ -1817,35 +1824,46 @@ parent node."
(error "No cross references in this node") (error "No cross references in this node")
(Info-prev-reference t))))) (Info-prev-reference t)))))
(defun Info-goto-index ()
(Info-goto-node "Top")
(or (search-forward "\n* menu:" nil t)
(error "No index"))
(or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
(error "No index"))
(goto-char (match-beginning 1))
(Info-goto-node (Info-extract-menu-node-name)))
(defun Info-index (topic) (defun Info-index (topic)
"Look up a string TOPIC in the index for this file. "Look up a string TOPIC in the index for this file.
The index is defined as the first node in the top-level menu whose The index is defined as the first node in the top level menu whose
name contains the word \"Index\", plus any immediately following name contains the word \"Index\", plus any immediately following
nodes whose names also contain the word \"Index\". nodes whose names also contain the word \"Index\".
If there are no exact matches to the specified topic, this chooses If there are no exact matches to the specified topic, this chooses
the first match which is a case-insensitive substring of a topic. the first match which is a case-insensitive substring of a topic.
Use the `,' command to see the other matches. Use the `,' command to see the other matches.
Give a blank topic name to go to the Index node itself." Give a blank topic name to go to the Index node itself."
(interactive "sIndex topic: ") (interactive
(list
(let ((Info-complete-menu-buffer (clone-buffer))
(Info-complete-next-re "\\<Index\\>"))
(unwind-protect
(with-current-buffer Info-complete-menu-buffer
(Info-goto-index)
(completing-read "Index topic: " 'Info-complete-menu-item))
(kill-buffer Info-complete-menu-buffer)))))
(let ((orignode Info-current-node) (let ((orignode Info-current-node)
(rnode nil) (rnode nil)
(pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)" (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
(regexp-quote topic))) (regexp-quote topic)))
node node
(case-fold-search t)) (case-fold-search t))
(Info-goto-node "Top")
(or (search-forward "\n* menu:" nil t)
(error "No index"))
(or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
(error "No index"))
(goto-char (match-beginning 1))
;; Here, and subsequently in this function, ;; Here, and subsequently in this function,
;; we bind Info-history to nil for internal node-switches ;; we bind Info-history to nil for internal node-switches
;; so that we don't put junk in the history. ;; so that we don't put junk in the history.
;; In the first Info-goto-node call, above, we do update the history ;; In the first Info-goto-node call, above, we do update the history
;; because that is what the user's previous node choice into it. ;; because that is what the user's previous node choice into it.
(let ((Info-history nil)) (let ((Info-history nil))
(Info-goto-node (Info-extract-menu-node-name))) (Info-goto-index))
(or (equal topic "") (or (equal topic "")
(let ((matches nil) (let ((matches nil)
(exact nil) (exact nil)
@ -2156,8 +2174,7 @@ If no reference to follow, moves to the next node, or up if none."
;; Update menu menu. ;; Update menu menu.
(let* ((Info-complete-menu-buffer (current-buffer)) (let* ((Info-complete-menu-buffer (current-buffer))
(items (nreverse (condition-case nil (items (nreverse (condition-case nil
(Info-complete-menu-item (Info-complete-menu-item "" nil t)
"" (lambda (e) t) t)
(error nil)))) (error nil))))
entries current entries current
(number 0)) (number 0))