2000-05-31 Karl M. Hegbloom <karlheg@debian.org>
[bpt/emacs.git] / lisp / info.el
index 002bc29..dc9a7b7 100644 (file)
@@ -1,6 +1,6 @@
 ;;; info.el --- info package for Emacs.
 
-;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98 Free Software
+;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99, 2000 Free Software
 ;; Foundation, Inc.
 
 ;; Maintainer: FSF
@@ -29,6 +29,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'jka-compr))
+
 (defgroup info nil
   "Info subsystem"
   :group 'help
@@ -59,72 +61,74 @@ The Lisp code is executed when the node is selected.")
   :group 'info)
 
 (defface info-node
-  '((t (:bold t :italic t)))
+  '((((class color) (background light)) (:foreground "brown" :bold t :italic t))
+    (((class color) (background dark)) (:foreground "white" :bold t :italic t))
+    (t (:bold t :italic t)))
   "Face for Info node names."
   :group 'info)
 
 (defface info-menu-5
-  '((t (:underline t)))
-  "Face for the fifth and tenth `*' in an Info menu."
+  '((((class color)) (:foreground "red1"))
+    (t (:underline t)))
+  "Face for the fifth and nineth `*' in an Info menu."
   :group 'info)
 
 (defface info-xref
-  '((t (:bold t)))
+  '((((class color) (background light)) (:foreground "magenta4" :bold t))
+    (((class color) (background dark)) (:foreground "cyan" :bold t))
+    (t (:bold t)))
   "Face for Info cross-references."
   :group 'info)
 
-(defcustom Info-fontify-maximum-menu-size 30000
+(defcustom Info-fontify-maximum-menu-size 100000
   "*Maximum size of menu to fontify if `Info-fontify' is non-nil."
   :type 'integer
   :group 'info)
 
-(defvar Info-directory-list
-  (let ((path (getenv "INFOPATH"))
-       ;; This is for older Emacs versions
-       ;; which might get this info.el from the Texinfo distribution.
-       (path-separator (if (boundp 'path-separator) path-separator
-                         (if (eq system-type 'ms-dos) ";" ":")))
-       (source (expand-file-name "info/" source-directory))
-       (sibling (if installation-directory
-                    (expand-file-name "info/" installation-directory)))
-       alternative)
-    (if path
-       (let ((list nil)
-             idx)
-         (while (> (length path) 0)
-           (setq idx (or (string-match path-separator path) (length path))
-                 list (cons (substring path 0 idx) list)
-                 path (substring path (min (1+ idx)
-                                           (length path)))))
-         (nreverse list))
-      (if (and sibling (file-exists-p sibling))
-         (setq alternative sibling)
-       (setq alternative source))
-      (if (or (member alternative Info-default-directory-list)
-             (not (file-exists-p alternative))
-             ;; On DOS/NT, we use movable executables always,
-             ;; and we must always find the Info dir at run time.
-             (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
-                 nil
-               ;; Use invocation-directory for Info only if we used it for
-               ;; exec-directory also.
-               (not (string= exec-directory
-                             (expand-file-name "lib-src/"
-                                               installation-directory)))))
-         Info-default-directory-list
-       (reverse (cons alternative
-                      (cdr (reverse Info-default-directory-list)))))))
+(defcustom Info-use-header-line t
+  "*Non-nil means to put the beginning-of-node links in an emacs header-line.
+A header-line does not scroll with the rest of the buffer."
+  :type 'boolean
+  :group 'info)
+
+(defface info-header-xref
+  '((t (:inherit info-xref)))
+  "Face for Info cross-references in a node header."
+  :group 'info)
+
+(defface info-header-node
+  '((t (:inherit info-node)))
+  "Face for Info nodes in a node header."
+  :group 'info)
+
+(defvar Info-directory-list nil
   "List of directories to search for Info documentation files.
 nil means not yet initialized.  In this case, Info uses the environment
 variable INFOPATH to initialize it, or `Info-default-directory-list'
 if there is no INFOPATH variable in the environment.
-The last element of `Info-default-directory-list' is the directory
-where Emacs installs the Info files that come with it.
+
+When `Info-directory-list' is initialized from the value of
+`Info-default-directory-list', and Emacs is installed in one of the
+standard directories, the directory of Info files that come with Emacs
+is put last (so that local Info files override standard ones).
+
+When `Info-directory-list' is initialized from the value of
+`Info-default-directory-list', and Emacs is not installed in one
+of the standard directories, the first element of the resulting
+list is the directory where Emacs installs the Info files that
+come with it.  This is so that Emacs's own manual, which suits the
+version of Emacs you are using, will always be found first.  This
+is useful when you install an experimental version of Emacs without
+removing the standard installation.
+
+If you want to override the order of directories in
+`Info-default-directory-list', set INFOPATH in the environment.
 
 If you run the Emacs executable from the `src' directory in the Emacs
-source tree, the `info' directory in the source tree is used as the last
-element, in place of the installation Info directory.  This is useful
-when you run a version of Emacs without installing it.")
+source tree, and INFOPATH is not defined, the `info' directory in the
+source tree is used as the first element of `Info-directory-list', in
+place of the installation Info directory.  This is useful when you run
+a version of Emacs without installing it.")
 
 (defcustom Info-additional-directory-list nil
   "List of additional directories to search for Info documentation files.
@@ -132,14 +136,28 @@ These directories are not searched for merging the `dir' file."
   :type '(repeat directory)
   :group 'info)
 
+(defcustom Info-scroll-prefer-subnodes t
+  "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
+If this is non-nil, and you scroll far enough in a node that its menu
+appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
+moves to a subnode indicated by the following menu item.  This means
+that you visit a subnode before getting to the end of the menu.
+
+Setting this option to nil results in behavior similar to the stand-alone
+Info reader program, which visits the first subnode from the menu only
+when you hit the end of the current node."
+  :type 'boolean
+  :group 'info)
+
 (defvar Info-current-file nil
   "Info file that Info is now looking at, or nil.
 This is the name that was specified in Info, not the actual file name.
-It doesn't contain directory names or file name extensions added by Info.")
+It doesn't contain directory names or file name extensions added by Info.
+Can also be t when using `Info-on-current-buffer'.")
 
 (defvar Info-current-subfile nil
-  "Info subfile that is actually in the *info* buffer now,
-or nil if current info file is not split into subfiles.")
+  "Info subfile that is actually in the *info* buffer now.
+nil if current info file is not split into subfiles.")
 
 (defvar Info-current-node nil
   "Name of node that Info is now looking at, or nil.")
@@ -155,17 +173,18 @@ Marker points nowhere if file has no tag table.")
   "Cached completion list for current Info file.")
 
 (defvar Info-index-alternatives nil
-  "List of possible matches for last Info-index command.")
+  "List of possible matches for last `Info-index' command.")
 
 (defvar Info-standalone nil
   "Non-nil if Emacs was started solely as an Info browser.")
-
+\f
 (defvar Info-suffix-list
   ;; The MS-DOS list should work both when long file names are
   ;; supported (Windows 9X), and when only 8+3 file names are available.
   (if (eq system-type 'ms-dos)
       '( (".gz"      . "gunzip")
         (".z"       . "gunzip")
+        (".bz2"     . ("bzip2" "-dc"))
         (".inz"     . "gunzip")
         (".igz"     . "gunzip")
         (".info.Z"  . "gunzip")
@@ -183,25 +202,34 @@ Marker points nowhere if file has no tag table.")
        (".info.Y".    "unyabba")
        (".info.gz".   "gunzip")
        (".info.z".    "gunzip")
+       (".info.bz2" . ("bzip2" "-dc"))
        (".info".      nil)
        ("-info.Z".   "uncompress")
        ("-info.Y".   "unyabba")
        ("-info.gz".  "gunzip")
+       ("-info.bz2" . ("bzip2" "-dc"))
        ("-info.z".   "gunzip")
        ("-info".     nil)
        ("/index.Z".   "uncompress")
        ("/index.Y".   "unyabba")
        ("/index.gz".  "gunzip")
        ("/index.z".   "gunzip")
+       ("/index.bz2". ("bzip2" "-dc"))
        ("/index".     nil)
        (".Z".         "uncompress")
        (".Y".         "unyabba")
        (".gz".        "gunzip")
        (".z".         "gunzip")
+       (".bz2" .      ("bzip2" "-dc"))
        ("".           nil)))
   "List of file name suffixes and associated decoding commands.
 Each entry should be (SUFFIX . STRING); the file is given to
-the command as standard input.  If STRING is nil, no decoding is done.
+the command as standard input.
+
+STRING may be a list of strings.  In that case, the first element is
+the command name, and the rest are arguments to that command.
+
+If STRING is nil, no decoding is done.
 Because the SUFFIXes are tried in order, the empty string should
 be last in the list.")
 
@@ -271,8 +299,46 @@ Do the right thing if the file has been compressed or zipped."
                (coding-system-for-write 'no-conversion)
                (default-directory (or (file-name-directory fullname)
                                       default-directory)))
-           (call-process-region (point-min) (point-max) decoder t t)))
+           (or (consp decoder)
+               (setq decoder (list decoder)))
+           (apply 'call-process-region (point-min) (point-max)
+                  (car decoder) t t nil (cdr decoder))))
       (insert-file-contents fullname visit))))
+\f
+(defun info-initialize ()
+  "Initialize `Info-directory-list', if that hasn't been done yet."
+  (unless Info-directory-list
+    (let ((path (getenv "INFOPATH"))
+         (source (expand-file-name "info/" source-directory))
+         (sibling (if installation-directory
+                      (expand-file-name "info/" installation-directory)))
+         alternative)
+      (setq Info-directory-list
+           (prune-directory-list
+            (if path
+                (split-string path (regexp-quote path-separator))
+              (if (and sibling (file-exists-p sibling))
+                  ;; Uninstalled, Emacs builddir != srcdir.
+                  (setq alternative sibling)
+                ;; Uninstalled, builddir == srcdir
+                (setq alternative source))
+              (if (or (member alternative Info-default-directory-list)
+                      ;; On DOS/NT, we use movable executables always,
+                      ;; and we must always find the Info dir at run time.
+                      (if (memq system-type '(ms-dos windows-nt))
+                          nil
+                        ;; Use invocation-directory for Info
+                        ;; only if we used it for exec-directory also.
+                        (not (string= exec-directory
+                                      (expand-file-name "lib-src/"
+                                                        installation-directory))))
+                      (not (file-exists-p alternative)))
+                  Info-default-directory-list
+                ;; `alternative' contains the Info files that came with this
+                ;; version, so we should look there first.  `Info-insert-dir'
+                ;; currently expects to find `alternative' first on the list.
+                (cons alternative
+                      (reverse (cdr (reverse Info-default-directory-list)))))))))))
 
 ;;;###autoload
 (defun info-other-window (&optional file)
@@ -281,7 +347,7 @@ Do the right thing if the file has been compressed or zipped."
                   (list (read-file-name "Info file name: " nil nil t))))
   (let (same-window-buffer-names)
     (info file)))
-  
+
 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
 
 ;;;###autoload
@@ -289,18 +355,27 @@ Do the right thing if the file has been compressed or zipped."
   "Enter Info, the documentation browser.
 Optional argument FILE specifies the file to examine;
 the default is the top-level directory of Info.
+Called from a program, FILE may specify an Info node of the form
+`(FILENAME)NODENAME'.
 
 In interactive use, a prefix argument directs this command
 to read a file name from the minibuffer.
 
 The search path for Info files is in the variable `Info-directory-list'.
-The top-level Info directory is made by combining all the files named `dir' 
+The top-level Info directory is made by combining all the files named `dir'
 in all the directories in that path."
   (interactive (if current-prefix-arg
                   (list (read-file-name "Info file name: " nil nil t))))
   (if file
-      (progn (pop-to-buffer "*info*")
-            (Info-goto-node (concat "(" file ")")))
+      (progn
+       (pop-to-buffer "*info*")
+       ;; If argument already contains parentheses, don't add another set
+       ;; since the argument will then be parsed improperly.  This also
+       ;; has the added benefit of allowing node names to be included
+       ;; following the parenthesized filename.
+       (if (and (stringp file) (string-match "(.*)" file))
+           (Info-goto-node file)
+         (Info-goto-node (concat "(" file ")"))))
     (if (get-buffer "*info*")
        (pop-to-buffer "*info*")
       (Info-directory))))
@@ -322,14 +397,35 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
                                   (nth 1 err) err)))
               (save-buffers-kill-emacs)))
     (info)))
+\f
+;; See if the accessible portion of the buffer begins with a node
+;; delimiter, and the node header line which follows matches REGEXP.
+;; Typically, this test will be followed by a loop that examines the
+;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
+;; to have the overhead of this special test inside the loop.
+
+;; This function changes match-data, but supposedly the caller might
+;; want to use the results of re-search-backward.
+
+;; The return value is the value of point at the beginning of matching
+;; REGEXP, if the function succeeds, nil otherwise.
+(defun Info-node-at-bob-matching (regexp)
+  (and (bobp)                          ; are we at beginning of buffer?
+       (looking-at "\^_")              ; does it begin with node delimiter?
+       (let (beg)
+        (forward-line 1)
+        (setq beg (point))
+        (forward-line 1)               ; does the line after delimiter match REGEXP?
+        (re-search-backward regexp beg t))))
 
-;; Go to an info node specified as separate filename and nodename.
-;; no-going-back is non-nil if recovering from an error in this function;
-;; it says do not attempt further (recursive) error recovery.
 (defun Info-find-node (filename nodename &optional no-going-back)
+  "Go to an info node specified as separate FILENAME and NODENAME.
+NO-GOING-BACK is non-nil if recovering from an error in this function;
+it says do not attempt further (recursive) error recovery."
+  (info-initialize)
   ;; Convert filename to lower case if not found as specified.
   ;; Expand it.
-  (if filename
+  (if (stringp filename)
       (let (temp temp-downcase found)
         (setq filename (substitute-in-file-name filename))
         (if (string= (downcase filename) "dir")
@@ -374,14 +470,101 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
                   Info-history)))
   ;; Go into info buffer.
   (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
+  (Info-find-node-2 filename nodename no-going-back))
+
+(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'."
+  (interactive
+   (list (if current-prefix-arg
+            (completing-read "Node name: " (Info-build-node-completions)
+                             nil t "Top")
+          "Top")))
+  (info-initialize)
+  (Info-mode)
+  (set (make-local-variable 'Info-current-file) t)
+  (Info-find-node-2 nil nodename))
+
+(defun Info-find-in-tag-table-1 (marker regexp case-fold)
+  "Find a node in a tag table.
+MARKER specifies the buffer and position to start searching at.
+REGEXP is a regular expression matching nodes or references.  Its first
+group should match `Node:' or `Ref:'.
+CASE-FOLD t means search for a case-insensitive match.
+If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
+FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
+where the match was found, and MODE is `major-mode' of the buffer in
+which the match was found."
+  (let ((case-fold-search case-fold)
+       found-mode guesspos found-anchor)
+    (save-excursion
+      (set-buffer (marker-buffer marker))
+      (goto-char marker)
+    
+      ;; Search tag table
+      (beginning-of-line)
+      (when (re-search-forward regexp nil t)
+       (list (string-equal "Ref:" (match-string 1))
+             (1+ (read (current-buffer)))
+             major-mode)))))
+
+(defun Info-find-in-tag-table (marker regexp)
+  "Find a node in a tag table.
+MARKER specifies the buffer and position to start searching at.
+REGEXP is a regular expression matching nodes or references.  Its first
+group should match `Node:' or `Ref:'.
+If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
+FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
+where the match was found, and MODE is `major-mode' of the buffer in
+which the match was found.
+This function tries to find a case-sensitive match first, then a
+case-insensitive match is tried."
+  (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
+    (when (null (car result))
+      (setq result (Info-find-in-tag-table-1 marker regexp t)))
+    result))
+
+(defun Info-find-node-in-buffer-1 (regexp case-fold)
+  "Find a node or anchor in the current buffer.
+REGEXP is a regular expression matching nodes or references.  Its first
+group should match `Node:' or `Ref:'.
+CASE-FOLD t means search for a case-insensitive match.
+Value is the position at which a match was found, or nil if not found."
+  (let ((case-fold-search case-fold)
+       found)
+    (save-excursion
+      (when (Info-node-at-bob-matching regexp)
+       (setq found (point)))
+      (while (and (not found)
+                 (search-forward "\n\^_" nil t))
+       (forward-line 1)
+       (let ((beg (point)))
+         (forward-line 1)
+         (when (re-search-backward regexp beg t)
+           (beginning-of-line)
+           (setq found (point)))))
+      found)))
+                 
+(defun Info-find-node-in-buffer (regexp)
+  "Find a node or anchor in the current buffer.
+REGEXP is a regular expression matching nodes or references.  Its first
+group should match `Node:' or `Ref:'.
+Value is the position at which a match was found, or nil if not found.
+This function looks for a case-sensitive match first.  If none is found,
+a case-insensitive match is tried."
+  (or (Info-find-node-in-buffer-1 regexp nil)
+      (Info-find-node-in-buffer-1 regexp t)))
+  
+(defun Info-find-node-2 (filename nodename &optional no-going-back)
   (buffer-disable-undo (current-buffer))
   (or (eq major-mode 'Info-mode)
       (Info-mode))
   (widen)
   (setq Info-current-node nil)
   (unwind-protect
-      ;; Bind case-fold-search in case the user sets it to nil.
-      (let ((case-fold-search t))
+      (let ((case-fold-search t)
+           anchorpos)
         ;; Switch files if necessary
         (or (null filename)
             (equal Info-current-file filename)
@@ -446,69 +629,55 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
           ;; *Or* the same, but in an indirect subfile.
 
           ;; Search file for a suitable node.
-          (let ((guesspos (point-min))
-                (regexp
-                 (concat "\\(Node:\\|Ref:\\) *"
-                         (regexp-quote nodename)
-                         " *[,\t\n\177]")))
-
-            ;; First, search a tag table, if any
-            (if (marker-position Info-tag-table-marker)
-
-                (let (found-in-tag-table
-                      found-mode
-                      (m Info-tag-table-marker))
-                  (save-excursion
-                    (set-buffer (marker-buffer m))
-                    (goto-char m)
-                    (beginning-of-line) ; so re-search will work.
-
-                    ;; Search tag table
-                    (setq found-in-tag-table
-                          (re-search-forward regexp nil t))
-                    (if found-in-tag-table
-                        (setq guesspos (read (current-buffer))))
-                    (setq found-mode major-mode))
-
-                  ;; Indirect file among split files
-                  (if found-in-tag-table
-                      (progn
-                        ;; If this is an indirect file, determine
-                        ;; which file really holds this node and
-                        ;; read it in.
-                        (if (not (eq found-mode 'Info-mode))
-                            ;; Note that the current buffer must be
-                            ;; the *info* buffer on entry to
-                            ;; Info-read-subfile.  Thus the hackery
-                            ;; above.
-                            (setq guesspos (Info-read-subfile guesspos)))))
-
-                  ;; Handle anchor
-                  (if (and found-in-tag-table
-                           (string-equal "Ref:" (match-string 1)))
-                      (goto-char guesspos)
-
-                    ;; Else we may have a node, which we search for:
-                   (goto-char (max (point-min)
-                                   (- (byte-to-position guesspos) 1000)))
-                    ;; Now search from our advised position
-                    ;; (or from beg of buffer)
-                    ;; to find the actual node.
-                    (catch 'foo
-                      (while (search-forward "\n\^_" nil t)
-                        (forward-line 1)
-                        (let ((beg (point)))
-                          (forward-line 1)
-                          (if (re-search-backward regexp beg t)
-                              (progn
-                                (beginning-of-line)
-                                (throw 'foo t)))))
-                      (error
-                       "No such anchor in tag table or node in tag table or file: %s"
-                       nodename))))))
-
-          (Info-select-node)
-         (goto-char (point-min))))
+         (let ((guesspos (point-min))
+               (regexp (concat "\\(Node:\\|Ref:\\) *\\("
+                               (if (stringp nodename) 
+                                   (regexp-quote nodename)
+                                 "")
+                               "\\) *[,\t\n\177]"))
+               (nodepos nil))
+
+           (catch 'foo
+             
+             ;; First, search a tag table, if any
+             (when (marker-position Info-tag-table-marker)
+               (let* ((m Info-tag-table-marker)
+                      (found (Info-find-in-tag-table m regexp)))
+                 
+                 (when found
+                   ;; FOUND is (ANCHOR POS MODE).
+                   (setq guesspos (nth 1 found))
+                   
+                   ;; If this is an indirect file, determine which
+                   ;; file really holds this node and read it in.
+                   (unless (eq (nth 2 found) 'Info-mode)
+                     ;; Note that the current buffer must be the
+                     ;; *info* buffer on entry to
+                     ;; Info-read-subfile.  Thus the hackery above.
+                     (setq guesspos (Info-read-subfile guesspos)))
+
+                   ;; Handle anchor
+                   (when (nth 0 found)
+                     (goto-char (setq anchorpos guesspos))
+                     (throw 'foo t)))))
+
+             ;; Else we may have a node, which we search for:
+             (goto-char (max (point-min)
+                             (- (byte-to-position guesspos) 1000)))
+             
+             ;; Now search from our advised position (or from beg of
+             ;; buffer) to find the actual node.  First, check
+             ;; whether the node is right where we are, in case the
+             ;; buffer begins with a node.
+             (let ((pos (Info-find-node-in-buffer regexp)))
+               (when pos
+                 (goto-char pos)
+                 (throw 'foo t))
+               (error "No such anchor in tag table or node in tag table or file: %s"
+                      nodename)))
+
+           (Info-select-node)
+           (goto-char (or anchorpos (point-min))))))
     ;; If we did not finish finding the specified node,
     ;; go back to the previous one.
     (or Info-current-node no-going-back (null Info-history)
@@ -529,6 +698,8 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
 ;; constructed Info-dir-contents.
 (defvar Info-dir-file-attributes nil)
 
+(defvar Info-dir-file-name nil)
+
 ;; Construct the Info directory node by merging the files named `dir'
 ;; from various directories.  Set the *info* buffer's
 ;; default-directory to the first directory we actually get any text
@@ -538,17 +709,27 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
           ;; Verify that none of the files we used has changed
           ;; since we used it.
           (eval (cons 'and
-                      (mapcar '(lambda (elt)
-                                 (let ((curr (file-attributes (car elt))))
-                                   ;; Don't compare the access time.
-                                   (if curr (setcar (nthcdr 4 curr) 0))
-                                   (setcar (nthcdr 4 (cdr elt)) 0)
-                                   (equal (cdr elt) curr)))
+                      (mapcar (lambda (elt)
+                                (let ((curr (file-attributes
+                                             ;; Handle symlinks
+                                             (file-truename (car elt)))))
+
+                                  ;; Don't compare the access time.
+                                  (if curr (setcar (nthcdr 4 curr) 0))
+                                  (setcar (nthcdr 4 (cdr elt)) 0)
+                                  (equal (cdr elt) curr)))
                               Info-dir-file-attributes))))
-      (insert Info-dir-contents)
-    (let ((dirs Info-directory-list)
+      (progn
+       (insert Info-dir-contents)
+       (goto-char (point-min)))
+    (let ((dirs (if Info-additional-directory-list
+                              (append Info-directory-list
+                                      Info-additional-directory-list)
+                            Info-directory-list))
          ;; Bind this in case the user sets it to nil.
          (case-fold-search t)
+         ;; This is set non-nil if we find a problem in some input files.
+         problems
          buffers buffer others nodes dirs-done)
 
       (setq Info-dir-file-attributes nil)
@@ -583,6 +764,8 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
                      (condition-case nil
                          (progn
                            (insert-file-contents file)
+                           (make-local-variable 'Info-dir-file-name)
+                           (setq Info-dir-file-name file)
                            (setq buffers (cons (current-buffer) buffers)
                                  Info-dir-file-attributes
                                  (cons (cons file attrs)
@@ -591,14 +774,15 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
          (or (cdr dirs) (setq Info-dir-contents-directory
                               (file-name-as-directory (car dirs))))
          (setq dirs (cdr dirs))))
-      
+
       (or buffers
          (error "Can't find the Info directory node"))
       ;; Distinguish the dir file that comes with Emacs from all the
       ;; others.  Yes, that is really what this is supposed to do.
-      ;; If it doesn't work, fix it.
-      (setq buffer (car buffers)
-           others (cdr buffers))
+      ;; The definition of `Info-directory-list' puts it first on that
+      ;; list and so last in `buffers' at this point.
+      (setq buffer (car (last buffers))
+           others (delq buffer buffers))
 
       ;; Insert the entire original dir file as a start; note that we've
       ;; already saved its default directory to use as the default
@@ -607,7 +791,10 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
 
       ;; Look at each of the other buffers one by one.
       (while others
-       (let ((other (car others)))
+       (let ((other (car others))
+             ;; Bind this in case the user sets it to nil.
+             (case-fold-search t)
+             this-buffer-nodes)
          ;; In each, find all the menus.
          (save-excursion
            (set-buffer other)
@@ -616,17 +803,28 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
            (while (re-search-forward "^\\* Menu:" nil t)
              (let (beg nodename end)
                (forward-line 1)
+               (while (and (eolp) (not (eobp)))
+                 (forward-line 1))
                (setq beg (point))
-               (search-backward "\n\^_")
+               (or (search-backward "\n\^_" nil 'move)
+                   (looking-at "\^_")
+                   (signal 'search-failed (list "\n\^_")))
                (search-forward "Node: ")
                (setq nodename (Info-following-node-name))
                (search-forward "\n\^_" nil 'move)
                (beginning-of-line)
                (setq end (point))
-               (setq nodes (cons (list nodename other beg end) nodes))))))
+               (setq this-buffer-nodes
+                     (cons (list nodename other beg end)
+                           this-buffer-nodes))))
+           (if (assoc-ignore-case "top" this-buffer-nodes)
+               (setq nodes (nconc this-buffer-nodes nodes))
+             (setq problems t)
+             (message "No `top' node in %s" Info-dir-file-name))))
        (setq others (cdr others)))
       ;; Add to the main menu a menu item for each other node.
-      (re-search-forward "^\\* Menu:")
+      (let ((case-fold-search t)
+           (re-search-forward "^\\* Menu:")))
       (forward-line 1)
       (let ((menu-items '("top"))
            (nodes nodes)
@@ -647,10 +845,11 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
       ;; Now take each node of each of the other buffers
       ;; and merge it into the main buffer.
       (while nodes
-       (let ((nodename (car (car nodes))))
+       (let ((case-fold-search t)
+             (nodename (car (car nodes))))
          (goto-char (point-min))
          ;; Find the like-named node in the main buffer.
-         (if (re-search-forward (concat "\n\^_.*\n.*Node: "
+         (if (re-search-forward (concat "^\^_.*\n.*Node: "
                                         (regexp-quote nodename)
                                         "[,\n\t]")
                                 nil t)
@@ -669,7 +868,11 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
       (while buffers
        (kill-buffer (car buffers))
        (setq buffers (cdr buffers)))
-      (message "Composing main Info directory...done"))
+      (if Info-fontify (Info-fontify-menu-headers))
+      (goto-char (point-min))
+      (if problems
+         (message "Composing main Info directory...problems encountered, see `*Messages*'")
+       (message "Composing main Info directory...done")))
     (setq Info-dir-contents (buffer-string)))
   (setq default-directory Info-dir-contents-directory))
 
@@ -684,7 +887,8 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
        (save-excursion
          (set-buffer (marker-buffer Info-tag-table-marker))
          (goto-char (point-min))
-         (search-forward "\n\^_")
+         (or (looking-at "\^_")
+             (search-forward "\n\^_"))
          (forward-line 2)
          (catch 'foo
            (while (not (looking-at "\^_"))
@@ -715,59 +919,100 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
          (set-buffer-modified-p nil)
          (setq Info-current-subfile lastfilename)))
     (goto-char (point-min))
-    (search-forward "\n\^_")
+    (if (looking-at "\^_")
+       (forward-char 1)
+      (search-forward "\n\^_"))
     (if (numberp nodepos)
        (+ (- nodepos lastfilepos) (point)))))
 
-;; Select the info node that point is in.
+(defvar Info-header-line nil
+  "If the info node header is hidden, the text of the header.")
+
 (defun Info-select-node ()
-  ;; Bind this in case the user sets it to nil.
+"Select the info node that point is in.
+Bind this in case the user sets it to nil."
   (let ((case-fold-search t))
     (save-excursion
-     ;; Find beginning of node.
-     (search-backward "\n\^_")
-     (forward-line 2)
-     ;; Get nodename spelled as it is in the node.
-     (re-search-forward "Node:[ \t]*")
-     (setq Info-current-node
-          (buffer-substring-no-properties (point)
-                                          (progn
-                                           (skip-chars-forward "^,\t\n")
-                                           (point))))
-     (Info-set-mode-line)
-     ;; Find the end of it, and narrow.
-     (beginning-of-line)
-     (let (active-expression)
-       (narrow-to-region (point)
-                        (if (re-search-forward "\n[\^_\f]" nil t)
-                            (prog1
-                             (1- (point))
-                             (if (looking-at "[\n\^_\f]*execute: ")
-                                 (progn
-                                   (goto-char (match-end 0))
-                                   (setq active-expression
-                                         (read (current-buffer))))))
-                          (point-max)))
-       (if Info-enable-active-nodes (eval active-expression))
-       (if Info-fontify (Info-fontify-node))
-       (run-hooks 'Info-selection-hook)))))
+      ;; Find beginning of node.
+      (if (search-backward "\n\^_" nil 'move)
+         (forward-line 2)
+       (if (looking-at "\^_")
+           (forward-line 1)
+         (signal 'search-failed (list "\n\^_"))))
+      ;; Get nodename spelled as it is in the node.
+      (re-search-forward "Node:[ \t]*")
+      (setq Info-current-node
+           (buffer-substring-no-properties (point)
+                                           (progn
+                                             (skip-chars-forward "^,\t\n")
+                                             (point))))
+      (Info-set-mode-line)
+      ;; Find the end of it, and narrow.
+      (beginning-of-line)
+      (let (active-expression)
+       ;; Narrow to the node contents
+       (narrow-to-region (point)
+                         (if (re-search-forward "\n[\^_\f]" nil t)
+                             (prog1
+                                 (1- (point))
+                               (if (looking-at "[\n\^_\f]*execute: ")
+                                   (progn
+                                     (goto-char (match-end 0))
+                                     (setq active-expression
+                                           (read (current-buffer))))))
+                           (point-max)))
+       (if Info-enable-active-nodes (eval active-expression))
+       (if Info-fontify (Info-fontify-node))
+       (if Info-use-header-line
+           (Info-setup-header-line)
+         (setq Info-header-line nil))
+       (run-hooks 'Info-selection-hook)))))
 
 (defun Info-set-mode-line ()
   (setq mode-line-buffer-identification
-       (concat
-        "  Info:  ("
-        (if Info-current-file
-            (file-name-nondirectory Info-current-file)
-          "")
-        ")"
-        (or Info-current-node ""))))
+       (nconc (propertized-buffer-identification "%b")
+              (list
+               (concat " ("
+                       (file-name-nondirectory
+                        (if (stringp Info-current-file)
+                            Info-current-file
+                          (or buffer-file-name "")))
+                       ") "
+                       (or Info-current-node ""))))))
+\f
+;; Skip the node header and make it into a header-line.  This function
+;; should be called when the node is already narrowed.
+(defun Info-setup-header-line ()
+  (goto-char (point-min))
+  (let* ((case-fold-search t)
+        (header-end (save-excursion (forward-line 1) (1- (point))))
+        ;; If we find neither Next: nor Prev: link, show the entire
+        ;; node header.  Otherwise, don't show the File: and Node:
+        ;; parts, to avoid wasting precious space on information that
+        ;; is available in the mode line.
+        (header-beg (if (re-search-forward
+                         "\\(next\\|prev[ious]*\\): "
+                         header-end t)
+                        (match-beginning 1)
+                      (point))))
+    (set (make-local-variable 'Info-header-line)
+        (buffer-substring header-beg header-end))
+    (setq header-line-format 'Info-header-line)
+    (narrow-to-region (1+ header-end) (point-max))))
 \f
 ;; Go to an info node specified with a filename-and-nodename string
 ;; of the sort that is found in pointers in nodes.
 
-(defun Info-goto-node (nodename)
-  "Go to info node named NAME.  Give just NODENAME or (FILENAME)NODENAME."
-  (interactive (list (Info-read-node-name "Goto node: ")))
+(defun Info-goto-node (nodename &optional fork)
+  "Go to info node named NAME.  Give just NODENAME or (FILENAME)NODENAME.
+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."
+  (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
+  (info-initialize)
+  (if fork
+      (set-buffer
+       (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
   (let (filename)
     (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
                  nodename)
@@ -816,7 +1061,8 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
   (or Info-current-file-completions
       (let ((compl nil)
            ;; Bind this in case the user sets it to nil.
-           (case-fold-search t))
+           (case-fold-search t)
+           (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
        (save-excursion
          (save-restriction
            (if (marker-buffer Info-tag-table-marker)
@@ -824,23 +1070,25 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
                  (set-buffer (marker-buffer marker))
                  (widen)
                  (goto-char marker)
-                 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
+                 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
                    (setq compl
-                         (cons (list (buffer-substring (match-beginning 1)
-                                                       (match-end 1)))
+                         (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: *\\([^,\n]*\\) *[,\n\t]"
-                                         beg t)
-                     (setq compl 
-                           (cons (list (buffer-substring (match-beginning 1)
-                                                         (match-end 1)))
+                 (if (re-search-backward node-regexp beg t)
+                     (setq compl
+                           (cons (list (match-string-no-properties 1))
                                  compl))))))))
+       (setq compl (cons '("*") compl))
        (setq Info-current-file-completions compl))))
 \f
 (defun Info-restore-point (hl)
@@ -854,100 +1102,110 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
          (setq hl nil))                ;terminate the while at next iter
       (setq hl (cdr hl)))))
 \f
-(defvar Info-last-search nil
-  "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
+(defvar Info-search-history nil
+  "The history list for `Info-search'.")
 
 (defun Info-search (regexp)
   "Search for REGEXP, starting from point, and select node it's found in."
-  (interactive "sSearch (regexp): ")
-  (if transient-mark-mode (deactivate-mark))
-  (if (equal regexp "")
-      (setq regexp Info-last-search)
-    (setq Info-last-search regexp))
-  (let ((found ()) current
-       (onode Info-current-node)
-       (ofile Info-current-file)
-       (opoint (point))
-       (ostart (window-start))
-       (osubfile Info-current-subfile))
-    (save-excursion
-      (save-restriction
-       (widen)
-       (if (null Info-current-subfile)
-           (progn (re-search-forward regexp) (setq found (point)))
-         (condition-case err
+  (interactive (list (read-string
+                     (if Info-search-history
+                         (format "Regexp search (default `%s'): "
+                                 (car Info-search-history))
+                       "Regexp search: ")
+                     nil 'Info-search-history)))
+  (when transient-mark-mode
+    (deactivate-mark))
+  (when (equal regexp "")
+    (setq regexp (car Info-search-history)))
+  (when regexp
+    (let ((found ()) current
+         (onode Info-current-node)
+         (ofile Info-current-file)
+         (opoint (point))
+         (ostart (window-start))
+         (osubfile Info-current-subfile))
+      (save-excursion
+       (save-restriction
+         (widen)
+         (if (null Info-current-subfile)
              (progn (re-search-forward regexp) (setq found (point)))
-           (search-failed nil)))))
-    (if (not found) ;can only happen in subfile case -- else would have erred
-       (unwind-protect
-           (let ((list ()))
-             (save-excursion
-               (set-buffer (marker-buffer Info-tag-table-marker))
-               (goto-char (point-min))
-               (search-forward "\n\^_\nIndirect:")
-               (save-restriction
-                 (narrow-to-region (point)
-                                   (progn (search-forward "\n\^_")
-                                          (1- (point))))
+           (condition-case err
+               (progn (re-search-forward regexp) (setq found (point)))
+             (search-failed nil)))))
+      (if (not found)                  ;can only happen in subfile case -- else would have erred
+         (unwind-protect
+             (let ((list ()))
+               (save-excursion
+                 (set-buffer (marker-buffer Info-tag-table-marker))
                  (goto-char (point-min))
-                 (search-forward (concat "\n" osubfile ": "))
-                 (beginning-of-line)
-                 (while (not (eobp))
-                   (re-search-forward "\\(^.*\\): [0-9]+$")
-                   (goto-char (+ (match-end 1) 2))
-                   (setq list (cons (cons (read (current-buffer))
-                                          (buffer-substring
-                                           (match-beginning 1) (match-end 1)))
-                                    list))
-                   (goto-char (1+ (match-end 0))))
-                 (setq list (nreverse list)
-                       current (car (car list))
-                       list (cdr list))))
-             (while list
-               (message "Searching subfile %s..." (cdr (car list)))
-               (Info-read-subfile (car (car list)))
-               (setq list (cdr list))
-;;             (goto-char (point-min))
-               (if (re-search-forward regexp nil t)
-                   (setq found (point) list ())))
-             (if found
-                 (message "")
-               (signal 'search-failed (list regexp))))
-         (if (not found)
-             (progn (Info-read-subfile osubfile)
-                    (goto-char opoint)
-                    (Info-select-node)
-                    (set-window-start (selected-window) ostart)))))
-    (widen)
-    (goto-char found)
-    (Info-select-node)
-    ;; Use string-equal, not equal, to ignore text props.
-    (or (and (string-equal onode Info-current-node)
-            (equal ofile Info-current-file))
-       (setq Info-history (cons (list ofile onode opoint)
-                                Info-history)))))
+                 (search-forward "\n\^_\nIndirect:")
+                 (save-restriction
+                   (narrow-to-region (point)
+                                     (progn (search-forward "\n\^_")
+                                            (1- (point))))
+                   (goto-char (point-min))
+                   (search-forward (concat "\n" osubfile ": "))
+                   (beginning-of-line)
+                   (while (not (eobp))
+                     (re-search-forward "\\(^.*\\): [0-9]+$")
+                     (goto-char (+ (match-end 1) 2))
+                     (setq list (cons (cons (read (current-buffer))
+                                            (match-string-no-properties 1))
+                                      list))
+                     (goto-char (1+ (match-end 0))))
+                   (setq list (nreverse list)
+                         current (car (car list))
+                         list (cdr list))))
+               (while list
+                 (message "Searching subfile %s..." (cdr (car list)))
+                 (Info-read-subfile (car (car list)))
+                 (setq list (cdr list))
+;;;            (goto-char (point-min))
+                 (if (re-search-forward regexp nil t)
+                     (setq found (point) list ())))
+               (if found
+                   (message "")
+                 (signal 'search-failed (list regexp))))
+           (if (not found)
+               (progn (Info-read-subfile osubfile)
+                      (goto-char opoint)
+                      (Info-select-node)
+                      (set-window-start (selected-window) ostart)))))
+      (widen)
+      (goto-char found)
+      (Info-select-node)
+      ;; Use string-equal, not equal, to ignore text props.
+      (or (and (string-equal onode Info-current-node)
+              (equal ofile Info-current-file))
+         (setq Info-history (cons (list ofile onode opoint)
+                                  Info-history))))))
 \f
-;; Extract the value of the node-pointer named NAME.
-;; If there is none, use ERRORNAME in the error message; 
-;; if ERRORNAME is nil, just return nil.
 (defun Info-extract-pointer (name &optional errorname)
-  ;; Bind this in case the user sets it to nil.
+  "Extract the value of the node-pointer named NAME.
+If there is none, use ERRORNAME in the error message;
+if ERRORNAME is nil, just return nil.
+Bind this in case the user sets it to nil."
   (let ((case-fold-search t))
     (save-excursion
-      (goto-char (point-min))
-      (forward-line 1)
-      (if (re-search-backward (concat name ":") nil t)
-         (progn
-           (goto-char (match-end 0))
-           (Info-following-node-name))
-       (if (eq errorname t)
-           nil
-         (error "Node has no %s" (capitalize (or errorname name))))))))
+      (save-restriction
+       (goto-char (point-min))
+       (when Info-header-line
+         ;; expose the header line in the buffer
+         (widen)
+         (forward-line -1))
+       (let ((bound (point)))
+         (forward-line 1)
+         (cond ((re-search-backward (concat name ":") bound t)
+                (goto-char (match-end 0))
+                (Info-following-node-name))
+               ((not (eq errorname t))
+                (error "Node has no %s"
+                       (capitalize (or errorname name))))))))))
 
-;; Return the node name in the buffer following point.
-;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
-;; saying which chars may appear in the node name.
 (defun Info-following-node-name (&optional allowedchars)
+  "Return the node name in the buffer following point.
+ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
+saying which chars may appear in the node name."
   (skip-chars-forward " \t")
   (buffer-substring-no-properties
    (point)
@@ -974,7 +1232,7 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
 If SAME-FILE is non-nil, do not move to a different Info file."
   (interactive)
   (let ((node (Info-extract-pointer "up")))
-    (and same-file
+    (and (or same-file (not (stringp Info-current-file)))
         (string-match "^(" node)
         (error "Up node is in another Info file"))
     (Info-goto-node node))
@@ -994,14 +1252,15 @@ If SAME-FILE is non-nil, do not move to a different Info file."
     (setq Info-history (cdr Info-history))
     (goto-char opoint)))
 
+;;;###autoload
 (defun Info-directory ()
   "Go to the Info directory node."
   (interactive)
   (Info-find-node "dir" "top"))
 \f
 (defun Info-follow-reference (footnotename)
-  "Follow cross reference named NAME to the node it refers to.
-NAME may be an abbreviation of the reference name."
+  "Follow cross reference named FOOTNOTENAME to the node it refers to.
+FOOTNOTENAME may be an abbreviation of the reference name."
   (interactive
    (let ((completion-ignore-case t)
         (case-fold-search t)
@@ -1015,7 +1274,7 @@ NAME may be an abbreviation of the reference name."
 
        (goto-char (point-min))
        (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
-        (setq str (buffer-substring
+        (setq str (buffer-substring-no-properties
                    (match-beginning 1)
                    (1- (point))))
         ;; See if this one should be the default.
@@ -1063,6 +1322,10 @@ NAME may be an abbreviation of the reference name."
           (list (if (equal input "")
                     default input)))
        (error "No cross-references in this node"))))
+
+  (unless footnotename
+    (error "No reference was specified"))
+
   (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
               (case-fold-search t))
     (while (setq i (string-match " " str i))
@@ -1108,7 +1371,8 @@ NAME may be an abbreviation of the reference name."
 (defvar Info-complete-menu-buffer)
 
 (defun Info-complete-menu-item (string predicate action)
-  (let ((case-fold-search t))
+  (let ((completion-ignore-case t)
+       (case-fold-search t))
     (cond ((eq action nil)
           (let (completions
                 (pattern (concat "\n\\* +\\("
@@ -1119,12 +1383,10 @@ NAME may be an abbreviation of the reference name."
               (goto-char (point-min))
               (search-forward "\n* Menu:")
               (while (re-search-forward pattern nil t)
-                (setq completions (cons (cons (format "%s"
-                                                      (buffer-substring
-                                                       (match-beginning 1)
-                                                       (match-end 1)))
-                                              (match-beginning 1))
-                                        completions))))
+                (setq completions
+                      (cons (cons (match-string-no-properties 1)
+                                  (match-beginning 1))
+                            completions))))
             (try-completion string completions predicate)))
          ((eq action t)
           (let (completions
@@ -1136,11 +1398,9 @@ NAME may be an abbreviation of the reference name."
               (goto-char (point-min))
               (search-forward "\n* Menu:")
               (while (re-search-forward pattern nil t)
-                (setq completions (cons (cons (format "%s"
-                                                      (buffer-substring
-                                                       (match-beginning 1)
-                                                       (match-end 1)))
-                                              (match-beginning 1))
+                (setq completions (cons (cons
+                                         (match-string-no-properties 1)
+                                         (match-beginning 1))
                                         completions))))
             (all-completions string completions predicate)))
          (t
@@ -1154,16 +1414,20 @@ NAME may be an abbreviation of the reference name."
                                nil t))))))
 
 
-(defun Info-menu (menu-item)
+(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."
+Completion is allowed, and the menu item point is on is the default.
+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."
   (interactive
    (let ((completions '())
         ;; If point is within a menu item, use that item as the default
         (default nil)
         (p (point))
         beg
-        (last nil))
+        (last nil)
+        (case-fold-search t))
      (save-excursion
        (goto-char (point-min))
        (if (not (search-forward "\n* menu:" nil t))
@@ -1173,10 +1437,8 @@ Completion is allowed, and the menu item point is on is the default."
            (save-excursion
              (goto-char p)
              (end-of-line)
-             (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
-             (setq default (format "%s" (buffer-substring
-                                         (match-beginning 1)
-                                         (match-end 1)))))))
+             (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
+                 (setq default (match-string-no-properties 1))))))
      (let ((item nil))
        (while (null item)
         (setq item (let ((completion-ignore-case t)
@@ -1184,7 +1446,7 @@ Completion is allowed, and the menu item point is on is the default."
                      (completing-read (if default
                                           (format "Menu item (default %s): "
                                                   default)
-                                          "Menu item: ")
+                                        "Menu item: ")
                                       'Info-complete-menu-item nil t)))
         ;; we rely on the fact that completing-read accepts an input
         ;; of "" even when the require-match argument is true and ""
@@ -1192,40 +1454,42 @@ Completion is allowed, and the menu item point is on is the default."
         (if (string= item "")
             (if default
                 (setq item default)
-                ;; ask again
-                (setq item nil))))
-       (list item))))
+              ;; ask again
+              (setq item nil))))
+       (list item current-prefix-arg))))
   ;; there is a problem here in that if several menu items have the same
   ;; name you can only go to the node of the first with this command.
-  (Info-goto-node (Info-extract-menu-item menu-item)))
-  
+  (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
+
 (defun Info-extract-menu-item (menu-item)
   (setq menu-item (regexp-quote menu-item))
   (let ((case-fold-search t))
     (save-excursion
-      (goto-char (point-min))
-      (or (search-forward "\n* menu:" nil t)
-         (error "No menu in this node"))
-      (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
-         (re-search-forward (concat "\n\\* +" menu-item) nil t)
-         (error "No such item in menu"))
-      (beginning-of-line)
-      (forward-char 2)
-      (Info-extract-menu-node-name))))
+      (let ((case-fold-search t))
+       (goto-char (point-min))
+       (or (search-forward "\n* menu:" nil t)
+           (error "No menu in this node"))
+       (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
+           (re-search-forward (concat "\n\\* +" menu-item) nil t)
+           (error "No such item in menu"))
+       (beginning-of-line)
+       (forward-char 2)
+       (Info-extract-menu-node-name)))))
 
 ;; If COUNT is nil, use the last item in the menu.
 (defun Info-extract-menu-counting (count)
   (let ((case-fold-search t))
     (save-excursion
-      (goto-char (point-min))
-      (or (search-forward "\n* menu:" nil t)
-         (error "No menu in this node"))
-      (if count
-         (or (search-forward "\n* " nil t count)
-             (error "Too few items in menu"))
-       (while (search-forward "\n* " nil t)
-         nil))
-      (Info-extract-menu-node-name))))
+      (let ((case-fold-search t))
+       (goto-char (point-min))
+       (or (search-forward "\n* menu:" nil t)
+           (error "No menu in this node"))
+       (if count
+           (or (search-forward "\n* " nil t count)
+               (error "Too few items in menu"))
+         (while (search-forward "\n* " nil t)
+           nil))
+       (Info-extract-menu-node-name)))))
 
 (defun Info-nth-menu-item ()
   "Go to the node of the Nth menu item.
@@ -1244,11 +1508,12 @@ N is the digit argument used to invoke this command."
   "Go to the final node in this file."
   (interactive)
   (Info-goto-node "Top")
-  (let (Info-history)
+  (let ((Info-history nil)
+       (case-fold-search t))
     ;; Go to the last node in the menu of Top.
     (Info-goto-node (Info-extract-menu-counting nil))
     ;; If the last node in the menu is not last in pointer structure,
-    ;; move forward until we can't go any farther. 
+    ;; move forward until we can't go any farther.
     (while (Info-forward-node t t) nil)
     ;; Then keep moving down to last subnode, unless we reach an index.
     (while (and (not (string-match "\\<index\\>" Info-current-node))
@@ -1260,36 +1525,56 @@ N is the digit argument used to invoke this command."
   (interactive)
   (goto-char (point-min))
   (forward-line 1)
-  ;; three possibilities, in order of priority:
-  ;;     1. next node is in a menu in this node (but not in an index)
-  ;;     2. next node is next at same level
-  ;;     3. next node is up and next
-  (cond ((and (not not-down)
-              (save-excursion (search-forward "\n* menu:" nil t))
-             (not (string-match "\\<index\\>" Info-current-node)))
-        (Info-goto-node (Info-extract-menu-counting 1))
-         t)
-        ((save-excursion (search-backward "next:" nil t))
-         (Info-next)
-         t)
-        ((and (save-excursion (search-backward "up:" nil t))
-             ;; Use string-equal, not equal, to ignore text props.
-             (not (string-equal (downcase (Info-extract-pointer "up"))
-                                "top")))
-         (let ((old-node Info-current-node))
-           (Info-up)
-           (let (Info-history success)
-             (unwind-protect
-                 (setq success (Info-forward-node t no-error))
-               (or success (Info-goto-node old-node))))))
-        (no-error nil)
-        (t (error "No pointer forward from this node"))))
+  (let ((case-fold-search t))
+    ;; three possibilities, in order of priority:
+    ;;     1. next node is in a menu in this node (but not in an index)
+    ;;     2. next node is next at same level
+    ;;     3. next node is up and next
+    (cond ((and (not not-down)
+               (save-excursion (search-forward "\n* menu:" nil t))
+               (not (string-match "\\<index\\>" Info-current-node)))
+          (Info-goto-node (Info-extract-menu-counting 1))
+          t)
+         ((save-excursion
+            (save-restriction
+              (let (limit)
+                (when Info-header-line
+                  (goto-char (point-min))
+                  (widen)
+                  (forward-line -1)
+                  (setq limit (point))
+                  (forward-line 1))
+                (search-backward "next:" limit t))))
+          (Info-next)
+          t)
+         ((and (save-excursion
+                 (save-restriction
+                   (let (limit)
+                     (when Info-header-line
+                       (goto-char (point-min))
+                       (widen)
+                       (forward-line -1)
+                       (setq limit (point))
+                       (forward-line 1))
+                     (search-backward "up:" limit t))))
+               ;; Use string-equal, not equal, to ignore text props.
+               (not (string-equal (downcase (Info-extract-pointer "up"))
+                                  "top")))
+          (let ((old-node Info-current-node))
+            (Info-up)
+            (let (Info-history success)
+              (unwind-protect
+                  (setq success (Info-forward-node t no-error))
+                (or success (Info-goto-node old-node))))))
+         (no-error nil)
+         (t (error "No pointer forward from this node")))))
 
 (defun Info-backward-node ()
   "Go backward one node, considering all nodes as forming one sequence."
   (interactive)
   (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
-       (upnode (Info-extract-pointer "up" t)))
+       (upnode (Info-extract-pointer "up" t))
+       (case-fold-search t))
     (cond ((and upnode (string-match "(" upnode))
           (error "First node in file"))
          ((and upnode (or (null prevnode)
@@ -1318,20 +1603,26 @@ N is the digit argument used to invoke this command."
 
 (defun Info-next-menu-item ()
   (interactive)
-  (save-excursion
-    (forward-line -1)
-    (search-forward "\n* menu:" nil t)
-    (or (search-forward "\n* " nil t)
-       (error "No more items in menu"))
-    (Info-goto-node (Info-extract-menu-node-name))))
+  ;; Bind this in case the user sets it to nil.
+  (let* ((case-fold-search t)
+        (node
+         (save-excursion
+           (forward-line -1)
+           (search-forward "\n* menu:" nil t)
+           (and (search-forward "\n* " nil t)
+                (Info-extract-menu-node-name)))))
+    (if node (Info-goto-node node)
+      (error "No more items in menu"))))
 
 (defun Info-last-menu-item ()
   (interactive)
   (save-excursion
     (forward-line 1)
-    (let ((beg (save-excursion
-                (and (search-backward "\n* menu:" nil t)
-                     (point)))))
+    ;; Bind this in case the user sets it to nil.
+    (let* ((case-fold-search t)
+          (beg (save-excursion
+                 (and (search-backward "\n* menu:" nil t)
+                      (point)))))
       (or (and beg (search-backward "\n* " beg t))
          (error "No previous items in menu")))
     (Info-goto-node (save-excursion
@@ -1371,7 +1662,8 @@ N is the digit argument used to invoke this command."
                 ;; so we can scroll back through it.
                 (goto-char (point-max))))
         (recenter -1))
-       ((and (not (equal (Info-extract-pointer "up")
+       ((and (Info-no-error (Info-extract-pointer "prev"))
+             (not (equal (Info-extract-pointer "up")
                          (Info-extract-pointer "prev"))))
         (Info-no-error (Info-prev))
         (goto-char (point-max))
@@ -1383,52 +1675,65 @@ N is the digit argument used to invoke this command."
         (recenter -1))
        ((Info-no-error (Info-up t))
         (goto-char (point-min))
-        (or (search-forward "\n* Menu:" nil t)
-            (goto-char (point-max))))
+        (let ((case-fold-search t))
+          (or (search-forward "\n* Menu:" nil t)
+              (goto-char (point-max)))))
        (t (error "No previous nodes"))))
 
 (defun Info-scroll-up ()
   "Scroll one screenful forward in Info, considering all nodes as one sequence.
 Once you scroll far enough in a node that its menu appears on the screen
-but after point, the next scroll moves into its first subnode.
+but after point, the next scroll moves into its first subnode, unless
+`Info-scroll-prefer-subnodes' is nil.
 
-When you scroll past the end of a node, that goes to the next node; if
-this node has no successor, it moves to the parent node's successor,
-and so on.  If point is inside the menu of a node, it moves to
-subnode indicated by the following menu item.  (That case won't
-normally result from this command, but can happen in other ways.)"
+When you scroll past the end of a node, that goes to the next node if
+`Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
+if this node has no successor, it moves to the parent node's successor,
+and so on.  If `Info-scroll-prefer-subnodes' is non-nil and point is inside
+the menu of a node, it moves to subnode indicated by the following menu
+item.  (That case won't normally result from this command, but can happen
+in other ways.)"
 
   (interactive)
   (if (or (< (window-start) (point-min))
          (> (window-start) (point-max)))
       (set-window-start (selected-window) (point)))
-  (let ((virtual-end (save-excursion
-                      (goto-char (point-min))
-                      (if (search-forward "\n* Menu:" nil t)
-                          (point)
-                        (point-max)))))
+  (let* ((case-fold-search t)
+        (virtual-end (save-excursion
+                       (goto-char (point-min))
+                       (if (and Info-scroll-prefer-subnodes
+                                (search-forward "\n* Menu:" nil t))
+                           (point)
+                         (point-max)))))
     (if (or (< virtual-end (window-start))
            (pos-visible-in-window-p virtual-end))
-       (Info-next-preorder)
+       (cond
+        (Info-scroll-prefer-subnodes (Info-next-preorder))
+        ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
+        (t (Info-next-preorder)))
       (scroll-up))))
 
 (defun Info-scroll-down ()
   "Scroll one screenful back in Info, considering all nodes as one sequence.
-Within the menu of a node, this goes to its last subnode.
-When you scroll past the beginning of a node, that goes to the
-previous node or back up to the parent node."
+If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
+is non-nil, this goes to its last subnode.  When you scroll past the
+beginning of a node, that goes to the previous node or back up to the
+parent node."
   (interactive)
   (if (or (< (window-start) (point-min))
          (> (window-start) (point-max)))
       (set-window-start (selected-window) (point)))
-  (let* ((current-point (point))
-        (virtual-end (save-excursion
-                       (beginning-of-line)
-                       (setq current-point (point))
-                       (goto-char (point-min))
-                       (search-forward "\n* Menu:"
-                                       current-point
-                                       t))))
+  (let* ((case-fold-search t)
+        (current-point (point))
+        (virtual-end
+         (and Info-scroll-prefer-subnodes
+              (save-excursion
+                (beginning-of-line)
+                (setq current-point (point))
+                (goto-char (point-min))
+                (search-forward "\n* Menu:"
+                                current-point
+                                t)))))
     (if (or virtual-end (pos-visible-in-window-p (point-min)))
        (Info-last-preorder)
       (scroll-down))))
@@ -1473,7 +1778,7 @@ previous node or back up to the parent node."
          (Info-prev-reference t)))))
 
 (defun Info-index (topic)
-  "Look up a string 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
 name contains the word \"Index\", plus any immediately following
 nodes whose names also contain the word \"Index\".
@@ -1510,17 +1815,12 @@ Give a blank topic name to go to the Index node itself."
              (progn
                (goto-char (point-min))
                (while (re-search-forward pattern nil t)
-                 (setq matches
-                       (cons (list (buffer-substring (match-beginning 1)
-                                                     (match-end 1))
-                                   (buffer-substring (match-beginning 2)
-                                                     (match-end 2))
-                                   Info-current-node
-                                   (string-to-int (concat "0"
-                                                          (buffer-substring
-                                                           (match-beginning 3)
-                                                           (match-end 3)))))
-                             matches)))
+                 (push (list (match-string-no-properties 1)
+                             (match-string-no-properties 2)
+                             Info-current-node
+                             (string-to-int (concat "0"
+                                                    (match-string 3))))
+                       matches))
                (and (setq node (Info-extract-pointer "next" t))
                     (string-match "\\<Index\\>" node)))
            (Info-goto-node node))
@@ -1550,7 +1850,7 @@ Give a blank topic name to go to the Index node itself."
   (Info-goto-node (nth 1 (car Info-index-alternatives)))
   (if (> (nth 3 (car Info-index-alternatives)) 0)
       (forward-line (nth 3 (car Info-index-alternatives)))
-    (forward-line 3)  ; don't search in headers
+    (forward-line 3)                   ; don't search in headers
     (let ((name (car (car Info-index-alternatives))))
       (Info-find-index-name name)))
   (message "Found `%s' in %s.  %s"
@@ -1610,15 +1910,15 @@ Give a blank topic name to go to the Index node itself."
     (bury-buffer "*Help*")))
 \f
 (defun Info-get-token (pos start all &optional errorstring)
-  "Return the token around POS,
+  "Return the token around POS.
 POS must be somewhere inside the token
 START is a regular expression which will match the
     beginning of the tokens delimited string
 ALL is a regular expression with a single
     parenthesized subpattern which is the token to be
-    returned. E.g. '{\(.*\)}' would return any string
+    returned.  E.g. '{\(.*\)}' would return any string
     enclosed in braces around POS.
-SIG optional fourth argument, controls action on no match
+ERRORSTRING optional fourth argument, controls action on no match
     nil: return nil
     t: beep
     a string: signal an error, using that string."
@@ -1641,7 +1941,7 @@ SIG optional fourth argument, controls action on no match
                                          (> (match-end 0) pos))))))
        (if (and found (<= (match-beginning 0) pos)
                 (> (match-end 0) pos))
-           (buffer-substring (match-beginning 1) (match-end 1))
+           (match-string-no-properties 1)
          (cond ((null errorstring)
                 nil)
                ((eq errorstring t)
@@ -1655,11 +1955,7 @@ SIG optional fourth argument, controls action on no match
 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
 At end of the node's text, moves to the next node, or up if none."
   (interactive "e")
-  (let* ((start (event-start click))
-        (window (car start))
-        (pos (car (cdr start))))
-    (select-window window)
-    (goto-char pos))
+  (mouse-set-point click)
   (and (not (Info-try-follow-nearest-node))
        (save-excursion (forward-line 1) (eobp))
        (Info-next-preorder)))
@@ -1682,8 +1978,11 @@ If no reference to follow, moves to the next node, or up if none."
       (Info-follow-reference node))
      ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
       (Info-goto-node node))
-     ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):"))
-      (Info-menu node))
+     ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
+      (beginning-of-line)
+      (forward-char 2)
+      (setq node (Info-extract-menu-node-name))
+      (Info-goto-node node))
      ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
       (Info-goto-node node))
      ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
@@ -1735,6 +2034,7 @@ If no reference to follow, moves to the next node, or up if none."
   (define-key Info-mode-map "s" 'Info-search)
   ;; For consistency with Rmail.
   (define-key Info-mode-map "\M-s" 'Info-search)
+  (define-key Info-mode-map "\M-n" 'clone-buffer)
   (define-key Info-mode-map "t" 'Info-top-node)
   (define-key Info-mode-map "u" 'Info-up)
   (define-key Info-mode-map "," 'Info-index-next)
@@ -1743,30 +2043,69 @@ If no reference to follow, moves to the next node, or up if none."
   )
 
 (defun Info-check-pointer (item)
-  ;; Non-nil if ITEM is present in this node.
+  "Non-nil if ITEM is present in this node."
   (condition-case nil
       (Info-extract-pointer item)
     (error nil)))
 
-(easy-menu-define Info-mode-menu Info-mode-map
-  "Menu for info files."
-  '("Info"
-    ["Up" Info-up (Info-check-pointer "up")]
-    ["Next" Info-next (Info-check-pointer "next")]
-    ["Previous" Info-prev (Info-check-pointer "prev[ious]*")]
-    ("Menu item" ["You should never see this" report-emacs-bug t])
-    ("Reference" ["You should never see this" report-emacs-bug t])
-    ["Search..." Info-search t]
-    ["Goto node..." Info-goto-node t]
-    ["Last" Info-last Info-history]
-    ["Exit" Info-exit t]))
+(easy-menu-define
+ Info-mode-menu Info-mode-map
+ "Menu for info files."
+ '("Info"
+   ["Up" Info-up :active (Info-check-pointer "up")
+    :help "Go up in the Info tree"]
+   ["Next" Info-next :active (Info-check-pointer "next")
+    :help "Go to the next node"]
+   ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
+    :help "Go to the previous node"]
+   ["Backward" Info-backward-node
+    :help "Go backward one node, considering all as a sequence"]
+   ["Forward" Info-forward-node
+    :help "Go forward one node, considering all as a sequence"]
+   ["Beginning" beginning-of-buffer
+    :help "Go to beginning of this node"]
+   ["Top" Info-top-node
+    :help "Go to top node of file"]
+   ["Final Node" Info-final-node
+    :help "Go to final node in this file"]
+   ("Menu Item" ["You should never see this" report-emacs-bug t])
+   ("Reference" ["You should never see this" report-emacs-bug t])
+   ["Search..." Info-search
+    :help "Search for regular expression in this Info file"]
+   ["Go to Node..." Info-goto-node
+    :help "Go to a named node"]
+   ["Last" Info-last :active Info-history
+    :help "Go to the last node you were at"]
+   ("Index..."
+    ["Lookup a String" Info-index
+     :help "Look for a string in the index items"]
+    ["Next Matching Item" Info-index-next
+     :help "Look for another occurrence of previous item"])
+   ["Edit" Info-edit :help "Edit contents of this node"
+    :active Info-enable-edit]
+   ["Exit" Info-exit :help "Stop reading Info"]))
+
+
+(defvar info-tool-bar-map
+  (if (display-graphic-p)
+      (let ((tool-bar-map (make-sparse-keymap)))
+       (tool-bar-add-item-from-menu 'Info-exit "close" Info-mode-map)
+       (tool-bar-add-item-from-menu 'Info-prev "left_arrow" Info-mode-map)
+       (tool-bar-add-item-from-menu 'Info-next "right_arrow" Info-mode-map)
+       (tool-bar-add-item-from-menu 'Info-up "up_arrow" Info-mode-map)
+       (tool-bar-add-item-from-menu 'Info-last "undo" Info-mode-map)
+       (tool-bar-add-item-from-menu 'Info-top-node "home" Info-mode-map)
+       (tool-bar-add-item-from-menu 'Info-index "index" Info-mode-map)
+       (tool-bar-add-item-from-menu 'Info-goto-node "jump_to" Info-mode-map)
+       (tool-bar-add-item-from-menu 'Info-search "search" Info-mode-map)
+       tool-bar-map)))
 
 (defvar Info-menu-last-node nil)
 ;; Last node the menu was created for.
 ;; Value is a list, (FILE-NAME NODE-NAME).
 
 (defun Info-menu-update ()
-  ;; Update the Info menu for the current node.
+  "Update the Info menu for the current node."
   (condition-case nil
       (if (or (not (eq major-mode 'Info-mode))
              (equal (list Info-current-file Info-current-node)
@@ -1778,13 +2117,13 @@ If no reference to follow, moves to the next node, or up if none."
                                    (Info-complete-menu-item
                                     "" (lambda (e) t) t)
                                  (error nil))))
-              entries current 
+              entries current
               (number 0))
          (while (and items (< number 9))
            (setq current (car items)
                  items (cdr items)
                  number (1+ number))
-           (setq entries (cons `[,current 
+           (setq entries (cons `[,current
                                  (Info-menu ,current)
                                  :keys ,(format "%d" number)]
                                entries)))
@@ -1792,10 +2131,10 @@ If no reference to follow, moves to the next node, or up if none."
              (setq entries (cons ["Other..." Info-menu t] entries)))
          (or entries
              (setq entries (list ["No menu" nil nil])))
-         (easy-menu-change '("Info") "Menu item" (nreverse entries)))
+         (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
        ;; Update reference menu.  Code stolen from `Info-follow-reference'.
        (let ((items nil)
-             str i entries current 
+             str i entries current
              (number 0)
              (case-fold-search t))
          (save-excursion
@@ -1815,7 +2154,7 @@ If no reference to follow, moves to the next node, or up if none."
            (setq current (car items)
                  items (cdr items)
                  number (1+ number))
-           (setq entries (cons `[,current 
+           (setq entries (cons `[,current
                                  (Info-follow-reference ,current)
                                  t]
                                entries)))
@@ -1832,15 +2171,15 @@ If no reference to follow, moves to the next node, or up if none."
 
 \f
 ;; Info mode is suitable only for specially formatted data.
-(put 'info-mode 'mode-class 'special)
+(put 'Info-mode 'mode-class 'special)
 
 (defun Info-mode ()
-  "\\<Info-mode-map>
-Info mode provides commands for browsing through the Info documentation tree.
+  "Info mode provides commands for browsing through the Info documentation tree.
 Documentation in Info is divided into \"nodes\", each of which discusses
 one topic and contains references to other nodes which discuss related
 topics.  Info has commands to follow the references and show you other nodes.
 
+\\<Info-mode-map>\
 \\[Info-help]  Invoke the Info tutorial.
 \\[Info-exit]  Quit Info: reselect previously selected buffer.
 
@@ -1873,7 +2212,7 @@ When after all menu items (or if their is no menu), move up to
 the parent node.
 \\[Info-scroll-down]   Normally, scroll backward.  If the beginning of the buffer is
 already visible, try to go to the previous menu entry, or up if there is none.
-\\[beginning-of-buffer]        Go to beginning of node.  
+\\[beginning-of-buffer]        Go to beginning of node.
 
 Advanced commands:
 \\[Info-exit]  Quit Info: reselect previously selected buffer.
@@ -1892,7 +2231,6 @@ Advanced commands:
   (setq mode-name "Info")
   (setq tab-width 8)
   (use-local-map Info-mode-map)
-  (make-local-hook 'activate-menubar-hook)
   (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
   (set-syntax-table text-mode-syntax-table)
   (setq local-abbrev-table text-mode-abbrev-table)
@@ -1907,21 +2245,32 @@ Advanced commands:
   (setq Info-tag-table-buffer nil)
   (make-local-variable 'Info-history)
   (make-local-variable 'Info-index-alternatives)
+  (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
   ;; This is for the sake of the invisible text we use handling titles.
   (make-local-variable 'line-move-ignore-invisible)
   (setq line-move-ignore-invisible t)
+  (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
   (Info-set-mode-line)
   (run-hooks 'Info-mode-hook))
 
-(defvar Info-edit-map nil
+(defun Info-clone-buffer-hook ()
+  (when (bufferp Info-tag-table-buffer)
+    (setq Info-tag-table-buffer
+         (with-current-buffer Info-tag-table-buffer (clone-buffer)))
+    (let ((m Info-tag-table-marker))
+      (when (and (markerp m) (marker-position m))
+       (setq Info-tag-table-marker
+             (with-current-buffer Info-tag-table-buffer
+               (copy-marker (marker-position m))))))))
+
+(defvar Info-edit-map (let ((map (make-sparse-keymap)))
+                       (set-keymap-parent map text-mode-map)
+                       (define-key map "\C-c\C-c" 'Info-cease-edit)
+                       map)
   "Local keymap used within `e' command of Info.")
-(if Info-edit-map
-    nil
-  (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
-  (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
 
 ;; Info-edit mode is suitable only for specially formatted data.
-(put 'info-edit-mode 'mode-class 'special)
+(put 'Info-edit-mode 'mode-class 'special)
 
 (defun Info-edit-mode ()
   "Major mode for editing the contents of an Info node.
@@ -1945,7 +2294,7 @@ Allowed only if variable `Info-enable-edit' is non-nil."
       (error "Editing info nodes is not enabled"))
   (Info-edit-mode)
   (message "%s" (substitute-command-keys
-           "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
+                "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
 
 (defun Info-cease-edit ()
   "Finish editing Info node; switch back to Info proper."
@@ -1965,7 +2314,14 @@ 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")
+  '("ediff" "forms" "gnus" ("mh" . "mh-e") "sc" "message"
+    ("dired" . "dired-x") ("c" . "ccmode") "viper" "vip"
+    ("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")
   "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.
@@ -1976,11 +2332,11 @@ If the element is just a file name, the file name also serves as the prefix.")
 The `info-file' property of COMMAND says which Info manual to search.
 If COMMAND has no property, the variable `Info-file-list-for-emacs'
 defines heuristics for which Info manual to try.
-The locations are of the format used in Info-history, i.e.
+The locations are of the format used in `Info-history', i.e.
 \(FILENAME NODENAME BUFFERPOS\)."
   (let ((where '())
        (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
-                         ":\\s *\\(.*\\)\\.$"))
+                         "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
        (info-file "emacs"))            ;default
     ;; Determine which info file this command is documented in.
     (if (get command 'info-file)
@@ -1999,29 +2355,35 @@ The locations are of the format used in Info-history, i.e.
            (if (string-match regexp (symbol-name command))
                (setq info-file file file-list nil))
            (setq file-list (cdr file-list))))))
-    (save-excursion
-      (condition-case nil
-         (Info-find-node info-file "Command Index")
-       ;; Some manuals may not have a separate Command Index node,
-       ;; so try just Index instead.
-       (error
-        (Info-find-node info-file "Index")))
-      ;; Take the index node off the Info history.
-      (setq Info-history (cdr Info-history))
-      (goto-char (point-max))
-      (while (re-search-backward cmd-desc nil t)
-         (setq where (cons (list Info-current-file
-                                 (buffer-substring
-                                  (match-beginning 1)
-                                  (match-end 1))
-                                 0)
-                           where)))
-      where)))
+    (Info-find-node info-file "Top")
+    (or (and (search-forward "\n* menu:" nil t)
+            (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
+       (error "Info file `%s' appears to lack an index" info-file))
+    (goto-char (match-beginning 1))
+    ;; Bind Info-history to nil, to prevent the index nodes from
+    ;; getting into the node history.
+    (let ((Info-history nil)
+         (exact nil)
+         node found)
+      (Info-goto-node (Info-extract-menu-node-name))
+      (while
+         (progn
+           (goto-char (point-min))
+           (while (re-search-forward cmd-desc nil t)
+             (setq where
+                   (cons (list Info-current-file
+                               (match-string-no-properties 2)
+                               0)
+                         where)))
+           (and (setq node (Info-extract-pointer "next" t))
+                (string-match "\\<Index\\>" node)))
+       (Info-goto-node node)))
+    where))
 
 ;;;###autoload
 (defun Info-goto-emacs-command-node (command)
   "Go to the Info node in the Emacs manual for command COMMAND.
-The command is found by looking up in Emacs manual's Command Index
+The command is found by looking up in Emacs manual's indices
 or in another manual found via COMMAND's `info-file' property or
 the variable `Info-file-list-for-emacs'."
   (interactive "CFind documentation for command: ")
@@ -2036,13 +2398,17 @@ the variable `Info-file-list-for-emacs'."
          ;; FIXME It would be cool if this could use a buffer other
          ;; than *info*.
          (pop-to-buffer "*info*")
-         (Info-find-node (car (car where))
-                         (car (cdr (car where))))
+         ;; Bind Info-history to nil, to prevent the last Index node
+         ;; visited by Info-find-emacs-command-nodes from being
+         ;; pushed onto the history.
+         (let ((Info-history nil))
+           (Info-find-node (car (car where))
+                           (car (cdr (car where)))))
          (if (> num-matches 1)
              (progn
-               ;; Info-find-node already pushed (car where) onto
-               ;; Info-history.  Put the other nodes that were found on
-               ;; the history.
+               ;; (car where) will be pushed onto Info-history
+               ;; when/if they go to another node.  Put the other
+               ;; nodes that were found on the history.
                (setq Info-history (nconc (cdr where) Info-history))
                (message "Found %d other entr%s.  Use %s to see %s."
                         (1- num-matches)
@@ -2053,12 +2419,13 @@ the variable `Info-file-list-for-emacs'."
 
 ;;;###autoload
 (defun Info-goto-emacs-key-command-node (key)
-  "Go to the Info node in the Emacs manual the command bound to KEY, a string.
-Interactively, if the binding is execute-extended-command, a command is read.
-The command is found by looking up in Emacs manual's Command Index
+  "Go to the node in the Emacs manual which describes the command bound to KEY.
+KEY is a string.
+Interactively, if the binding is `execute-extended-command', a command is read.
+The command is found by looking up in Emacs manual's indices
 or in another manual found via COMMAND's `info-file' property or
 the variable `Info-file-list-for-emacs'."
-  (interactive "kFind documentation for key:")
+  (interactive "kFind documentation for key: ")
   (let ((command (key-binding key)))
     (cond ((null command)
           (message "%s is undefined" (key-description key)))
@@ -2069,15 +2436,51 @@ the variable `Info-file-list-for-emacs'."
          (t
           (Info-goto-emacs-command-node command)))))
 \f
-(defcustom Info-title-face-alist
-  '((?* bold underline)
-    (?= bold-italic underline)
-    (?- italic underline))
-  "*Alist of face or list of faces to use for pseudo-underlined titles.
-The alist key is the character the title is underlined with (?*, ?= or ?-)."
-  :type '(repeat (list character face face))
+(defface Info-title-1-face
+  '((((type tty pc) (class color)) (:foreground "yellow" :weight bold))
+    (t (:height 1.2 :inherit Info-title-2-face)))
+  "Face for Info titles at level 1."
+  :group 'info)
+
+(defface Info-title-2-face
+  '((((type tty pc) (class color)) (:foreground "lightblue" :weight bold))
+    (t (:height 1.2 :inherit Info-title-3-face)))
+  "Face for Info titles at level 2."
+  :group 'info)
+
+(defface Info-title-3-face
+  '((((type tty pc) (class color)) (:weight bold))
+    (t (:height 1.2 :inherit Info-title-4-face)))
+  "Face for Info titles at level 3."
   :group 'info)
 
+(defface Info-title-4-face
+  '((((type tty pc) (class color)) (:weight bold))
+    (t (:weight bold :inherit variable-pitch)))
+  "Face for Info titles at level 4."
+  :group 'info)
+
+(defface info-menu-header
+  '((((type tty pc))
+     :underline t
+     :weight bold)
+    (t
+     :inherit variable-pitch
+     :weight bold))
+  "Face for headers in Info menus."
+  :group 'info)
+
+(defun Info-fontify-menu-headers ()
+  "Add the face `info-menu-header' to any header before a menu entry."
+  (save-excursion
+    (goto-char (point-min))
+    (when (re-search-forward "\\* Menu:" nil t)
+      (put-text-property (match-beginning 0) (match-end 0)
+                        'face 'info-menu-header)
+      (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
+       (put-text-property (match-beginning 1) (match-end 1)
+                          'face 'info-menu-header)))))
+
 (defun Info-fontify-node ()
   (save-excursion
     (let ((buffer-read-only nil)
@@ -2085,38 +2488,56 @@ The alist key is the character the title is underlined with (?*, ?= or ?-)."
       (goto-char (point-min))
       (when (looking-at "^File: [^,: \t]+,?[ \t]+")
        (goto-char (match-end 0))
-       (while
-           (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
+       (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
          (goto-char (match-end 0))
-         (if (save-excursion
-               (goto-char (match-beginning 1))
-               (save-match-data (looking-at "Node:")))
-             (put-text-property (match-beginning 2) (match-end 2)
-                                'face 'info-node)
-           (put-text-property (match-beginning 2) (match-end 2)
-                              'face 'info-xref)
-           (put-text-property (match-beginning 2) (match-end 2)
-                              'mouse-face 'highlight))))
+         (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)
-       (put-text-property (match-beginning 1) (match-end 1)
-                          'face
-                          (cdr (assq (preceding-char) Info-title-face-alist)))
+      (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.
-       (if (memq (framep (selected-frame)) '(x pc w32))
-           (put-text-property (match-end 1) (match-end 2)
-                              'invisible t)))
+       (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
-         (put-text-property (match-beginning 1) (match-end 1)
-                            'face 'info-xref)
-         (put-text-property (match-beginning 1) (match-end 1)
-                            'mouse-face 'highlight)))
+         (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))
@@ -2125,14 +2546,15 @@ The alist key is the character the title is underlined with (?*, ?= or ?-)."
          (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
+             (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))
-             (put-text-property (match-beginning 1) (match-end 1)
-                                'face 'info-xref)
-             (put-text-property (match-beginning 1) (match-end 1)
-                                'mouse-face 'highlight))))
+             (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
 
@@ -2199,6 +2621,8 @@ This will add a speedbar major display mode."
   (speedbar-change-initial-expansion-list "Info")
   )
 
+(eval-when-compile (defvar speedbar-attached-frame))
+
 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
   "Display an Info directory hierarchy in speedbar.
 DIRECTORY is the current directory in the attached frame.
@@ -2234,32 +2658,32 @@ specific node to expand."
             (setq completions (cdr completions)))
           t)
        nil))))
-  
+
 (defun Info-speedbar-goto-node (text node indent)
-  "When user clicks on TEXT, goto an info NODE.
+  "When user clicks on TEXT, go to an info NODE.
 The INDENT level is ignored."
-    (select-frame speedbar-attached-frame)
-    (let* ((buff (or (get-buffer "*info*")
-                    (progn (info) (get-buffer "*info*"))))
-          (bwin (get-buffer-window buff 0)))
-      (if bwin
-         (progn
-           (select-window bwin)
-           (raise-frame (window-frame bwin)))
-       (if speedbar-power-click
-           (let ((pop-up-frames t)) (select-window (display-buffer buff)))
-         (select-frame speedbar-attached-frame)
-         (switch-to-buffer buff)))
-      (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
-           (file (match-string 1 node))
-           (node (match-string 2 node)))
-       (Info-find-node file node)
-       ;; If we do a find-node, and we were in info mode, restore
-       ;; the old default method.  Once we are in info mode, it makes
-       ;; sense to return to whatever method the user was using before.
-       (if (string= speedbar-initial-expansion-list-name "Info")
-           (speedbar-change-initial-expansion-list
-            speedbar-previously-used-expansion-list-name)))))
+  (select-frame speedbar-attached-frame)
+  (let* ((buff (or (get-buffer "*info*")
+                  (progn (info) (get-buffer "*info*"))))
+        (bwin (get-buffer-window buff 0)))
+    (if bwin
+       (progn
+         (select-window bwin)
+         (raise-frame (window-frame bwin)))
+      (if speedbar-power-click
+         (let ((pop-up-frames t)) (select-window (display-buffer buff)))
+       (select-frame speedbar-attached-frame)
+       (switch-to-buffer buff)))
+    (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
+         (file (match-string 1 node))
+         (node (match-string 2 node)))
+      (Info-find-node file node)
+      ;; If we do a find-node, and we were in info mode, restore
+      ;; the old default method.  Once we are in info mode, it makes
+      ;; sense to return to whatever method the user was using before.
+      (if (string= speedbar-initial-expansion-list-name "Info")
+         (speedbar-change-initial-expansion-list
+          speedbar-previously-used-expansion-list-name)))))
 
 (defun Info-speedbar-expand-node (text token indent)
   "Expand the node the user clicked on.
@@ -2269,9 +2693,9 @@ INDENT is the current indentation depth."
   (cond ((string-match "+" text)       ;we have to expand this file
         (speedbar-change-expand-button-char ?-)
         (if (speedbar-with-writable
-              (save-excursion
-                (end-of-line) (forward-char 1)
-                (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
+             (save-excursion
+               (end-of-line) (forward-char 1)
+               (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
             (speedbar-change-expand-button-char ?-)
           (speedbar-change-expand-button-char ??)))
        ((string-match "-" text)        ;we have to contract this node
@@ -2326,6 +2750,14 @@ BUFFER is the buffer speedbar is requesting buttons for."
   (Info-speedbar-hierarchy-buttons nil 0)
   )
 
+(dolist (mess '("^Node has no Previous$"
+               "^No menu in this node$"
+               "^Node has no Next$"
+                "^No cross-references in this node^"
+                search-failed
+               "^No \".*\" in index$"))
+  (add-to-list 'debug-ignored-errors mess))
+
 (provide 'info)
 
 ;;; info.el ends here