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
314 "The info package for Emacs."
318 (defgroup info-faces nil
319 "The faces used by info browser."
324 (defcustom Info-inhibit-toolbar nil
325 "*Non-nil means don't use the specialized Info toolbar."
329 (defcustom Info-novice nil
330 "*Non-nil means to ask for confirmation before switching Info files."
334 (defvar Info-history nil
335 "List of info nodes user has visited.
336 Each element of list is a list (\"(FILENAME)NODENAME\" BUFPOS WINSTART).")
338 (defvar Info-keeping-history t
339 "Non-nil if Info-find-node should modify Info-history.
340 This is for use only by certain internal Info routines.")
342 (defvar Info-minibuffer-history nil
343 "Minibuffer history for Info.")
345 (defcustom Info-enable-edit nil
346 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info
347 can edit the current node.
348 This is convenient if you want to write info files by hand.
349 However, we recommend that you not do this.
350 It is better to write a Texinfo file and generate the Info file from that,
351 because that gives you a printed manual as well."
355 (defcustom Info-enable-active-nodes t
356 "*Non-nil allows Info to execute Lisp code associated with nodes.
357 The Lisp code is executed when the node is selected."
361 (defcustom Info-restoring-point t
362 "*Non-nil means to restore the cursor position when re-entering a node."
366 (defcustom Info-auto-advance 'twice
367 "*Control what SPC and DEL do when they can't scroll any further.
368 If nil, they beep and remain in the current node.
369 If t, they move to the next node (like Info-global-next/prev).
370 If anything else, they must be pressed twice to move to the next node."
371 :type '(choice (const :tag "off" nil)
372 (const :tag "advance" t)
373 (const :tag "confirm" twice))
376 (defcustom Info-fontify t
377 "*Non-nil enables font features in XEmacs.
378 This variable is ignored unless running under XEmacs."
382 (defcustom Info-additional-search-directory-list nil
383 "*List of additional directories to search for Info documentation
384 files. These directories are not searched for merging the `dir'
385 file. An example might be something like:
386 \"/usr/local/lib/xemacs/packages/lisp/calc/\""
387 :type '(repeat directory)
390 (defcustom Info-auto-generate-directory 'if-missing
391 "*When to auto generate an info directory listing.
393 nil or `never' never auto-generate a directory listing,
394 use any existing `dir' or `localdir' file and ignore info
395 directories containing none
396 `always' auto-generate a directory listing ignoring existing
397 `dir' and `localdir' files
398 `if-missing', the default, auto-generates a directory listing
399 if no `dir' or `localdir' file is present. Otherwise the
400 contents of any of these files is used instead.
401 `if-outdated' auto-generates a directory listing if the `dir'
402 and `localdir' are either inexistent or outdated (touched
403 less recently than an info file in the same directory)."
404 :type '(choice (const :tag "never" never)
405 (const :tag "always" always)
406 (const :tag "if-missing" if-missing)
407 (const :tag "if-outdated" if-outdated))
410 (defcustom Info-save-auto-generated-dir nil
411 "*Whether an auto-generated info directory listing should be saved.
413 nil or `never', the default, auto-generated info directory
414 information will never be saved.
415 `always', auto-generated info directory information will be saved to
416 a `dir' file in the same directory overwriting it if it exists
417 `conservative', auto-generated info directory information will be saved
418 to a `dir' file in the same directory but the user is asked before
419 overwriting any existing file."
420 :type '(choice (const :tag "never" never)
421 (const :tag "always" always)
422 (const :tag "conservative" conservative))
425 (defvar Info-emacs-info-file-name "xemacs.info"
426 "The filename of the XEmacs info for
427 `Info-goto-emacs-command-node' (`\\<help-mode-map>\\[Info-goto-emacs-command-node]')")
430 (defvar Info-directory-list nil
431 "List of directories to search for Info documentation files.
433 The first directory in this list, the \"dir\" file there will become
434 the (dir)Top node of the Info documentation tree. If you wish to
435 modify the info search path, use `M-x customize-variable,
436 Info-directory-list' to do so.")
438 (defcustom Info-localdir-heading-regexp
439 "^Locally installed XEmacs Packages:?"
440 "The menu part of localdir files will be inserted below this topic
445 (defface info-node '((t (:bold t :italic t)))
446 "Face used for node links in info."
449 (defface info-xref '((t (:bold t)))
450 "Face used for cross-references in info."
453 ;; Is this right for NT? .zip, with -c for to stdout, right?
454 (defvar Info-suffix-list '( ("" . nil)
456 (".info.gz" . "gzip -dc %s")
457 (".info-z" . "gzip -dc %s")
458 (".info.Z" . "uncompress -c %s")
459 (".gz" . "gzip -dc %s")
460 (".Z" . "uncompress -c %s")
461 (".zip" . "unzip -c %s") )
462 "List of file name suffixes and associated decoding commands.
463 Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
464 changed to name of the file to decode, otherwise the file is given to
465 the command as standard input. If STRING is nil, no decoding is done.")
467 (defvar Info-footnote-tag "Note"
468 "*Symbol that identifies a footnote or cross-reference.
469 All \"*Note\" references will be changed to use this word instead.")
471 (defvar Info-current-file nil
472 "Info file that Info is now looking at, or nil.
473 This is the name that was specified in Info, not the actual file name.
474 It doesn't contain directory names or file name extensions added by Info.")
476 (defvar Info-current-subfile nil
477 "Info subfile that is actually in the *info* buffer now,
478 or nil if current info file is not split into subfiles.")
480 (defvar Info-current-node nil
481 "Name of node that Info is now looking at, or nil.")
483 (defvar Info-tag-table-marker (make-marker)
484 "Marker pointing at beginning of current Info file's tag table.
485 Marker points nowhere if file has no tag table.")
487 (defvar Info-current-file-completions nil
488 "Cached completion list for current Info file.")
490 (defvar Info-current-annotation-completions nil
491 "Cached completion list for current annotation files.")
493 (defvar Info-index-alternatives nil
494 "List of possible matches for last Info-index command.")
495 (defvar Info-index-first-alternative nil)
497 (defcustom Info-annotations-path '("~/.xemacs/info.notes"
499 "/usr/lib/info.notes")
500 "*Names of files that contain annotations for different Info nodes.
501 By convention, the first one should reside in your personal directory.
502 The last should be a world-writable \"public\" annotations file."
506 (defcustom Info-button1-follows-hyperlink nil
507 "*Non-nil means mouse button1 click will follow hyperlink."
511 (defvar Info-standalone nil
512 "Non-nil if Emacs was started solely as an Info browser.")
514 (defvar Info-in-cross-reference nil)
515 (defvar Info-window-configuration nil)
517 (defvar Info-dir-prologue "-*- Text -*-
518 This is the file .../info/dir, which contains the topmost node of the
519 Info hierarchy. The first time you invoke Info you start off
520 looking at that node, which is (dir)Top.
522 File: dir Node: Top This is the top of the INFO tree
523 This (the Directory node) gives a menu of major topics.
525 * Menu: The list of major topics begins on the next line.
529 (defvar Info-no-description-string "[No description available]"
530 "Description string for info files that have none")
533 (defun info (&optional file)
534 "Enter Info, the documentation browser.
535 Optional argument FILE specifies the file to examine;
536 the default is the top-level directory of Info.
538 In interactive use, a prefix argument directs this command
539 to read a file name from the minibuffer."
540 (interactive (if current-prefix-arg
541 (list (read-file-name "Info file name: " nil nil t))))
542 (let ((p command-line-args))
544 (and (string-match "^-[fe]" (car p))
545 (equal (nth 1 p) "info")
546 (not Info-standalone)
547 (setq Info-standalone t)
549 (not (string-match "^-" (nth 2 p)))
550 (setq file (nth 2 p))
551 (setq command-line-args-left nil))
553 ; (Info-setup-x) ??? What was this going to be? Can anyone tell karlheg?
556 (Info-goto-node (concat "(" file ")"))
557 (and Info-standalone (info)))
558 (if (get-buffer "*info*")
559 (switch-to-buffer "*info*")
563 (defun Info-query (file)
564 "Enter Info, the documentation browser. Prompt for name of Info file."
565 (interactive "sInfo topic (default = menu): ")
568 (Info-goto-node "(dir)")
569 (Info-goto-node (concat "(" file ")"))))
571 (defun Info-setup-initial ()
572 (let ((f Info-annotations-path))
574 (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
575 (bury-buffer (find-file-noselect (car f))))
578 (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
579 "Go to an info node specified as separate FILENAME and NODENAME.
580 Look for a plausible filename, or if not found then look for URL's and
581 dispatch to the appropriate fn. NO-GOING-BACK is non-nil if
582 recovering from an error in this function; it says do not attempt
583 further (recursive) error recovery. TRYFILE is ??"
588 ;; empty filename is simple case
590 (Info-find-file-node nil nodename no-going-back tryfile line))
591 ;; Convert filename to lower case if not found as specified.
592 ;; Expand it, look harder...
593 ((let (temp temp-downcase found
594 (fname (substitute-in-file-name filename)))
596 ((string-match "^\\./" fname) ; If specified name starts with `./'
597 (list default-directory)) ; then just try current directory.
598 ((file-name-absolute-p fname)
599 '(nil)) ; No point in searching for an absolute file name
600 (Info-additional-search-directory-list
601 (append Info-directory-list
602 Info-additional-search-directory-list))
603 (t Info-directory-list))))
604 ;; Search the directory list for file FNAME.
605 (while (and dirs (not found))
606 (setq temp (expand-file-name fname (car dirs)))
608 (expand-file-name (downcase fname) (car dirs)))
609 (if (equal temp-downcase temp) (setq temp-downcase nil))
610 ;; Try several variants of specified name.
611 ;; Try downcasing, appending a suffix, or both.
612 (setq found (Info-suffixed-file temp temp-downcase))
613 (setq dirs (cdr dirs)))
615 (progn (setq filename (expand-file-name found))
617 (Info-find-file-node filename nodename no-going-back tryfile line))
618 ;; Look for a URL. This pattern is stolen from w3.el to prevent
619 ;; loading it if we won't need it.
620 ((string-match (concat "^\\(wais\\|solo\\|x-exec\\|newspost\\|www\\|"
621 "mailto\\|news\\|tn3270\\|ftp\\|http\\|file\\|"
622 "telnet\\|gopher\\):")
624 (if (fboundp 'browse-url)
625 (browse-url filename)
626 (error "Cannot follow URLs in this XEmacs")))
628 (error "Info file %s does not exist" filename))))
630 (defun Info-find-file-node (filename nodename
631 &optional no-going-back tryfile line)
632 ;; This is the guts of what was Info-find-node. Whoever wrote this
633 ;; should be locked up where they can't do any more harm.
635 ;; Go into info buffer.
636 (switch-to-buffer "*info*")
637 (buffer-disable-undo (current-buffer))
638 (run-hooks 'Info-startup-hook)
639 (or (eq major-mode 'Info-mode)
642 (equal Info-current-file filename)
644 (string= "dir" (file-name-nondirectory Info-current-file))
645 (if (y-or-n-p-maybe-dialog-box
646 (format "Leave Info file `%s'? "
647 (file-name-nondirectory Info-current-file)))
650 ;; Record the node we are leaving.
651 (if (and Info-current-file (not no-going-back))
652 (Info-history-add Info-current-file Info-current-node (point)))
654 (setq Info-current-node nil
655 Info-in-cross-reference nil)
658 ;; Switch files if necessary
660 (equal Info-current-file filename)
661 (let ((buffer-read-only nil))
662 (setq Info-current-file nil
663 Info-current-subfile nil
664 Info-current-file-completions nil
665 Info-index-alternatives nil
666 buffer-file-name nil)
668 (if (string= "dir" (file-name-nondirectory filename))
670 (Info-insert-file-contents filename t)
671 (setq default-directory (file-name-directory filename)))
672 (set-buffer-modified-p nil)
673 ;; See whether file has a tag table. Record the location if yes.
674 (set-marker Info-tag-table-marker nil)
675 (goto-char (point-max))
677 (or (equal nodename "*")
678 (not (search-forward "\^_\nEnd tag table\n" nil t))
680 ;; We have a tag table. Find its beginning.
681 ;; Is this an indirect file?
682 (search-backward "\nTag table:\n")
686 (looking-at "(Indirect)\n"))
687 ;; It is indirect. Copy it to another buffer
688 ;; and record that the tag table is in that buffer.
690 (let ((buf (current-buffer)))
692 (get-buffer-create " *info tag table*"))
693 (buffer-disable-undo (current-buffer))
694 (setq case-fold-search t)
696 (insert-buffer-substring buf)
697 (set-marker Info-tag-table-marker
699 (set-marker Info-tag-table-marker pos))))
700 (setq Info-current-file
701 (file-name-sans-versions buffer-file-name))))
702 (if (equal nodename "*")
703 (progn (setq Info-current-node nodename)
705 (goto-char (point-min)))
706 ;; Search file for a suitable node.
707 (let* ((qnode (regexp-quote nodename))
708 (regexp (concat "Node: *" qnode " *[,\t\n\177]"))
709 (guesspos (point-min))
711 ;; First get advice from tag table if file has one.
712 ;; Also, if this is an indirect info file,
713 ;; read the proper subfile into this buffer.
714 (if (marker-position Info-tag-table-marker)
716 (set-buffer (marker-buffer Info-tag-table-marker))
717 (goto-char Info-tag-table-marker)
718 (if (re-search-forward regexp nil t)
720 (setq guesspos (read (current-buffer)))
721 ;; If this is an indirect file,
722 ;; determine which file really holds this node
724 (if (not (eq (current-buffer) (get-buffer "*info*")))
726 (Info-read-subfile guesspos)))))))
727 (goto-char (max (point-min) (- guesspos 1000)))
728 ;; Now search from our advised position (or from beg of buffer)
729 ;; to find the actual node.
731 (while (search-forward "\n\^_" nil t)
735 (if (re-search-backward regexp beg t)
738 (let ((bufs (delq nil (mapcar 'get-file-buffer
739 Info-annotations-path)))
740 (pattern (if (string-match "\\`<<.*>>\\'" qnode) qnode
741 (format "\"%s\"\\|<<%s>>" qnode qnode)))
742 (pat2 (concat "------ *File: *\\([^ ].*[^ ]\\) *Node: "
743 "*\\([^ ].*[^ ]\\) *Line: *\\([0-9]+\\)"))
744 (afile nil) anode aline)
745 (while (and bufs (not anode))
747 (set-buffer (car bufs))
748 (goto-char (point-min))
749 (if (re-search-forward pattern nil t)
750 (if (re-search-backward pat2 nil t)
751 (setq afile (buffer-substring (match-beginning 1)
753 anode (buffer-substring (match-beginning 2)
756 (buffer-substring (match-beginning 3)
758 (setq bufs (cdr bufs)))
760 (Info-find-node afile anode t nil aline)
763 (Info-find-node nodename "Top" t)
765 (or Info-current-node
766 (error "No such node: %s" nodename)))
770 (goto-char (point-min))
771 (if line (forward-line line)))))))
772 ;; If we did not finish finding the specified node,
773 ;; go back to the previous one.
774 (or Info-current-node no-going-back
775 (let ((hist (car Info-history)))
776 ;; The following is no longer safe with new Info-history system
777 ;; (setq Info-history (cdr Info-history))
778 (Info-goto-node (car hist) t)
779 (goto-char (+ (point-min) (nth 1 hist)))))))
781 ;; Cache the contents of the (virtual) dir file, once we have merged
782 ;; it for the first time, so we can save time subsequently.
783 (defvar Info-dir-contents nil)
785 ;; Cache for the directory we decided to use for the default-directory
786 ;; of the merged dir text.
787 (defvar Info-dir-contents-directory nil)
789 ;; Record the file attributes of all the files from which we
790 ;; constructed Info-dir-contents.
791 (defvar Info-dir-file-attributes nil)
793 (defun Info-insert-dir ()
794 "Construct the Info directory node by merging the files named
795 \"dir\" or \"localdir\" from the directories in `Info-directory-list'
796 The \"dir\" files will take precedence in cases where both exist. It
797 sets the *info* buffer's `default-directory' to the first directory we
798 actually get any text from."
799 (if (and Info-dir-contents Info-dir-file-attributes
800 ;; Verify that none of the files we used has changed
803 (mapcar '(lambda (elt)
804 (let ((curr (file-attributes (car elt))))
805 ;; Don't compare the access time.
806 (if curr (setcar (nthcdr 4 curr) 0))
807 (setcar (nthcdr 4 (cdr elt)) 0)
808 (equal (cdr elt) curr)))
809 Info-dir-file-attributes))))
810 (insert Info-dir-contents)
811 (let ((dirs (reverse Info-directory-list))
812 buffers lbuffers buffer others nodes dirs-done)
814 (setq Info-dir-file-attributes nil)
816 ;; Search the directory list for the directory file.
818 (let ((truename (file-truename (expand-file-name (car dirs)))))
819 (or (member truename dirs-done)
820 (member (directory-file-name truename) dirs-done)
821 ;; Try several variants of specified name.
822 ;; Try upcasing, appending `.info', or both.
827 (progn (setq file (expand-file-name "dir" truename))
828 (file-attributes file))
829 (progn (setq file (expand-file-name "DIR" truename))
830 (file-attributes file))
831 (progn (setq file (expand-file-name "dir.info" truename))
832 (file-attributes file))
833 (progn (setq file (expand-file-name "DIR.INFO" truename))
834 (file-attributes file))
835 (progn (setq file (expand-file-name "localdir" truename))
836 (file-attributes file))
837 (progn (setq file (expand-file-name "dir" truename))
842 (cons (directory-file-name truename)
844 (Info-maybe-update-dir file)
845 (setq attrs (file-attributes file))
846 (if (or (setq buf (find-buffer-visiting file))
850 (message "Composing main Info directory..."))
853 (if (string-match "localdir" file)
857 (insert-file-contents file))
858 (if (string-match "localdir" (buffer-name))
859 (setq lbuffers (cons (current-buffer) lbuffers))
860 (setq buffers (cons (current-buffer) buffers)))
862 (setq Info-dir-file-attributes
863 (cons (cons file attrs)
864 Info-dir-file-attributes)))))))
865 (or (cdr dirs) (setq Info-dir-contents-directory (car dirs)))
866 (setq dirs (cdr dirs))))
868 ;; ensure that the localdir files are inserted last, and reverse
869 ;; the list of them so that when they get pushed in, they appear
870 ;; in the same order they got specified in the path, from top to
872 (nconc buffers (reverse lbuffers))
875 (error "Can't find the Info directory node"))
876 ;; Distinguish the dir file that comes with Emacs from all the
877 ;; others. Yes, that is really what this is supposed to do.
878 ;; If it doesn't work, fix it.
879 (setq buffer (car buffers)
880 ;; reverse it since they are pushed down from the top. the
881 ;; `Info-directory-list can be specified in natural order
883 others (reverse (cdr buffers)))
885 ;; Insert the entire original dir file as a start; note that we've
886 ;; already saved its default directory to use as the default
887 ;; directory for the whole concatenation.
888 (insert-buffer buffer)
890 ;; Look at each of the other buffers one by one.
892 (let ((other (car others))
893 (info-buffer (current-buffer)))
894 (if (string-match "localdir" (buffer-name other))
896 (set-buffer info-buffer)
897 (goto-char (point-max))
899 ((re-search-backward "^ *\\* *Locals *: *$" nil t)
900 (delete-region (match-beginning 0) (match-end 0)))
901 ;; look for a line like |Local XEmacs packages:
902 ;; or mismatch on some text ...
903 ((re-search-backward Info-localdir-heading-regexp nil t)
904 ;; This is for people who underline topic headings with
905 ;; equal signs or dashes.
906 (when (save-excursion
909 (looking-at "^[ \t]*[-=*]+"))
913 (t (search-backward "\^L" nil t)))
914 ;; Insert menu part of the file
916 (len (length (buffer-string nil nil other))))
917 (insert (buffer-string nil nil other))
918 (goto-char (+ pt len))
921 (if (search-forward "* Menu:" (+ pt len) t)
924 (delete-region pt (point)))))))
925 ;; In each, find all the menus.
928 (goto-char (point-min))
929 ;; Find each menu, and add an elt to NODES for it.
930 (while (re-search-forward "^\\* Menu:" nil t)
931 (let (beg nodename end)
934 (search-backward "\n\^_")
935 (search-forward "Node: ")
936 (setq nodename (Info-following-node-name))
937 (search-forward "\n\^_" nil 'move)
940 (setq nodes (cons (list nodename other beg end) nodes))))))
941 (setq others (cdr others))))
943 ;; Add to the main menu a menu item for each other node.
944 (re-search-forward "^\\* Menu:" nil t)
946 (let ((menu-items '("top"))
949 (end (save-excursion (search-forward "\^_" nil t) (point))))
951 (let ((nodename (car (car nodes))))
953 (or (member (downcase nodename) menu-items)
954 (re-search-forward (concat "^\\* "
955 (regexp-quote nodename)
959 (insert "* " nodename "::" "\n")
960 (setq menu-items (cons nodename menu-items))))))
961 (setq nodes (cdr nodes))))
962 ;; Now take each node of each of the other buffers
963 ;; and merge it into the main buffer.
965 (let ((nodename (car (car nodes))))
966 (goto-char (point-min))
967 ;; Find the like-named node in the main buffer.
968 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
969 (regexp-quote nodename)
973 (search-forward "\n\^_" nil 'move)
976 ;; If none exists, add one.
977 (goto-char (point-max))
978 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
979 ;; Merge the text from the other buffer's menu
980 ;; into the menu in the like-named node in the main buffer.
981 (apply 'insert-buffer-substring (cdr (car nodes))))
982 (setq nodes (cdr nodes)))
983 ;; Kill all the buffers we just made.
985 (kill-buffer (car buffers))
986 (setq buffers (cdr buffers)))
988 (kill-buffer (car lbuffers))
989 (setq lbuffers (cdr lbuffers)))
990 (message "Composing main Info directory...done"))
991 (setq Info-dir-contents (buffer-string)))
992 (setq default-directory Info-dir-contents-directory)
993 (setq buffer-file-name (caar Info-dir-file-attributes)))
995 (defun Info-maybe-update-dir (file)
996 "Rebuild dir or localdir according to `Info-auto-generate-directory'."
997 (unless (or (not (file-exists-p (file-name-directory file)))
998 (null (directory-files (file-name-directory file) nil "\\.info")))
999 (if (not (find-buffer-visiting file))
1000 (if (not (file-exists-p file))
1001 (if (or (eq Info-auto-generate-directory 'always)
1002 (eq Info-auto-generate-directory 'if-missing))
1003 (Info-build-dir-anew (file-name-directory file)))
1004 (if (or (eq Info-auto-generate-directory 'always)
1005 (and (eq Info-auto-generate-directory 'if-outdated)
1006 (Info-dir-outdated-p file)))
1007 (Info-rebuild-dir file))))))
1009 ;; Record which *.info files are newer than the dir file
1010 (defvar Info-dir-newer-info-files nil)
1012 (defun Info-dir-outdated-p (file)
1013 "Return non-nil if dir or localdir is outdated.
1014 dir or localdir are outdated when an info file in the same
1015 directory has been modified more recently."
1016 (let ((dir-mod-time (nth 5 (file-attributes file)))
1019 (setq Info-dir-newer-info-files nil)
1023 (setq f-mod-time (nth 5 (file-attributes f)))
1024 (setq newer (or (> (car f-mod-time) (car dir-mod-time))
1025 (and (= (car f-mod-time) (car dir-mod-time))
1026 (> (car (cdr f-mod-time)) (car (cdr dir-mod-time))))))
1027 (if (and (file-readable-p f)
1029 (setq Info-dir-newer-info-files
1030 (cons f Info-dir-newer-info-files)))))
1031 (directory-files (file-name-directory file)
1033 ".*\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1036 Info-dir-newer-info-files))
1038 (defun Info-extract-dir-entry-from (file)
1039 "Extract the dir entry from the info FILE.
1040 The dir entry is delimited by the markers `START-INFO-DIR-ENTRY'
1041 and `END-INFO-DIR-ENTRY'"
1043 (set-buffer (get-buffer-create " *Info-tmp*"))
1044 (when (file-readable-p file)
1045 (insert-file-contents file nil nil nil t)
1046 (goto-char (point-min))
1048 (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
1051 (unless (null (re-search-forward "^END-INFO-DIR-ENTRY" nil t))
1052 (goto-char (match-beginning 0))
1053 (car (Info-parse-dir-entries beg (point)))))))))
1055 ;; Parse dir entries contained between BEG and END into a list of the form
1056 ;; (filename topic node (description-line-1 description-line-2 ...))
1057 (defun Info-parse-dir-entries (beg end)
1058 (let (entry entries)
1061 (narrow-to-region beg end)
1063 (while (re-search-forward "^\\* \\([^:]+\\):\\([ \t]*(\\([^)]*\\))\\w*\\.\\|:\\)" nil t)
1064 (setq entry (list (match-string 2)
1066 (downcase (or (match-string 3)
1067 (match-string 1)))))
1074 (re-search-forward "[ \t]*" nil t)
1075 (or (and (re-search-forward "^[^ \t]" nil t)
1076 (goto-char (match-beginning 0)))
1078 "[ \t]*\n[ \t]*"))))
1080 (setq entries (cons (nreverse entry) entries)))))
1081 (nreverse entries)))
1083 (defun Info-dump-dir-entries (entries)
1087 (mapcar '(lambda (e)
1088 (setq e (cdr e)) ; Drop filename
1089 (setq len (length (concat (car e)
1091 (if (> len description-col)
1092 (setq description-col len)))
1094 (setq description-col (+ 5 description-col))
1095 (mapcar '(lambda (e)
1096 (setq e (cdr e)) ; Drop filename
1097 (insert "* " (car e) ":" (car (cdr e)))
1098 (setq e (car (cdr (cdr e))))
1100 (indent-to-column description-col)
1101 (insert (car e) "\n")
1107 (defun Info-build-dir-anew (directory)
1108 "Build info directory information for DIRECTORY.
1109 The generated directory listing may be saved to a `dir' according
1110 to the value of `Info-save-auto-generated-dir'"
1112 (let* ((dirfile (expand-file-name "dir" directory))
1113 (to-temp (or (null Info-save-auto-generated-dir)
1114 (eq Info-save-auto-generated-dir 'never)
1115 (and (not (file-writable-p dirfile))
1116 (message "File not writable %s. Using temporary." dirfile))))
1118 (directory-files directory
1120 ".*\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1124 (message "Creating temporary dir in %s..." directory)
1125 (message "Creating %s..." dirfile))
1126 (set-buffer (find-file-noselect dirfile t))
1127 (setq buffer-read-only nil)
1129 (insert Info-dir-prologue
1130 "Info files in " directory ":\n\n")
1131 (Info-dump-dir-entries
1134 (or (Info-extract-dir-entry-from f)
1137 (string-match "\\(.*\\)\\.info\\(.gz\\|.Z\\|-z\\|.zip\\)?$"
1138 (file-name-nondirectory f))
1139 (capitalize (match-string 1 (file-name-nondirectory f))))
1141 (list Info-no-description-string))))
1144 (set-buffer-modified-p nil)
1147 (message "Creating temporary dir in %s...done" directory)
1148 (message "Creating %s...done" dirfile)))))
1151 (defun Info-rebuild-dir (file)
1152 "Build info directory information in the directory of dir FILE.
1153 Description of info files are merged from the info files in the
1154 directory and the contents of FILE with the description in info files
1155 taking precedence over descriptions in FILE.
1156 The generated directory listing may be saved to a `dir' according to
1157 the value of `Info-save-auto-generated-dir' "
1160 (let (dir-section-contents dir-full-contents
1166 (or (null Info-save-auto-generated-dir)
1167 (eq Info-save-auto-generated-dir 'never)
1168 (and (eq Info-save-auto-generated-dir 'always)
1169 (not (file-writable-p file))
1170 (message "File not writable %s. Using temporary." file))
1171 (and (eq Info-save-auto-generated-dir 'conservative)
1172 (or (and (not (file-writable-p file))
1173 (message "File not writable %s. Using temporary." file))
1175 (message "%s is outdated. Overwrite ? "
1177 (set-buffer (find-file-noselect file t))
1178 (setq buffer-read-only nil)
1180 (message "Rebuilding temporary %s..." file)
1181 (message "Rebuilding %s..." file))
1183 (setq buffer-read-only nil)
1184 (goto-char (point-min))
1185 (unless (and (search-forward "\^_")
1186 (re-search-forward "^\\* Menu:.*$" nil t)
1187 (setq mark (and (re-search-forward "^\\* " nil t)
1188 (match-beginning 0))))
1190 (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1191 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$" nil t)
1192 (match-beginning 0))
1195 (narrow-to-region mark next-section)
1196 (setq dir-section-contents (nreverse (Info-parse-dir-entries (point-min)
1198 (mapcar '(lambda (file)
1199 (setq dir-entry (assoc (downcase
1200 (file-name-sans-extension
1201 (file-name-nondirectory file)))
1202 dir-section-contents)
1203 file-dir-entry (Info-extract-dir-entry-from file))
1206 ;; A dir entry in the info file takes precedence over an
1207 ;; existing entry in the dir file
1208 (setcdr dir-entry (cdr file-dir-entry)))
1209 (unless (or not-first-section
1211 (file-name-sans-extension
1212 (file-name-nondirectory file)))
1215 (setq dir-section-contents (cons file-dir-entry
1216 dir-section-contents))
1217 (setq dir-section-contents
1219 (capitalize (file-name-sans-extension
1220 (file-name-nondirectory file)))
1222 (list Info-no-description-string))
1223 dir-section-contents))))))
1224 Info-dir-newer-info-files)
1225 (delete-region (point-min) (point-max))
1226 (Info-dump-dir-entries (nreverse dir-section-contents))
1228 (if (= next-section (point-max))
1229 (setq next-section nil)
1230 (or (setq mark (and (re-search-forward "^\\* " nil t)
1231 (match-beginning 0)))
1233 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$" nil t)
1234 (match-beginning 0))
1236 (setq not-first-section t)))
1239 (set-buffer-modified-p nil)
1240 (message "Rebuilding temporary %s...done" file))
1242 (message "Rebuilding %s...done" file))))))
1245 (defun Info-batch-rebuild-dir ()
1246 "(Re)build info `dir' files in the directories remaining on the command line.
1247 Use this from the command line, with `-batch';
1248 it won't work in an interactive Emacs.
1249 Each file is processed even if an error occurred previously.
1250 For example, invoke \"xemacs -batch -f Info-batch-rebuild-dir /usr/local/info\""
1251 ;; command-line-args-left is what is left of the command line (from
1253 (defvar command-line-args-left) ; Avoid 'free variable' warning
1254 (if (not noninteractive)
1255 (error "`Info-batch-rebuild-dir' is to be used only with -batch"))
1256 (let ((Info-save-auto-generated-dir 'always)
1258 (while command-line-args-left
1259 (if (not (file-directory-p (car command-line-args-left)))
1260 (message "Warning: Skipped %s. Not a directory."
1261 (car command-line-args-left))
1262 (setq dir (expand-file-name "dir" (car command-line-args-left)))
1263 (setq localdir (expand-file-name "localdir" (car command-line-args-left)))
1265 ((file-exists-p dir)
1266 (Info-rebuild-dir dir))
1267 ((file-exists-p localdir)
1268 (Info-rebuild-dir localdir))
1270 (Info-build-dir-anew (car command-line-args-left)))))
1271 (setq command-line-args-left (cdr command-line-args-left)))
1275 (defun Info-history-add (file node point)
1276 (if Info-keeping-history
1277 (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
1278 (found (assoc name Info-history)))
1280 (setq Info-history (delq found Info-history)))
1281 (setq Info-history (cons (list name (- point (point-min))
1282 (and (eq (window-buffer)
1284 (- (window-start) (point-min))))
1287 (defun Info-file-name-only (file)
1288 (let ((dir (file-name-directory file))
1289 (p Info-directory-list))
1290 (while (and p (not (equal (car p) dir)))
1292 (if p (file-name-nondirectory file) file)))
1294 (defun Info-read-subfile (nodepos)
1295 (set-buffer (marker-buffer Info-tag-table-marker))
1296 (goto-char (point-min))
1297 (search-forward "\n\^_")
1302 (while (not (looking-at "\^_"))
1305 thisfilepos thisfilename)
1306 (search-forward ": ")
1307 (setq thisfilename (buffer-substring beg (- (point) 2)))
1308 (setq thisfilepos (read (current-buffer)))
1309 ;; read in version 19 stops at the end of number.
1310 ;; Advance to the next line.
1313 (if (> thisfilepos nodepos)
1315 (setq lastfilename thisfilename)
1316 (setq lastfilepos thisfilepos))
1318 (set-buffer (get-buffer "*info*"))
1319 (or (equal Info-current-subfile lastfilename)
1320 (let ((buffer-read-only nil))
1321 (setq buffer-file-name nil)
1324 (Info-insert-file-contents (Info-suffixed-file
1325 (expand-file-name lastfilename
1326 (file-name-directory
1327 Info-current-file)))
1329 (set-buffer-modified-p nil)
1330 (setq Info-current-subfile lastfilename)))
1331 (goto-char (point-min))
1332 (search-forward "\n\^_")
1333 (+ (- nodepos lastfilepos) (point))))
1335 (defun Info-suffixed-file (name &optional name2)
1336 "Look for NAME with each of the `Info-suffix-list' extensions in
1337 turn. Optional NAME2 is the name of a fallback info file to check
1338 for; usually a downcased version of NAME."
1339 (let ((suff Info-suffix-list)
1342 (while (and suff (not found))
1343 (setq file (concat name (caar suff))
1344 file2 (and name2 (concat name2 (caar suff))))
1346 ((file-regular-p file)
1348 ((and file2 (file-regular-p file2))
1351 (setq suff (cdr suff)))))
1353 (and name (when (file-regular-p name)
1355 (and name2 (when (file-regular-p name2)
1358 (defun Info-insert-file-contents (file &optional visit)
1359 (setq file (expand-file-name file default-directory))
1360 (let ((suff Info-suffix-list))
1361 (while (and suff (or (<= (length file) (length (car (car suff))))
1362 (not (equal (substring file
1363 (- (length (car (car suff)))))
1364 (car (car suff))))))
1365 (setq suff (cdr suff)))
1366 (if (stringp (cdr (car suff)))
1367 (let ((command (if (string-match "%s" (cdr (car suff)))
1368 (format (cdr (car suff)) file)
1369 (concat (cdr (car suff)) " < " file))))
1370 (message "%s..." command)
1371 (if (eq system-type 'vax-vms)
1372 (call-process command nil t nil)
1373 (call-process shell-file-name nil t nil "-c" command))
1377 (setq buffer-file-name file)
1378 (set-buffer-modified-p nil)
1379 (clear-visited-file-modtime))))
1380 (insert-file-contents file visit))))
1382 (defun Info-select-node ()
1383 "Select the node that point is in, after using `g *' to select whole file."
1387 ;; Find beginning of node.
1388 (search-backward "\n\^_")
1390 ;; Get nodename spelled as it is in the node.
1391 (re-search-forward "Node:[ \t]*")
1392 (setq Info-current-node
1393 (buffer-substring (point)
1395 (skip-chars-forward "^,\t\n")
1397 (Info-set-mode-line)
1398 ;; Find the end of it, and narrow.
1400 (let (active-expression)
1401 (narrow-to-region (point)
1402 (if (re-search-forward "\n[\^_\f]" nil t)
1405 (if (looking-at "[\n\^_\f]*execute: ")
1407 (goto-char (match-end 0))
1408 (setq active-expression
1409 (read (current-buffer))))))
1411 (or (equal Info-footnote-tag "Note")
1413 (goto-char (point-min))
1414 (let ((buffer-read-only nil)
1415 (bufmod (buffer-modified-p))
1416 (case-fold-search t))
1417 (while (re-search-forward "\\*[Nn]ote\\([ \n]\\)" nil t)
1418 (replace-match (concat "*" Info-footnote-tag "\ ")))
1419 (set-buffer-modified-p bufmod))))
1420 (Info-reannotate-node)
1421 ;; XEmacs: remove v19 test
1423 (Info-fontify-node))
1424 (run-hooks 'Info-select-hook)
1425 (if Info-enable-active-nodes (eval active-expression)))))
1427 (defun Info-set-mode-line ()
1428 (setq modeline-buffer-identification
1429 (list (cons modeline-buffer-id-left-extent "Info: ")
1430 (cons modeline-buffer-id-right-extent
1433 (if Info-current-file
1434 (let ((name (file-name-nondirectory Info-current-file)))
1435 (if (string-match "\\.info$" name)
1436 (substring name 0 -5)
1440 (or Info-current-node ""))))))
1442 ;; Go to an info node specified with a filename-and-nodename string
1443 ;; of the sort that is found in pointers in nodes.
1446 (defun Info-goto-node (nodename &optional no-going-back tryfile)
1447 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
1448 Actually, the following interpretations of NAME are tried in order:
1450 (FILENAME) (using Top node)
1451 NODENAME (in current file)
1453 FILENAME (using Top node)
1454 where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
1455 annotation for any node of any file. (See `a' and `x' commands.)"
1456 (interactive (list (Info-read-node-name "Goto node, file or tag: ")
1459 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1461 (setq filename (if (= (match-beginning 1) (match-end 1))
1463 (substring nodename (match-beginning 2) (match-end 2)))
1464 nodename (substring nodename (match-beginning 3) (match-end 3)))
1465 (let ((trim (string-match "\\s *\\'" filename)))
1466 (if trim (setq filename (substring filename 0 trim))))
1467 (let ((trim (string-match "\\s *\\'" nodename)))
1468 (if trim (setq nodename (substring nodename 0 trim))))
1469 (Info-find-node (if (equal filename "") nil filename)
1470 (if (equal nodename "") "Top" nodename)
1471 no-going-back (and tryfile (equal filename "")))))
1473 (defun Info-goto-bookmark ()
1475 (let ((completion-ignore-case nil)
1476 (tag (completing-read "Goto tag: "
1477 (Info-build-annotation-completions)
1479 'Info-minibuffer-history)))
1480 (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
1483 (defun Info-visit-file ()
1484 "Directly visit an info file."
1486 (let* ((insert-default-directory nil)
1487 (file (read-file-name "Goto Info file: " "" "")))
1488 (or (equal file "") (Info-find-node (expand-file-name file) "Top"))))
1490 (defun Info-restore-point (&optional always)
1491 "Restore point to same location it had last time we were in this node."
1493 (if (or Info-restoring-point always)
1494 (let* ((name (format "(%s)%s"
1495 (Info-file-name-only Info-current-file)
1497 (p (assoc name Info-history)))
1498 (if p (Info-restore-history-entry p)))))
1500 (defun Info-restore-history-entry (entry)
1501 (goto-char (+ (nth 1 entry) (point-min)))
1503 (get-buffer-window (current-buffer))
1504 (set-window-start (get-buffer-window (current-buffer))
1505 (+ (nth 2 entry) (point-min)))))
1507 (defun Info-read-node-name (prompt &optional default)
1508 (Info-setup-initial)
1509 (let* ((completion-ignore-case t)
1510 (nodename (completing-read prompt
1511 (Info-build-node-completions)
1513 'Info-minibuffer-history)))
1514 (if (equal nodename "")
1516 (Info-read-node-name prompt))
1519 (defun Info-build-annotation-completions ()
1520 (or Info-current-annotation-completions
1522 (let ((bufs (delq nil (mapcar 'get-file-buffer
1523 Info-annotations-path)))
1526 (set-buffer (car bufs))
1527 (goto-char (point-min))
1528 (while (re-search-forward "<<\\(.*\\)>>" nil t)
1529 (setq compl (cons (list (buffer-substring (match-beginning 1)
1532 (setq bufs (cdr bufs)))
1533 (setq Info-current-annotation-completions compl)))))
1535 (defun Info-build-node-completions ()
1536 (or Info-current-file-completions
1537 (let ((compl (Info-build-annotation-completions)))
1540 (if (marker-buffer Info-tag-table-marker)
1542 (set-buffer (marker-buffer Info-tag-table-marker))
1543 (goto-char Info-tag-table-marker)
1544 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
1546 (cons (list (buffer-substring (match-beginning 1)
1550 (goto-char (point-min))
1551 (while (search-forward "\n\^_" nil t)
1553 (let ((beg (point)))
1555 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
1558 (cons (list (buffer-substring (match-beginning 1)
1561 (setq Info-current-file-completions compl))))
1563 (defvar Info-last-search nil
1564 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1568 (defun Info-search (regexp)
1569 "Search for REGEXP, starting from point, and select node it's found in."
1570 (interactive "sSearch (regexp): ")
1571 (if (equal regexp "")
1572 (setq regexp Info-last-search)
1573 (setq Info-last-search regexp))
1574 (with-caps-disable-folding regexp
1576 (onode Info-current-node)
1577 (ofile Info-current-file)
1579 (osubfile Info-current-subfile))
1583 (if (null Info-current-subfile)
1584 (progn (re-search-forward regexp) (setq found (point)))
1586 (progn (re-search-forward regexp) (setq found (point)))
1587 (search-failed nil)))))
1588 (if (not found) ;can only happen in subfile case -- else would have erred
1591 (set-buffer (marker-buffer Info-tag-table-marker))
1592 (goto-char (point-min))
1593 (search-forward "\n\^_\nIndirect:")
1595 (narrow-to-region (point)
1596 (progn (search-forward "\n\^_")
1598 (goto-char (point-min))
1599 (search-forward (concat "\n" osubfile ": "))
1602 (re-search-forward "\\(^.*\\): [0-9]+$")
1603 (goto-char (+ (match-end 1) 2))
1604 (setq list (cons (cons (read (current-buffer))
1605 (buffer-substring (match-beginning 1)
1608 (goto-char (1+ (match-end 0))))
1609 (setq list (nreverse list)
1612 (message "Searching subfile %s..." (cdr (car list)))
1613 (Info-read-subfile (car (car list)))
1614 (setq list (cdr list))
1615 (goto-char (point-min))
1616 (if (re-search-forward regexp nil t)
1617 (setq found (point) list ())))
1620 (signal 'search-failed (list regexp))))
1622 (progn (Info-read-subfile opoint)
1624 (Info-select-node)))))
1628 (or (and (equal onode Info-current-node)
1629 (equal ofile Info-current-file))
1630 (Info-history-add ofile onode opoint)))))
1632 ;; Extract the value of the node-pointer named NAME.
1633 ;; If there is none, use ERRORNAME in the error message;
1634 ;; if ERRORNAME is nil, just return nil.
1635 (defun Info-extract-pointer (name &optional errorname)
1637 (goto-char (point-min))
1639 (let ((case-fold-search t))
1640 (if (re-search-backward (concat name ":") nil t)
1642 (goto-char (match-end 0))
1643 (Info-following-node-name))
1644 (if (eq errorname t)
1646 (error (concat "Node has no " (capitalize (or errorname name)))))))))
1648 ;; Return the node name in the buffer following point.
1649 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1650 ;; saying which chas may appear in the node name.
1651 (defun Info-following-node-name (&optional allowedchars)
1652 (skip-chars-forward " \t")
1656 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1657 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1658 (if (looking-at "(")
1659 (skip-chars-forward "^)")))
1660 (skip-chars-backward " ")
1663 (defun Info-next (&optional n)
1664 "Go to the next node of this node.
1665 A positive or negative prefix argument moves by multiple nodes."
1670 (while (>= (setq n (1- n)) 0)
1671 (Info-goto-node (Info-extract-pointer "next")))))
1673 (defun Info-prev (&optional n)
1674 "Go to the previous node of this node.
1675 A positive or negative prefix argument moves by multiple nodes."
1680 (while (>= (setq n (1- n)) 0)
1681 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
1683 (defun Info-up (&optional n)
1684 "Go to the superior node of this node.
1685 A positive prefix argument moves up several times."
1688 (while (>= (setq n (1- n)) 0)
1689 (Info-goto-node (Info-extract-pointer "up")))
1690 (if (interactive-p) (Info-restore-point)))
1692 (defun Info-last (&optional n)
1693 "Go back to the last node visited.
1694 With a prefix argument, go to Nth most recently visited node. History is
1695 circular; after oldest node, history comes back around to most recent one.
1696 Argument can be negative to go through the circle in the other direction.
1697 \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
1701 (error "This is the first Info node you looked at"))
1702 (let ((len (1+ (length Info-history))))
1703 (setq n (% (+ n (* len 100)) len)))
1705 (let ((entry (nth (1- n) Info-history)))
1706 (Info-history-add Info-current-file Info-current-node (point))
1707 (while (>= (setq n (1- n)) 0)
1708 (setq Info-history (nconc (cdr Info-history)
1709 (list (car Info-history)))))
1710 (setq Info-history (cdr Info-history))
1711 (let ((Info-keeping-history nil))
1712 (Info-goto-node (car entry)))
1713 (Info-restore-history-entry entry))))
1715 (defun Info-directory ()
1716 "Go to the Info directory node."
1718 (Info-find-node "dir" "top"))
1720 (defun Info-follow-reference (footnotename)
1721 "Follow cross reference named NAME to the node it refers to.
1722 NAME may be an abbreviation of the reference name."
1724 (let ((completion-ignore-case t)
1725 completions default (start-point (point)) str i)
1727 (goto-char (point-min))
1728 (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
1731 (setq str (buffer-substring
1734 ;; See if this one should be the default.
1736 (< (match-beginning 0) start-point)
1737 (<= start-point (point))
1740 (while (setq i (string-match "[ \n\t]+" str i))
1741 (setq str (concat (substring str 0 i) " "
1742 (substring str (match-end 0))))
1744 ;; Record as a completion and perhaps as default.
1745 (if (eq default t) (setq default str))
1747 (cons (cons str nil)
1750 (let ((item (completing-read (if default
1751 (concat "Follow reference named: ("
1753 "Follow reference named: ")
1754 completions nil t nil
1755 'Info-minibuffer-history)))
1756 (if (and (string= item "") default)
1759 (error "No cross-references in this node"))))
1760 (let (target i (str (concat "\\*" Info-footnote-tag " "
1761 (regexp-quote footnotename))))
1762 (while (setq i (string-match " " str i))
1763 (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
1764 (substring str (1+ i))))
1767 (goto-char (point-min))
1768 (or (re-search-forward str nil t)
1769 (error "No cross-reference named %s" footnotename))
1770 (goto-char (match-end 1))
1772 (Info-extract-menu-node-name "Bad format cross reference" t)))
1773 (while (setq i (string-match "[ \t\n]+" target i))
1774 (setq target (concat (substring target 0 i) " "
1775 (substring target (match-end 0))))
1777 (Info-goto-node target)
1778 (setq Info-in-cross-reference t)))
1780 (defun Info-next-reference (n)
1782 (let ((pat (format "\\*%s[ \n\t]*\\([^:]*\\):\\|^\\* .*:\\|<<.*>>"
1785 wrapped found-nomenu)
1787 (unless (re-search-backward pat nil t)
1788 ;; Don't wrap more than once in a buffer where only the
1789 ;; menu references are found.
1790 (when (and wrapped (not found-nomenu))
1792 (error "No cross references in this node"))
1794 (goto-char (point-max))
1795 (unless (re-search-backward pat nil t)
1797 (error "No cross references in this node")))
1798 (unless (save-excursion
1799 (goto-char (match-beginning 0))
1800 (when (looking-at "\\* Menu:")
1802 (setq found-nomenu t))
1805 (or (eobp) (forward-char 1))
1806 (unless (re-search-forward pat nil t)
1807 (when (and wrapped (not found-nomenu))
1809 (error "No cross references in this node"))
1811 (goto-char (point-min))
1812 (unless (re-search-forward pat nil t)
1814 (error "No cross references in this node")))
1815 (unless (save-excursion
1816 (goto-char (match-beginning 0))
1817 (when (looking-at "\\* Menu:")
1819 (setq found-nomenu t))
1821 (when (looking-at "\\* Menu:")
1822 (error "No cross references in this node"))
1823 (goto-char (match-beginning 0))))
1825 (defun Info-prev-reference (n)
1827 (Info-next-reference (- n)))
1829 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1830 (skip-chars-forward " \t\n")
1833 (skip-chars-forward "^:")
1836 (if (looking-at ":")
1837 (buffer-substring beg (1- (point)))
1838 (skip-chars-forward " \t\n")
1839 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1840 (while (setq i (string-match "\n" str i))
1844 (defun Info-menu (menu-item)
1845 "Go to node for menu item named (or abbreviated) NAME.
1846 Completion is allowed, and the menu item point is on is the default."
1848 (let ((completions '())
1849 ;; If point is within a menu item, use that item as the default
1854 (goto-char (point-min))
1855 (let ((case-fold-search t))
1856 (if (not (search-forward "\n* menu:" nil t))
1857 (error "No menu in this node")))
1858 (while (re-search-forward
1859 "\n\\* \\([^:\t\n]*\\):" nil t)
1860 (if (and (null default)
1861 (prog1 (if last (< last p) nil)
1862 (setq last (match-beginning 0)))
1864 (setq default (car (car completions))))
1865 (setq completions (cons (cons (buffer-substring
1868 (match-beginning 1))
1870 (if (and (null default) last
1872 (<= p (progn (end-of-line) (point))))
1873 (setq default (car (car completions)))))
1876 (setq item (let ((completion-ignore-case t))
1877 (completing-read (if default
1878 (format "Menu item (default %s): "
1881 completions nil t nil
1882 'Info-minibuffer-history)))
1883 ;; we rely on the fact that completing-read accepts an input
1884 ;; of "" even when the require-match argument is true and ""
1885 ;; is not a valid possibility
1886 (if (string= item "")
1892 ;; there is a problem here in that if several menu items have the same
1893 ;; name you can only go to the node of the first with this command.
1894 (Info-goto-node (Info-extract-menu-item menu-item) nil t))
1896 (defun Info-extract-menu-item (menu-item &optional noerror)
1898 (goto-char (point-min))
1899 (if (let ((case-fold-search t))
1900 (search-forward "\n* menu:" nil t))
1901 (if (or (search-forward (concat "\n* " menu-item ":") nil t)
1902 (search-forward (concat "\n* " menu-item) nil t))
1906 (Info-extract-menu-node-name))
1907 (and (not noerror) (error "No such item in menu")))
1908 (and (not noerror) (error "No menu in this node")))))
1910 ;; If COUNT is nil, use the last item in the menu.
1911 (defun Info-extract-menu-counting (count &optional noerror noindex)
1913 (goto-char (point-min))
1914 (if (let ((case-fold-search t))
1915 (and (search-forward "\n* menu:" nil t)
1917 (not (string-match "\\<Index\\>" Info-current-node)))))
1918 (if (search-forward "\n* " nil t count)
1921 (while (search-forward "\n* " nil t)))
1922 (Info-extract-menu-node-name))
1923 (and (not noerror) (error "Too few items in menu")))
1924 (and (not noerror) (error "No menu in this node")))))
1926 (defun Info-nth-menu-item (n)
1927 "Go to the node of the Nth menu item."
1929 (or n (setq n (- last-command-char ?0)))
1930 (if (< n 1) (error "Index must be at least 1"))
1931 (Info-goto-node (Info-extract-menu-counting n) nil t))
1933 (defun Info-last-menu-item ()
1934 "Go to the node of the tenth menu item."
1936 (Info-goto-node (Info-extract-menu-counting nil) nil t))
1939 "Go to the Top node of this file."
1941 (Info-goto-node "Top"))
1944 "Go to the final node in this file."
1947 (let ((Info-keeping-history nil)
1949 (Info-last-menu-item)
1950 (while (setq node (or (Info-extract-pointer "next" t)
1951 (Info-extract-menu-counting nil t t)))
1952 (Info-goto-node node))
1953 (or (equal (Info-extract-pointer "up" t) "Top")
1954 (let ((executing-kbd-macro "")) ; suppress messages
1956 (Info-global-next 10000)
1959 (defun Info-global-next (&optional n)
1960 "Go to the next node in this file, traversing node structure as necessary.
1961 This works only if the Info file is structured as a hierarchy of nodes.
1962 A positive or negative prefix argument moves by multiple nodes."
1966 (Info-global-prev (- n))
1967 (while (>= (setq n (1- n)) 0)
1969 (cond ((and (string-match "^Top$" Info-current-node)
1970 (setq node (Info-extract-pointer "next" t))
1971 (Info-extract-menu-item node t))
1972 (Info-goto-node node))
1973 ((setq node (Info-extract-menu-counting 1 t t))
1974 (message "Going down...")
1975 (Info-goto-node node))
1977 (let ((Info-keeping-history Info-keeping-history)
1978 (orignode Info-current-node)
1980 (while (not (Info-extract-pointer "next" t))
1981 (if (and (setq node (Info-extract-pointer "up" t))
1982 (not (equal node "Top")))
1984 (message "Going%s..." (setq ups (concat ups " up")))
1985 (Info-goto-node node)
1986 (setq Info-keeping-history nil))
1988 (let ((Info-keeping-history nil))
1989 (Info-goto-node orignode)))
1990 (error "Last node in file")))
1993 (defun Info-page-next (&optional n)
1994 "Scroll forward one screenful, or go to next global node.
1995 A positive or negative prefix argument moves by multiple screenfuls."
1999 (Info-page-prev (- n))
2000 (while (>= (setq n (1- n)) 0)
2001 (if (pos-visible-in-window-p (point-max))
2004 (message "Node: %s" Info-current-node))
2007 (defun Info-scroll-next (arg)
2009 (if Info-auto-advance
2010 (if (and (pos-visible-in-window-p (point-max))
2011 (not (eq Info-auto-advance t))
2012 (not (eq last-command this-command)))
2013 (message "Hit %s again to go to next node"
2014 (if (= last-command-char 0)
2016 (key-description (char-to-string last-command-char))))
2018 (setq this-command 'Info))
2021 (defun Info-global-prev (&optional n)
2022 "Go to the previous node in this file, traversing structure as necessary.
2023 This works only if the Info file is structured as a hierarchy of nodes.
2024 A positive or negative prefix argument moves by multiple nodes."
2028 (Info-global-next (- n))
2029 (while (>= (setq n (1- n)) 0)
2030 (let ((upnode (Info-extract-pointer "up" t))
2031 (prevnode (Info-extract-pointer "prev[ious]*" t)))
2032 (if (or (not prevnode)
2033 (equal prevnode upnode))
2034 (if (string-match "^Top$" Info-current-node)
2035 (error "First node in file")
2036 (message "Going up...")
2038 (Info-goto-node prevnode)
2040 (Info-keeping-history nil)
2042 (while (setq node (Info-extract-menu-counting nil t t))
2043 (message "Going%s..." (setq downs (concat downs " down")))
2044 (Info-goto-node node))))))))
2046 (defun Info-page-prev (&optional n)
2047 "Scroll backward one screenful, or go to previous global node.
2048 A positive or negative prefix argument moves by multiple screenfuls."
2052 (Info-page-next (- n))
2053 (while (>= (setq n (1- n)) 0)
2054 (if (pos-visible-in-window-p (point-min))
2057 (message "Node: %s" Info-current-node)
2059 ;;(scroll-up 1) ; work around bug in pos-visible-in-window-p
2061 (while (not (pos-visible-in-window-p (point-max)))
2065 (defun Info-scroll-prev (arg)
2067 (if Info-auto-advance
2068 (if (and (pos-visible-in-window-p (point-min))
2069 (not (eq Info-auto-advance t))
2070 (not (eq last-command this-command)))
2071 (message "Hit %s again to go to previous node"
2072 (if (= last-command-char 0)
2074 (key-description (char-to-string last-command-char))))
2076 (setq this-command 'Info))
2079 (defun Info-index (topic)
2080 "Look up a string in the index for this file.
2081 The index is defined as the first node in the top-level menu whose
2082 name contains the word \"Index\", plus any immediately following
2083 nodes whose names also contain the word \"Index\".
2084 If there are no exact matches to the specified topic, this chooses
2085 the first match which is a case-insensitive substring of a topic.
2086 Use the `,' command to see the other matches.
2087 Give a blank topic name to go to the Index node itself."
2088 (interactive "sIndex topic: ")
2089 (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
2090 (regexp-quote topic)
2091 "\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"))
2093 (message "Searching index for `%s'..." topic)
2094 (Info-goto-node "Top")
2095 (let ((case-fold-search t))
2096 (or (search-forward "\n* menu:" nil t)
2098 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2099 (error "No index")))
2100 (goto-char (match-beginning 1))
2101 (let ((Info-keeping-history nil)
2102 (Info-fontify (and Info-fontify (equal topic ""))))
2103 (Info-goto-node (Info-extract-menu-node-name)))
2104 (or (equal topic "")
2107 (Info-keeping-history nil)
2111 (goto-char (point-min))
2112 (while (re-search-forward pattern nil t)
2114 (cons (list (buffer-substring (match-beginning 1)
2116 (buffer-substring (match-beginning 2)
2119 (string-to-int (concat "0"
2124 (and (setq node (Info-extract-pointer "next" t))
2125 (string-match "\\<Index\\>" node)))
2126 (let ((Info-fontify nil))
2127 (Info-goto-node node)))
2131 (error "No \"%s\" in index" topic)))
2132 ;; Here it is a feature that assoc is case-sensitive.
2133 (while (setq found (assoc topic matches))
2134 (setq exact (cons found exact)
2135 matches (delq found matches)))
2136 (setq Info-index-alternatives (nconc exact (nreverse matches))
2137 Info-index-first-alternative (car Info-index-alternatives))
2138 (Info-index-next 0)))))
2140 (defun Info-index-next (num)
2141 "Go to the next matching index item from the last `i' command."
2143 (or Info-index-alternatives
2144 (error "No previous `i' command in this file"))
2146 (setq num (+ num (length Info-index-alternatives))))
2148 (setq Info-index-alternatives
2149 (nconc (cdr Info-index-alternatives)
2150 (list (car Info-index-alternatives)))
2152 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2153 (if (> (nth 3 (car Info-index-alternatives)) 0)
2154 (forward-line (nth 3 (car Info-index-alternatives)))
2155 (forward-line 3) ; don't search in headers
2156 (let ((name (car (car Info-index-alternatives))))
2157 (if (or (re-search-forward (format
2158 "\\(Function\\|Command\\): %s\\( \\|$\\)"
2159 (regexp-quote name)) nil t)
2160 (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
2161 (search-forward (format "`%s'" name) nil t)
2162 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2164 (format "`%s'" (substring name 0 (match-beginning 1)))
2166 (search-forward name nil t))
2168 (goto-char (point-min)))))
2169 (message "Found \"%s\" in %s. %s"
2170 (car (car Info-index-alternatives))
2171 (nth 2 (car Info-index-alternatives))
2172 (if (cdr Info-index-alternatives)
2173 (if (eq (car (cdr Info-index-alternatives))
2174 Info-index-first-alternative)
2175 "(Press `,' to repeat)"
2176 (format "(Press `,' for %d more)"
2177 (- (1- (length Info-index-alternatives))
2178 (length (memq Info-index-first-alternative
2179 (cdr Info-index-alternatives))))))
2184 (defun Info-emacs-command (command)
2185 "Look up an Emacs command in the Emacs manual in the Info system.
2186 This command is designed to be used whether you are already in Info or not."
2187 (interactive "CLook up command in Emacs manual: ")
2188 (save-window-excursion
2190 (Info-find-node Info-emacs-info-file-name "Top")
2191 (Info-index (symbol-name command)))
2192 (pop-to-buffer "*info*"))
2196 (defun Info-goto-emacs-command-node (key)
2197 "Look up an Emacs command in the Emacs manual in the Info system.
2198 This command is designed to be used whether you are already in Info or not."
2199 (interactive "CLook up command in Emacs manual: ")
2200 (Info-emacs-command key))
2203 (defun Info-goto-emacs-key-command-node (key)
2204 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2205 This command is designed to be used whether you are already in Info or not."
2206 (interactive "kLook up key in Emacs manual: ")
2207 (let ((command (key-binding key)))
2208 (cond ((eq command 'keyboard-quit)
2211 (error "%s is undefined" (key-description key)))
2212 ((and (interactive-p) (eq command 'execute-extended-command))
2213 (call-interactively 'Info-goto-emacs-command-node))
2215 (Info-goto-emacs-command-node command)))))
2218 (defun Info-emacs-key (key)
2219 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2220 This command is designed to be used whether you are already in Info or not."
2221 (interactive "kLook up key in Emacs manual: ")
2222 (cond ((eq (key-binding key) 'keyboard-quit)
2224 ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
2225 (call-interactively 'Info-goto-emacs-command-node))
2227 (save-window-excursion
2229 (Info-find-node Info-emacs-info-file-name "Top")
2230 (setq key (key-description key))
2232 (if (setq p (string-match "[@{}]" key))
2233 (setq key (concat (substring key 0 p) "@" (substring key p))))
2234 (if (string-match "^ESC " key)
2235 (setq key (concat "M-" (substring key 4))))
2236 (if (string-match "^M-C-" key)
2237 (setq key (concat "C-M-" (substring key 4)))))
2239 (pop-to-buffer "*info*"))))
2242 (defun Info-elisp-ref (func)
2243 "Look up an Emacs Lisp function in the Elisp manual in the Info system.
2244 This command is designed to be used whether you are already in Info or not."
2245 (interactive (let ((fn (function-at-point))
2246 (enable-recursive-minibuffers t)
2248 (setq val (completing-read
2249 (format "Look up Emacs Lisp function%s: "
2251 (format " (default %s)" fn)
2253 obarray 'fboundp t))
2254 (list (if (equal val "")
2256 (save-window-excursion
2259 (Info-find-node "lispref" "Top")
2260 (error (Info-find-node "elisp" "Top")))
2261 (Info-index (symbol-name func)))
2262 (pop-to-buffer "*info*"))
2264 (defun Info-reannotate-node ()
2265 (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
2267 (let ((ibuf (current-buffer))
2268 (file (concat "\\(" (regexp-quote
2269 (file-name-nondirectory Info-current-file))
2270 "\\|" (regexp-quote Info-current-file) "\\)"))
2271 (node (regexp-quote Info-current-node))
2273 (goto-char (point-min))
2274 (if (search-forward "\n------ NOTE:\n" nil t)
2275 (let ((buffer-read-only nil)
2276 (bufmod (buffer-modified-p))
2278 (setq savept (copy-marker savept))
2279 (goto-char (point-min))
2280 (while (search-forward "\n------ NOTE:" nil t)
2281 (setq top (1+ (match-beginning 0)))
2282 (if (search-forward "\n------\n" nil t)
2283 (delete-region top (point)))
2285 (set-buffer-modified-p bufmod)))
2288 (set-buffer (car bufs))
2289 (goto-char (point-min))
2290 (while (re-search-forward
2292 "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
2295 (let ((line (string-to-int
2296 (buffer-substring (match-beginning 2)
2300 (search-forward "\n------\n" nil t)
2304 (if (integerp savept) (setq savept (copy-marker savept)))
2306 (goto-char (point-max))
2307 (goto-char (point-min))
2308 (forward-line line))
2309 (let ((buffer-read-only nil)
2310 (bufmod (buffer-modified-p)))
2311 (insert "------ NOTE:\n")
2312 (insert-buffer-substring (car bufs) top bot)
2313 (set-buffer-modified-p bufmod)))))
2314 (setq bufs (cdr bufs))))
2315 (goto-char savept)))))
2317 (defvar Info-annotate-map nil
2318 "Local keymap used within `a' command of Info.")
2319 (if Info-annotate-map
2321 ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
2322 (setq Info-annotate-map (copy-keymap text-mode-map))
2323 (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
2325 (defun Info-annotate-mode ()
2326 "Major mode for adding an annotation to an Info node.
2327 Like text mode with the addition of Info-cease-annotate
2328 which returns to Info mode for browsing.
2329 \\{Info-annotate-map}")
2331 (defun Info-annotate (arg)
2332 "Add a personal annotation to the current Info node.
2333 Only you will be able to see this annotation. Annotations are stored
2334 in the file \"~/.xemacs/info.notes\" by default. If point is inside
2335 an existing annotation, edit that annotation. A prefix argument
2336 specifies which annotations file (from `Info-annotations-path') is to
2337 be edited; default is 1."
2340 (if (or (< arg 0) (not (nth arg Info-annotations-path)))
2342 (setq Info-annotations-path
2343 (list (read-file-name
2344 "Annotations file: " "~/" "~/.infonotes")))
2345 (error "File number must be in the range from 1 to %d"
2346 (length Info-annotations-path))))
2348 (file (file-name-nondirectory Info-current-file))
2349 (d Info-directory-list)
2351 (while (and d (not (equal (expand-file-name file (car d))
2352 Info-current-file)))
2354 (or d (setq file Info-current-file))
2355 (if (and (save-excursion
2356 (goto-char (min (point-max) (+ (point) 13)))
2357 (and (search-backward "------ NOTE:\n" nil t)
2358 (setq pt (match-end 0))
2359 (search-forward "\n------\n" nil t)))
2360 (< (point) (match-end 0)))
2361 (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
2363 (regexp-quote Info-current-node)
2365 (buffer-substring pt (match-beginning 0))))
2366 where (max (- (point) pt) 0)))
2367 (let ((node Info-current-node)
2368 (line (if (looking-at "[ \n]*\\'") 0
2369 (count-lines (point-min) (point)))))
2371 (let ((buffer-read-only nil)
2372 (bufmod (buffer-modified-p)))
2374 (if (bobp) (goto-char (point-max)))
2375 (insert "------ NOTE:\n------\n")
2377 (set-buffer-modified-p bufmod)))
2378 ;; (setq Info-window-start (window-start))
2379 (setq Info-window-configuration (current-window-configuration))
2380 (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
2381 (use-local-map Info-annotate-map)
2382 (setq major-mode 'Info-annotate-mode)
2383 (setq mode-name "Info Annotate")
2386 (goto-char (point-min))
2387 (re-search-forward which nil t))
2389 (goto-char (match-beginning 0))
2391 (forward-char where)))
2392 (let ((bufmod (buffer-modified-p)))
2393 (goto-char (point-max))
2394 (insert (format "\n------ File: %s Node: %s Line: %d\n"
2397 (insert "\n------\n"
2398 "\nPress C-c C-c to save and return to Info.\n")
2400 (set-buffer-modified-p bufmod))))))
2402 (defun Info-cease-annotate ()
2404 (let ((bufmod (buffer-modified-p)))
2405 (while (save-excursion
2406 (goto-char (point-min))
2407 (re-search-forward "\n\n?Press .* to save and return to Info.\n"
2409 (delete-region (1+ (match-beginning 0)) (match-end 0)))
2410 (while (save-excursion
2411 (goto-char (point-min))
2412 (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
2414 (delete-region (match-beginning 0) (match-end 0)))
2415 (set-buffer-modified-p bufmod))
2419 (or (one-window-p) (delete-window))
2421 (setq Info-current-annotation-completions nil)
2422 (set-window-configuration Info-window-configuration)
2423 (Info-reannotate-node))
2425 (defun Info-bookmark (arg tag)
2426 (interactive "p\nsBookmark name: ")
2428 (if (or (string-match "^\"\\(.*\\)\"$" tag)
2429 (string-match "^<<\\(.*\\)>>$" tag))
2430 (setq tag (substring tag (match-beginning 1) (match-end 1))))
2432 (search-forward "\n------\n")
2433 (let ((end (- (point) 8)))
2435 (if (re-search-forward "<<[^>\n]*>>" nil t)
2436 (delete-region (match-beginning 0) (match-end 0))
2439 (insert "<<" tag ">>"))))
2440 (Info-cease-annotate))
2443 "Exit Info by selecting some other buffer."
2446 (save-buffers-kill-emacs)
2447 (bury-buffer (current-buffer))
2448 (if (and (featurep 'toolbar)
2449 (boundp 'toolbar-info-frame)
2450 (eq toolbar-info-frame (selected-frame)))
2452 (delete-frame toolbar-info-frame)
2453 (error (bury-buffer)))
2454 (switch-to-buffer (other-buffer (current-buffer))))))
2456 (defun Info-undefined ()
2457 "Make command be undefined in Info."
2462 "Enter the Info tutorial."
2464 (delete-other-windows)
2465 (Info-find-node "info"
2466 (if (< (window-height) 23)
2470 (defun Info-summary ()
2471 "Display a brief summary of all Info commands."
2473 (save-window-excursion
2474 (switch-to-buffer "*Help*")
2476 (insert (documentation 'Info-mode))
2477 (goto-char (point-min))
2479 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2480 (message (if flag "Type Space to see more"
2481 "Type Space to return to Info"))
2482 (let ((e (next-command-event)))
2483 (if (/= ?\ (event-to-character e))
2484 (progn (setq unread-command-event e) nil)
2488 (bury-buffer "*Help*")))
2490 (defun Info-get-token (pos start all &optional errorstring)
2491 "Return the token around POS,
2492 POS must be somewhere inside the token
2493 START is a regular expression which will match the
2494 beginning of the tokens delimited string
2495 ALL is a regular expression with a single
2496 parenthized subpattern which is the token to be
2497 returned. E.g. '{\(.*\)}' would return any string
2498 enclosed in braces around POS.
2499 SIG optional fourth argument, controls action on no match
2502 a string: signal an error, using that string."
2504 (goto-char (point-min))
2505 (re-search-backward "\\`") ; Bug fix due to Nicholas J. Foskett.
2507 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
2509 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2510 (not (setq found (and (<= (match-beginning 0) pos)
2511 (> (match-end 0) pos))))))
2512 (if (and found (<= (match-beginning 0) pos)
2513 (> (match-end 0) pos))
2514 (buffer-substring (match-beginning 1) (match-end 1))
2515 (cond ((null errorstring)
2521 (error "No %s around position %d" errorstring pos)))))))
2523 (defun Info-follow-clicked-node (event)
2524 "Follow a node reference near clicked point. Like M, F, N, P or U command.
2525 At end of the node's text, moves to the next node."
2527 (or (and (event-point event)
2528 (Info-follow-nearest-node
2530 (select-window (event-window event))
2531 (event-point event))
2533 (error "click on a cross-reference to follow")))
2535 (defun Info-maybe-follow-clicked-node (event &optional click-count)
2536 "Follow a node reference (if any) near clicked point.
2537 Like M, F, N, P or U command. At end of the node's text, moves to the
2538 next node. No error is given if there is no node to follow."
2540 (and Info-button1-follows-hyperlink
2542 (Info-follow-nearest-node
2544 (select-window (event-window event))
2545 (event-point event))
2546 (1+ (point-min))))))
2548 (defun Info-find-nearest-node (point)
2551 ((= point (point-min)) nil) ; don't trigger on accidental RET.
2552 ((setq node (Info-get-token point
2553 (format "\\*%s[ \n]" Info-footnote-tag)
2554 (format "\\*%s[ \n]\\([^:]*\\):"
2555 Info-footnote-tag)))
2556 (list "Following cross-reference %s..."
2557 (list 'Info-follow-reference node)))
2558 ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\)::"))
2559 (list "Selecting menu item %s..."
2560 (list 'Info-goto-node node nil t)))
2561 ((setq node (Info-get-token point "\\* " "\\* \\([^:]*\\):"))
2562 (list "Selecting menu item %s..."
2563 (list 'Info-menu node)))
2564 ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
2566 (list 'Info-goto-node node)))
2567 ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
2568 (list "Next node..."
2569 (list 'Info-goto-node node)))
2570 ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
2572 (list 'Info-goto-node "Top")))
2573 ((setq node (Info-get-token point "Prev[ious]*: "
2574 "Prev[ious]*: \\([^,\n\t]*\\)"))
2575 (list "Previous node..."
2576 (list 'Info-goto-node node)))
2577 ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
2578 (list "Reselecting %s..."
2579 (list 'Info-goto-node node)))
2580 ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
2581 (if Info-in-cross-reference
2582 (list "Back to last node..."
2584 (list "Next node..."
2585 '(Info-global-next)))))
2588 (defun Info-follow-nearest-node (point)
2589 "Follow a node reference near point. Like M, F, N, P or U command.
2590 At end of the node's text, moves to the next node."
2592 (let ((data (Info-find-nearest-node point)))
2595 (let ((msg (format (car data) (nth 1 (nth 1 data)))))
2598 (message "%sdone" msg))
2601 (defun Info-indicated-node (event)
2604 (cond ((eventp event)
2605 (set-buffer (event-buffer event))
2606 (setq event (event-point event))))
2607 (let* ((data (Info-find-nearest-node event))
2608 (name (nth 1 (nth 1 data))))
2609 (and name (nth 1 data))))
2612 (defun Info-mouse-track-double-click-hook (event click-count)
2613 "Handle double-clicks by turning pages, like the `gv' ghostscript viewer"
2614 (if (/= click-count 2)
2615 ;; Return nil so any other hooks are performed.
2617 (let* ((x (event-x-pixel event))
2618 (y (event-y-pixel event))
2619 (w (window-pixel-width (event-window event)))
2620 (h (window-pixel-height (event-window event)))
2625 ;; In the top 1/4 and inside the middle 1/3
2627 (and (>= x w/3) (<= x (+ w/3 w/3))))
2630 ;; In the bottom 1/4 and inside the middle 1/3
2631 ((and (>= y (+ h/4 h/4 h/4))
2632 (and (>= x w/3) (<= x (+ w/3 w/3))))
2633 (Info-nth-menu-item 1)
2635 ;; In the lower 3/4 and the right 1/2
2636 ;; OR in the upper 1/4 and the right 1/3
2637 ((or (and (>= y h/4) (>= x w/2))
2638 (and (< y h/4) (>= x (+ w/3 w/3))))
2641 ;; In the lower 3/4 and the left 1/2
2642 ;; OR in the upper 1/4 and the left 1/3
2643 ((or (and (>= y h/4) (< x w/2))
2644 (and (< y h/4) (<= x w/3)))
2647 ;; This shouldn't happen.
2649 (error "event out of bounds: %s %s" x y))))))
2651 (defvar Info-mode-map nil
2652 "Keymap containing Info commands.")
2655 (setq Info-mode-map (make-sparse-keymap))
2656 (suppress-keymap Info-mode-map)
2657 (define-key Info-mode-map "." 'beginning-of-buffer)
2658 (define-key Info-mode-map " " 'Info-scroll-next)
2659 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2660 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2661 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2662 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2663 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2664 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2665 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2666 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2667 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2668 (define-key Info-mode-map "0" 'Info-last-menu-item)
2669 (define-key Info-mode-map "?" 'Info-summary)
2670 (define-key Info-mode-map "a" 'Info-annotate)
2671 (define-key Info-mode-map "b" 'beginning-of-buffer)
2672 (define-key Info-mode-map "d" 'Info-directory)
2673 (define-key Info-mode-map "e" 'Info-edit)
2674 (define-key Info-mode-map "f" 'Info-follow-reference)
2675 (define-key Info-mode-map "g" 'Info-goto-node)
2676 (define-key Info-mode-map "h" 'Info-help)
2677 (define-key Info-mode-map "i" 'Info-index)
2678 (define-key Info-mode-map "j" 'Info-goto-bookmark)
2679 (define-key Info-mode-map "k" 'Info-emacs-key)
2680 (define-key Info-mode-map "l" 'Info-last)
2681 (define-key Info-mode-map "m" 'Info-menu)
2682 (define-key Info-mode-map "n" 'Info-next)
2683 (define-key Info-mode-map "p" 'Info-prev)
2684 (define-key Info-mode-map "q" 'Info-exit)
2685 (define-key Info-mode-map "r" 'Info-follow-reference)
2686 (define-key Info-mode-map "s" 'Info-search)
2687 (define-key Info-mode-map "t" 'Info-top)
2688 (define-key Info-mode-map "u" 'Info-up)
2689 (define-key Info-mode-map "v" 'Info-visit-file)
2690 (define-key Info-mode-map "x" 'Info-bookmark)
2691 (define-key Info-mode-map "<" 'Info-top)
2692 (define-key Info-mode-map ">" 'Info-end)
2693 (define-key Info-mode-map "[" 'Info-global-prev)
2694 (define-key Info-mode-map "]" 'Info-global-next)
2695 (define-key Info-mode-map "{" 'Info-page-prev)
2696 (define-key Info-mode-map "}" 'Info-page-next)
2697 (define-key Info-mode-map "=" 'Info-restore-point)
2698 (define-key Info-mode-map "!" 'Info-select-node)
2699 (define-key Info-mode-map "@" 'Info-follow-nearest-node)
2700 (define-key Info-mode-map "," 'Info-index-next)
2701 (define-key Info-mode-map "*" 'Info-elisp-ref)
2702 (define-key Info-mode-map [tab] 'Info-next-reference)
2703 (define-key Info-mode-map [(meta tab)] 'Info-prev-reference)
2704 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2705 (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
2707 (define-key Info-mode-map 'backspace 'Info-scroll-prev)
2708 (define-key Info-mode-map 'delete 'Info-scroll-prev)
2709 (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
2710 (define-key Info-mode-map 'button3 'Info-select-node-menu))
2713 ;; Info mode is suitable only for specially formatted data.
2714 (put 'info-mode 'mode-class 'special)
2717 "Info mode is for browsing through the Info documentation tree.
2718 Documentation in Info is divided into \"nodes\", each of which
2719 discusses one topic and contains references to other nodes
2720 which discuss related topics. Info has commands to follow
2721 the references and show you other nodes.
2723 h Invoke the Info tutorial.
2724 q Quit Info: return to the previously selected file or buffer.
2726 Selecting other nodes:
2727 n Move to the \"next\" node of this node.
2728 p Move to the \"previous\" node of this node.
2729 m Pick menu item specified by name (or abbreviation).
2730 1-9, 0 Pick first..ninth, last item in node's menu.
2731 Menu items select nodes that are \"subsections\" of this node.
2732 u Move \"up\" from this node (i.e., from a subsection to a section).
2733 f or r Follow a cross reference by name (or abbrev). Type `l' to get back.
2734 RET Follow cross reference or menu item indicated by cursor.
2735 i Look up a topic in this file's Index and move to that node.
2736 , (comma) Move to the next match from a previous `i' command.
2737 l (letter L) Move back to the last node you were in.
2739 Moving within a node:
2740 Space Scroll forward a full screen. DEL Scroll backward.
2741 b Go to beginning of node. Meta-> Go to end of node.
2742 TAB Go to next cross-reference. Meta-TAB Go to previous ref.
2745 Left Button Set point.
2746 Middle Button Click on a highlighted node reference to go to it.
2747 Right Button Pop up a menu of applicable Info commands.
2750 g Move to node, file, or annotation tag specified by name.
2751 Examples: `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
2752 v Move to file, with filename completion.
2753 k Look up a key sequence in Emacs manual (also C-h C-k at any time).
2754 * Look up a function name in Emacs Lisp manual (also C-h C-f).
2755 d Go to the main directory of Info files.
2756 < or t Go to Top (first) node of this file.
2757 > Go to last node in this file.
2758 \[ Go to previous node, treating file as one linear document.
2759 \] Go to next node, treating file as one linear document.
2760 { Scroll backward, or go to previous node if at top.
2761 } Scroll forward, or go to next node if at bottom.
2762 = Restore cursor position from last time in this node.
2763 a Add a private note (annotation) to the current node.
2764 x, j Add, jump to a bookmark (annotation tag).
2765 s Search this Info file for a node containing the specified regexp.
2766 e Edit the contents of the current node."
2767 (kill-all-local-variables)
2768 (setq major-mode 'Info-mode)
2769 (setq mode-name "Info")
2770 (use-local-map Info-mode-map)
2771 (set-syntax-table text-mode-syntax-table)
2772 (setq local-abbrev-table text-mode-abbrev-table)
2773 (setq case-fold-search t)
2774 (setq buffer-read-only t)
2775 ; (setq buffer-mouse-map Info-mode-mouse-map)
2776 (make-local-variable 'Info-current-file)
2777 (make-local-variable 'Info-current-subfile)
2778 (make-local-variable 'Info-current-node)
2779 (make-local-variable 'Info-tag-table-marker)
2780 (make-local-variable 'Info-current-file-completions)
2781 (make-local-variable 'Info-current-annotation-completions)
2782 (make-local-variable 'Info-index-alternatives)
2783 (make-local-variable 'Info-history)
2784 ;; Faces are now defined by `defface'...
2785 (make-local-variable 'mouse-track-click-hook)
2786 (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
2787 (add-hook 'mouse-track-click-hook 'Info-mouse-track-double-click-hook)
2788 ;; #### The console-on-window-system-p check is to allow this to
2789 ;; work on tty's. The real problem here is that featurep really
2790 ;; needs to have some device/console domain knowledge added to it.
2791 (if (and (featurep 'toolbar)
2792 (console-on-window-system-p)
2793 (not Info-inhibit-toolbar))
2794 (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
2795 (if (featurep 'menubar)
2797 ;; make a local copy of the menubar, so our modes don't
2798 ;; change the global menubar
2799 (easy-menu-add '("Info" :filter Info-menu-filter))))
2800 (run-hooks 'Info-mode-hook)
2801 (Info-set-mode-line))
2803 (defvar Info-edit-map nil
2804 "Local keymap used within `e' command of Info.")
2807 ;; XEmacs: remove FSF stuff
2808 (setq Info-edit-map (make-sparse-keymap))
2809 (set-keymap-name Info-edit-map 'Info-edit-map)
2810 (set-keymap-parents Info-edit-map (list text-mode-map))
2811 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
2813 ;; Info-edit mode is suitable only for specially formatted data.
2814 (put 'info-edit-mode 'mode-class 'special)
2816 (defun Info-edit-mode ()
2817 "Major mode for editing the contents of an Info node.
2818 Like text mode with the addition of `Info-cease-edit'
2819 which returns to Info mode for browsing.
2824 "Edit the contents of this Info node.
2825 Allowed only if variable `Info-enable-edit' is non-nil."
2827 (or Info-enable-edit
2828 (error "Editing info nodes is not enabled"))
2829 (use-local-map Info-edit-map)
2830 (setq major-mode 'Info-edit-mode)
2831 (setq mode-name "Info Edit")
2832 (kill-local-variable 'modeline-buffer-identification)
2833 (setq buffer-read-only nil)
2834 ;; Make mode line update.
2835 (set-buffer-modified-p (buffer-modified-p))
2836 (message (substitute-command-keys
2837 "Editing: Type \\[Info-cease-edit] to return to info")))
2839 (defun Info-cease-edit ()
2840 "Finish editing Info node; switch back to Info proper."
2842 ;; Do this first, so nothing has changed if user C-g's at query.
2843 (and (buffer-modified-p)
2844 (y-or-n-p-maybe-dialog-box "Save the file? ")
2846 (use-local-map Info-mode-map)
2847 (setq major-mode 'Info-mode)
2848 (setq mode-name "Info")
2849 (Info-set-mode-line)
2850 (setq buffer-read-only t)
2851 ;; Make mode line update.
2852 (set-buffer-modified-p (buffer-modified-p))
2853 (and (marker-position Info-tag-table-marker)
2855 (message "Tags may have changed. Use Info-tagify if necessary")))
2857 (defun Info-find-emacs-command-nodes (command)
2858 "Return a list of locations documenting COMMAND in the XEmacs Info manual.
2859 The locations are of the format used in Info-history, i.e.
2860 \(FILENAME NODENAME BUFFERPOS\)."
2862 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
2863 ":\\s *\\(.*\\)\\.$")))
2865 (Info-find-node "XEmacs" "Command Index")
2866 ;; Take the index node off the Info history.
2867 ;; ??? says this isn't safe someplace else... hmmm.
2868 (setq Info-history (cdr Info-history))
2869 (goto-char (point-max))
2870 (while (re-search-backward cmd-desc nil t)
2871 (setq where (cons (list Info-current-file
2879 ;;; fontification and mousability for info
2881 (defun Info-highlight-region (start end face)
2883 (splitp (string-match "\n[ \t]+" (buffer-substring start end))))
2886 (setq extent (make-extent start (progn (goto-char start)
2889 (set-extent-face extent face)
2890 (set-extent-property extent 'info t)
2891 (set-extent-property extent 'highlight t)
2892 (skip-chars-forward "\n\t ")
2893 (setq extent (make-extent (point) end)))
2894 (setq extent (make-extent start end)))
2895 (set-extent-face extent face)
2896 (set-extent-property extent 'info t)
2897 (set-extent-property extent 'highlight t)))
2899 (defun Info-fontify-node ()
2901 (let ((case-fold-search t)
2902 (xref-regexp (concat "\\*"
2903 (regexp-quote Info-footnote-tag)
2904 "[ \n\t]*\\([^:]*\\):")))
2905 ;; Clear the old extents
2906 (map-extents #'(lambda (x y) (delete-extent x))
2907 (current-buffer) (point-min) (point-max) nil)
2908 ;; Break the top line iff it is > 79 characters. Some info nodes
2909 ;; have top lines that span 3 lines because of long node titles.
2910 ;; eg: (Info-find-node "lispref.info" "Window-Level Event Position Info")
2911 (toggle-read-only -1)
2916 (goto-char (point-min))
2917 (re-search-forward "Node: *[^,]+, " nil t)
2918 (setq len (- (point) (point-min))
2919 extent (make-extent (point-min) (point)))
2920 (set-extent-property extent 'invisible t)
2924 (if (< (current-column) (+ 78 len))
2927 (forward-char (+ 79 len))
2928 (re-search-backward "," nil t)
2932 (backward-delete-char 1)
2935 (toggle-read-only 1)
2936 ;; Highlight xrefs in the top few lines of the node
2937 (goto-char (point-min))
2938 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
2940 (goto-char (match-end 0))
2942 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?\n?")
2943 (goto-char (match-end 0))
2944 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref))))
2945 ;; Now get the xrefs in the body
2946 (goto-char (point-min))
2947 (while (re-search-forward xref-regexp nil t)
2948 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2950 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-xref)))
2951 ;; then highlight the nodes in the menu.
2952 (goto-char (point-min))
2953 (if (and (search-forward "\n* menu:" nil t))
2954 (while (re-search-forward
2955 "^\\* \\([^:\t\n]*\\):?:[ \t\n]" nil t)
2956 (Info-highlight-region (match-beginning 1) (match-end 1) 'info-node)))
2957 (set-buffer-modified-p nil))))
2959 (defun Info-construct-menu (&optional event)
2960 "Construct a menu of Info commands.
2961 Adds an entry for the node at EVENT, or under point if EVENT is omitted.
2962 Used to construct the menubar submenu and popup menu."
2963 (or event (setq event (point)))
2964 (let ((case-fold-search t)
2965 (xref-regexp (concat "\\*"
2966 (regexp-quote Info-footnote-tag)
2967 "[ \n\t]*\\([^:]*\\):"))
2968 up-p prev-p next-p menu xrefs subnodes in)
2970 ;; `one-space' fixes "Notes:" xrefs that are split across lines.
2974 (while (setq i (string-match "[ \n\t]+" text i))
2975 (setq text (concat (substring text 0 i) " "
2976 (substring text (match-end 0))))
2979 (goto-char (point-min))
2980 (if (looking-at ".*\\bNext:") (setq next-p t))
2981 (if (looking-at ".*\\bPrev:") (setq prev-p t))
2982 (if (looking-at ".*Up:") (setq up-p t))
2984 (if (setq in (Info-indicated-node event))
2985 (list (vector (one-space (cadr in)) in t)
2986 "--:shadowEtchedIn"))
2988 ["Goto Info Top-level" Info-directory]
2989 (vector "Next Node" 'Info-next :active next-p)
2990 (vector "Previous Node" 'Info-prev :active prev-p)
2991 (vector "Parent Node (Up)" 'Info-up :active up-p)
2992 ["Goto Node..." Info-goto-node]
2993 ["Goto Last Visited Node " Info-last])))
2994 ;; Find the xrefs and make a list
2995 (while (re-search-forward xref-regexp nil t)
2996 (setq xrefs (cons (one-space (buffer-substring (match-beginning 1)
2999 (setq xrefs (nreverse xrefs))
3000 (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
3001 ;; Find the subnodes and make a list
3002 (goto-char (point-min))
3003 (if (search-forward "\n* menu:" nil t)
3004 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
3005 (setq subnodes (cons (buffer-substring (match-beginning 1)
3008 (setq subnodes (nreverse subnodes))
3009 (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more))))
3011 (nconc menu (list "--:shadowDoubleEtchedIn"
3014 (mapcar #'(lambda (xref)
3018 (list 'Info-follow-reference xref))))
3021 (nconc menu (list "--:shadowDoubleEtchedIn"
3024 (mapcar #'(lambda (node)
3027 (vector node (list 'Info-menu node))))
3031 (defun Info-menu-filter (menu)
3032 "This is the menu filter for the \"Info\" submenu."
3033 (Info-construct-menu))
3035 (defun Info-select-node-menu (event)
3036 "Pops up a menu of applicable Info commands."
3038 (select-window (event-window event))
3039 (let ((menu (Info-construct-menu event)))
3040 (setq menu (nconc (list "Info" ; title: not displayed
3042 "--:shadowDoubleEtchedOut")
3044 (let ((popup-menu-titles nil))
3045 (popup-menu menu))))
3047 ;;; Info toolbar support
3049 ;; exit icon taken from GNUS
3050 (defvar info::toolbar-exit-icon
3051 (if (featurep 'toolbar)
3052 (toolbar-make-button-list
3053 (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
3054 toolbar-icon-directory)))
3057 (defvar info::toolbar-up-icon
3058 (if (featurep 'toolbar)
3059 (toolbar-make-button-list
3060 (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
3061 toolbar-icon-directory)))
3064 (defvar info::toolbar-next-icon
3065 (if (featurep 'toolbar)
3066 (toolbar-make-button-list
3067 (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
3068 toolbar-icon-directory)))
3071 (defvar info::toolbar-prev-icon
3072 (if (featurep 'toolbar)
3073 (toolbar-make-button-list
3074 (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
3075 toolbar-icon-directory)))
3078 (defvar info::toolbar
3079 (if (featurep 'toolbar)
3080 ; disabled until we get the next/prev-win icons working again.
3081 ; (cons (first initial-toolbar-spec)
3082 ; (cons (second initial-toolbar-spec)
3083 '([info::toolbar-exit-icon
3087 [info::toolbar-next-icon
3090 "Next entry in same section"]
3091 [info::toolbar-prev-icon
3094 "Prev entry in same section"]
3095 [info::toolbar-up-icon
3098 "Up entry to enclosing section"]
3104 (run-hooks 'Info-load-hook)
3106 ;;; info.el ends here