home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / info-Z.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  25.9 KB  |  774 lines

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