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