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