1 ;;; info.el --- info package for Emacs.
4 ;; Copyright (C) 1985, 1986, 1993, 1997 Free Software Foundation, Inc.
6 ;; Author: Dave Gillespie <daveg@synaptics.com>
7 ;; Richard Stallman <rms@gnu.ai.mit.edu>
8 ;; Maintainer: Dave Gillespie <daveg@synaptics.com>
9 ;; Version: 1.07 of 7/22/93
10 ;; Keywords: docs, help
12 ;; This file is part of XEmacs.
14 ;; XEmacs is free software; you can redistribute it and/or modify it
15 ;; under the terms of the GNU General Public License as published by
16 ;; the Free Software Foundation; either version 2, or (at your option)
19 ;; XEmacs is distributed in the hope that it will be useful, but
20 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 ;; General Public License for more details.
24 ;; You should have received a copy of the GNU General Public License
25 ;; along with XEmacs; see the file COPYING. If not, write to the
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27 ;; Boston, MA 02111-1307, USA.
29 ;;; Synched up with: Not synched with FSF.
33 ;; This is based on an early Emacs 19 info.el file.
35 ;; Note that Info-directory has been replaced by Info-directory-list,
36 ;; a search path of directories in which to find Info files.
37 ;; Also, Info tries adding ".info" to a file name if the name itself
40 ;; See the change log below for further details.
44 ;; info-dg|Dave Gillespie|daveg@synaptics.com
45 ;; |Info reader with many enhancements; replaces standard info.el.
46 ;; |93-07-22|1.07|~/modes/info.el
48 ;; Also available from anonymous FTP on csvax.cs.caltech.edu.
53 ;; Modified 3/7/1991 by Dave Gillespie:
54 ;; (Author's address: daveg@synaptics.com or daveg@csvax.cs.caltech.edu)
56 ;; Added keys: i, t, <, >, [, ], {, }, 6, 7, 8, 9, 0.
57 ;; Look at help for info-mode (type ? in Info) for descriptions.
59 ;; If Info-directory-list is undefined and there is no INFOPATH
60 ;; in the environment, use value of Info-directory for compatibility
63 ;; All files named "localdir" found in the path are appended to "dir",
64 ;; the Info directory. For this to work, "dir" should contain only
65 ;; one node (Top), and each "localdir" should contain no ^_ or ^L
66 ;; characters. Generally they will contain only one or several
67 ;; additional lines for the top-level menu. Note that "dir" is
68 ;; modified in memory each time it is loaded, but not on disk.
70 ;; If "dir" contains a line of the form: "* Locals:"
71 ;; then the "localdir"s are inserted there instead of at the end.
74 ;; Modified 4/3/1991 by Dave Gillespie:
76 ;; Added Info-mode-hook (suggested by Sebastian Kremer).
77 ;; Also added epoch-info-startup/select-hooks from Simon Spero's info.el.
79 ;; Added automatic decoding of compressed Info files.
80 ;; See documentation for the variable Info-suffix-list. Default is to
81 ;; run "uncompress" on ".Z" files and "unyabba" on ".Y" files.
82 ;; (See comp.sources.unix v24i073-076 for yabba/unyabba, a free software
83 ;; alternative to compress/uncompress.)
84 ;; Note: "dir" and "localdir" files should not be compressed.
86 ;; Changed variables like Info-enable-edit to be settable by M-x set-variable.
88 ;; Added Info-auto-advance variable. If t, SPC and DEL will act like
89 ;; } and {, i.e., they advance to the next/previous node if at the end
92 ;; Changed `u' to restore point to most recent location in that node.
93 ;; Added `=' to do this manually at any time. (Suggested by David Fox).
95 ;; Changed `m' and `0-9' to try interpreting menu name as a file name
96 ;; if not found as a node name. This allows (dir) menus of the form,
97 ;; Emacs:: Cool text editor
99 ;; Emacs:(emacs). Cool text editor
101 ;; Enhanced `i' to use line-number information in the index.
102 ;; Added `,' to move among all matches to a previous `i' command.
104 ;; Added `a' (Info-annotate) for adding personal notes to any Info node.
105 ;; Notes are not stored in the actual Info files, but in the user's own
106 ;; ~/.infonotes file.
108 ;; Added Info-footnote-tag, made default be "Ref" instead of "Note".
110 ;; Got mouse-click stuff to work under Emacs version 18. Check it out!
111 ;; Left and right clicks scroll the Info window.
112 ;; Middle click goes to clicked-on node, e.g., "Next:", a menu, or a note.
115 ;; Modified 6/29/1991 by Dave Gillespie:
117 ;; Renamed epoch-info-startup/select-hooks to Info-startup/select-hook.
119 ;; Made Info-select-node into a command on the `!' key.
121 ;; Added Info-mouse-support user option.
123 ;; Cleaned up the implementation of some routines.
125 ;; Added special treatment of quoted words in annotations: The `g'
126 ;; command for a nonexistent node name scans for an annotation
127 ;; (in any node of any file) containing that name in quotes: g foo RET
128 ;; looks for an annotation containing: "foo" or: <<foo>>
129 ;; If found, it goes to that file and node.
131 ;; Added a call to set up Info-directory-list in Info-find-node to
132 ;; work around a bug in GNUS where it calls Info-goto-node before info.
134 ;; Added completion for `g' command (inspired by Richard Kim's infox.el).
135 ;; Completion knows all node names for the current file, and all annotation
136 ;; tags (see above). It does not complete file names or node names in
139 ;; Added `k' (Info-emacs-key) and `*' (Info-elisp-ref) commands. You may
140 ;; wish to bind these to global keys outside of Info mode.
142 ;; Allowed localdir files to be full dir-like files; only the menu part
143 ;; of each localdir is copied. Also, redundant menu items are omitted.
145 ;; Changed Info-history to hold only one entry at a time for each node,
146 ;; and to be circular so that multiple `l's come back again to the most
147 ;; recent node. Note that the format of Info-history entries has changed,
148 ;; which may interfere with external programs that try to operate on it.
149 ;; (Also inspired by Kim's infox.el).
151 ;; Changed `n', `]', `l', etc. to accept prefix arguments to move several
152 ;; steps at once. Most accept negative arguments to move oppositely.
154 ;; Changed `?' to bury *Help* buffer afterwards to keep it out of the way.
156 ;; Rearranged `?' key's display to be a little better for new users.
158 ;; Changed `a' to save whole window configuration and restore on C-c C-c.
160 ;; Fixed the bug reported by Bill Reynolds on gnu.emacs.bugs.
162 ;; Changed Info-last to restore window-start as well as cursor position.
164 ;; Changed middle mouse button in space after end of node to do Info-last
165 ;; if we got here by following a cross reference, else do Info-global-next.
167 ;; Added some new mouse bindings: shift-left = Info-global-next,
168 ;; shift-right = Info-global-prev, shift-middle = Info-last.
170 ;; Fixed Info-follow-reference not to make assumptions about length
171 ;; of Info-footnote-tag [Linus Tolke].
173 ;; Changed default for Info-auto-advance mode to be press-twice-for-next-node.
175 ;; Modified x-mouse-ignore to preserve last-command variable, so that
176 ;; press-twice Info-auto-advance mode works with the mouse.
179 ;; Modified 3/4/1992 by Dave Gillespie:
181 ;; Added an "autoload" command to help autoload.el.
183 ;; Changed `*' command to look for file `elisp' as well as for `lispref'.
185 ;; Fixed a bug involving footnote names containing regexp special characters.
187 ;; Fixed a bug in completion during `f' (or `r') command.
189 ;; Added TAB (Info-next-reference), M-TAB, and RET keys to Info mode.
191 ;; Added new bindings, `C-h C-k' for Info-emacs-key and `C-h C-f' for
192 ;; Info-elisp-ref. These bindings are made when info.el is loaded, and
193 ;; only if those key sequences were previously unbound. These bindings
194 ;; work at any time, not just when Info is already running.
197 ;; Modified 3/8/1992 by Dave Gillespie:
199 ;; Fixed some long lines that were causing trouble with mailers.
202 ;; Modified 3/9/1992 by Dave Gillespie:
204 ;; Added `C-h C-i' (Info-query).
206 ;; Added Info-novice mode, warns if the user attempts to switch to
207 ;; a different Info file.
209 ;; Fixed a bug that caused problems using compressed Info files
210 ;; and Info-directory-list at the same time.
212 ;; Disabled Info-mouse-support by default if Epoch or Hyperbole is in use.
214 ;; Added an expand-file-name call to Info-find-node to fix a small bug.
217 ;; Modified 5/22/1992 by Dave Gillespie:
219 ;; Added "standalone" operation: "emacs -f info" runs Emacs specifically
220 ;; for use as an Info browser. In this mode, the `q' key quits Emacs
221 ;; itself. Also, "emacs -f info arg" starts in Info file "arg" instead
224 ;; Changed to prefer "foo.info" over "foo". If both exist, "foo" is
225 ;; probably a directory or executable program!
227 ;; Made control-mouse act like regular-mouse does in other buffers.
228 ;; (In most systems, this will be set-cursor for left-mouse, x-cut
229 ;; for right-mouse, and x-paste, which will be an error, for
232 ;; Improved prompting and searching for `,' key.
234 ;; Fixed a bug where some "* Menu:" lines disappeared when "dir"
235 ;; contained several nodes.
238 ;; Modified 9/10/1992 by Dave Gillespie:
240 ;; Mixed in support for XEmacs. Mouse works the same as in
241 ;; the other Emacs versions by default; added Info-lucid-mouse-style
242 ;; variable, which enables mouse operation similar to XEmacs's default.
244 ;; Fixed a bug where RET couldn't understand "* Foo::" if "Foo" was a
245 ;; file name instead of a node name.
247 ;; Added `x' (Info-bookmark), a simple interface to the annotation
248 ;; tags feature. Added `j' (Info-goto-bookmark), like `g' but only
249 ;; completes bookmarks.
251 ;; Added `<<tag>>' as alternate to `"tag"' in annotations.
253 ;; Added `v' (Info-visit-file), like Info-goto-node but specialized
254 ;; for going to a new Info file (with file name completion).
256 ;; Added recognition of gzip'd ".z" files.
259 ;; Modified 5/9/1993 by Dave Gillespie:
261 ;; Merged in various things from FSF's latest Emacs 19 info.el.
263 ;; Modified 6/2/1993 by Dave Gillespie:
265 ;; Changed to use new suffix ".gz" for gzip files.
268 ;; Modified 7/22/1993 by Dave Gillespie:
270 ;; Changed Info-footnote-tag to "See" instead of "Ref".
272 ;; Extended Info-fontify-node to work with FSF version of Emacs 19.
274 ;; Modified 7/30/1993 by Jamie Zawinski:
276 ;; Commented out the tty and fsf19 mouse support, because why bother.
277 ;; Commented out the politically incorrect version of XEmacs mouse support.
278 ;; Commented out mouse scrolling bindings because the party line on that
279 ;; is "scrollbars are coming soon."
280 ;; Commented out munging of help-for-help's doc; put it in help.el.
281 ;; Did Info-edit-map the modern XEmacs way.
282 ;; Pruned extra cruft from fontification and mouse handling code.
283 ;; Fixed ASCII-centric bogosity in unreading of events.
285 ;; Modified 8/11/95 by Chuck Thompson:
287 ;; Removed any pretense of ever referencing Info-directory since it
288 ;; wasn't working anyhow.
290 ;; Modified 4/5/97 by Tomasz J. Cholewo:
292 ;; Modified Info-search to use with-caps-disable-folding
294 ;; Modified 6/21/97 by Hrvoje Niksic
296 ;; Fixed up Info-next-reference to work sanely when n < 0.
297 ;; Added S-tab binding.
299 ;; Modified 1997-07-10 by Karl M. Hegbloom
301 ;; Added `Info-minibuffer-history'
302 ;; (also added to defaults in "lisp/utils/savehist.el")
303 ;; Other changes in main ChangeLog.
305 ;; Modified 1998-03-29 by Oscar Figueiredo
307 ;; Added automatic dir/localdir (re)building capability for directories that
308 ;; contain none or when it has become older than info files in the same
311 ;; Modified 1998-09-23 by Didier Verna <didier@xemacs.org>
313 ;; Use the new macro `with-search-caps-disable-folding'
317 (condition-case nil (require 'browse-url) (error nil)))
320 "The info package for Emacs."
324 (defgroup info-faces nil
325 "The faces used by info browser."
330 (defcustom Info-inhibit-toolbar nil
331 "*Non-nil means don't use the specialized Info toolbar."
335 (defcustom Info-novice nil
336 "*Non-nil means to ask for confirmation before switching Info files."
340 (defvar Info-history nil
341 "List of info nodes user has visited.
342 Each element of list is a list (\"(FILENAME)NODENAME\" BUFPOS WINSTART).")
344 (defvar Info-keeping-history t
345 "Non-nil if Info-find-node should modify Info-history.
346 This is for use only by certain internal Info routines.")
348 (defvar Info-minibuffer-history nil
349 "Minibuffer history for Info.")
351 (defcustom Info-enable-edit nil
352 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info
353 can edit the current node.
354 This is convenient if you want to write info files by hand.
355 However, we recommend that you not do this.
356 It is better to write a Texinfo file and generate the Info file from that,
357 because that gives you a printed manual as well."
361 (defcustom Info-enable-active-nodes t
362 "*Non-nil allows Info to execute Lisp code associated with nodes.
363 The Lisp code is executed when the node is selected."
367 (defcustom Info-restoring-point t
368 "*Non-nil means to restore the cursor position when re-entering a node."
372 (defcustom Info-auto-advance 'twice
373 "*Control what SPC and DEL do when they can't scroll any further.
374 If nil, they beep and remain in the current node.
375 If t, they move to the next node (like Info-global-next/prev).
376 If anything else, they must be pressed twice to move to the next node."
377 :type '(choice (const :tag "off" nil)
378 (const :tag "advance" t)
379 (const :tag "confirm" twice))
382 (defcustom Info-fontify t
383 "*Non-nil enables font features in XEmacs.
384 This variable is ignored unless running under XEmacs."
388 (defcustom Info-additional-search-directory-list nil
389 "*List of additional directories to search for Info documentation
390 files. These directories are not searched for merging the `dir'
391 file. An example might be something like:
392 \"/usr/local/lib/xemacs/packages/lisp/calc/\""
393 :type '(repeat directory)
396 (defcustom Info-auto-generate-directory 'if-outdated
397 "*When to auto generate an info directory listing.
399 nil or `never' never auto-generate a directory listing,
400 use any existing `dir' or `localdir' file and ignore info
401 directories containing none
402 `always' auto-generate a directory listing ignoring existing
403 `dir' and `localdir' files
404 `if-missing', the default, auto-generates a directory listing
405 if no `dir' or `localdir' file is present. Otherwise the
406 contents of any of these files is used instead.
407 `if-outdated' auto-generates a directory listing if the `dir'
408 and `localdir' are either inexistent or outdated (touched
409 less recently than an info file in the same directory)."
410 :type '(choice (const :tag "never" never)
411 (const :tag "always" always)
412 (const :tag "if-missing" if-missing)
413 (const :tag "if-outdated" if-outdated))
416 (defcustom Info-save-auto-generated-dir 'never
417 "*Whether an auto-generated info directory listing should be saved.
419 nil or `never', the default, auto-generated info directory
420 information will never be saved.
421 `always', auto-generated info directory information will be saved to
422 a `dir' file in the same directory overwriting it if it exists
423 `conservative', auto-generated info directory information will be saved
424 to a `dir' file in the same directory but the user is asked before
425 overwriting any existing file."
426 :type '(choice (const :tag "never" never)
427 (const :tag "always" always)
428 (const :tag "conservative" conservative))
431 (defconst Info-emacs-info-file-name "xemacs.info"
432 "The filename of the XEmacs info for `Info-goto-emacs-command-node'
433 (`\\<help-mode-map>\\[Info-goto-emacs-command-node]')")
436 (defvar Info-directory-list nil
437 "List of directories to search for Info documentation files.
439 The first directory in this list, the \"dir\" file there will become
440 the (dir)Top node of the Info documentation tree.
442 Note: DO NOT use the `customize' interface to change the value of this
443 variable. Its value is created dynamically on each startup, depending
444 on XEmacs packages installed on the system. If you want to change the
445 search path, make the needed modifications on the variable's value
446 from .emacs. For instance:
448 (setq Info-directory-list (cons \"~/info\" Info-directory-list))")
450 ;; This could as well be hard-coded since ${srcdir}/info/dir is in CVS --dv
451 (defconst Info-localdir-heading-regexp "^Local Packages:$"
452 "The menu part of localdir files will be inserted below this topic
455 (defface info-node '((t (:bold t :italic t)))
456 "Face used for node links in info."
459 (defface info-xref '((t (:bold t)))
460 "Face used for cross-references in info."
463 ;; This list is based on Karl Berry-s advice about extensions `info' itself
464 ;; might encounter. --dv
465 (defcustom Info-suffix-list '(("" . nil)
467 (".gz" . "gzip -dc %s")
468 (".info.gz" . "gzip -dc %s")
469 (".z" . "gzip -dc %s")
470 (".info.z" . "gzip -dc %s")
471 (".bz2" . "bzip2 -dc %s")
472 (".info.bz2" . "bzip2 -dc %s")
473 (".Z" . "uncompress -c %s")
474 (".info.Z" . "uncompress -c %s")
475 (".zip" . "unzip -c %s")
476 (".info.zip" . "unzip -c %s")
477 (".y" . "cat %s | unyabba")
478 ("info.y" . "cat %s | unyabba")
479 ;; These ones are for MS-DOS filenames.
481 (".igz" . "gzip -dc %s")
482 (".inz" . "gzip -c %s"))
483 "*List of file name suffixes and associated decoding commands.
484 Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
485 changed to name of the file to decode, otherwise the file is given to
486 the command as standard input. If STRING is nil, no decoding is done."
487 :type '(repeat (cons (string :tag "suffix")
488 (choice :tag "command"
489 (const :tag "none" :value nil)
493 (defcustom Info-footnote-tag "Note"
494 "*Symbol that identifies a footnote or cross-reference.
495 All \"*Note\" references will be changed to use this word instead."
499 (defvar Info-current-file nil
500 "Info file that Info is now looking at, or nil.
501 This is the name that was specified in Info, not the actual file name.
502 It doesn't contain directory names or file name extensions added by Info.")
504 (defvar Info-current-subfile nil
505 "Info subfile that is actually in the *info* buffer now,
506 or nil if current info file is not split into subfiles.")
508 (defvar Info-current-node nil
509 "Name of node that Info is now looking at, or nil.")
511 (defvar Info-tag-table-marker nil
512 "Marker pointing at beginning of current Info file's tag table.
513 Marker points nowhere if file has no tag table.")
515 (defvar Info-tag-table-buffer nil)
517 (defvar Info-current-file-completions nil
518 "Cached completion list for current Info file.")
520 (defvar Info-current-annotation-completions nil
521 "Cached completion list for current annotation files.")
523 (defvar Info-index-alternatives nil
524 "List of possible matches for last Info-index command.")
526 (defvar Info-index-first-alternative nil)
528 (defcustom Info-annotations-path
530 (paths-construct-path (list user-init-directory "info.notes"))
531 (paths-construct-path '("~" ".infonotes"))
532 (paths-construct-path '("usr" "lib" "info.notes")
533 (char-to-string directory-sep-char)))
534 "*Names of files that contain annotations for different Info nodes.
535 By convention, the first one should reside in your personal directory.
536 The last should be a world-writable \"public\" annotations file."
540 (defcustom Info-button1-follows-hyperlink nil
541 "*Non-nil means mouse button1 click will follow hyperlink."
545 (defvar Info-standalone nil
546 "Non-nil if Emacs was started solely as an Info browser.")
548 (defvar Info-in-cross-reference nil)
549 (defvar Info-window-configuration nil)
551 (defvar Info-dir-prologue "-*- Text -*-
552 This is the file .../info/dir, which contains the topmost node of the
553 Info hierarchy. The first time you invoke Info you start off
554 looking at that node, which is (dir)Top.
556 File: dir Node: Top This is the top of the INFO tree
557 This (the Directory node) gives a menu of major topics.
559 * Menu: The list of major topics begins on the next line.
563 (defcustom Info-no-description-string "[No description available]"
564 "*Description string for info files that have none"
569 (defun info (&optional file)
570 "Enter Info, the documentation browser.
571 Optional argument FILE specifies the file to examine;
572 the default is the top-level directory of Info.
574 In interactive use, a prefix argument directs this command
575 to read a file name from the minibuffer."
576 (interactive (if current-prefix-arg
577 (list (read-file-name "Info file name: " nil nil t))))
578 (let ((p command-line-args))
580 (and (string-match "^-[fe]" (car p))
581 (equal (nth 1 p) "info")
582 (not Info-standalone)
583 (setq Info-standalone t)
585 (not (string-match "^-" (nth 2 p)))
586 (setq file (nth 2 p))
587 (setq command-line-args-left nil))
589 ; (Info-setup-x) ??? What was this going to be? Can anyone tell karlheg?
592 (Info-goto-node (concat "(" file ")"))
593 (and Info-standalone (info)))
594 (if (get-buffer "*info*")
595 (switch-to-buffer "*info*")
599 (defun Info-query (file)
600 "Enter Info, the documentation browser. Prompt for name of Info file."
601 (interactive "sInfo topic (default = menu): ")
604 (Info-goto-node "(dir)")
605 (Info-goto-node (concat "(" file ")"))))
607 (defun Info-setup-initial ()
608 (let ((f Info-annotations-path))
610 (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
611 (bury-buffer (find-file-noselect (car f))))
615 (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
616 "Go to an info node specified as separate FILENAME and NODENAME.
617 Look for a plausible filename, or if not found then look for URL's and
618 dispatch to the appropriate fn. NO-GOING-BACK is non-nil if
619 recovering from an error in this function; it says do not attempt
620 further (recursive) error recovery. TRYFILE is ??"
625 ;; empty filename is simple case
627 (Info-find-file-node nil nodename no-going-back tryfile line))
628 ;; Convert filename to lower case if not found as specified.
629 ;; Expand it, look harder...
630 ((let ((fname (substitute-in-file-name filename))
633 ;; If specified name starts with `./', then just try
634 ;; current directory. No point in searching for an absolute
636 ((string-match "^\\./" fname)
637 (list default-directory))
638 ((file-name-absolute-p fname)
640 (Info-additional-search-directory-list
641 (append Info-directory-list
642 Info-additional-search-directory-list))
643 (t Info-directory-list))))
644 ;; Search the directory list for file FNAME.
645 (while (and dirs (not found))
646 (setq temp (expand-file-name fname (car dirs)))
647 (setq found (Info-suffixed-file temp))
648 (setq dirs (cdr dirs)))
650 (progn (setq filename (expand-file-name found))
652 (Info-find-file-node filename nodename no-going-back tryfile line))
653 ;; Look for a URL. This pattern is stolen from w3.el to prevent
654 ;; loading it if we won't need it.
655 ((string-match (concat "^\\(wais\\|solo\\|x-exec\\|newspost\\|www\\|"
656 "mailto\\|news\\|tn3270\\|ftp\\|http\\|file\\|"
657 "telnet\\|gopher\\):")
659 (if (fboundp 'browse-url)
660 (browse-url filename)
661 (error "Cannot follow URLs in this XEmacs")))
663 (error "Info file %s does not exist" filename))))
665 (defun Info-find-file-node (filename nodename
666 &optional no-going-back tryfile line)
667 ;; This is the guts of what was Info-find-node. Whoever wrote this
668 ;; should be locked up where they can't do any more harm.
670 ;; Go into info buffer.
671 (or (eq major-mode 'Info-mode)
672 (switch-to-buffer "*info*"))
673 (buffer-disable-undo (current-buffer))
674 (run-hooks 'Info-startup-hook)
675 (or (eq major-mode 'Info-mode)
678 (equal Info-current-file filename)
680 (string= "dir" (file-name-nondirectory Info-current-file))
682 (format "Leave Info file `%s'? "
683 (file-name-nondirectory Info-current-file)))
686 ;; Record the node we are leaving.
687 (if (and Info-current-file (not no-going-back))
688 (Info-history-add Info-current-file Info-current-node (point)))
690 (setq Info-current-node nil
691 Info-in-cross-reference nil)
694 ;; Switch files if necessary
696 (equal Info-current-file filename)
697 (let ((buffer-read-only nil))
698 (setq Info-current-file nil
699 Info-current-subfile nil
700 Info-current-file-completions nil
701 Info-index-alternatives nil
702 buffer-file-name 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 "\\`<<.*>>\\'" qnode) qnode
784 (format "\"%s\"\\|<<%s>>" qnode qnode)))
785 (pat2 (concat "------ *File: *\\([^ ].*[^ ]\\) *Node: "
786 "*\\([^ ].*[^ ]\\) *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)))
1039 (defmacro Info-directory-files (dir-file &optional all full nosort files-only)
1040 "Return a list of Info files living in the same directory as DIR-FILE.
1041 This list actually contains the files living in this directory, except for
1042 the dir file itself and the secondary info files (foo-1 foo-2 etc).
1044 If the optional argument ALL is non nil, the secondary info files are also
1045 included in the list.
1047 Please refer to the function `directory-files' for the meaning of the other
1048 optional arguments."
1049 `(let* ((dir (file-name-directory ,dir-file))
1050 (all-files (remove ,dir-file (directory-files dir ',full nil ',nosort
1054 (remove (concat dir ".")
1055 (remove (concat dir "..") all-files))
1057 (remove ".." all-files))))
1061 (concat "-[0-9]+\\("
1062 ;; Extract all known compression suffixes from
1063 ;; Info-suffix-list. These suffixes can typically be
1064 ;; found in entries of the form `.info.something'.
1065 (let ((suff-list Info-suffix-list)
1067 (while (setq suff (pop suff-list))
1068 (and (string-match "^\\.info" (car suff))
1069 (setq regexp (concat regexp
1073 (and suff-list "\\|")))))
1077 (while (setq file (pop all-files))
1078 (or (string-match suff-match file)
1079 (push file info-files)))
1080 (reverse info-files)
1084 (defun Info-maybe-update-dir (file)
1085 "Rebuild dir or localdir according to `Info-auto-generate-directory'."
1086 (unless (or (not (file-exists-p (file-name-directory file)))
1087 (null (Info-directory-files file 'all)))
1088 (if (not (find-buffer-visiting file))
1089 (if (not (file-exists-p file))
1090 (if (or (memq Info-auto-generate-directory
1091 '(always if-missing if-outdated)))
1092 (Info-build-dir-anew (file-name-directory file)))
1093 (if (or (eq Info-auto-generate-directory 'always)
1094 (and (eq Info-auto-generate-directory 'if-outdated)
1095 (Info-dir-outdated-p file)))
1096 (Info-rebuild-dir file))))))
1098 ;; Record which *.info files are newer than the dir file
1099 (defvar Info-dir-newer-info-files nil)
1101 (defun Info-dir-outdated-p (file)
1102 "Return non-nil if dir or localdir is outdated.
1103 dir or localdir are outdated when an info file in the same
1104 directory has been modified more recently."
1105 (let ((dir-mod-time (nth 5 (file-attributes file)))
1107 (setq Info-dir-newer-info-files nil)
1111 (setq f-mod-time (nth 5 (file-attributes f)))
1112 (setq newer (or (> (car f-mod-time) (car dir-mod-time))
1113 (and (= (car f-mod-time) (car dir-mod-time))
1114 (> (car (cdr f-mod-time))
1115 (car (cdr dir-mod-time))))))
1116 (if (and (file-readable-p f) newer)
1117 (setq Info-dir-newer-info-files
1118 (cons f Info-dir-newer-info-files)))))
1119 (Info-directory-files file nil 'fullname 'nosort t))
1120 Info-dir-newer-info-files))
1122 (defun Info-extract-dir-entry-from (file)
1123 "Extract the dir entry from the info FILE.
1124 The dir entry is delimited by the markers `START-INFO-DIR-ENTRY'
1125 and `END-INFO-DIR-ENTRY'."
1127 (set-buffer (get-buffer-create " *Info-tmp*"))
1128 (when (file-readable-p file)
1129 (insert-file-contents file nil nil nil t)
1130 (goto-char (point-min))
1132 (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
1135 (unless (null (re-search-forward "^END-INFO-DIR-ENTRY" nil t))
1136 (goto-char (match-beginning 0))
1137 (car (Info-parse-dir-entries beg (point)))))))))
1139 ;; Parse dir entries contained between START and END into a list of the form
1140 ;; (filename topic node (description-line-1 description-line-2 ...))
1141 (defun Info-parse-dir-entries (start end)
1142 (let (entry entries)
1145 (narrow-to-region start end)
1147 (while (re-search-forward
1148 "^\\* \\([^:]+\\):\\([ \t]*(\\([^)]*\\))\\w*\\.\\|:\\)" nil t)
1149 (setq entry (list (match-string 2)
1151 (downcase (or (match-string 3)
1152 (match-string 1)))))
1159 (re-search-forward "[ \t]*" nil t)
1160 (or (and (re-search-forward "^[^ \t]" nil t)
1161 (goto-char (match-beginning 0)))
1163 "[ \t]*\n[ \t]*"))))
1165 (setq entries (cons (nreverse entry) entries)))))
1166 (nreverse entries)))
1168 (defun Info-dump-dir-entries (entries)
1172 (mapcar #'(lambda (e)
1173 (setq e (cdr e)) ; Drop filename
1174 (setq len (length (concat (car e)
1176 (if (> len description-col)
1177 (setq description-col len)))
1179 (setq description-col (+ 5 description-col))
1180 (mapcar #'(lambda (e)
1181 (setq e (cdr e)) ; Drop filename
1182 (insert "* " (car e) ":" (car (cdr e)))
1183 (setq e (car (cdr (cdr e))))
1185 (indent-to-column description-col)
1186 (insert (car e) "\n")
1192 (defun Info-build-dir-anew (directory)
1193 "Build info directory information for DIRECTORY.
1194 The generated directory listing may be saved to a `dir' according
1195 to the value of `Info-save-auto-generated-dir'."
1197 (let* ((dirfile (expand-file-name "dir" directory))
1198 (to-temp (or (null Info-save-auto-generated-dir)
1199 (eq Info-save-auto-generated-dir 'never)
1200 (and (not (file-writable-p dirfile))
1201 (message "File not writable %s. Using temporary."
1203 (info-files (Info-directory-files dirfile nil 'fullname nil t)))
1205 (message "Creating temporary dir in %s..." directory)
1206 (message "Creating %s..." dirfile))
1207 (set-buffer (find-file-noselect dirfile t))
1208 (setq buffer-read-only nil)
1210 (insert Info-dir-prologue "Info files in " directory ":\n\n")
1211 (Info-dump-dir-entries
1214 (or (Info-extract-dir-entry-from f)
1216 (progn (string-match "\\([^.]*\\)\\(\\..*\\)?$"
1217 (file-name-nondirectory f))
1219 (match-string 1 (file-name-nondirectory f))))
1221 (list Info-no-description-string))))
1224 (set-buffer-modified-p nil)
1227 (message "Creating temporary dir in %s...done" directory)
1228 (message "Creating %s...done" dirfile)))))
1231 (defun Info-rebuild-dir (file)
1232 "Build info directory information in the directory of dir FILE.
1233 Description of info files are merged from the info files in the
1234 directory and the contents of FILE with the description in info files
1235 taking precedence over descriptions in FILE.
1236 The generated directory listing may be saved to a `dir' according to
1237 the value of `Info-save-auto-generated-dir'."
1240 (let (dir-section-contents dir-full-contents
1246 (or (null Info-save-auto-generated-dir)
1247 (eq Info-save-auto-generated-dir 'never)
1248 (and (eq Info-save-auto-generated-dir 'always)
1249 (not (file-writable-p file))
1250 (message "File not writable %s. Using temporary." file))
1251 (and (eq Info-save-auto-generated-dir 'conservative)
1252 (or (and (not (file-writable-p file))
1254 "File not writable %s. Using temporary." file))
1256 (message "%s is outdated. Overwrite ? "
1258 (set-buffer (find-file-noselect file t))
1259 (setq buffer-read-only nil)
1261 (message "Rebuilding temporary %s..." file)
1262 (message "Rebuilding %s..." file))
1264 (setq buffer-read-only nil)
1265 (goto-char (point-min))
1266 (unless (and (search-forward "\^_")
1267 (re-search-forward "^\\* Menu:.*$" nil t)
1268 (setq mark (and (re-search-forward "^\\* " nil t)
1269 (match-beginning 0))))
1271 (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1272 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$"
1274 (match-beginning 0))
1277 (narrow-to-region mark next-section)
1278 (setq dir-section-contents (nreverse (Info-parse-dir-entries
1279 (point-min) (point-max))))
1282 (setq dir-entry (assoc (downcase
1283 (file-name-sans-extension
1284 (file-name-nondirectory file)))
1285 dir-section-contents)
1286 file-dir-entry (Info-extract-dir-entry-from file))
1289 ;; A dir entry in the info file takes precedence over
1290 ;; an existing entry in the dir file
1291 (setcdr dir-entry (cdr file-dir-entry)))
1292 (unless (or not-first-section
1294 (file-name-sans-extension
1295 (file-name-nondirectory file)))
1298 (setq dir-section-contents
1299 (cons file-dir-entry dir-section-contents))
1300 (setq dir-section-contents
1302 (capitalize (file-name-sans-extension
1303 (file-name-nondirectory
1306 (list Info-no-description-string))
1307 dir-section-contents))))))
1308 Info-dir-newer-info-files)
1309 (delete-region (point-min) (point-max))
1310 (Info-dump-dir-entries (nreverse dir-section-contents))
1312 (if (= next-section (point-max))
1313 (setq next-section nil)
1314 (or (setq mark (and (re-search-forward "^\\* " nil t)
1315 (match-beginning 0)))
1317 (setq next-section (or (and (re-search-forward
1318 "^[^* \t].*:[ \t]*$" nil t)
1319 (match-beginning 0))
1321 (setq not-first-section t)))
1324 (set-buffer-modified-p nil)
1325 (message "Rebuilding temporary %s...done" file))
1327 (message "Rebuilding %s...done" file))))))
1330 (defun Info-batch-rebuild-dir ()
1331 "(Re)build `dir' files in the directories remaining on the command line.
1332 Use this from the command line, with `-batch', it won't work in an
1335 Each file is processed even if an error occurred previously. For example,
1336 invoke \"xemacs -batch -f Info-batch-rebuild-dir /usr/local/info\"."
1337 ;; command-line-args-left is what is left of the command line (from
1339 (defvar command-line-args-left) ; Avoid 'free variable' warning
1340 (if (not noninteractive)
1341 (error "`Info-batch-rebuild-dir' is to be used only with -batch"))
1342 (let ((Info-save-auto-generated-dir 'always)
1344 (while command-line-args-left
1345 (if (not (file-directory-p (car command-line-args-left)))
1346 (message "Warning: Skipped %s. Not a directory."
1347 (car command-line-args-left))
1348 (setq dir (expand-file-name "dir" (car command-line-args-left)))
1349 (setq localdir (expand-file-name "localdir"
1350 (car command-line-args-left)))
1352 ((file-exists-p dir)
1353 (Info-rebuild-dir dir))
1354 ((file-exists-p localdir)
1355 (Info-rebuild-dir localdir))
1357 (Info-build-dir-anew (car command-line-args-left)))))
1358 (setq command-line-args-left (cdr command-line-args-left)))
1362 (defun Info-history-add (file node point)
1363 (if Info-keeping-history
1364 (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
1365 (found (assoc name Info-history)))
1367 (setq Info-history (delq found Info-history)))
1368 (setq Info-history (cons (list name (- point (point-min))
1369 (and (eq (window-buffer)
1371 (- (window-start) (point-min))))
1374 (defun Info-file-name-only (file)
1375 (let ((dir (file-name-directory file))
1376 (p Info-directory-list))
1377 (while (and p (not (equal (car p) dir)))
1379 (if p (file-name-nondirectory file) file)))
1381 (defun Info-read-subfile (nodepos)
1385 (set-buffer (marker-buffer Info-tag-table-marker))
1386 (goto-char (point-min))
1387 (search-forward "\n\^_")
1390 (while (not (looking-at "\^_"))
1392 (let ((start (point))
1393 thisfilepos thisfilename)
1394 (search-forward ": ")
1395 (setq thisfilename (buffer-substring start (- (point) 2)))
1396 (setq thisfilepos (read (current-buffer)))
1397 ;; read in version 19 stops at the end of number.
1398 ;; Advance to the next line.
1401 (if (> thisfilepos nodepos)
1403 (setq lastfilename thisfilename)
1404 (setq lastfilepos thisfilepos))
1406 (or (equal Info-current-subfile lastfilename)
1407 (let ((buffer-read-only nil))
1408 (setq buffer-file-name nil)
1411 (Info-insert-file-contents (Info-suffixed-file
1412 (expand-file-name lastfilename
1413 (file-name-directory
1417 (set-buffer-modified-p nil)
1418 (setq Info-current-subfile lastfilename)))
1419 (goto-char (point-min))
1420 (search-forward "\n\^_")
1421 (+ (- nodepos lastfilepos) (point))))
1423 (defun Info-all-case-regexp (str)
1429 (setq c (aref str i))
1430 (cond ((or (and (>= c ?A) (<= c ?Z))
1431 (and (>= c ?a) (<= c ?z)))
1432 (setq regexp (concat regexp
1434 (char-to-string (downcase c))
1436 (char-to-string (upcase c))
1439 (setq regexp (concat regexp (char-to-string c)))))
1443 (defun Info-suffixed-file (name &optional exact)
1444 "Look for an info file named NAME. This function tries to be smart in
1445 finding the file corresponding to NAME: if it doesn't exist, several
1446 variants are looked for, notably by appending suffixes from
1447 `Info-suffix-list' and by trying to change the characters case in NAME.
1449 The optional argument EXACT prevents this function from trying different case
1450 versions of NAME. Only the suffixes are tried."
1452 ;; First, try NAME alone:
1453 (and (file-regular-p name) (throw 'found name))
1454 ;; Then, try different variants
1455 (let ((suff-match (concat "\\("
1456 (let ((suff-list Info-suffix-list)
1458 (while (setq suff (pop suff-list))
1461 (regexp-quote (car suff))
1462 (and suff-list "\\|"))))
1465 (dir (file-name-directory name))
1467 (setq name (file-name-nondirectory name))
1469 (condition-case data ;; protect against invalid directory
1470 ;; First, try NAME[.<suffix>]
1472 (directory-files dir 'fullname
1473 (concat "^" (regexp-quote name) suff-match)
1477 ;; Then, try to match the name independantly of the
1479 (directory-files dir 'fullname
1480 (Info-all-case-regexp
1486 (display-warning 'info
1487 (format "directory `%s' error: %s" dir data))
1489 (while (setq file (pop files))
1490 (and (file-regular-p file)
1491 (throw 'found file)))
1494 (defun Info-insert-file-contents (file &optional visit)
1495 (setq file (expand-file-name file default-directory))
1496 (let ((suff Info-suffix-list)
1499 (setq len (length (car (car suff))))
1500 (or (<= (length file) len)
1502 (equal (substring file (- len))
1504 (equal (substring file (- len))
1505 (upcase (car (car suff)))))
1507 (setq suff (cdr suff)))
1508 (if (stringp (cdr (car suff)))
1509 (let ((command (if (string-match "%s" (cdr (car suff)))
1510 (format (cdr (car suff)) file)
1511 (concat (cdr (car suff)) " < " file))))
1512 (message "%s..." command)
1513 (call-process shell-file-name nil t nil shell-command-switch command)
1516 (setq buffer-file-name file)
1517 (set-buffer-modified-p nil)
1518 (clear-visited-file-modtime)))
1519 (insert-file-contents file visit))))
1521 (defun Info-select-node ()
1522 "Select the node that point is in, after using `g *' to select whole file."
1526 ;; Find beginning of node.
1527 (search-backward "\n\^_")
1529 ;; Get nodename spelled as it is in the node.
1530 (re-search-forward "Node:[ \t]*")
1531 (setq Info-current-node
1532 (buffer-substring (point)
1534 (skip-chars-forward "^,\t\n")
1536 (Info-set-mode-line)
1537 ;; Find the end of it, and narrow.
1539 (let (active-expression)
1540 (narrow-to-region (point)
1541 (if (re-search-forward "\n[\^_\f]" nil t)
1544 (if (looking-at "[\n\^_\f]*execute: ")
1546 (goto-char (match-end 0))
1547 (setq active-expression
1548 (read (current-buffer))))))
1550 (or (equal Info-footnote-tag "Note")
1552 (goto-char (point-min))
1553 (let ((buffer-read-only nil)
1554 (bufmod (buffer-modified-p))
1555 (case-fold-search t))
1556 (while (re-search-forward "\\*[Nn]ote\\([ \n]\\)" nil t)
1557 (replace-match (concat "*" Info-footnote-tag "\ ")))
1558 (set-buffer-modified-p bufmod))))
1559 (Info-reannotate-node)
1560 ;; XEmacs: remove v19 test
1562 (Info-fontify-node))
1563 (run-hooks 'Info-select-hook)
1564 (if Info-enable-active-nodes (eval active-expression)))))
1566 (defun Info-set-mode-line ()
1567 (setq modeline-buffer-identification
1568 (list (cons modeline-buffer-id-left-extent "Info: ")
1569 (cons modeline-buffer-id-right-extent
1572 (if Info-current-file
1573 (let ((name (file-name-nondirectory
1574 Info-current-file)))
1575 (if (string-match "^\\([^.]*\\)\\..*$" name)
1576 (match-string 1 name)
1580 (or Info-current-node ""))))))
1582 ;; Go to an info node specified with a filename-and-nodename string
1583 ;; of the sort that is found in pointers in nodes.
1586 (defun Info-goto-node (nodename &optional no-going-back tryfile)
1587 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
1588 Actually, the following interpretations of NAME are tried in order:
1590 (FILENAME) (using Top node)
1591 NODENAME (in current file)
1593 FILENAME (using Top node)
1594 where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
1595 annotation for any node of any file. (See `a' and `x' commands.)"
1596 (interactive (list (Info-read-node-name "Goto node, file or tag: ")
1599 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1601 (setq filename (if (= (match-beginning 1) (match-end 1))
1603 (substring nodename (match-beginning 2) (match-end 2)))
1604 nodename (substring nodename (match-beginning 3) (match-end 3)))
1605 (let ((trim (string-match "\\s *\\'" filename)))
1606 (if trim (setq filename (substring filename 0 trim))))
1607 (let ((trim (string-match "\\s *\\'" nodename)))
1608 (if trim (setq nodename (substring nodename 0 trim))))
1609 (Info-find-node (if (equal filename "") nil filename)
1610 (if (equal nodename "") "Top" nodename)
1611 no-going-back (and tryfile (equal filename "")))))
1613 (defun Info-goto-bookmark ()
1615 (let ((completion-ignore-case nil)
1616 (tag (completing-read "Goto tag: "
1617 (Info-build-annotation-completions)
1619 'Info-minibuffer-history)))
1620 (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
1623 (defun Info-visit-file (file)
1624 "Directly visit an info file."
1625 (interactive "fVisit Info file: ")
1626 (Info-find-node (expand-file-name file) "Top"))
1628 (defun Info-restore-point (&optional always)
1629 "Restore point to same location it had last time we were in this node."
1631 (if (or Info-restoring-point always)
1632 (let* ((name (format "(%s)%s"
1633 (Info-file-name-only Info-current-file)
1635 (p (assoc name Info-history)))
1636 (if p (Info-restore-history-entry p)))))
1638 (defun Info-restore-history-entry (entry)
1639 (goto-char (+ (nth 1 entry) (point-min)))
1641 (get-buffer-window (current-buffer))
1642 (set-window-start (get-buffer-window (current-buffer))
1643 (+ (nth 2 entry) (point-min)))))
1645 (defvar Info-read-node-completion-table)
1647 ;; This function is used as the "completion table" while reading a node name.
1648 ;; It does completion using the alist in Info-read-node-completion-table
1649 ;; unless STRING starts with an open-paren.
1650 (defun Info-read-node-name-1 (string predicate code)
1651 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
1652 (cond ((eq code nil)
1655 (try-completion string Info-read-node-completion-table
1660 (all-completions string Info-read-node-completion-table
1665 (assoc string Info-read-node-completion-table))))))
1667 (defun Info-read-node-name (prompt &optional default)
1668 (Info-setup-initial)
1669 (let* ((completion-ignore-case t)
1670 (Info-read-node-completion-table (Info-build-node-completions))
1671 (nodename (completing-read prompt 'Info-read-node-name-1
1672 nil t nil 'Info-minibuffer-history
1674 (if (equal nodename "")
1676 (Info-read-node-name prompt))
1679 (defun Info-build-annotation-completions ()
1680 (or Info-current-annotation-completions
1682 (let ((bufs (delq nil (mapcar 'get-file-buffer
1683 Info-annotations-path)))
1686 (set-buffer (car bufs))
1687 (goto-char (point-min))
1688 (while (re-search-forward "<<\\(.*\\)>>" nil t)
1689 (setq compl (cons (list (buffer-substring (match-beginning 1)
1692 (setq bufs (cdr bufs)))
1693 (setq Info-current-annotation-completions compl)))))
1695 (defun Info-build-node-completions ()
1696 (or Info-current-file-completions
1697 (let ((m Info-tag-table-marker)
1698 (compl (Info-build-annotation-completions)))
1702 (if (marker-buffer Info-tag-table-marker)
1704 (set-buffer (marker-buffer Info-tag-table-marker))
1706 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
1708 (cons (list (buffer-substring (match-beginning 1)
1711 (goto-char (point-min))
1712 (while (search-forward "\n\^_" nil t)
1714 (let ((start (point)))
1716 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
1719 (cons (list (buffer-substring (match-beginning 1)
1722 (setq Info-current-file-completions compl))))
1724 (defvar Info-last-search nil
1725 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1729 (defun Info-search (regexp)
1730 "Search for REGEXP, starting from point, and select node it's found in."
1732 (read-from-minibuffer
1733 (if Info-last-search
1734 (format "Search (regexp, default %s): "
1736 "Search (regexp): ")
1737 nil nil nil nil nil Info-last-search)))
1738 (setq Info-last-search regexp)
1739 (with-search-caps-disable-folding regexp t
1741 (onode Info-current-node)
1742 (ofile Info-current-file)
1744 (osubfile Info-current-subfile))
1748 (if (null Info-current-subfile)
1749 (progn (re-search-forward regexp) (setq found (point)))
1751 (progn (re-search-forward regexp) (setq found (point)))
1752 (search-failed nil)))))
1754 ;; can only happen in subfile case -- else would have erred
1758 (set-buffer (marker-buffer Info-tag-table-marker))
1759 (goto-char (point-min))
1760 (search-forward "\n\^_\nIndirect:")
1762 (narrow-to-region (point)
1763 (progn (search-forward "\n\^_")
1765 (goto-char (point-min))
1766 (search-forward (concat "\n" osubfile ": "))
1769 (re-search-forward "\\(^.*\\): [0-9]+$")
1770 (goto-char (+ (match-end 1) 2))
1771 (setq list (cons (cons (read (current-buffer))
1776 (goto-char (1+ (match-end 0))))
1777 (setq list (nreverse list)
1780 (message "Searching subfile %s..." (cdr (car list)))
1781 (Info-read-subfile (car (car list)))
1782 (setq list (cdr list))
1783 (goto-char (point-min))
1784 (if (re-search-forward regexp nil t)
1785 (setq found (point) list ())))
1788 (signal 'search-failed (list regexp))))
1790 (progn (Info-read-subfile opoint)
1792 (Info-select-node)))))
1796 (or (and (equal onode Info-current-node)
1797 (equal ofile Info-current-file))
1798 (Info-history-add ofile onode opoint)))))
1800 ;; Extract the value of the node-pointer named NAME.
1801 ;; If there is none, use ERRORNAME in the error message;
1802 ;; if ERRORNAME is nil, just return nil.
1803 (defun Info-extract-pointer (name &optional errorname)
1805 (goto-char (point-min))
1807 (let ((case-fold-search t))
1808 (if (re-search-backward (concat name ":") nil t)
1810 (goto-char (match-end 0))
1811 (Info-following-node-name))
1812 (if (eq errorname t)
1814 (error (concat "Node has no " (capitalize (or errorname name)))))))))
1816 ;; Return the node name in the buffer following point.
1817 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1818 ;; saying which chars may appear in the node name.
1819 (defun Info-following-node-name (&optional allowedchars)
1820 (skip-chars-forward " \t")
1824 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1825 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1826 (if (looking-at "(")
1827 (skip-chars-forward "^)")))
1828 (skip-chars-backward " .")
1831 (defun Info-next (&optional n)
1832 "Go to the next node of this node.
1833 A positive or negative prefix argument moves by multiple nodes."
1838 (while (>= (setq n (1- n)) 0)
1839 (Info-goto-node (Info-extract-pointer "next")))))
1841 (defun Info-prev (&optional n)
1842 "Go to the previous node of this node.
1843 A positive or negative prefix argument moves by multiple nodes."
1848 (while (>= (setq n (1- n)) 0)
1849 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
1851 (defun Info-up (&optional n)
1852 "Go to the superior node of this node.
1853 A positive prefix argument moves up several times."
1856 (while (>= (setq n (1- n)) 0)
1857 (Info-goto-node (Info-extract-pointer "up")))
1858 (if (interactive-p) (Info-restore-point)))
1860 (defun Info-last (&optional n)
1861 "Go back to the last node visited.
1862 With a prefix argument, go to Nth most recently visited node. History is
1863 circular; after oldest node, history comes back around to most recent one.
1864 Argument can be negative to go through the circle in the other direction.
1865 \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
1869 (error "This is the first Info node you looked at"))
1870 (let ((len (1+ (length Info-history))))
1871 (setq n (% (+ n (* len 100)) len)))
1873 (let ((entry (nth (1- n) Info-history)))
1874 (Info-history-add Info-current-file Info-current-node (point))
1875 (while (>= (setq n (1- n)) 0)
1876 (setq Info-history (nconc (cdr Info-history)
1877 (list (car Info-history)))))
1878 (setq Info-history (cdr Info-history))
1879 (let ((Info-keeping-history nil))
1880 (Info-goto-node (car entry)))
1881 (Info-restore-history-entry entry))))
1883 (defun Info-directory ()
1884 "Go to the Info directory node."
1886 (Info-find-node "dir" "top"))
1888 (defun Info-follow-reference (footnotename)
1889 "Follow cross reference named NAME to the node it refers to.
1890 NAME may be an abbreviation of the reference name."
1892 (let ((completion-ignore-case t)
1893 completions default (start-point (point)) str i)
1895 (goto-char (point-min))
1896 (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
1899 (setq str (buffer-substring
1902 ;; See if this one should be the default.
1904 (< (match-beginning 0) start-point)
1905 (<= start-point (point))
1908 (while (setq i (string-match "[ \n\t]+" str i))
1909 (setq str (concat (substring str 0 i) " "
1910 (substring str (match-end 0))))
1912 ;; Record as a completion and perhaps as default.
1913 (if (eq default t) (setq default str))
1915 (cons (cons str nil)
1918 (let ((item (completing-read (if default
1919 (concat "Follow reference named: ("
1921 "Follow reference named: ")
1922 completions nil t nil
1923 'Info-minibuffer-history
1925 (if (and (string= item "") default)
1928 (error "No cross-references in this node"))))
1929 (let (target i (str (concat "\\*" Info-footnote-tag " "
1930 (regexp-quote footnotename))))
1931 (while (setq i (string-match " " str i))
1932 (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
1933 (substring str (1+ i))))
1936 (goto-char (point-min))
1937 (or (re-search-forward str nil t)
1938 (error "No cross-reference named %s" footnotename))
1939 (goto-char (match-end 1))
1941 (Info-extract-menu-node-name "Bad format cross reference" t)))
1942 (while (setq i (string-match "[ \t\n]+" target i))
1943 (setq target (concat (substring target 0 i) " "
1944 (substring target (match-end 0))))
1946 (Info-goto-node target)
1947 (setq Info-in-cross-reference t)))
1949 (defun Info-next-reference (n)
1951 (let ((pat (format "\\*%s[ \n\t]*\\([^:]*\\):\\|^\\* .*:\\|<<.*>>"
1954 wrapped found-nomenu)
1956 (unless (re-search-backward pat nil t)
1957 ;; Don't wrap more than once in a buffer where only the
1958 ;; menu references are found.
1959 (when (and wrapped (not found-nomenu))
1961 (error "No cross references in this node"))
1963 (goto-char (point-max))
1964 (unless (re-search-backward pat nil t)
1966 (error "No cross references in this node")))
1967 (unless (save-excursion
1968 (goto-char (match-beginning 0))
1969 (when (looking-at "\\* Menu:")
1971 (setq found-nomenu t))
1974 (or (eobp) (forward-char 1))
1975 (unless (re-search-forward pat nil t)
1976 (when (and wrapped (not found-nomenu))
1978 (error "No cross references in this node"))
1980 (goto-char (point-min))
1981 (unless (re-search-forward pat nil t)
1983 (error "No cross references in this node")))
1984 (unless (save-excursion
1985 (goto-char (match-beginning 0))
1986 (when (looking-at "\\* Menu:")
1988 (setq found-nomenu t))
1990 (when (looking-at "\\* Menu:")
1991 (error "No cross references in this node"))
1992 (goto-char (match-beginning 0))))
1994 (defun Info-prev-reference (n)
1996 (Info-next-reference (- n)))
1998 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1999 (skip-chars-forward " \t\n")
2000 (let ((start (point))
2002 (skip-chars-forward "^:")
2005 (if (looking-at ":")
2006 (buffer-substring start (1- (point)))
2007 (skip-chars-forward " \t\n")
2009 ;; Allow dots in node name not followed by whitespace.
2011 (concat "\\(([^)]+)[^.,"
2012 (if multi-line "" "\n")
2014 (if multi-line "" "\n")
2015 ;; We consider dots followed by newline as
2016 ;; end of nodename even if multil-line.
2017 ;; Also stops at .). It is generated by @pxref.
2018 ;; Skips sequential dots.
2019 "]\\|\\.+[^ \t\n)]\\)+\\)"))
2021 (while (setq i (string-match "\n" str i))
2025 (defun Info-menu (menu-item)
2026 "Go to node for menu item named (or abbreviated) NAME.
2027 Completion is allowed, and the menu item point is on is the default."
2029 (let ((completions '())
2030 ;; If point is within a menu item, use that item as the default
2035 (goto-char (point-min))
2036 (let ((case-fold-search t))
2037 (if (not (search-forward "\n* menu:" nil t))
2038 (error "No menu in this node")))
2039 (while (re-search-forward
2040 "\n\\* \\([^:\t\n]*\\):" nil t)
2041 (if (and (null default)
2042 (prog1 (if last (< last p) nil)
2043 (setq last (match-beginning 0)))
2045 (setq default (car (car completions))))
2046 (setq completions (cons (cons (buffer-substring
2049 (match-beginning 1))
2051 (if (and (null default) last
2053 (<= p (progn (end-of-line) (point))))
2054 (setq default (car (car completions)))))
2057 (setq item (let ((completion-ignore-case t))
2058 (completing-read (if default
2059 (format "Menu item (default %s): "
2062 completions nil t nil
2063 'Info-minibuffer-history
2065 ;; we rely on the fact that completing-read accepts an input
2066 ;; of "" even when the require-match argument is true and ""
2067 ;; is not a valid possibility
2068 (if (string= item "")
2074 ;; there is a problem here in that if several menu items have the same
2075 ;; name you can only go to the node of the first with this command.
2076 (Info-goto-node (Info-extract-menu-item menu-item) nil t))
2078 (defun Info-extract-menu-item (menu-item &optional noerror)
2080 (goto-char (point-min))
2081 (if (let ((case-fold-search t))
2082 (search-forward "\n* menu:" nil t))
2083 (if (or (search-forward (concat "\n* " menu-item ":") nil t)
2084 (search-forward (concat "\n* " menu-item) nil t))
2088 (Info-extract-menu-node-name))
2089 (and (not noerror) (error "No such item in menu")))
2090 (and (not noerror) (error "No menu in this node")))))
2092 ;; If COUNT is nil, use the last item in the menu.
2093 (defun Info-extract-menu-counting (count &optional noerror noindex)
2095 (goto-char (point-min))
2096 (if (let ((case-fold-search t))
2097 (and (search-forward "\n* menu:" nil t)
2099 (not (string-match "\\<Index\\>" Info-current-node)))))
2100 (if (search-forward "\n* " nil t count)
2103 (while (search-forward "\n* " nil t)))
2104 (Info-extract-menu-node-name))
2105 (and (not noerror) (error "Too few items in menu")))
2106 (and (not noerror) (error "No menu in this node")))))
2108 (defun Info-nth-menu-item (n)
2109 "Go to the node of the Nth menu item."
2111 (or n (setq n (- last-command-char ?0)))
2112 (if (< n 1) (error "Index must be at least 1"))
2113 (Info-goto-node (Info-extract-menu-counting n) nil t))
2115 (defun Info-last-menu-item ()
2116 "Go to the node of the tenth menu item."
2118 (Info-goto-node (Info-extract-menu-counting nil) nil t))
2121 "Go to the Top node of this file."
2123 (Info-goto-node "Top"))
2126 "Go to the final node in this file."
2129 (let ((Info-keeping-history nil)
2131 (Info-last-menu-item)
2132 (while (setq node (or (Info-extract-pointer "next" t)
2133 (Info-extract-menu-counting nil t t)))
2134 (Info-goto-node node))
2135 (or (equal (Info-extract-pointer "up" t) "Top")
2136 (let ((executing-kbd-macro "")) ; suppress messages
2138 (Info-global-next 10000)
2141 (defun Info-global-next (&optional n)
2142 "Go to the next node in this file, traversing node structure as necessary.
2143 This works only if the Info file is structured as a hierarchy of nodes.
2144 A positive or negative prefix argument moves by multiple nodes."
2148 (Info-global-prev (- n))
2149 (while (>= (setq n (1- n)) 0)
2151 (cond ((and (string-match "^Top$" Info-current-node)
2152 (setq node (Info-extract-pointer "next" t))
2153 (Info-extract-menu-item node t))
2154 (Info-goto-node node))
2155 ((setq node (Info-extract-menu-counting 1 t t))
2156 (message "Going down...")
2157 (Info-goto-node node))
2159 (let ((Info-keeping-history Info-keeping-history)
2160 (orignode Info-current-node)
2162 (while (not (Info-extract-pointer "next" t))
2163 (if (and (setq node (Info-extract-pointer "up" t))
2164 (not (equal node "Top")))
2166 (message "Going%s..." (setq ups (concat ups " up")))
2167 (Info-goto-node node)
2168 (setq Info-keeping-history nil))
2170 (let ((Info-keeping-history nil))
2171 (Info-goto-node orignode)))
2172 (error "Last node in file")))
2175 (defun Info-page-next (&optional n)
2176 "Scroll forward one screenful, or go to next global node.
2177 A positive or negative prefix argument moves by multiple screenfuls."
2181 (Info-page-prev (- n))
2182 (while (>= (setq n (1- n)) 0)
2183 (if (pos-visible-in-window-p (point-max))
2186 (message "Node: %s" Info-current-node))
2189 (defun Info-scroll-next (arg)
2191 (if Info-auto-advance
2192 (if (and (pos-visible-in-window-p (point-max))
2193 (not (eq Info-auto-advance t))
2194 (not (eq last-command this-command)))
2195 (message "Hit %s again to go to next node"
2196 (if (= last-command-char 0)
2198 (key-description (char-to-string last-command-char))))
2200 (setq this-command 'Info))
2203 (defun Info-global-prev (&optional n)
2204 "Go to the previous node in this file, traversing structure as necessary.
2205 This works only if the Info file is structured as a hierarchy of nodes.
2206 A positive or negative prefix argument moves by multiple nodes."
2210 (Info-global-next (- n))
2211 (while (>= (setq n (1- n)) 0)
2212 (let ((upnode (Info-extract-pointer "up" t))
2213 (prevnode (Info-extract-pointer "prev[ious]*" t)))
2214 (if (or (not prevnode)
2215 (equal prevnode upnode))
2216 (if (string-match "^Top$" Info-current-node)
2217 (error "First node in file")
2218 (message "Going up...")
2220 (Info-goto-node prevnode)
2222 (Info-keeping-history nil)
2224 (while (setq node (Info-extract-menu-counting nil t t))
2225 (message "Going%s..." (setq downs (concat downs " down")))
2226 (Info-goto-node node))))))))
2228 (defun Info-page-prev (&optional n)
2229 "Scroll backward one screenful, or go to previous global node.
2230 A positive or negative prefix argument moves by multiple screenfuls."
2234 (Info-page-next (- n))
2235 (while (>= (setq n (1- n)) 0)
2236 (if (pos-visible-in-window-p (point-min))
2239 (message "Node: %s" Info-current-node)
2240 (goto-char (point-max))
2242 (move-to-window-line 0))
2245 (defun Info-scroll-prev (arg)
2247 (if Info-auto-advance
2248 (if (and (pos-visible-in-window-p (point-min))
2249 (not (eq Info-auto-advance t))
2250 (not (eq last-command this-command)))
2251 (message "Hit %s again to go to previous node"
2252 (if (mouse-event-p last-command-event)
2254 (key-description (event-key last-command-event))))
2256 (setq this-command 'Info))
2259 (defun Info-index (topic)
2260 "Look up a string in the index for this file.
2261 The index is defined as the first node in the top-level menu whose
2262 name contains the word \"Index\", plus any immediately following
2263 nodes whose names also contain the word \"Index\".
2264 If there are no exact matches to the specified topic, this chooses
2265 the first match which is a case-insensitive substring of a topic.
2266 Use the `,' command to see the other matches.
2267 Give a blank topic name to go to the Index node itself."
2268 (interactive "sIndex topic: ")
2269 (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
2270 (regexp-quote topic)
2271 "\\(.*\\)\\.[ \t]*\\([0-9]*\\)$"))
2273 (message "Searching index for `%s'..." topic)
2274 (Info-goto-node "Top")
2275 (let ((case-fold-search t))
2276 (or (search-forward "\n* menu:" nil t)
2278 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2279 (error "No index")))
2280 (goto-char (match-beginning 1))
2281 (let ((Info-keeping-history nil)
2282 (Info-fontify (and Info-fontify (equal topic ""))))
2283 (Info-goto-node (Info-extract-menu-node-name)))
2284 (or (equal topic "")
2287 (Info-keeping-history nil)
2291 (goto-char (point-min))
2292 (while (re-search-forward pattern nil t)
2294 (cons (list (buffer-substring (match-beginning 1)
2296 (buffer-substring (match-beginning 2)
2299 (string-to-int (concat "0"
2304 (and (setq node (Info-extract-pointer "next" t))
2305 (string-match "\\<Index\\>" node)))
2306 (let ((Info-fontify nil))
2307 (Info-goto-node node)))
2311 (error "No \"%s\" in index" topic)))
2312 ;; Here it is a feature that assoc is case-sensitive.
2313 (while (setq found (assoc topic matches))
2314 (setq exact (cons found exact)
2315 matches (delq found matches)))
2316 (setq Info-index-alternatives (nconc exact (nreverse matches))
2317 Info-index-first-alternative (car Info-index-alternatives))
2318 (Info-index-next 0)))))
2320 (defun Info-index-next (num)
2321 "Go to the next matching index item from the last `i' command."
2323 (or Info-index-alternatives
2324 (error "No previous `i' command in this file"))
2326 (setq num (+ num (length Info-index-alternatives))))
2328 (setq Info-index-alternatives
2329 (nconc (cdr Info-index-alternatives)
2330 (list (car Info-index-alternatives)))
2332 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2333 (if (> (nth 3 (car Info-index-alternatives)) 0)
2334 (forward-line (nth 3 (car Info-index-alternatives)))
2335 (forward-line 3) ; don't search in headers
2336 (let ((name (car (car Info-index-alternatives))))
2337 (if (or (re-search-forward (format
2338 "\\(Function\\|Command\\): %s\\( \\|$\\)"
2339 (regexp-quote name)) nil t)
2340 (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
2341 (search-forward (format "`%s'" name) nil t)
2342 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2344 (format "`%s'" (substring name 0 (match-beginning 1)))
2346 (search-forward name nil t))
2348 (goto-char (point-min)))))
2349 (message "Found \"%s\" in %s. %s"
2350 (car (car Info-index-alternatives))
2351 (nth 2 (car Info-index-alternatives))
2352 (if (cdr Info-index-alternatives)
2353 (if (eq (car (cdr Info-index-alternatives))
2354 Info-index-first-alternative)
2355 "(Press `,' to repeat)"
2356 (format "(Press `,' for %d more)"
2357 (- (1- (length Info-index-alternatives))
2358 (length (memq Info-index-first-alternative
2359 (cdr Info-index-alternatives))))))
2364 (defun Info-emacs-command (command)
2365 "Look up an Emacs command in the Emacs manual in the Info system.
2366 This command is designed to be used whether you are already in Info or not."
2367 (interactive "CLook up command in Emacs manual: ")
2368 (save-window-excursion
2370 (Info-find-node Info-emacs-info-file-name "Top")
2371 (Info-index (symbol-name command)))
2372 (pop-to-buffer "*info*"))
2376 (defun Info-goto-emacs-command-node (key)
2377 "Look up an Emacs command in the Emacs manual in the Info system.
2378 This command is designed to be used whether you are already in Info or not."
2379 (interactive "CLook up command in Emacs manual: ")
2380 (Info-emacs-command key))
2383 (defun Info-goto-emacs-key-command-node (key)
2384 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2385 This command is designed to be used whether you are already in Info or not."
2386 (interactive "kLook up key in Emacs manual: ")
2387 (let ((command (key-binding key)))
2388 (cond ((eq command 'keyboard-quit)
2391 (error "%s is undefined" (key-description key)))
2392 ((and (interactive-p) (eq command 'execute-extended-command))
2393 (call-interactively 'Info-goto-emacs-command-node))
2395 (Info-goto-emacs-command-node command)))))
2398 (defun Info-emacs-key (key)
2399 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2400 This command is designed to be used whether you are already in Info or not."
2401 (interactive "kLook up key in Emacs manual: ")
2402 (cond ((eq (key-binding key) 'keyboard-quit)
2404 ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
2405 (call-interactively 'Info-goto-emacs-command-node))
2407 (save-window-excursion
2409 (Info-find-node Info-emacs-info-file-name "Top")
2410 (setq key (key-description key))
2412 (if (setq p (string-match "[@{}]" key))
2413 (setq key (concat (substring key 0 p) "@" (substring key p))))
2414 (if (string-match "^ESC " key)
2415 (setq key (concat "M-" (substring key 4))))
2416 (if (string-match "^M-C-" key)
2417 (setq key (concat "C-M-" (substring key 4)))))
2419 (pop-to-buffer "*info*"))))
2422 (defun Info-elisp-ref (func)
2423 "Look up an Emacs Lisp function in the Elisp manual in the Info system.
2424 This command is designed to be used whether you are already in Info or not."
2425 (interactive (let ((fn (function-at-point))
2426 (enable-recursive-minibuffers t)
2428 (setq val (completing-read
2429 (format "Look up Emacs Lisp function%s: "
2431 (format " (default %s)" fn)
2434 nil nil (and fn (symbol-name fn))))
2435 (list (if (equal val "")
2437 (save-window-excursion
2440 (Info-find-node "lispref" "Top")
2441 (error (Info-find-node "elisp" "Top")))
2442 (Info-index (symbol-name func)))
2443 (pop-to-buffer "*info*"))
2445 (defun Info-reannotate-node ()
2446 (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
2448 (let ((ibuf (current-buffer))
2449 (file (concat "\\(" (regexp-quote
2450 (file-name-nondirectory Info-current-file))
2451 "\\|" (regexp-quote Info-current-file) "\\)"))
2452 (node (regexp-quote Info-current-node))
2454 (goto-char (point-min))
2455 (if (search-forward "\n------ NOTE:\n" nil t)
2456 (let ((buffer-read-only nil)
2457 (bufmod (buffer-modified-p))
2459 (setq savept (copy-marker savept))
2460 (goto-char (point-min))
2461 (while (search-forward "\n------ NOTE:" nil t)
2462 (setq top (1+ (match-beginning 0)))
2463 (if (search-forward "\n------\n" nil t)
2464 (delete-region top (point)))
2466 (set-buffer-modified-p bufmod)))
2469 (set-buffer (car bufs))
2470 (goto-char (point-min))
2471 (while (re-search-forward
2473 "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
2476 (let ((line (string-to-int
2477 (buffer-substring (match-beginning 2)
2481 (search-forward "\n------\n" nil t)
2485 (if (integerp savept) (setq savept (copy-marker savept)))
2487 (goto-char (point-max))
2488 (goto-char (point-min))
2489 (forward-line line))
2490 (let ((buffer-read-only nil)
2491 (bufmod (buffer-modified-p)))
2492 (insert "------ NOTE:\n")
2493 (insert-buffer-substring (car bufs) top bot)
2494 (set-buffer-modified-p bufmod)))))
2495 (setq bufs (cdr bufs))))
2496 (goto-char savept)))))
2498 (defvar Info-annotate-map nil
2499 "Local keymap used within `a' command of Info.")
2501 (if Info-annotate-map
2503 ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
2504 (setq Info-annotate-map (copy-keymap text-mode-map))
2505 (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
2507 (defun Info-annotate-mode ()
2508 "Major mode for adding an annotation to an Info node.
2509 Like text mode with the addition of Info-cease-annotate
2510 which returns to Info mode for browsing.
2511 \\{Info-annotate-map}")
2513 (defun Info-annotate (arg)
2514 "Add a personal annotation to the current Info node.
2515 Only you will be able to see this annotation. Annotations are stored
2516 in the file \"~/.xemacs/info.notes\" by default. If point is inside
2517 an existing annotation, edit that annotation. A prefix argument
2518 specifies which annotations file (from `Info-annotations-path') is to
2519 be edited; default is 1."
2522 (if (or (< arg 0) (not (nth arg Info-annotations-path)))
2524 (setq Info-annotations-path
2525 (list (read-file-name
2526 "Annotations file: " "~/" "~/.infonotes")))
2527 (error "File number must be in the range from 1 to %d"
2528 (length Info-annotations-path))))
2530 (file (file-name-nondirectory Info-current-file))
2531 (d Info-directory-list)
2533 (while (and d (not (equal (expand-file-name file (car d))
2534 Info-current-file)))
2536 (or d (setq file Info-current-file))
2537 (if (and (save-excursion
2538 (goto-char (min (point-max) (+ (point) 13)))
2539 (and (search-backward "------ NOTE:\n" nil t)
2540 (setq pt (match-end 0))
2541 (search-forward "\n------\n" nil t)))
2542 (< (point) (match-end 0)))
2543 (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
2545 (regexp-quote Info-current-node)
2547 (buffer-substring pt (match-beginning 0))))
2548 where (max (- (point) pt) 0)))
2549 (let ((node Info-current-node)
2550 (line (if (looking-at "[ \n]*\\'") 0
2551 (count-lines (point-min) (point)))))
2553 (let ((buffer-read-only nil)
2554 (bufmod (buffer-modified-p)))
2556 (if (bobp) (goto-char (point-max)))
2557 (insert "------ NOTE:\n------\n")
2559 (set-buffer-modified-p bufmod)))
2560 ;; (setq Info-window-start (window-start))
2561 (setq Info-window-configuration (current-window-configuration))
2562 (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
2563 (use-local-map Info-annotate-map)
2564 (setq major-mode 'Info-annotate-mode)
2565 (setq mode-name "Info Annotate")
2568 (goto-char (point-min))
2569 (re-search-forward which nil t))
2571 (goto-char (match-beginning 0))
2573 (forward-char where)))
2574 (let ((bufmod (buffer-modified-p)))
2575 (goto-char (point-max))
2576 (insert (format "\n------ File: %s Node: %s Line: %d\n"
2579 (insert "\n------\n"
2580 "\nPress C-c C-c to save and return to Info.\n")
2582 (set-buffer-modified-p bufmod))))))
2584 (defun Info-cease-annotate ()
2586 (let ((bufmod (buffer-modified-p)))
2587 (while (save-excursion
2588 (goto-char (point-min))
2589 (re-search-forward "\n\n?Press .* to save and return to Info.\n"
2591 (delete-region (1+ (match-beginning 0)) (match-end 0)))
2592 (while (save-excursion
2593 (goto-char (point-min))
2594 (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
2596 (delete-region (match-beginning 0) (match-end 0)))
2597 (set-buffer-modified-p bufmod))
2601 (or (one-window-p) (delete-window))
2603 (setq Info-current-annotation-completions nil)
2604 (set-window-configuration Info-window-configuration)
2605 (Info-reannotate-node))
2607 (defun Info-bookmark (arg tag)
2608 (interactive "p\nsBookmark name: ")
2610 (if (or (string-match "^\"\\(.*\\)\"$" tag)
2611 (string-match "^<<\\(.*\\)>>$" tag))
2612 (setq tag (substring tag (match-beginning 1) (match-end 1))))
2614 (search-forward "\n------\n")
2615 (let ((end (- (point) 8)))
2617 (if (re-search-forward "<<[^>\n]*>>" nil t)
2618 (delete-region (match-beginning 0) (match-end 0))
2621 (insert "<<" tag ">>"))))
2622 (Info-cease-annotate))
2625 "Exit Info by selecting some other buffer."
2628 (save-buffers-kill-emacs)
2629 (bury-buffer (current-buffer))
2630 (if (and (featurep 'toolbar)
2631 (boundp 'toolbar-info-frame)
2632 (eq toolbar-info-frame (selected-frame)))
2634 (delete-frame toolbar-info-frame)
2635 (error (bury-buffer)))
2636 (switch-to-buffer (other-buffer (current-buffer))))))
2638 (defun Info-undefined ()
2639 "Make command be undefined in Info."
2644 "Enter the Info tutorial."
2646 (delete-other-windows)
2647 (Info-find-node "info"
2648 (if (< (window-height) 23)
2652 (defun Info-summary ()
2653 "Display a brief summary of all Info commands."
2655 (save-window-excursion
2656 (switch-to-buffer "*Help*")
2658 (insert (documentation 'Info-mode))
2659 (goto-char (point-min))
2661 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2662 (message (if flag "Type Space to see more"
2663 "Type Space to return to Info"))
2664 (let ((e (next-command-event)))
2665 (if (/= ?\ (event-to-character e))
2666 (progn (setq unread-command-event e) nil)
2670 (bury-buffer "*Help*")))
2672 (defun Info-get-token (pos start all &optional errorstring)
2673 "Return the token around POS,
2674 POS must be somewhere inside the token
2675 START is a regular expression which will match the
2676 beginning of the tokens delimited string
2677 ALL is a regular expression with a single
2678 parenthized subpattern which is the token to be
2679 returned. E.g. '{\(.*\)}' would return any string
2680 enclosed in braces around POS.
2681 SIG optional fourth argument, controls action on no match
2684 a string: signal an error, using that string."
2686 (goto-char (point-min))
2687 (re-search-backward "\\`") ; Bug fix due to Nicholas J. Foskett.
2689 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
2691 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2692 (not (setq found (and (<= (match-beginning 0) pos)
2693 (> (match-end 0) pos))))))
2694 (if (and found (<= (match-beginning 0) pos)
2695 (> (match-end 0) pos))
2696 (buffer-substring (match-beginning 1) (match-end 1))
2697 (cond ((null errorstring)
2703 (error "No %s around position %d" errorstring pos)))))))
2705 (defun Info-follow-clicked-node (event)
2706 "Follow a node reference near clicked point. Like M, F, N, P or U command.
2707 At end of the node's text, moves to the next node."
2709 (or (and (event-point event)
2710 (Info-follow-nearest-node
2712 (select-window (event-window event))
2713 (event-point event))
2715 (error "click on a cross-reference to follow")))
2717 (defun Info-maybe-follow-clicked-node (event &optional click-count)
2718 "Follow a node reference (if any) near clicked point.
2719 Like M, F, N, P or U command. At end of the node's text, moves to the
2720 next node. No error is given if there is no node to follow."
2722 (and Info-button1-follows-hyperlink
2724 (Info-follow-nearest-node
2726 (select-window (event-window event))
2727 (event-point event))
2728 (1+ (point-min))))))
2730 (defun Info-find-nearest-node (point)
2733 ((= point (point-min)) nil) ; don't trigger on accidental RET.
2734 ((setq node (Info-get-token point
2735 (format "\\*%s[ \n]" Info-footnote-tag)
2736 (format "\\*%s[ \n]\\([^:]*\\):"
2737 Info-footnote-tag)))
2738 (list "Following cross-reference %s..."
2739 (list 'Info-follow-reference node)))
2740 ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\)::"))
2741 (list "Selecting menu item %s..."
2742 (list 'Info-goto-node node nil t)))
2743 ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\):"))
2744 (list "Selecting menu item %s..."
2745 (list 'Info-menu node)))
2746 ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
2748 (list 'Info-goto-node node)))
2749 ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
2750 (list "Next node..."
2751 (list 'Info-goto-node node)))
2752 ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
2754 (list 'Info-goto-node "Top")))
2755 ((setq node (Info-get-token point "Prev[ious]*: "
2756 "Prev[ious]*: \\([^,\n\t]*\\)"))
2757 (list "Previous node..."
2758 (list 'Info-goto-node node)))
2759 ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
2760 (list "Reselecting %s..."
2761 (list 'Info-goto-node node)))
2762 ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
2763 (if Info-in-cross-reference
2764 (list "Back to last node..."
2766 (list "Next node..."
2767 '(Info-global-next)))))
2770 (defun Info-follow-nearest-node (point)
2771 "Follow a node reference near point. Like M, F, N, P or U command.
2772 At end of the node's text, moves to the next node."
2774 (let ((data (Info-find-nearest-node point)))
2777 (let ((msg (format (car data) (nth 1 (nth 1 data)))))
2780 (message "%sdone" msg))
2783 (defun Info-indicated-node (event)
2786 (cond ((eventp event)
2787 (set-buffer (event-buffer event))
2788 (setq event (event-point event))))
2789 (let* ((data (Info-find-nearest-node event))
2790 (name (nth 1 (nth 1 data))))
2791 (and name (nth 1 data))))
2794 (defun Info-mouse-track-double-click-hook (event click-count)
2795 "Handle double-clicks by turning pages, like the `gv' ghostscript viewer"
2796 (if (/= click-count 2)
2797 ;; Return nil so any other hooks are performed.
2799 (let* ((fw (face-width 'default))
2800 (fh (face-height 'default))
2801 (x (/ (event-x-pixel event) fw))
2802 (y (/ (event-y-pixel event) fw))
2803 (w (/ (window-pixel-width (event-window event)) fw))
2804 (h (/ (window-pixel-height (event-window event)) fh))
2808 ((<= y by) (Info-up) t)
2809 ((>= y (- h by)) (Info-nth-menu-item 1) t)
2810 ((<= x bx) (Info-prev) t)
2811 ((>= x (- w bx)) (Info-next) t)
2814 (defvar Info-mode-map nil
2815 "Keymap containing Info commands.")
2819 (setq Info-mode-map (make-sparse-keymap))
2820 (suppress-keymap Info-mode-map)
2821 (define-key Info-mode-map "." 'beginning-of-buffer)
2822 (define-key Info-mode-map " " 'Info-scroll-next)
2823 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2824 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2825 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2826 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2827 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2828 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2829 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2830 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2831 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2832 (define-key Info-mode-map "0" 'Info-last-menu-item)
2833 (define-key Info-mode-map "?" 'Info-summary)
2834 (define-key Info-mode-map "a" 'Info-annotate)
2835 (define-key Info-mode-map "b" 'beginning-of-buffer)
2836 (define-key Info-mode-map "d" 'Info-directory)
2837 (define-key Info-mode-map "e" 'Info-edit)
2838 (define-key Info-mode-map "f" 'Info-follow-reference)
2839 (define-key Info-mode-map "g" 'Info-goto-node)
2840 (define-key Info-mode-map "h" 'Info-help)
2841 (define-key Info-mode-map "i" 'Info-index)
2842 (define-key Info-mode-map "j" 'Info-goto-bookmark)
2843 (define-key Info-mode-map "k" 'Info-emacs-key)
2844 (define-key Info-mode-map "l" 'Info-last)
2845 (define-key Info-mode-map "m" 'Info-menu)
2846 (define-key Info-mode-map "n" 'Info-next)
2847 (define-key Info-mode-map "p" 'Info-prev)
2848 (define-key Info-mode-map "q" 'Info-exit)
2849 (define-key Info-mode-map "r" 'Info-follow-reference)
2850 (define-key Info-mode-map "s" 'Info-search)
2851 (define-key Info-mode-map "t" 'Info-top)
2852 (define-key Info-mode-map "u" 'Info-up)
2853 (define-key Info-mode-map "v" 'Info-visit-file)
2854 (define-key Info-mode-map "x" 'Info-bookmark)
2855 (define-key Info-mode-map "<" 'Info-top)
2856 (define-key Info-mode-map ">" 'Info-end)
2857 (define-key Info-mode-map "[" 'Info-global-prev)
2858 (define-key Info-mode-map "]" 'Info-global-next)
2859 (define-key Info-mode-map "{" 'Info-page-prev)
2860 (define-key Info-mode-map "}" 'Info-page-next)
2861 (define-key Info-mode-map "=" 'Info-restore-point)
2862 (define-key Info-mode-map "!" 'Info-select-node)
2863 (define-key Info-mode-map "@" 'Info-follow-nearest-node)
2864 (define-key Info-mode-map "," 'Info-index-next)
2865 (define-key Info-mode-map "*" 'Info-elisp-ref)
2866 (define-key Info-mode-map [tab] 'Info-next-reference)
2867 (define-key Info-mode-map [(meta tab)] 'Info-prev-reference)
2868 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2869 (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
2871 (define-key Info-mode-map 'backspace 'Info-scroll-prev)
2872 (define-key Info-mode-map 'delete 'Info-scroll-prev)
2873 (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
2874 (define-key Info-mode-map 'button3 'Info-select-node-menu))
2877 ;; Info mode is suitable only for specially formatted data.
2878 (put 'info-mode 'mode-class 'special)
2881 "Info mode is for browsing through the Info documentation tree.
2882 Documentation in Info is divided into \"nodes\", each of which
2883 discusses one topic and contains references to other nodes
2884 which discuss related topics. Info has commands to follow
2885 the references and show you other nodes.
2887 h Invoke the Info tutorial.
2888 q Quit Info: return to the previously selected file or buffer.
2890 Selecting other nodes:
2891 n Move to the \"next\" node of this node.
2892 p Move to the \"previous\" node of this node.
2893 m Pick menu item specified by name (or abbreviation).
2894 1-9, 0 Pick first..ninth, last item in node's menu.
2895 Menu items select nodes that are \"subsections\" of this node.
2896 u Move \"up\" from this node (i.e., from a subsection to a section).
2897 f or r Follow a cross reference by name (or abbrev). Type `l' to get back.
2898 RET Follow cross reference or menu item indicated by cursor.
2899 i Look up a topic in this file's Index and move to that node.
2900 , (comma) Move to the next match from a previous `i' command.
2901 l (letter L) Move back to the last node you were in.
2903 Moving within a node:
2904 Space Scroll forward a full screen. DEL Scroll backward.
2905 b Go to beginning of node. Meta-> Go to end of node.
2906 TAB Go to next cross-reference. Meta-TAB Go to previous ref.
2909 Left Button Set point (usual text-mode functionality)
2910 Middle Button Click on a highlighted node reference to go to it.
2911 Right Button Pop up a menu of applicable Info commands.
2913 Left Button Double Click in window edges:
2914 Top edge: Go up to the parent node, like `u'.
2915 Left edge: Go to the previous node, like `p'.
2916 Right edge: Go to the next node, like `n'.
2917 Bottom edge: Follow first menu item, like `1'.
2920 g Move to node, file, or annotation tag specified by name.
2921 Examples: `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
2922 v Move to file, with filename completion.
2923 k Look up a key sequence in Emacs manual (also C-h C-k at any time).
2924 * Look up a function name in Emacs Lisp manual (also C-h C-f).
2925 d Go to the main directory of Info files.
2926 < or t Go to Top (first) node of this file.
2927 > Go to last node in this file.
2928 \[ Go to previous node, treating file as one linear document.
2929 \] Go to next node, treating file as one linear document.
2930 { Scroll backward, or go to previous node if at top.
2931 } Scroll forward, or go to next node if at bottom.
2932 = Restore cursor position from last time in this node.
2933 a Add a private note (annotation) to the current node.
2934 x, j Add, jump to a bookmark (annotation tag).
2935 s Search this Info file for a node containing the specified regexp.
2936 e Edit the contents of the current node."
2937 (kill-all-local-variables)
2938 (setq major-mode 'Info-mode)
2939 (setq mode-name "Info")
2940 (use-local-map Info-mode-map)
2941 (set-syntax-table text-mode-syntax-table)
2942 (setq local-abbrev-table text-mode-abbrev-table)
2943 (setq case-fold-search t)
2944 (setq buffer-read-only t)
2945 ; (setq buffer-mouse-map Info-mode-mouse-map)
2946 (make-local-variable 'Info-current-file)
2947 (make-local-variable 'Info-current-subfile)
2948 (make-local-variable 'Info-current-node)
2949 (make-local-variable 'Info-tag-table-marker)
2950 (setq Info-tag-table-marker (make-marker))
2951 (make-local-variable 'Info-tag-table-buffer)
2952 (setq Info-tag-table-buffer nil)
2953 (make-local-variable 'Info-current-file-completions)
2954 (make-local-variable 'Info-current-annotation-completions)
2955 (make-local-variable 'Info-index-alternatives)
2956 (make-local-variable 'Info-history)
2957 ;; Faces are now defined by `defface'...
2958 (make-local-variable 'mouse-track-click-hook)
2959 (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
2960 (add-hook 'mouse-track-click-hook 'Info-mouse-track-double-click-hook)
2961 ;; #### The console-on-window-system-p check is to allow this to
2962 ;; work on tty's. The real problem here is that featurep really
2963 ;; needs to have some device/console domain knowledge added to it.
2964 (defvar info::toolbar)
2965 (if (and (featurep 'toolbar)
2966 (console-on-window-system-p)
2967 (not Info-inhibit-toolbar))
2968 (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
2969 (if (featurep 'menubar)
2971 ;; make a local copy of the menubar, so our modes don't
2972 ;; change the global menubar
2973 (easy-menu-add '("Info" :filter Info-menu-filter))))
2974 (run-hooks 'Info-mode-hook)
2975 (Info-set-mode-line))
2977 (defvar Info-edit-map nil
2978 "Local keymap used within `e' command of Info.")
2982 ;; XEmacs: remove FSF stuff
2983 (setq Info-edit-map (make-sparse-keymap))
2984 (set-keymap-name Info-edit-map 'Info-edit-map)
2985 (set-keymap-parents Info-edit-map (list text-mode-map))
2986 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
2988 ;; Info-edit mode is suitable only for specially formatted data.
2989 (put 'info-edit-mode 'mode-class 'special)
2991 (defun Info-edit-mode ()
2992 "Major mode for editing the contents of an Info node.
2993 Like text mode with the addition of `Info-cease-edit'
2994 which returns to Info mode for browsing.
2999 "Edit the contents of this Info node.
3000 Allowed only if variable `Info-enable-edit' is non-nil."
3002 (or Info-enable-edit
3003 (error "Editing info nodes is not enabled"))
3004 (use-local-map Info-edit-map)
3005 (setq major-mode 'Info-edit-mode)
3006 (setq mode-name "Info Edit")
3007 (kill-local-variable 'modeline-buffer-identification)
3008 (setq buffer-read-only nil)
3009 ;; Make mode line update.
3010 (set-buffer-modified-p (buffer-modified-p))
3011 (message (substitute-command-keys
3012 "Editing: Type \\[Info-cease-edit] to return to info")))
3014 (defun Info-cease-edit ()
3015 "Finish editing Info node; switch back to Info proper."
3017 ;; Do this first, so nothing has changed if user C-g's at query.
3018 (and (buffer-modified-p)
3019 (y-or-n-p "Save the file? ")
3021 (use-local-map Info-mode-map)
3022 (setq major-mode 'Info-mode)
3023 (setq mode-name "Info")
3024 (Info-set-mode-line)
3025 (setq buffer-read-only t)
3026 ;; Make mode line update.
3027 (set-buffer-modified-p (buffer-modified-p))
3028 (and (marker-position Info-tag-table-marker)
3030 (message "Tags may have changed. Use Info-tagify if necessary")))
3032 (defun Info-find-emacs-command-nodes (command)
3033 "Return a list of locations documenting COMMAND in the XEmacs Info manual.
3034 The locations are of the format used in Info-history, i.e.
3035 \(FILENAME NODENAME BUFFERPOS\)."
3037 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
3038 ":\\s *\\(.*\\)\\.$")))
3040 (Info-find-node "XEmacs" "Command Index")
3041 ;; Take the index node off the Info history.
3042 ;; ??? says this isn't safe someplace else... hmmm.
3043 (setq Info-history (cdr Info-history))
3044 (goto-char (point-max))
3045 (while (re-search-backward cmd-desc nil t)
3046 (setq where (cons (list Info-current-file
3054 ;;; fontification and mousability for info
3056 (defun Info-highlight-region (start end face)
3058 (splitp (string-match "\n[ \t]+" (buffer-substring start end))))
3061 (setq extent (make-extent start (progn (goto-char start)
3064 (set-extent-face extent face)
3065 (set-extent-property extent 'info t)
3066 (set-extent-property extent 'highlight t)
3067 (skip-chars-forward "\n\t ")
3068 (setq extent (make-extent (point) end)))
3069 (setq extent (make-extent start end)))
3070 (set-extent-face extent face)
3071 (set-extent-property extent 'info t)
3072 (set-extent-property extent 'highlight t)))
3074 (defun Info-fontify-node ()
3076 (let ((case-fold-search t)
3077 (xref-regexp (concat "\\*"
3078 (regexp-quote Info-footnote-tag)
3079 "[ \n\t]*\\([^:]*\\):")))
3080 ;; Clear the old extents
3081 (map-extents #'(lambda (x y) (delete-extent x))
3082 (current-buffer) (point-min) (point-max) nil)
3083 ;; Break the top line iff it is > 79 characters. Some info nodes
3084 ;; have top lines that span 3 lines because of long node titles.
3085 ;; eg: (Info-find-node "lispref.info" "Window-Level Event Position Info")
3086 (toggle-read-only -1)
3091 (goto-char (point-min))
3092 (re-search-forward "Node: *[^,]+, " nil t)
3093 (setq len (- (point) (point-min))
3094 extent (make-extent (point-min) (point)))
3095 (set-extent-property extent 'invisible t)
3099 (if (< (current-column) (+ 78 len))
3102 (forward-char (+ 79 len))
3103 (re-search-backward "," nil t)
3107 (delete-backward-char 1)
3110 (toggle-read-only 1)
3111 ;; Highlight xrefs in the top few lines of the node
3112 (goto-char (point-min))
3113 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
3115 (goto-char (match-end 0))
3117 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?\n?")
3118 (goto-char (match-end 0))
3119 (Info-highlight-region (match-beginning 1) (match-end 1)
3121 ;; Now get the xrefs in the body
3122 (goto-char (point-min))
3123 (while (re-search-forward xref-regexp nil t)
3124 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
3126 (Info-highlight-region (match-beginning 1) (match-end 1)
3128 ;; then highlight the nodes in the menu.
3129 (goto-char (point-min))
3130 (if (and (search-forward "\n* menu:" nil t))
3131 (while (re-search-forward
3132 "^\\* \\([^:\t\n]*\\):?:[ \t\n]" nil t)
3133 (Info-highlight-region (match-beginning 1) (match-end 1)
3135 (set-buffer-modified-p nil))))
3137 (defun Info-construct-menu (&optional event)
3138 "Construct a menu of Info commands.
3139 Adds an entry for the node at EVENT, or under point if EVENT is omitted.
3140 Used to construct the menubar submenu and popup menu."
3141 (or event (setq event (point)))
3142 (let ((case-fold-search t)
3143 (xref-regexp (concat "\\*"
3144 (regexp-quote Info-footnote-tag)
3145 "[ \n\t]*\\([^:]*\\):"))
3146 up-p prev-p next-p menu xrefs subnodes in)
3148 ;; `one-space' fixes "Notes:" xrefs that are split across lines.
3152 (while (setq i (string-match "[ \n\t]+" text i))
3153 (setq text (concat (substring text 0 i) " "
3154 (substring text (match-end 0))))
3157 (goto-char (point-min))
3158 (if (looking-at ".*\\bNext:") (setq next-p t))
3159 (if (looking-at ".*\\bPrev:") (setq prev-p t))
3160 (if (looking-at ".*Up:") (setq up-p t))
3162 (if (setq in (Info-indicated-node event))
3163 (list (vector (one-space (cadr in)) in t)
3164 "--:shadowEtchedIn"))
3166 ["Goto Info Top-level" Info-directory]
3167 (vector "Next Node" 'Info-next :active next-p)
3168 (vector "Previous Node" 'Info-prev :active prev-p)
3169 (vector "Parent Node (Up)" 'Info-up :active up-p)
3170 ["Goto Node..." Info-goto-node]
3171 ["Goto Last Visited Node " Info-last])))
3172 ;; Find the xrefs and make a list
3173 (while (re-search-forward xref-regexp nil t)
3174 (setq xrefs (cons (one-space (buffer-substring (match-beginning 1)
3177 (setq xrefs (nreverse xrefs))
3178 (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
3179 ;; Find the subnodes and make a list
3180 (goto-char (point-min))
3181 (if (search-forward "\n* menu:" nil t)
3182 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
3183 (setq subnodes (cons (buffer-substring (match-beginning 1)
3186 (setq subnodes (nreverse subnodes))
3187 (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more))))
3189 (nconc menu (list "--:shadowDoubleEtchedIn"
3192 (mapcar #'(lambda (xref)
3196 (list 'Info-follow-reference xref))))
3199 (nconc menu (list "--:shadowDoubleEtchedIn"
3202 (mapcar #'(lambda (node)
3205 (vector node (list 'Info-menu node))))
3209 (defun Info-menu-filter (menu)
3210 "This is the menu filter for the \"Info\" submenu."
3211 (Info-construct-menu))
3213 (defun Info-select-node-menu (event)
3214 "Pops up a menu of applicable Info commands."
3216 (select-window (event-window event))
3217 (let ((menu (Info-construct-menu event)))
3218 (setq menu (nconc (list "Info" ; title: not displayed
3220 "--:shadowDoubleEtchedOut")
3222 (let ((popup-menu-titles nil))
3223 (popup-menu menu))))
3225 ;;; Info toolbar support
3227 ;; exit icon taken from GNUS
3228 (defvar info::toolbar-exit-icon
3229 (if (featurep 'toolbar)
3230 (toolbar-make-button-list
3231 (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
3232 toolbar-icon-directory)))
3235 (defvar info::toolbar-up-icon
3236 (if (featurep 'toolbar)
3237 (toolbar-make-button-list
3238 (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
3239 toolbar-icon-directory)))
3242 (defvar info::toolbar-next-icon
3243 (if (featurep 'toolbar)
3244 (toolbar-make-button-list
3245 (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
3246 toolbar-icon-directory)))
3249 (defvar info::toolbar-prev-icon
3250 (if (featurep 'toolbar)
3251 (toolbar-make-button-list
3252 (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
3253 toolbar-icon-directory)))
3256 (defvar info::toolbar
3257 (if (featurep 'toolbar)
3258 ; disabled until we get the next/prev-win icons working again.
3259 ; (cons (first initial-toolbar-spec)
3260 ; (cons (second initial-toolbar-spec)
3261 '([info::toolbar-exit-icon
3265 [info::toolbar-next-icon
3268 "Next entry in same section"]
3269 [info::toolbar-prev-icon
3272 "Prev entry in same section"]
3273 [info::toolbar-up-icon
3276 "Up entry to enclosing section"]
3282 (run-hooks 'Info-load-hook)
3284 ;;; info.el ends here