]> code.delx.au - gnu-emacs/blobdiff - lisp/info.el
(hif-nexttoken): Move to before first def.
[gnu-emacs] / lisp / info.el
index 301ad5ae606d6d0e99ef93230b37478a5baf1d58..660af03c959fbf57c35c7e9111b4b2317044d32a 100644 (file)
@@ -1,4 +1,4 @@
-;;; info.el --- info package for Emacs.
+;;; info.el --- info package for Emacs
 
 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
 ;;  Free Software Foundation, Inc.
@@ -270,7 +270,7 @@ Do the right thing if the file has been compressed or zipped."
         (check-short (and (fboundp 'msdos-long-file-names)
                           lfn))
         fullname decoder done)
-    (if (file-exists-p filename)
+    (if (info-file-exists-p filename)
        ;; FILENAME exists--see if that name contains a suffix.
        ;; If so, set DECODE accordingly.
        (progn
@@ -508,12 +508,12 @@ it says do not attempt further (recursive) error recovery."
 (defun Info-on-current-buffer (&optional nodename)
   "Use the `Info-mode' to browse the current info buffer.
 If a prefix arg is provided, it queries for the NODENAME which
-else defaults to `Top'."
+else defaults to \"Top\"."
   (interactive
    (list (if current-prefix-arg
             (completing-read "Node name: " (Info-build-node-completions)
-                             nil t "Top")
-          "Top")))
+                             nil t "Top"))))
+  (unless nodename (setq nodename "Top"))
   (info-initialize)
   (Info-mode)
   (set (make-local-variable 'Info-current-file) t)
@@ -609,7 +609,7 @@ a case-insensitive match is tried."
               (erase-buffer)
               (if (eq filename t)
                   (Info-insert-dir)
-                (info-insert-file-contents filename t)
+                (info-insert-file-contents filename nil)
                 (setq default-directory (file-name-directory filename)))
               (set-buffer-modified-p nil)
               ;; See whether file has a tag table.  Record the location if yes.
@@ -901,7 +901,6 @@ a case-insensitive match is tried."
       (while buffers
        (kill-buffer (car buffers))
        (setq buffers (cdr buffers)))
-      (if Info-fontify (Info-fontify-menu-headers))
       (goto-char (point-min))
       (if problems
          (message "Composing main Info directory...problems encountered, see `*Messages*'")
@@ -1039,7 +1038,11 @@ Bind this in case the user sets it to nil."
 ;; of the sort that is found in pointers in nodes.
 
 (defun Info-goto-node (nodename &optional fork)
-  "Go to info node named NAME.  Give just NODENAME or (FILENAME)NODENAME.
+  "Go to info node named NODENAME.  Give just NODENAME or (FILENAME)NODENAME.
+If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
+FILENAME; otherwise, NODENAME should be in the current Info file (or one of
+its sub-files).
+Completion is available, but only for node names in the current Info file.
 If FORK is non-nil (interactively with a prefix arg), show the node in
 a new info buffer.
 If FORK is a string, it is the name to use for the new buffer."
@@ -1124,7 +1127,7 @@ If FORK is a string, it is the name to use for the new buffer."
                            (cons (list (match-string-no-properties 1))
                                  compl))))))))
        (setq compl (cons '("*") compl))
-       (setq Info-current-file-completions compl))))
+       (set (make-local-variable 'Info-current-file-completions) compl))))
 \f
 (defun Info-restore-point (hl)
   "If this node has been visited, restore the point value when we left."
@@ -1349,8 +1352,9 @@ FOOTNOTENAME may be an abbreviation of the reference name."
          (setq default (car (car completions))))
      (if completions
         (let ((input (completing-read (if default
-                                          (concat "Follow reference named: ("
-                                                  default ") ")
+                                          (concat
+                                           "Follow reference named: (default "
+                                           default ") ")
                                         "Follow reference named: ")
                                       completions nil t)))
           (list (if (equal input "")
@@ -1389,12 +1393,7 @@ FOOTNOTENAME may be an abbreviation of the reference name."
              (buffer-substring-no-properties beg (1- (point)))
            (skip-chars-forward " \t\n")
            (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
-    (while (setq i (string-match "\n" str i))
-      (aset str i ?\ ))
-    ;; Collapse multiple spaces.
-    (while (string-match "  +" str)
-      (setq str (replace-match " " t t str)))
-    str))
+    (replace-regexp-in-string "[ \n]+" " " str)))
 
 ;; No one calls this.
 ;;(defun Info-menu-item-sequence (list)
@@ -1403,54 +1402,62 @@ FOOTNOTENAME may be an abbreviation of the reference name."
 ;;    (setq list (cdr list))))
 
 (defvar Info-complete-menu-buffer)
+(defvar Info-complete-next-re nil)
+(defvar Info-complete-cache nil)
 
 (defun Info-complete-menu-item (string predicate action)
-  (let ((completion-ignore-case t)
-       (case-fold-search t))
-    (cond ((eq action nil)
-          (let (completions
-                (pattern (concat "\n\\* +\\("
-                                 (regexp-quote string)
-                                 "[^:\t\n]*\\):")))
-            (save-excursion
-              (set-buffer Info-complete-menu-buffer)
-              (goto-char (point-min))
-              (search-forward "\n* Menu:")
-              (while (re-search-forward pattern nil t)
-                (setq completions
-                      (cons (cons (match-string-no-properties 1)
-                                  (match-beginning 1))
-                            completions))))
-            (try-completion string completions predicate)))
-         ((eq action t)
-          (let (completions
-                (pattern (concat "\n\\* +\\("
-                                 (regexp-quote string)
-                                 "[^:\t\n]*\\):")))
-            (save-excursion
-              (set-buffer Info-complete-menu-buffer)
-              (goto-char (point-min))
-              (search-forward "\n* Menu:")
-              (while (re-search-forward pattern nil t)
-                (setq completions (cons (cons
-                                         (match-string-no-properties 1)
-                                         (match-beginning 1))
-                                        completions))))
-            (all-completions string completions predicate)))
-         (t
-          (save-excursion
-            (set-buffer Info-complete-menu-buffer)
-            (goto-char (point-min))
-            (search-forward "\n* Menu:")
-            (re-search-forward (concat "\n\\* +"
-                                       (regexp-quote string)
-                                       ":")
-                               nil t))))))
+  (save-excursion
+    (set-buffer Info-complete-menu-buffer)
+    (let ((completion-ignore-case t)
+         (case-fold-search t)
+         (orignode Info-current-node)
+         nextnode)
+      (goto-char (point-min))
+      (search-forward "\n* Menu:")
+      (if (not (memq action '(nil t)))
+         (re-search-forward
+          (concat "\n\\* +" (regexp-quote string) ":") nil t)
+       (let ((pattern (concat "\n\\* +\\("
+                              (regexp-quote string)
+                              "[^:\t\n]*\\):"))
+             completions)
+         ;; Check the cache.
+         (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
+                  (equal (nth 1 Info-complete-cache) Info-current-node)
+                  (equal (nth 2 Info-complete-cache) Info-complete-next-re)
+                  (let ((prev (nth 3 Info-complete-cache)))
+                    (eq t (compare-strings string 0 (length prev)
+                                           prev 0 nil t))))
+             ;; We can reuse the previous list.
+             (setq completions (nth 4 Info-complete-cache))
+           ;; The cache can't be used.
+           (while
+               (progn
+                 (while (re-search-forward pattern nil t)
+                   (push (cons (match-string-no-properties 1)
+                               (match-beginning 1))
+                         completions))
+                 ;; Check subsequent nodes if applicable.
+                 (and Info-complete-next-re
+                      (setq nextnode (Info-extract-pointer "next" t))
+                      (string-match Info-complete-next-re nextnode)))
+             (Info-goto-node nextnode))
+           ;; Go back to the start node (for the next completion).
+           (unless (equal Info-current-node orignode)
+             (Info-goto-node orignode))
+           ;; Update the cache.
+           (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)
-  "Go to node for menu item named (or abbreviated) NAME.
-Completion is allowed, and the menu item point is on is the default.
+  "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
+The menu item should one of those listed in the current node's menu.
+Completion is allowed, and the default menu item is the one point is on.
 If FORK is non-nil (interactively with a prefix arg), show the node in
 a new info buffer.  If FORK is a string, it is the name to use for the
 new buffer."
@@ -1812,38 +1819,49 @@ parent node."
            (error "No cross references in this node")
          (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))
+  ;; Protect Info-history so that the current node (Top) is not added to it.
+  (let ((Info-history nil))
+    (Info-goto-node (Info-extract-menu-node-name))))
+
 (defun Info-index (topic)
   "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
 nodes whose names also contain the word \"Index\".
 If there are no exact matches to the specified topic, this chooses
 the first match which is a case-insensitive substring of a topic.
 Use the `,' command to see the other matches.
 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)
        (rnode nil)
        (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
                         (regexp-quote topic)))
        node
        (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,
-    ;; we bind Info-history to nil for internal node-switches
-    ;; so that we don't put junk in 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.
-    (let ((Info-history nil))
-      (Info-goto-node (Info-extract-menu-node-name)))
+    (Info-goto-index)
     (or (equal topic "")
        (let ((matches nil)
              (exact nil)
+             ;; We bind Info-history to nil for internal node-switches so
+             ;; that we don't put junk in the history.  In the first
+             ;; Info-goto-index call, above, we do update the history
+             ;; because that is what the user's previous node choice into it.
              (Info-history nil)
              found)
          (while
@@ -2151,8 +2169,7 @@ If no reference to follow, moves to the next node, or up if none."
        ;; Update menu menu.
        (let* ((Info-complete-menu-buffer (current-buffer))
               (items (nreverse (condition-case nil
-                                   (Info-complete-menu-item
-                                    "" (lambda (e) t) t)
+                                   (Info-complete-menu-item "" nil t)
                                  (error nil))))
               entries current
               (number 0))
@@ -2225,6 +2242,7 @@ The name of the info file is prepended to the node name in parentheses."
 \f
 ;; Info mode is suitable only for specially formatted data.
 (put 'Info-mode 'mode-class 'special)
+(put 'Info-mode 'no-clone-indirect t)
 
 (defun Info-mode ()
   "Info mode provides commands for browsing through the Info documentation tree.
@@ -2369,14 +2387,26 @@ Allowed only if variable `Info-enable-edit' is non-nil."
        (message "Tags may have changed.  Use Info-tagify if necessary")))
 \f
 (defvar Info-file-list-for-emacs
-  '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc" "message"
-    ("dired" . "dired-x") ("c" . "ccmode") "viper" "vip"
+  '("ediff" "eudc" "forms" "gnus" "info" ("mh" . "mh-e")
+    "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
+    ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
+    ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
     ("skeleton" . "autotype") ("auto-insert" . "autotype")
     ("copyright" . "autotype") ("executable" . "autotype")
     ("time-stamp" . "autotype") ("quickurl" . "autotype")
     ("tempo" . "autotype") ("hippie-expand" . "autotype")
-    ("cvs" . "pcl-cvs")
-    "ebrowse" "eshell" "cl" "idlwave" "reftex" "speedbar" "widget" "woman")
+    ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
+    ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
+    "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
+    ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
+    ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
+    ("rfc2045" . "emacs-mime")
+    ("rfc2231" . "emacs-mime")  ("rfc2047" . "emacs-mime")
+    ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
+    ("ietf-drums" . "emacs-mime")  ("quoted-printable" . "emacs-mime")
+    ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
+    ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
+    ("mml" . "emacs-mime"))
   "List of Info files that describe Emacs commands.
 An element can be a file name, or a list of the form (PREFIX . FILE)
 where PREFIX is a name prefix and FILE is the file to look in.
@@ -2537,80 +2567,85 @@ the variable `Info-file-list-for-emacs'."
                           'face 'info-menu-header)))))
 
 (defun Info-fontify-node ()
-  (save-excursion
-    (let ((buffer-read-only nil)
-         (case-fold-search t))
-      (goto-char (point-min))
-      (when (looking-at "^File: [^,: \t]+,?[ \t]+")
-       (goto-char (match-end 0))
-       (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
+  ;; Only fontify the node if it hasn't already been done.  [We pass in
+  ;; LIMIT arg to `next-property-change' because it seems to search past
+  ;; (point-max).]
+  (unless (< (next-property-change (point-min) nil (point-max))
+            (point-max))
+    (save-excursion
+      (let ((buffer-read-only nil)
+           (case-fold-search t))
+       (goto-char (point-min))
+       (when (looking-at "^File: [^,: \t]+,?[ \t]+")
          (goto-char (match-end 0))
-         (let* ((nbeg (match-beginning 2))
-                (nend (match-end 2))
-                (tbeg (match-beginning 1))
-                (tag (buffer-substring tbeg (match-end 1))))
-           (if (string-equal tag "Node")
-               (put-text-property nbeg nend 'face 'info-header-node)
-             (put-text-property nbeg nend 'face 'info-header-xref)
-             (put-text-property nbeg nend 'mouse-face 'highlight)
-             (put-text-property tbeg nend
-                                'help-echo
-                                (concat "Go to node "
-                                        (buffer-substring nbeg nend)))
-             (let ((fun (cdr (assoc tag '(("Prev" . Info-prev)
-                                          ("Next" . Info-next)
-                                          ("Up" . Info-up))))))
-               (when fun
-                 (let ((keymap (make-sparse-keymap)))
-                   (define-key keymap [header-line mouse-1] fun)
-                   (define-key keymap [header-line mouse-2] fun)
-                   (put-text-property tbeg nend 'local-map keymap))))
-             ))))
-      (goto-char (point-min))
-      (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
-                               nil t)
-       (let ((c (preceding-char))
-             face)
-         (cond ((= c ?*) (setq face 'Info-title-1-face))
-               ((= c ?=) (setq face 'Info-title-2-face))
-               ((= c ?-) (setq face 'Info-title-3-face))
-               (t        (setq face 'Info-title-4-face)))
-         (put-text-property (match-beginning 1) (match-end 1)
-                            'face face))
-       ;; This is a serious problem for trying to handle multiple
-       ;; frame types at once.  We want this text to be invisible
-       ;; on frames that can display the font above.
-       (when (memq (framep (selected-frame)) '(x pc w32 mac))
-         (add-text-properties (match-end 1) (match-end 2)
-                              '(invisible t intangible t))
-         (add-text-properties (1- (match-end 1)) (match-end 2)
-                              '(intangible t))))
-      (goto-char (point-min))
-      (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
-       (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
-           nil
-         (add-text-properties (match-beginning 1) (match-end 1)
-                              '(face info-xref
-                                mouse-face highlight
-                                help-echo "mouse-2: go to this node"))))
-      (goto-char (point-min))
-      (if (and (search-forward "\n* Menu:" nil t)
-              (not (string-match "\\<Index\\>" Info-current-node))
-              ;; Don't take time to annotate huge menus
-              (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
-         (let ((n 0))
-           (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
-             (setq n (1+ n))
-             (if (memq n '(5 9))       ; visual aids to help with 1-9 keys
-                 (put-text-property (match-beginning 0)
-                                    (1+ (match-beginning 0))
-                                    'face 'info-menu-5))
-             (add-text-properties (match-beginning 1) (match-end 1)
-                                  '(face info-xref
-                                    mouse-face highlight
-                                    help-echo "mouse-2: go to this node")))))
-      (Info-fontify-menu-headers)
-      (set-buffer-modified-p nil))))
+         (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
+           (goto-char (match-end 0))
+           (let* ((nbeg (match-beginning 2))
+                  (nend (match-end 2))
+                  (tbeg (match-beginning 1))
+                  (tag (buffer-substring tbeg (match-end 1))))
+             (if (string-equal tag "Node")
+                 (put-text-property nbeg nend 'face 'info-header-node)
+               (put-text-property nbeg nend 'face 'info-header-xref)
+               (put-text-property nbeg nend 'mouse-face 'highlight)
+               (put-text-property tbeg nend
+                                  'help-echo
+                                  (concat "Go to node "
+                                          (buffer-substring nbeg nend)))
+               (let ((fun (cdr (assoc tag '(("Prev" . Info-prev)
+                                            ("Next" . Info-next)
+                                            ("Up" . Info-up))))))
+                 (when fun
+                   (let ((keymap (make-sparse-keymap)))
+                     (define-key keymap [header-line down-mouse-1] fun)
+                     (define-key keymap [header-line down-mouse-2] fun)
+                     (put-text-property tbeg nend 'local-map keymap))))
+               ))))
+       (goto-char (point-min))
+       (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
+                                 nil t)
+         (let ((c (preceding-char))
+               face)
+           (cond ((= c ?*) (setq face 'Info-title-1-face))
+                 ((= c ?=) (setq face 'Info-title-2-face))
+                 ((= c ?-) (setq face 'Info-title-3-face))
+                 (t        (setq face 'Info-title-4-face)))
+           (put-text-property (match-beginning 1) (match-end 1)
+                              'face face))
+         ;; This is a serious problem for trying to handle multiple
+         ;; frame types at once.  We want this text to be invisible
+         ;; on frames that can display the font above.
+         (when (memq (framep (selected-frame)) '(x pc w32 mac))
+           (add-text-properties (match-end 1) (match-end 2)
+                                '(invisible t intangible t))
+           (add-text-properties (1- (match-end 1)) (match-end 2)
+                                '(intangible t))))
+       (goto-char (point-min))
+       (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
+         (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
+             nil
+           (add-text-properties (match-beginning 1) (match-end 1)
+                                '(face info-xref
+                                  mouse-face highlight
+                                  help-echo "mouse-2: go to this node"))))
+       (goto-char (point-min))
+       (if (and (search-forward "\n* Menu:" nil t)
+                (not (string-match "\\<Index\\>" Info-current-node))
+                ;; Don't take time to annotate huge menus
+                (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
+           (let ((n 0))
+             (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
+               (setq n (1+ n))
+               (if (zerop (% n 3)) ; visual aids to help with 1-9 keys
+                   (put-text-property (match-beginning 0)
+                                      (1+ (match-beginning 0))
+                                      'face 'info-menu-5))
+               (add-text-properties (match-beginning 1) (match-end 1)
+                                    '(face info-xref
+                                      mouse-face highlight
+                                      help-echo "mouse-2: go to this node")))))
+       (Info-fontify-menu-headers)
+       (set-buffer-modified-p nil)))))
 \f
 
 ;; When an Info buffer is killed, make sure the associated tags buffer