home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / emacs-15.0.3 / lisp / info.el < prev    next >
Lisp/Scheme  |  1990-08-16  |  24KB  |  701 lines

  1. ;; Info package for Emacs  -- could use a "create node" feature.
  2. ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is distributed in the hope that it will be useful,
  7. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  8. ;; accepts responsibility to anyone for the consequences of using it
  9. ;; or for whether it serves any particular purpose or works at all,
  10. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  11. ;; License for full details.
  12.  
  13. ;; Everyone is granted permission to copy, modify and redistribute
  14. ;; GNU Emacs, but only under the conditions described in the
  15. ;; GNU Emacs General Public License.   A copy of this license is
  16. ;; supposed to have been given to you along with GNU Emacs so you
  17. ;; can know your rights and responsibilities.  It should be in a
  18. ;; file named COPYING.  Among other things, the copyright notice
  19. ;; and this notice must be preserved on all copies.
  20.  
  21. (provide 'info)
  22.  
  23. (defvar Info-history nil
  24.   "List of info nodes user has visited.
  25. Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
  26.  
  27. (defvar Info-enable-edit nil
  28.   "Non-nil means the \\[Info-edit] command in Info can edit the current node.")
  29.  
  30. (defvar Info-enable-active-nodes t
  31.   "Non-nil allows Info to execute Lisp code associated with nodes.
  32. The Lisp code is executed when the node is selected.")
  33.  
  34. (defvar Info-directory nil
  35.   "Default directory for Info documentation files.")
  36.  
  37. (defvar Info-current-file nil
  38.   "Info file that Info is now looking at, or nil.")
  39.  
  40. (defvar Info-current-subfile nil
  41.   "Info subfile that is actually in the *info* buffer now,
  42. or nil if current info file is not split into subfiles.")
  43.  
  44. (defvar Info-current-node nil
  45.   "Name of node that Info is now looking at, or nil.")
  46.  
  47. (defvar Info-tag-table-marker (make-marker)
  48.   "Marker pointing at beginning of current Info file's tag table.
  49. Marker points nowhere if file has no tag table.")
  50.  
  51. (defun info ()
  52.   "Enter Info, the documentation browser."
  53.   (interactive)
  54.   (if (get-buffer "*info*")
  55.       (switch-to-buffer "*info*")
  56.     (Info-directory)))
  57.  
  58. ;; Go to an info node specified as separate filename and nodename.
  59. ;; no-going-back is non-nil if recovering from an error in this function;
  60. ;; it says do not attempt further (recursive) error recovery.
  61. (defun Info-find-node (filename nodename &optional no-going-back)
  62.   ;; Convert filename to lower case if not found as specified.
  63.   ;; Expand it.
  64.   (if filename
  65.       (let (temp)
  66.     (setq filename (substitute-in-file-name filename))
  67.     (setq temp (expand-file-name filename
  68.                      ;; Use Info's default dir
  69.                      ;; unless the filename starts with `./'.
  70.                      (if (not (string-match "^\\./" filename))
  71.                      Info-directory)))
  72.     (if (file-exists-p temp)
  73.         (setq filename temp)
  74.       (setq temp (expand-file-name (downcase filename) Info-directory))
  75.       (if (file-exists-p temp)
  76.           (setq filename temp)
  77.         (error "Info file %s does not exist"
  78.            (expand-file-name filename Info-directory))))))
  79.   ;; Record the node we are leaving.
  80.   (if (and Info-current-file (not no-going-back))
  81.       (setq Info-history
  82.         (cons (list Info-current-file Info-current-node (point))
  83.           Info-history)))
  84.   ;; Go into info buffer.
  85.   (switch-to-buffer "*info*")
  86.   (or (eq major-mode 'Info-mode)
  87.       (Info-mode))
  88.   (widen)
  89.   (setq Info-current-node nil)
  90.   (unwind-protect
  91.       (progn
  92.     ;; Switch files if necessary
  93.     (or (null filename)
  94.         (equal Info-current-file filename)
  95.         (let ((buffer-read-only nil))
  96.           (setq Info-current-file nil
  97.             Info-current-subfile nil)
  98.           (erase-buffer)
  99.           (insert-file-contents filename t)
  100.           (set-buffer-modified-p nil)
  101.           (setq default-directory (file-name-directory filename))
  102.           ;; See whether file has a tag table.  Record the location if yes.
  103.           (set-marker Info-tag-table-marker nil)
  104.           (goto-char (point-max))
  105.           (forward-line -8)
  106.           (or (equal nodename "*")
  107.           (not (search-forward "\^_\nEnd tag table\n" nil t))
  108.           (let (pos)
  109.             ;; We have a tag table.  Find its beginning.
  110.             ;; Is this an indirect file?
  111.             (search-backward "\nTag table:\n")
  112.             (setq pos (point))
  113.             (if (save-excursion
  114.               (forward-line 2)
  115.               (looking-at "(Indirect)\n"))
  116.             ;; It is indirect.  Copy it to another buffer
  117.             ;; and record that the tag table is in that buffer.
  118.             (save-excursion
  119.               (let ((buf (current-buffer)))
  120.                 (set-buffer (get-buffer-create " *info tag table*"))
  121.                 (setq case-fold-search t)
  122.                 (erase-buffer)
  123.                 (insert-buffer-substring buf)
  124.                 (set-marker Info-tag-table-marker
  125.                     (match-end 0))))
  126.              (set-marker Info-tag-table-marker pos))))
  127.           (setq Info-current-file
  128.             (file-name-sans-versions buffer-file-name))))
  129.     (if (equal nodename "*")
  130.         (progn (setq Info-current-node nodename)
  131.            (Info-set-mode-line))
  132.       ;; Search file for a suitable node.
  133.       ;; First get advice from tag table if file has one.
  134.       ;; Also, if this is an indirect info file,
  135.       ;; read the proper subfile into this buffer.
  136.       (let ((guesspos (point-min)))
  137.         (if (marker-position Info-tag-table-marker)
  138.         (save-excursion
  139.           (set-buffer (marker-buffer Info-tag-table-marker))
  140.           (goto-char Info-tag-table-marker)
  141.           (if (search-forward (concat "Node: " nodename "\177") nil t)
  142.               (progn
  143.             (setq guesspos (read (current-buffer)))
  144.             ;; If this is an indirect file,
  145.             ;; determine which file really holds this node
  146.             ;; and read it in.
  147.             (if (not (eq (current-buffer) (get-buffer "*info*")))
  148.                 (setq guesspos
  149.                   (Info-read-subfile guesspos))))
  150.             (error "No such node: \"%s\"" nodename))))
  151.         (goto-char (max (point-min) (- guesspos 1000))))
  152.       ;; Now search from our advised position (or from beg of buffer)
  153.       ;; to find the actual node.
  154.       (let ((regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n]")))
  155.         (catch 'foo
  156.           (while (search-forward "\n\^_" nil t)
  157.         (forward-line 1)
  158.         (let ((beg (point)))
  159.           (forward-line 1)
  160.           (if (re-search-backward regexp beg t)
  161.               (throw 'foo t))))
  162.           (error "No such node: %s" nodename)))
  163.       (Info-select-node)))
  164.     ;; If we did not finish finding the specified node,
  165.     ;; go back to the previous one.
  166.     (or Info-current-node no-going-back
  167.     (let ((hist (car Info-history)))
  168.       (setq Info-history (cdr Info-history))
  169.       (Info-find-node (nth 0 hist) (nth 1 hist) t)
  170.       (goto-char (nth 2 hist)))))
  171.   (goto-char (point-min)))
  172.  
  173. (defun Info-read-subfile (nodepos)
  174.   (set-buffer (marker-buffer Info-tag-table-marker))
  175.   (goto-char (point-min))
  176.   (search-forward "\n\^_")
  177.   (let (lastfilepos
  178.     lastfilename)
  179.     (forward-line 2)
  180.     (catch 'foo
  181.       (while (not (looking-at "\^_"))
  182.     (if (not (eolp))
  183.         (let ((beg (point))
  184.           thisfilepos thisfilename)
  185.           (search-forward ": ")
  186.           (setq thisfilename  (buffer-substring beg (- (point) 2)))
  187.           (setq thisfilepos (read (current-buffer)))
  188.           (if (> thisfilepos nodepos)
  189.           (throw 'foo t))
  190.           (setq lastfilename thisfilename)
  191.           (setq lastfilepos thisfilepos)))))
  192.     (set-buffer (get-buffer "*info*"))
  193.     (or (equal Info-current-subfile lastfilename)
  194.     (let ((buffer-read-only nil))
  195.       (setq buffer-file-name nil)
  196.       (widen)
  197.       (erase-buffer)
  198.       (insert-file-contents lastfilename)
  199.       (set-buffer-modified-p nil)
  200.       (setq Info-current-subfile lastfilename)))
  201.     (goto-char (point-min))
  202.     (search-forward "\n\^_")
  203.     (+ (- nodepos lastfilepos) (point))))
  204.  
  205. ;; Select the info node that point is in.
  206. (defun Info-select-node ()
  207.   (save-excursion
  208.    ;; Find beginning of node.
  209.    (search-backward "\n\^_")
  210.    (forward-line 2)
  211.    ;; Get nodename spelled as it is in the node.
  212.    (re-search-forward "Node:[ \t]*")
  213.    (setq Info-current-node
  214.      (buffer-substring (point)
  215.                (progn
  216.                 (skip-chars-forward "^,\t\n")
  217.                 (point))))
  218.    (Info-set-mode-line)
  219.    ;; Find the end of it, and narrow.
  220.    (beginning-of-line)
  221.    (let (active-expression)
  222.      (narrow-to-region (point)
  223.                (if (re-search-forward "\n[\^_\f]" nil t)
  224.                (prog1
  225.                 (1- (point))
  226.                 (if (looking-at "[\n\^_\f]*execute: ")
  227.                 (progn
  228.                   (goto-char (match-end 0))
  229.                   (setq active-expression
  230.                     (read (current-buffer))))))
  231.              (point-max)))
  232.      (if Info-enable-active-nodes (eval active-expression)))))
  233.  
  234. (defun Info-set-mode-line ()
  235.   (setq mode-line-buffer-identification
  236.     (concat
  237.      "Info:  ("
  238.      (if Info-current-file
  239.          (file-name-nondirectory Info-current-file)
  240.        "")
  241.      ")"
  242.      (or Info-current-node ""))))
  243.  
  244. ;; Go to an info node specified with a filename-and-nodename string
  245. ;; of the sort that is found in pointers in nodes.
  246.  
  247. (defun Info-goto-node (nodename)
  248.   "Go to info node named NAME.  Give just NODENAME or (FILENAME)NODENAME."
  249.   (interactive "sGoto node: ")
  250.   (let (filename)
  251.     (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
  252.           nodename)
  253.     (setq filename (if (= (match-beginning 1) (match-end 1))
  254.                ""
  255.              (substring nodename (match-beginning 2) (match-end 2)))
  256.       nodename (substring nodename (match-beginning 3) (match-end 3)))
  257.     (let ((trim (string-match "\\s *\\'" filename)))
  258.       (if trim (setq filename (substring filename 0 trim))))
  259.     (let ((trim (string-match "\\s *\\'" nodename)))
  260.       (if trim (setq nodename (substring nodename 0 trim))))
  261.     (Info-find-node (if (equal filename "") nil filename)
  262.             (if (equal nodename "") "Top" nodename))))
  263.  
  264. (defvar Info-last-search nil
  265.   "Default regexp for Info S command to search for.")
  266.  
  267. (defun Info-search (regexp)
  268.   "Search for REGEXP, starting from point, and select node it's found in."
  269.   (interactive "sSearch (regexp): ")
  270.   (if (equal regexp "")
  271.       (setq regexp Info-last-search)
  272.     (setq Info-last-search regexp))
  273.   (let ((found ()) current
  274.     (onode Info-current-node)
  275.     (ofile Info-current-file)
  276.     (opoint (point))
  277.     (osubfile Info-current-subfile))
  278.     (save-excursion
  279.       (save-restriction
  280.     (widen)
  281.     (if (null Info-current-subfile)
  282.         (progn (re-search-forward regexp) (setq found (point)))
  283.       (condition-case err
  284.           (progn (re-search-forward regexp) (setq found (point)))
  285.         (search-failed nil)))))
  286.     (if (not found) ;can only happen in subfile case -- else would have erred
  287.     (unwind-protect
  288.         (let ((list ()))
  289.           (set-buffer (marker-buffer Info-tag-table-marker))
  290.           (goto-char (point-min))
  291.           (search-forward "\n\^_\nIndirect:")
  292.           (save-restriction
  293.         (narrow-to-region (point)
  294.                   (progn (search-forward "\n\^_")
  295.                      (1- (point))))
  296.         (goto-char (point-min))
  297.         (search-forward (concat "\n" osubfile ": "))
  298.         (beginning-of-line)
  299.         (while (not (eobp))
  300.           (re-search-forward "\\(^.*\\): [0-9]+$")
  301.           (goto-char (+ (match-end 1) 2))
  302.           (setq list (cons (cons (read (current-buffer))
  303.                      (buffer-substring (match-beginning 1)
  304.                                (match-end 1)))
  305.                    list))
  306.           (goto-char (1+ (match-end 0))))
  307.         (setq list (nreverse list)
  308.               current (car (car list))
  309.               list (cdr list)))
  310.           (while list
  311.         (message "Searching subfile %s..." (cdr (car list)))
  312.         (Info-read-subfile (car (car list)))
  313.         (setq list (cdr list))
  314.         (goto-char (point-min))
  315.         (if (re-search-forward regexp nil t)
  316.             (setq found (point) list ())))
  317.           (if found
  318.           (message "")
  319.         (signal 'search-failed (list regexp))))
  320.       (if (not found)
  321.           (progn (Info-read-subfile opoint)
  322.              (goto-char opoint)
  323.              (Info-select-node)))))
  324.     (widen)
  325.     (goto-char found)
  326.     (Info-select-node)
  327.     (or (and (equal onode Info-current-node)
  328.          (equal ofile Info-current-file))
  329.     (setq Info-history (cons (list ofile onode opoint)
  330.                  Info-history)))))
  331.  
  332. (defun Info-extract-pointer (name &optional errorname)
  333.   (save-excursion
  334.    (goto-char (point-min))
  335.    (forward-line 1)
  336.    (if (re-search-backward (concat name ":") nil t)
  337.        nil
  338.      (error (concat "Node has no " (capitalize (or errorname name)))))
  339.    (goto-char (match-end 0))
  340.    (Info-following-node-name)))
  341.  
  342. (defun Info-following-node-name (&optional allowedchars)
  343.   (skip-chars-forward " \t")
  344.   (buffer-substring
  345.    (point)
  346.    (progn
  347.      (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
  348.        (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
  349.        (if (looking-at "(")
  350.        (skip-chars-forward "^)")))
  351.      (skip-chars-backward " ")
  352.      (point))))
  353.  
  354. (defun Info-next ()
  355.   "Go to the next node of this node."
  356.   (interactive)
  357.   (Info-goto-node (Info-extract-pointer "next")))
  358.  
  359. (defun Info-prev ()
  360.   "Go to the previous node of this node."
  361.   (interactive)
  362.   (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
  363.  
  364. (defun Info-up ()
  365.   "Go to the superior node of this node."
  366.   (interactive)
  367.   (Info-goto-node (Info-extract-pointer "up")))
  368.  
  369. (defun Info-last ()
  370.   "Go back to the last node visited."
  371.   (interactive)
  372.   (or Info-history
  373.       (error "This is the first Info node you looked at"))
  374.   (let (filename nodename opoint)
  375.     (setq filename (car (car Info-history)))
  376.     (setq nodename (car (cdr (car Info-history))))
  377.     (setq opoint (car (cdr (cdr (car Info-history)))))
  378.     (setq Info-history (cdr Info-history))
  379.     (Info-find-node filename nodename)
  380.     (setq Info-history (cdr Info-history))
  381.     (goto-char opoint)))
  382.  
  383. (defun Info-directory ()
  384.   "Go to the Info directory node."
  385.   (interactive)
  386.   (Info-find-node "dir" "top"))
  387.  
  388. (defun Info-follow-reference (footnotename)
  389.   "Follow cross reference named NAME to the node it refers to.
  390. NAME may be an abbreviation of the reference name."
  391.   (interactive
  392.    (let ((completion-ignore-case t)
  393.      completions str i)
  394.      (save-excursion
  395.        (goto-char (point-min))
  396.        (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
  397.      (setq str (buffer-substring
  398.             (match-beginning 1)
  399.             (1- (point))))
  400.      (setq i 0)
  401.      (while (setq i (string-match "[ \n\t]+" str i))
  402.        (setq str (concat (substring str 0 i) " "
  403.                  (substring str (match-end 0))))
  404.        (setq i (1+ i)))
  405.      (setq completions
  406.            (cons (cons str nil)
  407.              completions))))
  408.      (if completions
  409.      (list (completing-read "Follow reference named: " completions nil t))
  410.        (error "No cross-references in this node"))))
  411.   (let (target beg i (str (concat "\\*note " footnotename)))
  412.     (while (setq i (string-match " " str i))
  413.       (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
  414.       (setq i (+ i 6)))
  415.     (save-excursion
  416.       (goto-char (point-min))
  417.       (or (re-search-forward str nil t)
  418.       (error "No cross-reference named %s" footnotename))
  419.       (goto-char (+ (match-beginning 0) 5))
  420.       (setq target (Info-extract-menu-node-name "Bad format cross reference")))
  421.     (while (setq i (string-match "[ \t\n]+" target i))
  422.       (setq target (concat (substring target 0 i) " "
  423.                (substring target (match-end 0))))
  424.       (setq i (+ i 1)))
  425.     (Info-goto-node target)))
  426.  
  427. (defun Info-extract-menu-node-name (&optional errmessage)
  428.   (skip-chars-forward " \t\n")
  429.   (let ((beg (point))
  430.     str i)
  431.     (skip-chars-forward "^:")
  432.     (forward-char 1)
  433.     (setq str
  434.       (if (looking-at ":")
  435.           (buffer-substring beg (1- (point)))
  436.         (Info-following-node-name "^.,\t\n")))
  437.     (while (setq i (string-match "\n" str i))
  438.       (aset str i ?\ ))
  439.     str))
  440.  
  441. (defun Info-menu-item-sequence (list)
  442.   (while list
  443.     (Info-menu-item (car list))
  444.     (setq list (cdr list))))
  445.  
  446. (defun Info-menu (menu-item)
  447.   "Go to node for menu item named (or abbreviated) NAME."
  448.   (interactive
  449.    (let ((completions '())
  450.      ;; If point is within a menu item, use that item as the default
  451.      (default nil)
  452.      (p (point))
  453.      (last nil))
  454.      (save-excursion
  455.        (goto-char (point-min))
  456.        (if (not (search-forward "\n* menu:" nil t))
  457.        (error "No menu in this node"))
  458.        (while (re-search-forward
  459.         "\n\\* \\([^:\t\n]*\\):" nil t)
  460.      (if (and (null default)
  461.           (prog1 (if last (< last p) nil)
  462.             (setq last (match-beginning 0)))
  463.           (<= p last))
  464.          (setq default (car (car completions))))
  465.      (setq completions (cons (cons (buffer-substring
  466.                      (match-beginning 1)
  467.                      (match-end 1))
  468.                        (match-beginning 1))
  469.                  completions)))
  470.        (if (and (null default) last
  471.         (< last p)
  472.         (<= p (progn (end-of-line) (point))))
  473.        (setq default (car (car completions)))))
  474.      (let ((item nil))
  475.        (while (null item)
  476.      (setq item (let ((completion-ignore-case t))
  477.               (completing-read (if default
  478.                        (format "Menu item (default %s): "
  479.                            default)
  480.                        "Menu item: ")
  481.                        completions nil t)))
  482.      ;; we rely on the bug (which RMS won't change for his own reasons)
  483.      ;; that ;; completing-read accepts an input of "" even when the
  484.      ;; require-match argument is true and "" is not a valid possibility
  485.      (if (string= item "")
  486.          (if default
  487.          (setq item default)
  488.              ;; ask again
  489.              (setq item nil))))
  490.        (list item))))
  491.   (Info-goto-node (Info-extract-menu-item menu-item)))
  492.   
  493. (defun Info-extract-menu-item (menu-item)
  494.   (save-excursion
  495.     (goto-char (point-min))
  496.     (or (search-forward "\n* menu:" nil t)
  497.     (error "No menu in this node"))
  498.     (or (search-forward (concat "\n* " menu-item) nil t)
  499.     (error "No such item in menu"))
  500.     (beginning-of-line)
  501.     (forward-char 2)
  502.     (Info-extract-menu-node-name)))
  503.  
  504. (defun Info-extract-menu-counting (count)
  505.   (save-excursion
  506.     (goto-char (point-min))
  507.     (or (search-forward "\n* menu:" nil t)
  508.     (error "No menu in this node"))
  509.     (or (search-forward "\n* " nil t count)
  510.     (error "Too few items in menu"))
  511.     (Info-extract-menu-node-name)))
  512.  
  513. (defun Info-first-menu-item ()
  514.   "Go to the node of the first menu item."
  515.   (interactive)
  516.   (Info-goto-node (Info-extract-menu-counting 1)))
  517.  
  518. (defun Info-second-menu-item ()
  519.   "Go to the node of the second menu item."
  520.   (interactive)
  521.   (Info-goto-node (Info-extract-menu-counting 2)))
  522.  
  523. (defun Info-third-menu-item ()
  524.   "Go to the node of the third menu item."
  525.   (interactive)
  526.   (Info-goto-node (Info-extract-menu-counting 3)))
  527.  
  528. (defun Info-fourth-menu-item ()
  529.   "Go to the node of the fourth menu item."
  530.   (interactive)
  531.   (Info-goto-node (Info-extract-menu-counting 4)))
  532.  
  533. (defun Info-fifth-menu-item ()
  534.   "Go to the node of the fifth menu item."
  535.   (interactive)
  536.   (Info-goto-node (Info-extract-menu-counting 5)))
  537.  
  538. (defun Info-exit ()
  539.   "Exit Info by selecting some other buffer."
  540.   (interactive)
  541.   (switch-to-buffer (prog1 (other-buffer (current-buffer))
  542.                (bury-buffer (current-buffer)))))
  543.  
  544. (defun Info-undefined ()
  545.   "Make command be undefined in Info."
  546.   (interactive)
  547.   (ding))
  548.  
  549. (defun Info-help ()
  550.   "Enter the Info tutorial."
  551.   (interactive)
  552.   (Info-find-node "info"
  553.           (if (< (window-height) 23)
  554.               "Help-Small-Screen"
  555.             "Help")))
  556.  
  557. (defun Info-summary ()
  558.   "Display a brief summary of all Info commands."
  559.   (interactive)
  560.   (save-window-excursion
  561.     (switch-to-buffer "*Help*")
  562.     (erase-buffer)
  563.     (insert (documentation 'Info-mode))
  564.     (goto-char (point-min))
  565.     (let (ch flag)
  566.       (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
  567.             (message (if flag "Type Space to see more"
  568.                    "Type Space to return to Info"))
  569.             (if (/= ?\  (setq ch (read-char)))
  570.             (progn (setq unread-command-char ch) nil)
  571.               flag))
  572.     (scroll-up)))))
  573.  
  574. (defvar Info-mode-map nil
  575.   "Keymap containing Info commands.")
  576. (if Info-mode-map
  577.     nil
  578.   (setq Info-mode-map (make-keymap))
  579.   (suppress-keymap Info-mode-map)
  580.   (define-key Info-mode-map "." 'beginning-of-buffer)
  581.   (define-key Info-mode-map " " 'scroll-up)
  582.   (define-key Info-mode-map "1" 'Info-first-menu-item)
  583.   (define-key Info-mode-map "2" 'Info-second-menu-item)
  584.   (define-key Info-mode-map "3" 'Info-third-menu-item)
  585.   (define-key Info-mode-map "4" 'Info-fourth-menu-item)
  586.   (define-key Info-mode-map "5" 'Info-fifth-menu-item)
  587.   (define-key Info-mode-map "6" 'undefined)
  588.   (define-key Info-mode-map "7" 'undefined)
  589.   (define-key Info-mode-map "8" 'undefined)
  590.   (define-key Info-mode-map "9" 'undefined)
  591.   (define-key Info-mode-map "0" 'undefined)
  592.   (define-key Info-mode-map "?" 'Info-summary)
  593.   (define-key Info-mode-map "b" 'beginning-of-buffer)
  594.   (define-key Info-mode-map "d" 'Info-directory)
  595.   (define-key Info-mode-map "e" 'Info-edit)
  596.   (define-key Info-mode-map "f" 'Info-follow-reference)
  597.   (define-key Info-mode-map "g" 'Info-goto-node)
  598.   (define-key Info-mode-map "h" 'Info-help)
  599.   (define-key Info-mode-map "l" 'Info-last)
  600.   (define-key Info-mode-map "m" 'Info-menu)
  601.   (define-key Info-mode-map "n" 'Info-next)
  602.   (define-key Info-mode-map "p" 'Info-prev)
  603.   (define-key Info-mode-map "q" 'Info-exit)
  604.   (define-key Info-mode-map "s" 'Info-search)
  605.   (define-key Info-mode-map "u" 'Info-up)
  606.   (define-key Info-mode-map "\177" 'scroll-down))
  607.  
  608. (defun Info-mode ()
  609.   "Info mode provides commands for browsing through the Info documentation tree.
  610. Documentation in Info is divided into \"nodes\", each of which
  611. discusses one topic and contains references to other nodes
  612. which discuss related topics.  Info has commands to follow
  613. the references and show you other nodes.
  614.  
  615. h    Invoke the Info tutorial.
  616.  
  617. Selecting other nodes:
  618. n    Move to the \"next\" node of this node.
  619. p    Move to the \"previous\" node of this node.
  620. u    Move \"up\" from this node.
  621. m    Pick menu item specified by name (or abbreviation).
  622.     Picking a menu item causes another node to be selected.
  623. f    Follow a cross reference.  Reads name of reference.
  624. l    Move to the last node you were at.
  625.  
  626. Moving within a node:
  627. Space    scroll forward a page.     DEL  scroll backward.
  628. b    Go to beginning of node.
  629.  
  630. Advanced commands:
  631. q    Quit Info: reselect previously selected buffer.
  632. e    Edit contents of selected node.
  633. 1    Pick first item in node's menu.
  634. 2, 3, 4, 5   Pick second ... fifth item in node's menu.
  635. g    Move to node specified by name.
  636.     You may include a filename as well, as (FILENAME)NODENAME.
  637. s    Search through this Info file for specified regexp,
  638.     and select the node in which the next occurrence is found."
  639.   (kill-all-local-variables)
  640.   (setq major-mode 'Info-mode)
  641.   (setq mode-name "Info")
  642.   (use-local-map Info-mode-map)
  643.   (set-syntax-table text-mode-syntax-table)
  644.   (setq local-abbrev-table text-mode-abbrev-table)
  645.   (setq case-fold-search t)
  646.   (setq buffer-read-only t)
  647.   (make-local-variable 'Info-current-file)
  648.   (make-local-variable 'Info-current-subfile)
  649.   (make-local-variable 'Info-current-node)
  650.   (make-local-variable 'Info-tag-table-marker)
  651.   (make-local-variable 'Info-history)
  652.   (Info-set-mode-line))
  653.  
  654. (defvar Info-edit-map nil
  655.   "Local keymap used within `e' command of Info.")
  656. (if Info-edit-map
  657.     nil
  658.   (setq Info-edit-map (copy-keymap text-mode-map))
  659.   (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
  660.  
  661. (defun Info-edit-mode ()
  662.   "Major mode for editing the contents of an Info node.
  663. Like text mode with the addition of Info-cease-edit
  664. which returns to Info mode for browsing.
  665. \\{Info-edit-map}"
  666.   )
  667.  
  668. (defun Info-edit ()
  669.   "Edit the contents of this Info node.
  670. Allowed only if variable Info-enable-edit is non-nil."
  671.   (interactive)
  672.   (or Info-enable-edit
  673.       (error "Editing info nodes is not enabled"))
  674.   (use-local-map Info-edit-map)
  675.   (setq major-mode 'Info-edit-mode)
  676.   (setq mode-name "Info Edit")
  677.   (kill-local-variable 'mode-line-buffer-identification)
  678.   (setq buffer-read-only nil)
  679.   ;; Make mode line update.
  680.   (set-buffer-modified-p (buffer-modified-p))
  681.   (message (substitute-command-keys
  682.          "Editing: Type \\[Info-cease-edit] to return to info")))
  683.  
  684. (defun Info-cease-edit ()
  685.   "Finish editing Info node; switch back to Info proper."
  686.   (interactive)
  687.   ;; Do this first, so nothing has changed if user C-g's at query.
  688.   (and (buffer-modified-p)
  689.        (y-or-n-p "Save the file? ")
  690.        (save-buffer))
  691.   (use-local-map Info-mode-map)
  692.   (setq major-mode 'Info-mode)
  693.   (setq mode-name "Info")
  694.   (Info-set-mode-line)
  695.   (setq buffer-read-only t)
  696.   ;; Make mode line update.
  697.   (set-buffer-modified-p (buffer-modified-p))
  698.   (and (marker-position Info-tag-table-marker)
  699.        (buffer-modified-p)
  700.        (message "Tags may have changed.  Use Info-tagify if necessary")))
  701.