XEmacs 21.2-b1
[chise/xemacs-chise.git.1] / lisp / info.el
1 ;;; info.el --- info package for Emacs.
2 ;; Keywords: help
3
4 ;; Copyright (C) 1985, 1986, 1993, 1997 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 ;; Keywords: docs, help
11
12 ;; This file is part of XEmacs.
13
14 ;; XEmacs is free software; you can redistribute it and/or modify it
15 ;; under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; any later version.
18
19 ;; XEmacs is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 ;; General Public License for more details.
23
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with XEmacs; see the file COPYING.  If not, write to the 
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
28
29 ;;; Synched up with: Not synched with FSF.
30
31 ;; Commentary:
32
33 ;; This is based on an early Emacs 19 info.el file.
34 ;;
35 ;; Note that Info-directory has been replaced by Info-directory-list,
36 ;; a search path of directories in which to find Info files.
37 ;; Also, Info tries adding ".info" to a file name if the name itself
38 ;; is not found.
39 ;;
40 ;; See the change log below for further details.
41
42
43 ;; LCD Archive Entry:
44 ;; info-dg|Dave Gillespie|daveg@synaptics.com
45 ;; |Info reader with many enhancements; replaces standard info.el.
46 ;; |93-07-22|1.07|~/modes/info.el
47
48 ;; Also available from anonymous FTP on csvax.cs.caltech.edu.
49
50
51 ;; Change Log:
52
53 ;; Modified 3/7/1991 by Dave Gillespie:
54 ;; (Author's address: daveg@synaptics.com or daveg@csvax.cs.caltech.edu)
55 ;;
56 ;; Added keys:  i, t, <, >, [, ], {, }, 6, 7, 8, 9, 0.
57 ;; Look at help for info-mode (type ? in Info) for descriptions.
58 ;;
59 ;; If Info-directory-list is undefined and there is no INFOPATH
60 ;; in the environment, use value of Info-directory for compatibility
61 ;; with Emacs 18.57.
62 ;;
63 ;; All files named "localdir" found in the path are appended to "dir",
64 ;; the Info directory.  For this to work, "dir" should contain only
65 ;; one node (Top), and each "localdir" should contain no ^_ or ^L
66 ;; characters.  Generally they will contain only one or several
67 ;; additional lines for the top-level menu.  Note that "dir" is
68 ;; modified in memory each time it is loaded, but not on disk.
69 ;;
70 ;; If "dir" contains a line of the form:  "* Locals:"
71 ;; then the "localdir"s are inserted there instead of at the end.
72
73
74 ;; Modified 4/3/1991 by Dave Gillespie:
75 ;;
76 ;; Added Info-mode-hook (suggested by Sebastian Kremer).
77 ;; Also added epoch-info-startup/select-hooks from Simon Spero's info.el.
78 ;;
79 ;; Added automatic decoding of compressed Info files.
80 ;; See documentation for the variable Info-suffix-list.  Default is to
81 ;; run "uncompress" on ".Z" files and "unyabba" on ".Y" files.
82 ;; (See comp.sources.unix v24i073-076 for yabba/unyabba, a free software
83 ;; alternative to compress/uncompress.)
84 ;; Note: "dir" and "localdir" files should not be compressed.
85 ;;
86 ;; Changed variables like Info-enable-edit to be settable by M-x set-variable.
87 ;;
88 ;; Added Info-auto-advance variable.  If t, SPC and DEL will act like
89 ;; } and {, i.e., they advance to the next/previous node if at the end
90 ;; of the buffer.
91 ;;
92 ;; Changed `u' to restore point to most recent location in that node.
93 ;; Added `=' to do this manually at any time.  (Suggested by David Fox).
94 ;;
95 ;; Changed `m' and `0-9' to try interpreting menu name as a file name
96 ;; if not found as a node name.  This allows (dir) menus of the form,
97 ;;     Emacs::          Cool text editor
98 ;; as a shorthand for
99 ;;     Emacs:(emacs).   Cool text editor
100 ;;
101 ;; Enhanced `i' to use line-number information in the index.
102 ;; Added `,' to move among all matches to a previous `i' command.
103 ;;
104 ;; Added `a' (Info-annotate) for adding personal notes to any Info node.
105 ;; Notes are not stored in the actual Info files, but in the user's own
106 ;; ~/.infonotes file.
107 ;;
108 ;; Added Info-footnote-tag, made default be "Ref" instead of "Note".
109 ;;
110 ;; Got mouse-click stuff to work under Emacs version 18.  Check it out!
111 ;; Left and right clicks scroll the Info window.
112 ;; Middle click goes to clicked-on node, e.g., "Next:", a menu, or a note.
113
114
115 ;; Modified 6/29/1991 by Dave Gillespie:
116 ;;
117 ;; Renamed epoch-info-startup/select-hooks to Info-startup/select-hook.
118 ;;
119 ;; Made Info-select-node into a command on the `!' key.
120 ;;
121 ;; Added Info-mouse-support user option.
122 ;;
123 ;; Cleaned up the implementation of some routines.
124 ;;
125 ;; Added special treatment of quoted words in annotations:  The `g'
126 ;; command for a nonexistent node name scans for an annotation
127 ;; (in any node of any file) containing that name in quotes:  g foo RET
128 ;; looks for an annotation containing:  "foo"  or:  <<foo>>
129 ;; If found, it goes to that file and node.
130 ;;
131 ;; Added a call to set up Info-directory-list in Info-find-node to
132 ;; work around a bug in GNUS where it calls Info-goto-node before info.
133 ;;
134 ;; Added completion for `g' command (inspired by Richard Kim's infox.el).
135 ;; Completion knows all node names for the current file, and all annotation
136 ;; tags (see above).  It does not complete file names or node names in
137 ;; other files.
138 ;;
139 ;; Added `k' (Info-emacs-key) and `*' (Info-elisp-ref) commands.  You may
140 ;; wish to bind these to global keys outside of Info mode.
141 ;;
142 ;; Allowed localdir files to be full dir-like files; only the menu part
143 ;; of each localdir is copied.  Also, redundant menu items are omitted.
144 ;;
145 ;; Changed Info-history to hold only one entry at a time for each node,
146 ;; and to be circular so that multiple `l's come back again to the most
147 ;; recent node.  Note that the format of Info-history entries has changed,
148 ;; which may interfere with external programs that try to operate on it.
149 ;; (Also inspired by Kim's infox.el).
150 ;;
151 ;; Changed `n', `]', `l', etc. to accept prefix arguments to move several
152 ;; steps at once.  Most accept negative arguments to move oppositely.
153 ;;
154 ;; Changed `?' to bury *Help* buffer afterwards to keep it out of the way.
155 ;;
156 ;; Rearranged `?' key's display to be a little better for new users.
157 ;;
158 ;; Changed `a' to save whole window configuration and restore on C-c C-c.
159 ;;
160 ;; Fixed the bug reported by Bill Reynolds on gnu.emacs.bugs.
161 ;;
162 ;; Changed Info-last to restore window-start as well as cursor position.
163 ;;
164 ;; Changed middle mouse button in space after end of node to do Info-last
165 ;; if we got here by following a cross reference, else do Info-global-next.
166 ;;
167 ;; Added some new mouse bindings: shift-left = Info-global-next,
168 ;; shift-right = Info-global-prev, shift-middle = Info-last.
169 ;;
170 ;; Fixed Info-follow-reference not to make assumptions about length
171 ;; of Info-footnote-tag [Linus Tolke].
172 ;;
173 ;; Changed default for Info-auto-advance mode to be press-twice-for-next-node.
174 ;;
175 ;; Modified x-mouse-ignore to preserve last-command variable, so that
176 ;; press-twice Info-auto-advance mode works with the mouse.
177
178
179 ;; Modified 3/4/1992 by Dave Gillespie:
180 ;;
181 ;; Added an "autoload" command to help autoload.el.
182 ;;
183 ;; Changed `*' command to look for file `elisp' as well as for `lispref'.
184 ;;
185 ;; Fixed a bug involving footnote names containing regexp special characters.
186 ;;
187 ;; Fixed a bug in completion during `f' (or `r') command.
188 ;;
189 ;; Added TAB (Info-next-reference), M-TAB, and RET keys to Info mode.
190 ;;
191 ;; Added new bindings, `C-h C-k' for Info-emacs-key and `C-h C-f' for
192 ;; Info-elisp-ref.  These bindings are made when info.el is loaded, and
193 ;; only if those key sequences were previously unbound.  These bindings
194 ;; work at any time, not just when Info is already running.
195
196
197 ;; Modified 3/8/1992 by Dave Gillespie:
198 ;;
199 ;; Fixed some long lines that were causing trouble with mailers.
200
201
202 ;; Modified 3/9/1992 by Dave Gillespie:
203 ;;
204 ;; Added `C-h C-i' (Info-query).
205 ;;
206 ;; Added Info-novice mode, warns if the user attempts to switch to
207 ;; a different Info file.
208 ;;
209 ;; Fixed a bug that caused problems using compressed Info files
210 ;; and Info-directory-list at the same time.
211 ;;
212 ;; Disabled Info-mouse-support by default if Epoch or Hyperbole is in use.
213 ;;
214 ;; Added an expand-file-name call to Info-find-node to fix a small bug.
215
216
217 ;; Modified 5/22/1992 by Dave Gillespie:
218 ;;
219 ;; Added "standalone" operation:  "emacs -f info" runs Emacs specifically
220 ;; for use as an Info browser.  In this mode, the `q' key quits Emacs
221 ;; itself.  Also, "emacs -f info arg" starts in Info file "arg" instead
222 ;; of "dir".
223 ;;
224 ;; Changed to prefer "foo.info" over "foo".  If both exist, "foo" is
225 ;; probably a directory or executable program!
226 ;;
227 ;; Made control-mouse act like regular-mouse does in other buffers.
228 ;; (In most systems, this will be set-cursor for left-mouse, x-cut
229 ;; for right-mouse, and x-paste, which will be an error, for
230 ;; middle-mouse.)
231 ;;
232 ;; Improved prompting and searching for `,' key.
233 ;;
234 ;; Fixed a bug where some "* Menu:" lines disappeared when "dir"
235 ;; contained several nodes.
236
237
238 ;; Modified 9/10/1992 by Dave Gillespie:
239 ;;
240 ;; Mixed in support for XEmacs.  Mouse works the same as in
241 ;; the other Emacs versions by default; added Info-lucid-mouse-style
242 ;; variable, which enables mouse operation similar to XEmacs's default.
243 ;;
244 ;; Fixed a bug where RET couldn't understand "* Foo::" if "Foo" was a
245 ;; file name instead of a node name.
246 ;;
247 ;; Added `x' (Info-bookmark), a simple interface to the annotation
248 ;; tags feature.  Added `j' (Info-goto-bookmark), like `g' but only
249 ;; completes bookmarks.
250 ;;
251 ;; Added `<<tag>>' as alternate to `"tag"' in annotations.
252 ;;
253 ;; Added `v' (Info-visit-file), like Info-goto-node but specialized
254 ;; for going to a new Info file (with file name completion).
255 ;;
256 ;; Added recognition of gzip'd ".z" files.
257
258
259 ;; Modified 5/9/1993 by Dave Gillespie:
260 ;;
261 ;; Merged in various things from FSF's latest Emacs 19 info.el.
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 ;; Modified 4/5/97 by Tomasz J. Cholewo:
291 ;;
292 ;; Modified Info-search to use with-caps-disable-folding
293
294 ;; Modified 6/21/97 by Hrvoje Niksic
295 ;;
296 ;; Fixed up Info-next-reference to work sanely when n < 0.
297 ;; Added S-tab binding.
298
299 ;; Modified 1997-07-10 by Karl M. Hegbloom
300 ;;
301 ;; Added `Info-minibuffer-history'
302 ;; (also added to defaults in "lisp/utils/savehist.el")
303 ;;  Other changes in main ChangeLog.
304
305 ;; Modified 1998-03-29 by Oscar Figueiredo
306 ;;
307 ;; Added automatic dir/localdir (re)building capability for directories that
308 ;; contain none or when it has become older than info files in the same
309 ;; directory.
310
311 ;; Code:
312
313 (defgroup info nil
314   "The info package for Emacs."
315   :group 'help
316   :group 'docs)
317
318 (defgroup info-faces nil
319   "The faces used by info browser."
320   :group 'info
321   :group 'faces)
322
323
324 (defcustom Info-inhibit-toolbar nil
325   "*Non-nil means don't use the specialized Info toolbar."
326   :type 'boolean
327   :group 'info)
328
329 (defcustom Info-novice nil
330   "*Non-nil means to ask for confirmation before switching Info files."
331   :type 'boolean
332   :group 'info)
333
334 (defvar Info-history nil
335   "List of info nodes user has visited.
336 Each element of list is a list (\"(FILENAME)NODENAME\" BUFPOS WINSTART).")
337
338 (defvar Info-keeping-history t
339   "Non-nil if Info-find-node should modify Info-history.
340 This is for use only by certain internal Info routines.")
341
342 (defvar Info-minibuffer-history nil
343   "Minibuffer history for Info.")
344
345 (defcustom Info-enable-edit nil
346   "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info
347 can edit the current node.
348 This is convenient if you want to write info files by hand.
349 However, we recommend that you not do this.
350 It is better to write a Texinfo file and generate the Info file from that,
351 because that gives you a printed manual as well."
352   :type 'boolean
353   :group 'info)
354
355 (defcustom Info-enable-active-nodes t
356   "*Non-nil allows Info to execute Lisp code associated with nodes.
357 The Lisp code is executed when the node is selected."
358   :type 'boolean
359   :group 'info)
360
361 (defcustom Info-restoring-point t
362   "*Non-nil means to restore the cursor position when re-entering a node."
363   :type 'boolean
364   :group 'info)
365
366 (defcustom Info-auto-advance 'twice
367   "*Control what SPC and DEL do when they can't scroll any further.
368 If nil, they beep and remain in the current node.
369 If t, they move to the next node (like Info-global-next/prev).
370 If anything else, they must be pressed twice to move to the next node."
371   :type '(choice (const :tag "off" nil)
372                  (const :tag "advance" t)
373                  (const :tag "confirm" twice))
374   :group 'info)
375
376 (defcustom Info-fontify t
377   "*Non-nil enables font features in XEmacs.
378 This variable is ignored unless running under XEmacs."
379   :type 'boolean
380   :group 'info)
381
382 (defcustom Info-additional-search-directory-list nil
383   "*List of additional directories to search for Info documentation
384 files.  These directories are not searched for merging the `dir'
385 file. An example might be something like:
386 \"/usr/local/lib/xemacs/packages/lisp/calc/\""
387   :type '(repeat directory)
388   :group 'info)
389
390 (defcustom Info-auto-generate-directory 'if-missing
391   "*When to auto generate an info directory listing.
392 Possible values are:
393 nil or `never' never auto-generate a directory listing,
394   use any existing `dir' or `localdir' file and ignore info
395   directories containing none
396 `always' auto-generate a directory listing ignoring existing
397   `dir' and `localdir' files
398 `if-missing', the default, auto-generates a directory listing
399   if no `dir' or `localdir' file is present.  Otherwise the 
400   contents of any of these files is used instead.
401 `if-outdated' auto-generates a directory listing if the `dir'
402   and `localdir' are either inexistent or outdated (touched 
403   less recently than an info file in the same directory)."
404   :type '(choice (const :tag "never" never)
405                  (const :tag "always" always)
406                  (const :tag "if-missing" if-missing)
407                  (const :tag "if-outdated" if-outdated))
408   :group 'info)
409
410 (defcustom Info-save-auto-generated-dir nil
411   "*Whether an auto-generated info directory listing should be saved.
412 Possible values are:
413 nil or `never', the default, auto-generated info directory 
414   information will never be saved.
415 `always', auto-generated info directory information will be saved to
416   a `dir' file in the same directory overwriting it if it exists
417 `conservative', auto-generated info directory information will be saved
418   to a `dir' file in the same directory but the user is asked before 
419   overwriting any existing file."
420   :type '(choice (const :tag "never" never)
421                  (const :tag "always" always)
422                  (const :tag "conservative" conservative))
423   :group 'info)
424
425 (defvar Info-emacs-info-file-name "xemacs.info"
426   "The filename of the XEmacs info for
427 `Info-goto-emacs-command-node' (`\\<help-mode-map>\\[Info-goto-emacs-command-node]')")
428
429 ;;;###autoload
430 (defvar Info-directory-list nil
431   "List of directories to search for Info documentation files.
432
433 The first directory in this list, the \"dir\" file there will become
434 the (dir)Top node of the Info documentation tree.  If you wish to
435 modify the info search path, use `M-x customize-variable,
436 Info-directory-list' to do so.")
437
438 (defcustom Info-localdir-heading-regexp
439     "^Locally installed XEmacs Packages:?"
440   "The menu part of localdir files will be inserted below this topic
441 heading."
442   :type 'regexp
443   :group 'info)
444
445 (defface info-node '((t (:bold t :italic t)))
446   "Face used for node links in info."
447   :group 'info-faces)
448
449 (defface info-xref '((t (:bold t)))
450   "Face used for cross-references in info."
451   :group 'info-faces)
452
453 ;; Is this right for NT?  .zip, with -c for to stdout, right?
454 (defvar Info-suffix-list '( ("" . nil) 
455                             (".info" . nil)
456                             (".info.gz" . "gzip -dc %s")
457                             (".info-z" . "gzip -dc %s")
458                             (".info.Z" . "uncompress -c %s")
459                             (".gz" . "gzip -dc %s")
460                             (".Z" . "uncompress -c %s")
461                             (".zip" . "unzip -c %s") )
462   "List of file name suffixes and associated decoding commands.
463 Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
464 changed to name of the file to decode, otherwise the file is given to
465 the command as standard input.  If STRING is nil, no decoding is done.")
466
467 (defvar Info-footnote-tag "Note"
468   "*Symbol that identifies a footnote or cross-reference.
469 All \"*Note\" references will be changed to use this word instead.")
470
471 (defvar Info-current-file nil
472   "Info file that Info is now looking at, or nil.
473 This is the name that was specified in Info, not the actual file name.
474 It doesn't contain directory names or file name extensions added by Info.")
475
476 (defvar Info-current-subfile nil
477   "Info subfile that is actually in the *info* buffer now,
478 or nil if current info file is not split into subfiles.")
479
480 (defvar Info-current-node nil
481   "Name of node that Info is now looking at, or nil.")
482
483 (defvar Info-tag-table-marker (make-marker)
484   "Marker pointing at beginning of current Info file's tag table.
485 Marker points nowhere if file has no tag table.")
486
487 (defvar Info-current-file-completions nil
488   "Cached completion list for current Info file.")
489
490 (defvar Info-current-annotation-completions nil
491   "Cached completion list for current annotation files.")
492
493 (defvar Info-index-alternatives nil
494   "List of possible matches for last Info-index command.")
495 (defvar Info-index-first-alternative nil)
496
497 (defcustom Info-annotations-path '("~/.xemacs/info.notes"
498                                    "~/.infonotes"
499                                    "/usr/lib/info.notes")
500   "*Names of files that contain annotations for different Info nodes.
501 By convention, the first one should reside in your personal directory.
502 The last should be a world-writable \"public\" annotations file."
503   :type '(repeat file)
504   :group 'info)
505
506 (defcustom Info-button1-follows-hyperlink nil
507   "*Non-nil means mouse button1 click will follow hyperlink."
508   :type 'boolean
509   :group 'info)
510
511 (defvar Info-standalone nil
512   "Non-nil if Emacs was started solely as an Info browser.")
513
514 (defvar Info-in-cross-reference nil)
515 (defvar Info-window-configuration nil)
516
517 (defvar Info-dir-prologue "-*- Text -*-
518 This is the file .../info/dir, which contains the topmost node of the
519 Info hierarchy.  The first time you invoke Info you start off
520 looking at that node, which is (dir)Top.
521 \1f
522 File: dir       Node: Top       This is the top of the INFO tree
523   This (the Directory node) gives a menu of major topics. 
524
525 * Menu: The list of major topics begins on the next line.
526
527 ")
528
529 (defvar Info-no-description-string "[No description available]"
530   "Description string for info files that have none")
531
532 ;;;###autoload
533 (defun info (&optional file)
534   "Enter Info, the documentation browser.
535 Optional argument FILE specifies the file to examine;
536 the default is the top-level directory of Info.
537
538 In interactive use, a prefix argument directs this command
539 to read a file name from the minibuffer."
540   (interactive (if current-prefix-arg
541                    (list (read-file-name "Info file name: " nil nil t))))
542   (let ((p command-line-args))
543     (while p
544       (and (string-match "^-[fe]" (car p))
545            (equal (nth 1 p) "info")
546            (not Info-standalone)
547            (setq Info-standalone t)
548            (= (length p) 3)
549            (not (string-match "^-" (nth 2 p)))
550            (setq file (nth 2 p))
551            (setq command-line-args-left nil))
552       (setq p (cdr p))))
553 ;  (Info-setup-x) ??? What was this going to be?  Can anyone tell karlheg?
554   (if file
555       (unwind-protect
556           (Info-goto-node (concat "(" file ")"))
557         (and Info-standalone (info)))
558     (if (get-buffer "*info*")
559         (switch-to-buffer "*info*")
560       (Info-directory))))
561
562 ;;;###autoload
563 (defun Info-query (file)
564   "Enter Info, the documentation browser.  Prompt for name of Info file."
565   (interactive "sInfo topic (default = menu): ")
566   (info)
567   (if (equal file "")
568       (Info-goto-node "(dir)")
569     (Info-goto-node (concat "(" file ")"))))
570
571 (defun Info-setup-initial ()
572   (let ((f Info-annotations-path))
573     (while f
574       (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
575           (bury-buffer (find-file-noselect (car f))))
576       (setq f (cdr f)))))
577
578 (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
579   "Go to an info node specified as separate FILENAME and NODENAME.
580 Look for a plausible filename, or if not found then look for URL's and
581 dispatch to the appropriate fn.  NO-GOING-BACK is non-nil if
582 recovering from an error in this function; it says do not attempt
583 further (recursive) error recovery.  TRYFILE is ??"
584
585   (Info-setup-initial)
586
587   (cond
588    ;; empty filename is simple case
589    ((null filename)
590     (Info-find-file-node nil nodename no-going-back tryfile line))
591    ;; Convert filename to lower case if not found as specified.
592    ;; Expand it, look harder...
593    ((let (temp temp-downcase found 
594                (fname (substitute-in-file-name filename)))
595       (let ((dirs (cond
596                    ((string-match "^\\./" fname) ; If specified name starts with `./'
597                     (list default-directory)) ; then just try current directory.
598                    ((file-name-absolute-p fname)
599                     '(nil))             ; No point in searching for an absolute file name
600                    (Info-additional-search-directory-list
601                     (append Info-directory-list
602                             Info-additional-search-directory-list))
603                    (t Info-directory-list))))
604         ;; Search the directory list for file FNAME.
605         (while (and dirs (not found))
606           (setq temp (expand-file-name fname (car dirs)))
607           (setq temp-downcase
608                 (expand-file-name (downcase fname) (car dirs)))
609           (if (equal temp-downcase temp) (setq temp-downcase nil))
610           ;; Try several variants of specified name.
611           ;; Try downcasing, appending a suffix, or both.
612           (setq found (Info-suffixed-file temp temp-downcase))
613           (setq dirs (cdr dirs)))
614         (if found 
615             (progn (setq filename (expand-file-name found))
616                    t))))
617     (Info-find-file-node filename nodename no-going-back tryfile line))
618    ;; Look for a URL.  This pattern is stolen from w3.el to prevent
619    ;; loading it if we won't need it.
620    ((string-match  (concat "^\\(wais\\|solo\\|x-exec\\|newspost\\|www\\|"
621                            "mailto\\|news\\|tn3270\\|ftp\\|http\\|file\\|"
622                            "telnet\\|gopher\\):")
623                    filename)
624     (if (fboundp 'browse-url)
625         (browse-url filename)
626       (error "Cannot follow URLs in this XEmacs")))
627    (t
628     (error "Info file %s does not exist" filename))))
629
630 (defun Info-find-file-node (filename nodename
631                                      &optional no-going-back tryfile line)
632   ;; This is the guts of what was Info-find-node. Whoever wrote this
633   ;; should be locked up where they can't do any more harm.
634
635   ;; Go into info buffer.
636   (switch-to-buffer "*info*")
637   (buffer-disable-undo (current-buffer))
638   (run-hooks 'Info-startup-hook)
639   (or (eq major-mode 'Info-mode)
640       (Info-mode))
641   (or (null filename)
642       (equal Info-current-file filename)
643       (not Info-novice)
644       (string= "dir" (file-name-nondirectory Info-current-file))
645       (if (y-or-n-p-maybe-dialog-box
646            (format "Leave Info file `%s'? "
647                    (file-name-nondirectory Info-current-file)))
648           (message "")
649         (keyboard-quit)))
650   ;; Record the node we are leaving.
651   (if (and Info-current-file (not no-going-back))
652       (Info-history-add Info-current-file Info-current-node (point)))
653   (widen)
654   (setq Info-current-node nil
655         Info-in-cross-reference nil)
656   (unwind-protect
657       (progn
658         ;; Switch files if necessary
659         (or (null filename)
660             (equal Info-current-file filename)
661             (let ((buffer-read-only nil))
662               (setq Info-current-file nil
663                     Info-current-subfile nil
664                     Info-current-file-completions nil
665                     Info-index-alternatives nil
666                     buffer-file-name nil)
667               (erase-buffer)
668               (if (string= "dir" (file-name-nondirectory filename))
669                   (Info-insert-dir)
670                 (Info-insert-file-contents filename t)
671                 (setq default-directory (file-name-directory filename)))
672               (set-buffer-modified-p nil)
673               ;; See whether file has a tag table.  Record the location if yes.
674               (set-marker Info-tag-table-marker nil)
675               (goto-char (point-max))
676               (forward-line -8)
677               (or (equal nodename "*")
678                   (not (search-forward "\^_\nEnd tag table\n" nil t))
679                   (let (pos)
680                     ;; We have a tag table.  Find its beginning.
681                     ;; Is this an indirect file?
682                     (search-backward "\nTag table:\n")
683                     (setq pos (point))
684                     (if (save-excursion
685                           (forward-line 2)
686                           (looking-at "(Indirect)\n"))
687                         ;; It is indirect.  Copy it to another buffer
688                         ;; and record that the tag table is in that buffer.
689                         (save-excursion
690                           (let ((buf (current-buffer)))
691                             (set-buffer
692                              (get-buffer-create " *info tag table*"))
693                             (buffer-disable-undo (current-buffer))
694                             (setq case-fold-search t)
695                             (erase-buffer)
696                             (insert-buffer-substring buf)
697                             (set-marker Info-tag-table-marker
698                                         (match-end 0))))
699                      (set-marker Info-tag-table-marker pos))))
700               (setq Info-current-file
701                     (file-name-sans-versions buffer-file-name))))
702         (if (equal nodename "*")
703             (progn (setq Info-current-node nodename)
704                    (Info-set-mode-line)
705                    (goto-char (point-min)))
706           ;; Search file for a suitable node.
707           (let* ((qnode (regexp-quote nodename))
708                  (regexp (concat "Node: *" qnode " *[,\t\n\177]"))
709                  (guesspos (point-min))
710                  (found t))
711             ;; First get advice from tag table if file has one.
712             ;; Also, if this is an indirect info file,
713             ;; read the proper subfile into this buffer.
714             (if (marker-position Info-tag-table-marker)
715                 (save-excursion
716                   (set-buffer (marker-buffer Info-tag-table-marker))
717                   (goto-char Info-tag-table-marker)
718                   (if (re-search-forward regexp nil t)
719                       (progn
720                         (setq guesspos (read (current-buffer)))
721                         ;; If this is an indirect file,
722                         ;; determine which file really holds this node
723                         ;; and read it in.
724                         (if (not (eq (current-buffer) (get-buffer "*info*")))
725                             (setq guesspos
726                                   (Info-read-subfile guesspos)))))))
727             (goto-char (max (point-min) (- guesspos 1000)))
728             ;; Now search from our advised position (or from beg of buffer)
729             ;; to find the actual node.
730             (catch 'foo
731               (while (search-forward "\n\^_" nil t)
732                 (forward-line 1)
733                 (let ((beg (point)))
734                   (forward-line 1)
735                   (if (re-search-backward regexp beg t)
736                       (throw 'foo t))))
737               (setq found nil)
738               (let ((bufs (delq nil (mapcar 'get-file-buffer
739                                             Info-annotations-path)))
740                     (pattern (if (string-match "\\`<<.*>>\\'" qnode) qnode
741                                (format "\"%s\"\\|<<%s>>" qnode qnode)))
742                     (pat2 (concat "------ *File: *\\([^ ].*[^ ]\\) *Node: "
743                                   "*\\([^ ].*[^ ]\\) *Line: *\\([0-9]+\\)"))
744                     (afile nil) anode aline)
745                 (while (and bufs (not anode))
746                   (save-excursion
747                     (set-buffer (car bufs))
748                     (goto-char (point-min))
749                     (if (re-search-forward pattern nil t)
750                         (if (re-search-backward pat2 nil t)
751                             (setq afile (buffer-substring (match-beginning 1)
752                                                           (match-end 1))
753                                   anode (buffer-substring (match-beginning 2)
754                                                           (match-end 2))
755                                   aline (string-to-int
756                                          (buffer-substring (match-beginning 3)
757                                                            (match-end 3)))))))
758                   (setq bufs (cdr bufs)))
759                 (if anode
760                     (Info-find-node afile anode t nil aline)
761                   (if tryfile
762                       (condition-case nil
763                           (Info-find-node nodename "Top" t)
764                         (error nil)))))
765               (or Info-current-node
766                   (error "No such node: %s" nodename)))
767             (if found
768                 (progn
769                   (Info-select-node)
770                   (goto-char (point-min))
771                   (if line (forward-line line)))))))
772     ;; If we did not finish finding the specified node,
773     ;; go back to the previous one.
774     (or Info-current-node no-going-back
775         (let ((hist (car Info-history)))
776           ;; The following is no longer safe with new Info-history system
777           ;; (setq Info-history (cdr Info-history))
778           (Info-goto-node (car hist) t)
779           (goto-char (+ (point-min) (nth 1 hist)))))))
780
781 ;; Cache the contents of the (virtual) dir file, once we have merged
782 ;; it for the first time, so we can save time subsequently.
783 (defvar Info-dir-contents nil)
784
785 ;; Cache for the directory we decided to use for the default-directory
786 ;; of the merged dir text.
787 (defvar Info-dir-contents-directory nil)
788
789 ;; Record the file attributes of all the files from which we
790 ;; constructed Info-dir-contents.
791 (defvar Info-dir-file-attributes nil)
792
793 (defun Info-insert-dir ()
794   "Construct the Info directory node by merging the files named
795 \"dir\" or \"localdir\" from the directories in `Info-directory-list'
796 The \"dir\" files will take precedence in cases where both exist.  It
797 sets the *info* buffer's `default-directory' to the first directory we
798 actually get any text from."
799   (if (and Info-dir-contents Info-dir-file-attributes
800            ;; Verify that none of the files we used has changed
801            ;; since we used it.
802            (eval (cons 'and
803                        (mapcar '(lambda (elt)
804                                   (let ((curr (file-attributes (car elt))))
805                                     ;; Don't compare the access time.
806                                     (if curr (setcar (nthcdr 4 curr) 0))
807                                     (setcar (nthcdr 4 (cdr elt)) 0)
808                                     (equal (cdr elt) curr)))
809                                Info-dir-file-attributes))))
810       (insert Info-dir-contents)
811     (let ((dirs (reverse Info-directory-list))
812           buffers lbuffers buffer others nodes dirs-done)
813
814       (setq Info-dir-file-attributes nil)
815
816       ;; Search the directory list for the directory file.
817       (while dirs
818         (let ((truename (file-truename (expand-file-name (car dirs)))))
819           (or (member truename dirs-done)
820               (member (directory-file-name truename) dirs-done)
821               ;; Try several variants of specified name.
822               ;; Try upcasing, appending `.info', or both.
823               (let* (buf
824                      file
825                      (attrs
826                       (or
827                        (progn (setq file (expand-file-name "dir" truename))
828                               (file-attributes file))
829                        (progn (setq file (expand-file-name "DIR" truename))
830                               (file-attributes file))
831                        (progn (setq file (expand-file-name "dir.info" truename))
832                               (file-attributes file))
833                        (progn (setq file (expand-file-name "DIR.INFO" truename))
834                               (file-attributes file))
835                        (progn (setq file (expand-file-name "localdir" truename))
836                               (file-attributes file))
837                        (progn (setq file (expand-file-name "dir" truename))
838                               nil)
839                        )))
840                 (setq dirs-done
841                       (cons truename
842                             (cons (directory-file-name truename)
843                                   dirs-done)))
844                 (Info-maybe-update-dir file)
845                 (setq attrs (file-attributes file))
846                 (if (or (setq buf (find-buffer-visiting file))
847                         attrs)
848                     (save-excursion
849                       (or buffers
850                           (message "Composing main Info directory..."))
851                       (set-buffer (or buf
852                                       (generate-new-buffer
853                                        (if (string-match "localdir" file)
854                                            "localdir"
855                                          "info dir"))))
856                       (if (not buf) 
857                           (insert-file-contents file))
858                       (if (string-match "localdir" (buffer-name))
859                           (setq lbuffers (cons (current-buffer) lbuffers))
860                         (setq buffers (cons (current-buffer) buffers)))
861                       (if attrs
862                           (setq Info-dir-file-attributes
863                                 (cons (cons file attrs)
864                                       Info-dir-file-attributes)))))))
865           (or (cdr dirs) (setq Info-dir-contents-directory (car dirs)))
866           (setq dirs (cdr dirs))))
867       
868       ;; ensure that the localdir files are inserted last, and reverse
869       ;; the list of them so that when they get pushed in, they appear
870       ;; in the same order they got specified in the path, from top to
871       ;; bottom.
872       (nconc buffers (reverse lbuffers))
873       
874       (or buffers
875           (error "Can't find the Info directory node"))
876       ;; Distinguish the dir file that comes with Emacs from all the
877       ;; others.  Yes, that is really what this is supposed to do.
878       ;; If it doesn't work, fix it.
879       (setq buffer (car buffers)
880             ;; reverse it since they are pushed down from the top. the
881             ;; `Info-directory-list can be specified in natural order
882             ;; this way.
883             others (reverse (cdr buffers)))
884
885       ;; Insert the entire original dir file as a start; note that we've
886       ;; already saved its default directory to use as the default
887       ;; directory for the whole concatenation.
888       (insert-buffer buffer)
889
890       ;; Look at each of the other buffers one by one.
891       (while others
892         (let ((other (car others))
893               (info-buffer (current-buffer)))
894           (if (string-match "localdir" (buffer-name other))
895               (save-excursion
896                 (set-buffer info-buffer)
897                 (goto-char (point-max))
898                 (cond
899                  ((re-search-backward "^ *\\* *Locals *: *$" nil t)
900                   (delete-region (match-beginning 0) (match-end 0)))
901                  ;; look for a line like |Local XEmacs packages:
902                  ;; or mismatch on some text ...
903                  ((re-search-backward Info-localdir-heading-regexp nil t)
904                   ;; This is for people who underline topic headings with
905                   ;; equal signs or dashes.
906                   (when (save-excursion
907                           (forward-line 1)
908                           (beginning-of-line)
909                           (looking-at "^[ \t]*[-=*]+"))
910                     (forward-line 1))
911                   (forward-line 1)
912                   (beginning-of-line))
913                  (t (search-backward "\^L" nil t)))
914                 ;; Insert menu part of the file
915                 (let* ((pt (point))
916                        (len (length (buffer-string nil nil other))))
917                   (insert (buffer-string nil nil other))
918                   (goto-char (+ pt len))
919                   (save-excursion
920                     (goto-char pt)
921                     (if (search-forward "* Menu:" (+ pt len) t)
922                         (progn
923                           (forward-line 1)
924                           (delete-region pt (point)))))))
925             ;; In each, find all the menus.
926             (save-excursion
927               (set-buffer other)
928               (goto-char (point-min))
929               ;; Find each menu, and add an elt to NODES for it.
930               (while (re-search-forward "^\\* Menu:" nil t)
931                 (let (beg nodename end)
932                   (forward-line 1)
933                   (setq beg (point))
934                   (search-backward "\n\^_")
935                   (search-forward "Node: ")
936                   (setq nodename (Info-following-node-name))
937                   (search-forward "\n\^_" nil 'move)
938                   (beginning-of-line)
939                   (setq end (point))
940                   (setq nodes (cons (list nodename other beg end) nodes))))))
941           (setq others (cdr others))))
942       
943       ;; Add to the main menu a menu item for each other node.
944       (re-search-forward "^\\* Menu:" nil t)
945       (forward-line 1)
946       (let ((menu-items '("top"))
947             (nodes nodes)
948             (case-fold-search t)
949             (end (save-excursion (search-forward "\^_" nil t) (point))))
950         (while nodes
951           (let ((nodename (car (car nodes))))
952             (save-excursion
953               (or (member (downcase nodename) menu-items)
954                   (re-search-forward (concat "^\\* "
955                                              (regexp-quote nodename)
956                                              "::")
957                                      end t)
958                   (progn
959                     (insert "* " nodename "::" "\n")
960                     (setq menu-items (cons nodename menu-items))))))
961           (setq nodes (cdr nodes))))
962       ;; Now take each node of each of the other buffers
963       ;; and merge it into the main buffer.
964       (while nodes
965         (let ((nodename (car (car nodes))))
966           (goto-char (point-min))
967           ;; Find the like-named node in the main buffer.
968           (if (re-search-forward (concat "\n\^_.*\n.*Node: "
969                                          (regexp-quote nodename)
970                                          "[,\n\t]")
971                                  nil t)
972               (progn
973                 (search-forward "\n\^_" nil 'move)
974                 (beginning-of-line)
975                 (insert "\n"))
976             ;; If none exists, add one.
977             (goto-char (point-max))
978             (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
979           ;; Merge the text from the other buffer's menu
980           ;; into the menu in the like-named node in the main buffer.
981           (apply 'insert-buffer-substring (cdr (car nodes))))
982         (setq nodes (cdr nodes)))
983       ;; Kill all the buffers we just made.
984       (while buffers
985         (kill-buffer (car buffers))
986         (setq buffers (cdr buffers)))
987       (while lbuffers
988         (kill-buffer (car lbuffers))
989         (setq lbuffers (cdr lbuffers)))
990       (message "Composing main Info directory...done"))
991     (setq Info-dir-contents (buffer-string)))
992   (setq default-directory Info-dir-contents-directory)
993   (setq buffer-file-name (caar Info-dir-file-attributes)))
994
995 (defun Info-maybe-update-dir (file)
996   "Rebuild dir or localdir according to `Info-auto-generate-directory'."
997   (unless (or (not (file-exists-p (file-name-directory file)))
998               (null (directory-files (file-name-directory file) nil "\\.info")))
999     (if (not (find-buffer-visiting file))
1000         (if (not (file-exists-p file))
1001             (if (or (eq Info-auto-generate-directory 'always)
1002                     (eq Info-auto-generate-directory 'if-missing))            
1003                 (Info-build-dir-anew (file-name-directory file)))
1004           (if (or (eq Info-auto-generate-directory 'always)
1005                   (and (eq Info-auto-generate-directory 'if-outdated)
1006                        (Info-dir-outdated-p file)))
1007               (Info-rebuild-dir file))))))
1008
1009 ;; Record which *.info files are newer than the dir file
1010 (defvar Info-dir-newer-info-files nil)
1011
1012 (defun Info-dir-outdated-p (file)
1013   "Return non-nil if dir or localdir is outdated.
1014 dir or localdir are outdated when an info file in the same
1015 directory has been modified more recently."
1016   (let ((dir-mod-time (nth 5 (file-attributes file)))
1017         f-mod-time
1018         newer)
1019     (setq Info-dir-newer-info-files nil)
1020     (mapcar 
1021      '(lambda (f)
1022         (prog2
1023             (setq f-mod-time (nth 5 (file-attributes f)))
1024             (setq newer (or (> (car f-mod-time) (car dir-mod-time))
1025                             (and (= (car f-mod-time) (car dir-mod-time))
1026                                  (> (car (cdr f-mod-time)) (car (cdr dir-mod-time))))))
1027           (if (and (file-readable-p f)
1028                    newer)
1029               (setq Info-dir-newer-info-files 
1030                     (cons f Info-dir-newer-info-files)))))
1031      (directory-files (file-name-directory file)
1032                       'fullname
1033                       ".*\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1034                       'nosort
1035                       t))
1036     Info-dir-newer-info-files))
1037
1038 (defun Info-extract-dir-entry-from (file)
1039   "Extract the dir entry from the info FILE.
1040 The dir entry is delimited by the markers `START-INFO-DIR-ENTRY'
1041 and `END-INFO-DIR-ENTRY'"
1042   (save-excursion
1043     (set-buffer (get-buffer-create " *Info-tmp*"))
1044     (when (file-readable-p file)
1045       (insert-file-contents file nil nil nil t)
1046       (goto-char (point-min))
1047       (let (beg)
1048         (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
1049           (forward-line 1)
1050           (setq beg (point))
1051           (unless (null (re-search-forward "^END-INFO-DIR-ENTRY" nil t))
1052             (goto-char (match-beginning 0))
1053             (car (Info-parse-dir-entries beg (point)))))))))
1054
1055 ;; Parse dir entries contained between BEG and END into a list of the form
1056 ;; (filename topic node (description-line-1 description-line-2 ...))
1057 (defun Info-parse-dir-entries (beg end)
1058   (let (entry entries)
1059     (save-excursion
1060       (save-restriction
1061         (narrow-to-region beg end)
1062         (goto-char beg)
1063         (while (re-search-forward "^\\* \\([^:]+\\):\\([ \t]*(\\([^)]*\\))\\w*\\.\\|:\\)" nil t)
1064           (setq entry (list (match-string 2)
1065                             (match-string 1)
1066                             (downcase (or (match-string 3)
1067                                           (match-string 1)))))
1068           (setq entry 
1069                 (cons (nreverse 
1070                        (cdr 
1071                         (nreverse 
1072                          (split-string 
1073                           (buffer-substring 
1074                            (re-search-forward "[ \t]*" nil t)
1075                            (or (and (re-search-forward "^[^ \t]" nil t)
1076                                     (goto-char (match-beginning 0)))
1077                                (point-max)))
1078                           "[ \t]*\n[ \t]*"))))
1079                       entry))
1080           (setq entries (cons (nreverse entry) entries)))))
1081     (nreverse entries)))
1082
1083 (defun Info-dump-dir-entries (entries)
1084   (let ((tab-width 8)
1085         (description-col 0)
1086         len)
1087     (mapcar '(lambda (e)
1088                (setq e (cdr e))         ; Drop filename
1089                (setq len (length (concat (car e)
1090                                          (car (cdr e)))))
1091                (if (> len description-col)
1092                    (setq description-col len)))
1093             entries)
1094     (setq description-col (+ 5 description-col)) 
1095     (mapcar '(lambda (e)
1096                (setq e (cdr e))         ; Drop filename
1097                (insert "* " (car e) ":" (car (cdr e)))
1098                (setq e (car (cdr (cdr e))))
1099                (while e
1100                  (indent-to-column description-col)
1101                  (insert (car e) "\n")
1102                  (setq e (cdr e))))
1103             entries)
1104     (insert "\n")))
1105
1106
1107 (defun Info-build-dir-anew (directory)
1108   "Build info directory information for DIRECTORY.
1109 The generated directory listing may be saved to a `dir' according 
1110 to the value of `Info-save-auto-generated-dir'"
1111   (save-excursion
1112     (let* ((dirfile (expand-file-name "dir" directory))
1113            (to-temp (or (null Info-save-auto-generated-dir)
1114                         (eq Info-save-auto-generated-dir 'never)
1115                         (and (not (file-writable-p dirfile))
1116                              (message "File not writable %s. Using temporary." dirfile))))
1117            (info-files 
1118             (directory-files directory
1119                              'fullname
1120                              ".*\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1121                              nil
1122                              t)))
1123       (if to-temp
1124           (message "Creating temporary dir in %s..." directory)
1125         (message "Creating %s..." dirfile))
1126       (set-buffer (find-file-noselect dirfile t))
1127       (setq buffer-read-only nil)
1128       (erase-buffer)
1129       (insert Info-dir-prologue
1130               "Info files in " directory ":\n\n")
1131       (Info-dump-dir-entries 
1132        (mapcar 
1133         '(lambda (f)
1134            (or (Info-extract-dir-entry-from f)
1135                (list 'dummy
1136                      (progn 
1137                        (string-match "\\(.*\\)\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$" 
1138                                      (file-name-nondirectory f))
1139                        (capitalize (match-string 1 (file-name-nondirectory f))))
1140                      ":"
1141                      (list Info-no-description-string))))
1142         info-files))
1143       (if to-temp
1144           (set-buffer-modified-p nil)
1145         (save-buffer))
1146       (if to-temp
1147           (message "Creating temporary dir in %s...done" directory)
1148         (message "Creating %s...done" dirfile)))))
1149
1150
1151 (defun Info-rebuild-dir (file)
1152   "Build info directory information in the directory of dir FILE.
1153 Description of info files are merged from the info files in the 
1154 directory and the contents of FILE with the description in info files
1155 taking precedence over descriptions in FILE.  
1156 The generated directory listing may be saved to a `dir' according to 
1157 the value of `Info-save-auto-generated-dir' "
1158   (save-excursion
1159     (save-restriction
1160       (let (dir-section-contents dir-full-contents
1161             dir-entry
1162             file-dir-entry
1163             mark next-section
1164             not-first-section
1165             (to-temp 
1166              (or (null Info-save-auto-generated-dir)
1167                  (eq Info-save-auto-generated-dir 'never)
1168                  (and (eq Info-save-auto-generated-dir 'always)
1169                       (not (file-writable-p file))
1170                       (message "File not writable %s. Using temporary." file))
1171                  (and (eq Info-save-auto-generated-dir 'conservative)
1172                       (or (and (not (file-writable-p file))
1173                                (message "File not writable %s. Using temporary." file))
1174                           (not (y-or-n-p 
1175                                 (message "%s is outdated. Overwrite ? " 
1176                                          file))))))))
1177         (set-buffer (find-file-noselect file t))
1178         (setq buffer-read-only nil)
1179         (if to-temp
1180             (message "Rebuilding temporary %s..." file)
1181           (message "Rebuilding %s..." file))
1182         (catch 'done
1183           (setq buffer-read-only nil)
1184           (goto-char (point-min))
1185           (unless (and (search-forward "\^_")
1186                        (re-search-forward "^\\* Menu:.*$" nil t)
1187                        (setq mark (and (re-search-forward "^\\* " nil t)
1188                                        (match-beginning 0))))
1189             (throw 'done nil))
1190           (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1191           (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$" nil t)
1192                                       (match-beginning 0))
1193                                  (point-max)))
1194           (while next-section
1195             (narrow-to-region mark next-section)
1196             (setq dir-section-contents (nreverse (Info-parse-dir-entries (point-min)
1197                                                                          (point-max))))
1198             (mapcar '(lambda (file)
1199                        (setq dir-entry (assoc (downcase
1200                                                (file-name-sans-extension
1201                                                 (file-name-nondirectory file)))
1202                                               dir-section-contents)
1203                              file-dir-entry (Info-extract-dir-entry-from file))
1204                        (if dir-entry
1205                            (if file-dir-entry
1206                                ;; A dir entry in the info file takes precedence over an
1207                                ;; existing entry in the dir file
1208                                (setcdr dir-entry (cdr file-dir-entry)))
1209                          (unless (or not-first-section
1210                                      (assoc (downcase
1211                                          (file-name-sans-extension
1212                                           (file-name-nondirectory file)))
1213                                         dir-full-contents))
1214                            (if file-dir-entry
1215                                (setq dir-section-contents (cons file-dir-entry
1216                                                                 dir-section-contents))
1217                              (setq dir-section-contents 
1218                                    (cons (list 'dummy
1219                                                (capitalize (file-name-sans-extension
1220                                                             (file-name-nondirectory file)))
1221                                                ":"
1222                                                (list Info-no-description-string)) 
1223                                          dir-section-contents))))))
1224                     Info-dir-newer-info-files)
1225             (delete-region (point-min) (point-max))
1226             (Info-dump-dir-entries (nreverse dir-section-contents))
1227             (widen)
1228             (if (= next-section (point-max))
1229                 (setq next-section nil)
1230               (or (setq mark (and (re-search-forward "^\\* " nil t)
1231                                   (match-beginning 0)))
1232                   (throw 'done nil))
1233               (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$" nil t)
1234                                           (match-beginning 0))
1235                                      (point-max))))
1236             (setq not-first-section t)))
1237         (if to-temp
1238             (progn
1239               (set-buffer-modified-p nil)
1240               (message "Rebuilding temporary %s...done" file))
1241           (save-buffer)
1242           (message "Rebuilding %s...done" file))))))
1243
1244 ;;;###autoload      
1245 (defun Info-batch-rebuild-dir ()
1246   "(Re)build info `dir' files in the directories remaining on the command line.
1247 Use this from the command line, with `-batch';
1248 it won't work in an interactive Emacs.
1249 Each file is processed even if an error occurred previously.
1250 For example, invoke \"xemacs -batch -f Info-batch-rebuild-dir /usr/local/info\""
1251   ;; command-line-args-left is what is left of the command line (from
1252   ;; startup.el)
1253   (defvar command-line-args-left)       ; Avoid 'free variable' warning
1254   (if (not noninteractive)
1255       (error "`Info-batch-rebuild-dir' is to be used only with -batch"))
1256   (let ((Info-save-auto-generated-dir 'always)
1257         dir localdir)
1258     (while command-line-args-left
1259       (if  (not (file-directory-p (car command-line-args-left)))
1260           (message "Warning: Skipped %s. Not a directory."
1261                    (car command-line-args-left))
1262         (setq dir (expand-file-name "dir" (car command-line-args-left)))
1263         (setq localdir (expand-file-name "localdir" (car command-line-args-left)))
1264         (cond 
1265          ((file-exists-p dir)
1266           (Info-rebuild-dir dir))
1267          ((file-exists-p localdir)
1268           (Info-rebuild-dir localdir))
1269          (t
1270           (Info-build-dir-anew (car command-line-args-left)))))
1271       (setq command-line-args-left (cdr command-line-args-left)))
1272     (message "Done")
1273     (kill-emacs 0)))
1274
1275 (defun Info-history-add (file node point)
1276   (if Info-keeping-history
1277       (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
1278              (found (assoc name Info-history)))
1279         (if found
1280             (setq Info-history (delq found Info-history)))
1281         (setq Info-history (cons (list name (- point (point-min))
1282                                        (and (eq (window-buffer)
1283                                                 (current-buffer))
1284                                             (- (window-start) (point-min))))
1285                                  Info-history)))))
1286
1287 (defun Info-file-name-only (file)
1288   (let ((dir (file-name-directory file))
1289         (p Info-directory-list))
1290     (while (and p (not (equal (car p) dir)))
1291       (setq p (cdr p)))
1292     (if p (file-name-nondirectory file) file)))
1293
1294 (defun Info-read-subfile (nodepos)
1295   (set-buffer (marker-buffer Info-tag-table-marker))
1296   (goto-char (point-min))
1297   (search-forward "\n\^_")
1298   (let (lastfilepos
1299         lastfilename)
1300     (forward-line 2)
1301     (catch 'foo
1302       (while (not (looking-at "\^_"))
1303         (if (not (eolp))
1304             (let ((beg (point))
1305                   thisfilepos thisfilename)
1306               (search-forward ": ")
1307               (setq thisfilename  (buffer-substring beg (- (point) 2)))
1308               (setq thisfilepos (read (current-buffer)))
1309               ;; read in version 19 stops at the end of number.
1310               ;; Advance to the next line.
1311               (if (eolp)
1312                   (forward-line 1))
1313               (if (> thisfilepos nodepos)
1314                   (throw 'foo t))
1315               (setq lastfilename thisfilename)
1316               (setq lastfilepos thisfilepos))
1317           (throw 'foo t))))
1318     (set-buffer (get-buffer "*info*"))
1319     (or (equal Info-current-subfile lastfilename)
1320         (let ((buffer-read-only nil))
1321           (setq buffer-file-name nil)
1322           (widen)
1323           (erase-buffer)
1324           (Info-insert-file-contents (Info-suffixed-file
1325                                       (expand-file-name lastfilename
1326                                                         (file-name-directory
1327                                                          Info-current-file)))
1328                                      t)
1329           (set-buffer-modified-p nil)
1330           (setq Info-current-subfile lastfilename)))
1331     (goto-char (point-min))
1332     (search-forward "\n\^_")
1333     (+ (- nodepos lastfilepos) (point))))
1334
1335 (defun Info-suffixed-file (name &optional name2)
1336   "Look for NAME with each of the `Info-suffix-list' extensions in
1337 turn. Optional NAME2 is the name of a fallback info file to check
1338 for; usually a downcased version of NAME."
1339   (let ((suff Info-suffix-list)
1340         (found nil)
1341         file file2)
1342     (while (and suff (not found))
1343       (setq file (concat name (caar suff))
1344             file2 (and name2 (concat name2 (caar suff))))
1345       (cond
1346        ((file-regular-p file)
1347         (setq found file))
1348        ((and file2 (file-regular-p file2))
1349         (setq found file2))
1350        (t
1351         (setq suff (cdr suff)))))
1352     (or found
1353         (and name (when (file-regular-p name)
1354                     name))
1355         (and name2 (when (file-regular-p name2)
1356                      name2)))))
1357
1358 (defun Info-insert-file-contents (file &optional visit)
1359   (setq file (expand-file-name file default-directory))
1360   (let ((suff Info-suffix-list))
1361     (while (and suff (or (<= (length file) (length (car (car suff))))
1362                          (not (equal (substring file
1363                                                 (- (length (car (car suff)))))
1364                                      (car (car suff))))))
1365       (setq suff (cdr suff)))
1366     (if (stringp (cdr (car suff)))
1367         (let ((command (if (string-match "%s" (cdr (car suff)))
1368                            (format (cdr (car suff)) file)
1369                          (concat (cdr (car suff)) " < " file))))
1370           (message "%s..." command)
1371           (if (eq system-type 'vax-vms)
1372               (call-process command nil t nil)
1373             (call-process shell-file-name nil t nil "-c" command))
1374           (message "")
1375           (if visit
1376               (progn
1377                 (setq buffer-file-name file)
1378                 (set-buffer-modified-p nil)
1379                 (clear-visited-file-modtime))))
1380       (insert-file-contents file visit))))
1381
1382 (defun Info-select-node ()
1383   "Select the node that point is in, after using `g *' to select whole file."
1384   (interactive)
1385   (widen)
1386   (save-excursion
1387    ;; Find beginning of node.
1388    (search-backward "\n\^_")
1389    (forward-line 2)
1390    ;; Get nodename spelled as it is in the node.
1391    (re-search-forward "Node:[ \t]*")
1392    (setq Info-current-node
1393          (buffer-substring (point)
1394                            (progn
1395                             (skip-chars-forward "^,\t\n")
1396                             (point))))
1397    (Info-set-mode-line)
1398    ;; Find the end of it, and narrow.
1399    (beginning-of-line)
1400    (let (active-expression)
1401      (narrow-to-region (point)
1402                        (if (re-search-forward "\n[\^_\f]" nil t)
1403                            (prog1
1404                             (1- (point))
1405                             (if (looking-at "[\n\^_\f]*execute: ")
1406                                 (progn
1407                                   (goto-char (match-end 0))
1408                                   (setq active-expression
1409                                         (read (current-buffer))))))
1410                          (point-max)))
1411      (or (equal Info-footnote-tag "Note")
1412          (progn
1413            (goto-char (point-min))
1414            (let ((buffer-read-only nil)
1415                  (bufmod (buffer-modified-p))
1416                  (case-fold-search t))
1417              (while (re-search-forward "\\*[Nn]ote\\([ \n]\\)" nil t)
1418                (replace-match (concat "*" Info-footnote-tag "\ ")))
1419              (set-buffer-modified-p bufmod))))
1420      (Info-reannotate-node)
1421      ;; XEmacs: remove v19 test
1422      (and Info-fontify
1423           (Info-fontify-node))
1424      (run-hooks 'Info-select-hook)
1425      (if Info-enable-active-nodes (eval active-expression)))))
1426
1427 (defun Info-set-mode-line ()
1428   (setq modeline-buffer-identification
1429         (list (cons modeline-buffer-id-left-extent "Info: ")
1430               (cons modeline-buffer-id-right-extent
1431                     (concat
1432                      "("
1433                      (if Info-current-file
1434                          (let ((name (file-name-nondirectory Info-current-file)))
1435                            (if (string-match "\\.info$" name)
1436                                (substring name 0 -5)
1437                              name))
1438                        "")
1439                      ")"
1440                      (or Info-current-node ""))))))
1441 \f
1442 ;; Go to an info node specified with a filename-and-nodename string
1443 ;; of the sort that is found in pointers in nodes.
1444
1445 ;;;###autoload
1446 (defun Info-goto-node (nodename &optional no-going-back tryfile)
1447   "Go to info node named NAME.  Give just NODENAME or (FILENAME)NODENAME.
1448 Actually, the following interpretations of NAME are tried in order:
1449     (FILENAME)NODENAME
1450     (FILENAME)     (using Top node)
1451     NODENAME       (in current file)
1452     TAGNAME        (see below)
1453     FILENAME       (using Top node)
1454 where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
1455 annotation for any node of any file.  (See `a' and `x' commands.)"
1456   (interactive (list (Info-read-node-name "Goto node, file or tag: ")
1457                      nil t))
1458   (let (filename)
1459     (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1460                   nodename)
1461     (setq filename (if (= (match-beginning 1) (match-end 1))
1462                        ""
1463                      (substring nodename (match-beginning 2) (match-end 2)))
1464           nodename (substring nodename (match-beginning 3) (match-end 3)))
1465     (let ((trim (string-match "\\s *\\'" filename)))
1466       (if trim (setq filename (substring filename 0 trim))))
1467     (let ((trim (string-match "\\s *\\'" nodename)))
1468       (if trim (setq nodename (substring nodename 0 trim))))
1469     (Info-find-node (if (equal filename "") nil filename)
1470                     (if (equal nodename "") "Top" nodename)
1471                     no-going-back (and tryfile (equal filename "")))))
1472
1473 (defun Info-goto-bookmark ()
1474   (interactive)
1475   (let ((completion-ignore-case nil)
1476         (tag (completing-read "Goto tag: "
1477                               (Info-build-annotation-completions)
1478                               nil t nil
1479                               'Info-minibuffer-history)))
1480     (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
1481
1482 ;;;###autoload
1483 (defun Info-visit-file ()
1484   "Directly visit an info file."
1485   (interactive)
1486   (let* ((insert-default-directory nil)
1487          (file (read-file-name "Goto Info file: " "" "")))
1488     (or (equal file "") (Info-find-node (expand-file-name file) "Top"))))
1489
1490 (defun Info-restore-point (&optional always)
1491   "Restore point to same location it had last time we were in this node."
1492   (interactive "p")
1493   (if (or Info-restoring-point always)
1494       (let* ((name (format "(%s)%s"
1495                            (Info-file-name-only Info-current-file)
1496                            Info-current-node))
1497              (p (assoc name Info-history)))
1498         (if p (Info-restore-history-entry p)))))
1499
1500 (defun Info-restore-history-entry (entry)
1501   (goto-char (+ (nth 1 entry) (point-min)))
1502   (and (nth 2 entry)
1503        (get-buffer-window (current-buffer))
1504        (set-window-start (get-buffer-window (current-buffer))
1505                          (+ (nth 2 entry) (point-min)))))
1506
1507 (defun Info-read-node-name (prompt &optional default)
1508   (Info-setup-initial)
1509   (let* ((completion-ignore-case t)
1510          (nodename (completing-read prompt
1511                                     (Info-build-node-completions)
1512                                     nil nil nil
1513                                     'Info-minibuffer-history)))
1514     (if (equal nodename "")
1515         (or default
1516             (Info-read-node-name prompt))
1517       nodename)))
1518
1519 (defun Info-build-annotation-completions ()
1520   (or Info-current-annotation-completions
1521       (save-excursion
1522         (let ((bufs (delq nil (mapcar 'get-file-buffer
1523                                       Info-annotations-path)))
1524               (compl nil))
1525           (while bufs
1526             (set-buffer (car bufs))
1527             (goto-char (point-min))
1528             (while (re-search-forward "<<\\(.*\\)>>" nil t)
1529               (setq compl (cons (list (buffer-substring (match-beginning 1)
1530                                                         (match-end 1)))
1531                                 compl)))
1532             (setq bufs (cdr bufs)))
1533           (setq Info-current-annotation-completions compl)))))
1534
1535 (defun Info-build-node-completions ()
1536   (or Info-current-file-completions
1537       (let ((compl (Info-build-annotation-completions)))
1538         (save-excursion
1539           (save-restriction
1540             (if (marker-buffer Info-tag-table-marker)
1541                 (progn
1542                   (set-buffer (marker-buffer Info-tag-table-marker))
1543                   (goto-char Info-tag-table-marker)
1544                   (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
1545                     (setq compl
1546                           (cons (list (buffer-substring (match-beginning 1)
1547                                                         (match-end 1)))
1548                                 compl))))
1549               (widen)
1550               (goto-char (point-min))
1551               (while (search-forward "\n\^_" nil t)
1552                 (forward-line 1)
1553                 (let ((beg (point)))
1554                   (forward-line 1)
1555                   (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
1556                                           beg t)
1557                       (setq compl 
1558                             (cons (list (buffer-substring (match-beginning 1)
1559                                                           (match-end 1)))
1560                                   compl))))))))
1561         (setq Info-current-file-completions compl))))
1562 \f
1563 (defvar Info-last-search nil
1564   "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1565
1566
1567 ;;;###autoload
1568 (defun Info-search (regexp)
1569   "Search for REGEXP, starting from point, and select node it's found in."
1570   (interactive "sSearch (regexp): ")
1571   (if (equal regexp "")
1572       (setq regexp Info-last-search)
1573     (setq Info-last-search regexp))
1574   (with-caps-disable-folding regexp
1575     (let ((found ())
1576           (onode Info-current-node)
1577           (ofile Info-current-file)
1578           (opoint (point))
1579           (osubfile Info-current-subfile))
1580       (save-excursion
1581         (save-restriction
1582           (widen)
1583           (if (null Info-current-subfile)
1584               (progn (re-search-forward regexp) (setq found (point)))
1585             (condition-case nil
1586                 (progn (re-search-forward regexp) (setq found (point)))
1587               (search-failed nil)))))
1588       (if (not found)                   ;can only happen in subfile case -- else would have erred
1589           (unwind-protect
1590               (let ((list ()))
1591                 (set-buffer (marker-buffer Info-tag-table-marker))
1592                 (goto-char (point-min))
1593                 (search-forward "\n\^_\nIndirect:")
1594                 (save-restriction
1595                   (narrow-to-region (point)
1596                                     (progn (search-forward "\n\^_")
1597                                            (1- (point))))
1598                   (goto-char (point-min))
1599                   (search-forward (concat "\n" osubfile ": "))
1600                   (beginning-of-line)
1601                   (while (not (eobp))
1602                     (re-search-forward "\\(^.*\\): [0-9]+$")
1603                     (goto-char (+ (match-end 1) 2))
1604                     (setq list (cons (cons (read (current-buffer))
1605                                            (buffer-substring (match-beginning 1)
1606                                                              (match-end 1)))
1607                                      list))
1608                     (goto-char (1+ (match-end 0))))
1609                   (setq list (nreverse list)
1610                         list (cdr list)))
1611                 (while list
1612                   (message "Searching subfile %s..." (cdr (car list)))
1613                   (Info-read-subfile (car (car list)))
1614                   (setq list (cdr list))
1615                   (goto-char (point-min))
1616                   (if (re-search-forward regexp nil t)
1617                       (setq found (point) list ())))
1618                 (if found
1619                     (message "")
1620                   (signal 'search-failed (list regexp))))
1621             (if (not found)
1622                 (progn (Info-read-subfile opoint)
1623                        (goto-char opoint)
1624                        (Info-select-node)))))
1625       (widen)
1626       (goto-char found)
1627       (Info-select-node)
1628       (or (and (equal onode Info-current-node)
1629                (equal ofile Info-current-file))
1630           (Info-history-add ofile onode opoint)))))
1631 \f
1632 ;; Extract the value of the node-pointer named NAME.
1633 ;; If there is none, use ERRORNAME in the error message; 
1634 ;; if ERRORNAME is nil, just return nil.
1635 (defun Info-extract-pointer (name &optional errorname)
1636   (save-excursion
1637    (goto-char (point-min))
1638    (forward-line 4)
1639    (let ((case-fold-search t))
1640      (if (re-search-backward (concat name ":") nil t)
1641          (progn
1642            (goto-char (match-end 0))
1643            (Info-following-node-name))
1644        (if (eq errorname t)
1645            nil
1646          (error (concat "Node has no " (capitalize (or errorname name)))))))))
1647
1648 ;; Return the node name in the buffer following point.
1649 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1650 ;; saying which chas may appear in the node name.
1651 (defun Info-following-node-name (&optional allowedchars)
1652   (skip-chars-forward " \t")
1653   (buffer-substring
1654    (point)
1655    (progn
1656      (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1657        (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1658        (if (looking-at "(")
1659            (skip-chars-forward "^)")))
1660      (skip-chars-backward " ")
1661      (point))))
1662
1663 (defun Info-next (&optional n)
1664   "Go to the next node of this node.
1665 A positive or negative prefix argument moves by multiple nodes."
1666   (interactive "p")
1667   (or n (setq n 1))
1668   (if (< n 0)
1669       (Info-prev (- n))
1670     (while (>= (setq n (1- n)) 0)
1671       (Info-goto-node (Info-extract-pointer "next")))))
1672
1673 (defun Info-prev (&optional n)
1674   "Go to the previous node of this node.
1675 A positive or negative prefix argument moves by multiple nodes."
1676   (interactive "p")
1677   (or n (setq n 1))
1678   (if (< n 0)
1679       (Info-next (- n))
1680     (while (>= (setq n (1- n)) 0)
1681       (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
1682
1683 (defun Info-up (&optional n)
1684   "Go to the superior node of this node.
1685 A positive prefix argument moves up several times."
1686   (interactive "p")
1687   (or n (setq n 1))
1688   (while (>= (setq n (1- n)) 0)
1689     (Info-goto-node (Info-extract-pointer "up")))
1690   (if (interactive-p) (Info-restore-point)))
1691
1692 (defun Info-last (&optional n)
1693   "Go back to the last node visited.
1694 With a prefix argument, go to Nth most recently visited node.  History is
1695 circular; after oldest node, history comes back around to most recent one.
1696 Argument can be negative to go through the circle in the other direction.
1697 \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
1698   (interactive "p")
1699   (or n (setq n 1))
1700   (or Info-history
1701       (error "This is the first Info node you looked at"))
1702   (let ((len (1+ (length Info-history))))
1703     (setq n (% (+ n (* len 100)) len)))
1704   (if (> n 0)
1705       (let ((entry (nth (1- n) Info-history)))
1706         (Info-history-add Info-current-file Info-current-node (point))
1707         (while (>= (setq n (1- n)) 0)
1708           (setq Info-history (nconc (cdr Info-history)
1709                                     (list (car Info-history)))))
1710         (setq Info-history (cdr Info-history))
1711         (let ((Info-keeping-history nil))
1712           (Info-goto-node (car entry)))
1713         (Info-restore-history-entry entry))))
1714
1715 (defun Info-directory ()
1716   "Go to the Info directory node."
1717   (interactive)
1718   (Info-find-node "dir" "top"))
1719 \f
1720 (defun Info-follow-reference (footnotename)
1721   "Follow cross reference named NAME to the node it refers to.
1722 NAME may be an abbreviation of the reference name."
1723   (interactive
1724    (let ((completion-ignore-case t)
1725          completions default (start-point (point)) str i)
1726      (save-excursion
1727        (goto-char (point-min))
1728        (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
1729                                          Info-footnote-tag)
1730                                  nil t)
1731          (setq str (buffer-substring
1732                     (match-beginning 1)
1733                     (1- (point))))
1734          ;; See if this one should be the default.
1735          (and (null default)
1736               (< (match-beginning 0) start-point)
1737               (<= start-point (point))
1738               (setq default t))
1739          (setq i 0)
1740          (while (setq i (string-match "[ \n\t]+" str i))
1741            (setq str (concat (substring str 0 i) " "
1742                              (substring str (match-end 0))))
1743            (setq i (1+ i)))
1744          ;; Record as a completion and perhaps as default.
1745          (if (eq default t) (setq default str))
1746          (setq completions
1747                (cons (cons str nil)
1748                      completions))))
1749      (if completions
1750          (let ((item (completing-read (if default
1751                                           (concat "Follow reference named: ("
1752                                                   default ") ")
1753                                         "Follow reference named: ")
1754                                       completions nil t nil
1755                                       'Info-minibuffer-history)))
1756            (if (and (string= item "") default)
1757                (list default)
1758              (list item)))
1759        (error "No cross-references in this node"))))
1760   (let (target i (str (concat "\\*" Info-footnote-tag " "
1761                               (regexp-quote footnotename))))
1762     (while (setq i (string-match " " str i))
1763       (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
1764                         (substring str (1+ i))))
1765       (setq i (+ i 10)))
1766     (save-excursion
1767       (goto-char (point-min))
1768       (or (re-search-forward str nil t)
1769           (error "No cross-reference named %s" footnotename))
1770       (goto-char (match-end 1))
1771       (setq target
1772             (Info-extract-menu-node-name "Bad format cross reference" t)))
1773     (while (setq i (string-match "[ \t\n]+" target i))
1774       (setq target (concat (substring target 0 i) " "
1775                            (substring target (match-end 0))))
1776       (setq i (+ i 1)))
1777     (Info-goto-node target)
1778     (setq Info-in-cross-reference t)))
1779
1780 (defun Info-next-reference (n)
1781   (interactive "p")
1782   (let ((pat (format "\\*%s[ \n\t]*\\([^:]*\\):\\|^\\* .*:\\|<<.*>>"
1783                      Info-footnote-tag))
1784         (old-pt (point))
1785         wrapped found-nomenu)
1786     (while (< n 0)
1787       (unless (re-search-backward pat nil t)
1788         ;; Don't wrap more than once in a buffer where only the
1789         ;; menu references are found.
1790         (when (and wrapped (not found-nomenu))
1791           (goto-char old-pt)
1792           (error "No cross references in this node"))
1793         (setq wrapped t)
1794         (goto-char (point-max))
1795         (unless (re-search-backward pat nil t)
1796           (goto-char old-pt)
1797           (error "No cross references in this node")))
1798       (unless (save-excursion
1799                 (goto-char (match-beginning 0))
1800                 (when (looking-at "\\* Menu:")
1801                   (decf n)))
1802         (setq found-nomenu t))
1803       (incf n))
1804     (while (> n 0)
1805       (or (eobp) (forward-char 1))
1806       (unless (re-search-forward pat nil t)
1807         (when (and wrapped (not found-nomenu))
1808           (goto-char old-pt)
1809           (error "No cross references in this node"))
1810         (setq wrapped t)
1811         (goto-char (point-min))
1812         (unless (re-search-forward pat nil t)
1813           (goto-char old-pt)
1814           (error "No cross references in this node")))
1815       (unless (save-excursion
1816                 (goto-char (match-beginning 0))
1817                 (when (looking-at "\\* Menu:")
1818                   (incf n)))
1819         (setq found-nomenu t))
1820       (decf n))
1821     (when (looking-at "\\* Menu:")
1822       (error "No cross references in this node"))
1823     (goto-char (match-beginning 0))))
1824
1825 (defun Info-prev-reference (n)
1826   (interactive "p")
1827   (Info-next-reference (- n)))
1828
1829 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1830   (skip-chars-forward " \t\n")
1831   (let ((beg (point))
1832         str i)
1833     (skip-chars-forward "^:")
1834     (forward-char 1)
1835     (setq str
1836           (if (looking-at ":")
1837               (buffer-substring beg (1- (point)))
1838             (skip-chars-forward " \t\n")
1839             (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1840     (while (setq i (string-match "\n" str i))
1841       (aset str i ?\ ))
1842     str))
1843
1844 (defun Info-menu (menu-item)
1845   "Go to node for menu item named (or abbreviated) NAME.
1846 Completion is allowed, and the menu item point is on is the default."
1847   (interactive
1848    (let ((completions '())
1849          ;; If point is within a menu item, use that item as the default
1850          (default nil)
1851          (p (point))
1852          (last nil))
1853      (save-excursion
1854        (goto-char (point-min))
1855        (let ((case-fold-search t))
1856          (if (not (search-forward "\n* menu:" nil t))
1857              (error "No menu in this node")))
1858        (while (re-search-forward
1859                 "\n\\* \\([^:\t\n]*\\):" nil t)
1860          (if (and (null default)
1861                   (prog1 (if last (< last p) nil)
1862                     (setq last (match-beginning 0)))
1863                   (<= p last))
1864              (setq default (car (car completions))))
1865          (setq completions (cons (cons (buffer-substring
1866                                          (match-beginning 1)
1867                                          (match-end 1))
1868                                        (match-beginning 1))
1869                                  completions)))
1870        (if (and (null default) last
1871                 (< last p)
1872                 (<= p (progn (end-of-line) (point))))
1873            (setq default (car (car completions)))))
1874      (let ((item nil))
1875        (while (null item)
1876          (setq item (let ((completion-ignore-case t))
1877                       (completing-read (if default
1878                                            (format "Menu item (default %s): "
1879                                                    default)
1880                                            "Menu item: ")
1881                                        completions nil t nil
1882                                        'Info-minibuffer-history)))
1883          ;; we rely on the fact that completing-read accepts an input
1884          ;; of "" even when the require-match argument is true and ""
1885          ;; is not a valid possibility
1886          (if (string= item "")
1887              (if default
1888                  (setq item default)
1889                  ;; ask again
1890                  (setq item nil))))
1891        (list item))))
1892   ;; there is a problem here in that if several menu items have the same
1893   ;; name you can only go to the node of the first with this command.
1894   (Info-goto-node (Info-extract-menu-item menu-item) nil t))
1895   
1896 (defun Info-extract-menu-item (menu-item &optional noerror)
1897   (save-excursion
1898     (goto-char (point-min))
1899     (if (let ((case-fold-search t))
1900           (search-forward "\n* menu:" nil t))
1901         (if (or (search-forward (concat "\n* " menu-item ":") nil t)
1902                 (search-forward (concat "\n* " menu-item) nil t))
1903             (progn
1904               (beginning-of-line)
1905               (forward-char 2)
1906               (Info-extract-menu-node-name))
1907           (and (not noerror) (error "No such item in menu")))
1908       (and (not noerror) (error "No menu in this node")))))
1909
1910 ;; If COUNT is nil, use the last item in the menu.
1911 (defun Info-extract-menu-counting (count &optional noerror noindex)
1912   (save-excursion
1913     (goto-char (point-min))
1914     (if (let ((case-fold-search t))
1915           (and (search-forward "\n* menu:" nil t)
1916                (or (not noindex)
1917                    (not (string-match "\\<Index\\>" Info-current-node)))))
1918         (if (search-forward "\n* " nil t count)
1919             (progn
1920               (or count
1921                   (while (search-forward "\n* " nil t)))
1922               (Info-extract-menu-node-name))
1923           (and (not noerror) (error "Too few items in menu")))
1924       (and (not noerror) (error "No menu in this node")))))
1925
1926 (defun Info-nth-menu-item (n)
1927   "Go to the node of the Nth menu item."
1928   (interactive "P")
1929   (or n (setq n (- last-command-char ?0)))
1930   (if (< n 1) (error "Index must be at least 1"))
1931   (Info-goto-node (Info-extract-menu-counting n) nil t))
1932
1933 (defun Info-last-menu-item ()
1934   "Go to the node of the tenth menu item."
1935   (interactive)
1936   (Info-goto-node (Info-extract-menu-counting nil) nil t))
1937 \f
1938 (defun Info-top ()
1939   "Go to the Top node of this file."
1940   (interactive)
1941   (Info-goto-node "Top"))
1942
1943 (defun Info-end ()
1944   "Go to the final node in this file."
1945   (interactive)
1946   (Info-top)
1947   (let ((Info-keeping-history nil)
1948         node)
1949     (Info-last-menu-item)
1950     (while (setq node (or (Info-extract-pointer "next" t)
1951                           (Info-extract-menu-counting nil t t)))
1952       (Info-goto-node node))
1953     (or (equal (Info-extract-pointer "up" t) "Top")
1954         (let ((executing-kbd-macro ""))   ; suppress messages
1955           (condition-case nil
1956               (Info-global-next 10000)
1957             (error nil))))))
1958
1959 (defun Info-global-next (&optional n)
1960   "Go to the next node in this file, traversing node structure as necessary.
1961 This works only if the Info file is structured as a hierarchy of nodes.
1962 A positive or negative prefix argument moves by multiple nodes."
1963   (interactive "p")
1964   (or n (setq n 1))
1965   (if (< n 0)
1966       (Info-global-prev (- n))
1967     (while (>= (setq n (1- n)) 0)
1968       (let (node)
1969         (cond ((and (string-match "^Top$" Info-current-node)
1970                     (setq node (Info-extract-pointer "next" t))
1971                     (Info-extract-menu-item node t))
1972                (Info-goto-node node))
1973               ((setq node (Info-extract-menu-counting 1 t t))
1974                (message "Going down...")
1975                (Info-goto-node node))
1976               (t
1977                (let ((Info-keeping-history Info-keeping-history)
1978                      (orignode Info-current-node)
1979                      (ups ""))
1980                  (while (not (Info-extract-pointer "next" t))
1981                    (if (and (setq node (Info-extract-pointer "up" t))
1982                             (not (equal node "Top")))
1983                        (progn
1984                          (message "Going%s..." (setq ups (concat ups " up")))
1985                          (Info-goto-node node)
1986                          (setq Info-keeping-history nil))
1987                      (if orignode
1988                          (let ((Info-keeping-history nil))
1989                            (Info-goto-node orignode)))
1990                      (error "Last node in file")))
1991                  (Info-next))))))))
1992
1993 (defun Info-page-next (&optional n)
1994   "Scroll forward one screenful, or go to next global node.
1995 A positive or negative prefix argument moves by multiple screenfuls."
1996   (interactive "p")
1997   (or n (setq n 1))
1998   (if (< n 0)
1999       (Info-page-prev (- n))
2000     (while (>= (setq n (1- n)) 0)
2001       (if (pos-visible-in-window-p (point-max))
2002           (progn
2003             (Info-global-next)
2004             (message "Node: %s" Info-current-node))
2005         (scroll-up)))))
2006
2007 (defun Info-scroll-next (arg)
2008   (interactive "P")
2009   (if Info-auto-advance
2010       (if (and (pos-visible-in-window-p (point-max))
2011                (not (eq Info-auto-advance t))
2012                (not (eq last-command this-command)))
2013           (message "Hit %s again to go to next node"
2014                    (if (= last-command-char 0)
2015                        "mouse button"
2016                      (key-description (char-to-string last-command-char))))
2017         (Info-page-next)
2018         (setq this-command 'Info))
2019     (scroll-up arg)))
2020
2021 (defun Info-global-prev (&optional n)
2022   "Go to the previous node in this file, traversing structure as necessary.
2023 This works only if the Info file is structured as a hierarchy of nodes.
2024 A positive or negative prefix argument moves by multiple nodes."
2025   (interactive "p")
2026   (or n (setq n 1))
2027   (if (< n 0)
2028       (Info-global-next (- n))
2029     (while (>= (setq n (1- n)) 0)
2030       (let ((upnode (Info-extract-pointer "up" t))
2031             (prevnode (Info-extract-pointer "prev[ious]*" t)))
2032         (if (or (not prevnode)
2033                 (equal prevnode upnode))
2034             (if (string-match "^Top$" Info-current-node)
2035                 (error "First node in file")
2036               (message "Going up...")
2037               (Info-up))
2038           (Info-goto-node prevnode)
2039           (let ((downs "")
2040                 (Info-keeping-history nil)
2041                 node)
2042             (while (setq node (Info-extract-menu-counting nil t t))
2043               (message "Going%s..." (setq downs (concat downs " down")))
2044               (Info-goto-node node))))))))
2045
2046 (defun Info-page-prev (&optional n)
2047   "Scroll backward one screenful, or go to previous global node.
2048 A positive or negative prefix argument moves by multiple screenfuls."
2049   (interactive "p")
2050   (or n (setq n 1))
2051   (if (< n 0)
2052       (Info-page-next (- n))
2053     (while (>= (setq n (1- n)) 0)
2054       (if (pos-visible-in-window-p (point-min))
2055           (progn
2056             (Info-global-prev)
2057             (message "Node: %s" Info-current-node)
2058             (sit-for 0)
2059             ;;(scroll-up 1)   ; work around bug in pos-visible-in-window-p
2060             ;;(scroll-down 1)
2061             (while (not (pos-visible-in-window-p (point-max)))
2062               (scroll-up)))
2063         (scroll-down)))))
2064
2065 (defun Info-scroll-prev (arg)
2066   (interactive "P")
2067   (if Info-auto-advance
2068       (if (and (pos-visible-in-window-p (point-min))
2069                (not (eq Info-auto-advance t))
2070                (not (eq last-command this-command)))
2071           (message "Hit %s again to go to previous node"
2072                    (if (= last-command-char 0)
2073                        "mouse button"
2074                      (key-description (char-to-string last-command-char))))
2075         (Info-page-prev)
2076         (setq this-command 'Info))
2077     (scroll-down arg)))
2078 \f
2079 (defun Info-index (topic)
2080   "Look up a string in the index for this file.
2081 The index is defined as the first node in the top-level menu whose
2082 name contains the word \"Index\", plus any immediately following
2083 nodes whose names also contain the word \"Index\".
2084 If there are no exact matches to the specified topic, this chooses
2085 the first match which is a case-insensitive substring of a topic.
2086 Use the `,' command to see the other matches.
2087 Give a blank topic name to go to the Index node itself."
2088   (interactive "sIndex topic: ")
2089   (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
2090                          (regexp-quote topic)
2091                          "\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"))
2092         node)
2093     (message "Searching index for `%s'..." topic)
2094     (Info-goto-node "Top")
2095     (let ((case-fold-search t))
2096       (or (search-forward "\n* menu:" nil t)
2097           (error "No index"))
2098       (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2099           (error "No index")))
2100     (goto-char (match-beginning 1))
2101     (let ((Info-keeping-history nil)
2102           (Info-fontify (and Info-fontify (equal topic ""))))
2103       (Info-goto-node (Info-extract-menu-node-name)))
2104     (or (equal topic "")
2105         (let ((matches nil)
2106               (exact nil)
2107               (Info-keeping-history nil)
2108               found)
2109           (while
2110               (progn
2111                 (goto-char (point-min))
2112                 (while (re-search-forward pattern nil t)
2113                   (setq matches
2114                         (cons (list (buffer-substring (match-beginning 1)
2115                                                       (match-end 1))
2116                                     (buffer-substring (match-beginning 2)
2117                                                       (match-end 2))
2118                                     Info-current-node
2119                                     (string-to-int (concat "0"
2120                                                            (buffer-substring
2121                                                             (match-beginning 3)
2122                                                             (match-end 3)))))
2123                               matches)))
2124                 (and (setq node (Info-extract-pointer "next" t))
2125                      (string-match "\\<Index\\>" node)))
2126             (let ((Info-fontify nil))
2127               (Info-goto-node node)))
2128           (or matches
2129               (progn
2130                 (Info-last)
2131                 (error "No \"%s\" in index" topic)))
2132           ;; Here it is a feature that assoc is case-sensitive.
2133           (while (setq found (assoc topic matches))
2134             (setq exact (cons found exact)
2135                   matches (delq found matches)))
2136           (setq Info-index-alternatives (nconc exact (nreverse matches))
2137                 Info-index-first-alternative (car Info-index-alternatives))
2138           (Info-index-next 0)))))
2139
2140 (defun Info-index-next (num)
2141   "Go to the next matching index item from the last `i' command."
2142   (interactive "p")
2143   (or Info-index-alternatives
2144       (error "No previous `i' command in this file"))
2145   (while (< num 0)
2146     (setq num (+ num (length Info-index-alternatives))))
2147   (while (> num 0)
2148     (setq Info-index-alternatives
2149           (nconc (cdr Info-index-alternatives)
2150                  (list (car Info-index-alternatives)))
2151           num (1- num)))
2152   (Info-goto-node (nth 1 (car Info-index-alternatives)))
2153   (if (> (nth 3 (car Info-index-alternatives)) 0)
2154       (forward-line (nth 3 (car Info-index-alternatives)))
2155     (forward-line 3)  ; don't search in headers
2156     (let ((name (car (car Info-index-alternatives))))
2157       (if (or (re-search-forward (format
2158                                   "\\(Function\\|Command\\): %s\\( \\|$\\)"
2159                                   (regexp-quote name)) nil t)
2160               (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
2161               (search-forward (format "`%s'" name) nil t)
2162               (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2163                    (search-forward
2164                     (format "`%s'" (substring name 0 (match-beginning 1)))
2165                     nil t))
2166               (search-forward name nil t))
2167           (beginning-of-line)
2168         (goto-char (point-min)))))
2169   (message "Found \"%s\" in %s.  %s"
2170            (car (car Info-index-alternatives))
2171            (nth 2 (car Info-index-alternatives))
2172            (if (cdr Info-index-alternatives)
2173                (if (eq (car (cdr Info-index-alternatives))
2174                        Info-index-first-alternative)
2175                    "(Press `,' to repeat)"
2176                  (format "(Press `,' for %d more)"
2177                          (- (1- (length Info-index-alternatives))
2178                             (length (memq Info-index-first-alternative
2179                                           (cdr Info-index-alternatives))))))
2180              "(Only match)")))
2181
2182
2183 ;;;###autoload
2184 (defun Info-emacs-command (command)
2185   "Look up an Emacs command in the Emacs manual in the Info system.
2186 This command is designed to be used whether you are already in Info or not."
2187   (interactive "CLook up command in Emacs manual: ")
2188   (save-window-excursion
2189     (info)
2190     (Info-find-node Info-emacs-info-file-name "Top")
2191     (Info-index (symbol-name command)))
2192   (pop-to-buffer "*info*"))
2193
2194
2195 ;;;###autoload
2196 (defun Info-goto-emacs-command-node (key)
2197   "Look up an Emacs command in the Emacs manual in the Info system.
2198 This command is designed to be used whether you are already in Info or not."
2199   (interactive "CLook up command in Emacs manual: ")
2200   (Info-emacs-command key))
2201
2202 ;;;###autoload
2203 (defun Info-goto-emacs-key-command-node (key)
2204   "Look up an Emacs key sequence in the Emacs manual in the Info system.
2205 This command is designed to be used whether you are already in Info or not."
2206   (interactive "kLook up key in Emacs manual: ")
2207   (let ((command (key-binding key)))
2208     (cond ((eq command 'keyboard-quit)
2209            (keyboard-quit))
2210           ((null command)
2211            (error "%s is undefined" (key-description key)))
2212           ((and (interactive-p) (eq command 'execute-extended-command))
2213            (call-interactively 'Info-goto-emacs-command-node))
2214           (t
2215            (Info-goto-emacs-command-node command)))))
2216
2217 ;;;###autoload
2218 (defun Info-emacs-key (key)
2219   "Look up an Emacs key sequence in the Emacs manual in the Info system.
2220 This command is designed to be used whether you are already in Info or not."
2221   (interactive "kLook up key in Emacs manual: ")
2222   (cond ((eq (key-binding key) 'keyboard-quit)
2223          (keyboard-quit))
2224         ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
2225          (call-interactively 'Info-goto-emacs-command-node))
2226         (t
2227          (save-window-excursion
2228            (info)
2229            (Info-find-node Info-emacs-info-file-name "Top")
2230            (setq key (key-description key))
2231            (let (p)
2232              (if (setq p (string-match "[@{}]" key))
2233                  (setq key (concat (substring key 0 p) "@" (substring key p))))
2234              (if (string-match "^ESC " key)
2235                  (setq key (concat "M-" (substring key 4))))
2236              (if (string-match "^M-C-" key)
2237                  (setq key (concat "C-M-" (substring key 4)))))
2238            (Info-index key))
2239          (pop-to-buffer "*info*"))))
2240
2241 ;;;###autoload
2242 (defun Info-elisp-ref (func)
2243   "Look up an Emacs Lisp function in the Elisp manual in the Info system.
2244 This command is designed to be used whether you are already in Info or not."
2245   (interactive (let ((fn (function-at-point))
2246                      (enable-recursive-minibuffers t)        
2247                      val)
2248                  (setq val (completing-read
2249                             (format "Look up Emacs Lisp function%s: "
2250                                     (if fn
2251                                         (format " (default %s)" fn)
2252                                       ""))
2253                             obarray 'fboundp t))
2254                  (list (if (equal val "")
2255                            fn (intern val)))))
2256   (save-window-excursion
2257     (info)
2258     (condition-case nil
2259         (Info-find-node "lispref" "Top")
2260       (error (Info-find-node "elisp" "Top")))
2261     (Info-index (symbol-name func)))
2262   (pop-to-buffer "*info*"))
2263 \f
2264 (defun Info-reannotate-node ()
2265   (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
2266     (if bufs
2267         (let ((ibuf (current-buffer))
2268               (file (concat "\\(" (regexp-quote
2269                              (file-name-nondirectory Info-current-file))
2270                             "\\|" (regexp-quote Info-current-file) "\\)"))
2271               (node (regexp-quote Info-current-node))
2272               (savept (point)))
2273           (goto-char (point-min))
2274           (if (search-forward "\n------ NOTE:\n" nil t)
2275               (let ((buffer-read-only nil)
2276                     (bufmod (buffer-modified-p))
2277                     top)
2278                 (setq savept (copy-marker savept))
2279                 (goto-char (point-min))
2280                 (while (search-forward "\n------ NOTE:" nil t)
2281                   (setq top (1+ (match-beginning 0)))
2282                   (if (search-forward "\n------\n" nil t)
2283                       (delete-region top (point)))
2284                   (backward-char 1))
2285                 (set-buffer-modified-p bufmod)))
2286           (save-excursion
2287             (while bufs
2288               (set-buffer (car bufs))
2289               (goto-char (point-min))
2290               (while (re-search-forward
2291                       (format
2292                        "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
2293                        file node)
2294                       nil t)
2295                 (let ((line (string-to-int
2296                              (buffer-substring (match-beginning 2)
2297                                                (match-end 2))))
2298                       (top (point))
2299                       bot)
2300                   (search-forward "\n------\n" nil t)
2301                   (setq bot (point))
2302                   (save-excursion
2303                     (set-buffer ibuf)
2304                     (if (integerp savept) (setq savept (copy-marker savept)))
2305                     (if (= line 0)
2306                         (goto-char (point-max))
2307                       (goto-char (point-min))
2308                       (forward-line line))
2309                     (let ((buffer-read-only nil)
2310                           (bufmod (buffer-modified-p)))
2311                       (insert "------ NOTE:\n")
2312                       (insert-buffer-substring (car bufs) top bot)
2313                       (set-buffer-modified-p bufmod)))))
2314               (setq bufs (cdr bufs))))
2315           (goto-char savept)))))
2316
2317 (defvar Info-annotate-map nil
2318   "Local keymap used within `a' command of Info.")
2319 (if Info-annotate-map
2320     nil
2321   ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
2322   (setq Info-annotate-map (copy-keymap text-mode-map))
2323   (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
2324
2325 (defun Info-annotate-mode ()
2326   "Major mode for adding an annotation to an Info node.
2327 Like text mode with the addition of Info-cease-annotate
2328 which returns to Info mode for browsing.
2329 \\{Info-annotate-map}")
2330
2331 (defun Info-annotate (arg)
2332   "Add a personal annotation to the current Info node.
2333  Only you will be able to see this annotation.  Annotations are stored
2334 in the file \"~/.xemacs/info.notes\" by default.  If point is inside
2335 an existing annotation, edit that annotation.  A prefix argument
2336 specifies which annotations file (from `Info-annotations-path') is to
2337 be edited; default is 1."
2338   (interactive "p")
2339   (setq arg (1- arg))
2340   (if (or (< arg 0) (not (nth arg Info-annotations-path)))
2341       (if (= arg 0)
2342           (setq Info-annotations-path
2343                 (list (read-file-name
2344                        "Annotations file: " "~/" "~/.infonotes")))
2345         (error "File number must be in the range from 1 to %d"
2346                (length Info-annotations-path))))
2347   (let ((which nil)
2348         (file (file-name-nondirectory Info-current-file))
2349         (d Info-directory-list)
2350         where pt)
2351     (while (and d (not (equal (expand-file-name file (car d))
2352                               Info-current-file)))
2353       (setq d (cdr d)))
2354     (or d (setq file Info-current-file))
2355     (if (and (save-excursion
2356                (goto-char (min (point-max) (+ (point) 13)))
2357                (and (search-backward "------ NOTE:\n" nil t)
2358                     (setq pt (match-end 0))
2359                     (search-forward "\n------\n" nil t)))
2360              (< (point) (match-end 0)))
2361         (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
2362                             (regexp-quote file)
2363                             (regexp-quote Info-current-node)
2364                             (regexp-quote
2365                              (buffer-substring pt (match-beginning 0))))
2366               where (max (- (point) pt) 0)))
2367     (let ((node Info-current-node)
2368           (line (if (looking-at "[ \n]*\\'") 0
2369                   (count-lines (point-min) (point)))))
2370       (or which
2371           (let ((buffer-read-only nil)
2372                 (bufmod (buffer-modified-p)))
2373             (beginning-of-line)
2374             (if (bobp) (goto-char (point-max)))
2375             (insert "------ NOTE:\n------\n")
2376             (backward-char 20)
2377             (set-buffer-modified-p bufmod)))
2378       ;; (setq Info-window-start (window-start))
2379       (setq Info-window-configuration (current-window-configuration))
2380       (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
2381       (use-local-map Info-annotate-map)
2382       (setq major-mode 'Info-annotate-mode)
2383       (setq mode-name "Info Annotate")
2384       (if which
2385           (if (save-excursion
2386                 (goto-char (point-min))
2387                 (re-search-forward which nil t))
2388               (progn
2389                 (goto-char (match-beginning 0))
2390                 (forward-line 1)
2391                 (forward-char where)))
2392         (let ((bufmod (buffer-modified-p)))
2393           (goto-char (point-max))
2394           (insert (format "\n------ File: %s  Node: %s  Line: %d\n"
2395                           file node line))
2396           (setq pt (point))
2397           (insert "\n------\n"
2398                   "\nPress C-c C-c to save and return to Info.\n")
2399           (goto-char pt)
2400           (set-buffer-modified-p bufmod))))))
2401
2402 (defun Info-cease-annotate ()
2403   (interactive)
2404   (let ((bufmod (buffer-modified-p)))
2405     (while (save-excursion
2406              (goto-char (point-min))
2407              (re-search-forward "\n\n?Press .* to save and return to Info.\n"
2408                                 nil t))
2409       (delete-region (1+ (match-beginning 0)) (match-end 0)))
2410     (while (save-excursion
2411              (goto-char (point-min))
2412              (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
2413                                 nil t))
2414       (delete-region (match-beginning 0) (match-end 0)))
2415     (set-buffer-modified-p bufmod))
2416   (save-buffer)
2417   (fundamental-mode)
2418   (bury-buffer)
2419   (or (one-window-p) (delete-window))
2420   (info)
2421   (setq Info-current-annotation-completions nil)
2422   (set-window-configuration Info-window-configuration)
2423   (Info-reannotate-node))
2424
2425 (defun Info-bookmark (arg tag)
2426   (interactive "p\nsBookmark name: ")
2427   (Info-annotate arg)
2428   (if (or (string-match "^\"\\(.*\\)\"$" tag)
2429           (string-match "^<<\\(.*\\)>>$" tag))
2430       (setq tag (substring tag (match-beginning 1) (match-end 1))))
2431   (let ((pt (point)))
2432     (search-forward "\n------\n")
2433     (let ((end (- (point) 8)))
2434       (goto-char pt)
2435       (if (re-search-forward "<<[^>\n]*>>" nil t)
2436           (delete-region (match-beginning 0) (match-end 0))
2437         (goto-char end))
2438       (or (equal tag "")
2439           (insert "<<" tag ">>"))))
2440   (Info-cease-annotate))
2441 \f
2442 (defun Info-exit ()
2443   "Exit Info by selecting some other buffer."
2444   (interactive)
2445   (if Info-standalone
2446       (save-buffers-kill-emacs)
2447     (bury-buffer (current-buffer))
2448     (if (and (featurep 'toolbar)
2449              (boundp 'toolbar-info-frame)
2450              (eq toolbar-info-frame (selected-frame)))
2451         (condition-case ()
2452             (delete-frame toolbar-info-frame)
2453           (error (bury-buffer)))
2454       (switch-to-buffer (other-buffer (current-buffer))))))
2455
2456 (defun Info-undefined ()
2457   "Make command be undefined in Info."
2458   (interactive)
2459   (ding))
2460
2461 (defun Info-help ()
2462   "Enter the Info tutorial."
2463   (interactive)
2464   (delete-other-windows)
2465   (Info-find-node "info"
2466                   (if (< (window-height) 23)
2467                       "Help-Small-Screen"
2468                     "Help")))
2469
2470 (defun Info-summary ()
2471   "Display a brief summary of all Info commands."
2472   (interactive)
2473   (save-window-excursion
2474     (switch-to-buffer "*Help*")
2475     (erase-buffer)
2476     (insert (documentation 'Info-mode))
2477     (goto-char (point-min))
2478     (let (flag)
2479       (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2480                     (message (if flag "Type Space to see more"
2481                                "Type Space to return to Info"))
2482                     (let ((e (next-command-event)))
2483                       (if (/= ?\  (event-to-character e))
2484                           (progn (setq unread-command-event e) nil)
2485                         flag)))
2486         (scroll-up)))
2487     (message "")
2488     (bury-buffer "*Help*")))
2489 \f
2490 (defun Info-get-token (pos start all &optional errorstring)
2491   "Return the token around POS,
2492 POS must be somewhere inside the token
2493 START is a regular expression which will match the
2494     beginning of the tokens delimited string
2495 ALL is a regular expression with a single
2496     parenthized subpattern which is the token to be
2497     returned. E.g. '{\(.*\)}' would return any string
2498     enclosed in braces around POS.
2499 SIG optional fourth argument, controls action on no match
2500     nil: return nil
2501     t: beep
2502     a string: signal an error, using that string."
2503   (save-excursion
2504     (goto-char (point-min))
2505     (re-search-backward "\\`")  ; Bug fix due to Nicholas J. Foskett.
2506     (goto-char pos)
2507     (re-search-backward start (max (point-min) (- pos 200)) 'yes)
2508     (let (found)
2509       (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2510                   (not (setq found (and (<= (match-beginning 0) pos)
2511                                         (> (match-end 0) pos))))))
2512       (if (and found (<= (match-beginning 0) pos)
2513                (> (match-end 0) pos))
2514           (buffer-substring (match-beginning 1) (match-end 1))
2515         (cond ((null errorstring)
2516                nil)
2517               ((eq errorstring t)
2518                (beep)
2519                nil)
2520               (t
2521                (error "No %s around position %d" errorstring pos)))))))
2522
2523 (defun Info-follow-clicked-node (event)
2524   "Follow a node reference near clicked point.  Like M, F, N, P or U command.
2525 At end of the node's text, moves to the next node."
2526   (interactive "@e")
2527   (or (and (event-point event)
2528            (Info-follow-nearest-node
2529             (max (progn
2530                    (select-window (event-window event))
2531                    (event-point event))
2532                  (1+ (point-min)))))
2533       (error "click on a cross-reference to follow")))
2534
2535 (defun Info-maybe-follow-clicked-node (event &optional click-count)
2536   "Follow a node reference (if any) near clicked point.
2537 Like M, F, N, P or U command.  At end of the node's text, moves to the
2538 next node.  No error is given if there is no node to follow."
2539   (interactive "@e")
2540   (and Info-button1-follows-hyperlink
2541        (event-point event)
2542        (Info-follow-nearest-node
2543         (max (progn
2544                (select-window (event-window event))
2545                (event-point event))
2546              (1+ (point-min))))))
2547
2548 (defun Info-find-nearest-node (point)
2549   (let (node)
2550     (cond
2551      ((= point (point-min)) nil)   ; don't trigger on accidental RET.
2552      ((setq node (Info-get-token point
2553                                  (format "\\*%s[ \n]" Info-footnote-tag)
2554                                  (format "\\*%s[ \n]\\([^:]*\\):"
2555                                          Info-footnote-tag)))
2556       (list "Following cross-reference %s..."
2557             (list 'Info-follow-reference node)))
2558      ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\)::"))
2559       (list "Selecting menu item %s..."
2560             (list 'Info-goto-node node nil t)))
2561      ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\):"))
2562       (list "Selecting menu item %s..."
2563             (list 'Info-menu node)))
2564      ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
2565       (list "Going up..."
2566             (list 'Info-goto-node node)))
2567      ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
2568       (list "Next node..."
2569             (list 'Info-goto-node node)))
2570      ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
2571       (list "Top node..."
2572             (list 'Info-goto-node "Top")))
2573      ((setq node (Info-get-token point "Prev[ious]*: "
2574                                  "Prev[ious]*: \\([^,\n\t]*\\)"))
2575       (list "Previous node..."
2576             (list 'Info-goto-node node)))
2577      ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
2578       (list "Reselecting %s..."
2579             (list 'Info-goto-node node)))
2580      ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
2581       (if Info-in-cross-reference
2582           (list "Back to last node..."
2583                 '(Info-last))
2584         (list "Next node..."
2585               '(Info-global-next)))))
2586     ))
2587
2588 (defun Info-follow-nearest-node (point)
2589   "Follow a node reference near point.  Like M, F, N, P or U command.
2590 At end of the node's text, moves to the next node."
2591   (interactive "d")
2592   (let ((data (Info-find-nearest-node point)))
2593     (if (null data)
2594         nil
2595       (let ((msg (format (car data) (nth 1 (nth 1 data)))))
2596         (message "%s" msg)
2597         (eval (nth 1 data))
2598         (message "%sdone" msg))
2599       t)))
2600
2601 (defun Info-indicated-node (event)
2602   (condition-case ()
2603       (save-excursion
2604         (cond ((eventp event)
2605                (set-buffer (event-buffer event))
2606                (setq event (event-point event))))
2607         (let* ((data (Info-find-nearest-node event))
2608                (name (nth 1 (nth 1 data))))
2609           (and name (nth 1 data))))
2610     (error nil)))
2611 \f
2612 (defun Info-mouse-track-double-click-hook (event click-count)
2613   "Handle double-clicks by turning pages, like the `gv' ghostscript viewer"
2614   (if (/= click-count 2)
2615       ;; Return nil so any other hooks are performed.
2616       nil
2617       (let* ((x (event-x-pixel event))
2618              (y (event-y-pixel event))
2619              (w (window-pixel-width (event-window event)))
2620              (h (window-pixel-height (event-window event)))
2621              (w/3 (/ w 3))
2622              (w/2 (/ w 2))
2623              (h/4 (/ h 4)))
2624         (cond
2625           ;; In the top 1/4 and inside the middle 1/3
2626           ((and (<= y h/4)
2627                 (and (>= x w/3) (<= x (+ w/3 w/3))))
2628            (Info-up)
2629            t)
2630           ;; In the bottom 1/4 and inside the middle 1/3
2631           ((and (>= y (+ h/4 h/4 h/4))
2632                 (and (>= x w/3) (<= x (+ w/3 w/3))))
2633            (Info-nth-menu-item 1)
2634            t)
2635           ;; In the lower 3/4 and the right 1/2
2636           ;; OR in the upper 1/4 and the right 1/3
2637           ((or (and (>= y h/4) (>= x w/2))
2638                (and (< y h/4) (>= x (+ w/3 w/3))))
2639            (Info-next)
2640            t)
2641           ;; In the lower 3/4 and the left 1/2
2642           ;; OR in the upper 1/4 and the left 1/3
2643           ((or (and (>= y h/4) (< x w/2))
2644                (and (< y h/4) (<= x w/3)))
2645            (Info-prev)
2646            t)
2647           ;; This shouldn't happen.
2648           (t
2649            (error "event out of bounds: %s %s" x y))))))
2650 \f
2651 (defvar Info-mode-map nil
2652   "Keymap containing Info commands.")
2653 (if Info-mode-map
2654     nil
2655   (setq Info-mode-map (make-sparse-keymap))
2656   (suppress-keymap Info-mode-map)
2657   (define-key Info-mode-map "." 'beginning-of-buffer)
2658   (define-key Info-mode-map " " 'Info-scroll-next)
2659   (define-key Info-mode-map "1" 'Info-nth-menu-item)
2660   (define-key Info-mode-map "2" 'Info-nth-menu-item)
2661   (define-key Info-mode-map "3" 'Info-nth-menu-item)
2662   (define-key Info-mode-map "4" 'Info-nth-menu-item)
2663   (define-key Info-mode-map "5" 'Info-nth-menu-item)
2664   (define-key Info-mode-map "6" 'Info-nth-menu-item)
2665   (define-key Info-mode-map "7" 'Info-nth-menu-item)
2666   (define-key Info-mode-map "8" 'Info-nth-menu-item)
2667   (define-key Info-mode-map "9" 'Info-nth-menu-item)
2668   (define-key Info-mode-map "0" 'Info-last-menu-item)
2669   (define-key Info-mode-map "?" 'Info-summary)
2670   (define-key Info-mode-map "a" 'Info-annotate)
2671   (define-key Info-mode-map "b" 'beginning-of-buffer)
2672   (define-key Info-mode-map "d" 'Info-directory)
2673   (define-key Info-mode-map "e" 'Info-edit)
2674   (define-key Info-mode-map "f" 'Info-follow-reference)
2675   (define-key Info-mode-map "g" 'Info-goto-node)
2676   (define-key Info-mode-map "h" 'Info-help)
2677   (define-key Info-mode-map "i" 'Info-index)
2678   (define-key Info-mode-map "j" 'Info-goto-bookmark)
2679   (define-key Info-mode-map "k" 'Info-emacs-key)
2680   (define-key Info-mode-map "l" 'Info-last)
2681   (define-key Info-mode-map "m" 'Info-menu)
2682   (define-key Info-mode-map "n" 'Info-next)
2683   (define-key Info-mode-map "p" 'Info-prev)
2684   (define-key Info-mode-map "q" 'Info-exit)
2685   (define-key Info-mode-map "r" 'Info-follow-reference)
2686   (define-key Info-mode-map "s" 'Info-search)
2687   (define-key Info-mode-map "t" 'Info-top)
2688   (define-key Info-mode-map "u" 'Info-up)
2689   (define-key Info-mode-map "v" 'Info-visit-file)
2690   (define-key Info-mode-map "x" 'Info-bookmark)
2691   (define-key Info-mode-map "<" 'Info-top)
2692   (define-key Info-mode-map ">" 'Info-end)
2693   (define-key Info-mode-map "[" 'Info-global-prev)
2694   (define-key Info-mode-map "]" 'Info-global-next)
2695   (define-key Info-mode-map "{" 'Info-page-prev)
2696   (define-key Info-mode-map "}" 'Info-page-next)
2697   (define-key Info-mode-map "=" 'Info-restore-point)
2698   (define-key Info-mode-map "!" 'Info-select-node)
2699   (define-key Info-mode-map "@" 'Info-follow-nearest-node)
2700   (define-key Info-mode-map "," 'Info-index-next)
2701   (define-key Info-mode-map "*" 'Info-elisp-ref)
2702   (define-key Info-mode-map [tab] 'Info-next-reference)
2703   (define-key Info-mode-map [(meta tab)] 'Info-prev-reference)
2704   (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2705   (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
2706   ;; XEmacs addition
2707   (define-key Info-mode-map 'backspace 'Info-scroll-prev)
2708   (define-key Info-mode-map 'delete 'Info-scroll-prev)
2709   (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
2710   (define-key Info-mode-map 'button3 'Info-select-node-menu))
2711
2712 \f
2713 ;; Info mode is suitable only for specially formatted data.
2714 (put 'info-mode 'mode-class 'special)
2715
2716 (defun Info-mode ()
2717   "Info mode is for browsing through the Info documentation tree.
2718 Documentation in Info is divided into \"nodes\", each of which
2719 discusses one topic and contains references to other nodes
2720 which discuss related topics.  Info has commands to follow
2721 the references and show you other nodes.
2722
2723 h       Invoke the Info tutorial.
2724 q       Quit Info: return to the previously selected file or buffer.
2725
2726 Selecting other nodes:
2727 n       Move to the \"next\" node of this node.
2728 p       Move to the \"previous\" node of this node.
2729 m       Pick menu item specified by name (or abbreviation).
2730 1-9, 0  Pick first..ninth, last item in node's menu.
2731         Menu items select nodes that are \"subsections\" of this node.
2732 u       Move \"up\" from this node (i.e., from a subsection to a section).
2733 f or r  Follow a cross reference by name (or abbrev).  Type `l' to get back.
2734 RET     Follow cross reference or menu item indicated by cursor.
2735 i       Look up a topic in this file's Index and move to that node.
2736 ,       (comma) Move to the next match from a previous `i' command.
2737 l       (letter L) Move back to the last node you were in.
2738
2739 Moving within a node:
2740 Space   Scroll forward a full screen.   DEL       Scroll backward.
2741 b       Go to beginning of node.        Meta->    Go to end of node.
2742 TAB     Go to next cross-reference.     Meta-TAB  Go to previous ref.
2743
2744 Mouse commands:
2745 Left Button     Set point.
2746 Middle Button   Click on a highlighted node reference to go to it.
2747 Right Button    Pop up a menu of applicable Info commands.
2748
2749 Advanced commands:
2750 g       Move to node, file, or annotation tag specified by name.
2751         Examples:  `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
2752 v       Move to file, with filename completion.
2753 k       Look up a key sequence in Emacs manual (also C-h C-k at any time).
2754 *       Look up a function name in Emacs Lisp manual (also C-h C-f).
2755 d       Go to the main directory of Info files.
2756 < or t  Go to Top (first) node of this file.
2757 >       Go to last node in this file.
2758 \[      Go to previous node, treating file as one linear document.
2759 \]      Go to next node, treating file as one linear document.
2760 {       Scroll backward, or go to previous node if at top.
2761 }       Scroll forward, or go to next node if at bottom.
2762 =       Restore cursor position from last time in this node.
2763 a       Add a private note (annotation) to the current node.
2764 x, j    Add, jump to a bookmark (annotation tag).
2765 s       Search this Info file for a node containing the specified regexp.
2766 e       Edit the contents of the current node."
2767   (kill-all-local-variables)
2768   (setq major-mode 'Info-mode)
2769   (setq mode-name "Info")
2770   (use-local-map Info-mode-map)
2771   (set-syntax-table text-mode-syntax-table)
2772   (setq local-abbrev-table text-mode-abbrev-table)
2773   (setq case-fold-search t)
2774   (setq buffer-read-only t)
2775 ;  (setq buffer-mouse-map Info-mode-mouse-map)
2776   (make-local-variable 'Info-current-file)
2777   (make-local-variable 'Info-current-subfile)
2778   (make-local-variable 'Info-current-node)
2779   (make-local-variable 'Info-tag-table-marker)
2780   (make-local-variable 'Info-current-file-completions)
2781   (make-local-variable 'Info-current-annotation-completions)
2782   (make-local-variable 'Info-index-alternatives)
2783   (make-local-variable 'Info-history)
2784   ;; Faces are now defined by `defface'...
2785   (make-local-variable 'mouse-track-click-hook)
2786   (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
2787   (add-hook 'mouse-track-click-hook 'Info-mouse-track-double-click-hook)
2788   ;; #### The console-on-window-system-p check is to allow this to
2789   ;; work on tty's.  The real problem here is that featurep really
2790   ;; needs to have some device/console domain knowledge added to it.
2791   (if (and (featurep 'toolbar)
2792            (console-on-window-system-p)
2793            (not Info-inhibit-toolbar))
2794       (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
2795   (if (featurep 'menubar)
2796       (progn
2797         ;; make a local copy of the menubar, so our modes don't
2798         ;; change the global menubar
2799         (easy-menu-add '("Info" :filter Info-menu-filter))))
2800   (run-hooks 'Info-mode-hook)
2801   (Info-set-mode-line))
2802
2803 (defvar Info-edit-map nil
2804   "Local keymap used within `e' command of Info.")
2805 (if Info-edit-map
2806     nil
2807   ;; XEmacs: remove FSF stuff
2808   (setq Info-edit-map (make-sparse-keymap))
2809   (set-keymap-name Info-edit-map 'Info-edit-map)
2810   (set-keymap-parents Info-edit-map (list text-mode-map))
2811   (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
2812
2813 ;; Info-edit mode is suitable only for specially formatted data.
2814 (put 'info-edit-mode 'mode-class 'special)
2815
2816 (defun Info-edit-mode ()
2817   "Major mode for editing the contents of an Info node.
2818 Like text mode with the addition of `Info-cease-edit'
2819 which returns to Info mode for browsing.
2820 \\{Info-edit-map}"
2821   )
2822
2823 (defun Info-edit ()
2824   "Edit the contents of this Info node.
2825 Allowed only if variable `Info-enable-edit' is non-nil."
2826   (interactive)
2827   (or Info-enable-edit
2828       (error "Editing info nodes is not enabled"))
2829   (use-local-map Info-edit-map)
2830   (setq major-mode 'Info-edit-mode)
2831   (setq mode-name "Info Edit")
2832   (kill-local-variable 'modeline-buffer-identification)
2833   (setq buffer-read-only nil)
2834   ;; Make mode line update.
2835   (set-buffer-modified-p (buffer-modified-p))
2836   (message (substitute-command-keys
2837              "Editing: Type \\[Info-cease-edit] to return to info")))
2838
2839 (defun Info-cease-edit ()
2840   "Finish editing Info node; switch back to Info proper."
2841   (interactive)
2842   ;; Do this first, so nothing has changed if user C-g's at query.
2843   (and (buffer-modified-p)
2844        (y-or-n-p-maybe-dialog-box "Save the file? ")
2845        (save-buffer))
2846   (use-local-map Info-mode-map)
2847   (setq major-mode 'Info-mode)
2848   (setq mode-name "Info")
2849   (Info-set-mode-line)
2850   (setq buffer-read-only t)
2851   ;; Make mode line update.
2852   (set-buffer-modified-p (buffer-modified-p))
2853   (and (marker-position Info-tag-table-marker)
2854        (buffer-modified-p)
2855        (message "Tags may have changed.  Use Info-tagify if necessary")))
2856 \f
2857 (defun Info-find-emacs-command-nodes (command)
2858   "Return a list of locations documenting COMMAND in the XEmacs Info manual.
2859 The locations are of the format used in Info-history, i.e.
2860 \(FILENAME NODENAME BUFFERPOS\)."
2861   (let ((where '())
2862         (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
2863                           ":\\s *\\(.*\\)\\.$")))
2864     (save-excursion
2865       (Info-find-node "XEmacs" "Command Index")
2866       ;; Take the index node off the Info history.
2867       ;; ??? says this isn't safe someplace else... hmmm.
2868       (setq Info-history (cdr Info-history))
2869       (goto-char (point-max))
2870       (while (re-search-backward cmd-desc nil t)
2871           (setq where (cons (list Info-current-file
2872                                   (buffer-substring
2873                                    (match-beginning 1)
2874                                    (match-end 1))
2875                                   0)
2876                             where)))
2877       where)))
2878 \f
2879 ;;; fontification and mousability for info
2880
2881 (defun Info-highlight-region (start end face)
2882   (let ((extent nil)
2883         (splitp (string-match "\n[ \t]+" (buffer-substring start end))))
2884     (if splitp
2885         (save-excursion
2886           (setq extent (make-extent start (progn (goto-char start)
2887                                                  (end-of-line)
2888                                                  (point))))
2889           (set-extent-face extent face)
2890           (set-extent-property extent 'info t)
2891           (set-extent-property extent 'highlight t)
2892           (skip-chars-forward "\n\t ")
2893           (setq extent (make-extent (point) end)))
2894       (setq extent (make-extent start end)))
2895     (set-extent-face extent face)
2896     (set-extent-property extent 'info t)
2897     (set-extent-property extent 'highlight t)))
2898
2899 (defun Info-fontify-node ()
2900   (save-excursion
2901     (let ((case-fold-search t)
2902           (xref-regexp (concat "\\*"
2903                                (regexp-quote Info-footnote-tag)
2904                                "[ \n\t]*\\([^:]*\\):")))
2905       ;; Clear the old extents
2906       (map-extents #'(lambda (x y) (delete-extent x))
2907                    (current-buffer) (point-min) (point-max) nil)
2908       ;; Break the top line iff it is > 79 characters.  Some info nodes
2909       ;; have top lines that span 3 lines because of long node titles.
2910       ;; eg: (Info-find-node "lispref.info" "Window-Level Event Position Info")
2911       (toggle-read-only -1)
2912       (let ((extent nil)
2913             (len 0)
2914             (done nil)
2915             (p (point-min)))
2916         (goto-char (point-min))
2917         (re-search-forward "Node: *[^,]+,  " nil t)
2918         (setq len (- (point) (point-min))
2919               extent (make-extent (point-min) (point)))
2920         (set-extent-property extent 'invisible t)
2921         (while (not done)
2922           (goto-char p)
2923           (end-of-line)
2924           (if (< (current-column) (+ 78 len))
2925               (setq done t)
2926             (goto-char p)
2927             (forward-char (+ 79 len))
2928             (re-search-backward "," nil t)
2929             (forward-char 1)
2930             (insert "\n")
2931             (just-one-space)
2932             (backward-delete-char 1)
2933             (setq p (point)
2934                   len 0))))
2935       (toggle-read-only 1)
2936       ;; Highlight xrefs in the top few lines of the node
2937       (goto-char (point-min))
2938       (if (looking-at "^File: [^,: \t]+,?[ \t]+")
2939           (progn
2940             (goto-char (match-end 0))
2941             (while
2942                 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?\n?")
2943               (goto-char (match-end 0))
2944               (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref))))
2945       ;; Now get the xrefs in the body
2946       (goto-char (point-min))
2947       (while (re-search-forward xref-regexp nil t)
2948         (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2949             nil
2950           (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref)))
2951       ;; then highlight the nodes in the menu.
2952       (goto-char (point-min))
2953       (if (and (search-forward "\n* menu:" nil t))
2954           (while (re-search-forward
2955                   "^\\* \\([^:\t\n]*\\):?:[ \t\n]" nil t)
2956             (Info-highlight-region (match-beginning 1) (match-end 1) 'info-node)))
2957       (set-buffer-modified-p nil))))
2958
2959 (defun Info-construct-menu (&optional event)
2960   "Construct a menu of Info commands.
2961 Adds an entry for the node at EVENT, or under point if EVENT is omitted.
2962 Used to construct the menubar submenu and popup menu."
2963   (or event (setq event (point)))
2964   (let ((case-fold-search t)
2965         (xref-regexp (concat "\\*" 
2966                              (regexp-quote Info-footnote-tag)
2967                              "[ \n\t]*\\([^:]*\\):"))
2968         up-p prev-p next-p menu xrefs subnodes in)
2969     (save-excursion
2970       ;; `one-space' fixes "Notes:" xrefs that are split across lines.
2971       (flet
2972           ((one-space (text)
2973                       (let (i)
2974                         (while (setq i (string-match "[ \n\t]+" text i))
2975                           (setq text (concat (substring text 0 i) " "
2976                                              (substring text (match-end 0))))
2977                           (setq i (1+ i)))
2978                         text)))
2979         (goto-char (point-min))
2980         (if (looking-at ".*\\bNext:") (setq next-p t))
2981         (if (looking-at ".*\\bPrev:") (setq prev-p t))
2982         (if (looking-at ".*Up:") (setq up-p t))
2983         (setq menu (nconc
2984                     (if (setq in (Info-indicated-node event))
2985                         (list (vector (one-space (cadr in)) in t)
2986                               "--:shadowEtchedIn"))
2987                     (list
2988                      ["Goto Info Top-level" Info-directory]
2989                      (vector "Next Node" 'Info-next :active next-p)
2990                      (vector "Previous Node" 'Info-prev :active prev-p)
2991                      (vector "Parent Node (Up)" 'Info-up :active up-p)
2992                      ["Goto Node..." Info-goto-node]
2993                      ["Goto Last Visited Node " Info-last])))
2994         ;; Find the xrefs and make a list
2995         (while (re-search-forward xref-regexp nil t)
2996           (setq xrefs (cons (one-space (buffer-substring (match-beginning 1)
2997                                                          (match-end 1)))
2998                             xrefs))))
2999       (setq xrefs (nreverse xrefs))
3000       (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
3001       ;; Find the subnodes and make a list
3002       (goto-char (point-min))
3003       (if (search-forward "\n* menu:" nil t)
3004       (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
3005         (setq subnodes (cons (buffer-substring (match-beginning 1)
3006                                                (match-end 1))
3007                              subnodes))))
3008       (setq subnodes (nreverse subnodes))
3009       (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more))))
3010     (if xrefs
3011         (nconc menu (list "--:shadowDoubleEtchedIn"
3012                           "    Cross-References"
3013                           "--:singleLine")
3014                (mapcar #'(lambda (xref)
3015                            (if (eq xref 'more)
3016                                "...more..."
3017                              (vector xref
3018                                      (list 'Info-follow-reference xref))))
3019                        xrefs)))
3020     (if subnodes
3021         (nconc menu (list "--:shadowDoubleEtchedIn"
3022                           "      Sub-Nodes"
3023                           "--:singleLine")
3024                (mapcar #'(lambda (node)
3025                            (if (eq node 'more)
3026                                "...more..."
3027                              (vector node (list 'Info-menu node))))
3028                        subnodes)))
3029     menu))
3030
3031 (defun Info-menu-filter (menu)
3032   "This is the menu filter for the \"Info\" submenu."
3033   (Info-construct-menu))
3034
3035 (defun Info-select-node-menu (event)
3036   "Pops up a menu of applicable Info commands."
3037   (interactive "e")
3038   (select-window (event-window event))
3039   (let ((menu (Info-construct-menu event)))
3040     (setq menu (nconc (list "Info" ; title: not displayed
3041                             "     Info Commands"
3042                             "--:shadowDoubleEtchedOut")
3043                       menu))
3044     (let ((popup-menu-titles nil))
3045       (popup-menu menu))))
3046 \f
3047 ;;; Info toolbar support
3048
3049 ;; exit icon taken from GNUS
3050 (defvar info::toolbar-exit-icon
3051   (if (featurep 'toolbar)
3052       (toolbar-make-button-list
3053        (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
3054                          toolbar-icon-directory)))
3055   "Exit Info icon")
3056
3057 (defvar info::toolbar-up-icon
3058   (if (featurep 'toolbar)
3059       (toolbar-make-button-list
3060        (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
3061                          toolbar-icon-directory)))
3062   "Up icon")
3063
3064 (defvar info::toolbar-next-icon
3065   (if (featurep 'toolbar)
3066       (toolbar-make-button-list
3067        (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
3068                          toolbar-icon-directory)))
3069   "Next icon")
3070
3071 (defvar info::toolbar-prev-icon
3072   (if (featurep 'toolbar)
3073       (toolbar-make-button-list
3074        (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
3075                          toolbar-icon-directory)))
3076   "Prev icon")
3077
3078 (defvar info::toolbar
3079   (if (featurep 'toolbar)
3080 ; disabled until we get the next/prev-win icons working again.
3081 ;      (cons (first initial-toolbar-spec)
3082 ;       (cons (second initial-toolbar-spec)
3083              '([info::toolbar-exit-icon
3084                  Info-exit
3085                  t
3086                  "Exit info"]
3087                 [info::toolbar-next-icon
3088                  Info-next
3089                  t
3090                  "Next entry in same section"]
3091                 [info::toolbar-prev-icon
3092                  Info-prev
3093                  t
3094                  "Prev entry in same section"]
3095                 [info::toolbar-up-icon
3096                  Info-up
3097                  t
3098                  "Up entry to enclosing section"]
3099                 )))
3100 ;))
3101 \f
3102 (provide 'info)
3103
3104 (run-hooks 'Info-load-hook)
3105
3106 ;;; info.el ends here