1 ;;; info.el --- info package for SXEmacs.
4 ;; Copyright (C) 1985, 1986, 1993, 1997 Free Software Foundation, Inc.
5 ;; Copyright (C) 2005 Steve Youngs.
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
13 ;; This file is part of SXEmacs.
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.
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.
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/>.
28 ;;; Synched up with: Not synched with FSF.
32 ;; This is based on an early Emacs 19 info.el file.
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
39 ;; See the change log below for further details.
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
47 ;; Also available from anonymous FTP on csvax.cs.caltech.edu.
52 ;; Modified 3/7/1991 by Dave Gillespie:
53 ;; (Author's address: daveg@synaptics.com or daveg@csvax.cs.caltech.edu)
55 ;; Added keys: i, t, <, >, [, ], {, }, 6, 7, 8, 9, 0.
56 ;; Look at help for info-mode (type ? in Info) for descriptions.
58 ;; If Info-directory-list is undefined and there is no INFOPATH
59 ;; in the environment, use value of Info-directory for compatibility
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.
69 ;; If "dir" contains a line of the form: "* Locals:"
70 ;; then the "localdir"s are inserted there instead of at the end.
73 ;; Modified 4/3/1991 by Dave Gillespie:
75 ;; Added Info-mode-hook (suggested by Sebastian Kremer).
76 ;; Also added epoch-info-startup/select-hooks from Simon Spero's info.el.
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.
85 ;; Changed variables like Info-enable-edit to be settable by M-x set-variable.
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
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).
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
98 ;; Emacs:(emacs). Cool text editor
100 ;; Enhanced `i' to use line-number information in the index.
101 ;; Added `,' to move among all matches to a previous `i' command.
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.
107 ;; Added Info-footnote-tag, made default be "Ref" instead of "Note".
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.
114 ;; Modified 6/29/1991 by Dave Gillespie:
116 ;; Renamed epoch-info-startup/select-hooks to Info-startup/select-hook.
118 ;; Made Info-select-node into a command on the `!' key.
120 ;; Added Info-mouse-support user option.
122 ;; Cleaned up the implementation of some routines.
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.
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.
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
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.
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.
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).
150 ;; Changed `n', `]', `l', etc. to accept prefix arguments to move several
151 ;; steps at once. Most accept negative arguments to move oppositely.
153 ;; Changed `?' to bury *Help* buffer afterwards to keep it out of the way.
155 ;; Rearranged `?' key's display to be a little better for new users.
157 ;; Changed `a' to save whole window configuration and restore on C-c C-c.
159 ;; Fixed the bug reported by Bill Reynolds on gnu.emacs.bugs.
161 ;; Changed Info-last to restore window-start as well as cursor position.
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.
166 ;; Added some new mouse bindings: shift-left = Info-global-next,
167 ;; shift-right = Info-global-prev, shift-middle = Info-last.
169 ;; Fixed Info-follow-reference not to make assumptions about length
170 ;; of Info-footnote-tag [Linus Tolke].
172 ;; Changed default for Info-auto-advance mode to be press-twice-for-next-node.
174 ;; Modified x-mouse-ignore to preserve last-command variable, so that
175 ;; press-twice Info-auto-advance mode works with the mouse.
178 ;; Modified 3/4/1992 by Dave Gillespie:
180 ;; Added an "autoload" command to help autoload.el.
182 ;; Changed `*' command to look for file `elisp' as well as for `lispref'.
184 ;; Fixed a bug involving footnote names containing regexp special characters.
186 ;; Fixed a bug in completion during `f' (or `r') command.
188 ;; Added TAB (Info-next-reference), M-TAB, and RET keys to Info mode.
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.
196 ;; Modified 3/8/1992 by Dave Gillespie:
198 ;; Fixed some long lines that were causing trouble with mailers.
201 ;; Modified 3/9/1992 by Dave Gillespie:
203 ;; Added `C-h C-i' (Info-query).
205 ;; Added Info-novice mode, warns if the user attempts to switch to
206 ;; a different Info file.
208 ;; Fixed a bug that caused problems using compressed Info files
209 ;; and Info-directory-list at the same time.
211 ;; Disabled Info-mouse-support by default if Epoch or Hyperbole is in use.
213 ;; Added an expand-file-name call to Info-find-node to fix a small bug.
216 ;; Modified 5/22/1992 by Dave Gillespie:
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
223 ;; Changed to prefer "foo.info" over "foo". If both exist, "foo" is
224 ;; probably a directory or executable program!
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
231 ;; Improved prompting and searching for `,' key.
233 ;; Fixed a bug where some "* Menu:" lines disappeared when "dir"
234 ;; contained several nodes.
237 ;; Modified 9/10/1992 by Dave Gillespie:
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.
243 ;; Fixed a bug where RET couldn't understand "* Foo::" if "Foo" was a
244 ;; file name instead of a node name.
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.
250 ;; Added `<<tag>>' as alternate to `"tag"' in annotations.
252 ;; Added `v' (Info-visit-file), like Info-goto-node but specialized
253 ;; for going to a new Info file (with file name completion).
255 ;; Added recognition of gzip'd ".z" files.
258 ;; Modified 5/9/1993 by Dave Gillespie:
260 ;; Merged in various things from FSF's latest Emacs 19 info.el.
262 ;; Modified 6/2/1993 by Dave Gillespie:
264 ;; Changed to use new suffix ".gz" for gzip files.
267 ;; Modified 7/22/1993 by Dave Gillespie:
269 ;; Changed Info-footnote-tag to "See" instead of "Ref".
271 ;; Extended Info-fontify-node to work with FSF version of Emacs 19.
273 ;; Modified 7/30/1993 by Jamie Zawinski:
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.
284 ;; Modified 8/11/95 by Chuck Thompson:
286 ;; Removed any pretense of ever referencing Info-directory since it
287 ;; wasn't working anyhow.
289 ;; Modified 4/5/97 by Tomasz J. Cholewo:
291 ;; Modified Info-search to use with-caps-disable-folding
293 ;; Modified 6/21/97 by Hrvoje Niksic
295 ;; Fixed up Info-next-reference to work sanely when n < 0.
296 ;; Added S-tab binding.
298 ;; Modified 1997-07-10 by Karl M. Hegbloom
300 ;; Added `Info-minibuffer-history'
301 ;; (also added to defaults in "lisp/utils/savehist.el")
302 ;; Other changes in main ChangeLog.
304 ;; Modified 1998-03-29 by Oscar Figueiredo
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
310 ;; Modified 1998-09-23 by Didier Verna <didier@xemacs.org>
312 ;; Use the new macro `with-search-caps-disable-folding'
316 (condition-case nil (require 'browse-url) (error nil)))
319 "The info package for Emacs."
323 (defgroup info-faces nil
324 "The faces used by info browser."
329 (defcustom Info-inhibit-toolbar nil
330 "*Non-nil means don't use the specialized Info toolbar."
334 (defcustom Info-novice nil
335 "*Non-nil means to ask for confirmation before switching Info files."
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).")
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.")
347 (defvar Info-minibuffer-history nil
348 "Minibuffer history for Info.")
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."
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."
366 (defcustom Info-restoring-point t
367 "*Non-nil means to restore the cursor position when re-entering a node."
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))
381 (defcustom Info-fontify t
382 "*Non-nil enables font features in XEmacs.
383 This variable is ignored unless running under XEmacs."
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)
395 (defcustom Info-auto-generate-directory 'if-outdated
396 "*When to auto generate an info directory listing.
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))
415 (defcustom Info-save-auto-generated-dir 'never
416 "*Whether an auto-generated info directory listing should be saved.
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))
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]'\)")
435 (defvar Info-directory-list nil
436 "List of directories to search for Info documentation files.
438 The first directory in this list, the \"dir\" file there will become
439 the (dir)Top node of the Info documentation tree.
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:
447 (setq Info-directory-list (cons \"~/info\" Info-directory-list))")
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
454 (defface info-node '((t (:bold t :italic t)))
455 "Face used for node links in info."
458 (defface info-xref '((t (:bold t)))
459 "Face used for cross-references in info."
462 ;; This list is based on Karl Berry-s advice about extensions `info' itself
463 ;; might encounter. --dv
464 (defcustom Info-suffix-list '(("" . 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.
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)
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."
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.")
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.")
507 (defvar Info-current-node nil
508 "Name of node that Info is now looking at, or nil.")
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.")
514 (defvar Info-tag-table-buffer nil)
516 (defvar Info-current-file-completions nil
517 "Cached completion list for current Info file.")
519 (defvar Info-current-annotation-completions nil
520 "Cached completion list for current annotation files.")
522 (defvar Info-index-alternatives nil
523 "List of possible matches for last Info-index command.")
525 (defvar Info-index-first-alternative nil)
527 (defcustom Info-annotations-path
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."
539 (defcustom Info-button1-follows-hyperlink nil
540 "*Non-nil means mouse button1 click will follow hyperlink."
544 (defvar Info-standalone nil
545 "Non-nil if Emacs was started solely as an Info browser.")
547 (defvar Info-in-cross-reference nil)
548 (defvar Info-window-configuration nil)
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.
555 File: dir Node: Top This is the top of the INFO tree
556 This (the Directory node) gives a menu of major topics.
558 * Menu: The list of major topics begins on the next line.
562 (defcustom Info-no-description-string "[No description available]"
563 "*Description string for info files that have none"
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.
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))
579 (and (string-match "^-[fe]" (car p))
580 (equal (nth 1 p) "info")
581 (not Info-standalone)
582 (setq Info-standalone t)
584 (not (string-match "^-" (nth 2 p)))
585 (setq file (nth 2 p))
586 (setq command-line-args-left nil))
588 ; (Info-setup-x) ??? What was this going to be? Can anyone tell karlheg?
591 (Info-goto-node (concat "(" file ")"))
592 (and Info-standalone (info)))
593 (if (get-buffer "*info*")
594 (switch-to-buffer "*info*")
598 (defun Info-query (file)
599 "Enter Info, the documentation browser. Prompt for name of Info file."
600 (interactive "sInfo topic (default = menu): ")
603 (Info-goto-node "(dir)")
604 (Info-goto-node (concat "(" file ")"))))
606 (defun Info-setup-initial ()
607 (let ((f Info-annotations-path))
609 (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
610 (bury-buffer (find-file-noselect (car f))))
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 ??"
624 ;; empty filename is simple case
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))
632 ;; If specified name starts with `./', then just try
633 ;; current directory. No point in searching for an absolute
635 ((string-match "^\\./" fname)
636 (list default-directory))
637 ((file-name-absolute-p fname)
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)))
649 (progn (setq filename (expand-file-name found))
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\):")
658 (if-fboundp 'browse-url
659 (browse-url filename)
660 (error "Cannot follow URLs in this SXEmacs")))
662 (error "Info file %s does not exist" filename))))
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.
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)
677 (equal Info-current-file filename)
679 (string= "dir" (file-name-nondirectory Info-current-file))
681 (format "Leave Info file `%s'? "
682 (file-name-nondirectory Info-current-file)))
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)))
689 (setq Info-current-node nil
690 Info-in-cross-reference nil)
693 ;; Switch files if necessary
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
702 buffer-file-truename nil)
704 (if (string= "dir" (file-name-nondirectory filename))
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))
713 (or (equal nodename "*")
714 (not (search-forward "\^_\nEnd tag table\n" nil t))
716 ;; We have a tag table. Find its beginning.
717 ;; Is this an indirect file?
718 (search-backward "\nTag table:\n")
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))
728 Info-tag-table-buffer
730 Info-tag-table-buffer
731 (generate-new-buffer " *info tag table*")))
733 (set-buffer Info-tag-table-buffer)
734 (buffer-disable-undo (current-buffer))
735 (setq case-fold-search t)
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)
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))
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))
757 (set-buffer (marker-buffer Info-tag-table-marker))
759 (setq foun (re-search-forward regexp nil t))
761 (setq guesspos (read (current-buffer))))
762 (setq found-mode major-mode))
764 ;; If this is an indirect file,
765 ;; determine which file really holds this node
767 (if (not (eq major-mode found-mode))
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.
774 (while (search-forward "\n\^_" nil t)
778 (if (re-search-backward regexp beg t)
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))
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)
796 anode (buffer-substring (match-beginning 2)
799 (buffer-substring (match-beginning 3)
801 (setq bufs (cdr bufs)))
803 (Info-find-node afile anode t nil aline)
806 (Info-find-node nodename "Top" t)
808 (or Info-current-node
809 (error "No such node: %s" nodename)))
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)))))))
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)
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)
832 ;; Record the file attributes of all the files from which we
833 ;; constructed Info-dir-contents.
834 (defvar Info-dir-file-attributes nil)
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
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)
857 (setq Info-dir-file-attributes nil)
859 ;; Search the directory list for the directory file.
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"
873 "localdir" "LOCALDIR"
874 "localdir.info" "LOCALDIR.INFO"
875 "localdir.inf" "LOCALDIR.INF"))
878 (while (setq file (pop trials))
879 (setq file (expand-file-name file truename))
880 (and (setq attrs (file-attributes file))
883 (setq file (expand-file-name "dir" truename)))
886 (cons (directory-file-name truename)
888 (Info-maybe-update-dir file)
889 (setq attrs (file-attributes file))
890 (if (or (setq buf (find-buffer-visiting file))
894 (message "Composing main Info directory..."))
897 (if (string-match "localdir" file)
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)))
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))))
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
916 (nconc buffers (reverse lbuffers))
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
927 others (reverse (cdr buffers)))
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)
934 ;; Look at each of the other buffers one by one.
936 (let ((other (car others))
937 (info-buffer (current-buffer)))
938 (if (string-match "localdir" (buffer-name other))
940 (set-buffer info-buffer)
941 (goto-char (point-max))
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
953 (looking-at "^[ \t]*[-=*]+"))
957 (t (search-backward "\^L" nil t)))
958 ;; Insert menu part of the file
960 (len (length (buffer-string nil nil other))))
961 (insert (buffer-string nil nil other))
962 (goto-char (+ pt len))
965 (if (search-forward "* Menu:" (+ pt len) t)
968 (delete-region pt (point)))))))
969 ;; In each, find all the menus.
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)
978 (search-backward "\n\^_")
979 (search-forward "Node: ")
980 (setq nodename (Info-following-node-name))
981 (search-forward "\n\^_" nil 'move)
984 (setq nodes (cons (list nodename other beg end) nodes))))))
985 (setq others (cdr others))))
987 ;; Add to the main menu a menu item for each other node.
988 (re-search-forward "^\\* Menu:" nil t)
990 (let ((menu-items '("top"))
993 (end (save-excursion (search-forward "\^_" nil t) (point))))
995 (let ((nodename (car (car nodes))))
997 (or (member (downcase nodename) menu-items)
998 (re-search-forward (concat "^\\* "
999 (regexp-quote nodename)
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.
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)
1017 (search-forward "\n\^_" nil 'move)
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.
1029 (kill-buffer (car buffers))
1030 (setq buffers (cdr buffers)))
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)))
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).
1045 If the optional argument ALL is non nil, the secondary info files are also
1046 included in the list.
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
1055 (remove (concat dir ".")
1056 (remove (concat dir "..") all-files))
1058 (remove ".." all-files))))
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)
1068 (while (setq suff (pop suff-list))
1069 (and (string-match "^\\.info" (car suff))
1070 (setq regexp (concat regexp
1074 (and suff-list "\\|")))))
1078 (while (setq file (pop all-files))
1079 (or (string-match suff-match file)
1080 (push file info-files)))
1081 (reverse info-files)
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))))))
1099 ;; Record which *.info files are newer than the dir file
1100 (defvar Info-dir-newer-info-files nil)
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)))
1108 (setq Info-dir-newer-info-files nil)
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))
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'."
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))
1133 (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
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)))))))))
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)
1146 (narrow-to-region start end)
1148 (while (re-search-forward
1149 (concat #r"^\* \([^:]+\):\("
1151 #r"(\([^)]*\))\w*\.\|:\)")
1153 (setq entry (list (match-string 2)
1155 (downcase (or (match-string 3)
1156 (match-string 1)))))
1163 (re-search-forward "[ \t]*" nil t)
1164 (or (and (re-search-forward "^[^ \t]" nil t)
1165 (goto-char (match-beginning 0)))
1167 "[ \t]*\n[ \t]*"))))
1169 (setq entries (cons (nreverse entry) entries)))))
1170 (nreverse entries)))
1172 (defun Info-dump-dir-entries (entries)
1176 (mapcar #'(lambda (e)
1177 (setq e (cdr e)) ; Drop filename
1178 (setq len (length (concat (car e)
1180 (if (> len description-col)
1181 (setq description-col len)))
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))))
1189 (indent-to-column description-col)
1190 (insert (car e) "\n")
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'."
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."
1207 (info-files (Info-directory-files dirfile nil 'fullname nil t)))
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)
1214 (insert Info-dir-prologue "Info files in " directory ":\n\n")
1215 (Info-dump-dir-entries
1218 (or (Info-extract-dir-entry-from f)
1220 (progn (string-match #r"\([^.]*\)\(\..*\)?$"
1221 (file-name-nondirectory f))
1223 (match-string 1 (file-name-nondirectory f))))
1225 (list Info-no-description-string))))
1228 (set-buffer-modified-p nil)
1231 (message "Creating temporary dir in %s...done" directory)
1232 (message "Creating %s...done" dirfile)))))
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'."
1244 (let (dir-section-contents dir-full-contents
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))
1258 "File not writable %s. Using temporary." file))
1260 (message "%s is outdated. Overwrite ? "
1262 (set-buffer (find-file-noselect file t))
1263 (setq buffer-read-only nil)
1265 (message "Rebuilding temporary %s..." file)
1266 (message "Rebuilding %s..." file))
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))))
1275 (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1276 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$"
1278 (match-beginning 0))
1281 (narrow-to-region mark next-section)
1282 (setq dir-section-contents (nreverse (Info-parse-dir-entries
1283 (point-min) (point-max))))
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))
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
1298 (file-name-sans-extension
1299 (file-name-nondirectory file)))
1302 (setq dir-section-contents
1303 (cons file-dir-entry dir-section-contents))