home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / info.el < prev    next >
Encoding:
Text File  |  1993-03-26  |  66.6 KB  |  1,902 lines

  1. ;; Info package for Emacs  --  Dave Gillespie's version 1.04 of 3/4/92.
  2. ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 1, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. ;; This is based on the version 19 info.el file.
  22. ;;
  23. ;; Note that Info-directory has been replaced by Info-directory-list,
  24. ;; a search path of directories in which to find Info files.
  25. ;; Also, Info tries adding ".info" to a file name if the name itself
  26. ;; is not found.
  27. ;;
  28. ;; This file also has several small bug fixes compared to the 18.57 version.
  29.  
  30.  
  31. ;; LCD Archive Entry:
  32. ;; info-dg|Dave Gillespie|daveg@synaptics.com
  33. ;; |Info reader with many enhancements; replaces standard info.el.
  34. ;; |92-03-04|1.04|~/modes/info.el
  35.  
  36. ;; Also available from anonymous FTP on csvax.cs.caltech.edu.
  37.  
  38.  
  39. ;; Modified 3/7/1991 by Dave Gillespie:
  40. ;; (Author's address: daveg@synaptics.com or daveg@csvax.cs.caltech.edu)
  41. ;;
  42. ;; Added keys:  i, t, <, >, [, ], {, }, 6, 7, 8, 9, 0.
  43. ;; Look at help for info-mode (type ? in Info) for descriptions.
  44. ;;
  45. ;; If Info-directory-list is undefined and there is no INFOPATH
  46. ;; in the environment, use value of Info-directory for compatibility
  47. ;; with Emacs 18.57.
  48. ;;
  49. ;; All files named "localdir" found in the path are appended to "dir",
  50. ;; the Info directory.  For this to work, "dir" should contain only
  51. ;; one node (Top), and each "localdir" should contain no ^_ or ^L
  52. ;; characters.  Generally they will contain only one or several
  53. ;; additional lines for the top-level menu.  Note that "dir" is
  54. ;; modified in memory each time it is loaded, but not on disk.
  55. ;;
  56. ;; If "dir" contains a line of the form:  "* Locals:"
  57. ;; then the "localdir"s are inserted there instead of at the end.
  58.  
  59.  
  60. ;; Modified 4/3/1991 by Dave Gillespie:
  61. ;;
  62. ;; Added Info-mode-hook (suggested by Sebastian Kremer).
  63. ;; Also added epoch-info-startup/select-hooks from Simon Spero's info.el.
  64. ;;
  65. ;; Added automatic decoding of compressed Info files.
  66. ;; See documentation for the variable Info-suffix-list.  Default is to
  67. ;; run "uncompress" on ".Z" files and "unyabba" on ".Y" files.
  68. ;; (See comp.sources.unix v24i073-076 for yabba/unyabba, a free software
  69. ;; alternative to compress/uncompress.)
  70. ;; Note: "dir" and "localdir" files should not be compressed.
  71. ;;
  72. ;; Changed variables like Info-enable-edit to be settable by M-x set-variable.
  73. ;;
  74. ;; Added Info-auto-advance variable.  If t, SPC and DEL will act like
  75. ;; } and {, i.e., they advance to the next/previous node if at the end
  76. ;; of the buffer.
  77. ;;
  78. ;; Changed `u' to restore point to most recent location in that node.
  79. ;; Added `=' to do this manually at any time.  (Suggested by David Fox).
  80. ;;
  81. ;; Changed `m' and `0-9' to try interpreting menu name as a file name
  82. ;; if not found as a node name.  This allows (dir) menus of the form,
  83. ;;     Emacs::        Cool text editor
  84. ;; as a shorthand for
  85. ;;     Emacs:(emacs).    Cool text editor
  86. ;;
  87. ;; Enhanced `i' to use line-number information in the index.
  88. ;; Added `,' to move among all matches to a previous `i' command.
  89. ;;
  90. ;; Added `a' (Info-annotate) for adding personal notes to any Info node.
  91. ;; Notes are not stored in the actual Info files, but in the user's own
  92. ;; ~/.infonotes file.
  93. ;;
  94. ;; Added Info-footnote-tag, made default be "Ref" instead of "Note".
  95. ;;
  96. ;; Got mouse-click stuff to work under Emacs version 18.  Check it out!
  97. ;; Left and right clicks scroll the Info window.
  98. ;; Middle click goes to clicked-on node, e.g., "Next:", a menu, or a note.
  99.  
  100.  
  101. ;; Modified 6/29/1991 by Dave Gillespie:
  102. ;;
  103. ;; Renamed epoch-info-startup/select-hooks to Info-startup/select-hook.
  104. ;;
  105. ;; Made Info-select-node into a command on the `!' key.
  106. ;;
  107. ;; Added Info-mouse-support user option.
  108. ;;
  109. ;; Cleaned up the implementation of some routines.
  110. ;;
  111. ;; Added special treatment of quoted words in annotations:  The `g'
  112. ;; command for a nonexistent node name scans for an annotation
  113. ;; (in any node of any file) containing that name in quotes:  g foo RET
  114. ;; looks for an annotation containing:  "foo"
  115. ;; If found, it goes to that file and node.
  116. ;;
  117. ;; Added a call to set up Info-directory-list in Info-find-node to
  118. ;; work around a bug in GNUS where it calls Info-goto-node before info.
  119. ;;
  120. ;; Added completion for `g' command (inspired by Richard Kim's infox.el).
  121. ;; Completion knows all node names for the current file, and all annotation
  122. ;; tags (see above).  It does not complete file names or node names in
  123. ;; other files.
  124. ;;
  125. ;; Added `k' (Info-emacs-key) and `*' (Info-elisp-ref) commands.  You may
  126. ;; wish to bind these to global keys outside of Info mode.
  127. ;;
  128. ;; Allowed localdir files to be full dir-like files; only the menu part
  129. ;; of each localdir is copied.  Also, redundant menu items are omitted.
  130. ;;
  131. ;; Changed Info-history to hold only one entry at a time for each node,
  132. ;; and to be circular so that multiple `l's come back again to the most
  133. ;; recent node.  Note that the format of Info-history entries has changed,
  134. ;; which may interfere with external programs that try to operate on it.
  135. ;; (Also inspired by Kim's infox.el).
  136. ;;
  137. ;; Changed `n', `]', `l', etc. to accept prefix arguments to move several
  138. ;; steps at once.  Most accept negative arguments to move oppositely.
  139. ;;
  140. ;; Changed `?' to bury *Help* buffer afterwards to keep it out of the way.
  141. ;;
  142. ;; Rearranged `?' key's display to be a little better for new users.
  143. ;;
  144. ;; Changed `a' to save whole window configuration and restore on C-c C-c.
  145. ;;
  146. ;; Fixed the bug reported by Bill Reynolds on gnu.emacs.bugs.
  147. ;;
  148. ;; Changed Info-last to restore window-start as well as cursor position.
  149. ;;
  150. ;; Changed middle mouse button in space after end of node to do Info-last
  151. ;; if we got here by following a cross reference, else do Info-global-next.
  152. ;;
  153. ;; Added some new mouse bindings: shift-left = Info-global-next,
  154. ;; shift-right = Info-global-prev, shift-middle = Info-last.
  155. ;;
  156. ;; Fixed Info-follow-reference not to make assumptions about length
  157. ;; of Info-footnote-tag [Linus Tolke].
  158. ;;
  159. ;; Changed default for Info-auto-advance mode to be press-twice-for-next-node.
  160. ;;
  161. ;; Modified x-mouse-ignore to preserve last-command variable, so that
  162. ;; press-twice Info-auto-advance mode works with the mouse.
  163.  
  164.  
  165. ;; Modified 3/4/1992 by Dave Gillespie:
  166. ;;
  167. ;; Added an "autoload" command to help autoload.el.
  168. ;;
  169. ;; Changed `*' command to look for file `elisp' as well as for `lispref'.
  170. ;;
  171. ;; Fixed a bug involving footnote names containing regexp special characters.
  172. ;;
  173. ;; Fixed a bug in completion during `f' (or `r') command.
  174. ;;
  175. ;; Added TAB (Info-next-reference), M-TAB, and RET keys to Info mode.
  176. ;;
  177. ;; Added new bindings, `C-h C-k' for Info-emacs-key and `C-h C-f' for
  178. ;; Info-elisp-ref.  These bindings are made when info.el is loaded, and
  179. ;; only if those key sequences were previously unbound.  These bindings
  180. ;; work at any time, not just when Info is already running.
  181.  
  182.  
  183.  
  184. (provide 'info)
  185.  
  186. (defvar Info-mouse-support t
  187.   "*Non-nil means to install Info mouse drivers for Emacs version 18.
  188. Set this to nil if you have your own Info mouse support.")
  189.  
  190. (defvar Info-history nil
  191.   "List of info nodes user has visited.
  192. Each element of list is a list (\"(FILENAME)NODENAME\" BUFPOS WINSTART).")
  193.  
  194. (defvar Info-keeping-history t
  195.   "Non-nil if Info-find-node should modify Info-history.
  196. This is for use only by certain internal Info routines.")
  197.  
  198. (defvar Info-enable-edit nil
  199.   "*Non-nil means the \\[Info-edit] command in Info can edit the current node.")
  200.  
  201. (defvar Info-enable-active-nodes t
  202.   "*Non-nil allows Info to execute Lisp code associated with nodes.
  203. The Lisp code is executed when the node is selected.")
  204.  
  205. (defvar Info-restoring-point t
  206.   "*Non-nil means to restore the cursor position when re-entering a node.")
  207.  
  208. (defvar Info-auto-advance 'twice
  209.   "*Control what SPC and DEL do when they can't scroll any further.
  210. If nil, they beep and remain in the current node.
  211. If t, they move to the next node (like Info-global-next/prev).
  212. If anything else, they must be pressed twice to move to the next node.")
  213.  
  214. (defvar Info-directory-list (getenv "INFOPATH")
  215.   "List of directories to search for Info documentation files.
  216. Default is to use the environment variable INFOPATH if it exists,
  217. else to use Info-directory if it exists.")
  218.  
  219. (defvar Info-suffix-list '( (".info" . nil)
  220.                 (".Z" . "uncompress -c %s")
  221.                 (".Y" . "unyabba")
  222.                 (".info.Z" . "uncompress -c %s")
  223.                 (".info.Y" . "unyabba") )
  224.   "List of file name suffixes and associated decoding commands.
  225. Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
  226. changed to name of the file to decode, otherwise the file is given to
  227. the command as standard input.  If STRING is nil, no decoding is done.")
  228.  
  229. (defvar Info-footnote-tag "Ref"
  230.   "*Symbol that identifies a footnote or cross-reference.
  231. All \"*Note\" references will be changed to use this word instead.")
  232.  
  233. (defvar Info-current-file nil
  234.   "Info file that Info is now looking at, or nil.")
  235.  
  236. (defvar Info-current-subfile nil
  237.   "Info subfile that is actually in the *info* buffer now,
  238. or nil if current info file is not split into subfiles.")
  239.  
  240. (defvar Info-current-node nil
  241.   "Name of node that Info is now looking at, or nil.")
  242.  
  243. (defvar Info-tag-table-marker (make-marker)
  244.   "Marker pointing at beginning of current Info file's tag table.
  245. Marker points nowhere if file has no tag table.")
  246.  
  247. (defvar Info-current-file-completions nil
  248.   "Cached completion list for current Info file.")
  249.  
  250. (defvar Info-index-alternatives nil
  251.   "List of possible matches for last Info-index command.")
  252.  
  253. (defvar Info-annotations-path '("~/.infonotes" "/usr/lib/info.notes")
  254.   "*Names of files that contain annotations for different Info nodes.
  255. By convention, the first one should reside in your personal directory.
  256. The last should be a world-writable \"public\" annotations file.")
  257.  
  258. (defvar Info-in-cross-reference nil)
  259. (defvar Info-window-configuration nil)
  260.  
  261. ;;;###autoload
  262. (defun info (&optional file)
  263.   "Enter Info, the documentation browser.
  264. Optional argument FILE specifies the file to examine;
  265. the default is the top-level directory of Info.
  266.  
  267. In interactive use, a prefix argument directs this command
  268. to read a file name from the minibuffer."
  269.   (interactive (if current-prefix-arg
  270.            (list (read-file-name "Info file name: " nil nil t))))
  271.   (Info-find-directory-list)
  272.   (Info-setup-x)
  273.   (if file
  274.       (Info-goto-node (concat "(" file ")"))
  275.     (if (get-buffer "*info*")
  276.     (switch-to-buffer "*info*")
  277.       (let ((f Info-annotations-path))
  278.     (while f
  279.       (if (file-exists-p (car f))
  280.           (bury-buffer (find-file-noselect (car f))))
  281.       (setq f (cdr f))))
  282.       (Info-directory))))
  283.  
  284. (defun Info-find-directory-list ()
  285.   (if (stringp Info-directory-list)
  286.       (let ((path Info-directory-list)
  287.         list)
  288.     (while (> (length path) 0)
  289.       (let ((idx (or (string-match ":" path) (length path))))
  290.         (setq list (cons (substring path 0 idx) list)
  291.           path (substring path (min (1+ idx) (length path))))))
  292.     (setq Info-directory-list (nreverse list))))
  293.   (or Info-directory-list
  294.       (setq Info-directory-list (list (if (boundp 'Info-directory)
  295.                       Info-directory
  296.                     ".")))))
  297. (Info-find-directory-list)
  298.  
  299. ;; Go to an info node specified as separate filename and nodename.
  300. ;; no-going-back is non-nil if recovering from an error in this function;
  301. ;; it says do not attempt further (recursive) error recovery.
  302. (defun Info-find-node (filename nodename &optional no-going-back tryfile line)
  303.   ;; Convert filename to lower case if not found as specified.
  304.   ;; Expand it.
  305.   (if filename
  306.       (let (temp temp-downcase found)
  307.     (setq filename (substitute-in-file-name filename))
  308.     (let ((dirs (if (string-match "^\\./" filename)
  309.             ;; If specified name starts with `./'
  310.             ;; then just try current directory.
  311.             '("./")
  312.               Info-directory-list)))
  313.       ;; Search the directory list for file FILENAME.
  314.       (while (and dirs (not found))
  315.         (setq temp (expand-file-name filename (car dirs)))
  316.         (setq temp-downcase
  317.           (expand-file-name (downcase filename) (car dirs)))
  318.         (if (equal temp-downcase temp) (setq temp-downcase nil))
  319.         ;; Try several variants of specified name.
  320.         ;; Try downcasing, appending a suffix, or both.
  321.         (setq found (Info-suffixed-file temp temp-downcase))
  322.         (setq dirs (cdr dirs))))
  323.     (if found
  324.         (setq filename found)
  325.       (error "Info file %s does not exist" filename))))
  326.   ;; Go into info buffer.
  327.   (switch-to-buffer "*info*")
  328.   (run-hooks 'Info-startup-hook)
  329.   (or (eq major-mode 'Info-mode)
  330.       (Info-mode))
  331.   ;; Record the node we are leaving.
  332.   (if (and Info-current-file (not no-going-back))
  333.       (Info-history-add Info-current-file Info-current-node (point)))
  334.   (widen)
  335.   (setq Info-current-node nil
  336.     Info-in-cross-reference nil)
  337.   (unwind-protect
  338.       (progn
  339.     ;; Switch files if necessary
  340.     (or (null filename)
  341.         (equal Info-current-file filename)
  342.         (let ((buffer-read-only nil))
  343.           (setq Info-current-file nil
  344.             Info-current-subfile nil
  345.             Info-index-alternatives nil
  346.             Info-current-file-completions nil
  347.             buffer-file-name nil)
  348.           (erase-buffer)
  349.           (Info-insert-file-contents filename t)
  350.           ;; Add all "localdir" files in search path to "dir" file.
  351.           (if (string-match "^dir$" (file-name-nondirectory filename))
  352.           (let ((d Info-directory-list)
  353.             name)
  354.             (goto-char (point-max))
  355.             (if (re-search-backward "^ *\\* *Locals *: *\n" nil t)
  356.             (delete-region (match-beginning 0) (match-end 0))
  357.               (search-backward "\^L" nil t))
  358.             (while d
  359.               (setq name (expand-file-name "localdir" (car d)))
  360.               (if (or (file-exists-p name)
  361.                   (file-exists-p
  362.                    (setq name (concat name ".info"))))
  363.               ;; Insert menu part of the file
  364.               (let* ((pt (point))
  365.                  (len (nth 1 (insert-file-contents name))))
  366.                 (if (search-forward "* menu:" (+ pt len) t)
  367.                 (progn
  368.                   (forward-line 1)
  369.                   (delete-region pt (point))))))
  370.               (setq d (cdr d)))
  371.             ;; Eliminate redundant menu entries.
  372.             (goto-char (point-min))
  373.             (while (re-search-forward "\n\\* \\([^:\n]*\\):" nil t)
  374.               (let ((str (buffer-substring (match-beginning 1)
  375.                            (match-end 1))))
  376.             (save-excursion
  377.               (if (search-forward (format "\n* %s:" str) nil t)
  378.                   (let ((pt (- (point) 3 (length str))))
  379.                 (forward-line 1)
  380.                 (delete-region pt (point)))))))))
  381.           (set-buffer-modified-p nil)
  382.           (setq default-directory (file-name-directory filename))
  383.           ;; See whether file has a tag table.  Record the location if yes.
  384.           (set-marker Info-tag-table-marker nil)
  385.           (goto-char (point-max))
  386.           (forward-line -8)
  387.           (or (equal nodename "*")
  388.           (not (search-forward "\^_\nEnd tag table\n" nil t))
  389.           (let (pos)
  390.             ;; We have a tag table.  Find its beginning.
  391.             ;; Is this an indirect file?
  392.             (search-backward "\nTag table:\n")
  393.             (setq pos (point))
  394.             (if (save-excursion
  395.               (forward-line 2)
  396.               (looking-at "(Indirect)\n"))
  397.             ;; It is indirect.  Copy it to another buffer
  398.             ;; and record that the tag table is in that buffer.
  399.             (save-excursion
  400.               (let ((buf (current-buffer)))
  401.                 (set-buffer (get-buffer-create " *info tag table*"))
  402.                 (setq case-fold-search t)
  403.                 (erase-buffer)
  404.                 (insert-buffer-substring buf)
  405.                 (set-marker Info-tag-table-marker
  406.                     (match-end 0))))
  407.              (set-marker Info-tag-table-marker pos))))
  408.           (setq Info-current-file
  409.             (file-name-sans-versions buffer-file-name))))
  410.     (if (equal nodename "*")
  411.         (progn (setq Info-current-node nodename)
  412.            (Info-set-mode-line)
  413.            (goto-char (point-min)))
  414.       ;; Search file for a suitable node.
  415.       ;; First get advice from tag table if file has one.
  416.       ;; Also, if this is an indirect info file,
  417.       ;; read the proper subfile into this buffer.
  418.       (let ((guesspos (point-min)))
  419.         (if (marker-position Info-tag-table-marker)
  420.         (save-excursion
  421.           (set-buffer (marker-buffer Info-tag-table-marker))
  422.           (goto-char Info-tag-table-marker)
  423.           (if (search-forward (concat "Node: " nodename "\177") nil t)
  424.               (progn
  425.             (setq guesspos (read (current-buffer)))
  426.             ;; If this is an indirect file,
  427.             ;; determine which file really holds this node
  428.             ;; and read it in.
  429.             (if (not (eq (current-buffer) (get-buffer "*info*")))
  430.                 (setq guesspos
  431.                   (Info-read-subfile guesspos)))))))
  432.         (goto-char (max (point-min) (- guesspos 1000))))
  433.       ;; Now search from our advised position (or from beg of buffer)
  434.       ;; to find the actual node.
  435.       (let ((regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n]"))
  436.         (found t))
  437.         (catch 'foo
  438.           (while (search-forward "\n\^_" nil t)
  439.         (forward-line 1)
  440.         (let ((beg (point)))
  441.           (forward-line 1)
  442.           (if (re-search-backward regexp beg t)
  443.               (throw 'foo t))))
  444.           (setq found nil)
  445.           (let ((bufs (delq nil (mapcar 'get-file-buffer
  446.                         Info-annotations-path)))
  447.             (pattern (concat "\"" nodename "\""))
  448.             (afile nil) anode aline)
  449.         (while (and bufs (not anode))
  450.           (save-excursion
  451.             (set-buffer (car bufs))
  452.             (goto-char (point-min))
  453.             (if (search-forward pattern nil t)
  454.             (if (re-search-backward
  455.                  "------ *File: *\\([^ ].*[^ ]\\) *Node: *\\([^ ].*[^ ]\\) *Line: *\\([0-9]+\\)"
  456.                  nil t)
  457.                 (setq afile
  458.                   (buffer-substring (match-beginning 1)
  459.                             (match-end 1))
  460.                   anode
  461.                   (buffer-substring (match-beginning 2)
  462.                             (match-end 2))
  463.                   aline
  464.                   (string-to-int
  465.                    (buffer-substring (match-beginning 3)
  466.                              (match-end 3)))))))
  467.           (setq bufs (cdr bufs)))
  468.         (if anode
  469.             (Info-find-node afile anode t nil aline)
  470.           (if tryfile
  471.               (condition-case err
  472.               (Info-find-node nodename "Top" t)
  473.             (error nil)))))
  474.           (or Info-current-node
  475.           (error "No such node: %s" nodename)))
  476.         (if found
  477.         (progn
  478.           (Info-select-node)
  479.           (goto-char (point-min))
  480.           (if line (forward-line line)))))))
  481.     ;; If we did not finish finding the specified node,
  482.     ;; go back to the previous one.
  483.     (or Info-current-node no-going-back
  484.     (let ((hist (car Info-history)))
  485.       ;; The following is no longer safe with new Info-history system
  486.       ;; (setq Info-history (cdr Info-history))
  487.       (Info-goto-node (car hist) t)
  488.       (goto-char (nth 1 hist))))))
  489.  
  490. (defun Info-history-add (file node point)
  491.   (if Info-keeping-history
  492.       (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
  493.          (found (assoc name Info-history)))
  494.     (if found
  495.         (setq Info-history (delq found Info-history)))
  496.     (setq Info-history (cons (list name point
  497.                        (and (eq (window-buffer)
  498.                         (current-buffer))
  499.                         (window-start)))
  500.                  Info-history)))))
  501.  
  502. (defun Info-file-name-only (file)
  503.   (let ((dir (file-name-directory file))
  504.     (p Info-directory-list))
  505.     (while (and p (not (equal (car p) dir)))
  506.       (setq p (cdr p)))
  507.     (if p (file-name-nondirectory file) file)))
  508.  
  509. (defun Info-read-subfile (nodepos)
  510.   (set-buffer (marker-buffer Info-tag-table-marker))
  511.   (goto-char (point-min))
  512.   (search-forward "\n\^_")
  513.   (let (lastfilepos
  514.     lastfilename)
  515.     (forward-line 2)
  516.     (catch 'foo
  517.       (while (not (looking-at "\^_"))
  518.     (if (not (eolp))
  519.         (let ((beg (point))
  520.           thisfilepos thisfilename)
  521.           (search-forward ": ")
  522.           (setq thisfilename  (buffer-substring beg (- (point) 2)))
  523.           (setq thisfilepos (read (current-buffer)))
  524.           ;; read in version 19 stops at the end of number.
  525.           ;; Advance to the next line.
  526.           ;; (forward-line 1)
  527.           (if (> thisfilepos nodepos)
  528.           (throw 'foo t))
  529.           (setq lastfilename thisfilename)
  530.           (setq lastfilepos thisfilepos))
  531.       (throw 'foo t))))
  532.     (set-buffer (get-buffer "*info*"))
  533.     (or (equal Info-current-subfile lastfilename)
  534.     (let ((buffer-read-only nil))
  535.       (setq buffer-file-name nil)
  536.       (widen)
  537.       (erase-buffer)
  538.       (Info-insert-file-contents (Info-suffixed-file lastfilename))
  539.       (set-buffer-modified-p nil)
  540.       (setq Info-current-subfile lastfilename)))
  541.     (goto-char (point-min))
  542.     (search-forward "\n\^_")
  543.     (+ (- nodepos lastfilepos) (point))))
  544.  
  545. (defun Info-suffixed-file (name &optional name2)
  546.   (cond ((file-exists-p name)
  547.      name)
  548.     ((and name2 (file-exists-p name2))
  549.      name2)
  550.     (t
  551.      (let ((suff Info-suffix-list)
  552.            (found nil))
  553.        (while (and suff (not found))
  554.          (if (file-exists-p (concat name (car (car suff))))
  555.          (setq found (concat name (car (car suff))))
  556.            (if (and name2 (file-exists-p (concat name2 (car (car suff)))))
  557.            (setq found (concat name2 (car (car suff))))
  558.          (setq suff (cdr suff)))))
  559.        found))))
  560.  
  561. (defun Info-insert-file-contents (file &optional visit)
  562.   (let ((suff Info-suffix-list))
  563.     (while (and suff (or (<= (length file) (length (car (car suff))))
  564.              (not (equal (substring file
  565.                         (- (length (car (car suff)))))
  566.                      (car (car suff))))))
  567.       (setq suff (cdr suff)))
  568.     (if (stringp (cdr (car suff)))
  569.     (let ((command (if (string-match "%s" (cdr (car suff)))
  570.                (format (cdr (car suff)) file)
  571.              (concat (cdr (car suff)) " < " file))))
  572.       (message "%s..." command)
  573.       (call-process shell-file-name nil t nil "-c" command)
  574.       (message "")
  575.       (if visit
  576.           (progn
  577.         (setq buffer-file-name file)
  578.         (set-buffer-modified-p nil)
  579.         (clear-visited-file-modtime))))
  580.       (insert-file-contents file visit))))
  581.  
  582. (defun Info-select-node ()
  583.   "Select the node that point is in, after using `g *' to select whole file."
  584.   (interactive)
  585.   (widen)
  586.   (save-excursion
  587.    ;; Find beginning of node.
  588.    (search-backward "\n\^_")
  589.    (forward-line 2)
  590.    ;; Get nodename spelled as it is in the node.
  591.    (re-search-forward "Node:[ \t]*")
  592.    (setq Info-current-node
  593.      (buffer-substring (point)
  594.                (progn
  595.                 (skip-chars-forward "^,\t\n")
  596.                 (point))))
  597.    (Info-set-mode-line)
  598.    ;; Find the end of it, and narrow.
  599.    (beginning-of-line)
  600.    (let (active-expression)
  601.      (narrow-to-region (point)
  602.                (if (re-search-forward "\n[\^_\f]" nil t)
  603.                (prog1
  604.                 (1- (point))
  605.                 (if (looking-at "[\n\^_\f]*execute: ")
  606.                 (progn
  607.                   (goto-char (match-end 0))
  608.                   (setq active-expression
  609.                     (read (current-buffer))))))
  610.              (point-max)))
  611.      (or (equal Info-footnote-tag "Note")
  612.      (progn
  613.        (goto-char (point-min))
  614.        (let ((buffer-read-only nil)
  615.          (bufmod (buffer-modified-p)))
  616.          (while (re-search-forward "\\*Note\\([ \n]\\)" nil t)
  617.            (replace-match (concat "*" Info-footnote-tag "\\1")))
  618.          (set-buffer-modified-p bufmod))))
  619.      (Info-reannotate-node)
  620.      (run-hooks 'Info-select-hook)
  621.      (if Info-enable-active-nodes (eval active-expression)))))
  622.  
  623. (defun Info-set-mode-line ()
  624.   (setq mode-line-buffer-identification
  625.     (concat
  626.      "Info:  ("
  627.      (if Info-current-file
  628.          (file-name-nondirectory Info-current-file)
  629.        "")
  630.      ")"
  631.      (or Info-current-node ""))))
  632.  
  633. ;; Go to an info node specified with a filename-and-nodename string
  634. ;; of the sort that is found in pointers in nodes.
  635.  
  636. (defun Info-goto-node (nodename &optional no-going-back tryfile)
  637.   "Go to info node named NAME.  Give just NODENAME or (FILENAME)NODENAME.
  638. Actually, the following interpretations of NAME are tried in order:
  639.     (FILENAME)NODENAME
  640.     (FILENAME)     (using Top node)
  641.     NODENAME       (in current file)
  642.     TAGNAME        (see below)
  643.     FILENAME       (using Top node)
  644. where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
  645. annotation for any node of any file.  (See `a' for annotations.)"
  646.   (interactive (list (Info-read-node-name "Goto node, file or tag: ")
  647.              nil t))
  648.   (let (filename)
  649.     (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
  650.           nodename)
  651.     (setq filename (if (= (match-beginning 1) (match-end 1))
  652.                ""
  653.              (substring nodename (match-beginning 2) (match-end 2)))
  654.       nodename (substring nodename (match-beginning 3) (match-end 3)))
  655.     (let ((trim (string-match "\\s *\\'" filename)))
  656.       (if trim (setq filename (substring filename 0 trim))))
  657.     (let ((trim (string-match "\\s *\\'" nodename)))
  658.       (if trim (setq nodename (substring nodename 0 trim))))
  659.     (Info-find-node (if (equal filename "") nil filename)
  660.             (if (equal nodename "") "Top" nodename)
  661.             no-going-back (and tryfile (equal filename "")))))
  662.  
  663. (defun Info-restore-point (&optional always)
  664.   "Restore point to same location it had last time we were in this node."
  665.   (interactive "p")
  666.   (if (or Info-restoring-point always)
  667.       (let* ((name (format "(%s)%s"
  668.                (Info-file-name-only Info-current-file)
  669.                Info-current-node))
  670.          (p (assoc name Info-history)))
  671.     (if p (Info-restore-history-entry p)))))
  672.  
  673. (defun Info-restore-history-entry (entry)
  674.   (goto-char (nth 1 entry))
  675.   (and (nth 2 entry)
  676.        (get-buffer-window (current-buffer))
  677.        (set-window-start (get-buffer-window (current-buffer))
  678.              (nth 2 entry))))
  679.  
  680. (defun Info-read-node-name (prompt &optional default)
  681.   (Info-build-node-completions)
  682.   (let* ((completion-ignore-case t)
  683.      (nodename (completing-read prompt Info-current-file-completions)))
  684.     (if (equal nodename "")
  685.     (or default
  686.         (Info-read-node-name prompt))
  687.       nodename)))
  688.  
  689. (defun Info-build-node-completions ()
  690.   (or Info-current-file-completions
  691.       (let ((compl nil))
  692.     (save-excursion
  693.       (save-restriction
  694.         (if (marker-buffer Info-tag-table-marker)
  695.         (progn
  696.           (set-buffer (marker-buffer Info-tag-table-marker))
  697.           (goto-char Info-tag-table-marker)
  698.           (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
  699.             (setq compl
  700.               (cons (list (buffer-substring (match-beginning 1)
  701.                             (match-end 1)))
  702.                 compl))))
  703.           (widen)
  704.           (goto-char (point-min))
  705.           (while (search-forward "\n\^_" nil t)
  706.         (forward-line 1)
  707.         (let ((beg (point)))
  708.           (forward-line 1)
  709.           (if (re-search-backward "Node: *\\(.*\\) *[,\n\t]" beg t)
  710.               (setq compl 
  711.                 (cons (list (buffer-substring (match-beginning 1)
  712.                               (match-end 1)))
  713.                   compl)))))))
  714.       (let ((bufs (delq nil (mapcar 'get-file-buffer
  715.                     Info-annotations-path))))
  716.         (while bufs
  717.           (set-buffer (car bufs))
  718.           (goto-char (point-min))
  719.           (while (re-search-forward "\"\\(.*\\)\"" nil t)
  720.         (setq compl 
  721.               (cons (list (buffer-substring (match-beginning 1)
  722.                             (match-end 1)))
  723.                 compl)))
  724.           (setq bufs (cdr bufs)))))
  725.     (setq Info-current-file-completions compl))))
  726.  
  727. (defvar Info-last-search nil
  728.   "Default regexp for Info S command to search for.")
  729.  
  730. (defun Info-search (regexp)
  731.   "Search for REGEXP, starting from point, and select node it's found in."
  732.   (interactive "sSearch (regexp): ")
  733.   (if (equal regexp "")
  734.       (setq regexp Info-last-search)
  735.     (setq Info-last-search regexp))
  736.   (let ((found ()) current
  737.     (onode Info-current-node)
  738.     (ofile Info-current-file)
  739.     (opoint (point))
  740.     (osubfile Info-current-subfile))
  741.     (save-excursion
  742.       (save-restriction
  743.     (widen)
  744.     (if (null Info-current-subfile)
  745.         (progn (re-search-forward regexp) (setq found (point)))
  746.       (condition-case err
  747.           (progn (re-search-forward regexp) (setq found (point)))
  748.         (search-failed nil)))))
  749.     (if (not found) ;can only happen in subfile case -- else would have erred
  750.     (unwind-protect
  751.         (let ((list ()))
  752.           (set-buffer (marker-buffer Info-tag-table-marker))
  753.           (goto-char (point-min))
  754.           (search-forward "\n\^_\nIndirect:")
  755.           (save-restriction
  756.         (narrow-to-region (point)
  757.                   (progn (search-forward "\n\^_")
  758.                      (1- (point))))
  759.         (goto-char (point-min))
  760.         (search-forward (concat "\n" osubfile ": "))
  761.         (beginning-of-line)
  762.         (while (not (eobp))
  763.           (re-search-forward "\\(^.*\\): [0-9]+$")
  764.           (goto-char (+ (match-end 1) 2))
  765.           (setq list (cons (cons (read (current-buffer))
  766.                      (buffer-substring (match-beginning 1)
  767.                                (match-end 1)))
  768.                    list))
  769.           (goto-char (1+ (match-end 0))))
  770.         (setq list (nreverse list)
  771.               current (car (car list))
  772.               list (cdr list)))
  773.           (while list
  774.         (message "Searching subfile %s..." (cdr (car list)))
  775.         (Info-read-subfile (car (car list)))
  776.         (setq list (cdr list))
  777.         (goto-char (point-min))
  778.         (if (re-search-forward regexp nil t)
  779.             (setq found (point) list ())))
  780.           (if found
  781.           (message "")
  782.         (signal 'search-failed (list regexp))))
  783.       (if (not found)
  784.           (progn (Info-read-subfile opoint)
  785.              (goto-char opoint)
  786.              (Info-select-node)))))
  787.     (widen)
  788.     (goto-char found)
  789.     (Info-select-node)
  790.     (or (and (equal onode Info-current-node)
  791.          (equal ofile Info-current-file))
  792.     (Info-history-add ofile onode opoint))))
  793.  
  794. (defun Info-extract-pointer (name &optional errorname)
  795.   (save-excursion
  796.    (goto-char (point-min))
  797.    (forward-line 1)
  798.    (if (re-search-backward (concat name ":") nil t)
  799.        (progn
  800.      (goto-char (match-end 0))
  801.      (Info-following-node-name))
  802.      (if (eq errorname t)
  803.      nil
  804.        (error (concat "Node has no " (capitalize (or errorname name))))))))
  805.  
  806. (defun Info-following-node-name (&optional allowedchars)
  807.   (skip-chars-forward " \t")
  808.   (buffer-substring
  809.    (point)
  810.    (progn
  811.      (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
  812.        (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
  813.        (if (looking-at "(")
  814.        (skip-chars-forward "^)")))
  815.      (skip-chars-backward " ")
  816.      (point))))
  817.  
  818. (defun Info-next (&optional n)
  819.   "Go to the next node of this node.
  820. A positive or negative prefix argument moves by multiple nodes."
  821.   (interactive "p")
  822.   (or n (setq n 1))
  823.   (if (< n 0)
  824.       (Info-prev (- n))
  825.     (while (>= (setq n (1- n)) 0)
  826.       (Info-goto-node (Info-extract-pointer "next")))))
  827.  
  828. (defun Info-prev (&optional n)
  829.   "Go to the previous node of this node.
  830. A positive or negative prefix argument moves by multiple nodes."
  831.   (interactive "p")
  832.   (or n (setq n 1))
  833.   (if (< n 0)
  834.       (Info-next (- n))
  835.     (while (>= (setq n (1- n)) 0)
  836.       (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
  837.  
  838. (defun Info-up (&optional n)
  839.   "Go to the superior node of this node.
  840. A positive prefix argument moves up several times."
  841.   (interactive "p")
  842.   (or n (setq n 1))
  843.   (while (>= (setq n (1- n)) 0)
  844.     (Info-goto-node (Info-extract-pointer "up")))
  845.   (if (interactive-p) (Info-restore-point)))
  846.  
  847. (defun Info-last (&optional n)
  848.   "Go back to the last node visited.
  849. With a prefix argument, go to Nth most recently visited node.  History is
  850. circular; after oldest node, history comes back around to most recent one.
  851. Argument can be negative to go through the circle in the other direction.
  852. \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
  853.   (interactive "p")
  854.   (or n (setq n 1))
  855.   (or Info-history
  856.       (error "This is the first Info node you looked at"))
  857.   (let ((len (1+ (length Info-history))))
  858.     (setq n (% (+ n (* len 100)) len)))
  859.   (if (> n 0)
  860.       (let ((entry (nth (1- n) Info-history)))
  861.     (Info-history-add Info-current-file Info-current-node (point))
  862.     (while (>= (setq n (1- n)) 0)
  863.       (setq Info-history (nconc (cdr Info-history)
  864.                     (list (car Info-history)))))
  865.     (setq Info-history (cdr Info-history))
  866.     (let ((Info-keeping-history nil))
  867.       (Info-goto-node (car entry)))
  868.     (Info-restore-history-entry entry))))
  869.  
  870. (defun Info-directory ()
  871.   "Go to the Info directory node."
  872.   (interactive)
  873.   (Info-find-node "dir" "top"))
  874.  
  875. (defun Info-follow-reference (footnotename)
  876.   "Follow cross reference named NAME to the node it refers to.
  877. NAME may be an abbreviation of the reference name."
  878.   (interactive
  879.    (let ((completion-ignore-case t)
  880.      completions default (start-point (point)) str i)
  881.      (save-excursion
  882.        (goto-char (point-min))
  883.        (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
  884.                      Info-footnote-tag)
  885.                  nil t)
  886.      (setq str (buffer-substring
  887.             (match-beginning 1)
  888.             (1- (point))))
  889.      ;; See if this one should be the default.
  890.      (and (null default)
  891.           (< (match-beginning 0) start-point)
  892.           (<= start-point (point))
  893.           (setq default t))
  894.      (setq i 0)
  895.      (while (setq i (string-match "[ \n\t]+" str i))
  896.        (setq str (concat (substring str 0 i) " "
  897.                  (substring str (match-end 0))))
  898.        (setq i (1+ i)))
  899.      ;; Record as a completion and perhaps as default.
  900.      (if (eq default t) (setq default str))
  901.      (setq completions
  902.            (cons (cons str nil)
  903.              completions))))
  904.      (if completions
  905.      (let ((item (completing-read (if default
  906.                       (concat "Follow reference named: ("
  907.                           default ") ")
  908.                     "Follow reference named: ")
  909.                       completions nil t)))
  910.        (if (and (string= item "") default)
  911.            (list default)
  912.          (list item)))
  913.        (error "No cross-references in this node"))))
  914.   (let (target beg i (str (concat "\\*" Info-footnote-tag " "
  915.                   (regexp-quote footnotename))))
  916.     (while (setq i (string-match " " str i))
  917.       (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
  918.             (substring str (1+ i))))
  919.       (setq i (+ i 10)))
  920.     (save-excursion
  921.       (goto-char (point-min))
  922.       (or (re-search-forward str nil t)
  923.       (error "No cross-reference named %s" footnotename))
  924.       (goto-char (match-end 1))
  925.       (setq target
  926.         (Info-extract-menu-node-name "Bad format cross reference" t)))
  927.     (while (setq i (string-match "[ \t\n]+" target i))
  928.       (setq target (concat (substring target 0 i) " "
  929.                (substring target (match-end 0))))
  930.       (setq i (+ i 1)))
  931.     (Info-goto-node target)
  932.     (setq Info-in-cross-reference t)))
  933.  
  934. (defun Info-next-reference (n)
  935.   (interactive "p")
  936.   (let ((pat (format "\\*%s[ \n\t]*\\([^:]*\\):\\|^\\* .*:"
  937.              Info-footnote-tag))
  938.     (case-fold-search nil)
  939.     (old-pt (point)))
  940.     (while (< n 0)
  941.       (save-excursion
  942.     (goto-char (point-min))
  943.     (while (re-search-forward pat nil t)
  944.       (setq n (1+ n)))
  945.     (goto-char (point-min))
  946.     (if (re-search-forward "^\\* Menu:" nil t)
  947.         (setq n (1- n)))))
  948.     (while (>= (setq n (1- n)) 0)
  949.       (or (eobp) (forward-char 1))
  950.       (or (re-search-forward pat nil t)
  951.       (progn
  952.         (goto-char (point-min))
  953.         (or (re-search-forward pat nil t)
  954.         (progn
  955.           (goto-char old-pt)
  956.           (error "No cross references in this node")))))
  957.       (goto-char (match-beginning 0))
  958.       (if (looking-at "\\* Menu:")
  959.       (setq n (1+ n))))))
  960.  
  961. (defun Info-prev-reference (n)
  962.   (interactive "p")
  963.   (Info-next-reference (- n)))
  964.  
  965. (defun Info-extract-menu-node-name (&optional errmessage multi-line)
  966.   (skip-chars-forward " \t\n")
  967.   (let ((beg (point))
  968.     str i)
  969.     (skip-chars-forward "^:")
  970.     (forward-char 1)
  971.     (setq str
  972.       (if (looking-at ":")
  973.           (buffer-substring beg (1- (point)))
  974.         (skip-chars-forward " \t\n")
  975.         (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
  976.     (while (setq i (string-match "\n" str i))
  977.       (aset str i ?\ ))
  978.     str))
  979.  
  980. (defun Info-menu (menu-item)
  981.   "Go to node for menu item named (or abbreviated) NAME.
  982. Completion is allowed, and the menu item point is on is the default."
  983.   (interactive
  984.    (let ((completions '())
  985.      ;; If point is within a menu item, use that item as the default
  986.      (default nil)
  987.      (p (point))
  988.      (last nil))
  989.      (save-excursion
  990.        (goto-char (point-min))
  991.        (if (not (search-forward "\n* menu:" nil t))
  992.        (error "No menu in this node"))
  993.        (while (re-search-forward
  994.         "\n\\* \\([^:\t\n]*\\):" nil t)
  995.      (if (and (null default)
  996.           (prog1 (if last (< last p) nil)
  997.             (setq last (match-beginning 0)))
  998.           (<= p last))
  999.          (setq default (car (car completions))))
  1000.      (setq completions (cons (cons (buffer-substring
  1001.                      (match-beginning 1)
  1002.                      (match-end 1))
  1003.                        (match-beginning 1))
  1004.                  completions)))
  1005.        (if (and (null default) last
  1006.         (< last p)
  1007.         (<= p (progn (end-of-line) (point))))
  1008.        (setq default (car (car completions)))))
  1009.      (let ((item nil))
  1010.        (while (null item)
  1011.      (setq item (let ((completion-ignore-case t))
  1012.               (completing-read (if default
  1013.                        (format "Menu item (default %s): "
  1014.                            default)
  1015.                        "Menu item: ")
  1016.                        completions nil t)))
  1017.      ;; we rely on the bug (which RMS won't change for his own reasons)
  1018.      ;; that ;; completing-read accepts an input of "" even when the
  1019.      ;; require-match argument is true and "" is not a valid possibility
  1020.      (if (string= item "")
  1021.          (if default
  1022.          (setq item default)
  1023.              ;; ask again
  1024.              (setq item nil))))
  1025.        (list item))))
  1026.   ;; there is a problem here in that if several menu items have the same
  1027.   ;; name you can only go to the node of the first with this command.
  1028.   (Info-goto-node (Info-extract-menu-item menu-item) nil t))
  1029.   
  1030. (defun Info-extract-menu-item (menu-item &optional noerror)
  1031.   (save-excursion
  1032.     (goto-char (point-min))
  1033.     (if (search-forward "\n* menu:" nil t)
  1034.     (if (or (search-forward (concat "\n* " menu-item ":") nil t)
  1035.         (search-forward (concat "\n* " menu-item) nil t))
  1036.         (progn
  1037.           (beginning-of-line)
  1038.           (forward-char 2)
  1039.           (Info-extract-menu-node-name))
  1040.       (and (not noerror) (error "No such item in menu")))
  1041.       (and (not noerror) (error "No menu in this node")))))
  1042.  
  1043. (defun Info-extract-menu-counting (count &optional noerror noindex)
  1044.   (save-excursion
  1045.     (goto-char (point-min))
  1046.     (if (and (search-forward "\n* menu:" nil t)
  1047.          (or (not noindex)
  1048.          (not (string-match "\\<Index\\>" Info-current-node))))
  1049.     (if (search-forward "\n* " nil t count)
  1050.         (progn
  1051.           (or count
  1052.           (while (search-forward "\n* " nil t)))
  1053.           (Info-extract-menu-node-name))
  1054.       (and (not noerror) (error "Too few items in menu")))
  1055.       (and (not noerror) (error "No menu in this node")))))
  1056.  
  1057. (defun Info-nth-menu-item (n)
  1058.   "Go to the node of the Nth menu item."
  1059.   (interactive "P")
  1060.   (or n (setq n (- last-command-char ?0)))
  1061.   (if (< n 1) (error "Index must be at least 1"))
  1062.   (Info-goto-node (Info-extract-menu-counting n) nil t))
  1063.  
  1064. (defun Info-last-menu-item ()
  1065.   "Go to the node of the tenth menu item."
  1066.   (interactive)
  1067.   (Info-goto-node (Info-extract-menu-counting nil) nil t))
  1068.  
  1069. (defun Info-top ()
  1070.   "Go to the Top node of this file."
  1071.   (interactive)
  1072.   (Info-goto-node "Top"))
  1073.  
  1074. (defun Info-end ()
  1075.   "Go to the final node in this file."
  1076.   (interactive)
  1077.   (Info-top)
  1078.   (let ((Info-keeping-history nil)
  1079.     node)
  1080.     (Info-last-menu-item)
  1081.     (while (setq node (or (Info-extract-pointer "next" t)
  1082.               (Info-extract-menu-counting nil t t)))
  1083.       (Info-goto-node node))
  1084.     (or (equal (Info-extract-pointer "up" t) "Top")
  1085.     (let ((executing-kbd-macro ""))   ; suppress messages
  1086.       (condition-case err
  1087.           (Info-global-next 10000)
  1088.         (error nil))))))
  1089.  
  1090. (defun Info-global-next (&optional n)
  1091.   "Go to the next node in this file, traversing node structure as necessary.
  1092. This works only if the Info file is structured as a hierarchy of nodes.
  1093. A positive or negative prefix argument moves by multiple nodes."
  1094.   (interactive "p")
  1095.   (or n (setq n 1))
  1096.   (if (< n 0)
  1097.       (Info-global-prev (- n))
  1098.     (while (>= (setq n (1- n)) 0)
  1099.       (let (node)
  1100.     (cond ((and (string-match "^Top$" Info-current-node)
  1101.             (setq node (Info-extract-pointer "next" t))
  1102.             (Info-extract-menu-item node t))
  1103.            (Info-goto-node node))
  1104.           ((setq node (Info-extract-menu-counting 1 t t))
  1105.            (message "Going down...")
  1106.            (Info-goto-node node))
  1107.           (t
  1108.            (let ((Info-keeping-history Info-keeping-history)
  1109.              (orignode Info-current-node)
  1110.              (ups ""))
  1111.          (while (not (Info-extract-pointer "next" t))
  1112.            (if (and (setq node (Info-extract-pointer "up" t))
  1113.                 (not (equal node "Top")))
  1114.                (progn
  1115.              (message "Going%s..." (setq ups (concat ups " up")))
  1116.              (Info-goto-node node)
  1117.              (setq Info-keeping-history nil))
  1118.              (if orignode
  1119.              (let ((Info-keeping-history nil))
  1120.                (Info-goto-node orignode)))
  1121.              (error "Last node in file")))
  1122.          (Info-next))))))))
  1123.  
  1124. (defun Info-page-next (&optional n)
  1125.   "Scroll forward one screenful, or go to next global node.
  1126. A positive or negative prefix argument moves by multiple screenfuls."
  1127.   (interactive "p")
  1128.   (or n (setq n 1))
  1129.   (if (< n 0)
  1130.       (Info-page-prev (- n))
  1131.     (while (>= (setq n (1- n)) 0)
  1132.       (if (pos-visible-in-window-p (point-max))
  1133.       (progn
  1134.         (Info-global-next)
  1135.         (message "Node: %s" Info-current-node))
  1136.     (scroll-up)))))
  1137.  
  1138. (defun Info-scroll-next (arg)
  1139.   (interactive "P")
  1140.   (if Info-auto-advance
  1141.       (if (and (pos-visible-in-window-p (point-max))
  1142.            (not (eq Info-auto-advance t))
  1143.            (not (eq last-command this-command)))
  1144.       (message "Hit %s again to go to next node"
  1145.            (if (= last-command-char 0)
  1146.                "mouse button"
  1147.              (key-description (char-to-string last-command-char))))
  1148.     (Info-page-next)
  1149.     (setq this-command 'Info))
  1150.     (scroll-up arg)))
  1151.  
  1152. (defun Info-global-prev (&optional n)
  1153.   "Go to the previous node in this file, traversing structure as necessary.
  1154. This works only if the Info file is structured as a hierarchy of nodes.
  1155. A positive or negative prefix argument moves by multiple nodes."
  1156.   (interactive "p")
  1157.   (or n (setq n 1))
  1158.   (if (< n 0)
  1159.       (Info-global-next (- n))
  1160.     (while (>= (setq n (1- n)) 0)
  1161.       (let ((upnode (Info-extract-pointer "up" t))
  1162.         (prevnode (Info-extract-pointer "prev[ious]*" t)))
  1163.     (if (or (not prevnode)
  1164.         (equal prevnode upnode))
  1165.         (if (string-match "^Top$" Info-current-node)
  1166.         (error "First node in file")
  1167.           (message "Going up...")
  1168.           (Info-up))
  1169.       (Info-goto-node prevnode)
  1170.       (let ((downs "")
  1171.         (Info-keeping-history nil)
  1172.         node)
  1173.         (while (setq node (Info-extract-menu-counting nil t t))
  1174.           (message "Going%s..." (setq downs (concat downs " down")))
  1175.           (Info-goto-node node))))))))
  1176.  
  1177. (defun Info-page-prev (&optional n)
  1178.   "Scroll backward one screenful, or go to previous global node.
  1179. A positive or negative prefix argument moves by multiple screenfuls."
  1180.   (interactive "p")
  1181.   (or n (setq n 1))
  1182.   (if (< n 0)
  1183.       (Info-page-next (- n))
  1184.     (while (>= (setq n (1- n)) 0)
  1185.       (if (pos-visible-in-window-p (point-min))
  1186.       (progn
  1187.         (Info-global-prev)
  1188.         (message "Node: %s" Info-current-node)
  1189.         (sit-for 0)
  1190.         ;;(scroll-up 1)   ; work around bug in pos-visible-in-window-p
  1191.         ;;(scroll-down 1)
  1192.         (while (not (pos-visible-in-window-p (point-max)))
  1193.           (scroll-up)))
  1194.     (scroll-down)))))
  1195.  
  1196. (defun Info-scroll-prev (arg)
  1197.   (interactive "P")
  1198.   (if Info-auto-advance
  1199.       (if (and (pos-visible-in-window-p (point-min))
  1200.            (not (eq Info-auto-advance t))
  1201.            (not (eq last-command this-command)))
  1202.       (message "Hit %s again to go to previous node"
  1203.            (if (= last-command-char 0)
  1204.                "mouse button"
  1205.              (key-description (char-to-string last-command-char))))
  1206.     (Info-page-prev)
  1207.     (setq this-command 'Info))
  1208.     (scroll-down arg)))
  1209.  
  1210. (defun Info-index (topic)
  1211.   "Look up a string in the index for this file.
  1212. The index is defined as the first node in the top-level menu whose
  1213. name contains the word \"Index\", plus any immediately following
  1214. nodes whose names also contain the word \"Index\".
  1215. If there are no exact matches to the specified topic, this chooses
  1216. the first match which is a case-insensitive substring of a topic.
  1217. Use the `,' command to see the other matches.
  1218. Give a blank topic name to go to the Index node itself."
  1219.   (interactive "sIndex topic: ")
  1220.   (let ((orignode Info-current-node)
  1221.     (rnode nil)
  1222.     (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"
  1223.              (regexp-quote topic)))
  1224.     node)
  1225.     (Info-goto-node "Top")
  1226.     (or (search-forward "\n* menu:" nil t)
  1227.     (error "No index"))
  1228.     (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
  1229.     (error "No index"))
  1230.     (goto-char (match-beginning 1))
  1231.     (let ((Info-keeping-history nil))
  1232.       (Info-goto-node (Info-extract-menu-node-name)))
  1233.     (or (equal topic "")
  1234.     (let ((matches nil)
  1235.           (exact nil)
  1236.           (Info-keeping-history nil)
  1237.           found)
  1238.       (while
  1239.           (progn
  1240.         (goto-char (point-min))
  1241.         (while (re-search-forward pattern nil t)
  1242.           (setq matches
  1243.             (cons (list (buffer-substring (match-beginning 1)
  1244.                               (match-end 1))
  1245.                     (buffer-substring (match-beginning 2)
  1246.                               (match-end 2))
  1247.                     Info-current-node
  1248.                     (string-to-int (concat "0"
  1249.                                (buffer-substring
  1250.                                 (match-beginning 3)
  1251.                                 (match-end 3)))))
  1252.                   matches)))
  1253.         (and (setq node (Info-extract-pointer "next" t))
  1254.              (string-match "\\<Index\\>" node)))
  1255.         (Info-goto-node node))
  1256.       (or matches
  1257.           (progn
  1258.         (Info-last)
  1259.         (error "No \"%s\" in index" topic)))
  1260.       ;; Here it is a feature that assoc is case-sensitive.
  1261.       (while (setq found (assoc topic matches))
  1262.         (setq exact (cons found exact)
  1263.           matches (delq found matches)))
  1264.       (setq Info-index-alternatives (nconc exact (nreverse matches)))
  1265.       (Info-index-next 0)))))
  1266.  
  1267. (defun Info-index-next (num)
  1268.   "Go to the next matching index item from the last `i' command."
  1269.   (interactive "p")
  1270.   (or Info-index-alternatives
  1271.       (error "No previous `i' command in this file"))
  1272.   (while (< num 0)
  1273.     (setq num (+ num (length Info-index-alternatives))))
  1274.   (while (> num 0)
  1275.     (setq Info-index-alternatives
  1276.       (nconc (cdr Info-index-alternatives)
  1277.          (list (car Info-index-alternatives)))
  1278.       num (1- num)))
  1279.   (Info-goto-node (nth 1 (car Info-index-alternatives)))
  1280.   (if (> (nth 3 (car Info-index-alternatives)) 0)
  1281.       (forward-line (nth 3 (car Info-index-alternatives)))
  1282.     (forward-line 3)  ; don't search in headers
  1283.     (let ((name (car (car Info-index-alternatives))))
  1284.       (if (or (re-search-forward (format
  1285.                   "\\(Function\\|Command\\): %s\\( \\|$\\)"
  1286.                   (regexp-quote name)) nil t)
  1287.           (search-forward (format "`%s'" name) nil t)
  1288.           (and (string-match "\\`.*\\( (.*)\\)\\'" name)
  1289.            (search-forward
  1290.             (format "`%s'" (substring name 0 (match-beginning 1)))
  1291.             nil t))
  1292.           (search-forward name nil t))
  1293.       (beginning-of-line)
  1294.     (goto-char (point-min)))))
  1295.   (message "Found \"%s\" in %s.  %s"
  1296.        (car (car Info-index-alternatives))
  1297.        (nth 2 (car Info-index-alternatives))
  1298.        (if (cdr Info-index-alternatives)
  1299.            "(Press `,' for more)"
  1300.          "(Only match)")))
  1301.  
  1302. (defun Info-emacs-key (key)
  1303.   "Look up an Emacs key sequence in the Emacs manual in the Info system.
  1304. This command is designed to be used whether you are already in Info or not."
  1305.   (interactive "kLook up key in Emacs manual: ")
  1306.   (if (equal key "\C-g")
  1307.       (keyboard-quit))
  1308.   (info)
  1309.   (Info-find-node "emacs" "Top")
  1310.   (setq key (key-description key))
  1311.   (let (p)
  1312.     (if (setq p (string-match "[@{}]" key))
  1313.     (setq key (concat (substring key 0 p) "@" (substring key p))))
  1314.     (if (string-match "^ESC " key)
  1315.     (setq key (concat "M-" (substring key 4))))
  1316.     (if (string-match "^M-C-" key)
  1317.     (setq key (concat "C-M-" (substring key 4)))))
  1318.   (Info-index key))
  1319.  
  1320. (defun Info-elisp-ref (func)
  1321.   "Look up an Emacs Lisp function in the Elisp manual in the Info system.
  1322. This command is designed to be used whether you are already in Info or not."
  1323.   (interactive (let ((fn (function-called-at-point))
  1324.              (enable-recursive-minibuffers t)         
  1325.              val)
  1326.          (setq val (completing-read
  1327.                 (format "Look up Emacs Lisp function%s: "
  1328.                     (if fn
  1329.                     (format " (default %s)" fn)
  1330.                       ""))
  1331.                 obarray 'fboundp t))
  1332.          (list (if (equal val "")
  1333.                fn (intern val)))))
  1334.   (info)
  1335.   (condition-case err
  1336.       (Info-find-node "elisp" "Top")
  1337.     (error (Info-find-node "lispref" "Top")))
  1338.   (Info-index (symbol-name func)))
  1339.  
  1340. (defun Info-reannotate-node ()
  1341.   (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
  1342.     (if bufs
  1343.     (let ((ibuf (current-buffer))
  1344.           (file (regexp-quote
  1345.              (file-name-nondirectory Info-current-file)))
  1346.           (node (regexp-quote Info-current-node))
  1347.           (savept (point)))
  1348.       (goto-char (point-min))
  1349.       (if (search-forward "\n------ NOTE:\n" nil t)
  1350.           (let ((buffer-read-only nil)
  1351.             (bufmod (buffer-modified-p))
  1352.             top)
  1353.         (setq savept (copy-marker savept))
  1354.         (goto-char (point-min))
  1355.         (while (search-forward "\n------ NOTE:" nil t)
  1356.           (setq top (1+ (match-beginning 0)))
  1357.           (if (search-forward "\n------\n" nil t)
  1358.               (delete-region top (point)))
  1359.           (backward-char 1))
  1360.         (set-buffer-modified-p bufmod)))
  1361.       (save-excursion
  1362.         (while bufs
  1363.           (set-buffer (car bufs))
  1364.           (goto-char (point-min))
  1365.           (while (re-search-forward
  1366.               (format "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
  1367.                   file node)
  1368.               nil t)
  1369.         (let ((line (string-to-int
  1370.                  (buffer-substring (match-beginning 1)
  1371.                            (match-end 1))))
  1372.               (top (point))
  1373.               bot)
  1374.           (search-forward "\n------\n" nil t)
  1375.           (setq bot (point))
  1376.           (save-excursion
  1377.             (set-buffer ibuf)
  1378.             (if (integerp savept) (setq savept (copy-marker savept)))
  1379.             (if (= line 0)
  1380.             (goto-char (point-max))
  1381.               (goto-char (point-min))
  1382.               (forward-line line))
  1383.             (let ((buffer-read-only nil)
  1384.               (bufmod (buffer-modified-p)))
  1385.               (insert "------ NOTE:\n")
  1386.               (insert-buffer-substring (car bufs) top bot)
  1387.               (set-buffer-modified-p bufmod)))))
  1388.           (setq bufs (cdr bufs))))
  1389.       (goto-char savept)))))
  1390.  
  1391. (defvar Info-annotate-map nil
  1392.   "Local keymap used within `a' command of Info.")
  1393. (if Info-annotate-map
  1394.     nil
  1395.   ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
  1396.   (setq Info-annotate-map (copy-keymap text-mode-map))
  1397.   (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
  1398.  
  1399. (defun Info-annotate-mode ()
  1400.   "Major mode for adding an annotation to an Info node.
  1401. Like text mode with the addition of Info-cease-annotate
  1402. which returns to Info mode for browsing.
  1403. \\{Info-annotate-map}")
  1404.  
  1405. (defun Info-annotate (arg)
  1406.   "Add a personal annotation to the current Info node.
  1407. Only you will be able to see this annotation.
  1408. Annotations are stored in the file ~/.infonotes by default.
  1409. If point is inside an existing annotation, edit that annotation.
  1410. A prefix argument specifies which annotations file (from
  1411. Info-annotations-path) is to be edited; default is 1."
  1412.   (interactive "p")
  1413.   (setq arg (1- arg))
  1414.   (if (or (< arg 0) (not (nth arg Info-annotations-path)))
  1415.       (if (= arg 0)
  1416.       (setq Info-annotations-path
  1417.         (list (read-file-name
  1418.                "Annotations file: " "~/" "~/.infonotes")))
  1419.     (error "File number must be in the range from 1 to %d"
  1420.            (length Info-annotations-path))))
  1421.   (let ((which nil)
  1422.     where pt)
  1423.     (if (and (save-excursion
  1424.            (goto-char (min (point-max) (+ (point) 13)))
  1425.            (and (search-backward "------ NOTE:\n" nil t)
  1426.             (setq pt (match-end 0))
  1427.             (search-forward "\n------\n" nil t)))
  1428.          (< (point) (match-end 0)))
  1429.     (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
  1430.                 (regexp-quote
  1431.                  (file-name-nondirectory Info-current-file))
  1432.                 (regexp-quote Info-current-node)
  1433.                 (regexp-quote
  1434.                  (buffer-substring pt (match-beginning 0))))
  1435.           where (max (- (point) pt) 0)))
  1436.     (let ((file (file-name-nondirectory Info-current-file))
  1437.       (node Info-current-node)
  1438.       (line (if (looking-at "[ \n]*\\'") 0
  1439.           (count-lines (point-min) (point)))))
  1440.       (or which
  1441.       (let ((buffer-read-only nil)
  1442.         (bufmod (buffer-modified-p))
  1443.         top)
  1444.         (beginning-of-line)
  1445.         (if (bobp) (goto-char (point-max)))
  1446.         (insert "------ NOTE:\n------\n")
  1447.         (backward-char 20)
  1448.         (set-buffer-modified-p bufmod)))
  1449.       ;; (setq Info-window-start (window-start))
  1450.       (setq Info-window-configuration (current-window-configuration))
  1451.       (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
  1452.       (use-local-map Info-annotate-map)
  1453.       (setq major-mode 'Info-annotate-mode)
  1454.       (setq mode-name "Info Annotate")
  1455.       (if which
  1456.       (if (save-excursion
  1457.         (goto-char (point-min))
  1458.         (re-search-forward which nil t))
  1459.           (progn
  1460.         (goto-char (match-beginning 0))
  1461.         (forward-line 1)
  1462.         (forward-char where)))
  1463.     (let ((bufmod (buffer-modified-p)))
  1464.       (goto-char (point-max))
  1465.       (insert (format "\n------ File: %s  Node: %s  Line: %d\n"
  1466.               file node line))
  1467.       (setq pt (point))
  1468.       (insert "\n------\n"
  1469.           "\nPress C-c C-c to save and return to Info.\n")
  1470.       (goto-char pt)
  1471.       (set-buffer-modified-p bufmod))))))
  1472.  
  1473. (defun Info-cease-annotate ()
  1474.   (interactive)
  1475.   (let ((bufmod (buffer-modified-p)))
  1476.     (while (save-excursion
  1477.          (goto-char (point-min))
  1478.          (re-search-forward "\n\n?Press .* to save and return to Info.\n"
  1479.                 nil t))
  1480.       (delete-region (1+ (match-beginning 0)) (match-end 0)))
  1481.     (while (save-excursion
  1482.          (goto-char (point-min))
  1483.          (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
  1484.                 nil t))
  1485.       (delete-region (match-beginning 0) (match-end 0)))
  1486.     (set-buffer-modified-p bufmod))
  1487.   (save-buffer)
  1488.   (fundamental-mode)
  1489.   (bury-buffer)
  1490.   (or (one-window-p) (delete-window))
  1491.   (info)
  1492.   (setq Info-current-file-completions nil)
  1493.   (set-window-configuration Info-window-configuration)
  1494.   (Info-reannotate-node))
  1495.  
  1496. (defun Info-exit ()
  1497.   "Exit Info by selecting some other buffer."
  1498.   (interactive)
  1499.   (switch-to-buffer (prog1 (other-buffer (current-buffer))
  1500.                (bury-buffer (current-buffer)))))
  1501.  
  1502. (defun Info-undefined ()
  1503.   "Make command be undefined in Info."
  1504.   (interactive)
  1505.   (ding))
  1506.  
  1507. (defun Info-help ()
  1508.   "Enter the Info tutorial."
  1509.   (interactive)
  1510.   (delete-other-windows)
  1511.   (Info-find-node "info"
  1512.           (if (< (window-height) 23)
  1513.               "Help-Small-Screen"
  1514.             "Help")))
  1515.  
  1516. (defun Info-summary ()
  1517.   "Display a brief summary of all Info commands."
  1518.   (interactive)
  1519.   (save-window-excursion
  1520.     (switch-to-buffer "*Help*")
  1521.     (erase-buffer)
  1522.     (insert (documentation 'Info-mode))
  1523.     (goto-char (point-min))
  1524.     (let (ch flag)
  1525.       (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
  1526.             (message (if flag "Type Space to see more"
  1527.                    "Type Space to return to Info"))
  1528.             (if (/= ?\  (setq ch (read-char)))
  1529.             (progn (setq unread-command-char ch) nil)
  1530.               flag))
  1531.     (scroll-up)))
  1532.     (bury-buffer "*Help*")))
  1533.  
  1534. (defun Info-get-token (pos start all &optional errorstring)
  1535.   "Return the token around POS,
  1536. POS must be somewhere inside the token
  1537. START is a regular expression which will match the
  1538.     beginning of the tokens delimited string
  1539. ALL is a regular expression with a single
  1540.     parenthized subpattern which is the token to be
  1541.     returned. E.g. '{\(.*\)}' would return any string
  1542.     enclosed in braces around POS.
  1543. SIG optional fourth argument, controls action on no match
  1544.     nil: return nil
  1545.     t: beep
  1546.     a string: signal an error, using that string."
  1547.   (save-excursion
  1548.     (goto-char pos)
  1549.     (re-search-backward start (max (point-min) (- pos 200)) 'yes)
  1550.     (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
  1551.         (not (and (<= (match-beginning 0) pos)
  1552.               (> (match-end 0) pos)))))
  1553.     (if (and (<= (match-beginning 0) pos)
  1554.          (> (match-end 0) pos)
  1555.          (match-beginning 1))
  1556.     (buffer-substring (match-beginning 1) (match-end 1))
  1557.       (cond ((null errorstring)
  1558.          nil)
  1559.         ((eq errorstring t)
  1560.          (beep)
  1561.          nil)
  1562.         (t
  1563.          (error "No %s around position %d" errorstring pos))))))
  1564.  
  1565. (defun Info-follow-clicked-node (event)
  1566.   "Follow a node reference near clicked point.  Like M, F, N, P or U command.
  1567. At end of the node's text, moves to the next node."
  1568.   (interactive "@e")
  1569.   (let* ((relative-coordinates (coordinates-in-window-p (car event)
  1570.                             (selected-window)))
  1571.      (rel-x (car relative-coordinates))
  1572.      (rel-y (car (cdr relative-coordinates)))
  1573.      (point (save-excursion
  1574.           (move-to-window-line rel-y)
  1575.           (move-to-column (+ rel-x (current-column)))
  1576.           (point))))
  1577.     (Info-follow-nearest-node (max point (1+ (point-min))))))
  1578.  
  1579. (defun Info-follow-nearest-node (point)
  1580.   "Follow a node reference near point.  Like M, F, N, P or U command.
  1581. At end of the node's text, moves to the next node."
  1582.   (interactive "d")
  1583.   (let (node)
  1584.     (cond
  1585.      ((= point (point-min)))   ; don't trigger on accidental RET.
  1586.      ((setq node (Info-get-token point
  1587.                  (format "\\*%s[ \n]" Info-footnote-tag)
  1588.                  (format "\\*%s[ \n]\\([^:]*\\):"
  1589.                      Info-footnote-tag)))
  1590.       (message "Following cross-reference %s..." node)
  1591.       (Info-follow-reference node))
  1592.      ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\)::"))
  1593.       (message "Selecting menu item %s..." node)
  1594.       (Info-goto-node node))
  1595.      ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\):"))
  1596.       (message "Selecting menu item %s..." node)
  1597.       (Info-menu node))
  1598.      ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
  1599.       (message "Going up...")
  1600.       (Info-goto-node node))
  1601.      ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
  1602.       (message "Next node...")
  1603.       (Info-goto-node node))
  1604.      ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
  1605.       (message "Top node...")
  1606.       (Info-goto-node "Top"))
  1607.      ((setq node (Info-get-token point "Prev[ious]*: "
  1608.                  "Prev[ious]*: \\([^,\n\t]*\\)"))
  1609.       (message "Previous node...")
  1610.       (Info-goto-node node))
  1611.      ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
  1612.       (if Info-in-cross-reference
  1613.       (progn
  1614.         (message "Back to last node...")
  1615.         (Info-last))
  1616.     (message "Next node...")
  1617.     (Info-global-next))))
  1618.     ))
  1619.  
  1620. ;;; Provide Emacs 18 support for mouse clicks.
  1621. (defvar Info-prev-x-right-click nil)
  1622. (defvar Info-prev-x-middle-click nil)
  1623. (defvar Info-prev-x-left-click nil)
  1624. (defvar Info-prev-x-s-right-click nil)
  1625. (defvar Info-prev-x-s-middle-click nil)
  1626. (defvar Info-prev-x-s-left-click nil)
  1627. (defun Info-setup-x ()
  1628.   (and (eq window-system 'x)
  1629.        (not Info-prev-x-left-click)
  1630.        Info-mouse-support
  1631.        (progn
  1632.      (setq Info-prev-x-right-click (aref mouse-map 0)
  1633.            Info-prev-x-middle-click (aref mouse-map 1)
  1634.            Info-prev-x-left-click (aref mouse-map 2)
  1635.            Info-prev-x-s-right-click (aref mouse-map 16)
  1636.            Info-prev-x-s-middle-click (aref mouse-map 17)
  1637.            Info-prev-x-s-left-click (aref mouse-map 18))
  1638.      (aset mouse-map 0 'Info-x-right-click)
  1639.      (aset mouse-map 1 'Info-x-middle-click)
  1640.      (aset mouse-map 2 'Info-x-left-click)
  1641.      (aset mouse-map 16 'Info-x-s-right-click)
  1642.      (aset mouse-map 17 'Info-x-s-middle-click)
  1643.      (aset mouse-map 18 'Info-x-s-left-click))))
  1644.  
  1645. (defun Info-x-left-click (arg)
  1646.   "Handle a left-button mouse click in Info window."
  1647.   (Info-handle-click '(condition-case err (Info-scroll-next nil) (error nil))
  1648.              arg Info-prev-x-left-click))
  1649.  
  1650. (defun Info-x-right-click (arg)
  1651.   "Handle a right-button mouse click in Info window."
  1652.   (Info-handle-click '(condition-case err (Info-scroll-prev nil) (error nil))
  1653.              arg Info-prev-x-right-click))
  1654.  
  1655. (defun Info-x-middle-click (arg)
  1656.   "Handle a middle-button mouse click in Info window."
  1657.   (Info-handle-click '(Info-follow-clicked-node (list arg))
  1658.              arg Info-prev-x-middle-click))
  1659.  
  1660. (defun Info-x-s-left-click (arg)
  1661.   "Handle a shift-left-button mouse click in Info window."
  1662.   (Info-handle-click '(Info-global-next) arg Info-prev-x-s-left-click))
  1663.  
  1664. (defun Info-x-s-right-click (arg)
  1665.   "Handle a shift-right-button mouse click in Info window."
  1666.   (Info-handle-click '(Info-global-prev) arg Info-prev-x-s-right-click))
  1667.  
  1668. (defun Info-x-s-middle-click (arg)
  1669.   "Handle a shift-middle-button mouse click in Info window."
  1670.   (Info-handle-click '(Info-last) arg Info-prev-x-s-middle-click))
  1671.  
  1672. (defun Info-handle-click (form arg prev)
  1673.   (if (and (get-buffer-window "*info*")
  1674.        (coordinates-in-window-p arg (get-buffer-window "*info*")))
  1675.       (let ((win (selected-window)))
  1676.     (unwind-protect
  1677.         (progn
  1678.           (select-window (get-buffer-window "*info*"))
  1679.           (eval form))
  1680.       (and (window-point win)
  1681.            (select-window win))))
  1682.     (funcall prev arg)))
  1683.  
  1684. (defun x-mouse-ignore (arg)
  1685.   "Don't do anything."
  1686.   ;; Added the following line to support Info-auto-advance mode.
  1687.   (setq this-command last-command))
  1688.  
  1689. (defvar Info-mode-map nil
  1690.   "Keymap containing Info commands.")
  1691. (if Info-mode-map
  1692.     nil
  1693.   (setq Info-mode-map (make-keymap))
  1694.   (suppress-keymap Info-mode-map)
  1695.   (define-key Info-mode-map "." 'beginning-of-buffer)
  1696.   (define-key Info-mode-map " " 'Info-scroll-next)
  1697.   (define-key Info-mode-map "1" 'Info-nth-menu-item)
  1698.   (define-key Info-mode-map "2" 'Info-nth-menu-item)
  1699.   (define-key Info-mode-map "3" 'Info-nth-menu-item)
  1700.   (define-key Info-mode-map "4" 'Info-nth-menu-item)
  1701.   (define-key Info-mode-map "5" 'Info-nth-menu-item)
  1702.   (define-key Info-mode-map "6" 'Info-nth-menu-item)
  1703.   (define-key Info-mode-map "7" 'Info-nth-menu-item)
  1704.   (define-key Info-mode-map "8" 'Info-nth-menu-item)
  1705.   (define-key Info-mode-map "9" 'Info-nth-menu-item)
  1706.   (define-key Info-mode-map "0" 'Info-last-menu-item)
  1707.   (define-key Info-mode-map "?" 'Info-summary)
  1708.   (define-key Info-mode-map "a" 'Info-annotate)
  1709.   (define-key Info-mode-map "b" 'beginning-of-buffer)
  1710.   (define-key Info-mode-map "d" 'Info-directory)
  1711.   (define-key Info-mode-map "e" 'Info-edit)
  1712.   (define-key Info-mode-map "f" 'Info-follow-reference)
  1713.   (define-key Info-mode-map "g" 'Info-goto-node)
  1714.   (define-key Info-mode-map "h" 'Info-help)
  1715.   (define-key Info-mode-map "i" 'Info-index)
  1716.   (define-key Info-mode-map "k" 'Info-emacs-key)
  1717.   (define-key Info-mode-map "l" 'Info-last)
  1718.   (define-key Info-mode-map "m" 'Info-menu)
  1719.   (define-key Info-mode-map "n" 'Info-next)
  1720.   (define-key Info-mode-map "p" 'Info-prev)
  1721.   (define-key Info-mode-map "q" 'Info-exit)
  1722.   (define-key Info-mode-map "r" 'Info-follow-reference)
  1723.   (define-key Info-mode-map "s" 'Info-search)
  1724.   (define-key Info-mode-map "t" 'Info-top)
  1725.   (define-key Info-mode-map "u" 'Info-up)
  1726.   (define-key Info-mode-map "<" 'Info-top)
  1727.   (define-key Info-mode-map ">" 'Info-end)
  1728.   (define-key Info-mode-map "[" 'Info-global-prev)
  1729.   (define-key Info-mode-map "]" 'Info-global-next)
  1730.   (define-key Info-mode-map "{" 'Info-page-prev)
  1731.   (define-key Info-mode-map "}" 'Info-page-next)
  1732.   (define-key Info-mode-map "=" 'Info-restore-point)
  1733.   (define-key Info-mode-map "!" 'Info-select-node)
  1734.   (define-key Info-mode-map "@" 'Info-follow-nearest-node)
  1735.   (define-key Info-mode-map "," 'Info-index-next)
  1736.   (define-key Info-mode-map "*" 'Info-elisp-ref)
  1737.   (define-key Info-mode-map "\t" 'Info-next-reference)
  1738.   (define-key Info-mode-map "\e\t" 'Info-prev-reference)
  1739.   (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
  1740.   (define-key Info-mode-map "\177" 'Info-scroll-prev))
  1741.  
  1742. (or (lookup-key help-map "\C-k")
  1743.     (define-key help-map "\C-k" 'Info-emacs-key))
  1744.  
  1745. (or (lookup-key help-map "\C-f")
  1746.     (define-key help-map "\C-f" 'Info-elisp-ref))
  1747.  
  1748. (let ((help (symbol-function 'help-for-help))
  1749.       (doc (documentation 'help-for-help)))
  1750.   (and (consp help) (eq (car help) 'lambda)
  1751.        (not (string-match "C-k" doc))
  1752.        (setq doc (concat
  1753.           doc
  1754.           "\n\nC-k  Info-emacs-key.  Look up a key in Emacs manual."
  1755.           "\nC-f  Info-elisp-ref."
  1756.           "  Look up a function in Emacs Lisp manual."))
  1757.        (fset 'help-for-help
  1758.          (cons 'lambda (cons (nth 1 help) (cons doc (nthcdr 2 help)))))))
  1759.  
  1760.  
  1761. ;;; The following stuff is for Emacs 19 only---it's ignored in Emacs 18.
  1762. (defvar Info-mode-mouse-map nil
  1763.   "Mouse map for use with Info mode.")
  1764.  
  1765. (if Info-mode-mouse-map
  1766.     nil
  1767.   (if (or (not (boundp 'global-mouse-map))
  1768.       (null (cdr global-mouse-map)))
  1769.       nil
  1770.     (setq Info-mode-mouse-map (make-sparse-keymap))
  1771.     (define-key Info-mode-mouse-map mouse-button-middle
  1772.       'Info-follow-clicked-node)
  1773.     (define-key Info-mode-mouse-map mouse-button-left 'mouse-scroll-up-full)
  1774.     (define-key Info-mode-mouse-map mouse-button-right 'mouse-scroll-down-full)))
  1775.  
  1776. ;; Info mode is suitable only for specially formatted data.
  1777. (put 'info-mode 'mode-class 'special)
  1778.  
  1779. (defun Info-mode ()
  1780.   "Info mode is for browsing through the Info documentation tree.
  1781. Documentation in Info is divided into \"nodes\", each of which
  1782. discusses one topic and contains references to other nodes
  1783. which discuss related topics.  Info has commands to follow
  1784. the references and show you other nodes.
  1785.  
  1786. h    Invoke the Info tutorial.
  1787. q    Quit Info: return to previously selected file or buffer.
  1788.  
  1789. Selecting other nodes:
  1790. n    Move to the \"next\" node of this node.
  1791. p    Move to the \"previous\" node of this node.
  1792. m    Pick menu item specified by name (or abbreviation).
  1793. 1-9, 0    Pick first..ninth, last item in node's menu.
  1794.     Menu items select nodes that are \"subsections\" of this node.
  1795. u    Move \"up\" from this node (i.e., from a subsection to a section).
  1796. f or r    Follow a cross reference by name (or abbrev).  Type `l' to get back.
  1797. RET     Follow cross reference or menu item indicated by cursor.
  1798. i    Look up a topic in this file's Index and move to that node.
  1799. ,    (comma) Move to the next match from a previous `i' command.
  1800. l    Move back to the last node you were in.
  1801.  
  1802. Moving within a node:
  1803. Space    Scroll forward a full screen.   DEL       Scroll backward.
  1804. b    Go to beginning of node.        Meta->    Go to end of node.
  1805. TAB    Go to next cross-reference.     Meta-TAB  Go to previous ref.
  1806.  
  1807. Mouse commands:                Shifted mouse commands:
  1808. Middle    Follow reference (RET).        S-Middle  Back to last node (`l').
  1809. Left    Next page or node (Space).    S-Left    Next node (`]').
  1810. Right    Prev page or node (DEL).    S-Right   Prev node (`[').
  1811.  
  1812. Advanced commands:
  1813. g    Move to node, file, or annotation tag specified by name.
  1814.     Examples:  `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
  1815. k    Look up a key sequence in Emacs manual (also C-h C-k at any time).
  1816. *    Look up a function name in Emacs Lisp manual (also C-h C-f).
  1817. d    Go to the main directory of Info files.
  1818. < or t    Go to Top (first) node of this file.
  1819. >    Go to last node in this file.
  1820. \[    Go to previous node, treating file as one linear document.
  1821. \]    Go to next node, treating file as one linear document.
  1822. {    Scroll backward, or go to previous node if at top.
  1823. }    Scroll forward, or go to next node if at bottom.
  1824. =    Restore cursor position from last time in this node.
  1825. a    Add a private note (annotation) to the current node.
  1826. s    Search this Info file for a node containing the specified regexp.
  1827. e    Edit the contents of the current node."
  1828.   (kill-all-local-variables)
  1829.   (setq major-mode 'Info-mode)
  1830.   (setq mode-name "Info")
  1831.   (use-local-map Info-mode-map)
  1832.   (set-syntax-table text-mode-syntax-table)
  1833.   (setq local-abbrev-table text-mode-abbrev-table)
  1834.   (setq case-fold-search t)
  1835.   (setq buffer-read-only t)
  1836.   (setq buffer-mouse-map Info-mode-mouse-map)
  1837.   (make-local-variable 'Info-current-file)
  1838.   (make-local-variable 'Info-current-subfile)
  1839.   (make-local-variable 'Info-current-node)
  1840.   (make-local-variable 'Info-tag-table-marker)
  1841.   (make-local-variable 'Info-current-file-completions)
  1842.   (make-local-variable 'Info-index-alternatives)
  1843.   (make-local-variable 'Info-history)
  1844.   (run-hooks 'Info-mode-hook)
  1845.   (Info-set-mode-line))
  1846.  
  1847. (defvar Info-edit-map nil
  1848.   "Local keymap used within `e' command of Info.")
  1849. (if Info-edit-map
  1850.     nil
  1851.   ;; (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
  1852.   (setq Info-edit-map (copy-keymap text-mode-map))
  1853.   (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
  1854.  
  1855. ;; Info-edit mode is suitable only for specially formatted data.
  1856. (put 'info-edit-mode 'mode-class 'special)
  1857.  
  1858. (defun Info-edit-mode ()
  1859.   "Major mode for editing the contents of an Info node.
  1860. Like text mode with the addition of Info-cease-edit
  1861. which returns to Info mode for browsing.
  1862. \\{Info-edit-map}"
  1863.   )
  1864.  
  1865. (defun Info-edit ()
  1866.   "Edit the contents of this Info node.
  1867. Allowed only if variable Info-enable-edit is non-nil."
  1868.   (interactive)
  1869.   (or Info-enable-edit
  1870.       (error "Editing info nodes is not enabled"))
  1871.   (use-local-map Info-edit-map)
  1872.   (setq major-mode 'Info-edit-mode)
  1873.   (setq mode-name "Info Edit")
  1874.   (kill-local-variable 'mode-line-buffer-identification)
  1875.   (setq buffer-read-only nil)
  1876.   ;; Make mode line update.
  1877.   (set-buffer-modified-p (buffer-modified-p))
  1878.   (message (substitute-command-keys
  1879.          "Editing: Type \\[Info-cease-edit] to return to info")))
  1880.  
  1881. (defun Info-cease-edit ()
  1882.   "Finish editing Info node; switch back to Info proper."
  1883.   (interactive)
  1884.   ;; Do this first, so nothing has changed if user C-g's at query.
  1885.   (and (buffer-modified-p)
  1886.        (y-or-n-p "Save the file? ")
  1887.        (save-buffer))
  1888.   (use-local-map Info-mode-map)
  1889.   (setq major-mode 'Info-mode)
  1890.   (setq mode-name "Info")
  1891.   (Info-set-mode-line)
  1892.   (setq buffer-read-only t)
  1893.   ;; Make mode line update.
  1894.   (set-buffer-modified-p (buffer-modified-p))
  1895.   (and (marker-position Info-tag-table-marker)
  1896.        (buffer-modified-p)
  1897.        (message "Tags may have changed.  Use Info-tagify if necessary")))
  1898.  
  1899. (run-hooks 'Info-load-hook)
  1900.  
  1901. ;;; End.
  1902.