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