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 <verna@inf.enst.fr>
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 nil
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))))
595 (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
596 "Go to an info node specified as separate FILENAME and NODENAME.
597 Look for a plausible filename, or if not found then look for URL's and
598 dispatch to the appropriate fn. NO-GOING-BACK is non-nil if
599 recovering from an error in this function; it says do not attempt
600 further (recursive) error recovery. TRYFILE is ??"
605 ;; empty filename is simple case
607 (Info-find-file-node nil nodename no-going-back tryfile line))
608 ;; Convert filename to lower case if not found as specified.
609 ;; Expand it, look harder...
610 ((let (temp temp-downcase found
611 (fname (substitute-in-file-name filename)))
613 ((string-match "^\\./" fname) ; If specified name starts with `./'
614 (list default-directory)) ; then just try current directory.
615 ((file-name-absolute-p fname)
616 '(nil)) ; No point in searching for an absolute file name
617 (Info-additional-search-directory-list
618 (append Info-directory-list
619 Info-additional-search-directory-list))
620 (t Info-directory-list))))
621 ;; Search the directory list for file FNAME.
622 (while (and dirs (not found))
623 (setq temp (expand-file-name fname (car dirs)))
625 (expand-file-name (downcase fname) (car dirs)))
626 (if (equal temp-downcase temp) (setq temp-downcase nil))
627 ;; Try several variants of specified name.
628 ;; Try downcasing, appending a suffix, or both.
629 (setq found (Info-suffixed-file temp temp-downcase))
630 (setq dirs (cdr dirs)))
632 (progn (setq filename (expand-file-name found))
634 (Info-find-file-node filename nodename no-going-back tryfile line))
635 ;; Look for a URL. This pattern is stolen from w3.el to prevent
636 ;; loading it if we won't need it.
637 ((string-match (concat "^\\(wais\\|solo\\|x-exec\\|newspost\\|www\\|"
638 "mailto\\|news\\|tn3270\\|ftp\\|http\\|file\\|"
639 "telnet\\|gopher\\):")
641 (if (fboundp 'browse-url)
642 (browse-url filename)
643 (error "Cannot follow URLs in this XEmacs")))
645 (error "Info file %s does not exist" filename))))
647 (defun Info-find-file-node (filename nodename
648 &optional no-going-back tryfile line)
649 ;; This is the guts of what was Info-find-node. Whoever wrote this
650 ;; should be locked up where they can't do any more harm.
652 ;; Go into info buffer.
653 (switch-to-buffer "*info*")
654 (buffer-disable-undo (current-buffer))
655 (run-hooks 'Info-startup-hook)
656 (or (eq major-mode 'Info-mode)
659 (equal Info-current-file filename)
661 (string= "dir" (file-name-nondirectory Info-current-file))
662 (if (y-or-n-p-maybe-dialog-box
663 (format "Leave Info file `%s'? "
664 (file-name-nondirectory Info-current-file)))
667 ;; Record the node we are leaving.
668 (if (and Info-current-file (not no-going-back))
669 (Info-history-add Info-current-file Info-current-node (point)))
671 (setq Info-current-node nil
672 Info-in-cross-reference nil)
675 ;; Switch files if necessary
677 (equal Info-current-file filename)
678 (let ((buffer-read-only nil))
679 (setq Info-current-file nil
680 Info-current-subfile nil
681 Info-current-file-completions nil
682 Info-index-alternatives nil
683 buffer-file-name nil)
685 (if (string= "dir" (file-name-nondirectory filename))
687 (Info-insert-file-contents filename t)
688 (setq default-directory (file-name-directory filename)))
689 (set-buffer-modified-p nil)
690 ;; See whether file has a tag table. Record the location if yes.
691 (set-marker Info-tag-table-marker nil)
692 (goto-char (point-max))
694 (or (equal nodename "*")
695 (not (search-forward "\^_\nEnd tag table\n" nil t))
697 ;; We have a tag table. Find its beginning.
698 ;; Is this an indirect file?
699 (search-backward "\nTag table:\n")
703 (looking-at "(Indirect)\n"))
704 ;; It is indirect. Copy it to another buffer
705 ;; and record that the tag table is in that buffer.
707 (let ((buf (current-buffer)))
709 (get-buffer-create " *info tag table*"))
710 (buffer-disable-undo (current-buffer))
711 (setq case-fold-search t)
713 (insert-buffer-substring buf)
714 (set-marker Info-tag-table-marker
716 (set-marker Info-tag-table-marker pos))))
717 (setq Info-current-file
718 (file-name-sans-versions buffer-file-name))))
719 (if (equal nodename "*")
720 (progn (setq Info-current-node nodename)
722 (goto-char (point-min)))
723 ;; Search file for a suitable node.
724 (let* ((qnode (regexp-quote nodename))
725 (regexp (concat "Node: *" qnode " *[,\t\n\177]"))
726 (guesspos (point-min))
728 ;; First get advice from tag table if file has one.
729 ;; Also, if this is an indirect info file,
730 ;; read the proper subfile into this buffer.
731 (if (marker-position Info-tag-table-marker)
733 (set-buffer (marker-buffer Info-tag-table-marker))
734 (goto-char Info-tag-table-marker)
735 (if (re-search-forward regexp nil t)
737 (setq guesspos (read (current-buffer)))
738 ;; If this is an indirect file,
739 ;; determine which file really holds this node
741 (if (not (eq (current-buffer) (get-buffer "*info*")))
743 (Info-read-subfile guesspos)))))))
744 (goto-char (max (point-min) (- guesspos 1000)))
745 ;; Now search from our advised position (or from beg of buffer)
746 ;; to find the actual node.
748 (while (search-forward "\n\^_" nil t)
752 (if (re-search-backward regexp beg t)
755 (let ((bufs (delq nil (mapcar 'get-file-buffer
756 Info-annotations-path)))
757 (pattern (if (string-match "\\`<<.*>>\\'" qnode) qnode
758 (format "\"%s\"\\|<<%s>>" qnode qnode)))
759 (pat2 (concat "------ *File: *\\([^ ].*[^ ]\\) *Node: "
760 "*\\([^ ].*[^ ]\\) *Line: *\\([0-9]+\\)"))
761 (afile nil) anode aline)
762 (while (and bufs (not anode))
764 (set-buffer (car bufs))
765 (goto-char (point-min))
766 (if (re-search-forward pattern nil t)
767 (if (re-search-backward pat2 nil t)
768 (setq afile (buffer-substring (match-beginning 1)
770 anode (buffer-substring (match-beginning 2)
773 (buffer-substring (match-beginning 3)
775 (setq bufs (cdr bufs)))
777 (Info-find-node afile anode t nil aline)
780 (Info-find-node nodename "Top" t)
782 (or Info-current-node
783 (error "No such node: %s" nodename)))
787 (goto-char (point-min))
788 (if line (forward-line line)))))))
789 ;; If we did not finish finding the specified node,
790 ;; go back to the previous one.
791 (or Info-current-node no-going-back
792 (let ((hist (car Info-history)))
793 ;; The following is no longer safe with new Info-history system
794 ;; (setq Info-history (cdr Info-history))
795 (Info-goto-node (car hist) t)
796 (goto-char (+ (point-min) (nth 1 hist)))))))
798 ;; Cache the contents of the (virtual) dir file, once we have merged
799 ;; it for the first time, so we can save time subsequently.
800 (defvar Info-dir-contents nil)
802 ;; Cache for the directory we decided to use for the default-directory
803 ;; of the merged dir text.
804 (defvar Info-dir-contents-directory nil)
806 ;; Record the file attributes of all the files from which we
807 ;; constructed Info-dir-contents.
808 (defvar Info-dir-file-attributes nil)
810 (defun Info-insert-dir ()
811 "Construct the Info directory node by merging the files named
812 \"dir\" or \"localdir\" from the directories in `Info-directory-list'
813 The \"dir\" files will take precedence in cases where both exist. It
814 sets the *info* buffer's `default-directory' to the first directory we
815 actually get any text from."
816 (if (and Info-dir-contents Info-dir-file-attributes
817 ;; Verify that none of the files we used has changed
820 (mapcar #'(lambda (elt)
821 (let ((curr (file-attributes (car elt))))
822 ;; Don't compare the access time.
823 (if curr (setcar (nthcdr 4 curr) 0))
824 (setcar (nthcdr 4 (cdr elt)) 0)
825 (equal (cdr elt) curr)))
826 Info-dir-file-attributes))))
827 (insert Info-dir-contents)
828 (let ((dirs (reverse Info-directory-list))
829 buffers lbuffers buffer others nodes dirs-done)
831 (setq Info-dir-file-attributes nil)
833 ;; Search the directory list for the directory file.
835 (let ((truename (file-truename (expand-file-name (car dirs)))))
836 (or (member truename dirs-done)
837 (member (directory-file-name truename) dirs-done)
838 ;; Try several variants of specified name.
839 ;; Try upcasing, appending `.info', or both.
844 (progn (setq file (expand-file-name "dir" truename))
845 (file-attributes file))
846 (progn (setq file (expand-file-name "DIR" truename))
847 (file-attributes file))
848 (progn (setq file (expand-file-name "dir.info" truename))
849 (file-attributes file))
850 (progn (setq file (expand-file-name "DIR.INFO" truename))
851 (file-attributes file))
852 (progn (setq file (expand-file-name "localdir" truename))
853 (file-attributes file))
854 (progn (setq file (expand-file-name "dir" truename))
859 (cons (directory-file-name truename)
861 (Info-maybe-update-dir file)
862 (setq attrs (file-attributes file))
863 (if (or (setq buf (find-buffer-visiting file))
867 (message "Composing main Info directory..."))
870 (if (string-match "localdir" file)
874 (insert-file-contents file))
875 (if (string-match "localdir" (buffer-name))
876 (setq lbuffers (cons (current-buffer) lbuffers))
877 (setq buffers (cons (current-buffer) buffers)))
879 (setq Info-dir-file-attributes
880 (cons (cons file attrs)
881 Info-dir-file-attributes)))))))
882 (or (cdr dirs) (setq Info-dir-contents-directory (car dirs)))
883 (setq dirs (cdr dirs))))
885 ;; ensure that the localdir files are inserted last, and reverse
886 ;; the list of them so that when they get pushed in, they appear
887 ;; in the same order they got specified in the path, from top to
889 (nconc buffers (reverse lbuffers))
892 (error "Can't find the Info directory node"))
893 ;; Distinguish the dir file that comes with Emacs from all the
894 ;; others. Yes, that is really what this is supposed to do.
895 ;; If it doesn't work, fix it.
896 (setq buffer (car buffers)
897 ;; reverse it since they are pushed down from the top. the
898 ;; `Info-directory-list can be specified in natural order
900 others (reverse (cdr buffers)))
902 ;; Insert the entire original dir file as a start; note that we've
903 ;; already saved its default directory to use as the default
904 ;; directory for the whole concatenation.
905 (insert-buffer buffer)
907 ;; Look at each of the other buffers one by one.
909 (let ((other (car others))
910 (info-buffer (current-buffer)))
911 (if (string-match "localdir" (buffer-name other))
913 (set-buffer info-buffer)
914 (goto-char (point-max))
916 ((re-search-backward "^ *\\* *Locals *: *$" nil t)
917 (delete-region (match-beginning 0) (match-end 0)))
918 ;; look for a line like |Local XEmacs packages:
919 ;; or mismatch on some text ...
920 ((re-search-backward Info-localdir-heading-regexp nil t)
921 ;; This is for people who underline topic headings with
922 ;; equal signs or dashes.
923 (when (save-excursion
926 (looking-at "^[ \t]*[-=*]+"))
930 (t (search-backward "\^L" nil t)))
931 ;; Insert menu part of the file
933 (len (length (buffer-string nil nil other))))
934 (insert (buffer-string nil nil other))
935 (goto-char (+ pt len))
938 (if (search-forward "* Menu:" (+ pt len) t)
941 (delete-region pt (point)))))))
942 ;; In each, find all the menus.
945 (goto-char (point-min))
946 ;; Find each menu, and add an elt to NODES for it.
947 (while (re-search-forward "^\\* Menu:" nil t)
948 (let (beg nodename end)
951 (search-backward "\n\^_")
952 (search-forward "Node: ")
953 (setq nodename (Info-following-node-name))
954 (search-forward "\n\^_" nil 'move)
957 (setq nodes (cons (list nodename other beg end) nodes))))))
958 (setq others (cdr others))))
960 ;; Add to the main menu a menu item for each other node.
961 (re-search-forward "^\\* Menu:" nil t)
963 (let ((menu-items '("top"))
966 (end (save-excursion (search-forward "\^_" nil t) (point))))
968 (let ((nodename (car (car nodes))))
970 (or (member (downcase nodename) menu-items)
971 (re-search-forward (concat "^\\* "
972 (regexp-quote nodename)
976 (insert "* " nodename "::" "\n")
977 (setq menu-items (cons nodename menu-items))))))
978 (setq nodes (cdr nodes))))
979 ;; Now take each node of each of the other buffers
980 ;; and merge it into the main buffer.
982 (let ((nodename (car (car nodes))))
983 (goto-char (point-min))
984 ;; Find the like-named node in the main buffer.
985 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
986 (regexp-quote nodename)
990 (search-forward "\n\^_" nil 'move)
993 ;; If none exists, add one.
994 (goto-char (point-max))
995 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
996 ;; Merge the text from the other buffer's menu
997 ;; into the menu in the like-named node in the main buffer.
998 (apply 'insert-buffer-substring (cdr (car nodes))))
999 (setq nodes (cdr nodes)))
1000 ;; Kill all the buffers we just made.
1002 (kill-buffer (car buffers))
1003 (setq buffers (cdr buffers)))
1005 (kill-buffer (car lbuffers))
1006 (setq lbuffers (cdr lbuffers)))
1007 (message "Composing main Info directory...done"))
1008 (setq Info-dir-contents (buffer-string)))
1009 (setq default-directory Info-dir-contents-directory)
1010 (setq buffer-file-name (caar Info-dir-file-attributes)))
1012 (defun Info-maybe-update-dir (file)
1013 "Rebuild dir or localdir according to `Info-auto-generate-directory'."
1014 (unless (or (not (file-exists-p (file-name-directory file)))
1015 (null (directory-files (file-name-directory file) nil "\\.info")))
1016 (if (not (find-buffer-visiting file))
1017 (if (not (file-exists-p file))
1018 (if (or (eq Info-auto-generate-directory 'always)
1019 (eq Info-auto-generate-directory 'if-missing))
1020 (Info-build-dir-anew (file-name-directory file)))
1021 (if (or (eq Info-auto-generate-directory 'always)
1022 (and (eq Info-auto-generate-directory 'if-outdated)
1023 (Info-dir-outdated-p file)))
1024 (Info-rebuild-dir file))))))
1026 ;; Record which *.info files are newer than the dir file
1027 (defvar Info-dir-newer-info-files nil)
1029 (defun Info-dir-outdated-p (file)
1030 "Return non-nil if dir or localdir is outdated.
1031 dir or localdir are outdated when an info file in the same
1032 directory has been modified more recently."
1033 (let ((dir-mod-time (nth 5 (file-attributes file)))
1036 (setq Info-dir-newer-info-files nil)
1040 (setq f-mod-time (nth 5 (file-attributes f)))
1041 (setq newer (or (> (car f-mod-time) (car dir-mod-time))
1042 (and (= (car f-mod-time) (car dir-mod-time))
1043 (> (car (cdr f-mod-time)) (car (cdr dir-mod-time))))))
1044 (if (and (file-readable-p f)
1046 (setq Info-dir-newer-info-files
1047 (cons f Info-dir-newer-info-files)))))
1048 (directory-files (file-name-directory file)
1050 ".*\\.info\\(\\.gz\\|\\.bz2\\|\\.Z\\|-z\\|\\.zip\\)?$"
1053 Info-dir-newer-info-files))
1055 (defun Info-extract-dir-entry-from (file)
1056 "Extract the dir entry from the info FILE.
1057 The dir entry is delimited by the markers `START-INFO-DIR-ENTRY'
1058 and `END-INFO-DIR-ENTRY'"
1060 (set-buffer (get-buffer-create " *Info-tmp*"))
1061 (when (file-readable-p file)
1062 (insert-file-contents file nil nil nil t)
1063 (goto-char (point-min))
1065 (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
1068 (unless (null (re-search-forward "^END-INFO-DIR-ENTRY" nil t))
1069 (goto-char (match-beginning 0))
1070 (car (Info-parse-dir-entries beg (point)))))))))
1072 ;; Parse dir entries contained between BEG and END into a list of the form
1073 ;; (filename topic node (description-line-1 description-line-2 ...))
1074 (defun Info-parse-dir-entries (beg end)
1075 (let (entry entries)
1078 (narrow-to-region beg end)
1080 (while (re-search-forward "^\\* \\([^:]+\\):\\([ \t]*(\\([^)]*\\))\\w*\\.\\|:\\)" nil t)
1081 (setq entry (list (match-string 2)
1083 (downcase (or (match-string 3)
1084 (match-string 1)))))
1091 (re-search-forward "[ \t]*" nil t)
1092 (or (and (re-search-forward "^[^ \t]" nil t)
1093 (goto-char (match-beginning 0)))
1095 "[ \t]*\n[ \t]*"))))
1097 (setq entries (cons (nreverse entry) entries)))))
1098 (nreverse entries)))
1100 (defun Info-dump-dir-entries (entries)
1104 (mapcar #'(lambda (e)
1105 (setq e (cdr e)) ; Drop filename
1106 (setq len (length (concat (car e)
1108 (if (> len description-col)
1109 (setq description-col len)))
1111 (setq description-col (+ 5 description-col))
1112 (mapcar #'(lambda (e)
1113 (setq e (cdr e)) ; Drop filename
1114 (insert "* " (car e) ":" (car (cdr e)))
1115 (setq e (car (cdr (cdr e))))
1117 (indent-to-column description-col)
1118 (insert (car e) "\n")
1124 (defun Info-build-dir-anew (directory)
1125 "Build info directory information for DIRECTORY.
1126 The generated directory listing may be saved to a `dir' according
1127 to the value of `Info-save-auto-generated-dir'"
1129 (let* ((dirfile (expand-file-name "dir" directory))
1130 (to-temp (or (null Info-save-auto-generated-dir)
1131 (eq Info-save-auto-generated-dir 'never)
1132 (and (not (file-writable-p dirfile))
1133 (message "File not writable %s. Using temporary." dirfile))))
1135 (directory-files directory
1137 ".*\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1141 (message "Creating temporary dir in %s..." directory)
1142 (message "Creating %s..." dirfile))
1143 (set-buffer (find-file-noselect dirfile t))
1144 (setq buffer-read-only nil)
1146 (insert Info-dir-prologue
1147 "Info files in " directory ":\n\n")
1148 (Info-dump-dir-entries
1151 (or (Info-extract-dir-entry-from f)
1154 (string-match "\\(.*\\)\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1155 (file-name-nondirectory f))
1156 (capitalize (match-string 1 (file-name-nondirectory f))))
1158 (list Info-no-description-string))))
1161 (set-buffer-modified-p nil)
1164 (message "Creating temporary dir in %s...done" directory)
1165 (message "Creating %s...done" dirfile)))))
1168 (defun Info-rebuild-dir (file)
1169 "Build info directory information in the directory of dir FILE.
1170 Description of info files are merged from the info files in the
1171 directory and the contents of FILE with the description in info files
1172 taking precedence over descriptions in FILE.
1173 The generated directory listing may be saved to a `dir' according to
1174 the value of `Info-save-auto-generated-dir' "
1177 (let (dir-section-contents dir-full-contents
1183 (or (null Info-save-auto-generated-dir)
1184 (eq Info-save-auto-generated-dir 'never)
1185 (and (eq Info-save-auto-generated-dir 'always)
1186 (not (file-writable-p file))
1187 (message "File not writable %s. Using temporary." file))
1188 (and (eq Info-save-auto-generated-dir 'conservative)
1189 (or (and (not (file-writable-p file))
1190 (message "File not writable %s. Using temporary." file))
1192 (message "%s is outdated. Overwrite ? "
1194 (set-buffer (find-file-noselect file t))
1195 (setq buffer-read-only nil)
1197 (message "Rebuilding temporary %s..." file)
1198 (message "Rebuilding %s..." file))
1200 (setq buffer-read-only nil)
1201 (goto-char (point-min))
1202 (unless (and (search-forward "\^_")
1203 (re-search-forward "^\\* Menu:.*$" nil t)
1204 (setq mark (and (re-search-forward "^\\* " nil t)
1205 (match-beginning 0))))
1207 (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1208 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$" nil t)
1209 (match-beginning 0))
1212 (narrow-to-region mark next-section)
1213 (setq dir-section-contents (nreverse (Info-parse-dir-entries (point-min)
1217 (setq dir-entry (assoc (downcase
1218 (file-name-sans-extension
1219 (file-name-nondirectory file)))
1220 dir-section-contents)
1221 file-dir-entry (Info-extract-dir-entry-from file))
1224 ;; A dir entry in the info file takes precedence over an
1225 ;; existing entry in the dir file
1226 (setcdr dir-entry (cdr file-dir-entry)))
1227 (unless (or not-first-section
1229 (file-name-sans-extension
1230 (file-name-nondirectory file)))
1233 (setq dir-section-contents (cons file-dir-entry
1234 dir-section-contents))
1235 (setq dir-section-contents
1237 (capitalize (file-name-sans-extension
1238 (file-name-nondirectory file)))
1240 (list Info-no-description-string))
1241 dir-section-contents))))))
1242 Info-dir-newer-info-files)
1243 (delete-region (point-min) (point-max))
1244 (Info-dump-dir-entries (nreverse dir-section-contents))
1246 (if (= next-section (point-max))
1247 (setq next-section nil)
1248 (or (setq mark (and (re-search-forward "^\\* " nil t)
1249 (match-beginning 0)))
1251 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$" nil t)
1252 (match-beginning 0))
1254 (setq not-first-section t)))
1257 (set-buffer-modified-p nil)
1258 (message "Rebuilding temporary %s...done" file))
1260 (message "Rebuilding %s...done" file))))))
1263 (defun Info-batch-rebuild-dir ()
1264 "(Re)build info `dir' files in the directories remaining on the command line.
1265 Use this from the command line, with `-batch';
1266 it won't work in an interactive Emacs.
1267 Each file is processed even if an error occurred previously.
1268 For example, invoke \"xemacs -batch -f Info-batch-rebuild-dir /usr/local/info\""
1269 ;; command-line-args-left is what is left of the command line (from
1271 (defvar command-line-args-left) ; Avoid 'free variable' warning
1272 (if (not noninteractive)
1273 (error "`Info-batch-rebuild-dir' is to be used only with -batch"))
1274 (let ((Info-save-auto-generated-dir 'always)
1276 (while command-line-args-left
1277 (if (not (file-directory-p (car command-line-args-left)))
1278 (message "Warning: Skipped %s. Not a directory."
1279 (car command-line-args-left))
1280 (setq dir (expand-file-name "dir" (car command-line-args-left)))
1281 (setq localdir (expand-file-name "localdir" (car command-line-args-left)))
1283 ((file-exists-p dir)
1284 (Info-rebuild-dir dir))
1285 ((file-exists-p localdir)
1286 (Info-rebuild-dir localdir))
1288 (Info-build-dir-anew (car command-line-args-left)))))
1289 (setq command-line-args-left (cdr command-line-args-left)))
1293 (defun Info-history-add (file node point)
1294 (if Info-keeping-history
1295 (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
1296 (found (assoc name Info-history)))
1298 (setq Info-history (delq found Info-history)))
1299 (setq Info-history (cons (list name (- point (point-min))
1300 (and (eq (window-buffer)
1302 (- (window-start) (point-min))))
1305 (defun Info-file-name-only (file)
1306 (let ((dir (file-name-directory file))
1307 (p Info-directory-list))
1308 (while (and p (not (equal (car p) dir)))
1310 (if p (file-name-nondirectory file) file)))
1312 (defun Info-read-subfile (nodepos)
1313 (set-buffer (marker-buffer Info-tag-table-marker))
1314 (goto-char (point-min))
1315 (search-forward "\n\^_")
1320 (while (not (looking-at "\^_"))
1323 thisfilepos thisfilename)
1324 (search-forward ": ")
1325 (setq thisfilename (buffer-substring beg (- (point) 2)))
1326 (setq thisfilepos (read (current-buffer)))
1327 ;; read in version 19 stops at the end of number.
1328 ;; Advance to the next line.
1331 (if (> thisfilepos nodepos)
1333 (setq lastfilename thisfilename)
1334 (setq lastfilepos thisfilepos))
1336 (set-buffer (get-buffer "*info*"))
1337 (or (equal Info-current-subfile lastfilename)
1338 (let ((buffer-read-only nil))
1339 (setq buffer-file-name nil)
1342 (Info-insert-file-contents (Info-suffixed-file
1343 (expand-file-name lastfilename
1344 (file-name-directory
1345 Info-current-file)))
1347 (set-buffer-modified-p nil)
1348 (setq Info-current-subfile lastfilename)))
1349 (goto-char (point-min))
1350 (search-forward "\n\^_")
1351 (+ (- nodepos lastfilepos) (point))))
1353 (defun Info-suffixed-file (name &optional name2)
1354 "Look for NAME with each of the `Info-suffix-list' extensions in
1355 turn. Optional NAME2 is the name of a fallback info file to check
1356 for; usually a downcased version of NAME."
1357 (let ((suff Info-suffix-list)
1360 (while (and suff (not found))
1361 (setq file (concat name (caar suff))
1362 file2 (and name2 (concat name2 (caar suff))))
1364 ((file-regular-p file)
1366 ((and file2 (file-regular-p file2))
1369 (setq suff (cdr suff)))))
1371 (and name (when (file-regular-p name)
1373 (and name2 (when (file-regular-p name2)
1376 (defun Info-insert-file-contents (file &optional visit)
1377 (setq file (expand-file-name file default-directory))
1378 (let ((suff Info-suffix-list))
1379 (while (and suff (or (<= (length file) (length (car (car suff))))
1380 (not (equal (substring file
1381 (- (length (car (car suff)))))
1382 (car (car suff))))))
1383 (setq suff (cdr suff)))
1384 (if (stringp (cdr (car suff)))
1385 (let ((command (if (string-match "%s" (cdr (car suff)))
1386 (format (cdr (car suff)) file)
1387 (concat (cdr (car suff)) " < " file))))
1388 (message "%s..." command)
1389 (call-process shell-file-name nil t nil "-c" command)
1392 (setq buffer-file-name file)
1393 (set-buffer-modified-p nil)
1394 (clear-visited-file-modtime)))
1395 (insert-file-contents file visit))))
1397 (defun Info-select-node ()
1398 "Select the node that point is in, after using `g *' to select whole file."
1402 ;; Find beginning of node.
1403 (search-backward "\n\^_")
1405 ;; Get nodename spelled as it is in the node.
1406 (re-search-forward "Node:[ \t]*")
1407 (setq Info-current-node
1408 (buffer-substring (point)
1410 (skip-chars-forward "^,\t\n")
1412 (Info-set-mode-line)
1413 ;; Find the end of it, and narrow.
1415 (let (active-expression)
1416 (narrow-to-region (point)
1417 (if (re-search-forward "\n[\^_\f]" nil t)
1420 (if (looking-at "[\n\^_\f]*execute: ")
1422 (goto-char (match-end 0))
1423 (setq active-expression
1424 (read (current-buffer))))))
1426 (or (equal Info-footnote-tag "Note")
1428 (goto-char (point-min))
1429 (let ((buffer-read-only nil)
1430 (bufmod (buffer-modified-p))
1431 (case-fold-search t))
1432 (while (re-search-forward "\\*[Nn]ote\\([ \n]\\)" nil t)
1433 (replace-match (concat "*" Info-footnote-tag "\ ")))
1434 (set-buffer-modified-p bufmod))))
1435 (Info-reannotate-node)
1436 ;; XEmacs: remove v19 test
1438 (Info-fontify-node))
1439 (run-hooks 'Info-select-hook)
1440 (if Info-enable-active-nodes (eval active-expression)))))
1442 (defun Info-set-mode-line ()
1443 (setq modeline-buffer-identification
1444 (list (cons modeline-buffer-id-left-extent "Info: ")
1445 (cons modeline-buffer-id-right-extent
1448 (if Info-current-file
1449 (let ((name (file-name-nondirectory Info-current-file)))
1450 (if (string-match "\\.info$" name)
1451 (substring name 0 -5)
1455 (or Info-current-node ""))))))
1457 ;; Go to an info node specified with a filename-and-nodename string
1458 ;; of the sort that is found in pointers in nodes.
1461 (defun Info-goto-node (nodename &optional no-going-back tryfile)
1462 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
1463 Actually, the following interpretations of NAME are tried in order:
1465 (FILENAME) (using Top node)
1466 NODENAME (in current file)
1468 FILENAME (using Top node)
1469 where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
1470 annotation for any node of any file. (See `a' and `x' commands.)"
1471 (interactive (list (Info-read-node-name "Goto node, file or tag: ")
1474 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1476 (setq filename (if (= (match-beginning 1) (match-end 1))
1478 (substring nodename (match-beginning 2) (match-end 2)))
1479 nodename (substring nodename (match-beginning 3) (match-end 3)))
1480 (let ((trim (string-match "\\s *\\'" filename)))
1481 (if trim (setq filename (substring filename 0 trim))))
1482 (let ((trim (string-match "\\s *\\'" nodename)))
1483 (if trim (setq nodename (substring nodename 0 trim))))
1484 (Info-find-node (if (equal filename "") nil filename)
1485 (if (equal nodename "") "Top" nodename)
1486 no-going-back (and tryfile (equal filename "")))))
1488 (defun Info-goto-bookmark ()
1490 (let ((completion-ignore-case nil)
1491 (tag (completing-read "Goto tag: "
1492 (Info-build-annotation-completions)
1494 'Info-minibuffer-history)))
1495 (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
1498 (defun Info-visit-file (file)
1499 "Directly visit an info file."
1500 (interactive "fVisit Info file: ")
1501 (Info-find-node (expand-file-name file) "Top"))
1503 (defun Info-restore-point (&optional always)
1504 "Restore point to same location it had last time we were in this node."
1506 (if (or Info-restoring-point always)
1507 (let* ((name (format "(%s)%s"
1508 (Info-file-name-only Info-current-file)
1510 (p (assoc name Info-history)))
1511 (if p (Info-restore-history-entry p)))))
1513 (defun Info-restore-history-entry (entry)
1514 (goto-char (+ (nth 1 entry) (point-min)))
1516 (get-buffer-window (current-buffer))
1517 (set-window-start (get-buffer-window (current-buffer))
1518 (+ (nth 2 entry) (point-min)))))
1520 (defvar Info-read-node-completion-table)
1522 ;; This function is used as the "completion table" while reading a node name.
1523 ;; It does completion using the alist in Info-read-node-completion-table
1524 ;; unless STRING starts with an open-paren.
1525 (defun Info-read-node-name-1 (string predicate code)
1526 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
1527 (cond ((eq code nil)
1530 (try-completion string Info-read-node-completion-table predicate)))
1534 (all-completions string Info-read-node-completion-table predicate)))
1538 (assoc string Info-read-node-completion-table))))))
1540 (defun Info-read-node-name (prompt &optional default)
1541 (Info-setup-initial)
1542 (let* ((completion-ignore-case t)
1543 (Info-read-node-completion-table (Info-build-node-completions))
1544 (nodename (completing-read prompt 'Info-read-node-name-1
1545 nil t nil 'Info-minibuffer-history
1547 (if (equal nodename "")
1549 (Info-read-node-name prompt))
1552 (defun Info-build-annotation-completions ()
1553 (or Info-current-annotation-completions
1555 (let ((bufs (delq nil (mapcar 'get-file-buffer
1556 Info-annotations-path)))
1559 (set-buffer (car bufs))
1560 (goto-char (point-min))
1561 (while (re-search-forward "<<\\(.*\\)>>" nil t)
1562 (setq compl (cons (list (buffer-substring (match-beginning 1)
1565 (setq bufs (cdr bufs)))
1566 (setq Info-current-annotation-completions compl)))))
1568 (defun Info-build-node-completions ()
1569 (or Info-current-file-completions
1570 (let ((compl (Info-build-annotation-completions)))
1574 (if (marker-buffer Info-tag-table-marker)
1576 (set-buffer (marker-buffer Info-tag-table-marker))
1577 (goto-char Info-tag-table-marker)
1578 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
1580 (cons (list (buffer-substring (match-beginning 1)
1583 (goto-char (point-min))
1584 (while (search-forward "\n\^_" nil t)
1586 (let ((beg (point)))
1588 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
1591 (cons (list (buffer-substring (match-beginning 1)
1594 (setq Info-current-file-completions compl))))
1596 (defvar Info-last-search nil
1597 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1601 (defun Info-search (regexp)
1602 "Search for REGEXP, starting from point, and select node it's found in."
1604 (read-from-minibuffer
1605 (if Info-last-search
1606 (format "Search (regexp, default %s): "
1608 "Search (regexp): ")
1609 nil nil nil nil nil Info-last-search)))
1610 (setq Info-last-search regexp)
1611 (with-search-caps-disable-folding regexp t
1613 (onode Info-current-node)
1614 (ofile Info-current-file)
1616 (osubfile Info-current-subfile))
1620 (if (null Info-current-subfile)
1621 (progn (re-search-forward regexp) (setq found (point)))
1623 (progn (re-search-forward regexp) (setq found (point)))
1624 (search-failed nil)))))
1625 (if (not found) ;can only happen in subfile case -- else would have erred
1628 (set-buffer (marker-buffer Info-tag-table-marker))
1629 (goto-char (point-min))
1630 (search-forward "\n\^_\nIndirect:")
1632 (narrow-to-region (point)
1633 (progn (search-forward "\n\^_")
1635 (goto-char (point-min))
1636 (search-forward (concat "\n" osubfile ": "))
1639 (re-search-forward "\\(^.*\\): [0-9]+$")
1640 (goto-char (+ (match-end 1) 2))
1641 (setq list (cons (cons (read (current-buffer))
1642 (buffer-substring (match-beginning 1)
1645 (goto-char (1+ (match-end 0))))
1646 (setq list (nreverse list)
1649 (message "Searching subfile %s..." (cdr (car list)))
1650 (Info-read-subfile (car (car list)))
1651 (setq list (cdr list))
1652 (goto-char (point-min))
1653 (if (re-search-forward regexp nil t)
1654 (setq found (point) list ())))
1657 (signal 'search-failed (list regexp))))
1659 (progn (Info-read-subfile opoint)
1661 (Info-select-node)))))
1665 (or (and (equal onode Info-current-node)
1666 (equal ofile Info-current-file))
1667 (Info-history-add ofile onode opoint)))))
1669 ;; Extract the value of the node-pointer named NAME.
1670 ;; If there is none, use ERRORNAME in the error message;
1671 ;; if ERRORNAME is nil, just return nil.
1672 (defun Info-extract-pointer (name &optional errorname)
1674 (goto-char (point-min))
1676 (let ((case-fold-search t))
1677 (if (re-search-backward (concat name ":") nil t)
1679 (goto-char (match-end 0))
1680 (Info-following-node-name))
1681 (if (eq errorname t)
1683 (error (concat "Node has no " (capitalize (or errorname name)))))))))
1685 ;; Return the node name in the buffer following point.
1686 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1687 ;; saying which chas may appear in the node name.
1688 (defun Info-following-node-name (&optional allowedchars)
1689 (skip-chars-forward " \t")
1693 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1694 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1695 (if (looking-at "(")
1696 (skip-chars-forward "^)")))
1697 (skip-chars-backward " .")
1700 (defun Info-next (&optional n)
1701 "Go to the next node of this node.
1702 A positive or negative prefix argument moves by multiple nodes."
1707 (while (>= (setq n (1- n)) 0)
1708 (Info-goto-node (Info-extract-pointer "next")))))
1710 (defun Info-prev (&optional n)
1711 "Go to the previous node of this node.
1712 A positive or negative prefix argument moves by multiple nodes."
1717 (while (>= (setq n (1- n)) 0)
1718 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
1720 (defun Info-up (&optional n)
1721 "Go to the superior node of this node.
1722 A positive prefix argument moves up several times."
1725 (while (>= (setq n (1- n)) 0)
1726 (Info-goto-node (Info-extract-pointer "up")))
1727 (if (interactive-p) (Info-restore-point)))
1729 (defun Info-last (&optional n)
1730 "Go back to the last node visited.
1731 With a prefix argument, go to Nth most recently visited node. History is
1732 circular; after oldest node, history comes back around to most recent one.
1733 Argument can be negative to go through the circle in the other direction.
1734 \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
1738 (error "This is the first Info node you looked at"))
1739 (let ((len (1+ (length Info-history))))
1740 (setq n (% (+ n (* len 100)) len)))
1742 (let ((entry (nth (1- n) Info-history)))
1743 (Info-history-add Info-current-file Info-current-node (point))
1744 (while (>= (setq n (1- n)) 0)
1745 (setq Info-history (nconc (cdr Info-history)
1746 (list (car Info-history)))))
1747 (setq Info-history (cdr Info-history))
1748 (let ((Info-keeping-history nil))
1749 (Info-goto-node (car entry)))
1750 (Info-restore-history-entry entry))))
1752 (defun Info-directory ()
1753 "Go to the Info directory node."
1755 (Info-find-node "dir" "top"))
1757 (defun Info-follow-reference (footnotename)
1758 "Follow cross reference named NAME to the node it refers to.
1759 NAME may be an abbreviation of the reference name."
1761 (let ((completion-ignore-case t)
1762 completions default (start-point (point)) str i)
1764 (goto-char (point-min))
1765 (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
1768 (setq str (buffer-substring
1771 ;; See if this one should be the default.
1773 (< (match-beginning 0) start-point)
1774 (<= start-point (point))
1777 (while (setq i (string-match "[ \n\t]+" str i))
1778 (setq str (concat (substring str 0 i) " "
1779 (substring str (match-end 0))))
1781 ;; Record as a completion and perhaps as default.
1782 (if (eq default t) (setq default str))
1784 (cons (cons str nil)
1787 (let ((item (completing-read (if default
1788 (concat "Follow reference named: ("
1790 "Follow reference named: ")
1791 completions nil t nil
1792 'Info-minibuffer-history
1794 (if (and (string= item "") default)
1797 (error "No cross-references in this node"))))
1798 (let (target i (str (concat "\\*" Info-footnote-tag " "
1799 (regexp-quote footnotename))))
1800 (while (setq i (string-match " " str i))
1801 (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
1802 (substring str (1+ i))))
1805 (goto-char (point-min))
1806 (or (re-search-forward str nil t)
1807 (error "No cross-reference named %s" footnotename))
1808 (goto-char (match-end 1))
1810 (Info-extract-menu-node-name "Bad format cross reference" t)))
1811 (while (setq i (string-match "[ \t\n]+" target i))
1812 (setq target (concat (substring target 0 i) " "
1813 (substring target (match-end 0))))
1815 (Info-goto-node target)
1816 (setq Info-in-cross-reference t)))
1818 (defun Info-next-reference (n)
1820 (let ((pat (format "\\*%s[ \n\t]*\\([^:]*\\):\\|^\\* .*:\\|<<.*>>"
1823 wrapped found-nomenu)
1825 (unless (re-search-backward pat nil t)
1826 ;; Don't wrap more than once in a buffer where only the
1827 ;; menu references are found.
1828 (when (and wrapped (not found-nomenu))
1830 (error "No cross references in this node"))
1832 (goto-char (point-max))
1833 (unless (re-search-backward pat nil t)
1835 (error "No cross references in this node")))
1836 (unless (save-excursion
1837 (goto-char (match-beginning 0))
1838 (when (looking-at "\\* Menu:")
1840 (setq found-nomenu t))
1843 (or (eobp) (forward-char 1))
1844 (unless (re-search-forward pat nil t)
1845 (when (and wrapped (not found-nomenu))
1847 (error "No cross references in this node"))
1849 (goto-char (point-min))
1850 (unless (re-search-forward pat nil t)
1852 (error "No cross references in this node")))
1853 (unless (save-excursion
1854 (goto-char (match-beginning 0))
1855 (when (looking-at "\\* Menu:")
1857 (setq found-nomenu t))
1859 (when (looking-at "\\* Menu:")
1860 (error "No cross references in this node"))
1861 (goto-char (match-beginning 0))))
1863 (defun Info-prev-reference (n)
1865 (Info-next-reference (- n)))
1867 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1868 (skip-chars-forward " \t\n")
1871 (skip-chars-forward "^:")
1874 (if (looking-at ":")
1875 (buffer-substring beg (1- (point)))
1876 (skip-chars-forward " \t\n")
1878 ;; Allow dots in node name not followed by whitespace.
1880 (concat "\\(([^)]+)[^."
1881 (if multi-line "" "\n")
1883 (if multi-line "" "\n")
1884 ;; We consider dots followed by newline as
1885 ;; end of nodename even if multil-line.
1886 ;; Also stops at .). It is generated by @pxref.
1887 ;; Skips sequential dots.
1888 "]\\|\\.+[^ \t\n)]\\)+\\)"))
1890 (while (setq i (string-match "\n" str i))
1894 (defun Info-menu (menu-item)
1895 "Go to node for menu item named (or abbreviated) NAME.
1896 Completion is allowed, and the menu item point is on is the default."
1898 (let ((completions '())
1899 ;; If point is within a menu item, use that item as the default
1904 (goto-char (point-min))
1905 (let ((case-fold-search t))
1906 (if (not (search-forward "\n* menu:" nil t))
1907 (error "No menu in this node")))
1908 (while (re-search-forward
1909 "\n\\* \\([^:\t\n]*\\):" nil t)
1910 (if (and (null default)
1911 (prog1 (if last (< last p) nil)
1912 (setq last (match-beginning 0)))
1914 (setq default (car (car completions))))
1915 (setq completions (cons (cons (buffer-substring
1918 (match-beginning 1))
1920 (if (and (null default) last
1922 (<= p (progn (end-of-line) (point))))
1923 (setq default (car (car completions)))))
1926 (setq item (let ((completion-ignore-case t))
1927 (completing-read (if default
1928 (format "Menu item (default %s): "
1931 completions nil t nil
1932 'Info-minibuffer-history
1934 ;; we rely on the fact that completing-read accepts an input
1935 ;; of "" even when the require-match argument is true and ""
1936 ;; is not a valid possibility
1937 (if (string= item "")
1943 ;; there is a problem here in that if several menu items have the same
1944 ;; name you can only go to the node of the first with this command.
1945 (Info-goto-node (Info-extract-menu-item menu-item) nil t))
1947 (defun Info-extract-menu-item (menu-item &optional noerror)
1949 (goto-char (point-min))
1950 (if (let ((case-fold-search t))
1951 (search-forward "\n* menu:" nil t))
1952 (if (or (search-forward (concat "\n* " menu-item ":") nil t)
1953 (search-forward (concat "\n* " menu-item) nil t))
1957 (Info-extract-menu-node-name))
1958 (and (not noerror) (error "No such item in menu")))
1959 (and (not noerror) (error "No menu in this node")))))
1961 ;; If COUNT is nil, use the last item in the menu.
1962 (defun Info-extract-menu-counting (count &optional noerror noindex)
1964 (goto-char (point-min))
1965 (if (let ((case-fold-search t))
1966 (and (search-forward "\n* menu:" nil t)
1968 (not (string-match "\\<Index\\>" Info-current-node)))))
1969 (if (search-forward "\n* " nil t count)
1972 (while (search-forward "\n* " nil t)))
1973 (Info-extract-menu-node-name))
1974 (and (not noerror) (error "Too few items in menu")))
1975 (and (not noerror) (error "No menu in this node")))))
1977 (defun Info-nth-menu-item (n)
1978 "Go to the node of the Nth menu item."
1980 (or n (setq n (- last-command-char ?0)))
1981 (if (< n 1) (error "Index must be at least 1"))
1982 (Info-goto-node (Info-extract-menu-counting n) nil t))
1984 (defun Info-last-menu-item ()
1985 "Go to the node of the tenth menu item."
1987 (Info-goto-node (Info-extract-menu-counting nil) nil t))
1990 "Go to the Top node of this file."
1992 (Info-goto-node "Top"))
1995 "Go to the final node in this file."
1998 (let ((Info-keeping-history nil)
2000 (Info-last-menu-item)
2001 (while (setq node (or (Info-extract-pointer "next" t)
2002 (Info-extract-menu-counting nil t t)))
2003 (Info-goto-node node))
2004 (or (equal (Info-extract-pointer "up" t) "Top")
2005 (let ((executing-kbd-macro "")) ; suppress messages
2007 (Info-global-next 10000)
2010 (defun Info-global-next (&optional n)
2011 "Go to the next node in this file, traversing node structure as necessary.
2012 This works only if the Info file is structured as a hierarchy of nodes.
2013 A positive or negative prefix argument moves by multiple nodes."
2017 (Info-global-prev (- n))
2018 (while (>= (setq n (1- n)) 0)
2020 (cond ((and (string-match "^Top$" Info-current-node)
2021 (setq node (Info-extract-pointer "next" t))
2022 (Info-extract-menu-item node t))
2023 (Info-goto-node node))
2024 ((setq node (Info-extract-menu-counting 1 t t))
2025 (message "Going down...")
2026 (Info-goto-node node))
2028 (let ((Info-keeping-history Info-keeping-history)
2029 (orignode Info-current-node)
2031 (while (not (Info-extract-pointer "next" t))
2032 (if (and (setq node (Info-extract-pointer "up" t))
2033 (not (equal node "Top")))
2035 (message "Going%s..." (setq ups (concat ups " up")))
2036 (Info-goto-node node)
2037 (setq Info-keeping-history nil))
2039 (let ((Info-keeping-history nil))
2040 (Info-goto-node orignode)))
2041 (error "Last node in file")))
2044 (defun Info-page-next (&optional n)
2045 "Scroll forward one screenful, or go to next global node.
2046 A positive or negative prefix argument moves by multiple screenfuls."
2050 (Info-page-prev (- n))
2051 (while (>= (setq n (1- n)) 0)
2052 (if (pos-visible-in-window-p (point-max))
2055 (message "Node: %s" Info-current-node))
2058 (defun Info-scroll-next (arg)
2060 (if Info-auto-advance
2061 (if (and (pos-visible-in-window-p (point-max))
2062 (not (eq Info-auto-advance t))
2063 (not (eq last-command this-command)))
2064 (message "Hit %s again to go to next node"
2065 (if (= last-command-char 0)
2067 (key-description (char-to-string last-command-char))))
2069 (setq this-command 'Info))
2072 (defun Info-global-prev (&optional n)
2073 "Go to the previous node in this file, traversing structure as necessary.
2074 This works only if the Info file is structured as a hierarchy of nodes.
2075 A positive or negative prefix argument moves by multiple nodes."
2079 (Info-global-next (- n))
2080 (while (>= (setq n (1- n)) 0)
2081 (let ((upnode (Info-extract-pointer "up" t))
2082 (prevnode (Info-extract-pointer "prev[ious]*" t)))
2083 (if (or (not prevnode)
2084 (equal prevnode upnode))
2085 (if (string-match "^Top$" Info-current-node)
2086 (error "First node in file")
2087 (message "Going up...")
2089 (Info-goto-node prevnode)
2091 (Info-keeping-history nil)
2093 (while (setq node (Info-extract-menu-counting nil t t))
2094 (message "Going%s..." (setq downs (concat downs " down")))
2095 (Info-goto-node node))))))))
2097 (defun Info-page-prev (&optional n)
2098 "Scroll backward one screenful, or go to previous global node.
2099 A positive or negative prefix argument moves by multiple screenfuls."
2103 (Info-page-next (- n))
2104 (while (>= (setq n (1- n)) 0)
2105 (if (pos-visible-in-window-p (point-min))
2108 (message "Node: %s" Info-current-node)
2109 (goto-char (point-max))
2111 (move-to-window-line 0))
2114 (defun Info-scroll-prev (arg)
2116 (if Info-auto-advance
2117 (if (and (pos-visible-in-window-p (point-min))
2118 (not (eq Info-auto-advance t))
2119 (not (eq last-command this-command)))
2120 (message "Hit %s again to go to previous node"
2121 (if (mouse-event-p last-command-event)
2123 (key-description (event-key last-command-event))))
2125 (setq this-command 'Info))
2128 (defun Info-index (topic)
2129 "Look up a string in the index for this file.
2130 The index is defined as the first node in the top-level menu whose
2131 name contains the word \"Index\", plus any immediately following
2132 nodes whose names also contain the word \"Index\".
2133 If there are no exact matches to the specified topic, this chooses
2134 the first match which is a case-insensitive substring of a topic.
2135 Use the `,' command to see the other matches.
2136 Give a blank topic name to go to the Index node itself."
2137 (interactive "sIndex topic: ")
2138 (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
2139 (regexp-quote topic)
2140 "\\(.*\\)\\.[ t]*\\([0-9]*\\)$"))
2142 (message "Searching index for `%s'..." topic)
2143 (Info-goto-node "Top")
2144 (let ((case-fold-search t))
2145 (or (search-forward "\n* menu:" nil t)
2147 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2148 (error "No index")))
2149 (goto-char (match-beginning 1))
2150 (let ((Info-keeping-history nil)
2151 (Info-fontify (and Info-fontify (equal topic ""))))
2152 (Info-goto-node (Info-extract-menu-node-name)))
2153 (or (equal topic "")
2156 (Info-keeping-history nil)
2160 (goto-char (point-min))
2161 (while (re-search-forward pattern nil t)
2163 (cons (list (buffer-substring (match-beginning 1)
2165 (buffer-substring (match-beginning 2)
2168 (string-to-int (concat "0"
2173 (and (setq node (Info-extract-pointer "next" t))
2174 (string-match "\\<Index\\>" node)))
2175 (let ((Info-fontify nil))
2176 (Info-goto-node node)))
2180 (error "No \"%s\" in index" topic)))
2181 ;; Here it is a feature that assoc is case-sensitive.
2182 (while (setq found (assoc topic matches))
2183 (setq exact (cons found exact)
2184 matches (delq found matches)))
2185 (setq Info-index-alternatives (nconc exact (nreverse matches))
2186 Info-index-first-alternative (car Info-index-alternatives))
2187 (Info-index-next 0)))))
2189 (defun Info-index-next (num)
2190 "Go to the next matching index item from the last `i' command."
2192 (or Info-index-alternatives
2193 (error "No previous `i' command in this file"))
2195 (setq num (+ num (length Info-index-alternatives))))
2197 (setq Info-index-alternatives
2198 (nconc (cdr Info-index-alternatives)
2199 (list (car Info-index-alternatives)))
2201 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2202 (if (> (nth 3 (car Info-index-alternatives)) 0)
2203 (forward-line (nth 3 (car Info-index-alternatives)))
2204 (forward-line 3) ; don't search in headers
2205 (let ((name (car (car Info-index-alternatives))))
2206 (if (or (re-search-forward (format
2207 "\\(Function\\|Command\\): %s\\( \\|$\\)"
2208 (regexp-quote name)) nil t)
2209 (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
2210 (search-forward (format "`%s'" name) nil t)
2211 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2213 (format "`%s'" (substring name 0 (match-beginning 1)))
2215 (search-forward name nil t))
2217 (goto-char (point-min)))))
2218 (message "Found \"%s\" in %s. %s"
2219 (car (car Info-index-alternatives))
2220 (nth 2 (car Info-index-alternatives))
2221 (if (cdr Info-index-alternatives)
2222 (if (eq (car (cdr Info-index-alternatives))
2223 Info-index-first-alternative)
2224 "(Press `,' to repeat)"
2225 (format "(Press `,' for %d more)"
2226 (- (1- (length Info-index-alternatives))
2227 (length (memq Info-index-first-alternative
2228 (cdr Info-index-alternatives))))))
2233 (defun Info-emacs-command (command)
2234 "Look up an Emacs command in the Emacs manual in the Info system.
2235 This command is designed to be used whether you are already in Info or not."
2236 (interactive "CLook up command in Emacs manual: ")
2237 (save-window-excursion
2239 (Info-find-node Info-emacs-info-file-name "Top")
2240 (Info-index (symbol-name command)))
2241 (pop-to-buffer "*info*"))
2245 (defun Info-goto-emacs-command-node (key)
2246 "Look up an Emacs command in the Emacs manual in the Info system.
2247 This command is designed to be used whether you are already in Info or not."
2248 (interactive "CLook up command in Emacs manual: ")
2249 (Info-emacs-command key))
2252 (defun Info-goto-emacs-key-command-node (key)
2253 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2254 This command is designed to be used whether you are already in Info or not."
2255 (interactive "kLook up key in Emacs manual: ")
2256 (let ((command (key-binding key)))
2257 (cond ((eq command 'keyboard-quit)
2260 (error "%s is undefined" (key-description key)))
2261 ((and (interactive-p) (eq command 'execute-extended-command))
2262 (call-interactively 'Info-goto-emacs-command-node))
2264 (Info-goto-emacs-command-node command)))))
2267 (defun Info-emacs-key (key)
2268 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2269 This command is designed to be used whether you are already in Info or not."
2270 (interactive "kLook up key in Emacs manual: ")
2271 (cond ((eq (key-binding key) 'keyboard-quit)
2273 ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
2274 (call-interactively 'Info-goto-emacs-command-node))
2276 (save-window-excursion
2278 (Info-find-node Info-emacs-info-file-name "Top")
2279 (setq key (key-description key))
2281 (if (setq p (string-match "[@{}]" key))
2282 (setq key (concat (substring key 0 p) "@" (substring key p))))
2283 (if (string-match "^ESC " key)
2284 (setq key (concat "M-" (substring key 4))))
2285 (if (string-match "^M-C-" key)
2286 (setq key (concat "C-M-" (substring key 4)))))
2288 (pop-to-buffer "*info*"))))
2291 (defun Info-elisp-ref (func)
2292 "Look up an Emacs Lisp function in the Elisp manual in the Info system.
2293 This command is designed to be used whether you are already in Info or not."
2294 (interactive (let ((fn (function-at-point))
2295 (enable-recursive-minibuffers t)
2297 (setq val (completing-read
2298 (format "Look up Emacs Lisp function%s: "
2300 (format " (default %s)" fn)
2302 obarray 'fboundp t))
2303 (list (if (equal val "")
2305 (save-window-excursion
2308 (Info-find-node "lispref" "Top")
2309 (error (Info-find-node "elisp" "Top")))
2310 (Info-index (symbol-name func)))
2311 (pop-to-buffer "*info*"))
2313 (defun Info-reannotate-node ()
2314 (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
2316 (let ((ibuf (current-buffer))
2317 (file (concat "\\(" (regexp-quote
2318 (file-name-nondirectory Info-current-file))
2319 "\\|" (regexp-quote Info-current-file) "\\)"))
2320 (node (regexp-quote Info-current-node))
2322 (goto-char (point-min))
2323 (if (search-forward "\n------ NOTE:\n" nil t)
2324 (let ((buffer-read-only nil)
2325 (bufmod (buffer-modified-p))
2327 (setq savept (copy-marker savept))
2328 (goto-char (point-min))
2329 (while (search-forward "\n------ NOTE:" nil t)
2330 (setq top (1+ (match-beginning 0)))
2331 (if (search-forward "\n------\n" nil t)
2332 (delete-region top (point)))
2334 (set-buffer-modified-p bufmod)))
2337 (set-buffer (car bufs))
2338 (goto-char (point-min))
2339 (while (re-search-forward
2341 "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
2344 (let ((line (string-to-int
2345 (buffer-substring (match-beginning 2)
2349 (search-forward "\n------\n" nil t)
2353 (if (integerp savept) (setq savept (copy-marker savept)))
2355 (goto-char (point-max))
2356 (goto-char (point-min))
2357 (forward-line line))
2358 (let ((buffer-read-only nil)
2359 (bufmod (buffer-modified-p)))
2360 (insert "------ NOTE:\n")
2361 (insert-buffer-substring (car bufs) top bot)
2362 (set-buffer-modified-p bufmod)))))
2363 (setq bufs (cdr bufs))))
2364 (goto-char savept)))))
2366 (defvar Info-annotate-map nil
2367 "Local keymap used within `a' command of Info.")
2368 (if Info-annotate-map
2370 ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
2371 (setq Info-annotate-map (copy-keymap text-mode-map))
2372 (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
2374 (defun Info-annotate-mode ()
2375 "Major mode for adding an annotation to an Info node.
2376 Like text mode with the addition of Info-cease-annotate
2377 which returns to Info mode for browsing.
2378 \\{Info-annotate-map}")
2380 (defun Info-annotate (arg)
2381 "Add a personal annotation to the current Info node.
2382 Only you will be able to see this annotation. Annotations are stored
2383 in the file \"~/.xemacs/info.notes\" by default. If point is inside
2384 an existing annotation, edit that annotation. A prefix argument
2385 specifies which annotations file (from `Info-annotations-path') is to
2386 be edited; default is 1."
2389 (if (or (< arg 0) (not (nth arg Info-annotations-path)))
2391 (setq Info-annotations-path
2392 (list (read-file-name
2393 "Annotations file: " "~/" "~/.infonotes")))
2394 (error "File number must be in the range from 1 to %d"
2395 (length Info-annotations-path))))
2397 (file (file-name-nondirectory Info-current-file))
2398 (d Info-directory-list)
2400 (while (and d (not (equal (expand-file-name file (car d))
2401 Info-current-file)))
2403 (or d (setq file Info-current-file))
2404 (if (and (save-excursion
2405 (goto-char (min (point-max) (+ (point) 13)))
2406 (and (search-backward "------ NOTE:\n" nil t)
2407 (setq pt (match-end 0))
2408 (search-forward "\n------\n" nil t)))
2409 (< (point) (match-end 0)))
2410 (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
2412 (regexp-quote Info-current-node)
2414 (buffer-substring pt (match-beginning 0))))
2415 where (max (- (point) pt) 0)))
2416 (let ((node Info-current-node)
2417 (line (if (looking-at "[ \n]*\\'") 0
2418 (count-lines (point-min) (point)))))
2420 (let ((buffer-read-only nil)
2421 (bufmod (buffer-modified-p)))
2423 (if (bobp) (goto-char (point-max)))
2424 (insert "------ NOTE:\n------\n")
2426 (set-buffer-modified-p bufmod)))
2427 ;; (setq Info-window-start (window-start))
2428 (setq Info-window-configuration (current-window-configuration))
2429 (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
2430 (use-local-map Info-annotate-map)
2431 (setq major-mode 'Info-annotate-mode)
2432 (setq mode-name "Info Annotate")
2435 (goto-char (point-min))
2436 (re-search-forward which nil t))
2438 (goto-char (match-beginning 0))
2440 (forward-char where)))
2441 (let ((bufmod (buffer-modified-p)))
2442 (goto-char (point-max))
2443 (insert (format "\n------ File: %s Node: %s Line: %d\n"
2446 (insert "\n------\n"
2447 "\nPress C-c C-c to save and return to Info.\n")
2449 (set-buffer-modified-p bufmod))))))
2451 (defun Info-cease-annotate ()
2453 (let ((bufmod (buffer-modified-p)))
2454 (while (save-excursion
2455 (goto-char (point-min))
2456 (re-search-forward "\n\n?Press .* to save and return to Info.\n"
2458 (delete-region (1+ (match-beginning 0)) (match-end 0)))
2459 (while (save-excursion
2460 (goto-char (point-min))
2461 (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
2463 (delete-region (match-beginning 0) (match-end 0)))
2464 (set-buffer-modified-p bufmod))
2468 (or (one-window-p) (delete-window))
2470 (setq Info-current-annotation-completions nil)
2471 (set-window-configuration Info-window-configuration)
2472 (Info-reannotate-node))
2474 (defun Info-bookmark (arg tag)
2475 (interactive "p\nsBookmark name: ")
2477 (if (or (string-match "^\"\\(.*\\)\"$" tag)
2478 (string-match "^<<\\(.*\\)>>$" tag))
2479 (setq tag (substring tag (match-beginning 1) (match-end 1))))
2481 (search-forward "\n------\n")
2482 (let ((end (- (point) 8)))
2484 (if (re-search-forward "<<[^>\n]*>>" nil t)
2485 (delete-region (match-beginning 0) (match-end 0))
2488 (insert "<<" tag ">>"))))
2489 (Info-cease-annotate))
2492 "Exit Info by selecting some other buffer."
2495 (save-buffers-kill-emacs)
2496 (bury-buffer (current-buffer))
2497 (if (and (featurep 'toolbar)
2498 (boundp 'toolbar-info-frame)
2499 (eq toolbar-info-frame (selected-frame)))
2501 (delete-frame toolbar-info-frame)
2502 (error (bury-buffer)))
2503 (switch-to-buffer (other-buffer (current-buffer))))))
2505 (defun Info-undefined ()
2506 "Make command be undefined in Info."
2511 "Enter the Info tutorial."
2513 (delete-other-windows)
2514 (Info-find-node "info"
2515 (if (< (window-height) 23)
2519 (defun Info-summary ()
2520 "Display a brief summary of all Info commands."
2522 (save-window-excursion
2523 (switch-to-buffer "*Help*")
2525 (insert (documentation 'Info-mode))
2526 (goto-char (point-min))
2528 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2529 (message (if flag "Type Space to see more"
2530 "Type Space to return to Info"))
2531 (let ((e (next-command-event)))
2532 (if (/= ?\ (event-to-character e))
2533 (progn (setq unread-command-event e) nil)
2537 (bury-buffer "*Help*")))
2539 (defun Info-get-token (pos start all &optional errorstring)
2540 "Return the token around POS,
2541 POS must be somewhere inside the token
2542 START is a regular expression which will match the
2543 beginning of the tokens delimited string
2544 ALL is a regular expression with a single
2545 parenthized subpattern which is the token to be
2546 returned. E.g. '{\(.*\)}' would return any string
2547 enclosed in braces around POS.
2548 SIG optional fourth argument, controls action on no match
2551 a string: signal an error, using that string."
2553 (goto-char (point-min))
2554 (re-search-backward "\\`") ; Bug fix due to Nicholas J. Foskett.
2556 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
2558 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2559 (not (setq found (and (<= (match-beginning 0) pos)
2560 (> (match-end 0) pos))))))
2561 (if (and found (<= (match-beginning 0) pos)
2562 (> (match-end 0) pos))
2563 (buffer-substring (match-beginning 1) (match-end 1))
2564 (cond ((null errorstring)
2570 (error "No %s around position %d" errorstring pos)))))))
2572 (defun Info-follow-clicked-node (event)
2573 "Follow a node reference near clicked point. Like M, F, N, P or U command.
2574 At end of the node's text, moves to the next node."
2576 (or (and (event-point event)
2577 (Info-follow-nearest-node
2579 (select-window (event-window event))
2580 (event-point event))
2582 (error "click on a cross-reference to follow")))
2584 (defun Info-maybe-follow-clicked-node (event &optional click-count)
2585 "Follow a node reference (if any) near clicked point.
2586 Like M, F, N, P or U command. At end of the node's text, moves to the
2587 next node. No error is given if there is no node to follow."
2589 (and Info-button1-follows-hyperlink
2591 (Info-follow-nearest-node
2593 (select-window (event-window event))
2594 (event-point event))
2595 (1+ (point-min))))))
2597 (defun Info-find-nearest-node (point)
2600 ((= point (point-min)) nil) ; don't trigger on accidental RET.
2601 ((setq node (Info-get-token point
2602 (format "\\*%s[ \n]" Info-footnote-tag)
2603 (format "\\*%s[ \n]\\([^:]*\\):"
2604 Info-footnote-tag)))
2605 (list "Following cross-reference %s..."
2606 (list 'Info-follow-reference node)))
2607 ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\)::"))
2608 (list "Selecting menu item %s..."
2609 (list 'Info-goto-node node nil t)))
2610 ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\):"))
2611 (list "Selecting menu item %s..."
2612 (list 'Info-menu node)))
2613 ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
2615 (list 'Info-goto-node node)))
2616 ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
2617 (list "Next node..."
2618 (list 'Info-goto-node node)))
2619 ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
2621 (list 'Info-goto-node "Top")))
2622 ((setq node (Info-get-token point "Prev[ious]*: "
2623 "Prev[ious]*: \\([^,\n\t]*\\)"))
2624 (list "Previous node..."
2625 (list 'Info-goto-node node)))
2626 ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
2627 (list "Reselecting %s..."
2628 (list 'Info-goto-node node)))
2629 ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
2630 (if Info-in-cross-reference
2631 (list "Back to last node..."
2633 (list "Next node..."
2634 '(Info-global-next)))))
2637 (defun Info-follow-nearest-node (point)
2638 "Follow a node reference near point. Like M, F, N, P or U command.
2639 At end of the node's text, moves to the next node."
2641 (let ((data (Info-find-nearest-node point)))
2644 (let ((msg (format (car data) (nth 1 (nth 1 data)))))
2647 (message "%sdone" msg))
2650 (defun Info-indicated-node (event)
2653 (cond ((eventp event)
2654 (set-buffer (event-buffer event))
2655 (setq event (event-point event))))
2656 (let* ((data (Info-find-nearest-node event))
2657 (name (nth 1 (nth 1 data))))
2658 (and name (nth 1 data))))
2661 (defun Info-mouse-track-double-click-hook (event click-count)
2662 "Handle double-clicks by turning pages, like the `gv' ghostscript viewer"
2663 (if (/= click-count 2)
2664 ;; Return nil so any other hooks are performed.
2666 (let* ((fw (face-width 'default))
2667 (fh (face-height 'default))
2668 (x (/ (event-x-pixel event) fw))
2669 (y (/ (event-y-pixel event) fw))
2670 (w (/ (window-pixel-width (event-window event)) fw))
2671 (h (/ (window-pixel-height (event-window event)) fh))
2675 ((<= y by) (Info-up) t)
2676 ((>= y (- h by)) (Info-nth-menu-item 1) t)
2677 ((<= x bx) (Info-prev) t)
2678 ((>= x (- w bx)) (Info-next) t)
2681 (defvar Info-mode-map nil
2682 "Keymap containing Info commands.")
2685 (setq Info-mode-map (make-sparse-keymap))
2686 (suppress-keymap Info-mode-map)
2687 (define-key Info-mode-map "." 'beginning-of-buffer)
2688 (define-key Info-mode-map " " 'Info-scroll-next)
2689 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2690 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2691 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2692 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2693 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2694 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2695 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2696 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2697 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2698 (define-key Info-mode-map "0" 'Info-last-menu-item)
2699 (define-key Info-mode-map "?" 'Info-summary)
2700 (define-key Info-mode-map "a" 'Info-annotate)
2701 (define-key Info-mode-map "b" 'beginning-of-buffer)
2702 (define-key Info-mode-map "d" 'Info-directory)
2703 (define-key Info-mode-map "e" 'Info-edit)
2704 (define-key Info-mode-map "f" 'Info-follow-reference)
2705 (define-key Info-mode-map "g" 'Info-goto-node)
2706 (define-key Info-mode-map "h" 'Info-help)
2707 (define-key Info-mode-map "i" 'Info-index)
2708 (define-key Info-mode-map "j" 'Info-goto-bookmark)
2709 (define-key Info-mode-map "k" 'Info-emacs-key)
2710 (define-key Info-mode-map "l" 'Info-last)
2711 (define-key Info-mode-map "m" 'Info-menu)
2712 (define-key Info-mode-map "n" 'Info-next)
2713 (define-key Info-mode-map "p" 'Info-prev)
2714 (define-key Info-mode-map "q" 'Info-exit)
2715 (define-key Info-mode-map "r" 'Info-follow-reference)
2716 (define-key Info-mode-map "s" 'Info-search)
2717 (define-key Info-mode-map "t" 'Info-top)
2718 (define-key Info-mode-map "u" 'Info-up)
2719 (define-key Info-mode-map "v" 'Info-visit-file)
2720 (define-key Info-mode-map "x" 'Info-bookmark)
2721 (define-key Info-mode-map "<" 'Info-top)
2722 (define-key Info-mode-map ">" 'Info-end)
2723 (define-key Info-mode-map "[" 'Info-global-prev)
2724 (define-key Info-mode-map "]" 'Info-global-next)
2725 (define-key Info-mode-map "{" 'Info-page-prev)
2726 (define-key Info-mode-map "}" 'Info-page-next)
2727 (define-key Info-mode-map "=" 'Info-restore-point)
2728 (define-key Info-mode-map "!" 'Info-select-node)
2729 (define-key Info-mode-map "@" 'Info-follow-nearest-node)
2730 (define-key Info-mode-map "," 'Info-index-next)
2731 (define-key Info-mode-map "*" 'Info-elisp-ref)
2732 (define-key Info-mode-map [tab] 'Info-next-reference)
2733 (define-key Info-mode-map [(meta tab)] 'Info-prev-reference)
2734 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2735 (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
2737 (define-key Info-mode-map 'backspace 'Info-scroll-prev)
2738 (define-key Info-mode-map 'delete 'Info-scroll-prev)
2739 (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
2740 (define-key Info-mode-map 'button3 'Info-select-node-menu))
2743 ;; Info mode is suitable only for specially formatted data.
2744 (put 'info-mode 'mode-class 'special)
2747 "Info mode is for browsing through the Info documentation tree.
2748 Documentation in Info is divided into \"nodes\", each of which
2749 discusses one topic and contains references to other nodes
2750 which discuss related topics. Info has commands to follow
2751 the references and show you other nodes.
2753 h Invoke the Info tutorial.
2754 q Quit Info: return to the previously selected file or buffer.
2756 Selecting other nodes:
2757 n Move to the \"next\" node of this node.
2758 p Move to the \"previous\" node of this node.
2759 m Pick menu item specified by name (or abbreviation).
2760 1-9, 0 Pick first..ninth, last item in node's menu.
2761 Menu items select nodes that are \"subsections\" of this node.
2762 u Move \"up\" from this node (i.e., from a subsection to a section).
2763 f or r Follow a cross reference by name (or abbrev). Type `l' to get back.
2764 RET Follow cross reference or menu item indicated by cursor.
2765 i Look up a topic in this file's Index and move to that node.
2766 , (comma) Move to the next match from a previous `i' command.
2767 l (letter L) Move back to the last node you were in.
2769 Moving within a node:
2770 Space Scroll forward a full screen. DEL Scroll backward.
2771 b Go to beginning of node. Meta-> Go to end of node.
2772 TAB Go to next cross-reference. Meta-TAB Go to previous ref.
2775 Left Button Set point (usual text-mode functionality)
2776 Middle Button Click on a highlighted node reference to go to it.
2777 Right Button Pop up a menu of applicable Info commands.
2779 Left Button Double Click in window edges:
2780 Top edge: Go up to the parent node, like `u'.
2781 Left edge: Go to the previous node, like `p'.
2782 Right edge: Go to the next node, like `n'.
2783 Bottom edge: Follow first menu item, like `1'.
2786 g Move to node, file, or annotation tag specified by name.
2787 Examples: `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
2788 v Move to file, with filename completion.
2789 k Look up a key sequence in Emacs manual (also C-h C-k at any time).
2790 * Look up a function name in Emacs Lisp manual (also C-h C-f).
2791 d Go to the main directory of Info files.
2792 < or t Go to Top (first) node of this file.
2793 > Go to last node in this file.
2794 \[ Go to previous node, treating file as one linear document.
2795 \] Go to next node, treating file as one linear document.
2796 { Scroll backward, or go to previous node if at top.
2797 } Scroll forward, or go to next node if at bottom.
2798 = Restore cursor position from last time in this node.
2799 a Add a private note (annotation) to the current node.
2800 x, j Add, jump to a bookmark (annotation tag).
2801 s Search this Info file for a node containing the specified regexp.
2802 e Edit the contents of the current node."
2803 (kill-all-local-variables)
2804 (setq major-mode 'Info-mode)
2805 (setq mode-name "Info")
2806 (use-local-map Info-mode-map)
2807 (set-syntax-table text-mode-syntax-table)
2808 (setq local-abbrev-table text-mode-abbrev-table)
2809 (setq case-fold-search t)
2810 (setq buffer-read-only t)
2811 ; (setq buffer-mouse-map Info-mode-mouse-map)
2812 (make-local-variable 'Info-current-file)
2813 (make-local-variable 'Info-current-subfile)
2814 (make-local-variable 'Info-current-node)
2815 (make-local-variable 'Info-tag-table-marker)
2816 (make-local-variable 'Info-current-file-completions)
2817 (make-local-variable 'Info-current-annotation-completions)
2818 (make-local-variable 'Info-index-alternatives)
2819 (make-local-variable 'Info-history)
2820 ;; Faces are now defined by `defface'...
2821 (make-local-variable 'mouse-track-click-hook)
2822 (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
2823 (add-hook 'mouse-track-click-hook 'Info-mouse-track-double-click-hook)
2824 ;; #### The console-on-window-system-p check is to allow this to
2825 ;; work on tty's. The real problem here is that featurep really
2826 ;; needs to have some device/console domain knowledge added to it.
2827 (defvar info::toolbar)
2828 (if (and (featurep 'toolbar)
2829 (console-on-window-system-p)
2830 (not Info-inhibit-toolbar))
2831 (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
2832 (if (featurep 'menubar)
2834 ;; make a local copy of the menubar, so our modes don't
2835 ;; change the global menubar
2836 (easy-menu-add '("Info" :filter Info-menu-filter))))
2837 (run-hooks 'Info-mode-hook)
2838 (Info-set-mode-line))
2840 (defvar Info-edit-map nil
2841 "Local keymap used within `e' command of Info.")
2844 ;; XEmacs: remove FSF stuff
2845 (setq Info-edit-map (make-sparse-keymap))
2846 (set-keymap-name Info-edit-map 'Info-edit-map)
2847 (set-keymap-parents Info-edit-map (list text-mode-map))
2848 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
2850 ;; Info-edit mode is suitable only for specially formatted data.
2851 (put 'info-edit-mode 'mode-class 'special)
2853 (defun Info-edit-mode ()
2854 "Major mode for editing the contents of an Info node.
2855 Like text mode with the addition of `Info-cease-edit'
2856 which returns to Info mode for browsing.
2861 "Edit the contents of this Info node.
2862 Allowed only if variable `Info-enable-edit' is non-nil."
2864 (or Info-enable-edit
2865 (error "Editing info nodes is not enabled"))
2866 (use-local-map Info-edit-map)
2867 (setq major-mode 'Info-edit-mode)
2868 (setq mode-name "Info Edit")
2869 (kill-local-variable 'modeline-buffer-identification)
2870 (setq buffer-read-only nil)
2871 ;; Make mode line update.
2872 (set-buffer-modified-p (buffer-modified-p))
2873 (message (substitute-command-keys
2874 "Editing: Type \\[Info-cease-edit] to return to info")))
2876 (defun Info-cease-edit ()
2877 "Finish editing Info node; switch back to Info proper."
2879 ;; Do this first, so nothing has changed if user C-g's at query.
2880 (and (buffer-modified-p)
2881 (y-or-n-p-maybe-dialog-box "Save the file? ")
2883 (use-local-map Info-mode-map)
2884 (setq major-mode 'Info-mode)
2885 (setq mode-name "Info")
2886 (Info-set-mode-line)
2887 (setq buffer-read-only t)
2888 ;; Make mode line update.
2889 (set-buffer-modified-p (buffer-modified-p))
2890 (and (marker-position Info-tag-table-marker)
2892 (message "Tags may have changed. Use Info-tagify if necessary")))
2894 (defun Info-find-emacs-command-nodes (command)
2895 "Return a list of locations documenting COMMAND in the XEmacs Info manual.
2896 The locations are of the format used in Info-history, i.e.
2897 \(FILENAME NODENAME BUFFERPOS\)."
2899 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
2900 ":\\s *\\(.*\\)\\.$")))
2902 (Info-find-node "XEmacs" "Command Index")
2903 ;; Take the index node off the Info history.
2904 ;; ??? says this isn't safe someplace else... hmmm.
2905 (setq Info-history (cdr Info-history))
2906 (goto-char (point-max))
2907 (while (re-search-backward cmd-desc nil t)
2908 (setq where (cons (list Info-current-file
2916 ;;; fontification and mousability for info
2918 (defun Info-highlight-region (start end face)
2920 (splitp (string-match "\n[ \t]+" (buffer-substring start end))))
2923 (setq extent (make-extent start (progn (goto-char start)
2926 (set-extent-face extent face)
2927 (set-extent-property extent 'info t)
2928 (set-extent-property extent 'highlight t)
2929 (skip-chars-forward "\n\t ")
2930 (setq extent (make-extent (point) end)))
2931 (setq extent (make-extent start end)))
2932 (set-extent-face extent face)
2933 (set-extent-property extent 'info t)
2934 (set-extent-property extent 'highlight t)))
2936 (defun Info-fontify-node ()
2938 (let ((case-fold-search t)
2939 (xref-regexp (concat "\\*"
2940 (regexp-quote Info-footnote-tag)
2941 "[ \n\t]*\\([^:]*\\):")))
2942 ;; Clear the old extents
2943 (map-extents #'(lambda (x y) (delete-extent x))
2944 (current-buffer) (point-min) (point-max) nil)
2945 ;; Break the top line iff it is > 79 characters. Some info nodes
2946 ;; have top lines that span 3 lines because of long node titles.
2947 ;; eg: (Info-find-node "lispref.info" "Window-Level Event Position Info")
2948 (toggle-read-only -1)
2953 (goto-char (point-min))
2954 (re-search-forward "Node: *[^,]+, " nil t)
2955 (setq len (- (point) (point-min))
2956 extent (make-extent (point-min) (point)))
2957 (set-extent-property extent 'invisible t)
2961 (if (< (current-column) (+ 78 len))
2964 (forward-char (+ 79 len))
2965 (re-search-backward "," nil t)
2969 (backward-delete-char 1)
2972 (toggle-read-only 1)
2973 ;; Highlight xrefs in the top few lines of the node
2974 (goto-char (point-min))
2975 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
2977 (goto-char (match-end 0))
2979 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?\n?")
2980 (goto-char (match-end 0))
2981 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref))))
2982 ;; Now get the xrefs in the body
2983 (goto-char (point-min))
2984 (while (re-search-forward xref-regexp nil t)
2985 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2987 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref)))
2988 ;; then highlight the nodes in the menu.
2989 (goto-char (point-min))
2990 (if (and (search-forward "\n* menu:" nil t))
2991 (while (re-search-forward
2992 "^\\* \\([^:\t\n]*\\):?:[ \t\n]" nil t)
2993 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-node)))
2994 (set-buffer-modified-p nil))))
2996 (defun Info-construct-menu (&optional event)
2997 "Construct a menu of Info commands.
2998 Adds an entry for the node at EVENT, or under point if EVENT is omitted.
2999 Used to construct the menubar submenu and popup menu."
3000 (or event (setq event (point)))
3001 (let ((case-fold-search t)
3002 (xref-regexp (concat "\\*"
3003 (regexp-quote Info-footnote-tag)
3004 "[ \n\t]*\\([^:]*\\):"))
3005 up-p prev-p next-p menu xrefs subnodes in)
3007 ;; `one-space' fixes "Notes:" xrefs that are split across lines.
3011 (while (setq i (string-match "[ \n\t]+" text i))
3012 (setq text (concat (substring text 0 i) " "
3013 (substring text (match-end 0))))
3016 (goto-char (point-min))
3017 (if (looking-at ".*\\bNext:") (setq next-p t))
3018 (if (looking-at ".*\\bPrev:") (setq prev-p t))
3019 (if (looking-at ".*Up:") (setq up-p t))
3021 (if (setq in (Info-indicated-node event))
3022 (list (vector (one-space (cadr in)) in t)
3023 "--:shadowEtchedIn"))
3025 ["Goto Info Top-level" Info-directory]
3026 (vector "Next Node" 'Info-next :active next-p)
3027 (vector "Previous Node" 'Info-prev :active prev-p)
3028 (vector "Parent Node (Up)" 'Info-up :active up-p)
3029 ["Goto Node..." Info-goto-node]
3030 ["Goto Last Visited Node " Info-last])))
3031 ;; Find the xrefs and make a list
3032 (while (re-search-forward xref-regexp nil t)
3033 (setq xrefs (cons (one-space (buffer-substring (match-beginning 1)
3036 (setq xrefs (nreverse xrefs))
3037 (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
3038 ;; Find the subnodes and make a list
3039 (goto-char (point-min))
3040 (if (search-forward "\n* menu:" nil t)
3041 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
3042 (setq subnodes (cons (buffer-substring (match-beginning 1)
3045 (setq subnodes (nreverse subnodes))
3046 (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more))))
3048 (nconc menu (list "--:shadowDoubleEtchedIn"
3051 (mapcar #'(lambda (xref)
3055 (list 'Info-follow-reference xref))))
3058 (nconc menu (list "--:shadowDoubleEtchedIn"
3061 (mapcar #'(lambda (node)
3064 (vector node (list 'Info-menu node))))
3068 (defun Info-menu-filter (menu)
3069 "This is the menu filter for the \"Info\" submenu."
3070 (Info-construct-menu))
3072 (defun Info-select-node-menu (event)
3073 "Pops up a menu of applicable Info commands."
3075 (select-window (event-window event))
3076 (let ((menu (Info-construct-menu event)))
3077 (setq menu (nconc (list "Info" ; title: not displayed
3079 "--:shadowDoubleEtchedOut")
3081 (let ((popup-menu-titles nil))
3082 (popup-menu menu))))
3084 ;;; Info toolbar support
3086 ;; exit icon taken from GNUS
3087 (defvar info::toolbar-exit-icon
3088 (if (featurep 'toolbar)
3089 (toolbar-make-button-list
3090 (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
3091 toolbar-icon-directory)))
3094 (defvar info::toolbar-up-icon
3095 (if (featurep 'toolbar)
3096 (toolbar-make-button-list
3097 (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
3098 toolbar-icon-directory)))
3101 (defvar info::toolbar-next-icon
3102 (if (featurep 'toolbar)
3103 (toolbar-make-button-list
3104 (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
3105 toolbar-icon-directory)))
3108 (defvar info::toolbar-prev-icon
3109 (if (featurep 'toolbar)
3110 (toolbar-make-button-list
3111 (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
3112 toolbar-icon-directory)))
3115 (defvar info::toolbar
3116 (if (featurep 'toolbar)
3117 ; disabled until we get the next/prev-win icons working again.
3118 ; (cons (first initial-toolbar-spec)
3119 ; (cons (second initial-toolbar-spec)
3120 '([info::toolbar-exit-icon
3124 [info::toolbar-next-icon
3127 "Next entry in same section"]
3128 [info::toolbar-prev-icon
3131 "Prev entry in same section"]
3132 [info::toolbar-up-icon
3135 "Up entry to enclosing section"]
3141 (run-hooks 'Info-load-hook)
3143 ;;; info.el ends here