home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / packages / info.el < prev    next >
Encoding:
Text File  |  1995-08-31  |  82.6 KB  |  2,376 lines

  1. ;;; info.el --- info package for Emacs.
  2. ;; Keywords: help
  3.  
  4. ;; Copyright (C) 1985, 1986, 1993 Free Software Foundation, Inc.
  5.  
  6. ;; Author: Dave Gillespie <daveg@synaptics.com>
  7. ;;       Richard Stallman <rms@gnu.ai.mit.edu>
  8. ;; Maintainer: Dave Gillespie <daveg@synaptics.com>
  9. ;; Version: 1.07 of 7/22/93
  10.  
  11. ;; This file is part of XEmacs.
  12.  
  13. ;; XEmacs is free software; you can redistribute it and/or modify it
  14. ;; under the terms of the GNU General Public License as published by
  15. ;; the Free Software Foundation; either version 2, or (at your option)
  16. ;; any later version.
  17.  
  18. ;; XEmacs is distributed in the hope that it will be useful, but
  19. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  20. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  21. ;; General Public License for more details.
  22.  
  23. ;; You should have received a copy of the GNU General Public License
  24. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  25. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  26.  
  27. ;;; Synched up with: Not synched with FSF.
  28.  
  29. ;; Commentary:
  30.  
  31. ;; This is based on an early Emacs 19 info.el file.
  32. ;;
  33. ;; Note that Info-directory has been replaced by Info-directory-list,
  34. ;; a search path of directories in which to find Info files.
  35. ;; Also, Info tries adding ".info" to a file name if the name itself
  36. ;; is not found.
  37. ;;
  38. ;; See the change log below for further details.
  39.  
  40.  
  41. ;; LCD Archive Entry:
  42. ;; info-dg|Dave Gillespie|daveg@synaptics.com
  43. ;; |Info reader with many enhancements; replaces standard info.el.
  44. ;; |93-07-22|1.07|~/modes/info.el
  45.  
  46. ;; Also available from anonymous FTP on csvax.cs.caltech.edu.
  47.  
  48.  
  49. ;; Change Log:
  50.  
  51. ;; Modified 3/7/1991 by Dave Gillespie:
  52. ;; (Author's address: daveg@synaptics.com or daveg@csvax.cs.caltech.edu)
  53. ;;
  54. ;; Added keys:  i, t, <, >, [, ], {, }, 6, 7, 8, 9, 0.
  55. ;; Look at help for info-mode (type ? in Info) for descriptions.
  56. ;;
  57. ;; If Info-directory-list is undefined and there is no INFOPATH
  58. ;; in the environment, use value of Info-directory for compatibility
  59. ;; with Emacs 18.57.
  60. ;;
  61. ;; All files named "localdir" found in the path are appended to "dir",
  62. ;; the Info directory.  For this to work, "dir" should contain only
  63. ;; one node (Top), and each "localdir" should contain no ^_ or ^L
  64. ;; characters.  Generally they will contain only one or several
  65. ;; additional lines for the top-level menu.  Note that "dir" is
  66. ;; modified in memory each time it is loaded, but not on disk.
  67. ;;
  68. ;; If "dir" contains a line of the form:  "* Locals:"
  69. ;; then the "localdir"s are inserted there instead of at the end.
  70.  
  71.  
  72. ;; Modified 4/3/1991 by Dave Gillespie:
  73. ;;
  74. ;; Added Info-mode-hook (suggested by Sebastian Kremer).
  75. ;; Also added epoch-info-startup/select-hooks from Simon Spero's info.el.
  76. ;;
  77. ;; Added automatic decoding of compressed Info files.
  78. ;; See documentation for the variable Info-suffix-list.  Default is to
  79. ;; run "uncompress" on ".Z" files and "unyabba" on ".Y" files.
  80. ;; (See comp.sources.unix v24i073-076 for yabba/unyabba, a free software
  81. ;; alternative to compress/uncompress.)
  82. ;; Note: "dir" and "localdir" files should not be compressed.
  83. ;;
  84. ;; Changed variables like Info-enable-edit to be settable by M-x set-variable.
  85. ;;
  86. ;; Added Info-auto-advance variable.  If t, SPC and DEL will act like
  87. ;; } and {, i.e., they advance to the next/previous node if at the end
  88. ;; of the buffer.
  89. ;;
  90. ;; Changed `u' to restore point to most recent location in that node.
  91. ;; Added `=' to do this manually at any time.  (Suggested by David Fox).
  92. ;;
  93. ;; Changed `m' and `0-9' to try interpreting menu name as a file name
  94. ;; if not found as a node name.  This allows (dir) menus of the form,
  95. ;;     Emacs::        Cool text editor
  96. ;; as a shorthand for
  97. ;;     Emacs:(emacs).    Cool text editor
  98. ;;
  99. ;; Enhanced `i' to use line-number information in the index.
  100. ;; Added `,' to move among all matches to a previous `i' command.
  101. ;;
  102. ;; Added `a' (Info-annotate) for adding personal notes to any Info node.
  103. ;; Notes are not stored in the actual Info files, but in the user's own
  104. ;; ~/.infonotes file.
  105. ;;
  106. ;; Added Info-footnote-tag, made default be "Ref" instead of "Note".
  107. ;;
  108. ;; Got mouse-click stuff to work under Emacs version 18.  Check it out!
  109. ;; Left and right clicks scroll the Info window.
  110. ;; Middle click goes to clicked-on node, e.g., "Next:", a menu, or a note.
  111.  
  112.  
  113. ;; Modified 6/29/1991 by Dave Gillespie:
  114. ;;
  115. ;; Renamed epoch-info-startup/select-hooks to Info-startup/select-hook.
  116. ;;
  117. ;; Made Info-select-node into a command on the `!' key.
  118. ;;
  119. ;; Added Info-mouse-support user option.
  120. ;;
  121. ;; Cleaned up the implementation of some routines.
  122. ;;
  123. ;; Added special treatment of quoted words in annotations:  The `g'
  124. ;; command for a nonexistent node name scans for an annotation
  125. ;; (in any node of any file) containing that name in quotes:  g foo RET
  126. ;; looks for an annotation containing:  "foo"  or:  <<foo>>
  127. ;; If found, it goes to that file and node.
  128. ;;
  129. ;; Added a call to set up Info-directory-list in Info-find-node to
  130. ;; work around a bug in GNUS where it calls Info-goto-node before info.
  131. ;;
  132. ;; Added completion for `g' command (inspired by Richard Kim's infox.el).
  133. ;; Completion knows all node names for the current file, and all annotation
  134. ;; tags (see above).  It does not complete file names or node names in
  135. ;; other files.
  136. ;;
  137. ;; Added `k' (Info-emacs-key) and `*' (Info-elisp-ref) commands.  You may
  138. ;; wish to bind these to global keys outside of Info mode.
  139. ;;
  140. ;; Allowed localdir files to be full dir-like files; only the menu part
  141. ;; of each localdir is copied.  Also, redundant menu items are omitted.
  142. ;;
  143. ;; Changed Info-history to hold only one entry at a time for each node,
  144. ;; and to be circular so that multiple `l's come back again to the most
  145. ;; recent node.  Note that the format of Info-history entries has changed,
  146. ;; which may interfere with external programs that try to operate on it.
  147. ;; (Also inspired by Kim's infox.el).
  148. ;;
  149. ;; Changed `n', `]', `l', etc. to accept prefix arguments to move several
  150. ;; steps at once.  Most accept negative arguments to move oppositely.
  151. ;;
  152. ;; Changed `?' to bury *Help* buffer afterwards to keep it out of the way.
  153. ;;
  154. ;; Rearranged `?' key's display to be a little better for new users.
  155. ;;
  156. ;; Changed `a' to save whole window configuration and restore on C-c C-c.
  157. ;;
  158. ;; Fixed the bug reported by Bill Reynolds on gnu.emacs.bugs.
  159. ;;
  160. ;; Changed Info-last to restore window-start as well as cursor position.
  161. ;;
  162. ;; Changed middle mouse button in space after end of node to do Info-last
  163. ;; if we got here by following a cross reference, else do Info-global-next.
  164. ;;
  165. ;; Added some new mouse bindings: shift-left = Info-global-next,
  166. ;; shift-right = Info-global-prev, shift-middle = Info-last.
  167. ;;
  168. ;; Fixed Info-follow-reference not to make assumptions about length
  169. ;; of Info-footnote-tag [Linus Tolke].
  170. ;;
  171. ;; Changed default for Info-auto-advance mode to be press-twice-for-next-node.
  172. ;;
  173. ;; Modified x-mouse-ignore to preserve last-command variable, so that
  174. ;; press-twice Info-auto-advance mode works with the mouse.
  175.  
  176.  
  177. ;; Modified 3/4/1992 by Dave Gillespie:
  178. ;;
  179. ;; Added an "autoload" command to help autoload.el.
  180. ;;
  181. ;; Changed `*' command to look for file `elisp' as well as for `lispref'.
  182. ;;
  183. ;; Fixed a bug involving footnote names containing regexp special characters.
  184. ;;
  185. ;; Fixed a bug in completion during `f' (or `r') command.
  186. ;;
  187. ;; Added TAB (Info-next-reference), M-TAB, and RET keys to Info mode.
  188. ;;
  189. ;; Added new bindings, `C-h C-k' for Info-emacs-key and `C-h C-f' for
  190. ;; Info-elisp-ref.  These bindings are made when info.el is loaded, and
  191. ;; only if those key sequences were previously unbound.  These bindings
  192. ;; work at any time, not just when Info is already running.
  193.  
  194.  
  195. ;; Modified 3/8/1992 by Dave Gillespie:
  196. ;;
  197. ;; Fixed some long lines that were causing trouble with mailers.
  198.  
  199.  
  200. ;; Modified 3/9/1992 by Dave Gillespie:
  201. ;;
  202. ;; Added `C-h C-i' (Info-query).
  203. ;;
  204. ;; Added Info-novice mode, warns if the user attempts to switch to
  205. ;; a different Info file.
  206. ;;
  207. ;; Fixed a bug that caused problems using compressed Info files
  208. ;; and Info-directory-list at the same time.
  209. ;;
  210. ;; Disabled Info-mouse-support by default if Epoch or Hyperbole is in use.
  211. ;;
  212. ;; Added an expand-file-name call to Info-find-node to fix a small bug.
  213.  
  214.  
  215. ;; Modified 5/22/1992 by Dave Gillespie:
  216. ;;
  217. ;; Added "standalone" operation:  "emacs -f info" runs Emacs specifically
  218. ;; for use as an Info browser.  In this mode, the `q' key quits Emacs
  219. ;; itself.  Also, "emacs -f info arg" starts in Info file "arg" instead
  220. ;; of "dir".
  221. ;;
  222. ;; Changed to prefer "foo.info" over "foo".  If both exist, "foo" is
  223. ;; probably a directory or executable program!
  224. ;;
  225. ;; Made control-mouse act like regular-mouse does in other buffers.
  226. ;; (In most systems, this will be set-cursor for left-mouse, x-cut
  227. ;; for right-mouse, and x-paste, which will be an error, for
  228. ;; middle-mouse.)
  229. ;;
  230. ;; Improved prompting and searching for `,' key.
  231. ;;
  232. ;; Fixed a bug where some "* Menu:" lines disappeared when "dir"
  233. ;; contained several nodes.
  234.  
  235.  
  236. ;; Modified 9/10/1992 by Dave Gillespie:
  237. ;;
  238. ;; Mixed in support for XEmacs.  Mouse works the same as in
  239. ;; the other Emacs versions by default; added Info-lucid-mouse-style
  240. ;; variable, which enables mouse operation similar to XEmacs's default.
  241. ;;
  242. ;; Fixed a bug where RET couldn't understand "* Foo::" if "Foo" was a
  243. ;; file name instead of a node name.
  244. ;;
  245. ;; Added `x' (Info-bookmark), a simple interface to the annotation
  246. ;; tags feature.  Added `j' (Info-goto-bookmark), like `g' but only
  247. ;; completes bookmarks.
  248. ;;
  249. ;; Added `<<tag>>' as alternate to `"tag"' in annotations.
  250. ;;
  251. ;; Added `v' (Info-visit-file), like Info-goto-node but specialized
  252. ;; for going to a new Info file (with file name completion).
  253. ;;
  254. ;; Added recognition of gzip'd ".z" files.
  255.  
  256.  
  257. ;; Modified 5/9/1993 by Dave Gillespie:
  258. ;;
  259. ;; Merged in various things from FSF's latest Emacs 19 info.el.
  260. ;; Notably:  Added Info-default-directory-list.
  261.  
  262.  
  263. ;; Modified 6/2/1993 by Dave Gillespie:
  264. ;;
  265. ;; Changed to use new suffix ".gz" for gzip files.
  266.  
  267.  
  268. ;; Modified 7/22/1993 by Dave Gillespie:
  269. ;;
  270. ;; Changed Info-footnote-tag to "See" instead of "Ref".
  271. ;;
  272. ;; Extended Info-fontify-node to work with FSF version of Emacs 19.
  273.  
  274. ;; Modified 7/30/1993 by Jamie Zawinski:
  275. ;;
  276. ;; Commented out the tty and fsf19 mouse support, because why bother.
  277. ;; Commented out the politically incorrect version of XEmacs mouse support.
  278. ;; Commented out mouse scrolling bindings because the party line on that
  279. ;;  is "scrollbars are coming soon."
  280. ;; Commented out munging of help-for-help's doc; put it in help.el.
  281. ;; Did Info-edit-map the modern XEmacs way.
  282. ;; Pruned extra cruft from fontification and mouse handling code.
  283. ;; Fixed ASCII-centric bogosity in unreading of events.
  284.  
  285. ;; Modified 8/11/95 by Chuck Thompson:
  286. ;;
  287. ;; Removed any pretense of ever referencing Info-directory since it
  288. ;; wasn't working anyhow.
  289.  
  290. ;; Code:
  291.  
  292. (defvar Info-inhibit-toolbar nil
  293.   "*Non-nil means don't use the specialized Info toolbar.")
  294.  
  295. (defvar Info-novice nil
  296.   "*Non-nil means to ask for confirmation before switching Info files.")
  297.  
  298. (defvar Info-history nil
  299.   "List of info nodes user has visited.
  300. Each element of list is a list (\"(FILENAME)NODENAME\" BUFPOS WINSTART).")
  301.  
  302. (defvar Info-keeping-history t
  303.   "Non-nil if Info-find-node should modify Info-history.
  304. This is for use only by certain internal Info routines.")
  305.  
  306. (defvar Info-enable-edit nil
  307.   "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info
  308. can edit the current node.
  309. This is convenient if you want to write info files by hand.
  310. However, we recommend that you not do this.
  311. It is better to write a Texinfo file and generate the Info file from that,
  312. because that gives you a printed manual as well.")
  313.  
  314. (defvar Info-enable-active-nodes t
  315.   "*Non-nil allows Info to execute Lisp code associated with nodes.
  316. The Lisp code is executed when the node is selected.")
  317.  
  318. (defvar Info-restoring-point t
  319.   "*Non-nil means to restore the cursor position when re-entering a node.")
  320.  
  321. (defvar Info-auto-advance 'twice
  322.   "*Control what SPC and DEL do when they can't scroll any further.
  323. If nil, they beep and remain in the current node.
  324. If t, they move to the next node (like Info-global-next/prev).
  325. If anything else, they must be pressed twice to move to the next node.")
  326.  
  327. (defvar Info-fontify t
  328.   "*Non-nil enables font features in XEmacs.
  329. This variable is ignored unless running under XEmacs.")
  330.  
  331. (defvar Info-default-directory-list nil
  332.   "List of default directories to search for Info documentation files.
  333. This value is used as the default for `Info-directory-list'.  It is set
  334. in startup.el.")
  335.  
  336. (defvar Info-directory-list
  337.   (let ((path (getenv "INFOPATH")))
  338.     (if path
  339.     (let ((list nil)
  340.            idx)
  341.       (while (> (length path) 0)
  342.         (setq idx (or (string-match ":" path) (length path))
  343.           list (cons (substring path 0 idx) list)
  344.           path (substring path (min (1+ idx)
  345.                         (length path)))))
  346.       (nreverse list))
  347.       Info-default-directory-list))
  348.   "List of directories to search for Info documentation files.
  349. Default is to use the environment variable INFOPATH if it exists,
  350. else to use Info-default-directory-list.")
  351.  
  352. (defvar Info-suffix-list '( (".info" . nil)
  353.                 (".info.gz" . "gzip -dc %s")
  354.                 (".info-z" . "gzip -dc %s")
  355.                 (".info.Z" . "uncompress -c %s")
  356.                 (".gz" . "gzip -dc %s")
  357.                 (".Z" . "uncompress -c %s") )
  358.   "List of file name suffixes and associated decoding commands.
  359. Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
  360. changed to name of the file to decode, otherwise the file is given to
  361. the command as standard input.  If STRING is nil, no decoding is done.")
  362.  
  363. (defvar Info-footnote-tag "See"
  364.   "*Symbol that identifies a footnote or cross-reference.
  365. All \"*Note\" references will be changed to use this word instead.")
  366.  
  367. (defvar Info-current-file nil
  368.   "Info file that Info is now looking at, or nil.")
  369.  
  370. (defvar Info-current-subfile nil
  371.   "Info subfile that is actually in the *info* buffer now,
  372. or nil if current info file is not split into subfiles.")
  373.  
  374. (defvar Info-current-node nil
  375.   "Name of node that Info is now looking at, or nil.")
  376.  
  377. (defvar Info-tag-table-marker (make-marker)
  378.   "Marker pointing at beginning of current Info file's tag table.
  379. Marker points nowhere if file has no tag table.")
  380.  
  381. (defvar Info-current-file-completions nil
  382.   "Cached completion list for current Info file.")
  383.  
  384. (defvar Info-current-annotation-completions nil
  385.   "Cached completion list for current annotation files.")
  386.  
  387. (defvar Info-index-alternatives nil
  388.   "List of possible matches for last Info-index command.")
  389. (defvar Info-index-first-alternative nil)
  390.  
  391. (defvar Info-annotations-path '("~/.infonotes" "/usr/lib/info.notes")
  392.   "*Names of files that contain annotations for different Info nodes.
  393. By convention, the first one should reside in your personal directory.
  394. The last should be a world-writable \"public\" annotations file.")
  395.  
  396. (defvar Info-standalone nil
  397.   "Non-nil if Emacs was started solely as an Info browser.")
  398.  
  399. (defvar Info-in-cross-reference nil)
  400. (defvar Info-window-configuration nil)
  401.  
  402. ;;;###autoload
  403. (defun info (&optional file)
  404.   "Enter Info, the documentation browser.
  405. Optional argument FILE specifies the file to examine;
  406. the default is the top-level directory of Info.
  407.  
  408. In interactive use, a prefix argument directs this command
  409. to read a file name from the minibuffer."
  410.   (interactive (if current-prefix-arg
  411.            (list (read-file-name "Info file name: " nil nil t))))
  412.   (let ((p command-line-args))
  413.     (while p
  414.       (and (string-match "^-[fe]" (car p))
  415.        (equal (nth 1 p) "info")
  416.        (not Info-standalone)
  417.        (setq Info-standalone t)
  418.        (= (length p) 3)
  419.        (not (string-match "^-" (nth 2 p)))
  420.        (setq file (nth 2 p))
  421.        (setq command-line-args-left nil))
  422.       (setq p (cdr p))))
  423. ;  (Info-setup-x)
  424.   (if file
  425.       (unwind-protect
  426.       (Info-goto-node (concat "(" file ")"))
  427.     (and Info-standalone (info)))
  428.     (if (get-buffer "*info*")
  429.     (switch-to-buffer "*info*")
  430.       (Info-directory))))
  431.  
  432. ;;;###autoload
  433. (defun Info-query (file)
  434.   "Enter Info, the documentation browser.  Prompt for name of Info file."
  435.   (interactive "sInfo topic (default = menu): ")
  436.   (info)
  437.   (if (equal file "")
  438.       (Info-goto-node "(dir)")
  439.     (Info-goto-node (concat "(" file ")"))))
  440.  
  441. (defun Info-setup-initial ()
  442.   (let ((f Info-annotations-path))
  443.     (while f
  444.       (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
  445.       (bury-buffer (find-file-noselect (car f))))
  446.       (setq f (cdr f)))))
  447.  
  448. (defconst Info-emacs-info-file-name "xemacs")
  449.  
  450. ;; Go to an info node specified as separate filename and nodename.
  451. ;; no-going-back is non-nil if recovering from an error in this function;
  452. ;; it says do not attempt further (recursive) error recovery.
  453. (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
  454.   ;; Look for a plausible filename, or if not found then look for URls
  455.   ;; &c, and dispatch to the appropriate fn.
  456.  
  457.   (Info-setup-initial)
  458.  
  459.   (cond 
  460.    ;; empty filename is simple case
  461.    ((null filename)
  462.     (Info-find-file-node nil nodename no-going-back tryfile line))
  463.    ;; Convert filename to lower case if not found as specified.
  464.    ;; Expand it, look harder...
  465.    ((let (temp temp-downcase found 
  466.            (fname (substitute-in-file-name filename)))
  467.       ;; horrible kludge so that I can call the emacs doc
  468.       ;; "XEmacs" without having to make .../info/dir be ugly.
  469.       ;; I'd like to do this only if the "emacs" node wasn't
  470.       ;; found, but this 200+ line function is too hairy for me
  471.       ;; to want to think about any longer than I have to.
  472.       (if (equal (downcase fname) "emacs")
  473.       (setq fname Info-emacs-info-file-name))
  474.       (let ((dirs (if (string-match "^\\./" fname)
  475.               ;; If specified name starts with `./'
  476.               ;; then just try current directory.
  477.               (list default-directory) ; '("./")
  478.             Info-directory-list)))
  479.     ;; Search the directory list for file FNAME.
  480.     (while (and dirs (not found))
  481.       (setq temp (expand-file-name fname (car dirs)))
  482.       (setq temp-downcase
  483.         (expand-file-name (downcase fname) (car dirs)))
  484.       (if (equal temp-downcase temp) (setq temp-downcase nil))
  485.       ;; Try several variants of specified name.
  486.       ;; Try downcasing, appending a suffix, or both.
  487.       (setq found (Info-suffixed-file temp temp-downcase))
  488.       (setq dirs (cdr dirs)))
  489.     (if found 
  490.         (progn (setq filename (expand-file-name found))
  491.            t))))
  492.     (Info-find-file-node filename nodename no-going-back tryfile line))
  493.    ;; Look for a URL.  This pattern is stolen from w3.el to prevent
  494.    ;; loading it if we won't need it.
  495.    ((string-match  "^\\(wais\\|solo\\|x-exec\\|newspost\\|www\\|mailto\\|news\\|tn3270\\|ftp\\|http\\|file\\|telnet\\|gopher\\):" filename)
  496.     (w3-fetch filename))
  497.    (t
  498.     (error "Info file %s does not exist" filename))))
  499.  
  500. (defun Info-find-file-node (filename nodename 
  501.                      &optional no-going-back tryfile line)
  502.   ;; This is the guts of what was Info-find-node. Whoever wrote this
  503.   ;; should be locked up where they can't do any more harm.
  504.  
  505.   ;; Go into info buffer.
  506.   (switch-to-buffer "*info*")
  507.   (if (fboundp 'buffer-disable-undo)
  508.       (buffer-disable-undo (current-buffer)))
  509.   (run-hooks 'Info-startup-hook)
  510.   (or (eq major-mode 'Info-mode)
  511.       (Info-mode))
  512.   (or (null filename)
  513.       (equal Info-current-file filename)
  514.       (not Info-novice)
  515.       (string-match "^dir$" (file-name-nondirectory Info-current-file))
  516.       (if (y-or-n-p (format "Leave Info file `%s'? "
  517.                 (file-name-nondirectory Info-current-file)))
  518.       (message "")
  519.     (keyboard-quit)))
  520.   ;; Record the node we are leaving.
  521.   (if (and Info-current-file (not no-going-back))
  522.       (Info-history-add Info-current-file Info-current-node (point)))
  523.   (widen)
  524.   (setq Info-current-node nil
  525.     Info-in-cross-reference nil)
  526.   (unwind-protect
  527.       (progn
  528.     ;; Switch files if necessary
  529.     (or (null filename)
  530.         (equal Info-current-file filename)
  531.         (let ((buffer-read-only nil))
  532.           (setq Info-current-file nil
  533.             Info-current-subfile nil
  534.             Info-index-alternatives nil
  535.             Info-current-file-completions nil
  536.             buffer-file-name nil)
  537.           (erase-buffer)
  538.           (Info-insert-file-contents filename t)
  539.           ;; Add all "localdir" files in search path to "dir" file.
  540.           (if (string-match "^dir$" (file-name-nondirectory filename))
  541.           (let ((d Info-directory-list)
  542.             name (lim -1))
  543.             (goto-char (point-max))
  544.             (if (re-search-backward "^ *\\* *Locals *: *\n" nil t)
  545.             (delete-region (match-beginning 0) (match-end 0))
  546.               (search-backward "\^L" nil t))
  547.             (while d
  548.               (setq name (expand-file-name "localdir" (car d)))
  549.               (if (or (file-exists-p name)
  550.                   (file-exists-p
  551.                    (setq name (concat name ".info"))))
  552.               ;; Insert menu part of the file
  553.               (let* ((pt (point))
  554.                  (len (nth 1 (insert-file-contents name))))
  555.                 ;; be careful to put the local info entries
  556.                 ;; in the buffer in the order they were found
  557.                 ;; in the search path.
  558.                 (goto-char (+ pt len))
  559.                 (save-excursion
  560.                   (goto-char pt)
  561.                   (if (search-forward "* menu:" (+ pt len) t)
  562.                   (progn
  563.                     (forward-line 1)
  564.                     (delete-region pt (point)))))))
  565.               (setq d (cdr d)))
  566.             ;; Eliminate redundant menu entries.
  567.             (goto-char (point-min))
  568.             (while (re-search-forward "\n\\* \\([^:\n]*\\):" nil t)
  569.               (let ((str (buffer-substring (match-beginning 1)
  570.                            (match-end 1))))
  571.             (if (> (point) lim)
  572.                 (save-excursion
  573.                   (setq lim (if (search-forward "\^_" nil t)
  574.                         (point)
  575.                       (point-max)))))
  576.             (save-excursion
  577.               (if (search-forward (format "\n* %s:" str) lim t)
  578.                   (let ((pt (- (point) 3 (length str))))
  579.                 (forward-line 1)
  580.                 (delete-region pt (point)))))))))
  581.           (set-buffer-modified-p nil)
  582.           (setq default-directory (file-name-directory filename))
  583.           ;; See whether file has a tag table.  Record the location if yes.
  584.           (set-marker Info-tag-table-marker nil)
  585.           (goto-char (point-max))
  586.           (forward-line -8)
  587.           (or (equal nodename "*")
  588.           (not (search-forward "\^_\nEnd tag table\n" nil t))
  589.           (let (pos)
  590.             ;; We have a tag table.  Find its beginning.
  591.             ;; Is this an indirect file?
  592.             (search-backward "\nTag table:\n")
  593.             (setq pos (point))
  594.             (if (save-excursion
  595.               (forward-line 2)
  596.               (looking-at "(Indirect)\n"))
  597.             ;; It is indirect.  Copy it to another buffer
  598.             ;; and record that the tag table is in that buffer.
  599.             (save-excursion
  600.               (let ((buf (current-buffer)))
  601.                 (set-buffer
  602.                  (get-buffer-create " *info tag table*"))
  603.                 (if (fboundp 'buffer-disable-undo)
  604.                 (buffer-disable-undo (current-buffer)))
  605.                 (setq case-fold-search t)
  606.                 (erase-buffer)
  607.                 (insert-buffer-substring buf)
  608.                 (set-marker Info-tag-table-marker
  609.                     (match-end 0))))
  610.              (set-marker Info-tag-table-marker pos))))
  611.           (setq Info-current-file
  612.             (file-name-sans-versions buffer-file-name))))
  613.     (if (equal nodename "*")
  614.         (progn (setq Info-current-node nodename)
  615.            (Info-set-mode-line)
  616.            (goto-char (point-min)))
  617.       ;; Search file for a suitable node.
  618.       (let* ((qnode (regexp-quote nodename))
  619.          (regexp (concat "Node: *" qnode " *[,\t\n\177]"))
  620.          (guesspos (point-min))
  621.          (found t))
  622.         ;; First get advice from tag table if file has one.
  623.         ;; Also, if this is an indirect info file,
  624.         ;; read the proper subfile into this buffer.
  625.         (if (marker-position Info-tag-table-marker)
  626.         (save-excursion
  627.           (set-buffer (marker-buffer Info-tag-table-marker))
  628.           (goto-char Info-tag-table-marker)
  629.           (if (re-search-forward regexp nil t)
  630.               (progn
  631.             (setq guesspos (read (current-buffer)))
  632.             ;; If this is an indirect file,
  633.             ;; determine which file really holds this node
  634.             ;; and read it in.
  635.             (if (not (eq (current-buffer) (get-buffer "*info*")))
  636.                 (setq guesspos
  637.                   (Info-read-subfile guesspos)))))))
  638.         (goto-char (max (point-min) (- guesspos 1000)))
  639.         ;; Now search from our advised position (or from beg of buffer)
  640.         ;; to find the actual node.
  641.         (catch 'foo
  642.           (while (search-forward "\n\^_" nil t)
  643.         (forward-line 1)
  644.         (let ((beg (point)))
  645.           (forward-line 1)
  646.           (if (re-search-backward regexp beg t)
  647.               (throw 'foo t))))
  648.           (setq found nil)
  649.           (let ((bufs (delq nil (mapcar 'get-file-buffer
  650.                         Info-annotations-path)))
  651.             (pattern (if (string-match "\\`<<.*>>\\'" qnode) qnode
  652.                    (format "\"%s\"\\|<<%s>>" qnode qnode)))
  653.             (pat2 (concat "------ *File: *\\([^ ].*[^ ]\\) *Node: "
  654.                   "*\\([^ ].*[^ ]\\) *Line: *\\([0-9]+\\)"))
  655.             (afile nil) anode aline)
  656.         (while (and bufs (not anode))
  657.           (save-excursion
  658.             (set-buffer (car bufs))
  659.             (goto-char (point-min))
  660.             (if (re-search-forward pattern nil t)
  661.             (if (re-search-backward pat2 nil t)
  662.                 (setq afile (buffer-substring (match-beginning 1)
  663.                               (match-end 1))
  664.                   anode (buffer-substring (match-beginning 2)
  665.                               (match-end 2))
  666.                   aline (string-to-int
  667.                      (buffer-substring (match-beginning 3)
  668.                                (match-end 3)))))))
  669.           (setq bufs (cdr bufs)))
  670.         (if anode
  671.             (Info-find-node afile anode t nil aline)
  672.           (if tryfile
  673.               (condition-case nil
  674.               (Info-find-node nodename "Top" t)
  675.             (error nil)))))
  676.           (or Info-current-node
  677.           (error "No such node: %s" nodename)))
  678.         (if found
  679.         (progn
  680.           (Info-select-node)
  681.           (goto-char (point-min))
  682.           (if line (forward-line line)))))))
  683.     ;; If we did not finish finding the specified node,
  684.     ;; go back to the previous one.
  685.     (or Info-current-node no-going-back
  686.     (let ((hist (car Info-history)))
  687.       ;; The following is no longer safe with new Info-history system
  688.       ;; (setq Info-history (cdr Info-history))
  689.       (Info-goto-node (car hist) t)
  690.       (goto-char (+ (point-min) (nth 1 hist)))))))
  691.  
  692. (defun Info-history-add (file node point)
  693.   (if Info-keeping-history
  694.       (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
  695.          (found (assoc name Info-history)))
  696.     (if found
  697.         (setq Info-history (delq found Info-history)))
  698.     (setq Info-history (cons (list name (- point (point-min))
  699.                        (and (eq (window-buffer)
  700.                         (current-buffer))
  701.                         (- (window-start) (point-min))))
  702.                  Info-history)))))
  703.  
  704. (defun Info-file-name-only (file)
  705.   (let ((dir (file-name-directory file))
  706.     (p Info-directory-list))
  707.     (while (and p (not (equal (car p) dir)))
  708.       (setq p (cdr p)))
  709.     (if p (file-name-nondirectory file) file)))
  710.  
  711. (defun Info-read-subfile (nodepos)
  712.   (set-buffer (marker-buffer Info-tag-table-marker))
  713.   (goto-char (point-min))
  714.   (search-forward "\n\^_")
  715.   (let (lastfilepos
  716.     lastfilename)
  717.     (forward-line 2)
  718.     (catch 'foo
  719.       (while (not (looking-at "\^_"))
  720.     (if (not (eolp))
  721.         (let ((beg (point))
  722.           thisfilepos thisfilename)
  723.           (search-forward ": ")
  724.           (setq thisfilename  (buffer-substring beg (- (point) 2)))
  725.           (setq thisfilepos (read (current-buffer)))
  726.           ;; read in version 19 stops at the end of number.
  727.           ;; Advance to the next line.
  728.           (if (eolp)
  729.           (forward-line 1))
  730.           (if (> thisfilepos nodepos)
  731.           (throw 'foo t))
  732.           (setq lastfilename thisfilename)
  733.           (setq lastfilepos thisfilepos))
  734.       (throw 'foo t))))
  735.     (set-buffer (get-buffer "*info*"))
  736.     (or (equal Info-current-subfile lastfilename)
  737.     (let ((buffer-read-only nil))
  738.       (setq buffer-file-name nil)
  739.       (widen)
  740.       (erase-buffer)
  741.       (Info-insert-file-contents (Info-suffixed-file
  742.                       (expand-file-name lastfilename
  743.                             (file-name-directory
  744.                              Info-current-file)))
  745.                      t)
  746.       (set-buffer-modified-p nil)
  747.       (setq Info-current-subfile lastfilename)))
  748.     (goto-char (point-min))
  749.     (search-forward "\n\^_")
  750.     (+ (- nodepos lastfilepos) (point))))
  751.  
  752. (defun Info-suffixed-file (name &optional name2)
  753.   (let ((suff Info-suffix-list)
  754.     (found nil))
  755.     (while (and suff (not found))
  756.       (if (file-exists-p (concat name (car (car suff))))
  757.       (setq found (concat name (car (car suff))))
  758.     (if (and name2 (file-exists-p (concat name2 (car (car suff)))))
  759.         (setq found (concat name2 (car (car suff))))
  760.       (setq suff (cdr suff)))))
  761.     (or found
  762.     (and (file-exists-p name) name)
  763.     (and name2 (file-exists-p name2) name2))))
  764.  
  765. (defun Info-insert-file-contents (file &optional visit)
  766.   (setq file (expand-file-name file default-directory))
  767.   (let ((suff Info-suffix-list))
  768.     (while (and suff (or (<= (length file) (length (car (car suff))))
  769.              (not (equal (substring file
  770.                         (- (length (car (car suff)))))
  771.                      (car (car suff))))))
  772.       (setq suff (cdr suff)))
  773.     (if (stringp (cdr (car suff)))
  774.     (let ((command (if (string-match "%s" (cdr (car suff)))
  775.                (format (cdr (car suff)) file)
  776.              (concat (cdr (car suff)) " < " file))))
  777.       (message "%s..." command)
  778.       (if (eq system-type 'vax-vms)
  779.           (call-process command nil t nil)
  780.         (call-process shell-file-name nil t nil "-c" command))
  781.       (message "")
  782.       (if visit
  783.           (progn
  784.         (setq buffer-file-name file)
  785.         (set-buffer-modified-p nil)
  786.         (clear-visited-file-modtime))))
  787.       (insert-file-contents file visit))))
  788.  
  789. (defun Info-select-node ()
  790.   "Select the node that point is in, after using `g *' to select whole file."
  791.   (interactive)
  792.   (widen)
  793.   (save-excursion
  794.    ;; Find beginning of node.
  795.    (search-backward "\n\^_")
  796.    (forward-line 2)
  797.    ;; Get nodename spelled as it is in the node.
  798.    (re-search-forward "Node:[ \t]*")
  799.    (setq Info-current-node
  800.      (buffer-substring (point)
  801.                (progn
  802.                 (skip-chars-forward "^,\t\n")
  803.                 (point))))
  804.    (Info-set-mode-line)
  805.    ;; Find the end of it, and narrow.
  806.    (beginning-of-line)
  807.    (let (active-expression)
  808.      (narrow-to-region (point)
  809.                (if (re-search-forward "\n[\^_\f]" nil t)
  810.                (prog1
  811.                 (1- (point))
  812.                 (if (looking-at "[\n\^_\f]*execute: ")
  813.                 (progn
  814.                   (goto-char (match-end 0))
  815.                   (setq active-expression
  816.                     (read (current-buffer))))))
  817.              (point-max)))
  818.      (or (equal Info-footnote-tag "Note")
  819.      (progn
  820.        (goto-char (point-min))
  821.        (let ((buffer-read-only nil)
  822.          (bufmod (buffer-modified-p))
  823.          (case-fold-search t))
  824.          (while (re-search-forward "\\*Note\\([ \n]\\)" nil t)
  825.            (replace-match (concat "*" Info-footnote-tag "\ ")))
  826.          (set-buffer-modified-p bufmod))))
  827.      (Info-reannotate-node)
  828.      (and (string-match "^19" emacs-version)
  829.       Info-fontify
  830.       (Info-fontify-node))
  831.      (run-hooks 'Info-select-hook)
  832.      (if Info-enable-active-nodes (eval active-expression)))))
  833.  
  834. (defun Info-set-mode-line ()
  835.   (setq modeline-buffer-identification
  836.     (concat
  837.      "Info:  ("
  838.      (if Info-current-file
  839.          (let ((name (file-name-nondirectory Info-current-file)))
  840.            (if (string-match "\\.info$" name)
  841.            (substring name 0 -5)
  842.          name))
  843.        "")
  844.      ")"
  845.      (or Info-current-node ""))))
  846.  
  847. ;; Go to an info node specified with a filename-and-nodename string
  848. ;; of the sort that is found in pointers in nodes.
  849.  
  850. (defun Info-goto-node (nodename &optional no-going-back tryfile)
  851.   "Go to info node named NAME.  Give just NODENAME or (FILENAME)NODENAME.
  852. Actually, the following interpretations of NAME are tried in order:
  853.     (FILENAME)NODENAME
  854.     (FILENAME)     (using Top node)
  855.     NODENAME       (in current file)
  856.     TAGNAME        (see below)
  857.     FILENAME       (using Top node)
  858. where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
  859. annotation for any node of any file.  (See `a' and `x' commands.)"
  860.   (interactive (list (Info-read-node-name "Goto node, file or tag: ")
  861.              nil t))
  862.   (let (filename)
  863.     (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
  864.           nodename)
  865.     (setq filename (if (= (match-beginning 1) (match-end 1))
  866.                ""
  867.              (substring nodename (match-beginning 2) (match-end 2)))
  868.       nodename (substring nodename (match-beginning 3) (match-end 3)))
  869.     (let ((trim (string-match "\\s *\\'" filename)))
  870.       (if trim (setq filename (substring filename 0 trim))))
  871.     (let ((trim (string-match "\\s *\\'" nodename)))
  872.       (if trim (setq nodename (substring nodename 0 trim))))
  873.     (Info-find-node (if (equal filename "") nil filename)
  874.             (if (equal nodename "") "Top" nodename)
  875.             no-going-back (and tryfile (equal filename "")))))
  876.  
  877. (defun Info-goto-bookmark ()
  878.   (interactive)
  879.   
  880.   (let ((completion-ignore-case nil)
  881.     (tag (completing-read "Goto tag: "
  882.                   (Info-build-annotation-completions)
  883.                   nil t)))
  884.     (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
  885.  
  886. (defun Info-visit-file ()
  887.   "Directly visit an info file."
  888.   (interactive)
  889.   (let* ((insert-default-directory nil)
  890.      (file (read-file-name "Goto Info file: " "" "")))
  891.     (or (equal file "") (Info-find-node (expand-file-name file) "Top"))))
  892.  
  893. (defun Info-restore-point (&optional always)
  894.   "Restore point to same location it had last time we were in this node."
  895.   (interactive "p")
  896.   (if (or Info-restoring-point always)
  897.       (let* ((name (format "(%s)%s"
  898.                (Info-file-name-only Info-current-file)
  899.                Info-current-node))
  900.          (p (assoc name Info-history)))
  901.     (if p (Info-restore-history-entry p)))))
  902.  
  903. (defun Info-restore-history-entry (entry)
  904.   (goto-char (+ (nth 1 entry) (point-min)))
  905.   (and (nth 2 entry)
  906.        (get-buffer-window (current-buffer))
  907.        (set-window-start (get-buffer-window (current-buffer))
  908.              (+ (nth 2 entry) (point-min)))))
  909.  
  910. (defun Info-read-node-name (prompt &optional default)
  911.   (Info-setup-initial)
  912.   (let* ((completion-ignore-case t)
  913.      (nodename (completing-read prompt (Info-build-node-completions))))
  914.     (if (equal nodename "")
  915.     (or default
  916.         (Info-read-node-name prompt))
  917.       nodename)))
  918.  
  919. (defun Info-build-annotation-completions ()
  920.   (or Info-current-annotation-completions
  921.       (save-excursion
  922.     (let ((bufs (delq nil (mapcar 'get-file-buffer
  923.                       Info-annotations-path)))
  924.           (compl nil))
  925.       (while bufs
  926.         (set-buffer (car bufs))
  927.         (goto-char (point-min))
  928.         (while (re-search-forward "<<\\(.*\\)>>" nil t)
  929.           (setq compl (cons (list (buffer-substring (match-beginning 1)
  930.                             (match-end 1)))
  931.                 compl)))
  932.         (setq bufs (cdr bufs)))
  933.       (setq Info-current-annotation-completions compl)))))
  934.  
  935. (defun Info-build-node-completions ()
  936.   (or Info-current-file-completions
  937.       (let ((compl (Info-build-annotation-completions)))
  938.     (save-excursion
  939.       (save-restriction
  940.         (if (marker-buffer Info-tag-table-marker)
  941.         (progn
  942.           (set-buffer (marker-buffer Info-tag-table-marker))
  943.           (goto-char Info-tag-table-marker)
  944.           (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
  945.             (setq compl
  946.               (cons (list (buffer-substring (match-beginning 1)
  947.                             (match-end 1)))
  948.                 compl))))
  949.           (widen)
  950.           (goto-char (point-min))
  951.           (while (search-forward "\n\^_" nil t)
  952.         (forward-line 1)
  953.         (let ((beg (point)))
  954.           (forward-line 1)
  955.           (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
  956.                       beg t)
  957.               (setq compl 
  958.                 (cons (list (buffer-substring (match-beginning 1)
  959.                               (match-end 1)))
  960.                   compl))))))))
  961.     (setq Info-current-file-completions compl))))
  962.  
  963. (defvar Info-last-search nil
  964.   "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
  965.  
  966. (defun Info-search (regexp)
  967.   "Search for REGEXP, starting from point, and select node it's found in."
  968.   (interactive "sSearch (regexp): ")
  969.   (if (equal regexp "")
  970.       (setq regexp Info-last-search)
  971.     (setq Info-last-search regexp))
  972.   (let ((found ())
  973.     (onode Info-current-node)
  974.     (ofile Info-current-file)
  975.     (opoint (point))
  976.     (osubfile Info-current-subfile))
  977.     (save-excursion
  978.       (save-restriction
  979.     (widen)
  980.     (if (null Info-current-subfile)
  981.         (progn (re-search-forward regexp) (setq found (point)))
  982.       (condition-case nil
  983.           (progn (re-search-forward regexp) (setq found (point)))
  984.         (search-failed nil)))))
  985.     (if (not found) ;can only happen in subfile case -- else would have erred
  986.     (unwind-protect
  987.         (let ((list ()))
  988.           (set-buffer (marker-buffer Info-tag-table-marker))
  989.           (goto-char (point-min))
  990.           (search-forward "\n\^_\nIndirect:")
  991.           (save-restriction
  992.         (narrow-to-region (point)
  993.                   (progn (search-forward "\n\^_")
  994.                      (1- (point))))
  995.         (goto-char (point-min))
  996.         (search-forward (concat "\n" osubfile ": "))
  997.         (beginning-of-line)
  998.         (while (not (eobp))
  999.           (re-search-forward "\\(^.*\\): [0-9]+$")
  1000.           (goto-char (+ (match-end 1) 2))
  1001.           (setq list (cons (cons (read (current-buffer))
  1002.                      (buffer-substring (match-beginning 1)
  1003.                                (match-end 1)))
  1004.                    list))
  1005.           (goto-char (1+ (match-end 0))))
  1006.         (setq list (nreverse list)
  1007.               list (cdr list)))
  1008.           (while list
  1009.         (message "Searching subfile %s..." (cdr (car list)))
  1010.         (Info-read-subfile (car (car list)))
  1011.         (setq list (cdr list))
  1012.         (goto-char (point-min))
  1013.         (if (re-search-forward regexp nil t)
  1014.             (setq found (point) list ())))
  1015.           (if found
  1016.           (message "")
  1017.         (signal 'search-failed (list regexp))))
  1018.       (if (not found)
  1019.           (progn (Info-read-subfile opoint)
  1020.              (goto-char opoint)
  1021.              (Info-select-node)))))
  1022.     (widen)
  1023.     (goto-char found)
  1024.     (Info-select-node)
  1025.     (or (and (equal onode Info-current-node)
  1026.          (equal ofile Info-current-file))
  1027.     (Info-history-add ofile onode opoint))))
  1028.  
  1029. ;; Extract the value of the node-pointer named NAME.
  1030. ;; If there is none, use ERRORNAME in the error message; 
  1031. ;; if ERRORNAME is nil, just return nil.
  1032. (defun Info-extract-pointer (name &optional errorname)
  1033.   (save-excursion
  1034.    (goto-char (point-min))
  1035.    (forward-line 1)
  1036.    (let ((case-fold-search t))
  1037.      (if (re-search-backward (concat name ":") nil t)
  1038.      (progn
  1039.        (goto-char (match-end 0))
  1040.        (Info-following-node-name))
  1041.        (if (eq errorname t)
  1042.        nil
  1043.      (error (concat "Node has no " (capitalize (or errorname name)))))))))
  1044.  
  1045. ;; Return the node name in the buffer following point.
  1046. ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
  1047. ;; saying which chas may appear in the node name.
  1048. (defun Info-following-node-name (&optional allowedchars)
  1049.   (skip-chars-forward " \t")
  1050.   (buffer-substring
  1051.    (point)
  1052.    (progn
  1053.      (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
  1054.        (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
  1055.        (if (looking-at "(")
  1056.        (skip-chars-forward "^)")))
  1057.      (skip-chars-backward " ")
  1058.      (point))))
  1059.  
  1060. (defun Info-next (&optional n)
  1061.   "Go to the next node of this node.
  1062. A positive or negative prefix argument moves by multiple nodes."
  1063.   (interactive "p")
  1064.   (or n (setq n 1))
  1065.   (if (< n 0)
  1066.       (Info-prev (- n))
  1067.     (while (>= (setq n (1- n)) 0)
  1068.       (Info-goto-node (Info-extract-pointer "next")))))
  1069.  
  1070. (defun Info-prev (&optional n)
  1071.   "Go to the previous node of this node.
  1072. A positive or negative prefix argument moves by multiple nodes."
  1073.   (interactive "p")
  1074.   (or n (setq n 1))
  1075.   (if (< n 0)
  1076.       (Info-next (- n))
  1077.     (while (>= (setq n (1- n)) 0)
  1078.       (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
  1079.  
  1080. (defun Info-up (&optional n)
  1081.   "Go to the superior node of this node.
  1082. A positive prefix argument moves up several times."
  1083.   (interactive "p")
  1084.   (or n (setq n 1))
  1085.   (while (>= (setq n (1- n)) 0)
  1086.     (Info-goto-node (Info-extract-pointer "up")))
  1087.   (if (interactive-p) (Info-restore-point)))
  1088.  
  1089. (defun Info-last (&optional n)
  1090.   "Go back to the last node visited.
  1091. With a prefix argument, go to Nth most recently visited node.  History is
  1092. circular; after oldest node, history comes back around to most recent one.
  1093. Argument can be negative to go through the circle in the other direction.
  1094. \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
  1095.   (interactive "p")
  1096.   (or n (setq n 1))
  1097.   (or Info-history
  1098.       (error "This is the first Info node you looked at"))
  1099.   (let ((len (1+ (length Info-history))))
  1100.     (setq n (% (+ n (* len 100)) len)))
  1101.   (if (> n 0)
  1102.       (let ((entry (nth (1- n) Info-history)))
  1103.     (Info-history-add Info-current-file Info-current-node (point))
  1104.     (while (>= (setq n (1- n)) 0)
  1105.       (setq Info-history (nconc (cdr Info-history)
  1106.                     (list (car Info-history)))))
  1107.     (setq Info-history (cdr Info-history))
  1108.     (let ((Info-keeping-history nil))
  1109.       (Info-goto-node (car entry)))
  1110.     (Info-restore-history-entry entry))))
  1111.  
  1112. (defun Info-directory ()
  1113.   "Go to the Info directory node."
  1114.   (interactive)
  1115.   (Info-find-node "dir" "top"))
  1116.  
  1117. (defun Info-follow-reference (footnotename)
  1118.   "Follow cross reference named NAME to the node it refers to.
  1119. NAME may be an abbreviation of the reference name."
  1120.   (interactive
  1121.    (let ((completion-ignore-case t)
  1122.      completions default (start-point (point)) str i)
  1123.      (save-excursion
  1124.        (goto-char (point-min))
  1125.        (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
  1126.                      Info-footnote-tag)
  1127.                  nil t)
  1128.      (setq str (buffer-substring
  1129.             (match-beginning 1)
  1130.             (1- (point))))
  1131.      ;; See if this one should be the default.
  1132.      (and (null default)
  1133.           (< (match-beginning 0) start-point)
  1134.           (<= start-point (point))
  1135.           (setq default t))
  1136.      (setq i 0)
  1137.      (while (setq i (string-match "[ \n\t]+" str i))
  1138.        (setq str (concat (substring str 0 i) " "
  1139.                  (substring str (match-end 0))))
  1140.        (setq i (1+ i)))
  1141.      ;; Record as a completion and perhaps as default.
  1142.      (if (eq default t) (setq default str))
  1143.      (setq completions
  1144.            (cons (cons str nil)
  1145.              completions))))
  1146.      (if completions
  1147.      (let ((item (completing-read (if default
  1148.                       (concat "Follow reference named: ("
  1149.                           default ") ")
  1150.                     "Follow reference named: ")
  1151.                       completions nil t)))
  1152.        (if (and (string= item "") default)
  1153.            (list default)
  1154.          (list item)))
  1155.        (error "No cross-references in this node"))))
  1156.   (let (target i (str (concat "\\*" Info-footnote-tag " "
  1157.                   (regexp-quote footnotename))))
  1158.     (while (setq i (string-match " " str i))
  1159.       (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
  1160.             (substring str (1+ i))))
  1161.       (setq i (+ i 10)))
  1162.     (save-excursion
  1163.       (goto-char (point-min))
  1164.       (or (re-search-forward str nil t)
  1165.       (error "No cross-reference named %s" footnotename))
  1166.       (goto-char (match-end 1))
  1167.       (setq target
  1168.         (Info-extract-menu-node-name "Bad format cross reference" t)))
  1169.     (while (setq i (string-match "[ \t\n]+" target i))
  1170.       (setq target (concat (substring target 0 i) " "
  1171.                (substring target (match-end 0))))
  1172.       (setq i (+ i 1)))
  1173.     (Info-goto-node target)
  1174.     (setq Info-in-cross-reference t)))
  1175.  
  1176. (defun Info-next-reference (n)
  1177.   (interactive "p")
  1178.   (let ((pat (format "\\*%s[ \n\t]*\\([^:]*\\):\\|^\\* .*:\\|<<.*>>"
  1179.              Info-footnote-tag))
  1180.     (case-fold-search nil)
  1181.     (old-pt (point)))
  1182.     (while (< n 0)
  1183.       (save-excursion
  1184.     (goto-char (point-min))
  1185.     (while (re-search-forward pat nil t)
  1186.       (setq n (1+ n)))
  1187.     (goto-char (point-min))
  1188.     (if (re-search-forward "^\\* Menu:" nil t)
  1189.         (setq n (1- n)))))
  1190.     (while (>= (setq n (1- n)) 0)
  1191.       (or (eobp) (forward-char 1))
  1192.       (or (re-search-forward pat nil t)
  1193.       (progn
  1194.         (goto-char (point-min))
  1195.         (or (re-search-forward pat nil t)
  1196.         (progn
  1197.           (goto-char old-pt)
  1198.           (error "No cross references in this node")))))
  1199.       (goto-char (match-beginning 0))
  1200.       (if (looking-at "\\* Menu:")
  1201.       (setq n (1+ n))))))
  1202.  
  1203. (defun Info-prev-reference (n)
  1204.   (interactive "p")
  1205.   (Info-next-reference (- n)))
  1206.  
  1207. (defun Info-extract-menu-node-name (&optional errmessage multi-line)
  1208.   (skip-chars-forward " \t\n")
  1209.   (let ((beg (point))
  1210.     str i)
  1211.     (skip-chars-forward "^:")
  1212.     (forward-char 1)
  1213.     (setq str
  1214.       (if (looking-at ":")
  1215.           (buffer-substring beg (1- (point)))
  1216.         (skip-chars-forward " \t\n")
  1217.         (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
  1218.     (while (setq i (string-match "\n" str i))
  1219.       (aset str i ?\ ))
  1220.     str))
  1221.  
  1222. (defun Info-menu (menu-item)
  1223.   "Go to node for menu item named (or abbreviated) NAME.
  1224. Completion is allowed, and the menu item point is on is the default."
  1225.   (interactive
  1226.    (let ((completions '())
  1227.      ;; If point is within a menu item, use that item as the default
  1228.      (default nil)
  1229.      (p (point))
  1230.      (last nil))
  1231.      (save-excursion
  1232.        (goto-char (point-min))
  1233.        (let ((case-fold-search t))
  1234.      (if (not (search-forward "\n* menu:" nil t))
  1235.          (error "No menu in this node")))
  1236.        (while (re-search-forward
  1237.         "\n\\* \\([^:\t\n]*\\):" nil t)
  1238.      (if (and (null default)
  1239.           (prog1 (if last (< last p) nil)
  1240.             (setq last (match-beginning 0)))
  1241.           (<= p last))
  1242.          (setq default (car (car completions))))
  1243.      (setq completions (cons (cons (buffer-substring
  1244.                      (match-beginning 1)
  1245.                      (match-end 1))
  1246.                        (match-beginning 1))
  1247.                  completions)))
  1248.        (if (and (null default) last
  1249.         (< last p)
  1250.         (<= p (progn (end-of-line) (point))))
  1251.        (setq default (car (car completions)))))
  1252.      (let ((item nil))
  1253.        (while (null item)
  1254.      (setq item (let ((completion-ignore-case t))
  1255.               (completing-read (if default
  1256.                        (format "Menu item (default %s): "
  1257.                            default)
  1258.                        "Menu item: ")
  1259.                        completions nil t)))
  1260.      ;; we rely on the fact that completing-read accepts an input
  1261.      ;; of "" even when the require-match argument is true and ""
  1262.      ;; is not a valid possibility
  1263.      (if (string= item "")
  1264.          (if default
  1265.          (setq item default)
  1266.              ;; ask again
  1267.              (setq item nil))))
  1268.        (list item))))
  1269.   ;; there is a problem here in that if several menu items have the same
  1270.   ;; name you can only go to the node of the first with this command.
  1271.   (Info-goto-node (Info-extract-menu-item menu-item) nil t))
  1272.   
  1273. (defun Info-extract-menu-item (menu-item &optional noerror)
  1274.   (save-excursion
  1275.     (goto-char (point-min))
  1276.     (if (let ((case-fold-search t))
  1277.       (search-forward "\n* menu:" nil t))
  1278.     (if (or (search-forward (concat "\n* " menu-item ":") nil t)
  1279.         (search-forward (concat "\n* " menu-item) nil t))
  1280.         (progn
  1281.           (beginning-of-line)
  1282.           (forward-char 2)
  1283.           (Info-extract-menu-node-name))
  1284.       (and (not noerror) (error "No such item in menu")))
  1285.       (and (not noerror) (error "No menu in this node")))))
  1286.  
  1287. ;; If COUNT is nil, use the last item in the menu.
  1288. (defun Info-extract-menu-counting (count &optional noerror noindex)
  1289.   (save-excursion
  1290.     (goto-char (point-min))
  1291.     (if (let ((case-fold-search t))
  1292.       (and (search-forward "\n* menu:" nil t)
  1293.            (or (not noindex)
  1294.            (not (string-match "\\<Index\\>" Info-current-node)))))
  1295.     (if (search-forward "\n* " nil t count)
  1296.         (progn
  1297.           (or count
  1298.           (while (search-forward "\n* " nil t)))
  1299.           (Info-extract-menu-node-name))
  1300.       (and (not noerror) (error "Too few items in menu")))
  1301.       (and (not noerror) (error "No menu in this node")))))
  1302.  
  1303. (defun Info-nth-menu-item (n)
  1304.   "Go to the node of the Nth menu item."
  1305.   (interactive "P")
  1306.   (or n (setq n (- last-command-char ?0)))
  1307.   (if (< n 1) (error "Index must be at least 1"))
  1308.   (Info-goto-node (Info-extract-menu-counting n) nil t))
  1309.  
  1310. (defun Info-last-menu-item ()
  1311.   "Go to the node of the tenth menu item."
  1312.   (interactive)
  1313.   (Info-goto-node (Info-extract-menu-counting nil) nil t))
  1314.  
  1315. (defun Info-top ()
  1316.   "Go to the Top node of this file."
  1317.   (interactive)
  1318.   (Info-goto-node "Top"))
  1319.  
  1320. (defun Info-end ()
  1321.   "Go to the final node in this file."
  1322.   (interactive)
  1323.   (Info-top)
  1324.   (let ((Info-keeping-history nil)
  1325.     node)
  1326.     (Info-last-menu-item)
  1327.     (while (setq node (or (Info-extract-pointer "next" t)
  1328.               (Info-extract-menu-counting nil t t)))
  1329.       (Info-goto-node node))
  1330.     (or (equal (Info-extract-pointer "up" t) "Top")
  1331.     (let ((executing-kbd-macro ""))   ; suppress messages
  1332.       (condition-case nil
  1333.           (Info-global-next 10000)
  1334.         (error nil))))))
  1335.  
  1336. (defun Info-global-next (&optional n)
  1337.   "Go to the next node in this file, traversing node structure as necessary.
  1338. This works only if the Info file is structured as a hierarchy of nodes.
  1339. A positive or negative prefix argument moves by multiple nodes."
  1340.   (interactive "p")
  1341.   (or n (setq n 1))
  1342.   (if (< n 0)
  1343.       (Info-global-prev (- n))
  1344.     (while (>= (setq n (1- n)) 0)
  1345.       (let (node)
  1346.     (cond ((and (string-match "^Top$" Info-current-node)
  1347.             (setq node (Info-extract-pointer "next" t))
  1348.             (Info-extract-menu-item node t))
  1349.            (Info-goto-node node))
  1350.           ((setq node (Info-extract-menu-counting 1 t t))
  1351.            (message "Going down...")
  1352.            (Info-goto-node node))
  1353.           (t
  1354.            (let ((Info-keeping-history Info-keeping-history)
  1355.              (orignode Info-current-node)
  1356.              (ups ""))
  1357.          (while (not (Info-extract-pointer "next" t))
  1358.            (if (and (setq node (Info-extract-pointer "up" t))
  1359.                 (not (equal node "Top")))
  1360.                (progn
  1361.              (message "Going%s..." (setq ups (concat ups " up")))
  1362.              (Info-goto-node node)
  1363.              (setq Info-keeping-history nil))
  1364.              (if orignode
  1365.              (let ((Info-keeping-history nil))
  1366.                (Info-goto-node orignode)))
  1367.              (error "Last node in file")))
  1368.          (Info-next))))))))
  1369.  
  1370. (defun Info-page-next (&optional n)
  1371.   "Scroll forward one screenful, or go to next global node.
  1372. A positive or negative prefix argument moves by multiple screenfuls."
  1373.   (interactive "p")
  1374.   (or n (setq n 1))
  1375.   (if (< n 0)
  1376.       (Info-page-prev (- n))
  1377.     (while (>= (setq n (1- n)) 0)
  1378.       (if (pos-visible-in-window-p (point-max))
  1379.       (progn
  1380.         (Info-global-next)
  1381.         (message "Node: %s" Info-current-node))
  1382.     (scroll-up)))))
  1383.  
  1384. (defun Info-scroll-next (arg)
  1385.   (interactive "P")
  1386.   (if Info-auto-advance
  1387.       (if (and (pos-visible-in-window-p (point-max))
  1388.            (not (eq Info-auto-advance t))
  1389.            (not (eq last-command this-command)))
  1390.       (message "Hit %s again to go to next node"
  1391.            (if (= last-command-char 0)
  1392.                "mouse button"
  1393.              (key-description (char-to-string last-command-char))))
  1394.     (Info-page-next)
  1395.     (setq this-command 'Info))
  1396.     (scroll-up arg)))
  1397.  
  1398. (defun Info-global-prev (&optional n)
  1399.   "Go to the previous node in this file, traversing structure as necessary.
  1400. This works only if the Info file is structured as a hierarchy of nodes.
  1401. A positive or negative prefix argument moves by multiple nodes."
  1402.   (interactive "p")
  1403.   (or n (setq n 1))
  1404.   (if (< n 0)
  1405.       (Info-global-next (- n))
  1406.     (while (>= (setq n (1- n)) 0)
  1407.       (let ((upnode (Info-extract-pointer "up" t))
  1408.         (prevnode (Info-extract-pointer "prev[ious]*" t)))
  1409.     (if (or (not prevnode)
  1410.         (equal prevnode upnode))
  1411.         (if (string-match "^Top$" Info-current-node)
  1412.         (error "First node in file")
  1413.           (message "Going up...")
  1414.           (Info-up))
  1415.       (Info-goto-node prevnode)
  1416.       (let ((downs "")
  1417.         (Info-keeping-history nil)
  1418.         node)
  1419.         (while (setq node (Info-extract-menu-counting nil t t))
  1420.           (message "Going%s..." (setq downs (concat downs " down")))
  1421.           (Info-goto-node node))))))))
  1422.  
  1423. (defun Info-page-prev (&optional n)
  1424.   "Scroll backward one screenful, or go to previous global node.
  1425. A positive or negative prefix argument moves by multiple screenfuls."
  1426.   (interactive "p")
  1427.   (or n (setq n 1))
  1428.   (if (< n 0)
  1429.       (Info-page-next (- n))
  1430.     (while (>= (setq n (1- n)) 0)
  1431.       (if (pos-visible-in-window-p (point-min))
  1432.       (progn
  1433.         (Info-global-prev)
  1434.         (message "Node: %s" Info-current-node)
  1435.         (sit-for 0)
  1436.         ;;(scroll-up 1)   ; work around bug in pos-visible-in-window-p
  1437.         ;;(scroll-down 1)
  1438.         (while (not (pos-visible-in-window-p (point-max)))
  1439.           (scroll-up)))
  1440.     (scroll-down)))))
  1441.  
  1442. (defun Info-scroll-prev (arg)
  1443.   (interactive "P")
  1444.   (if Info-auto-advance
  1445.       (if (and (pos-visible-in-window-p (point-min))
  1446.            (not (eq Info-auto-advance t))
  1447.            (not (eq last-command this-command)))
  1448.       (message "Hit %s again to go to previous node"
  1449.            (if (= last-command-char 0)
  1450.                "mouse button"
  1451.              (key-description (char-to-string last-command-char))))
  1452.     (Info-page-prev)
  1453.     (setq this-command 'Info))
  1454.     (scroll-down arg)))
  1455.  
  1456. (defun Info-index (topic)
  1457.   "Look up a string in the index for this file.
  1458. The index is defined as the first node in the top-level menu whose
  1459. name contains the word \"Index\", plus any immediately following
  1460. nodes whose names also contain the word \"Index\".
  1461. If there are no exact matches to the specified topic, this chooses
  1462. the first match which is a case-insensitive substring of a topic.
  1463. Use the `,' command to see the other matches.
  1464. Give a blank topic name to go to the Index node itself."
  1465.   (interactive "sIndex topic: ")
  1466.   (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
  1467.              (regexp-quote topic)
  1468.              "\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"))
  1469.     node)
  1470.     (message "Searching index for `%s'..." topic)
  1471.     (Info-goto-node "Top")
  1472.     (let ((case-fold-search t))
  1473.       (or (search-forward "\n* menu:" nil t)
  1474.       (error "No index"))
  1475.       (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
  1476.       (error "No index")))
  1477.     (goto-char (match-beginning 1))
  1478.     (let ((Info-keeping-history nil)
  1479.       (Info-fontify (and Info-fontify (equal topic ""))))
  1480.       (Info-goto-node (Info-extract-menu-node-name)))
  1481.     (or (equal topic "")
  1482.     (let ((matches nil)
  1483.           (exact nil)
  1484.           (Info-keeping-history nil)
  1485.           found)
  1486.       (while
  1487.           (progn
  1488.         (goto-char (point-min))
  1489.         (while (re-search-forward pattern nil t)
  1490.           (setq matches
  1491.             (cons (list (buffer-substring (match-beginning 1)
  1492.                               (match-end 1))
  1493.                     (buffer-substring (match-beginning 2)
  1494.                               (match-end 2))
  1495.                     Info-current-node
  1496.                     (string-to-int (concat "0"
  1497.                                (buffer-substring
  1498.                                 (match-beginning 3)
  1499.                                 (match-end 3)))))
  1500.                   matches)))
  1501.         (and (setq node (Info-extract-pointer "next" t))
  1502.              (string-match "\\<Index\\>" node)))
  1503.         (let ((Info-fontify nil))
  1504.           (Info-goto-node node)))
  1505.       (or matches
  1506.           (progn
  1507.         (Info-last)
  1508.         (error "No \"%s\" in index" topic)))
  1509.       ;; Here it is a feature that assoc is case-sensitive.
  1510.       (while (setq found (assoc topic matches))
  1511.         (setq exact (cons found exact)
  1512.           matches (delq found matches)))
  1513.       (setq Info-index-alternatives (nconc exact (nreverse matches))
  1514.         Info-index-first-alternative (car Info-index-alternatives))
  1515.       (Info-index-next 0)))))
  1516.  
  1517. (defun Info-index-next (num)
  1518.   "Go to the next matching index item from the last `i' command."
  1519.   (interactive "p")
  1520.   (or Info-index-alternatives
  1521.       (error "No previous `i' command in this file"))
  1522.   (while (< num 0)
  1523.     (setq num (+ num (length Info-index-alternatives))))
  1524.   (while (> num 0)
  1525.     (setq Info-index-alternatives
  1526.       (nconc (cdr Info-index-alternatives)
  1527.          (list (car Info-index-alternatives)))
  1528.       num (1- num)))
  1529.   (Info-goto-node (nth 1 (car Info-index-alternatives)))
  1530.   (if (> (nth 3 (car Info-index-alternatives)) 0)
  1531.       (forward-line (nth 3 (car Info-index-alternatives)))
  1532.     (forward-line 3)  ; don't search in headers
  1533.     (let ((name (car (car Info-index-alternatives))))
  1534.       (if (or (re-search-forward (format
  1535.                   "\\(Function\\|Command\\): %s\\( \\|$\\)"
  1536.                   (regexp-quote name)) nil t)
  1537.           (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
  1538.           (search-forward (format "`%s'" name) nil t)
  1539.           (and (string-match "\\`.*\\( (.*)\\)\\'" name)
  1540.            (search-forward
  1541.             (format "`%s'" (substring name 0 (match-beginning 1)))
  1542.             nil t))
  1543.           (search-forward name nil t))
  1544.       (beginning-of-line)
  1545.     (goto-char (point-min)))))
  1546.   (message "Found \"%s\" in %s.  %s"
  1547.        (car (car Info-index-alternatives))
  1548.        (nth 2 (car Info-index-alternatives))
  1549.        (if (cdr Info-index-alternatives)
  1550.            (if (eq (car (cdr Info-index-alternatives))
  1551.                Info-index-first-alternative)
  1552.            "(Press `,' to repeat)"
  1553.          (format "(Press `,' for %d more)"
  1554.              (- (1- (length Info-index-alternatives))
  1555.                 (length (memq Info-index-first-alternative
  1556.                       (cdr Info-index-alternatives))))))
  1557.          "(Only match)")))
  1558.  
  1559.  
  1560. ;;;###autoload
  1561. (defun Info-emacs-command (command)
  1562.   "Look up an Emacs command in the Emacs manual in the Info system.
  1563. This command is designed to be used whether you are already in Info or not."
  1564.   (interactive "CLook up command in Emacs manual: ")
  1565.   (save-window-excursion
  1566.     (info)
  1567.     (Info-find-node Info-emacs-info-file-name "Top")
  1568.     (Info-index (symbol-name command)))
  1569.   (pop-to-buffer "*info*"))
  1570.  
  1571. ;;;###autoload
  1572. (defun Info-goto-emacs-command-node (key)
  1573.   "Look up an Emacs command in the Emacs manual in the Info system.
  1574. This command is designed to be used whether you are already in Info or not."
  1575.   (interactive "CLook up command in Emacs manual: ")
  1576.   (Info-emacs-command key))
  1577.  
  1578. ;;;###autoload
  1579. (defun Info-goto-emacs-key-command-node (key)
  1580.   "Look up an Emacs key sequence in the Emacs manual in the Info system.
  1581. This command is designed to be used whether you are already in Info or not."
  1582.   (interactive "kLook up key in Emacs manual: ")
  1583.   (let ((command (key-binding key)))
  1584.     (cond ((eq command 'keyboard-quit)
  1585.        (keyboard-quit))
  1586.       ((null command)
  1587.        (error "%s is undefined" (key-description key)))
  1588.       ((and (interactive-p) (eq command 'execute-extended-command))
  1589.        (call-interactively 'Info-goto-emacs-command-node))
  1590.       (t
  1591.        (Info-goto-emacs-command-node command)))))
  1592.  
  1593. ;;;###autoload
  1594. (defun Info-emacs-key (key)
  1595.   "Look up an Emacs key sequence in the Emacs manual in the Info system.
  1596. This command is designed to be used whether you are already in Info or not."
  1597.   (interactive "kLook up key in Emacs manual: ")
  1598.   (cond ((eq (key-binding key) 'keyboard-quit)
  1599.      (keyboard-quit))
  1600.     ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
  1601.      (call-interactively 'Info-goto-emacs-command-node))
  1602.     (t
  1603.      (save-window-excursion
  1604.        (info)
  1605.        (Info-find-node Info-emacs-info-file-name "Top")
  1606.        (setq key (key-description key))
  1607.        (let (p)
  1608.          (if (setq p (string-match "[@{}]" key))
  1609.          (setq key (concat (substring key 0 p) "@" (substring key p))))
  1610.          (if (string-match "^ESC " key)
  1611.          (setq key (concat "M-" (substring key 4))))
  1612.          (if (string-match "^M-C-" key)
  1613.          (setq key (concat "C-M-" (substring key 4)))))
  1614.        (Info-index key))
  1615.      (pop-to-buffer "*info*"))))
  1616.  
  1617. ;;;###autoload
  1618. (defun Info-elisp-ref (func)
  1619.   "Look up an Emacs Lisp function in the Elisp manual in the Info system.
  1620. This command is designed to be used whether you are already in Info or not."
  1621.   (interactive (let ((fn (function-called-at-point))
  1622.              (enable-recursive-minibuffers t)         
  1623.              val)
  1624.          (setq val (completing-read
  1625.                 (format "Look up Emacs Lisp function%s: "
  1626.                     (if fn
  1627.                     (format " (default %s)" fn)
  1628.                       ""))
  1629.                 obarray 'fboundp t))
  1630.          (list (if (equal val "")
  1631.                fn (intern val)))))
  1632.   (save-window-excursion
  1633.     (info)
  1634.     (condition-case nil
  1635.     (Info-find-node "elisp" "Top")
  1636.       (error (Info-find-node "lispref" "Top")))
  1637.     (Info-index (symbol-name func)))
  1638.   (pop-to-buffer "*info*"))
  1639.  
  1640. (defun Info-reannotate-node ()
  1641.   (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
  1642.     (if bufs
  1643.     (let ((ibuf (current-buffer))
  1644.           (file (concat "\\(" (regexp-quote
  1645.                  (file-name-nondirectory Info-current-file))
  1646.                 "\\|" (regexp-quote Info-current-file) "\\)"))
  1647.           (node (regexp-quote Info-current-node))
  1648.           (savept (point)))
  1649.       (goto-char (point-min))
  1650.       (if (search-forward "\n------ NOTE:\n" nil t)
  1651.           (let ((buffer-read-only nil)
  1652.             (bufmod (buffer-modified-p))
  1653.             top)
  1654.         (setq savept (copy-marker savept))
  1655.         (goto-char (point-min))
  1656.         (while (search-forward "\n------ NOTE:" nil t)
  1657.           (setq top (1+ (match-beginning 0)))
  1658.           (if (search-forward "\n------\n" nil t)
  1659.               (delete-region top (point)))
  1660.           (backward-char 1))
  1661.         (set-buffer-modified-p bufmod)))
  1662.       (save-excursion
  1663.         (while bufs
  1664.           (set-buffer (car bufs))
  1665.           (goto-char (point-min))
  1666.           (while (re-search-forward
  1667.               (format
  1668.                "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
  1669.                file node)
  1670.               nil t)
  1671.         (let ((line (string-to-int
  1672.                  (buffer-substring (match-beginning 2)
  1673.                            (match-end 2))))
  1674.               (top (point))
  1675.               bot)
  1676.           (search-forward "\n------\n" nil t)
  1677.           (setq bot (point))
  1678.           (save-excursion
  1679.             (set-buffer ibuf)
  1680.             (if (integerp savept) (setq savept (copy-marker savept)))
  1681.             (if (= line 0)
  1682.             (goto-char (point-max))
  1683.               (goto-char (point-min))
  1684.               (forward-line line))
  1685.             (let ((buffer-read-only nil)
  1686.               (bufmod (buffer-modified-p)))
  1687.               (insert "------ NOTE:\n")
  1688.               (insert-buffer-substring (car bufs) top bot)
  1689.               (set-buffer-modified-p bufmod)))))
  1690.           (setq bufs (cdr bufs))))
  1691.       (goto-char savept)))))
  1692.  
  1693. (defvar Info-annotate-map nil
  1694.   "Local keymap used within `a' command of Info.")
  1695. (if Info-annotate-map
  1696.     nil
  1697.   ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
  1698.   (setq Info-annotate-map (copy-keymap text-mode-map))
  1699.   (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
  1700.  
  1701. (defun Info-annotate-mode ()
  1702.   "Major mode for adding an annotation to an Info node.
  1703. Like text mode with the addition of Info-cease-annotate
  1704. which returns to Info mode for browsing.
  1705. \\{Info-annotate-map}")
  1706.  
  1707. (defun Info-annotate (arg)
  1708.   "Add a personal annotation to the current Info node.
  1709. Only you will be able to see this annotation.
  1710. Annotations are stored in the file ~/.infonotes by default.
  1711. If point is inside an existing annotation, edit that annotation.
  1712. A prefix argument specifies which annotations file (from
  1713. Info-annotations-path) is to be edited; default is 1."
  1714.   (interactive "p")
  1715.   (setq arg (1- arg))
  1716.   (if (or (< arg 0) (not (nth arg Info-annotations-path)))
  1717.       (if (= arg 0)
  1718.       (setq Info-annotations-path
  1719.         (list (read-file-name
  1720.                "Annotations file: " "~/" "~/.infonotes")))
  1721.     (error "File number must be in the range from 1 to %d"
  1722.            (length Info-annotations-path))))
  1723.   (let ((which nil)
  1724.     (file (file-name-nondirectory Info-current-file))
  1725.     (d Info-directory-list)
  1726.     where pt)
  1727.     (while (and d (not (equal (expand-file-name file (car d))
  1728.                   Info-current-file)))
  1729.       (setq d (cdr d)))
  1730.     (or d (setq file Info-current-file))
  1731.     (if (and (save-excursion
  1732.            (goto-char (min (point-max) (+ (point) 13)))
  1733.            (and (search-backward "------ NOTE:\n" nil t)
  1734.             (setq pt (match-end 0))
  1735.             (search-forward "\n------\n" nil t)))
  1736.          (< (point) (match-end 0)))
  1737.     (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
  1738.                 (regexp-quote file)
  1739.                 (regexp-quote Info-current-node)
  1740.                 (regexp-quote
  1741.                  (buffer-substring pt (match-beginning 0))))
  1742.           where (max (- (point) pt) 0)))
  1743.     (let ((node Info-current-node)
  1744.       (line (if (looking-at "[ \n]*\\'") 0
  1745.           (count-lines (point-min) (point)))))
  1746.       (or which
  1747.       (let ((buffer-read-only nil)
  1748.         (bufmod (buffer-modified-p)))
  1749.         (beginning-of-line)
  1750.         (if (bobp) (goto-char (point-max)))
  1751.         (insert "------ NOTE:\n------\n")
  1752.         (backward-char 20)
  1753.         (set-buffer-modified-p bufmod)))
  1754.       ;; (setq Info-window-start (window-start))
  1755.       (setq Info-window-configuration (current-window-configuration))
  1756.       (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
  1757.       (use-local-map Info-annotate-map)
  1758.       (setq major-mode 'Info-annotate-mode)
  1759.       (setq mode-name "Info Annotate")
  1760.       (if which
  1761.       (if (save-excursion
  1762.         (goto-char (point-min))
  1763.         (re-search-forward which nil t))
  1764.           (progn
  1765.         (goto-char (match-beginning 0))
  1766.         (forward-line 1)
  1767.         (forward-char where)))
  1768.     (let ((bufmod (buffer-modified-p)))
  1769.       (goto-char (point-max))
  1770.       (insert (format "\n------ File: %s  Node: %s  Line: %d\n"
  1771.               file node line))
  1772.       (setq pt (point))
  1773.       (insert "\n------\n"
  1774.           "\nPress C-c C-c to save and return to Info.\n")
  1775.       (goto-char pt)
  1776.       (set-buffer-modified-p bufmod))))))
  1777.  
  1778. (defun Info-cease-annotate ()
  1779.   (interactive)
  1780.   (let ((bufmod (buffer-modified-p)))
  1781.     (while (save-excursion
  1782.          (goto-char (point-min))
  1783.          (re-search-forward "\n\n?Press .* to save and return to Info.\n"
  1784.                 nil t))
  1785.       (delete-region (1+ (match-beginning 0)) (match-end 0)))
  1786.     (while (save-excursion
  1787.          (goto-char (point-min))
  1788.          (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
  1789.                 nil t))
  1790.       (delete-region (match-beginning 0) (match-end 0)))
  1791.     (set-buffer-modified-p bufmod))
  1792.   (save-buffer)
  1793.   (fundamental-mode)
  1794.   (bury-buffer)
  1795.   (or (one-window-p) (delete-window))
  1796.   (info)
  1797.   (setq Info-current-annotation-completions nil)
  1798.   (set-window-configuration Info-window-configuration)
  1799.   (Info-reannotate-node))
  1800.  
  1801. (defun Info-bookmark (arg tag)
  1802.   (interactive "p\nsBookmark name: ")
  1803.   (Info-annotate arg)
  1804.   (if (or (string-match "^\"\\(.*\\)\"$" tag)
  1805.       (string-match "^<<\\(.*\\)>>$" tag))
  1806.       (setq tag (substring tag (match-beginning 1) (match-end 1))))
  1807.   (let ((pt (point)))
  1808.     (search-forward "\n------\n")
  1809.     (let ((end (- (point) 8)))
  1810.       (goto-char pt)
  1811.       (if (re-search-forward "<<[^>\n]*>>" nil t)
  1812.       (delete-region (match-beginning 0) (match-end 0))
  1813.     (goto-char end))
  1814.       (or (equal tag "")
  1815.       (insert "<<" tag ">>"))))
  1816.   (Info-cease-annotate))
  1817.  
  1818. (defun Info-exit ()
  1819.   "Exit Info by selecting some other buffer."
  1820.   (interactive)
  1821.   (if Info-standalone
  1822.       (save-buffers-kill-emacs)
  1823.     (switch-to-buffer (prog1 (other-buffer (current-buffer))
  1824.             (bury-buffer (current-buffer))))))
  1825.  
  1826. (defun Info-undefined ()
  1827.   "Make command be undefined in Info."
  1828.   (interactive)
  1829.   (ding))
  1830.  
  1831. (defun Info-help ()
  1832.   "Enter the Info tutorial."
  1833.   (interactive)
  1834.   (delete-other-windows)
  1835.   (Info-find-node "info"
  1836.           (if (< (window-height) 23)
  1837.               "Help-Small-Screen"
  1838.             "Help")))
  1839.  
  1840. (defun Info-summary ()
  1841.   "Display a brief summary of all Info commands."
  1842.   (interactive)
  1843.   (save-window-excursion
  1844.     (switch-to-buffer "*Help*")
  1845.     (erase-buffer)
  1846.     (insert (documentation 'Info-mode))
  1847.     (goto-char (point-min))
  1848.     (let (flag)
  1849.       (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
  1850.             (message (if flag "Type Space to see more"
  1851.                    "Type Space to return to Info"))
  1852.             (let ((e (next-command-event)))
  1853.               (if (/= ?\  (event-to-character e))
  1854.               (progn (setq unread-command-event e) nil)
  1855.             flag)))
  1856.     (scroll-up)))
  1857.     (message "")
  1858.     (bury-buffer "*Help*")))
  1859.  
  1860. (defun Info-get-token (pos start all &optional errorstring)
  1861.   "Return the token around POS,
  1862. POS must be somewhere inside the token
  1863. START is a regular expression which will match the
  1864.     beginning of the tokens delimited string
  1865. ALL is a regular expression with a single
  1866.     parenthized subpattern which is the token to be
  1867.     returned. E.g. '{\(.*\)}' would return any string
  1868.     enclosed in braces around POS.
  1869. SIG optional fourth argument, controls action on no match
  1870.     nil: return nil
  1871.     t: beep
  1872.     a string: signal an error, using that string."
  1873.   (save-excursion
  1874.     (goto-char (point-min))
  1875.     (re-search-backward "\\`")  ; Bug fix due to Nicholas J. Foskett.
  1876.     (goto-char pos)
  1877.     (re-search-backward start (max (point-min) (- pos 200)) 'yes)
  1878.     (let (found)
  1879.       (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
  1880.           (not (setq found (and (<= (match-beginning 0) pos)
  1881.                     (> (match-end 0) pos))))))
  1882.       (if (and found (<= (match-beginning 0) pos)
  1883.            (> (match-end 0) pos))
  1884.       (buffer-substring (match-beginning 1) (match-end 1))
  1885.     (cond ((null errorstring)
  1886.            nil)
  1887.           ((eq errorstring t)
  1888.            (beep)
  1889.            nil)
  1890.           (t
  1891.            (error "No %s around position %d" errorstring pos)))))))
  1892.  
  1893. (defun Info-follow-clicked-node (event)
  1894.   "Follow a node reference near clicked point.  Like M, F, N, P or U command.
  1895. At end of the node's text, moves to the next node."
  1896.   (interactive "@e")
  1897.   (or (and (event-point event)
  1898.        (Info-follow-nearest-node
  1899.         (max (progn
  1900.            (select-window (event-window event))
  1901.            (event-point event))
  1902.          (1+ (point-min)))))
  1903.       (error "click on a cross-reference to follow")))
  1904.  
  1905. (defun Info-maybe-follow-clicked-node (event &optional click-count)
  1906.   "Follow a node reference (if any) near clicked point.
  1907. Like M, F, N, P or U command.  At end of the node's text, moves to the
  1908. next node.  No error is given if there is no node to follow."
  1909.   (interactive "@e")
  1910.   (and (event-point event)
  1911.        (Info-follow-nearest-node
  1912.     (max (progn
  1913.            (select-window (event-window event))
  1914.            (event-point event))
  1915.          (1+ (point-min))))))
  1916.  
  1917. (defun Info-find-nearest-node (point)
  1918.   (let (node)
  1919.     (cond
  1920.      ((= point (point-min)) nil)   ; don't trigger on accidental RET.
  1921.      ((setq node (Info-get-token point
  1922.                  (format "\\*%s[ \n]" Info-footnote-tag)
  1923.                  (format "\\*%s[ \n]\\([^:]*\\):"
  1924.                      Info-footnote-tag)))
  1925.       (list "Following cross-reference %s..."
  1926.         (list 'Info-follow-reference node)))
  1927.      ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\)::"))
  1928.       (list "Selecting menu item %s..."
  1929.         (list 'Info-goto-node node nil t)))
  1930.      ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\):"))
  1931.       (list "Selecting menu item %s..."
  1932.         (list 'Info-menu node)))
  1933.      ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
  1934.       (list "Going up..."
  1935.         (list 'Info-goto-node node)))
  1936.      ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
  1937.       (list "Next node..."
  1938.         (list 'Info-goto-node node)))
  1939.      ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
  1940.       (list "Top node..."
  1941.         (list 'Info-goto-node "Top")))
  1942.      ((setq node (Info-get-token point "Prev[ious]*: "
  1943.                  "Prev[ious]*: \\([^,\n\t]*\\)"))
  1944.       (list "Previous node..."
  1945.         (list 'Info-goto-node node)))
  1946.      ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
  1947.       (list "Reselecting %s..."
  1948.         (list 'Info-goto-node node)))
  1949.      ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
  1950.       (if Info-in-cross-reference
  1951.       (list "Back to last node..."
  1952.         '(Info-last))
  1953.     (list "Next node..."
  1954.           '(Info-global-next)))))
  1955.     ))
  1956.  
  1957. (defun Info-follow-nearest-node (point)
  1958.   "Follow a node reference near point.  Like M, F, N, P or U command.
  1959. At end of the node's text, moves to the next node."
  1960.   (interactive "d")
  1961.   (let ((data (Info-find-nearest-node point)))
  1962.     (if (null data)
  1963.     nil
  1964.       (let ((msg (format (car data) (nth 1 (nth 1 data)))))
  1965.     (message "%s" msg)
  1966.     (eval (nth 1 data))
  1967.     (message "%sdone" msg))
  1968.       t)))
  1969.  
  1970. (defun Info-indicated-node (event)
  1971.   (condition-case ()
  1972.       (save-excursion
  1973.     (cond ((eventp event)
  1974.            (set-buffer (event-buffer event))
  1975.            (setq event (event-point event))))
  1976.     (let* ((data (Info-find-nearest-node event))
  1977.            (name (nth 1 (nth 1 data))))
  1978.       (and name (nth 1 data))))
  1979.     (error nil)))
  1980.  
  1981.  
  1982. (defvar Info-mode-map nil
  1983.   "Keymap containing Info commands.")
  1984. (if Info-mode-map
  1985.     nil
  1986.   (setq Info-mode-map (make-keymap))
  1987.   (suppress-keymap Info-mode-map)
  1988.   (define-key Info-mode-map "." 'beginning-of-buffer)
  1989.   (define-key Info-mode-map " " 'Info-scroll-next)
  1990.   (define-key Info-mode-map "1" 'Info-nth-menu-item)
  1991.   (define-key Info-mode-map "2" 'Info-nth-menu-item)
  1992.   (define-key Info-mode-map "3" 'Info-nth-menu-item)
  1993.   (define-key Info-mode-map "4" 'Info-nth-menu-item)
  1994.   (define-key Info-mode-map "5" 'Info-nth-menu-item)
  1995.   (define-key Info-mode-map "6" 'Info-nth-menu-item)
  1996.   (define-key Info-mode-map "7" 'Info-nth-menu-item)
  1997.   (define-key Info-mode-map "8" 'Info-nth-menu-item)
  1998.   (define-key Info-mode-map "9" 'Info-nth-menu-item)
  1999.   (define-key Info-mode-map "0" 'Info-last-menu-item)
  2000.   (define-key Info-mode-map "?" 'Info-summary)
  2001.   (define-key Info-mode-map "a" 'Info-annotate)
  2002.   (define-key Info-mode-map "b" 'beginning-of-buffer)
  2003.   (define-key Info-mode-map "d" 'Info-directory)
  2004.   (define-key Info-mode-map "e" 'Info-edit)
  2005.   (define-key Info-mode-map "f" 'Info-follow-reference)
  2006.   (define-key Info-mode-map "g" 'Info-goto-node)
  2007.   (define-key Info-mode-map "h" 'Info-help)
  2008.   (define-key Info-mode-map "i" 'Info-index)
  2009.   (define-key Info-mode-map "j" 'Info-goto-bookmark)
  2010.   (define-key Info-mode-map "k" 'Info-emacs-key)
  2011.   (define-key Info-mode-map "l" 'Info-last)
  2012.   (define-key Info-mode-map "m" 'Info-menu)
  2013.   (define-key Info-mode-map "n" 'Info-next)
  2014.   (define-key Info-mode-map "p" 'Info-prev)
  2015.   (define-key Info-mode-map "q" 'Info-exit)
  2016.   (define-key Info-mode-map "r" 'Info-follow-reference)
  2017.   (define-key Info-mode-map "s" 'Info-search)
  2018.   (define-key Info-mode-map "t" 'Info-top)
  2019.   (define-key Info-mode-map "u" 'Info-up)
  2020.   (define-key Info-mode-map "v" 'Info-visit-file)
  2021.   (define-key Info-mode-map "x" 'Info-bookmark)
  2022.   (define-key Info-mode-map "<" 'Info-top)
  2023.   (define-key Info-mode-map ">" 'Info-end)
  2024.   (define-key Info-mode-map "[" 'Info-global-prev)
  2025.   (define-key Info-mode-map "]" 'Info-global-next)
  2026.   (define-key Info-mode-map "{" 'Info-page-prev)
  2027.   (define-key Info-mode-map "}" 'Info-page-next)
  2028.   (define-key Info-mode-map "=" 'Info-restore-point)
  2029.   (define-key Info-mode-map "!" 'Info-select-node)
  2030.   (define-key Info-mode-map "@" 'Info-follow-nearest-node)
  2031.   (define-key Info-mode-map "," 'Info-index-next)
  2032.   (define-key Info-mode-map "*" 'Info-elisp-ref)
  2033.   (define-key Info-mode-map "\t" 'Info-next-reference)
  2034.   (define-key Info-mode-map "\e\t" 'Info-prev-reference)
  2035.   (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
  2036.   (define-key Info-mode-map "\177" 'Info-scroll-prev)
  2037.  
  2038.   (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
  2039.   (define-key Info-mode-map 'button3 'Info-select-node-menu))
  2040.  
  2041.  
  2042. ;; Info mode is suitable only for specially formatted data.
  2043. (put 'info-mode 'mode-class 'special)
  2044.  
  2045. (defun Info-mode ()
  2046.   "Info mode is for browsing through the Info documentation tree.
  2047. Documentation in Info is divided into \"nodes\", each of which
  2048. discusses one topic and contains references to other nodes
  2049. which discuss related topics.  Info has commands to follow
  2050. the references and show you other nodes.
  2051.  
  2052. h    Invoke the Info tutorial.
  2053. q    Quit Info: return to the previously selected file or buffer.
  2054.  
  2055. Selecting other nodes:
  2056. n    Move to the \"next\" node of this node.
  2057. p    Move to the \"previous\" node of this node.
  2058. m    Pick menu item specified by name (or abbreviation).
  2059. 1-9, 0    Pick first..ninth, last item in node's menu.
  2060.     Menu items select nodes that are \"subsections\" of this node.
  2061. u    Move \"up\" from this node (i.e., from a subsection to a section).
  2062. f or r    Follow a cross reference by name (or abbrev).  Type `l' to get back.
  2063. RET     Follow cross reference or menu item indicated by cursor.
  2064. i    Look up a topic in this file's Index and move to that node.
  2065. ,    (comma) Move to the next match from a previous `i' command.
  2066. l    (letter L) Move back to the last node you were in.
  2067.  
  2068. Moving within a node:
  2069. Space    Scroll forward a full screen.   DEL       Scroll backward.
  2070. b    Go to beginning of node.        Meta->    Go to end of node.
  2071. TAB    Go to next cross-reference.     Meta-TAB  Go to previous ref.
  2072.  
  2073. Mouse commands:
  2074. Left Button    Set point.
  2075. Middle Button    Click on a highlighted node reference to go to it.
  2076. Right Button    Pop up a menu of applicable Info commands.
  2077.  
  2078. Advanced commands:
  2079. g    Move to node, file, or annotation tag specified by name.
  2080.     Examples:  `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
  2081. v    Move to file, with filename completion.
  2082. k    Look up a key sequence in Emacs manual (also C-h C-k at any time).
  2083. *    Look up a function name in Emacs Lisp manual (also C-h C-f).
  2084. d    Go to the main directory of Info files.
  2085. < or t    Go to Top (first) node of this file.
  2086. >    Go to last node in this file.
  2087. \[    Go to previous node, treating file as one linear document.
  2088. \]    Go to next node, treating file as one linear document.
  2089. {    Scroll backward, or go to previous node if at top.
  2090. }    Scroll forward, or go to next node if at bottom.
  2091. =    Restore cursor position from last time in this node.
  2092. a    Add a private note (annotation) to the current node.
  2093. x, j    Add, jump to a bookmark (annotation tag).
  2094. s    Search this Info file for a node containing the specified regexp.
  2095. e    Edit the contents of the current node."
  2096.   (kill-all-local-variables)
  2097.   (setq major-mode 'Info-mode)
  2098.   (setq mode-name "Info")
  2099.   (use-local-map Info-mode-map)
  2100.   (set-syntax-table text-mode-syntax-table)
  2101.   (setq local-abbrev-table text-mode-abbrev-table)
  2102.   (setq case-fold-search t)
  2103.   (setq buffer-read-only t)
  2104. ;  (setq buffer-mouse-map Info-mode-mouse-map)
  2105.   (make-local-variable 'Info-current-file)
  2106.   (make-local-variable 'Info-current-subfile)
  2107.   (make-local-variable 'Info-current-node)
  2108.   (make-local-variable 'Info-tag-table-marker)
  2109.   (make-local-variable 'Info-current-file-completions)
  2110.   (make-local-variable 'Info-current-annotation-completions)
  2111.   (make-local-variable 'Info-index-alternatives)
  2112.   (make-local-variable 'Info-history)
  2113.   (if (string-match "^19" emacs-version)
  2114.       (progn
  2115.     (or (and (fboundp 'find-face) (find-face 'info-node))
  2116.         (make-face 'info-node))
  2117.     (or (and (fboundp 'find-face) (find-face 'info-xref))
  2118.         (make-face 'info-xref))
  2119.     (or (face-differs-from-default-p 'info-node)
  2120.         (if (face-differs-from-default-p 'bold-italic)
  2121.         (copy-face 'bold-italic 'info-node)
  2122.           (copy-face 'bold 'info-node)))
  2123.     (or (face-differs-from-default-p 'info-xref)
  2124.         (copy-face 'bold 'info-xref))))
  2125.   (make-local-variable 'mouse-track-click-hook)
  2126.   (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
  2127.   (if (and (featurep 'toolbar) (not Info-inhibit-toolbar))
  2128.       (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
  2129.   (run-hooks 'Info-mode-hook)
  2130.   (Info-set-mode-line))
  2131.  
  2132. (defvar Info-edit-map nil
  2133.   "Local keymap used within `e' command of Info.")
  2134. (if Info-edit-map
  2135.     nil
  2136. ;  (if (and (string-match "^19" emacs-version)
  2137. ;       (not (string-match "Lucid" emacs-version)))
  2138. ;      (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
  2139. ;    (setq Info-edit-map (copy-keymap text-mode-map)))
  2140.   (setq Info-edit-map (make-sparse-keymap))
  2141.   (set-keymap-name Info-edit-map 'Info-edit-map)
  2142.   (set-keymap-parents Info-edit-map (list text-mode-map))
  2143.   (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
  2144.  
  2145. ;; Info-edit mode is suitable only for specially formatted data.
  2146. (put 'info-edit-mode 'mode-class 'special)
  2147.  
  2148. (defun Info-edit-mode ()
  2149.   "Major mode for editing the contents of an Info node.
  2150. Like text mode with the addition of `Info-cease-edit'
  2151. which returns to Info mode for browsing.
  2152. \\{Info-edit-map}"
  2153.   )
  2154.  
  2155. (defun Info-edit ()
  2156.   "Edit the contents of this Info node.
  2157. Allowed only if variable `Info-enable-edit' is non-nil."
  2158.   (interactive)
  2159.   (or Info-enable-edit
  2160.       (error "Editing info nodes is not enabled"))
  2161.   (use-local-map Info-edit-map)
  2162.   (setq major-mode 'Info-edit-mode)
  2163.   (setq mode-name "Info Edit")
  2164.   (kill-local-variable 'modeline-buffer-identification)
  2165.   (setq buffer-read-only nil)
  2166.   ;; Make mode line update.
  2167.   (set-buffer-modified-p (buffer-modified-p))
  2168.   (message (substitute-command-keys
  2169.          "Editing: Type \\[Info-cease-edit] to return to info")))
  2170.  
  2171. (defun Info-cease-edit ()
  2172.   "Finish editing Info node; switch back to Info proper."
  2173.   (interactive)
  2174.   ;; Do this first, so nothing has changed if user C-g's at query.
  2175.   (and (buffer-modified-p)
  2176.        (y-or-n-p "Save the file? ")
  2177.        (save-buffer))
  2178.   (use-local-map Info-mode-map)
  2179.   (setq major-mode 'Info-mode)
  2180.   (setq mode-name "Info")
  2181.   (Info-set-mode-line)
  2182.   (setq buffer-read-only t)
  2183.   ;; Make mode line update.
  2184.   (set-buffer-modified-p (buffer-modified-p))
  2185.   (and (marker-position Info-tag-table-marker)
  2186.        (buffer-modified-p)
  2187.        (message "Tags may have changed.  Use Info-tagify if necessary")))
  2188.  
  2189. (defun Info-find-emacs-command-nodes (command)
  2190.   "Return a list of locations documenting COMMAND in the XEmacs Info manual.
  2191. The locations are of the format used in Info-history, i.e.
  2192. \(FILENAME NODENAME BUFFERPOS\)."
  2193.   (let ((where '())
  2194.     (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
  2195.               ":\\s *\\(.*\\)\\.$")))
  2196.     (save-excursion
  2197.       (Info-find-node "XEmacs" "Command Index")
  2198.       ;; Take the index node off the Info history.
  2199.       (setq Info-history (cdr Info-history))
  2200.       (goto-char (point-max))
  2201.       (while (re-search-backward cmd-desc nil t)
  2202.       (setq where (cons (list Info-current-file
  2203.                   (buffer-substring
  2204.                    (match-beginning 1)
  2205.                    (match-end 1))
  2206.                   0)
  2207.                 where)))
  2208.       where)))
  2209.  
  2210.  
  2211. ;;; fontification and mousability for info
  2212.  
  2213. (defun Info-highlight-region (start end face)
  2214.   (let ((extent (make-extent start end)))
  2215.     (set-extent-face extent face)
  2216.     (set-extent-property extent 'info t)
  2217.     (set-extent-property extent 'highlight t)))
  2218.  
  2219. (defun Info-fontify-node ()
  2220.   (save-excursion
  2221.     (let (;(lucid (string-match "Lucid" emacs-version))
  2222.       (case-fold-search t)
  2223.       (xref-regexp (concat "\\*" 
  2224.                    (regexp-quote Info-footnote-tag)
  2225.                    "[ \n\t]*\\([^:]*\\):")))
  2226. ;      (if lucid
  2227.       (map-extents (function (lambda (x y) (delete-extent x)))
  2228.                (current-buffer) (point-min) (point-max) nil)
  2229. ;    )
  2230.       (goto-char (point-min))
  2231.       (if (looking-at "^File: [^,: \t]+,?[ \t]+")
  2232.       (progn
  2233.         (goto-char (match-end 0))
  2234.         (while
  2235.         (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
  2236.           (goto-char (match-end 0))
  2237.           (Info-highlight-region (match-beginning 1) (match-end 1)
  2238.                      'info-xref ;lucid
  2239.                      ))))
  2240.       (goto-char (point-min))
  2241.       (while (re-search-forward xref-regexp nil t)
  2242.     (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
  2243.         nil
  2244.       (Info-highlight-region (match-beginning 1) (match-end 1)
  2245.                  'info-xref ;lucid
  2246.                  )))
  2247.       (goto-char (point-min))
  2248.       (if (and (search-forward "\n* menu:" nil t)
  2249. ;; principle of least astonishment, dude...
  2250. ;; (Also, in xemacs this is fast even on indexes, and without it, nodes don't
  2251. ;; highlight when you move over them.)
  2252. ;;           (not (string-match "\\<Index\\>" Info-current-node))
  2253. ;;           (< (- (point-max) (point)) 10000)
  2254.            )
  2255.       (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
  2256.         (Info-highlight-region (match-beginning 1) (match-end 1)
  2257.                    'info-node ;lucid
  2258.                    )))
  2259.       (set-buffer-modified-p nil))))
  2260.  
  2261. (defun Info-select-node-menu (event)
  2262.   "Pops up a menu of applicable Info commands."
  2263.   (interactive "e")
  2264.   (select-window (event-window event))
  2265.   (let ((case-fold-search t)
  2266.     (xref-regexp (concat "\\*" 
  2267.                  (regexp-quote Info-footnote-tag)
  2268.                  "[ \n\t]*\\([^:]*\\):"))
  2269.     up-p prev-p next-p menu
  2270.     i text xrefs subnodes in)
  2271.     (save-excursion
  2272.       (goto-char (point-min))
  2273.       (if (looking-at ".*\\bNext:") (setq next-p t))
  2274.       (if (looking-at ".*\\bPrev:") (setq prev-p t))
  2275.       (if (looking-at ".*Up:") (setq up-p t))
  2276.       (setq menu (nconc (list "Info" ; title: not shown
  2277.                   "Info Commands:" "----")
  2278.             (if (setq in (Info-indicated-node event))
  2279.                 (list (vector (car (cdr in)) in t)))
  2280.             (list
  2281.              ["Goto Info Top-level" Info-directory t]
  2282.              (vector "Next Node" 'Info-next next-p)
  2283.              (vector "Previous Node" 'Info-prev prev-p)
  2284.              (vector "Parent Node (Up)" 'Info-up up-p)
  2285.              ["Goto Node..." Info-goto-node t]
  2286.              ["Goto Last Visited Node" Info-last t])))
  2287.       (while (re-search-forward xref-regexp nil t)
  2288.     (setq text (buffer-substring (match-beginning 1) (match-end 1)))
  2289.     (while (setq i (string-match "[ \n\t]+" text i))
  2290.       (setq text (concat (substring text 0 i) " "
  2291.                  (substring text (match-end 0))))
  2292.       (setq i (1+ i)))
  2293.     (setq xrefs (cons text xrefs)))
  2294.       (setq xrefs (nreverse xrefs))
  2295.       (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
  2296.       (goto-char (point-min))
  2297.       (if (search-forward "\n* menu:" nil t)
  2298.       (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
  2299.         (setq text (buffer-substring (match-beginning 1) (match-end 1)))
  2300.         (setq subnodes (cons text subnodes))))
  2301.       (setq subnodes (nreverse subnodes))
  2302.       (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more)))
  2303.       )
  2304.     (if xrefs
  2305.     (nconc menu (list "----" "Cross-References:" "----")
  2306.            (mapcar (function (lambda (xref)
  2307.                    (if (eq xref 'more)
  2308.                        "...more..."
  2309.                      (vector xref
  2310.                          (list 'Info-follow-reference xref)
  2311.                          t))))
  2312.                xrefs)))
  2313.     (if subnodes
  2314.     (nconc menu (list "----" "Sub-Nodes:" "----")
  2315.            (mapcar (function (lambda (node)
  2316.                    (if (eq node 'more)
  2317.                        "...more..."
  2318.                      (vector node (list 'Info-menu node)
  2319.                          t))))
  2320.                subnodes)))
  2321.     (let ((popup-menu-titles nil))
  2322.       (popup-menu menu))))
  2323.  
  2324. ;;; Info toolbar support
  2325.  
  2326. ;; exit icon taken from GNUS
  2327. (defvar info::toolbar-exit-icon
  2328.   (toolbar-make-button-list
  2329.    (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
  2330.              toolbar-icon-directory))
  2331.   "Exit Info icon")
  2332.  
  2333. (defvar info::toolbar-up-icon
  2334.   (toolbar-make-button-list
  2335.    (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
  2336.              toolbar-icon-directory))
  2337.   "Up icon")
  2338.  
  2339. (defvar info::toolbar-next-icon
  2340.   (toolbar-make-button-list
  2341.    (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
  2342.              toolbar-icon-directory))
  2343.   "Next icon")
  2344.  
  2345. (defvar info::toolbar-prev-icon
  2346.   (toolbar-make-button-list
  2347.    (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
  2348.              toolbar-icon-directory))
  2349.   "Prev icon")
  2350.  
  2351. (defvar info::toolbar
  2352.   '([info::toolbar-exit-icon
  2353.      Info-exit
  2354.      t
  2355.      "Exit info"]
  2356.     [info::toolbar-prev-icon
  2357.      Info-prev
  2358.      t
  2359.      "Prev info entry"]
  2360.     [info::toolbar-next-icon
  2361.      Info-next
  2362.      t
  2363.      "Next info entry"]
  2364.     [info::toolbar-up-icon
  2365.      Info-up
  2366.      t
  2367.      "Up entry"]
  2368.     ))
  2369.  
  2370.  
  2371. (provide 'info)
  2372.  
  2373. (run-hooks 'Info-load-hook)
  2374.  
  2375. ;;; info.el ends here
  2376.