1 ;;; info.el --- info package for SXEmacs.
4 ;; Copyright (C) 1985, 1986, 1993, 1997 Free Software Foundation, Inc.
5 ;; Copyright (C) 2005 Steve Youngs.
7 ;; Author: Dave Gillespie <daveg@synaptics.com>
8 ;; Richard Stallman <rms@gnu.ai.mit.edu>
9 ;; Maintainer: Dave Gillespie <daveg@synaptics.com>
10 ;; Version: 1.07 of 7/22/93
11 ;; Keywords: docs, help
13 ;; This file is part of SXEmacs.
15 ;; SXEmacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
20 ;; SXEmacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
28 ;;; Synched up with: Not synched with FSF.
32 ;; This is based on an early Emacs 19 info.el file.
34 ;; Note that Info-directory has been replaced by Info-directory-list,
35 ;; a search path of directories in which to find Info files.
36 ;; Also, Info tries adding ".info" to a file name if the name itself
39 ;; See the change log below for further details.
43 ;; info-dg|Dave Gillespie|daveg@synaptics.com
44 ;; |Info reader with many enhancements; replaces standard info.el.
45 ;; |93-07-22|1.07|~/modes/info.el
47 ;; Also available from anonymous FTP on csvax.cs.caltech.edu.
52 ;; Modified 3/7/1991 by Dave Gillespie:
53 ;; (Author's address: daveg@synaptics.com or daveg@csvax.cs.caltech.edu)
55 ;; Added keys: i, t, <, >, [, ], {, }, 6, 7, 8, 9, 0.
56 ;; Look at help for info-mode (type ? in Info) for descriptions.
58 ;; If Info-directory-list is undefined and there is no INFOPATH
59 ;; in the environment, use value of Info-directory for compatibility
62 ;; All files named "localdir" found in the path are appended to "dir",
63 ;; the Info directory. For this to work, "dir" should contain only
64 ;; one node (Top), and each "localdir" should contain no ^_ or ^L
65 ;; characters. Generally they will contain only one or several
66 ;; additional lines for the top-level menu. Note that "dir" is
67 ;; modified in memory each time it is loaded, but not on disk.
69 ;; If "dir" contains a line of the form: "* Locals:"
70 ;; then the "localdir"s are inserted there instead of at the end.
73 ;; Modified 4/3/1991 by Dave Gillespie:
75 ;; Added Info-mode-hook (suggested by Sebastian Kremer).
76 ;; Also added epoch-info-startup/select-hooks from Simon Spero's info.el.
78 ;; Added automatic decoding of compressed Info files.
79 ;; See documentation for the variable Info-suffix-list. Default is to
80 ;; run "uncompress" on ".Z" files and "unyabba" on ".Y" files.
81 ;; (See comp.sources.unix v24i073-076 for yabba/unyabba, a free software
82 ;; alternative to compress/uncompress.)
83 ;; Note: "dir" and "localdir" files should not be compressed.
85 ;; Changed variables like Info-enable-edit to be settable by M-x set-variable.
87 ;; Added Info-auto-advance variable. If t, SPC and DEL will act like
88 ;; } and {, i.e., they advance to the next/previous node if at the end
91 ;; Changed `u' to restore point to most recent location in that node.
92 ;; Added `=' to do this manually at any time. (Suggested by David Fox).
94 ;; Changed `m' and `0-9' to try interpreting menu name as a file name
95 ;; if not found as a node name. This allows (dir) menus of the form,
96 ;; Emacs:: Cool text editor
98 ;; Emacs:(emacs). Cool text editor
100 ;; Enhanced `i' to use line-number information in the index.
101 ;; Added `,' to move among all matches to a previous `i' command.
103 ;; Added `a' (Info-annotate) for adding personal notes to any Info node.
104 ;; Notes are not stored in the actual Info files, but in the user's own
105 ;; ~/.infonotes file.
107 ;; Added Info-footnote-tag, made default be "Ref" instead of "Note".
109 ;; Got mouse-click stuff to work under Emacs version 18. Check it out!
110 ;; Left and right clicks scroll the Info window.
111 ;; Middle click goes to clicked-on node, e.g., "Next:", a menu, or a note.
114 ;; Modified 6/29/1991 by Dave Gillespie:
116 ;; Renamed epoch-info-startup/select-hooks to Info-startup/select-hook.
118 ;; Made Info-select-node into a command on the `!' key.
120 ;; Added Info-mouse-support user option.
122 ;; Cleaned up the implementation of some routines.
124 ;; Added special treatment of quoted words in annotations: The `g'
125 ;; command for a nonexistent node name scans for an annotation
126 ;; (in any node of any file) containing that name in quotes: g foo RET
127 ;; looks for an annotation containing: "foo" or: <<foo>>
128 ;; If found, it goes to that file and node.
130 ;; Added a call to set up Info-directory-list in Info-find-node to
131 ;; work around a bug in GNUS where it calls Info-goto-node before info.
133 ;; Added completion for `g' command (inspired by Richard Kim's infox.el).
134 ;; Completion knows all node names for the current file, and all annotation
135 ;; tags (see above). It does not complete file names or node names in
138 ;; Added `k' (Info-emacs-key) and `*' (Info-elisp-ref) commands. You may
139 ;; wish to bind these to global keys outside of Info mode.
141 ;; Allowed localdir files to be full dir-like files; only the menu part
142 ;; of each localdir is copied. Also, redundant menu items are omitted.
144 ;; Changed Info-history to hold only one entry at a time for each node,
145 ;; and to be circular so that multiple `l's come back again to the most
146 ;; recent node. Note that the format of Info-history entries has changed,
147 ;; which may interfere with external programs that try to operate on it.
148 ;; (Also inspired by Kim's infox.el).
150 ;; Changed `n', `]', `l', etc. to accept prefix arguments to move several
151 ;; steps at once. Most accept negative arguments to move oppositely.
153 ;; Changed `?' to bury *Help* buffer afterwards to keep it out of the way.
155 ;; Rearranged `?' key's display to be a little better for new users.
157 ;; Changed `a' to save whole window configuration and restore on C-c C-c.
159 ;; Fixed the bug reported by Bill Reynolds on gnu.emacs.bugs.
161 ;; Changed Info-last to restore window-start as well as cursor position.
163 ;; Changed middle mouse button in space after end of node to do Info-last
164 ;; if we got here by following a cross reference, else do Info-global-next.
166 ;; Added some new mouse bindings: shift-left = Info-global-next,
167 ;; shift-right = Info-global-prev, shift-middle = Info-last.
169 ;; Fixed Info-follow-reference not to make assumptions about length
170 ;; of Info-footnote-tag [Linus Tolke].
172 ;; Changed default for Info-auto-advance mode to be press-twice-for-next-node.
174 ;; Modified x-mouse-ignore to preserve last-command variable, so that
175 ;; press-twice Info-auto-advance mode works with the mouse.
178 ;; Modified 3/4/1992 by Dave Gillespie:
180 ;; Added an "autoload" command to help autoload.el.
182 ;; Changed `*' command to look for file `elisp' as well as for `lispref'.
184 ;; Fixed a bug involving footnote names containing regexp special characters.
186 ;; Fixed a bug in completion during `f' (or `r') command.
188 ;; Added TAB (Info-next-reference), M-TAB, and RET keys to Info mode.
190 ;; Added new bindings, `C-h C-k' for Info-emacs-key and `C-h C-f' for
191 ;; Info-elisp-ref. These bindings are made when info.el is loaded, and
192 ;; only if those key sequences were previously unbound. These bindings
193 ;; work at any time, not just when Info is already running.
196 ;; Modified 3/8/1992 by Dave Gillespie:
198 ;; Fixed some long lines that were causing trouble with mailers.
201 ;; Modified 3/9/1992 by Dave Gillespie:
203 ;; Added `C-h C-i' (Info-query).
205 ;; Added Info-novice mode, warns if the user attempts to switch to
206 ;; a different Info file.
208 ;; Fixed a bug that caused problems using compressed Info files
209 ;; and Info-directory-list at the same time.
211 ;; Disabled Info-mouse-support by default if Epoch or Hyperbole is in use.
213 ;; Added an expand-file-name call to Info-find-node to fix a small bug.
216 ;; Modified 5/22/1992 by Dave Gillespie:
218 ;; Added "standalone" operation: "emacs -f info" runs Emacs specifically
219 ;; for use as an Info browser. In this mode, the `q' key quits Emacs
220 ;; itself. Also, "emacs -f info arg" starts in Info file "arg" instead
223 ;; Changed to prefer "foo.info" over "foo". If both exist, "foo" is
224 ;; probably a directory or executable program!
226 ;; Made control-mouse act like regular-mouse does in other buffers.
227 ;; (In most systems, this will be set-cursor for left-mouse, x-cut
228 ;; for right-mouse, and x-paste, which will be an error, for
231 ;; Improved prompting and searching for `,' key.
233 ;; Fixed a bug where some "* Menu:" lines disappeared when "dir"
234 ;; contained several nodes.
237 ;; Modified 9/10/1992 by Dave Gillespie:
239 ;; Mixed in support for XEmacs. Mouse works the same as in
240 ;; the other Emacs versions by default; added Info-lucid-mouse-style
241 ;; variable, which enables mouse operation similar to XEmacs's default.
243 ;; Fixed a bug where RET couldn't understand "* Foo::" if "Foo" was a
244 ;; file name instead of a node name.
246 ;; Added `x' (Info-bookmark), a simple interface to the annotation
247 ;; tags feature. Added `j' (Info-goto-bookmark), like `g' but only
248 ;; completes bookmarks.
250 ;; Added `<<tag>>' as alternate to `"tag"' in annotations.
252 ;; Added `v' (Info-visit-file), like Info-goto-node but specialized
253 ;; for going to a new Info file (with file name completion).
255 ;; Added recognition of gzip'd ".z" files.
258 ;; Modified 5/9/1993 by Dave Gillespie:
260 ;; Merged in various things from FSF's latest Emacs 19 info.el.
262 ;; Modified 6/2/1993 by Dave Gillespie:
264 ;; Changed to use new suffix ".gz" for gzip files.
267 ;; Modified 7/22/1993 by Dave Gillespie:
269 ;; Changed Info-footnote-tag to "See" instead of "Ref".
271 ;; Extended Info-fontify-node to work with FSF version of Emacs 19.
273 ;; Modified 7/30/1993 by Jamie Zawinski:
275 ;; Commented out the tty and fsf19 mouse support, because why bother.
276 ;; Commented out the politically incorrect version of XEmacs mouse support.
277 ;; Commented out mouse scrolling bindings because the party line on that
278 ;; is "scrollbars are coming soon."
279 ;; Commented out munging of help-for-help's doc; put it in help.el.
280 ;; Did Info-edit-map the modern XEmacs way.
281 ;; Pruned extra cruft from fontification and mouse handling code.
282 ;; Fixed ASCII-centric bogosity in unreading of events.
284 ;; Modified 8/11/95 by Chuck Thompson:
286 ;; Removed any pretense of ever referencing Info-directory since it
287 ;; wasn't working anyhow.
289 ;; Modified 4/5/97 by Tomasz J. Cholewo:
291 ;; Modified Info-search to use with-caps-disable-folding
293 ;; Modified 6/21/97 by Hrvoje Niksic
295 ;; Fixed up Info-next-reference to work sanely when n < 0.
296 ;; Added S-tab binding.
298 ;; Modified 1997-07-10 by Karl M. Hegbloom
300 ;; Added `Info-minibuffer-history'
301 ;; (also added to defaults in "lisp/utils/savehist.el")
302 ;; Other changes in main ChangeLog.
304 ;; Modified 1998-03-29 by Oscar Figueiredo
306 ;; Added automatic dir/localdir (re)building capability for directories that
307 ;; contain none or when it has become older than info files in the same
310 ;; Modified 1998-09-23 by Didier Verna <didier@xemacs.org>
312 ;; Use the new macro `with-search-caps-disable-folding'
316 (condition-case nil (require 'browse-url) (error nil)))
319 "The info package for Emacs."
323 (defgroup info-faces nil
324 "The faces used by info browser."
329 (defcustom Info-inhibit-toolbar nil
330 "*Non-nil means don't use the specialized Info toolbar."
334 (defcustom Info-novice nil
335 "*Non-nil means to ask for confirmation before switching Info files."
339 (defvar Info-history nil
340 "List of info nodes user has visited.
341 Each element of list is a list (\"(FILENAME)NODENAME\" BUFPOS WINSTART).")
343 (defvar Info-keeping-history t
344 "Non-nil if Info-find-node should modify Info-history.
345 This is for use only by certain internal Info routines.")
347 (defvar Info-minibuffer-history nil
348 "Minibuffer history for Info.")
350 (defcustom Info-enable-edit nil
351 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info
352 can edit the current node.
353 This is convenient if you want to write info files by hand.
354 However, we recommend that you not do this.
355 It is better to write a Texinfo file and generate the Info file from that,
356 because that gives you a printed manual as well."
360 (defcustom Info-enable-active-nodes t
361 "*Non-nil allows Info to execute Lisp code associated with nodes.
362 The Lisp code is executed when the node is selected."
366 (defcustom Info-restoring-point t
367 "*Non-nil means to restore the cursor position when re-entering a node."
371 (defcustom Info-auto-advance 'twice
372 "*Control what SPC and DEL do when they can't scroll any further.
373 If nil, they beep and remain in the current node.
374 If t, they move to the next node (like Info-global-next/prev).
375 If anything else, they must be pressed twice to move to the next node."
376 :type '(choice (const :tag "off" nil)
377 (const :tag "advance" t)
378 (const :tag "confirm" twice))
381 (defcustom Info-fontify t
382 "*Non-nil enables font features in XEmacs.
383 This variable is ignored unless running under XEmacs."
387 (defcustom Info-additional-search-directory-list nil
388 "*List of additional directories to search for Info documentation
389 files. These directories are not searched for merging the `dir'
390 file. An example might be something like:
391 \"/usr/local/lib/xemacs/packages/lisp/calc/\""
392 :type '(repeat directory)
395 (defcustom Info-auto-generate-directory 'if-outdated
396 "*When to auto generate an info directory listing.
398 nil or `never' never auto-generate a directory listing,
399 use any existing `dir' or `localdir' file and ignore info
400 directories containing none
401 `always' auto-generate a directory listing ignoring existing
402 `dir' and `localdir' files
403 `if-missing', the default, auto-generates a directory listing
404 if no `dir' or `localdir' file is present. Otherwise the
405 contents of any of these files is used instead.
406 `if-outdated' auto-generates a directory listing if the `dir'
407 and `localdir' are either inexistent or outdated (touched
408 less recently than an info file in the same directory)."
409 :type '(choice (const :tag "never" never)
410 (const :tag "always" always)
411 (const :tag "if-missing" if-missing)
412 (const :tag "if-outdated" if-outdated))
415 (defcustom Info-save-auto-generated-dir 'never
416 "*Whether an auto-generated info directory listing should be saved.
418 nil or `never', the default, auto-generated info directory
419 information will never be saved.
420 `always', auto-generated info directory information will be saved to
421 a `dir' file in the same directory overwriting it if it exists
422 `conservative', auto-generated info directory information will be saved
423 to a `dir' file in the same directory but the user is asked before
424 overwriting any existing file."
425 :type '(choice (const :tag "never" never)
426 (const :tag "always" always)
427 (const :tag "conservative" conservative))
430 (defconst Info-emacs-info-file-name "sxemacs.info"
431 "The filename of the SXEmacs info for `Info-goto-emacs-command-node'
432 \(`\\<help-mode-map>\\[Info-goto-emacs-command-node]'\)")
435 (defvar Info-directory-list nil
436 "List of directories to search for Info documentation files.
438 The first directory in this list, the \"dir\" file there will become
439 the (dir)Top node of the Info documentation tree.
441 Note: DO NOT use the `customize' interface to change the value of this
442 variable. Its value is created dynamically on each startup, depending
443 on XEmacs packages installed on the system. If you want to change the
444 search path, make the needed modifications on the variable's value
445 from .emacs. For instance:
447 (setq Info-directory-list (cons \"~/info\" Info-directory-list))")
449 ;; This could as well be hard-coded since ${srcdir}/info/dir is in CVS --dv
450 (defconst Info-localdir-heading-regexp "^Local Packages:$"
451 "The menu part of localdir files will be inserted below this topic
454 (defface info-node '((t (:bold t :italic t)))
455 "Face used for node links in info."
458 (defface info-xref '((t (:bold t)))
459 "Face used for cross-references in info."
462 ;; This list is based on Karl Berry-s advice about extensions `info' itself
463 ;; might encounter. --dv
464 (defcustom Info-suffix-list '(("" . nil)
466 (".gz" . "gzip -dc %s")
467 (".info.gz" . "gzip -dc %s")
468 (".z" . "gzip -dc %s")
469 (".info.z" . "gzip -dc %s")
470 (".bz2" . "bzip2 -dc %s")
471 (".info.bz2" . "bzip2 -dc %s")
472 (".Z" . "uncompress -c %s")
473 (".info.Z" . "uncompress -c %s")
474 (".zip" . "unzip -c %s")
475 (".info.zip" . "unzip -c %s")
476 (".y" . "cat %s | unyabba")
477 ("info.y" . "cat %s | unyabba")
478 ;; These ones are for MS-DOS filenames.
480 (".igz" . "gzip -dc %s")
481 (".inz" . "gzip -c %s"))
482 "*List of file name suffixes and associated decoding commands.
483 Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
484 changed to name of the file to decode, otherwise the file is given to
485 the command as standard input. If STRING is nil, no decoding is done."
486 :type '(repeat (cons (string :tag "suffix")
487 (choice :tag "command"
488 (const :tag "none" :value nil)
492 (defcustom Info-footnote-tag "Note"
493 "*Symbol that identifies a footnote or cross-reference.
494 All \"*Note\" references will be changed to use this word instead."
498 (defvar Info-current-file nil
499 "Info file that Info is now looking at, or nil.
500 This is the name that was specified in Info, not the actual file name.
501 It doesn't contain directory names or file name extensions added by Info.")
503 (defvar Info-current-subfile nil
504 "Info subfile that is actually in the *info* buffer now,
505 or nil if current info file is not split into subfiles.")
507 (defvar Info-current-node nil
508 "Name of node that Info is now looking at, or nil.")
510 (defvar Info-tag-table-marker nil
511 "Marker pointing at beginning of current Info file's tag table.
512 Marker points nowhere if file has no tag table.")
514 (defvar Info-tag-table-buffer nil)
516 (defvar Info-current-file-completions nil
517 "Cached completion list for current Info file.")
519 (defvar Info-current-annotation-completions nil
520 "Cached completion list for current annotation files.")
522 (defvar Info-index-alternatives nil
523 "List of possible matches for last Info-index command.")
525 (defvar Info-index-first-alternative nil)
527 (defcustom Info-annotations-path
529 (paths-construct-path (list user-init-directory "info.notes"))
530 (paths-construct-path '("~" ".infonotes"))
531 (paths-construct-path '("usr" "lib" "info.notes")
532 (char-to-string directory-sep-char)))
533 "*Names of files that contain annotations for different Info nodes.
534 By convention, the first one should reside in your personal directory.
535 The last should be a world-writable \"public\" annotations file."
539 (defcustom Info-button1-follows-hyperlink nil
540 "*Non-nil means mouse button1 click will follow hyperlink."
544 (defvar Info-standalone nil
545 "Non-nil if Emacs was started solely as an Info browser.")
547 (defvar Info-in-cross-reference nil)
548 (defvar Info-window-configuration nil)
550 (defvar Info-dir-prologue "-*- Text -*-
551 This is the file .../info/dir, which contains the topmost node of the
552 Info hierarchy. The first time you invoke Info you start off
553 looking at that node, which is (dir)Top.
555 File: dir Node: Top This is the top of the INFO tree
556 This (the Directory node) gives a menu of major topics.
558 * Menu: The list of major topics begins on the next line.
562 (defcustom Info-no-description-string "[No description available]"
563 "*Description string for info files that have none"
568 (defun info (&optional file)
569 "Enter Info, the documentation browser.
570 Optional argument FILE specifies the file to examine;
571 the default is the top-level directory of Info.
573 In interactive use, a prefix argument directs this command
574 to read a file name from the minibuffer."
575 (interactive (if current-prefix-arg
576 (list (read-file-name "Info file name: " nil nil t))))
577 (let ((p command-line-args))
579 (and (string-match "^-[fe]" (car p))
580 (equal (nth 1 p) "info")
581 (not Info-standalone)
582 (setq Info-standalone t)
584 (not (string-match "^-" (nth 2 p)))
585 (setq file (nth 2 p))
586 (setq command-line-args-left nil))
588 ; (Info-setup-x) ??? What was this going to be? Can anyone tell karlheg?
591 (Info-goto-node (concat "(" file ")"))
592 (and Info-standalone (info)))
593 (if (get-buffer "*info*")
594 (switch-to-buffer "*info*")
598 (defun Info-query (file)
599 "Enter Info, the documentation browser. Prompt for name of Info file."
600 (interactive "sInfo topic (default = menu): ")
603 (Info-goto-node "(dir)")
604 (Info-goto-node (concat "(" file ")"))))
606 (defun Info-setup-initial ()
607 (let ((f Info-annotations-path))
609 (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
610 (bury-buffer (find-file-noselect (car f))))
614 (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
615 "Go to an info node specified as separate FILENAME and NODENAME.
616 Look for a plausible filename, or if not found then look for URL's and
617 dispatch to the appropriate fn. NO-GOING-BACK is non-nil if
618 recovering from an error in this function; it says do not attempt
619 further (recursive) error recovery. TRYFILE is ??"
624 ;; empty filename is simple case
626 (Info-find-file-node nil nodename no-going-back tryfile line))
627 ;; Convert filename to lower case if not found as specified.
628 ;; Expand it, look harder...
629 ((let ((fname (substitute-in-file-name filename))
632 ;; If specified name starts with `./', then just try
633 ;; current directory. No point in searching for an absolute
635 ((string-match "^\\./" fname)
636 (list default-directory))
637 ((file-name-absolute-p fname)
639 (Info-additional-search-directory-list
640 (append Info-directory-list
641 Info-additional-search-directory-list))
642 (t Info-directory-list))))
643 ;; Search the directory list for file FNAME.
644 (while (and dirs (not found))
645 (setq temp (expand-file-name fname (car dirs)))
646 (setq found (Info-suffixed-file temp))
647 (setq dirs (cdr dirs)))
649 (progn (setq filename (expand-file-name found))
651 (Info-find-file-node filename nodename no-going-back tryfile line))
652 ;; Look for a URL. This pattern is stolen from w3.el to prevent
653 ;; loading it if we won't need it.
654 ((string-match (concat #r"^\(wais\|solo\|x-exec\|newspost\|www\|"
655 #r"mailto\|news\|tn3270\|ftp\|http\|file\|"
656 #r"telnet\|gopher\):")
658 (if-fboundp 'browse-url
659 (browse-url filename)
660 (error "Cannot follow URLs in this SXEmacs")))
662 (error "Info file %s does not exist" filename))))
664 (defun Info-find-file-node (filename nodename
665 &optional no-going-back tryfile line)
666 ;; This is the guts of what was Info-find-node. Whoever wrote this
667 ;; should be locked up where they can't do any more harm.
669 ;; Go into info buffer.
670 (or (eq major-mode 'Info-mode)
671 (switch-to-buffer "*info*"))
672 (buffer-disable-undo (current-buffer))
673 (run-hooks 'Info-startup-hook)
674 (or (eq major-mode 'Info-mode)
677 (equal Info-current-file filename)
679 (string= "dir" (file-name-nondirectory Info-current-file))
681 (format "Leave Info file `%s'? "
682 (file-name-nondirectory Info-current-file)))
685 ;; Record the node we are leaving.
686 (if (and Info-current-file (not no-going-back))
687 (Info-history-add Info-current-file Info-current-node (point)))
689 (setq Info-current-node nil
690 Info-in-cross-reference nil)
693 ;; Switch files if necessary
695 (equal Info-current-file filename)
696 (let ((buffer-read-only nil))
697 (setq Info-current-file nil
698 Info-current-subfile nil
699 Info-current-file-completions nil
700 Info-index-alternatives nil
702 buffer-file-truename nil)
704 (if (string= "dir" (file-name-nondirectory filename))
706 (Info-insert-file-contents filename t)
707 (setq default-directory (file-name-directory filename)))
708 (set-buffer-modified-p nil)
709 ;; See whether file has a tag table. Record the location if yes.
710 (set-marker Info-tag-table-marker nil)
711 (goto-char (point-max))
713 (or (equal nodename "*")
714 (not (search-forward "\^_\nEnd tag table\n" nil t))
716 ;; We have a tag table. Find its beginning.
717 ;; Is this an indirect file?
718 (search-backward "\nTag table:\n")
722 (looking-at "(Indirect)\n"))
723 ;; It is indirect. Copy it to another buffer
724 ;; and record that the tag table is in that buffer.
725 (let ((buf (current-buffer))
726 (m Info-tag-table-marker))
728 Info-tag-table-buffer
730 Info-tag-table-buffer
731 (generate-new-buffer " *info tag table*")))
733 (set-buffer Info-tag-table-buffer)
734 (buffer-disable-undo (current-buffer))
735 (setq case-fold-search t)
737 (insert-buffer-substring buf)
738 (set-marker m (match-end 0))))
739 (set-marker Info-tag-table-marker pos))))
740 (setq Info-current-file
741 (file-name-sans-versions buffer-file-name))))
742 (if (equal nodename "*")
743 (progn (setq Info-current-node nodename)
745 (goto-char (point-min)))
746 ;; Search file for a suitable node.
747 (let* ((qnode (regexp-quote nodename))
748 (regexp (concat "Node: *" qnode " *[,\t\n\177]"))
749 (guesspos (point-min))
751 ;; First get advice from tag table if file has one.
752 ;; Also, if this is an indirect info file,
753 ;; read the proper subfile into this buffer.
754 (if (marker-position Info-tag-table-marker)
755 (let (foun found-mode (m Info-tag-table-marker))
757 (set-buffer (marker-buffer Info-tag-table-marker))
759 (setq foun (re-search-forward regexp nil t))
761 (setq guesspos (read (current-buffer))))
762 (setq found-mode major-mode))
764 ;; If this is an indirect file,
765 ;; determine which file really holds this node
767 (if (not (eq major-mode found-mode))
769 (Info-read-subfile guesspos))))))
770 (goto-char (max (point-min) (- guesspos 1000)))
771 ;; Now search from our advised position (or from beg of buffer)
772 ;; to find the actual node.
774 (while (search-forward "\n\^_" nil t)
778 (if (re-search-backward regexp beg t)
781 (let ((bufs (delq nil (mapcar 'get-file-buffer
782 Info-annotations-path)))
783 (pattern (if (string-match #r"\`<<.*>>\'" qnode) qnode
784 (format "\"%s\"\\|<<%s>>" qnode qnode)))
785 (pat2 (concat #r"------ *File: *\([^ ].*[^ ]\) *Node: "
786 #r"*\([^ ].*[^ ]\) *Line: *\([0-9]+\)"))
787 (afile nil) anode aline)
788 (while (and bufs (not anode))
790 (set-buffer (car bufs))
791 (goto-char (point-min))
792 (if (re-search-forward pattern nil t)
793 (if (re-search-backward pat2 nil t)
794 (setq afile (buffer-substring (match-beginning 1)
796 anode (buffer-substring (match-beginning 2)
799 (buffer-substring (match-beginning 3)
801 (setq bufs (cdr bufs)))
803 (Info-find-node afile anode t nil aline)
806 (Info-find-node nodename "Top" t)
808 (or Info-current-node
809 (error "No such node: %s" nodename)))
813 (goto-char (point-min))
814 (if line (forward-line line)))))))
815 ;; If we did not finish finding the specified node,
816 ;; go back to the previous one.
817 (or Info-current-node no-going-back
818 (let ((hist (car Info-history)))
819 ;; The following is no longer safe with new Info-history system
820 ;; (setq Info-history (cdr Info-history))
821 (Info-goto-node (car hist) t)
822 (goto-char (+ (point-min) (nth 1 hist)))))))
824 ;; Cache the contents of the (virtual) dir file, once we have merged
825 ;; it for the first time, so we can save time subsequently.
826 (defvar Info-dir-contents nil)
828 ;; Cache for the directory we decided to use for the default-directory
829 ;; of the merged dir text.
830 (defvar Info-dir-contents-directory nil)
832 ;; Record the file attributes of all the files from which we
833 ;; constructed Info-dir-contents.
834 (defvar Info-dir-file-attributes nil)
836 (defun Info-insert-dir ()
837 "Construct the Info directory node by merging the files named
838 \"dir\" or \"localdir\" from the directories in `Info-directory-list'.
839 The \"dir\" files will take precedence in cases where both exist. It
840 sets the *info* buffer's `default-directory' to the first directory we
841 actually get any text from."
842 (if (and Info-dir-contents Info-dir-file-attributes
843 ;; Verify that none of the files we used has changed
846 (mapcar #'(lambda (elt)
847 (let ((curr (file-attributes (car elt))))
848 ;; Don't compare the access time.
849 (if curr (setcar (nthcdr 4 curr) 0))
850 (setcar (nthcdr 4 (cdr elt)) 0)
851 (equal (cdr elt) curr)))
852 Info-dir-file-attributes))))
853 (insert Info-dir-contents)
854 (let ((dirs (reverse Info-directory-list))
855 buffers lbuffers buffer others nodes dirs-done)
857 (setq Info-dir-file-attributes nil)
859 ;; Search the directory list for the directory file.
861 (let ((truename (file-truename (expand-file-name (car dirs)))))
862 (or (member truename dirs-done)
863 (member (directory-file-name truename) dirs-done)
864 ;; Karl Berry recently added the ability all possibilities for
865 ;; extension as for normal info files. This code however is
866 ;; still unsatisfactory: if one day, we find a compressed dir
867 ;; file (which looks possible), we should be able to handle it
868 ;; (which means decompress and read it, update it, save and
869 ;; recompress it). --dv
870 (let ((trials '("dir" "DIR"
871 "dir.info" "DIR.INFO"
873 "localdir" "LOCALDIR"
874 "localdir.info" "LOCALDIR.INFO"
875 "localdir.inf" "LOCALDIR.INF"))
878 (while (setq file (pop trials))
879 (setq file (expand-file-name file truename))
880 (and (setq attrs (file-attributes file))
883 (setq file (expand-file-name "dir" truename)))
886 (cons (directory-file-name truename)
888 (Info-maybe-update-dir file)
889 (setq attrs (file-attributes file))
890 (if (or (setq buf (find-buffer-visiting file))
894 (message "Composing main Info directory..."))
897 (if (string-match "localdir" file)
901 (insert-file-contents file))
902 (if (string-match "localdir" (buffer-name))
903 (setq lbuffers (cons (current-buffer) lbuffers))
904 (setq buffers (cons (current-buffer) buffers)))
906 (setq Info-dir-file-attributes
907 (cons (cons file attrs)
908 Info-dir-file-attributes)))))))
909 (or (cdr dirs) (setq Info-dir-contents-directory (car dirs)))
910 (setq dirs (cdr dirs))))
912 ;; ensure that the localdir files are inserted last, and reverse
913 ;; the list of them so that when they get pushed in, they appear
914 ;; in the same order they got specified in the path, from top to
916 (nconc buffers (reverse lbuffers))
919 (error "Can't find the Info directory node"))
920 ;; Distinguish the dir file that comes with Emacs from all the
921 ;; others. Yes, that is really what this is supposed to do.
922 ;; If it doesn't work, fix it.
923 (setq buffer (car buffers)
924 ;; reverse it since they are pushed down from the top. the
925 ;; `Info-directory-list can be specified in natural order
927 others (reverse (cdr buffers)))
929 ;; Insert the entire original dir file as a start; note that we've
930 ;; already saved its default directory to use as the default
931 ;; directory for the whole concatenation.
932 (insert-buffer buffer)
934 ;; Look at each of the other buffers one by one.
936 (let ((other (car others))
937 (info-buffer (current-buffer)))
938 (if (string-match "localdir" (buffer-name other))
940 (set-buffer info-buffer)
941 (goto-char (point-max))
943 ((re-search-backward "^ *\\* *Locals *: *$" nil t)
944 (delete-region (match-beginning 0) (match-end 0)))
945 ;; look for a line like |Local XEmacs packages:
946 ;; or mismatch on some text ...
947 ((re-search-backward Info-localdir-heading-regexp nil t)
948 ;; This is for people who underline topic headings with
949 ;; equal signs or dashes.
950 (when (save-excursion
953 (looking-at "^[ \t]*[-=*]+"))
957 (t (search-backward "\^L" nil t)))
958 ;; Insert menu part of the file
960 (len (length (buffer-string nil nil other))))
961 (insert (buffer-string nil nil other))
962 (goto-char (+ pt len))
965 (if (search-forward "* Menu:" (+ pt len) t)
968 (delete-region pt (point)))))))
969 ;; In each, find all the menus.
972 (goto-char (point-min))
973 ;; Find each menu, and add an elt to NODES for it.
974 (while (re-search-forward "^\\* Menu:" nil t)
975 (let (beg nodename end)
978 (search-backward "\n\^_")
979 (search-forward "Node: ")
980 (setq nodename (Info-following-node-name))
981 (search-forward "\n\^_" nil 'move)
984 (setq nodes (cons (list nodename other beg end) nodes))))))
985 (setq others (cdr others))))
987 ;; Add to the main menu a menu item for each other node.
988 (re-search-forward "^\\* Menu:" nil t)
990 (let ((menu-items '("top"))
993 (end (save-excursion (search-forward "\^_" nil t) (point))))
995 (let ((nodename (car (car nodes))))
997 (or (member (downcase nodename) menu-items)
998 (re-search-forward (concat "^\\* "
999 (regexp-quote nodename)
1003 (insert "* " nodename "::" "\n")
1004 (setq menu-items (cons nodename menu-items))))))
1005 (setq nodes (cdr nodes))))
1006 ;; Now take each node of each of the other buffers
1007 ;; and merge it into the main buffer.
1009 (let ((nodename (car (car nodes))))
1010 (goto-char (point-min))
1011 ;; Find the like-named node in the main buffer.
1012 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
1013 (regexp-quote nodename)
1017 (search-forward "\n\^_" nil 'move)
1020 ;; If none exists, add one.
1021 (goto-char (point-max))
1022 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
1023 ;; Merge the text from the other buffer's menu
1024 ;; into the menu in the like-named node in the main buffer.
1025 (apply 'insert-buffer-substring (cdr (car nodes))))
1026 (setq nodes (cdr nodes)))
1027 ;; Kill all the buffers we just made.
1029 (kill-buffer (car buffers))
1030 (setq buffers (cdr buffers)))
1032 (kill-buffer (car lbuffers))
1033 (setq lbuffers (cdr lbuffers)))
1034 (message "Composing main Info directory...done"))
1035 (setq Info-dir-contents (buffer-string)))
1036 (setq default-directory (file-name-as-directory Info-dir-contents-directory))
1037 (setq buffer-file-name (caar Info-dir-file-attributes)
1038 buffer-file-truename (file-truename buffer-file-name)))
1040 (defmacro Info-directory-files (dir-file &optional all full nosort files-only)
1041 "Return a list of Info files living in the same directory as DIR-FILE.
1042 This list actually contains the files living in this directory, except for
1043 the dir file itself and the secondary info files (foo-1 foo-2 etc).
1045 If the optional argument ALL is non nil, the secondary info files are also
1046 included in the list.
1048 Please refer to the function `directory-files' for the meaning of the other
1049 optional arguments."
1050 `(let* ((dir (file-name-directory ,dir-file))
1051 (all-files (remove ,dir-file (directory-files dir ',full nil ',nosort
1055 (remove (concat dir ".")
1056 (remove (concat dir "..") all-files))
1058 (remove ".." all-files))))
1062 (concat "-[0-9]+\\("
1063 ;; Extract all known compression suffixes from
1064 ;; Info-suffix-list. These suffixes can typically be
1065 ;; found in entries of the form `.info.something'.
1066 (let ((suff-list Info-suffix-list)
1068 (while (setq suff (pop suff-list))
1069 (and (string-match "^\\.info" (car suff))
1070 (setq regexp (concat regexp
1074 (and suff-list "\\|")))))
1078 (while (setq file (pop all-files))
1079 (or (string-match suff-match file)
1080 (push file info-files)))
1081 (reverse info-files)
1085 (defun Info-maybe-update-dir (file)
1086 "Rebuild dir or localdir according to `Info-auto-generate-directory'."
1087 (unless (or (not (file-exists-p (file-name-directory file)))
1088 (null (Info-directory-files file 'all)))
1089 (if (not (find-buffer-visiting file))
1090 (if (not (file-exists-p file))
1091 (if (or (memq Info-auto-generate-directory
1092 '(always if-missing if-outdated)))
1093 (Info-build-dir-anew (file-name-directory file)))
1094 (if (or (eq Info-auto-generate-directory 'always)
1095 (and (eq Info-auto-generate-directory 'if-outdated)
1096 (Info-dir-outdated-p file)))
1097 (Info-rebuild-dir file))))))
1099 ;; Record which *.info files are newer than the dir file
1100 (defvar Info-dir-newer-info-files nil)
1102 (defun Info-dir-outdated-p (file)
1103 "Return non-nil if dir or localdir is outdated.
1104 dir or localdir are outdated when an info file in the same
1105 directory has been modified more recently."
1106 (let ((dir-mod-time (nth 5 (file-attributes file)))
1108 (setq Info-dir-newer-info-files nil)
1112 (setq f-mod-time (nth 5 (file-attributes f)))
1113 (setq newer (or (> (car f-mod-time) (car dir-mod-time))
1114 (and (= (car f-mod-time) (car dir-mod-time))
1115 (> (car (cdr f-mod-time))
1116 (car (cdr dir-mod-time))))))
1117 (if (and (file-readable-p f) newer)
1118 (setq Info-dir-newer-info-files
1119 (cons f Info-dir-newer-info-files)))))
1120 (Info-directory-files file nil 'fullname 'nosort t))
1121 Info-dir-newer-info-files))
1123 (defun Info-extract-dir-entry-from (file)
1124 "Extract the dir entry from the info FILE.
1125 The dir entry is delimited by the markers `START-INFO-DIR-ENTRY'
1126 and `END-INFO-DIR-ENTRY'."
1128 (set-buffer (get-buffer-create " *Info-tmp*"))
1129 (when (file-readable-p file)
1130 (insert-file-contents file nil nil nil t)
1131 (goto-char (point-min))
1133 (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
1136 (unless (null (re-search-forward "^END-INFO-DIR-ENTRY" nil t))
1137 (goto-char (match-beginning 0))
1138 (car (Info-parse-dir-entries beg (point)))))))))
1140 ;; Parse dir entries contained between START and END into a list of the form
1141 ;; (filename topic node (description-line-1 description-line-2 ...))
1142 (defun Info-parse-dir-entries (start end)
1143 (let (entry entries)
1146 (narrow-to-region start end)
1148 (while (re-search-forward
1149 (concat #r"^\* \([^:]+\):\("
1151 #r"(\([^)]*\))\w*\.\|:\)")
1153 (setq entry (list (match-string 2)
1155 (downcase (or (match-string 3)
1156 (match-string 1)))))
1163 (re-search-forward "[ \t]*" nil t)
1164 (or (and (re-search-forward "^[^ \t]" nil t)
1165 (goto-char (match-beginning 0)))
1167 "[ \t]*\n[ \t]*"))))
1169 (setq entries (cons (nreverse entry) entries)))))
1170 (nreverse entries)))
1172 (defun Info-dump-dir-entries (entries)
1176 (mapcar #'(lambda (e)
1177 (setq e (cdr e)) ; Drop filename
1178 (setq len (length (concat (car e)
1180 (if (> len description-col)
1181 (setq description-col len)))
1183 (setq description-col (+ 5 description-col))
1184 (mapcar #'(lambda (e)
1185 (setq e (cdr e)) ; Drop filename
1186 (insert "* " (car e) ":" (car (cdr e)))
1187 (setq e (car (cdr (cdr e))))
1189 (indent-to-column description-col)
1190 (insert (car e) "\n")
1196 (defun Info-build-dir-anew (directory)
1197 "Build info directory information for DIRECTORY.
1198 The generated directory listing may be saved to a `dir' according
1199 to the value of `Info-save-auto-generated-dir'."
1201 (let* ((dirfile (expand-file-name "dir" directory))
1202 (to-temp (or (null Info-save-auto-generated-dir)
1203 (eq Info-save-auto-generated-dir 'never)
1204 (and (not (file-writable-p dirfile))
1205 (message "File not writable %s. Using temporary."
1207 (info-files (Info-directory-files dirfile nil 'fullname nil t)))
1209 (message "Creating temporary dir in %s..." directory)
1210 (message "Creating %s..." dirfile))
1211 (set-buffer (find-file-noselect dirfile t))
1212 (setq buffer-read-only nil)
1214 (insert Info-dir-prologue "Info files in " directory ":\n\n")
1215 (Info-dump-dir-entries
1218 (or (Info-extract-dir-entry-from f)
1220 (progn (string-match #r"\([^.]*\)\(\..*\)?$"
1221 (file-name-nondirectory f))
1223 (match-string 1 (file-name-nondirectory f))))
1225 (list Info-no-description-string))))
1228 (set-buffer-modified-p nil)
1231 (message "Creating temporary dir in %s...done" directory)
1232 (message "Creating %s...done" dirfile)))))
1235 (defun Info-rebuild-dir (file)
1236 "Build info directory information in the directory of dir FILE.
1237 Description of info files are merged from the info files in the
1238 directory and the contents of FILE with the description in info files
1239 taking precedence over descriptions in FILE.
1240 The generated directory listing may be saved to a `dir' according to
1241 the value of `Info-save-auto-generated-dir'."
1244 (let (dir-section-contents dir-full-contents
1250 (or (null Info-save-auto-generated-dir)
1251 (eq Info-save-auto-generated-dir 'never)
1252 (and (eq Info-save-auto-generated-dir 'always)
1253 (not (file-writable-p file))
1254 (message "File not writable %s. Using temporary." file))
1255 (and (eq Info-save-auto-generated-dir 'conservative)
1256 (or (and (not (file-writable-p file))
1258 "File not writable %s. Using temporary." file))
1260 (message "%s is outdated. Overwrite ? "
1262 (set-buffer (find-file-noselect file t))
1263 (setq buffer-read-only nil)
1265 (message "Rebuilding temporary %s..." file)
1266 (message "Rebuilding %s..." file))
1268 (setq buffer-read-only nil)
1269 (goto-char (point-min))
1270 (unless (and (search-forward "\^_")
1271 (re-search-forward "^\\* Menu:.*$" nil t)
1272 (setq mark (and (re-search-forward "^\\* " nil t)
1273 (match-beginning 0))))
1275 (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1276 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$"
1278 (match-beginning 0))
1281 (narrow-to-region mark next-section)
1282 (setq dir-section-contents (nreverse (Info-parse-dir-entries
1283 (point-min) (point-max))))
1286 (setq dir-entry (assoc (downcase
1287 (file-name-sans-extension
1288 (file-name-nondirectory file)))
1289 dir-section-contents)
1290 file-dir-entry (Info-extract-dir-entry-from file))
1293 ;; A dir entry in the info file takes precedence over
1294 ;; an existing entry in the dir file
1295 (setcdr dir-entry (cdr file-dir-entry)))
1296 (unless (or not-first-section
1298 (file-name-sans-extension
1299 (file-name-nondirectory file)))
1302 (setq dir-section-contents
1303 (cons file-dir-entry dir-section-contents))
1304 (setq dir-section-contents
1306 (capitalize (file-name-sans-extension
1307 (file-name-nondirectory
1310 (list Info-no-description-string))
1311 dir-section-contents))))))
1312 Info-dir-newer-info-files)
1313 (delete-region (point-min) (point-max))
1314 (Info-dump-dir-entries (nreverse dir-section-contents))
1316 (if (= next-section (point-max))
1317 (setq next-section nil)
1318 (or (setq mark (and (re-search-forward "^\\* " nil t)
1319 (match-beginning 0)))
1321 (setq next-section (or (and (re-search-forward
1322 "^[^* \t].*:[ \t]*$" nil t)
1323 (match-beginning 0))
1325 (setq not-first-section t)))
1328 (set-buffer-modified-p nil)
1329 (message "Rebuilding temporary %s...done" file))
1331 (message "Rebuilding %s...done" file))))))
1334 (defun Info-batch-rebuild-dir ()
1335 "(Re)build `dir' files in the directories remaining on the command line.
1336 Use this from the command line, with `-batch', it won't work in an
1339 Each file is processed even if an error occurred previously. For example,
1340 invoke \"sxemacs -batch -f Info-batch-rebuild-dir /usr/local/info\"."
1341 ;; command-line-args-left is what is left of the command line (from
1343 (defvar command-line-args-left) ; Avoid 'free variable' warning
1344 (if (not noninteractive)
1345 (error "`Info-batch-rebuild-dir' is to be used only with -batch"))
1346 (let ((Info-save-auto-generated-dir 'always)
1348 (while command-line-args-left
1349 (if (not (file-directory-p (car command-line-args-left)))
1350 (message "Warning: Skipped %s. Not a directory."
1351 (car command-line-args-left))
1352 (setq dir (expand-file-name "dir" (car command-line-args-left)))
1353 (setq localdir (expand-file-name "localdir"
1354 (car command-line-args-left)))
1356 ((file-exists-p dir)
1357 (Info-rebuild-dir dir))
1358 ((file-exists-p localdir)
1359 (Info-rebuild-dir localdir))
1361 (Info-build-dir-anew (car command-line-args-left)))))
1362 (setq command-line-args-left (cdr command-line-args-left)))
1366 (defun Info-history-add (file node point)
1367 (if Info-keeping-history
1368 (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
1369 (found (assoc name Info-history)))
1371 (setq Info-history (delq found Info-history)))
1372 (setq Info-history (cons (list name (- point (point-min))
1373 (and (eq (window-buffer)
1375 (- (window-start) (point-min))))
1378 (defun Info-file-name-only (file)
1379 (let ((dir (file-name-directory file))
1380 (p Info-directory-list))
1381 (while (and p (not (equal (car p) dir)))
1383 (if p (file-name-nondirectory file) file)))
1385 (defun Info-read-subfile (nodepos)
1389 (set-buffer (marker-buffer Info-tag-table-marker))
1390 (goto-char (point-min))
1391 (search-forward "\n\^_")
1394 (while (not (looking-at "\^_"))
1396 (let ((start (point))
1397 thisfilepos thisfilename)
1398 (search-forward ": ")
1399 (setq thisfilename (buffer-substring start (- (point) 2)))
1400 (setq thisfilepos (read (current-buffer)))
1401 ;; read in version 19 stops at the end of number.
1402 ;; Advance to the next line.
1405 (if (> thisfilepos nodepos)
1407 (setq lastfilename thisfilename)
1408 (setq lastfilepos thisfilepos))
1410 (or (equal Info-current-subfile lastfilename)
1411 (let ((buffer-read-only nil))
1412 (setq buffer-file-name nil
1413 buffer-file-truename nil)
1416 (Info-insert-file-contents (Info-suffixed-file
1417 (expand-file-name lastfilename
1418 (file-name-directory
1422 (set-buffer-modified-p nil)
1423 (setq Info-current-subfile lastfilename)))
1424 (goto-char (point-min))
1425 (search-forward "\n\^_")
1426 (+ (- nodepos lastfilepos) (point))))
1428 (defun Info-all-case-regexp (str)
1434 (setq c (aref str i))
1435 (cond ((or (and (>= c ?A) (<= c ?Z))
1436 (and (>= c ?a) (<= c ?z)))
1437 (setq regexp (concat regexp
1439 (char-to-string (downcase c))
1441 (char-to-string (upcase c))
1444 (setq regexp (concat regexp (char-to-string c)))))
1448 (defun Info-suffixed-file (name &optional exact)
1449 "Look for an info file named NAME. This function tries to be smart in
1450 finding the file corresponding to NAME: if it doesn't exist, several
1451 variants are looked for, notably by appending suffixes from
1452 `Info-suffix-list' and by trying to change the characters case in NAME.
1454 The optional argument EXACT prevents this function from trying different case
1455 versions of NAME. Only the suffixes are tried."
1457 ;; First, try NAME alone:
1458 (and (file-regular-p name) (throw 'found name))
1459 ;; Then, try different variants
1460 (let ((suff-match (concat "\\("
1461 (let ((suff-list Info-suffix-list)
1463 (while (setq suff (pop suff-list))
1466 (regexp-quote (car suff))
1467 (and suff-list "\\|"))))
1470 (dir (file-name-directory name))
1472 (setq name (file-name-nondirectory name))
1474 (condition-case data ;; protect against invalid directory
1475 ;; First, try NAME[.<suffix>]
1477 (directory-files dir 'fullname
1478 (concat "^" (regexp-quote name) suff-match)
1482 ;; Then, try to match the name independantly of the
1484 (directory-files dir 'fullname
1485 (Info-all-case-regexp
1491 (display-warning 'info
1492 (format "directory `%s' error: %s" dir data))
1494 (while (setq file (pop files))
1495 (and (file-regular-p file)
1496 (throw 'found file)))
1499 (defun Info-insert-file-contents (file &optional visit)
1500 (setq file (expand-file-name file default-directory))
1501 (let ((suff Info-suffix-list)
1504 (setq len (length (car (car suff))))
1505 (or (<= (length file) len)
1507 (equal (substring file (- len))
1509 (equal (substring file (- len))
1510 (upcase (car (car suff)))))
1512 (setq suff (cdr suff)))
1513 (if (stringp (cdr (car suff)))
1514 (let ((command (if (string-match "%s" (cdr (car suff)))
1515 (format (cdr (car suff)) file)
1516 (concat (cdr (car suff)) " < " file))))
1517 (message "%s..." command)
1518 (call-process shell-file-name nil t nil shell-command-switch command)
1521 (setq buffer-file-name file
1522 buffer-file-truename (file-truename buffer-file-name))
1523 (set-buffer-modified-p nil)
1524 (clear-visited-file-modtime)))
1525 (insert-file-contents file visit))))
1527 (defun Info-select-node ()
1528 "Select the node that point is in, after using `g *' to select whole file."
1532 ;; Find beginning of node.
1533 (search-backward "\n\^_")
1535 ;; Get nodename spelled as it is in the node.
1536 (re-search-forward "Node:[ \t]*")
1537 (setq Info-current-node
1538 (buffer-substring (point)
1540 (skip-chars-forward "^,\t\n")
1542 (Info-set-mode-line)
1543 ;; Find the end of it, and narrow.
1545 (let (active-expression)
1546 (narrow-to-region (point)
1547 (if (re-search-forward "\n[\^_\f]" nil t)
1550 (if (looking-at "[\n\^_\f]*execute: ")
1552 (goto-char (match-end 0))
1553 (setq active-expression
1554 (read (current-buffer))))))
1556 (or (equal Info-footnote-tag "Note")
1558 (goto-char (point-min))
1559 (let ((buffer-read-only nil)
1560 (bufmod (buffer-modified-p))
1561 (case-fold-search t))
1562 (while (re-search-forward "\\*[Nn]ote\\([ \n]\\)" nil t)
1563 (replace-match (concat "*" Info-footnote-tag "\ ")))
1564 (set-buffer-modified-p bufmod))))
1565 (Info-reannotate-node)
1566 ;; XEmacs: remove v19 test
1568 (Info-fontify-node))
1569 (run-hooks 'Info-select-hook)
1570 (if Info-enable-active-nodes (eval active-expression)))))
1572 (defun Info-set-mode-line ()
1573 (setq modeline-buffer-identification
1574 (list (cons modeline-buffer-id-left-extent "Info: ")
1575 (cons modeline-buffer-id-right-extent
1578 (if Info-current-file
1579 (let ((name (file-name-nondirectory
1580 Info-current-file)))
1581 (if (string-match #r"^\([^.]*\)\..*$" name)
1582 (match-string 1 name)
1586 (or Info-current-node ""))))))
1588 ;; Go to an info node specified with a filename-and-nodename string
1589 ;; of the sort that is found in pointers in nodes.
1592 (defun Info-goto-node (nodename &optional no-going-back tryfile)
1593 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
1594 Actually, the following interpretations of NAME are tried in order:
1596 (FILENAME) (using Top node)
1597 NODENAME (in current file)
1599 FILENAME (using Top node)
1600 where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
1601 annotation for any node of any file. (See `a' and `x' commands.)"
1602 (interactive (list (Info-read-node-name "Goto node, file or tag: ")
1605 (string-match (concat #r"\s *\((\s *\("
1607 #r"\)\s *)\s *\|\)\(.*\)")
1609 (setq filename (if (= (match-beginning 1) (match-end 1))
1611 (substring nodename (match-beginning 2) (match-end 2)))
1612 nodename (substring nodename (match-beginning 3) (match-end 3)))
1613 (let ((trim (string-match #r"\s *\'" filename)))
1614 (if trim (setq filename (substring filename 0 trim))))
1615 (let ((trim (string-match #r"\s *\'" nodename)))
1616 (if trim (setq nodename (substring nodename 0 trim))))
1617 (Info-find-node (if (equal filename "") nil filename)
1618 (if (equal nodename "") "Top" nodename)
1619 no-going-back (and tryfile (equal filename "")))))
1621 (defun Info-goto-bookmark ()
1623 (let ((completion-ignore-case nil)
1624 (tag (completing-read "Goto tag: "
1625 (Info-build-annotation-completions)
1627 'Info-minibuffer-history)))
1628 (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
1631 (defun Info-visit-file (file)
1632 "Directly visit an info file."
1633 (interactive "fVisit Info file: ")
1634 (Info-find-node (expand-file-name file) "Top"))
1636 (defun Info-restore-point (&optional always)
1637 "Restore point to same location it had last time we were in this node."
1639 (if (or Info-restoring-point always)
1640 (let* ((name (format "(%s)%s"
1641 (Info-file-name-only Info-current-file)
1643 (p (assoc name Info-history)))
1644 (if p (Info-restore-history-entry p)))))
1646 (defun Info-restore-history-entry (entry)
1647 (goto-char (+ (nth 1 entry) (point-min)))
1649 (get-buffer-window (current-buffer))
1650 (set-window-start (get-buffer-window (current-buffer))
1651 (+ (nth 2 entry) (point-min)))))
1653 (defvar Info-read-node-completion-table)
1655 ;; This function is used as the "completion table" while reading a node name.
1656 ;; It does completion using the alist in Info-read-node-completion-table
1657 ;; unless STRING starts with an open-paren.
1658 (defun Info-read-node-name-1 (string predicate code)
1659 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
1660 (cond ((eq code nil)
1663 (try-completion string Info-read-node-completion-table
1668 (all-completions string Info-read-node-completion-table
1673 (assoc string Info-read-node-completion-table))))))
1675 (defun Info-read-node-name (prompt &optional default)
1676 (Info-setup-initial)
1677 (let* ((completion-ignore-case t)
1678 (Info-read-node-completion-table (Info-build-node-completions))
1679 (nodename (completing-read prompt 'Info-read-node-name-1
1680 nil t nil 'Info-minibuffer-history
1682 (if (equal nodename "")
1684 (Info-read-node-name prompt))
1687 (defun Info-build-annotation-completions ()
1688 (or Info-current-annotation-completions
1690 (let ((bufs (delq nil (mapcar 'get-file-buffer
1691 Info-annotations-path)))
1694 (set-buffer (car bufs))
1695 (goto-char (point-min))
1696 (while (re-search-forward #r"<<\(.*\)>>" nil t)
1697 (setq compl (cons (list (buffer-substring (match-beginning 1)
1700 (setq bufs (cdr bufs)))
1701 (setq Info-current-annotation-completions compl)))))
1703 (defun Info-build-node-completions ()
1704 (or Info-current-file-completions
1705 (let ((m Info-tag-table-marker)
1706 (compl (Info-build-annotation-completions)))
1710 (if (marker-buffer Info-tag-table-marker)
1712 (set-buffer (marker-buffer Info-tag-table-marker))
1714 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
1716 (cons (list (buffer-substring (match-beginning 1)
1719 (goto-char (point-min))
1720 (while (search-forward "\n\^_" nil t)
1722 (let ((start (point)))
1724 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
1727 (cons (list (buffer-substring (match-beginning 1)
1730 (setq Info-current-file-completions compl))))
1732 (defvar Info-last-search nil
1733 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1737 (defun Info-search (regexp)
1738 "Search for REGEXP, starting from point, and select node it's found in."
1740 (read-from-minibuffer
1741 (if Info-last-search
1742 (format "Search (regexp, default %s): "
1744 "Search (regexp): ")
1745 nil nil nil nil nil Info-last-search)))
1746 (setq Info-last-search regexp)
1747 (with-search-caps-disable-folding regexp t
1749 (onode Info-current-node)
1750 (ofile Info-current-file)
1752 (osubfile Info-current-subfile))
1756 (if (null Info-current-subfile)
1757 (progn (re-search-forward regexp) (setq found (point)))
1759 (progn (re-search-forward regexp) (setq found (point)))
1760 (search-failed nil)))))
1762 ;; can only happen in subfile case -- else would have erred
1766 (set-buffer (marker-buffer Info-tag-table-marker))
1767 (goto-char (point-min))
1768 (search-forward "\n\^_\nIndirect:")
1770 (narrow-to-region (point)
1771 (progn (search-forward "\n\^_")
1773 (goto-char (point-min))
1774 (search-forward (concat "\n" osubfile ": "))
1777 (re-search-forward #r"\(^.*\): [0-9]+$")
1778 (goto-char (+ (match-end 1) 2))
1779 (setq list (cons (cons (read (current-buffer))
1784 (goto-char (1+ (match-end 0))))
1785 (setq list (nreverse list)
1788 (message "Searching subfile %s..." (cdr (car list)))
1789 (Info-read-subfile (car (car list)))
1790 (setq list (cdr list))
1791 (goto-char (point-min))
1792 (if (re-search-forward regexp nil t)
1793 (setq found (point) list ())))
1796 (signal 'search-failed (list regexp))))
1798 (progn (Info-read-subfile opoint)
1800 (Info-select-node)))))
1804 (or (and (equal onode Info-current-node)
1805 (equal ofile Info-current-file))
1806 (Info-history-add ofile onode opoint)))))
1808 ;; Extract the value of the node-pointer named NAME.
1809 ;; If there is none, use ERRORNAME in the error message;
1810 ;; if ERRORNAME is nil, just return nil.
1811 (defun Info-extract-pointer (name &optional errorname)
1813 (goto-char (point-min))
1815 (let ((case-fold-search t))
1816 (if (re-search-backward (concat name ":") nil t)
1818 (goto-char (match-end 0))
1819 (Info-following-node-name))
1820 (if (eq errorname t)
1822 (error (concat "Node has no " (capitalize (or errorname name)))))))))
1824 ;; Return the node name in the buffer following point.
1825 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1826 ;; saying which chars may appear in the node name.
1827 (defun Info-following-node-name (&optional allowedchars)
1828 (skip-chars-forward " \t")
1832 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1833 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1834 (if (looking-at "(")
1835 (skip-chars-forward "^)")))
1836 (skip-chars-backward " .")
1839 (defun Info-next (&optional n)
1840 "Go to the next node of this node.
1841 A positive or negative prefix argument moves by multiple nodes."
1846 (while (>= (setq n (1- n)) 0)
1847 (Info-goto-node (Info-extract-pointer "next")))))
1849 (defun Info-prev (&optional n)
1850 "Go to the previous node of this node.
1851 A positive or negative prefix argument moves by multiple nodes."
1856 (while (>= (setq n (1- n)) 0)
1857 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
1859 (defun Info-up (&optional n)
1860 "Go to the superior node of this node.
1861 A positive prefix argument moves up several times."
1864 (while (>= (setq n (1- n)) 0)
1865 (Info-goto-node (Info-extract-pointer "up")))
1866 (if (interactive-p) (Info-restore-point)))
1868 (defun Info-last (&optional n)
1869 "Go back to the last node visited.
1870 With a prefix argument, go to Nth most recently visited node. History is
1871 circular; after oldest node, history comes back around to most recent one.
1872 Argument can be negative to go through the circle in the other direction.
1873 \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
1877 (error "This is the first Info node you looked at"))
1878 (let ((len (1+ (length Info-history))))
1879 (setq n (% (+ n (* len 100)) len)))
1881 (let ((entry (nth (1- n) Info-history)))
1882 (Info-history-add Info-current-file Info-current-node (point))
1883 (while (>= (setq n (1- n)) 0)
1884 (setq Info-history (nconc (cdr Info-history)
1885 (list (car Info-history)))))
1886 (setq Info-history (cdr Info-history))
1887 (let ((Info-keeping-history nil))
1888 (Info-goto-node (car entry)))
1889 (Info-restore-history-entry entry))))
1891 (defun Info-directory ()
1892 "Go to the Info directory node."
1894 (Info-find-node "dir" "top"))
1896 (defun Info-follow-reference (footnotename)
1897 "Follow cross reference named NAME to the node it refers to.
1898 NAME may be an abbreviation of the reference name."
1900 (let ((completion-ignore-case t)
1901 completions default (start-point (point)) str i)
1903 (goto-char (point-min))
1904 (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
1907 (setq str (buffer-substring
1910 ;; See if this one should be the default.
1912 (< (match-beginning 0) start-point)
1913 (<= start-point (point))
1916 (while (setq i (string-match "[ \n\t]+" str i))
1917 (setq str (concat (substring str 0 i) " "
1918 (substring str (match-end 0))))
1920 ;; Record as a completion and perhaps as default.
1921 (if (eq default t) (setq default str))
1923 (cons (cons str nil)
1926 (let ((item (completing-read (if default
1927 (concat "Follow reference named: ("
1929 "Follow reference named: ")
1930 completions nil t nil
1931 'Info-minibuffer-history
1933 (if (and (string= item "") default)
1936 (error "No cross-references in this node"))))
1937 (let (target i (str (concat "\\*" Info-footnote-tag " "
1938 (regexp-quote footnotename))))
1939 (while (setq i (string-match " " str i))
1940 (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
1941 (substring str (1+ i))))
1944 (goto-char (point-min))
1945 (or (re-search-forward str nil t)
1946 (error "No cross-reference named %s" footnotename))
1947 (goto-char (match-end 1))
1949 (Info-extract-menu-node-name "Bad format cross reference" t)))
1950 (while (setq i (string-match "[ \t\n]+" target i))
1951 (setq target (concat (substring target 0 i) " "
1952 (substring target (match-end 0))))
1954 (Info-goto-node target)
1955 (setq Info-in-cross-reference t)))
1957 (defun Info-next-reference (n)
1959 (let ((pat (format (concat "\\*%s[ \n\t]*"
1960 #r"\([^:]*\):\|^\* .*:\|<<.*>>")
1963 wrapped found-nomenu)
1965 (unless (re-search-backward pat nil t)
1966 ;; Don't wrap more than once in a buffer where only the
1967 ;; menu references are found.
1968 (when (and wrapped (not found-nomenu))
1970 (error "No cross references in this node"))
1972 (goto-char (point-max))
1973 (unless (re-search-backward pat nil t)
1975 (error "No cross references in this node")))
1976 (unless (save-excursion
1977 (goto-char (match-beginning 0))
1978 (when (looking-at "\\* Menu:")
1980 (setq found-nomenu t))
1983 (or (eobp) (forward-char 1))
1984 (unless (re-search-forward pat nil t)
1985 (when (and wrapped (not found-nomenu))
1987 (error "No cross references in this node"))
1989 (goto-char (point-min))
1990 (unless (re-search-forward pat nil t)
1992 (error "No cross references in this node")))
1993 (unless (save-excursion
1994 (goto-char (match-beginning 0))
1995 (when (looking-at "\\* Menu:")
1997 (setq found-nomenu t))
1999 (when (looking-at "\\* Menu:")
2000 (error "No cross references in this node"))
2001 (goto-char (match-beginning 0))))
2003 (defun Info-prev-reference (n)
2005 (Info-next-reference (- n)))
2007 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
2008 (skip-chars-forward " \t\n")
2009 (let ((start (point))
2011 (skip-chars-forward "^:")
2014 (if (looking-at ":")
2015 (buffer-substring start (1- (point)))
2016 (skip-chars-forward " \t\n")
2018 ;; Allow dots in node name not followed by whitespace.
2020 (concat "\\(([^)]+)[^.,"
2021 (if multi-line "" "\n")
2023 (if multi-line "" "\n")
2024 ;; We consider dots followed by newline as
2025 ;; end of nodename even if multil-line.
2026 ;; Also stops at .). It is generated by @pxref.
2027 ;; Skips sequential dots.
2028 "]\\|\\.+[^ \t\n)]\\)+\\)"))
2030 (while (setq i (string-match "\n" str i))
2034 (defun Info-menu (menu-item)
2035 "Go to node for menu item named (or abbreviated) NAME.
2036 Completion is allowed, and the menu item point is on is the default."
2038 (let ((completions '())
2039 ;; If point is within a menu item, use that item as the default
2044 (goto-char (point-min))
2045 (let ((case-fold-search t))
2046 (if (not (search-forward "\n* menu:" nil t))
2047 (error "No menu in this node")))
2048 (while (re-search-forward
2049 "\n\\* \\([^:\t\n]*\\):" nil t)
2050 (if (and (null default)
2051 (prog1 (if last (< last p) nil)
2052 (setq last (match-beginning 0)))
2054 (setq default (car (car completions))))
2055 (setq completions (cons (cons (buffer-substring
2058 (match-beginning 1))
2060 (if (and (null default) last
2062 (<= p (progn (end-of-line) (point))))
2063 (setq default (car (car completions)))))
2066 (setq item (let ((completion-ignore-case t))
2067 (completing-read (if default
2068 (format "Menu item (default %s): "
2071 completions nil t nil
2072 'Info-minibuffer-history
2074 ;; we rely on the fact that completing-read accepts an input
2075 ;; of "" even when the require-match argument is true and ""
2076 ;; is not a valid possibility
2077 (if (string= item "")
2083 ;; there is a problem here in that if several menu items have the same
2084 ;; name you can only go to the node of the first with this command.
2085 (Info-goto-node (Info-extract-menu-item menu-item) nil t))
2087 (defun Info-extract-menu-item (menu-item &optional noerror)
2089 (goto-char (point-min))
2090 (if (let ((case-fold-search t))
2091 (search-forward "\n* menu:" nil t))
2092 (if (or (search-forward (concat "\n* " menu-item ":") nil t)
2093 (search-forward (concat "\n* " menu-item) nil t))
2097 (Info-extract-menu-node-name))
2098 (and (not noerror) (error "No such item in menu")))
2099 (and (not noerror) (error "No menu in this node")))))
2101 ;; If COUNT is nil, use the last item in the menu.
2102 (defun Info-extract-menu-counting (count &optional noerror noindex)
2104 (goto-char (point-min))
2105 (if (let ((case-fold-search t))
2106 (and (search-forward "\n* menu:" nil t)
2108 (not (string-match "\\<Index\\>" Info-current-node)))))
2109 (if (search-forward "\n* " nil t count)
2112 (while (search-forward "\n* " nil t)))
2113 (Info-extract-menu-node-name))
2114 (and (not noerror) (error "Too few items in menu")))
2115 (and (not noerror) (error "No menu in this node")))))
2117 (defun Info-nth-menu-item (n)
2118 "Go to the node of the Nth menu item."
2120 (or n (setq n (- last-command-char ?0)))
2121 (if (< n 1) (error "Index must be at least 1"))
2122 (Info-goto-node (Info-extract-menu-counting n) nil t))
2124 (defun Info-last-menu-item ()
2125 "Go to the node of the tenth menu item."
2127 (Info-goto-node (Info-extract-menu-counting nil) nil t))
2130 "Go to the Top node of this file."
2132 (Info-goto-node "Top"))
2135 "Go to the final node in this file."
2138 (let ((Info-keeping-history nil)
2140 (Info-last-menu-item)
2141 (while (setq node (or (Info-extract-pointer "next" t)
2142 (Info-extract-menu-counting nil t t)))
2143 (Info-goto-node node))
2144 (or (equal (Info-extract-pointer "up" t) "Top")
2145 (let ((executing-kbd-macro "")) ; suppress messages
2147 (Info-global-next 10000)
2150 (defun Info-global-next (&optional n)
2151 "Go to the next node in this file, traversing node structure as necessary.
2152 This works only if the Info file is structured as a hierarchy of nodes.
2153 A positive or negative prefix argument moves by multiple nodes."
2157 (Info-global-prev (- n))
2158 (while (>= (setq n (1- n)) 0)
2160 (cond ((and (string-match "^Top$" Info-current-node)
2161 (setq node (Info-extract-pointer "next" t))
2162 (Info-extract-menu-item node t))
2163 (Info-goto-node node))
2164 ((setq node (Info-extract-menu-counting 1 t t))
2165 (message "Going down...")
2166 (Info-goto-node node))
2168 (let ((Info-keeping-history Info-keeping-history)
2169 (orignode Info-current-node)
2171 (while (not (Info-extract-pointer "next" t))
2172 (if (and (setq node (Info-extract-pointer "up" t))
2173 (not (equal node "Top")))
2175 (message "Going%s..." (setq ups (concat ups " up")))
2176 (Info-goto-node node)
2177 (setq Info-keeping-history nil))
2179 (let ((Info-keeping-history nil))
2180 (Info-goto-node orignode)))
2181 (error "Last node in file")))
2184 (defun Info-page-next (&optional n)
2185 "Scroll forward one screenful, or go to next global node.
2186 A positive or negative prefix argument moves by multiple screenfuls."
2190 (Info-page-prev (- n))
2191 (while (>= (setq n (1- n)) 0)
2192 (if (pos-visible-in-window-p (point-max))
2195 (message "Node: %s" Info-current-node))
2198 (defun Info-scroll-next (arg)
2200 (if Info-auto-advance
2201 (if (and (pos-visible-in-window-p (point-max))
2202 (not (eq Info-auto-advance t))
2203 (not (eq last-command this-command)))
2204 (message "Hit %s again to go to next node"
2205 (if (= last-command-char 0)
2207 (key-description (char-to-string last-command-char))))
2209 (setq this-command 'Info))
2212 (defun Info-global-prev (&optional n)
2213 "Go to the previous node in this file, traversing structure as necessary.
2214 This works only if the Info file is structured as a hierarchy of nodes.
2215 A positive or negative prefix argument moves by multiple nodes."
2219 (Info-global-next (- n))
2220 (while (>= (setq n (1- n)) 0)
2221 (let ((upnode (Info-extract-pointer "up" t))
2222 (prevnode (Info-extract-pointer "prev[ious]*" t)))
2223 (if (or (not prevnode)
2224 (equal prevnode upnode))
2225 (if (string-match "^Top$" Info-current-node)
2226 (error "First node in file")
2227 (message "Going up...")
2229 (Info-goto-node prevnode)
2231 (Info-keeping-history nil)
2233 (while (setq node (Info-extract-menu-counting nil t t))
2234 (message "Going%s..." (setq downs (concat downs " down")))
2235 (Info-goto-node node))))))))
2237 (defun Info-page-prev (&optional n)
2238 "Scroll backward one screenful, or go to previous global node.
2239 A positive or negative prefix argument moves by multiple screenfuls."
2243 (Info-page-next (- n))
2244 (while (>= (setq n (1- n)) 0)
2245 (if (pos-visible-in-window-p (point-min))
2248 (message "Node: %s" Info-current-node)
2249 (goto-char (point-max))
2251 (move-to-window-line 0))
2254 (defun Info-scroll-prev (arg)
2256 (if Info-auto-advance
2257 (if (and (pos-visible-in-window-p (point-min))
2258 (not (eq Info-auto-advance t))
2259 (not (eq last-command this-command)))
2260 (message "Hit %s again to go to previous node"
2261 (if (mouse-event-p last-command-event)
2263 (key-description (event-key last-command-event))))
2265 (setq this-command 'Info))
2268 (defun Info-index (topic)
2269 "Look up a string in the index for this file.
2270 The index is defined as the first node in the top-level menu whose
2271 name contains the word \"Index\", plus any immediately following
2272 nodes whose names also contain the word \"Index\".
2273 If there are no exact matches to the specified topic, this chooses
2274 the first match which is a case-insensitive substring of a topic.
2275 Use the `,' command to see the other matches.
2276 Give a blank topic name to go to the Index node itself."
2277 (interactive "sIndex topic: ")
2278 (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
2279 (regexp-quote topic)
2280 "\\(.*\\)\\.[ \t]*\\([0-9]*\\)$"))
2282 (message "Searching index for `%s'..." topic)
2283 (Info-goto-node "Top")
2284 (let ((case-fold-search t))
2285 (or (search-forward "\n* menu:" nil t)
2287 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2288 (error "No index")))
2289 (goto-char (match-beginning 1))
2290 (let ((Info-keeping-history nil)
2291 (Info-fontify (and Info-fontify (equal topic ""))))
2292 (Info-goto-node (Info-extract-menu-node-name)))
2293 (or (equal topic "")
2296 (Info-keeping-history nil)
2300 (goto-char (point-min))
2301 (while (re-search-forward pattern nil t)
2303 (cons (list (buffer-substring (match-beginning 1)
2305 (buffer-substring (match-beginning 2)
2308 (string-to-int (concat "0"
2313 (and (setq node (Info-extract-pointer "next" t))
2314 (string-match "\\<Index\\>" node)))
2315 (let ((Info-fontify nil))
2316 (Info-goto-node node)))
2320 (error "No \"%s\" in index" topic)))
2321 ;; Here it is a feature that assoc is case-sensitive.
2322 (while (setq found (assoc topic matches))
2323 (setq exact (cons found exact)
2324 matches (delq found matches)))
2325 (setq Info-index-alternatives (nconc exact (nreverse matches))
2326 Info-index-first-alternative (car Info-index-alternatives))
2327 (Info-index-next 0)))))
2329 (defun Info-index-next (num)
2330 "Go to the next matching index item from the last `i' command."
2332 (or Info-index-alternatives
2333 (error "No previous `i' command in this file"))
2335 (setq num (+ num (length Info-index-alternatives))))
2337 (setq Info-index-alternatives
2338 (nconc (cdr Info-index-alternatives)
2339 (list (car Info-index-alternatives)))
2341 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2342 (if (> (nth 3 (car Info-index-alternatives)) 0)
2343 (forward-line (nth 3 (car Info-index-alternatives)))
2344 (forward-line 3) ; don't search in headers
2345 (let ((name (car (car Info-index-alternatives))))
2346 (if (or (re-search-forward (format
2347 #r"\(Function\|Command\): %s\( \|$\)"
2348 (regexp-quote name)) nil t)
2349 (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
2350 (search-forward (format "`%s'" name) nil t)
2351 (and (string-match #r"\`.*\( (.*)\)\'" name)
2353 (format "`%s'" (substring name 0 (match-beginning 1)))
2355 (search-forward name nil t))
2357 (goto-char (point-min)))))
2358 (message "Found \"%s\" in %s. %s"
2359 (car (car Info-index-alternatives))
2360 (nth 2 (car Info-index-alternatives))
2361 (if (cdr Info-index-alternatives)
2362 (if (eq (car (cdr Info-index-alternatives))
2363 Info-index-first-alternative)
2364 "(Press `,' to repeat)"
2365 (format "(Press `,' for %d more)"
2366 (- (1- (length Info-index-alternatives))
2367 (length (memq Info-index-first-alternative
2368 (cdr Info-index-alternatives))))))
2373 (defun Info-emacs-command (command)
2374 "Look up an Emacs command in the Emacs manual in the Info system.
2375 This command is designed to be used whether you are already in Info or not."
2376 (interactive "CLook up command in Emacs manual: ")
2377 (save-window-excursion
2379 (Info-find-node Info-emacs-info-file-name "Top")
2380 (Info-index (symbol-name command)))
2381 (pop-to-buffer "*info*"))
2385 (defun Info-goto-emacs-command-node (key)
2386 "Look up an Emacs command in the Emacs manual in the Info system.
2387 This command is designed to be used whether you are already in Info or not."
2388 (interactive "CLook up command in Emacs manual: ")
2389 (Info-emacs-command key))
2392 (defun Info-goto-emacs-key-command-node (key)
2393 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2394 This command is designed to be used whether you are already in Info or not."
2395 (interactive "kLook up key in Emacs manual: ")
2396 (let ((command (key-binding key)))
2397 (cond ((eq command 'keyboard-quit)
2400 (error "%s is undefined" (key-description key)))
2401 ((and (interactive-p) (eq command 'execute-extended-command))
2402 (call-interactively 'Info-goto-emacs-command-node))
2404 (Info-goto-emacs-command-node command)))))
2407 (defun Info-emacs-key (key)
2408 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2409 This command is designed to be used whether you are already in Info or not."
2410 (interactive "kLook up key in Emacs manual: ")
2411 (cond ((eq (key-binding key) 'keyboard-quit)
2413 ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
2414 (call-interactively 'Info-goto-emacs-command-node))
2416 (save-window-excursion
2418 (Info-find-node Info-emacs-info-file-name "Top")
2419 (setq key (key-description key))
2421 (if (setq p (string-match "[@{}]" key))
2422 (setq key (concat (substring key 0 p) "@" (substring key p))))
2423 (if (string-match "^ESC " key)
2424 (setq key (concat "M-" (substring key 4))))
2425 (if (string-match "^M-C-" key)
2426 (setq key (concat "C-M-" (substring key 4)))))
2428 (pop-to-buffer "*info*"))))
2431 (defun Info-elisp-ref (func)
2432 "Look up an Emacs Lisp function in the Elisp manual in the Info system.
2433 This command is designed to be used whether you are already in Info or not."
2434 (interactive (let ((fn (function-at-point))
2435 (enable-recursive-minibuffers t)
2437 (setq val (completing-read
2438 (format "Look up Emacs Lisp function%s: "
2440 (format " (default %s)" fn)
2443 nil nil (and fn (symbol-name fn))))
2444 (list (if (equal val "")
2446 (save-window-excursion
2449 (Info-find-node "lispref" "Top")
2450 (error (Info-find-node "elisp" "Top")))
2451 (Info-index (symbol-name func)))
2452 (pop-to-buffer "*info*"))
2454 (defun Info-reannotate-node ()
2455 (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
2457 (let ((ibuf (current-buffer))
2458 (file (concat "\\(" (regexp-quote
2459 (file-name-nondirectory Info-current-file))
2460 "\\|" (regexp-quote Info-current-file) "\\)"))
2461 (node (regexp-quote Info-current-node))
2463 (goto-char (point-min))
2464 (if (search-forward "\n------ NOTE:\n" nil t)
2465 (let ((buffer-read-only nil)
2466 (bufmod (buffer-modified-p))
2468 (setq savept (copy-marker savept))
2469 (goto-char (point-min))
2470 (while (search-forward "\n------ NOTE:" nil t)
2471 (setq top (1+ (match-beginning 0)))
2472 (if (search-forward "\n------\n" nil t)
2473 (delete-region top (point)))
2475 (set-buffer-modified-p bufmod)))
2478 (set-buffer (car bufs))
2479 (goto-char (point-min))
2480 (while (re-search-forward
2482 "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
2485 (let ((line (string-to-int
2486 (buffer-substring (match-beginning 2)
2490 (search-forward "\n------\n" nil t)
2494 (if (integerp savept) (setq savept (copy-marker savept)))
2496 (goto-char (point-max))
2497 (goto-char (point-min))
2498 (forward-line line))
2499 (let ((buffer-read-only nil)
2500 (bufmod (buffer-modified-p)))
2501 (insert "------ NOTE:\n")
2502 (insert-buffer-substring (car bufs) top bot)
2503 (set-buffer-modified-p bufmod)))))
2504 (setq bufs (cdr bufs))))
2505 (goto-char savept)))))
2507 (defvar Info-annotate-map nil
2508 "Local keymap used within `a' command of Info.")
2510 (if Info-annotate-map
2512 ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
2513 (setq Info-annotate-map (copy-keymap text-mode-map))
2514 (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
2516 (defun Info-annotate-mode ()
2517 "Major mode for adding an annotation to an Info node.
2518 Like text mode with the addition of Info-cease-annotate
2519 which returns to Info mode for browsing.
2520 \\{Info-annotate-map}")
2522 (defun Info-annotate (arg)
2523 "Add a personal annotation to the current Info node.
2524 Only you will be able to see this annotation. Annotations are stored
2525 in the file \"info.notes\" in your `user-init-directory' by default. If
2526 point is inside an existing annotation, edit that annotation. A prefix
2527 argument specifies which annotations file (from `Info-annotations-path')
2528 is to be edited; default is 1."
2531 (if (or (< arg 0) (not (nth arg Info-annotations-path)))
2533 (setq Info-annotations-path
2534 (list (read-file-name
2535 "Annotations file: " "~/" "~/.infonotes")))
2536 (error "File number must be in the range from 1 to %d"
2537 (length Info-annotations-path))))
2539 (file (file-name-nondirectory Info-current-file))
2540 (d Info-directory-list)
2542 (while (and d (not (equal (expand-file-name file (car d))
2543 Info-current-file)))
2545 (or d (setq file Info-current-file))
2546 (if (and (save-excursion
2547 (goto-char (min (point-max) (+ (point) 13)))
2548 (and (search-backward "------ NOTE:\n" nil t)
2549 (setq pt (match-end 0))
2550 (search-forward "\n------\n" nil t)))
2551 (< (point) (match-end 0)))
2552 (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
2554 (regexp-quote Info-current-node)
2556 (buffer-substring pt (match-beginning 0))))
2557 where (max (- (point) pt) 0)))
2558 (let ((node Info-current-node)
2559 (line (if (looking-at "[ \n]*\\'") 0
2560 (count-lines (point-min) (point)))))
2562 (let ((buffer-read-only nil)
2563 (bufmod (buffer-modified-p)))
2565 (if (bobp) (goto-char (point-max)))
2566 (insert "------ NOTE:\n------\n")
2568 (set-buffer-modified-p bufmod)))
2569 ;; (setq Info-window-start (window-start))
2570 (setq Info-window-configuration (current-window-configuration))
2571 (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
2572 (use-local-map Info-annotate-map)
2573 (setq major-mode 'Info-annotate-mode)
2574 (setq mode-name "Info Annotate")
2577 (goto-char (point-min))
2578 (re-search-forward which nil t))
2580 (goto-char (match-beginning 0))
2582 (forward-char where)))
2583 (let ((bufmod (buffer-modified-p)))
2584 (goto-char (point-max))
2585 (insert (format "\n------ File: %s Node: %s Line: %d\n"
2588 (insert "\n------\n"
2589 "\nPress C-c C-c to save and return to Info.\n")
2591 (set-buffer-modified-p bufmod))))))
2593 (defun Info-cease-annotate ()
2595 (let ((bufmod (buffer-modified-p)))
2596 (while (save-excursion
2597 (goto-char (point-min))
2598 (re-search-forward "\n\n?Press .* to save and return to Info.\n"
2600 (delete-region (1+ (match-beginning 0)) (match-end 0)))
2601 (while (save-excursion
2602 (goto-char (point-min))
2603 (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
2605 (delete-region (match-beginning 0) (match-end 0)))
2606 (set-buffer-modified-p bufmod))
2610 (or (one-window-p) (delete-window))
2612 (setq Info-current-annotation-completions nil)
2613 (set-window-configuration Info-window-configuration)
2614 (Info-reannotate-node))
2616 (defun Info-bookmark (arg tag)
2617 (interactive "p\nsBookmark name: ")
2619 (if (or (string-match "^\"\\(.*\\)\"$" tag)
2620 (string-match #r"^<<\(.*\)>>$" tag))
2621 (setq tag (substring tag (match-beginning 1) (match-end 1))))
2623 (search-forward "\n------\n")
2624 (let ((end (- (point) 8)))
2626 (if (re-search-forward "<<[^>\n]*>>" nil t)
2627 (delete-region (match-beginning 0) (match-end 0))
2630 (insert "<<" tag ">>"))))
2631 (Info-cease-annotate))
2634 "Exit Info by selecting some other buffer."
2637 (save-buffers-kill-emacs)
2638 (bury-buffer (current-buffer))
2639 (if (and (featurep 'toolbar)
2640 (boundp 'toolbar-info-frame)
2641 (eq toolbar-info-frame (selected-frame)))
2643 (delete-frame toolbar-info-frame)
2644 (error (bury-buffer)))
2645 (switch-to-buffer (other-buffer (current-buffer))))))
2647 (defun Info-undefined ()
2648 "Make command be undefined in Info."
2653 "Enter the Info tutorial."
2655 (delete-other-windows)
2656 (Info-find-node "info"
2657 (if (< (window-height) 23)
2661 (defun Info-summary ()
2662 "Display a brief summary of all Info commands."
2664 (save-window-excursion
2665 (switch-to-buffer "*Help*")
2667 (insert (documentation 'Info-mode))
2668 (goto-char (point-min))
2670 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2671 (message (if flag "Type Space to see more"
2672 "Type Space to return to Info"))
2673 (let ((e (next-command-event)))
2674 (if (/= ?\ (event-to-character e))
2675 (progn (setq unread-command-event e) nil)
2679 (bury-buffer "*Help*")))
2681 (defun Info-get-token (pos start all &optional errorstring)
2682 "Return the token around POS,
2683 POS must be somewhere inside the token
2684 START is a regular expression which will match the
2685 beginning of the tokens delimited string
2686 ALL is a regular expression with a single
2687 parenthized subpattern which is the token to be
2688 returned. E.g. '{\(.*\)}' would return any string
2689 enclosed in braces around POS.
2690 SIG optional fourth argument, controls action on no match
2693 a string: signal an error, using that string."
2695 (goto-char (point-min))
2696 (re-search-backward "\\`") ; Bug fix due to Nicholas J. Foskett.
2698 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
2700 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2701 (not (setq found (and (<= (match-beginning 0) pos)
2702 (> (match-end 0) pos))))))
2703 (if (and found (<= (match-beginning 0) pos)
2704 (> (match-end 0) pos))
2705 (buffer-substring (match-beginning 1) (match-end 1))
2706 (cond ((null errorstring)
2712 (error "No %s around position %d" errorstring pos)))))))
2714 (defun Info-follow-clicked-node (event)
2715 "Follow a node reference near clicked point. Like M, F, N, P or U command.
2716 At end of the node's text, moves to the next node."
2718 (or (and (event-point event)
2719 (Info-follow-nearest-node
2721 (select-window (event-window event))
2722 (event-point event))
2724 (error "click on a cross-reference to follow")))
2726 (defun Info-maybe-follow-clicked-node (event &optional click-count)
2727 "Follow a node reference (if any) near clicked point.
2728 Like M, F, N, P or U command. At end of the node's text, moves to the
2729 next node. No error is given if there is no node to follow."
2731 (and Info-button1-follows-hyperlink
2733 (Info-follow-nearest-node
2735 (select-window (event-window event))
2736 (event-point event))
2737 (1+ (point-min))))))
2739 (defun Info-find-nearest-node (point)
2742 ((= point (point-min)) nil) ; don't trigger on accidental RET.
2743 ((setq node (Info-get-token point
2744 (format "\\*%s[ \n]" Info-footnote-tag)
2745 (format "\\*%s[ \n]\\([^:]*\\):"
2746 Info-footnote-tag)))
2747 (list "Following cross-reference %s..."
2748 (list 'Info-follow-reference node)))
2749 ((setq node (Info-get-token point "\\* " #r"\* \([^:]*\)::"))
2750 (list "Selecting menu item %s..."
2751 (list 'Info-goto-node node nil t)))
2752 ((setq node (Info-get-token point "\\* " #r"\* \([^:]*\):"))
2753 (list "Selecting menu item %s..."
2754 (list 'Info-menu node)))
2755 ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
2757 (list 'Info-goto-node node)))
2758 ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
2759 (list "Next node..."
2760 (list 'Info-goto-node node)))
2761 ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
2763 (list 'Info-goto-node "Top")))
2764 ((setq node (Info-get-token point "Prev[ious]*: "
2765 "Prev[ious]*: \\([^,\n\t]*\\)"))
2766 (list "Previous node..."
2767 (list 'Info-goto-node node)))
2768 ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
2769 (list "Reselecting %s..."
2770 (list 'Info-goto-node node)))
2771 ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
2772 (if Info-in-cross-reference
2773 (list "Back to last node..."
2775 (list "Next node..."
2776 '(Info-global-next)))))
2779 (defun Info-follow-nearest-node (point)
2780 "Follow a node reference near point. Like M, F, N, P or U command.
2781 At end of the node's text, moves to the next node."
2783 (let ((data (Info-find-nearest-node point)))
2786 (let ((msg (format (car data) (nth 1 (nth 1 data)))))
2789 (message "%sdone" msg))
2792 (defun Info-indicated-node (event)
2795 (cond ((eventp event)
2796 (set-buffer (event-buffer event))
2797 (setq event (event-point event))))
2798 (let* ((data (Info-find-nearest-node event))
2799 (name (nth 1 (nth 1 data))))
2800 (and name (nth 1 data))))
2803 (defun Info-mouse-track-double-click-hook (event click-count)
2804 "Handle double-clicks by turning pages, like the `gv' ghostscript viewer"
2805 (if (/= click-count 2)
2806 ;; Return nil so any other hooks are performed.
2808 (let* ((fw (face-width 'default))
2809 (fh (face-height 'default))
2810 (x (/ (event-x-pixel event) fw))
2811 (y (/ (event-y-pixel event) fw))
2812 (w (/ (window-pixel-width (event-window event)) fw))
2813 (h (/ (window-pixel-height (event-window event)) fh))
2817 ((<= y by) (Info-up) t)
2818 ((>= y (- h by)) (Info-nth-menu-item 1) t)
2819 ((<= x bx) (Info-prev) t)
2820 ((>= x (- w bx)) (Info-next) t)
2823 (defvar Info-mode-map nil
2824 "Keymap containing Info commands.")
2828 (setq Info-mode-map (make-sparse-keymap))
2829 (suppress-keymap Info-mode-map)
2830 (define-key Info-mode-map "." 'beginning-of-buffer)
2831 (define-key Info-mode-map " " 'Info-scroll-next)
2832 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2833 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2834 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2835 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2836 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2837 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2838 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2839 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2840 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2841 (define-key Info-mode-map "0" 'Info-last-menu-item)
2842 (define-key Info-mode-map "?" 'Info-summary)
2843 (define-key Info-mode-map "a" 'Info-annotate)
2844 (define-key Info-mode-map "b" 'beginning-of-buffer)
2845 (define-key Info-mode-map "d" 'Info-directory)
2846 (define-key Info-mode-map "e" 'Info-edit)
2847 (define-key Info-mode-map "f" 'Info-follow-reference)
2848 (define-key Info-mode-map "g" 'Info-goto-node)
2849 (define-key Info-mode-map "h" 'Info-help)
2850 (define-key Info-mode-map "i" 'Info-index)
2851 (define-key Info-mode-map "j" 'Info-goto-bookmark)
2852 (define-key Info-mode-map "k" 'Info-emacs-key)
2853 (define-key Info-mode-map "l" 'Info-last)
2854 (define-key Info-mode-map "m" 'Info-menu)
2855 (define-key Info-mode-map "n" 'Info-next)
2856 (define-key Info-mode-map "p" 'Info-prev)
2857 (define-key Info-mode-map "q" 'Info-exit)
2858 (define-key Info-mode-map "r" 'Info-follow-reference)
2859 (define-key Info-mode-map "s" 'Info-search)
2860 (define-key Info-mode-map "t" 'Info-top)
2861 (define-key Info-mode-map "u" 'Info-up)
2862 (define-key Info-mode-map "v" 'Info-visit-file)
2863 (define-key Info-mode-map "x" 'Info-bookmark)
2864 (define-key Info-mode-map "<" 'Info-top)
2865 (define-key Info-mode-map ">" 'Info-end)
2866 (define-key Info-mode-map "[" 'Info-global-prev)
2867 (define-key Info-mode-map "]" 'Info-global-next)
2868 (define-key Info-mode-map "{" 'Info-page-prev)
2869 (define-key Info-mode-map "}" 'Info-page-next)
2870 (define-key Info-mode-map "=" 'Info-restore-point)
2871 (define-key Info-mode-map "!" 'Info-select-node)
2872 (define-key Info-mode-map "@" 'Info-follow-nearest-node)
2873 (define-key Info-mode-map "," 'Info-index-next)
2874 (define-key Info-mode-map "*" 'Info-elisp-ref)
2875 (define-key Info-mode-map [tab] 'Info-next-reference)
2876 (define-key Info-mode-map [(meta tab)] 'Info-prev-reference)
2877 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2878 (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
2880 (define-key Info-mode-map 'backspace 'Info-scroll-prev)
2881 (define-key Info-mode-map 'delete 'Info-scroll-prev)
2882 (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
2883 (define-key Info-mode-map 'button3 'Info-select-node-menu))
2886 ;; Info mode is suitable only for specially formatted data.
2887 (put 'info-mode 'mode-class 'special)
2890 "Info mode is for browsing through the Info documentation tree.
2891 Documentation in Info is divided into \"nodes\", each of which
2892 discusses one topic and contains references to other nodes
2893 which discuss related topics. Info has commands to follow
2894 the references and show you other nodes.
2896 h Invoke the Info tutorial.
2897 q Quit Info: return to the previously selected file or buffer.
2899 Selecting other nodes:
2900 n Move to the \"next\" node of this node.
2901 p Move to the \"previous\" node of this node.
2902 m Pick menu item specified by name (or abbreviation).
2903 1-9, 0 Pick first..ninth, last item in node's menu.
2904 Menu items select nodes that are \"subsections\" of this node.
2905 u Move \"up\" from this node (i.e., from a subsection to a section).
2906 f or r Follow a cross reference by name (or abbrev). Type `l' to get back.
2907 RET Follow cross reference or menu item indicated by cursor.
2908 i Look up a topic in this file's Index and move to that node.
2909 , (comma) Move to the next match from a previous `i' command.
2910 l (letter L) Move back to the last node you were in.
2912 Moving within a node:
2913 Space Scroll forward a full screen. DEL Scroll backward.
2914 b Go to beginning of node. Meta-> Go to end of node.
2915 TAB Go to next cross-reference. Meta-TAB Go to previous ref.
2918 Left Button Set point (usual text-mode functionality)
2919 Middle Button Click on a highlighted node reference to go to it.
2920 Right Button Pop up a menu of applicable Info commands.
2922 Left Button Double Click in window edges:
2923 Top edge: Go up to the parent node, like `u'.
2924 Left edge: Go to the previous node, like `p'.
2925 Right edge: Go to the next node, like `n'.
2926 Bottom edge: Follow first menu item, like `1'.
2929 g Move to node, file, or annotation tag specified by name.
2930 Examples: `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
2931 v Move to file, with filename completion.
2932 k Look up a key sequence in Emacs manual (also C-h C-k at any time).
2933 * Look up a function name in Emacs Lisp manual (also C-h C-f).
2934 d Go to the main directory of Info files.
2935 < or t Go to Top (first) node of this file.
2936 > Go to last node in this file.
2937 \[ Go to previous node, treating file as one linear document.
2938 \] Go to next node, treating file as one linear document.
2939 { Scroll backward, or go to previous node if at top.
2940 } Scroll forward, or go to next node if at bottom.
2941 = Restore cursor position from last time in this node.
2942 a Add a private note (annotation) to the current node.
2943 x, j Add, jump to a bookmark (annotation tag).
2944 s Search this Info file for a node containing the specified regexp.
2945 e Edit the contents of the current node."
2946 (kill-all-local-variables)
2947 (setq major-mode 'Info-mode)
2948 (setq mode-name "Info")
2949 (use-local-map Info-mode-map)
2950 (set-syntax-table text-mode-syntax-table)
2951 (setq local-abbrev-table text-mode-abbrev-table)
2952 (setq case-fold-search t)
2953 (setq buffer-read-only t)
2954 ; (setq buffer-mouse-map Info-mode-mouse-map)
2955 (make-local-variable 'Info-current-file)
2956 (make-local-variable 'Info-current-subfile)
2957 (make-local-variable 'Info-current-node)
2958 (make-local-variable 'Info-tag-table-marker)
2959 (setq Info-tag-table-marker (make-marker))
2960 (make-local-variable 'Info-tag-table-buffer)
2961 (setq Info-tag-table-buffer nil)
2962 (make-local-variable 'Info-current-file-completions)
2963 (make-local-variable 'Info-current-annotation-completions)
2964 (make-local-variable 'Info-index-alternatives)
2965 (make-local-variable 'Info-history)
2966 ;; Faces are now defined by `defface'...
2967 (make-local-variable 'mouse-track-click-hook)
2968 (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
2969 (add-hook 'mouse-track-click-hook 'Info-mouse-track-double-click-hook)
2970 ;; #### The console-on-window-system-p check is to allow this to
2971 ;; work on tty's. The real problem here is that featurep really
2972 ;; needs to have some device/console domain knowledge added to it.
2973 (defvar info::toolbar)
2974 (if (and (featurep 'toolbar)
2975 (console-on-window-system-p)
2976 (not Info-inhibit-toolbar))
2977 (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
2978 (if (featurep 'menubar)
2980 ;; make a local copy of the menubar, so our modes don't
2981 ;; change the global menubar
2982 (easy-menu-add '("Info" :filter Info-menu-filter))))
2983 (run-hooks 'Info-mode-hook)
2984 (Info-set-mode-line))
2986 (defvar Info-edit-map nil
2987 "Local keymap used within `e' command of Info.")
2991 ;; XEmacs: remove FSF stuff
2992 (setq Info-edit-map (make-sparse-keymap))
2993 (set-keymap-name Info-edit-map 'Info-edit-map)
2994 (set-keymap-parents Info-edit-map (list text-mode-map))
2995 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
2997 ;; Info-edit mode is suitable only for specially formatted data.
2998 (put 'info-edit-mode 'mode-class 'special)
3000 (defun Info-edit-mode ()
3001 "Major mode for editing the contents of an Info node.
3002 Like text mode with the addition of `Info-cease-edit'
3003 which returns to Info mode for browsing.
3008 "Edit the contents of this Info node.
3009 Allowed only if variable `Info-enable-edit' is non-nil."
3011 (or Info-enable-edit
3012 (error "Editing info nodes is not enabled"))
3013 (use-local-map Info-edit-map)
3014 (setq major-mode 'Info-edit-mode)
3015 (setq mode-name "Info Edit")
3016 (kill-local-variable 'modeline-buffer-identification)
3017 (setq buffer-read-only nil)
3018 ;; Make mode line update.
3019 (set-buffer-modified-p (buffer-modified-p))
3020 (message (substitute-command-keys
3021 "Editing: Type \\[Info-cease-edit] to return to info")))
3023 (defun Info-cease-edit ()
3024 "Finish editing Info node; switch back to Info proper."
3026 ;; Do this first, so nothing has changed if user C-g's at query.
3027 (and (buffer-modified-p)
3028 (y-or-n-p "Save the file? ")
3030 (use-local-map Info-mode-map)
3031 (setq major-mode 'Info-mode)
3032 (setq mode-name "Info")
3033 (Info-set-mode-line)
3034 (setq buffer-read-only t)
3035 ;; Make mode line update.
3036 (set-buffer-modified-p (buffer-modified-p))
3037 (and (marker-position Info-tag-table-marker)
3039 (message "Tags may have changed. Use Info-tagify if necessary")))
3041 (defun Info-find-emacs-command-nodes (command)
3042 "Return a list of locations documenting COMMAND in the SXEmacs Info manual.
3043 The locations are of the format used in Info-history, i.e.
3044 \(FILENAME NODENAME BUFFERPOS\)."
3046 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
3047 #r":\s *\(.*\)\.")))
3049 (Info-find-node "SXEmacs" "Command Index")
3050 ;; Take the index node off the Info history.
3051 ;; ??? says this isn't safe someplace else... hmmm.
3052 (setq Info-history (cdr Info-history))
3053 (goto-char (point-max))
3054 (while (re-search-backward cmd-desc nil t)
3055 (setq where (cons (list Info-current-file
3063 ;;; fontification and mousability for info
3065 (defun Info-highlight-region (start end face)
3067 (splitp (string-match "\n[ \t]+" (buffer-substring start end))))
3070 (setq extent (make-extent start (progn (goto-char start)
3073 (set-extent-face extent face)
3074 (set-extent-property extent 'info t)
3075 (set-extent-property extent 'highlight t)
3076 (skip-chars-forward "\n\t ")
3077 (setq extent (make-extent (point) end)))
3078 (setq extent (make-extent start end)))
3079 (set-extent-face extent face)
3080 (set-extent-property extent 'info t)
3081 (set-extent-property extent 'highlight t)))
3083 (defun Info-fontify-node ()
3085 (let ((case-fold-search t)
3086 (xref-regexp (concat "\\*"
3087 (regexp-quote Info-footnote-tag)
3088 "[ \n\t]*\\([^:]*\\):")))
3089 ;; Clear the old extents
3090 (map-extents #'(lambda (x y) (delete-extent x))
3091 (current-buffer) (point-min) (point-max) nil)
3092 ;; Break the top line iff it is > 79 characters. Some info nodes
3093 ;; have top lines that span 3 lines because of long node titles.
3094 ;; eg: (Info-find-node "lispref.info" "Window-Level Event Position Info")
3095 (toggle-read-only -1)
3100 (goto-char (point-min))
3101 (re-search-forward "Node: *[^,]+, " nil t)
3102 (setq len (- (point) (point-min))
3103 extent (make-extent (point-min) (point)))
3104 (set-extent-property extent 'invisible t)
3108 (if (< (current-column) (+ 78 len))
3111 (forward-char (+ 79 len))
3112 (re-search-backward "," nil t)
3116 (delete-backward-char 1)
3119 (toggle-read-only 1)
3120 ;; Highlight xrefs in the top few lines of the node
3121 (goto-char (point-min))
3122 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
3124 (goto-char (match-end 0))
3126 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?\n?")
3127 (goto-char (match-end 0))
3128 (Info-highlight-region (match-beginning 1) (match-end 1)
3130 ;; Now get the xrefs in the body
3131 (goto-char (point-min))
3132 (while (re-search-forward xref-regexp nil t)
3133 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
3135 (Info-highlight-region (match-beginning 1) (match-end 1)
3137 ;; then highlight the nodes in the menu.
3138 (goto-char (point-min))
3139 (if (and (search-forward "\n* menu:" nil t))
3140 (while (re-search-forward
3141 "^\\* \\([^:\t\n]*\\):?:[ \t\n]" nil t)
3142 (Info-highlight-region (match-beginning 1) (match-end 1)
3144 (set-buffer-modified-p nil))))
3146 (defun Info-construct-menu (&optional event)
3147 "Construct a menu of Info commands.
3148 Adds an entry for the node at EVENT, or under point if EVENT is omitted.
3149 Used to construct the menubar submenu and popup menu."
3150 (or event (setq event (point)))
3151 (let ((case-fold-search t)
3152 (xref-regexp (concat "\\*"
3153 (regexp-quote Info-footnote-tag)
3154 "[ \n\t]*\\([^:]*\\):"))
3155 up-p prev-p next-p menu xrefs subnodes in)
3157 ;; `one-space' fixes "Notes:" xrefs that are split across lines.
3161 (while (setq i (string-match "[ \n\t]+" text i))
3162 (setq text (concat (substring text 0 i) " "
3163 (substring text (match-end 0))))
3166 (goto-char (point-min))
3167 (if (looking-at ".*\\bNext:") (setq next-p t))
3168 (if (looking-at ".*\\bPrev:") (setq prev-p t))
3169 (if (looking-at ".*Up:") (setq up-p t))
3171 (if (setq in (Info-indicated-node event))
3172 (list (vector (one-space (cadr in)) in t)
3173 "--:shadowEtchedIn"))
3175 ["Goto Info Top-level" Info-directory]
3176 (vector "Next Node" 'Info-next :active next-p)
3177 (vector "Previous Node" 'Info-prev :active prev-p)
3178 (vector "Parent Node (Up)" 'Info-up :active up-p)
3179 ["Goto Node..." Info-goto-node]
3180 ["Goto Last Visited Node " Info-last])))
3181 ;; Find the xrefs and make a list
3182 (while (re-search-forward xref-regexp nil t)
3183 (setq xrefs (cons (one-space (buffer-substring (match-beginning 1)
3186 (setq xrefs (nreverse xrefs))
3187 (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
3188 ;; Find the subnodes and make a list
3189 (goto-char (point-min))
3190 (if (search-forward "\n* menu:" nil t)
3191 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
3192 (setq subnodes (cons (buffer-substring (match-beginning 1)
3195 (setq subnodes (nreverse subnodes))
3196 (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more))))
3198 (nconc menu (list "--:shadowDoubleEtchedIn"
3201 (mapcar #'(lambda (xref)
3205 (list 'Info-follow-reference xref))))
3208 (nconc menu (list "--:shadowDoubleEtchedIn"
3211 (mapcar #'(lambda (node)
3214 (vector node (list 'Info-menu node))))
3218 (defun Info-menu-filter (menu)
3219 "This is the menu filter for the \"Info\" submenu."
3220 (Info-construct-menu))
3222 (defun Info-select-node-menu (event)
3223 "Pops up a menu of applicable Info commands."
3225 (select-window (event-window event))
3226 (let ((menu (Info-construct-menu event)))
3227 (setq menu (nconc (list "Info" ; title: not displayed
3229 "--:shadowDoubleEtchedOut")
3231 (let ((popup-menu-titles nil))
3232 (popup-menu menu))))
3234 ;;; Info toolbar support
3236 ;; exit icon taken from GNUS
3237 (defvar info::toolbar-exit-icon
3238 (if (featurep 'toolbar)
3239 (toolbar-make-button-list
3240 (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
3241 toolbar-icon-directory)))
3244 (defvar info::toolbar-up-icon
3245 (if (featurep 'toolbar)
3246 (toolbar-make-button-list
3247 (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
3248 toolbar-icon-directory)))
3251 (defvar info::toolbar-next-icon
3252 (if (featurep 'toolbar)
3253 (toolbar-make-button-list
3254 (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
3255 toolbar-icon-directory)))
3258 (defvar info::toolbar-prev-icon
3259 (if (featurep 'toolbar)
3260 (toolbar-make-button-list
3261 (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
3262 toolbar-icon-directory)))
3265 (defvar info::toolbar
3266 (if (featurep 'toolbar)
3267 ; disabled until we get the next/prev-win icons working again.
3268 ; (cons (first initial-toolbar-spec)
3269 ; (cons (second initial-toolbar-spec)
3270 '([info::toolbar-exit-icon
3274 [info::toolbar-next-icon
3277 "Next entry in same section"]
3278 [info::toolbar-prev-icon
3281 "Prev entry in same section"]
3282 [info::toolbar-up-icon
3285 "Up entry to enclosing section"]
3291 (run-hooks 'Info-load-hook)
3293 ;;; info.el ends here