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 ;; Presently, the only reason this exists is to keep a few FSF-originated
340 ;; packages happy. We don't use it. --SY
341 (defvar Info-file-list-for-emacs nil)
342 (make-compatible-variable 'Info-file-list-for-emacs
343 "SXEmacs does NOT use this")
345 (defvar Info-history nil
346 "List of info nodes user has visited.
347 Each element of list is a list (\"(FILENAME)NODENAME\" BUFPOS WINSTART).")
349 (defvar Info-keeping-history t
350 "Non-nil if Info-find-node should modify Info-history.
351 This is for use only by certain internal Info routines.")
353 (defvar Info-minibuffer-history nil
354 "Minibuffer history for Info.")
356 (defcustom Info-enable-edit nil
357 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info
358 can edit the current node.
359 This is convenient if you want to write info files by hand.
360 However, we recommend that you not do this.
361 It is better to write a Texinfo file and generate the Info file from that,
362 because that gives you a printed manual as well."
366 (defcustom Info-enable-active-nodes t
367 "*Non-nil allows Info to execute Lisp code associated with nodes.
368 The Lisp code is executed when the node is selected."
372 (defcustom Info-restoring-point t
373 "*Non-nil means to restore the cursor position when re-entering a node."
377 (defcustom Info-auto-advance 'twice
378 "*Control what SPC and DEL do when they can't scroll any further.
379 If nil, they beep and remain in the current node.
380 If t, they move to the next node (like Info-global-next/prev).
381 If anything else, they must be pressed twice to move to the next node."
382 :type '(choice (const :tag "off" nil)
383 (const :tag "advance" t)
384 (const :tag "confirm" twice))
387 (defcustom Info-fontify t
388 "*Non-nil enables font features in XEmacs.
389 This variable is ignored unless running under XEmacs."
393 (defcustom Info-additional-search-directory-list nil
394 "*List of additional directories to search for Info documentation
395 files. These directories are not searched for merging the `dir'
396 file. An example might be something like:
397 \"/usr/local/lib/xemacs/packages/lisp/calc/\""
398 :type '(repeat directory)
401 (defcustom Info-auto-generate-directory 'if-outdated
402 "*When to auto generate an info directory listing.
404 nil or `never' never auto-generate a directory listing,
405 use any existing `dir' or `localdir' file and ignore info
406 directories containing none
407 `always' auto-generate a directory listing ignoring existing
408 `dir' and `localdir' files
409 `if-missing', the default, auto-generates a directory listing
410 if no `dir' or `localdir' file is present. Otherwise the
411 contents of any of these files is used instead.
412 `if-outdated' auto-generates a directory listing if the `dir'
413 and `localdir' are either inexistent or outdated (touched
414 less recently than an info file in the same directory)."
415 :type '(choice (const :tag "never" never)
416 (const :tag "always" always)
417 (const :tag "if-missing" if-missing)
418 (const :tag "if-outdated" if-outdated))
421 (defcustom Info-save-auto-generated-dir 'never
422 "*Whether an auto-generated info directory listing should be saved.
424 nil or `never', the default, auto-generated info directory
425 information will never be saved.
426 `always', auto-generated info directory information will be saved to
427 a `dir' file in the same directory overwriting it if it exists
428 `conservative', auto-generated info directory information will be saved
429 to a `dir' file in the same directory but the user is asked before
430 overwriting any existing file."
431 :type '(choice (const :tag "never" never)
432 (const :tag "always" always)
433 (const :tag "conservative" conservative))
436 (defconst Info-emacs-info-file-name "sxemacs.info"
437 "The filename of the SXEmacs info for `Info-goto-emacs-command-node'
438 \(`\\<help-mode-map>\\[Info-goto-emacs-command-node]'\)")
441 (defvar Info-directory-list nil
442 "List of directories to search for Info documentation files.
444 The first directory in this list, the \"dir\" file there will become
445 the (dir)Top node of the Info documentation tree.
447 Note: DO NOT use the `customize' interface to change the value of this
448 variable. Its value is created dynamically on each startup, depending
449 on XEmacs packages installed on the system. If you want to change the
450 search path, make the needed modifications on the variable's value
451 from .emacs. For instance:
453 (setq Info-directory-list (cons \"~/info\" Info-directory-list))")
455 ;; This could as well be hard-coded since ${srcdir}/info/dir is in CVS --dv
456 (defconst Info-localdir-heading-regexp "^Local Packages:$"
457 "The menu part of localdir files will be inserted below this topic
460 (defface info-node '((t (:bold t :italic t)))
461 "Face used for node links in info."
464 (defface info-xref '((t (:bold t)))
465 "Face used for cross-references in info."
468 ;; This list is based on Karl Berry-s advice about extensions `info' itself
469 ;; might encounter. --dv
470 (defcustom Info-suffix-list '(("" . nil)
472 (".gz" . "gzip -dc %s")
473 (".info.gz" . "gzip -dc %s")
474 (".z" . "gzip -dc %s")
475 (".info.z" . "gzip -dc %s")
476 (".bz2" . "bzip2 -dc %s")
477 (".info.bz2" . "bzip2 -dc %s")
478 (".Z" . "uncompress -c %s")
479 (".info.Z" . "uncompress -c %s")
480 (".zip" . "unzip -c %s")
481 (".info.zip" . "unzip -c %s")
482 (".y" . "cat %s | unyabba")
483 ("info.y" . "cat %s | unyabba")
484 ;; These ones are for MS-DOS filenames.
486 (".igz" . "gzip -dc %s")
487 (".inz" . "gzip -c %s"))
488 "*List of file name suffixes and associated decoding commands.
489 Each entry should be (SUFFIX . STRING); if STRING contains %s, that is
490 changed to name of the file to decode, otherwise the file is given to
491 the command as standard input. If STRING is nil, no decoding is done."
492 :type '(repeat (cons (string :tag "suffix")
493 (choice :tag "command"
494 (const :tag "none" :value nil)
498 (defcustom Info-footnote-tag "Note"
499 "*Symbol that identifies a footnote or cross-reference.
500 All \"*Note\" references will be changed to use this word instead."
504 (defvar Info-current-file nil
505 "Info file that Info is now looking at, or nil.
506 This is the name that was specified in Info, not the actual file name.
507 It doesn't contain directory names or file name extensions added by Info.")
509 (defvar Info-current-subfile nil
510 "Info subfile that is actually in the *info* buffer now,
511 or nil if current info file is not split into subfiles.")
513 (defvar Info-current-node nil
514 "Name of node that Info is now looking at, or nil.")
516 (defvar Info-tag-table-marker nil
517 "Marker pointing at beginning of current Info file's tag table.
518 Marker points nowhere if file has no tag table.")
520 (defvar Info-tag-table-buffer nil)
522 (defvar Info-current-file-completions nil
523 "Cached completion list for current Info file.")
525 (defvar Info-current-annotation-completions nil
526 "Cached completion list for current annotation files.")
528 (defvar Info-index-alternatives nil
529 "List of possible matches for last Info-index command.")
531 (defvar Info-index-first-alternative nil)
533 (defcustom Info-annotations-path
535 (paths-construct-path (list user-init-directory "info.notes"))
536 (paths-construct-path '("~" ".infonotes"))
537 (paths-construct-path '("usr" "lib" "info.notes")
538 (char-to-string directory-sep-char)))
539 "*Names of files that contain annotations for different Info nodes.
540 By convention, the first one should reside in your personal directory.
541 The last should be a world-writable \"public\" annotations file."
545 (defcustom Info-button1-follows-hyperlink nil
546 "*Non-nil means mouse button1 click will follow hyperlink."
550 (defvar Info-standalone nil
551 "Non-nil if Emacs was started solely as an Info browser.")
553 (defvar Info-in-cross-reference nil)
554 (defvar Info-window-configuration nil)
556 (defvar Info-dir-prologue "-*- Text -*-
557 This is the file .../info/dir, which contains the topmost node of the
558 Info hierarchy. The first time you invoke Info you start off
559 looking at that node, which is (dir)Top.
561 File: dir Node: Top This is the top of the INFO tree
562 This (the Directory node) gives a menu of major topics.
564 * Menu: The list of major topics begins on the next line.
568 (defcustom Info-no-description-string "[No description available]"
569 "*Description string for info files that have none"
574 (defun info (&optional file)
575 "Enter Info, the documentation browser.
576 Optional argument FILE specifies the file to examine;
577 the default is the top-level directory of Info.
579 In interactive use, a prefix argument directs this command
580 to read a file name from the minibuffer."
581 (interactive (if current-prefix-arg
582 (list (read-file-name "Info file name: " nil nil t))))
583 (let ((p command-line-args))
585 (and (string-match "^-[fe]" (car p))
586 (equal (nth 1 p) "info")
587 (not Info-standalone)
588 (setq Info-standalone t)
590 (not (string-match "^-" (nth 2 p)))
591 (setq file (nth 2 p))
592 (setq command-line-args-left nil))
594 ; (Info-setup-x) ??? What was this going to be? Can anyone tell karlheg?
597 (Info-goto-node (concat "(" file ")"))
598 (and Info-standalone (info)))
599 (if (get-buffer "*info*")
600 (switch-to-buffer "*info*")
604 (defun Info-query (file)
605 "Enter Info, the documentation browser. Prompt for name of Info file."
606 (interactive "sInfo topic (default = menu): ")
609 (Info-goto-node "(dir)")
610 (Info-goto-node (concat "(" file ")"))))
612 (defun Info-setup-initial ()
613 (let ((f Info-annotations-path))
615 (if (and (file-exists-p (car f)) (not (get-file-buffer (car f))))
616 (bury-buffer (find-file-noselect (car f))))
620 (defun Info-find-node (filename &optional nodename no-going-back tryfile line)
621 "Go to an info node specified as separate FILENAME and NODENAME.
622 Look for a plausible filename, or if not found then look for URL's and
623 dispatch to the appropriate fn. NO-GOING-BACK is non-nil if
624 recovering from an error in this function; it says do not attempt
625 further (recursive) error recovery. TRYFILE is ??"
630 ;; empty filename is simple case
632 (Info-find-file-node nil nodename no-going-back tryfile line))
633 ;; Convert filename to lower case if not found as specified.
634 ;; Expand it, look harder...
635 ((let ((fname (substitute-in-file-name filename))
638 ;; If specified name starts with `./', then just try
639 ;; current directory. No point in searching for an absolute
641 ((string-match "^\\./" fname)
642 (list default-directory))
643 ((file-name-absolute-p fname)
645 (Info-additional-search-directory-list
646 (append Info-directory-list
647 Info-additional-search-directory-list))
648 (t Info-directory-list))))
649 ;; Search the directory list for file FNAME.
650 (while (and dirs (not found))
651 (setq temp (expand-file-name fname (car dirs)))
652 (setq found (Info-suffixed-file temp))
653 (setq dirs (cdr dirs)))
655 (progn (setq filename (expand-file-name found))
657 (Info-find-file-node filename nodename no-going-back tryfile line))
658 ;; Look for a URL. This pattern is stolen from w3.el to prevent
659 ;; loading it if we won't need it.
660 ((string-match (concat #r"^\(wais\|solo\|x-exec\|newspost\|www\|"
661 #r"mailto\|news\|tn3270\|ftp\|http\|file\|"
662 #r"telnet\|gopher\):")
664 (if-fboundp 'browse-url
665 (browse-url filename)
666 (error "Cannot follow URLs in this SXEmacs")))
668 (error "Info file %s does not exist" filename))))
670 (defun Info-find-file-node (filename nodename
671 &optional no-going-back tryfile line)
672 ;; This is the guts of what was Info-find-node. Whoever wrote this
673 ;; should be locked up where they can't do any more harm.
675 ;; Go into info buffer.
676 (or (eq major-mode 'Info-mode)
677 (switch-to-buffer "*info*"))
678 (buffer-disable-undo (current-buffer))
679 (run-hooks 'Info-startup-hook)
680 (or (eq major-mode 'Info-mode)
683 (equal Info-current-file filename)
685 (string= "dir" (file-name-nondirectory Info-current-file))
687 (format "Leave Info file `%s'? "
688 (file-name-nondirectory Info-current-file)))
691 ;; Record the node we are leaving.
692 (if (and Info-current-file (not no-going-back))
693 (Info-history-add Info-current-file Info-current-node (point)))
695 (setq Info-current-node nil
696 Info-in-cross-reference nil)
699 ;; Switch files if necessary
701 (equal Info-current-file filename)
702 (let ((buffer-read-only nil))
703 (setq Info-current-file nil
704 Info-current-subfile nil
705 Info-current-file-completions nil
706 Info-index-alternatives nil
708 buffer-file-truename nil)
710 (if (string= "dir" (file-name-nondirectory filename))
712 (Info-insert-file-contents filename t)
713 (setq default-directory (file-name-directory filename)))
714 (set-buffer-modified-p nil)
715 ;; See whether file has a tag table. Record the location if yes.
716 (set-marker Info-tag-table-marker nil)
717 (goto-char (point-max))
719 (or (equal nodename "*")
720 (not (search-forward "\^_\nEnd tag table\n" nil t))
722 ;; We have a tag table. Find its beginning.
723 ;; Is this an indirect file?
724 (search-backward "\nTag table:\n")
728 (looking-at "(Indirect)\n"))
729 ;; It is indirect. Copy it to another buffer
730 ;; and record that the tag table is in that buffer.
731 (let ((buf (current-buffer))
732 (m Info-tag-table-marker))
734 Info-tag-table-buffer
736 Info-tag-table-buffer
737 (generate-new-buffer " *info tag table*")))
739 (set-buffer Info-tag-table-buffer)
740 (buffer-disable-undo (current-buffer))
741 (setq case-fold-search t)
743 (insert-buffer-substring buf)
744 (set-marker m (match-end 0))))
745 (set-marker Info-tag-table-marker pos))))
746 (setq Info-current-file
747 (file-name-sans-versions buffer-file-name))))
748 (if (equal nodename "*")
749 (progn (setq Info-current-node nodename)
751 (goto-char (point-min)))
752 ;; Search file for a suitable node.
753 (let* ((qnode (regexp-quote nodename))
754 (regexp (concat "Node: *" qnode " *[,\t\n\177]"))
755 (guesspos (point-min))
757 ;; First get advice from tag table if file has one.
758 ;; Also, if this is an indirect info file,
759 ;; read the proper subfile into this buffer.
760 (if (marker-position Info-tag-table-marker)
761 (let (foun found-mode (m Info-tag-table-marker))
763 (set-buffer (marker-buffer Info-tag-table-marker))
765 (setq foun (re-search-forward regexp nil t))
767 (setq guesspos (read (current-buffer))))
768 (setq found-mode major-mode))
770 ;; If this is an indirect file,
771 ;; determine which file really holds this node
773 (if (not (eq major-mode found-mode))
775 (Info-read-subfile guesspos))))))
776 (goto-char (max (point-min) (- guesspos 1000)))
777 ;; Now search from our advised position (or from beg of buffer)
778 ;; to find the actual node.
780 (while (search-forward "\n\^_" nil t)
784 (if (re-search-backward regexp beg t)
787 (let ((bufs (delq nil (mapcar 'get-file-buffer
788 Info-annotations-path)))
789 (pattern (if (string-match #r"\`<<.*>>\'" qnode) qnode
790 (format "\"%s\"\\|<<%s>>" qnode qnode)))
791 (pat2 (concat #r"------ *File: *\([^ ].*[^ ]\) *Node: "
792 #r"*\([^ ].*[^ ]\) *Line: *\([0-9]+\)"))
793 (afile nil) anode aline)
794 (while (and bufs (not anode))
796 (set-buffer (car bufs))
797 (goto-char (point-min))
798 (if (re-search-forward pattern nil t)
799 (if (re-search-backward pat2 nil t)
800 (setq afile (buffer-substring (match-beginning 1)
802 anode (buffer-substring (match-beginning 2)
805 (buffer-substring (match-beginning 3)
807 (setq bufs (cdr bufs)))
809 (Info-find-node afile anode t nil aline)
812 (Info-find-node nodename "Top" t)
814 (or Info-current-node
815 (error "No such node: %s" nodename)))
819 (goto-char (point-min))
820 (if line (forward-line line)))))))
821 ;; If we did not finish finding the specified node,
822 ;; go back to the previous one.
823 (or Info-current-node no-going-back
824 (let ((hist (car Info-history)))
825 ;; The following is no longer safe with new Info-history system
826 ;; (setq Info-history (cdr Info-history))
827 (Info-goto-node (car hist) t)
828 (goto-char (+ (point-min) (nth 1 hist)))))))
830 ;; Cache the contents of the (virtual) dir file, once we have merged
831 ;; it for the first time, so we can save time subsequently.
832 (defvar Info-dir-contents nil)
834 ;; Cache for the directory we decided to use for the default-directory
835 ;; of the merged dir text.
836 (defvar Info-dir-contents-directory nil)
838 ;; Record the file attributes of all the files from which we
839 ;; constructed Info-dir-contents.
840 (defvar Info-dir-file-attributes nil)
842 (defun Info-insert-dir ()
843 "Construct the Info directory node by merging the files named
844 \"dir\" or \"localdir\" from the directories in `Info-directory-list'.
845 The \"dir\" files will take precedence in cases where both exist. It
846 sets the *info* buffer's `default-directory' to the first directory we
847 actually get any text from."
848 (if (and Info-dir-contents Info-dir-file-attributes
849 ;; Verify that none of the files we used has changed
852 (mapcar #'(lambda (elt)
853 (let ((curr (file-attributes (car elt))))
854 ;; Don't compare the access time.
855 (if curr (setcar (nthcdr 4 curr) 0))
856 (setcar (nthcdr 4 (cdr elt)) 0)
857 (equal (cdr elt) curr)))
858 Info-dir-file-attributes))))
859 (insert Info-dir-contents)
860 (let ((dirs (reverse Info-directory-list))
861 buffers lbuffers buffer others nodes dirs-done)
863 (setq Info-dir-file-attributes nil)
865 ;; Search the directory list for the directory file.
867 (let ((truename (file-truename (expand-file-name (car dirs)))))
868 (or (member truename dirs-done)
869 (member (directory-file-name truename) dirs-done)
870 ;; Karl Berry recently added the ability all possibilities for
871 ;; extension as for normal info files. This code however is
872 ;; still unsatisfactory: if one day, we find a compressed dir
873 ;; file (which looks possible), we should be able to handle it
874 ;; (which means decompress and read it, update it, save and
875 ;; recompress it). --dv
876 (let ((trials '("dir" "DIR"
877 "dir.info" "DIR.INFO"
879 "localdir" "LOCALDIR"
880 "localdir.info" "LOCALDIR.INFO"
881 "localdir.inf" "LOCALDIR.INF"))
884 (while (setq file (pop trials))
885 (setq file (expand-file-name file truename))
886 (and (setq attrs (file-attributes file))
889 (setq file (expand-file-name "dir" truename)))
892 (cons (directory-file-name truename)
894 (Info-maybe-update-dir file)
895 (setq attrs (file-attributes file))
896 (if (or (setq buf (find-buffer-visiting file))
900 (message "Composing main Info directory..."))
903 (if (string-match "localdir" file)
907 (insert-file-contents file))
908 (if (string-match "localdir" (buffer-name))
909 (setq lbuffers (cons (current-buffer) lbuffers))
910 (setq buffers (cons (current-buffer) buffers)))
912 (setq Info-dir-file-attributes
913 (cons (cons file attrs)
914 Info-dir-file-attributes)))))))
915 (or (cdr dirs) (setq Info-dir-contents-directory (car dirs)))
916 (setq dirs (cdr dirs))))
918 ;; ensure that the localdir files are inserted last, and reverse
919 ;; the list of them so that when they get pushed in, they appear
920 ;; in the same order they got specified in the path, from top to
922 (nconc buffers (reverse lbuffers))
925 (error "Can't find the Info directory node"))
926 ;; Distinguish the dir file that comes with Emacs from all the
927 ;; others. Yes, that is really what this is supposed to do.
928 ;; If it doesn't work, fix it.
929 (setq buffer (car buffers)
930 ;; reverse it since they are pushed down from the top. the
931 ;; `Info-directory-list can be specified in natural order
933 others (reverse (cdr buffers)))
935 ;; Insert the entire original dir file as a start; note that we've
936 ;; already saved its default directory to use as the default
937 ;; directory for the whole concatenation.
938 (insert-buffer buffer)
940 ;; Look at each of the other buffers one by one.
942 (let ((other (car others))
943 (info-buffer (current-buffer)))
944 (if (string-match "localdir" (buffer-name other))
946 (set-buffer info-buffer)
947 (goto-char (point-max))
949 ((re-search-backward "^ *\\* *Locals *: *$" nil t)
950 (delete-region (match-beginning 0) (match-end 0)))
951 ;; look for a line like |Local XEmacs packages:
952 ;; or mismatch on some text ...
953 ((re-search-backward Info-localdir-heading-regexp nil t)
954 ;; This is for people who underline topic headings with
955 ;; equal signs or dashes.
956 (when (save-excursion
959 (looking-at "^[ \t]*[-=*]+"))
963 (t (search-backward "\^L" nil t)))
964 ;; Insert menu part of the file
966 (len (length (buffer-string nil nil other))))
967 (insert (buffer-string nil nil other))
968 (goto-char (+ pt len))
971 (if (search-forward "* Menu:" (+ pt len) t)
974 (delete-region pt (point)))))))
975 ;; In each, find all the menus.
978 (goto-char (point-min))
979 ;; Find each menu, and add an elt to NODES for it.
980 (while (re-search-forward "^\\* Menu:" nil t)
981 (let (beg nodename end)
984 (search-backward "\n\^_")
985 (search-forward "Node: ")
986 (setq nodename (Info-following-node-name))
987 (search-forward "\n\^_" nil 'move)
990 (setq nodes (cons (list nodename other beg end) nodes))))))
991 (setq others (cdr others))))
993 ;; Add to the main menu a menu item for each other node.
994 (re-search-forward "^\\* Menu:" nil t)
996 (let ((menu-items '("top"))
999 (end (save-excursion (search-forward "\^_" nil t) (point))))
1001 (let ((nodename (car (car nodes))))
1003 (or (member (downcase nodename) menu-items)
1004 (re-search-forward (concat "^\\* "
1005 (regexp-quote nodename)
1009 (insert "* " nodename "::" "\n")
1010 (setq menu-items (cons nodename menu-items))))))
1011 (setq nodes (cdr nodes))))
1012 ;; Now take each node of each of the other buffers
1013 ;; and merge it into the main buffer.
1015 (let ((nodename (car (car nodes))))
1016 (goto-char (point-min))
1017 ;; Find the like-named node in the main buffer.
1018 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
1019 (regexp-quote nodename)
1023 (search-forward "\n\^_" nil 'move)
1026 ;; If none exists, add one.
1027 (goto-char (point-max))
1028 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
1029 ;; Merge the text from the other buffer's menu
1030 ;; into the menu in the like-named node in the main buffer.
1031 (apply 'insert-buffer-substring (cdr (car nodes))))
1032 (setq nodes (cdr nodes)))
1033 ;; Kill all the buffers we just made.
1035 (kill-buffer (car buffers))
1036 (setq buffers (cdr buffers)))
1038 (kill-buffer (car lbuffers))
1039 (setq lbuffers (cdr lbuffers)))
1040 (message "Composing main Info directory...done"))
1041 (setq Info-dir-contents (buffer-string)))
1042 (setq default-directory (file-name-as-directory Info-dir-contents-directory))
1043 (setq buffer-file-name (caar Info-dir-file-attributes)
1044 buffer-file-truename (file-truename buffer-file-name)))
1046 (defmacro Info-directory-files (dir-file &optional all full nosort files-only)
1047 "Return a list of Info files living in the same directory as DIR-FILE.
1048 This list actually contains the files living in this directory, except for
1049 the dir file itself and the secondary info files (foo-1 foo-2 etc).
1051 If the optional argument ALL is non nil, the secondary info files are also
1052 included in the list.
1054 Please refer to the function `directory-files' for the meaning of the other
1055 optional arguments."
1056 `(let* ((dir (file-name-directory ,dir-file))
1057 (all-files (remove ,dir-file (directory-files dir ',full nil ',nosort
1061 (remove (concat dir ".")
1062 (remove (concat dir "..") all-files))
1064 (remove ".." all-files))))
1068 (concat "-[0-9]+\\("
1069 ;; Extract all known compression suffixes from
1070 ;; Info-suffix-list. These suffixes can typically be
1071 ;; found in entries of the form `.info.something'.
1072 (let ((suff-list Info-suffix-list)
1074 (while (setq suff (pop suff-list))
1075 (and (string-match "^\\.info" (car suff))
1076 (setq regexp (concat regexp
1080 (and suff-list "\\|")))))
1084 (while (setq file (pop all-files))
1085 (or (string-match suff-match file)
1086 (push file info-files)))
1087 (reverse info-files)
1091 (defun Info-maybe-update-dir (file)
1092 "Rebuild dir or localdir according to `Info-auto-generate-directory'."
1093 (unless (or (not (file-exists-p (file-name-directory file)))
1094 (null (Info-directory-files file 'all)))
1095 (if (not (find-buffer-visiting file))
1096 (if (not (file-exists-p file))
1097 (if (or (memq Info-auto-generate-directory
1098 '(always if-missing if-outdated)))
1099 (Info-build-dir-anew (file-name-directory file)))
1100 (if (or (eq Info-auto-generate-directory 'always)
1101 (and (eq Info-auto-generate-directory 'if-outdated)
1102 (Info-dir-outdated-p file)))
1103 (Info-rebuild-dir file))))))
1105 ;; Record which *.info files are newer than the dir file
1106 (defvar Info-dir-newer-info-files nil)
1108 (defun Info-dir-outdated-p (file)
1109 "Return non-nil if dir or localdir is outdated.
1110 dir or localdir are outdated when an info file in the same
1111 directory has been modified more recently."
1112 (let ((dir-mod-time (nth 5 (file-attributes file)))
1114 (setq Info-dir-newer-info-files nil)
1118 (setq f-mod-time (nth 5 (file-attributes f)))
1119 (setq newer (or (> (car f-mod-time) (car dir-mod-time))
1120 (and (= (car f-mod-time) (car dir-mod-time))
1121 (> (car (cdr f-mod-time))
1122 (car (cdr dir-mod-time))))))
1123 (if (and (file-readable-p f) newer)
1124 (setq Info-dir-newer-info-files
1125 (cons f Info-dir-newer-info-files)))))
1126 (Info-directory-files file nil 'fullname 'nosort t))
1127 Info-dir-newer-info-files))
1129 (defun Info-extract-dir-entry-from (file)
1130 "Extract the dir entry from the info FILE.
1131 The dir entry is delimited by the markers `START-INFO-DIR-ENTRY'
1132 and `END-INFO-DIR-ENTRY'."
1134 (set-buffer (get-buffer-create " *Info-tmp*"))
1135 (when (file-readable-p file)
1136 (insert-file-contents file nil nil nil t)
1137 (goto-char (point-min))
1139 (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
1142 (unless (null (re-search-forward "^END-INFO-DIR-ENTRY" nil t))
1143 (goto-char (match-beginning 0))
1144 (car (Info-parse-dir-entries beg (point)))))))))
1146 ;; Parse dir entries contained between START and END into a list of the form
1147 ;; (filename topic node (description-line-1 description-line-2 ...))
1148 (defun Info-parse-dir-entries (start end)
1149 (let (entry entries)
1152 (narrow-to-region start end)
1154 (while (re-search-forward
1155 (concat #r"^\* \([^:]+\):\("
1157 #r"(\([^)]*\))\w*\.\|:\)")
1159 (setq entry (list (match-string 2)
1161 (downcase (or (match-string 3)
1162 (match-string 1)))))
1169 (re-search-forward "[ \t]*" nil t)
1170 (or (and (re-search-forward "^[^ \t]" nil t)
1171 (goto-char (match-beginning 0)))
1173 "[ \t]*\n[ \t]*"))))
1175 (setq entries (cons (nreverse entry) entries)))))
1176 (nreverse entries)))
1178 (defun Info-dump-dir-entries (entries)
1182 (mapcar #'(lambda (e)
1183 (setq e (cdr e)) ; Drop filename
1184 (setq len (length (concat (car e)
1186 (if (> len description-col)
1187 (setq description-col len)))
1189 (setq description-col (+ 5 description-col))
1190 (mapcar #'(lambda (e)
1191 (setq e (cdr e)) ; Drop filename
1192 (insert "* " (car e) ":" (car (cdr e)))
1193 (setq e (car (cdr (cdr e))))
1195 (indent-to-column description-col)
1196 (insert (car e) "\n")
1202 (defun Info-build-dir-anew (directory)
1203 "Build info directory information for DIRECTORY.
1204 The generated directory listing may be saved to a `dir' according
1205 to the value of `Info-save-auto-generated-dir'."
1207 (let* ((dirfile (expand-file-name "dir" directory))
1208 (to-temp (or (null Info-save-auto-generated-dir)
1209 (eq Info-save-auto-generated-dir 'never)
1210 (and (not (file-writable-p dirfile))
1211 (message "File not writable %s. Using temporary."
1213 (info-files (Info-directory-files dirfile nil 'fullname nil t)))
1215 (message "Creating temporary dir in %s..." directory)
1216 (message "Creating %s..." dirfile))
1217 (set-buffer (find-file-noselect dirfile t))
1218 (setq buffer-read-only nil)
1220 (insert Info-dir-prologue "Info files in " directory ":\n\n")
1221 (Info-dump-dir-entries
1224 (or (Info-extract-dir-entry-from f)
1226 (progn (string-match #r"\([^.]*\)\(\..*\)?$"
1227 (file-name-nondirectory f))
1229 (match-string 1 (file-name-nondirectory f))))
1231 (list Info-no-description-string))))
1234 (set-buffer-modified-p nil)
1237 (message "Creating temporary dir in %s...done" directory)
1238 (message "Creating %s...done" dirfile)))))
1241 (defun Info-rebuild-dir (file)
1242 "Build info directory information in the directory of dir FILE.
1243 Description of info files are merged from the info files in the
1244 directory and the contents of FILE with the description in info files
1245 taking precedence over descriptions in FILE.
1246 The generated directory listing may be saved to a `dir' according to
1247 the value of `Info-save-auto-generated-dir'."
1250 (let (dir-section-contents dir-full-contents
1256 (or (null Info-save-auto-generated-dir)
1257 (eq Info-save-auto-generated-dir 'never)
1258 (and (eq Info-save-auto-generated-dir 'always)
1259 (not (file-writable-p file))
1260 (message "File not writable %s. Using temporary." file))
1261 (and (eq Info-save-auto-generated-dir 'conservative)
1262 (or (and (not (file-writable-p file))
1264 "File not writable %s. Using temporary." file))
1266 (message "%s is outdated. Overwrite ? "
1268 (set-buffer (find-file-noselect file t))
1269 (setq buffer-read-only nil)
1271 (message "Rebuilding temporary %s..." file)
1272 (message "Rebuilding %s..." file))
1274 (setq buffer-read-only nil)
1275 (goto-char (point-min))
1276 (unless (and (search-forward "\^_")
1277 (re-search-forward "^\\* Menu:.*$" nil t)
1278 (setq mark (and (re-search-forward "^\\* " nil t)
1279 (match-beginning 0))))
1281 (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1282 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$"
1284 (match-beginning 0))
1287 (narrow-to-region mark next-section)
1288 (setq dir-section-contents (nreverse (Info-parse-dir-entries
1289 (point-min) (point-max))))
1292 (setq dir-entry (assoc (downcase
1293 (file-name-sans-extension
1294 (file-name-nondirectory file)))
1295 dir-section-contents)
1296 file-dir-entry (Info-extract-dir-entry-from file))
1299 ;; A dir entry in the info file takes precedence over
1300 ;; an existing entry in the dir file
1301 (setcdr dir-entry (cdr file-dir-entry)))
1302 (unless (or not-first-section
1304 (file-name-sans-extension
1305 (file-name-nondirectory file)))
1308 (setq dir-section-contents
1309 (cons file-dir-entry dir-section-contents))
1310 (setq dir-section-contents
1312 (capitalize (file-name-sans-extension
1313 (file-name-nondirectory
1316 (list Info-no-description-string))
1317 dir-section-contents))))))
1318 Info-dir-newer-info-files)
1319 (delete-region (point-min) (point-max))
1320 (Info-dump-dir-entries (nreverse dir-section-contents))
1322 (if (= next-section (point-max))
1323 (setq next-section nil)
1324 (or (setq mark (and (re-search-forward "^\\* " nil t)
1325 (match-beginning 0)))
1327 (setq next-section (or (and (re-search-forward
1328 "^[^* \t].*:[ \t]*$" nil t)
1329 (match-beginning 0))
1331 (setq not-first-section t)))
1334 (set-buffer-modified-p nil)
1335 (message "Rebuilding temporary %s...done" file))
1337 (message "Rebuilding %s...done" file))))))
1340 (defun Info-batch-rebuild-dir ()
1341 "(Re)build `dir' files in the directories remaining on the command line.
1342 Use this from the command line, with `-batch', it won't work in an
1345 Each file is processed even if an error occurred previously. For example,
1346 invoke \"sxemacs -batch -f Info-batch-rebuild-dir /usr/local/info\"."
1347 ;; command-line-args-left is what is left of the command line (from
1349 (defvar command-line-args-left) ; Avoid 'free variable' warning
1350 (if (not noninteractive)
1351 (error "`Info-batch-rebuild-dir' is to be used only with -batch"))
1352 (let ((Info-save-auto-generated-dir 'always)
1354 (while command-line-args-left
1355 (if (not (file-directory-p (car command-line-args-left)))
1356 (message "Warning: Skipped %s. Not a directory."
1357 (car command-line-args-left))
1358 (setq dir (expand-file-name "dir" (car command-line-args-left)))
1359 (setq localdir (expand-file-name "localdir"
1360 (car command-line-args-left)))
1362 ((file-exists-p dir)
1363 (Info-rebuild-dir dir))
1364 ((file-exists-p localdir)
1365 (Info-rebuild-dir localdir))
1367 (Info-build-dir-anew (car command-line-args-left)))))
1368 (setq command-line-args-left (cdr command-line-args-left)))
1372 (defun Info-history-add (file node point)
1373 (if Info-keeping-history
1374 (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
1375 (found (assoc name Info-history)))
1377 (setq Info-history (delq found Info-history)))
1378 (setq Info-history (cons (list name (- point (point-min))
1379 (and (eq (window-buffer)
1381 (- (window-start) (point-min))))
1384 (defun Info-file-name-only (file)
1385 (let ((dir (file-name-directory file))
1386 (p Info-directory-list))
1387 (while (and p (not (equal (car p) dir)))
1389 (if p (file-name-nondirectory file) file)))
1391 (defun Info-read-subfile (nodepos)
1395 (set-buffer (marker-buffer Info-tag-table-marker))
1396 (goto-char (point-min))
1397 (search-forward "\n\^_")
1400 (while (not (looking-at "\^_"))
1402 (let ((start (point))
1403 thisfilepos thisfilename)
1404 (search-forward ": ")
1405 (setq thisfilename (buffer-substring start (- (point) 2)))
1406 (setq thisfilepos (read (current-buffer)))
1407 ;; read in version 19 stops at the end of number.
1408 ;; Advance to the next line.
1411 (if (> thisfilepos nodepos)
1413 (setq lastfilename thisfilename)
1414 (setq lastfilepos thisfilepos))
1416 (or (equal Info-current-subfile lastfilename)
1417 (let ((buffer-read-only nil))
1418 (setq buffer-file-name nil
1419 buffer-file-truename nil)
1422 (Info-insert-file-contents (Info-suffixed-file
1423 (expand-file-name lastfilename
1424 (file-name-directory
1428 (set-buffer-modified-p nil)
1429 (setq Info-current-subfile lastfilename)))
1430 (goto-char (point-min))
1431 (search-forward "\n\^_")
1432 (+ (- nodepos lastfilepos) (point))))
1434 (defun Info-all-case-regexp (str)
1440 (setq c (aref str i))
1441 (cond ((or (and (>= c ?A) (<= c ?Z))
1442 (and (>= c ?a) (<= c ?z)))
1443 (setq regexp (concat regexp
1445 (char-to-string (downcase c))
1447 (char-to-string (upcase c))
1450 (setq regexp (concat regexp (char-to-string c)))))
1454 (defun Info-suffixed-file (name &optional exact)
1455 "Look for an info file named NAME. This function tries to be smart in
1456 finding the file corresponding to NAME: if it doesn't exist, several
1457 variants are looked for, notably by appending suffixes from
1458 `Info-suffix-list' and by trying to change the characters case in NAME.
1460 The optional argument EXACT prevents this function from trying different case
1461 versions of NAME. Only the suffixes are tried."
1463 ;; First, try NAME alone:
1464 (and (file-regular-p name) (throw 'found name))
1465 ;; Then, try different variants
1466 (let ((suff-match (concat "\\("
1467 (let ((suff-list Info-suffix-list)
1469 (while (setq suff (pop suff-list))
1472 (regexp-quote (car suff))
1473 (and suff-list "\\|"))))
1476 (dir (file-name-directory name))
1478 (setq name (file-name-nondirectory name))
1480 (condition-case data ;; protect against invalid directory
1481 ;; First, try NAME[.<suffix>]
1483 (directory-files dir 'fullname
1484 (concat "^" (regexp-quote name) suff-match)
1488 ;; Then, try to match the name independantly of the
1490 (directory-files dir 'fullname
1491 (Info-all-case-regexp
1497 (display-warning 'info
1498 (format "directory `%s' error: %s" dir data))
1500 (while (setq file (pop files))
1501 (and (file-regular-p file)
1502 (throw 'found file)))
1505 (defun Info-insert-file-contents (file &optional visit)
1506 (setq file (expand-file-name file default-directory))
1507 (let ((suff Info-suffix-list)
1510 (setq len (length (car (car suff))))
1511 (or (<= (length file) len)
1513 (equal (substring file (- len))
1515 (equal (substring file (- len))
1516 (upcase (car (car suff)))))
1518 (setq suff (cdr suff)))
1519 (if (stringp (cdr (car suff)))
1520 (let ((command (if (string-match "%s" (cdr (car suff)))
1521 (format (cdr (car suff)) file)
1522 (concat (cdr (car suff)) " < " file))))
1523 (message "%s..." command)
1524 (call-process shell-file-name nil t nil shell-command-switch command)
1527 (setq buffer-file-name file
1528 buffer-file-truename (file-truename buffer-file-name))
1529 (set-buffer-modified-p nil)
1530 (clear-visited-file-modtime)))
1531 (insert-file-contents file visit))))
1533 (defun Info-select-node ()
1534 "Select the node that point is in, after using `g *' to select whole file."
1538 ;; Find beginning of node.
1539 (search-backward "\n\^_")
1541 ;; Get nodename spelled as it is in the node.
1542 (re-search-forward "Node:[ \t]*")
1543 (setq Info-current-node
1544 (buffer-substring (point)
1546 (skip-chars-forward "^,\t\n")
1548 (Info-set-mode-line)
1549 ;; Find the end of it, and narrow.
1551 (let (active-expression)
1552 (narrow-to-region (point)
1553 (if (re-search-forward "\n[\^_\f]" nil t)
1556 (if (looking-at "[\n\^_\f]*execute: ")
1558 (goto-char (match-end 0))
1559 (setq active-expression
1560 (read (current-buffer))))))
1562 (or (equal Info-footnote-tag "Note")
1564 (goto-char (point-min))
1565 (let ((buffer-read-only nil)
1566 (bufmod (buffer-modified-p))
1567 (case-fold-search t))
1568 (while (re-search-forward "\\*[Nn]ote\\([ \n]\\)" nil t)
1569 (replace-match (concat "*" Info-footnote-tag "\ ")))
1570 (set-buffer-modified-p bufmod))))
1571 (Info-reannotate-node)
1572 ;; XEmacs: remove v19 test
1574 (Info-fontify-node))
1575 (run-hooks 'Info-select-hook)
1576 (if Info-enable-active-nodes (eval active-expression)))))
1578 (defun Info-set-mode-line ()
1579 (setq modeline-buffer-identification
1580 (list (cons modeline-buffer-id-left-extent "Info: ")
1581 (cons modeline-buffer-id-right-extent
1584 (if Info-current-file
1585 (let ((name (file-name-nondirectory
1586 Info-current-file)))
1587 (if (string-match #r"^\([^.]*\)\..*$" name)
1588 (match-string 1 name)
1592 (or Info-current-node ""))))))
1594 ;; Go to an info node specified with a filename-and-nodename string
1595 ;; of the sort that is found in pointers in nodes.
1598 (defun Info-goto-node (nodename &optional no-going-back tryfile)
1599 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
1600 Actually, the following interpretations of NAME are tried in order:
1602 (FILENAME) (using Top node)
1603 NODENAME (in current file)
1605 FILENAME (using Top node)
1606 where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
1607 annotation for any node of any file. (See `a' and `x' commands.)"
1608 (interactive (list (Info-read-node-name "Goto node, file or tag: ")
1611 (string-match (concat #r"\s *\((\s *\("
1613 #r"\)\s *)\s *\|\)\(.*\)")
1615 (setq filename (if (= (match-beginning 1) (match-end 1))
1617 (substring nodename (match-beginning 2) (match-end 2)))
1618 nodename (substring nodename (match-beginning 3) (match-end 3)))
1619 (let ((trim (string-match #r"\s *\'" filename)))
1620 (if trim (setq filename (substring filename 0 trim))))
1621 (let ((trim (string-match #r"\s *\'" nodename)))
1622 (if trim (setq nodename (substring nodename 0 trim))))
1623 (Info-find-node (if (equal filename "") nil filename)
1624 (if (equal nodename "") "Top" nodename)
1625 no-going-back (and tryfile (equal filename "")))))
1627 (defun Info-goto-bookmark ()
1629 (let ((completion-ignore-case nil)
1630 (tag (completing-read "Goto tag: "
1631 (Info-build-annotation-completions)
1633 'Info-minibuffer-history)))
1634 (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
1637 (defun Info-visit-file (file)
1638 "Directly visit an info file."
1639 (interactive "fVisit Info file: ")
1640 (Info-find-node (expand-file-name file) "Top"))
1642 (defun Info-restore-point (&optional always)
1643 "Restore point to same location it had last time we were in this node."
1645 (if (or Info-restoring-point always)
1646 (let* ((name (format "(%s)%s"
1647 (Info-file-name-only Info-current-file)
1649 (p (assoc name Info-history)))
1650 (if p (Info-restore-history-entry p)))))
1652 (defun Info-restore-history-entry (entry)
1653 (goto-char (+ (nth 1 entry) (point-min)))
1655 (get-buffer-window (current-buffer))
1656 (set-window-start (get-buffer-window (current-buffer))
1657 (+ (nth 2 entry) (point-min)))))
1659 (defvar Info-read-node-completion-table)
1661 ;; This function is used as the "completion table" while reading a node name.
1662 ;; It does completion using the alist in Info-read-node-completion-table
1663 ;; unless STRING starts with an open-paren.
1664 (defun Info-read-node-name-1 (string predicate code)
1665 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
1666 (cond ((eq code nil)
1669 (try-completion string Info-read-node-completion-table
1674 (all-completions string Info-read-node-completion-table
1679 (assoc string Info-read-node-completion-table))))))
1681 (defun Info-read-node-name (prompt &optional default)
1682 (Info-setup-initial)
1683 (let* ((completion-ignore-case t)
1684 (Info-read-node-completion-table (Info-build-node-completions))
1685 (nodename (completing-read prompt 'Info-read-node-name-1
1686 nil t nil 'Info-minibuffer-history
1688 (if (equal nodename "")
1690 (Info-read-node-name prompt))
1693 (defun Info-build-annotation-completions ()
1694 (or Info-current-annotation-completions
1696 (let ((bufs (delq nil (mapcar 'get-file-buffer
1697 Info-annotations-path)))
1700 (set-buffer (car bufs))
1701 (goto-char (point-min))
1702 (while (re-search-forward #r"<<\(.*\)>>" nil t)
1703 (setq compl (cons (list (buffer-substring (match-beginning 1)
1706 (setq bufs (cdr bufs)))
1707 (setq Info-current-annotation-completions compl)))))
1709 (defun Info-build-node-completions ()
1710 (or Info-current-file-completions
1711 (let ((m Info-tag-table-marker)
1712 (compl (Info-build-annotation-completions)))
1716 (if (marker-buffer Info-tag-table-marker)
1718 (set-buffer (marker-buffer Info-tag-table-marker))
1720 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
1722 (cons (list (buffer-substring (match-beginning 1)
1725 (goto-char (point-min))
1726 (while (search-forward "\n\^_" nil t)
1728 (let ((start (point)))
1730 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
1733 (cons (list (buffer-substring (match-beginning 1)
1736 (setq Info-current-file-completions compl))))
1738 (defvar Info-last-search nil
1739 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1743 (defun Info-search (regexp)
1744 "Search for REGEXP, starting from point, and select node it's found in."
1746 (read-from-minibuffer
1747 (if Info-last-search
1748 (format "Search (regexp, default %s): "
1750 "Search (regexp): ")
1751 nil nil nil nil nil Info-last-search)))
1752 (setq Info-last-search regexp)
1753 (with-search-caps-disable-folding regexp t
1755 (onode Info-current-node)
1756 (ofile Info-current-file)
1758 (osubfile Info-current-subfile))
1762 (if (null Info-current-subfile)
1763 (progn (re-search-forward regexp) (setq found (point)))
1765 (progn (re-search-forward regexp) (setq found (point)))
1766 (search-failed nil)))))
1768 ;; can only happen in subfile case -- else would have erred
1772 (set-buffer (marker-buffer Info-tag-table-marker))
1773 (goto-char (point-min))
1774 (search-forward "\n\^_\nIndirect:")
1776 (narrow-to-region (point)
1777 (progn (search-forward "\n\^_")
1779 (goto-char (point-min))
1780 (search-forward (concat "\n" osubfile ": "))
1783 (re-search-forward #r"\(^.*\): [0-9]+$")
1784 (goto-char (+ (match-end 1) 2))
1785 (setq list (cons (cons (read (current-buffer))
1790 (goto-char (1+ (match-end 0))))
1791 (setq list (nreverse list)
1794 (message "Searching subfile %s..." (cdr (car list)))
1795 (Info-read-subfile (car (car list)))
1796 (setq list (cdr list))
1797 (goto-char (point-min))
1798 (if (re-search-forward regexp nil t)
1799 (setq found (point) list ())))
1802 (signal 'search-failed (list regexp))))
1804 (progn (Info-read-subfile opoint)
1806 (Info-select-node)))))
1810 (or (and (equal onode Info-current-node)
1811 (equal ofile Info-current-file))
1812 (Info-history-add ofile onode opoint)))))
1814 ;; Extract the value of the node-pointer named NAME.
1815 ;; If there is none, use ERRORNAME in the error message;
1816 ;; if ERRORNAME is nil, just return nil.
1817 (defun Info-extract-pointer (name &optional errorname)
1819 (goto-char (point-min))
1821 (let ((case-fold-search t))
1822 (if (re-search-backward (concat name ":") nil t)
1824 (goto-char (match-end 0))
1825 (Info-following-node-name))
1826 (if (eq errorname t)
1828 (error (concat "Node has no " (capitalize (or errorname name)))))))))
1830 ;; Return the node name in the buffer following point.
1831 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1832 ;; saying which chars may appear in the node name.
1833 (defun Info-following-node-name (&optional allowedchars)
1834 (skip-chars-forward " \t")
1838 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1839 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1840 (if (looking-at "(")
1841 (skip-chars-forward "^)")))
1842 (skip-chars-backward " .")
1845 (defun Info-next (&optional n)
1846 "Go to the next node of this node.
1847 A positive or negative prefix argument moves by multiple nodes."
1852 (while (>= (setq n (1- n)) 0)
1853 (Info-goto-node (Info-extract-pointer "next")))))
1855 (defun Info-prev (&optional n)
1856 "Go to the previous node of this node.
1857 A positive or negative prefix argument moves by multiple nodes."
1862 (while (>= (setq n (1- n)) 0)
1863 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
1865 (defun Info-up (&optional n)
1866 "Go to the superior node of this node.
1867 A positive prefix argument moves up several times."
1870 (while (>= (setq n (1- n)) 0)
1871 (Info-goto-node (Info-extract-pointer "up")))
1872 (if (interactive-p) (Info-restore-point)))
1874 (defun Info-last (&optional n)
1875 "Go back to the last node visited.
1876 With a prefix argument, go to Nth most recently visited node. History is
1877 circular; after oldest node, history comes back around to most recent one.
1878 Argument can be negative to go through the circle in the other direction.
1879 \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
1883 (error "This is the first Info node you looked at"))
1884 (let ((len (1+ (length Info-history))))
1885 (setq n (% (+ n (* len 100)) len)))
1887 (let ((entry (nth (1- n) Info-history)))
1888 (Info-history-add Info-current-file Info-current-node (point))
1889 (while (>= (setq n (1- n)) 0)
1890 (setq Info-history (nconc (cdr Info-history)
1891 (list (car Info-history)))))
1892 (setq Info-history (cdr Info-history))
1893 (let ((Info-keeping-history nil))
1894 (Info-goto-node (car entry)))
1895 (Info-restore-history-entry entry))))
1897 (defun Info-directory ()
1898 "Go to the Info directory node."
1900 (Info-find-node "dir" "top"))
1902 (defun Info-follow-reference (footnotename)
1903 "Follow cross reference named NAME to the node it refers to.
1904 NAME may be an abbreviation of the reference name."
1906 (let ((completion-ignore-case t)
1907 completions default (start-point (point)) str i)
1909 (goto-char (point-min))
1910 (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
1913 (setq str (buffer-substring
1916 ;; See if this one should be the default.
1918 (< (match-beginning 0) start-point)
1919 (<= start-point (point))
1922 (while (setq i (string-match "[ \n\t]+" str i))
1923 (setq str (concat (substring str 0 i) " "
1924 (substring str (match-end 0))))
1926 ;; Record as a completion and perhaps as default.
1927 (if (eq default t) (setq default str))
1929 (cons (cons str nil)
1932 (let ((item (completing-read (if default
1933 (concat "Follow reference named: ("
1935 "Follow reference named: ")
1936 completions nil t nil
1937 'Info-minibuffer-history
1939 (if (and (string= item "") default)
1942 (error "No cross-references in this node"))))
1943 (let (target i (str (concat "\\*" Info-footnote-tag " "
1944 (regexp-quote footnotename))))
1945 (while (setq i (string-match " " str i))
1946 (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
1947 (substring str (1+ i))))
1950 (goto-char (point-min))
1951 (or (re-search-forward str nil t)
1952 (error "No cross-reference named %s" footnotename))
1953 (goto-char (match-end 1))
1955 (Info-extract-menu-node-name "Bad format cross reference" t)))
1956 (while (setq i (string-match "[ \t\n]+" target i))
1957 (setq target (concat (substring target 0 i) " "
1958 (substring target (match-end 0))))
1960 (Info-goto-node target)
1961 (setq Info-in-cross-reference t)))
1963 (defun Info-next-reference (n)
1965 (let ((pat (format (concat "\\*%s[ \n\t]*"
1966 #r"\([^:]*\):\|^\* .*:\|<<.*>>")
1969 wrapped found-nomenu)
1971 (unless (re-search-backward pat nil t)
1972 ;; Don't wrap more than once in a buffer where only the
1973 ;; menu references are found.
1974 (when (and wrapped (not found-nomenu))
1976 (error "No cross references in this node"))
1978 (goto-char (point-max))
1979 (unless (re-search-backward pat nil t)
1981 (error "No cross references in this node")))
1982 (unless (save-excursion
1983 (goto-char (match-beginning 0))
1984 (when (looking-at "\\* Menu:")
1986 (setq found-nomenu t))
1989 (or (eobp) (forward-char 1))
1990 (unless (re-search-forward pat nil t)
1991 (when (and wrapped (not found-nomenu))
1993 (error "No cross references in this node"))
1995 (goto-char (point-min))
1996 (unless (re-search-forward pat nil t)
1998 (error "No cross references in this node")))
1999 (unless (save-excursion
2000 (goto-char (match-beginning 0))
2001 (when (looking-at "\\* Menu:")
2003 (setq found-nomenu t))
2005 (when (looking-at "\\* Menu:")
2006 (error "No cross references in this node"))
2007 (goto-char (match-beginning 0))))
2009 (defun Info-prev-reference (n)
2011 (Info-next-reference (- n)))
2013 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
2014 (skip-chars-forward " \t\n")
2015 (let ((start (point))
2017 (skip-chars-forward "^:")
2020 (if (looking-at ":")
2021 (buffer-substring start (1- (point)))
2022 (skip-chars-forward " \t\n")
2024 ;; Allow dots in node name not followed by whitespace.
2026 (concat "\\(([^)]+)[^.,"
2027 (if multi-line "" "\n")
2029 (if multi-line "" "\n")
2030 ;; We consider dots followed by newline as
2031 ;; end of nodename even if multil-line.
2032 ;; Also stops at .). It is generated by @pxref.
2033 ;; Skips sequential dots.
2034 "]\\|\\.+[^ \t\n)]\\)+\\)"))
2036 (while (setq i (string-match "\n" str i))
2040 (defun Info-menu (menu-item)
2041 "Go to node for menu item named (or abbreviated) NAME.
2042 Completion is allowed, and the menu item point is on is the default."
2044 (let ((completions '())
2045 ;; If point is within a menu item, use that item as the default
2050 (goto-char (point-min))
2051 (let ((case-fold-search t))
2052 (if (not (search-forward "\n* menu:" nil t))
2053 (error "No menu in this node")))
2054 (while (re-search-forward
2055 "\n\\* \\([^:\t\n]*\\):" nil t)
2056 (if (and (null default)
2057 (prog1 (if last (< last p) nil)
2058 (setq last (match-beginning 0)))
2060 (setq default (car (car completions))))
2061 (setq completions (cons (cons (buffer-substring
2064 (match-beginning 1))
2066 (if (and (null default) last
2068 (<= p (progn (end-of-line) (point))))
2069 (setq default (car (car completions)))))
2072 (setq item (let ((completion-ignore-case t))
2073 (completing-read (if default
2074 (format "Menu item (default %s): "
2077 completions nil t nil
2078 'Info-minibuffer-history
2080 ;; we rely on the fact that completing-read accepts an input
2081 ;; of "" even when the require-match argument is true and ""
2082 ;; is not a valid possibility
2083 (if (string= item "")
2089 ;; there is a problem here in that if several menu items have the same
2090 ;; name you can only go to the node of the first with this command.
2091 (Info-goto-node (Info-extract-menu-item menu-item) nil t))
2093 (defun Info-extract-menu-item (menu-item &optional noerror)
2095 (goto-char (point-min))
2096 (if (let ((case-fold-search t))
2097 (search-forward "\n* menu:" nil t))
2098 (if (or (search-forward (concat "\n* " menu-item ":") nil t)
2099 (search-forward (concat "\n* " menu-item) nil t))
2103 (Info-extract-menu-node-name))
2104 (and (not noerror) (error "No such item in menu")))
2105 (and (not noerror) (error "No menu in this node")))))
2107 ;; If COUNT is nil, use the last item in the menu.
2108 (defun Info-extract-menu-counting (count &optional noerror noindex)
2110 (goto-char (point-min))
2111 (if (let ((case-fold-search t))
2112 (and (search-forward "\n* menu:" nil t)
2114 (not (string-match "\\<Index\\>" Info-current-node)))))
2115 (if (search-forward "\n* " nil t count)
2118 (while (search-forward "\n* " nil t)))
2119 (Info-extract-menu-node-name))
2120 (and (not noerror) (error "Too few items in menu")))
2121 (and (not noerror) (error "No menu in this node")))))
2123 (defun Info-nth-menu-item (n)
2124 "Go to the node of the Nth menu item."
2126 (or n (setq n (- last-command-char ?0)))
2127 (if (< n 1) (error "Index must be at least 1"))
2128 (Info-goto-node (Info-extract-menu-counting n) nil t))
2130 (defun Info-last-menu-item ()
2131 "Go to the node of the tenth menu item."
2133 (Info-goto-node (Info-extract-menu-counting nil) nil t))
2136 "Go to the Top node of this file."
2138 (Info-goto-node "Top"))
2141 "Go to the final node in this file."
2144 (let ((Info-keeping-history nil)
2146 (Info-last-menu-item)
2147 (while (setq node (or (Info-extract-pointer "next" t)
2148 (Info-extract-menu-counting nil t t)))
2149 (Info-goto-node node))
2150 (or (equal (Info-extract-pointer "up" t) "Top")
2151 (let ((executing-kbd-macro "")) ; suppress messages
2153 (Info-global-next 10000)
2156 (defun Info-global-next (&optional n)
2157 "Go to the next node in this file, traversing node structure as necessary.
2158 This works only if the Info file is structured as a hierarchy of nodes.
2159 A positive or negative prefix argument moves by multiple nodes."
2163 (Info-global-prev (- n))
2164 (while (>= (setq n (1- n)) 0)
2166 (cond ((and (string-match "^Top$" Info-current-node)
2167 (setq node (Info-extract-pointer "next" t))
2168 (Info-extract-menu-item node t))
2169 (Info-goto-node node))
2170 ((setq node (Info-extract-menu-counting 1 t t))
2171 (message "Going down...")
2172 (Info-goto-node node))
2174 (let ((Info-keeping-history Info-keeping-history)
2175 (orignode Info-current-node)
2177 (while (not (Info-extract-pointer "next" t))
2178 (if (and (setq node (Info-extract-pointer "up" t))
2179 (not (equal node "Top")))
2181 (message "Going%s..." (setq ups (concat ups " up")))
2182 (Info-goto-node node)
2183 (setq Info-keeping-history nil))
2185 (let ((Info-keeping-history nil))
2186 (Info-goto-node orignode)))
2187 (error "Last node in file")))
2190 (defun Info-page-next (&optional n)
2191 "Scroll forward one screenful, or go to next global node.
2192 A positive or negative prefix argument moves by multiple screenfuls."
2196 (Info-page-prev (- n))
2197 (while (>= (setq n (1- n)) 0)
2198 (if (pos-visible-in-window-p (point-max))
2201 (message "Node: %s" Info-current-node))
2204 (defun Info-scroll-next (arg)
2206 (if Info-auto-advance
2207 (if (and (pos-visible-in-window-p (point-max))
2208 (not (eq Info-auto-advance t))
2209 (not (eq last-command this-command)))
2210 (message "Hit %s again to go to next node"
2211 (if (= last-command-char 0)
2213 (key-description (char-to-string last-command-char))))
2215 (setq this-command 'Info))
2218 (defun Info-global-prev (&optional n)
2219 "Go to the previous node in this file, traversing structure as necessary.
2220 This works only if the Info file is structured as a hierarchy of nodes.
2221 A positive or negative prefix argument moves by multiple nodes."
2225 (Info-global-next (- n))
2226 (while (>= (setq n (1- n)) 0)
2227 (let ((upnode (Info-extract-pointer "up" t))
2228 (prevnode (Info-extract-pointer "prev[ious]*" t)))
2229 (if (or (not prevnode)
2230 (equal prevnode upnode))
2231 (if (string-match "^Top$" Info-current-node)
2232 (error "First node in file")
2233 (message "Going up...")
2235 (Info-goto-node prevnode)
2237 (Info-keeping-history nil)
2239 (while (setq node (Info-extract-menu-counting nil t t))
2240 (message "Going%s..." (setq downs (concat downs " down")))
2241 (Info-goto-node node))))))))
2243 (defun Info-page-prev (&optional n)
2244 "Scroll backward one screenful, or go to previous global node.
2245 A positive or negative prefix argument moves by multiple screenfuls."
2249 (Info-page-next (- n))
2250 (while (>= (setq n (1- n)) 0)
2251 (if (pos-visible-in-window-p (point-min))
2254 (message "Node: %s" Info-current-node)
2255 (goto-char (point-max))
2257 (move-to-window-line 0))
2260 (defun Info-scroll-prev (arg)
2262 (if Info-auto-advance
2263 (if (and (pos-visible-in-window-p (point-min))
2264 (not (eq Info-auto-advance t))
2265 (not (eq last-command this-command)))
2266 (message "Hit %s again to go to previous node"
2267 (if (mouse-event-p last-command-event)
2269 (key-description (event-key last-command-event))))
2271 (setq this-command 'Info))
2274 (defun Info-index (topic)
2275 "Look up a string in the index for this file.
2276 The index is defined as the first node in the top-level menu whose
2277 name contains the word \"Index\", plus any immediately following
2278 nodes whose names also contain the word \"Index\".
2279 If there are no exact matches to the specified topic, this chooses
2280 the first match which is a case-insensitive substring of a topic.
2281 Use the `,' command to see the other matches.
2282 Give a blank topic name to go to the Index node itself."
2283 (interactive "sIndex topic: ")
2284 (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
2285 (regexp-quote topic)
2286 "\\(.*\\)\\.[ \t]*\\([0-9]*\\)$"))
2288 (message "Searching index for `%s'..." topic)
2289 (Info-goto-node "Top")
2290 (let ((case-fold-search t))
2291 (or (search-forward "\n* menu:" nil t)
2293 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2294 (error "No index")))
2295 (goto-char (match-beginning 1))
2296 (let ((Info-keeping-history nil)
2297 (Info-fontify (and Info-fontify (equal topic ""))))
2298 (Info-goto-node (Info-extract-menu-node-name)))
2299 (or (equal topic "")
2302 (Info-keeping-history nil)
2306 (goto-char (point-min))
2307 (while (re-search-forward pattern nil t)
2309 (cons (list (buffer-substring (match-beginning 1)
2311 (buffer-substring (match-beginning 2)
2314 (string-to-int (concat "0"
2319 (and (setq node (Info-extract-pointer "next" t))
2320 (string-match "\\<Index\\>" node)))
2321 (let ((Info-fontify nil))
2322 (Info-goto-node node)))
2326 (error "No \"%s\" in index" topic)))
2327 ;; Here it is a feature that assoc is case-sensitive.
2328 (while (setq found (assoc topic matches))
2329 (setq exact (cons found exact)
2330 matches (delq found matches)))
2331 (setq Info-index-alternatives (nconc exact (nreverse matches))
2332 Info-index-first-alternative (car Info-index-alternatives))
2333 (Info-index-next 0)))))
2335 (defun Info-index-next (num)
2336 "Go to the next matching index item from the last `i' command."
2338 (or Info-index-alternatives
2339 (error "No previous `i' command in this file"))
2341 (setq num (+ num (length Info-index-alternatives))))
2343 (setq Info-index-alternatives
2344 (nconc (cdr Info-index-alternatives)
2345 (list (car Info-index-alternatives)))
2347 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2348 (if (> (nth 3 (car Info-index-alternatives)) 0)
2349 (forward-line (nth 3 (car Info-index-alternatives)))
2350 (forward-line 3) ; don't search in headers
2351 (let ((name (car (car Info-index-alternatives))))
2352 (if (or (re-search-forward (format
2353 #r"\(Function\|Command\): %s\( \|$\)"
2354 (regexp-quote name)) nil t)
2355 (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
2356 (search-forward (format "`%s'" name) nil t)
2357 (and (string-match #r"\`.*\( (.*)\)\'" name)
2359 (format "`%s'" (substring name 0 (match-beginning 1)))
2361 (search-forward name nil t))
2363 (goto-char (point-min)))))
2364 (message "Found \"%s\" in %s. %s"
2365 (car (car Info-index-alternatives))
2366 (nth 2 (car Info-index-alternatives))
2367 (if (cdr Info-index-alternatives)
2368 (if (eq (car (cdr Info-index-alternatives))
2369 Info-index-first-alternative)
2370 "(Press `,' to repeat)"
2371 (format "(Press `,' for %d more)"
2372 (- (1- (length Info-index-alternatives))
2373 (length (memq Info-index-first-alternative
2374 (cdr Info-index-alternatives))))))
2379 (defun Info-emacs-command (command)
2380 "Look up an Emacs command in the Emacs manual in the Info system.
2381 This command is designed to be used whether you are already in Info or not."
2382 (interactive "CLook up command in Emacs manual: ")
2383 (save-window-excursion
2385 (Info-find-node Info-emacs-info-file-name "Top")
2386 (Info-index (symbol-name command)))
2387 (pop-to-buffer "*info*"))
2391 (defun Info-goto-emacs-command-node (key)
2392 "Look up an Emacs command in the Emacs manual in the Info system.
2393 This command is designed to be used whether you are already in Info or not."
2394 (interactive "CLook up command in Emacs manual: ")
2395 (Info-emacs-command key))
2398 (defun Info-goto-emacs-key-command-node (key)
2399 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2400 This command is designed to be used whether you are already in Info or not."
2401 (interactive "kLook up key in Emacs manual: ")
2402 (let ((command (key-binding key)))
2403 (cond ((eq command 'keyboard-quit)
2406 (error "%s is undefined" (key-description key)))
2407 ((and (interactive-p) (eq command 'execute-extended-command))
2408 (call-interactively 'Info-goto-emacs-command-node))
2410 (Info-goto-emacs-command-node command)))))
2413 (defun Info-emacs-key (key)
2414 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2415 This command is designed to be used whether you are already in Info or not."
2416 (interactive "kLook up key in Emacs manual: ")
2417 (cond ((eq (key-binding key) 'keyboard-quit)
2419 ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
2420 (call-interactively 'Info-goto-emacs-command-node))
2422 (save-window-excursion
2424 (Info-find-node Info-emacs-info-file-name "Top")
2425 (setq key (key-description key))
2427 (if (setq p (string-match "[@{}]" key))
2428 (setq key (concat (substring key 0 p) "@" (substring key p))))
2429 (if (string-match "^ESC " key)
2430 (setq key (concat "M-" (substring key 4))))
2431 (if (string-match "^M-C-" key)
2432 (setq key (concat "C-M-" (substring key 4)))))
2434 (pop-to-buffer "*info*"))))
2437 (defun Info-elisp-ref (func)
2438 "Look up an Emacs Lisp function in the Elisp manual in the Info system.
2439 This command is designed to be used whether you are already in Info or not."
2440 (interactive (let ((fn (function-at-point))
2441 (enable-recursive-minibuffers t)
2443 (setq val (completing-read
2444 (format "Look up Emacs Lisp function%s: "
2446 (format " (default %s)" fn)
2449 nil nil (and fn (symbol-name fn))))
2450 (list (if (equal val "")
2452 (save-window-excursion
2455 (Info-find-node "lispref" "Top")
2456 (error (Info-find-node "elisp" "Top")))
2457 (Info-index (symbol-name func)))
2458 (pop-to-buffer "*info*"))
2460 (defun Info-reannotate-node ()
2461 (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
2463 (let ((ibuf (current-buffer))
2464 (file (concat "\\(" (regexp-quote
2465 (file-name-nondirectory Info-current-file))
2466 "\\|" (regexp-quote Info-current-file) "\\)"))
2467 (node (regexp-quote Info-current-node))
2469 (goto-char (point-min))
2470 (if (search-forward "\n------ NOTE:\n" nil t)
2471 (let ((buffer-read-only nil)
2472 (bufmod (buffer-modified-p))
2474 (setq savept (copy-marker savept))
2475 (goto-char (point-min))
2476 (while (search-forward "\n------ NOTE:" nil t)
2477 (setq top (1+ (match-beginning 0)))
2478 (if (search-forward "\n------\n" nil t)
2479 (delete-region top (point)))
2481 (set-buffer-modified-p bufmod)))
2484 (set-buffer (car bufs))
2485 (goto-char (point-min))
2486 (while (re-search-forward
2488 "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
2491 (let ((line (string-to-int
2492 (buffer-substring (match-beginning 2)
2496 (search-forward "\n------\n" nil t)
2500 (if (integerp savept) (setq savept (copy-marker savept)))
2502 (goto-char (point-max))
2503 (goto-char (point-min))
2504 (forward-line line))
2505 (let ((buffer-read-only nil)
2506 (bufmod (buffer-modified-p)))
2507 (insert "------ NOTE:\n")
2508 (insert-buffer-substring (car bufs) top bot)
2509 (set-buffer-modified-p bufmod)))))
2510 (setq bufs (cdr bufs))))
2511 (goto-char savept)))))
2513 (defvar Info-annotate-map nil
2514 "Local keymap used within `a' command of Info.")
2516 (if Info-annotate-map
2518 ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
2519 (setq Info-annotate-map (copy-keymap text-mode-map))
2520 (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
2522 (defun Info-annotate-mode ()
2523 "Major mode for adding an annotation to an Info node.
2524 Like text mode with the addition of Info-cease-annotate
2525 which returns to Info mode for browsing.
2526 \\{Info-annotate-map}")
2528 (defun Info-annotate (arg)
2529 "Add a personal annotation to the current Info node.
2530 Only you will be able to see this annotation. Annotations are stored
2531 in the file \"info.notes\" in your `user-init-directory' by default. If
2532 point is inside an existing annotation, edit that annotation. A prefix
2533 argument specifies which annotations file (from `Info-annotations-path')
2534 is to be edited; default is 1."
2537 (if (or (< arg 0) (not (nth arg Info-annotations-path)))
2539 (setq Info-annotations-path
2540 (list (read-file-name
2541 "Annotations file: " "~/" "~/.infonotes")))
2542 (error "File number must be in the range from 1 to %d"
2543 (length Info-annotations-path))))
2545 (file (file-name-nondirectory Info-current-file))
2546 (d Info-directory-list)
2548 (while (and d (not (equal (expand-file-name file (car d))
2549 Info-current-file)))
2551 (or d (setq file Info-current-file))
2552 (if (and (save-excursion
2553 (goto-char (min (point-max) (+ (point) 13)))
2554 (and (search-backward "------ NOTE:\n" nil t)
2555 (setq pt (match-end 0))
2556 (search-forward "\n------\n" nil t)))
2557 (< (point) (match-end 0)))
2558 (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
2560 (regexp-quote Info-current-node)
2562 (buffer-substring pt (match-beginning 0))))
2563 where (max (- (point) pt) 0)))
2564 (let ((node Info-current-node)
2565 (line (if (looking-at "[ \n]*\\'") 0
2566 (count-lines (point-min) (point)))))
2568 (let ((buffer-read-only nil)
2569 (bufmod (buffer-modified-p)))
2571 (if (bobp) (goto-char (point-max)))
2572 (insert "------ NOTE:\n------\n")
2574 (set-buffer-modified-p bufmod)))
2575 ;; (setq Info-window-start (window-start))
2576 (setq Info-window-configuration (current-window-configuration))
2577 (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
2578 (use-local-map Info-annotate-map)
2579 (setq major-mode 'Info-annotate-mode)
2580 (setq mode-name "Info Annotate")
2583 (goto-char (point-min))
2584 (re-search-forward which nil t))
2586 (goto-char (match-beginning 0))
2588 (forward-char where)))
2589 (let ((bufmod (buffer-modified-p)))
2590 (goto-char (point-max))
2591 (insert (format "\n------ File: %s Node: %s Line: %d\n"
2594 (insert "\n------\n"
2595 "\nPress C-c C-c to save and return to Info.\n")
2597 (set-buffer-modified-p bufmod))))))
2599 (defun Info-cease-annotate ()
2601 (let ((bufmod (buffer-modified-p)))
2602 (while (save-excursion
2603 (goto-char (point-min))
2604 (re-search-forward "\n\n?Press .* to save and return to Info.\n"
2606 (delete-region (1+ (match-beginning 0)) (match-end 0)))
2607 (while (save-excursion
2608 (goto-char (point-min))
2609 (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
2611 (delete-region (match-beginning 0) (match-end 0)))
2612 (set-buffer-modified-p bufmod))
2616 (or (one-window-p) (delete-window))
2618 (setq Info-current-annotation-completions nil)
2619 (set-window-configuration Info-window-configuration)
2620 (Info-reannotate-node))
2622 (defun Info-bookmark (arg tag)
2623 (interactive "p\nsBookmark name: ")
2625 (if (or (string-match "^\"\\(.*\\)\"$" tag)
2626 (string-match #r"^<<\(.*\)>>$" tag))
2627 (setq tag (substring tag (match-beginning 1) (match-end 1))))
2629 (search-forward "\n------\n")
2630 (let ((end (- (point) 8)))
2632 (if (re-search-forward "<<[^>\n]*>>" nil t)
2633 (delete-region (match-beginning 0) (match-end 0))
2636 (insert "<<" tag ">>"))))
2637 (Info-cease-annotate))
2640 "Exit Info by selecting some other buffer."
2643 (save-buffers-kill-emacs)
2644 (bury-buffer (current-buffer))
2645 (if (and (featurep 'toolbar)
2646 (boundp 'toolbar-info-frame)
2647 (eq toolbar-info-frame (selected-frame)))
2649 (delete-frame toolbar-info-frame)
2650 (error (bury-buffer)))
2651 (switch-to-buffer (other-buffer (current-buffer))))))
2653 (defun Info-undefined ()
2654 "Make command be undefined in Info."
2659 "Enter the Info tutorial."
2661 (delete-other-windows)
2662 (Info-find-node "info"
2663 (if (< (window-height) 23)
2667 (defun Info-summary ()
2668 "Display a brief summary of all Info commands."
2670 (save-window-excursion
2671 (switch-to-buffer "*Help*")
2673 (insert (documentation 'Info-mode))
2674 (goto-char (point-min))
2676 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2677 (message (if flag "Type Space to see more"
2678 "Type Space to return to Info"))
2679 (let ((e (next-command-event)))
2680 (if (/= ?\ (event-to-character e))
2681 (progn (setq unread-command-event e) nil)
2685 (bury-buffer "*Help*")))
2687 (defun Info-get-token (pos start all &optional errorstring)
2688 "Return the token around POS,
2689 POS must be somewhere inside the token
2690 START is a regular expression which will match the
2691 beginning of the tokens delimited string
2692 ALL is a regular expression with a single
2693 parenthized subpattern which is the token to be
2694 returned. E.g. '{\(.*\)}' would return any string
2695 enclosed in braces around POS.
2696 SIG optional fourth argument, controls action on no match
2699 a string: signal an error, using that string."
2701 (goto-char (point-min))
2702 (re-search-backward "\\`") ; Bug fix due to Nicholas J. Foskett.
2704 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
2706 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2707 (not (setq found (and (<= (match-beginning 0) pos)
2708 (> (match-end 0) pos))))))
2709 (if (and found (<= (match-beginning 0) pos)
2710 (> (match-end 0) pos))
2711 (buffer-substring (match-beginning 1) (match-end 1))
2712 (cond ((null errorstring)
2718 (error "No %s around position %d" errorstring pos)))))))
2720 (defun Info-follow-clicked-node (event)
2721 "Follow a node reference near clicked point. Like M, F, N, P or U command.
2722 At end of the node's text, moves to the next node."
2724 (or (and (event-point event)
2725 (Info-follow-nearest-node
2727 (select-window (event-window event))
2728 (event-point event))
2730 (error "click on a cross-reference to follow")))
2732 (defun Info-maybe-follow-clicked-node (event &optional click-count)
2733 "Follow a node reference (if any) near clicked point.
2734 Like M, F, N, P or U command. At end of the node's text, moves to the
2735 next node. No error is given if there is no node to follow."
2737 (and Info-button1-follows-hyperlink
2739 (Info-follow-nearest-node
2741 (select-window (event-window event))
2742 (event-point event))
2743 (1+ (point-min))))))
2745 (defun Info-find-nearest-node (point)
2748 ((= point (point-min)) nil) ; don't trigger on accidental RET.
2749 ((setq node (Info-get-token point
2750 (format "\\*%s[ \n]" Info-footnote-tag)
2751 (format "\\*%s[ \n]\\([^:]*\\):"
2752 Info-footnote-tag)))
2753 (list "Following cross-reference %s..."
2754 (list 'Info-follow-reference node)))
2755 ((setq node (Info-get-token point "\\* " #r"\* \([^:]*\)::"))
2756 (list "Selecting menu item %s..."
2757 (list 'Info-goto-node node nil t)))
2758 ((setq node (Info-get-token point "\\* " #r"\* \([^:]*\):"))
2759 (list "Selecting menu item %s..."
2760 (list 'Info-menu node)))
2761 ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
2763 (list 'Info-goto-node node)))
2764 ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
2765 (list "Next node..."
2766 (list 'Info-goto-node node)))
2767 ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
2769 (list 'Info-goto-node "Top")))
2770 ((setq node (Info-get-token point "Prev[ious]*: "
2771 "Prev[ious]*: \\([^,\n\t]*\\)"))
2772 (list "Previous node..."
2773 (list 'Info-goto-node node)))
2774 ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
2775 (list "Reselecting %s..."
2776 (list 'Info-goto-node node)))
2777 ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
2778 (if Info-in-cross-reference
2779 (list "Back to last node..."
2781 (list "Next node..."
2782 '(Info-global-next)))))
2785 (defun Info-follow-nearest-node (point)
2786 "Follow a node reference near point. Like M, F, N, P or U command.
2787 At end of the node's text, moves to the next node."
2789 (let ((data (Info-find-nearest-node point)))
2792 (let ((msg (format (car data) (nth 1 (nth 1 data)))))
2795 (message "%sdone" msg))
2798 (defun Info-indicated-node (event)
2801 (cond ((eventp event)
2802 (set-buffer (event-buffer event))
2803 (setq event (event-point event))))
2804 (let* ((data (Info-find-nearest-node event))
2805 (name (nth 1 (nth 1 data))))
2806 (and name (nth 1 data))))
2809 (defun Info-mouse-track-double-click-hook (event click-count)
2810 "Handle double-clicks by turning pages, like the `gv' ghostscript viewer"
2811 (if (/= click-count 2)
2812 ;; Return nil so any other hooks are performed.
2814 (let* ((fw (face-width 'default))
2815 (fh (face-height 'default))
2816 (x (/ (event-x-pixel event) fw))
2817 (y (/ (event-y-pixel event) fw))
2818 (w (/ (window-pixel-width (event-window event)) fw))
2819 (h (/ (window-pixel-height (event-window event)) fh))
2823 ((<= y by) (Info-up) t)
2824 ((>= y (- h by)) (Info-nth-menu-item 1) t)
2825 ((<= x bx) (Info-prev) t)
2826 ((>= x (- w bx)) (Info-next) t)
2829 (defvar Info-mode-map nil
2830 "Keymap containing Info commands.")
2834 (setq Info-mode-map (make-sparse-keymap))
2835 (suppress-keymap Info-mode-map)
2836 (define-key Info-mode-map "." 'beginning-of-buffer)
2837 (define-key Info-mode-map " " 'Info-scroll-next)
2838 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2839 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2840 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2841 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2842 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2843 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2844 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2845 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2846 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2847 (define-key Info-mode-map "0" 'Info-last-menu-item)
2848 (define-key Info-mode-map "?" 'Info-summary)
2849 (define-key Info-mode-map "a" 'Info-annotate)
2850 (define-key Info-mode-map "b" 'beginning-of-buffer)
2851 (define-key Info-mode-map "d" 'Info-directory)
2852 (define-key Info-mode-map "e" 'Info-edit)
2853 (define-key Info-mode-map "f" 'Info-follow-reference)
2854 (define-key Info-mode-map "g" 'Info-goto-node)
2855 (define-key Info-mode-map "h" 'Info-help)
2856 (define-key Info-mode-map "i" 'Info-index)
2857 (define-key Info-mode-map "j" 'Info-goto-bookmark)
2858 (define-key Info-mode-map "k" 'Info-emacs-key)
2859 (define-key Info-mode-map "l" 'Info-last)
2860 (define-key Info-mode-map "m" 'Info-menu)
2861 (define-key Info-mode-map "n" 'Info-next)
2862 (define-key Info-mode-map "p" 'Info-prev)
2863 (define-key Info-mode-map "q" 'Info-exit)
2864 (define-key Info-mode-map "r" 'Info-follow-reference)
2865 (define-key Info-mode-map "s" 'Info-search)
2866 (define-key Info-mode-map "t" 'Info-top)
2867 (define-key Info-mode-map "u" 'Info-up)
2868 (define-key Info-mode-map "v" 'Info-visit-file)
2869 (define-key Info-mode-map "x" 'Info-bookmark)
2870 (define-key Info-mode-map "<" 'Info-top)
2871 (define-key Info-mode-map ">" 'Info-end)
2872 (define-key Info-mode-map "[" 'Info-global-prev)
2873 (define-key Info-mode-map "]" 'Info-global-next)
2874 (define-key Info-mode-map "{" 'Info-page-prev)
2875 (define-key Info-mode-map "}" 'Info-page-next)
2876 (define-key Info-mode-map "=" 'Info-restore-point)
2877 (define-key Info-mode-map "!" 'Info-select-node)
2878 (define-key Info-mode-map "@" 'Info-follow-nearest-node)
2879 (define-key Info-mode-map "," 'Info-index-next)
2880 (define-key Info-mode-map "*" 'Info-elisp-ref)
2881 (define-key Info-mode-map [tab] 'Info-next-reference)
2882 (define-key Info-mode-map [(meta tab)] 'Info-prev-reference)
2883 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2884 (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
2886 (define-key Info-mode-map 'backspace 'Info-scroll-prev)
2887 (define-key Info-mode-map 'delete 'Info-scroll-prev)
2888 (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
2889 (define-key Info-mode-map 'button3 'Info-select-node-menu))
2892 ;; Info mode is suitable only for specially formatted data.
2893 (put 'info-mode 'mode-class 'special)
2896 "Info mode is for browsing through the Info documentation tree.
2897 Documentation in Info is divided into \"nodes\", each of which
2898 discusses one topic and contains references to other nodes
2899 which discuss related topics. Info has commands to follow
2900 the references and show you other nodes.
2902 h Invoke the Info tutorial.
2903 q Quit Info: return to the previously selected file or buffer.
2905 Selecting other nodes:
2906 n Move to the \"next\" node of this node.
2907 p Move to the \"previous\" node of this node.
2908 m Pick menu item specified by name (or abbreviation).
2909 1-9, 0 Pick first..ninth, last item in node's menu.
2910 Menu items select nodes that are \"subsections\" of this node.
2911 u Move \"up\" from this node (i.e., from a subsection to a section).
2912 f or r Follow a cross reference by name (or abbrev). Type `l' to get back.
2913 RET Follow cross reference or menu item indicated by cursor.
2914 i Look up a topic in this file's Index and move to that node.
2915 , (comma) Move to the next match from a previous `i' command.
2916 l (letter L) Move back to the last node you were in.
2918 Moving within a node:
2919 Space Scroll forward a full screen. DEL Scroll backward.
2920 b Go to beginning of node. Meta-> Go to end of node.
2921 TAB Go to next cross-reference. Meta-TAB Go to previous ref.
2924 Left Button Set point (usual text-mode functionality)
2925 Middle Button Click on a highlighted node reference to go to it.
2926 Right Button Pop up a menu of applicable Info commands.
2928 Left Button Double Click in window edges:
2929 Top edge: Go up to the parent node, like `u'.
2930 Left edge: Go to the previous node, like `p'.
2931 Right edge: Go to the next node, like `n'.
2932 Bottom edge: Follow first menu item, like `1'.
2935 g Move to node, file, or annotation tag specified by name.
2936 Examples: `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
2937 v Move to file, with filename completion.
2938 k Look up a key sequence in Emacs manual (also C-h C-k at any time).
2939 * Look up a function name in Emacs Lisp manual (also C-h C-f).
2940 d Go to the main directory of Info files.
2941 < or t Go to Top (first) node of this file.
2942 > Go to last node in this file.
2943 \[ Go to previous node, treating file as one linear document.
2944 \] Go to next node, treating file as one linear document.
2945 { Scroll backward, or go to previous node if at top.
2946 } Scroll forward, or go to next node if at bottom.
2947 = Restore cursor position from last time in this node.
2948 a Add a private note (annotation) to the current node.
2949 x, j Add, jump to a bookmark (annotation tag).
2950 s Search this Info file for a node containing the specified regexp.
2951 e Edit the contents of the current node."
2952 (kill-all-local-variables)
2953 (setq major-mode 'Info-mode)
2954 (setq mode-name "Info")
2955 (use-local-map Info-mode-map)
2956 (set-syntax-table text-mode-syntax-table)
2957 (setq local-abbrev-table text-mode-abbrev-table)
2958 (setq case-fold-search t)
2959 (setq buffer-read-only t)
2960 ; (setq buffer-mouse-map Info-mode-mouse-map)
2961 (make-local-variable 'Info-current-file)
2962 (make-local-variable 'Info-current-subfile)
2963 (make-local-variable 'Info-current-node)
2964 (make-local-variable 'Info-tag-table-marker)
2965 (setq Info-tag-table-marker (make-marker))
2966 (make-local-variable 'Info-tag-table-buffer)
2967 (setq Info-tag-table-buffer nil)
2968 (make-local-variable 'Info-current-file-completions)
2969 (make-local-variable 'Info-current-annotation-completions)
2970 (make-local-variable 'Info-index-alternatives)
2971 (make-local-variable 'Info-history)
2972 ;; Faces are now defined by `defface'...
2973 (make-local-variable 'mouse-track-click-hook)
2974 (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
2975 (add-hook 'mouse-track-click-hook 'Info-mouse-track-double-click-hook)
2976 ;; #### The console-on-window-system-p check is to allow this to
2977 ;; work on tty's. The real problem here is that featurep really
2978 ;; needs to have some device/console domain knowledge added to it.
2979 (defvar info::toolbar)
2980 (if (and (featurep 'toolbar)
2981 (console-on-window-system-p)
2982 (not Info-inhibit-toolbar))
2983 (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
2984 (if (featurep 'menubar)
2986 ;; make a local copy of the menubar, so our modes don't
2987 ;; change the global menubar
2988 (easy-menu-add '("Info" :filter Info-menu-filter))))
2989 (run-hooks 'Info-mode-hook)
2990 (Info-set-mode-line))
2992 (defvar Info-edit-map nil
2993 "Local keymap used within `e' command of Info.")
2997 ;; XEmacs: remove FSF stuff
2998 (setq Info-edit-map (make-sparse-keymap))
2999 (set-keymap-name Info-edit-map 'Info-edit-map)
3000 (set-keymap-parents Info-edit-map (list text-mode-map))
3001 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
3003 ;; Info-edit mode is suitable only for specially formatted data.
3004 (put 'info-edit-mode 'mode-class 'special)
3006 (defun Info-edit-mode ()
3007 "Major mode for editing the contents of an Info node.
3008 Like text mode with the addition of `Info-cease-edit'
3009 which returns to Info mode for browsing.
3014 "Edit the contents of this Info node.
3015 Allowed only if variable `Info-enable-edit' is non-nil."
3017 (or Info-enable-edit
3018 (error "Editing info nodes is not enabled"))
3019 (use-local-map Info-edit-map)
3020 (setq major-mode 'Info-edit-mode)
3021 (setq mode-name "Info Edit")
3022 (kill-local-variable 'modeline-buffer-identification)
3023 (setq buffer-read-only nil)
3024 ;; Make mode line update.
3025 (set-buffer-modified-p (buffer-modified-p))
3026 (message (substitute-command-keys
3027 "Editing: Type \\[Info-cease-edit] to return to info")))
3029 (defun Info-cease-edit ()
3030 "Finish editing Info node; switch back to Info proper."
3032 ;; Do this first, so nothing has changed if user C-g's at query.
3033 (and (buffer-modified-p)
3034 (y-or-n-p "Save the file? ")
3036 (use-local-map Info-mode-map)
3037 (setq major-mode 'Info-mode)
3038 (setq mode-name "Info")
3039 (Info-set-mode-line)
3040 (setq buffer-read-only t)
3041 ;; Make mode line update.
3042 (set-buffer-modified-p (buffer-modified-p))
3043 (and (marker-position Info-tag-table-marker)
3045 (message "Tags may have changed. Use Info-tagify if necessary")))
3047 (defun Info-find-emacs-command-nodes (command)
3048 "Return a list of locations documenting COMMAND in the SXEmacs Info manual.
3049 The locations are of the format used in Info-history, i.e.
3050 \(FILENAME NODENAME BUFFERPOS\)."
3052 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
3053 #r":\s *\(.*\)\.")))
3055 (Info-find-node "SXEmacs" "Command Index")
3056 ;; Take the index node off the Info history.
3057 ;; ??? says this isn't safe someplace else... hmmm.
3058 (setq Info-history (cdr Info-history))
3059 (goto-char (point-max))
3060 (while (re-search-backward cmd-desc nil t)
3061 (setq where (cons (list Info-current-file
3069 ;;; fontification and mousability for info
3071 (defun Info-highlight-region (start end face)
3073 (splitp (string-match "\n[ \t]+" (buffer-substring start end))))
3076 (setq extent (make-extent start (progn (goto-char start)
3079 (set-extent-face extent face)
3080 (set-extent-property extent 'info t)
3081 (set-extent-property extent 'highlight t)
3082 (skip-chars-forward "\n\t ")
3083 (setq extent (make-extent (point) end)))
3084 (setq extent (make-extent start end)))
3085 (set-extent-face extent face)
3086 (set-extent-property extent 'info t)
3087 (set-extent-property extent 'highlight t)))
3089 (defun Info-fontify-node ()
3091 (let ((case-fold-search t)
3092 (xref-regexp (concat "\\*"
3093 (regexp-quote Info-footnote-tag)
3094 "[ \n\t]*\\([^:]*\\):")))
3095 ;; Clear the old extents
3096 (map-extents #'(lambda (x y) (delete-extent x))
3097 (current-buffer) (point-min) (point-max) nil)
3098 ;; Break the top line iff it is > 79 characters. Some info nodes
3099 ;; have top lines that span 3 lines because of long node titles.
3100 ;; eg: (Info-find-node "lispref.info" "Window-Level Event Position Info")
3101 (toggle-read-only -1)
3106 (goto-char (point-min))
3107 (re-search-forward "Node: *[^,]+, " nil t)
3108 (setq len (- (point) (point-min))
3109 extent (make-extent (point-min) (point)))
3110 (set-extent-property extent 'invisible t)
3114 (if (< (current-column) (+ 78 len))
3117 (forward-char (+ 79 len))
3118 (re-search-backward "," nil t)
3122 (delete-backward-char 1)
3125 (toggle-read-only 1)
3126 ;; Highlight xrefs in the top few lines of the node
3127 (goto-char (point-min))
3128 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
3130 (goto-char (match-end 0))
3132 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?\n?")
3133 (goto-char (match-end 0))
3134 (Info-highlight-region (match-beginning 1) (match-end 1)
3136 ;; Now get the xrefs in the body
3137 (goto-char (point-min))
3138 (while (re-search-forward xref-regexp nil t)
3139 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
3141 (Info-highlight-region (match-beginning 1) (match-end 1)
3143 ;; then highlight the nodes in the menu.
3144 (goto-char (point-min))
3145 (if (and (search-forward "\n* menu:" nil t))
3146 (while (re-search-forward
3147 "^\\* \\([^:\t\n]*\\):?:[ \t\n]" nil t)
3148 (Info-highlight-region (match-beginning 1) (match-end 1)
3150 (set-buffer-modified-p nil))))
3152 (defun Info-construct-menu (&optional event)
3153 "Construct a menu of Info commands.
3154 Adds an entry for the node at EVENT, or under point if EVENT is omitted.
3155 Used to construct the menubar submenu and popup menu."
3156 (or event (setq event (point)))
3157 (let ((case-fold-search t)
3158 (xref-regexp (concat "\\*"
3159 (regexp-quote Info-footnote-tag)
3160 "[ \n\t]*\\([^:]*\\):"))
3161 up-p prev-p next-p menu xrefs subnodes in)
3163 ;; `one-space' fixes "Notes:" xrefs that are split across lines.
3167 (while (setq i (string-match "[ \n\t]+" text i))
3168 (setq text (concat (substring text 0 i) " "
3169 (substring text (match-end 0))))
3172 (goto-char (point-min))
3173 (if (looking-at ".*\\bNext:") (setq next-p t))
3174 (if (looking-at ".*\\bPrev:") (setq prev-p t))
3175 (if (looking-at ".*Up:") (setq up-p t))
3177 (if (setq in (Info-indicated-node event))
3178 (list (vector (one-space (cadr in)) in t)
3179 "--:shadowEtchedIn"))
3181 ["Goto Info Top-level" Info-directory]
3182 (vector "Next Node" 'Info-next :active next-p)
3183 (vector "Previous Node" 'Info-prev :active prev-p)
3184 (vector "Parent Node (Up)" 'Info-up :active up-p)
3185 ["Goto Node..." Info-goto-node]
3186 ["Goto Last Visited Node " Info-last])))
3187 ;; Find the xrefs and make a list
3188 (while (re-search-forward xref-regexp nil t)
3189 (setq xrefs (cons (one-space (buffer-substring (match-beginning 1)
3192 (setq xrefs (nreverse xrefs))
3193 (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
3194 ;; Find the subnodes and make a list
3195 (goto-char (point-min))
3196 (if (search-forward "\n* menu:" nil t)
3197 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
3198 (setq subnodes (cons (buffer-substring (match-beginning 1)
3201 (setq subnodes (nreverse subnodes))
3202 (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more))))
3204 (nconc menu (list "--:shadowDoubleEtchedIn"
3207 (mapcar #'(lambda (xref)
3211 (list 'Info-follow-reference xref))))
3214 (nconc menu (list "--:shadowDoubleEtchedIn"
3217 (mapcar #'(lambda (node)
3220 (vector node (list 'Info-menu node))))
3224 (defun Info-menu-filter (menu)
3225 "This is the menu filter for the \"Info\" submenu."
3226 (Info-construct-menu))
3228 (defun Info-select-node-menu (event)
3229 "Pops up a menu of applicable Info commands."
3231 (select-window (event-window event))
3232 (let ((menu (Info-construct-menu event)))
3233 (setq menu (nconc (list "Info" ; title: not displayed
3235 "--:shadowDoubleEtchedOut")
3237 (let ((popup-menu-titles nil))
3238 (popup-menu menu))))
3240 ;;; Info toolbar support
3242 ;; exit icon taken from GNUS
3243 (defvar info::toolbar-exit-icon
3244 (if (featurep 'toolbar)
3245 (toolbar-make-button-list
3246 (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
3247 toolbar-icon-directory)))
3250 (defvar info::toolbar-up-icon
3251 (if (featurep 'toolbar)
3252 (toolbar-make-button-list
3253 (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
3254 toolbar-icon-directory)))
3257 (defvar info::toolbar-next-icon
3258 (if (featurep 'toolbar)
3259 (toolbar-make-button-list
3260 (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
3261 toolbar-icon-directory)))
3264 (defvar info::toolbar-prev-icon
3265 (if (featurep 'toolbar)
3266 (toolbar-make-button-list
3267 (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
3268 toolbar-icon-directory)))
3271 (defvar info::toolbar
3272 (if (featurep 'toolbar)
3273 ; disabled until we get the next/prev-win icons working again.
3274 ; (cons (first initial-toolbar-spec)
3275 ; (cons (second initial-toolbar-spec)
3276 '([info::toolbar-exit-icon
3280 [info::toolbar-next-icon
3283 "Next entry in same section"]
3284 [info::toolbar-prev-icon
3287 "Prev entry in same section"]
3288 [info::toolbar-up-icon
3291 "Up entry to enclosing section"]
3297 (run-hooks 'Info-load-hook)
3299 ;;; info.el ends here