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-missing
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 (defvar Info-emacs-info-file-name "xemacs.info"
432 "The filename of the XEmacs info for
433 `Info-goto-emacs-command-node' (`\\<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 (defcustom Info-localdir-heading-regexp
451 "^Locally installed XEmacs Packages:?"
452 "The menu part of localdir files will be inserted below this topic
457 (defface info-node '((t (:bold t :italic t)))
458 "Face used for node links in info."
461 (defface info-xref '((t (:bold t)))
462 "Face used for cross-references in info."
465 ;; Is this right for NT? .zip, with -c for to stdout, right?
466 (defvar Info-suffix-list '( ("" . nil)
468 (".info.bz2" . "bzip2 -dc %s")
469 (".info.gz" . "gzip -dc %s")
470 (".info-z" . "gzip -dc %s")
471 (".info.Z" . "uncompress -c %s")
472 (".bz2" . "bzip2 -dc %s")
473 (".gz" . "gzip -dc %s")
474 (".Z" . "uncompress -c %s")
475 (".zip" . "unzip -c %s") )
476 "List of file name suffixes and associated decoding commands.
477 Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
478 changed to name of the file to decode, otherwise the file is given to
479 the command as standard input. If STRING is nil, no decoding is done.")
481 (defvar Info-footnote-tag "Note"
482 "*Symbol that identifies a footnote or cross-reference.
483 All \"*Note\" references will be changed to use this word instead.")
485 (defvar Info-current-file nil
486 "Info file that Info is now looking at, or nil.
487 This is the name that was specified in Info, not the actual file name.
488 It doesn't contain directory names or file name extensions added by Info.")
490 (defvar Info-current-subfile nil
491 "Info subfile that is actually in the *info* buffer now,
492 or nil if current info file is not split into subfiles.")
494 (defvar Info-current-node nil
495 "Name of node that Info is now looking at, or nil.")
497 (defvar Info-tag-table-marker (make-marker)
498 "Marker pointing at beginning of current Info file's tag table.
499 Marker points nowhere if file has no tag table.")
501 (defvar Info-current-file-completions nil
502 "Cached completion list for current Info file.")
504 (defvar Info-current-annotation-completions nil
505 "Cached completion list for current annotation files.")
507 (defvar Info-index-alternatives nil
508 "List of possible matches for last Info-index command.")
509 (defvar Info-index-first-alternative nil)
511 (defcustom Info-annotations-path
513 (paths-construct-path (list user-init-directory "info.notes"))
514 (paths-construct-path '("~" ".infonotes"))
515 (paths-construct-path '("usr" "lib" "info.notes")
516 (char-to-string directory-sep-char)))
517 "*Names of files that contain annotations for different Info nodes.
518 By convention, the first one should reside in your personal directory.
519 The last should be a world-writable \"public\" annotations file."
523 (defcustom Info-button1-follows-hyperlink nil
524 "*Non-nil means mouse button1 click will follow hyperlink."
528 (defvar Info-standalone nil
529 "Non-nil if Emacs was started solely as an Info browser.")
531 (defvar Info-in-cross-reference nil)
532 (defvar Info-window-configuration nil)
534 (defvar Info-dir-prologue "-*- Text -*-
535 This is the file .../info/dir, which contains the topmost node of the
536 Info hierarchy. The first time you invoke Info you start off
537 looking at that node, which is (dir)Top.
539 File: dir Node: Top This is the top of the INFO tree
540 This (the Directory node) gives a menu of major topics.
542 * Menu: The list of major topics begins on the next line.
546 (defvar Info-no-description-string "[No description available]"
547 "Description string for info files that have none")
550 (defun info (&optional file)
551 "Enter Info, the documentation browser.
552 Optional argument FILE specifies the file to examine;
553 the default is the top-level directory of Info.
555 In interactive use, a prefix argument directs this command
556 to read a file name from the minibuffer."
557 (interactive (if current-prefix-arg
558 (list (read-file-name "Info file name: " nil nil t))))
559 (let ((p command-line-args))
561 (and (string-match "^-[fe]" (car p))
562 (equal (nth 1 p) "info")
563 (not Info-standalone)
564 (setq Info-standalone t)
566 (not (string-match "^-" (nth 2 p)))
567 (setq file (nth 2 p))
568 (setq command-line-args-left nil))
570 ; (Info-setup-x) ??? What was this going to be? Can anyone tell karlheg?
573 (Info-goto-node (concat "(" file ")"))
574 (and Info-standalone (info)))
575 (if (get-buffer "*info*")
576 (switch-to-buffer "*info*")
580 (defun Info-query (file)
581 "Enter Info, the documentation browser. Prompt for name of Info file."
582 (interactive "sInfo topic (default = menu): ")
585 (Info-goto-node "(dir)")
586 (Info-goto-node (concat "(" file ")"))))
588 (defun Info-setup-initial ()
589 (let ((f Info-annotations-path))
591 (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
592 (bury-buffer (find-file-noselect (car f))))
596 (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
597 "Go to an info node specified as separate FILENAME and NODENAME.
598 Look for a plausible filename, or if not found then look for URL's and
599 dispatch to the appropriate fn. NO-GOING-BACK is non-nil if
600 recovering from an error in this function; it says do not attempt
601 further (recursive) error recovery. TRYFILE is ??"
606 ;; empty filename is simple case
608 (Info-find-file-node nil nodename no-going-back tryfile line))
609 ;; Convert filename to lower case if not found as specified.
610 ;; Expand it, look harder...
611 ((let (temp temp-downcase found
612 (fname (substitute-in-file-name filename)))
614 ((string-match "^\\./" fname) ; If specified name starts with `./'
615 (list default-directory)) ; then just try current directory.
616 ((file-name-absolute-p fname)
617 '(nil)) ; No point in searching for an absolute file name
618 (Info-additional-search-directory-list
619 (append Info-directory-list
620 Info-additional-search-directory-list))
621 (t Info-directory-list))))
622 ;; Search the directory list for file FNAME.
623 (while (and dirs (not found))
624 (setq temp (expand-file-name fname (car dirs)))
626 (expand-file-name (downcase fname) (car dirs)))
627 (if (equal temp-downcase temp) (setq temp-downcase nil))
628 ;; Try several variants of specified name.
629 ;; Try downcasing, appending a suffix, or both.
630 (setq found (Info-suffixed-file temp temp-downcase))
631 (setq dirs (cdr dirs)))
633 (progn (setq filename (expand-file-name found))
635 (Info-find-file-node filename nodename no-going-back tryfile line))
636 ;; Look for a URL. This pattern is stolen from w3.el to prevent
637 ;; loading it if we won't need it.
638 ((string-match (concat "^\\(wais\\|solo\\|x-exec\\|newspost\\|www\\|"
639 "mailto\\|news\\|tn3270\\|ftp\\|http\\|file\\|"
640 "telnet\\|gopher\\):")
642 (if (fboundp 'browse-url)
643 (browse-url filename)
644 (error "Cannot follow URLs in this XEmacs")))
646 (error "Info file %s does not exist" filename))))
648 (defun Info-find-file-node (filename nodename
649 &optional no-going-back tryfile line)
650 ;; This is the guts of what was Info-find-node. Whoever wrote this
651 ;; should be locked up where they can't do any more harm.
653 ;; Go into info buffer.
654 (switch-to-buffer "*info*")
655 (buffer-disable-undo (current-buffer))
656 (run-hooks 'Info-startup-hook)
657 (or (eq major-mode 'Info-mode)
660 (equal Info-current-file filename)
662 (string= "dir" (file-name-nondirectory Info-current-file))
663 (if (y-or-n-p-maybe-dialog-box
664 (format "Leave Info file `%s'? "
665 (file-name-nondirectory Info-current-file)))
668 ;; Record the node we are leaving.
669 (if (and Info-current-file (not no-going-back))
670 (Info-history-add Info-current-file Info-current-node (point)))
672 (setq Info-current-node nil
673 Info-in-cross-reference nil)
676 ;; Switch files if necessary
678 (equal Info-current-file filename)
679 (let ((buffer-read-only nil))
680 (setq Info-current-file nil
681 Info-current-subfile nil
682 Info-current-file-completions nil
683 Info-index-alternatives nil
684 buffer-file-name nil)
686 (if (string= "dir" (file-name-nondirectory filename))
688 (Info-insert-file-contents filename t)
689 (setq default-directory (file-name-directory filename)))
690 (set-buffer-modified-p nil)
691 ;; See whether file has a tag table. Record the location if yes.
692 (set-marker Info-tag-table-marker nil)
693 (goto-char (point-max))
695 (or (equal nodename "*")
696 (not (search-forward "\^_\nEnd tag table\n" nil t))
698 ;; We have a tag table. Find its beginning.
699 ;; Is this an indirect file?
700 (search-backward "\nTag table:\n")
704 (looking-at "(Indirect)\n"))
705 ;; It is indirect. Copy it to another buffer
706 ;; and record that the tag table is in that buffer.
708 (let ((buf (current-buffer)))
710 (get-buffer-create " *info tag table*"))
711 (buffer-disable-undo (current-buffer))
712 (setq case-fold-search t)
714 (insert-buffer-substring buf)
715 (set-marker Info-tag-table-marker
717 (set-marker Info-tag-table-marker pos))))
718 (setq Info-current-file
719 (file-name-sans-versions buffer-file-name))))
720 (if (equal nodename "*")
721 (progn (setq Info-current-node nodename)
723 (goto-char (point-min)))
724 ;; Search file for a suitable node.
725 (let* ((qnode (regexp-quote nodename))
726 (regexp (concat "Node: *" qnode " *[,\t\n\177]"))
727 (guesspos (point-min))
729 ;; First get advice from tag table if file has one.
730 ;; Also, if this is an indirect info file,
731 ;; read the proper subfile into this buffer.
732 (if (marker-position Info-tag-table-marker)
734 (set-buffer (marker-buffer Info-tag-table-marker))
735 (goto-char Info-tag-table-marker)
736 (if (re-search-forward regexp nil t)
738 (setq guesspos (read (current-buffer)))
739 ;; If this is an indirect file,
740 ;; determine which file really holds this node
742 (if (not (eq (current-buffer) (get-buffer "*info*")))
744 (Info-read-subfile guesspos)))))))
745 (goto-char (max (point-min) (- guesspos 1000)))
746 ;; Now search from our advised position (or from beg of buffer)
747 ;; to find the actual node.
749 (while (search-forward "\n\^_" nil t)
753 (if (re-search-backward regexp beg t)
756 (let ((bufs (delq nil (mapcar 'get-file-buffer
757 Info-annotations-path)))
758 (pattern (if (string-match "\\`<<.*>>\\'" qnode) qnode
759 (format "\"%s\"\\|<<%s>>" qnode qnode)))
760 (pat2 (concat "------ *File: *\\([^ ].*[^ ]\\) *Node: "
761 "*\\([^ ].*[^ ]\\) *Line: *\\([0-9]+\\)"))
762 (afile nil) anode aline)
763 (while (and bufs (not anode))
765 (set-buffer (car bufs))
766 (goto-char (point-min))
767 (if (re-search-forward pattern nil t)
768 (if (re-search-backward pat2 nil t)
769 (setq afile (buffer-substring (match-beginning 1)
771 anode (buffer-substring (match-beginning 2)
774 (buffer-substring (match-beginning 3)
776 (setq bufs (cdr bufs)))
778 (Info-find-node afile anode t nil aline)
781 (Info-find-node nodename "Top" t)
783 (or Info-current-node
784 (error "No such node: %s" nodename)))
788 (goto-char (point-min))
789 (if line (forward-line line)))))))
790 ;; If we did not finish finding the specified node,
791 ;; go back to the previous one.
792 (or Info-current-node no-going-back
793 (let ((hist (car Info-history)))
794 ;; The following is no longer safe with new Info-history system
795 ;; (setq Info-history (cdr Info-history))
796 (Info-goto-node (car hist) t)
797 (goto-char (+ (point-min) (nth 1 hist)))))))
799 ;; Cache the contents of the (virtual) dir file, once we have merged
800 ;; it for the first time, so we can save time subsequently.
801 (defvar Info-dir-contents nil)
803 ;; Cache for the directory we decided to use for the default-directory
804 ;; of the merged dir text.
805 (defvar Info-dir-contents-directory nil)
807 ;; Record the file attributes of all the files from which we
808 ;; constructed Info-dir-contents.
809 (defvar Info-dir-file-attributes nil)
811 (defun Info-insert-dir ()
812 "Construct the Info directory node by merging the files named
813 \"dir\" or \"localdir\" from the directories in `Info-directory-list'
814 The \"dir\" files will take precedence in cases where both exist. It
815 sets the *info* buffer's `default-directory' to the first directory we
816 actually get any text from."
817 (if (and Info-dir-contents Info-dir-file-attributes
818 ;; Verify that none of the files we used has changed
821 (mapcar #'(lambda (elt)
822 (let ((curr (file-attributes (car elt))))
823 ;; Don't compare the access time.
824 (if curr (setcar (nthcdr 4 curr) 0))
825 (setcar (nthcdr 4 (cdr elt)) 0)
826 (equal (cdr elt) curr)))
827 Info-dir-file-attributes))))
828 (insert Info-dir-contents)
829 (let ((dirs (reverse Info-directory-list))
830 buffers lbuffers buffer others nodes dirs-done)
832 (setq Info-dir-file-attributes nil)
834 ;; Search the directory list for the directory file.
836 (let ((truename (file-truename (expand-file-name (car dirs)))))
837 (or (member truename dirs-done)
838 (member (directory-file-name truename) dirs-done)
839 ;; Try several variants of specified name.
840 ;; Try upcasing, appending `.info', or both.
845 (progn (setq file (expand-file-name "dir" truename))
846 (file-attributes file))
847 (progn (setq file (expand-file-name "DIR" truename))
848 (file-attributes file))
849 (progn (setq file (expand-file-name "dir.info" truename))
850 (file-attributes file))
851 (progn (setq file (expand-file-name "DIR.INFO" truename))
852 (file-attributes file))
853 (progn (setq file (expand-file-name "localdir" truename))
854 (file-attributes file))
855 (progn (setq file (expand-file-name "dir" truename))
860 (cons (directory-file-name truename)
862 (Info-maybe-update-dir file)
863 (setq attrs (file-attributes file))
864 (if (or (setq buf (find-buffer-visiting file))
868 (message "Composing main Info directory..."))
871 (if (string-match "localdir" file)
875 (insert-file-contents file))
876 (if (string-match "localdir" (buffer-name))
877 (setq lbuffers (cons (current-buffer) lbuffers))
878 (setq buffers (cons (current-buffer) buffers)))
880 (setq Info-dir-file-attributes
881 (cons (cons file attrs)
882 Info-dir-file-attributes)))))))
883 (or (cdr dirs) (setq Info-dir-contents-directory (car dirs)))
884 (setq dirs (cdr dirs))))
886 ;; ensure that the localdir files are inserted last, and reverse
887 ;; the list of them so that when they get pushed in, they appear
888 ;; in the same order they got specified in the path, from top to
890 (nconc buffers (reverse lbuffers))
893 (error "Can't find the Info directory node"))
894 ;; Distinguish the dir file that comes with Emacs from all the
895 ;; others. Yes, that is really what this is supposed to do.
896 ;; If it doesn't work, fix it.
897 (setq buffer (car buffers)
898 ;; reverse it since they are pushed down from the top. the
899 ;; `Info-directory-list can be specified in natural order
901 others (reverse (cdr buffers)))
903 ;; Insert the entire original dir file as a start; note that we've
904 ;; already saved its default directory to use as the default
905 ;; directory for the whole concatenation.
906 (insert-buffer buffer)
908 ;; Look at each of the other buffers one by one.
910 (let ((other (car others))
911 (info-buffer (current-buffer)))
912 (if (string-match "localdir" (buffer-name other))
914 (set-buffer info-buffer)
915 (goto-char (point-max))
917 ((re-search-backward "^ *\\* *Locals *: *$" nil t)
918 (delete-region (match-beginning 0) (match-end 0)))
919 ;; look for a line like |Local XEmacs packages:
920 ;; or mismatch on some text ...
921 ((re-search-backward Info-localdir-heading-regexp nil t)
922 ;; This is for people who underline topic headings with
923 ;; equal signs or dashes.
924 (when (save-excursion
927 (looking-at "^[ \t]*[-=*]+"))
931 (t (search-backward "\^L" nil t)))
932 ;; Insert menu part of the file
934 (len (length (buffer-string nil nil other))))
935 (insert (buffer-string nil nil other))
936 (goto-char (+ pt len))
939 (if (search-forward "* Menu:" (+ pt len) t)
942 (delete-region pt (point)))))))
943 ;; In each, find all the menus.
946 (goto-char (point-min))
947 ;; Find each menu, and add an elt to NODES for it.
948 (while (re-search-forward "^\\* Menu:" nil t)
949 (let (beg nodename end)
952 (search-backward "\n\^_")
953 (search-forward "Node: ")
954 (setq nodename (Info-following-node-name))
955 (search-forward "\n\^_" nil 'move)
958 (setq nodes (cons (list nodename other beg end) nodes))))))
959 (setq others (cdr others))))
961 ;; Add to the main menu a menu item for each other node.
962 (re-search-forward "^\\* Menu:" nil t)
964 (let ((menu-items '("top"))
967 (end (save-excursion (search-forward "\^_" nil t) (point))))
969 (let ((nodename (car (car nodes))))
971 (or (member (downcase nodename) menu-items)
972 (re-search-forward (concat "^\\* "
973 (regexp-quote nodename)
977 (insert "* " nodename "::" "\n")
978 (setq menu-items (cons nodename menu-items))))))
979 (setq nodes (cdr nodes))))
980 ;; Now take each node of each of the other buffers
981 ;; and merge it into the main buffer.
983 (let ((nodename (car (car nodes))))
984 (goto-char (point-min))
985 ;; Find the like-named node in the main buffer.
986 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
987 (regexp-quote nodename)
991 (search-forward "\n\^_" nil 'move)
994 ;; If none exists, add one.
995 (goto-char (point-max))
996 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
997 ;; Merge the text from the other buffer's menu
998 ;; into the menu in the like-named node in the main buffer.
999 (apply 'insert-buffer-substring (cdr (car nodes))))
1000 (setq nodes (cdr nodes)))
1001 ;; Kill all the buffers we just made.
1003 (kill-buffer (car buffers))
1004 (setq buffers (cdr buffers)))
1006 (kill-buffer (car lbuffers))
1007 (setq lbuffers (cdr lbuffers)))
1008 (message "Composing main Info directory...done"))
1009 (setq Info-dir-contents (buffer-string)))
1010 (setq default-directory Info-dir-contents-directory)
1011 (setq buffer-file-name (caar Info-dir-file-attributes)))
1013 (defun Info-maybe-update-dir (file)
1014 "Rebuild dir or localdir according to `Info-auto-generate-directory'."
1015 (unless (or (not (file-exists-p (file-name-directory file)))
1016 (null (directory-files (file-name-directory file) nil "\\.info")))
1017 (if (not (find-buffer-visiting file))
1018 (if (not (file-exists-p file))
1019 (if (or (eq Info-auto-generate-directory 'always)
1020 (eq Info-auto-generate-directory 'if-missing))
1021 (Info-build-dir-anew (file-name-directory file)))
1022 (if (or (eq Info-auto-generate-directory 'always)
1023 (and (eq Info-auto-generate-directory 'if-outdated)
1024 (Info-dir-outdated-p file)))
1025 (Info-rebuild-dir file))))))
1027 ;; Record which *.info files are newer than the dir file
1028 (defvar Info-dir-newer-info-files nil)
1030 (defun Info-dir-outdated-p (file)
1031 "Return non-nil if dir or localdir is outdated.
1032 dir or localdir are outdated when an info file in the same
1033 directory has been modified more recently."
1034 (let ((dir-mod-time (nth 5 (file-attributes file)))
1037 (setq Info-dir-newer-info-files nil)
1041 (setq f-mod-time (nth 5 (file-attributes f)))
1042 (setq newer (or (> (car f-mod-time) (car dir-mod-time))
1043 (and (= (car f-mod-time) (car dir-mod-time))
1044 (> (car (cdr f-mod-time)) (car (cdr dir-mod-time))))))
1045 (if (and (file-readable-p f)
1047 (setq Info-dir-newer-info-files
1048 (cons f Info-dir-newer-info-files)))))
1049 (directory-files (file-name-directory file)
1051 ".*\\.info\\(\\.gz\\|\\.bz2\\|\\.Z\\|-z\\|\\.zip\\)?$"
1054 Info-dir-newer-info-files))
1056 (defun Info-extract-dir-entry-from (file)
1057 "Extract the dir entry from the info FILE.
1058 The dir entry is delimited by the markers `START-INFO-DIR-ENTRY'
1059 and `END-INFO-DIR-ENTRY'"
1061 (set-buffer (get-buffer-create " *Info-tmp*"))
1062 (when (file-readable-p file)
1063 (insert-file-contents file nil nil nil t)
1064 (goto-char (point-min))
1066 (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
1069 (unless (null (re-search-forward "^END-INFO-DIR-ENTRY" nil t))
1070 (goto-char (match-beginning 0))
1071 (car (Info-parse-dir-entries beg (point)))))))))
1073 ;; Parse dir entries contained between BEG and END into a list of the form
1074 ;; (filename topic node (description-line-1 description-line-2 ...))
1075 (defun Info-parse-dir-entries (beg end)
1076 (let (entry entries)
1079 (narrow-to-region beg end)
1081 (while (re-search-forward "^\\* \\([^:]+\\):\\([ \t]*(\\([^)]*\\))\\w*\\.\\|:\\)" nil t)
1082 (setq entry (list (match-string 2)
1084 (downcase (or (match-string 3)
1085 (match-string 1)))))
1092 (re-search-forward "[ \t]*" nil t)
1093 (or (and (re-search-forward "^[^ \t]" nil t)
1094 (goto-char (match-beginning 0)))
1096 "[ \t]*\n[ \t]*"))))
1098 (setq entries (cons (nreverse entry) entries)))))
1099 (nreverse entries)))
1101 (defun Info-dump-dir-entries (entries)
1105 (mapcar #'(lambda (e)
1106 (setq e (cdr e)) ; Drop filename
1107 (setq len (length (concat (car e)
1109 (if (> len description-col)
1110 (setq description-col len)))
1112 (setq description-col (+ 5 description-col))
1113 (mapcar #'(lambda (e)
1114 (setq e (cdr e)) ; Drop filename
1115 (insert "* " (car e) ":" (car (cdr e)))
1116 (setq e (car (cdr (cdr e))))
1118 (indent-to-column description-col)
1119 (insert (car e) "\n")
1125 (defun Info-build-dir-anew (directory)
1126 "Build info directory information for DIRECTORY.
1127 The generated directory listing may be saved to a `dir' according
1128 to the value of `Info-save-auto-generated-dir'"
1130 (let* ((dirfile (expand-file-name "dir" directory))
1131 (to-temp (or (null Info-save-auto-generated-dir)
1132 (eq Info-save-auto-generated-dir 'never)
1133 (and (not (file-writable-p dirfile))
1134 (message "File not writable %s. Using temporary." dirfile))))
1136 (directory-files directory
1138 ".*\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1142 (message "Creating temporary dir in %s..." directory)
1143 (message "Creating %s..." dirfile))
1144 (set-buffer (find-file-noselect dirfile t))
1145 (setq buffer-read-only nil)
1147 (insert Info-dir-prologue
1148 "Info files in " directory ":\n\n")
1149 (Info-dump-dir-entries
1152 (or (Info-extract-dir-entry-from f)
1155 (string-match "\\(.*\\)\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1156 (file-name-nondirectory f))
1157 (capitalize (match-string 1 (file-name-nondirectory f))))
1159 (list Info-no-description-string))))
1162 (set-buffer-modified-p nil)
1165 (message "Creating temporary dir in %s...done" directory)
1166 (message "Creating %s...done" dirfile)))))
1169 (defun Info-rebuild-dir (file)
1170 "Build info directory information in the directory of dir FILE.
1171 Description of info files are merged from the info files in the
1172 directory and the contents of FILE with the description in info files
1173 taking precedence over descriptions in FILE.
1174 The generated directory listing may be saved to a `dir' according to
1175 the value of `Info-save-auto-generated-dir' "
1178 (let (dir-section-contents dir-full-contents
1184 (or (null Info-save-auto-generated-dir)
1185 (eq Info-save-auto-generated-dir 'never)
1186 (and (eq Info-save-auto-generated-dir 'always)
1187 (not (file-writable-p file))
1188 (message "File not writable %s. Using temporary." file))
1189 (and (eq Info-save-auto-generated-dir 'conservative)
1190 (or (and (not (file-writable-p file))
1191 (message "File not writable %s. Using temporary." file))
1193 (message "%s is outdated. Overwrite ? "
1195 (set-buffer (find-file-noselect file t))
1196 (setq buffer-read-only nil)
1198 (message "Rebuilding temporary %s..." file)
1199 (message "Rebuilding %s..." file))
1201 (setq buffer-read-only nil)
1202 (goto-char (point-min))
1203 (unless (and (search-forward "\^_")
1204 (re-search-forward "^\\* Menu:.*$" nil t)
1205 (setq mark (and (re-search-forward "^\\* " nil t)
1206 (match-beginning 0))))
1208 (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1209 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$" nil t)
1210 (match-beginning 0))
1213 (narrow-to-region mark next-section)
1214 (setq dir-section-contents (nreverse (Info-parse-dir-entries (point-min)
1218 (setq dir-entry (assoc (downcase
1219 (file-name-sans-extension
1220 (file-name-nondirectory file)))
1221 dir-section-contents)
1222 file-dir-entry (Info-extract-dir-entry-from file))
1225 ;; A dir entry in the info file takes precedence over an
1226 ;; existing entry in the dir file
1227 (setcdr dir-entry (cdr file-dir-entry)))
1228 (unless (or not-first-section
1230 (file-name-sans-extension
1231 (file-name-nondirectory file)))
1234 (setq dir-section-contents (cons file-dir-entry
1235 dir-section-contents))
1236 (setq dir-section-contents
1238 (capitalize (file-name-sans-extension
1239 (file-name-nondirectory file)))
1241 (list Info-no-description-string))
1242 dir-section-contents))))))
1243 Info-dir-newer-info-files)
1244 (delete-region (point-min) (point-max))
1245 (Info-dump-dir-entries (nreverse dir-section-contents))
1247 (if (= next-section (point-max))
1248 (setq next-section nil)
1249 (or (setq mark (and (re-search-forward "^\\* " nil t)
1250 (match-beginning 0)))
1252 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$" nil t)
1253 (match-beginning 0))
1255 (setq not-first-section t)))
1258 (set-buffer-modified-p nil)
1259 (message "Rebuilding temporary %s...done" file))
1261 (message "Rebuilding %s...done" file))))))
1264 (defun Info-batch-rebuild-dir ()
1265 "(Re)build info `dir' files in the directories remaining on the command line.
1266 Use this from the command line, with `-batch';
1267 it won't work in an interactive Emacs.
1268 Each file is processed even if an error occurred previously.
1269 For example, invoke \"xemacs -batch -f Info-batch-rebuild-dir /usr/local/info\""
1270 ;; command-line-args-left is what is left of the command line (from
1272 (defvar command-line-args-left) ; Avoid 'free variable' warning
1273 (if (not noninteractive)
1274 (error "`Info-batch-rebuild-dir' is to be used only with -batch"))
1275 (let ((Info-save-auto-generated-dir 'always)
1277 (while command-line-args-left
1278 (if (not (file-directory-p (car command-line-args-left)))
1279 (message "Warning: Skipped %s. Not a directory."
1280 (car command-line-args-left))
1281 (setq dir (expand-file-name "dir" (car command-line-args-left)))
1282 (setq localdir (expand-file-name "localdir" (car command-line-args-left)))
1284 ((file-exists-p dir)
1285 (Info-rebuild-dir dir))
1286 ((file-exists-p localdir)
1287 (Info-rebuild-dir localdir))
1289 (Info-build-dir-anew (car command-line-args-left)))))
1290 (setq command-line-args-left (cdr command-line-args-left)))
1294 (defun Info-history-add (file node point)
1295 (if Info-keeping-history
1296 (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
1297 (found (assoc name Info-history)))
1299 (setq Info-history (delq found Info-history)))
1300 (setq Info-history (cons (list name (- point (point-min))
1301 (and (eq (window-buffer)
1303 (- (window-start) (point-min))))
1306 (defun Info-file-name-only (file)
1307 (let ((dir (file-name-directory file))
1308 (p Info-directory-list))
1309 (while (and p (not (equal (car p) dir)))
1311 (if p (file-name-nondirectory file) file)))
1313 (defun Info-read-subfile (nodepos)
1314 (set-buffer (marker-buffer Info-tag-table-marker))
1315 (goto-char (point-min))
1316 (search-forward "\n\^_")
1321 (while (not (looking-at "\^_"))
1324 thisfilepos thisfilename)
1325 (search-forward ": ")
1326 (setq thisfilename (buffer-substring beg (- (point) 2)))
1327 (setq thisfilepos (read (current-buffer)))
1328 ;; read in version 19 stops at the end of number.
1329 ;; Advance to the next line.
1332 (if (> thisfilepos nodepos)
1334 (setq lastfilename thisfilename)
1335 (setq lastfilepos thisfilepos))
1337 (set-buffer (get-buffer "*info*"))
1338 (or (equal Info-current-subfile lastfilename)
1339 (let ((buffer-read-only nil))
1340 (setq buffer-file-name nil)
1343 (Info-insert-file-contents (Info-suffixed-file
1344 (expand-file-name lastfilename
1345 (file-name-directory
1346 Info-current-file)))
1348 (set-buffer-modified-p nil)
1349 (setq Info-current-subfile lastfilename)))
1350 (goto-char (point-min))
1351 (search-forward "\n\^_")
1352 (+ (- nodepos lastfilepos) (point))))
1354 (defun Info-suffixed-file (name &optional name2)
1355 "Look for NAME with each of the `Info-suffix-list' extensions in
1356 turn. Optional NAME2 is the name of a fallback info file to check
1357 for; usually a downcased version of NAME."
1358 (let ((suff Info-suffix-list)
1361 (while (and suff (not found))
1362 (setq file (concat name (caar suff))
1363 file2 (and name2 (concat name2 (caar suff))))
1365 ((file-regular-p file)
1367 ((and file2 (file-regular-p file2))
1370 (setq suff (cdr suff)))))
1372 (and name (when (file-regular-p name)
1374 (and name2 (when (file-regular-p name2)
1377 (defun Info-insert-file-contents (file &optional visit)
1378 (setq file (expand-file-name file default-directory))
1379 (let ((suff Info-suffix-list))
1380 (while (and suff (or (<= (length file) (length (car (car suff))))
1381 (not (equal (substring file
1382 (- (length (car (car suff)))))
1383 (car (car suff))))))
1384 (setq suff (cdr suff)))
1385 (if (stringp (cdr (car suff)))
1386 (let ((command (if (string-match "%s" (cdr (car suff)))
1387 (format (cdr (car suff)) file)
1388 (concat (cdr (car suff)) " < " file))))
1389 (message "%s..." command)
1390 (call-process shell-file-name nil t nil "-c" command)
1393 (setq buffer-file-name file)
1394 (set-buffer-modified-p nil)
1395 (clear-visited-file-modtime)))
1396 (insert-file-contents file visit))))
1398 (defun Info-select-node ()
1399 "Select the node that point is in, after using `g *' to select whole file."
1403 ;; Find beginning of node.
1404 (search-backward "\n\^_")
1406 ;; Get nodename spelled as it is in the node.
1407 (re-search-forward "Node:[ \t]*")
1408 (setq Info-current-node
1409 (buffer-substring (point)
1411 (skip-chars-forward "^,\t\n")
1413 (Info-set-mode-line)
1414 ;; Find the end of it, and narrow.
1416 (let (active-expression)
1417 (narrow-to-region (point)
1418 (if (re-search-forward "\n[\^_\f]" nil t)
1421 (if (looking-at "[\n\^_\f]*execute: ")
1423 (goto-char (match-end 0))
1424 (setq active-expression
1425 (read (current-buffer))))))
1427 (or (equal Info-footnote-tag "Note")
1429 (goto-char (point-min))
1430 (let ((buffer-read-only nil)
1431 (bufmod (buffer-modified-p))
1432 (case-fold-search t))
1433 (while (re-search-forward "\\*[Nn]ote\\([ \n]\\)" nil t)
1434 (replace-match (concat "*" Info-footnote-tag "\ ")))
1435 (set-buffer-modified-p bufmod))))
1436 (Info-reannotate-node)
1437 ;; XEmacs: remove v19 test
1439 (Info-fontify-node))
1440 (run-hooks 'Info-select-hook)
1441 (if Info-enable-active-nodes (eval active-expression)))))
1443 (defun Info-set-mode-line ()
1444 (setq modeline-buffer-identification
1445 (list (cons modeline-buffer-id-left-extent "Info: ")
1446 (cons modeline-buffer-id-right-extent
1449 (if Info-current-file
1450 (let ((name (file-name-nondirectory Info-current-file)))
1451 (if (string-match "\\.info$" name)
1452 (substring name 0 -5)
1456 (or Info-current-node ""))))))
1458 ;; Go to an info node specified with a filename-and-nodename string
1459 ;; of the sort that is found in pointers in nodes.
1462 (defun Info-goto-node (nodename &optional no-going-back tryfile)
1463 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
1464 Actually, the following interpretations of NAME are tried in order:
1466 (FILENAME) (using Top node)
1467 NODENAME (in current file)
1469 FILENAME (using Top node)
1470 where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
1471 annotation for any node of any file. (See `a' and `x' commands.)"
1472 (interactive (list (Info-read-node-name "Goto node, file or tag: ")
1475 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1477 (setq filename (if (= (match-beginning 1) (match-end 1))
1479 (substring nodename (match-beginning 2) (match-end 2)))
1480 nodename (substring nodename (match-beginning 3) (match-end 3)))
1481 (let ((trim (string-match "\\s *\\'" filename)))
1482 (if trim (setq filename (substring filename 0 trim))))
1483 (let ((trim (string-match "\\s *\\'" nodename)))
1484 (if trim (setq nodename (substring nodename 0 trim))))
1485 (Info-find-node (if (equal filename "") nil filename)
1486 (if (equal nodename "") "Top" nodename)
1487 no-going-back (and tryfile (equal filename "")))))
1489 (defun Info-goto-bookmark ()
1491 (let ((completion-ignore-case nil)
1492 (tag (completing-read "Goto tag: "
1493 (Info-build-annotation-completions)
1495 'Info-minibuffer-history)))
1496 (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
1499 (defun Info-visit-file (file)
1500 "Directly visit an info file."
1501 (interactive "fVisit Info file: ")
1502 (Info-find-node (expand-file-name file) "Top"))
1504 (defun Info-restore-point (&optional always)
1505 "Restore point to same location it had last time we were in this node."
1507 (if (or Info-restoring-point always)
1508 (let* ((name (format "(%s)%s"
1509 (Info-file-name-only Info-current-file)
1511 (p (assoc name Info-history)))
1512 (if p (Info-restore-history-entry p)))))
1514 (defun Info-restore-history-entry (entry)
1515 (goto-char (+ (nth 1 entry) (point-min)))
1517 (get-buffer-window (current-buffer))
1518 (set-window-start (get-buffer-window (current-buffer))
1519 (+ (nth 2 entry) (point-min)))))
1521 (defvar Info-read-node-completion-table)
1523 ;; This function is used as the "completion table" while reading a node name.
1524 ;; It does completion using the alist in Info-read-node-completion-table
1525 ;; unless STRING starts with an open-paren.
1526 (defun Info-read-node-name-1 (string predicate code)
1527 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
1528 (cond ((eq code nil)
1531 (try-completion string Info-read-node-completion-table predicate)))
1535 (all-completions string Info-read-node-completion-table predicate)))
1539 (assoc string Info-read-node-completion-table))))))
1541 (defun Info-read-node-name (prompt &optional default)
1542 (Info-setup-initial)
1543 (let* ((completion-ignore-case t)
1544 (Info-read-node-completion-table (Info-build-node-completions))
1545 (nodename (completing-read prompt 'Info-read-node-name-1
1546 nil t nil 'Info-minibuffer-history
1548 (if (equal nodename "")
1550 (Info-read-node-name prompt))
1553 (defun Info-build-annotation-completions ()
1554 (or Info-current-annotation-completions
1556 (let ((bufs (delq nil (mapcar 'get-file-buffer
1557 Info-annotations-path)))
1560 (set-buffer (car bufs))
1561 (goto-char (point-min))
1562 (while (re-search-forward "<<\\(.*\\)>>" nil t)
1563 (setq compl (cons (list (buffer-substring (match-beginning 1)
1566 (setq bufs (cdr bufs)))
1567 (setq Info-current-annotation-completions compl)))))
1569 (defun Info-build-node-completions ()
1570 (or Info-current-file-completions
1571 (let ((compl (Info-build-annotation-completions)))
1575 (if (marker-buffer Info-tag-table-marker)
1577 (set-buffer (marker-buffer Info-tag-table-marker))
1578 (goto-char Info-tag-table-marker)
1579 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
1581 (cons (list (buffer-substring (match-beginning 1)
1584 (goto-char (point-min))
1585 (while (search-forward "\n\^_" nil t)
1587 (let ((beg (point)))
1589 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
1592 (cons (list (buffer-substring (match-beginning 1)
1595 (setq Info-current-file-completions compl))))
1597 (defvar Info-last-search nil
1598 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1602 (defun Info-search (regexp)
1603 "Search for REGEXP, starting from point, and select node it's found in."
1605 (read-from-minibuffer
1606 (if Info-last-search
1607 (format "Search (regexp, default %s): "
1609 "Search (regexp): ")
1610 nil nil nil nil nil Info-last-search)))
1611 (setq Info-last-search regexp)
1612 (with-search-caps-disable-folding regexp t
1614 (onode Info-current-node)
1615 (ofile Info-current-file)
1617 (osubfile Info-current-subfile))
1621 (if (null Info-current-subfile)
1622 (progn (re-search-forward regexp) (setq found (point)))
1624 (progn (re-search-forward regexp) (setq found (point)))
1625 (search-failed nil)))))
1626 (if (not found) ;can only happen in subfile case -- else would have erred
1629 (set-buffer (marker-buffer Info-tag-table-marker))
1630 (goto-char (point-min))
1631 (search-forward "\n\^_\nIndirect:")
1633 (narrow-to-region (point)
1634 (progn (search-forward "\n\^_")
1636 (goto-char (point-min))
1637 (search-forward (concat "\n" osubfile ": "))
1640 (re-search-forward "\\(^.*\\): [0-9]+$")
1641 (goto-char (+ (match-end 1) 2))
1642 (setq list (cons (cons (read (current-buffer))
1643 (buffer-substring (match-beginning 1)
1646 (goto-char (1+ (match-end 0))))
1647 (setq list (nreverse list)
1650 (message "Searching subfile %s..." (cdr (car list)))
1651 (Info-read-subfile (car (car list)))
1652 (setq list (cdr list))
1653 (goto-char (point-min))
1654 (if (re-search-forward regexp nil t)
1655 (setq found (point) list ())))
1658 (signal 'search-failed (list regexp))))
1660 (progn (Info-read-subfile opoint)
1662 (Info-select-node)))))
1666 (or (and (equal onode Info-current-node)
1667 (equal ofile Info-current-file))
1668 (Info-history-add ofile onode opoint)))))
1670 ;; Extract the value of the node-pointer named NAME.
1671 ;; If there is none, use ERRORNAME in the error message;
1672 ;; if ERRORNAME is nil, just return nil.
1673 (defun Info-extract-pointer (name &optional errorname)
1675 (goto-char (point-min))
1677 (let ((case-fold-search t))
1678 (if (re-search-backward (concat name ":") nil t)
1680 (goto-char (match-end 0))
1681 (Info-following-node-name))
1682 (if (eq errorname t)
1684 (error (concat "Node has no " (capitalize (or errorname name)))))))))
1686 ;; Return the node name in the buffer following point.
1687 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1688 ;; saying which chars may appear in the node name.
1689 (defun Info-following-node-name (&optional allowedchars)
1690 (skip-chars-forward " \t")
1694 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1695 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1696 (if (looking-at "(")
1697 (skip-chars-forward "^)")))
1698 (skip-chars-backward " .")
1701 (defun Info-next (&optional n)
1702 "Go to the next node of this node.
1703 A positive or negative prefix argument moves by multiple nodes."
1708 (while (>= (setq n (1- n)) 0)
1709 (Info-goto-node (Info-extract-pointer "next")))))
1711 (defun Info-prev (&optional n)
1712 "Go to the previous node of this node.
1713 A positive or negative prefix argument moves by multiple nodes."
1718 (while (>= (setq n (1- n)) 0)
1719 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
1721 (defun Info-up (&optional n)
1722 "Go to the superior node of this node.
1723 A positive prefix argument moves up several times."
1726 (while (>= (setq n (1- n)) 0)
1727 (Info-goto-node (Info-extract-pointer "up")))
1728 (if (interactive-p) (Info-restore-point)))
1730 (defun Info-last (&optional n)
1731 "Go back to the last node visited.
1732 With a prefix argument, go to Nth most recently visited node. History is
1733 circular; after oldest node, history comes back around to most recent one.
1734 Argument can be negative to go through the circle in the other direction.
1735 \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
1739 (error "This is the first Info node you looked at"))
1740 (let ((len (1+ (length Info-history))))
1741 (setq n (% (+ n (* len 100)) len)))
1743 (let ((entry (nth (1- n) Info-history)))
1744 (Info-history-add Info-current-file Info-current-node (point))
1745 (while (>= (setq n (1- n)) 0)
1746 (setq Info-history (nconc (cdr Info-history)
1747 (list (car Info-history)))))
1748 (setq Info-history (cdr Info-history))
1749 (let ((Info-keeping-history nil))
1750 (Info-goto-node (car entry)))
1751 (Info-restore-history-entry entry))))
1753 (defun Info-directory ()
1754 "Go to the Info directory node."
1756 (Info-find-node "dir" "top"))
1758 (defun Info-follow-reference (footnotename)
1759 "Follow cross reference named NAME to the node it refers to.
1760 NAME may be an abbreviation of the reference name."
1762 (let ((completion-ignore-case t)
1763 completions default (start-point (point)) str i)
1765 (goto-char (point-min))
1766 (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
1769 (setq str (buffer-substring
1772 ;; See if this one should be the default.
1774 (< (match-beginning 0) start-point)
1775 (<= start-point (point))
1778 (while (setq i (string-match "[ \n\t]+" str i))
1779 (setq str (concat (substring str 0 i) " "
1780 (substring str (match-end 0))))
1782 ;; Record as a completion and perhaps as default.
1783 (if (eq default t) (setq default str))
1785 (cons (cons str nil)
1788 (let ((item (completing-read (if default
1789 (concat "Follow reference named: ("
1791 "Follow reference named: ")
1792 completions nil t nil
1793 'Info-minibuffer-history
1795 (if (and (string= item "") default)
1798 (error "No cross-references in this node"))))
1799 (let (target i (str (concat "\\*" Info-footnote-tag " "
1800 (regexp-quote footnotename))))
1801 (while (setq i (string-match " " str i))
1802 (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
1803 (substring str (1+ i))))
1806 (goto-char (point-min))
1807 (or (re-search-forward str nil t)
1808 (error "No cross-reference named %s" footnotename))
1809 (goto-char (match-end 1))
1811 (Info-extract-menu-node-name "Bad format cross reference" t)))
1812 (while (setq i (string-match "[ \t\n]+" target i))
1813 (setq target (concat (substring target 0 i) " "
1814 (substring target (match-end 0))))
1816 (Info-goto-node target)
1817 (setq Info-in-cross-reference t)))
1819 (defun Info-next-reference (n)
1821 (let ((pat (format "\\*%s[ \n\t]*\\([^:]*\\):\\|^\\* .*:\\|<<.*>>"
1824 wrapped found-nomenu)
1826 (unless (re-search-backward pat nil t)
1827 ;; Don't wrap more than once in a buffer where only the
1828 ;; menu references are found.
1829 (when (and wrapped (not found-nomenu))
1831 (error "No cross references in this node"))
1833 (goto-char (point-max))
1834 (unless (re-search-backward pat nil t)
1836 (error "No cross references in this node")))
1837 (unless (save-excursion
1838 (goto-char (match-beginning 0))
1839 (when (looking-at "\\* Menu:")
1841 (setq found-nomenu t))
1844 (or (eobp) (forward-char 1))
1845 (unless (re-search-forward pat nil t)
1846 (when (and wrapped (not found-nomenu))
1848 (error "No cross references in this node"))
1850 (goto-char (point-min))
1851 (unless (re-search-forward pat nil t)
1853 (error "No cross references in this node")))
1854 (unless (save-excursion
1855 (goto-char (match-beginning 0))
1856 (when (looking-at "\\* Menu:")
1858 (setq found-nomenu t))
1860 (when (looking-at "\\* Menu:")
1861 (error "No cross references in this node"))
1862 (goto-char (match-beginning 0))))
1864 (defun Info-prev-reference (n)
1866 (Info-next-reference (- n)))
1868 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1869 (skip-chars-forward " \t\n")
1872 (skip-chars-forward "^:")
1875 (if (looking-at ":")
1876 (buffer-substring beg (1- (point)))
1877 (skip-chars-forward " \t\n")
1879 ;; Allow dots in node name not followed by whitespace.
1881 (concat "\\(([^)]+)[^."
1882 (if multi-line "" "\n")
1884 (if multi-line "" "\n")
1885 ;; We consider dots followed by newline as
1886 ;; end of nodename even if multil-line.
1887 ;; Also stops at .). It is generated by @pxref.
1888 ;; Skips sequential dots.
1889 "]\\|\\.+[^ \t\n)]\\)+\\)"))
1891 (while (setq i (string-match "\n" str i))
1895 (defun Info-menu (menu-item)
1896 "Go to node for menu item named (or abbreviated) NAME.
1897 Completion is allowed, and the menu item point is on is the default."
1899 (let ((completions '())
1900 ;; If point is within a menu item, use that item as the default
1905 (goto-char (point-min))
1906 (let ((case-fold-search t))
1907 (if (not (search-forward "\n* menu:" nil t))
1908 (error "No menu in this node")))
1909 (while (re-search-forward
1910 "\n\\* \\([^:\t\n]*\\):" nil t)
1911 (if (and (null default)
1912 (prog1 (if last (< last p) nil)
1913 (setq last (match-beginning 0)))
1915 (setq default (car (car completions))))
1916 (setq completions (cons (cons (buffer-substring
1919 (match-beginning 1))
1921 (if (and (null default) last
1923 (<= p (progn (end-of-line) (point))))
1924 (setq default (car (car completions)))))
1927 (setq item (let ((completion-ignore-case t))
1928 (completing-read (if default
1929 (format "Menu item (default %s): "
1932 completions nil t nil
1933 'Info-minibuffer-history
1935 ;; we rely on the fact that completing-read accepts an input
1936 ;; of "" even when the require-match argument is true and ""
1937 ;; is not a valid possibility
1938 (if (string= item "")
1944 ;; there is a problem here in that if several menu items have the same
1945 ;; name you can only go to the node of the first with this command.
1946 (Info-goto-node (Info-extract-menu-item menu-item) nil t))
1948 (defun Info-extract-menu-item (menu-item &optional noerror)
1950 (goto-char (point-min))
1951 (if (let ((case-fold-search t))
1952 (search-forward "\n* menu:" nil t))
1953 (if (or (search-forward (concat "\n* " menu-item ":") nil t)
1954 (search-forward (concat "\n* " menu-item) nil t))
1958 (Info-extract-menu-node-name))
1959 (and (not noerror) (error "No such item in menu")))
1960 (and (not noerror) (error "No menu in this node")))))
1962 ;; If COUNT is nil, use the last item in the menu.
1963 (defun Info-extract-menu-counting (count &optional noerror noindex)
1965 (goto-char (point-min))
1966 (if (let ((case-fold-search t))
1967 (and (search-forward "\n* menu:" nil t)
1969 (not (string-match "\\<Index\\>" Info-current-node)))))
1970 (if (search-forward "\n* " nil t count)
1973 (while (search-forward "\n* " nil t)))
1974 (Info-extract-menu-node-name))
1975 (and (not noerror) (error "Too few items in menu")))
1976 (and (not noerror) (error "No menu in this node")))))
1978 (defun Info-nth-menu-item (n)
1979 "Go to the node of the Nth menu item."
1981 (or n (setq n (- last-command-char ?0)))
1982 (if (< n 1) (error "Index must be at least 1"))
1983 (Info-goto-node (Info-extract-menu-counting n) nil t))
1985 (defun Info-last-menu-item ()
1986 "Go to the node of the tenth menu item."
1988 (Info-goto-node (Info-extract-menu-counting nil) nil t))
1991 "Go to the Top node of this file."
1993 (Info-goto-node "Top"))
1996 "Go to the final node in this file."
1999 (let ((Info-keeping-history nil)
2001 (Info-last-menu-item)
2002 (while (setq node (or (Info-extract-pointer "next" t)
2003 (Info-extract-menu-counting nil t t)))
2004 (Info-goto-node node))
2005 (or (equal (Info-extract-pointer "up" t) "Top")
2006 (let ((executing-kbd-macro "")) ; suppress messages
2008 (Info-global-next 10000)
2011 (defun Info-global-next (&optional n)
2012 "Go to the next node in this file, traversing node structure as necessary.
2013 This works only if the Info file is structured as a hierarchy of nodes.
2014 A positive or negative prefix argument moves by multiple nodes."
2018 (Info-global-prev (- n))
2019 (while (>= (setq n (1- n)) 0)
2021 (cond ((and (string-match "^Top$" Info-current-node)
2022 (setq node (Info-extract-pointer "next" t))
2023 (Info-extract-menu-item node t))
2024 (Info-goto-node node))
2025 ((setq node (Info-extract-menu-counting 1 t t))
2026 (message "Going down...")
2027 (Info-goto-node node))
2029 (let ((Info-keeping-history Info-keeping-history)
2030 (orignode Info-current-node)
2032 (while (not (Info-extract-pointer "next" t))
2033 (if (and (setq node (Info-extract-pointer "up" t))
2034 (not (equal node "Top")))
2036 (message "Going%s..." (setq ups (concat ups " up")))
2037 (Info-goto-node node)
2038 (setq Info-keeping-history nil))
2040 (let ((Info-keeping-history nil))
2041 (Info-goto-node orignode)))
2042 (error "Last node in file")))
2045 (defun Info-page-next (&optional n)
2046 "Scroll forward one screenful, or go to next global node.
2047 A positive or negative prefix argument moves by multiple screenfuls."
2051 (Info-page-prev (- n))
2052 (while (>= (setq n (1- n)) 0)
2053 (if (pos-visible-in-window-p (point-max))
2056 (message "Node: %s" Info-current-node))
2059 (defun Info-scroll-next (arg)
2061 (if Info-auto-advance
2062 (if (and (pos-visible-in-window-p (point-max))
2063 (not (eq Info-auto-advance t))
2064 (not (eq last-command this-command)))
2065 (message "Hit %s again to go to next node"
2066 (if (= last-command-char 0)
2068 (key-description (char-to-string last-command-char))))
2070 (setq this-command 'Info))
2073 (defun Info-global-prev (&optional n)
2074 "Go to the previous node in this file, traversing structure as necessary.
2075 This works only if the Info file is structured as a hierarchy of nodes.
2076 A positive or negative prefix argument moves by multiple nodes."
2080 (Info-global-next (- n))
2081 (while (>= (setq n (1- n)) 0)
2082 (let ((upnode (Info-extract-pointer "up" t))
2083 (prevnode (Info-extract-pointer "prev[ious]*" t)))
2084 (if (or (not prevnode)
2085 (equal prevnode upnode))
2086 (if (string-match "^Top$" Info-current-node)
2087 (error "First node in file")
2088 (message "Going up...")
2090 (Info-goto-node prevnode)
2092 (Info-keeping-history nil)
2094 (while (setq node (Info-extract-menu-counting nil t t))
2095 (message "Going%s..." (setq downs (concat downs " down")))
2096 (Info-goto-node node))))))))
2098 (defun Info-page-prev (&optional n)
2099 "Scroll backward one screenful, or go to previous global node.
2100 A positive or negative prefix argument moves by multiple screenfuls."
2104 (Info-page-next (- n))
2105 (while (>= (setq n (1- n)) 0)
2106 (if (pos-visible-in-window-p (point-min))
2109 (message "Node: %s" Info-current-node)
2110 (goto-char (point-max))
2112 (move-to-window-line 0))
2115 (defun Info-scroll-prev (arg)
2117 (if Info-auto-advance
2118 (if (and (pos-visible-in-window-p (point-min))
2119 (not (eq Info-auto-advance t))
2120 (not (eq last-command this-command)))
2121 (message "Hit %s again to go to previous node"
2122 (if (mouse-event-p last-command-event)
2124 (key-description (event-key last-command-event))))
2126 (setq this-command 'Info))
2129 (defun Info-index (topic)
2130 "Look up a string in the index for this file.
2131 The index is defined as the first node in the top-level menu whose
2132 name contains the word \"Index\", plus any immediately following
2133 nodes whose names also contain the word \"Index\".
2134 If there are no exact matches to the specified topic, this chooses
2135 the first match which is a case-insensitive substring of a topic.
2136 Use the `,' command to see the other matches.
2137 Give a blank topic name to go to the Index node itself."
2138 (interactive "sIndex topic: ")
2139 (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
2140 (regexp-quote topic)
2141 "\\(.*\\)\\.[ t]*\\([0-9]*\\)$"))
2143 (message "Searching index for `%s'..." topic)
2144 (Info-goto-node "Top")
2145 (let ((case-fold-search t))
2146 (or (search-forward "\n* menu:" nil t)
2148 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2149 (error "No index")))
2150 (goto-char (match-beginning 1))
2151 (let ((Info-keeping-history nil)
2152 (Info-fontify (and Info-fontify (equal topic ""))))
2153 (Info-goto-node (Info-extract-menu-node-name)))
2154 (or (equal topic "")
2157 (Info-keeping-history nil)
2161 (goto-char (point-min))
2162 (while (re-search-forward pattern nil t)
2164 (cons (list (buffer-substring (match-beginning 1)
2166 (buffer-substring (match-beginning 2)
2169 (string-to-int (concat "0"
2174 (and (setq node (Info-extract-pointer "next" t))
2175 (string-match "\\<Index\\>" node)))
2176 (let ((Info-fontify nil))
2177 (Info-goto-node node)))
2181 (error "No \"%s\" in index" topic)))
2182 ;; Here it is a feature that assoc is case-sensitive.
2183 (while (setq found (assoc topic matches))
2184 (setq exact (cons found exact)
2185 matches (delq found matches)))
2186 (setq Info-index-alternatives (nconc exact (nreverse matches))
2187 Info-index-first-alternative (car Info-index-alternatives))
2188 (Info-index-next 0)))))
2190 (defun Info-index-next (num)
2191 "Go to the next matching index item from the last `i' command."
2193 (or Info-index-alternatives
2194 (error "No previous `i' command in this file"))
2196 (setq num (+ num (length Info-index-alternatives))))
2198 (setq Info-index-alternatives
2199 (nconc (cdr Info-index-alternatives)
2200 (list (car Info-index-alternatives)))
2202 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2203 (if (> (nth 3 (car Info-index-alternatives)) 0)
2204 (forward-line (nth 3 (car Info-index-alternatives)))
2205 (forward-line 3) ; don't search in headers
2206 (let ((name (car (car Info-index-alternatives))))
2207 (if (or (re-search-forward (format
2208 "\\(Function\\|Command\\): %s\\( \\|$\\)"
2209 (regexp-quote name)) nil t)
2210 (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
2211 (search-forward (format "`%s'" name) nil t)
2212 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2214 (format "`%s'" (substring name 0 (match-beginning 1)))
2216 (search-forward name nil t))
2218 (goto-char (point-min)))))
2219 (message "Found \"%s\" in %s. %s"
2220 (car (car Info-index-alternatives))
2221 (nth 2 (car Info-index-alternatives))
2222 (if (cdr Info-index-alternatives)
2223 (if (eq (car (cdr Info-index-alternatives))
2224 Info-index-first-alternative)
2225 "(Press `,' to repeat)"
2226 (format "(Press `,' for %d more)"
2227 (- (1- (length Info-index-alternatives))
2228 (length (memq Info-index-first-alternative
2229 (cdr Info-index-alternatives))))))
2234 (defun Info-emacs-command (command)
2235 "Look up an Emacs command in the Emacs manual in the Info system.
2236 This command is designed to be used whether you are already in Info or not."
2237 (interactive "CLook up command in Emacs manual: ")
2238 (save-window-excursion
2240 (Info-find-node Info-emacs-info-file-name "Top")
2241 (Info-index (symbol-name command)))
2242 (pop-to-buffer "*info*"))
2246 (defun Info-goto-emacs-command-node (key)
2247 "Look up an Emacs command in the Emacs manual in the Info system.
2248 This command is designed to be used whether you are already in Info or not."
2249 (interactive "CLook up command in Emacs manual: ")
2250 (Info-emacs-command key))
2253 (defun Info-goto-emacs-key-command-node (key)
2254 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2255 This command is designed to be used whether you are already in Info or not."
2256 (interactive "kLook up key in Emacs manual: ")
2257 (let ((command (key-binding key)))
2258 (cond ((eq command 'keyboard-quit)
2261 (error "%s is undefined" (key-description key)))
2262 ((and (interactive-p) (eq command 'execute-extended-command))
2263 (call-interactively 'Info-goto-emacs-command-node))
2265 (Info-goto-emacs-command-node command)))))
2268 (defun Info-emacs-key (key)
2269 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2270 This command is designed to be used whether you are already in Info or not."
2271 (interactive "kLook up key in Emacs manual: ")
2272 (cond ((eq (key-binding key) 'keyboard-quit)
2274 ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
2275 (call-interactively 'Info-goto-emacs-command-node))
2277 (save-window-excursion
2279 (Info-find-node Info-emacs-info-file-name "Top")
2280 (setq key (key-description key))
2282 (if (setq p (string-match "[@{}]" key))
2283 (setq key (concat (substring key 0 p) "@" (substring key p))))
2284 (if (string-match "^ESC " key)
2285 (setq key (concat "M-" (substring key 4))))
2286 (if (string-match "^M-C-" key)
2287 (setq key (concat "C-M-" (substring key 4)))))
2289 (pop-to-buffer "*info*"))))
2292 (defun Info-elisp-ref (func)
2293 "Look up an Emacs Lisp function in the Elisp manual in the Info system.
2294 This command is designed to be used whether you are already in Info or not."
2295 (interactive (let ((fn (function-at-point))
2296 (enable-recursive-minibuffers t)
2298 (setq val (completing-read
2299 (format "Look up Emacs Lisp function%s: "
2301 (format " (default %s)" fn)
2303 obarray 'fboundp t))
2304 (list (if (equal val "")
2306 (save-window-excursion
2309 (Info-find-node "lispref" "Top")
2310 (error (Info-find-node "elisp" "Top")))
2311 (Info-index (symbol-name func)))
2312 (pop-to-buffer "*info*"))
2314 (defun Info-reannotate-node ()
2315 (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
2317 (let ((ibuf (current-buffer))
2318 (file (concat "\\(" (regexp-quote
2319 (file-name-nondirectory Info-current-file))
2320 "\\|" (regexp-quote Info-current-file) "\\)"))
2321 (node (regexp-quote Info-current-node))
2323 (goto-char (point-min))
2324 (if (search-forward "\n------ NOTE:\n" nil t)
2325 (let ((buffer-read-only nil)
2326 (bufmod (buffer-modified-p))
2328 (setq savept (copy-marker savept))
2329 (goto-char (point-min))
2330 (while (search-forward "\n------ NOTE:" nil t)
2331 (setq top (1+ (match-beginning 0)))
2332 (if (search-forward "\n------\n" nil t)
2333 (delete-region top (point)))
2335 (set-buffer-modified-p bufmod)))
2338 (set-buffer (car bufs))
2339 (goto-char (point-min))
2340 (while (re-search-forward
2342 "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
2345 (let ((line (string-to-int
2346 (buffer-substring (match-beginning 2)
2350 (search-forward "\n------\n" nil t)
2354 (if (integerp savept) (setq savept (copy-marker savept)))
2356 (goto-char (point-max))
2357 (goto-char (point-min))
2358 (forward-line line))
2359 (let ((buffer-read-only nil)
2360 (bufmod (buffer-modified-p)))
2361 (insert "------ NOTE:\n")
2362 (insert-buffer-substring (car bufs) top bot)
2363 (set-buffer-modified-p bufmod)))))
2364 (setq bufs (cdr bufs))))
2365 (goto-char savept)))))
2367 (defvar Info-annotate-map nil
2368 "Local keymap used within `a' command of Info.")
2369 (if Info-annotate-map
2371 ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
2372 (setq Info-annotate-map (copy-keymap text-mode-map))
2373 (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
2375 (defun Info-annotate-mode ()
2376 "Major mode for adding an annotation to an Info node.
2377 Like text mode with the addition of Info-cease-annotate
2378 which returns to Info mode for browsing.
2379 \\{Info-annotate-map}")
2381 (defun Info-annotate (arg)
2382 "Add a personal annotation to the current Info node.
2383 Only you will be able to see this annotation. Annotations are stored
2384 in the file \"~/.xemacs/info.notes\" by default. If point is inside
2385 an existing annotation, edit that annotation. A prefix argument
2386 specifies which annotations file (from `Info-annotations-path') is to
2387 be edited; default is 1."
2390 (if (or (< arg 0) (not (nth arg Info-annotations-path)))
2392 (setq Info-annotations-path
2393 (list (read-file-name
2394 "Annotations file: " "~/" "~/.infonotes")))
2395 (error "File number must be in the range from 1 to %d"
2396 (length Info-annotations-path))))
2398 (file (file-name-nondirectory Info-current-file))
2399 (d Info-directory-list)
2401 (while (and d (not (equal (expand-file-name file (car d))
2402 Info-current-file)))
2404 (or d (setq file Info-current-file))
2405 (if (and (save-excursion
2406 (goto-char (min (point-max) (+ (point) 13)))
2407 (and (search-backward "------ NOTE:\n" nil t)
2408 (setq pt (match-end 0))
2409 (search-forward "\n------\n" nil t)))
2410 (< (point) (match-end 0)))
2411 (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
2413 (regexp-quote Info-current-node)
2415 (buffer-substring pt (match-beginning 0))))
2416 where (max (- (point) pt) 0)))
2417 (let ((node Info-current-node)
2418 (line (if (looking-at "[ \n]*\\'") 0
2419 (count-lines (point-min) (point)))))
2421 (let ((buffer-read-only nil)
2422 (bufmod (buffer-modified-p)))
2424 (if (bobp) (goto-char (point-max)))
2425 (insert "------ NOTE:\n------\n")
2427 (set-buffer-modified-p bufmod)))
2428 ;; (setq Info-window-start (window-start))
2429 (setq Info-window-configuration (current-window-configuration))
2430 (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
2431 (use-local-map Info-annotate-map)
2432 (setq major-mode 'Info-annotate-mode)
2433 (setq mode-name "Info Annotate")
2436 (goto-char (point-min))
2437 (re-search-forward which nil t))
2439 (goto-char (match-beginning 0))
2441 (forward-char where)))
2442 (let ((bufmod (buffer-modified-p)))
2443 (goto-char (point-max))
2444 (insert (format "\n------ File: %s Node: %s Line: %d\n"
2447 (insert "\n------\n"
2448 "\nPress C-c C-c to save and return to Info.\n")
2450 (set-buffer-modified-p bufmod))))))
2452 (defun Info-cease-annotate ()
2454 (let ((bufmod (buffer-modified-p)))
2455 (while (save-excursion
2456 (goto-char (point-min))
2457 (re-search-forward "\n\n?Press .* to save and return to Info.\n"
2459 (delete-region (1+ (match-beginning 0)) (match-end 0)))
2460 (while (save-excursion
2461 (goto-char (point-min))
2462 (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
2464 (delete-region (match-beginning 0) (match-end 0)))
2465 (set-buffer-modified-p bufmod))
2469 (or (one-window-p) (delete-window))
2471 (setq Info-current-annotation-completions nil)
2472 (set-window-configuration Info-window-configuration)
2473 (Info-reannotate-node))
2475 (defun Info-bookmark (arg tag)
2476 (interactive "p\nsBookmark name: ")
2478 (if (or (string-match "^\"\\(.*\\)\"$" tag)
2479 (string-match "^<<\\(.*\\)>>$" tag))
2480 (setq tag (substring tag (match-beginning 1) (match-end 1))))
2482 (search-forward "\n------\n")
2483 (let ((end (- (point) 8)))
2485 (if (re-search-forward "<<[^>\n]*>>" nil t)
2486 (delete-region (match-beginning 0) (match-end 0))
2489 (insert "<<" tag ">>"))))
2490 (Info-cease-annotate))
2493 "Exit Info by selecting some other buffer."
2496 (save-buffers-kill-emacs)
2497 (bury-buffer (current-buffer))
2498 (if (and (featurep 'toolbar)
2499 (boundp 'toolbar-info-frame)
2500 (eq toolbar-info-frame (selected-frame)))
2502 (delete-frame toolbar-info-frame)
2503 (error (bury-buffer)))
2504 (switch-to-buffer (other-buffer (current-buffer))))))
2506 (defun Info-undefined ()
2507 "Make command be undefined in Info."
2512 "Enter the Info tutorial."
2514 (delete-other-windows)
2515 (Info-find-node "info"
2516 (if (< (window-height) 23)
2520 (defun Info-summary ()
2521 "Display a brief summary of all Info commands."
2523 (save-window-excursion
2524 (switch-to-buffer "*Help*")
2526 (insert (documentation 'Info-mode))
2527 (goto-char (point-min))
2529 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2530 (message (if flag "Type Space to see more"
2531 "Type Space to return to Info"))
2532 (let ((e (next-command-event)))
2533 (if (/= ?\ (event-to-character e))
2534 (progn (setq unread-command-event e) nil)
2538 (bury-buffer "*Help*")))
2540 (defun Info-get-token (pos start all &optional errorstring)
2541 "Return the token around POS,
2542 POS must be somewhere inside the token
2543 START is a regular expression which will match the
2544 beginning of the tokens delimited string
2545 ALL is a regular expression with a single
2546 parenthized subpattern which is the token to be
2547 returned. E.g. '{\(.*\)}' would return any string
2548 enclosed in braces around POS.
2549 SIG optional fourth argument, controls action on no match
2552 a string: signal an error, using that string."
2554 (goto-char (point-min))
2555 (re-search-backward "\\`") ; Bug fix due to Nicholas J. Foskett.
2557 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
2559 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2560 (not (setq found (and (<= (match-beginning 0) pos)
2561 (> (match-end 0) pos))))))
2562 (if (and found (<= (match-beginning 0) pos)
2563 (> (match-end 0) pos))
2564 (buffer-substring (match-beginning 1) (match-end 1))
2565 (cond ((null errorstring)
2571 (error "No %s around position %d" errorstring pos)))))))
2573 (defun Info-follow-clicked-node (event)
2574 "Follow a node reference near clicked point. Like M, F, N, P or U command.
2575 At end of the node's text, moves to the next node."
2577 (or (and (event-point event)
2578 (Info-follow-nearest-node
2580 (select-window (event-window event))
2581 (event-point event))
2583 (error "click on a cross-reference to follow")))
2585 (defun Info-maybe-follow-clicked-node (event &optional click-count)
2586 "Follow a node reference (if any) near clicked point.
2587 Like M, F, N, P or U command. At end of the node's text, moves to the
2588 next node. No error is given if there is no node to follow."
2590 (and Info-button1-follows-hyperlink
2592 (Info-follow-nearest-node
2594 (select-window (event-window event))
2595 (event-point event))
2596 (1+ (point-min))))))
2598 (defun Info-find-nearest-node (point)
2601 ((= point (point-min)) nil) ; don't trigger on accidental RET.
2602 ((setq node (Info-get-token point
2603 (format "\\*%s[ \n]" Info-footnote-tag)
2604 (format "\\*%s[ \n]\\([^:]*\\):"
2605 Info-footnote-tag)))
2606 (list "Following cross-reference %s..."
2607 (list 'Info-follow-reference node)))
2608 ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\)::"))
2609 (list "Selecting menu item %s..."
2610 (list 'Info-goto-node node nil t)))
2611 ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\):"))
2612 (list "Selecting menu item %s..."
2613 (list 'Info-menu node)))
2614 ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
2616 (list 'Info-goto-node node)))
2617 ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
2618 (list "Next node..."
2619 (list 'Info-goto-node node)))
2620 ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
2622 (list 'Info-goto-node "Top")))
2623 ((setq node (Info-get-token point "Prev[ious]*: "
2624 "Prev[ious]*: \\([^,\n\t]*\\)"))
2625 (list "Previous node..."
2626 (list 'Info-goto-node node)))
2627 ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
2628 (list "Reselecting %s..."
2629 (list 'Info-goto-node node)))
2630 ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
2631 (if Info-in-cross-reference
2632 (list "Back to last node..."
2634 (list "Next node..."
2635 '(Info-global-next)))))
2638 (defun Info-follow-nearest-node (point)
2639 "Follow a node reference near point. Like M, F, N, P or U command.
2640 At end of the node's text, moves to the next node."
2642 (let ((data (Info-find-nearest-node point)))
2645 (let ((msg (format (car data) (nth 1 (nth 1 data)))))
2648 (message "%sdone" msg))
2651 (defun Info-indicated-node (event)
2654 (cond ((eventp event)
2655 (set-buffer (event-buffer event))
2656 (setq event (event-point event))))
2657 (let* ((data (Info-find-nearest-node event))
2658 (name (nth 1 (nth 1 data))))
2659 (and name (nth 1 data))))
2662 (defun Info-mouse-track-double-click-hook (event click-count)
2663 "Handle double-clicks by turning pages, like the `gv' ghostscript viewer"
2664 (if (/= click-count 2)
2665 ;; Return nil so any other hooks are performed.
2667 (let* ((fw (face-width 'default))
2668 (fh (face-height 'default))
2669 (x (/ (event-x-pixel event) fw))
2670 (y (/ (event-y-pixel event) fw))
2671 (w (/ (window-pixel-width (event-window event)) fw))
2672 (h (/ (window-pixel-height (event-window event)) fh))
2676 ((<= y by) (Info-up) t)
2677 ((>= y (- h by)) (Info-nth-menu-item 1) t)
2678 ((<= x bx) (Info-prev) t)
2679 ((>= x (- w bx)) (Info-next) t)
2682 (defvar Info-mode-map nil
2683 "Keymap containing Info commands.")
2686 (setq Info-mode-map (make-sparse-keymap))
2687 (suppress-keymap Info-mode-map)
2688 (define-key Info-mode-map "." 'beginning-of-buffer)
2689 (define-key Info-mode-map " " 'Info-scroll-next)
2690 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2691 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2692 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2693 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2694 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2695 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2696 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2697 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2698 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2699 (define-key Info-mode-map "0" 'Info-last-menu-item)
2700 (define-key Info-mode-map "?" 'Info-summary)
2701 (define-key Info-mode-map "a" 'Info-annotate)
2702 (define-key Info-mode-map "b" 'beginning-of-buffer)
2703 (define-key Info-mode-map "d" 'Info-directory)
2704 (define-key Info-mode-map "e" 'Info-edit)
2705 (define-key Info-mode-map "f" 'Info-follow-reference)
2706 (define-key Info-mode-map "g" 'Info-goto-node)
2707 (define-key Info-mode-map "h" 'Info-help)
2708 (define-key Info-mode-map "i" 'Info-index)
2709 (define-key Info-mode-map "j" 'Info-goto-bookmark)
2710 (define-key Info-mode-map "k" 'Info-emacs-key)
2711 (define-key Info-mode-map "l" 'Info-last)
2712 (define-key Info-mode-map "m" 'Info-menu)
2713 (define-key Info-mode-map "n" 'Info-next)
2714 (define-key Info-mode-map "p" 'Info-prev)
2715 (define-key Info-mode-map "q" 'Info-exit)
2716 (define-key Info-mode-map "r" 'Info-follow-reference)
2717 (define-key Info-mode-map "s" 'Info-search)
2718 (define-key Info-mode-map "t" 'Info-top)
2719 (define-key Info-mode-map "u" 'Info-up)
2720 (define-key Info-mode-map "v" 'Info-visit-file)
2721 (define-key Info-mode-map "x" 'Info-bookmark)
2722 (define-key Info-mode-map "<" 'Info-top)
2723 (define-key Info-mode-map ">" 'Info-end)
2724 (define-key Info-mode-map "[" 'Info-global-prev)
2725 (define-key Info-mode-map "]" 'Info-global-next)
2726 (define-key Info-mode-map "{" 'Info-page-prev)
2727 (define-key Info-mode-map "}" 'Info-page-next)
2728 (define-key Info-mode-map "=" 'Info-restore-point)
2729 (define-key Info-mode-map "!" 'Info-select-node)
2730 (define-key Info-mode-map "@" 'Info-follow-nearest-node)
2731 (define-key Info-mode-map "," 'Info-index-next)
2732 (define-key Info-mode-map "*" 'Info-elisp-ref)
2733 (define-key Info-mode-map [tab] 'Info-next-reference)
2734 (define-key Info-mode-map [(meta tab)] 'Info-prev-reference)
2735 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2736 (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
2738 (define-key Info-mode-map 'backspace 'Info-scroll-prev)
2739 (define-key Info-mode-map 'delete 'Info-scroll-prev)
2740 (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
2741 (define-key Info-mode-map 'button3 'Info-select-node-menu))
2744 ;; Info mode is suitable only for specially formatted data.
2745 (put 'info-mode 'mode-class 'special)
2748 "Info mode is for browsing through the Info documentation tree.
2749 Documentation in Info is divided into \"nodes\", each of which
2750 discusses one topic and contains references to other nodes
2751 which discuss related topics. Info has commands to follow
2752 the references and show you other nodes.
2754 h Invoke the Info tutorial.
2755 q Quit Info: return to the previously selected file or buffer.
2757 Selecting other nodes:
2758 n Move to the \"next\" node of this node.
2759 p Move to the \"previous\" node of this node.
2760 m Pick menu item specified by name (or abbreviation).
2761 1-9, 0 Pick first..ninth, last item in node's menu.
2762 Menu items select nodes that are \"subsections\" of this node.
2763 u Move \"up\" from this node (i.e., from a subsection to a section).
2764 f or r Follow a cross reference by name (or abbrev). Type `l' to get back.
2765 RET Follow cross reference or menu item indicated by cursor.
2766 i Look up a topic in this file's Index and move to that node.
2767 , (comma) Move to the next match from a previous `i' command.
2768 l (letter L) Move back to the last node you were in.
2770 Moving within a node:
2771 Space Scroll forward a full screen. DEL Scroll backward.
2772 b Go to beginning of node. Meta-> Go to end of node.
2773 TAB Go to next cross-reference. Meta-TAB Go to previous ref.
2776 Left Button Set point (usual text-mode functionality)
2777 Middle Button Click on a highlighted node reference to go to it.
2778 Right Button Pop up a menu of applicable Info commands.
2780 Left Button Double Click in window edges:
2781 Top edge: Go up to the parent node, like `u'.
2782 Left edge: Go to the previous node, like `p'.
2783 Right edge: Go to the next node, like `n'.
2784 Bottom edge: Follow first menu item, like `1'.
2787 g Move to node, file, or annotation tag specified by name.
2788 Examples: `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
2789 v Move to file, with filename completion.
2790 k Look up a key sequence in Emacs manual (also C-h C-k at any time).
2791 * Look up a function name in Emacs Lisp manual (also C-h C-f).
2792 d Go to the main directory of Info files.
2793 < or t Go to Top (first) node of this file.
2794 > Go to last node in this file.
2795 \[ Go to previous node, treating file as one linear document.
2796 \] Go to next node, treating file as one linear document.
2797 { Scroll backward, or go to previous node if at top.
2798 } Scroll forward, or go to next node if at bottom.
2799 = Restore cursor position from last time in this node.
2800 a Add a private note (annotation) to the current node.
2801 x, j Add, jump to a bookmark (annotation tag).
2802 s Search this Info file for a node containing the specified regexp.
2803 e Edit the contents of the current node."
2804 (kill-all-local-variables)
2805 (setq major-mode 'Info-mode)
2806 (setq mode-name "Info")
2807 (use-local-map Info-mode-map)
2808 (set-syntax-table text-mode-syntax-table)
2809 (setq local-abbrev-table text-mode-abbrev-table)
2810 (setq case-fold-search t)
2811 (setq buffer-read-only t)
2812 ; (setq buffer-mouse-map Info-mode-mouse-map)
2813 (make-local-variable 'Info-current-file)
2814 (make-local-variable 'Info-current-subfile)
2815 (make-local-variable 'Info-current-node)
2816 (make-local-variable 'Info-tag-table-marker)
2817 (make-local-variable 'Info-current-file-completions)
2818 (make-local-variable 'Info-current-annotation-completions)
2819 (make-local-variable 'Info-index-alternatives)
2820 (make-local-variable 'Info-history)
2821 ;; Faces are now defined by `defface'...
2822 (make-local-variable 'mouse-track-click-hook)
2823 (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
2824 (add-hook 'mouse-track-click-hook 'Info-mouse-track-double-click-hook)
2825 ;; #### The console-on-window-system-p check is to allow this to
2826 ;; work on tty's. The real problem here is that featurep really
2827 ;; needs to have some device/console domain knowledge added to it.
2828 (defvar info::toolbar)
2829 (if (and (featurep 'toolbar)
2830 (console-on-window-system-p)
2831 (not Info-inhibit-toolbar))
2832 (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
2833 (if (featurep 'menubar)
2835 ;; make a local copy of the menubar, so our modes don't
2836 ;; change the global menubar
2837 (easy-menu-add '("Info" :filter Info-menu-filter))))
2838 (run-hooks 'Info-mode-hook)
2839 (Info-set-mode-line))
2841 (defvar Info-edit-map nil
2842 "Local keymap used within `e' command of Info.")
2845 ;; XEmacs: remove FSF stuff
2846 (setq Info-edit-map (make-sparse-keymap))
2847 (set-keymap-name Info-edit-map 'Info-edit-map)
2848 (set-keymap-parents Info-edit-map (list text-mode-map))
2849 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
2851 ;; Info-edit mode is suitable only for specially formatted data.
2852 (put 'info-edit-mode 'mode-class 'special)
2854 (defun Info-edit-mode ()
2855 "Major mode for editing the contents of an Info node.
2856 Like text mode with the addition of `Info-cease-edit'
2857 which returns to Info mode for browsing.
2862 "Edit the contents of this Info node.
2863 Allowed only if variable `Info-enable-edit' is non-nil."
2865 (or Info-enable-edit
2866 (error "Editing info nodes is not enabled"))
2867 (use-local-map Info-edit-map)
2868 (setq major-mode 'Info-edit-mode)
2869 (setq mode-name "Info Edit")
2870 (kill-local-variable 'modeline-buffer-identification)
2871 (setq buffer-read-only nil)
2872 ;; Make mode line update.
2873 (set-buffer-modified-p (buffer-modified-p))
2874 (message (substitute-command-keys
2875 "Editing: Type \\[Info-cease-edit] to return to info")))
2877 (defun Info-cease-edit ()
2878 "Finish editing Info node; switch back to Info proper."
2880 ;; Do this first, so nothing has changed if user C-g's at query.
2881 (and (buffer-modified-p)
2882 (y-or-n-p-maybe-dialog-box "Save the file? ")
2884 (use-local-map Info-mode-map)
2885 (setq major-mode 'Info-mode)
2886 (setq mode-name "Info")
2887 (Info-set-mode-line)
2888 (setq buffer-read-only t)
2889 ;; Make mode line update.
2890 (set-buffer-modified-p (buffer-modified-p))
2891 (and (marker-position Info-tag-table-marker)
2893 (message "Tags may have changed. Use Info-tagify if necessary")))
2895 (defun Info-find-emacs-command-nodes (command)
2896 "Return a list of locations documenting COMMAND in the XEmacs Info manual.
2897 The locations are of the format used in Info-history, i.e.
2898 \(FILENAME NODENAME BUFFERPOS\)."
2900 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
2901 ":\\s *\\(.*\\)\\.$")))
2903 (Info-find-node "XEmacs" "Command Index")
2904 ;; Take the index node off the Info history.
2905 ;; ??? says this isn't safe someplace else... hmmm.
2906 (setq Info-history (cdr Info-history))
2907 (goto-char (point-max))
2908 (while (re-search-backward cmd-desc nil t)
2909 (setq where (cons (list Info-current-file
2917 ;;; fontification and mousability for info
2919 (defun Info-highlight-region (start end face)
2921 (splitp (string-match "\n[ \t]+" (buffer-substring start end))))
2924 (setq extent (make-extent start (progn (goto-char start)
2927 (set-extent-face extent face)
2928 (set-extent-property extent 'info t)
2929 (set-extent-property extent 'highlight t)
2930 (skip-chars-forward "\n\t ")
2931 (setq extent (make-extent (point) end)))
2932 (setq extent (make-extent start end)))
2933 (set-extent-face extent face)
2934 (set-extent-property extent 'info t)
2935 (set-extent-property extent 'highlight t)))
2937 (defun Info-fontify-node ()
2939 (let ((case-fold-search t)
2940 (xref-regexp (concat "\\*"
2941 (regexp-quote Info-footnote-tag)
2942 "[ \n\t]*\\([^:]*\\):")))
2943 ;; Clear the old extents
2944 (map-extents #'(lambda (x y) (delete-extent x))
2945 (current-buffer) (point-min) (point-max) nil)
2946 ;; Break the top line iff it is > 79 characters. Some info nodes
2947 ;; have top lines that span 3 lines because of long node titles.
2948 ;; eg: (Info-find-node "lispref.info" "Window-Level Event Position Info")
2949 (toggle-read-only -1)
2954 (goto-char (point-min))
2955 (re-search-forward "Node: *[^,]+, " nil t)
2956 (setq len (- (point) (point-min))
2957 extent (make-extent (point-min) (point)))
2958 (set-extent-property extent 'invisible t)
2962 (if (< (current-column) (+ 78 len))
2965 (forward-char (+ 79 len))
2966 (re-search-backward "," nil t)
2970 (backward-delete-char 1)
2973 (toggle-read-only 1)
2974 ;; Highlight xrefs in the top few lines of the node
2975 (goto-char (point-min))
2976 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
2978 (goto-char (match-end 0))
2980 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?\n?")
2981 (goto-char (match-end 0))
2982 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref))))
2983 ;; Now get the xrefs in the body
2984 (goto-char (point-min))
2985 (while (re-search-forward xref-regexp nil t)
2986 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2988 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref)))
2989 ;; then highlight the nodes in the menu.
2990 (goto-char (point-min))
2991 (if (and (search-forward "\n* menu:" nil t))
2992 (while (re-search-forward
2993 "^\\* \\([^:\t\n]*\\):?:[ \t\n]" nil t)
2994 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-node)))
2995 (set-buffer-modified-p nil))))
2997 (defun Info-construct-menu (&optional event)
2998 "Construct a menu of Info commands.
2999 Adds an entry for the node at EVENT, or under point if EVENT is omitted.
3000 Used to construct the menubar submenu and popup menu."
3001 (or event (setq event (point)))
3002 (let ((case-fold-search t)
3003 (xref-regexp (concat "\\*"
3004 (regexp-quote Info-footnote-tag)
3005 "[ \n\t]*\\([^:]*\\):"))
3006 up-p prev-p next-p menu xrefs subnodes in)
3008 ;; `one-space' fixes "Notes:" xrefs that are split across lines.
3012 (while (setq i (string-match "[ \n\t]+" text i))
3013 (setq text (concat (substring text 0 i) " "
3014 (substring text (match-end 0))))
3017 (goto-char (point-min))
3018 (if (looking-at ".*\\bNext:") (setq next-p t))
3019 (if (looking-at ".*\\bPrev:") (setq prev-p t))
3020 (if (looking-at ".*Up:") (setq up-p t))
3022 (if (setq in (Info-indicated-node event))
3023 (list (vector (one-space (cadr in)) in t)
3024 "--:shadowEtchedIn"))
3026 ["Goto Info Top-level" Info-directory]
3027 (vector "Next Node" 'Info-next :active next-p)
3028 (vector "Previous Node" 'Info-prev :active prev-p)
3029 (vector "Parent Node (Up)" 'Info-up :active up-p)
3030 ["Goto Node..." Info-goto-node]
3031 ["Goto Last Visited Node " Info-last])))
3032 ;; Find the xrefs and make a list
3033 (while (re-search-forward xref-regexp nil t)
3034 (setq xrefs (cons (one-space (buffer-substring (match-beginning 1)
3037 (setq xrefs (nreverse xrefs))
3038 (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
3039 ;; Find the subnodes and make a list
3040 (goto-char (point-min))
3041 (if (search-forward "\n* menu:" nil t)
3042 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
3043 (setq subnodes (cons (buffer-substring (match-beginning 1)
3046 (setq subnodes (nreverse subnodes))
3047 (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more))))
3049 (nconc menu (list "--:shadowDoubleEtchedIn"
3052 (mapcar #'(lambda (xref)
3056 (list 'Info-follow-reference xref))))
3059 (nconc menu (list "--:shadowDoubleEtchedIn"
3062 (mapcar #'(lambda (node)
3065 (vector node (list 'Info-menu node))))
3069 (defun Info-menu-filter (menu)
3070 "This is the menu filter for the \"Info\" submenu."
3071 (Info-construct-menu))
3073 (defun Info-select-node-menu (event)
3074 "Pops up a menu of applicable Info commands."
3076 (select-window (event-window event))
3077 (let ((menu (Info-construct-menu event)))
3078 (setq menu (nconc (list "Info" ; title: not displayed
3080 "--:shadowDoubleEtchedOut")
3082 (let ((popup-menu-titles nil))
3083 (popup-menu menu))))
3085 ;;; Info toolbar support
3087 ;; exit icon taken from GNUS
3088 (defvar info::toolbar-exit-icon
3089 (if (featurep 'toolbar)
3090 (toolbar-make-button-list
3091 (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
3092 toolbar-icon-directory)))
3095 (defvar info::toolbar-up-icon
3096 (if (featurep 'toolbar)
3097 (toolbar-make-button-list
3098 (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
3099 toolbar-icon-directory)))
3102 (defvar info::toolbar-next-icon
3103 (if (featurep 'toolbar)
3104 (toolbar-make-button-list
3105 (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
3106 toolbar-icon-directory)))
3109 (defvar info::toolbar-prev-icon
3110 (if (featurep 'toolbar)
3111 (toolbar-make-button-list
3112 (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
3113 toolbar-icon-directory)))
3116 (defvar info::toolbar
3117 (if (featurep 'toolbar)
3118 ; disabled until we get the next/prev-win icons working again.
3119 ; (cons (first initial-toolbar-spec)
3120 ; (cons (second initial-toolbar-spec)
3121 '([info::toolbar-exit-icon
3125 [info::toolbar-next-icon
3128 "Next entry in same section"]
3129 [info::toolbar-prev-icon
3132 "Prev entry in same section"]
3133 [info::toolbar-up-icon
3136 "Up entry to enclosing section"]
3142 (run-hooks 'Info-load-hook)
3144 ;;; info.el ends here