home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / epoch / tek-epoch-stuff / tek-info.el < prev    next >
Encoding:
Text File  |  1991-10-22  |  64.8 KB  |  1,848 lines

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