1 ;;; info.el --- info package for SXEmacs.
4 ;; Copyright (C) 1985, 1986, 1993, 1997 Free Software Foundation, Inc.
5 ;; Copyright (C) 2005, 2020 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 "\037\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 (if (eq buffer-file-coding-system (find-coding-system 'utf-8))
777 (goto-char (point-min))
778 (goto-char (max (point-min) (- guesspos 1000))))
779 ;; Now search from our advised position (or from beg of buffer)
780 ;; to find the actual node.
782 (while (search-forward "\n\037" nil t)
786 (if (re-search-backward regexp beg t)
789 (let ((bufs (delq nil (mapcar 'get-file-buffer
790 Info-annotations-path)))
791 (pattern (if (string-match #r"\`<<.*>>\'" qnode) qnode
792 (format "\"%s\"\\|<<%s>>" qnode qnode)))
793 (pat2 (concat #r"------ *File: *\([^ ].*[^ ]\) *Node: "
794 #r"*\([^ ].*[^ ]\) *Line: *\([0-9]+\)"))
795 (afile nil) anode aline)
796 (while (and bufs (not anode))
798 (set-buffer (car bufs))
799 (goto-char (point-min))
800 (if (re-search-forward pattern nil t)
801 (if (re-search-backward pat2 nil t)
802 (setq afile (buffer-substring (match-beginning 1)
804 anode (buffer-substring (match-beginning 2)
807 (buffer-substring (match-beginning 3)
809 (setq bufs (cdr bufs)))
811 (Info-find-node afile anode t nil aline)
814 (Info-find-node nodename "Top" t)
816 (or Info-current-node
817 (error "No such node: %s" nodename)))
821 (goto-char (point-min))
822 (if line (forward-line line)))))))
823 ;; If we did not finish finding the specified node,
824 ;; go back to the previous one.
825 (or Info-current-node no-going-back
826 (let ((hist (car Info-history)))
827 ;; The following is no longer safe with new Info-history system
828 ;; (setq Info-history (cdr Info-history))
829 (Info-goto-node (car hist) t)
830 (goto-char (+ (point-min) (nth 1 hist)))))))
832 ;; Cache the contents of the (virtual) dir file, once we have merged
833 ;; it for the first time, so we can save time subsequently.
834 (defvar Info-dir-contents nil)
836 ;; Cache for the directory we decided to use for the default-directory
837 ;; of the merged dir text.
838 (defvar Info-dir-contents-directory nil)
840 ;; Record the file attributes of all the files from which we
841 ;; constructed Info-dir-contents.
842 (defvar Info-dir-file-attributes nil)
844 (defun Info-insert-dir ()
845 "Construct the Info directory node by merging the files named
846 \"dir\" or \"localdir\" from the directories in `Info-directory-list'.
847 The \"dir\" files will take precedence in cases where both exist. It
848 sets the *info* buffer's `default-directory' to the first directory we
849 actually get any text from."
850 (if (and Info-dir-contents Info-dir-file-attributes
851 ;; Verify that none of the files we used has changed
854 (mapcar #'(lambda (elt)
855 (let ((curr (file-attributes (car elt))))
856 ;; Don't compare the access time.
857 (if curr (setcar (nthcdr 4 curr) 0))
858 (setcar (nthcdr 4 (cdr elt)) 0)
859 (equal (cdr elt) curr)))
860 Info-dir-file-attributes))))
861 (insert Info-dir-contents)
862 (let ((dirs (reverse Info-directory-list))
863 buffers lbuffers buffer others nodes dirs-done)
865 (setq Info-dir-file-attributes nil)
867 ;; Search the directory list for the directory file.
869 (let ((truename (file-truename (expand-file-name (car dirs)))))
870 (or (member truename dirs-done)
871 (member (directory-file-name truename) dirs-done)
872 ;; Karl Berry recently added the ability all possibilities for
873 ;; extension as for normal info files. This code however is
874 ;; still unsatisfactory: if one day, we find a compressed dir
875 ;; file (which looks possible), we should be able to handle it
876 ;; (which means decompress and read it, update it, save and
877 ;; recompress it). --dv
878 (let ((trials '("dir" "DIR"
879 "dir.info" "DIR.INFO"
881 "localdir" "LOCALDIR"
882 "localdir.info" "LOCALDIR.INFO"
883 "localdir.inf" "LOCALDIR.INF"))
886 (while (setq file (pop trials))
887 (setq file (expand-file-name file truename))
888 (and (setq attrs (file-attributes file))
891 (setq file (expand-file-name "dir" truename)))
894 (cons (directory-file-name truename)
896 (Info-maybe-update-dir file)
897 (setq attrs (file-attributes file))
898 (if (or (setq buf (find-buffer-visiting file))
902 (message "Composing main Info directory..."))
905 (if (string-match "localdir" file)
909 (insert-file-contents file))
910 (if (string-match "localdir" (buffer-name))
911 (setq lbuffers (cons (current-buffer) lbuffers))
912 (setq buffers (cons (current-buffer) buffers)))
914 (setq Info-dir-file-attributes
915 (cons (cons file attrs)
916 Info-dir-file-attributes)))))))
917 (or (cdr dirs) (setq Info-dir-contents-directory (car dirs)))
918 (setq dirs (cdr dirs))))
920 ;; ensure that the localdir files are inserted last, and reverse
921 ;; the list of them so that when they get pushed in, they appear
922 ;; in the same order they got specified in the path, from top to
924 (nconc buffers (reverse lbuffers))
927 (error "Can't find the Info directory node"))
928 ;; Distinguish the dir file that comes with Emacs from all the
929 ;; others. Yes, that is really what this is supposed to do.
930 ;; If it doesn't work, fix it.
931 (setq buffer (car buffers)
932 ;; reverse it since they are pushed down from the top. the
933 ;; `Info-directory-list can be specified in natural order
935 others (reverse (cdr buffers)))
937 ;; Insert the entire original dir file as a start; note that we've
938 ;; already saved its default directory to use as the default
939 ;; directory for the whole concatenation.
940 (insert-buffer buffer)
942 ;; Look at each of the other buffers one by one.
944 (let ((other (car others))
945 (info-buffer (current-buffer)))
946 (if (string-match "localdir" (buffer-name other))
948 (set-buffer info-buffer)
949 (goto-char (point-max))
951 ((re-search-backward "^ *\\* *Locals *: *$" nil t)
952 (delete-region (match-beginning 0) (match-end 0)))
953 ;; look for a line like |Local XEmacs packages:
954 ;; or mismatch on some text ...
955 ((re-search-backward Info-localdir-heading-regexp nil t)
956 ;; This is for people who underline topic headings with
957 ;; equal signs or dashes.
958 (when (save-excursion
961 (looking-at "^[ \t]*[-=*]+"))
965 (t (search-backward "\^L" nil t)))
966 ;; Insert menu part of the file
968 (len (length (buffer-string nil nil other))))
969 (insert (buffer-string nil nil other))
970 (goto-char (+ pt len))
973 (if (search-forward "* Menu:" (+ pt len) t)
976 (delete-region pt (point)))))))
977 ;; In each, find all the menus.
980 (goto-char (point-min))
981 ;; Find each menu, and add an elt to NODES for it.
982 (while (re-search-forward "^\\* Menu:" nil t)
983 (let (beg nodename end)
986 (search-backward "\n\037")
987 (search-forward "Node: ")
988 (setq nodename (Info-following-node-name))
989 (search-forward "\n\037" nil 'move)
992 (setq nodes (cons (list nodename other beg end) nodes))))))
993 (setq others (cdr others))))
995 ;; Add to the main menu a menu item for each other node.
996 (re-search-forward "^\\* Menu:" nil t)
998 (let ((menu-items '("top"))
1000 (case-fold-search t)
1001 (end (save-excursion (search-forward "\037" nil t) (point))))
1003 (let ((nodename (car (car nodes))))
1005 (or (member (downcase nodename) menu-items)
1006 (re-search-forward (concat "^\\* "
1007 (regexp-quote nodename)
1011 (insert "* " nodename "::" "\n")
1012 (setq menu-items (cons nodename menu-items))))))
1013 (setq nodes (cdr nodes))))
1014 ;; Now take each node of each of the other buffers
1015 ;; and merge it into the main buffer.
1017 (let ((nodename (car (car nodes))))
1018 (goto-char (point-min))
1019 ;; Find the like-named node in the main buffer.
1020 (if (re-search-forward (concat "\n\037.*\n.*Node: "
1021 (regexp-quote nodename)
1025 (search-forward "\n\037" nil 'move)
1028 ;; If none exists, add one.
1029 (goto-char (point-max))
1030 (insert "\037\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
1031 ;; Merge the text from the other buffer's menu
1032 ;; into the menu in the like-named node in the main buffer.
1033 (apply 'insert-buffer-substring (cdr (car nodes))))
1034 (setq nodes (cdr nodes)))
1035 ;; Kill all the buffers we just made.
1037 (kill-buffer (car buffers))
1038 (setq buffers (cdr buffers)))
1040 (kill-buffer (car lbuffers))
1041 (setq lbuffers (cdr lbuffers)))
1042 (message "Composing main Info directory...done"))
1043 (setq Info-dir-contents (buffer-string)))
1044 (setq default-directory (file-name-as-directory Info-dir-contents-directory))
1045 (setq buffer-file-name (caar Info-dir-file-attributes)
1046 buffer-file-truename (file-truename buffer-file-name)))
1048 (defmacro Info-directory-files (dir-file &optional all full nosort files-only)
1049 "Return a list of Info files living in the same directory as DIR-FILE.
1050 This list actually contains the files living in this directory, except for
1051 the dir file itself and the secondary info files (foo-1 foo-2 etc).
1053 If the optional argument ALL is non nil, the secondary info files are also
1054 included in the list.
1056 Please refer to the function `directory-files' for the meaning of the other
1057 optional arguments."
1058 `(let* ((dir (file-name-directory ,dir-file))
1059 (all-files (remove ,dir-file (directory-files dir ',full nil ',nosort
1063 (remove (concat dir ".")
1064 (remove (concat dir "..") all-files))
1066 (remove ".." all-files))))
1070 (concat "-[0-9]+\\("
1071 ;; Extract all known compression suffixes from
1072 ;; Info-suffix-list. These suffixes can typically be
1073 ;; found in entries of the form `.info.something'.
1074 (let ((suff-list Info-suffix-list)
1076 (while (setq suff (pop suff-list))
1077 (and (string-match "^\\.info" (car suff))
1078 (setq regexp (concat regexp
1082 (and suff-list "\\|")))))
1086 (while (setq file (pop all-files))
1087 (or (string-match suff-match file)
1088 (push file info-files)))
1089 (reverse info-files)
1093 (defun Info-maybe-update-dir (file)
1094 "Rebuild dir or localdir according to `Info-auto-generate-directory'."
1095 (unless (or (not (file-exists-p (file-name-directory file)))
1096 (null (Info-directory-files file 'all)))
1097 (if (not (find-buffer-visiting file))
1098 (if (not (file-exists-p file))
1099 (if (or (memq Info-auto-generate-directory
1100 '(always if-missing if-outdated)))
1101 (Info-build-dir-anew (file-name-directory file)))
1102 (if (or (eq Info-auto-generate-directory 'always)
1103 (and (eq Info-auto-generate-directory 'if-outdated)
1104 (Info-dir-outdated-p file)))
1105 (Info-rebuild-dir file))))))
1107 ;; Record which *.info files are newer than the dir file
1108 (defvar Info-dir-newer-info-files nil)
1110 (defun Info-dir-outdated-p (file)
1111 "Return non-nil if dir or localdir is outdated.
1112 dir or localdir are outdated when an info file in the same
1113 directory has been modified more recently."
1114 (let ((dir-mod-time (nth 5 (file-attributes file)))
1116 (setq Info-dir-newer-info-files nil)
1120 (setq f-mod-time (nth 5 (file-attributes f)))
1121 (setq newer (or (> (car f-mod-time) (car dir-mod-time))
1122 (and (= (car f-mod-time) (car dir-mod-time))
1123 (> (car (cdr f-mod-time))
1124 (car (cdr dir-mod-time))))))
1125 (if (and (file-readable-p f) newer)
1126 (setq Info-dir-newer-info-files
1127 (cons f Info-dir-newer-info-files)))))
1128 (Info-directory-files file nil 'fullname 'nosort t))
1129 Info-dir-newer-info-files))
1131 (defun Info-extract-dir-entry-from (file)
1132 "Extract the dir entry from the info FILE.
1133 The dir entry is delimited by the markers `START-INFO-DIR-ENTRY'
1134 and `END-INFO-DIR-ENTRY'."
1136 (set-buffer (get-buffer-create " *Info-tmp*"))
1137 (when (file-readable-p file)
1138 (insert-file-contents file nil nil nil t)
1139 (goto-char (point-min))
1141 (unless (null (re-search-forward "^START-INFO-DIR-ENTRY" nil t))
1144 (unless (null (re-search-forward "^END-INFO-DIR-ENTRY" nil t))
1145 (goto-char (match-beginning 0))
1146 (car (Info-parse-dir-entries beg (point)))))))))
1148 ;; Parse dir entries contained between START and END into a list of the form
1149 ;; (filename topic node (description-line-1 description-line-2 ...))
1150 (defun Info-parse-dir-entries (start end)
1151 (let (entry entries)
1154 (narrow-to-region start end)
1156 (while (re-search-forward
1157 (concat #r"^\* \([^:]+\):\("
1159 #r"(\([^)]*\))\w*\.\|:\)")
1161 (setq entry (list (match-string 2)
1163 (downcase (or (match-string 3)
1164 (match-string 1)))))
1171 (re-search-forward "[ \t]*" nil t)
1172 (or (and (re-search-forward "^[^ \t]" nil t)
1173 (goto-char (match-beginning 0)))
1175 "[ \t]*\n[ \t]*"))))
1177 (setq entries (cons (nreverse entry) entries)))))
1178 (nreverse entries)))
1180 (defun Info-dump-dir-entries (entries)
1184 (mapcar #'(lambda (e)
1185 (setq e (cdr e)) ; Drop filename
1186 (setq len (length (concat (car e)
1188 (if (> len description-col)
1189 (setq description-col len)))
1191 (setq description-col (+ 5 description-col))
1192 (mapcar #'(lambda (e)
1193 (setq e (cdr e)) ; Drop filename
1194 (insert "* " (car e) ":" (car (cdr e)))
1195 (setq e (car (cdr (cdr e))))
1197 (indent-to-column description-col)
1198 (insert (car e) "\n")
1204 (defun Info-build-dir-anew (directory)
1205 "Build info directory information for DIRECTORY.
1206 The generated directory listing may be saved to a `dir' according
1207 to the value of `Info-save-auto-generated-dir'."
1209 (let* ((dirfile (expand-file-name "dir" directory))
1210 (to-temp (or (null Info-save-auto-generated-dir)
1211 (eq Info-save-auto-generated-dir 'never)
1212 (and (not (file-writable-p dirfile))
1213 (message "File not writable %s. Using temporary."
1215 (info-files (Info-directory-files dirfile nil 'fullname nil t)))
1217 (message "Creating temporary dir in %s..." directory)
1218 (message "Creating %s..." dirfile))
1219 (set-buffer (find-file-noselect dirfile t))
1220 (setq buffer-read-only nil)
1222 (insert Info-dir-prologue "Info files in " directory ":\n\n")
1223 (Info-dump-dir-entries
1226 (or (Info-extract-dir-entry-from f)
1228 (progn (string-match #r"\([^.]*\)\(\..*\)?$"
1229 (file-name-nondirectory f))
1231 (match-string 1 (file-name-nondirectory f))))
1233 (list Info-no-description-string))))
1236 (set-buffer-modified-p nil)
1239 (message "Creating temporary dir in %s...done" directory)
1240 (message "Creating %s...done" dirfile)))))
1243 (defun Info-rebuild-dir (file)
1244 "Build info directory information in the directory of dir FILE.
1245 Description of info files are merged from the info files in the
1246 directory and the contents of FILE with the description in info files
1247 taking precedence over descriptions in FILE.
1248 The generated directory listing may be saved to a `dir' according to
1249 the value of `Info-save-auto-generated-dir'."
1252 (let (dir-section-contents dir-full-contents
1258 (or (null Info-save-auto-generated-dir)
1259 (eq Info-save-auto-generated-dir 'never)
1260 (and (eq Info-save-auto-generated-dir 'always)
1261 (not (file-writable-p file))
1262 (message "File not writable %s. Using temporary." file))
1263 (and (eq Info-save-auto-generated-dir 'conservative)
1264 (or (and (not (file-writable-p file))
1266 "File not writable %s. Using temporary." file))
1268 (message "%s is outdated. Overwrite ? "
1270 (set-buffer (find-file-noselect file t))
1271 (setq buffer-read-only nil)
1273 (message "Rebuilding temporary %s..." file)
1274 (message "Rebuilding %s..." file))
1276 (setq buffer-read-only nil)
1277 (goto-char (point-min))
1278 (unless (and (search-forward "\037")
1279 (re-search-forward "^\\* Menu:.*$" nil t)
1280 (setq mark (and (re-search-forward "^\\* " nil t)
1281 (match-beginning 0))))
1283 (setq dir-full-contents (Info-parse-dir-entries mark (point-max)))
1284 (setq next-section (or (and (re-search-forward "^[^* \t].*:[ \t]*$"
1286 (match-beginning 0))
1289 (narrow-to-region mark next-section)
1290 (setq dir-section-contents (nreverse (Info-parse-dir-entries
1291 (point-min) (point-max))))
1294 (setq dir-entry (assoc (downcase
1295 (file-name-sans-extension
1296 (file-name-nondirectory file)))
1297 dir-section-contents)
1298 file-dir-entry (Info-extract-dir-entry-from file))
1301 ;; A dir entry in the info file takes precedence over
1302 ;; an existing entry in the dir file
1303 (setcdr dir-entry (cdr file-dir-entry)))
1304 (unless (or not-first-section
1306 (file-name-sans-extension
1307 (file-name-nondirectory file)))
1310 (setq dir-section-contents
1311 (cons file-dir-entry dir-section-contents))
1312 (setq dir-section-contents
1314 (capitalize (file-name-sans-extension
1315 (file-name-nondirectory
1318 (list Info-no-description-string))
1319 dir-section-contents))))))
1320 Info-dir-newer-info-files)
1321 (delete-region (point-min) (point-max))
1322 (Info-dump-dir-entries (nreverse dir-section-contents))
1324 (if (= next-section (point-max))
1325 (setq next-section nil)
1326 (or (setq mark (and (re-search-forward "^\\* " nil t)
1327 (match-beginning 0)))
1329 (setq next-section (or (and (re-search-forward
1330 "^[^* \t].*:[ \t]*$" nil t)
1331 (match-beginning 0))
1333 (setq not-first-section t)))
1336 (set-buffer-modified-p nil)
1337 (message "Rebuilding temporary %s...done" file))
1339 (message "Rebuilding %s...done" file))))))
1342 (defun Info-batch-rebuild-dir ()
1343 "(Re)build `dir' files in the directories remaining on the command line.
1344 Use this from the command line, with `-batch', it won't work in an
1347 Each file is processed even if an error occurred previously. For example,
1348 invoke \"sxemacs -batch -f Info-batch-rebuild-dir /usr/local/info\"."
1349 ;; command-line-args-left is what is left of the command line (from
1351 (defvar command-line-args-left) ; Avoid 'free variable' warning
1352 (if (not noninteractive)
1353 (error "`Info-batch-rebuild-dir' is to be used only with -batch"))
1354 (let ((Info-save-auto-generated-dir 'always)
1356 (while command-line-args-left
1357 (if (not (file-directory-p (car command-line-args-left)))
1358 (message "Warning: Skipped %s. Not a directory."
1359 (car command-line-args-left))
1360 (setq dir (expand-file-name "dir" (car command-line-args-left)))
1361 (setq localdir (expand-file-name "localdir"
1362 (car command-line-args-left)))
1364 ((file-exists-p dir)
1365 (Info-rebuild-dir dir))
1366 ((file-exists-p localdir)
1367 (Info-rebuild-dir localdir))
1369 (Info-build-dir-anew (car command-line-args-left)))))
1370 (setq command-line-args-left (cdr command-line-args-left)))
1374 (defun Info-history-add (file node point)
1375 (if Info-keeping-history
1376 (let* ((name (format "(%s)%s" (Info-file-name-only file) node))
1377 (found (assoc name Info-history)))
1379 (setq Info-history (delq found Info-history)))
1380 (setq Info-history (cons (list name (- point (point-min))
1381 (and (eq (window-buffer)
1383 (- (window-start) (point-min))))
1386 (defun Info-file-name-only (file)
1387 (let ((dir (file-name-directory file))
1388 (p Info-directory-list))
1389 (while (and p (not (equal (car p) dir)))
1391 (if p (file-name-nondirectory file) file)))
1393 (defun Info-read-subfile (nodepos)
1397 (set-buffer (marker-buffer Info-tag-table-marker))
1398 (goto-char (point-min))
1399 (search-forward "\n\037")
1402 (while (not (looking-at "\037"))
1404 (let ((start (point))
1405 thisfilepos thisfilename)
1406 (search-forward ": ")
1407 (setq thisfilename (buffer-substring start (- (point) 2)))
1408 (setq thisfilepos (read (current-buffer)))
1409 ;; read in version 19 stops at the end of number.
1410 ;; Advance to the next line.
1413 (if (> thisfilepos nodepos)
1415 (setq lastfilename thisfilename)
1416 (setq lastfilepos thisfilepos))
1418 (or (equal Info-current-subfile lastfilename)
1419 (let ((buffer-read-only nil))
1420 (setq buffer-file-name nil
1421 buffer-file-truename nil)
1424 (Info-insert-file-contents (Info-suffixed-file
1425 (expand-file-name lastfilename
1426 (file-name-directory
1430 (set-buffer-modified-p nil)
1431 (setq Info-current-subfile lastfilename)))
1432 (goto-char (point-min))
1433 (search-forward "\n\037")
1434 (+ (- nodepos lastfilepos) (point))))
1436 (defun Info-all-case-regexp (str)
1442 (setq c (aref str i))
1443 (cond ((or (and (>= c ?A) (<= c ?Z))
1444 (and (>= c ?a) (<= c ?z)))
1445 (setq regexp (concat regexp
1447 (char-to-string (downcase c))
1449 (char-to-string (upcase c))
1452 (setq regexp (concat regexp (char-to-string c)))))
1456 (defun Info-suffixed-file (name &optional exact)
1457 "Look for an info file named NAME. This function tries to be smart in
1458 finding the file corresponding to NAME: if it doesn't exist, several
1459 variants are looked for, notably by appending suffixes from
1460 `Info-suffix-list' and by trying to change the characters case in NAME.
1462 The optional argument EXACT prevents this function from trying different case
1463 versions of NAME. Only the suffixes are tried."
1465 ;; First, try NAME alone:
1466 (and (file-regular-p name) (throw 'found name))
1467 ;; Then, try different variants
1468 (let ((suff-match (concat "\\("
1469 (let ((suff-list Info-suffix-list)
1471 (while (setq suff (pop suff-list))
1474 (regexp-quote (car suff))
1475 (and suff-list "\\|"))))
1478 (dir (file-name-directory name))
1480 (setq name (file-name-nondirectory name))
1482 (condition-case data ;; protect against invalid directory
1483 ;; First, try NAME[.<suffix>]
1485 (directory-files dir 'fullname
1486 (concat "^" (regexp-quote name) suff-match)
1490 ;; Then, try to match the name independantly of the
1492 (directory-files dir 'fullname
1493 (Info-all-case-regexp
1499 (display-warning 'info
1500 (format "directory `%s' error: %s" dir data))
1502 (while (setq file (pop files))
1503 (and (file-regular-p file)
1504 (throw 'found file)))
1507 (defun Info-insert-file-contents (file &optional visit)
1508 (setq file (expand-file-name file default-directory))
1509 (let ((suff Info-suffix-list)
1512 (setq len (length (car (car suff))))
1513 (or (<= (length file) len)
1515 (equal (substring file (- len))
1517 (equal (substring file (- len))
1518 (upcase (car (car suff)))))
1520 (setq suff (cdr suff)))
1521 (if (stringp (cdr (car suff)))
1522 (let ((command (if (string-match "%s" (cdr (car suff)))
1523 (format (cdr (car suff)) file)
1524 (concat (cdr (car suff)) " < " file))))
1525 (message "%s..." command)
1526 (call-process shell-file-name nil t nil shell-command-switch command)
1529 (setq buffer-file-name file
1530 buffer-file-truename (file-truename buffer-file-name))
1531 (set-buffer-modified-p nil)
1532 (clear-visited-file-modtime)))
1533 (insert-file-contents file visit)
1534 ;; Often info files, especially those from FSF-land set the
1535 ;; coding system via a "Last page Local variables" at the end
1536 ;; of the file. #'insert-file-contents doesn't (rightly so)
1537 ;; process local vars. But this time we need it, so force the
1538 ;; issue and set the coding system if we find it. --SY.
1539 (hack-local-variables)
1540 (when (and-boundp 'coding
1541 (find-coding-system coding))
1542 (let ((coding-system-for-read coding))
1543 (set-buffer-file-coding-system coding)
1544 (insert-file-contents file visit nil nil t))))))
1546 (defun Info-select-node ()
1547 "Select the node that point is in, after using `g *' to select whole file."
1551 ;; Find beginning of node.
1552 (search-backward "\n\037")
1554 ;; Get nodename spelled as it is in the node.
1555 (re-search-forward "Node:[ \t]*")
1556 (setq Info-current-node
1557 (buffer-substring (point)
1559 (skip-chars-forward "^,\t\n")
1561 (Info-set-mode-line)
1562 ;; Find the end of it, and narrow.
1564 (let (active-expression)
1565 (narrow-to-region (point)
1566 (if (re-search-forward "\n[\037\f]" nil t)
1569 (if (looking-at "[\n\037\f]*execute: ")
1571 (goto-char (match-end 0))
1572 (setq active-expression
1573 (read (current-buffer))))))
1575 (or (equal Info-footnote-tag "Note")
1577 (goto-char (point-min))
1578 (let ((buffer-read-only nil)
1579 (bufmod (buffer-modified-p))
1580 (case-fold-search t))
1581 (while (re-search-forward "\\*[Nn]ote\\([ \n]\\)" nil t)
1582 (replace-match (concat "*" Info-footnote-tag "\ ")))
1583 (set-buffer-modified-p bufmod))))
1584 (Info-reannotate-node)
1585 ;; XEmacs: remove v19 test
1587 (Info-fontify-node))
1588 (run-hooks 'Info-select-hook)
1589 (if Info-enable-active-nodes (eval active-expression)))))
1591 (defun Info-set-mode-line ()
1592 (setq modeline-buffer-identification
1593 (list (cons modeline-buffer-id-left-extent "Info: ")
1594 (cons modeline-buffer-id-right-extent
1597 (if Info-current-file
1598 (let ((name (file-name-nondirectory
1599 Info-current-file)))
1600 (if (string-match #r"^\([^.]*\)\..*$" name)
1601 (match-string 1 name)
1605 (or Info-current-node ""))))))
1607 ;; Go to an info node specified with a filename-and-nodename string
1608 ;; of the sort that is found in pointers in nodes.
1611 (defun Info-goto-node (nodename &optional no-going-back tryfile)
1612 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
1613 Actually, the following interpretations of NAME are tried in order:
1615 (FILENAME) (using Top node)
1616 NODENAME (in current file)
1618 FILENAME (using Top node)
1619 where TAGNAME is a string that appears in quotes: \"TAGNAME\", in an
1620 annotation for any node of any file. (See `a' and `x' commands.)"
1621 (interactive (list (Info-read-node-name "Goto node, file or tag: ")
1624 (string-match (concat #r"\s *\((\s *\("
1626 #r"\)\s *)\s *\|\)\(.*\)")
1628 (setq filename (if (= (match-beginning 1) (match-end 1))
1630 (substring nodename (match-beginning 2) (match-end 2)))
1631 nodename (substring nodename (match-beginning 3) (match-end 3)))
1632 (let ((trim (string-match #r"\s *\'" filename)))
1633 (if trim (setq filename (substring filename 0 trim))))
1634 (let ((trim (string-match #r"\s *\'" nodename)))
1635 (if trim (setq nodename (substring nodename 0 trim))))
1636 (Info-find-node (if (equal filename "") nil filename)
1637 (if (equal nodename "") "Top" nodename)
1638 no-going-back (and tryfile (equal filename "")))))
1640 (defun Info-goto-bookmark ()
1642 (let ((completion-ignore-case nil)
1643 (tag (completing-read "Goto tag: "
1644 (Info-build-annotation-completions)
1646 'Info-minibuffer-history)))
1647 (or (equal tag "") (Info-find-node nil (format "<<%s>>" tag)))))
1650 (defun Info-visit-file (file)
1651 "Directly visit an info file."
1652 (interactive "fVisit Info file: ")
1653 (Info-find-node (expand-file-name file) "Top"))
1655 (defun Info-restore-point (&optional always)
1656 "Restore point to same location it had last time we were in this node."
1658 (if (or Info-restoring-point always)
1659 (let* ((name (format "(%s)%s"
1660 (Info-file-name-only Info-current-file)
1662 (p (assoc name Info-history)))
1663 (if p (Info-restore-history-entry p)))))
1665 (defun Info-restore-history-entry (entry)
1666 (goto-char (+ (nth 1 entry) (point-min)))
1668 (get-buffer-window (current-buffer))
1669 (set-window-start (get-buffer-window (current-buffer))
1670 (+ (nth 2 entry) (point-min)))))
1672 (defvar Info-read-node-completion-table)
1674 ;; This function is used as the "completion table" while reading a node name.
1675 ;; It does completion using the alist in Info-read-node-completion-table
1676 ;; unless STRING starts with an open-paren.
1677 (defun Info-read-node-name-1 (string predicate code)
1678 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
1679 (cond ((eq code nil)
1682 (try-completion string Info-read-node-completion-table
1687 (all-completions string Info-read-node-completion-table
1692 (assoc string Info-read-node-completion-table))))))
1694 (defun Info-read-node-name (prompt &optional default)
1695 (Info-setup-initial)
1696 (let* ((completion-ignore-case t)
1697 (Info-read-node-completion-table (Info-build-node-completions))
1698 (nodename (completing-read prompt 'Info-read-node-name-1
1699 nil t nil 'Info-minibuffer-history
1701 (if (equal nodename "")
1703 (Info-read-node-name prompt))
1706 (defun Info-build-annotation-completions ()
1707 (or Info-current-annotation-completions
1709 (let ((bufs (delq nil (mapcar 'get-file-buffer
1710 Info-annotations-path)))
1713 (set-buffer (car bufs))
1714 (goto-char (point-min))
1715 (while (re-search-forward #r"<<\(.*\)>>" nil t)
1716 (setq compl (cons (list (buffer-substring (match-beginning 1)
1719 (setq bufs (cdr bufs)))
1720 (setq Info-current-annotation-completions compl)))))
1722 (defun Info-build-node-completions ()
1723 (or Info-current-file-completions
1724 (let ((m Info-tag-table-marker)
1725 (compl (Info-build-annotation-completions)))
1729 (if (marker-buffer Info-tag-table-marker)
1731 (set-buffer (marker-buffer Info-tag-table-marker))
1733 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
1735 (cons (list (buffer-substring (match-beginning 1)
1738 (goto-char (point-min))
1739 (while (search-forward "\n\037" nil t)
1741 (let ((start (point)))
1743 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
1746 (cons (list (buffer-substring (match-beginning 1)
1749 (setq Info-current-file-completions compl))))
1751 (defvar Info-last-search nil
1752 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1756 (defun Info-search (regexp)
1757 "Search for REGEXP, starting from point, and select node it's found in."
1759 (read-from-minibuffer
1760 (if Info-last-search
1761 (format "Search (regexp, default %s): "
1763 "Search (regexp): ")
1764 nil nil nil nil nil Info-last-search)))
1765 (setq Info-last-search regexp)
1766 (with-search-caps-disable-folding regexp t
1768 (onode Info-current-node)
1769 (ofile Info-current-file)
1771 (osubfile Info-current-subfile))
1775 (if (null Info-current-subfile)
1776 (progn (re-search-forward regexp) (setq found (point)))
1778 (progn (re-search-forward regexp) (setq found (point)))
1779 (search-failed nil)))))
1781 ;; can only happen in subfile case -- else would have erred
1785 (set-buffer (marker-buffer Info-tag-table-marker))
1786 (goto-char (point-min))
1787 (search-forward "\n\037\nIndirect:")
1789 (narrow-to-region (point)
1790 (progn (search-forward "\n\037")
1792 (goto-char (point-min))
1793 (search-forward (concat "\n" osubfile ": "))
1796 (re-search-forward #r"\(^.*\): [0-9]+$")
1797 (goto-char (+ (match-end 1) 2))
1798 (setq list (cons (cons (read (current-buffer))
1803 (goto-char (1+ (match-end 0))))
1804 (setq list (nreverse list)
1807 (message "Searching subfile %s..." (cdr (car list)))
1808 (Info-read-subfile (car (car list)))
1809 (setq list (cdr list))
1810 (goto-char (point-min))
1811 (if (re-search-forward regexp nil t)
1812 (setq found (point) list ())))
1815 (signal 'search-failed (list regexp))))
1817 (progn (Info-read-subfile opoint)
1819 (Info-select-node)))))
1823 (or (and (equal onode Info-current-node)
1824 (equal ofile Info-current-file))
1825 (Info-history-add ofile onode opoint)))))
1827 ;; Extract the value of the node-pointer named NAME.
1828 ;; If there is none, use ERRORNAME in the error message;
1829 ;; if ERRORNAME is nil, just return nil.
1830 (defun Info-extract-pointer (name &optional errorname)
1832 (goto-char (point-min))
1834 (let ((case-fold-search t))
1835 (if (re-search-backward (concat name ":") nil t)
1837 (goto-char (match-end 0))
1838 (Info-following-node-name))
1839 (if (eq errorname t)
1841 (error (concat "Node has no " (capitalize (or errorname name)))))))))
1843 ;; Return the node name in the buffer following point.
1844 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1845 ;; saying which chars may appear in the node name.
1846 (defun Info-following-node-name (&optional allowedchars)
1847 (skip-chars-forward " \t")
1851 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1852 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1853 (if (looking-at "(")
1854 (skip-chars-forward "^)")))
1855 (skip-chars-backward " .")
1858 (defun Info-next (&optional n)
1859 "Go to the next node of this node.
1860 A positive or negative prefix argument moves by multiple nodes."
1865 (while (>= (setq n (1- n)) 0)
1866 (Info-goto-node (Info-extract-pointer "next")))))
1868 (defun Info-prev (&optional n)
1869 "Go to the previous node of this node.
1870 A positive or negative prefix argument moves by multiple nodes."
1875 (while (>= (setq n (1- n)) 0)
1876 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))))
1878 (defun Info-up (&optional n)
1879 "Go to the superior node of this node.
1880 A positive prefix argument moves up several times."
1883 (while (>= (setq n (1- n)) 0)
1884 (Info-goto-node (Info-extract-pointer "up")))
1885 (if (interactive-p) (Info-restore-point)))
1887 (defun Info-last (&optional n)
1888 "Go back to the last node visited.
1889 With a prefix argument, go to Nth most recently visited node. History is
1890 circular; after oldest node, history comes back around to most recent one.
1891 Argument can be negative to go through the circle in the other direction.
1892 \(In other words, `l' is like \"undo\" and `C-u - l' is like \"redo\".)"
1896 (error "This is the first Info node you looked at"))
1897 (let ((len (1+ (length Info-history))))
1898 (setq n (% (+ n (* len 100)) len)))
1900 (let ((entry (nth (1- n) Info-history)))
1901 (Info-history-add Info-current-file Info-current-node (point))
1902 (while (>= (setq n (1- n)) 0)
1903 (setq Info-history (nconc (cdr Info-history)
1904 (list (car Info-history)))))
1905 (setq Info-history (cdr Info-history))
1906 (let ((Info-keeping-history nil))
1907 (Info-goto-node (car entry)))
1908 (Info-restore-history-entry entry))))
1910 (defun Info-directory ()
1911 "Go to the Info directory node."
1913 (Info-find-node "dir" "top"))
1915 (defun Info-follow-reference (footnotename)
1916 "Follow cross reference named NAME to the node it refers to.
1917 NAME may be an abbreviation of the reference name."
1919 (let ((completion-ignore-case t)
1920 completions default (start-point (point)) str i)
1922 (goto-char (point-min))
1923 (while (re-search-forward (format "\\*%s[ \n\t]*\\([^:]*\\):"
1926 (setq str (buffer-substring
1929 ;; See if this one should be the default.
1931 (< (match-beginning 0) start-point)
1932 (<= start-point (point))
1935 (while (setq i (string-match "[ \n\t]+" str i))
1936 (setq str (concat (substring str 0 i) " "
1937 (substring str (match-end 0))))
1939 ;; Record as a completion and perhaps as default.
1940 (if (eq default t) (setq default str))
1942 (cons (cons str nil)
1945 (let ((item (completing-read (if default
1946 (concat "Follow reference named: ("
1948 "Follow reference named: ")
1949 completions nil t nil
1950 'Info-minibuffer-history
1952 (if (and (string= item "") default)
1955 (error "No cross-references in this node"))))
1956 (let (target i (str (concat "\\*" Info-footnote-tag " "
1957 (regexp-quote footnotename))))
1958 (while (setq i (string-match " " str i))
1959 (setq str (concat (substring str 0 i) "\\([ \t\n]+\\)"
1960 (substring str (1+ i))))
1963 (goto-char (point-min))
1964 (or (re-search-forward str nil t)
1965 (error "No cross-reference named %s" footnotename))
1966 (goto-char (match-end 1))
1968 (Info-extract-menu-node-name "Bad format cross reference" t)))
1969 (while (setq i (string-match "[ \t\n]+" target i))
1970 (setq target (concat (substring target 0 i) " "
1971 (substring target (match-end 0))))
1973 (Info-goto-node target)
1974 (setq Info-in-cross-reference t)))
1976 (defun Info-next-reference (n)
1978 (let ((pat (format (concat "\\*%s[ \n\t]*"
1979 #r"\([^:]*\):\|^\* .*:\|<<.*>>")
1982 wrapped found-nomenu)
1984 (unless (re-search-backward pat nil t)
1985 ;; Don't wrap more than once in a buffer where only the
1986 ;; menu references are found.
1987 (when (and wrapped (not found-nomenu))
1989 (error "No cross references in this node"))
1991 (goto-char (point-max))
1992 (unless (re-search-backward pat nil t)
1994 (error "No cross references in this node")))
1995 (unless (save-excursion
1996 (goto-char (match-beginning 0))
1997 (when (looking-at "\\* Menu:")
1999 (setq found-nomenu t))
2002 (or (eobp) (forward-char 1))
2003 (unless (re-search-forward pat nil t)
2004 (when (and wrapped (not found-nomenu))
2006 (error "No cross references in this node"))
2008 (goto-char (point-min))
2009 (unless (re-search-forward pat nil t)
2011 (error "No cross references in this node")))
2012 (unless (save-excursion
2013 (goto-char (match-beginning 0))
2014 (when (looking-at "\\* Menu:")
2016 (setq found-nomenu t))
2018 (when (looking-at "\\* Menu:")
2019 (error "No cross references in this node"))
2020 (goto-char (match-beginning 0))))
2022 (defun Info-prev-reference (n)
2024 (Info-next-reference (- n)))
2026 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
2027 (skip-chars-forward " \t\n")
2028 (let ((start (point))
2030 (skip-chars-forward "^:")
2033 (if (looking-at ":")
2034 (buffer-substring start (1- (point)))
2035 (skip-chars-forward " \t\n")
2037 ;; Allow dots in node name not followed by whitespace.
2039 (concat "\\(([^)]+)[^.,"
2040 (if multi-line "" "\n")
2042 (if multi-line "" "\n")
2043 ;; We consider dots followed by newline as
2044 ;; end of nodename even if multil-line.
2045 ;; Also stops at .). It is generated by @pxref.
2046 ;; Skips sequential dots.
2047 "]\\|\\.+[^ \t\n)]\\)+\\)"))
2049 (while (setq i (string-match "\n" str i))
2053 (defun Info-menu (menu-item)
2054 "Go to node for menu item named (or abbreviated) NAME.
2055 Completion is allowed, and the menu item point is on is the default."
2057 (let ((completions '())
2058 ;; If point is within a menu item, use that item as the default
2063 (goto-char (point-min))
2064 (let ((case-fold-search t))
2065 (if (not (search-forward "\n* menu:" nil t))
2066 (error "No menu in this node")))
2067 (while (re-search-forward
2068 "\n\\* \\([^:\t\n]*\\):" nil t)
2069 (if (and (null default)
2070 (prog1 (if last (< last p) nil)
2071 (setq last (match-beginning 0)))
2073 (setq default (car (car completions))))
2074 (setq completions (cons (cons (buffer-substring
2077 (match-beginning 1))
2079 (if (and (null default) last
2081 (<= p (progn (end-of-line) (point))))
2082 (setq default (car (car completions)))))
2085 (setq item (let ((completion-ignore-case t))
2086 (completing-read (if default
2087 (format "Menu item (default %s): "
2090 completions nil t nil
2091 'Info-minibuffer-history
2093 ;; we rely on the fact that completing-read accepts an input
2094 ;; of "" even when the require-match argument is true and ""
2095 ;; is not a valid possibility
2096 (if (string= item "")
2102 ;; there is a problem here in that if several menu items have the same
2103 ;; name you can only go to the node of the first with this command.
2104 (Info-goto-node (Info-extract-menu-item menu-item) nil t))
2106 (defun Info-extract-menu-item (menu-item &optional noerror)
2108 (goto-char (point-min))
2109 (if (let ((case-fold-search t))
2110 (search-forward "\n* menu:" nil t))
2111 (if (or (search-forward (concat "\n* " menu-item ":") nil t)
2112 (search-forward (concat "\n* " menu-item) nil t))
2116 (Info-extract-menu-node-name))
2117 (and (not noerror) (error "No such item in menu")))
2118 (and (not noerror) (error "No menu in this node")))))
2120 ;; If COUNT is nil, use the last item in the menu.
2121 (defun Info-extract-menu-counting (count &optional noerror noindex)
2123 (goto-char (point-min))
2124 (if (let ((case-fold-search t))
2125 (and (search-forward "\n* menu:" nil t)
2127 (not (string-match "\\<Index\\>" Info-current-node)))))
2128 (if (search-forward "\n* " nil t count)
2131 (while (search-forward "\n* " nil t)))
2132 (Info-extract-menu-node-name))
2133 (and (not noerror) (error "Too few items in menu")))
2134 (and (not noerror) (error "No menu in this node")))))
2136 (defun Info-nth-menu-item (n)
2137 "Go to the node of the Nth menu item."
2139 (or n (setq n (- last-command-char ?0)))
2140 (if (< n 1) (error "Index must be at least 1"))
2141 (Info-goto-node (Info-extract-menu-counting n) nil t))
2143 (defun Info-last-menu-item ()
2144 "Go to the node of the tenth menu item."
2146 (Info-goto-node (Info-extract-menu-counting nil) nil t))
2149 "Go to the Top node of this file."
2151 (Info-goto-node "Top"))
2154 "Go to the final node in this file."
2157 (let ((Info-keeping-history nil)
2159 (Info-last-menu-item)
2160 (while (setq node (or (Info-extract-pointer "next" t)
2161 (Info-extract-menu-counting nil t t)))
2162 (Info-goto-node node))
2163 (or (equal (Info-extract-pointer "up" t) "Top")
2164 (let ((executing-kbd-macro "")) ; suppress messages
2166 (Info-global-next 10000)
2169 (defun Info-global-next (&optional n)
2170 "Go to the next node in this file, traversing node structure as necessary.
2171 This works only if the Info file is structured as a hierarchy of nodes.
2172 A positive or negative prefix argument moves by multiple nodes."
2176 (Info-global-prev (- n))
2177 (while (>= (setq n (1- n)) 0)
2179 (cond ((and (string-match "^Top$" Info-current-node)
2180 (setq node (Info-extract-pointer "next" t))
2181 (Info-extract-menu-item node t))
2182 (Info-goto-node node))
2183 ((setq node (Info-extract-menu-counting 1 t t))
2184 (message "Going down...")
2185 (Info-goto-node node))
2187 (let ((Info-keeping-history Info-keeping-history)
2188 (orignode Info-current-node)
2190 (while (not (Info-extract-pointer "next" t))
2191 (if (and (setq node (Info-extract-pointer "up" t))
2192 (not (equal node "Top")))
2194 (message "Going%s..." (setq ups (concat ups " up")))
2195 (Info-goto-node node)
2196 (setq Info-keeping-history nil))
2198 (let ((Info-keeping-history nil))
2199 (Info-goto-node orignode)))
2200 (error "Last node in file")))
2203 (defun Info-page-next (&optional n)
2204 "Scroll forward one screenful, or go to next global node.
2205 A positive or negative prefix argument moves by multiple screenfuls."
2209 (Info-page-prev (- n))
2210 (while (>= (setq n (1- n)) 0)
2211 (if (pos-visible-in-window-p (point-max))
2214 (message "Node: %s" Info-current-node))
2217 (defun Info-scroll-next (arg)
2219 (if Info-auto-advance
2220 (if (and (pos-visible-in-window-p (point-max))
2221 (not (eq Info-auto-advance t))
2222 (not (eq last-command this-command)))
2223 (message "Hit %s again to go to next node"
2224 (if (= last-command-char 0)
2226 (key-description (char-to-string last-command-char))))
2228 (setq this-command 'Info))
2231 (defun Info-global-prev (&optional n)
2232 "Go to the previous node in this file, traversing structure as necessary.
2233 This works only if the Info file is structured as a hierarchy of nodes.
2234 A positive or negative prefix argument moves by multiple nodes."
2238 (Info-global-next (- n))
2239 (while (>= (setq n (1- n)) 0)
2240 (let ((upnode (Info-extract-pointer "up" t))
2241 (prevnode (Info-extract-pointer "prev[ious]*" t)))
2242 (if (or (not prevnode)
2243 (equal prevnode upnode))
2244 (if (string-match "^Top$" Info-current-node)
2245 (error "First node in file")
2246 (message "Going up...")
2248 (Info-goto-node prevnode)
2250 (Info-keeping-history nil)
2252 (while (setq node (Info-extract-menu-counting nil t t))
2253 (message "Going%s..." (setq downs (concat downs " down")))
2254 (Info-goto-node node))))))))
2256 (defun Info-page-prev (&optional n)
2257 "Scroll backward one screenful, or go to previous global node.
2258 A positive or negative prefix argument moves by multiple screenfuls."
2262 (Info-page-next (- n))
2263 (while (>= (setq n (1- n)) 0)
2264 (if (pos-visible-in-window-p (point-min))
2267 (message "Node: %s" Info-current-node)
2268 (goto-char (point-max))
2270 (move-to-window-line 0))
2273 (defun Info-scroll-prev (arg)
2275 (if Info-auto-advance
2276 (if (and (pos-visible-in-window-p (point-min))
2277 (not (eq Info-auto-advance t))
2278 (not (eq last-command this-command)))
2279 (message "Hit %s again to go to previous node"
2280 (if (mouse-event-p last-command-event)
2282 (key-description (event-key last-command-event))))
2284 (setq this-command 'Info))
2287 (defun Info-index (topic)
2288 "Look up a string in the index for this file.
2289 The index is defined as the first node in the top-level menu whose
2290 name contains the word \"Index\", plus any immediately following
2291 nodes whose names also contain the word \"Index\".
2292 If there are no exact matches to the specified topic, this chooses
2293 the first match which is a case-insensitive substring of a topic.
2294 Use the `,' command to see the other matches.
2295 Give a blank topic name to go to the Index node itself."
2296 (interactive "sIndex topic: ")
2297 (let ((pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*%s"
2298 (regexp-quote topic)
2299 "\\(.*\\)\\.[ \t]*\\([0-9]*\\)$"))
2301 (message "Searching index for `%s'..." topic)
2302 (Info-goto-node "Top")
2303 (let ((case-fold-search t))
2304 (or (search-forward "\n* menu:" nil t)
2306 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
2307 (error "No index")))
2308 (goto-char (match-beginning 1))
2309 (let ((Info-keeping-history nil)
2310 (Info-fontify (and Info-fontify (equal topic ""))))
2311 (Info-goto-node (Info-extract-menu-node-name)))
2312 (or (equal topic "")
2315 (Info-keeping-history nil)
2319 (goto-char (point-min))
2320 (while (re-search-forward pattern nil t)
2322 (cons (list (buffer-substring (match-beginning 1)
2324 (buffer-substring (match-beginning 2)
2327 (string-to-int (concat "0"
2332 (and (setq node (Info-extract-pointer "next" t))
2333 (string-match "\\<Index\\>" node)))
2334 (let ((Info-fontify nil))
2335 (Info-goto-node node)))
2339 (error "No \"%s\" in index" topic)))
2340 ;; Here it is a feature that assoc is case-sensitive.
2341 (while (setq found (assoc topic matches))
2342 (setq exact (cons found exact)
2343 matches (delq found matches)))
2344 (setq Info-index-alternatives (nconc exact (nreverse matches))
2345 Info-index-first-alternative (car Info-index-alternatives))
2346 (Info-index-next 0)))))
2348 (defun Info-index-next (num)
2349 "Go to the next matching index item from the last `i' command."
2351 (or Info-index-alternatives
2352 (error "No previous `i' command in this file"))
2354 (setq num (+ num (length Info-index-alternatives))))
2356 (setq Info-index-alternatives
2357 (nconc (cdr Info-index-alternatives)
2358 (list (car Info-index-alternatives)))
2360 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2361 (if (> (nth 3 (car Info-index-alternatives)) 0)
2362 (forward-line (nth 3 (car Info-index-alternatives)))
2363 (forward-line 3) ; don't search in headers
2364 (let ((name (car (car Info-index-alternatives))))
2365 (if (or (re-search-forward (format
2366 #r"\(Function\|Command\): %s\( \|$\)"
2367 (regexp-quote name)) nil t)
2368 (re-search-forward (format "^`%s[ ']" (regexp-quote name)) nil t)
2369 (search-forward (format "`%s'" name) nil t)
2370 (and (string-match #r"\`.*\( (.*)\)\'" name)
2372 (format "`%s'" (substring name 0 (match-beginning 1)))
2374 (search-forward name nil t))
2376 (goto-char (point-min)))))
2377 (message "Found \"%s\" in %s. %s"
2378 (car (car Info-index-alternatives))
2379 (nth 2 (car Info-index-alternatives))
2380 (if (cdr Info-index-alternatives)
2381 (if (eq (car (cdr Info-index-alternatives))
2382 Info-index-first-alternative)
2383 "(Press `,' to repeat)"
2384 (format "(Press `,' for %d more)"
2385 (- (1- (length Info-index-alternatives))
2386 (length (memq Info-index-first-alternative
2387 (cdr Info-index-alternatives))))))
2392 (defun Info-emacs-command (command)
2393 "Look up an Emacs command in the Emacs manual in the Info system.
2394 This command is designed to be used whether you are already in Info or not."
2395 (interactive "CLook up command in Emacs manual: ")
2396 (save-window-excursion
2398 (Info-find-node Info-emacs-info-file-name "Top")
2399 (Info-index (symbol-name command)))
2400 (pop-to-buffer "*info*"))
2404 (defun Info-goto-emacs-command-node (key)
2405 "Look up an Emacs command in the Emacs manual in the Info system.
2406 This command is designed to be used whether you are already in Info or not."
2407 (interactive "CLook up command in Emacs manual: ")
2408 (Info-emacs-command key))
2411 (defun Info-goto-emacs-key-command-node (key)
2412 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2413 This command is designed to be used whether you are already in Info or not."
2414 (interactive "kLook up key in Emacs manual: ")
2415 (let ((command (key-binding key)))
2416 (cond ((eq command 'keyboard-quit)
2419 (error "%s is undefined" (key-description key)))
2420 ((and (interactive-p) (eq command 'execute-extended-command))
2421 (call-interactively 'Info-goto-emacs-command-node))
2423 (Info-goto-emacs-command-node command)))))
2426 (defun Info-emacs-key (key)
2427 "Look up an Emacs key sequence in the Emacs manual in the Info system.
2428 This command is designed to be used whether you are already in Info or not."
2429 (interactive "kLook up key in Emacs manual: ")
2430 (cond ((eq (key-binding key) 'keyboard-quit)
2432 ((and (interactive-p) (eq (key-binding key) 'execute-extended-command))
2433 (call-interactively 'Info-goto-emacs-command-node))
2435 (save-window-excursion
2437 (Info-find-node Info-emacs-info-file-name "Top")
2438 (setq key (key-description key))
2440 (if (setq p (string-match "[@{}]" key))
2441 (setq key (concat (substring key 0 p) "@" (substring key p))))
2442 (if (string-match "^ESC " key)
2443 (setq key (concat "M-" (substring key 4))))
2444 (if (string-match "^M-C-" key)
2445 (setq key (concat "C-M-" (substring key 4)))))
2447 (pop-to-buffer "*info*"))))
2450 (defun Info-elisp-ref (func)
2451 "Look up an Emacs Lisp function in the Elisp manual in the Info system.
2452 This command is designed to be used whether you are already in Info or not."
2453 (interactive (let ((fn (function-at-point))
2454 (enable-recursive-minibuffers t)
2456 (setq val (completing-read
2457 (format "Look up Emacs Lisp function%s: "
2459 (format " (default %s)" fn)
2462 nil nil (and fn (symbol-name fn))))
2463 (list (if (equal val "")
2465 (save-window-excursion
2468 (Info-find-node "lispref" "Top")
2469 (error (Info-find-node "elisp" "Top")))
2470 (Info-index (symbol-name func)))
2471 (pop-to-buffer "*info*"))
2473 (defun Info-reannotate-node ()
2474 (let ((bufs (delq nil (mapcar 'get-file-buffer Info-annotations-path))))
2476 (let ((ibuf (current-buffer))
2477 (file (concat "\\(" (regexp-quote
2478 (file-name-nondirectory Info-current-file))
2479 "\\|" (regexp-quote Info-current-file) "\\)"))
2480 (node (regexp-quote Info-current-node))
2482 (goto-char (point-min))
2483 (if (search-forward "\n------ NOTE:\n" nil t)
2484 (let ((buffer-read-only nil)
2485 (bufmod (buffer-modified-p))
2487 (setq savept (copy-marker savept))
2488 (goto-char (point-min))
2489 (while (search-forward "\n------ NOTE:" nil t)
2490 (setq top (1+ (match-beginning 0)))
2491 (if (search-forward "\n------\n" nil t)
2492 (delete-region top (point)))
2494 (set-buffer-modified-p bufmod)))
2497 (set-buffer (car bufs))
2498 (goto-char (point-min))
2499 (while (re-search-forward
2501 "------ *File: *%s *Node: *%s *Line: *\\([0-9]+\\) *\n"
2504 (let ((line (string-to-int
2505 (buffer-substring (match-beginning 2)
2509 (search-forward "\n------\n" nil t)
2513 (if (integerp savept) (setq savept (copy-marker savept)))
2515 (goto-char (point-max))
2516 (goto-char (point-min))
2517 (forward-line line))
2518 (let ((buffer-read-only nil)
2519 (bufmod (buffer-modified-p)))
2520 (insert "------ NOTE:\n")
2521 (insert-buffer-substring (car bufs) top bot)
2522 (set-buffer-modified-p bufmod)))))
2523 (setq bufs (cdr bufs))))
2524 (goto-char savept)))))
2526 (defvar Info-annotate-map nil
2527 "Local keymap used within `a' command of Info.")
2529 (if Info-annotate-map
2531 ;; (setq Info-annotate-map (nconc (make-sparse-keymap) text-mode-map))
2532 (setq Info-annotate-map (copy-keymap text-mode-map))
2533 (define-key Info-annotate-map "\C-c\C-c" 'Info-cease-annotate))
2535 (defun Info-annotate-mode ()
2536 "Major mode for adding an annotation to an Info node.
2537 Like text mode with the addition of Info-cease-annotate
2538 which returns to Info mode for browsing.
2539 \\{Info-annotate-map}")
2541 (defun Info-annotate (arg)
2542 "Add a personal annotation to the current Info node.
2543 Only you will be able to see this annotation. Annotations are stored
2544 in the file \"info.notes\" in your `user-init-directory' by default. If
2545 point is inside an existing annotation, edit that annotation. A prefix
2546 argument specifies which annotations file (from `Info-annotations-path')
2547 is to be edited; default is 1."
2550 (if (or (< arg 0) (not (nth arg Info-annotations-path)))
2552 (setq Info-annotations-path
2553 (list (read-file-name
2554 "Annotations file: " "~/" "~/.infonotes")))
2555 (error "File number must be in the range from 1 to %d"
2556 (length Info-annotations-path))))
2558 (file (file-name-nondirectory Info-current-file))
2559 (d Info-directory-list)
2561 (while (and d (not (equal (expand-file-name file (car d))
2562 Info-current-file)))
2564 (or d (setq file Info-current-file))
2565 (if (and (save-excursion
2566 (goto-char (min (point-max) (+ (point) 13)))
2567 (and (search-backward "------ NOTE:\n" nil t)
2568 (setq pt (match-end 0))
2569 (search-forward "\n------\n" nil t)))
2570 (< (point) (match-end 0)))
2571 (setq which (format "File: *%s *Node: *%s *Line:.*\n%s"
2573 (regexp-quote Info-current-node)
2575 (buffer-substring pt (match-beginning 0))))
2576 where (max (- (point) pt) 0)))
2577 (let ((node Info-current-node)
2578 (line (if (looking-at "[ \n]*\\'") 0
2579 (count-lines (point-min) (point)))))
2581 (let ((buffer-read-only nil)
2582 (bufmod (buffer-modified-p)))
2584 (if (bobp) (goto-char (point-max)))
2585 (insert "------ NOTE:\n------\n")
2587 (set-buffer-modified-p bufmod)))
2588 ;; (setq Info-window-start (window-start))
2589 (setq Info-window-configuration (current-window-configuration))
2590 (pop-to-buffer (find-file-noselect (nth arg Info-annotations-path)))
2591 (use-local-map Info-annotate-map)
2592 (setq major-mode 'Info-annotate-mode)
2593 (setq mode-name "Info Annotate")
2596 (goto-char (point-min))
2597 (re-search-forward which nil t))
2599 (goto-char (match-beginning 0))
2601 (forward-char where)))
2602 (let ((bufmod (buffer-modified-p)))
2603 (goto-char (point-max))
2604 (insert (format "\n------ File: %s Node: %s Line: %d\n"
2607 (insert "\n------\n"
2608 "\nPress C-c C-c to save and return to Info.\n")
2610 (set-buffer-modified-p bufmod))))))
2612 (defun Info-cease-annotate ()
2614 (let ((bufmod (buffer-modified-p)))
2615 (while (save-excursion
2616 (goto-char (point-min))
2617 (re-search-forward "\n\n?Press .* to save and return to Info.\n"
2619 (delete-region (1+ (match-beginning 0)) (match-end 0)))
2620 (while (save-excursion
2621 (goto-char (point-min))
2622 (re-search-forward "\n------ File:.*Node:.*Line:.*\n+------\n"
2624 (delete-region (match-beginning 0) (match-end 0)))
2625 (set-buffer-modified-p bufmod))
2629 (or (one-window-p) (delete-window))
2631 (setq Info-current-annotation-completions nil)
2632 (set-window-configuration Info-window-configuration)
2633 (Info-reannotate-node))
2635 (defun Info-bookmark (arg tag)
2636 (interactive "p\nsBookmark name: ")
2638 (if (or (string-match "^\"\\(.*\\)\"$" tag)
2639 (string-match #r"^<<\(.*\)>>$" tag))
2640 (setq tag (substring tag (match-beginning 1) (match-end 1))))
2642 (search-forward "\n------\n")
2643 (let ((end (- (point) 8)))
2645 (if (re-search-forward "<<[^>\n]*>>" nil t)
2646 (delete-region (match-beginning 0) (match-end 0))
2649 (insert "<<" tag ">>"))))
2650 (Info-cease-annotate))
2653 "Exit Info by selecting some other buffer."
2656 (save-buffers-kill-emacs)
2657 (bury-buffer (current-buffer))
2658 (if (and (featurep 'toolbar)
2659 (boundp 'toolbar-info-frame)
2660 (eq toolbar-info-frame (selected-frame)))
2662 (delete-frame toolbar-info-frame)
2663 (error (bury-buffer)))
2664 (switch-to-buffer (other-buffer (current-buffer))))))
2666 (defun Info-undefined ()
2667 "Make command be undefined in Info."
2672 "Enter the Info tutorial."
2674 (delete-other-windows)
2675 (Info-find-node "info"
2676 (if (< (window-height) 23)
2680 (defun Info-summary ()
2681 "Display a brief summary of all Info commands."
2683 (save-window-excursion
2684 (switch-to-buffer "*Help*")
2686 (insert (documentation 'Info-mode))
2687 (goto-char (point-min))
2689 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2690 (message (if flag "Type Space to see more"
2691 "Type Space to return to Info"))
2692 (let ((e (next-command-event)))
2693 (if (/= ?\ (event-to-character e))
2694 (progn (setq unread-command-event e) nil)
2698 (bury-buffer "*Help*")))
2700 (defun Info-get-token (pos start all &optional errorstring)
2701 "Return the token around POS,
2702 POS must be somewhere inside the token
2703 START is a regular expression which will match the
2704 beginning of the tokens delimited string
2705 ALL is a regular expression with a single
2706 parenthized subpattern which is the token to be
2707 returned. E.g. '{\(.*\)}' would return any string
2708 enclosed in braces around POS.
2709 SIG optional fourth argument, controls action on no match
2712 a string: signal an error, using that string."
2714 (goto-char (point-min))
2715 (re-search-backward "\\`") ; Bug fix due to Nicholas J. Foskett.
2717 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
2719 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2720 (not (setq found (and (<= (match-beginning 0) pos)
2721 (> (match-end 0) pos))))))
2722 (if (and found (<= (match-beginning 0) pos)
2723 (> (match-end 0) pos))
2724 (buffer-substring (match-beginning 1) (match-end 1))
2725 (cond ((null errorstring)
2731 (error "No %s around position %d" errorstring pos)))))))
2733 (defun Info-follow-clicked-node (event)
2734 "Follow a node reference near clicked point. Like M, F, N, P or U command.
2735 At end of the node's text, moves to the next node."
2737 (or (and (event-point event)
2738 (Info-follow-nearest-node
2740 (select-window (event-window event))
2741 (event-point event))
2743 (error "click on a cross-reference to follow")))
2745 (defun Info-maybe-follow-clicked-node (event &optional click-count)
2746 "Follow a node reference (if any) near clicked point.
2747 Like M, F, N, P or U command. At end of the node's text, moves to the
2748 next node. No error is given if there is no node to follow."
2750 (and Info-button1-follows-hyperlink
2752 (Info-follow-nearest-node
2754 (select-window (event-window event))
2755 (event-point event))
2756 (1+ (point-min))))))
2758 (defun Info-find-nearest-node (point)
2761 ((= point (point-min)) nil) ; don't trigger on accidental RET.
2762 ((setq node (Info-get-token point
2763 (format "\\*%s[ \n]" Info-footnote-tag)
2764 (format "\\*%s[ \n]\\([^:]*\\):"
2765 Info-footnote-tag)))
2766 (list "Following cross-reference %s..."
2767 (list 'Info-follow-reference node)))
2768 ((setq node (Info-get-token point "\\* " #r"\* \([^:]*\)::"))
2769 (list "Selecting menu item %s..."
2770 (list 'Info-goto-node node nil t)))
2771 ((setq node (Info-get-token point "\\* " #r"\* \([^:]*\):"))
2772 (list "Selecting menu item %s..."
2773 (list 'Info-menu node)))
2774 ((setq node (Info-get-token point "Up: " "Up: \\([^,\n\t]*\\)"))
2776 (list 'Info-goto-node node)))
2777 ((setq node (Info-get-token point "Next: " "Next: \\([^,\n\t]*\\)"))
2778 (list "Next node..."
2779 (list 'Info-goto-node node)))
2780 ((setq node (Info-get-token point "File: " "File: \\([^,\n\t]*\\)"))
2782 (list 'Info-goto-node "Top")))
2783 ((setq node (Info-get-token point "Prev[ious]*: "
2784 "Prev[ious]*: \\([^,\n\t]*\\)"))
2785 (list "Previous node..."
2786 (list 'Info-goto-node node)))
2787 ((setq node (Info-get-token point "Node: " "Node: \\([^,\n\t]*\\)"))
2788 (list "Reselecting %s..."
2789 (list 'Info-goto-node node)))
2790 ((save-excursion (goto-char point) (looking-at "[ \n]*\\'"))
2791 (if Info-in-cross-reference
2792 (list "Back to last node..."
2794 (list "Next node..."
2795 '(Info-global-next)))))
2798 (defun Info-follow-nearest-node (point)
2799 "Follow a node reference near point. Like M, F, N, P or U command.
2800 At end of the node's text, moves to the next node."
2802 (let ((data (Info-find-nearest-node point)))
2805 (let ((msg (format (car data) (nth 1 (nth 1 data)))))
2808 (message "%sdone" msg))
2811 (defun Info-indicated-node (event)
2814 (cond ((eventp event)
2815 (set-buffer (event-buffer event))
2816 (setq event (event-point event))))
2817 (let* ((data (Info-find-nearest-node event))
2818 (name (nth 1 (nth 1 data))))
2819 (and name (nth 1 data))))
2822 (defun Info-mouse-track-double-click-hook (event click-count)
2823 "Handle double-clicks by turning pages, like the `gv' ghostscript viewer"
2824 (if (/= click-count 2)
2825 ;; Return nil so any other hooks are performed.
2827 (let* ((fw (face-width 'default))
2828 (fh (face-height 'default))
2829 (x (/ (event-x-pixel event) fw))
2830 (y (/ (event-y-pixel event) fw))
2831 (w (/ (window-pixel-width (event-window event)) fw))
2832 (h (/ (window-pixel-height (event-window event)) fh))
2836 ((<= y by) (Info-up) t)
2837 ((>= y (- h by)) (Info-nth-menu-item 1) t)
2838 ((<= x bx) (Info-prev) t)
2839 ((>= x (- w bx)) (Info-next) t)
2842 (defvar Info-mode-map nil
2843 "Keymap containing Info commands.")
2847 (setq Info-mode-map (make-sparse-keymap))
2848 (suppress-keymap Info-mode-map)
2849 (define-key Info-mode-map "." 'beginning-of-buffer)
2850 (define-key Info-mode-map " " 'Info-scroll-next)
2851 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2852 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2853 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2854 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2855 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2856 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2857 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2858 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2859 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2860 (define-key Info-mode-map "0" 'Info-last-menu-item)
2861 (define-key Info-mode-map "?" 'Info-summary)
2862 (define-key Info-mode-map "a" 'Info-annotate)
2863 (define-key Info-mode-map "b" 'beginning-of-buffer)
2864 (define-key Info-mode-map "d" 'Info-directory)
2865 (define-key Info-mode-map "e" 'Info-edit)
2866 (define-key Info-mode-map "f" 'Info-follow-reference)
2867 (define-key Info-mode-map "g" 'Info-goto-node)
2868 (define-key Info-mode-map "h" 'Info-help)
2869 (define-key Info-mode-map "i" 'Info-index)
2870 (define-key Info-mode-map "j" 'Info-goto-bookmark)
2871 (define-key Info-mode-map "k" 'Info-emacs-key)
2872 (define-key Info-mode-map "l" 'Info-last)
2873 (define-key Info-mode-map "m" 'Info-menu)
2874 (define-key Info-mode-map "n" 'Info-next)
2875 (define-key Info-mode-map "p" 'Info-prev)
2876 (define-key Info-mode-map "q" 'Info-exit)
2877 (define-key Info-mode-map "r" 'Info-follow-reference)
2878 (define-key Info-mode-map "s" 'Info-search)
2879 (define-key Info-mode-map "t" 'Info-top)
2880 (define-key Info-mode-map "u" 'Info-up)
2881 (define-key Info-mode-map "v" 'Info-visit-file)
2882 (define-key Info-mode-map "x" 'Info-bookmark)
2883 (define-key Info-mode-map "<" 'Info-top)
2884 (define-key Info-mode-map ">" 'Info-end)
2885 (define-key Info-mode-map "[" 'Info-global-prev)
2886 (define-key Info-mode-map "]" 'Info-global-next)
2887 (define-key Info-mode-map "{" 'Info-page-prev)
2888 (define-key Info-mode-map "}" 'Info-page-next)
2889 (define-key Info-mode-map "=" 'Info-restore-point)
2890 (define-key Info-mode-map "!" 'Info-select-node)
2891 (define-key Info-mode-map "@" 'Info-follow-nearest-node)
2892 (define-key Info-mode-map "," 'Info-index-next)
2893 (define-key Info-mode-map "*" 'Info-elisp-ref)
2894 (define-key Info-mode-map [tab] 'Info-next-reference)
2895 (define-key Info-mode-map [(meta tab)] 'Info-prev-reference)
2896 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2897 (define-key Info-mode-map "\r" 'Info-follow-nearest-node)
2899 (define-key Info-mode-map 'backspace 'Info-scroll-prev)
2900 (define-key Info-mode-map 'delete 'Info-scroll-prev)
2901 (define-key Info-mode-map 'button2 'Info-follow-clicked-node)
2902 (define-key Info-mode-map 'button3 'Info-select-node-menu))
2905 ;; Info mode is suitable only for specially formatted data.
2906 (put 'info-mode 'mode-class 'special)
2909 "Info mode is for browsing through the Info documentation tree.
2910 Documentation in Info is divided into \"nodes\", each of which
2911 discusses one topic and contains references to other nodes
2912 which discuss related topics. Info has commands to follow
2913 the references and show you other nodes.
2915 h Invoke the Info tutorial.
2916 q Quit Info: return to the previously selected file or buffer.
2918 Selecting other nodes:
2919 n Move to the \"next\" node of this node.
2920 p Move to the \"previous\" node of this node.
2921 m Pick menu item specified by name (or abbreviation).
2922 1-9, 0 Pick first..ninth, last item in node's menu.
2923 Menu items select nodes that are \"subsections\" of this node.
2924 u Move \"up\" from this node (i.e., from a subsection to a section).
2925 f or r Follow a cross reference by name (or abbrev). Type `l' to get back.
2926 RET Follow cross reference or menu item indicated by cursor.
2927 i Look up a topic in this file's Index and move to that node.
2928 , (comma) Move to the next match from a previous `i' command.
2929 l (letter L) Move back to the last node you were in.
2931 Moving within a node:
2932 Space Scroll forward a full screen. DEL Scroll backward.
2933 b Go to beginning of node. Meta-> Go to end of node.
2934 TAB Go to next cross-reference. Meta-TAB Go to previous ref.
2937 Left Button Set point (usual text-mode functionality)
2938 Middle Button Click on a highlighted node reference to go to it.
2939 Right Button Pop up a menu of applicable Info commands.
2941 Left Button Double Click in window edges:
2942 Top edge: Go up to the parent node, like `u'.
2943 Left edge: Go to the previous node, like `p'.
2944 Right edge: Go to the next node, like `n'.
2945 Bottom edge: Follow first menu item, like `1'.
2948 g Move to node, file, or annotation tag specified by name.
2949 Examples: `g Rectangles' `g (Emacs)Rectangles' `g Emacs'.
2950 v Move to file, with filename completion.
2951 k Look up a key sequence in Emacs manual (also C-h C-k at any time).
2952 * Look up a function name in Emacs Lisp manual (also C-h C-f).
2953 d Go to the main directory of Info files.
2954 < or t Go to Top (first) node of this file.
2955 > Go to last node in this file.
2956 \[ Go to previous node, treating file as one linear document.
2957 \] Go to next node, treating file as one linear document.
2958 { Scroll backward, or go to previous node if at top.
2959 } Scroll forward, or go to next node if at bottom.
2960 = Restore cursor position from last time in this node.
2961 a Add a private note (annotation) to the current node.
2962 x, j Add, jump to a bookmark (annotation tag).
2963 s Search this Info file for a node containing the specified regexp.
2964 e Edit the contents of the current node."
2965 (kill-all-local-variables)
2966 (setq major-mode 'Info-mode)
2967 (setq mode-name "Info")
2968 (use-local-map Info-mode-map)
2969 (set-syntax-table text-mode-syntax-table)
2970 (setq local-abbrev-table text-mode-abbrev-table)
2971 (setq case-fold-search t)
2972 (setq buffer-read-only t)
2973 ; (setq buffer-mouse-map Info-mode-mouse-map)
2974 (make-local-variable 'Info-current-file)
2975 (make-local-variable 'Info-current-subfile)
2976 (make-local-variable 'Info-current-node)
2977 (make-local-variable 'Info-tag-table-marker)
2978 (setq Info-tag-table-marker (make-marker))
2979 (make-local-variable 'Info-tag-table-buffer)
2980 (setq Info-tag-table-buffer nil)
2981 (make-local-variable 'Info-current-file-completions)
2982 (make-local-variable 'Info-current-annotation-completions)
2983 (make-local-variable 'Info-index-alternatives)
2984 (make-local-variable 'Info-history)
2985 ;; Faces are now defined by `defface'...
2986 (make-local-variable 'mouse-track-click-hook)
2987 (add-hook 'mouse-track-click-hook 'Info-maybe-follow-clicked-node)
2988 (add-hook 'mouse-track-click-hook 'Info-mouse-track-double-click-hook)
2989 ;; #### The console-on-window-system-p check is to allow this to
2990 ;; work on tty's. The real problem here is that featurep really
2991 ;; needs to have some device/console domain knowledge added to it.
2992 (defvar info::toolbar)
2993 (if (and (featurep 'toolbar)
2994 (console-on-window-system-p)
2995 (not Info-inhibit-toolbar))
2996 (set-specifier default-toolbar (cons (current-buffer) info::toolbar)))
2997 (if (featurep 'menubar)
2999 ;; make a local copy of the menubar, so our modes don't
3000 ;; change the global menubar
3001 (easy-menu-add '("Info" :filter Info-menu-filter))))
3002 (run-hooks 'Info-mode-hook)
3003 (Info-set-mode-line))
3005 (defvar Info-edit-map nil
3006 "Local keymap used within `e' command of Info.")
3010 ;; XEmacs: remove FSF stuff
3011 (setq Info-edit-map (make-sparse-keymap))
3012 (set-keymap-name Info-edit-map 'Info-edit-map)
3013 (set-keymap-parents Info-edit-map (list text-mode-map))
3014 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
3016 ;; Info-edit mode is suitable only for specially formatted data.
3017 (put 'info-edit-mode 'mode-class 'special)
3019 (defun Info-edit-mode ()
3020 "Major mode for editing the contents of an Info node.
3021 Like text mode with the addition of `Info-cease-edit'
3022 which returns to Info mode for browsing.
3027 "Edit the contents of this Info node.
3028 Allowed only if variable `Info-enable-edit' is non-nil."
3030 (or Info-enable-edit
3031 (error "Editing info nodes is not enabled"))
3032 (use-local-map Info-edit-map)
3033 (setq major-mode 'Info-edit-mode)
3034 (setq mode-name "Info Edit")
3035 (kill-local-variable 'modeline-buffer-identification)
3036 (setq buffer-read-only nil)
3037 ;; Make mode line update.
3038 (set-buffer-modified-p (buffer-modified-p))
3039 (message (substitute-command-keys
3040 "Editing: Type \\[Info-cease-edit] to return to info")))
3042 (defun Info-cease-edit ()
3043 "Finish editing Info node; switch back to Info proper."
3045 ;; Do this first, so nothing has changed if user C-g's at query.
3046 (and (buffer-modified-p)
3047 (y-or-n-p "Save the file? ")
3049 (use-local-map Info-mode-map)
3050 (setq major-mode 'Info-mode)
3051 (setq mode-name "Info")
3052 (Info-set-mode-line)
3053 (setq buffer-read-only t)
3054 ;; Make mode line update.
3055 (set-buffer-modified-p (buffer-modified-p))
3056 (and (marker-position Info-tag-table-marker)
3058 (message "Tags may have changed. Use Info-tagify if necessary")))
3060 (defun Info-find-emacs-command-nodes (command)
3061 "Return a list of locations documenting COMMAND in the SXEmacs Info manual.
3062 The locations are of the format used in Info-history, i.e.
3063 \(FILENAME NODENAME BUFFERPOS\)."
3065 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
3066 #r":\s *\(.*\)\.")))
3068 (Info-find-node "SXEmacs" "Command Index")
3069 ;; Take the index node off the Info history.
3070 ;; ??? says this isn't safe someplace else... hmmm.
3071 (setq Info-history (cdr Info-history))
3072 (goto-char (point-max))
3073 (while (re-search-backward cmd-desc nil t)
3074 (setq where (cons (list Info-current-file
3082 ;;; fontification and mousability for info
3084 (defun Info-highlight-region (start end face)
3086 (splitp (string-match "\n[ \t]+" (buffer-substring start end))))
3089 (setq extent (make-extent start (progn (goto-char start)
3092 (set-extent-face extent face)
3093 (set-extent-property extent 'info t)
3094 (set-extent-property extent 'highlight t)
3095 (skip-chars-forward "\n\t ")
3096 (setq extent (make-extent (point) end)))
3097 (setq extent (make-extent start end)))
3098 (set-extent-face extent face)
3099 (set-extent-property extent 'info t)
3100 (set-extent-property extent 'highlight t)))
3102 (defun Info-fontify-node ()
3104 (let ((case-fold-search t)
3105 (xref-regexp (concat "\\*"
3106 (regexp-quote Info-footnote-tag)
3107 "[ \n\t]*\\([^:]*\\):")))
3108 ;; Clear the old extents
3109 (map-extents #'(lambda (x y) (delete-extent x))
3110 (current-buffer) (point-min) (point-max) nil)
3111 ;; Break the top line iff it is > 79 characters. Some info nodes
3112 ;; have top lines that span 3 lines because of long node titles.
3113 ;; eg: (Info-find-node "lispref.info" "Window-Level Event Position Info")
3114 (toggle-read-only -1)
3119 (goto-char (point-min))
3120 (re-search-forward "Node: *[^,]+, " nil t)
3121 (setq len (- (point) (point-min))
3122 extent (make-extent (point-min) (point)))
3123 (set-extent-property extent 'invisible t)
3127 (if (< (current-column) (+ 78 len))
3130 (forward-char (+ 79 len))
3131 (re-search-backward "," nil t)
3135 (delete-backward-char 1)
3138 (toggle-read-only 1)
3139 ;; Highlight xrefs in the top few lines of the node
3140 (goto-char (point-min))
3141 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
3143 (goto-char (match-end 0))
3145 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?\n?")
3146 (goto-char (match-end 0))
3147 (Info-highlight-region (match-beginning 1) (match-end 1)
3149 ;; Now get the xrefs in the body
3150 (goto-char (point-min))
3151 (while (re-search-forward xref-regexp nil t)
3152 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
3154 (Info-highlight-region (match-beginning 1) (match-end 1)
3156 ;; then highlight the nodes in the menu.
3157 (goto-char (point-min))
3158 (if (and (search-forward "\n* menu:" nil t))
3159 (while (re-search-forward
3160 "^\\* \\([^:\t\n]*\\):?:[ \t\n]" nil t)
3161 (Info-highlight-region (match-beginning 1) (match-end 1)
3163 (set-buffer-modified-p nil))))
3165 (defun Info-construct-menu (&optional event)
3166 "Construct a menu of Info commands.
3167 Adds an entry for the node at EVENT, or under point if EVENT is omitted.
3168 Used to construct the menubar submenu and popup menu."
3169 (or event (setq event (point)))
3170 (let ((case-fold-search t)
3171 (xref-regexp (concat "\\*"
3172 (regexp-quote Info-footnote-tag)
3173 "[ \n\t]*\\([^:]*\\):"))
3174 up-p prev-p next-p menu xrefs subnodes in)
3176 ;; `one-space' fixes "Notes:" xrefs that are split across lines.
3180 (while (setq i (string-match "[ \n\t]+" text i))
3181 (setq text (concat (substring text 0 i) " "
3182 (substring text (match-end 0))))
3185 (goto-char (point-min))
3186 (if (looking-at ".*\\bNext:") (setq next-p t))
3187 (if (looking-at ".*\\bPrev:") (setq prev-p t))
3188 (if (looking-at ".*Up:") (setq up-p t))
3190 (if (setq in (Info-indicated-node event))
3191 (list (vector (one-space (cadr in)) in t)
3192 "--:shadowEtchedIn"))
3194 ["Goto Info Top-level" Info-directory]
3195 (vector "Next Node" 'Info-next :active next-p)
3196 (vector "Previous Node" 'Info-prev :active prev-p)
3197 (vector "Parent Node (Up)" 'Info-up :active up-p)
3198 ["Goto Node..." Info-goto-node]
3199 ["Goto Last Visited Node " Info-last])))
3200 ;; Find the xrefs and make a list
3201 (while (re-search-forward xref-regexp nil t)
3202 (setq xrefs (cons (one-space (buffer-substring (match-beginning 1)
3205 (setq xrefs (nreverse xrefs))
3206 (if (> (length xrefs) 21) (setcdr (nthcdr 20 xrefs) '(more)))
3207 ;; Find the subnodes and make a list
3208 (goto-char (point-min))
3209 (if (search-forward "\n* menu:" nil t)
3210 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
3211 (setq subnodes (cons (buffer-substring (match-beginning 1)
3214 (setq subnodes (nreverse subnodes))
3215 (if (> (length subnodes) 21) (setcdr (nthcdr 20 subnodes) '(more))))
3217 (nconc menu (list "--:shadowDoubleEtchedIn"
3220 (mapcar #'(lambda (xref)
3224 (list 'Info-follow-reference xref))))
3227 (nconc menu (list "--:shadowDoubleEtchedIn"
3230 (mapcar #'(lambda (node)
3233 (vector node (list 'Info-menu node))))
3237 (defun Info-menu-filter (menu)
3238 "This is the menu filter for the \"Info\" submenu."
3239 (Info-construct-menu))
3241 (defun Info-select-node-menu (event)
3242 "Pops up a menu of applicable Info commands."
3244 (select-window (event-window event))
3245 (let ((menu (Info-construct-menu event)))
3246 (setq menu (nconc (list "Info" ; title: not displayed
3248 "--:shadowDoubleEtchedOut")
3250 (let ((popup-menu-titles nil))
3251 (popup-menu menu))))
3253 ;;; Info toolbar support
3255 ;; exit icon taken from GNUS
3256 (defvar info::toolbar-exit-icon
3257 (if (featurep 'toolbar)
3258 (toolbar-make-button-list
3259 (expand-file-name (if (featurep 'xpm) "info-exit.xpm" "info-exit.xbm")
3260 toolbar-icon-directory)))
3263 (defvar info::toolbar-up-icon
3264 (if (featurep 'toolbar)
3265 (toolbar-make-button-list
3266 (expand-file-name (if (featurep 'xpm) "info-up.xpm" "info-up.xbm")
3267 toolbar-icon-directory)))
3270 (defvar info::toolbar-next-icon
3271 (if (featurep 'toolbar)
3272 (toolbar-make-button-list
3273 (expand-file-name (if (featurep 'xpm) "info-next.xpm" "info-next.xbm")
3274 toolbar-icon-directory)))
3277 (defvar info::toolbar-prev-icon
3278 (if (featurep 'toolbar)
3279 (toolbar-make-button-list
3280 (expand-file-name (if (featurep 'xpm) "info-prev.xpm" "info-prev.xbm")
3281 toolbar-icon-directory)))
3284 (defvar info::toolbar
3285 (if (featurep 'toolbar)
3286 ; disabled until we get the next/prev-win icons working again.
3287 ; (cons (first initial-toolbar-spec)
3288 ; (cons (second initial-toolbar-spec)
3289 '([info::toolbar-exit-icon
3293 [info::toolbar-next-icon
3296 "Next entry in same section"]
3297 [info::toolbar-prev-icon
3300 "Prev entry in same section"]
3301 [info::toolbar-up-icon
3304 "Up entry to enclosing section"]
3310 (run-hooks 'Info-load-hook)
3312 ;;; info.el ends here