Revision: miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-572
[bpt/emacs.git] / lisp / info.el
CommitLineData
55535639 1;;; info.el --- info package for Emacs
e5167999 2
83040cb0 3;; Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
0d30b337 4;; 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3a801d0c 5
e5167999 6;; Maintainer: FSF
fd7fa35a 7;; Keywords: help
e5167999 8
a384cab3
JB
9;; This file is part of GNU Emacs.
10
11;; GNU Emacs is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
e5167999 13;; the Free Software Foundation; either version 2, or (at your option)
a384cab3
JB
14;; any later version.
15
16;; GNU Emacs is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
b578f267 22;; along with GNU Emacs; see the file COPYING. If not, write to the
086add15
LK
23;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24;; Boston, MA 02110-1301, USA.
a384cab3 25
e5167999
ER
26;;; Commentary:
27
185cff95 28;; Note that nowadays we expect Info files to be made using makeinfo.
921e5fe6
TTN
29;; In particular we make these assumptions:
30;; - a menu item MAY contain colons but not colon-space ": "
31;; - a menu item ending with ": " (but not ":: ") is an index entry
32;; - a node name MAY NOT contain a colon
505b68d5
TTN
33;; This distinction is to support indexing of computer programming
34;; language terms that may contain ":" but not ": ".
e5167999
ER
35
36;;; Code:
37
bc6262c8
DL
38(eval-when-compile (require 'jka-compr))
39
ded3e3d8 40(defgroup info nil
fc039bdc 41 "Info subsystem."
ded3e3d8
RS
42 :group 'help
43 :group 'docs)
44
45
a384cab3 46(defvar Info-history nil
185cff95 47 "Stack of Info nodes user has visited.
db90d225 48Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
a384cab3 49
424b9d3e 50(defvar Info-history-forward nil
185cff95 51 "Stack of Info nodes user has visited with `Info-history-back' command.
db90d225 52Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
424b9d3e 53
8a7757f6 54(defvar Info-history-list nil
185cff95 55 "List of all Info nodes user has visited.
db90d225 56Each element of the list is a list (FILENAME NODENAME).")
8a7757f6 57
ded3e3d8 58(defcustom Info-enable-edit nil
d5913bf6 59 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
185cff95 60This is convenient if you want to write Info files by hand.
ada0a60d
RS
61However, we recommend that you not do this.
62It is better to write a Texinfo file and generate the Info file from that,
ded3e3d8
RS
63because that gives you a printed manual as well."
64 :type 'boolean
65 :group 'info)
a384cab3 66
67f445d7 67(defvar Info-enable-active-nodes nil
a384cab3
JB
68 "Non-nil allows Info to execute Lisp code associated with nodes.
69The Lisp code is executed when the node is selected.")
67f445d7 70(put 'Info-enable-active-nodes 'risky-local-variable t)
a384cab3 71
93480d70 72(defface info-node
508bce68
SM
73 '((((class color) (background light)) :foreground "brown" :weight bold :slant italic)
74 (((class color) (background dark)) :foreground "white" :weight bold :slant italic)
75 (t :weight bold :slant italic))
93480d70
RS
76 "Face for Info node names."
77 :group 'info)
78
185cff95
JL
79(defface info-title-1
80 '((((type tty pc) (class color) (background light))
81 :foreground "green" :weight bold)
82 (((type tty pc) (class color) (background dark))
83 :foreground "yellow" :weight bold)
84 (t :height 1.2 :inherit info-title-2))
85 "Face for info titles at level 1."
86 :group 'info)
87;; backward-compatibility alias
88(put 'Info-title-1-face 'face-alias 'info-title-1)
89
90(defface info-title-2
91 '((((type tty pc) (class color)) :foreground "lightblue" :weight bold)
92 (t :height 1.2 :inherit info-title-3))
93 "Face for info titles at level 2."
94 :group 'info)
95;; backward-compatibility alias
96(put 'Info-title-2-face 'face-alias 'info-title-2)
97
98(defface info-title-3
99 '((((type tty pc) (class color)) :weight bold)
100 (t :height 1.2 :inherit info-title-4))
101 "Face for info titles at level 3."
102 :group 'info)
103;; backward-compatibility alias
104(put 'Info-title-3-face 'face-alias 'info-title-3)
105
106(defface info-title-4
107 '((((type tty pc) (class color)) :weight bold)
108 (t :weight bold :inherit variable-pitch))
109 "Face for info titles at level 4."
110 :group 'info)
111;; backward-compatibility alias
112(put 'Info-title-4-face 'face-alias 'info-title-4)
113
114(defface info-menu-header
115 '((((type tty pc))
116 :underline t
117 :weight bold)
118 (t
119 :inherit variable-pitch
120 :weight bold))
121 "Face for headers in Info menus."
122 :group 'info)
123
124(defface info-menu-star
508bce68
SM
125 '((((class color)) :foreground "red1")
126 (t :underline t))
ccfb7415 127 "Face for every third `*' in an Info menu."
93480d70 128 :group 'info)
185cff95 129(put 'info-menu-5 'face-alias 'info-menu-star)
93480d70
RS
130
131(defface info-xref
e37c1854 132 '((((min-colors 88)
ea81d57e
DN
133 (class color) (background light)) :foreground "blue1" :underline t)
134 (((class color) (background light)) :foreground "blue" :underline t)
e37c1854 135 (((min-colors 88)
ea81d57e 136 (class color) (background dark)) :foreground "cyan1" :underline t)
cc3f6c32 137 (((class color) (background dark)) :foreground "cyan" :underline t)
508bce68 138 (t :underline t))
93480d70
RS
139 "Face for Info cross-references."
140 :group 'info)
141
8a7757f6 142(defface info-xref-visited
6b3600ff 143 '((default :inherit info-xref)
508bce68 144 (((class color) (background light)) :foreground "magenta4")
71672328 145 (((class color) (background dark)) :foreground "violet"))
8a7757f6
JL
146 "Face for visited Info cross-references."
147 :group 'info)
148
149(defcustom Info-fontify-visited-nodes t
185cff95 150 "*Non-nil to fontify references to visited nodes in `info-xref-visited' face."
bf247b6e 151 :version "22.1"
8a7757f6
JL
152 :type 'boolean
153 :group 'info)
154
88ef7f62 155(defcustom Info-fontify-maximum-menu-size 100000
ccfb7415 156 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
ded3e3d8
RS
157 :type 'integer
158 :group 'info)
bdf62a4d 159
50ac70af 160(defcustom Info-use-header-line t
c3717746 161 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
50ac70af
MB
162A header-line does not scroll with the rest of the buffer."
163 :type 'boolean
164 :group 'info)
165
166(defface info-header-xref
508bce68 167 '((t :inherit info-xref))
50ac70af
MB
168 "Face for Info cross-references in a node header."
169 :group 'info)
170
171(defface info-header-node
508bce68 172 '((t :inherit info-node))
50ac70af
MB
173 "Face for Info nodes in a node header."
174 :group 'info)
175
7d3766a8 176(defvar Info-directory-list nil
a384cab3 177 "List of directories to search for Info documentation files.
fc4d14c5 178If nil, meaning not yet initialized, Info uses the environment
44c327f9 179variable INFOPATH to initialize it, or `Info-default-directory-list'
dde7f979
SM
180if there is no INFOPATH variable in the environment, or the
181concatenation of the two if INFOPATH ends with a colon.
778911b9
EZ
182
183When `Info-directory-list' is initialized from the value of
4dddb0b7
EZ
184`Info-default-directory-list', and Emacs is installed in one of the
185standard directories, the directory of Info files that come with Emacs
186is put last (so that local Info files override standard ones).
187
188When `Info-directory-list' is initialized from the value of
189`Info-default-directory-list', and Emacs is not installed in one
190of the standard directories, the first element of the resulting
778911b9
EZ
191list is the directory where Emacs installs the Info files that
192come with it. This is so that Emacs's own manual, which suits the
4dddb0b7
EZ
193version of Emacs you are using, will always be found first. This
194is useful when you install an experimental version of Emacs without
195removing the standard installation.
196
197If you want to override the order of directories in
198`Info-default-directory-list', set INFOPATH in the environment.
5da0f945
RS
199
200If you run the Emacs executable from the `src' directory in the Emacs
778911b9
EZ
201source tree, and INFOPATH is not defined, the `info' directory in the
202source tree is used as the first element of `Info-directory-list', in
203place of the installation Info directory. This is useful when you run
204a version of Emacs without installing it.")
a384cab3 205
ded3e3d8 206(defcustom Info-additional-directory-list nil
bdf62a4d 207 "List of additional directories to search for Info documentation files.
e9b1d996 208These directories are searched after those in `Info-directory-list'."
ded3e3d8
RS
209 :type '(repeat directory)
210 :group 'info)
bdf62a4d 211
610bc96b 212(defcustom Info-scroll-prefer-subnodes nil
7a53d8c8 213 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
185cff95 214
7a53d8c8
EZ
215If this is non-nil, and you scroll far enough in a node that its menu
216appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
217moves to a subnode indicated by the following menu item. This means
218that you visit a subnode before getting to the end of the menu.
219
220Setting this option to nil results in behavior similar to the stand-alone
221Info reader program, which visits the first subnode from the menu only
222when you hit the end of the current node."
bf247b6e 223 :version "22.1"
7a53d8c8
EZ
224 :type 'boolean
225 :group 'info)
226
a9efebd0 227(defcustom Info-hide-note-references t
5f812a3c 228 "*If non-nil, hide the tag and section reference in *note and * menu items.
8a7757f6 229If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
185cff95
JL
230If value is non-nil but not t or `hide', the reference section is still shown.
231`nil' completely disables this feature."
bf247b6e 232 :version "22.1"
8a7757f6 233 :type '(choice (const :tag "No hiding" nil)
0452a274 234 (const :tag "Replace tag and hide reference" t)
8a7757f6
JL
235 (const :tag "Hide tag and reference" hide)
236 (other :tag "Only replace tag" tag))
a9efebd0
KS
237 :group 'info)
238
bb1e1730
KS
239(defcustom Info-refill-paragraphs nil
240 "*If non-nil, attempt to refill paragraphs with hidden references.
185cff95 241This refilling may accidentally remove explicit line breaks in the Info
bb1e1730 242file, so be prepared for a few surprises if you enable this feature."
bf247b6e 243 :version "22.1"
bb1e1730
KS
244 :type 'boolean
245 :group 'info)
246
180ee7c7 247(defcustom Info-search-whitespace-regexp "\\s-+"
8a7757f6
JL
248 "*If non-nil, regular expression to match a sequence of whitespace chars.
249This applies to Info search for regular expressions.
250You might want to use something like \"[ \\t\\r\\n]+\" instead.
251In the Customization buffer, that is `[' followed by a space,
252a tab, a carriage return (control-M), a newline, and `]+'."
253 :type 'regexp
254 :group 'info)
255
98e77be5 256(defcustom Info-isearch-search t
6270bbe7
JL
257 "*If non-nil, isearch in Info searches through multiple nodes.
258Before leaving the initial Info node, where isearch was started,
259it fails once with the error message [initial node], and with
260subsequent C-s/C-r continues through other nodes without failing
261with this error message in other nodes. When isearch fails for
262the rest of the manual, it wraps aroung the whole manual and
263restarts the search from the top/final node depending on
264search direction.
265
266Setting this option to nil restores the default isearch behavior
267with wrapping around the current Info node."
98e77be5
JL
268 :version "22.1"
269 :type 'boolean
270 :group 'info)
271
d457219d
JL
272(defvar Info-isearch-initial-node nil)
273
dde7f979
SM
274(defcustom Info-mode-hook
275 ;; Try to obey obsolete Info-fontify settings.
276 (unless (and (boundp 'Info-fontify) (null Info-fontify))
277 '(turn-on-font-lock))
8a7757f6
JL
278 "Hooks run when `Info-mode' is called."
279 :type 'hook
280 :group 'info)
281
282(defcustom Info-selection-hook nil
283 "Hooks run when `Info-select-node' is called."
544e5562
CW
284 :type 'hook
285 :group 'info)
286
8a7757f6
JL
287(defvar Info-edit-mode-hook nil
288 "Hooks run when `Info-edit-mode' is called.")
289
a384cab3 290(defvar Info-current-file nil
d6be34f3
RS
291 "Info file that Info is now looking at, or nil.
292This is the name that was specified in Info, not the actual file name.
4fceda3c
SM
293It doesn't contain directory names or file name extensions added by Info.
294Can also be t when using `Info-on-current-buffer'.")
a384cab3
JB
295
296(defvar Info-current-subfile nil
fdf4b680 297 "Info subfile that is actually in the *info* buffer now.
185cff95 298nil if current Info file is not split into subfiles.")
a384cab3
JB
299
300(defvar Info-current-node nil
301 "Name of node that Info is now looking at, or nil.")
302
c5fe2ff1 303(defvar Info-tag-table-marker nil
a384cab3
JB
304 "Marker pointing at beginning of current Info file's tag table.
305Marker points nowhere if file has no tag table.")
306
c5fe2ff1
RS
307(defvar Info-tag-table-buffer nil
308 "Buffer used for indirect tag tables.")
309
552775bd
RS
310(defvar Info-current-file-completions nil
311 "Cached completion list for current Info file.")
312
1143a6b0 313(defvar Info-index-alternatives nil
fdf4b680 314 "List of possible matches for last `Info-index' command.")
1143a6b0 315
836bb478
JL
316(defvar Info-point-loc nil
317 "Point location within a selected node.
318If string, the point is moved to the proper occurrence of the
319name of the followed cross reference within a selected node.
320If number, the point is moved to the corresponding line.")
8a7757f6 321
552775bd
RS
322(defvar Info-standalone nil
323 "Non-nil if Emacs was started solely as an Info browser.")
7d3766a8 324\f
bd0c9168 325(defvar Info-suffix-list
3c19e6c1
RS
326 ;; The MS-DOS list should work both when long file names are
327 ;; supported (Windows 9X), and when only 8+3 file names are available.
bd0c9168
RS
328 (if (eq system-type 'ms-dos)
329 '( (".gz" . "gunzip")
330 (".z" . "gunzip")
544e210f 331 (".bz2" . ("bzip2" "-dc"))
3c19e6c1
RS
332 (".inz" . "gunzip")
333 (".igz" . "gunzip")
334 (".info.Z" . "gunzip")
335 (".info.gz" . "gunzip")
336 ("-info.Z" . "gunzip")
337 ("-info.gz" . "gunzip")
338 ("/index.gz". "gunzip")
339 ("/index.z" . "gunzip")
9b842cab 340 (".inf" . nil)
3c19e6c1
RS
341 (".info" . nil)
342 ("-info" . nil)
343 ("/index" . nil)
bd0c9168 344 ("" . nil))
a70dc410
RS
345 '( (".info.Z". "uncompress")
346 (".info.Y". "unyabba")
347 (".info.gz". "gunzip")
348 (".info.z". "gunzip")
544e210f 349 (".info.bz2" . ("bzip2" "-dc"))
a70dc410
RS
350 (".info". nil)
351 ("-info.Z". "uncompress")
352 ("-info.Y". "unyabba")
353 ("-info.gz". "gunzip")
544e210f 354 ("-info.bz2" . ("bzip2" "-dc"))
a70dc410
RS
355 ("-info.z". "gunzip")
356 ("-info". nil)
357 ("/index.Z". "uncompress")
358 ("/index.Y". "unyabba")
359 ("/index.gz". "gunzip")
360 ("/index.z". "gunzip")
544e210f 361 ("/index.bz2". ("bzip2" "-dc"))
a70dc410
RS
362 ("/index". nil)
363 (".Z". "uncompress")
364 (".Y". "unyabba")
365 (".gz". "gunzip")
366 (".z". "gunzip")
544e210f 367 (".bz2" . ("bzip2" "-dc"))
a70dc410 368 ("". nil)))
1143a6b0
ER
369 "List of file name suffixes and associated decoding commands.
370Each entry should be (SUFFIX . STRING); the file is given to
544e210f
KH
371the command as standard input.
372
373STRING may be a list of strings. In that case, the first element is
374the command name, and the rest are arguments to that command.
375
376If STRING is nil, no decoding is done.
97f99202
KH
377Because the SUFFIXes are tried in order, the empty string should
378be last in the list.")
1143a6b0 379
c8e9dd54 380;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
e0c1e774
EZ
381;; First, on MS-DOS with no long file names support, delete some of
382;; the extension in FILENAME to make room.
383(defun info-insert-file-contents-1 (filename suffix lfn)
384 (if lfn ; long file names are supported
bd0c9168
RS
385 (concat filename suffix)
386 (let* ((sans-exts (file-name-sans-extension filename))
c8e9dd54
RS
387 ;; How long is the extension in FILENAME (not counting the dot).
388 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
389 ext-left)
9b842cab 390 ;; SUFFIX starts with a dot. If FILENAME already has one,
1583fe94 391 ;; get rid of the one in SUFFIX (unless suffix is empty).
c8e9dd54 392 (or (and (<= ext-len 0)
9b842cab 393 (not (eq (aref filename (1- (length filename))) ?.)))
1583fe94 394 (= (length suffix) 0)
9b842cab 395 (setq suffix (substring suffix 1)))
c8e9dd54
RS
396 ;; How many chars of that extension should we keep?
397 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
bd0c9168
RS
398 ;; Get rid of the rest of the extension, and add SUFFIX.
399 (concat (substring filename 0 (- (length filename)
400 (- ext-len ext-left)))
401 suffix))))
402
9c7924d5
RS
403(defun info-file-exists-p (filename)
404 (and (file-exists-p filename)
405 (not (file-directory-p filename))))
406
1143a6b0 407(defun info-insert-file-contents (filename &optional visit)
185cff95 408 "Insert the contents of an Info file in the current buffer.
1143a6b0 409Do the right thing if the file has been compressed or zipped."
e0c1e774 410 (let* ((tail Info-suffix-list)
ab5a535c
KS
411 (lfn (if (fboundp 'msdos-long-file-names)
412 (msdos-long-file-names)
413 t))
e0c1e774
EZ
414 (check-short (and (fboundp 'msdos-long-file-names)
415 lfn))
416 fullname decoder done)
b8fa4e87 417 (if (info-file-exists-p filename)
bd0c9168
RS
418 ;; FILENAME exists--see if that name contains a suffix.
419 ;; If so, set DECODE accordingly.
97f99202
KH
420 (progn
421 (while (and tail
422 (not (string-match
423 (concat (regexp-quote (car (car tail))) "$")
424 filename)))
425 (setq tail (cdr tail)))
426 (setq fullname filename
427 decoder (cdr (car tail))))
bd0c9168 428 ;; Try adding suffixes to FILENAME and see if we can find something.
e0c1e774
EZ
429 (while (and tail (not done))
430 (setq fullname (info-insert-file-contents-1 filename
431 (car (car tail)) lfn))
432 (if (info-file-exists-p fullname)
433 (setq done t
434 ;; If we found a file with a suffix, set DECODER
435 ;; according to the suffix.
436 decoder (cdr (car tail)))
437 ;; When the MS-DOS port runs on Windows, we need to check
438 ;; the short variant of a long file name as well.
439 (when check-short
440 (setq fullname (info-insert-file-contents-1 filename
441 (car (car tail)) nil))
442 (if (info-file-exists-p fullname)
443 (setq done t
444 decoder (cdr (car tail))))))
97f99202 445 (setq tail (cdr tail)))
97f99202 446 (or tail
bd0c9168 447 (error "Can't find %s or any compressed version of it" filename)))
e175bda2
RS
448 ;; check for conflict with jka-compr
449 (if (and (featurep 'jka-compr)
450 (jka-compr-installed-p)
451 (jka-compr-get-compression-info fullname))
452 (setq decoder nil))
97f99202 453 (if decoder
3c19e6c1
RS
454 (progn
455 (insert-file-contents-literally fullname visit)
456 (let ((buffer-read-only nil)
457 (coding-system-for-write 'no-conversion)
458 (default-directory (or (file-name-directory fullname)
459 default-directory)))
544e210f
KH
460 (or (consp decoder)
461 (setq decoder (list decoder)))
462 (apply 'call-process-region (point-min) (point-max)
463 (car decoder) t t nil (cdr decoder))))
3c19e6c1 464 (insert-file-contents fullname visit))))
7d3766a8 465\f
3a59b662
SM
466(defun Info-default-dirs ()
467 (let ((source (expand-file-name "info/" source-directory))
468 (sibling (if installation-directory
469 (expand-file-name "info/" installation-directory)
470 (if invocation-directory
471 (let ((infodir (expand-file-name
472 "../info/"
473 invocation-directory)))
474 (if (file-exists-p infodir)
475 infodir
476 (setq infodir (expand-file-name
477 "../../../info/"
478 invocation-directory))
479 (and (file-exists-p infodir)
480 infodir))))))
481 alternative)
482 (setq alternative
483 (if (and sibling (file-exists-p sibling))
484 ;; Uninstalled, Emacs builddir != srcdir.
485 sibling
486 ;; Uninstalled, builddir == srcdir
487 source))
488 (if (or (member alternative Info-default-directory-list)
489 ;; On DOS/NT, we use movable executables always,
490 ;; and we must always find the Info dir at run time.
491 (if (memq system-type '(ms-dos windows-nt))
492 nil
493 ;; Use invocation-directory for Info
494 ;; only if we used it for exec-directory also.
495 (not (string= exec-directory
496 (expand-file-name "lib-src/"
497 installation-directory))))
498 (not (file-exists-p alternative)))
499 Info-default-directory-list
500 ;; `alternative' contains the Info files that came with this
501 ;; version, so we should look there first. `Info-insert-dir'
502 ;; currently expects to find `alternative' first on the list.
503 (cons alternative
a025fccf
SM
504 ;; Don't drop the last part, it might contain non-Emacs stuff.
505 ;; (reverse (cdr (reverse
506 Info-default-directory-list)))) ;; )))
3a59b662 507
7d3766a8 508(defun info-initialize ()
fdf4b680 509 "Initialize `Info-directory-list', if that hasn't been done yet."
7d3766a8 510 (unless Info-directory-list
3a59b662 511 (let ((path (getenv "INFOPATH")))
7d3766a8 512 (setq Info-directory-list
78e7e8a0
MB
513 (prune-directory-list
514 (if path
3a59b662
SM
515 (if (string-match ":\\'" path)
516 (append (split-string (substring path 0 -1)
517 (regexp-quote path-separator))
518 (Info-default-dirs))
519 (split-string path (regexp-quote path-separator)))
520 (Info-default-dirs)))))))
1143a6b0 521
a6e4564e
RS
522;;;###autoload
523(defun info-other-window (&optional file)
524 "Like `info' but show the Info buffer in another window."
525 (interactive (if current-prefix-arg
526 (list (read-file-name "Info file name: " nil nil t))))
836bb478 527 (let (same-window-buffer-names same-window-regexps)
a6e4564e 528 (info file)))
399c88ad 529
836bb478 530;;;###autoload (add-hook 'same-window-regexps "\\*info\\*\\(\\|<[0-9]+>\\)")
211d6309 531
cc3f6c32 532;;;###autoload (put 'info 'info-file "emacs")
a384cab3 533;;;###autoload
836bb478 534(defun info (&optional file buffer)
a384cab3
JB
535 "Enter Info, the documentation browser.
536Optional argument FILE specifies the file to examine;
537the default is the top-level directory of Info.
83d5c772
DL
538Called from a program, FILE may specify an Info node of the form
539`(FILENAME)NODENAME'.
836bb478
JL
540Optional argument BUFFER specifies the Info buffer name;
541the default buffer name is *info*. If BUFFER exists,
542just switch to BUFFER. Otherwise, create a new buffer
543with the top-level Info directory.
a384cab3 544
836bb478
JL
545In interactive use, a non-numeric prefix argument directs
546this command to read a file name from the minibuffer.
bc224645
JL
547A numeric prefix argument selects an Info buffer with the prefix number
548appended to the Info buffer name.
e341dab2
RS
549
550The search path for Info files is in the variable `Info-directory-list'.
399c88ad 551The top-level Info directory is made by combining all the files named `dir'
e341dab2 552in all the directories in that path."
836bb478
JL
553 (interactive (list
554 (if (and current-prefix-arg (not (numberp current-prefix-arg)))
555 (read-file-name "Info file name: " nil nil t))
556 (if (numberp current-prefix-arg)
557 (format "*info*<%s>" current-prefix-arg))))
558 (pop-to-buffer (or buffer "*info*"))
559 (if (and buffer (not (eq major-mode 'Info-mode)))
560 (Info-mode))
a384cab3 561 (if file
60705054
SM
562 ;; If argument already contains parentheses, don't add another set
563 ;; since the argument will then be parsed improperly. This also
564 ;; has the added benefit of allowing node names to be included
565 ;; following the parenthesized filename.
83040cb0
SM
566 (Info-goto-node
567 (if (and (stringp file) (string-match "(.*)" file))
568 file
569 (concat "(" file ")")))
60705054 570 (if (zerop (buffer-size))
89b064a9 571 (Info-directory))))
a384cab3 572
c3717746
RS
573;;;###autoload
574(defun info-emacs-manual ()
3a8803c0 575 "Display the Emacs manual in Info mode."
c3717746
RS
576 (interactive)
577 (info "emacs"))
578
552775bd
RS
579;;;###autoload
580(defun info-standalone ()
581 "Run Emacs as a standalone Info reader.
582Usage: emacs -f info-standalone [filename]
583In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
584 (setq Info-standalone t)
585 (if (and command-line-args-left
586 (not (string-match "^-" (car command-line-args-left))))
587 (condition-case err
588 (progn
589 (info (car command-line-args-left))
590 (setq command-line-args-left (cdr command-line-args-left)))
591 (error (send-string-to-terminal
592 (format "%s\n" (if (eq (car-safe err) 'error)
593 (nth 1 err) err)))
594 (save-buffers-kill-emacs)))
595 (info)))
7d3766a8 596\f
983dfbf8 597;; See if the accessible portion of the buffer begins with a node
11638562
EZ
598;; delimiter, and the node header line which follows matches REGEXP.
599;; Typically, this test will be followed by a loop that examines the
600;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
601;; to have the overhead of this special test inside the loop.
602
603;; This function changes match-data, but supposedly the caller might
604;; want to use the results of re-search-backward.
605
606;; The return value is the value of point at the beginning of matching
983dfbf8 607;; REGEXP, if the function succeeds, nil otherwise.
11638562 608(defun Info-node-at-bob-matching (regexp)
760d5cb3
GM
609 (and (bobp) ; are we at beginning of buffer?
610 (looking-at "\^_") ; does it begin with node delimiter?
11638562
EZ
611 (let (beg)
612 (forward-line 1)
613 (setq beg (point))
760d5cb3 614 (forward-line 1) ; does the line after delimiter match REGEXP?
11638562
EZ
615 (re-search-backward regexp beg t))))
616
8a7757f6
JL
617(defun Info-find-file (filename &optional noerror)
618 "Return expanded FILENAME, or t, if FILENAME is \"dir\".
619Optional second argument NOERROR, if t, means if file is not found
620just return nil (no error)."
a384cab3
JB
621 ;; Convert filename to lower case if not found as specified.
622 ;; Expand it.
4fceda3c 623 (if (stringp filename)
a384cab3 624 (let (temp temp-downcase found)
37a3ff5b 625 (setq filename (substitute-in-file-name filename))
89b064a9 626 (cond
ab2f22ad
JH
627 ((string= (downcase filename) "dir")
628 (setq found t))
629 ((string= filename "apropos")
630 (setq found 'apropos))
89b064a9
JL
631 ((string= filename "history")
632 (setq found 'history))
633 ((string= filename "toc")
634 (setq found 'toc))
ab2f22ad
JH
635 (t
636 (let ((dirs (if (string-match "^\\./" filename)
37a3ff5b
RS
637 ;; If specified name starts with `./'
638 ;; then just try current directory.
639 '("./")
640 (if (file-name-absolute-p filename)
641 ;; No point in searching for an
642 ;; absolute file name
643 '(nil)
644 (if Info-additional-directory-list
645 (append Info-directory-list
646 Info-additional-directory-list)
647 Info-directory-list)))))
648 ;; Search the directory list for file FILENAME.
649 (while (and dirs (not found))
650 (setq temp (expand-file-name filename (car dirs)))
651 (setq temp-downcase
652 (expand-file-name (downcase filename) (car dirs)))
653 ;; Try several variants of specified name.
e0c1e774 654 (let ((suffix-list Info-suffix-list)
ab5a535c
KS
655 (lfn (if (fboundp 'msdos-long-file-names)
656 (msdos-long-file-names)
657 t)))
37a3ff5b
RS
658 (while (and suffix-list (not found))
659 (cond ((info-file-exists-p
660 (info-insert-file-contents-1
e0c1e774 661 temp (car (car suffix-list)) lfn))
37a3ff5b
RS
662 (setq found temp))
663 ((info-file-exists-p
664 (info-insert-file-contents-1
e0c1e774
EZ
665 temp-downcase (car (car suffix-list)) lfn))
666 (setq found temp-downcase))
667 ((and (fboundp 'msdos-long-file-names)
668 lfn
669 (info-file-exists-p
670 (info-insert-file-contents-1
671 temp (car (car suffix-list)) nil)))
672 (setq found temp)))
37a3ff5b 673 (setq suffix-list (cdr suffix-list))))
ab2f22ad 674 (setq dirs (cdr dirs))))))
37a3ff5b
RS
675 (if found
676 (setq filename found)
8a7757f6
JL
677 (if noerror
678 (setq filename nil)
679 (error "Info file %s does not exist" filename)))
680 filename)))
681
682(defun Info-find-node (filename nodename &optional no-going-back)
185cff95 683 "Go to an Info node specified as separate FILENAME and NODENAME.
8a7757f6
JL
684NO-GOING-BACK is non-nil if recovering from an error in this function;
685it says do not attempt further (recursive) error recovery."
686 (info-initialize)
687 (setq filename (Info-find-file filename))
185cff95 688 ;; Go into Info buffer.
6270bbe7 689 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
37a3ff5b
RS
690 ;; Record the node we are leaving.
691 (if (and Info-current-file (not no-going-back))
692 (setq Info-history
693 (cons (list Info-current-file Info-current-node (point))
694 Info-history)))
4fceda3c
SM
695 (Info-find-node-2 filename nodename no-going-back))
696
697(defun Info-on-current-buffer (&optional nodename)
185cff95 698 "Use the `Info-mode' to browse the current Info buffer.
4fceda3c 699If a prefix arg is provided, it queries for the NODENAME which
07e91aa3 700else defaults to \"Top\"."
4fceda3c
SM
701 (interactive
702 (list (if current-prefix-arg
703 (completing-read "Node name: " (Info-build-node-completions)
07e91aa3
SM
704 nil t "Top"))))
705 (unless nodename (setq nodename "Top"))
75296efc 706 (info-initialize)
4fceda3c
SM
707 (Info-mode)
708 (set (make-local-variable 'Info-current-file) t)
709 (Info-find-node-2 nil nodename))
710
f584b4c7
RS
711;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
712;; but at least it keeps this routine (which is only for the benefit of
713;; makeinfo-buffer) out of the way of normal operations.
714;;
715(defun Info-revert-find-node (filename nodename)
185cff95 716 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
f584b4c7
RS
717When *info* is already displaying FILENAME and NODENAME, the window position
718is preserved, if possible."
719 (pop-to-buffer "*info*")
720 (let ((old-filename Info-current-file)
721 (old-nodename Info-current-node)
722 (pcolumn (current-column))
723 (pline (count-lines (point-min) (line-beginning-position)))
724 (wline (count-lines (point-min) (window-start)))
725 (old-history Info-history)
726 (new-history (and Info-current-file
727 (list Info-current-file Info-current-node (point)))))
728 (kill-buffer (current-buffer))
729 (Info-find-node filename nodename)
730 (setq Info-history old-history)
731 (if (and (equal old-filename Info-current-file)
732 (equal old-nodename Info-current-node))
733 (progn
734 ;; note goto-line is no good, we want to measure from point-min
cb7de2e7 735 (goto-char (point-min))
f584b4c7
RS
736 (forward-line wline)
737 (set-window-start (selected-window) (point))
cb7de2e7 738 (goto-char (point-min))
f584b4c7
RS
739 (forward-line pline)
740 (move-to-column pcolumn))
741 ;; only add to the history when coming from a different file+node
742 (if new-history
743 (setq Info-history (cons new-history Info-history))))))
744
357d11de
GM
745(defun Info-find-in-tag-table-1 (marker regexp case-fold)
746 "Find a node in a tag table.
747MARKER specifies the buffer and position to start searching at.
748REGEXP is a regular expression matching nodes or references. Its first
749group should match `Node:' or `Ref:'.
750CASE-FOLD t means search for a case-insensitive match.
751If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
752FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
753where the match was found, and MODE is `major-mode' of the buffer in
754which the match was found."
dde7f979 755 (let ((case-fold-search case-fold))
357d11de
GM
756 (save-excursion
757 (set-buffer (marker-buffer marker))
758 (goto-char marker)
921e5fe6 759
357d11de
GM
760 ;; Search tag table
761 (beginning-of-line)
762 (when (re-search-forward regexp nil t)
763 (list (string-equal "Ref:" (match-string 1))
365d2503 764 (+ (point-min) (read (current-buffer)))
357d11de
GM
765 major-mode)))))
766
767(defun Info-find-in-tag-table (marker regexp)
768 "Find a node in a tag table.
769MARKER specifies the buffer and position to start searching at.
770REGEXP is a regular expression matching nodes or references. Its first
771group should match `Node:' or `Ref:'.
772If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
773FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
774where the match was found, and MODE is `major-mode' of the buffer in
775which the match was found.
776This function tries to find a case-sensitive match first, then a
777case-insensitive match is tried."
778 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
779 (when (null (car result))
780 (setq result (Info-find-in-tag-table-1 marker regexp t)))
781 result))
782
783(defun Info-find-node-in-buffer-1 (regexp case-fold)
784 "Find a node or anchor in the current buffer.
785REGEXP is a regular expression matching nodes or references. Its first
786group should match `Node:' or `Ref:'.
787CASE-FOLD t means search for a case-insensitive match.
788Value is the position at which a match was found, or nil if not found."
789 (let ((case-fold-search case-fold)
790 found)
791 (save-excursion
792 (when (Info-node-at-bob-matching regexp)
793 (setq found (point)))
794 (while (and (not found)
795 (search-forward "\n\^_" nil t))
796 (forward-line 1)
797 (let ((beg (point)))
798 (forward-line 1)
799 (when (re-search-backward regexp beg t)
800 (beginning-of-line)
801 (setq found (point)))))
802 found)))
921e5fe6 803
357d11de
GM
804(defun Info-find-node-in-buffer (regexp)
805 "Find a node or anchor in the current buffer.
806REGEXP is a regular expression matching nodes or references. Its first
807group should match `Node:' or `Ref:'.
808Value is the position at which a match was found, or nil if not found.
809This function looks for a case-sensitive match first. If none is found,
810a case-insensitive match is tried."
811 (or (Info-find-node-in-buffer-1 regexp nil)
812 (Info-find-node-in-buffer-1 regexp t)))
921e5fe6 813
4fceda3c 814(defun Info-find-node-2 (filename nodename &optional no-going-back)
9e5c2f50 815 (buffer-disable-undo (current-buffer))
a384cab3
JB
816 (or (eq major-mode 'Info-mode)
817 (Info-mode))
818 (widen)
819 (setq Info-current-node nil)
820 (unwind-protect
8bdf4b20
KH
821 (let ((case-fold-search t)
822 anchorpos)
37a3ff5b
RS
823 ;; Switch files if necessary
824 (or (null filename)
825 (equal Info-current-file filename)
826 (let ((buffer-read-only nil))
827 (setq Info-current-file nil
828 Info-current-subfile nil
829 Info-current-file-completions nil
830 buffer-file-name nil)
831 (erase-buffer)
ab2f22ad
JH
832 (cond
833 ((eq filename t)
834 (Info-insert-dir))
835 ((eq filename 'apropos)
836 (insert-buffer-substring " *info-apropos*"))
89b064a9
JL
837 ((eq filename 'history)
838 (insert-buffer-substring " *info-history*"))
839 ((eq filename 'toc)
840 (insert-buffer-substring " *info-toc*"))
ab2f22ad 841 (t
f7d5479b 842 (info-insert-file-contents filename nil)
ab2f22ad 843 (setq default-directory (file-name-directory filename))))
37a3ff5b
RS
844 (set-buffer-modified-p nil)
845 ;; See whether file has a tag table. Record the location if yes.
846 (goto-char (point-max))
847 (forward-line -8)
848 ;; Use string-equal, not equal, to ignore text props.
849 (if (not (or (string-equal nodename "*")
850 (not
851 (search-forward "\^_\nEnd tag table\n" nil t))))
852 (let (pos)
853 ;; We have a tag table. Find its beginning.
854 ;; Is this an indirect file?
855 (search-backward "\nTag table:\n")
856 (setq pos (point))
857 (if (save-excursion
858 (forward-line 2)
859 (looking-at "(Indirect)\n"))
860 ;; It is indirect. Copy it to another buffer
861 ;; and record that the tag table is in that buffer.
862 (let ((buf (current-buffer))
863 (tagbuf
864 (or Info-tag-table-buffer
865 (generate-new-buffer " *info tag table*"))))
866 (setq Info-tag-table-buffer tagbuf)
867 (save-excursion
868 (set-buffer tagbuf)
9e5c2f50 869 (buffer-disable-undo (current-buffer))
37a3ff5b
RS
870 (setq case-fold-search t)
871 (erase-buffer)
872 (insert-buffer-substring buf))
873 (set-marker Info-tag-table-marker
874 (match-end 0) tagbuf))
875 (set-marker Info-tag-table-marker pos)))
876 (set-marker Info-tag-table-marker nil))
877 (setq Info-current-file
ab2f22ad
JH
878 (cond
879 ((eq filename t) "dir")
880 ((eq filename 'apropos) "apropos")
89b064a9
JL
881 ((eq filename 'history) "history")
882 ((eq filename 'toc) "toc")
ab2f22ad
JH
883 (t filename)))
884 ))
37a3ff5b
RS
885 ;; Use string-equal, not equal, to ignore text props.
886 (if (string-equal nodename "*")
887 (progn (setq Info-current-node nodename)
888 (Info-set-mode-line))
889 ;; Possibilities:
890 ;;
891 ;; 1. Anchor found in tag table
892 ;; 2. Anchor *not* in tag table
893 ;;
894 ;; 3. Node found in tag table
895 ;; 4. Node *not* found in tag table, but found in file
896 ;; 5. Node *not* in tag table, and *not* in file
897 ;;
898 ;; *Or* the same, but in an indirect subfile.
899
900 ;; Search file for a suitable node.
8bdf4b20 901 (let ((guesspos (point-min))
357d11de 902 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
4ce5c223 903 (if (stringp nodename)
dd31e4e8
GM
904 (regexp-quote nodename)
905 "")
dde7f979 906 "\\) *[,\t\n\177]")))
37a3ff5b 907
82172606 908 (catch 'foo
921e5fe6 909
82172606 910 ;; First, search a tag table, if any
357d11de
GM
911 (when (marker-position Info-tag-table-marker)
912 (let* ((m Info-tag-table-marker)
913 (found (Info-find-in-tag-table m regexp)))
921e5fe6 914
357d11de
GM
915 (when found
916 ;; FOUND is (ANCHOR POS MODE).
917 (setq guesspos (nth 1 found))
921e5fe6 918
357d11de
GM
919 ;; If this is an indirect file, determine which
920 ;; file really holds this node and read it in.
921 (unless (eq (nth 2 found) 'Info-mode)
922 ;; Note that the current buffer must be the
923 ;; *info* buffer on entry to
924 ;; Info-read-subfile. Thus the hackery above.
925 (setq guesspos (Info-read-subfile guesspos)))
82172606
DL
926
927 ;; Handle anchor
357d11de
GM
928 (when (nth 0 found)
929 (goto-char (setq anchorpos guesspos))
930 (throw 'foo t)))))
82172606
DL
931
932 ;; Else we may have a node, which we search for:
933 (goto-char (max (point-min)
934 (- (byte-to-position guesspos) 1000)))
921e5fe6 935
357d11de
GM
936 ;; Now search from our advised position (or from beg of
937 ;; buffer) to find the actual node. First, check
938 ;; whether the node is right where we are, in case the
939 ;; buffer begins with a node.
940 (let ((pos (Info-find-node-in-buffer regexp)))
941 (when pos
942 (goto-char pos)
141b49f5
JL
943 (throw 'foo t)))
944
945 (when (string-match "\\([^.]+\\)\\." nodename)
946 (let (Info-point-loc)
947 (Info-find-node-2
948 filename (match-string 1 nodename) no-going-back))
949 (widen)
950 (throw 'foo t))
951
952 ;; No such anchor in tag table or node in tag table or file
953 (error "No such node or anchor: %s" nodename))
82172606
DL
954
955 (Info-select-node)
8a7757f6
JL
956 (goto-char (point-min))
957 (cond (anchorpos
958 (let ((new-history (list Info-current-file
959 (substring-no-properties nodename))))
960 ;; Add anchors to the history too
961 (setq Info-history-list
962 (cons new-history
963 (delete new-history Info-history-list))))
964 (goto-char anchorpos))
836bb478
JL
965 ((numberp Info-point-loc)
966 (forward-line (1- Info-point-loc))
967 (setq Info-point-loc nil))
968 ((stringp Info-point-loc)
969 (Info-find-index-name Info-point-loc)
970 (setq Info-point-loc nil))))))
a384cab3
JB
971 ;; If we did not finish finding the specified node,
972 ;; go back to the previous one.
4db579ab 973 (or Info-current-node no-going-back (null Info-history)
37a3ff5b
RS
974 (let ((hist (car Info-history)))
975 (setq Info-history (cdr Info-history))
976 (Info-find-node (nth 0 hist) (nth 1 hist) t)
977 (goto-char (nth 2 hist))))))
a384cab3 978
44c327f9
JB
979;; Cache the contents of the (virtual) dir file, once we have merged
980;; it for the first time, so we can save time subsequently.
7ea13762
RS
981(defvar Info-dir-contents nil)
982
44c327f9
JB
983;; Cache for the directory we decided to use for the default-directory
984;; of the merged dir text.
985(defvar Info-dir-contents-directory nil)
986
c142ab2d
RS
987;; Record the file attributes of all the files from which we
988;; constructed Info-dir-contents.
989(defvar Info-dir-file-attributes nil)
990
4fba3b2c
RS
991(defvar Info-dir-file-name nil)
992
7ea13762 993;; Construct the Info directory node by merging the files named `dir'
44c327f9
JB
994;; from various directories. Set the *info* buffer's
995;; default-directory to the first directory we actually get any text
996;; from.
7ea13762 997(defun Info-insert-dir ()
c142ab2d
RS
998 (if (and Info-dir-contents Info-dir-file-attributes
999 ;; Verify that none of the files we used has changed
1000 ;; since we used it.
1001 (eval (cons 'and
b461e32d
SM
1002 (mapcar (lambda (elt)
1003 (let ((curr (file-attributes
1004 ;; Handle symlinks
1005 (file-truename (car elt)))))
1006
1007 ;; Don't compare the access time.
1008 (if curr (setcar (nthcdr 4 curr) 0))
1009 (setcar (nthcdr 4 (cdr elt)) 0)
1010 (equal (cdr elt) curr)))
c142ab2d 1011 Info-dir-file-attributes))))
4fba3b2c
RS
1012 (progn
1013 (insert Info-dir-contents)
1014 (goto-char (point-min)))
dd31e4e8 1015 (let ((dirs (if Info-additional-directory-list
b34dcc82
RS
1016 (append Info-directory-list
1017 Info-additional-directory-list)
1018 Info-directory-list))
1bd19a31 1019 (dir-file-attrs nil)
1bcedb3b
RS
1020 ;; Bind this in case the user sets it to nil.
1021 (case-fold-search t)
4fba3b2c
RS
1022 ;; This is set non-nil if we find a problem in some input files.
1023 problems
f4008b6e 1024 buffers buffer others nodes dirs-done)
44c327f9
JB
1025
1026 ;; Search the directory list for the directory file.
7ea13762 1027 (while dirs
8d1abb42
RS
1028 (let ((truename (file-truename (expand-file-name (car dirs)))))
1029 (or (member truename dirs-done)
1030 (member (directory-file-name truename) dirs-done)
1031 ;; Try several variants of specified name.
1032 ;; Try upcasing, appending `.info', or both.
825d6f08
RS
1033 (let* (file
1034 (attrs
1035 (or
1036 (progn (setq file (expand-file-name "dir" truename))
1037 (file-attributes file))
1038 (progn (setq file (expand-file-name "DIR" truename))
1039 (file-attributes file))
1040 (progn (setq file (expand-file-name "dir.info" truename))
1041 (file-attributes file))
1042 (progn (setq file (expand-file-name "DIR.INFO" truename))
1043 (file-attributes file)))))
8d1abb42
RS
1044 (setq dirs-done
1045 (cons truename
1046 (cons (directory-file-name truename)
1047 dirs-done)))
825d6f08
RS
1048 (if attrs
1049 (save-excursion
1050 (or buffers
1051 (message "Composing main Info directory..."))
2d41cf59 1052 (set-buffer (generate-new-buffer " info dir"))
9d499629
RS
1053 (condition-case nil
1054 (progn
1055 (insert-file-contents file)
1bd19a31
MB
1056 (set (make-local-variable 'Info-dir-file-name)
1057 file)
6af7040d 1058 (push (current-buffer) buffers)
1bd19a31 1059 (push (cons file attrs) dir-file-attrs))
9d499629 1060 (error (kill-buffer (current-buffer))))))))
1bd19a31
MB
1061 (unless (cdr dirs)
1062 (set (make-local-variable 'Info-dir-contents-directory)
1063 (file-name-as-directory (car dirs))))
825d6f08 1064 (setq dirs (cdr dirs))))
399c88ad 1065
4db579ab 1066 (or buffers
81e14cb2 1067 (error "Can't find the Info directory node"))
1bd19a31 1068
44c327f9 1069 ;; Distinguish the dir file that comes with Emacs from all the
f4008b6e 1070 ;; others. Yes, that is really what this is supposed to do.
f601cd3e
DL
1071 ;; The definition of `Info-directory-list' puts it first on that
1072 ;; list and so last in `buffers' at this point.
1073 (setq buffer (car (last buffers))
1074 others (delq buffer buffers))
44c327f9 1075
debcea0c
KH
1076 ;; Insert the entire original dir file as a start; note that we've
1077 ;; already saved its default directory to use as the default
1078 ;; directory for the whole concatenation.
69672704 1079 (save-excursion (insert-buffer-substring buffer))
44c327f9 1080
7ea13762 1081 ;; Look at each of the other buffers one by one.
6af7040d
SM
1082 (dolist (other others)
1083 (let (this-buffer-nodes)
7ea13762 1084 ;; In each, find all the menus.
6af7040d 1085 (with-current-buffer other
7ea13762
RS
1086 (goto-char (point-min))
1087 ;; Find each menu, and add an elt to NODES for it.
1088 (while (re-search-forward "^\\* Menu:" nil t)
6af7040d
SM
1089 (while (and (zerop (forward-line 1)) (eolp)))
1090 (let ((beg (point))
1091 nodename end)
1092 (re-search-backward "^\^_")
7ea13762 1093 (search-forward "Node: ")
89b064a9 1094 (setq nodename (Info-following-node-name))
3a6ade8a 1095 (search-forward "\n\^_" nil 'move)
7ea13762
RS
1096 (beginning-of-line)
1097 (setq end (point))
6af7040d 1098 (push (list nodename other beg end) this-buffer-nodes)))
9f4aee27 1099 (if (assoc-string "top" this-buffer-nodes t)
4fba3b2c
RS
1100 (setq nodes (nconc this-buffer-nodes nodes))
1101 (setq problems t)
6af7040d 1102 (message "No `top' node in %s" Info-dir-file-name)))))
fdf4b680 1103 ;; Add to the main menu a menu item for each other node.
6af7040d 1104 (re-search-forward "^\\* Menu:")
7ea13762
RS
1105 (forward-line 1)
1106 (let ((menu-items '("top"))
3a6ade8a 1107 (end (save-excursion (search-forward "\^_" nil t) (point))))
6af7040d
SM
1108 (dolist (node nodes)
1109 (let ((nodename (car node)))
c3a29d70
RS
1110 (save-excursion
1111 (or (member (downcase nodename) menu-items)
b37daea4 1112 (re-search-forward (concat "^\\* +"
c3a29d70
RS
1113 (regexp-quote nodename)
1114 "::")
1115 end t)
1116 (progn
1117 (insert "* " nodename "::" "\n")
6af7040d 1118 (push nodename menu-items)))))))
7ea13762
RS
1119 ;; Now take each node of each of the other buffers
1120 ;; and merge it into the main buffer.
6af7040d 1121 (dolist (node nodes)
760d5cb3 1122 (let ((case-fold-search t)
6af7040d 1123 (nodename (car node)))
7ea13762
RS
1124 (goto-char (point-min))
1125 ;; Find the like-named node in the main buffer.
ba42ce14 1126 (if (re-search-forward (concat "^\^_.*\n.*Node: "
7ea13762
RS
1127 (regexp-quote nodename)
1128 "[,\n\t]")
1129 nil t)
1130 (progn
3a6ade8a 1131 (search-forward "\n\^_" nil 'move)
25869acf
RS
1132 (beginning-of-line)
1133 (insert "\n"))
7ea13762
RS
1134 ;; If none exists, add one.
1135 (goto-char (point-max))
dfbf6104 1136 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
7ea13762
RS
1137 ;; Merge the text from the other buffer's menu
1138 ;; into the menu in the like-named node in the main buffer.
6af7040d
SM
1139 (apply 'insert-buffer-substring (cdr node))))
1140 (Info-dir-remove-duplicates)
dc9bec22
TTN
1141 ;; Kill all the buffers we just made, including the special one excised.
1142 (mapc 'kill-buffer (cons buffer buffers))
4fba3b2c
RS
1143 (goto-char (point-min))
1144 (if problems
1145 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1bd19a31
MB
1146 (message "Composing main Info directory...done"))
1147 (set (make-local-variable 'Info-dir-contents) (buffer-string))
1148 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
44c327f9 1149 (setq default-directory Info-dir-contents-directory))
7ea13762 1150
6af7040d
SM
1151(defvar Info-streamline-headings
1152 '(("Emacs" . "Emacs")
1153 ("Programming" . "Programming")
1154 ("Libraries" . "Libraries")
1155 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
1156 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1157
1158(defun Info-dir-remove-duplicates ()
1159 (let (limit)
1160 (goto-char (point-min))
1161 ;; Remove duplicate headings in the same menu.
1162 (while (search-forward "\n* Menu:" nil t)
141b49f5 1163 (setq limit (save-excursion (search-forward "\n\^_" nil t)))
6af7040d
SM
1164 ;; Look for the next heading to unify.
1165 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1166 (let ((name (match-string 1))
1167 (start (match-beginning 0))
1168 (entries nil) re)
1169 ;; Check whether this heading should be streamlined.
1170 (save-match-data
1171 (dolist (x Info-streamline-headings)
1172 (when (string-match (car x) name)
1173 (setq name (cdr x))
1174 (setq re (car x)))))
1175 (if re (replace-match name t t nil 1))
1176 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
1177 (match-beginning 0)
1178 (or limit (point-max))))
1179 ;; Look for other headings of the same category and merge them.
1180 (save-excursion
1181 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1182 (when (if re (save-match-data (string-match re (match-string 1)))
1183 (equal name (match-string 1)))
1184 (forward-line 0)
1185 ;; Delete redundant heading.
1186 (delete-region (match-beginning 0) (point))
1187 ;; Push the entries onto `text'.
1188 (push
1189 (delete-and-extract-region
1190 (point)
1191 (if (re-search-forward "^[^* \n\t]" nil t)
1192 (match-beginning 0)
1193 (or limit (point-max)))) entries))))
1194 ;; Insert the entries just found.
1195 (while (= (line-beginning-position 0) (1- (point)))
1196 (backward-char))
1197 (dolist (entry (nreverse entries))
1198 (insert entry)
1199 (while (= (line-beginning-position 0) (1- (point)))
1200 (delete-region (1- (point)) (point))))
921e5fe6 1201
6af7040d
SM
1202 ;; Now remove duplicate entries under the same heading.
1203 (let ((seen nil)
1204 (limit (point)))
1205 (goto-char start)
1206 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1207 limit 'move)
b499789c
TTN
1208 ;; Fold case straight away; `member-ignore-case' here wasteful.
1209 (let ((x (downcase (match-string 1))))
1210 (if (member x seen)
6af7040d
SM
1211 (delete-region (match-beginning 0)
1212 (progn (re-search-forward "^[^ \t]" nil t)
25046503 1213 (match-beginning 0)))
6af7040d
SM
1214 (push x seen))))))))))
1215
c5fe2ff1
RS
1216;; Note that on entry to this function the current-buffer must be the
1217;; *info* buffer; not the info tags buffer.
a384cab3 1218(defun Info-read-subfile (nodepos)
a361deba
RS
1219 ;; NODEPOS is either a position (in the Info file as a whole,
1220 ;; not relative to a subfile) or the name of a subfile.
a384cab3
JB
1221 (let (lastfilepos
1222 lastfilename)
a361deba
RS
1223 (if (numberp nodepos)
1224 (save-excursion
1225 (set-buffer (marker-buffer Info-tag-table-marker))
1226 (goto-char (point-min))
ba42ce14
EZ
1227 (or (looking-at "\^_")
1228 (search-forward "\n\^_"))
a361deba
RS
1229 (forward-line 2)
1230 (catch 'foo
1231 (while (not (looking-at "\^_"))
1232 (if (not (eolp))
1233 (let ((beg (point))
1234 thisfilepos thisfilename)
1235 (search-forward ": ")
1236 (setq thisfilename (buffer-substring beg (- (point) 2)))
365d2503 1237 (setq thisfilepos (+ (point-min) (read (current-buffer))))
a361deba
RS
1238 ;; read in version 19 stops at the end of number.
1239 ;; Advance to the next line.
1240 (forward-line 1)
1241 (if (> thisfilepos nodepos)
1242 (throw 'foo t))
1243 (setq lastfilename thisfilename)
1244 (setq lastfilepos thisfilepos))
1245 (forward-line 1)))))
1246 (setq lastfilename nodepos)
1247 (setq lastfilepos 0))
c5fe2ff1
RS
1248 ;; Assume previous buffer is in Info-mode.
1249 ;; (set-buffer (get-buffer "*info*"))
a384cab3
JB
1250 (or (equal Info-current-subfile lastfilename)
1251 (let ((buffer-read-only nil))
1252 (setq buffer-file-name nil)
1253 (widen)
1254 (erase-buffer)
1143a6b0 1255 (info-insert-file-contents lastfilename)
a384cab3
JB
1256 (set-buffer-modified-p nil)
1257 (setq Info-current-subfile lastfilename)))
b0e52598
RS
1258 ;; Widen in case we are in the same subfile as before.
1259 (widen)
a384cab3 1260 (goto-char (point-min))
ba42ce14
EZ
1261 (if (looking-at "\^_")
1262 (forward-char 1)
1263 (search-forward "\n\^_"))
a361deba
RS
1264 (if (numberp nodepos)
1265 (+ (- nodepos lastfilepos) (point)))))
a384cab3 1266
ec9b1372 1267(defun Info-unescape-quotes (value)
1ed6e0c3 1268 "Unescape double quotes and backslashes in VALUE."
ec9b1372
KB
1269 (let ((start 0)
1270 (unquote value))
1271 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start)
1272 (setq unquote (replace-match "" t t unquote 1))
1273 (setq start (- (match-end 0) 1)))
1274 unquote))
1275
1276;; As of Texinfo 4.6, makeinfo writes constructs like
1277;; \0\h[image param=value ...\h\0]
1278;; into the Info file for handling images.
1279(defun Info-split-parameter-string (parameter-string)
1280 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1ed6e0c3
JPW
1281whitespace separated list of KEY=VALUE pairs. If VALUE contains
1282whitespace or double quotes, it must be quoted in double quotes and
1283any double quotes or backslashes must be escaped (\\\",\\\\)."
ec9b1372
KB
1284 (let ((start 0)
1285 (parameter-alist))
1286 (while (string-match
1287 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1288 parameter-string start)
1289 (setq start (match-end 0))
1290 (push (cons (match-string 1 parameter-string)
1291 (or (match-string 2 parameter-string)
1292 (Info-unescape-quotes
1293 (match-string 3 parameter-string))))
1294 parameter-alist))
1295 parameter-alist))
1296
1297(defun Info-display-images-node ()
1298 "Display images in current node."
1299 (save-excursion
1300 (let ((inhibit-read-only t)
dde7f979 1301 (case-fold-search t))
ec9b1372
KB
1302 (goto-char (point-min))
1303 (while (re-search-forward
1304 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1305 nil t)
1306 (let* ((start (match-beginning 1))
1307 (parameter-alist (Info-split-parameter-string (match-string 2)))
1308 (src (cdr (assoc-string "src" parameter-alist)))
1309 (image-file (if src (if (file-name-absolute-p src) src
1310 (concat default-directory src))
1311 ""))
1312 (image (if (file-exists-p image-file)
1313 (create-image image-file)
1314 "[broken image]")))
ec9b1372
KB
1315 (if (not (get-text-property start 'display))
1316 (add-text-properties
1317 start (point) `(display ,image rear-nonsticky (display)))))))
1318 (set-buffer-modified-p nil)))
1319
0c1b7af5
JL
1320;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1321;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1322;; including one optional trailing newline.
1323(defun Info-hide-cookies-node ()
e37c1854 1324 "Hide unrecognized cookies in current node."
0c1b7af5
JL
1325 (save-excursion
1326 (let ((inhibit-read-only t)
1327 (case-fold-search t))
1328 (goto-char (point-min))
1329 (while (re-search-forward
1330 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1331 nil t)
1332 (let* ((start (match-beginning 1)))
1333 (if (not (get-text-property start 'invisible))
1334 (put-text-property start (point) 'invisible t)))))
1335 (set-buffer-modified-p nil)))
1336
a384cab3 1337(defun Info-select-node ()
185cff95 1338 "Select the Info node that point is in."
b038485e 1339 ;; Bind this in case the user sets it to nil.
1bcedb3b
RS
1340 (let ((case-fold-search t))
1341 (save-excursion
760d5cb3
GM
1342 ;; Find beginning of node.
1343 (if (search-backward "\n\^_" nil 'move)
1344 (forward-line 2)
1345 (if (looking-at "\^_")
1346 (forward-line 1)
1347 (signal 'search-failed (list "\n\^_"))))
1348 ;; Get nodename spelled as it is in the node.
1349 (re-search-forward "Node:[ \t]*")
1350 (setq Info-current-node
1351 (buffer-substring-no-properties (point)
1352 (progn
1353 (skip-chars-forward "^,\t\n")
1354 (point))))
1355 (Info-set-mode-line)
1356 ;; Find the end of it, and narrow.
1357 (beginning-of-line)
1358 (let (active-expression)
50ac70af 1359 ;; Narrow to the node contents
760d5cb3
GM
1360 (narrow-to-region (point)
1361 (if (re-search-forward "\n[\^_\f]" nil t)
1362 (prog1
1363 (1- (point))
1364 (if (looking-at "[\n\^_\f]*execute: ")
1365 (progn
1366 (goto-char (match-end 0))
1367 (setq active-expression
1368 (read (current-buffer))))))
1369 (point-max)))
1370 (if Info-enable-active-nodes (eval active-expression))
8a7757f6
JL
1371 ;; Add a new unique history item to full history list
1372 (let ((new-history (list Info-current-file Info-current-node)))
1373 (setq Info-history-list
424b9d3e
JL
1374 (cons new-history (delete new-history Info-history-list)))
1375 (setq Info-history-forward nil))
141b49f5
JL
1376 (if (not (eq Info-fontify-maximum-menu-size nil))
1377 (Info-fontify-node))
ec9b1372 1378 (Info-display-images-node)
0c1b7af5 1379 (Info-hide-cookies-node)
760d5cb3 1380 (run-hooks 'Info-selection-hook)))))
a384cab3
JB
1381
1382(defun Info-set-mode-line ()
1383 (setq mode-line-buffer-identification
313fe58a 1384 (nconc (propertized-buffer-identification "%b")
918e364a
MB
1385 (list
1386 (concat " ("
1387 (file-name-nondirectory
1388 (if (stringp Info-current-file)
1389 Info-current-file
1390 (or buffer-file-name "")))
1391 ") "
1392 (or Info-current-node ""))))))
a384cab3 1393\f
185cff95 1394;; Go to an Info node specified with a filename-and-nodename string
a384cab3
JB
1395;; of the sort that is found in pointers in nodes.
1396
83040cb0
SM
1397;; Don't autoload this function: the correct entry point for other packages
1398;; to use is `info'. --Stef
1399;; ;;;###autoload
4fceda3c 1400(defun Info-goto-node (nodename &optional fork)
185cff95 1401 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
dc414be1
EZ
1402If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1403FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1404its sub-files).
1405Completion is available, but only for node names in the current Info file.
7210b6f5 1406If FORK is non-nil (interactively with a prefix arg), show the node in
185cff95 1407a new Info buffer.
4fceda3c 1408If FORK is a string, it is the name to use for the new buffer."
d1268e52 1409 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
d0e41cba 1410 (info-initialize)
4fceda3c 1411 (if fork
760d5cb3
GM
1412 (set-buffer
1413 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
a384cab3
JB
1414 (let (filename)
1415 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1416 nodename)
1417 (setq filename (if (= (match-beginning 1) (match-end 1))
1418 ""
c60c12be
SM
1419 (match-string 2 nodename))
1420 nodename (match-string 3 nodename))
836bb478 1421 (let ((trim (string-match "\\s +\\'" filename)))
a384cab3 1422 (if trim (setq filename (substring filename 0 trim))))
836bb478 1423 (let ((trim (string-match "\\s +\\'" nodename)))
a384cab3 1424 (if trim (setq nodename (substring nodename 0 trim))))
e579232c 1425 (if transient-mark-mode (deactivate-mark))
a384cab3
JB
1426 (Info-find-node (if (equal filename "") nil filename)
1427 (if (equal nodename "") "Top" nodename))))
552775bd 1428
ddf89211
RS
1429(defvar Info-read-node-completion-table)
1430
a89da416
RS
1431(defun Info-read-node-name-2 (string path-and-suffixes action)
1432 "Virtual completion table for file names input in Info node names.
1433PATH-AND-SUFFIXES is a pair of lists, (DIRECTORIES . SUFFIXES)."
1434 (let* ((names nil)
1435 (suffixes (remove "" (cdr path-and-suffixes)))
1436 (suffix (concat (regexp-opt suffixes t) "\\'"))
1437 (string-dir (file-name-directory string))
1438 (dirs
1439 (if (file-name-absolute-p string)
1440 (list (file-name-directory string))
1441 (car path-and-suffixes))))
1442 (dolist (dir dirs)
1443 (unless dir
1444 (setq dir default-directory))
1445 (if string-dir (setq dir (expand-file-name string-dir dir)))
1446 (when (file-directory-p dir)
1447 (dolist (file (file-name-all-completions
1448 (file-name-nondirectory string) dir))
1449 ;; If the file name has no suffix or a standard suffix,
1450 ;; include it.
1451 (and (or (null (file-name-extension file))
1452 (string-match suffix file))
185cff95 1453 ;; But exclude subfiles of split Info files.
a89da416
RS
1454 (not (string-match "-[0-9]+\\'" file))
1455 ;; And exclude backup files.
1456 (not (string-match "~\\'" file))
1457 (push (if string-dir (concat string-dir file) file) names))
1458 ;; If the file name ends in a standard suffix,
1459 ;; add the unsuffixed name as a completion option.
1460 (when (string-match suffix file)
1461 (setq file (substring file 0 (match-beginning 0)))
1462 (push (if string-dir (concat string-dir file) file) names)))))
1463 (cond
1464 ((eq action t) (all-completions string names))
1465 ((null action) (try-completion string names))
1466 (t (test-completion string names)))))
1467
03524be6 1468;; This function is used as the "completion table" while reading a node name.
ddf89211 1469;; It does completion using the alist in Info-read-node-completion-table
03524be6
RS
1470;; unless STRING starts with an open-paren.
1471(defun Info-read-node-name-1 (string predicate code)
365d2503
SM
1472 (cond
1473 ;; First complete embedded file names.
1474 ((string-match "\\`([^)]*\\'" string)
1475 (let ((file (substring string 1)))
1476 (cond
1477 ((eq code nil)
a89da416 1478 (let ((comp (try-completion file 'Info-read-node-name-2
365d2503
SM
1479 (cons Info-directory-list
1480 (mapcar 'car Info-suffix-list)))))
1481 (cond
1482 ((eq comp t) (concat string ")"))
1483 (comp (concat "(" comp)))))
a89da416
RS
1484 ((eq code t)
1485 (all-completions file 'Info-read-node-name-2
1486 (cons Info-directory-list
1487 (mapcar 'car Info-suffix-list))))
365d2503
SM
1488 (t nil))))
1489 ;; If a file name was given, then any node is fair game.
1490 ((string-match "\\`(" string)
1491 (cond
1492 ((eq code nil) string)
1493 ((eq code t) nil)
1494 (t t)))
1495 ;; Otherwise use Info-read-node-completion-table.
1496 ((eq code nil)
1497 (try-completion string Info-read-node-completion-table predicate))
1498 ((eq code t)
1499 (all-completions string Info-read-node-completion-table predicate))
1500 (t
1501 (test-completion string Info-read-node-completion-table predicate))))
03524be6 1502
a89da416
RS
1503;; Arrange to highlight the proper letters in the completion list buffer.
1504(put 'Info-read-node-name-1 'completion-base-size-function
1505 (lambda () 1))
1506
552775bd
RS
1507(defun Info-read-node-name (prompt &optional default)
1508 (let* ((completion-ignore-case t)
ddf89211 1509 (Info-read-node-completion-table (Info-build-node-completions))
b6d61ffa 1510 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
552775bd
RS
1511 (if (equal nodename "")
1512 (or default
1513 (Info-read-node-name prompt))
1514 nodename)))
1515
1516(defun Info-build-node-completions ()
1517 (or Info-current-file-completions
1bcedb3b
RS
1518 (let ((compl nil)
1519 ;; Bind this in case the user sets it to nil.
11638562
EZ
1520 (case-fold-search t)
1521 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
552775bd
RS
1522 (save-excursion
1523 (save-restriction
1524 (if (marker-buffer Info-tag-table-marker)
c5fe2ff1
RS
1525 (let ((marker Info-tag-table-marker))
1526 (set-buffer (marker-buffer marker))
cedb118c 1527 (widen)
c5fe2ff1 1528 (goto-char marker)
fdf4b680 1529 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
552775bd 1530 (setq compl
fdf4b680 1531 (cons (list (match-string-no-properties 2))
552775bd
RS
1532 compl))))
1533 (widen)
1534 (goto-char (point-min))
11638562
EZ
1535 ;; If the buffer begins with a node header, process that first.
1536 (if (Info-node-at-bob-matching node-regexp)
110d4e80 1537 (setq compl (list (match-string-no-properties 1))))
11638562 1538 ;; Now for the rest of the nodes.
552775bd
RS
1539 (while (search-forward "\n\^_" nil t)
1540 (forward-line 1)
1541 (let ((beg (point)))
1542 (forward-line 1)
11638562 1543 (if (re-search-backward node-regexp beg t)
399c88ad 1544 (setq compl
110d4e80 1545 (cons (list (match-string-no-properties 1))
552775bd 1546 compl))))))))
87d2b5a2 1547 (setq compl (cons '("*") compl))
07b1b912 1548 (set (make-local-variable 'Info-current-file-completions) compl))))
a384cab3 1549\f
aea2a8da
JB
1550(defun Info-restore-point (hl)
1551 "If this node has been visited, restore the point value when we left."
cedb118c
RS
1552 (while hl
1553 (if (and (equal (nth 0 (car hl)) Info-current-file)
e90d1271
RS
1554 ;; Use string-equal, not equal, to ignore text props.
1555 (string-equal (nth 1 (car hl)) Info-current-node))
cedb118c 1556 (progn
d96504df
KH
1557 (goto-char (nth 2 (car hl)))
1558 (setq hl nil)) ;terminate the while at next iter
cedb118c 1559 (setq hl (cdr hl)))))
aea2a8da 1560\f
2c80a618
GM
1561(defvar Info-search-history nil
1562 "The history list for `Info-search'.")
a384cab3 1563
8a7757f6
JL
1564(defvar Info-search-case-fold nil
1565 "The value of `case-fold-search' from previous `Info-search' command.")
1566
0b02cda9
JL
1567(defun Info-search (regexp &optional bound noerror count direction)
1568 "Search for REGEXP, starting from point, and select node it's found in.
1569If DIRECTION is `backward', search in the reverse direction."
bbc96600
EZ
1570 (interactive (list (read-string
1571 (if Info-search-history
5b76833f
RF
1572 (format "Regexp search%s (default %s): "
1573 (if case-fold-search "" " case-sensitively")
bbc96600 1574 (car Info-search-history))
8a7757f6 1575 (format "Regexp search%s: "
5b76833f 1576 (if case-fold-search "" " case-sensitively")))
bbc96600 1577 nil 'Info-search-history)))
2c80a618
GM
1578 (when transient-mark-mode
1579 (deactivate-mark))
1580 (when (equal regexp "")
1581 (setq regexp (car Info-search-history)))
c47b5bbe 1582 (when regexp
774f8aee 1583 (let (found beg-found give-up
0b02cda9 1584 (backward (eq direction 'backward))
c47b5bbe
DL
1585 (onode Info-current-node)
1586 (ofile Info-current-file)
1587 (opoint (point))
0b02cda9
JL
1588 (opoint-min (point-min))
1589 (opoint-max (point-max))
c47b5bbe
DL
1590 (ostart (window-start))
1591 (osubfile Info-current-subfile))
8a7757f6 1592 (setq Info-search-case-fold case-fold-search)
c47b5bbe
DL
1593 (save-excursion
1594 (save-restriction
1595 (widen)
ca53db33
JL
1596 (when backward
1597 ;; Hide Info file header for backward search
1598 (narrow-to-region (save-excursion
1599 (goto-char (point-min))
1600 (search-forward "\n\^_")
1601 (1- (point)))
1602 (point-max)))
774f8aee 1603 (while (and (not give-up)
be4b3ae8
JL
1604 (save-match-data
1605 (or (null found)
1606 (if backward
1607 (isearch-range-invisible found beg-found)
1608 (isearch-range-invisible beg-found found))
1609 ;; Skip node header line
180ee7c7
JL
1610 (and (save-excursion (forward-line -1)
1611 (looking-at "\^_"))
866920e3 1612 (forward-line (if backward -1 1)))
be4b3ae8
JL
1613 ;; Skip Tag Table node
1614 (save-excursion
1615 (and (search-backward "\^_" nil t)
1616 (looking-at "\^_\nTag Table"))))))
180ee7c7 1617 (let ((search-spaces-regexp Info-search-whitespace-regexp))
5d4faeda
RS
1618 (if (if backward
1619 (re-search-backward regexp bound t)
1620 (re-search-forward regexp bound t))
1621 (setq found (point) beg-found (if backward (match-end 0)
1622 (match-beginning 0)))
1623 (setq give-up t))))))
d457219d
JL
1624
1625 (when (and isearch-mode Info-isearch-search
1626 (not Info-isearch-initial-node)
1627 (not bound)
1628 (or give-up (and found (not (and (> found opoint-min)
1629 (< found opoint-max))))))
1630 (signal 'search-failed (list regexp "initial node")))
1631
774f8aee
RS
1632 ;; If no subfiles, give error now.
1633 (if give-up
c47b5bbe 1634 (if (null Info-current-subfile)
180ee7c7
JL
1635 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1636 (if backward
1637 (re-search-backward regexp)
1638 (re-search-forward regexp)))
774f8aee
RS
1639 (setq found nil)))
1640
d457219d
JL
1641 (if (and bound (not found))
1642 (signal 'search-failed (list regexp)))
1643
0b02cda9 1644 (unless (or found bound)
774f8aee
RS
1645 (unwind-protect
1646 ;; Try other subfiles.
1647 (let ((list ()))
1648 (save-excursion
1649 (set-buffer (marker-buffer Info-tag-table-marker))
1650 (goto-char (point-min))
1651 (search-forward "\n\^_\nIndirect:")
1652 (save-restriction
1653 (narrow-to-region (point)
1654 (progn (search-forward "\n\^_")
1655 (1- (point))))
c5fe2ff1 1656 (goto-char (point-min))
774f8aee
RS
1657 ;; Find the subfile we just searched.
1658 (search-forward (concat "\n" osubfile ": "))
1659 ;; Skip that one.
0b02cda9 1660 (forward-line (if backward 0 1))
866920e3 1661 (if backward (forward-char -1))
774f8aee
RS
1662 ;; Make a list of all following subfiles.
1663 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
0b02cda9
JL
1664 (while (not (if backward (bobp) (eobp)))
1665 (if backward
1666 (re-search-backward "\\(^.*\\): [0-9]+$")
1667 (re-search-forward "\\(^.*\\): [0-9]+$"))
774f8aee
RS
1668 (goto-char (+ (match-end 1) 2))
1669 (setq list (cons (cons (+ (point-min)
1670 (read (current-buffer)))
1671 (match-string-no-properties 1))
1672 list))
0b02cda9
JL
1673 (goto-char (if backward
1674 (1- (match-beginning 0))
1675 (1+ (match-end 0)))))
774f8aee
RS
1676 ;; Put in forward order
1677 (setq list (nreverse list))))
1678 (while list
1679 (message "Searching subfile %s..." (cdr (car list)))
1680 (Info-read-subfile (car (car list)))
ca53db33
JL
1681 (when backward
1682 ;; Hide Info file header for backward search
1683 (narrow-to-region (save-excursion
1684 (goto-char (point-min))
1685 (search-forward "\n\^_")
1686 (1- (point)))
1687 (point-max))
1688 (goto-char (point-max)))
774f8aee
RS
1689 (setq list (cdr list))
1690 (setq give-up nil found nil)
1691 (while (and (not give-up)
be4b3ae8
JL
1692 (save-match-data
1693 (or (null found)
1694 (if backward
1695 (isearch-range-invisible found beg-found)
1696 (isearch-range-invisible beg-found found))
1697 ;; Skip node header line
180ee7c7
JL
1698 (and (save-excursion (forward-line -1)
1699 (looking-at "\^_"))
866920e3 1700 (forward-line (if backward -1 1)))
be4b3ae8
JL
1701 ;; Skip Tag Table node
1702 (save-excursion
1703 (and (search-backward "\^_" nil t)
1704 (looking-at "\^_\nTag Table"))))))
180ee7c7
JL
1705 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1706 (if (if backward
1707 (re-search-backward regexp nil t)
1708 (re-search-forward regexp nil t))
1709 (setq found (point) beg-found (if backward (match-end 0)
1710 (match-beginning 0)))
1711 (setq give-up t))))
774f8aee
RS
1712 (if give-up
1713 (setq found nil))
c47b5bbe 1714 (if found
774f8aee
RS
1715 (setq list nil)))
1716 (if found
1717 (message "")
1718 (signal 'search-failed (list regexp))))
1719 (if (not found)
1720 (progn (Info-read-subfile osubfile)
1721 (goto-char opoint)
1722 (Info-select-node)
1723 (set-window-start (selected-window) ostart)))))
0b02cda9
JL
1724
1725 (if (and (string= osubfile Info-current-subfile)
1726 (> found opoint-min)
1727 (< found opoint-max))
1728 ;; Search landed in the same node
1729 (goto-char found)
1730 (widen)
1731 (goto-char found)
1732 (save-match-data (Info-select-node)))
1733
760d5cb3
GM
1734 ;; Use string-equal, not equal, to ignore text props.
1735 (or (and (string-equal onode Info-current-node)
1736 (equal ofile Info-current-file))
866920e3
JL
1737 (and isearch-mode isearch-wrapped
1738 (eq opoint (if isearch-forward opoint-min opoint-max)))
760d5cb3
GM
1739 (setq Info-history (cons (list ofile onode opoint)
1740 Info-history))))))
8a7757f6
JL
1741
1742(defun Info-search-case-sensitively ()
1743 "Search for a regexp case-sensitively."
1744 (interactive)
1745 (let ((case-fold-search nil))
1746 (call-interactively 'Info-search)))
1747
1748(defun Info-search-next ()
1749 "Search for next regexp from a previous `Info-search' command."
1750 (interactive)
1751 (let ((case-fold-search Info-search-case-fold))
1752 (if Info-search-history
1753 (Info-search (car Info-search-history))
1754 (call-interactively 'Info-search))))
0b02cda9
JL
1755
1756(defun Info-search-backward (regexp &optional bound noerror count)
1757 "Search for REGEXP in the reverse direction."
1758 (interactive (list (read-string
1759 (if Info-search-history
5b76833f
RF
1760 (format "Regexp search%s backward (default %s): "
1761 (if case-fold-search "" " case-sensitively")
0b02cda9
JL
1762 (car Info-search-history))
1763 (format "Regexp search%s backward: "
5b76833f 1764 (if case-fold-search "" " case-sensitively")))
0b02cda9
JL
1765 nil 'Info-search-history)))
1766 (Info-search regexp bound noerror count 'backward))
1767
1768(defun Info-isearch-search ()
9553cf63 1769 (if Info-isearch-search
98e77be5 1770 (lambda (string &optional bound noerror count)
d457219d
JL
1771 (if isearch-word
1772 (Info-search (concat "\\b" (replace-regexp-in-string
69672704 1773 "\\W+" "\\W+"
d457219d 1774 (replace-regexp-in-string
69672704
JL
1775 "^\\W+\\|\\W+$" "" string)
1776 nil t)
1777 "\\b")
d457219d
JL
1778 bound noerror count
1779 (unless isearch-forward 'backward))
1780 (Info-search (if isearch-regexp string (regexp-quote string))
1781 bound noerror count
1782 (unless isearch-forward 'backward))
1783 (point)))
98e77be5
JL
1784 (let ((isearch-search-fun-function nil))
1785 (isearch-search-fun))))
0b02cda9
JL
1786
1787(defun Info-isearch-wrap ()
d457219d
JL
1788 (if Info-isearch-search
1789 (if Info-isearch-initial-node
1790 (progn
1791 (if isearch-forward (Info-top-node) (Info-final-node))
1792 (goto-char (if isearch-forward (point-min) (point-max))))
1793 (setq Info-isearch-initial-node Info-current-node)
1794 (setq isearch-wrapped nil))
0b02cda9
JL
1795 (goto-char (if isearch-forward (point-min) (point-max)))))
1796
1797(defun Info-isearch-push-state ()
1798 `(lambda (cmd)
1799 (Info-isearch-pop-state cmd ,Info-current-file ,Info-current-node)))
1800
1801(defun Info-isearch-pop-state (cmd file node)
1802 (or (and (string= Info-current-file file)
1803 (string= Info-current-node node))
1804 (progn (Info-find-node file node) (sit-for 0))))
1805
d457219d
JL
1806(defun Info-isearch-start ()
1807 (setq Info-isearch-initial-node nil))
a384cab3 1808\f
a384cab3 1809(defun Info-extract-pointer (name &optional errorname)
fdf4b680
DL
1810 "Extract the value of the node-pointer named NAME.
1811If there is none, use ERRORNAME in the error message;
c60c12be
SM
1812if ERRORNAME is nil, just return nil."
1813 ;; Bind this in case the user sets it to nil.
1bcedb3b
RS
1814 (let ((case-fold-search t))
1815 (save-excursion
c60c12be
SM
1816 (goto-char (point-min))
1817 (let ((bound (point)))
1818 (forward-line 1)
1819 (cond ((re-search-backward
1820 (concat name ":" (Info-following-node-name-re)) bound t)
1821 (match-string 1))
1822 ((not (eq errorname t))
1823 (error "Node has no %s"
1824 (capitalize (or errorname name)))))))))
1825
1826(defun Info-following-node-name-re (&optional allowedchars)
1827 "Return a regexp matching a node name.
fdf4b680 1828ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
c60c12be
SM
1829saying which chars may appear in the node name.
1830Submatch 1 is the complete node name.
1831Submatch 2 if non-nil is the parenthesized file name part of the node name.
1832Submatch 3 is the local part of the node name.
1833End of submatch 0, 1, and 3 are the same, so you can safely concat."
1834 (concat "[ \t]*" ;Skip leading space.
1835 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1836 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
1837 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
1838 "\\|\\)\\)")) ;Allow empty node names.
a384cab3 1839
718e6bc7
RS
1840;;; For compatibility; other files have used this name.
1841(defun Info-following-node-name ()
1842 (and (looking-at (Info-following-node-name-re))
1843 (match-string 1)))
1844
a384cab3
JB
1845(defun Info-next ()
1846 "Go to the next node of this node."
1847 (interactive)
1848 (Info-goto-node (Info-extract-pointer "next")))
1849
1850(defun Info-prev ()
1851 "Go to the previous node of this node."
1852 (interactive)
1853 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1854
5dab2fb4
RS
1855(defun Info-up (&optional same-file)
1856 "Go to the superior node of this node.
1857If SAME-FILE is non-nil, do not move to a different Info file."
a384cab3 1858 (interactive)
8a7757f6
JL
1859 (let ((old-node Info-current-node)
1860 (old-file Info-current-file)
1861 (node (Info-extract-pointer "up")) p)
4fceda3c 1862 (and (or same-file (not (stringp Info-current-file)))
5dab2fb4
RS
1863 (string-match "^(" node)
1864 (error "Up node is in another Info file"))
8a7757f6
JL
1865 (Info-goto-node node)
1866 (setq p (point))
1867 (goto-char (point-min))
1868 (if (and (search-forward "\n* Menu:" nil t)
1869 (re-search-forward
1870 (if (string-equal old-node "Top")
1871 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
1872 (concat "\n\\* +\\(" (regexp-quote old-node)
1873 ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
1874 nil t))
185cff95 1875 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
8a7757f6
JL
1876 (goto-char p)
1877 (Info-restore-point Info-history))))
a384cab3 1878
424b9d3e
JL
1879(defun Info-history-back ()
1880 "Go back in the history to the last node visited."
a384cab3
JB
1881 (interactive)
1882 (or Info-history
1883 (error "This is the first Info node you looked at"))
424b9d3e
JL
1884 (let ((history-forward
1885 (cons (list Info-current-file Info-current-node (point))
1886 Info-history-forward))
1887 filename nodename opoint)
a384cab3
JB
1888 (setq filename (car (car Info-history)))
1889 (setq nodename (car (cdr (car Info-history))))
1890 (setq opoint (car (cdr (cdr (car Info-history)))))
1891 (setq Info-history (cdr Info-history))
1892 (Info-find-node filename nodename)
1893 (setq Info-history (cdr Info-history))
424b9d3e
JL
1894 (setq Info-history-forward history-forward)
1895 (goto-char opoint)))
1896
1897(defalias 'Info-last 'Info-history-back)
1898
1899(defun Info-history-forward ()
1900 "Go forward in the history of visited nodes."
1901 (interactive)
1902 (or Info-history-forward
1903 (error "This is the last Info node you looked at"))
1904 (let ((history-forward (cdr Info-history-forward))
1905 filename nodename opoint)
1906 (setq filename (car (car Info-history-forward)))
1907 (setq nodename (car (cdr (car Info-history-forward))))
1908 (setq opoint (car (cdr (cdr (car Info-history-forward)))))
1909 (Info-find-node filename nodename)
1910 (setq Info-history-forward history-forward)
a384cab3
JB
1911 (goto-char opoint)))
1912
48e5b471 1913;;;###autoload
a384cab3
JB
1914(defun Info-directory ()
1915 "Go to the Info directory node."
1916 (interactive)
1917 (Info-find-node "dir" "top"))
1918\f
8a7757f6 1919(defun Info-history ()
89b064a9 1920 "Go to a node with a menu of visited nodes."
8a7757f6
JL
1921 (interactive)
1922 (let ((curr-file Info-current-file)
1923 (curr-node Info-current-node)
1924 p)
89b064a9
JL
1925 (with-current-buffer (get-buffer-create " *info-history*")
1926 (let ((inhibit-read-only t))
1927 (erase-buffer)
1928 (goto-char (point-min))
ea99d5c8 1929 (insert "\n\^_\nFile: history, Node: Top, Up: (dir)\n\n")
89b064a9
JL
1930 (insert "Recently Visited Nodes\n**********************\n\n")
1931 (insert "* Menu:\n\n")
1932 (let ((hl (delete '("history" "Top") Info-history-list)))
1933 (while hl
1934 (let ((file (nth 0 (car hl)))
1935 (node (nth 1 (car hl))))
1936 (if (and (string-equal file curr-file)
1937 (string-equal node curr-node))
1938 (setq p (point)))
1939 (insert "* " node ": (" (file-name-nondirectory file)
1940 ")" node ".\n"))
1941 (setq hl (cdr hl))))))
1942 (Info-find-node "history" "Top")
8a7757f6
JL
1943 (goto-char (or p (point-min)))))
1944
8a7757f6 1945(defun Info-toc ()
bc224645
JL
1946 "Go to a node with table of contents of the current Info file.
1947Table of contents is created from the tree structure of menus."
8a7757f6 1948 (interactive)
ea99d5c8
JL
1949 (let ((curr-file (substring-no-properties Info-current-file))
1950 (curr-node (substring-no-properties Info-current-node))
8a7757f6 1951 p)
89b064a9
JL
1952 (with-current-buffer (get-buffer-create " *info-toc*")
1953 (let ((inhibit-read-only t)
1954 (node-list (Info-build-toc curr-file)))
1955 (erase-buffer)
1956 (goto-char (point-min))
ea99d5c8 1957 (insert "\n\^_\nFile: toc, Node: Top, Up: (dir)\n\n")
89b064a9 1958 (insert "Table of Contents\n*****************\n\n")
ea99d5c8 1959 (insert "*Note Top: (" curr-file ")Top.\n")
89b064a9
JL
1960 (Info-insert-toc
1961 (nth 2 (assoc "Top" node-list)) ; get Top nodes
ea99d5c8 1962 node-list 0 curr-file))
89b064a9
JL
1963 (if (not (bobp))
1964 (let ((Info-hide-note-references 'hide)
1965 (Info-fontify-visited-nodes nil))
50163b00 1966 (Info-mode)
141b49f5 1967 (setq Info-current-file "toc" Info-current-node "Top")
ea99d5c8
JL
1968 (goto-char (point-min))
1969 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t)
1970 (point-min))
1971 (point-max))
1972 (Info-fontify-node)
1973 (widen)))
89b064a9
JL
1974 (goto-char (point-min))
1975 (if (setq p (search-forward (concat "*Note " curr-node ":") nil t))
1976 (setq p (- p (length curr-node) 2))))
1977 (Info-find-node "toc" "Top")
8a7757f6
JL
1978 (goto-char (or p (point-min)))))
1979
89b064a9 1980(defun Info-insert-toc (nodes node-list level curr-file)
8a7757f6
JL
1981 "Insert table of contents with references to nodes."
1982 (let ((section "Top"))
1983 (while nodes
1984 (let ((node (assoc (car nodes) node-list)))
1985 (unless (member (nth 1 node) (list nil section))
1986 (insert (setq section (nth 1 node)) "\n"))
1987 (insert (make-string level ?\t))
89b064a9
JL
1988 (insert "*Note " (car nodes) ": (" curr-file ")" (car nodes) ".\n")
1989 (Info-insert-toc (nth 2 node) node-list (1+ level) curr-file)
8a7757f6
JL
1990 (setq nodes (cdr nodes))))))
1991
1992(defun Info-build-toc (file)
1993 "Build table of contents from menus of Info FILE and its subfiles."
8a7757f6 1994 (with-temp-buffer
ea99d5c8
JL
1995 (let* ((file (and (stringp file) (Info-find-file file)))
1996 (default-directory (or (and (stringp file)
1997 (file-name-directory file))
141b49f5 1998 default-directory))
ea99d5c8 1999 (main-file (and (stringp file) file))
141b49f5
JL
2000 (sections '(("Top" "Top")))
2001 nodes subfiles)
2002 (while (or main-file subfiles)
2003 (or main-file (message "Searching subfile %s..." (car subfiles)))
8a7757f6 2004 (erase-buffer)
141b49f5
JL
2005 (info-insert-file-contents (or main-file (car subfiles)))
2006 (goto-char (point-min))
8a7757f6
JL
2007 (while (and (search-forward "\n\^_\nFile:" nil 'move)
2008 (search-forward "Node: " nil 'move))
2009 (let ((nodename (substring-no-properties (Info-following-node-name)))
2010 (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
2011 (point-max)) 2))
2012 (section "Top")
2013 menu-items)
141b49f5 2014 (when (and (not (Info-index-node nodename file))
8a7757f6
JL
2015 (re-search-forward "^\\* Menu:" bound t))
2016 (forward-line 1)
2017 (beginning-of-line)
2018 (setq bound (or (and (equal nodename "Top")
2019 (save-excursion
2020 (re-search-forward
2021 "^[ \t-]*The Detailed Node Listing" nil t)))
2022 bound))
2023 (while (< (point) bound)
2024 (cond
2025 ;; Menu item line
2026 ((looking-at "^\\* +[^:]+:")
2027 (beginning-of-line)
2028 (forward-char 2)
2029 (let ((menu-node-name (substring-no-properties
2030 (Info-extract-menu-node-name))))
2031 (setq menu-items (cons menu-node-name menu-items))
2032 (if (equal nodename "Top")
2033 (setq sections
2034 (cons (list menu-node-name section) sections)))))
2035 ;; Other non-empty strings in the Top node are section names
2036 ((and (equal nodename "Top")
2037 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2038 (setq section (match-string-no-properties 1))))
2039 (forward-line 1)
2040 (beginning-of-line)))
2041 (setq nodes (cons (list nodename
2042 (cadr (assoc nodename sections))
2043 (nreverse menu-items))
2044 nodes))
2045 (goto-char bound)))
141b49f5 2046 (if main-file
8a7757f6
JL
2047 (save-excursion
2048 (goto-char (point-min))
2049 (if (search-forward "\n\^_\nIndirect:" nil t)
2050 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2051 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2052 (setq subfiles (cons (match-string-no-properties 1)
2053 subfiles)))))
2054 (setq subfiles (nreverse subfiles)
141b49f5 2055 main-file nil))
8a7757f6
JL
2056 (setq subfiles (cdr subfiles))))
2057 (message "")
2058 (nreverse nodes))))
2059\f
2060(defun Info-follow-reference (footnotename &optional fork)
fdf4b680 2061 "Follow cross reference named FOOTNOTENAME to the node it refers to.
8a7757f6
JL
2062FOOTNOTENAME may be an abbreviation of the reference name.
2063If FORK is non-nil (interactively with a prefix arg), show the node in
185cff95 2064a new Info buffer. If FORK is a string, it is the name to use for the
8a7757f6 2065new buffer."
a384cab3
JB
2066 (interactive
2067 (let ((completion-ignore-case t)
1bcedb3b 2068 (case-fold-search t)
67bc89ab 2069 completions default alt-default (start-point (point)) str i bol eol)
a384cab3 2070 (save-excursion
67bc89ab
RS
2071 ;; Store end and beginning of line.
2072 (end-of-line)
2073 (setq eol (point))
2074 (beginning-of-line)
2075 (setq bol (point))
2076
a384cab3 2077 (goto-char (point-min))
8a7757f6 2078 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
c60c12be 2079 (setq str (match-string-no-properties 1))
a384cab3
JB
2080 ;; See if this one should be the default.
2081 (and (null default)
1f179e27 2082 (<= (match-beginning 0) start-point)
a384cab3
JB
2083 (<= start-point (point))
2084 (setq default t))
67bc89ab
RS
2085 ;; See if this one should be the alternate default.
2086 (and (null alt-default)
2087 (and (<= bol (match-beginning 0))
2088 (<= (point) eol))
2089 (setq alt-default t))
a384cab3
JB
2090 (setq i 0)
2091 (while (setq i (string-match "[ \n\t]+" str i))
2092 (setq str (concat (substring str 0 i) " "
2093 (substring str (match-end 0))))
2094 (setq i (1+ i)))
2095 ;; Record as a completion and perhaps as default.
2096 (if (eq default t) (setq default str))
67bc89ab 2097 (if (eq alt-default t) (setq alt-default str))
ec6d29af 2098 ;; Don't add this string if it's a duplicate.
c60c12be
SM
2099 (or (assoc-string str completions t)
2100 (push str completions))))
67bc89ab
RS
2101 ;; If no good default was found, try an alternate.
2102 (or default
2103 (setq default alt-default))
2104 ;; If only one cross-reference found, then make it default.
2105 (if (eq (length completions) 1)
c60c12be 2106 (setq default (car completions)))
a384cab3 2107 (if completions
b0ebdfe5 2108 (let ((input (completing-read (if default
968b7671 2109 (concat
5b76833f
RF
2110 "Follow reference named (default "
2111 default "): ")
b0ebdfe5
RS
2112 "Follow reference named: ")
2113 completions nil t)))
2114 (list (if (equal input "")
8a7757f6 2115 default input) current-prefix-arg))
a384cab3 2116 (error "No cross-references in this node"))))
ebf8f7e1
RS
2117
2118 (unless footnotename
2119 (error "No reference was specified"))
2120
dde7f979 2121 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
1bcedb3b 2122 (case-fold-search t))
a384cab3
JB
2123 (while (setq i (string-match " " str i))
2124 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
2125 (setq i (+ i 6)))
2126 (save-excursion
8a7757f6
JL
2127 ;; Move point to the beginning of reference if point is on reference
2128 (or (looking-at "\\*note[ \n\t]+")
2129 (and (looking-back "\\*note[ \n\t]+")
2130 (goto-char (match-beginning 0)))
2131 (if (and (save-excursion
2132 (goto-char (+ (point) 5)) ; skip a possible *note
2133 (re-search-backward "\\*note[ \n\t]+" nil t)
836bb478 2134 (looking-at str))
8a7757f6
JL
2135 (<= (point) (match-end 0)))
2136 (goto-char (match-beginning 0))))
2137 ;; Go to the reference closest to point
2138 (let ((next-ref (save-excursion (and (re-search-forward str nil t)
2139 (+ (match-beginning 0) 5))))
2140 (prev-ref (save-excursion (and (re-search-backward str nil t)
2141 (+ (match-beginning 0) 5)))))
2142 (goto-char (cond ((and next-ref prev-ref)
2143 (if (< (abs (- next-ref (point)))
2144 (abs (- prev-ref (point))))
2145 next-ref prev-ref))
2146 ((or next-ref prev-ref))
2147 ((error "No cross-reference named %s" footnotename))))
2148 (setq target (Info-extract-menu-node-name t))))
a384cab3
JB
2149 (while (setq i (string-match "[ \t\n]+" target i))
2150 (setq target (concat (substring target 0 i) " "
2151 (substring target (match-end 0))))
2152 (setq i (+ i 1)))
8a7757f6 2153 (Info-goto-node target fork)))
a384cab3 2154
e057da52
SM
2155(defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2156 ;; We allow newline because this is also used in Info-follow-reference,
2157 ;; where the xref name might be wrapped over two lines.
c60c12be
SM
2158 "Regexp that matches a menu entry name upto but not including the colon.
2159Because of ambiguities, this should be concatenated with something like
2160`:' and `Info-following-node-name-re'.")
2161
836bb478 2162(defun Info-extract-menu-node-name (&optional multi-line index-node)
a384cab3 2163 (skip-chars-forward " \t\n")
c60c12be
SM
2164 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
2165 (Info-following-node-name-re
836bb478
JL
2166 (cond
2167 (index-node "^,\t\n")
2168 (multi-line "^.,\t")
2169 (t "^.,\t\n")))
2170 "\\)"
2171 (if index-node
2172 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2173 "")))
2174 (if index-node
2175 (setq Info-point-loc
2176 (if (match-beginning 5)
2177 (string-to-number (match-string 5))
2178 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))
02c9f5cd 2179;;; Uncomment next line to use names of cross-references in non-index nodes:
836bb478
JL
2180;;; (setq Info-point-loc
2181;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2182 )
c60c12be
SM
2183 (replace-regexp-in-string
2184 "[ \n]+" " "
2185 (or (match-string 2)
2186 ;; If the node name is the menu entry name (using `entry::').
2187 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))))
a384cab3 2188
e8adde3f 2189;; No one calls this.
9e5c2f50
RS
2190;;(defun Info-menu-item-sequence (list)
2191;; (while list
e8adde3f 2192;; (Info-menu (car list))
9e5c2f50 2193;; (setq list (cdr list))))
a384cab3 2194
6356e646 2195(defvar Info-complete-menu-buffer)
e4e8ee63 2196(defvar Info-complete-next-re nil)
141b49f5 2197(defvar Info-complete-nodes nil)
e4e8ee63 2198(defvar Info-complete-cache nil)
6356e646 2199
c60c12be
SM
2200(defconst Info-node-spec-re
2201 (concat (Info-following-node-name-re "^.,:") "[,:.]")
a1637357
SM
2202 "Regexp to match the text after a : until the terminating `.'.")
2203
e8adde3f 2204(defun Info-complete-menu-item (string predicate action)
2d12f5c2
SM
2205 ;; This uses two dynamically bound variables:
2206 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2207 ;; is the menu of items we're trying to complete.
2208 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2209 ;; also look for menu items in subsequent nodes as long as those
2210 ;; nodes' names match `Info-complete-next-re'. This feature is currently
141b49f5
JL
2211 ;; not used.
2212 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2213 ;; also look for menu items in these nodes. This feature is currently
2d12f5c2 2214 ;; only used for completion in Info-index.
0defe758
LK
2215
2216 ;; Note that `Info-complete-menu-buffer' could be current already,
2217 ;; so we want to save point.
2218 (save-excursion
2219 (set-buffer Info-complete-menu-buffer)
e4e8ee63
SM
2220 (let ((completion-ignore-case t)
2221 (case-fold-search t)
2222 (orignode Info-current-node)
2223 nextnode)
2224 (goto-char (point-min))
2225 (search-forward "\n* Menu:")
2226 (if (not (memq action '(nil t)))
2227 (re-search-forward
2228 (concat "\n\\* +" (regexp-quote string) ":") nil t)
2229 (let ((pattern (concat "\n\\* +\\("
2230 (regexp-quote string)
c60c12be 2231 Info-menu-entry-name-re "\\):" Info-node-spec-re))
e4e8ee63
SM
2232 completions)
2233 ;; Check the cache.
2234 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
2235 (equal (nth 1 Info-complete-cache) Info-current-node)
2236 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
141b49f5 2237 (equal (nth 5 Info-complete-cache) Info-complete-nodes)
e4e8ee63
SM
2238 (let ((prev (nth 3 Info-complete-cache)))
2239 (eq t (compare-strings string 0 (length prev)
2240 prev 0 nil t))))
2241 ;; We can reuse the previous list.
2242 (setq completions (nth 4 Info-complete-cache))
2243 ;; The cache can't be used.
2244 (while
2245 (progn
2246 (while (re-search-forward pattern nil t)
365d2503 2247 (push (match-string-no-properties 1)
e4e8ee63
SM
2248 completions))
2249 ;; Check subsequent nodes if applicable.
141b49f5
JL
2250 (or (and Info-complete-next-re
2251 (setq nextnode (Info-extract-pointer "next" t))
2252 (string-match Info-complete-next-re nextnode))
2253 (and Info-complete-nodes
2254 (setq Info-complete-nodes (cdr Info-complete-nodes)
2255 nextnode (car Info-complete-nodes)))))
e4e8ee63
SM
2256 (Info-goto-node nextnode))
2257 ;; Go back to the start node (for the next completion).
2258 (unless (equal Info-current-node orignode)
2259 (Info-goto-node orignode))
2260 ;; Update the cache.
271f4a9e
MB
2261 (set (make-local-variable 'Info-complete-cache)
2262 (list Info-current-file Info-current-node
141b49f5
JL
2263 Info-complete-next-re string completions
2264 Info-complete-nodes)))
e4e8ee63
SM
2265 (if action
2266 (all-completions string completions predicate)
2267 (try-completion string completions predicate)))))))
e8adde3f
RS
2268
2269
4fceda3c 2270(defun Info-menu (menu-item &optional fork)
dc414be1
EZ
2271 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2272The menu item should one of those listed in the current node's menu.
2273Completion is allowed, and the default menu item is the one point is on.
7210b6f5 2274If FORK is non-nil (interactively with a prefix arg), show the node in
185cff95 2275a new Info buffer. If FORK is a string, it is the name to use for the
7210b6f5 2276new buffer."
a384cab3
JB
2277 (interactive
2278 (let ((completions '())
2279 ;; If point is within a menu item, use that item as the default
2280 (default nil)
2281 (p (point))
211d6309 2282 beg
760d5cb3
GM
2283 (last nil)
2284 (case-fold-search t))
a384cab3
JB
2285 (save-excursion
2286 (goto-char (point-min))
2287 (if (not (search-forward "\n* menu:" nil t))
2288 (error "No menu in this node"))
e8adde3f
RS
2289 (setq beg (point))
2290 (and (< (point) p)
2291 (save-excursion
2292 (goto-char p)
2293 (end-of-line)
00d32b3f
SM
2294 (if (re-search-backward (concat "\n\\* +\\("
2295 Info-menu-entry-name-re
2296 "\\):") beg t)
110d4e80 2297 (setq default (match-string-no-properties 1))))))
a384cab3
JB
2298 (let ((item nil))
2299 (while (null item)
e8adde3f
RS
2300 (setq item (let ((completion-ignore-case t)
2301 (Info-complete-menu-buffer (current-buffer)))
a384cab3
JB
2302 (completing-read (if default
2303 (format "Menu item (default %s): "
2304 default)
760d5cb3 2305 "Menu item: ")
e8adde3f 2306 'Info-complete-menu-item nil t)))
aea2a8da
JB
2307 ;; we rely on the fact that completing-read accepts an input
2308 ;; of "" even when the require-match argument is true and ""
2309 ;; is not a valid possibility
a384cab3
JB
2310 (if (string= item "")
2311 (if default
2312 (setq item default)
760d5cb3
GM
2313 ;; ask again
2314 (setq item nil))))
4fceda3c 2315 (list item current-prefix-arg))))
a384cab3
JB
2316 ;; there is a problem here in that if several menu items have the same
2317 ;; name you can only go to the node of the first with this command.
4fceda3c 2318 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
399c88ad 2319
a384cab3
JB
2320(defun Info-extract-menu-item (menu-item)
2321 (setq menu-item (regexp-quote menu-item))
1bcedb3b
RS
2322 (let ((case-fold-search t))
2323 (save-excursion
760d5cb3
GM
2324 (let ((case-fold-search t))
2325 (goto-char (point-min))
2326 (or (search-forward "\n* menu:" nil t)
2327 (error "No menu in this node"))
2328 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
2329 (re-search-forward (concat "\n\\* +" menu-item) nil t)
2330 (error "No such item in menu"))
2331 (beginning-of-line)
2332 (forward-char 2)
141b49f5 2333 (Info-extract-menu-node-name nil (Info-index-node))))))
a384cab3
JB
2334
2335;; If COUNT is nil, use the last item in the menu.
2336(defun Info-extract-menu-counting (count)
1bcedb3b
RS
2337 (let ((case-fold-search t))
2338 (save-excursion
760d5cb3
GM
2339 (let ((case-fold-search t))
2340 (goto-char (point-min))
2341 (or (search-forward "\n* menu:" nil t)
2342 (error "No menu in this node"))
2343 (if count
2344 (or (search-forward "\n* " nil t count)
2345 (error "Too few items in menu"))
2346 (while (search-forward "\n* " nil t)
2347 nil))
141b49f5 2348 (Info-extract-menu-node-name nil (Info-index-node))))))
a384cab3 2349
e38e7367
RM
2350(defun Info-nth-menu-item ()
2351 "Go to the node of the Nth menu item.
2352N is the digit argument used to invoke this command."
a384cab3 2353 (interactive)
e38e7367
RM
2354 (Info-goto-node
2355 (Info-extract-menu-counting
2356 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
a384cab3
JB
2357
2358(defun Info-top-node ()
2359 "Go to the Top node of this file."
2360 (interactive)
2361 (Info-goto-node "Top"))
2362
2363(defun Info-final-node ()
2364 "Go to the final node in this file."
2365 (interactive)
2366 (Info-goto-node "Top")
760d5cb3
GM
2367 (let ((Info-history nil)
2368 (case-fold-search t))
a384cab3
JB
2369 ;; Go to the last node in the menu of Top.
2370 (Info-goto-node (Info-extract-menu-counting nil))
2371 ;; If the last node in the menu is not last in pointer structure,
399c88ad 2372 ;; move forward until we can't go any farther.
a384cab3
JB
2373 (while (Info-forward-node t t) nil)
2374 ;; Then keep moving down to last subnode, unless we reach an index.
141b49f5 2375 (while (and (not (Info-index-node))
a384cab3
JB
2376 (save-excursion (search-forward "\n* Menu:" nil t)))
2377 (Info-goto-node (Info-extract-menu-counting nil)))))
2378
2379(defun Info-forward-node (&optional not-down no-error)
2380 "Go forward one node, considering all nodes as forming one sequence."
2381 (interactive)
2382 (goto-char (point-min))
2383 (forward-line 1)
760d5cb3
GM
2384 (let ((case-fold-search t))
2385 ;; three possibilities, in order of priority:
2386 ;; 1. next node is in a menu in this node (but not in an index)
2387 ;; 2. next node is next at same level
2388 ;; 3. next node is up and next
2389 (cond ((and (not not-down)
2390 (save-excursion (search-forward "\n* menu:" nil t))
141b49f5 2391 (not (Info-index-node)))
760d5cb3
GM
2392 (Info-goto-node (Info-extract-menu-counting 1))
2393 t)
6af7040d 2394 ((save-excursion (search-backward "next:" nil t))
760d5cb3
GM
2395 (Info-next)
2396 t)
6af7040d 2397 ((and (save-excursion (search-backward "up:" nil t))
760d5cb3
GM
2398 ;; Use string-equal, not equal, to ignore text props.
2399 (not (string-equal (downcase (Info-extract-pointer "up"))
2400 "top")))
2401 (let ((old-node Info-current-node))
2402 (Info-up)
2403 (let (Info-history success)
2404 (unwind-protect
2405 (setq success (Info-forward-node t no-error))
2406 (or success (Info-goto-node old-node))))))
2407 (no-error nil)
2408 (t (error "No pointer forward from this node")))))
a384cab3
JB
2409
2410(defun Info-backward-node ()
2411 "Go backward one node, considering all nodes as forming one sequence."
2412 (interactive)
2413 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
760d5cb3
GM
2414 (upnode (Info-extract-pointer "up" t))
2415 (case-fold-search t))
a384cab3
JB
2416 (cond ((and upnode (string-match "(" upnode))
2417 (error "First node in file"))
2418 ((and upnode (or (null prevnode)
e90d1271
RS
2419 ;; Use string-equal, not equal,
2420 ;; to ignore text properties.
2421 (string-equal (downcase prevnode)
2422 (downcase upnode))))
a384cab3
JB
2423 (Info-up))
2424 (prevnode
2425 ;; If we move back at the same level,
2426 ;; go down to find the last subnode*.
2427 (Info-prev)
2428 (let (Info-history)
141b49f5 2429 (while (and (not (Info-index-node))
a384cab3
JB
2430 (save-excursion (search-forward "\n* Menu:" nil t)))
2431 (Info-goto-node (Info-extract-menu-counting nil)))))
2432 (t
2433 (error "No pointer backward from this node")))))
2434
2435(defun Info-exit ()
2436 "Exit Info by selecting some other buffer."
2437 (interactive)
552775bd
RS
2438 (if Info-standalone
2439 (save-buffers-kill-emacs)
4643e92f 2440 (quit-window)))
a384cab3 2441
253db917 2442(defun Info-next-menu-item ()
3a8803c0 2443 "Go to the node of the next menu item."
253db917 2444 (interactive)
fdf4b680 2445 ;; Bind this in case the user sets it to nil.
760d5cb3
GM
2446 (let* ((case-fold-search t)
2447 (node
2448 (save-excursion
2449 (forward-line -1)
2450 (search-forward "\n* menu:" nil t)
2451 (and (search-forward "\n* " nil t)
2452 (Info-extract-menu-node-name)))))
fadfb77f
RS
2453 (if node (Info-goto-node node)
2454 (error "No more items in menu"))))
253db917
ER
2455
2456(defun Info-last-menu-item ()
3a8803c0 2457 "Go to the node of the previous menu item."
253db917
ER
2458 (interactive)
2459 (save-excursion
2460 (forward-line 1)
fdf4b680 2461 ;; Bind this in case the user sets it to nil.
760d5cb3
GM
2462 (let* ((case-fold-search t)
2463 (beg (save-excursion
2464 (and (search-backward "\n* menu:" nil t)
2465 (point)))))
0a56332b
RS
2466 (or (and beg (search-backward "\n* " beg t))
2467 (error "No previous items in menu")))
2468 (Info-goto-node (save-excursion
2469 (goto-char (match-end 0))
2470 (Info-extract-menu-node-name)))))
253db917 2471
552775bd 2472(defmacro Info-no-error (&rest body)
253db917
ER
2473 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
2474
2475(defun Info-next-preorder ()
3c9179ea
RS
2476 "Go to the next subnode or the next node, or go up a level."
2477 (interactive)
2478 (cond ((Info-no-error (Info-next-menu-item)))
2479 ((Info-no-error (Info-next)))
5dab2fb4 2480 ((Info-no-error (Info-up t))
ed690657
KH
2481 ;; Since we have already gone thru all the items in this menu,
2482 ;; go up to the end of this node.
b54d0f0e
RS
2483 (goto-char (point-max))
2484 ;; Since logically we are done with the node with that menu,
2485 ;; move on from it.
2486 (Info-next-preorder))
3c9179ea
RS
2487 (t
2488 (error "No more nodes"))))
253db917
ER
2489
2490(defun Info-last-preorder ()
2491 "Go to the last node, popping up a level if there is none."
2492 (interactive)
0a56332b
RS
2493 (cond ((Info-no-error
2494 (Info-last-menu-item)
2495 ;; If we go down a menu item, go to the end of the node
2496 ;; so we can scroll back through it.
ed690657 2497 (goto-char (point-max)))
b54d0f0e
RS
2498 ;; Keep going down, as long as there are nested menu nodes.
2499 (while (Info-no-error
2500 (Info-last-menu-item)
2501 ;; If we go down a menu item, go to the end of the node
2502 ;; so we can scroll back through it.
2503 (goto-char (point-max))))
ed690657 2504 (recenter -1))
c2def7a0
MB
2505 ((and (Info-no-error (Info-extract-pointer "prev"))
2506 (not (equal (Info-extract-pointer "up")
5dab2fb4
RS
2507 (Info-extract-pointer "prev"))))
2508 (Info-no-error (Info-prev))
ed690657 2509 (goto-char (point-max))
b54d0f0e
RS
2510 (while (Info-no-error
2511 (Info-last-menu-item)
2512 ;; If we go down a menu item, go to the end of the node
2513 ;; so we can scroll back through it.
2514 (goto-char (point-max))))
ed690657 2515 (recenter -1))
5dab2fb4 2516 ((Info-no-error (Info-up t))
ed690657 2517 (goto-char (point-min))
760d5cb3
GM
2518 (let ((case-fold-search t))
2519 (or (search-forward "\n* Menu:" nil t)
2520 (goto-char (point-max)))))
ed690657 2521 (t (error "No previous nodes"))))
253db917
ER
2522
2523(defun Info-scroll-up ()
3f32dc86 2524 "Scroll one screenful forward in Info, considering all nodes as one sequence.
280d11ed 2525Once you scroll far enough in a node that its menu appears on the screen
7a53d8c8
EZ
2526but after point, the next scroll moves into its first subnode, unless
2527`Info-scroll-prefer-subnodes' is nil.
280d11ed 2528
7a53d8c8
EZ
2529When you scroll past the end of a node, that goes to the next node if
2530`Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2531if this node has no successor, it moves to the parent node's successor,
2532and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2533the menu of a node, it moves to subnode indicated by the following menu
2534item. (That case won't normally result from this command, but can happen
2535in other ways.)"
280d11ed 2536
253db917 2537 (interactive)
0a56332b
RS
2538 (if (or (< (window-start) (point-min))
2539 (> (window-start) (point-max)))
2540 (set-window-start (selected-window) (point)))
760d5cb3
GM
2541 (let* ((case-fold-search t)
2542 (virtual-end (save-excursion
2543 (goto-char (point-min))
7a53d8c8
EZ
2544 (if (and Info-scroll-prefer-subnodes
2545 (search-forward "\n* Menu:" nil t))
760d5cb3
GM
2546 (point)
2547 (point-max)))))
0a56332b
RS
2548 (if (or (< virtual-end (window-start))
2549 (pos-visible-in-window-p virtual-end))
7a53d8c8
EZ
2550 (cond
2551 (Info-scroll-prefer-subnodes (Info-next-preorder))
2552 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2553 (t (Info-next-preorder)))
0a56332b 2554 (scroll-up))))
253db917
ER
2555
2556(defun Info-scroll-down ()
3f32dc86 2557 "Scroll one screenful back in Info, considering all nodes as one sequence.
c2def7a0
MB
2558If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2559is non-nil, this goes to its last subnode. When you scroll past the
2560beginning of a node, that goes to the previous node or back up to the
2561parent node."
253db917 2562 (interactive)
0a56332b
RS
2563 (if (or (< (window-start) (point-min))
2564 (> (window-start) (point-max)))
2565 (set-window-start (selected-window) (point)))
760d5cb3
GM
2566 (let* ((case-fold-search t)
2567 (current-point (point))
c2def7a0
MB
2568 (virtual-end
2569 (and Info-scroll-prefer-subnodes
2570 (save-excursion
2571 (beginning-of-line)
2572 (setq current-point (point))
2573 (goto-char (point-min))
2574 (search-forward "\n* Menu:"
2575 current-point
2576 t)))))
3a8803c0 2577 (if (or virtual-end
7afe24e3 2578 (pos-visible-in-window-p (point-min) nil t))
0a56332b
RS
2579 (Info-last-preorder)
2580 (scroll-down))))
253db917 2581
56cda6f5 2582(defun Info-next-reference (&optional recur)
552775bd
RS
2583 "Move cursor to the next cross-reference or menu item in the node."
2584 (interactive)
8a7757f6 2585 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
1bcedb3b
RS
2586 (old-pt (point))
2587 (case-fold-search t))
552775bd
RS
2588 (or (eobp) (forward-char 1))
2589 (or (re-search-forward pat nil t)
2590 (progn
2591 (goto-char (point-min))
2592 (or (re-search-forward pat nil t)
2593 (progn
2594 (goto-char old-pt)
2595 (error "No cross references in this node")))))
8a7757f6 2596 (goto-char (or (match-beginning 1) (match-beginning 0)))
552775bd 2597 (if (looking-at "\\* Menu:")
56cda6f5
RS
2598 (if recur
2599 (error "No cross references in this node")
185cff95
JL
2600 (Info-next-reference t))
2601 (if (looking-at "^\\* ")
2602 (forward-char 2)))))
552775bd 2603
56cda6f5 2604(defun Info-prev-reference (&optional recur)
552775bd
RS
2605 "Move cursor to the previous cross-reference or menu item in the node."
2606 (interactive)
8a7757f6 2607 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
1bcedb3b
RS
2608 (old-pt (point))
2609 (case-fold-search t))
552775bd
RS
2610 (or (re-search-backward pat nil t)
2611 (progn
2612 (goto-char (point-max))
2613 (or (re-search-backward pat nil t)
2614 (progn
2615 (goto-char old-pt)
2616 (error "No cross references in this node")))))
8a7757f6 2617 (goto-char (or (match-beginning 1) (match-beginning 0)))
552775bd 2618 (if (looking-at "\\* Menu:")
56cda6f5
RS
2619 (if recur
2620 (error "No cross references in this node")
185cff95
JL
2621 (Info-prev-reference t))
2622 (if (looking-at "^\\* ")
2623 (forward-char 2)))))
141b49f5
JL
2624\f
2625(defvar Info-index-nodes nil
2626 "Alist of cached index node names of visited Info files.
2627Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2628
2629(defun Info-index-nodes (&optional file)
2630 "Return a list of names of all index nodes in Info FILE.
2631If FILE is omitted, it defaults to the current Info file.
50163b00
JL
2632First look in a list of cached index node names. Then scan Info
2633file and its subfiles for nodes with the index cookie. Then try
2634to find index nodes starting from the first node in the top level
2635menu whose name contains the word \"Index\", plus any immediately
2636following nodes whose names also contain the word \"Index\"."
141b49f5
JL
2637 (or file (setq file Info-current-file))
2638 (or (assoc file Info-index-nodes)
2639 ;; Skip virtual Info files
50163b00
JL
2640 (and (member file '("dir" "history" "toc" "apropos"))
2641 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
2642 (not (stringp file))
141b49f5
JL
2643 ;; Find nodes with index cookie
2644 (let* ((default-directory (or (and (stringp file)
2645 (file-name-directory
2646 (setq file (Info-find-file file))))
2647 default-directory))
50163b00
JL
2648 Info-history Info-history-list Info-fontify-maximum-menu-size
2649 (main-file file) subfiles nodes node)
2650 (condition-case nil
2651 (with-temp-buffer
2652 (while (or main-file subfiles)
2653 (erase-buffer)
2654 (info-insert-file-contents (or main-file (car subfiles)))
2655 (goto-char (point-min))
2656 (while (search-forward "\0\b[index\0\b]" nil 'move)
2657 (save-excursion
2658 (re-search-backward "^\^_")
2659 (search-forward "Node: ")
2660 (setq nodes (cons (Info-following-node-name) nodes))))
2661 (if main-file
2662 (save-excursion
2663 (goto-char (point-min))
2664 (if (search-forward "\n\^_\nIndirect:" nil t)
2665 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2666 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2667 (setq subfiles (cons (match-string-no-properties 1)
2668 subfiles)))))
2669 (setq subfiles (nreverse subfiles)
2670 main-file nil))
2671 (setq subfiles (cdr subfiles)))))
2672 (error nil))
141b49f5
JL
2673 (if nodes
2674 (setq nodes (nreverse nodes)
2675 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2676 nodes)
50163b00
JL
2677 ;; Find nodes with the word "Index" in the node name
2678 (let ((case-fold-search t)
2679 Info-history Info-history-list Info-fontify-maximum-menu-size
2680 nodes node)
2681 (condition-case nil
2682 (with-temp-buffer
2683 (Info-mode)
2684 (Info-find-node file "Top")
2685 (when (and (search-forward "\n* menu:" nil t)
2686 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2687 (goto-char (match-beginning 1))
2688 (setq nodes (list (Info-extract-menu-node-name)))
2689 (Info-goto-node (car nodes))
2690 (while (and (setq node (Info-extract-pointer "next" t))
2691 (string-match "\\<Index\\>" node))
2692 (setq nodes (cons node nodes))
2693 (Info-goto-node node))))
2694 (error nil))
141b49f5
JL
2695 (if nodes
2696 (setq nodes (nreverse nodes)
2697 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2698 nodes)
50163b00
JL
2699 ;; If file has no index nodes, still add it to the cache
2700 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
141b49f5
JL
2701 (cdr (assoc file Info-index-nodes)))
2702
2703(defun Info-index-node (&optional node file)
2704 "Return non-nil value if NODE is an index node.
2705If NODE is nil, check the current Info node.
2706If FILE is nil, check the current Info file."
50163b00
JL
2707 (if (or (and node (not (equal node Info-current-node)))
2708 (assoc (or file Info-current-file) Info-index-nodes))
2709 (member (or node Info-current-node) (Info-index-nodes file))
2710 ;; Don't search all index nodes if request is only for the current node
2711 ;; and file is not in the cache of index nodes
2712 (or
2713 (save-match-data
2714 (string-match "\\<Index\\>" (or node Info-current-node "")))
2715 (save-excursion
2716 (goto-char (+ (or (save-excursion
2717 (search-backward "\n\^_" nil t))
2718 (point-min)) 2))
2719 (search-forward "\0\b[index\0\b]"
2720 (or (save-excursion
2721 (search-forward "\n\^_" nil t))
2722 (point-max)) t)))))
552775bd 2723
e4e8ee63 2724(defun Info-goto-index ()
141b49f5
JL
2725 "Go to the first index node."
2726 (let ((node (car (Info-index-nodes))))
2727 (or node (error "No index"))
2728 (Info-goto-node node)))
e4e8ee63 2729
201bc1bd 2730;;;###autoload
1143a6b0 2731(defun Info-index (topic)
fdf4b680 2732 "Look up a string TOPIC in the index for this file.
1143a6b0
ER
2733If there are no exact matches to the specified topic, this chooses
2734the first match which is a case-insensitive substring of a topic.
89b064a9 2735Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
1143a6b0 2736Give a blank topic name to go to the Index node itself."
e4e8ee63
SM
2737 (interactive
2738 (list
2739 (let ((Info-complete-menu-buffer (clone-buffer))
141b49f5
JL
2740 (Info-complete-nodes (Info-index-nodes))
2741 (Info-history-list nil))
aebd1760
RS
2742 (if (equal Info-current-file "dir")
2743 (error "The Info directory node has no index; use m to select a manual"))
e4e8ee63
SM
2744 (unwind-protect
2745 (with-current-buffer Info-complete-menu-buffer
2746 (Info-goto-index)
2747 (completing-read "Index topic: " 'Info-complete-menu-item))
2748 (kill-buffer Info-complete-menu-buffer)))))
aebd1760
RS
2749 (if (equal Info-current-file "dir")
2750 (error "The Info directory node has no index; use m to select a manual"))
1143a6b0 2751 (let ((orignode Info-current-node)
836bb478 2752 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
1143a6b0 2753 (regexp-quote topic)))
141b49f5
JL
2754 node (nodes (Info-index-nodes))
2755 (ohist-list Info-history-list)
1bcedb3b 2756 (case-fold-search t))
e700ec12 2757 (Info-goto-index)
1143a6b0
ER
2758 (or (equal topic "")
2759 (let ((matches nil)
2760 (exact nil)
e700ec12
SM
2761 ;; We bind Info-history to nil for internal node-switches so
2762 ;; that we don't put junk in the history. In the first
2763 ;; Info-goto-index call, above, we do update the history
2764 ;; because that is what the user's previous node choice into it.
c696ac76 2765 (Info-history nil)
1143a6b0
ER
2766 found)
2767 (while
2768 (progn
2769 (goto-char (point-min))
2770 (while (re-search-forward pattern nil t)
983dfbf8
SM
2771 (push (list (match-string-no-properties 1)
2772 (match-string-no-properties 2)
2773 Info-current-node
3a8803c0
JPW
2774 (string-to-number (concat "0"
2775 (match-string 3))))
983dfbf8 2776 matches))
141b49f5 2777 (setq nodes (cdr nodes) node (car nodes)))
1143a6b0
ER
2778 (Info-goto-node node))
2779 (or matches
2780 (progn
81e14cb2 2781 (Info-goto-node orignode)
920bdaab 2782 (error "No `%s' in index" topic)))
1143a6b0
ER
2783 ;; Here it is a feature that assoc is case-sensitive.
2784 (while (setq found (assoc topic matches))
2785 (setq exact (cons found exact)
2786 matches (delq found matches)))
141b49f5 2787 (setq Info-history-list ohist-list)
1143a6b0
ER
2788 (setq Info-index-alternatives (nconc exact (nreverse matches)))
2789 (Info-index-next 0)))))
2790
2791(defun Info-index-next (num)
89b064a9 2792 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
1143a6b0
ER
2793 (interactive "p")
2794 (or Info-index-alternatives
882e61bf 2795 (error "No previous `i' command"))
1143a6b0
ER
2796 (while (< num 0)
2797 (setq num (+ num (length Info-index-alternatives))))
2798 (while (> num 0)
2799 (setq Info-index-alternatives
2800 (nconc (cdr Info-index-alternatives)
2801 (list (car Info-index-alternatives)))
2802 num (1- num)))
2803 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2804 (if (> (nth 3 (car Info-index-alternatives)) 0)
836bb478 2805 (forward-line (1- (nth 3 (car Info-index-alternatives))))
760d5cb3 2806 (forward-line 3) ; don't search in headers
1143a6b0 2807 (let ((name (car (car Info-index-alternatives))))
920bdaab
RS
2808 (Info-find-index-name name)))
2809 (message "Found `%s' in %s. %s"
1143a6b0
ER
2810 (car (car Info-index-alternatives))
2811 (nth 2 (car Info-index-alternatives))
2812 (if (cdr Info-index-alternatives)
c702ed73 2813 "(`,' tries to find next)"
1143a6b0
ER
2814 "(Only match)")))
2815
920bdaab
RS
2816(defun Info-find-index-name (name)
2817 "Move point to the place within the current node where NAME is defined."
1bcedb3b
RS
2818 (let ((case-fold-search t))
2819 (if (or (re-search-forward (format
2820 "[a-zA-Z]+: %s\\( \\|$\\)"
2821 (regexp-quote name)) nil t)
d31c6ecf
RS
2822 ;; Find a function definition with a return type.
2823 (re-search-forward (format
f2fc5b0a 2824 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
d31c6ecf 2825 (regexp-quote name)) nil t)
1bcedb3b
RS
2826 (search-forward (format "`%s'" name) nil t)
2827 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2828 (search-forward
2829 (format "`%s'" (substring name 0 (match-beginning 1)))
2830 nil t))
bbe054f7
EZ
2831 (search-forward name nil t)
2832 ;; Try again without the " <1>" makeinfo can append
2833 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
2834 (Info-find-index-name (match-string 1 name))))
2835 (progn (beginning-of-line) t) ;; non-nil for recursive call
1bcedb3b 2836 (goto-char (point-min)))))
920bdaab 2837
ab2f22ad
JH
2838;;;###autoload
2839(defun info-apropos (string)
2840 "Grovel indices of all known Info files on your system for STRING.
2841Build a menu of the possible matches."
2842 (interactive "sIndex apropos: ")
2843 (unless (string= string "")
836bb478 2844 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
ab2f22ad
JH
2845 (regexp-quote string)))
2846 (ohist Info-history)
37600b6d 2847 (ohist-list Info-history-list)
ab2f22ad
JH
2848 (current-node Info-current-node)
2849 (current-file Info-current-file)
141b49f5
JL
2850 manuals matches node nodes)
2851 (let ((Info-fontify-maximum-menu-size nil))
ab2f22ad
JH
2852 (Info-directory)
2853 (message "Searching indices...")
2854 (goto-char (point-min))
2855 (re-search-forward "\\* Menu: *\n" nil t)
7b30b20c 2856 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
185cff95
JL
2857 (setq manuals (cons (match-string 1) manuals)))
2858 (dolist (manual (nreverse manuals))
ab2f22ad 2859 (message "Searching %s" manual)
185cff95
JL
2860 (condition-case err
2861 (if (setq nodes (Info-index-nodes (Info-find-file manual)))
141b49f5
JL
2862 (save-excursion
2863 (Info-find-node manual (car nodes))
2864 (while
2865 (progn
2866 (goto-char (point-min))
2867 (while (re-search-forward pattern nil t)
185cff95
JL
2868 (setq matches
2869 (cons (list manual
2870 (match-string-no-properties 1)
2871 (match-string-no-properties 2)
2872 (match-string-no-properties 3))
2873 matches)))
141b49f5 2874 (setq nodes (cdr nodes) node (car nodes)))
185cff95
JL
2875 (Info-goto-node node))))
2876 (error
2877 (message "%s" (if (eq (car-safe err) 'error)
2878 (nth 1 err) err))
2879 (sit-for 1 t)))))
ab2f22ad 2880 (Info-goto-node (concat "(" current-file ")" current-node))
37600b6d
JH
2881 (setq Info-history ohist
2882 Info-history-list ohist-list)
ab2f22ad
JH
2883 (message "Searching indices...done")
2884 (if (null matches)
2885 (message "No matches found")
2886 (with-current-buffer (get-buffer-create " *info-apropos*")
2887 (erase-buffer)
141b49f5 2888 (insert "\n\^_\nFile: apropos, Node: Index, Up: (dir)\n")
185cff95
JL
2889 (insert "* Menu: \nNodes whose indices contain `" string "':\n\n")
2890 (dolist (entry (nreverse matches))
5242942f
JH
2891 (insert
2892 (format "* %-38s (%s)%s.%s\n"
2893 (concat (nth 1 entry) " [" (nth 0 entry) "]:")
2894 (nth 0 entry)
2895 (nth 2 entry)
2896 (if (nth 3 entry)
2897 (concat " (line " (nth 3 entry) ")")
2898 "")))))
2899 (Info-find-node "apropos" "Index")
82f1aca9 2900 (setq Info-complete-cache nil)))))
ab2f22ad 2901
a384cab3
JB
2902(defun Info-undefined ()
2903 "Make command be undefined in Info."
2904 (interactive)
2905 (ding))
2906
2907(defun Info-help ()
2908 "Enter the Info tutorial."
2909 (interactive)
2910 (delete-other-windows)
2911 (Info-find-node "info"
2912 (if (< (window-height) 23)
2913 "Help-Small-Screen"
2914 "Help")))
2915
2916(defun Info-summary ()
2917 "Display a brief summary of all Info commands."
2918 (interactive)
2919 (save-window-excursion
2920 (switch-to-buffer "*Help*")
881c84c7 2921 (setq buffer-read-only nil)
a384cab3
JB
2922 (erase-buffer)
2923 (insert (documentation 'Info-mode))
9d29f94c 2924 (help-mode)
a384cab3
JB
2925 (goto-char (point-min))
2926 (let (ch flag)
2927 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2928 (message (if flag "Type Space to see more"
2929 "Type Space to return to Info"))
fc039bdc 2930 (if (not (eq ?\s (setq ch (read-event))))
dbc4e1c1 2931 (progn (setq unread-command-events (list ch)) nil)
a384cab3 2932 flag))
552775bd
RS
2933 (scroll-up)))
2934 (bury-buffer "*Help*")))
a384cab3
JB
2935\f
2936(defun Info-get-token (pos start all &optional errorstring)
fdf4b680 2937 "Return the token around POS.
a384cab3
JB
2938POS must be somewhere inside the token
2939START is a regular expression which will match the
2940 beginning of the tokens delimited string
2941ALL is a regular expression with a single
90a715f0 2942 parenthesized subpattern which is the token to be
fdf4b680 2943 returned. E.g. '{\(.*\)}' would return any string
a384cab3 2944 enclosed in braces around POS.
fdf4b680 2945ERRORSTRING optional fourth argument, controls action on no match
a384cab3
JB
2946 nil: return nil
2947 t: beep
2948 a string: signal an error, using that string."
1bcedb3b
RS
2949 (let ((case-fold-search t))
2950 (save-excursion
2951 (goto-char pos)
2952 ;; First look for a match for START that goes across POS.
2953 (while (and (not (bobp)) (> (point) (- pos (length start)))
2954 (not (looking-at start)))
2955 (forward-char -1))
2956 ;; If we did not find one, search back for START
2957 ;; (this finds only matches that end at or before POS).
2958 (or (looking-at start)
2959 (progn
2960 (goto-char pos)
2961 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
2962 (let (found)
2963 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2964 (not (setq found (and (<= (match-beginning 0) pos)
2965 (> (match-end 0) pos))))))
2966 (if (and found (<= (match-beginning 0) pos)
2967 (> (match-end 0) pos))
110d4e80 2968 (match-string-no-properties 1)
1bcedb3b
RS
2969 (cond ((null errorstring)
2970 nil)
2971 ((eq errorstring t)
2972 (beep)
2973 nil)
2974 (t
2975 (error "No %s around position %d" errorstring pos))))))))
a384cab3 2976
981947af 2977(defun Info-mouse-follow-nearest-node (click)
f9969361
RS
2978 "\\<Info-mode-map>Follow a node reference near point.
2979Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
981947af 2980At end of the node's text, moves to the next node, or up if none."
f9969361 2981 (interactive "e")
d1268e52 2982 (mouse-set-point click)
981947af
KH
2983 (and (not (Info-try-follow-nearest-node))
2984 (save-excursion (forward-line 1) (eobp))
ed690657 2985 (Info-next-preorder)))
981947af 2986
8a7757f6 2987(defun Info-follow-nearest-node (&optional fork)
d0b560c6
JB
2988 "Follow a node reference near point.
2989If point is on a reference, follow that reference. Otherwise,
2990if point is in a menu item description, follow that menu item."
8a7757f6
JL
2991 (interactive "P")
2992 (or (Info-try-follow-nearest-node fork)
d0b560c6
JB
2993 (when (save-excursion
2994 (search-backward "\n* menu:" nil t))
2995 (save-excursion
2996 (beginning-of-line)
2997 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2998 (beginning-of-line 0))
2999 (when (looking-at "\\* +\\([^\t\n]*\\):")
3000 (Info-goto-node
8a7757f6 3001 (Info-extract-menu-item (match-string-no-properties 1)) fork)
d0b560c6
JB
3002 t)))
3003 (error "Point neither on reference nor in menu item description")))
981947af
KH
3004
3005;; Common subroutine.
8a7757f6 3006(defun Info-try-follow-nearest-node (&optional fork)
981947af 3007 "Follow a node reference near point. Return non-nil if successful."
6af7040d 3008 (let (node)
a384cab3 3009 (cond
6b3600ff 3010 ((Info-get-token (point) "[hf]t?tp://" "[hf]t?tp://\\([^ \t\n\"`({<>})']+\\)")
8a7757f6
JL
3011 (setq node t)
3012 (browse-url (browse-url-url-at-point)))
3013 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
3014 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
8a7757f6 3015 (Info-follow-reference node fork))
505b68d5 3016 ;; menu item: node name
b37daea4 3017 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
8a7757f6 3018 (Info-goto-node node fork))
836bb478 3019 ;; menu item: node name or index entry
505b68d5 3020 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
631ba13e
RS
3021 (beginning-of-line)
3022 (forward-char 2)
141b49f5 3023 (setq node (Info-extract-menu-node-name nil (Info-index-node)))
8a7757f6 3024 (Info-goto-node node fork))
bc2ada62 3025 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
8a7757f6 3026 (Info-goto-node node fork))
bc2ada62 3027 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
8a7757f6 3028 (Info-goto-node node fork))
bc2ada62 3029 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
8a7757f6 3030 (Info-goto-node "Top" fork))
bc2ada62 3031 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
8a7757f6 3032 (Info-goto-node node fork)))
981947af 3033 node))
a384cab3
JB
3034\f
3035(defvar Info-mode-map nil
3036 "Keymap containing Info commands.")
3037(if Info-mode-map
3038 nil
3039 (setq Info-mode-map (make-keymap))
3040 (suppress-keymap Info-mode-map)
3041 (define-key Info-mode-map "." 'beginning-of-buffer)
253db917 3042 (define-key Info-mode-map " " 'Info-scroll-up)
981947af 3043 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
552775bd 3044 (define-key Info-mode-map "\t" 'Info-next-reference)
508f27a0
RS
3045 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
3046 (define-key Info-mode-map [backtab] 'Info-prev-reference)
e38e7367
RM
3047 (define-key Info-mode-map "1" 'Info-nth-menu-item)
3048 (define-key Info-mode-map "2" 'Info-nth-menu-item)
3049 (define-key Info-mode-map "3" 'Info-nth-menu-item)
3050 (define-key Info-mode-map "4" 'Info-nth-menu-item)
3051 (define-key Info-mode-map "5" 'Info-nth-menu-item)
3052 (define-key Info-mode-map "6" 'Info-nth-menu-item)
3053 (define-key Info-mode-map "7" 'Info-nth-menu-item)
3054 (define-key Info-mode-map "8" 'Info-nth-menu-item)
3055 (define-key Info-mode-map "9" 'Info-nth-menu-item)
82a4c008 3056 (define-key Info-mode-map "0" 'undefined)
a384cab3
JB
3057 (define-key Info-mode-map "?" 'Info-summary)
3058 (define-key Info-mode-map "]" 'Info-forward-node)
3059 (define-key Info-mode-map "[" 'Info-backward-node)
3060 (define-key Info-mode-map "<" 'Info-top-node)
3061 (define-key Info-mode-map ">" 'Info-final-node)
3062 (define-key Info-mode-map "b" 'beginning-of-buffer)
3063 (define-key Info-mode-map "d" 'Info-directory)
3064 (define-key Info-mode-map "e" 'Info-edit)
3065 (define-key Info-mode-map "f" 'Info-follow-reference)
3066 (define-key Info-mode-map "g" 'Info-goto-node)
3067 (define-key Info-mode-map "h" 'Info-help)
1143a6b0 3068 (define-key Info-mode-map "i" 'Info-index)
424b9d3e 3069 (define-key Info-mode-map "l" 'Info-history-back)
bc224645 3070 (define-key Info-mode-map "L" 'Info-history)
a384cab3
JB
3071 (define-key Info-mode-map "m" 'Info-menu)
3072 (define-key Info-mode-map "n" 'Info-next)
3073 (define-key Info-mode-map "p" 'Info-prev)
3074 (define-key Info-mode-map "q" 'Info-exit)
424b9d3e 3075 (define-key Info-mode-map "r" 'Info-history-forward)
a384cab3 3076 (define-key Info-mode-map "s" 'Info-search)
50163b00 3077 (define-key Info-mode-map "S" 'Info-search-case-sensitively)
47fc33ca
RS
3078 ;; For consistency with Rmail.
3079 (define-key Info-mode-map "\M-s" 'Info-search)
4fceda3c 3080 (define-key Info-mode-map "\M-n" 'clone-buffer)
db0c9809 3081 (define-key Info-mode-map "t" 'Info-top-node)
bc224645 3082 (define-key Info-mode-map "T" 'Info-toc)
a384cab3 3083 (define-key Info-mode-map "u" 'Info-up)
185cff95 3084 ;; `w' for consistency with `dired-copy-filename-as-kill'.
50163b00 3085 (define-key Info-mode-map "w" 'Info-copy-current-node-name)
185cff95
JL
3086 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
3087 ;; `^' for consistency with `dired-up-directory'.
3088 (define-key Info-mode-map "^" 'Info-up)
1143a6b0 3089 (define-key Info-mode-map "," 'Info-index-next)
803eaf50 3090 (define-key Info-mode-map "\177" 'Info-scroll-down)
981947af 3091 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
3c1498ac 3092 (define-key Info-mode-map [follow-link] 'mouse-face)
aea2a8da 3093 )
75a209d4
RS
3094
3095(defun Info-check-pointer (item)
fdf4b680 3096 "Non-nil if ITEM is present in this node."
75a209d4
RS
3097 (condition-case nil
3098 (Info-extract-pointer item)
3099 (error nil)))
3100
d4af987a
DL
3101(easy-menu-define
3102 Info-mode-menu Info-mode-map
185cff95 3103 "Menu for Info files."
d4af987a
DL
3104 '("Info"
3105 ["Up" Info-up :active (Info-check-pointer "up")
3106 :help "Go up in the Info tree"]
3107 ["Next" Info-next :active (Info-check-pointer "next")
3108 :help "Go to the next node"]
3109 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3110 :help "Go to the previous node"]
3111 ["Backward" Info-backward-node
3112 :help "Go backward one node, considering all as a sequence"]
3113 ["Forward" Info-forward-node
3114 :help "Go forward one node, considering all as a sequence"]
7210b6f5
DL
3115 ["Beginning" beginning-of-buffer
3116 :help "Go to beginning of this node"]
d4af987a
DL
3117 ["Top" Info-top-node
3118 :help "Go to top node of file"]
3119 ["Final Node" Info-final-node
3120 :help "Go to final node in this file"]
3121 ("Menu Item" ["You should never see this" report-emacs-bug t])
3122 ("Reference" ["You should never see this" report-emacs-bug t])
3123 ["Search..." Info-search
3124 :help "Search for regular expression in this Info file"]
8a7757f6
JL
3125 ["Search Next" Info-search-next
3126 :help "Search for another occurrence of regular expression"]
d1268e52 3127 ["Go to Node..." Info-goto-node
d4af987a 3128 :help "Go to a named node"]
424b9d3e
JL
3129 ["Back in history" Info-history-back :active Info-history
3130 :help "Go back in history to the last node you were at"]
3131 ["Forward in history" Info-history-forward :active Info-history-forward
3132 :help "Go forward in history"]
8a7757f6 3133 ["History" Info-history :active Info-history-list
bc224645 3134 :help "Go to menu of visited nodes"]
8a7757f6 3135 ["Table of Contents" Info-toc
bc224645 3136 :help "Go to table of contents"]
5938202c
JL
3137 ("Index"
3138 ["Lookup a String..." Info-index
d4af987a 3139 :help "Look for a string in the index items"]
5938202c 3140 ["Next Matching Item" Info-index-next :active Info-index-alternatives
ab2f22ad 3141 :help "Look for another occurrence of previous item"]
5938202c 3142 ["Lookup a string in all indices..." info-apropos
ab2f22ad 3143 :help "Look for a string in the indices of all manuals"])
7210b6f5
DL
3144 ["Edit" Info-edit :help "Edit contents of this node"
3145 :active Info-enable-edit]
126f5d4d
MB
3146 ["Copy Node Name" Info-copy-current-node-name
3147 :help "Copy the name of the current node into the kill ring"]
8a7757f6
JL
3148 ["Clone Info buffer" clone-buffer
3149 :help "Create a twin copy of the current Info buffer."]
ec03f31e 3150 ["Exit" Info-exit :help "Stop reading Info"]))
75a209d4 3151
7210b6f5
DL
3152
3153(defvar info-tool-bar-map
3154 (if (display-graphic-p)
df6aed99
RS
3155 (let ((map (make-sparse-keymap)))
3156 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
3157 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
3158 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
3159 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
424b9d3e
JL
3160 (tool-bar-local-item-from-menu 'Info-history-back "back_arrow" map Info-mode-map)
3161 (tool-bar-local-item-from-menu 'Info-history-forward "fwd_arrow" map Info-mode-map)
df6aed99
RS
3162 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
3163 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
3164 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
3165 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
3166 map)))
7210b6f5 3167
75a209d4
RS
3168(defvar Info-menu-last-node nil)
3169;; Last node the menu was created for.
6d2c8e3e 3170;; Value is a list, (FILE-NAME NODE-NAME).
75a209d4
RS
3171
3172(defun Info-menu-update ()
fdf4b680 3173 "Update the Info menu for the current node."
75a209d4
RS
3174 (condition-case nil
3175 (if (or (not (eq major-mode 'Info-mode))
6d2c8e3e
RS
3176 (equal (list Info-current-file Info-current-node)
3177 Info-menu-last-node))
75a209d4
RS
3178 ()
3179 ;; Update menu menu.
3180 (let* ((Info-complete-menu-buffer (current-buffer))
3181 (items (nreverse (condition-case nil
e4e8ee63 3182 (Info-complete-menu-item "" nil t)
75a209d4 3183 (error nil))))
399c88ad 3184 entries current
75a209d4
RS
3185 (number 0))
3186 (while (and items (< number 9))
3187 (setq current (car items)
3188 items (cdr items)
3189 number (1+ number))
399c88ad 3190 (setq entries (cons `[,current
75a209d4
RS
3191 (Info-menu ,current)
3192 :keys ,(format "%d" number)]
3193 entries)))
3194 (if items
3195 (setq entries (cons ["Other..." Info-menu t] entries)))
3196 (or entries
5d5845dc 3197 (setq entries (list ["No menu" nil nil] nil :active)))
d4af987a 3198 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
75a209d4
RS
3199 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3200 (let ((items nil)
399c88ad 3201 str i entries current
1bcedb3b
RS
3202 (number 0)
3203 (case-fold-search t))
75a209d4
RS
3204 (save-excursion
3205 (goto-char (point-min))
8a7757f6 3206 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
c60c12be 3207 (setq str (match-string 1))
75a209d4
RS
3208 (setq i 0)
3209 (while (setq i (string-match "[ \n\t]+" str i))
3210 (setq str (concat (substring str 0 i) " "
3211 (substring str (match-end 0))))
3212 (setq i (1+ i)))
3213 (setq items
3214 (cons str items))))
3215 (while (and items (< number 9))
3216 (setq current (car items)
3217 items (cdr items)
3218 number (1+ number))
399c88ad 3219 (setq entries (cons `[,current
75a209d4
RS
3220 (Info-follow-reference ,current)
3221 t]
3222 entries)))
3223 (if items
3224 (setq entries (cons ["Other..." Info-follow-reference t]
3225 entries)))
3226 (or entries
5d5845dc 3227 (setq entries (list ["No references" nil nil] nil :active)))
75a209d4
RS
3228 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3229 ;; Update last seen node.
6d2c8e3e 3230 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
75a209d4
RS
3231 ;; Try to avoid entering infinite beep mode in case of errors.
3232 (error (ding))))
3233
a384cab3 3234\f
50163b00 3235(defun Info-copy-current-node-name (&optional arg)
185cff95
JL
3236 "Put the name of the current Info node into the kill ring.
3237The name of the Info file is prepended to the node name in parentheses.
50163b00
JL
3238With a zero prefix arg, put the name inside a function call to `info'."
3239 (interactive "P")
126f5d4d 3240 (unless Info-current-node
185cff95 3241 (error "No current Info node"))
50163b00
JL
3242 (let ((node (concat "(" (file-name-nondirectory
3243 (or (and (stringp Info-current-file)
3244 Info-current-file)
3245 buffer-file-name
3246 ""))
3247 ")" Info-current-node)))
3248 (if (zerop (prefix-numeric-value arg))
3249 (setq node (concat "(info \"" node "\")")))
3250 (kill-new node)
3251 (message "%s" node)))
126f5d4d
MB
3252
3253\f
a384cab3 3254;; Info mode is suitable only for specially formatted data.
68bc119c 3255(put 'Info-mode 'mode-class 'special)
2fa8f8a4 3256(put 'Info-mode 'no-clone-indirect t)
a384cab3 3257
f4f2bca3
RS
3258(defvar tool-bar-map)
3259
80123c9e
LH
3260;; Autoload cookie needed by desktop.el
3261;;;###autoload
a384cab3 3262(defun Info-mode ()
fdf4b680 3263 "Info mode provides commands for browsing through the Info documentation tree.
a384cab3
JB
3264Documentation in Info is divided into \"nodes\", each of which discusses
3265one topic and contains references to other nodes which discuss related
3266topics. Info has commands to follow the references and show you other nodes.
3267
fdf4b680 3268\\<Info-mode-map>\
a384cab3 3269\\[Info-help] Invoke the Info tutorial.
6b136ab9 3270\\[Info-exit] Quit Info: reselect previously selected buffer.
a384cab3
JB
3271
3272Selecting other nodes:
21d5959f
RS
3273\\[Info-mouse-follow-nearest-node]
3274 Follow a node reference you click on.
3275 This works with menu items, cross references, and
3276 the \"next\", \"previous\" and \"up\", depending on where you click.
6b136ab9 3277\\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
a384cab3 3278\\[Info-next] Move to the \"next\" node of this node.
bc2ada62 3279\\[Info-prev] Move to the \"previous\" node of this node.
a384cab3
JB
3280\\[Info-up] Move \"up\" from this node.
3281\\[Info-menu] Pick menu item specified by name (or abbreviation).
e8042313 3282 Picking a menu item causes another node to be selected.
aea2a8da 3283\\[Info-directory] Go to the Info directory node.
a384cab3 3284\\[Info-follow-reference] Follow a cross reference. Reads name of reference.
424b9d3e
JL
3285\\[Info-history-back] Move back in history to the last node you were at.
3286\\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
bc224645
JL
3287\\[Info-history] Go to menu of visited nodes.
3288\\[Info-toc] Go to table of contents of the current Info file.
6b136ab9
DL
3289\\[Info-top-node] Go to the Top node of this file.
3290\\[Info-final-node] Go to the final node in this file.
3291\\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3292\\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
bc224645
JL
3293\\[Info-index] Look up a topic in this file's Index and move to that node.
3294\\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3295\\[info-apropos] Look for a string in the indices of all manuals.
a384cab3
JB
3296
3297Moving within a node:
177c3549 3298\\[Info-scroll-up] Normally, scroll forward a full screen.
e8042313
PJ
3299 Once you scroll far enough in a node that its menu appears on the
3300 screen but after point, the next scroll moves into its first
3301 subnode. When after all menu items (or if there is no menu),
3302 move up to the parent node.
177c3549 3303\\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
e8042313
PJ
3304 already visible, try to go to the previous menu entry, or up
3305 if there is none.
399c88ad 3306\\[beginning-of-buffer] Go to beginning of node.
a384cab3 3307
a384cab3 3308Advanced commands:
185cff95 3309\\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
8a7757f6 3310\\[clone-buffer] Select a new cloned Info buffer in another window.
a384cab3 3311\\[Info-edit] Edit contents of selected node.
bc224645
JL
33121 .. 9 Pick first ... ninth item in node's menu.
3313 Every third `*' is highlighted to help pick the right number.
a384cab3 3314\\[Info-goto-node] Move to node specified by name.
e8042313 3315 You may include a filename as well, as (FILENAME)NODENAME.
552775bd 3316\\[universal-argument] \\[info] Move to new Info file with completion.
bc224645 3317\\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>.
a384cab3 3318\\[Info-search] Search through this Info file for specified regexp,
e8042313 3319 and select the node in which the next occurrence is found.
bc224645 3320\\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
8a7757f6 3321\\[Info-search-next] Search for another occurrence of regexp
89b064a9 3322 from a previous \\<Info-mode-map>\\[Info-search] command.
552775bd
RS
3323\\[Info-next-reference] Move cursor to next cross-reference or menu item.
3324\\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
a384cab3
JB
3325 (kill-all-local-variables)
3326 (setq major-mode 'Info-mode)
3327 (setq mode-name "Info")
f73299f3 3328 (setq tab-width 8)
a384cab3 3329 (use-local-map Info-mode-map)
75a209d4 3330 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
a384cab3
JB
3331 (set-syntax-table text-mode-syntax-table)
3332 (setq local-abbrev-table text-mode-abbrev-table)
3333 (setq case-fold-search t)
3334 (setq buffer-read-only t)
a384cab3
JB
3335 (make-local-variable 'Info-current-file)
3336 (make-local-variable 'Info-current-subfile)
3337 (make-local-variable 'Info-current-node)
3338 (make-local-variable 'Info-tag-table-marker)
c5fe2ff1
RS
3339 (setq Info-tag-table-marker (make-marker))
3340 (make-local-variable 'Info-tag-table-buffer)
3341 (setq Info-tag-table-buffer nil)
a384cab3 3342 (make-local-variable 'Info-history)
424b9d3e 3343 (make-local-variable 'Info-history-forward)
1143a6b0 3344 (make-local-variable 'Info-index-alternatives)
dde7f979
SM
3345 (setq header-line-format
3346 (if Info-use-header-line
3536c121 3347 '(:eval (get-text-property (point-min) 'header-line))
dde7f979 3348 nil)) ; so the header line isn't displayed
7210b6f5 3349 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
93480d70
RS
3350 ;; This is for the sake of the invisible text we use handling titles.
3351 (make-local-variable 'line-move-ignore-invisible)
3352 (setq line-move-ignore-invisible t)
9d9d10ec 3353 (make-local-variable 'desktop-save-buffer)
ab357a65
RS
3354 (make-local-variable 'widen-automatically)
3355 (setq widen-automatically nil)
9d9d10ec 3356 (setq desktop-save-buffer 'Info-desktop-buffer-misc-data)
34d86208 3357 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
b7aeabeb 3358 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
3d12b331 3359 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
d457219d 3360 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
0b02cda9
JL
3361 (set (make-local-variable 'isearch-search-fun-function)
3362 'Info-isearch-search)
3363 (set (make-local-variable 'isearch-wrap-function)
3364 'Info-isearch-wrap)
3365 (set (make-local-variable 'isearch-push-state-function)
3366 'Info-isearch-push-state)
3367 (set (make-local-variable 'search-whitespace-regexp)
3368 Info-search-whitespace-regexp)
a384cab3 3369 (Info-set-mode-line)
d39f149d 3370 (run-mode-hooks 'Info-mode-hook))
a384cab3 3371
34d86208
JL
3372;; When an Info buffer is killed, make sure the associated tags buffer
3373;; is killed too.
3374(defun Info-kill-buffer ()
3375 (and (eq major-mode 'Info-mode)
3376 Info-tag-table-buffer
3377 (kill-buffer Info-tag-table-buffer)))
3378
4fceda3c
SM
3379(defun Info-clone-buffer-hook ()
3380 (when (bufferp Info-tag-table-buffer)
3381 (setq Info-tag-table-buffer
4ce5c223
SM
3382 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
3383 (let ((m Info-tag-table-marker))
3384 (when (markerp m)
15533ae2 3385 (setq Info-tag-table-marker
4ce5c223 3386 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
15533ae2
SM
3387 (with-current-buffer Info-tag-table-buffer
3388 (copy-marker (marker-position m)))
3389 (make-marker))))))
4fceda3c 3390
7210b6f5
DL
3391(defvar Info-edit-map (let ((map (make-sparse-keymap)))
3392 (set-keymap-parent map text-mode-map)
3393 (define-key map "\C-c\C-c" 'Info-cease-edit)
3394 map)
a384cab3 3395 "Local keymap used within `e' command of Info.")
a384cab3
JB
3396
3397;; Info-edit mode is suitable only for specially formatted data.
68bc119c 3398(put 'Info-edit-mode 'mode-class 'special)
a384cab3
JB
3399
3400(defun Info-edit-mode ()
3401 "Major mode for editing the contents of an Info node.
a426b157 3402Like text mode with the addition of `Info-cease-edit'
a384cab3
JB
3403which returns to Info mode for browsing.
3404\\{Info-edit-map}"
a384cab3
JB
3405 (use-local-map Info-edit-map)
3406 (setq major-mode 'Info-edit-mode)
3407 (setq mode-name "Info Edit")
3408 (kill-local-variable 'mode-line-buffer-identification)
3409 (setq buffer-read-only nil)
2c609f53 3410 (force-mode-line-update)
e82c28f9 3411 (buffer-enable-undo (current-buffer))
d39f149d 3412 (run-mode-hooks 'Info-edit-mode-hook))
e82c28f9
KH
3413
3414(defun Info-edit ()
3415 "Edit the contents of this Info node.
3416Allowed only if variable `Info-enable-edit' is non-nil."
3417 (interactive)
3418 (or Info-enable-edit
185cff95 3419 (error "Editing Info nodes is not enabled"))
e82c28f9 3420 (Info-edit-mode)
8ab3e50b 3421 (message "%s" (substitute-command-keys
760d5cb3 3422 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
a384cab3
JB
3423
3424(defun Info-cease-edit ()
3425 "Finish editing Info node; switch back to Info proper."
3426 (interactive)
3427 ;; Do this first, so nothing has changed if user C-g's at query.
3428 (and (buffer-modified-p)
3429 (y-or-n-p "Save the file? ")
3430 (save-buffer))
3431 (use-local-map Info-mode-map)
3432 (setq major-mode 'Info-mode)
3433 (setq mode-name "Info")
3434 (Info-set-mode-line)
3435 (setq buffer-read-only t)
2c609f53 3436 (force-mode-line-update)
a384cab3
JB
3437 (and (marker-position Info-tag-table-marker)
3438 (buffer-modified-p)
3439 (message "Tags may have changed. Use Info-tagify if necessary")))
f0a8a3f1 3440\f
f88ab1c9 3441(defvar Info-file-list-for-emacs
02c9f5cd 3442 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
906b3163
EZ
3443 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
3444 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
3445 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
af718538
EZ
3446 ("skeleton" . "autotype") ("auto-insert" . "autotype")
3447 ("copyright" . "autotype") ("executable" . "autotype")
3448 ("time-stamp" . "autotype") ("quickurl" . "autotype")
3449 ("tempo" . "autotype") ("hippie-expand" . "autotype")
807378ad
EZ
3450 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
3451 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
906b3163
EZ
3452 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
3453 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
3454 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
3455 ("rfc2045" . "emacs-mime")
3456 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
3457 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
3458 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
3459 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
3460 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
3461 ("mml" . "emacs-mime"))
f88ab1c9
RS
3462 "List of Info files that describe Emacs commands.
3463An element can be a file name, or a list of the form (PREFIX . FILE)
3464where PREFIX is a name prefix and FILE is the file to look in.
3465If the element is just a file name, the file name also serves as the prefix.")
3466
f0a8a3f1 3467(defun Info-find-emacs-command-nodes (command)
f88ab1c9 3468 "Return a list of locations documenting COMMAND.
f57b2cd8
RS
3469The `info-file' property of COMMAND says which Info manual to search.
3470If COMMAND has no property, the variable `Info-file-list-for-emacs'
3471defines heuristics for which Info manual to try.
fdf4b680 3472The locations are of the format used in `Info-history', i.e.
02c9f5cd
JL
3473\(FILENAME NODENAME BUFFERPOS\), where BUFFERPOS is the line number
3474in the first element of the returned list (which is treated specially in
3475`Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
3476 (let ((where '()) line-number
b37daea4 3477 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
f254e21f 3478 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
02c9f5cd 3479 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
f88ab1c9 3480 (info-file "emacs")) ;default
185cff95 3481 ;; Determine which Info file this command is documented in.
f88ab1c9
RS
3482 (if (get command 'info-file)
3483 (setq info-file (get command 'info-file))
3484 ;; If it doesn't say explicitly, test its name against
3485 ;; various prefixes that we know.
3486 (let ((file-list Info-file-list-for-emacs))
3487 (while file-list
3488 (let* ((elt (car file-list))
3489 (name (if (consp elt)
3490 (car elt)
3491 elt))
3492 (file (if (consp elt) (cdr elt) elt))
cc3f6c32 3493 (case-fold-search nil)
f57b2cd8 3494 (regexp (concat "\\`" (regexp-quote name)
f88ab1c9
RS
3495 "\\(\\'\\|-\\)")))
3496 (if (string-match regexp (symbol-name command))
3497 (setq info-file file file-list nil))
3498 (setq file-list (cdr file-list))))))
218c2cc7
EZ
3499 (Info-find-node info-file "Top")
3500 (or (and (search-forward "\n* menu:" nil t)
3501 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
3502 (error "Info file `%s' appears to lack an index" info-file))
3503 (goto-char (match-beginning 1))
3504 ;; Bind Info-history to nil, to prevent the index nodes from
3505 ;; getting into the node history.
3506 (let ((Info-history nil)
141b49f5
JL
3507 (Info-history-list nil)
3508 node (nodes (Info-index-nodes)))
3509 (Info-goto-node (car nodes))
218c2cc7
EZ
3510 (while
3511 (progn
3512 (goto-char (point-min))
3513 (while (re-search-forward cmd-desc nil t)
3514 (setq where
3515 (cons (list Info-current-file
3516 (match-string-no-properties 2)
760d5cb3 3517 0)
02c9f5cd
JL
3518 where))
3519 (setq line-number (and (match-beginning 3)
3520 (string-to-number (match-string 3)))))
141b49f5 3521 (and (setq nodes (cdr nodes) node (car nodes))))
218c2cc7 3522 (Info-goto-node node)))
02c9f5cd
JL
3523 (if (and line-number where)
3524 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
3525 (cdr where))
3526 where)))
f0a8a3f1 3527
02c9f5cd 3528;;;###autoload (put 'Info-goto-emacs-command-node 'info-file "emacs")
f0a8a3f1
RM
3529;;;###autoload
3530(defun Info-goto-emacs-command-node (command)
e0568e86 3531 "Go to the Info node in the Emacs manual for command COMMAND.
30db89f9 3532The command is found by looking up in Emacs manual's indices
f57b2cd8 3533or in another manual found via COMMAND's `info-file' property or
1ed6e0c3
JPW
3534the variable `Info-file-list-for-emacs'.
3535COMMAND must be a symbol or string."
f0a8a3f1 3536 (interactive "CFind documentation for command: ")
fafb00dc
MY
3537 ;; If command is given as a string, convert it to a symbol.
3538 (if (stringp command)
1ed6e0c3 3539 (setq command (intern command)))
f0a8a3f1
RM
3540 (or (commandp command)
3541 (signal 'wrong-type-argument (list 'commandp command)))
3542 (let ((where (Info-find-emacs-command-nodes command)))
3543 (if where
3544 (let ((num-matches (length where)))
3545 ;; Get Info running, and pop to it in another window.
3546 (save-window-excursion
3547 (info))
89b064a9 3548 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
218c2cc7
EZ
3549 ;; Bind Info-history to nil, to prevent the last Index node
3550 ;; visited by Info-find-emacs-command-nodes from being
3551 ;; pushed onto the history.
02c9f5cd
JL
3552 (let ((Info-history nil) (Info-history-list nil)
3553 (line-number (nth 2 (car where))))
3554 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
3555 (if (and (integerp line-number) (> line-number 0))
3556 (forward-line (1- line-number))))
f0a8a3f1
RM
3557 (if (> num-matches 1)
3558 (progn
218c2cc7
EZ
3559 ;; (car where) will be pushed onto Info-history
3560 ;; when/if they go to another node. Put the other
3561 ;; nodes that were found on the history.
f0a8a3f1 3562 (setq Info-history (nconc (cdr where) Info-history))
8ab3e50b 3563 (message "Found %d other entr%s. Use %s to see %s."
cedb118c
RS
3564 (1- num-matches)
3565 (if (> num-matches 2) "ies" "y")
424b9d3e 3566 (substitute-command-keys "\\[Info-history-back]")
cedb118c 3567 (if (> num-matches 2) "them" "it")))))
e9b81433 3568 (error "Couldn't find documentation for %s" command))))
f0a8a3f1 3569
02c9f5cd 3570;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file "emacs")
f0a8a3f1
RM
3571;;;###autoload
3572(defun Info-goto-emacs-key-command-node (key)
30db89f9
EZ
3573 "Go to the node in the Emacs manual which describes the command bound to KEY.
3574KEY is a string.
fdf4b680 3575Interactively, if the binding is `execute-extended-command', a command is read.
30db89f9 3576The command is found by looking up in Emacs manual's indices
f57b2cd8
RS
3577or in another manual found via COMMAND's `info-file' property or
3578the variable `Info-file-list-for-emacs'."
ea33749b 3579 (interactive "kFind documentation for key: ")
f0a8a3f1
RM
3580 (let ((command (key-binding key)))
3581 (cond ((null command)
9e5c2f50 3582 (message "%s is undefined" (key-description key)))
f0a8a3f1
RM
3583 ((and (interactive-p)
3584 (eq command 'execute-extended-command))
3585 (Info-goto-emacs-command-node
3586 (read-command "Find documentation for command: ")))
3587 (t
3588 (Info-goto-emacs-command-node command)))))
552775bd 3589\f
efb21aab
RS
3590(defvar Info-next-link-keymap
3591 (let ((keymap (make-sparse-keymap)))
3592 (define-key keymap [header-line mouse-1] 'Info-next)
3593 (define-key keymap [header-line mouse-2] 'Info-next)
3594 (define-key keymap [header-line down-mouse-1] 'ignore)
3595 (define-key keymap [mouse-2] 'Info-next)
3c1498ac 3596 (define-key keymap [follow-link] 'mouse-face)
efb21aab
RS
3597 keymap)
3598 "Keymap to put on the Next link in the text or the header line.")
3599
3600(defvar Info-prev-link-keymap
3601 (let ((keymap (make-sparse-keymap)))
3602 (define-key keymap [header-line mouse-1] 'Info-prev)
3603 (define-key keymap [header-line mouse-2] 'Info-prev)
3604 (define-key keymap [header-line down-mouse-1] 'ignore)
3605 (define-key keymap [mouse-2] 'Info-prev)
3c1498ac 3606 (define-key keymap [follow-link] 'mouse-face)
efb21aab
RS
3607 keymap)
3608 "Keymap to put on the Prev link in the text or the header line.")
3609
efb21aab
RS
3610(defvar Info-up-link-keymap
3611 (let ((keymap (make-sparse-keymap)))
3612 (define-key keymap [header-line mouse-1] 'Info-up)
3613 (define-key keymap [header-line mouse-2] 'Info-up)
3614 (define-key keymap [header-line down-mouse-1] 'ignore)
3615 (define-key keymap [mouse-2] 'Info-up)
3c1498ac 3616 (define-key keymap [follow-link] 'mouse-face)
efb21aab
RS
3617 keymap)
3618 "Keymap to put on the Up link in the text or the header line.")
3619
552775bd 3620(defun Info-fontify-node ()
8a7757f6
JL
3621 "Fontify the node."
3622 (save-excursion
3623 (let* ((inhibit-read-only t)
3624 (case-fold-search t)
3625 paragraph-markers
3626 (not-fontified-p ; the node hasn't already been fontified
3627 (not (let ((where (next-property-change (point-min))))
3628 (and where (not (= where (point-max)))))))
3629 (fontify-visited-p ; visited nodes need to be re-fontified
3630 (and Info-fontify-visited-nodes
3631 ;; Don't take time to refontify visited nodes in huge nodes
e14105f6
TTN
3632 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
3633 rbeg rend)
8a7757f6
JL
3634
3635 ;; Fontify header line
3636 (goto-char (point-min))
3637 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
3638 (goto-char (match-end 0))
3639 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
3640 (goto-char (match-end 0))
3641 (let* ((nbeg (match-beginning 2))
3642 (nend (match-end 2))
3643 (tbeg (match-beginning 1))
3644 (tag (match-string 1)))
3645 (if (string-equal tag "Node")
3646 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
3647 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
3648 (put-text-property tbeg nend 'mouse-face 'highlight)
3649 (put-text-property tbeg nend
3650 'help-echo
3c1498ac 3651 (concat "mouse-2: Go to node "
8a7757f6
JL
3652 (buffer-substring nbeg nend)))
3653 ;; Always set up the text property keymap.
3654 ;; It will either be used in the buffer
3655 ;; or copied in the header line.
3656 (put-text-property tbeg nend 'keymap
3657 (cond
3658 ((equal tag "Prev") Info-prev-link-keymap)
3659 ((equal tag "Next") Info-next-link-keymap)
3660 ((equal tag "Up") Info-up-link-keymap))))))
3661 (when Info-use-header-line
3662 (goto-char (point-min))
3663 (let ((header-end (line-end-position))
3664 header)
3665 ;; If we find neither Next: nor Prev: link, show the entire
3666 ;; node header. Otherwise, don't show the File: and Node:
3667 ;; parts, to avoid wasting precious space on information that
3668 ;; is available in the mode line.
3669 (if (re-search-forward
3670 "\\(next\\|up\\|prev[ious]*\\): "
3671 header-end t)
3672 (progn
3673 (goto-char (match-beginning 1))
3674 (setq header (buffer-substring (point) header-end)))
3675 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" header-end t)
3676 (setq header
3677 (concat "No next, prev or up links -- "
3678 (buffer-substring (point) header-end)))
3679 (setq header (buffer-substring (point) header-end))))
3680 (put-text-property (point-min) (1+ (point-min))
69672704
JL
3681 'header-line
3682 (replace-regexp-in-string
3683 "%"
3684 ;; Preserve text properties on duplicated `%'.
3685 (lambda (s) (concat s s)) header))
8a7757f6
JL
3686 ;; Hide the part of the first line
3687 ;; that is in the header, if it is just part.
3688 (unless (bobp)
3689 ;; Hide the punctuation at the end, too.
3690 (skip-chars-backward " \t,")
3691 (put-text-property (point) header-end 'invisible t)))))
3692
3693 ;; Fontify titles
3694 (goto-char (point-min))
3695 (when not-fontified-p
6270bbe7 3696 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
8a7757f6
JL
3697 nil t)
3698 (let* ((c (preceding-char))
3699 (face
a335c06e
MB
3700 (cond ((= c ?*) 'info-title-1)
3701 ((= c ?=) 'info-title-2)
3702 ((= c ?-) 'info-title-3)
3703 (t 'info-title-4))))
8a7757f6
JL
3704 (put-text-property (match-beginning 1) (match-end 1)
3705 'font-lock-face face))
3706 ;; This is a serious problem for trying to handle multiple
3707 ;; frame types at once. We want this text to be invisible
3708 ;; on frames that can display the font above.
3709 (when (memq (framep (selected-frame)) '(x pc w32 mac))
3710 (add-text-properties (1- (match-beginning 2)) (match-end 2)
3711 '(invisible t front-sticky nil rear-nonsticky t)))))
3712
3713 ;; Fontify cross references
3714 (goto-char (point-min))
3715 (when (or not-fontified-p fontify-visited-p)
3716 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
3717 (let ((start (match-beginning 0))
3718 (next (point))
3719 other-tag)
3720 (when not-fontified-p
3721 (when Info-hide-note-references
fc11ddc8
JL
3722 (when (not (eq Info-hide-note-references 'hide))
3723 ;; *Note is often used where *note should have been
3724 (goto-char start)
3725 (skip-syntax-backward " ")
3726 (setq other-tag
3727 (cond ((memq (char-before) '(nil ?\. ?! ??))
3728 "See ")
3729 ((memq (char-before) '(?\, ?\; ?\: ?-))
3730 "see ")
3731 ((memq (char-before) '(?\( ?\[ ?\{))
3732 ;; Check whether the paren is preceded by
3733 ;; an end of sentence
3734 (skip-syntax-backward " (")
3735 (if (memq (char-before) '(nil ?\. ?! ??))
3736 "See "
3737 "see "))
3738 ((save-match-data (looking-at "\n\n"))
3739 "See "))))
8a7757f6
JL
3740 (goto-char next)
3741 (add-text-properties
3742 (match-beginning 1)
3743 (or (save-match-data
3744 ;; Don't hide \n after *Note
3745 (let ((start1 (match-beginning 1)))
3746 (if (string-match "\n" (match-string 1))
3747 (+ start1 (match-beginning 0)))))
3748 (match-end 1))
fc11ddc8 3749 (if other-tag
8a7757f6
JL
3750 `(display ,other-tag front-sticky nil rear-nonsticky t)
3751 '(invisible t front-sticky nil rear-nonsticky t))))
3752 (add-text-properties
3753 (match-beginning 2) (match-end 2)
3754 (list
3755 'help-echo (if (or (match-end 5)
3756 (not (equal (match-string 4) "")))
3757 (concat "mouse-2: go to " (or (match-string 5)
3758 (match-string 4)))
3759 "mouse-2: go to this node")
3760 'mouse-face 'highlight)))
3761 (when (or not-fontified-p fontify-visited-p)
e14105f6
TTN
3762 (setq rbeg (match-beginning 2)
3763 rend (match-end 2))
3764 (put-text-property
3765 rbeg rend
3766 'font-lock-face
3767 ;; Display visited nodes in a different face
3768 (if (and Info-fontify-visited-nodes
3769 (save-match-data
3770 (let* ((node (replace-regexp-in-string
3771 "^[ \t]+" ""
3772 (replace-regexp-in-string
3773 "[ \t\n]+" " "
3774 (or (match-string 5)
3775 (and (not (equal (match-string 4) ""))
3776 (match-string 4))
3777 (match-string 2)))))
3778 (file (file-name-nondirectory
3779 Info-current-file))
3780 (hl Info-history-list)
3781 res)
3782 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3783 (setq file (file-name-nondirectory
3784 (match-string 1 node))
3785 node (if (equal (match-string 2 node) "")
3786 "Top"
3787 (match-string 2 node))))
3788 (while hl
3789 (if (and (string-equal node (nth 1 (car hl)))
3790 (string-equal file
3791 (file-name-nondirectory
3792 (nth 0 (car hl)))))
3793 (setq res (car hl) hl nil)
3794 (setq hl (cdr hl))))
3795 res))) 'info-xref-visited 'info-xref))
3796 ;; For multiline ref, unfontify newline and surrounding whitespace
3797 (save-excursion
3798 (goto-char rbeg)
3799 (save-match-data
3800 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
3801 (remove-text-properties (match-beginning 0)
3802 (match-end 0)
3803 '(font-lock-face t))))))
8a7757f6
JL
3804 (when not-fontified-p
3805 (when (memq Info-hide-note-references '(t hide))
3806 (add-text-properties (match-beginning 3) (match-end 3)
3807 '(invisible t front-sticky nil rear-nonsticky t))
3808 ;; Unhide the file name of the external reference in parens
89b064a9 3809 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
8a7757f6
JL
3810 (remove-text-properties (match-beginning 6) (match-end 6)
3811 '(invisible t front-sticky nil rear-nonsticky t)))
3812 ;; Unhide newline because hidden newlines cause too long lines
3813 (save-match-data
89b064a9
JL
3814 (let ((beg3 (match-beginning 3))
3815 (end3 (match-end 3)))
3816 (if (and (string-match "\n[ \t]*" (match-string 3))
3817 (not (save-match-data
3818 (save-excursion
3819 (goto-char (1+ end3))
3820 (looking-at "[.)]*$")))))
3821 (remove-text-properties (+ beg3 (match-beginning 0))
3822 (+ beg3 (match-end 0))
8a7757f6
JL
3823 '(invisible t front-sticky nil rear-nonsticky t))))))
3824 (when (and Info-refill-paragraphs Info-hide-note-references)
3825 (push (set-marker (make-marker) start)
3826 paragraph-markers))))))
3827
3828 ;; Refill paragraphs (experimental feature)
3829 (when (and not-fontified-p
3830 Info-refill-paragraphs
3831 paragraph-markers)
3832 (let ((fill-nobreak-invisible t)
3833 (fill-individual-varying-indent nil)
3834 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
3835 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
3836 (adaptive-fill-mode nil))
3837 (goto-char (point-max))
3838 (while paragraph-markers
3839 (let ((m (car paragraph-markers)))
3840 (setq paragraph-markers (cdr paragraph-markers))
3841 (when (< m (point))
3842 (goto-char m)
3843 (beginning-of-line)
3844 (let ((beg (point)))
3845 (when (zerop (forward-paragraph))
3846 (fill-individual-paragraphs beg (point) nil nil)
3847 (goto-char beg))))
3848 (set-marker m nil)))))
3849
3850 ;; Fontify menu items
3851 (goto-char (point-min))
3852 (when (and (or not-fontified-p fontify-visited-p)
3853 (search-forward "\n* Menu:" nil t)
141b49f5 3854 (not (Info-index-node))
8a7757f6
JL
3855 ;; Don't take time to annotate huge menus
3856 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
3857 (let ((n 0)
3858 cont)
3859 (while (re-search-forward
1ecc5922
RS
3860 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
3861 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
8a7757f6 3862 nil t)
1ecc5922
RS
3863 (when (match-beginning 1)
3864 (when not-fontified-p
3865 (setq n (1+ n))
3866 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
3867 (put-text-property (match-beginning 0)
3868 (1+ (match-beginning 0))
185cff95 3869 'font-lock-face 'info-menu-star)))
1ecc5922
RS
3870 (when not-fontified-p
3871 (add-text-properties
3872 (match-beginning 1) (match-end 1)
3873 (list
3874 'help-echo (if (and (match-end 3)
3875 (not (equal (match-string 3) "")))
3876 (concat "mouse-2: go to " (match-string 3))
3877 "mouse-2: go to this node")
3878 'mouse-face 'highlight)))
3879 (when (or not-fontified-p fontify-visited-p)
3880 (add-text-properties
3881 (match-beginning 1) (match-end 1)
3882 (list
3883 'font-lock-face
3884 ;; Display visited menu items in a different face
3885 (if (and Info-fontify-visited-nodes
3886 (save-match-data
3887 (let ((node (if (equal (match-string 3) "")
3888 (match-string 1)
3889 (match-string 3)))
3890 (file (file-name-nondirectory Info-current-file))
3891 (hl Info-history-list)
3892 res)
3893 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3894 (setq file (file-name-nondirectory
3895 (match-string 1 node))
3896 node (if (equal (match-string 2 node) "")
3897 "Top"
3898 (match-string 2 node))))
3899 (while hl
3900 (if (and (string-equal node (nth 1 (car hl)))
3901 (string-equal file
3902 (file-name-nondirectory
3903 (nth 0 (car hl)))))
3904 (setq res (car hl) hl nil)
3905 (setq hl (cdr hl))))
3906 res))) 'info-xref-visited 'info-xref))))
3907 (when (and not-fontified-p (memq Info-hide-note-references '(t hide)))
3908 (put-text-property (match-beginning 2) (1- (match-end 6))
3909 'invisible t)
3910 ;; Unhide the file name in parens
3911 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
3912 (remove-text-properties (match-beginning 4) (match-end 4)
3913 '(invisible t)))
3914 ;; We need a stretchable space like :align-to but with
3915 ;; a minimum value.
3916 (put-text-property (1- (match-end 6)) (match-end 6) 'display
3917 (if (>= 22 (- (match-end 1)
3918 (match-beginning 0)))
3919 '(space :align-to 24)
3920 '(space :width 2)))
3921 (setq cont (looking-at "."))
3922 (while (and (= (forward-line 1) 0)
3923 (looking-at "\\([ \t]+\\)[^*\n]"))
3924 (put-text-property (match-beginning 1) (1- (match-end 1))
3925 'invisible t)
3926 (put-text-property (1- (match-end 1)) (match-end 1)
3927 'display
3928 (if cont
3929 '(space :align-to 26)
3930 '(space :align-to 24)))
3931 (setq cont t)))))))
8a7757f6
JL
3932
3933 ;; Fontify menu headers
3934 ;; Add the face `info-menu-header' to any header before a menu entry
3935 (goto-char (point-min))
3936 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
3937 (put-text-property (match-beginning 0) (match-end 0)
3938 'font-lock-face 'info-menu-header)
3939 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
3940 (put-text-property (match-beginning 1) (match-end 1)
3941 'font-lock-face 'info-menu-header)))
3942
836bb478
JL
3943 ;; Hide index line numbers
3944 (goto-char (point-min))
141b49f5 3945 (when (and not-fontified-p (Info-index-node))
836bb478
JL
3946 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
3947 (put-text-property (match-beginning 0) (match-end 0)
3948 'invisible t)))
3949
8a7757f6
JL
3950 ;; Fontify http and ftp references
3951 (goto-char (point-min))
3952 (when not-fontified-p
3953 (while (re-search-forward "[hf]t?tp://[^ \t\n\"`({<>})']+" nil t)
3954 (add-text-properties (match-beginning 0) (match-end 0)
3955 '(font-lock-face info-xref
3956 mouse-face highlight
3957 help-echo "mouse-2: go to this URL"))))
3958
3959 (set-buffer-modified-p nil))))
c5fe2ff1 3960\f
3cb6768f
EL
3961;;; Speedbar support:
3962;; These functions permit speedbar to display the "tags" in the
185cff95 3963;; current Info node.
96ee3f29 3964(eval-when-compile (require 'speedbar))
3cb6768f 3965
96ee3f29
KH
3966(defvar Info-speedbar-key-map nil
3967 "Keymap used when in the info display mode.")
3cb6768f 3968
96ee3f29
KH
3969(defun Info-install-speedbar-variables ()
3970 "Install those variables used by speedbar to enhance Info."
3971 (if Info-speedbar-key-map
3972 nil
3973 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
3974
3975 ;; Basic tree features
3976 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
3977 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
3978 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
3979 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
3980 )
3981
3982 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
3983 Info-speedbar-key-map
3984 Info-speedbar-hierarchy-buttons)))
3cb6768f
EL
3985
3986(defvar Info-speedbar-menu-items
96ee3f29
KH
3987 '(["Browse Node" speedbar-edit-line t]
3988 ["Expand Node" speedbar-expand-line
3989 (save-excursion (beginning-of-line)
3990 (looking-at "[0-9]+: *.\\+. "))]
3991 ["Contract Node" speedbar-contract-line
3992 (save-excursion (beginning-of-line)
3993 (looking-at "[0-9]+: *.-. "))]
3994 )
3cb6768f
EL
3995 "Additional menu-items to add to speedbar frame.")
3996
96ee3f29
KH
3997;; Make sure our special speedbar major mode is loaded
3998(if (featurep 'speedbar)
3999 (Info-install-speedbar-variables)
4000 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4001
4002;;; Info hierarchy display method
4003;;;###autoload
4004(defun Info-speedbar-browser ()
185cff95 4005 "Initialize speedbar to display an Info node browser.
96ee3f29
KH
4006This will add a speedbar major display mode."
4007 (interactive)
4008 (require 'speedbar)
4009 ;; Make sure that speedbar is active
4010 (speedbar-frame-mode 1)
4011 ;; Now, throw us into Info mode on speedbar.
4012 (speedbar-change-initial-expansion-list "Info")
4013 )
4014
4015(defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
4016 "Display an Info directory hierarchy in speedbar.
4017DIRECTORY is the current directory in the attached frame.
4018DEPTH is the current indentation depth.
4019NODE is an optional argument that is used to represent the
4020specific node to expand."
4021 (if (and (not node)
4022 (save-excursion (goto-char (point-min))
1bcedb3b
RS
4023 (let ((case-fold-search t))
4024 (looking-at "Info Nodes:"))))
96ee3f29
KH
4025 ;; Update our "current node" maybe?
4026 nil
4027 ;; We cannot use the generic list code, that depends on all leaves
4028 ;; being known at creation time.
4029 (if (not node)
4030 (speedbar-with-writable (insert "Info Nodes:\n")))
24bbdbef
CY
4031 (let ((completions nil))
4032 (speedbar-select-attached-frame)
5fdc7997
EL
4033 (save-window-excursion
4034 (setq completions
4035 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
24bbdbef 4036 (select-frame speedbar-frame)
96ee3f29
KH
4037 (if completions
4038 (speedbar-with-writable
dde7f979 4039 (dolist (completion completions)
96ee3f29 4040 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
dde7f979
SM
4041 (cdr completion)
4042 (car completion)
96ee3f29 4043 'Info-speedbar-goto-node
dde7f979
SM
4044 (cdr completion)
4045 'info-xref depth))
96ee3f29
KH
4046 t)
4047 nil))))
399c88ad 4048
96ee3f29 4049(defun Info-speedbar-goto-node (text node indent)
d1268e52 4050 "When user clicks on TEXT, go to an info NODE.
96ee3f29 4051The INDENT level is ignored."
24bbdbef 4052 (speedbar-select-attached-frame)
760d5cb3
GM
4053 (let* ((buff (or (get-buffer "*info*")
4054 (progn (info) (get-buffer "*info*"))))
4055 (bwin (get-buffer-window buff 0)))
4056 (if bwin
4057 (progn
4058 (select-window bwin)
4059 (raise-frame (window-frame bwin)))
4060 (if speedbar-power-click
4061 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
24bbdbef 4062 (speedbar-select-attached-frame)
760d5cb3 4063 (switch-to-buffer buff)))
dde7f979
SM
4064 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4065 (error "Invalid node %s" node)
4066 (Info-find-node (match-string 1 node) (match-string 2 node))
760d5cb3
GM
4067 ;; If we do a find-node, and we were in info mode, restore
4068 ;; the old default method. Once we are in info mode, it makes
4069 ;; sense to return to whatever method the user was using before.
4070 (if (string= speedbar-initial-expansion-list-name "Info")
4071 (speedbar-change-initial-expansion-list
4072 speedbar-previously-used-expansion-list-name)))))
96ee3f29
KH
4073
4074(defun Info-speedbar-expand-node (text token indent)
4075 "Expand the node the user clicked on.
4076TEXT is the text of the button we clicked on, a + or - item.
4077TOKEN is data related to this node (NAME . FILE).
4078INDENT is the current indentation depth."
4079 (cond ((string-match "+" text) ;we have to expand this file
4080 (speedbar-change-expand-button-char ?-)
4081 (if (speedbar-with-writable
760d5cb3
GM
4082 (save-excursion
4083 (end-of-line) (forward-char 1)
4084 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
96ee3f29
KH
4085 (speedbar-change-expand-button-char ?-)
4086 (speedbar-change-expand-button-char ??)))
4087 ((string-match "-" text) ;we have to contract this node
4088 (speedbar-change-expand-button-char ?+)
4089 (speedbar-delete-subblock indent))
4090 (t (error "Ooops... not sure what to do")))
4091 (speedbar-center-buffer-smartly))
4092
4093(defun Info-speedbar-fetch-file-nodes (nodespec)
4094 "Fetch the subnodes from the info NODESPEC.
db90d225 4095NODESPEC is a string of the form: (file)node."
96ee3f29
KH
4096 (save-excursion
4097 ;; Set up a buffer we can use to fake-out Info.
4098 (set-buffer (get-buffer-create "*info-browse-tmp*"))
4099 (if (not (equal major-mode 'Info-mode))
4100 (Info-mode))
4101 ;; Get the node into this buffer
dde7f979
SM
4102 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4103 (error "Invalid node specification %s" nodespec)
4104 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
96ee3f29
KH
4105 ;; Scan the created buffer
4106 (goto-char (point-min))
4107 (let ((completions nil)
1bcedb3b 4108 (case-fold-search t)
96ee3f29
KH
4109 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4110 (match-string 1 nodespec))))
4111 ;; Always skip the first one...
4112 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4113 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4114 (let ((name (match-string 1)))
dde7f979
SM
4115 (push (cons name
4116 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4117 (match-string 1)
4118 (if (looking-at " *\\(([^)]+)\\)\\.")
4119 (concat (match-string 1) "Top")
4120 (concat "(" thisfile ")"
4121 (if (looking-at " \\([^.]+\\).")
4122 (match-string 1)
4123 name)))))
4124 completions)))
96ee3f29
KH
4125 (nreverse completions))))
4126
4127;;; Info mode node listing
24bbdbef 4128;; This is called by `speedbar-add-localized-speedbar-support'
3cb6768f
EL
4129(defun Info-speedbar-buttons (buffer)
4130 "Create a speedbar display to help navigation in an Info file.
4131BUFFER is the buffer speedbar is requesting buttons for."
96ee3f29 4132 (if (save-excursion (goto-char (point-min))
1bcedb3b
RS
4133 (let ((case-fold-search t))
4134 (not (looking-at "Info Nodes:"))))
96ee3f29 4135 (erase-buffer))
24bbdbef 4136 (Info-speedbar-hierarchy-buttons nil 0))
49116ac0 4137
6270bbe7
JL
4138(dolist (mess '("^First node in file$"
4139 "^No `.*' in index$"
4140 "^No cross-reference named"
4141 "^No cross.references in this node$"
185cff95 4142 "^No current Info node$"
48e5b471 4143 "^No menu in this node$"
6270bbe7
JL
4144 "^No more items in menu$"
4145 "^No more nodes$"
4146 "^No pointer \\(?:forward\\|backward\\) from this node$"
4147 "^No previous `i' command$"
4148 "^No previous items in menu$"
4149 "^No previous nodes$"
4150 "^No such item in menu$"
4151 "^No such node or anchor"
4152 "^Node has no"
4153 "^Point neither on reference nor in menu item description$"
4154 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4155 search-failed))
48e5b471
DL
4156 (add-to-list 'debug-ignored-errors mess))
4157
f3a45db0
LH
4158;;;; Desktop support
4159
4160(defun Info-desktop-buffer-misc-data (desktop-dirname)
4161 "Auxiliary information to be saved in desktop file."
c9ce1e40
JL
4162 (if (not (member Info-current-file '("apropos" "history" "toc")))
4163 (list Info-current-file Info-current-node)))
f3a45db0 4164
f3a45db0
LH
4165(defun Info-restore-desktop-buffer (desktop-buffer-file-name
4166 desktop-buffer-name
4167 desktop-buffer-misc)
185cff95 4168 "Restore an Info buffer specified in a desktop file."
f3a45db0
LH
4169 (let ((first (nth 0 desktop-buffer-misc))
4170 (second (nth 1 desktop-buffer-misc)))
4171 (when (and first second)
c9ce1e40
JL
4172 (when desktop-buffer-name
4173 (set-buffer (get-buffer-create desktop-buffer-name))
4174 (Info-mode))
2a3f604d 4175 (Info-find-node first second)
f3a45db0
LH
4176 (current-buffer))))
4177
9e7357b0
AS
4178(add-to-list 'desktop-buffer-mode-handlers
4179 '(Info-mode . Info-restore-desktop-buffer))
80123c9e 4180
49116ac0
JB
4181(provide 'info)
4182
83040cb0 4183;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
1a06eabd 4184;;; info.el ends here