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'
318 "The info package for Emacs."
322 (defgroup info-faces nil
323 "The faces used by info browser."
328 (defcustom Info-inhibit-toolbar nil
329 "*Non-nil means don't use the specialized Info toolbar."
333 (defcustom Info-novice nil
334 "*Non-nil means to ask for confirmation before switching Info files."
338 (defvar Info-history nil
339 "List of info nodes user has visited.
340 Each element of list is a list (\"(FILENAME)NODENAME\" BUFPOS WINSTART).")
342 (defvar Info-keeping-history t
343 "Non-nil if Info-find-node should modify Info-history.
344 This is for use only by certain internal Info routines.")
346 (defvar Info-minibuffer-history nil
347 "Minibuffer history for Info.")
349 (defcustom Info-enable-edit nil
350 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info
351 can edit the current node.
352 This is convenient if you want to write info files by hand.
353 However, we recommend that you not do this.
354 It is better to write a Texinfo file and generate the Info file from that,
355 because that gives you a printed manual as well."
359 (defcustom Info-enable-active-nodes t
360 "*Non-nil allows Info to execute Lisp code associated with nodes.
361 The Lisp code is executed when the node is selected."
365 (defcustom Info-restoring-point t
366 "*Non-nil means to restore the cursor position when re-entering a node."
370 (defcustom Info-auto-advance 'twice
371 "*Control what SPC and DEL do when they can't scroll any further.
372 If nil, they beep and remain in the current node.
373 If t, they move to the next node (like Info-global-next/prev).
374 If anything else, they must be pressed twice to move to the next node."
375 :type '(choice (const :tag "off" nil)
376 (const :tag "advance" t)
377 (const :tag "confirm" twice))
380 (defcustom Info-fontify t
381 "*Non-nil enables font features in XEmacs.
382 This variable is ignored unless running under XEmacs."
386 (defcustom Info-additional-search-directory-list nil
387 "*List of additional directories to search for Info documentation
388 files. These directories are not searched for merging the `dir'
389 file. An example might be something like:
390 \"/usr/local/lib/xemacs/packages/lisp/calc/\""
391 :type '(repeat directory)
394 (defcustom Info-auto-generate-directory 'if-missing
395 "*When to auto generate an info directory listing.
397 nil or `never' never auto-generate a directory listing,
398 use any existing `dir' or `localdir' file and ignore info
399 directories containing none
400 `always' auto-generate a directory listing ignoring existing
401 `dir' and `localdir' files
402 `if-missing', the default, auto-generates a directory listing
403 if no `dir' or `localdir' file is present. Otherwise the
404 contents of any of these files is used instead.
405 `if-outdated' auto-generates a directory listing if the `dir'
406 and `localdir' are either inexistent or outdated (touched
407 less recently than an info file in the same directory)."
408 :type '(choice (const :tag "never" never)
409 (const :tag "always" always)
410 (const :tag "if-missing" if-missing)
411 (const :tag "if-outdated" if-outdated))
414 (defcustom Info-save-auto-generated-dir nil
415 "*Whether an auto-generated info directory listing should be saved.
417 nil or `never', the default, auto-generated info directory
418 information will never be saved.
419 `always', auto-generated info directory information will be saved to
420 a `dir' file in the same directory overwriting it if it exists
421 `conservative', auto-generated info directory information will be saved
422 to a `dir' file in the same directory but the user is asked before
423 overwriting any existing file."
424 :type '(choice (const :tag "never" never)
425 (const :tag "always" always)
426 (const :tag "conservative" conservative))
429 (defvar Info-emacs-info-file-name "xemacs.info"
430 "The filename of the XEmacs info for
431 `Info-goto-emacs-command-node' (`\\<help-mode-map>\\[Info-goto-emacs-command-node]')")
434 (defvar Info-directory-list nil
435 "List of directories to search for Info documentation files.
437 The first directory in this list, the \"dir\" file there will become
438 the (dir)Top node of the Info documentation tree. If you wish to
439 modify the info search path, use `M-x customize-variable,
440 Info-directory-list' to do so.")
442 (defcustom Info-localdir-heading-regexp
443 "^Locally installed XEmacs Packages:?"
444 "The menu part of localdir files will be inserted below this topic
449 (defface info-node '((t (:bold t :italic t)))
450 "Face used for node links in info."
453 (defface info-xref '((t (:bold t)))
454 "Face used for cross-references in info."
457 ;; Is this right for NT? .zip, with -c for to stdout, right?
458 (defvar Info-suffix-list '( ("" . nil)
460 (".info.gz" . "gzip -dc %s")
461 (".info-z" . "gzip -dc %s")
462 (".info.Z" . "uncompress -c %s")
463 (".gz" . "gzip -dc %s")
464 (".Z" . "uncompress -c %s")
465 (".zip" . "unzip -c %s") )
466 "List of file name suffixes and associated decoding commands.
467 Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
468 changed to name of the file to decode, otherwise the file is given to
469 the command as standard input. If STRING is nil, no decoding is done.")
471 (defvar Info-footnote-tag "Note"
472 "*Symbol that identifies a footnote or cross-reference.
473 All \"*Note\" references will be changed to use this word instead.")
475 (defvar Info-current-file nil
476 "Info file that Info is now looking at, or nil.
477 This is the name that was specified in Info, not the actual file name.
478 It doesn't contain directory names or file name extensions added by Info.")
480 (defvar Info-current-subfile nil
481 "Info subfile that is actually in the *info* buffer now,
482 or nil if current info file is not split into subfiles.")
484 (defvar Info-current-node nil
485 "Name of node that Info is now looking at, or nil.")
487 (defvar Info-tag-table-marker (make-marker)
488 "Marker pointing at beginning of current Info file's tag table.
489 Marker points nowhere if file has no tag table.")
491 (defvar Info-current-file-completions nil
492 "Cached completion list for current Info file.")
494 (defvar Info-current-annotation-completions nil
495 "Cached completion list for current annotation files.")
497 (defvar Info-index-alternatives nil
498 "List of possible matches for last Info-index command.")
499 (defvar Info-index-first-alternative nil)
501 (defcustom Info-annotations-path '("~/.xemacs/info.notes"
503 "/usr/lib/info.notes")
504 "*Names of files that contain annotations for different Info nodes.
505 By convention, the first one should reside in your personal directory.
506 The last should be a world-writable \"public\" annotations file."
510 (defcustom Info-button1-follows-hyperlink nil
511 "*Non-nil means mouse button1 click will follow hyperlink."
515 (defvar Info-standalone nil
516 "Non-nil if Emacs was started solely as an Info browser.")
518 (defvar Info-in-cross-reference nil)
519 (defvar Info-window-configuration nil)
521 (defvar Info-dir-prologue "-*- Text -*-
522 This is the file .../info/dir, which contains the topmost node of the
523 Info hierarchy. The first time you invoke Info you start off
524 looking at that node, which is (dir)Top.
526 File: dir Node: Top This is the top of the INFO tree
527 This (the Directory node) gives a menu of major topics.
529 * Menu: The list of major topics begins on the next line.
533 (defvar Info-no-description-string "[No description available]"
534 "Description string for info files that have none")
537 (defun info (&optional file)
538 "Enter Info, the documentation browser.
539 Optional argument FILE specifies the file to examine;
540 the default is the top-level directory of Info.
542 In interactive use, a prefix argument directs this command
543 to read a file name from the minibuffer."
544 (interactive (if current-prefix-arg
545 (list (read-file-name "Info file name: " nil nil t))))
546 (let ((p command-line-args))
548 (and (string-match "^-[fe]" (car p))
549 (equal (nth 1 p) "info")
550 (not Info-standalone)
551 (setq Info-standalone t)
553 (not (string-match "^-" (nth 2 p)))
554 (setq file (nth 2 p))
555 (setq command-line-args-left nil))
557 ; (Info-setup-x) ??? What was this going to be? Can anyone tell karlheg?
560 (Info-goto-node (concat "(" file ")"))
561 (and Info-standalone (info)))
562 (if (get-buffer "*info*")
563 (switch-to-buffer "*info*")
567 (defun Info-query (file)
568 "Enter Info, the documentation browser. Prompt for name of Info file."
569 (interactive "sInfo topic (default = menu): ")
572 (Info-goto-node "(dir)")
573 (Info-goto-node (concat "(" file ")"))))
575 (defun Info-setup-initial ()
576 (let ((f Info-annotations-path))
578 (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
579 (bury-buffer (find-file-noselect (car f))))
582 (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
583 "Go to an info node specified as separate FILENAME and NODENAME.
584 Look for a plausible filename, or if not found then look for URL's and
585 dispatch to the appropriate fn. NO-GOING-BACK is non-nil if
586 recovering from an error in this function; it says do not attempt
587 further (recursive) error recovery. TRYFILE is ??"
592 ;; empty filename is simple case
594 (Info-find-file-node nil nodename no-going-back tryfile line))
595 ;; Convert filename to lower case if not found as specified.
596 ;; Expand it, look harder...
597 ((let (temp temp-downcase found
598 (fname (substitute-in-file-name filename)))
600 ((string-match "^\\./" fname) ; If specified name starts with `./'
601 (list default-directory)) ; then just try current directory.
602 ((file-name-absolute-p fname)
603 '(nil)) ; No point in searching for an absolute file name
604 (Info-additional-search-directory-list
605 (append Info-directory-list
606 Info-additional-search-directory-list))
607 (t Info-directory-list))))
608 ;; Search the directory list for file FNAME.
609 (while (and dirs (not found))
610 (setq temp (expand-file-name fname (car dirs)))
612 (expand-file-name (downcase fname) (car dirs)))
613 (if (equal temp-downcase temp) (setq temp-downcase nil))
614 ;; Try several variants of specified name.
615 ;; Try downcasing, appending a suffix, or both.
616 (setq found (Info-suffixed-file temp temp-downcase))
617 (setq dirs (cdr dirs)))
619 (progn (setq filename (expand-file-name found))
621 (Info-find-file-node filename nodename no-going-back tryfile line))
622 ;; Look for a URL. This pattern is stolen from w3.el to prevent
623 ;; loading it if we won't need it.
624 ((string-match (concat "^\\(wais\\|solo\\|x-exec\\|newspost\\|www\\|"
625 "mailto\\|news\\|tn3270\\|ftp\\|http\\|file\\|"
626 "telnet\\|gopher\\):")
628 (if (fboundp 'browse-url)
629 (browse-url filename)
630 (error "Cannot follow URLs in this XEmacs")))
632 (error "Info file %s does not exist" filename))))
634 (defun Info-find-file-node (filename nodename
635 &optional no-going-back tryfile line)
636 ;; This is the guts of what was Info-find-node. Whoever wrote this
637 ;; should be locked up where they can't do any more harm.
639 ;; Go into info buffer.
640 (switch-to-buffer "*info*")
641 (buffer-disable-undo (current-buffer))
642 (run-hooks 'Info-startup-hook)
643 (or (eq major-mode 'Info-mode)
646 (equal Info-current-file filename)
648 (string= "dir" (file-name-nondirectory Info-current-file))
649 (if (y-or-n-p-maybe-dialog-box
650 (format "Leave Info file `%s'? "
651 (file-name-nondirectory Info-current-file)))
654 ;; Record the node we are leaving.
655 (if (and Info-current-file (not no-going-back))
656 (Info-history-add Info-current-file Info-current-node (point)))
658 (setq Info-current-node nil
659 Info-in-cross-reference nil)
662 ;; Switch files if necessary
664 (equal Info-current-file filename)
665 (let ((buffer-read-only nil))
666 (setq Info-current-file nil
667 Info-current-subfile nil
668 Info-current-file-completions nil
669 Info-index-alternatives nil
670 buffer-file-name nil)
672 (if (string= "dir" (file-name-nondirectory filename))
674 (Info-insert-file-contents filename t)
675 (setq default-directory (file-name-directory filename)))
676 (set-buffer-modified-p nil)
677 ;; See whether file has a tag table. Record the location if yes.
678 (set-marker Info-tag-table-marker nil)
679 (goto-char (point-max))
681 (or (equal nodename "*")
682 (not (search-forward "\^_\nEnd tag table\n" nil t))
684 ;; We have a tag table. Find its beginning.
685 ;; Is this an indirect file?
686 (search-backward "\nTag table:\n")
690 (looking-at "(Indirect)\n"))
691 ;; It is indirect. Copy it to another buffer
692 ;; and record that the tag table is in that buffer.
694 (let ((buf (current-buffer)))
696 (get-buffer-create " *info tag table*"))
697 (buffer-disable-undo (current-buffer))
698 (setq case-fold-search t)
700 (insert-buffer-substring buf)
701 (set-marker Info-tag-table-marker
703 (set-marker Info-tag-table-marker pos))))
704 (setq Info-current-file
705 (file-name-sans-versions buffer-file-name))))
706 (if (equal nodename "*")
707 (progn (setq Info-current-node nodename)
709 (goto-char (point-min)))
710 ;; Search file for a suitable node.
711 (let* ((qnode (regexp-quote nodename))
712 (regexp (concat "Node: *" qnode " *[,\t\n\177]"))
713 (guesspos (point-min))
715 ;; First get advice from tag table if file has one.
716 ;; Also, if this is an indirect info file,
717 ;; read the proper subfile into this buffer.
718 (if (marker-position Info-tag-table-marker)
720 (set-buffer (marker-buffer Info-tag-table-marker))
721 (goto-char Info-tag-table-marker)
722 (if (re-search-forward regexp nil t)
724 (setq guesspos (read (current-buffer)))
725 ;; If this is an indirect file,
726 ;; determine which file really holds this node
728 (if (not (eq (current-buffer) (get-buffer "*info*")))
730 (Info-read-subfile guesspos)))))))
731 (goto-char (max (point-min) (- guesspos 1000)))
732 ;; Now search from our advised position (or from beg of buffer)
733 ;; to find the actual node.
735 (while (search-forward "\n\^_" nil t)
739 (if (re-search-backward regexp beg t)
742 (let ((bufs (delq nil (mapcar 'get-file-buffer
743 Info-annotations-path)))
744 (pattern (if (string-match "\\`<<.*>>\\'" qnode) qnode
745 (format "\"%s\"\\|<<%s>>" qnode qnode)))
746 (pat2 (concat "------ *File: *\\([^ ].*[^ ]\\) *Node: "
747 "*\\([^ ].*[^ ]\\) *Line: *\\([0-9]+\\)"))
748 (afile nil) anode aline)
749 (while (and bufs (not anode))
751 (set-buffer (car bufs))
752 (goto-char (point-min))
753 (if (re-search-forward pattern nil t)
754 (if (re-search-backward pat2 nil t)
755 (setq afile (buffer-substring (match-beginning 1)
757 anode (buffer-substring (match-beginning 2)
760 (buffer-substring (match-beginning 3)
762 (setq bufs (cdr bufs)))
764 (Info-find-node afile anode t nil aline)
767 (Info-find-node nodename "Top" t)
769 (or Info-current-node
770 (error "No such node: %s" nodename)))
774 (goto-char (point-min))
775 (if line (forward-line line)))))))
776 ;; If we did not finish finding the specified node,
777 ;; go back to the previous one.
778 (or Info-current-node no-going-back
779 (let ((hist (car Info-history)))
780 ;; The following is no longer safe with new Info-history system
781 ;; (setq Info-history (cdr Info-history))
782 (Info-goto-node (car hist) t)
783 (goto-char (+ (point-min) (nth 1 hist)))))))
785 ;; Cache the contents of the (virtual) dir file, once we have merged
786 ;; it for the first time, so we can save time subsequently.
787 (defvar Info-dir-contents nil)
789 ;; Cache for the directory we decided to use for the default-directory
790 ;; of the merged dir text.
791 (defvar Info-dir-contents-directory nil)
793 ;; Record the file attributes of all the files from which we
794 ;; constructed Info-dir-contents.
795 (defvar Info-dir-file-attributes nil)
797 (defun Info-insert-dir ()
798 "Construct the Info directory node by merging the files named
799 \"dir\" or \"localdir\" from the directories in `Info-directory-list'
800 The \"dir\" files will take precedence in cases where both exist. It
801 sets the *info* buffer's `default-directory' to the first directory we
802 actually get any text from."
803 (if (and Info-dir-contents Info-dir-file-attributes
804 ;; Verify that none of the files we used has changed
807 (mapcar '(lambda (elt)
808 (let ((curr (file-attributes (car elt))))
809 ;; Don't compare the access time.
810 (if curr (setcar (nthcdr 4 curr) 0))
811 (setcar (nthcdr 4 (cdr elt)) 0)
812 (equal (cdr elt) curr)))
813 Info-dir-file-attributes))))
814 (insert Info-dir-contents)
815 (let ((dirs (reverse Info-directory-list))
816 buffers lbuffers buffer others nodes dirs-done)
818 (setq Info-dir-file-attributes nil)
820 ;; Search the directory list for the directory file.
822 (let ((truename (file-truename (expand-file-name (car dirs)))))
823 (or (member truename dirs-done)
824 (member (directory-file-name truename) dirs-done)
825 ;; Try several variants of specified name.
826 ;; Try upcasing, appending `.info', or both.
831 (progn (setq file (expand-file-name "dir" truename))
832 (file-attributes file))
833 (progn (setq file (expand-file-name "DIR" truename))
834 (file-attributes file))
835 (progn (setq file (expand-file-name "dir.info" truename))
836 (file-attributes file))
837 (progn (setq file (expand-file-name "DIR.INFO" truename))
838 (file-attributes file))
839 (progn (setq file (expand-file-name "localdir" truename))
840 (file-attributes file))
841 (progn (setq file (expand-file-name "dir" truename))
846 (cons (directory-file-name truename)
848 (Info-maybe-update-dir file)
849 (setq attrs (file-attributes file))
850 (if (or (setq buf (find-buffer-visiting file))
854 (message "Composing main Info directory..."))
857 (if (string-match "localdir" file)
861 (insert-file-contents file))
862 (if (string-match "localdir" (buffer-name))
863 (setq lbuffers (cons (current-buffer) lbuffers))
864 (setq buffers (cons (current-buffer) buffers)))
866 (setq Info-dir-file-attributes
867 (cons (cons file attrs)
868 Info-dir-file-attributes)))))))
869 (or (cdr dirs) (setq Info-dir-contents-directory (car dirs)))
870 (setq dirs (cdr dirs))))
872 ;; ensure that the localdir files are inserted last, and reverse
873 ;; the list of them so that when they get pushed in, they appear
874 ;; in the same order they got specified in the path, from top to
876 (nconc buffers (reverse lbuffers))
879 (error "Can't find the Info directory node"))
880 ;; Distinguish the dir file that comes with Emacs from all the
881 ;; others. Yes, that is really what this is supposed to do.
882 ;; If it doesn't work, fix it.
883 (setq buffer (car buffers)
884 ;; reverse it since they are pushed down from the top. the
885 ;; `Info-directory-list can be specified in natural order
887 others (reverse (cdr buffers)))
889 ;; Insert the entire original dir file as a start; note that we've
890 ;; already saved its default directory to use as the default
891 ;; directory for the whole concatenation.
892 (insert-buffer buffer)
894 ;; Look at each of the other buffers one by one.
896 (let ((other (car others))
897 (info-buffer (current-buffer)))
898 (if (string-match "localdir" (buffer-name other))
900 (set-buffer info-buffer)
901 (goto-char (point-max))
903 ((re-search-backward "^ *\\* *Locals *: *$" nil t)
904 (delete-region (match-beginning 0) (match-end 0)))
905 ;; look for a line like |Local XEmacs packages:
906 ;; or mismatch on some text ...
907 ((re-search-backward Info-localdir-heading-regexp nil t)
908 ;; This is for people who underline topic headings with
909 ;; equal signs or dashes.
910 (when (save-excursion
913 (looking-at "^[ \t]*[-=*]+"))
917 (t (search-backward "\^L" nil t)))
918 ;; Insert menu part of the file
920 (len (length (buffer-string nil nil other))))
921 (insert (buffer-string nil nil other))
922 (goto-char (+ pt len))
925 (if (search-forward "* Menu:" (+ pt len) t)
928 (delete-region pt (point)))))))
929 ;; In each, find all the menus.
932 (goto-char (point-min))
933 ;; Find each menu, and add an elt to NODES for it.
934 (while (re-search-forward "^\\* Menu:" nil t)
935 (let (beg nodename end)
938 (search-backward "\n\^_")
939 (search-forward "Node: ")
940 (setq nodename (Info-following-node-name))
941 (search-forward "\n\^_" nil 'move)
944 (setq nodes (cons (list nodename other beg end) nodes))))))
945 (setq others (cdr others))))
947 ;; Add to the main menu a menu item for each other node.
948 (re-search-forward "^\\* Menu:" nil t)
950 (let ((menu-items '("top"))
953 (end (save-excursion (search-forward "\^_" nil t) (point))))
955 (let ((nodename (car (car nodes))))
957 (or (member (downcase nodename) menu-items)
958 (re-search-forward (concat "^\\* "
959 (regexp-quote nodename)
963 (insert "* " nodename "::" "\n")
964 (setq menu-items (cons nodename menu-items))))))
965 (setq nodes (cdr nodes))))
966 ;; Now take each node of each of the other buffers
967 ;; and merge it into the main buffer.
969 (let ((nodename (car (car nodes))))
970 (goto-char (point-min))
971 ;; Find the like-named node in the main buffer.
972 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
973 (regexp-quote nodename)
977 (search-forward "\n\^_" nil 'move)
980 ;; If none exists, add one.
981 (goto-char (point-max))
982 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
983 ;; Merge the text from the other buffer's menu
984 ;; into the menu in the like-named node in the main buffer.
985 (apply 'insert-buffer-substring (cdr (car nodes))))
986 (setq nodes (cdr nodes)))
987 ;; Kill all the buffers we just made.
989 (kill-buffer (car buffers))
990 (setq buffers (cdr buffers)))
992 (kill-buffer (car lbuffers))
993 (setq lbuffers (cdr lbuffers)))
994 (message "Composing main Info directory...done"))
995 (setq Info-dir-contents (buffer-string)))
996 (setq default-directory Info-dir-contents-directory)
997 (setq buffer-file-name (caar Info-dir-file-attributes)))
999 (defun Info-maybe-update-dir (file)
1000 "Rebuild dir or localdir according to `Info-auto-generate-directory'."
1001 (unless (or (not (file-exists-p (file-name-directory file)))
1002 (null (directory-files (file-name-directory file) nil "\\.info")))
1003 (if (not (find-buffer-visiting file))
1004 (if (not (file-exists-p file))
1005 (if (or (eq Info-auto-generate-directory 'always)
1006 (eq Info-auto-generate-directory 'if-missing))
1007 (Info-build-dir-anew (file-name-directory file)))
1008 (if (or (eq Info-auto-generate-directory 'always)
1009 (and (eq Info-auto-generate-directory 'if-outdated)
1010 (Info-dir-outdated-p file)))
1011 (Info-rebuild-dir file))))))
1013 ;; Record which *.info files are newer than the dir file
1014 (defvar Info-dir-newer-info-files nil)
1016 (defun Info-dir-outdated-p (file)
1017 "Return non-nil if dir or localdir is outdated.
1018 dir or localdir are outdated when an info file in the same
1019 directory has been modified more recently."
1020 (let ((dir-mod-time (nth 5 (file-attributes file)))
1023 (setq Info-dir-newer-info-files nil)
1027 (setq f-mod-time (nth 5 (file-attributes f)))
1028 (setq newer (or (> (car f-mod-time) (car dir-mod-time))
1029 (and (= (car f-mod-time) (car dir-mod-time))
1030 (> (car (cdr f-mod-time)) (car (cdr dir-mod-time))))))
1031 (if (and (file-readable-p f)
1033 (setq Info-dir-newer-info-files
1034 (cons f Info-dir-newer-info-files)))))
1035 (directory-files (file-name-directory file)
1037 ".*\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1040 Info-dir-newer-info-files))
1042 (defun Info-extract-dir-entry-from (file)
1043 "Extract the dir entry from the info FILE.
1044 The dir entry is delimited by the markers `START-INFO-DIR-ENTRY'
1045 and `END-INFO-DIR-ENTRY'"
1047 (set-buffer (get-buffer-create " *Info-tmp*"))
1048 (when (file-readable-p file)
1049 (insert-file-contents file nil nil nil t)
1050 (goto-char (point-min))
1052 (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
1055 (unless (null (re-search-forward "^END-INFO-DIR-ENTRY" nil t))
1056 (goto-char (match-beginning 0))
1057 (car (Info-parse-dir-entries beg (point)))))))))
1059 ;; Parse dir entries contained between BEG and END into a list of the form
1060 ;; (filename topic node (description-line-1 description-line-2 ...))
1061 (defun Info-parse-dir-entries (beg end)
1062 (let (entry entries)
1065 (narrow-to-region beg end)
1067 (while (re-search-forward "^\\* \\([^:]+\\):\\([ \t]*(\\([^)]*\\))\\w*\\.\\|:\\)" nil t)
1068 (setq entry (list (match-string 2)
1070 (downcase (or (match-string 3)
1071 (match-string 1)))))
1078 (re-search-forward "[ \t]*" nil t)
1079 (or (and (re-search-forward "^[^ \t]" nil t)
1080 (goto-char (match-beginning 0)))
1082 "[ \t]*\n[ \t]*"))))
1084 (setq entries (cons (nreverse entry) entries)))))
1085 (nreverse entries)))
1087 (defun Info-dump-dir-entries (entries)
1091 (mapcar '(lambda (e)
1092 (setq e (cdr e)) ; Drop filename
1093 (setq len (length (concat (car e)
1095 (if (> len description-col)
1096 (setq description-col len)))
1098 (setq description-col (+ 5 description-col))
1099 (mapcar '(lambda (e)
1100 (setq e (cdr e)) ; Drop filename
1101 (insert "* " (car e) ":" (car (cdr e)))
1102 (setq e (car (cdr (cdr e))))
1104 (indent-to-column description-col)
1105 (insert (car e) "\n")
1111 (defun Info-build-dir-anew (directory)
1112 "Build info directory information for DIRECTORY.
1113 The generated directory listing may be saved to a `dir' according
1114 to the value of `Info-save-auto-generated-dir'"
1116 (let* ((dirfile (expand-file-name "dir" directory))
1117 (to-temp (or (null Info-save-auto-generated-dir)
1118 (eq Info-save-auto-generated-dir 'never)
1119 (and (not (file-writable-p dirfile))
1120 (message "File not writable %s. Using temporary." dirfile))))
1122 (directory-files directory
1124 ".*\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1128 (message "Creating temporary dir in %s..." directory)
1129 (message "Creating %s..." dirfile))
1130 (set-buffer (find-file-noselect dirfile t))
1131 (setq buffer-read-only nil)
1133 (insert Info-dir-prologue
1134 "Info files in " directory ":\n\n")
1135 (Info-dump-dir-entries
1138 (or (Info-extract-dir-entry-from f)
1141 (string-match "\\(.*\\)\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1142 (file-name-nondirectory f))
1143 (capitalize (match-string 1 (file-name-nondirectory f))))
1145 (list Info-no-description-string))))
1148 (set-buffer-modified-p nil)
1151 (message "Creating temporary dir in %s...done" directory)
1152 (message "Creating %s...done" dirfile)))))
1155 (defun Info-rebuild-dir (file)
1156 "Build info directory information in the directory of dir FILE.
1157 Description of info files are merged from the info files in the
1158 directory and the contents of FILE with the description in info files
1159 taking precedence over descriptions in FILE.
1160 The generated directory listing may be saved to a `dir' according to
1161 the value of `Info-save-auto-generated-dir' "
1164 (let (dir-section-contents dir-full-contents
1170 (or (null Info-save-auto-generated-dir)
1171 (eq Info-save-auto-generated-dir 'never)
1172 (and (eq Info-save-auto-generated-dir 'always)
1173 (not (file-writable-p file))
1174 (message "File not writable %s. Using temporary." file))
1175 (and (eq Info-save-auto-generated-dir 'conservative)
1176 (or (and (not (file-writable-p file))
1177 (message "File not writable %s. Using temporary." file))
1179 (message "%s is outdated. Overwrite ? "
1181 (set-buffer (find-file-noselect file t))
1182 (setq buffer-read-only nil)
1184 (message "Rebuilding temporary %s..." file)
1185 (message "Rebuilding %s..." file))
1187 (setq buffer-read-only nil)
1188 (goto-char (point-min))
1189 (unless (and (search-forward "\^_")
1190 (re-search-forward "^\\* Menu:.*$" nil t)
1191 (setq mark (and (re-search-forward "^\\* " nil t)
1192 (match-beginning 0))))
1194 (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1195 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$" nil t)
1196 (match-beginning 0))
1199 (narrow-to-region mark next-section)
1200 (setq dir-section-contents (nreverse (Info-parse-dir-entries (point-min)
1202 (mapcar '(lambda (file)
1203 (setq dir-entry (assoc (downcase
1204 (file-name-sans-extension
1205 (file-name-nondirectory file)))
1206 dir-section-contents)
1207 file-dir-entry (Info-extract-dir-entry-from file))
1210 ;; A dir entry in the info file takes precedence over an
1211 ;; existing entry in the dir file
1212 (setcdr dir-entry (cdr file-dir-entry)))
1213 (unless (or not-first-section
1215 (file-name-sans-extension
1216 (file-name-nondirectory file)))
1219 (setq dir-section-contents (cons file-dir-entry
1220 dir-section-contents))
1221 (setq dir-section-contents
1223 (capitalize (file-name-sans-extension
1224 (file-name-nondirectory file)))
1226 (list Info-no-description-string))
1227 dir-section-contents))))))
1228 Info-dir-newer-info-files)
1229 (delete-region (point-min) (point-max))
1230 (Info-dump-dir-entries (nreverse dir-section-contents))
1232 (if (= next-section (point-max))
1233 (setq next-section nil)
1234 (or (setq mark (and (re-search-forward "^\\* " nil t)
1235 (match-beginning 0)))
1237 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$" nil t)
1238 (match-beginning 0))
1240 (setq not-first-section t)))
1243 (set-buffer-modified-p nil)
1244 (message "Rebuilding temporary %s...done" file))
1246 (message "Rebuilding %s...done" file))))))
1249 (defun Info-batch-rebuild-dir ()
1250 "(Re)build info `dir' files in the directories remaining on the command line.
1251 Use this from the command line, with `-batch';
1252 it won't work in an interactive Emacs.
1253 Each file is processed even if an error occurred previously.
1254 For example, invoke \"xemacs -batch -f Info-batch-rebuild-dir /usr/local/info\""
1255 ;; command-line-args-left is what is left of the command line (from
1257 (defvar command-line-args-left) ; Avoid 'free variable' warning
1258 (if (not noninteractive)
1259 (error "`Info-batch-rebuild-dir' is to be used only with -batch"))
1260 (let ((Info-save-auto-generated-dir 'always)
1262 (while command-line-args-left
1263 (if (not (file-directory-p (car command-line-args-left)))
1264 (message "Warning: Skipped %s. Not a directory."
1265 (car command-line-args-left))
1266 (setq dir (expand-file-name "dir" (car command-line-args-left)))
1267 (setq localdir (expand-file-name "localdir" (car command-line-args-left)))
1269 ((file-exists-p dir)
1270 (Info-rebuild-dir dir))
1271 ((file-exists-p localdir)
1272 (Info-rebuild-dir localdir))
1274 (Info-build-dir-anew (car command-line-args-left)))))
1275 (setq command-line-args-left (cdr command-line-args-left)))
1279 (defun Info-history-add (file node point)
1280 (if Info-keeping-history
1281 (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
1282 (found (assoc name Info-history)))
1284 (setq Info-history (delq found Info-history)))
1285 (setq Info-history (cons (list name (- point (point-min))
1286 (and (eq (window-buffer)
1288 (- (window-start) (point-min))))
1291 (defun Info-file-name-only (file)
1292 (let ((dir (file-name-directory file))
1293 (p Info-directory-list))
1294 (while (and p (not (equal (car p) dir)))
1296 (if p (file-name-nondirectory file) file)))
1298 (defun Info-read-subfile (nodepos)
1299 (set-buffer (marker-buffer Info-tag-table-marker))
1300 (goto-char (point-min))
1301 (search-forward "\n\^_")
1306 (while (not (looking-at "\^_"))
1309 thisfilepos thisfilename)
1310 (search-forward ": ")
1311 (setq thisfilename (buffer-substring beg (- (point) 2)))
1312 (setq thisfilepos (read (current-buffer)))
1313 ;; read in version 19 stops at the end of number.
1314 ;; Advance to the next line.
1317 (if (> thisfilepos nodepos)
1319 (setq lastfilename thisfilename)
1320 (setq lastfilepos thisfilepos))
1322 (set-buffer (get-buffer "*info*"))
1323 (or (equal Info-current-subfile lastfilename)
1324 (let ((buffer-read-only nil))
1325 (setq buffer-file-name nil)
1328 (Info-insert-file-contents (Info-suffixed-file
1329 (expand-file-name lastfilename
1330 (file-name-directory
1331 Info-current-file)))
1333 (set-buffer-modified-p nil)
1334 (setq Info-current-subfile lastfilename)))
1335 (goto-char (point-min))
1336 (search-forward "\n\^_")
1337 (+ (- nodepos lastfilepos) (point))))
1339 (defun Info-suffixed-file (name &optional name2)
1340 "Look for NAME with each of the `Info-suffix-list' extensions in
1341 turn. Optional NAME2 is the name of a fallback info file to check
1342 for; usually a downcased version of NAME."
1343 (let ((suff Info-suffix-list)
1346 (while (and suff (not found))
1347 (setq file (concat name (caar suff))
1348 file2 (and name2 (concat name2 (caar suff))))
1350 ((file-regular-p file)
1352 ((and file2 (file-regular-p file2))
1355 (setq suff (cdr suff)))))
1357 (and name (when (file-regular-p name)
1359 (and name2 (when (file-regular-p name2)
1362 (defun Info-insert-file-contents (file &optional visit)
1363 (setq file (expand-file-name file default-directory))
1364 (let ((suff Info-suffix-list))
1365 (while (and suff (or (<= (length file) (length (car (car suff))))
1366 (not (equal (substring file
1367 (- (length (car (car suff)))))
1368 (car (car suff))))))
1369 (setq suff (cdr suff)))
1370 (if (stringp (cdr (car suff)))
1371 (let ((command (if (string-match "%s" (cdr (car suff)))
1372 (format (cdr (car suff)) file)
1373 (concat (cdr (car suff)) " < " file))))
1374 (message "%s..." command)
1375 (if (eq system-type 'vax-vms)
1376 (call-process command nil t nil)
1377 (call-process shell-file-name nil t nil "-c" command))
1381 (setq buffer-file-name file)
1382 (set-buffer-modified-p nil)
1383 (clear-visited-file-modtime))))
1384 (insert-file-contents file visit))))
1386 (defun Info-select-node ()
1387 "Select the node that point is in, after using `g *' to select whole file."
1391 ;; Find beginning of node.
1392 (search-backward "\n\^_")
1394 ;; Get nodename spelled as it is in the node.
1395 (re-search-forward "Node:[ \t]*")
1396 (setq Info-current-node
1397 (buffer-substring (point)
1399 (skip-chars-forward "^,\t\n")
1401 (Info-set-mode-line)
1402 ;; Find the end of it, and narrow.
1404 (let (active-expression)
1405 (narrow-to-region (point)
1406 (if (re-search-forward "\n[\^_\f]" nil t)
1409 (if (looking-at "[\n\^_\f]*execute: ")
1411 (goto-char (match-end 0))
1412 (setq active-expression
1413 (read (current-buffer))))))
1415 (or (equal Info-footnote-tag "Note")
1417 (goto-char (point-min))
1418 (let ((buffer-read-only nil)
1419 (bufmod (buffer-modified-p))
1420 (case-fold-search t))
1421 (while (re-search-forward "\\*[Nn]ote\\([ \n]\\)" nil t)
1422 (replace-match (concat "*" Info-footnote-tag "\ ")))
1423 (set-buffer-modified-p bufmod))))
1424 (Info-reannotate-node)
1425 ;; XEmacs: remove v19 test
1427 (Info-fontify-node))
1428 (run-hooks 'Info-select-hook)
1429 (if Info-enable-active-nodes (eval active-expression)))))
1431 (defun Info-set-mode-line ()
1432 (setq modeline-buffer-identification
1433 (list (cons modeline-buffer-id-left-extent "Info: ")
1434 (cons modeline-buffer-id-right-extent
1437 (if Info-current-file
1438 (let ((name (file-name-nondirectory Info-current-file)))
1439 (if (string-match "\\.info$" name)
1440 (substring name 0 -5)
1444 (or Info-current-node ""))))))
1446 ;; Go to an info node specified with a filename-and-nodename string
1447 ;; of the sort that is found in pointers in nodes.
1450 (defun Info-goto-node (nodename &optional no-going-back tryfile)
1451 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
1452 Actually, the following interpretations of NAME are tried in order:
1454 (FILENAME) (using Top node)
1455 NODENAME (in current file)
1457 FILENAME (using Top node)
1458 where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
1459 annotation for any node of any file. (See `a' and `x' commands.)"
1460 (interactive (list (Info-read-node-name "Goto node, file or tag: ")
1463 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1465 (setq filename (if (= (match-beginning 1) (match-end 1))
1467 (substring nodename (match-beginning 2) (match-end 2)))
1468 nodename (substring nodename (match-beginning 3) (match-end 3)))
1469 (let ((trim (string-match "\\s *\\'" filename)))
1470 (if trim (setq filename (substring filename 0 trim))))
1471 (let ((trim (string-match "\\s *\\'" nodename)))
1472 (if trim (setq nodename (substring nodename 0 trim))))
1473 (Info-find-node (if (equal filename "") nil filename)
1474 (if (equal nodename "") "Top" nodename)
1475 no-going-back (and tryfile (equal filename "")))))
1477 (defun Info-goto-bookmark ()
1479 (let ((completion-ignore-case nil)
1480 (tag (completing-read "Goto tag: "
1481 (Info-build-annotation-completions)
1483 'Info-minibuffer-history)))
1484 (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
1487 (defun Info-visit-file ()
1488 "Directly visit an info file."
1490 (let* ((insert-default-directory nil)
1491 (file (read-file-name "Goto Info file: " "" "")))
1492 (or (equal file "") (Info-find-node (expand-file-name file) "Top"))))
1494 (defun Info-restore-point (&optional always)
1495 "Restore point to same location it had last time we were in this node."
1497 (if (or Info-restoring-point always)
1498 (let* ((name (format "(%s)%s"
1499 (Info-file-name-only Info-current-file)
1501 (p (assoc name Info-history)))
1502 (if p (Info-restore-history-entry p)))))
1504 (defun Info-restore-history-entry (entry)
1505 (goto-char (+ (nth 1 entry) (point-min)))
1507 (get-buffer-window (current-buffer))
1508 (set-window-start (get-buffer-window (current-buffer))
1509 (+ (nth 2 entry) (point-min)))))
1511 (defun Info-read-node-name (prompt &optional default)
1512 (Info-setup-initial)
1513 (let* ((completion-ignore-case t)
1514 (nodename (completing-read prompt
1515 (Info-build-node-completions)
1517 'Info-minibuffer-history)))
1518 (if (equal nodename "")
1520 (Info-read-node-name prompt))
1523 (defun Info-build-annotation-completions ()
1524 (or Info-current-annotation-completions
1526 (let ((bufs (delq nil (mapcar 'get-file-buffer
1527 Info-annotations-path)))
1530 (set-buffer (car bufs))
1531 (goto-char (point-min))
1532 (while (re-search-forward "<<\\(.*\\)>>" nil t)
1533 (setq compl (cons (list (buffer-substring (match-beginning 1)
1536 (setq bufs (cdr bufs)))
1537 (setq Info-current-annotation-completions compl)))))
1539 (defun Info-build-node-completions ()
1540 (or Info-current-file-completions
1541 (let ((compl (Info-build-annotation-completions)))
1544 (if (marker-buffer Info-tag-table-marker)
1546 (set-buffer (marker-buffer Info-tag-table-marker))
1547 (goto-char Info-tag-table-marker)
1548 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
1550 (cons (list (buffer-substring (match-beginning 1)
1554 (goto-char (point-min))
1555 (while (search-forward "\n\^_" nil t)
1557 (let ((beg (point)))
1559 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
1562 (cons (list (buffer-substring (match-beginning 1)
1565 (setq Info-current-file-completions compl))))
1567 (defvar Info-last-search nil
1568 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1572 (defun Info-search (regexp)
1573 "Search for REGEXP, starting from point, and select node it's found in."
1574 (interactive "sSearch (regexp): ")
1575 (if (equal regexp "")
1576 (setq regexp Info-last-search)
1577 (setq Info-last-search regexp))
1578 (with-search-caps-disable-folding regexp t
1580 (onode Info-current-node)
1581 (ofile Info-current-file)
1583 (osubfile Info-current-subfile))
1587 (if (null Info-current-subfile)
1588 (progn (re-search-forward regexp) (setq found (point)))
1590 (progn (re-search-forward regexp) (setq found (point)))
1591 (search-failed nil)))))
1592 (if (not found) ;can only happen in subfile case -- else would have erred
1595 (set-buffer (marker-buffer Info-tag-table-marker))
1596 (goto-char (point-min))
1597 (search-forward "\n\^_\nIndirect:")
1599 (narrow-to-region (point)
1600 (progn (search-forward "\n\^_")
1602 (goto-char (point-min))
1603 (search-forward (concat "\n" osubfile ": "))
1606 (re-search-forward "\\(^.*\\): [0-9]+$")
1607 (goto-char (+ (match-end 1) 2))
1608 (setq list (cons (cons (read (current-buffer))
1609 (buffer-substring (match-beginning 1)
1612 (goto-char (1+ (match-end 0))))
1613 (setq list (nreverse list)
1616 (message "Searching subfile %s..." (cdr (car list)))
1617 (Info-read-subfile (car (car list)))
1618 (setq list (cdr list))
1619 (goto-char (point-min))
1620 (if (re-search-forward regexp nil t)
1621 (setq found (point) list ())))
1624 (signal 'search-failed (list regexp))))
1626 (progn (Info-read-subfile opoint)
1628 (Info-select-node)))))
1632 (or (and (equal onode Info-current-node)
1633 (equal ofile Info-current-file))
1634 (Info-history-add ofile onode opoint)))))
1636 ;; Extract the value of the node-pointer named NAME.
1637 ;; If there is none, use ERRORNAME in the error message;
1638 ;; if ERRORNAME is nil, just return nil.
1639 (defun Info-extract-pointer (name &optional errorname)
1641 (goto-char (point-min))
1643 (let ((case-fold-search t))
1644 (if (re-search-backward (concat name ":") nil t)
1646 (goto-char (match-end 0))
1647 (Info-following-node-name))
1648 (if (eq errorname t)
1650 (error (concat "Node has no " (capitalize (or errorname name)))))))))
1652 ;; Return the node name in the buffer following point.
1653 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1654 ;; saying which chas may appear in the node name.
1655 (defun Info-following-node-name (&optional allowedchars)
1656 (skip-chars-forward " \t")
1660 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1661 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1662 (if (looking-at "(")
1663 (skip-chars-forward "^)")))
1664 (skip-chars-backward " ")
1667 (defun Info-next (&optional n)
1668 "Go to the next node of this node.
1669 A positive or negative prefix argument moves by multiple nodes."
1674 (while (>= (setq n (1- n)) 0)
1675 (Info-goto-node (Info-extract-pointer "next")))))
1677 (defun Info-prev (&optional n)
1678 "Go to the previous node of this node.
1679 A positive or negative prefix argument moves by multiple nodes."
1684 (while (>= (setq n (1- n)) 0)
1685 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
1687 (defun Info-up (&optional n)
1688 "Go to the superior node of this node.
1689 A positive prefix argument moves up several times."
1692 (while (>= (setq n (1- n)) 0)
1693 (Info-goto-node (Info-extract-pointer "up")))
1694 (if (interactive-p) (Info-restore-point)))
1696 (defun Info-last (&optional n)
1697 "Go back to the last node visited.
1698 With a prefix argument, go to Nth most recently visited node. History is
1699 circular; after oldest node, history comes back around to most recent one.
1700 Argument can be negative to go through the circle in the other direction.
1701 \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
1705 (error "This is the first Info node you looked at"))
1706 (let ((len (1+ (length Info-history))))
1707 (setq n (% (+ n (* len 100)) len)))
1709 (let ((entry (nth (1- n) Info-history)))
1710 (Info-history-add Info-current-file Info-current-node (point))
1711 (while (>= (setq n (1- n)) 0)
1712 (setq Info-history (nconc (cdr Info-history)
1713 (list (car Info-history)))))
1714 (setq Info-history (cdr Info-history))
1715 (let ((Info-keeping-history nil))
1716 (Info-goto-node (car entry)))
1717 (Info-restore-history-entry entry))))
1719 (defun Info-directory ()
1720 "Go to the Info directory node."
1722 (Info-find-node "dir" "top"))
1724 (defun Info-follow-reference (footnotename)
1725 "Follow cross reference named NAME to the node it refers to.
1726 NAME may be an abbreviation of the reference name."
1728 (let ((completion-ignore-case t)
1729 completions default (start-point (point)) str i)
1731 (goto-char (point-min))
1732 (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
1735 (setq str (buffer-substring
1738 ;; See if this one should be the default.
1740 (< (match-beginning 0) start-point)
1741 (<= start-point (point))
1744 (while (setq i (string-match "[ \n\t]+" str i))
1745 (setq str (concat (substring str 0 i) " "
1746 (substring str (match-end 0))))
1748 ;; Record as a completion and perhaps as default.
1749 (if (eq default t) (setq default str))
1751 (cons (cons str nil)
1754 (let ((item (completing-read (if default
1755 (concat "Follow reference named: ("
1757 "Follow reference named: ")
1758 completions nil t nil
1759 'Info-minibuffer-history)))
1760 (if (and (string= item "") default)
1763 (error "No cross-references in this node"))))
1764 (let (target i (str (concat "\\*" Info-footnote-tag " "
1765 (regexp-quote footnotename))))
1766 (while (setq i (string-match " " str i))
1767 (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
1768 (substring str (1+ i))))
1771 (goto-char (point-min))
1772 (or (re-search-forward str nil t)
1773 (error "No cross-reference named %s" footnotename))
1774 (goto-char (match-end 1))
1776 (Info-extract-menu-node-name "Bad format cross reference" t)))
1777 (while (setq i (string-match "[ \t\n]+" target i))
1778 (setq target (concat (substring target 0 i) " "
1779 (substring target (match-end 0))))
1781 (Info-goto-node target)
1782 (setq Info-in-cross-reference t)))
1784 (defun Info-next-reference (n)
1786 (let ((pat (format "\\*%s[ \n\t]*\\([^:]*\\):\\|^\\* .*:\\|<<.*>>"
1789 wrapped found-nomenu)
1791 (unless (re-search-backward pat nil t)
1792 ;; Don't wrap more than once in a buffer where only the
1793 ;; menu references are found.
1794 (when (and wrapped (not found-nomenu))
1796 (error "No cross references in this node"))
1798 (goto-char (point-max))
1799 (unless (re-search-backward pat nil t)
1801 (error "No cross references in this node")))
1802 (unless (save-excursion
1803 (goto-char (match-beginning 0))
1804 (when (looking-at "\\* Menu:")
1806 (setq found-nomenu t))
1809 (or (eobp) (forward-char 1))
1810 (unless (re-search-forward pat nil t)
1811 (when (and wrapped (not found-nomenu))
1813 (error "No cross references in this node"))
1815 (goto-char (point-min))
1816 (unless (re-search-forward pat nil t)
1818 (error "No cross references in this node")))
1819 (unless (save-excursion
1820 (goto-char (match-beginning 0))
1821 (when (looking-at "\\* Menu:")
1823 (setq found-nomenu t))
1825 (when (looking-at "\\* Menu:")
1826 (error "No cross references in this node"))
1827 (goto-char (match-beginning 0))))
1829 (defun Info-prev-reference (n)
1831 (Info-next-reference (- n)))
1833 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1834 (skip-chars-forward " \t\n")
1837 (skip-chars-forward "^:")
1840 (if (looking-at ":")
1841 (buffer-substring beg (1- (point)))
1842 (skip-chars-forward " \t\n")
1843 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1844 (while (setq i (string-match "\n" str i))
1848 (defun Info-menu (menu-item)
1849 "Go to node for menu item named (or abbreviated) NAME.
1850 Completion is allowed, and the menu item point is on is the default."
1852 (let ((completions '())
1853 ;; If point is within a menu item, use that item as the default
1858 (goto-char (point-min))
1859 (let ((case-fold-search t))
1860 (if (not (search-forward "\n* menu:" nil t))
1861 (error "No menu in this node")))
1862 (while (re-search-forward
1863 "\n\\* \\([^:\t\n]*\\):" nil t)
1864 (if (and (null default)
1865 (prog1 (if last (< last p) nil)
1866 (setq last (match-beginning 0)))
1868 (setq default (car (car completions))))
1869 (setq completions (cons (cons (buffer-substring
1872 (match-beginning 1))
1874 (if (and (null default) last
1876 (<= p (progn (end-of-line) (point))))
1877 (setq default (car (car completions)))))
1880 (setq item (let ((completion-ignore-case t))
1881 (completing-read (if default
1882 (format "Menu item (default %s): "
1885 completions nil t nil
1886 'Info-minibuffer-history)))
1887 ;; we rely on the fact that completing-read accepts an input
1888 ;; of "" even when the require-match argument is true and ""
1889 ;; is not a valid possibility
1890 (if (string= item "")
1896 ;; there is a problem here in that if several menu items have the same
1897 ;; name you can only go to the node of the first with this command.
1898 (Info-goto-node (Info-extract-menu-item menu-item) nil t))
1900 (defun Info-extract-menu-item (menu-item &optional noerror)
1902 (goto-char (point-min))
1903 (if (let ((case-fold-search t))
1904 (search-forward "\n* menu:" nil t))
1905 (if (or (search-forward (concat "\n* " menu-item ":") nil t)
1906 (search-forward (concat "\n* " menu-item) nil t))
1910 (Info-extract-menu-node-name))
1911 (and (not noerror) (error "No such item in menu")))
1912 (and (not noerror) (error "No menu in this node")))))
1914 ;; If COUNT is nil, use the last item in the menu.
1915 (defun Info-extract-menu-counting (count &optional noerror noindex)
1917 (goto-char (point-min))
1918 (if (let ((case-fold-search t))
1919 (and (search-forward "\n* menu:" nil t)
1921 (not (string-match "\\<Index\\>" Info-current-node)))))
1922 (if (search-forward "\n* " nil t count)
1925 (while (search-forward "\n* " nil t)))
1926 (Info-extract-menu-node-name))
1927 (and (not noerror) (error "Too few items in menu")))
1928 (and (not noerror) (error "No menu in this node")))))
1930 (defun Info-nth-menu-item (n)
1931 "Go to the node of the Nth menu item."
1933 (or n (setq n (- last-command-char ?0)))
1934 (if (< n 1) (error "Index must be at least 1"))
1935 (Info-goto-node (Info-extract-menu-counting n) nil t))
1937 (defun Info-last-menu-item ()
1938 "Go to the node of the tenth menu item."
1940 (Info-goto-node (Info-extract-menu-counting nil) nil t))
1943 "Go to the Top node of this file."
1945 (Info-goto-node "Top"))
1948 "Go to the final node in this file."
1951 (let ((Info-keeping-history nil)
1953 (Info-last-menu-item)
1954 (while (setq node (or (Info-extract-pointer "next" t)
1955 (Info-extract-menu-counting nil t t)))
1956 (Info-goto-node node))
1957 (or (equal (Info-extract-pointer "up" t) "Top")
1958 (let ((executing-kbd-macro "")) ; suppress messages
1960 (Info-global-next 10000)
1963 (defun Info-global-next (&optional n)
1964 "Go to the next node in this file, traversing node structure as necessary.
1965 This works only if the Info file is structured as a hierarchy of nodes.
1966 A positive or negative prefix argument moves by multiple nodes."
1970 (Info-global-prev (- n))
1971 (while (>= (setq n (1- n)) 0)
1973 (cond ((and (string-match "^Top$" Info-current-node)
1974 (setq node (Info-extract-pointer "next" t))
1975 (Info-extract-menu-item node t))
1976 (Info-goto-node node))
1977 ((setq node (Info-extract-menu-counting 1 t t))
1978 (message "Going down...")
1979 (Info-goto-node node))
1981 (let ((Info-keeping-history Info-keeping-history)
1982 (orignode Info-current-node)
1984 (while (not (Info-extract-pointer "next" t))
1985 (if (and (setq node (Info-extract-pointer "up" t))
1986 (not (equal node "Top")))
1988 (message "Going%s..." (setq ups (concat ups " up")))
1989 (Info-goto-node node)
1990 (setq Info-keeping-history nil))
1992 (let ((Info-keeping-history nil))
1993 (Info-goto-node orignode)))
1994 (error "Last node in file")))
1997 (defun Info-page-next (&optional n)
1998 "Scroll forward one screenful, or go to next global node.
1999 A positive or negative prefix argument moves by multiple screenfuls."
2003 (Info-page-prev (- n))
2004 (while (>= (setq n (1- n)) 0)
2005 (if (pos-visible-in-window-p (point-max))
2008 (message "Node: %s" Info-current-node))
2011 (defun Info-scroll-next (arg)
2013 (if Info-auto-advance
2014 (if (and (pos-visible-in-window-p (point-max))
2015 (not (eq Info-auto-advance t))
2016 (not (eq last-command this-command)))
2017 (message "Hit %s again to go to next node"
2018 (if (= last-command-char 0)
2020 (key-description (char-to-string last-command-char))))
2022 (setq this-command 'Info))
2025 (defun Info-global-prev (&optional n)
2026 "Go to the previous node in this file, traversing structure as necessary.
2027 This works only if the Info file is structured as a hierarchy of nodes.
2028 A positive or negative prefix argument moves by multiple nodes."
2032 (Info-global-next (- n))
2033 (while (>= (setq n (1- n)) 0)
2034 (let ((upnode (Info-extract-pointer "up" t))
2035 (prevnode (Info-extract-pointer "prev[ious]*" t)))
2036 (if (or (not prevnode)
2037 (equal prevnode upnode))
2038 (if (string-match "^Top$" Info-current-node)
2039 (error "First node in file")
2040 (message "Going up...")
2042 (Info-goto-node prevnode)
2044 (Info-keeping-history nil)
2046 (while (setq node (Info-extract-menu-counting nil t t))
2047 (message "Going%s..." (setq downs (concat downs " down")))
2048 (Info-goto-node node))))))))
2050 (defun Info-page-prev (&optional n)
2051 "Scroll backward one screenful, or go to previous global node.
2052 A positive or negative prefix argument moves by multiple screenfuls."
2056 (Info-page-next (- n))
2057 (while (>= (setq n (1- n)) 0)
2058 (if (pos-visible-in-window-p (point-min))
2061 (message "Node: %s" Info-current-node)
2063 ;;(scroll-up 1) ; work around bug in pos-visible-in-window-p
2065 (while (not (pos-visible-in-window-p (point-max)))
2069 (defun Info-scroll-prev (arg)
2071 (if Info-auto-advance
2072 (if (and (pos-visible-in-window-p (point-min))
2073 (not (eq Info-auto-advance t))
2074 (not (eq last-command this-command)))
2075 (message "Hit %s again to go to previous node"
2076 (if (= last-command-char 0)
2078 (key-description (char-to-string last-command-char))))
2080 (setq this-command 'Info))
2083 (defun Info-index (topic)
2084 "Look up a string in the index for this file.
2085 The index is defined as the first node in the top-level menu whose
2086 name contains the word \"Index\", plus any immediately following
2087 nodes whose names also contain the word \"Index\".
2088 If there are no exact matches to the specified topic, this chooses
2089 the first match which is a case-insensitive substring of a topic.
2090 Use the `,' command to see the other matches.
2091 Give a blank topic name to go to the Index node itself."
2092 (interactive "sIndex topic: ")
2093 (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
2094 (regexp-quote topic)
2095 "\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"))
2097 (message "Searching index for `%s'..." topic)
2098 (Info-goto-node "Top")
2099 (let ((case-fold-search t))
2100 (or (search-forward "\n* menu:" nil t)
2102 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2103 (error "No index")))
2104 (goto-char (match-beginning 1))
2105 (let ((Info-keeping-history nil)
2106 (Info-fontify (and Info-fontify (equal topic ""))))
2107 (Info-goto-node (Info-extract-menu-node-name)))
2108 (or (equal topic "")
2111 (Info-keeping-history nil)
2115 (goto-char (point-min))
2116 (while (re-search-forward pattern nil t)
2118 (cons (list (buffer-substring (match-beginning 1)
2120 (buffer-substring (match-beginning 2)
2123 (string-to-int (concat "0"
2128 (and (setq node (Info-extract-pointer "next" t))
2129 (string-match "\\<Index\\>" node)))
2130 (let ((Info-fontify nil))
2131 (Info-goto-node node)))
2135 (error "No \"%s\" in index" topic)))
2136 ;; Here it is a feature that assoc is case-sensitive.
2137 (while (setq found (assoc topic matches))
2138 (setq exact (cons found exact)
2139 matches (delq found matches)))
2140 (setq Info-index-alternatives (nconc exact (nreverse matches))
2141 Info-index-first-alternative (car Info-index-alternatives))
2142 (Info-index-next 0)))))
2144 (defun Info-index-next (num)
2145 "Go to the next matching index item from the last `i' command."
2147 (or Info-index-alternatives
2148 (error "No previous `i' command in this file"))
2150 (setq num (+ num (length Info-index-alternatives))))
2152 (setq Info-index-alternatives
2153 (nconc (cdr Info-index-alternatives)
2154 (list (car Info-index-alternatives)))
2156 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2157 (if (> (nth 3 (car Info-index-alternatives)) 0)
2158 (forward-line (nth 3 (car Info-index-alternatives)))
2159 (forward-line 3) ; don't search in headers
2160 (let ((name (car (car Info-index-alternatives))))
2161 (if (or (re-search-forward (format
2162 "\\(Function\\|Command\\): %s\\( \\|$\\)"
2163 (regexp-quote name)) nil t)
2164 (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
2165 (search-forward (format "`%s'" name) nil t)
2166 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2168 (format "`%s'" (substring name 0 (match-beginning 1)))
2170 (search-forward name nil t))
2172 (goto-char (point-min)))))
2173 (message "Found \"%s\" in %s. %s"
2174 (car (car Info-index-alternatives))
2175 (nth 2 (car Info-index-alternatives))
2176 (if (cdr Info-index-alternatives)
2177 (if (eq (car (cdr Info-index-alternatives))
2178 Info-index-first-alternative)
2179 "(Press `,' to repeat)"
2180 (format "(Press `,' for %d more)"
2181 (- (1- (length Info-index-alternatives))
2182 (length (memq Info-index-first-alternative
2183 (cdr Info-index-alternatives))))))
2188 (defun Info-emacs-command (command)
2189 "Look up an Emacs command in the Emacs manual in the Info system.
2190 This command is designed to be used whether you are already in Info or not."
2191 (interactive "CLook up command in Emacs manual: ")
2192 (save-window-excursion
2194 (Info-find-node Info-emacs-info-file-name "Top")
2195 (Info-index (symbol-name command)))
2196 (pop-to-buffer "*info*"))
2200 (defun Info-goto-emacs-command-node (key)
2201 "Look up an Emacs command in the Emacs manual in the Info system.
2202 This command is designed to be used whether you are already in Info or not."
2203 (interactive "CLook up command in Emacs manual: ")
2204 (Info-emacs-command key))
2207 (defun Info-goto-emacs-key-command-node (key)
2208 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2209 This command is designed to be used whether you are already in Info or not."
2210 (interactive "kLook up key in Emacs manual: ")
2211 (let ((command (key-binding key)))
2212 (cond ((eq command 'keyboard-quit)
2215 (error "%s is undefined" (key-description key)))
2216 ((and (interactive-p) (eq command 'execute-extended-command))
2217 (call-interactively 'Info-goto-emacs-command-node))
2219 (Info-goto-emacs-command-node command)))))
2222 (defun Info-emacs-key (key)
2223 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2224 This command is designed to be used whether you are already in Info or not."
2225 (interactive "kLook up key in Emacs manual: ")
2226 (cond ((eq (key-binding key) 'keyboard-quit)
2228 ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
2229 (call-interactively 'Info-goto-emacs-command-node))
2231 (save-window-excursion
2233 (Info-find-node Info-emacs-info-file-name "Top")
2234 (setq key (key-description key))
2236 (if (setq p (string-match "[@{}]" key))
2237 (setq key (concat (substring key 0 p) "@" (substring key p))))
2238 (if (string-match "^ESC " key)
2239 (setq key (concat "M-" (substring key 4))))
2240 (if (string-match "^M-C-" key)
2241 (setq key (concat "C-M-" (substring key 4)))))
2243 (pop-to-buffer "*info*"))))
2246 (defun Info-elisp-ref (func)
2247 "Look up an Emacs Lisp function in the Elisp manual in the Info system.
2248 This command is designed to be used whether you are already in Info or not."
2249 (interactive (let ((fn (function-at-point))
2250 (enable-recursive-minibuffers t)
2252 (setq val (completing-read
2253 (format "Look up Emacs Lisp function%s: "
2255 (format " (default %s)" fn)
2257 obarray 'fboundp t))
2258 (list (if (equal val "")
2260 (save-window-excursion
2263 (Info-find-node "lispref" "Top")
2264 (error (Info-find-node "elisp" "Top")))
2265 (Info-index (symbol-name func)))
2266 (pop-to-buffer "*info*"))
2268 (defun Info-reannotate-node ()
2269 (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
2271 (let ((ibuf (current-buffer))
2272 (file (concat "\\(" (regexp-quote
2273 (file-name-nondirectory Info-current-file))
2274 "\\|" (regexp-quote Info-current-file) "\\)"))
2275 (node (regexp-quote Info-current-node))
2277 (goto-char (point-min))
2278 (if (search-forward "\n------ NOTE:\n" nil t)
2279 (let ((buffer-read-only nil)
2280 (bufmod (buffer-modified-p))
2282 (setq savept (copy-marker savept))
2283 (goto-char (point-min))
2284 (while (search-forward "\n------ NOTE:" nil t)
2285 (setq top (1+ (match-beginning 0)))
2286 (if (search-forward "\n------\n" nil t)
2287 (delete-region top (point)))
2289 (set-buffer-modified-p bufmod)))
2292 (set-buffer (car bufs))
2293 (goto-char (point-min))
2294 (while (re-search-forward
2296 "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
2299 (let ((line (string-to-int
2300 (buffer-substring (match-beginning 2)
2304 (search-forward "\n------\n" nil t)
2308 (if (integerp savept) (setq savept (copy-marker savept)))
2310 (goto-char (point-max))
2311 (goto-char (point-min))
2312 (forward-line line))
2313 (let ((buffer-read-only nil)
2314 (bufmod (buffer-modified-p)))
2315 (insert "------ NOTE:\n")
2316 (insert-buffer-substring (car bufs) top bot)
2317 (set-buffer-modified-p bufmod)))))
2318 (setq bufs (cdr bufs))))
2319 (goto-char savept)))))
2321 (defvar Info-annotate-map nil
2322 "Local keymap used within `a' command of Info.")
2323 (if Info-annotate-map
2325 ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
2326 (setq Info-annotate-map (copy-keymap text-mode-map))
2327 (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
2329 (defun Info-annotate-mode ()
2330 "Major mode for adding an annotation to an Info node.
2331 Like text mode with the addition of Info-cease-annotate
2332 which returns to Info mode for browsing.
2333 \\{Info-annotate-map}")
2335 (defun Info-annotate (arg)
2336 "Add a personal annotation to the current Info node.
2337 Only you will be able to see this annotation. Annotations are stored
2338 in the file \"~/.xemacs/info.notes\" by default. If point is inside
2339 an existing annotation, edit that annotation. A prefix argument
2340 specifies which annotations file (from `Info-annotations-path') is to
2341 be edited; default is 1."
2344 (if (or (< arg 0) (not (nth arg Info-annotations-path)))
2346 (setq Info-annotations-path
2347 (list (read-file-name
2348 "Annotations file: " "~/" "~/.infonotes")))
2349 (error "File number must be in the range from 1 to %d"
2350 (length Info-annotations-path))))
2352 (file (file-name-nondirectory Info-current-file))
2353 (d Info-directory-list)
2355 (while (and d (not (equal (expand-file-name file (car d))
2356 Info-current-file)))
2358 (or d (setq file Info-current-file))
2359 (if (and (save-excursion
2360 (goto-char (min (point-max) (+ (point) 13)))
2361 (and (search-backward "------ NOTE:\n" nil t)
2362 (setq pt (match-end 0))
2363 (search-forward "\n------\n" nil t)))
2364 (< (point) (match-end 0)))
2365 (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
2367 (regexp-quote Info-current-node)
2369 (buffer-substring pt (match-beginning 0))))
2370 where (max (- (point) pt) 0)))
2371 (let ((node Info-current-node)
2372 (line (if (looking-at "[ \n]*\\'") 0
2373 (count-lines (point-min) (point)))))
2375 (let ((buffer-read-only nil)
2376 (bufmod (buffer-modified-p)))
2378 (if (bobp) (goto-char (point-max)))
2379 (insert "------ NOTE:\n------\n")
2381 (set-buffer-modified-p bufmod)))
2382 ;; (setq Info-window-start (window-start))
2383 (setq Info-window-configuration (current-window-configuration))
2384 (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
2385 (use-local-map Info-annotate-map)
2386 (setq major-mode 'Info-annotate-mode)
2387 (setq mode-name "Info Annotate")
2390 (goto-char (point-min))
2391 (re-search-forward which nil t))
2393 (goto-char (match-beginning 0))
2395 (forward-char where)))
2396 (let ((bufmod (buffer-modified-p)))
2397 (goto-char (point-max))
2398 (insert (format "\n------ File: %s Node: %s Line: %d\n"
2401 (insert "\n------\n"
2402 "\nPress C-c C-c to save and return to Info.\n")
2404 (set-buffer-modified-p bufmod))))))
2406 (defun Info-cease-annotate ()
2408 (let ((bufmod (buffer-modified-p)))
2409 (while (save-excursion
2410 (goto-char (point-min))
2411 (re-search-forward "\n\n?Press .* to save and return to Info.\n"
2413 (delete-region (1+ (match-beginning 0)) (match-end 0)))
2414 (while (save-excursion
2415 (goto-char (point-min))
2416 (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
2418 (delete-region (match-beginning 0) (match-end 0)))
2419 (set-buffer-modified-p bufmod))
2423 (or (one-window-p) (delete-window))
2425 (setq Info-current-annotation-completions nil)
2426 (set-window-configuration Info-window-configuration)
2427 (Info-reannotate-node))
2429 (defun Info-bookmark (arg tag)
2430 (interactive "p\nsBookmark name: ")
2432 (if (or (string-match "^\"\\(.*\\)\"$" tag)
2433 (string-match "^<<\\(.*\\)>>$" tag))
2434 (setq tag (substring tag (match-beginning 1) (match-end 1))))
2436 (search-forward "\n------\n")
2437 (let ((end (- (point) 8)))
2439 (if (re-search-forward "<<[^>\n]*>>" nil t)
2440 (delete-region (match-beginning 0) (match-end 0))
2443 (insert "<<" tag ">>"))))
2444 (Info-cease-annotate))
2447 "Exit Info by selecting some other buffer."
2450 (save-buffers-kill-emacs)
2451 (bury-buffer (current-buffer))
2452 (if (and (featurep 'toolbar)
2453 (boundp 'toolbar-info-frame)
2454 (eq toolbar-info-frame (selected-frame)))
2456 (delete-frame toolbar-info-frame)
2457 (error (bury-buffer)))
2458 (switch-to-buffer (other-buffer (current-buffer))))))
2460 (defun Info-undefined ()
2461 "Make command be undefined in Info."
2466 "Enter the Info tutorial."
2468 (delete-other-windows)
2469 (Info-find-node "info"
2470 (if (< (window-height) 23)
2474 (defun Info-summary ()
2475 "Display a brief summary of all Info commands."
2477 (save-window-excursion
2478 (switch-to-buffer "*Help*")
2480 (insert (documentation 'Info-mode))
2481 (goto-char (point-min))
2483 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2484 (message (if flag "Type Space to see more"
2485 "Type Space to return to Info"))
2486 (let ((e (next-command-event)))
2487 (if (/= ?\ (event-to-character e))
2488 (progn (setq unread-command-event e) nil)
2492 (bury-buffer "*Help*")))
2494 (defun Info-get-token (pos start all &optional errorstring)
2495 "Return the token around POS,
2496 POS must be somewhere inside the token
2497 START is a regular expression which will match the
2498 beginning of the tokens delimited string
2499 ALL is a regular expression with a single
2500 parenthized subpattern which is the token to be
2501 returned. E.g. '{\(.*\)}' would return any string
2502 enclosed in braces around POS.
2503 SIG optional fourth argument, controls action on no match
2506 a string: signal an error, using that string."
2508 (goto-char (point-min))
2509 (re-search-backward "\\`") ; Bug fix due to Nicholas J. Foskett.
2511 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
2513 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2514 (not (setq found (and (<= (match-beginning 0) pos)
2515 (> (match-end 0) pos))))))
2516 (if (and found (<= (match-beginning 0) pos)
2517 (> (match-end 0) pos))
2518 (buffer-substring (match-beginning 1) (match-end 1))
2519 (cond ((null errorstring)
2525 (error "No %s around position %d" errorstring pos)))))))
2527 (defun Info-follow-clicked-node (event)
2528 "Follow a node reference near clicked point. Like M, F, N, P or U command.
2529 At end of the node's text, moves to the next node."
2531 (or (and (event-point event)
2532 (Info-follow-nearest-node
2534 (select-window (event-window event))
2535 (event-point event))
2537 (error "click on a cross-reference to follow")))
2539 (defun Info-maybe-follow-clicked-node (event &optional click-count)
2540 "Follow a node reference (if any) near clicked point.
2541 Like M, F, N, P or U command. At end of the node's text, moves to the
2542 next node. No error is given if there is no node to follow."
2544 (and Info-button1-follows-hyperlink
2546 (Info-follow-nearest-node
2548 (select-window (event-window event))
2549 (event-point event))
2550 (1+ (point-min))))))
2552 (defun Info-find-nearest-node (point)
2555 ((= point (point-min)) nil) ; don't trigger on accidental RET.
2556 ((setq node (Info-get-token point
2557 (format "\\*%s[ \n]" Info-footnote-tag)
2558 (format "\\*%s[ \n]\\([^:]*\\):"
2559 Info-footnote-tag)))
2560 (list "Following cross-reference %s..."
2561 (list 'Info-follow-reference node)))
2562 ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\)::"))
2563 (list "Selecting menu item %s..."
2564 (list 'Info-goto-node node nil t)))
2565 ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\):"))
2566 (list "Selecting menu item %s..."
2567 (list 'Info-menu node)))
2568 ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
2570 (list 'Info-goto-node node)))
2571 ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
2572 (list "Next node..."
2573 (list 'Info-goto-node node)))
2574 ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
2576 (list 'Info-goto-node "Top")))
2577 ((setq node (Info-get-token point "Prev[ious]*: "
2578 "Prev[ious]*: \\([^,\n\t]*\\)"))
2579 (list "Previous node..."
2580 (list 'Info-goto-node node)))
2581 ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
2582 (list "Reselecting %s..."
2583 (list 'Info-goto-node node)))
2584 ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
2585 (if Info-in-cross-reference
2586 (list "Back to last node..."
2588 (list "Next node..."
2589 '(Info-global-next)))))
2592 (defun Info-follow-nearest-node (point)
2593 "Follow a node reference near point. Like M, F, N, P or U command.
2594 At end of the node's text, moves to the next node."
2596 (let ((data (Info-find-nearest-node point)))
2599 (let ((msg (format (car data) (nth 1 (nth 1 data)))))
2602 (message "%sdone" msg))
2605 (defun Info-indicated-node (event)
2608 (cond ((eventp event)
2609 (set-buffer (event-buffer event))
2610 (setq event (event-point event))))
2611 (let* ((data (Info-find-nearest-node event))
2612 (name (nth 1 (nth 1 data))))
2613 (and name (nth 1 data))))
2616 (defun Info-mouse-track-double-click-hook (event click-count)
2617 "Handle double-clicks by turning pages, like the `gv' ghostscript viewer"
2618 (if (/= click-count 2)
2619 ;; Return nil so any other hooks are performed.
2621 (let* ((fw (face-width 'default))
2622 (fh (face-height 'default))
2623 (x (/ (event-x-pixel event) fw))
2624 (y (/ (event-y-pixel event) fw))
2625 (w (/ (window-pixel-width (event-window event)) fw))
2626 (h (/ (window-pixel-height (event-window event)) fh))
2630 ((<= y by) (Info-up) t)
2631 ((>= y (- h by)) (Info-nth-menu-item 1) t)
2632 ((<= x bx) (Info-prev) t)
2633 ((>= x (- w bx)) (Info-next) t)
2636 (defvar Info-mode-map nil
2637 "Keymap containing Info commands.")
2640 (setq Info-mode-map (make-sparse-keymap))
2641 (suppress-keymap Info-mode-map)
2642 (define-key Info-mode-map "." 'beginning-of-buffer)
2643 (define-key Info-mode-map " " 'Info-scroll-next)
2644 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2645 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2646 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2647 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2648 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2649 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2650 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2651 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2652 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2653 (define-key Info-mode-map "0" 'Info-last-menu-item)
2654 (define-key Info-mode-map "?" 'Info-summary)
2655 (define-key Info-mode-map "a" 'Info-annotate)
2656 (define-key Info-mode-map "b" 'beginning-of-buffer)
2657 (define-key Info-mode-map "d" 'Info-directory)
2658 (define-key Info-mode-map "e" 'Info-edit)
2659 (define-key Info-mode-map "f" 'Info-follow-reference)
2660 (define-key Info-mode-map "g" 'Info-goto-node)
2661 (define-key Info-mode-map "h" 'Info-help)
2662 (define-key Info-mode-map "i" 'Info-index)
2663 (define-key Info-mode-map "j" 'Info-goto-bookmark)
2664 (define-key Info-mode-map "k" 'Info-emacs-key)
2665 (define-key Info-mode-map "l" 'Info-last)
2666 (define-key Info-mode-map "m" 'Info-menu)
2667 (define-key Info-mode-map "n" 'Info-next)
2668 (define-key Info-mode-map "p" 'Info-prev)
2669 (define-key Info-mode-map "q" 'Info-exit)
2670 (define-key Info-mode-map "r" 'Info-follow-reference)
2671 (define-key Info-mode-map "s" 'Info-search)
2672 (define-key Info-mode-map "t" 'Info-top)
2673 (define-key Info-mode-map "u" 'Info-up)
2674 (define-key Info-mode-map "v" 'Info-visit-file)
2675 (define-key Info-mode-map "x" 'Info-bookmark)
2676 (define-key Info-mode-map "<" 'Info-top)
2677 (define-key Info-mode-map ">" 'Info-end)
2678 (define-key Info-mode-map "[" 'Info-global-prev)
2679 (define-key Info-mode-map "]" 'Info-global-next)
2680 (define-key Info-mode-map "{" 'Info-page-prev)
2681 (define-key Info-mode-map "}" 'Info-page-next)
2682 (define-key Info-mode-map "=" 'Info-restore-point)
2683 (define-key Info-mode-map "!" 'Info-select-node)
2684 (define-key Info-mode-map "@" 'Info-follow-nearest-node)
2685 (define-key Info-mode-map "," 'Info-index-next)
2686 (define-key Info-mode-map "*" 'Info-elisp-ref)
2687 (define-key Info-mode-map [tab] 'Info-next-reference)
2688 (define-key Info-mode-map [(meta tab)] 'Info-prev-reference)
2689 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2690 (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
2692 (define-key Info-mode-map 'backspace 'Info-scroll-prev)
2693 (define-key Info-mode-map 'delete 'Info-scroll-prev)
2694 (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
2695 (define-key Info-mode-map 'button3 'Info-select-node-menu))
2698 ;; Info mode is suitable only for specially formatted data.
2699 (put 'info-mode 'mode-class 'special)
2702 "Info mode is for browsing through the Info documentation tree.
2703 Documentation in Info is divided into \"nodes\", each of which
2704 discusses one topic and contains references to other nodes
2705 which discuss related topics. Info has commands to follow
2706 the references and show you other nodes.
2708 h Invoke the Info tutorial.
2709 q Quit Info: return to the previously selected file or buffer.
2711 Selecting other nodes:
2712 n Move to the \"next\" node of this node.
2713 p Move to the \"previous\" node of this node.
2714 m Pick menu item specified by name (or abbreviation).
2715 1-9, 0 Pick first..ninth, last item in node's menu.
2716 Menu items select nodes that are \"subsections\" of this node.
2717 u Move \"up\" from this node (i.e., from a subsection to a section).
2718 f or r Follow a cross reference by name (or abbrev). Type `l' to get back.
2719 RET Follow cross reference or menu item indicated by cursor.
2720 i Look up a topic in this file's Index and move to that node.
2721 , (comma) Move to the next match from a previous `i' command.
2722 l (letter L) Move back to the last node you were in.
2724 Moving within a node:
2725 Space Scroll forward a full screen. DEL Scroll backward.
2726 b Go to beginning of node. Meta-> Go to end of node.
2727 TAB Go to next cross-reference. Meta-TAB Go to previous ref.
2730 Left Button Set point (usual text-mode functionality)
2731 Middle Button Click on a highlighted node reference to go to it.
2732 Right Button Pop up a menu of applicable Info commands.
2734 Left Button Double Click in window edges:
2735 Top edge: Go up to the parent node, like `u'.
2736 Left edge: Go to the previous node, like `p'.
2737 Right edge: Go to the next node, like `n'.
2738 Bottom edge: Follow first menu item, like `1'.
2741 g Move to node, file, or annotation tag specified by name.
2742 Examples: `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
2743 v Move to file, with filename completion.
2744 k Look up a key sequence in Emacs manual (also C-h C-k at any time).
2745 * Look up a function name in Emacs Lisp manual (also C-h C-f).
2746 d Go to the main directory of Info files.
2747 < or t Go to Top (first) node of this file.
2748 > Go to last node in this file.
2749 \[ Go to previous node, treating file as one linear document.
2750 \] Go to next node, treating file as one linear document.
2751 { Scroll backward, or go to previous node if at top.
2752 } Scroll forward, or go to next node if at bottom.
2753 = Restore cursor position from last time in this node.
2754 a Add a private note (annotation) to the current node.
2755 x, j Add, jump to a bookmark (annotation tag).
2756 s Search this Info file for a node containing the specified regexp.
2757 e Edit the contents of the current node."
2758 (kill-all-local-variables)
2759 (setq major-mode 'Info-mode)
2760 (setq mode-name "Info")
2761 (use-local-map Info-mode-map)
2762 (set-syntax-table text-mode-syntax-table)
2763 (setq local-abbrev-table text-mode-abbrev-table)
2764 (setq case-fold-search t)
2765 (setq buffer-read-only t)
2766 ; (setq buffer-mouse-map Info-mode-mouse-map)
2767 (make-local-variable 'Info-current-file)
2768 (make-local-variable 'Info-current-subfile)
2769 (make-local-variable 'Info-current-node)
2770 (make-local-variable 'Info-tag-table-marker)
2771 (make-local-variable 'Info-current-file-completions)
2772 (make-local-variable 'Info-current-annotation-completions)
2773 (make-local-variable 'Info-index-alternatives)
2774 (make-local-variable 'Info-history)
2775 ;; Faces are now defined by `defface'...
2776 (make-local-variable 'mouse-track-click-hook)
2777 (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
2778 (add-hook 'mouse-track-click-hook 'Info-mouse-track-double-click-hook)
2779 ;; #### The console-on-window-system-p check is to allow this to
2780 ;; work on tty's. The real problem here is that featurep really
2781 ;; needs to have some device/console domain knowledge added to it.
2782 (if (and (featurep 'toolbar)
2783 (console-on-window-system-p)
2784 (not Info-inhibit-toolbar))
2785 (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
2786 (if (featurep 'menubar)
2788 ;; make a local copy of the menubar, so our modes don't
2789 ;; change the global menubar
2790 (easy-menu-add '("Info" :filter Info-menu-filter))))
2791 (run-hooks 'Info-mode-hook)
2792 (Info-set-mode-line))
2794 (defvar Info-edit-map nil
2795 "Local keymap used within `e' command of Info.")
2798 ;; XEmacs: remove FSF stuff
2799 (setq Info-edit-map (make-sparse-keymap))
2800 (set-keymap-name Info-edit-map 'Info-edit-map)
2801 (set-keymap-parents Info-edit-map (list text-mode-map))
2802 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
2804 ;; Info-edit mode is suitable only for specially formatted data.
2805 (put 'info-edit-mode 'mode-class 'special)
2807 (defun Info-edit-mode ()
2808 "Major mode for editing the contents of an Info node.
2809 Like text mode with the addition of `Info-cease-edit'
2810 which returns to Info mode for browsing.
2815 "Edit the contents of this Info node.
2816 Allowed only if variable `Info-enable-edit' is non-nil."
2818 (or Info-enable-edit
2819 (error "Editing info nodes is not enabled"))
2820 (use-local-map Info-edit-map)
2821 (setq major-mode 'Info-edit-mode)
2822 (setq mode-name "Info Edit")
2823 (kill-local-variable 'modeline-buffer-identification)
2824 (setq buffer-read-only nil)
2825 ;; Make mode line update.
2826 (set-buffer-modified-p (buffer-modified-p))
2827 (message (substitute-command-keys
2828 "Editing: Type \\[Info-cease-edit] to return to info")))
2830 (defun Info-cease-edit ()
2831 "Finish editing Info node; switch back to Info proper."
2833 ;; Do this first, so nothing has changed if user C-g's at query.
2834 (and (buffer-modified-p)
2835 (y-or-n-p-maybe-dialog-box "Save the file? ")
2837 (use-local-map Info-mode-map)
2838 (setq major-mode 'Info-mode)
2839 (setq mode-name "Info")
2840 (Info-set-mode-line)
2841 (setq buffer-read-only t)
2842 ;; Make mode line update.
2843 (set-buffer-modified-p (buffer-modified-p))
2844 (and (marker-position Info-tag-table-marker)
2846 (message "Tags may have changed. Use Info-tagify if necessary")))
2848 (defun Info-find-emacs-command-nodes (command)
2849 "Return a list of locations documenting COMMAND in the XEmacs Info manual.
2850 The locations are of the format used in Info-history, i.e.
2851 \(FILENAME NODENAME BUFFERPOS\)."
2853 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
2854 ":\\s *\\(.*\\)\\.$")))
2856 (Info-find-node "XEmacs" "Command Index")
2857 ;; Take the index node off the Info history.
2858 ;; ??? says this isn't safe someplace else... hmmm.
2859 (setq Info-history (cdr Info-history))
2860 (goto-char (point-max))
2861 (while (re-search-backward cmd-desc nil t)
2862 (setq where (cons (list Info-current-file
2870 ;;; fontification and mousability for info
2872 (defun Info-highlight-region (start end face)
2874 (splitp (string-match "\n[ \t]+" (buffer-substring start end))))
2877 (setq extent (make-extent start (progn (goto-char start)
2880 (set-extent-face extent face)
2881 (set-extent-property extent 'info t)
2882 (set-extent-property extent 'highlight t)
2883 (skip-chars-forward "\n\t ")
2884 (setq extent (make-extent (point) end)))
2885 (setq extent (make-extent start end)))
2886 (set-extent-face extent face)
2887 (set-extent-property extent 'info t)
2888 (set-extent-property extent 'highlight t)))
2890 (defun Info-fontify-node ()
2892 (let ((case-fold-search t)
2893 (xref-regexp (concat "\\*"
2894 (regexp-quote Info-footnote-tag)
2895 "[ \n\t]*\\([^:]*\\):")))
2896 ;; Clear the old extents
2897 (map-extents #'(lambda (x y) (delete-extent x))
2898 (current-buffer) (point-min) (point-max) nil)
2899 ;; Break the top line iff it is > 79 characters. Some info nodes
2900 ;; have top lines that span 3 lines because of long node titles.
2901 ;; eg: (Info-find-node "lispref.info" "Window-Level Event Position Info")
2902 (toggle-read-only -1)
2907 (goto-char (point-min))
2908 (re-search-forward "Node: *[^,]+, " nil t)
2909 (setq len (- (point) (point-min))
2910 extent (make-extent (point-min) (point)))
2911 (set-extent-property extent 'invisible t)
2915 (if (< (current-column) (+ 78 len))
2918 (forward-char (+ 79 len))
2919 (re-search-backward "," nil t)
2923 (backward-delete-char 1)
2926 (toggle-read-only 1)
2927 ;; Highlight xrefs in the top few lines of the node
2928 (goto-char (point-min))
2929 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
2931 (goto-char (match-end 0))
2933 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?\n?")
2934 (goto-char (match-end 0))
2935 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref))))
2936 ;; Now get the xrefs in the body
2937 (goto-char (point-min))
2938 (while (re-search-forward xref-regexp nil t)
2939 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2941 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref)))
2942 ;; then highlight the nodes in the menu.
2943 (goto-char (point-min))
2944 (if (and (search-forward "\n* menu:" nil t))
2945 (while (re-search-forward
2946 "^\\* \\([^:\t\n]*\\):?:[ \t\n]" nil t)
2947 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-node)))
2948 (set-buffer-modified-p nil))))
2950 (defun Info-construct-menu (&optional event)
2951 "Construct a menu of Info commands.
2952 Adds an entry for the node at EVENT, or under point if EVENT is omitted.
2953 Used to construct the menubar submenu and popup menu."
2954 (or event (setq event (point)))
2955 (let ((case-fold-search t)
2956 (xref-regexp (concat "\\*"
2957 (regexp-quote Info-footnote-tag)
2958 "[ \n\t]*\\([^:]*\\):"))
2959 up-p prev-p next-p menu xrefs subnodes in)
2961 ;; `one-space' fixes "Notes:" xrefs that are split across lines.
2965 (while (setq i (string-match "[ \n\t]+" text i))
2966 (setq text (concat (substring text 0 i) " "
2967 (substring text (match-end 0))))
2970 (goto-char (point-min))
2971 (if (looking-at ".*\\bNext:") (setq next-p t))
2972 (if (looking-at ".*\\bPrev:") (setq prev-p t))
2973 (if (looking-at ".*Up:") (setq up-p t))
2975 (if (setq in (Info-indicated-node event))
2976 (list (vector (one-space (cadr in)) in t)
2977 "--:shadowEtchedIn"))
2979 ["Goto Info Top-level" Info-directory]
2980 (vector "Next Node" 'Info-next :active next-p)
2981 (vector "Previous Node" 'Info-prev :active prev-p)
2982 (vector "Parent Node (Up)" 'Info-up :active up-p)
2983 ["Goto Node..." Info-goto-node]
2984 ["Goto Last Visited Node " Info-last])))
2985 ;; Find the xrefs and make a list
2986 (while (re-search-forward xref-regexp nil t)
2987 (setq xrefs (cons (one-space (buffer-substring (match-beginning 1)
2990 (setq xrefs (nreverse xrefs))
2991 (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
2992 ;; Find the subnodes and make a list
2993 (goto-char (point-min))
2994 (if (search-forward "\n* menu:" nil t)
2995 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
2996 (setq subnodes (cons (buffer-substring (match-beginning 1)
2999 (setq subnodes (nreverse subnodes))
3000 (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more))))
3002 (nconc menu (list "--:shadowDoubleEtchedIn"
3005 (mapcar #'(lambda (xref)
3009 (list 'Info-follow-reference xref))))
3012 (nconc menu (list "--:shadowDoubleEtchedIn"
3015 (mapcar #'(lambda (node)
3018 (vector node (list 'Info-menu node))))
3022 (defun Info-menu-filter (menu)
3023 "This is the menu filter for the \"Info\" submenu."
3024 (Info-construct-menu))
3026 (defun Info-select-node-menu (event)
3027 "Pops up a menu of applicable Info commands."
3029 (select-window (event-window event))
3030 (let ((menu (Info-construct-menu event)))
3031 (setq menu (nconc (list "Info" ; title: not displayed
3033 "--:shadowDoubleEtchedOut")
3035 (let ((popup-menu-titles nil))
3036 (popup-menu menu))))
3038 ;;; Info toolbar support
3040 ;; exit icon taken from GNUS
3041 (defvar info::toolbar-exit-icon
3042 (if (featurep 'toolbar)
3043 (toolbar-make-button-list
3044 (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
3045 toolbar-icon-directory)))
3048 (defvar info::toolbar-up-icon
3049 (if (featurep 'toolbar)
3050 (toolbar-make-button-list
3051 (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
3052 toolbar-icon-directory)))
3055 (defvar info::toolbar-next-icon
3056 (if (featurep 'toolbar)
3057 (toolbar-make-button-list
3058 (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
3059 toolbar-icon-directory)))
3062 (defvar info::toolbar-prev-icon
3063 (if (featurep 'toolbar)
3064 (toolbar-make-button-list
3065 (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
3066 toolbar-icon-directory)))
3069 (defvar info::toolbar
3070 (if (featurep 'toolbar)
3071 ; disabled until we get the next/prev-win icons working again.
3072 ; (cons (first initial-toolbar-spec)
3073 ; (cons (second initial-toolbar-spec)
3074 '([info::toolbar-exit-icon
3078 [info::toolbar-next-icon
3081 "Next entry in same section"]
3082 [info::toolbar-prev-icon
3085 "Prev entry in same section"]
3086 [info::toolbar-up-icon
3089 "Up entry to enclosing section"]
3095 (run-hooks 'Info-load-hook)
3097 ;;; info.el ends here