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