Fix get_dyna_doc CHAR_IO issue sync
[sxemacs] / lisp / info.el
1 ;;; info.el --- info package for SXEmacs.
2 ;; Keywords: help
3
4 ;; Copyright (C) 1985, 1986, 1993, 1997 Free Software Foundation, Inc.
5 ;; Copyright (C) 2005 Steve Youngs.
6
7 ;; Author: Dave Gillespie <daveg@synaptics.com>
8 ;;         Richard Stallman <rms@gnu.ai.mit.edu>
9 ;; Maintainer: Dave Gillespie <daveg@synaptics.com>
10 ;; Version: 1.07 of 7/22/93
11 ;; Keywords: docs, help
12
13 ;; This file is part of SXEmacs.
14
15 ;; SXEmacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
19
20 ;; SXEmacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 ;; GNU General Public License for more details.
24
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
28 ;;; Synched up with: Not synched with FSF.
29
30 ;; Commentary:
31
32 ;; This is based on an early Emacs 19 info.el file.
33 ;;
34 ;; Note that Info-directory has been replaced by Info-directory-list,
35 ;; a search path of directories in which to find Info files.
36 ;; Also, Info tries adding ".info" to a file name if the name itself
37 ;; is not found.
38 ;;
39 ;; See the change log below for further details.
40
41
42 ;; LCD Archive Entry:
43 ;; info-dg|Dave Gillespie|daveg@synaptics.com
44 ;; |Info reader with many enhancements; replaces standard info.el.
45 ;; |93-07-22|1.07|~/modes/info.el
46
47 ;; Also available from anonymous FTP on csvax.cs.caltech.edu.
48
49
50 ;; Change Log:
51
52 ;; Modified 3/7/1991 by Dave Gillespie:
53 ;; (Author's address: daveg@synaptics.com or daveg@csvax.cs.caltech.edu)
54 ;;
55 ;; Added keys:  i, t, <, >, [, ], {, }, 6, 7, 8, 9, 0.
56 ;; Look at help for info-mode (type ? in Info) for descriptions.
57 ;;
58 ;; If Info-directory-list is undefined and there is no INFOPATH
59 ;; in the environment, use value of Info-directory for compatibility
60 ;; with Emacs 18.57.
61 ;;
62 ;; All files named "localdir" found in the path are appended to "dir",
63 ;; the Info directory.  For this to work, "dir" should contain only
64 ;; one node (Top), and each "localdir" should contain no ^_ or ^L
65 ;; characters.  Generally they will contain only one or several
66 ;; additional lines for the top-level menu.  Note that "dir" is
67 ;; modified in memory each time it is loaded, but not on disk.
68 ;;
69 ;; If "dir" contains a line of the form:  "* Locals:"
70 ;; then the "localdir"s are inserted there instead of at the end.
71
72
73 ;; Modified 4/3/1991 by Dave Gillespie:
74 ;;
75 ;; Added Info-mode-hook (suggested by Sebastian Kremer).
76 ;; Also added epoch-info-startup/select-hooks from Simon Spero's info.el.
77 ;;
78 ;; Added automatic decoding of compressed Info files.
79 ;; See documentation for the variable Info-suffix-list.  Default is to
80 ;; run "uncompress" on ".Z" files and "unyabba" on ".Y" files.
81 ;; (See comp.sources.unix v24i073-076 for yabba/unyabba, a free software
82 ;; alternative to compress/uncompress.)
83 ;; Note: "dir" and "localdir" files should not be compressed.
84 ;;
85 ;; Changed variables like Info-enable-edit to be settable by M-x set-variable.
86 ;;
87 ;; Added Info-auto-advance variable.  If t, SPC and DEL will act like
88 ;; } and {, i.e., they advance to the next/previous node if at the end
89 ;; of the buffer.
90 ;;
91 ;; Changed `u' to restore point to most recent location in that node.
92 ;; Added `=' to do this manually at any time.  (Suggested by David Fox).
93 ;;
94 ;; Changed `m' and `0-9' to try interpreting menu name as a file name
95 ;; if not found as a node name.  This allows (dir) menus of the form,
96 ;;     Emacs::          Cool text editor
97 ;; as a shorthand for
98 ;;     Emacs:(emacs).   Cool text editor
99 ;;
100 ;; Enhanced `i' to use line-number information in the index.
101 ;; Added `,' to move among all matches to a previous `i' command.
102 ;;
103 ;; Added `a' (Info-annotate) for adding personal notes to any Info node.
104 ;; Notes are not stored in the actual Info files, but in the user's own
105 ;; ~/.infonotes file.
106 ;;
107 ;; Added Info-footnote-tag, made default be "Ref" instead of "Note".
108 ;;
109 ;; Got mouse-click stuff to work under Emacs version 18.  Check it out!
110 ;; Left and right clicks scroll the Info window.
111 ;; Middle click goes to clicked-on node, e.g., "Next:", a menu, or a note.
112
113
114 ;; Modified 6/29/1991 by Dave Gillespie:
115 ;;
116 ;; Renamed epoch-info-startup/select-hooks to Info-startup/select-hook.
117 ;;
118 ;; Made Info-select-node into a command on the `!' key.
119 ;;
120 ;; Added Info-mouse-support user option.
121 ;;
122 ;; Cleaned up the implementation of some routines.
123 ;;
124 ;; Added special treatment of quoted words in annotations:  The `g'
125 ;; command for a nonexistent node name scans for an annotation
126 ;; (in any node of any file) containing that name in quotes:  g foo RET
127 ;; looks for an annotation containing:  "foo"  or:  <<foo>>
128 ;; If found, it goes to that file and node.
129 ;;
130 ;; Added a call to set up Info-directory-list in Info-find-node to
131 ;; work around a bug in GNUS where it calls Info-goto-node before info.
132 ;;
133 ;; Added completion for `g' command (inspired by Richard Kim's infox.el).
134 ;; Completion knows all node names for the current file, and all annotation
135 ;; tags (see above).  It does not complete file names or node names in
136 ;; other files.
137 ;;
138 ;; Added `k' (Info-emacs-key) and `*' (Info-elisp-ref) commands.  You may
139 ;; wish to bind these to global keys outside of Info mode.
140 ;;
141 ;; Allowed localdir files to be full dir-like files; only the menu part
142 ;; of each localdir is copied.  Also, redundant menu items are omitted.
143 ;;
144 ;; Changed Info-history to hold only one entry at a time for each node,
145 ;; and to be circular so that multiple `l's come back again to the most
146 ;; recent node.  Note that the format of Info-history entries has changed,
147 ;; which may interfere with external programs that try to operate on it.
148 ;; (Also inspired by Kim's infox.el).
149 ;;
150 ;; Changed `n', `]', `l', etc. to accept prefix arguments to move several
151 ;; steps at once.  Most accept negative arguments to move oppositely.
152 ;;
153 ;; Changed `?' to bury *Help* buffer afterwards to keep it out of the way.
154 ;;
155 ;; Rearranged `?' key's display to be a little better for new users.
156 ;;
157 ;; Changed `a' to save whole window configuration and restore on C-c C-c.
158 ;;
159 ;; Fixed the bug reported by Bill Reynolds on gnu.emacs.bugs.
160 ;;
161 ;; Changed Info-last to restore window-start as well as cursor position.
162 ;;
163 ;; Changed middle mouse button in space after end of node to do Info-last
164 ;; if we got here by following a cross reference, else do Info-global-next.
165 ;;
166 ;; Added some new mouse bindings: shift-left = Info-global-next,
167 ;; shift-right = Info-global-prev, shift-middle = Info-last.
168 ;;
169 ;; Fixed Info-follow-reference not to make assumptions about length
170 ;; of Info-footnote-tag [Linus Tolke].
171 ;;
172 ;; Changed default for Info-auto-advance mode to be press-twice-for-next-node.
173 ;;
174 ;; Modified x-mouse-ignore to preserve last-command variable, so that
175 ;; press-twice Info-auto-advance mode works with the mouse.
176
177
178 ;; Modified 3/4/1992 by Dave Gillespie:
179 ;;
180 ;; Added an "autoload" command to help autoload.el.
181 ;;
182 ;; Changed `*' command to look for file `elisp' as well as for `lispref'.
183 ;;
184 ;; Fixed a bug involving footnote names containing regexp special characters.
185 ;;
186 ;; Fixed a bug in completion during `f' (or `r') command.
187 ;;
188 ;; Added TAB (Info-next-reference), M-TAB, and RET keys to Info mode.
189 ;;
190 ;; Added new bindings, `C-h C-k' for Info-emacs-key and `C-h C-f' for
191 ;; Info-elisp-ref.  These bindings are made when info.el is loaded, and
192 ;; only if those key sequences were previously unbound.  These bindings
193 ;; work at any time, not just when Info is already running.
194
195
196 ;; Modified 3/8/1992 by Dave Gillespie:
197 ;;
198 ;; Fixed some long lines that were causing trouble with mailers.
199
200
201 ;; Modified 3/9/1992 by Dave Gillespie:
202 ;;
203 ;; Added `C-h C-i' (Info-query).
204 ;;
205 ;; Added Info-novice mode, warns if the user attempts to switch to
206 ;; a different Info file.
207 ;;
208 ;; Fixed a bug that caused problems using compressed Info files
209 ;; and Info-directory-list at the same time.
210 ;;
211 ;; Disabled Info-mouse-support by default if Epoch or Hyperbole is in use.
212 ;;
213 ;; Added an expand-file-name call to Info-find-node to fix a small bug.
214
215
216 ;; Modified 5/22/1992 by Dave Gillespie:
217 ;;
218 ;; Added "standalone" operation:  "emacs -f info" runs Emacs specifically
219 ;; for use as an Info browser.  In this mode, the `q' key quits Emacs
220 ;; itself.  Also, "emacs -f info arg" starts in Info file "arg" instead
221 ;; of "dir".
222 ;;
223 ;; Changed to prefer "foo.info" over "foo".  If both exist, "foo" is
224 ;; probably a directory or executable program!
225 ;;
226 ;; Made control-mouse act like regular-mouse does in other buffers.
227 ;; (In most systems, this will be set-cursor for left-mouse, x-cut
228 ;; for right-mouse, and x-paste, which will be an error, for
229 ;; middle-mouse.)
230 ;;
231 ;; Improved prompting and searching for `,' key.
232 ;;
233 ;; Fixed a bug where some "* Menu:" lines disappeared when "dir"
234 ;; contained several nodes.
235
236
237 ;; Modified 9/10/1992 by Dave Gillespie:
238 ;;
239 ;; Mixed in support for XEmacs.  Mouse works the same as in
240 ;; the other Emacs versions by default; added Info-lucid-mouse-style
241 ;; variable, which enables mouse operation similar to XEmacs's default.
242 ;;
243 ;; Fixed a bug where RET couldn't understand "* Foo::" if "Foo" was a
244 ;; file name instead of a node name.
245 ;;
246 ;; Added `x' (Info-bookmark), a simple interface to the annotation
247 ;; tags feature.  Added `j' (Info-goto-bookmark), like `g' but only
248 ;; completes bookmarks.
249 ;;
250 ;; Added `<<tag>>' as alternate to `"tag"' in annotations.
251 ;;
252 ;; Added `v' (Info-visit-file), like Info-goto-node but specialized
253 ;; for going to a new Info file (with file name completion).
254 ;;
255 ;; Added recognition of gzip'd ".z" files.
256
257
258 ;; Modified 5/9/1993 by Dave Gillespie:
259 ;;
260 ;; Merged in various things from FSF's latest Emacs 19 info.el.
261
262 ;; Modified 6/2/1993 by Dave Gillespie:
263 ;;
264 ;; Changed to use new suffix ".gz" for gzip files.
265
266
267 ;; Modified 7/22/1993 by Dave Gillespie:
268 ;;
269 ;; Changed Info-footnote-tag to "See" instead of "Ref".
270 ;;
271 ;; Extended Info-fontify-node to work with FSF version of Emacs 19.
272
273 ;; Modified 7/30/1993 by Jamie Zawinski:
274 ;;
275 ;; Commented out the tty and fsf19 mouse support, because why bother.
276 ;; Commented out the politically incorrect version of XEmacs mouse support.
277 ;; Commented out mouse scrolling bindings because the party line on that
278 ;;  is "scrollbars are coming soon."
279 ;; Commented out munging of help-for-help's doc; put it in help.el.
280 ;; Did Info-edit-map the modern XEmacs way.
281 ;; Pruned extra cruft from fontification and mouse handling code.
282 ;; Fixed ASCII-centric bogosity in unreading of events.
283
284 ;; Modified 8/11/95 by Chuck Thompson:
285 ;;
286 ;; Removed any pretense of ever referencing Info-directory since it
287 ;; wasn't working anyhow.
288
289 ;; Modified 4/5/97 by Tomasz J. Cholewo:
290 ;;
291 ;; Modified Info-search to use with-caps-disable-folding
292
293 ;; Modified 6/21/97 by Hrvoje Niksic
294 ;;
295 ;; Fixed up Info-next-reference to work sanely when n < 0.
296 ;; Added S-tab binding.
297
298 ;; Modified 1997-07-10 by Karl M. Hegbloom
299 ;;
300 ;; Added `Info-minibuffer-history'
301 ;; (also added to defaults in "lisp/utils/savehist.el")
302 ;;  Other changes in main ChangeLog.
303
304 ;; Modified 1998-03-29 by Oscar Figueiredo
305 ;;
306 ;; Added automatic dir/localdir (re)building capability for directories that
307 ;; contain none or when it has become older than info files in the same
308 ;; directory.
309
310 ;; Modified 1998-09-23 by Didier Verna <didier@xemacs.org>
311 ;;
312 ;; Use the new macro `with-search-caps-disable-folding'
313
314 ;; Code:
315 (eval-when-compile
316   (condition-case nil (require 'browse-url) (error nil)))
317
318 (defgroup info nil
319   "The info package for Emacs."
320   :group 'help
321   :group 'docs)
322
323 (defgroup info-faces nil
324   "The faces used by info browser."
325   :group 'info
326   :group 'faces)
327
328
329 (defcustom Info-inhibit-toolbar nil
330   "*Non-nil means don't use the specialized Info toolbar."
331   :type 'boolean
332   :group 'info)
333
334 (defcustom Info-novice nil
335   "*Non-nil means to ask for confirmation before switching Info files."
336   :type 'boolean
337   :group 'info)
338
339 (defvar Info-history nil
340   "List of info nodes user has visited.
341 Each element of list is a list (\"(FILENAME)NODENAME\" BUFPOS WINSTART).")
342
343 (defvar Info-keeping-history t
344   "Non-nil if Info-find-node should modify Info-history.
345 This is for use only by certain internal Info routines.")
346
347 (defvar Info-minibuffer-history nil
348   "Minibuffer history for Info.")
349
350 (defcustom Info-enable-edit nil
351   "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info
352 can edit the current node.
353 This is convenient if you want to write info files by hand.
354 However, we recommend that you not do this.
355 It is better to write a Texinfo file and generate the Info file from that,
356 because that gives you a printed manual as well."
357   :type 'boolean
358   :group 'info)
359
360 (defcustom Info-enable-active-nodes t
361   "*Non-nil allows Info to execute Lisp code associated with nodes.
362 The Lisp code is executed when the node is selected."
363   :type 'boolean
364   :group 'info)
365
366 (defcustom Info-restoring-point t
367   "*Non-nil means to restore the cursor position when re-entering a node."
368   :type 'boolean
369   :group 'info)
370
371 (defcustom Info-auto-advance 'twice
372   "*Control what SPC and DEL do when they can't scroll any further.
373 If nil, they beep and remain in the current node.
374 If t, they move to the next node (like Info-global-next/prev).
375 If anything else, they must be pressed twice to move to the next node."
376   :type '(choice (const :tag "off" nil)
377                  (const :tag "advance" t)
378                  (const :tag "confirm" twice))
379   :group 'info)
380
381 (defcustom Info-fontify t
382   "*Non-nil enables font features in XEmacs.
383 This variable is ignored unless running under XEmacs."
384   :type 'boolean
385   :group 'info)
386
387 (defcustom Info-additional-search-directory-list nil
388   "*List of additional directories to search for Info documentation
389 files.  These directories are not searched for merging the `dir'
390 file. An example might be something like:
391 \"/usr/local/lib/xemacs/packages/lisp/calc/\""
392   :type '(repeat directory)
393   :group 'info)
394
395 (defcustom Info-auto-generate-directory 'if-outdated
396   "*When to auto generate an info directory listing.
397 Possible values are:
398 nil or `never' never auto-generate a directory listing,
399   use any existing `dir' or `localdir' file and ignore info
400   directories containing none
401 `always' auto-generate a directory listing ignoring existing
402   `dir' and `localdir' files
403 `if-missing', the default, auto-generates a directory listing
404   if no `dir' or `localdir' file is present.  Otherwise the
405   contents of any of these files is used instead.
406 `if-outdated' auto-generates a directory listing if the `dir'
407   and `localdir' are either inexistent or outdated (touched
408   less recently than an info file in the same directory)."
409   :type '(choice (const :tag "never" never)
410                  (const :tag "always" always)
411                  (const :tag "if-missing" if-missing)
412                  (const :tag "if-outdated" if-outdated))
413   :group 'info)
414
415 (defcustom Info-save-auto-generated-dir 'never
416   "*Whether an auto-generated info directory listing should be saved.
417 Possible values are:
418 nil or `never', the default, auto-generated info directory
419   information will never be saved.
420 `always', auto-generated info directory information will be saved to
421   a `dir' file in the same directory overwriting it if it exists
422 `conservative', auto-generated info directory information will be saved
423   to a `dir' file in the same directory but the user is asked before
424   overwriting any existing file."
425   :type '(choice (const :tag "never" never)
426                  (const :tag "always" always)
427                  (const :tag "conservative" conservative))
428   :group 'info)
429
430 (defconst Info-emacs-info-file-name "sxemacs.info"
431   "The filename of the SXEmacs info for `Info-goto-emacs-command-node'
432 \(`\\<help-mode-map>\\[Info-goto-emacs-command-node]'\)")
433
434 ;;;###autoload
435 (defvar Info-directory-list nil
436   "List of directories to search for Info documentation files.
437
438 The first directory in this list, the \"dir\" file there will become
439 the (dir)Top node of the Info documentation tree.
440
441 Note: DO NOT use the `customize' interface to change the value of this
442 variable.  Its value is created dynamically on each startup, depending
443 on XEmacs packages installed on the system.  If you want to change the
444 search path, make the needed modifications on the variable's value
445 from .emacs.  For instance:
446
447     (setq Info-directory-list (cons \"~/info\" Info-directory-list))")
448
449 ;; This could as well be hard-coded since ${srcdir}/info/dir is in CVS --dv
450 (defconst Info-localdir-heading-regexp "^Local Packages:$"
451   "The menu part of localdir files will be inserted below this topic
452 heading.")
453
454 (defface info-node '((t (:bold t :italic t)))
455   "Face used for node links in info."
456   :group 'info-faces)
457
458 (defface info-xref '((t (:bold t)))
459   "Face used for cross-references in info."
460   :group 'info-faces)
461
462 ;; This list is based on Karl Berry-s advice about extensions `info' itself
463 ;; might encounter. --dv
464 (defcustom Info-suffix-list '(("" . nil)
465                               (".info" . nil)
466                               (".gz" . "gzip -dc %s")
467                               (".info.gz" . "gzip -dc %s")
468                               (".z" . "gzip -dc %s")
469                               (".info.z" . "gzip -dc %s")
470                               (".bz2" . "bzip2 -dc %s")
471                               (".info.bz2" . "bzip2 -dc %s")
472                               (".Z" . "uncompress -c %s")
473                               (".info.Z" . "uncompress -c %s")
474                               (".zip" . "unzip -c %s")
475                               (".info.zip" . "unzip -c %s")
476                               (".y" . "cat %s | unyabba")
477                               ("info.y" . "cat %s | unyabba")
478                               ;; These ones are for MS-DOS filenames.
479                               (".inf" . nil)
480                               (".igz" . "gzip -dc %s")
481                               (".inz" . "gzip -c %s"))
482   "*List of file name suffixes and associated decoding commands.
483 Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
484 changed to name of the file to decode, otherwise the file is given to
485 the command as standard input.  If STRING is nil, no decoding is done."
486   :type '(repeat (cons (string :tag "suffix")
487                        (choice :tag "command"
488                                (const  :tag "none" :value nil)
489                                (string :tag ""))))
490   :group 'info)
491
492 (defcustom Info-footnote-tag "Note"
493   "*Symbol that identifies a footnote or cross-reference.
494 All \"*Note\" references will be changed to use this word instead."
495   :type 'string
496   :group 'info)
497
498 (defvar Info-current-file nil
499   "Info file that Info is now looking at, or nil.
500 This is the name that was specified in Info, not the actual file name.
501 It doesn't contain directory names or file name extensions added by Info.")
502
503 (defvar Info-current-subfile nil
504   "Info subfile that is actually in the *info* buffer now,
505 or nil if current info file is not split into subfiles.")
506
507 (defvar Info-current-node nil
508   "Name of node that Info is now looking at, or nil.")
509
510 (defvar Info-tag-table-marker nil
511   "Marker pointing at beginning of current Info file's tag table.
512 Marker points nowhere if file has no tag table.")
513
514 (defvar Info-tag-table-buffer nil)
515
516 (defvar Info-current-file-completions nil
517   "Cached completion list for current Info file.")
518
519 (defvar Info-current-annotation-completions nil
520   "Cached completion list for current annotation files.")
521
522 (defvar Info-index-alternatives nil
523   "List of possible matches for last Info-index command.")
524
525 (defvar Info-index-first-alternative nil)
526
527 (defcustom Info-annotations-path
528   (list
529    (paths-construct-path (list user-init-directory "info.notes"))
530    (paths-construct-path '("~" ".infonotes"))
531    (paths-construct-path '("usr" "lib" "info.notes")
532                          (char-to-string directory-sep-char)))
533   "*Names of files that contain annotations for different Info nodes.
534 By convention, the first one should reside in your personal directory.
535 The last should be a world-writable \"public\" annotations file."
536   :type '(repeat file)
537   :group 'info)
538
539 (defcustom Info-button1-follows-hyperlink nil
540   "*Non-nil means mouse button1 click will follow hyperlink."
541   :type 'boolean
542   :group 'info)
543
544 (defvar Info-standalone nil
545   "Non-nil if Emacs was started solely as an Info browser.")
546
547 (defvar Info-in-cross-reference nil)
548 (defvar Info-window-configuration nil)
549
550 (defvar Info-dir-prologue "-*- Text -*-
551 This is the file .../info/dir, which contains the topmost node of the
552 Info hierarchy.  The first time you invoke Info you start off
553 looking at that node, which is (dir)Top.
554 \1f
555 File: dir       Node: Top       This is the top of the INFO tree
556   This (the Directory node) gives a menu of major topics.
557
558 * Menu: The list of major topics begins on the next line.
559
560 ")
561
562 (defcustom Info-no-description-string "[No description available]"
563   "*Description string for info files that have none"
564   :type 'string
565   :group 'info)
566
567 ;;;###autoload
568 (defun info (&optional file)
569   "Enter Info, the documentation browser.
570 Optional argument FILE specifies the file to examine;
571 the default is the top-level directory of Info.
572
573 In interactive use, a prefix argument directs this command
574 to read a file name from the minibuffer."
575   (interactive (if current-prefix-arg
576                    (list (read-file-name "Info file name: " nil nil t))))
577   (let ((p command-line-args))
578     (while p
579       (and (string-match "^-[fe]" (car p))
580            (equal (nth 1 p) "info")
581            (not Info-standalone)
582            (setq Info-standalone t)
583            (= (length p) 3)
584            (not (string-match "^-" (nth 2 p)))
585            (setq file (nth 2 p))
586            (setq command-line-args-left nil))
587       (setq p (cdr p))))
588 ;  (Info-setup-x) ??? What was this going to be?  Can anyone tell karlheg?
589   (if file
590       (unwind-protect
591           (Info-goto-node (concat "(" file ")"))
592         (and Info-standalone (info)))
593     (if (get-buffer "*info*")
594         (switch-to-buffer "*info*")
595       (Info-directory))))
596
597 ;;;###autoload
598 (defun Info-query (file)
599   "Enter Info, the documentation browser.  Prompt for name of Info file."
600   (interactive "sInfo topic (default = menu): ")
601   (info)
602   (if (equal file "")
603       (Info-goto-node "(dir)")
604     (Info-goto-node (concat "(" file ")"))))
605
606 (defun Info-setup-initial ()
607   (let ((f Info-annotations-path))
608     (while f
609       (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
610           (bury-buffer (find-file-noselect (car f))))
611       (setq f (cdr f)))))
612
613 ;;;###autoload
614 (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
615   "Go to an info node specified as separate FILENAME and NODENAME.
616 Look for a plausible filename, or if not found then look for URL's and
617 dispatch to the appropriate fn.  NO-GOING-BACK is non-nil if
618 recovering from an error in this function; it says do not attempt
619 further (recursive) error recovery.  TRYFILE is ??"
620
621   (Info-setup-initial)
622
623   (cond
624    ;; empty filename is simple case
625    ((null filename)
626     (Info-find-file-node nil nodename no-going-back tryfile line))
627    ;; Convert filename to lower case if not found as specified.
628    ;; Expand it, look harder...
629    ((let ((fname (substitute-in-file-name filename))
630           temp found)
631       (let ((dirs (cond
632                    ;; If specified name starts with `./', then just try
633                    ;; current directory. No point in searching for an absolute
634                    ;; file name
635                    ((string-match "^\\./" fname)
636                     (list default-directory))
637                    ((file-name-absolute-p fname)
638                     '(nil))
639                    (Info-additional-search-directory-list
640                     (append Info-directory-list
641                             Info-additional-search-directory-list))
642                    (t Info-directory-list))))
643         ;; Search the directory list for file FNAME.
644         (while (and dirs (not found))
645           (setq temp (expand-file-name fname (car dirs)))
646           (setq found (Info-suffixed-file temp))
647           (setq dirs (cdr dirs)))
648         (if found
649             (progn (setq filename (expand-file-name found))
650                    t))))
651     (Info-find-file-node filename nodename no-going-back tryfile line))
652    ;; Look for a URL.  This pattern is stolen from w3.el to prevent
653    ;; loading it if we won't need it.
654    ((string-match  (concat #r"^\(wais\|solo\|x-exec\|newspost\|www\|"
655                            #r"mailto\|news\|tn3270\|ftp\|http\|file\|"
656                            #r"telnet\|gopher\):")
657                    filename)
658     (if-fboundp 'browse-url
659         (browse-url filename)
660       (error "Cannot follow URLs in this SXEmacs")))
661    (t
662     (error "Info file %s does not exist" filename))))
663
664 (defun Info-find-file-node (filename nodename
665                                      &optional no-going-back tryfile line)
666   ;; This is the guts of what was Info-find-node. Whoever wrote this
667   ;; should be locked up where they can't do any more harm.
668
669   ;; Go into info buffer.
670   (or (eq major-mode 'Info-mode)
671       (switch-to-buffer "*info*"))
672   (buffer-disable-undo (current-buffer))
673   (run-hooks 'Info-startup-hook)
674   (or (eq major-mode 'Info-mode)
675       (Info-mode))
676   (or (null filename)
677       (equal Info-current-file filename)
678       (not Info-novice)
679       (string= "dir" (file-name-nondirectory Info-current-file))
680       (if (y-or-n-p
681            (format "Leave Info file `%s'? "
682                    (file-name-nondirectory Info-current-file)))
683           (message "")
684         (keyboard-quit)))
685   ;; Record the node we are leaving.
686   (if (and Info-current-file (not no-going-back))
687       (Info-history-add Info-current-file Info-current-node (point)))
688   (widen)
689   (setq Info-current-node nil
690         Info-in-cross-reference nil)
691   (unwind-protect
692       (progn
693         ;; Switch files if necessary
694         (or (null filename)
695             (equal Info-current-file filename)
696             (let ((buffer-read-only nil))
697               (setq Info-current-file nil
698                     Info-current-subfile nil
699                     Info-current-file-completions nil
700                     Info-index-alternatives nil
701                     buffer-file-name nil
702                     buffer-file-truename nil)
703               (erase-buffer)
704               (if (string= "dir" (file-name-nondirectory filename))
705                   (Info-insert-dir)
706                 (Info-insert-file-contents filename t)
707                 (setq default-directory (file-name-directory filename)))
708               (set-buffer-modified-p nil)
709               ;; See whether file has a tag table.  Record the location if yes.
710               (set-marker Info-tag-table-marker nil)
711               (goto-char (point-max))
712               (forward-line -8)
713               (or (equal nodename "*")
714                   (not (search-forward "\^_\nEnd tag table\n" nil t))
715                   (let (pos)
716                     ;; We have a tag table.  Find its beginning.
717                     ;; Is this an indirect file?
718                     (search-backward "\nTag table:\n")
719                     (setq pos (point))
720                     (if (save-excursion
721                           (forward-line 2)
722                           (looking-at "(Indirect)\n"))
723                         ;; It is indirect.  Copy it to another buffer
724                         ;; and record that the tag table is in that buffer.
725                           (let ((buf (current-buffer))
726                                 (m Info-tag-table-marker))
727                             (or
728                              Info-tag-table-buffer
729                              (setq
730                               Info-tag-table-buffer
731                               (generate-new-buffer " *info tag table*")))
732                             (save-excursion
733                               (set-buffer Info-tag-table-buffer)
734                               (buffer-disable-undo (current-buffer))
735                               (setq case-fold-search t)
736                               (erase-buffer)
737                               (insert-buffer-substring buf)
738                               (set-marker m (match-end 0))))
739                      (set-marker Info-tag-table-marker pos))))
740               (setq Info-current-file
741                     (file-name-sans-versions buffer-file-name))))
742         (if (equal nodename "*")
743             (progn (setq Info-current-node nodename)
744                    (Info-set-mode-line)
745                    (goto-char (point-min)))
746           ;; Search file for a suitable node.
747           (let* ((qnode (regexp-quote nodename))
748                  (regexp (concat "Node: *" qnode " *[,\t\n\177]"))
749                  (guesspos (point-min))
750                  (found t))
751             ;; First get advice from tag table if file has one.
752             ;; Also, if this is an indirect info file,
753             ;; read the proper subfile into this buffer.
754             (if (marker-position Info-tag-table-marker)
755                 (let (foun found-mode (m Info-tag-table-marker))
756                   (save-excursion
757                     (set-buffer (marker-buffer Info-tag-table-marker))
758                     (goto-char m)
759                     (setq foun (re-search-forward regexp nil t))
760                     (if foun
761                         (setq guesspos (read (current-buffer))))
762                     (setq found-mode major-mode))
763                   (if foun
764                       ;; If this is an indirect file,
765                       ;; determine which file really holds this node
766                       ;; and read it in.
767                       (if (not (eq major-mode found-mode))
768                           (setq guesspos
769                                 (Info-read-subfile guesspos))))))
770             (goto-char (max (point-min) (- guesspos 1000)))
771             ;; Now search from our advised position (or from beg of buffer)
772             ;; to find the actual node.
773             (catch 'foo
774               (while (search-forward "\n\^_" nil t)
775                 (forward-line 1)
776                 (let ((beg (point)))
777                   (forward-line 1)
778                   (if (re-search-backward regexp beg t)
779                       (throw 'foo t))))
780               (setq found nil)
781               (let ((bufs (delq nil (mapcar 'get-file-buffer
782                                             Info-annotations-path)))
783                     (pattern (if (string-match #r"\`<<.*>>\'" qnode) qnode
784                                (format "\"%s\"\\|<<%s>>" qnode qnode)))
785                     (pat2 (concat #r"------ *File: *\([^ ].*[^ ]\) *Node: "
786                                   #r"*\([^ ].*[^ ]\) *Line: *\([0-9]+\)"))
787                     (afile nil) anode aline)
788                 (while (and bufs (not anode))
789                   (save-excursion
790                     (set-buffer (car bufs))
791                     (goto-char (point-min))
792                     (if (re-search-forward pattern nil t)
793                         (if (re-search-backward pat2 nil t)
794                             (setq afile (buffer-substring (match-beginning 1)
795                                                           (match-end 1))
796                                   anode (buffer-substring (match-beginning 2)
797                                                           (match-end 2))
798                                   aline (string-to-int
799                                          (buffer-substring (match-beginning 3)
800                                                            (match-end 3)))))))
801                   (setq bufs (cdr bufs)))
802                 (if anode
803                     (Info-find-node afile anode t nil aline)
804                   (if tryfile
805                       (condition-case nil
806                           (Info-find-node nodename "Top" t)
807                         (error nil)))))
808               (or Info-current-node
809                   (error "No such node: %s" nodename)))
810             (if found
811                 (progn
812                   (Info-select-node)
813                   (goto-char (point-min))
814                   (if line (forward-line line)))))))
815     ;; If we did not finish finding the specified node,
816     ;; go back to the previous one.
817     (or Info-current-node no-going-back
818         (let ((hist (car Info-history)))
819           ;; The following is no longer safe with new Info-history system
820           ;; (setq Info-history (cdr Info-history))
821           (Info-goto-node (car hist) t)
822           (goto-char (+ (point-min) (nth 1 hist)))))))
823
824 ;; Cache the contents of the (virtual) dir file, once we have merged
825 ;; it for the first time, so we can save time subsequently.
826 (defvar Info-dir-contents nil)
827
828 ;; Cache for the directory we decided to use for the default-directory
829 ;; of the merged dir text.
830 (defvar Info-dir-contents-directory nil)
831
832 ;; Record the file attributes of all the files from which we
833 ;; constructed Info-dir-contents.
834 (defvar Info-dir-file-attributes nil)
835
836 (defun Info-insert-dir ()
837   "Construct the Info directory node by merging the files named
838 \"dir\" or \"localdir\" from the directories in `Info-directory-list'.
839 The \"dir\" files will take precedence in cases where both exist.  It
840 sets the *info* buffer's `default-directory' to the first directory we
841 actually get any text from."
842   (if (and Info-dir-contents Info-dir-file-attributes
843            ;; Verify that none of the files we used has changed
844            ;; since we used it.
845            (eval (cons 'and
846                        (mapcar #'(lambda (elt)
847                                    (let ((curr (file-attributes (car elt))))
848                                      ;; Don't compare the access time.
849                                      (if curr (setcar (nthcdr 4 curr) 0))
850                                      (setcar (nthcdr 4 (cdr elt)) 0)
851                                      (equal (cdr elt) curr)))
852                                Info-dir-file-attributes))))
853       (insert Info-dir-contents)
854     (let ((dirs (reverse Info-directory-list))
855           buffers lbuffers buffer others nodes dirs-done)
856
857       (setq Info-dir-file-attributes nil)
858
859       ;; Search the directory list for the directory file.
860       (while dirs
861         (let ((truename (file-truename (expand-file-name (car dirs)))))
862           (or (member truename dirs-done)
863               (member (directory-file-name truename) dirs-done)
864               ;; Karl Berry recently added the ability all possibilities for
865               ;; extension as for normal info files. This code however is
866               ;; still unsatisfactory: if one day, we find a compressed dir
867               ;; file (which looks possible), we should be able to handle it
868               ;; (which means decompress and read it, update it, save and
869               ;; recompress it). --dv
870               (let ((trials '("dir" "DIR"
871                               "dir.info" "DIR.INFO"
872                               "dir.inf" "DIR.INF"
873                               "localdir" "LOCALDIR"
874                               "localdir.info" "LOCALDIR.INFO"
875                               "localdir.inf" "LOCALDIR.INF"))
876                     buf file attrs)
877                 (catch 'found
878                   (while (setq file (pop trials))
879                     (setq file (expand-file-name file truename))
880                     (and (setq attrs (file-attributes file))
881                          (throw 'found t))))
882                 (unless file
883                   (setq file (expand-file-name "dir" truename)))
884                 (setq dirs-done
885                       (cons truename
886                             (cons (directory-file-name truename)
887                                   dirs-done)))
888                 (Info-maybe-update-dir file)
889                 (setq attrs (file-attributes file))
890                 (if (or (setq buf (find-buffer-visiting file))
891                         attrs)
892                     (save-excursion
893                       (or buffers
894                           (message "Composing main Info directory..."))
895                       (set-buffer (or buf
896                                       (generate-new-buffer
897                                        (if (string-match "localdir" file)
898                                            "localdir"
899                                          "info dir"))))
900                       (if (not buf)
901                           (insert-file-contents file))
902                       (if (string-match "localdir" (buffer-name))
903                           (setq lbuffers (cons (current-buffer) lbuffers))
904                         (setq buffers (cons (current-buffer) buffers)))
905                       (if attrs
906                           (setq Info-dir-file-attributes
907                                 (cons (cons file attrs)
908                                       Info-dir-file-attributes)))))))
909           (or (cdr dirs) (setq Info-dir-contents-directory (car dirs)))
910           (setq dirs (cdr dirs))))
911
912       ;; ensure that the localdir files are inserted last, and reverse
913       ;; the list of them so that when they get pushed in, they appear
914       ;; in the same order they got specified in the path, from top to
915       ;; bottom.
916       (nconc buffers (reverse lbuffers))
917
918       (or buffers
919           (error "Can't find the Info directory node"))
920       ;; Distinguish the dir file that comes with Emacs from all the
921       ;; others.  Yes, that is really what this is supposed to do.
922       ;; If it doesn't work, fix it.
923       (setq buffer (car buffers)
924             ;; reverse it since they are pushed down from the top. the
925             ;; `Info-directory-list can be specified in natural order
926             ;; this way.
927             others (reverse (cdr buffers)))
928
929       ;; Insert the entire original dir file as a start; note that we've
930       ;; already saved its default directory to use as the default
931       ;; directory for the whole concatenation.
932       (insert-buffer buffer)
933
934       ;; Look at each of the other buffers one by one.
935       (while others
936         (let ((other (car others))
937               (info-buffer (current-buffer)))
938           (if (string-match "localdir" (buffer-name other))
939               (save-excursion
940                 (set-buffer info-buffer)
941                 (goto-char (point-max))
942                 (cond
943                  ((re-search-backward "^ *\\* *Locals *: *$" nil t)
944                   (delete-region (match-beginning 0) (match-end 0)))
945                  ;; look for a line like |Local XEmacs packages:
946                  ;; or mismatch on some text ...
947                  ((re-search-backward Info-localdir-heading-regexp nil t)
948                   ;; This is for people who underline topic headings with
949                   ;; equal signs or dashes.
950                   (when (save-excursion
951                           (forward-line 1)
952                           (beginning-of-line)
953                           (looking-at "^[ \t]*[-=*]+"))
954                     (forward-line 1))
955                   (forward-line 1)
956                   (beginning-of-line))
957                  (t (search-backward "\^L" nil t)))
958                 ;; Insert menu part of the file
959                 (let* ((pt (point))
960                        (len (length (buffer-string nil nil other))))
961                   (insert (buffer-string nil nil other))
962                   (goto-char (+ pt len))
963                   (save-excursion
964                     (goto-char pt)
965                     (if (search-forward "* Menu:" (+ pt len) t)
966                         (progn
967                           (forward-line 1)
968                           (delete-region pt (point)))))))
969             ;; In each, find all the menus.
970             (save-excursion
971               (set-buffer other)
972               (goto-char (point-min))
973               ;; Find each menu, and add an elt to NODES for it.
974               (while (re-search-forward "^\\* Menu:" nil t)
975                 (let (beg nodename end)
976                   (forward-line 1)
977                   (setq beg (point))
978                   (search-backward "\n\^_")
979                   (search-forward "Node: ")
980                   (setq nodename (Info-following-node-name))
981                   (search-forward "\n\^_" nil 'move)
982                   (beginning-of-line)
983                   (setq end (point))
984                   (setq nodes (cons (list nodename other beg end) nodes))))))
985           (setq others (cdr others))))
986
987       ;; Add to the main menu a menu item for each other node.
988       (re-search-forward "^\\* Menu:" nil t)
989       (forward-line 1)
990       (let ((menu-items '("top"))
991             (nodes nodes)
992             (case-fold-search t)
993             (end (save-excursion (search-forward "\^_" nil t) (point))))
994         (while nodes
995           (let ((nodename (car (car nodes))))
996             (save-excursion
997               (or (member (downcase nodename) menu-items)
998                   (re-search-forward (concat "^\\* "
999                                              (regexp-quote nodename)
1000                                              "::")
1001                                      end t)
1002                   (progn
1003                     (insert "* " nodename "::" "\n")
1004                     (setq menu-items (cons nodename menu-items))))))
1005           (setq nodes (cdr nodes))))
1006       ;; Now take each node of each of the other buffers
1007       ;; and merge it into the main buffer.
1008       (while nodes
1009         (let ((nodename (car (car nodes))))
1010           (goto-char (point-min))
1011           ;; Find the like-named node in the main buffer.
1012           (if (re-search-forward (concat "\n\^_.*\n.*Node: "
1013                                          (regexp-quote nodename)
1014                                          "[,\n\t]")
1015                                  nil t)
1016               (progn
1017                 (search-forward "\n\^_" nil 'move)
1018                 (beginning-of-line)
1019                 (insert "\n"))
1020             ;; If none exists, add one.
1021             (goto-char (point-max))
1022             (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
1023           ;; Merge the text from the other buffer's menu
1024           ;; into the menu in the like-named node in the main buffer.
1025           (apply 'insert-buffer-substring (cdr (car nodes))))
1026         (setq nodes (cdr nodes)))
1027       ;; Kill all the buffers we just made.
1028       (while buffers
1029         (kill-buffer (car buffers))
1030         (setq buffers (cdr buffers)))
1031       (while lbuffers
1032         (kill-buffer (car lbuffers))
1033         (setq lbuffers (cdr lbuffers)))
1034       (message "Composing main Info directory...done"))
1035     (setq Info-dir-contents (buffer-string)))
1036   (setq default-directory (file-name-as-directory Info-dir-contents-directory))
1037   (setq buffer-file-name (caar Info-dir-file-attributes)
1038         buffer-file-truename (file-truename buffer-file-name)))
1039
1040 (defmacro Info-directory-files (dir-file &optional all full nosort files-only)
1041   "Return a list of Info files living in the same directory as DIR-FILE.
1042 This list actually contains the files living in this directory, except for
1043 the dir file itself and the secondary info files (foo-1 foo-2 etc).
1044
1045 If the optional argument ALL is non nil, the secondary info files are also
1046 included in the list.
1047
1048 Please refer to the function `directory-files' for the meaning of the other
1049 optional arguments."
1050   `(let* ((dir (file-name-directory ,dir-file))
1051           (all-files (remove ,dir-file (directory-files dir ',full nil ',nosort
1052                                                         ',files-only))))
1053      (setq all-files
1054            (if ,full
1055                (remove (concat dir ".")
1056                        (remove (concat dir "..") all-files))
1057              (remove "."
1058                      (remove ".." all-files))))
1059      (if ,all
1060          all-files
1061        (let ((suff-match
1062               (concat "-[0-9]+\\("
1063                       ;; Extract all known compression suffixes from
1064                       ;; Info-suffix-list. These suffixes can typically  be
1065                       ;; found in entries of the form `.info.something'.
1066                       (let ((suff-list Info-suffix-list)
1067                             suff regexp)
1068                         (while (setq suff (pop suff-list))
1069                           (and (string-match "^\\.info" (car suff))
1070                                (setq regexp (concat regexp
1071                                                     (regexp-quote
1072                                                      (substring
1073                                                       (car suff) 5))
1074                                                     (and suff-list "\\|")))))
1075                         regexp)
1076                       "\\)?$"))
1077              info-files file)
1078          (while (setq file (pop all-files))
1079            (or (string-match suff-match file)
1080                (push file info-files)))
1081          (reverse info-files)
1082          ))
1083      ))
1084
1085 (defun Info-maybe-update-dir (file)
1086   "Rebuild dir or localdir according to `Info-auto-generate-directory'."
1087   (unless (or (not (file-exists-p (file-name-directory file)))
1088               (null (Info-directory-files file 'all)))
1089     (if (not (find-buffer-visiting file))
1090         (if (not (file-exists-p file))
1091             (if (or (memq Info-auto-generate-directory
1092                           '(always if-missing if-outdated)))
1093                 (Info-build-dir-anew (file-name-directory file)))
1094           (if (or (eq Info-auto-generate-directory 'always)
1095                   (and (eq Info-auto-generate-directory 'if-outdated)
1096                        (Info-dir-outdated-p file)))
1097               (Info-rebuild-dir file))))))
1098
1099 ;; Record which *.info files are newer than the dir file
1100 (defvar Info-dir-newer-info-files nil)
1101
1102 (defun Info-dir-outdated-p (file)
1103   "Return non-nil if dir or localdir is outdated.
1104 dir or localdir are outdated when an info file in the same
1105 directory has been modified more recently."
1106   (let ((dir-mod-time (nth 5 (file-attributes file)))
1107         f-mod-time newer)
1108     (setq Info-dir-newer-info-files nil)
1109     (mapcar
1110      #'(lambda (f)
1111          (prog2
1112              (setq f-mod-time (nth 5 (file-attributes f)))
1113              (setq newer (or (> (car f-mod-time) (car dir-mod-time))
1114                              (and (= (car f-mod-time) (car dir-mod-time))
1115                                   (> (car (cdr f-mod-time))
1116                                      (car (cdr dir-mod-time))))))
1117            (if (and (file-readable-p f) newer)
1118                (setq Info-dir-newer-info-files
1119                      (cons f Info-dir-newer-info-files)))))
1120      (Info-directory-files file nil 'fullname 'nosort t))
1121     Info-dir-newer-info-files))
1122
1123 (defun Info-extract-dir-entry-from (file)
1124   "Extract the dir entry from the info FILE.
1125 The dir entry is delimited by the markers `START-INFO-DIR-ENTRY'
1126 and `END-INFO-DIR-ENTRY'."
1127   (save-excursion
1128     (set-buffer (get-buffer-create " *Info-tmp*"))
1129     (when (file-readable-p file)
1130       (insert-file-contents file nil nil nil t)
1131       (goto-char (point-min))
1132       (let (beg)
1133         (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
1134           (forward-line 1)
1135           (setq beg (point))
1136           (unless (null (re-search-forward "^END-INFO-DIR-ENTRY" nil t))
1137             (goto-char (match-beginning 0))
1138             (car (Info-parse-dir-entries beg (point)))))))))
1139
1140 ;; Parse dir entries contained between START and END into a list of the form
1141 ;; (filename topic node (description-line-1 description-line-2 ...))
1142 (defun Info-parse-dir-entries (start end)
1143   (let (entry entries)
1144     (save-excursion
1145       (save-restriction
1146         (narrow-to-region start end)
1147         (goto-char start)
1148         (while (re-search-forward
1149                 (concat #r"^\* \([^:]+\):\("
1150                         "[ \t]*"
1151                         #r"(\([^)]*\))\w*\.\|:\)")
1152                 nil t)
1153           (setq entry (list (match-string 2)
1154                             (match-string 1)
1155                             (downcase (or (match-string 3)
1156                                           (match-string 1)))))
1157           (setq entry
1158                 (cons (nreverse
1159                        (cdr
1160                         (nreverse
1161                          (split-string
1162                           (buffer-substring
1163                            (re-search-forward "[ \t]*" nil t)
1164                            (or (and (re-search-forward "^[^ \t]" nil t)
1165                                     (goto-char (match-beginning 0)))
1166                                (point-max)))
1167                           "[ \t]*\n[ \t]*"))))
1168                       entry))
1169           (setq entries (cons (nreverse entry) entries)))))
1170     (nreverse entries)))
1171
1172 (defun Info-dump-dir-entries (entries)
1173   (let ((tab-width 8)
1174         (description-col 0)
1175         len)
1176     (mapcar #'(lambda (e)
1177                 (setq e (cdr e))        ; Drop filename
1178                 (setq len (length (concat (car e)
1179                                           (car (cdr e)))))
1180                 (if (> len description-col)
1181                     (setq description-col len)))
1182             entries)
1183     (setq description-col (+ 5 description-col))
1184     (mapcar #'(lambda (e)
1185                 (setq e (cdr e))        ; Drop filename
1186                 (insert "* " (car e) ":" (car (cdr e)))
1187                 (setq e (car (cdr (cdr e))))
1188                 (while e
1189                   (indent-to-column description-col)
1190                   (insert (car e) "\n")
1191                   (setq e (cdr e))))
1192             entries)
1193     (insert "\n")))
1194
1195
1196 (defun Info-build-dir-anew (directory)
1197   "Build info directory information for DIRECTORY.
1198 The generated directory listing may be saved to a `dir' according
1199 to the value of `Info-save-auto-generated-dir'."
1200   (save-excursion
1201     (let* ((dirfile (expand-file-name "dir" directory))
1202            (to-temp (or (null Info-save-auto-generated-dir)
1203                         (eq Info-save-auto-generated-dir 'never)
1204                         (and (not (file-writable-p dirfile))
1205                              (message "File not writable %s. Using temporary."
1206                                       dirfile))))
1207            (info-files (Info-directory-files dirfile nil 'fullname nil t)))
1208       (if to-temp
1209           (message "Creating temporary dir in %s..." directory)
1210         (message "Creating %s..." dirfile))
1211       (set-buffer (find-file-noselect dirfile t))
1212       (setq buffer-read-only nil)
1213       (erase-buffer)
1214       (insert Info-dir-prologue "Info files in " directory ":\n\n")
1215       (Info-dump-dir-entries
1216        (mapcar
1217         #'(lambda (f)
1218             (or (Info-extract-dir-entry-from f)
1219                 (list 'dummy
1220                       (progn (string-match #r"\([^.]*\)\(\..*\)?$"
1221                                            (file-name-nondirectory f))
1222                              (capitalize
1223                               (match-string 1 (file-name-nondirectory f))))
1224                       ":"
1225                       (list Info-no-description-string))))
1226         info-files))
1227       (if to-temp
1228           (set-buffer-modified-p nil)
1229         (save-buffer))
1230       (if to-temp
1231           (message "Creating temporary dir in %s...done" directory)
1232         (message "Creating %s...done" dirfile)))))
1233
1234
1235 (defun Info-rebuild-dir (file)
1236   "Build info directory information in the directory of dir FILE.
1237 Description of info files are merged from the info files in the
1238 directory and the contents of FILE with the description in info files
1239 taking precedence over descriptions in FILE.
1240 The generated directory listing may be saved to a `dir' according to
1241 the value of `Info-save-auto-generated-dir'."
1242   (save-excursion
1243     (save-restriction
1244       (let (dir-section-contents dir-full-contents
1245             dir-entry
1246             file-dir-entry
1247             mark next-section
1248             not-first-section
1249             (to-temp
1250              (or (null Info-save-auto-generated-dir)
1251                  (eq Info-save-auto-generated-dir 'never)
1252                  (and (eq Info-save-auto-generated-dir 'always)
1253                       (not (file-writable-p file))
1254                       (message "File not writable %s. Using temporary." file))
1255                  (and (eq Info-save-auto-generated-dir 'conservative)
1256                       (or (and (not (file-writable-p file))
1257                                (message
1258                                 "File not writable %s. Using temporary." file))
1259                           (not (y-or-n-p
1260                                 (message "%s is outdated. Overwrite ? "
1261                                          file))))))))
1262         (set-buffer (find-file-noselect file t))
1263         (setq buffer-read-only nil)
1264         (if to-temp
1265             (message "Rebuilding temporary %s..." file)
1266           (message "Rebuilding %s..." file))
1267         (catch 'done
1268           (setq buffer-read-only nil)
1269           (goto-char (point-min))
1270           (unless (and (search-forward "\^_")
1271                        (re-search-forward "^\\* Menu:.*$" nil t)
1272                        (setq mark (and (re-search-forward "^\\* " nil t)
1273                                        (match-beginning 0))))
1274             (throw 'done nil))
1275           (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1276           (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$"
1277                                                          nil t)
1278                                       (match-beginning 0))
1279                                  (point-max)))
1280           (while next-section
1281             (narrow-to-region mark next-section)
1282             (setq dir-section-contents (nreverse (Info-parse-dir-entries
1283                                                   (point-min) (point-max))))
1284             (mapcar
1285              #'(lambda (file)
1286                  (setq dir-entry (assoc (downcase
1287                                          (file-name-sans-extension
1288                                           (file-name-nondirectory file)))
1289                                         dir-section-contents)
1290                        file-dir-entry (Info-extract-dir-entry-from file))
1291                  (if dir-entry
1292                      (if file-dir-entry
1293                          ;; A dir entry in the info file takes precedence over
1294                          ;; an existing entry in the dir file
1295                          (setcdr dir-entry (cdr file-dir-entry)))
1296                    (unless (or not-first-section
1297                                (assoc (downcase
1298                                        (file-name-sans-extension
1299                                         (file-name-nondirectory file)))
1300                                       dir-full-contents))
1301                      (if file-dir-entry
1302                          (setq dir-section-contents
1303                                (cons file-dir-entry dir-section-contents))
1304