(mh-version): Set to 7.3+cvs.
[bpt/emacs.git] / lisp / info.el
CommitLineData
55535639 1;;; info.el --- info package for Emacs
e5167999 2
35ab7deb
KB
3;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001,
4;; 2002, 2003
5b3ebb44 5;; Free Software Foundation, Inc.
3a801d0c 6
e5167999 7;; Maintainer: FSF
fd7fa35a 8;; Keywords: help
e5167999 9
a384cab3
JB
10;; This file is part of GNU Emacs.
11
12;; GNU Emacs is free software; you can redistribute it and/or modify
13;; it under the terms of the GNU General Public License as published by
e5167999 14;; the Free Software Foundation; either version 2, or (at your option)
a384cab3
JB
15;; any later version.
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
b578f267
EN
23;; along with GNU Emacs; see the file COPYING. If not, write to the
24;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25;; Boston, MA 02111-1307, USA.
a384cab3 26
e5167999
ER
27;;; Commentary:
28
b578f267 29;; Note that nowadays we expect info files to be made using makeinfo.
921e5fe6
TTN
30;; In particular we make these assumptions:
31;; - a menu item MAY contain colons but not colon-space ": "
32;; - a menu item ending with ": " (but not ":: ") is an index entry
33;; - a node name MAY NOT contain a colon
505b68d5
TTN
34;; This distinction is to support indexing of computer programming
35;; language terms that may contain ":" but not ": ".
e5167999
ER
36
37;;; Code:
38
bc6262c8
DL
39(eval-when-compile (require 'jka-compr))
40
ded3e3d8
RS
41(defgroup info nil
42 "Info subsystem"
43 :group 'help
44 :group 'docs)
45
46
a384cab3
JB
47(defvar Info-history nil
48 "List of info nodes user has visited.
49Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
50
ded3e3d8 51(defcustom Info-enable-edit nil
d5913bf6 52 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
ada0a60d
RS
53This is convenient if you want to write info files by hand.
54However, we recommend that you not do this.
55It is better to write a Texinfo file and generate the Info file from that,
ded3e3d8
RS
56because that gives you a printed manual as well."
57 :type 'boolean
58 :group 'info)
a384cab3 59
67f445d7 60(defvar Info-enable-active-nodes nil
a384cab3
JB
61 "Non-nil allows Info to execute Lisp code associated with nodes.
62The Lisp code is executed when the node is selected.")
67f445d7 63(put 'Info-enable-active-nodes 'risky-local-variable t)
a384cab3 64
93480d70 65(defface info-node
58b64ac7
RS
66 '((((class color) (background light)) (:foreground "brown" :weight bold :slant italic))
67 (((class color) (background dark)) (:foreground "white" :weight bold :slant italic))
68 (t (:weight bold :slant italic)))
93480d70
RS
69 "Face for Info node names."
70 :group 'info)
71
72(defface info-menu-5
7a3abcd8
EZ
73 '((((class color)) (:foreground "red1"))
74 (t (:underline t)))
ccfb7415 75 "Face for every third `*' in an Info menu."
93480d70
RS
76 :group 'info)
77
78(defface info-xref
58b64ac7
RS
79 '((((class color) (background light)) (:foreground "magenta4" :weight bold))
80 (((class color) (background dark)) (:foreground "cyan" :weight bold))
81 (t (:weight bold)))
93480d70
RS
82 "Face for Info cross-references."
83 :group 'info)
84
88ef7f62 85(defcustom Info-fontify-maximum-menu-size 100000
ccfb7415 86 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
ded3e3d8
RS
87 :type 'integer
88 :group 'info)
bdf62a4d 89
50ac70af 90(defcustom Info-use-header-line t
c3717746 91 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
50ac70af
MB
92A header-line does not scroll with the rest of the buffer."
93 :type 'boolean
94 :group 'info)
95
96(defface info-header-xref
52cbdfbd 97 '((t (:inherit info-xref)))
50ac70af
MB
98 "Face for Info cross-references in a node header."
99 :group 'info)
100
101(defface info-header-node
4ad6e379 102 '((t (:inherit info-node)))
50ac70af
MB
103 "Face for Info nodes in a node header."
104 :group 'info)
105
7d3766a8 106(defvar Info-directory-list nil
a384cab3 107 "List of directories to search for Info documentation files.
fc4d14c5 108If nil, meaning not yet initialized, Info uses the environment
44c327f9 109variable INFOPATH to initialize it, or `Info-default-directory-list'
e5bd2125 110if there is no INFOPATH variable in the environment.
778911b9
EZ
111
112When `Info-directory-list' is initialized from the value of
4dddb0b7
EZ
113`Info-default-directory-list', and Emacs is installed in one of the
114standard directories, the directory of Info files that come with Emacs
115is put last (so that local Info files override standard ones).
116
117When `Info-directory-list' is initialized from the value of
118`Info-default-directory-list', and Emacs is not installed in one
119of the standard directories, the first element of the resulting
778911b9
EZ
120list is the directory where Emacs installs the Info files that
121come with it. This is so that Emacs's own manual, which suits the
4dddb0b7
EZ
122version of Emacs you are using, will always be found first. This
123is useful when you install an experimental version of Emacs without
124removing the standard installation.
125
126If you want to override the order of directories in
127`Info-default-directory-list', set INFOPATH in the environment.
5da0f945
RS
128
129If you run the Emacs executable from the `src' directory in the Emacs
778911b9
EZ
130source tree, and INFOPATH is not defined, the `info' directory in the
131source tree is used as the first element of `Info-directory-list', in
132place of the installation Info directory. This is useful when you run
133a version of Emacs without installing it.")
a384cab3 134
ded3e3d8 135(defcustom Info-additional-directory-list nil
bdf62a4d 136 "List of additional directories to search for Info documentation files.
e9b1d996 137These directories are searched after those in `Info-directory-list'."
ded3e3d8
RS
138 :type '(repeat directory)
139 :group 'info)
bdf62a4d 140
7a53d8c8
EZ
141(defcustom Info-scroll-prefer-subnodes t
142 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
143If this is non-nil, and you scroll far enough in a node that its menu
144appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
145moves to a subnode indicated by the following menu item. This means
146that you visit a subnode before getting to the end of the menu.
147
148Setting this option to nil results in behavior similar to the stand-alone
149Info reader program, which visits the first subnode from the menu only
150when you hit the end of the current node."
151 :type 'boolean
152 :group 'info)
153
a9efebd0 154(defcustom Info-hide-note-references t
5f812a3c
KS
155 "*If non-nil, hide the tag and section reference in *note and * menu items.
156Also replaces the \"*note\" text with \"see\".
0452a274 157If value is non-nil but not t, the reference section is still shown."
5f812a3c 158 :version "21.4"
0452a274
AS
159 :type '(choice (const :tag "No reformatting" nil)
160 (const :tag "Replace tag and hide reference" t)
161 (other :tag "Replace only tag" tag))
a9efebd0
KS
162 :group 'info)
163
57190f92 164(defcustom Info-mode-hook '(turn-on-font-lock)
544e5562
CW
165 "Hooks run when `info-mode' is called."
166 :type 'hook
167 :group 'info)
168
a384cab3 169(defvar Info-current-file nil
d6be34f3
RS
170 "Info file that Info is now looking at, or nil.
171This is the name that was specified in Info, not the actual file name.
4fceda3c
SM
172It doesn't contain directory names or file name extensions added by Info.
173Can also be t when using `Info-on-current-buffer'.")
a384cab3
JB
174
175(defvar Info-current-subfile nil
fdf4b680
DL
176 "Info subfile that is actually in the *info* buffer now.
177nil if current info file is not split into subfiles.")
a384cab3
JB
178
179(defvar Info-current-node nil
180 "Name of node that Info is now looking at, or nil.")
181
c5fe2ff1 182(defvar Info-tag-table-marker nil
a384cab3
JB
183 "Marker pointing at beginning of current Info file's tag table.
184Marker points nowhere if file has no tag table.")
185
c5fe2ff1
RS
186(defvar Info-tag-table-buffer nil
187 "Buffer used for indirect tag tables.")
188
552775bd
RS
189(defvar Info-current-file-completions nil
190 "Cached completion list for current Info file.")
191
1143a6b0 192(defvar Info-index-alternatives nil
fdf4b680 193 "List of possible matches for last `Info-index' command.")
1143a6b0 194
552775bd
RS
195(defvar Info-standalone nil
196 "Non-nil if Emacs was started solely as an Info browser.")
7d3766a8 197\f
bd0c9168 198(defvar Info-suffix-list
3c19e6c1
RS
199 ;; The MS-DOS list should work both when long file names are
200 ;; supported (Windows 9X), and when only 8+3 file names are available.
bd0c9168
RS
201 (if (eq system-type 'ms-dos)
202 '( (".gz" . "gunzip")
203 (".z" . "gunzip")
544e210f 204 (".bz2" . ("bzip2" "-dc"))
3c19e6c1
RS
205 (".inz" . "gunzip")
206 (".igz" . "gunzip")
207 (".info.Z" . "gunzip")
208 (".info.gz" . "gunzip")
209 ("-info.Z" . "gunzip")
210 ("-info.gz" . "gunzip")
211 ("/index.gz". "gunzip")
212 ("/index.z" . "gunzip")
9b842cab 213 (".inf" . nil)
3c19e6c1
RS
214 (".info" . nil)
215 ("-info" . nil)
216 ("/index" . nil)
bd0c9168 217 ("" . nil))
a70dc410
RS
218 '( (".info.Z". "uncompress")
219 (".info.Y". "unyabba")
220 (".info.gz". "gunzip")
221 (".info.z". "gunzip")
544e210f 222 (".info.bz2" . ("bzip2" "-dc"))
a70dc410
RS
223 (".info". nil)
224 ("-info.Z". "uncompress")
225 ("-info.Y". "unyabba")
226 ("-info.gz". "gunzip")
544e210f 227 ("-info.bz2" . ("bzip2" "-dc"))
a70dc410
RS
228 ("-info.z". "gunzip")
229 ("-info". nil)
230 ("/index.Z". "uncompress")
231 ("/index.Y". "unyabba")
232 ("/index.gz". "gunzip")
233 ("/index.z". "gunzip")
544e210f 234 ("/index.bz2". ("bzip2" "-dc"))
a70dc410
RS
235 ("/index". nil)
236 (".Z". "uncompress")
237 (".Y". "unyabba")
238 (".gz". "gunzip")
239 (".z". "gunzip")
544e210f 240 (".bz2" . ("bzip2" "-dc"))
a70dc410 241 ("". nil)))
1143a6b0
ER
242 "List of file name suffixes and associated decoding commands.
243Each entry should be (SUFFIX . STRING); the file is given to
544e210f
KH
244the command as standard input.
245
246STRING may be a list of strings. In that case, the first element is
247the command name, and the rest are arguments to that command.
248
249If STRING is nil, no decoding is done.
97f99202
KH
250Because the SUFFIXes are tried in order, the empty string should
251be last in the list.")
1143a6b0 252
c8e9dd54 253;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
e0c1e774
EZ
254;; First, on MS-DOS with no long file names support, delete some of
255;; the extension in FILENAME to make room.
256(defun info-insert-file-contents-1 (filename suffix lfn)
257 (if lfn ; long file names are supported
bd0c9168
RS
258 (concat filename suffix)
259 (let* ((sans-exts (file-name-sans-extension filename))
c8e9dd54
RS
260 ;; How long is the extension in FILENAME (not counting the dot).
261 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
262 ext-left)
9b842cab 263 ;; SUFFIX starts with a dot. If FILENAME already has one,
1583fe94 264 ;; get rid of the one in SUFFIX (unless suffix is empty).
c8e9dd54 265 (or (and (<= ext-len 0)
9b842cab 266 (not (eq (aref filename (1- (length filename))) ?.)))
1583fe94 267 (= (length suffix) 0)
9b842cab 268 (setq suffix (substring suffix 1)))
c8e9dd54
RS
269 ;; How many chars of that extension should we keep?
270 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
bd0c9168
RS
271 ;; Get rid of the rest of the extension, and add SUFFIX.
272 (concat (substring filename 0 (- (length filename)
273 (- ext-len ext-left)))
274 suffix))))
275
9c7924d5
RS
276(defun info-file-exists-p (filename)
277 (and (file-exists-p filename)
278 (not (file-directory-p filename))))
279
1143a6b0
ER
280(defun info-insert-file-contents (filename &optional visit)
281 "Insert the contents of an info file in the current buffer.
282Do the right thing if the file has been compressed or zipped."
e0c1e774 283 (let* ((tail Info-suffix-list)
ab5a535c
KS
284 (lfn (if (fboundp 'msdos-long-file-names)
285 (msdos-long-file-names)
286 t))
e0c1e774
EZ
287 (check-short (and (fboundp 'msdos-long-file-names)
288 lfn))
289 fullname decoder done)
b8fa4e87 290 (if (info-file-exists-p filename)
bd0c9168
RS
291 ;; FILENAME exists--see if that name contains a suffix.
292 ;; If so, set DECODE accordingly.
97f99202
KH
293 (progn
294 (while (and tail
295 (not (string-match
296 (concat (regexp-quote (car (car tail))) "$")
297 filename)))
298 (setq tail (cdr tail)))
299 (setq fullname filename
300 decoder (cdr (car tail))))
bd0c9168 301 ;; Try adding suffixes to FILENAME and see if we can find something.
e0c1e774
EZ
302 (while (and tail (not done))
303 (setq fullname (info-insert-file-contents-1 filename
304 (car (car tail)) lfn))
305 (if (info-file-exists-p fullname)
306 (setq done t
307 ;; If we found a file with a suffix, set DECODER
308 ;; according to the suffix.
309 decoder (cdr (car tail)))
310 ;; When the MS-DOS port runs on Windows, we need to check
311 ;; the short variant of a long file name as well.
312 (when check-short
313 (setq fullname (info-insert-file-contents-1 filename
314 (car (car tail)) nil))
315 (if (info-file-exists-p fullname)
316 (setq done t
317 decoder (cdr (car tail))))))
97f99202 318 (setq tail (cdr tail)))
97f99202 319 (or tail
bd0c9168 320 (error "Can't find %s or any compressed version of it" filename)))
e175bda2
RS
321 ;; check for conflict with jka-compr
322 (if (and (featurep 'jka-compr)
323 (jka-compr-installed-p)
324 (jka-compr-get-compression-info fullname))
325 (setq decoder nil))
97f99202 326 (if decoder
3c19e6c1
RS
327 (progn
328 (insert-file-contents-literally fullname visit)
329 (let ((buffer-read-only nil)
330 (coding-system-for-write 'no-conversion)
331 (default-directory (or (file-name-directory fullname)
332 default-directory)))
544e210f
KH
333 (or (consp decoder)
334 (setq decoder (list decoder)))
335 (apply 'call-process-region (point-min) (point-max)
336 (car decoder) t t nil (cdr decoder))))
3c19e6c1 337 (insert-file-contents fullname visit))))
7d3766a8 338\f
3a59b662
SM
339(defun Info-default-dirs ()
340 (let ((source (expand-file-name "info/" source-directory))
341 (sibling (if installation-directory
342 (expand-file-name "info/" installation-directory)
343 (if invocation-directory
344 (let ((infodir (expand-file-name
345 "../info/"
346 invocation-directory)))
347 (if (file-exists-p infodir)
348 infodir
349 (setq infodir (expand-file-name
350 "../../../info/"
351 invocation-directory))
352 (and (file-exists-p infodir)
353 infodir))))))
354 alternative)
355 (setq alternative
356 (if (and sibling (file-exists-p sibling))
357 ;; Uninstalled, Emacs builddir != srcdir.
358 sibling
359 ;; Uninstalled, builddir == srcdir
360 source))
361 (if (or (member alternative Info-default-directory-list)
362 ;; On DOS/NT, we use movable executables always,
363 ;; and we must always find the Info dir at run time.
364 (if (memq system-type '(ms-dos windows-nt))
365 nil
366 ;; Use invocation-directory for Info
367 ;; only if we used it for exec-directory also.
368 (not (string= exec-directory
369 (expand-file-name "lib-src/"
370 installation-directory))))
371 (not (file-exists-p alternative)))
372 Info-default-directory-list
373 ;; `alternative' contains the Info files that came with this
374 ;; version, so we should look there first. `Info-insert-dir'
375 ;; currently expects to find `alternative' first on the list.
376 (cons alternative
377 (reverse (cdr (reverse Info-default-directory-list)))))))
378
7d3766a8 379(defun info-initialize ()
fdf4b680 380 "Initialize `Info-directory-list', if that hasn't been done yet."
7d3766a8 381 (unless Info-directory-list
3a59b662 382 (let ((path (getenv "INFOPATH")))
7d3766a8 383 (setq Info-directory-list
78e7e8a0
MB
384 (prune-directory-list
385 (if path
3a59b662
SM
386 (if (string-match ":\\'" path)
387 (append (split-string (substring path 0 -1)
388 (regexp-quote path-separator))
389 (Info-default-dirs))
390 (split-string path (regexp-quote path-separator)))
391 (Info-default-dirs)))))))
1143a6b0 392
a6e4564e
RS
393;;;###autoload
394(defun info-other-window (&optional file)
395 "Like `info' but show the Info buffer in another window."
396 (interactive (if current-prefix-arg
397 (list (read-file-name "Info file name: " nil nil t))))
398 (let (same-window-buffer-names)
399 (info file)))
399c88ad 400
d282974b 401;;;###autoload (add-hook 'same-window-buffer-names "*info*")
211d6309 402
a384cab3
JB
403;;;###autoload
404(defun info (&optional file)
405 "Enter Info, the documentation browser.
406Optional argument FILE specifies the file to examine;
407the default is the top-level directory of Info.
83d5c772
DL
408Called from a program, FILE may specify an Info node of the form
409`(FILENAME)NODENAME'.
a384cab3
JB
410
411In interactive use, a prefix argument directs this command
e341dab2
RS
412to read a file name from the minibuffer.
413
414The search path for Info files is in the variable `Info-directory-list'.
399c88ad 415The top-level Info directory is made by combining all the files named `dir'
e341dab2 416in all the directories in that path."
a384cab3
JB
417 (interactive (if current-prefix-arg
418 (list (read-file-name "Info file name: " nil nil t))))
a384cab3 419 (if file
c613e27e
KH
420 (progn
421 (pop-to-buffer "*info*")
422 ;; If argument already contains parentheses, don't add another set
423 ;; since the argument will then be parsed improperly. This also
424 ;; has the added benefit of allowing node names to be included
425 ;; following the parenthesized filename.
426 (if (and (stringp file) (string-match "(.*)" file))
427 (Info-goto-node file)
428 (Info-goto-node (concat "(" file ")"))))
35d2d241
RS
429 (if (get-buffer "*info*")
430 (pop-to-buffer "*info*")
431 (Info-directory))))
a384cab3 432
c3717746
RS
433;;;###autoload
434(defun info-emacs-manual ()
3a8803c0 435 "Display the Emacs manual in Info mode."
c3717746
RS
436 (interactive)
437 (info "emacs"))
438
552775bd
RS
439;;;###autoload
440(defun info-standalone ()
441 "Run Emacs as a standalone Info reader.
442Usage: emacs -f info-standalone [filename]
443In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
444 (setq Info-standalone t)
445 (if (and command-line-args-left
446 (not (string-match "^-" (car command-line-args-left))))
447 (condition-case err
448 (progn
449 (info (car command-line-args-left))
450 (setq command-line-args-left (cdr command-line-args-left)))
451 (error (send-string-to-terminal
452 (format "%s\n" (if (eq (car-safe err) 'error)
453 (nth 1 err) err)))
454 (save-buffers-kill-emacs)))
455 (info)))
7d3766a8 456\f
983dfbf8 457;; See if the accessible portion of the buffer begins with a node
11638562
EZ
458;; delimiter, and the node header line which follows matches REGEXP.
459;; Typically, this test will be followed by a loop that examines the
460;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
461;; to have the overhead of this special test inside the loop.
462
463;; This function changes match-data, but supposedly the caller might
464;; want to use the results of re-search-backward.
465
466;; The return value is the value of point at the beginning of matching
983dfbf8 467;; REGEXP, if the function succeeds, nil otherwise.
11638562 468(defun Info-node-at-bob-matching (regexp)
760d5cb3
GM
469 (and (bobp) ; are we at beginning of buffer?
470 (looking-at "\^_") ; does it begin with node delimiter?
11638562
EZ
471 (let (beg)
472 (forward-line 1)
473 (setq beg (point))
760d5cb3 474 (forward-line 1) ; does the line after delimiter match REGEXP?
11638562
EZ
475 (re-search-backward regexp beg t))))
476
a384cab3 477(defun Info-find-node (filename nodename &optional no-going-back)
fdf4b680
DL
478 "Go to an info node specified as separate FILENAME and NODENAME.
479NO-GOING-BACK is non-nil if recovering from an error in this function;
480it says do not attempt further (recursive) error recovery."
d0e41cba 481 (info-initialize)
a384cab3
JB
482 ;; Convert filename to lower case if not found as specified.
483 ;; Expand it.
4fceda3c 484 (if (stringp filename)
a384cab3 485 (let (temp temp-downcase found)
37a3ff5b
RS
486 (setq filename (substitute-in-file-name filename))
487 (if (string= (downcase filename) "dir")
488 (setq found t)
489 (let ((dirs (if (string-match "^\\./" filename)
490 ;; If specified name starts with `./'
491 ;; then just try current directory.
492 '("./")
493 (if (file-name-absolute-p filename)
494 ;; No point in searching for an
495 ;; absolute file name
496 '(nil)
497 (if Info-additional-directory-list
498 (append Info-directory-list
499 Info-additional-directory-list)
500 Info-directory-list)))))
501 ;; Search the directory list for file FILENAME.
502 (while (and dirs (not found))
503 (setq temp (expand-file-name filename (car dirs)))
504 (setq temp-downcase
505 (expand-file-name (downcase filename) (car dirs)))
506 ;; Try several variants of specified name.
e0c1e774 507 (let ((suffix-list Info-suffix-list)
ab5a535c
KS
508 (lfn (if (fboundp 'msdos-long-file-names)
509 (msdos-long-file-names)
510 t)))
37a3ff5b
RS
511 (while (and suffix-list (not found))
512 (cond ((info-file-exists-p
513 (info-insert-file-contents-1
e0c1e774 514 temp (car (car suffix-list)) lfn))
37a3ff5b
RS
515 (setq found temp))
516 ((info-file-exists-p
517 (info-insert-file-contents-1
e0c1e774
EZ
518 temp-downcase (car (car suffix-list)) lfn))
519 (setq found temp-downcase))
520 ((and (fboundp 'msdos-long-file-names)
521 lfn
522 (info-file-exists-p
523 (info-insert-file-contents-1
524 temp (car (car suffix-list)) nil)))
525 (setq found temp)))
37a3ff5b
RS
526 (setq suffix-list (cdr suffix-list))))
527 (setq dirs (cdr dirs)))))
528 (if found
529 (setq filename found)
530 (error "Info file %s does not exist" filename))))
531 ;; Record the node we are leaving.
532 (if (and Info-current-file (not no-going-back))
533 (setq Info-history
534 (cons (list Info-current-file Info-current-node (point))
535 Info-history)))
a384cab3 536 ;; Go into info buffer.
c5fe2ff1 537 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
4fceda3c
SM
538 (Info-find-node-2 filename nodename no-going-back))
539
540(defun Info-on-current-buffer (&optional nodename)
541 "Use the `Info-mode' to browse the current info buffer.
542If a prefix arg is provided, it queries for the NODENAME which
07e91aa3 543else defaults to \"Top\"."
4fceda3c
SM
544 (interactive
545 (list (if current-prefix-arg
546 (completing-read "Node name: " (Info-build-node-completions)
07e91aa3
SM
547 nil t "Top"))))
548 (unless nodename (setq nodename "Top"))
75296efc 549 (info-initialize)
4fceda3c
SM
550 (Info-mode)
551 (set (make-local-variable 'Info-current-file) t)
552 (Info-find-node-2 nil nodename))
553
f584b4c7
RS
554;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
555;; but at least it keeps this routine (which is only for the benefit of
556;; makeinfo-buffer) out of the way of normal operations.
557;;
558(defun Info-revert-find-node (filename nodename)
559 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
560When *info* is already displaying FILENAME and NODENAME, the window position
561is preserved, if possible."
562 (pop-to-buffer "*info*")
563 (let ((old-filename Info-current-file)
564 (old-nodename Info-current-node)
565 (pcolumn (current-column))
566 (pline (count-lines (point-min) (line-beginning-position)))
567 (wline (count-lines (point-min) (window-start)))
568 (old-history Info-history)
569 (new-history (and Info-current-file
570 (list Info-current-file Info-current-node (point)))))
571 (kill-buffer (current-buffer))
572 (Info-find-node filename nodename)
573 (setq Info-history old-history)
574 (if (and (equal old-filename Info-current-file)
575 (equal old-nodename Info-current-node))
576 (progn
577 ;; note goto-line is no good, we want to measure from point-min
578 (beginning-of-buffer)
579 (forward-line wline)
580 (set-window-start (selected-window) (point))
581 (beginning-of-buffer)
582 (forward-line pline)
583 (move-to-column pcolumn))
584 ;; only add to the history when coming from a different file+node
585 (if new-history
586 (setq Info-history (cons new-history Info-history))))))
587
357d11de
GM
588(defun Info-find-in-tag-table-1 (marker regexp case-fold)
589 "Find a node in a tag table.
590MARKER specifies the buffer and position to start searching at.
591REGEXP is a regular expression matching nodes or references. Its first
592group should match `Node:' or `Ref:'.
593CASE-FOLD t means search for a case-insensitive match.
594If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
595FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
596where the match was found, and MODE is `major-mode' of the buffer in
597which the match was found."
598 (let ((case-fold-search case-fold)
599 found-mode guesspos found-anchor)
600 (save-excursion
601 (set-buffer (marker-buffer marker))
602 (goto-char marker)
921e5fe6 603
357d11de
GM
604 ;; Search tag table
605 (beginning-of-line)
606 (when (re-search-forward regexp nil t)
607 (list (string-equal "Ref:" (match-string 1))
365d2503 608 (+ (point-min) (read (current-buffer)))
357d11de
GM
609 major-mode)))))
610
611(defun Info-find-in-tag-table (marker regexp)
612 "Find a node in a tag table.
613MARKER specifies the buffer and position to start searching at.
614REGEXP is a regular expression matching nodes or references. Its first
615group should match `Node:' or `Ref:'.
616If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
617FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
618where the match was found, and MODE is `major-mode' of the buffer in
619which the match was found.
620This function tries to find a case-sensitive match first, then a
621case-insensitive match is tried."
622 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
623 (when (null (car result))
624 (setq result (Info-find-in-tag-table-1 marker regexp t)))
625 result))
626
627(defun Info-find-node-in-buffer-1 (regexp case-fold)
628 "Find a node or anchor in the current buffer.
629REGEXP is a regular expression matching nodes or references. Its first
630group should match `Node:' or `Ref:'.
631CASE-FOLD t means search for a case-insensitive match.
632Value is the position at which a match was found, or nil if not found."
633 (let ((case-fold-search case-fold)
634 found)
635 (save-excursion
636 (when (Info-node-at-bob-matching regexp)
637 (setq found (point)))
638 (while (and (not found)
639 (search-forward "\n\^_" nil t))
640 (forward-line 1)
641 (let ((beg (point)))
642 (forward-line 1)
643 (when (re-search-backward regexp beg t)
644 (beginning-of-line)
645 (setq found (point)))))
646 found)))
921e5fe6 647
357d11de
GM
648(defun Info-find-node-in-buffer (regexp)
649 "Find a node or anchor in the current buffer.
650REGEXP is a regular expression matching nodes or references. Its first
651group should match `Node:' or `Ref:'.
652Value is the position at which a match was found, or nil if not found.
653This function looks for a case-sensitive match first. If none is found,
654a case-insensitive match is tried."
655 (or (Info-find-node-in-buffer-1 regexp nil)
656 (Info-find-node-in-buffer-1 regexp t)))
921e5fe6 657
4fceda3c 658(defun Info-find-node-2 (filename nodename &optional no-going-back)
9e5c2f50 659 (buffer-disable-undo (current-buffer))
a384cab3
JB
660 (or (eq major-mode 'Info-mode)
661 (Info-mode))
662 (widen)
663 (setq Info-current-node nil)
664 (unwind-protect
8bdf4b20
KH
665 (let ((case-fold-search t)
666 anchorpos)
37a3ff5b
RS
667 ;; Switch files if necessary
668 (or (null filename)
669 (equal Info-current-file filename)
670 (let ((buffer-read-only nil))
671 (setq Info-current-file nil
672 Info-current-subfile nil
673 Info-current-file-completions nil
674 buffer-file-name nil)
675 (erase-buffer)
676 (if (eq filename t)
677 (Info-insert-dir)
f7d5479b 678 (info-insert-file-contents filename nil)
37a3ff5b
RS
679 (setq default-directory (file-name-directory filename)))
680 (set-buffer-modified-p nil)
681 ;; See whether file has a tag table. Record the location if yes.
682 (goto-char (point-max))
683 (forward-line -8)
684 ;; Use string-equal, not equal, to ignore text props.
685 (if (not (or (string-equal nodename "*")
686 (not
687 (search-forward "\^_\nEnd tag table\n" nil t))))
688 (let (pos)
689 ;; We have a tag table. Find its beginning.
690 ;; Is this an indirect file?
691 (search-backward "\nTag table:\n")
692 (setq pos (point))
693 (if (save-excursion
694 (forward-line 2)
695 (looking-at "(Indirect)\n"))
696 ;; It is indirect. Copy it to another buffer
697 ;; and record that the tag table is in that buffer.
698 (let ((buf (current-buffer))
699 (tagbuf
700 (or Info-tag-table-buffer
701 (generate-new-buffer " *info tag table*"))))
702 (setq Info-tag-table-buffer tagbuf)
703 (save-excursion
704 (set-buffer tagbuf)
9e5c2f50 705 (buffer-disable-undo (current-buffer))
37a3ff5b
RS
706 (setq case-fold-search t)
707 (erase-buffer)
708 (insert-buffer-substring buf))
709 (set-marker Info-tag-table-marker
710 (match-end 0) tagbuf))
711 (set-marker Info-tag-table-marker pos)))
712 (set-marker Info-tag-table-marker nil))
713 (setq Info-current-file
714 (if (eq filename t) "dir" filename))))
715 ;; Use string-equal, not equal, to ignore text props.
716 (if (string-equal nodename "*")
717 (progn (setq Info-current-node nodename)
718 (Info-set-mode-line))
719 ;; Possibilities:
720 ;;
721 ;; 1. Anchor found in tag table
722 ;; 2. Anchor *not* in tag table
723 ;;
724 ;; 3. Node found in tag table
725 ;; 4. Node *not* found in tag table, but found in file
726 ;; 5. Node *not* in tag table, and *not* in file
727 ;;
728 ;; *Or* the same, but in an indirect subfile.
729
730 ;; Search file for a suitable node.
8bdf4b20 731 (let ((guesspos (point-min))
357d11de 732 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
4ce5c223 733 (if (stringp nodename)
dd31e4e8
GM
734 (regexp-quote nodename)
735 "")
357d11de 736 "\\) *[,\t\n\177]"))
8bdf4b20 737 (nodepos nil))
37a3ff5b 738
82172606 739 (catch 'foo
921e5fe6 740
82172606 741 ;; First, search a tag table, if any
357d11de
GM
742 (when (marker-position Info-tag-table-marker)
743 (let* ((m Info-tag-table-marker)
744 (found (Info-find-in-tag-table m regexp)))
921e5fe6 745
357d11de
GM
746 (when found
747 ;; FOUND is (ANCHOR POS MODE).
748 (setq guesspos (nth 1 found))
921e5fe6 749
357d11de
GM
750 ;; If this is an indirect file, determine which
751 ;; file really holds this node and read it in.
752 (unless (eq (nth 2 found) 'Info-mode)
753 ;; Note that the current buffer must be the
754 ;; *info* buffer on entry to
755 ;; Info-read-subfile. Thus the hackery above.
756 (setq guesspos (Info-read-subfile guesspos)))
82172606
DL
757
758 ;; Handle anchor
357d11de
GM
759 (when (nth 0 found)
760 (goto-char (setq anchorpos guesspos))
761 (throw 'foo t)))))
82172606
DL
762
763 ;; Else we may have a node, which we search for:
764 (goto-char (max (point-min)
765 (- (byte-to-position guesspos) 1000)))
921e5fe6 766
357d11de
GM
767 ;; Now search from our advised position (or from beg of
768 ;; buffer) to find the actual node. First, check
769 ;; whether the node is right where we are, in case the
770 ;; buffer begins with a node.
771 (let ((pos (Info-find-node-in-buffer regexp)))
772 (when pos
773 (goto-char pos)
774 (throw 'foo t))
775 (error "No such anchor in tag table or node in tag table or file: %s"
776 nodename)))
82172606
DL
777
778 (Info-select-node)
779 (goto-char (or anchorpos (point-min))))))
a384cab3
JB
780 ;; If we did not finish finding the specified node,
781 ;; go back to the previous one.
4db579ab 782 (or Info-current-node no-going-back (null Info-history)
37a3ff5b
RS
783 (let ((hist (car Info-history)))
784 (setq Info-history (cdr Info-history))
785 (Info-find-node (nth 0 hist) (nth 1 hist) t)
786 (goto-char (nth 2 hist))))))
a384cab3 787
44c327f9
JB
788;; Cache the contents of the (virtual) dir file, once we have merged
789;; it for the first time, so we can save time subsequently.
7ea13762
RS
790(defvar Info-dir-contents nil)
791
44c327f9
JB
792;; Cache for the directory we decided to use for the default-directory
793;; of the merged dir text.
794(defvar Info-dir-contents-directory nil)
795
c142ab2d
RS
796;; Record the file attributes of all the files from which we
797;; constructed Info-dir-contents.
798(defvar Info-dir-file-attributes nil)
799
4fba3b2c
RS
800(defvar Info-dir-file-name nil)
801
7ea13762 802;; Construct the Info directory node by merging the files named `dir'
44c327f9
JB
803;; from various directories. Set the *info* buffer's
804;; default-directory to the first directory we actually get any text
805;; from.
7ea13762 806(defun Info-insert-dir ()
c142ab2d
RS
807 (if (and Info-dir-contents Info-dir-file-attributes
808 ;; Verify that none of the files we used has changed
809 ;; since we used it.
810 (eval (cons 'and
b461e32d
SM
811 (mapcar (lambda (elt)
812 (let ((curr (file-attributes
813 ;; Handle symlinks
814 (file-truename (car elt)))))
815
816 ;; Don't compare the access time.
817 (if curr (setcar (nthcdr 4 curr) 0))
818 (setcar (nthcdr 4 (cdr elt)) 0)
819 (equal (cdr elt) curr)))
c142ab2d 820 Info-dir-file-attributes))))
4fba3b2c
RS
821 (progn
822 (insert Info-dir-contents)
823 (goto-char (point-min)))
dd31e4e8 824 (let ((dirs (if Info-additional-directory-list
b34dcc82
RS
825 (append Info-directory-list
826 Info-additional-directory-list)
827 Info-directory-list))
1bd19a31 828 (dir-file-attrs nil)
1bcedb3b
RS
829 ;; Bind this in case the user sets it to nil.
830 (case-fold-search t)
4fba3b2c
RS
831 ;; This is set non-nil if we find a problem in some input files.
832 problems
f4008b6e 833 buffers buffer others nodes dirs-done)
44c327f9
JB
834
835 ;; Search the directory list for the directory file.
7ea13762 836 (while dirs
8d1abb42
RS
837 (let ((truename (file-truename (expand-file-name (car dirs)))))
838 (or (member truename dirs-done)
839 (member (directory-file-name truename) dirs-done)
840 ;; Try several variants of specified name.
841 ;; Try upcasing, appending `.info', or both.
825d6f08
RS
842 (let* (file
843 (attrs
844 (or
845 (progn (setq file (expand-file-name "dir" truename))
846 (file-attributes file))
847 (progn (setq file (expand-file-name "DIR" truename))
848 (file-attributes file))
849 (progn (setq file (expand-file-name "dir.info" truename))
850 (file-attributes file))
851 (progn (setq file (expand-file-name "DIR.INFO" truename))
852 (file-attributes file)))))
8d1abb42
RS
853 (setq dirs-done
854 (cons truename
855 (cons (directory-file-name truename)
856 dirs-done)))
825d6f08
RS
857 (if attrs
858 (save-excursion
859 (or buffers
860 (message "Composing main Info directory..."))
2d41cf59 861 (set-buffer (generate-new-buffer " info dir"))
9d499629
RS
862 (condition-case nil
863 (progn
864 (insert-file-contents file)
1bd19a31
MB
865 (set (make-local-variable 'Info-dir-file-name)
866 file)
6af7040d 867 (push (current-buffer) buffers)
1bd19a31 868 (push (cons file attrs) dir-file-attrs))
9d499629 869 (error (kill-buffer (current-buffer))))))))
1bd19a31
MB
870 (unless (cdr dirs)
871 (set (make-local-variable 'Info-dir-contents-directory)
872 (file-name-as-directory (car dirs))))
825d6f08 873 (setq dirs (cdr dirs))))
399c88ad 874
4db579ab 875 (or buffers
81e14cb2 876 (error "Can't find the Info directory node"))
1bd19a31 877
44c327f9 878 ;; Distinguish the dir file that comes with Emacs from all the
f4008b6e 879 ;; others. Yes, that is really what this is supposed to do.
f601cd3e
DL
880 ;; The definition of `Info-directory-list' puts it first on that
881 ;; list and so last in `buffers' at this point.
882 (setq buffer (car (last buffers))
883 others (delq buffer buffers))
44c327f9 884
debcea0c
KH
885 ;; Insert the entire original dir file as a start; note that we've
886 ;; already saved its default directory to use as the default
887 ;; directory for the whole concatenation.
7ea13762 888 (insert-buffer buffer)
44c327f9 889
7ea13762 890 ;; Look at each of the other buffers one by one.
6af7040d
SM
891 (dolist (other others)
892 (let (this-buffer-nodes)
7ea13762 893 ;; In each, find all the menus.
6af7040d 894 (with-current-buffer other
7ea13762
RS
895 (goto-char (point-min))
896 ;; Find each menu, and add an elt to NODES for it.
897 (while (re-search-forward "^\\* Menu:" nil t)
6af7040d
SM
898 (while (and (zerop (forward-line 1)) (eolp)))
899 (let ((beg (point))
900 nodename end)
901 (re-search-backward "^\^_")
7ea13762
RS
902 (search-forward "Node: ")
903 (setq nodename (Info-following-node-name))
3a6ade8a 904 (search-forward "\n\^_" nil 'move)
7ea13762
RS
905 (beginning-of-line)
906 (setq end (point))
6af7040d 907 (push (list nodename other beg end) this-buffer-nodes)))
4fba3b2c
RS
908 (if (assoc-ignore-case "top" this-buffer-nodes)
909 (setq nodes (nconc this-buffer-nodes nodes))
910 (setq problems t)
6af7040d 911 (message "No `top' node in %s" Info-dir-file-name)))))
fdf4b680 912 ;; Add to the main menu a menu item for each other node.
6af7040d 913 (re-search-forward "^\\* Menu:")
7ea13762
RS
914 (forward-line 1)
915 (let ((menu-items '("top"))
3a6ade8a 916 (end (save-excursion (search-forward "\^_" nil t) (point))))
6af7040d
SM
917 (dolist (node nodes)
918 (let ((nodename (car node)))
c3a29d70
RS
919 (save-excursion
920 (or (member (downcase nodename) menu-items)
b37daea4 921 (re-search-forward (concat "^\\* +"
c3a29d70
RS
922 (regexp-quote nodename)
923 "::")
924 end t)
925 (progn
926 (insert "* " nodename "::" "\n")
6af7040d 927 (push nodename menu-items)))))))
7ea13762
RS
928 ;; Now take each node of each of the other buffers
929 ;; and merge it into the main buffer.
6af7040d 930 (dolist (node nodes)
760d5cb3 931 (let ((case-fold-search t)
6af7040d 932 (nodename (car node)))
7ea13762
RS
933 (goto-char (point-min))
934 ;; Find the like-named node in the main buffer.
ba42ce14 935 (if (re-search-forward (concat "^\^_.*\n.*Node: "
7ea13762
RS
936 (regexp-quote nodename)
937 "[,\n\t]")
938 nil t)
939 (progn
3a6ade8a 940 (search-forward "\n\^_" nil 'move)
25869acf
RS
941 (beginning-of-line)
942 (insert "\n"))
7ea13762
RS
943 ;; If none exists, add one.
944 (goto-char (point-max))
dfbf6104 945 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
7ea13762
RS
946 ;; Merge the text from the other buffer's menu
947 ;; into the menu in the like-named node in the main buffer.
6af7040d
SM
948 (apply 'insert-buffer-substring (cdr node))))
949 (Info-dir-remove-duplicates)
7ea13762 950 ;; Kill all the buffers we just made.
6af7040d 951 (mapc 'kill-buffer buffers)
4fba3b2c
RS
952 (goto-char (point-min))
953 (if problems
954 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1bd19a31
MB
955 (message "Composing main Info directory...done"))
956 (set (make-local-variable 'Info-dir-contents) (buffer-string))
957 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
44c327f9 958 (setq default-directory Info-dir-contents-directory))
7ea13762 959
6af7040d
SM
960(defvar Info-streamline-headings
961 '(("Emacs" . "Emacs")
962 ("Programming" . "Programming")
963 ("Libraries" . "Libraries")
964 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
965 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
966
967(defun Info-dir-remove-duplicates ()
968 (let (limit)
969 (goto-char (point-min))
970 ;; Remove duplicate headings in the same menu.
971 (while (search-forward "\n* Menu:" nil t)
972 (setq limit (save-excursion (search-forward "\n\1f" nil t)))
973 ;; Look for the next heading to unify.
974 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
975 (let ((name (match-string 1))
976 (start (match-beginning 0))
977 (entries nil) re)
978 ;; Check whether this heading should be streamlined.
979 (save-match-data
980 (dolist (x Info-streamline-headings)
981 (when (string-match (car x) name)
982 (setq name (cdr x))
983 (setq re (car x)))))
984 (if re (replace-match name t t nil 1))
985 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
986 (match-beginning 0)
987 (or limit (point-max))))
988 ;; Look for other headings of the same category and merge them.
989 (save-excursion
990 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
991 (when (if re (save-match-data (string-match re (match-string 1)))
992 (equal name (match-string 1)))
993 (forward-line 0)
994 ;; Delete redundant heading.
995 (delete-region (match-beginning 0) (point))
996 ;; Push the entries onto `text'.
997 (push
998 (delete-and-extract-region
999 (point)
1000 (if (re-search-forward "^[^* \n\t]" nil t)
1001 (match-beginning 0)
1002 (or limit (point-max)))) entries))))
1003 ;; Insert the entries just found.
1004 (while (= (line-beginning-position 0) (1- (point)))
1005 (backward-char))
1006 (dolist (entry (nreverse entries))
1007 (insert entry)
1008 (while (= (line-beginning-position 0) (1- (point)))
1009 (delete-region (1- (point)) (point))))
921e5fe6 1010
6af7040d
SM
1011 ;; Now remove duplicate entries under the same heading.
1012 (let ((seen nil)
1013 (limit (point)))
1014 (goto-char start)
1015 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1016 limit 'move)
1017 (let ((x (match-string 1)))
1018 (if (member-ignore-case x seen)
1019 (delete-region (match-beginning 0)
1020 (progn (re-search-forward "^[^ \t]" nil t)
25046503 1021 (match-beginning 0)))
6af7040d
SM
1022 (push x seen))))))))))
1023
c5fe2ff1
RS
1024;; Note that on entry to this function the current-buffer must be the
1025;; *info* buffer; not the info tags buffer.
a384cab3 1026(defun Info-read-subfile (nodepos)
a361deba
RS
1027 ;; NODEPOS is either a position (in the Info file as a whole,
1028 ;; not relative to a subfile) or the name of a subfile.
a384cab3
JB
1029 (let (lastfilepos
1030 lastfilename)
a361deba
RS
1031 (if (numberp nodepos)
1032 (save-excursion
1033 (set-buffer (marker-buffer Info-tag-table-marker))
1034 (goto-char (point-min))
ba42ce14
EZ
1035 (or (looking-at "\^_")
1036 (search-forward "\n\^_"))
a361deba
RS
1037 (forward-line 2)
1038 (catch 'foo
1039 (while (not (looking-at "\^_"))
1040 (if (not (eolp))
1041 (let ((beg (point))
1042 thisfilepos thisfilename)
1043 (search-forward ": ")
1044 (setq thisfilename (buffer-substring beg (- (point) 2)))
365d2503 1045 (setq thisfilepos (+ (point-min) (read (current-buffer))))
a361deba
RS
1046 ;; read in version 19 stops at the end of number.
1047 ;; Advance to the next line.
1048 (forward-line 1)
1049 (if (> thisfilepos nodepos)
1050 (throw 'foo t))
1051 (setq lastfilename thisfilename)
1052 (setq lastfilepos thisfilepos))
1053 (forward-line 1)))))
1054 (setq lastfilename nodepos)
1055 (setq lastfilepos 0))
c5fe2ff1
RS
1056 ;; Assume previous buffer is in Info-mode.
1057 ;; (set-buffer (get-buffer "*info*"))
a384cab3
JB
1058 (or (equal Info-current-subfile lastfilename)
1059 (let ((buffer-read-only nil))
1060 (setq buffer-file-name nil)
1061 (widen)
1062 (erase-buffer)
1143a6b0 1063 (info-insert-file-contents lastfilename)
a384cab3
JB
1064 (set-buffer-modified-p nil)
1065 (setq Info-current-subfile lastfilename)))
b0e52598
RS
1066 ;; Widen in case we are in the same subfile as before.
1067 (widen)
a384cab3 1068 (goto-char (point-min))
ba42ce14
EZ
1069 (if (looking-at "\^_")
1070 (forward-char 1)
1071 (search-forward "\n\^_"))
a361deba
RS
1072 (if (numberp nodepos)
1073 (+ (- nodepos lastfilepos) (point)))))
a384cab3 1074
50ac70af
MB
1075(defvar Info-header-line nil
1076 "If the info node header is hidden, the text of the header.")
c793c600 1077(put 'Info-header-line 'risky-local-variable t)
50ac70af 1078
a384cab3 1079(defun Info-select-node ()
fdf4b680
DL
1080"Select the info node that point is in.
1081Bind this in case the user sets it to nil."
1bcedb3b
RS
1082 (let ((case-fold-search t))
1083 (save-excursion
760d5cb3
GM
1084 ;; Find beginning of node.
1085 (if (search-backward "\n\^_" nil 'move)
1086 (forward-line 2)
1087 (if (looking-at "\^_")
1088 (forward-line 1)
1089 (signal 'search-failed (list "\n\^_"))))
1090 ;; Get nodename spelled as it is in the node.
1091 (re-search-forward "Node:[ \t]*")
1092 (setq Info-current-node
1093 (buffer-substring-no-properties (point)
1094 (progn
1095 (skip-chars-forward "^,\t\n")
1096 (point))))
1097 (Info-set-mode-line)
1098 ;; Find the end of it, and narrow.
1099 (beginning-of-line)
1100 (let (active-expression)
50ac70af 1101 ;; Narrow to the node contents
760d5cb3
GM
1102 (narrow-to-region (point)
1103 (if (re-search-forward "\n[\^_\f]" nil t)
1104 (prog1
1105 (1- (point))
1106 (if (looking-at "[\n\^_\f]*execute: ")
1107 (progn
1108 (goto-char (match-end 0))
1109 (setq active-expression
1110 (read (current-buffer))))))
1111 (point-max)))
1112 (if Info-enable-active-nodes (eval active-expression))
544e5562 1113 (Info-fontify-node)
6af7040d 1114 (setq Info-header-line (get-text-property (point-min) 'header-line))
760d5cb3 1115 (run-hooks 'Info-selection-hook)))))
a384cab3
JB
1116
1117(defun Info-set-mode-line ()
1118 (setq mode-line-buffer-identification
313fe58a 1119 (nconc (propertized-buffer-identification "%b")
918e364a
MB
1120 (list
1121 (concat " ("
1122 (file-name-nondirectory
1123 (if (stringp Info-current-file)
1124 Info-current-file
1125 (or buffer-file-name "")))
1126 ") "
1127 (or Info-current-node ""))))))
a384cab3
JB
1128\f
1129;; Go to an info node specified with a filename-and-nodename string
1130;; of the sort that is found in pointers in nodes.
1131
4fceda3c 1132(defun Info-goto-node (nodename &optional fork)
cfc697a2 1133 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
dc414be1
EZ
1134If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1135FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1136its sub-files).
1137Completion is available, but only for node names in the current Info file.
7210b6f5
DL
1138If FORK is non-nil (interactively with a prefix arg), show the node in
1139a new info buffer.
4fceda3c 1140If FORK is a string, it is the name to use for the new buffer."
d1268e52 1141 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
d0e41cba 1142 (info-initialize)
4fceda3c 1143 (if fork
760d5cb3
GM
1144 (set-buffer
1145 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
a384cab3
JB
1146 (let (filename)
1147 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1148 nodename)
1149 (setq filename (if (= (match-beginning 1) (match-end 1))
1150 ""
1151 (substring nodename (match-beginning 2) (match-end 2)))
1152 nodename (substring nodename (match-beginning 3) (match-end 3)))
1153 (let ((trim (string-match "\\s *\\'" filename)))
1154 (if trim (setq filename (substring filename 0 trim))))
1155 (let ((trim (string-match "\\s *\\'" nodename)))
1156 (if trim (setq nodename (substring nodename 0 trim))))
e579232c 1157 (if transient-mark-mode (deactivate-mark))
a384cab3
JB
1158 (Info-find-node (if (equal filename "") nil filename)
1159 (if (equal nodename "") "Top" nodename))))
552775bd 1160
ddf89211
RS
1161(defvar Info-read-node-completion-table)
1162
03524be6 1163;; This function is used as the "completion table" while reading a node name.
ddf89211 1164;; It does completion using the alist in Info-read-node-completion-table
03524be6
RS
1165;; unless STRING starts with an open-paren.
1166(defun Info-read-node-name-1 (string predicate code)
365d2503
SM
1167 (cond
1168 ;; First complete embedded file names.
1169 ((string-match "\\`([^)]*\\'" string)
1170 (let ((file (substring string 1)))
1171 (cond
1172 ((eq code nil)
1173 (let ((comp (try-completion file 'locate-file-completion
1174 (cons Info-directory-list
1175 (mapcar 'car Info-suffix-list)))))
1176 (cond
1177 ((eq comp t) (concat string ")"))
1178 (comp (concat "(" comp)))))
1179 ((eq code t) (all-completions file 'locate-file-completion
1180 (cons Info-directory-list
1181 (mapcar 'car Info-suffix-list))))
1182 (t nil))))
1183 ;; If a file name was given, then any node is fair game.
1184 ((string-match "\\`(" string)
1185 (cond
1186 ((eq code nil) string)
1187 ((eq code t) nil)
1188 (t t)))
1189 ;; Otherwise use Info-read-node-completion-table.
1190 ((eq code nil)
1191 (try-completion string Info-read-node-completion-table predicate))
1192 ((eq code t)
1193 (all-completions string Info-read-node-completion-table predicate))
1194 (t
1195 (test-completion string Info-read-node-completion-table predicate))))
03524be6 1196
552775bd
RS
1197(defun Info-read-node-name (prompt &optional default)
1198 (let* ((completion-ignore-case t)
ddf89211 1199 (Info-read-node-completion-table (Info-build-node-completions))
b6d61ffa 1200 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
552775bd
RS
1201 (if (equal nodename "")
1202 (or default
1203 (Info-read-node-name prompt))
1204 nodename)))
1205
1206(defun Info-build-node-completions ()
1207 (or Info-current-file-completions
1bcedb3b
RS
1208 (let ((compl nil)
1209 ;; Bind this in case the user sets it to nil.
11638562
EZ
1210 (case-fold-search t)
1211 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
552775bd
RS
1212 (save-excursion
1213 (save-restriction
1214 (if (marker-buffer Info-tag-table-marker)
c5fe2ff1
RS
1215 (let ((marker Info-tag-table-marker))
1216 (set-buffer (marker-buffer marker))
cedb118c 1217 (widen)
c5fe2ff1 1218 (goto-char marker)
fdf4b680 1219 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
552775bd 1220 (setq compl
fdf4b680 1221 (cons (list (match-string-no-properties 2))
552775bd
RS
1222 compl))))
1223 (widen)
1224 (goto-char (point-min))
11638562
EZ
1225 ;; If the buffer begins with a node header, process that first.
1226 (if (Info-node-at-bob-matching node-regexp)
110d4e80 1227 (setq compl (list (match-string-no-properties 1))))
11638562 1228 ;; Now for the rest of the nodes.
552775bd
RS
1229 (while (search-forward "\n\^_" nil t)
1230 (forward-line 1)
1231 (let ((beg (point)))
1232 (forward-line 1)
11638562 1233 (if (re-search-backward node-regexp beg t)
399c88ad 1234 (setq compl
110d4e80 1235 (cons (list (match-string-no-properties 1))
552775bd 1236 compl))))))))
87d2b5a2 1237 (setq compl (cons '("*") compl))
07b1b912 1238 (set (make-local-variable 'Info-current-file-completions) compl))))
a384cab3 1239\f
aea2a8da
JB
1240(defun Info-restore-point (hl)
1241 "If this node has been visited, restore the point value when we left."
cedb118c
RS
1242 (while hl
1243 (if (and (equal (nth 0 (car hl)) Info-current-file)
e90d1271
RS
1244 ;; Use string-equal, not equal, to ignore text props.
1245 (string-equal (nth 1 (car hl)) Info-current-node))
cedb118c 1246 (progn
d96504df
KH
1247 (goto-char (nth 2 (car hl)))
1248 (setq hl nil)) ;terminate the while at next iter
cedb118c 1249 (setq hl (cdr hl)))))
aea2a8da 1250\f
2c80a618
GM
1251(defvar Info-search-history nil
1252 "The history list for `Info-search'.")
a384cab3
JB
1253
1254(defun Info-search (regexp)
1255 "Search for REGEXP, starting from point, and select node it's found in."
bbc96600
EZ
1256 (interactive (list (read-string
1257 (if Info-search-history
1258 (format "Regexp search (default `%s'): "
1259 (car Info-search-history))
1260 "Regexp search: ")
1261 nil 'Info-search-history)))
2c80a618
GM
1262 (when transient-mark-mode
1263 (deactivate-mark))
1264 (when (equal regexp "")
1265 (setq regexp (car Info-search-history)))
c47b5bbe
DL
1266 (when regexp
1267 (let ((found ()) current
1268 (onode Info-current-node)
1269 (ofile Info-current-file)
1270 (opoint (point))
1271 (ostart (window-start))
1272 (osubfile Info-current-subfile))
1273 (save-excursion
1274 (save-restriction
1275 (widen)
1276 (if (null Info-current-subfile)
a384cab3 1277 (progn (re-search-forward regexp) (setq found (point)))
c47b5bbe
DL
1278 (condition-case err
1279 (progn (re-search-forward regexp) (setq found (point)))
1280 (search-failed nil)))))
760d5cb3 1281 (if (not found) ;can only happen in subfile case -- else would have erred
c47b5bbe
DL
1282 (unwind-protect
1283 (let ((list ()))
1284 (save-excursion
1285 (set-buffer (marker-buffer Info-tag-table-marker))
c5fe2ff1 1286 (goto-char (point-min))
c47b5bbe
DL
1287 (search-forward "\n\^_\nIndirect:")
1288 (save-restriction
1289 (narrow-to-region (point)
1290 (progn (search-forward "\n\^_")
1291 (1- (point))))
1292 (goto-char (point-min))
112211d1 1293 ;; Find the subfile we just searched.
c47b5bbe 1294 (search-forward (concat "\n" osubfile ": "))
112211d1
RS
1295 ;; Skip that one.
1296 (forward-line 1)
1297 ;; Make a list of all following subfiles.
1298 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
c47b5bbe
DL
1299 (while (not (eobp))
1300 (re-search-forward "\\(^.*\\): [0-9]+$")
1301 (goto-char (+ (match-end 1) 2))
112211d1
RS
1302 (setq list (cons (cons (+ (point-min)
1303 (read (current-buffer)))
110d4e80 1304 (match-string-no-properties 1))
c47b5bbe
DL
1305 list))
1306 (goto-char (1+ (match-end 0))))
112211d1
RS
1307 ;; Put in forward order
1308 (setq list (nreverse list))))
c47b5bbe
DL
1309 (while list
1310 (message "Searching subfile %s..." (cdr (car list)))
1311 (Info-read-subfile (car (car list)))
1312 (setq list (cdr list))
c47b5bbe
DL
1313 (if (re-search-forward regexp nil t)
1314 (setq found (point) list ())))
1315 (if found
1316 (message "")
1317 (signal 'search-failed (list regexp))))
1318 (if (not found)
1319 (progn (Info-read-subfile osubfile)
1320 (goto-char opoint)
1321 (Info-select-node)
1322 (set-window-start (selected-window) ostart)))))
760d5cb3
GM
1323 (widen)
1324 (goto-char found)
1325 (Info-select-node)
1326 ;; Use string-equal, not equal, to ignore text props.
1327 (or (and (string-equal onode Info-current-node)
1328 (equal ofile Info-current-file))
1329 (setq Info-history (cons (list ofile onode opoint)
1330 Info-history))))))
a384cab3 1331\f
a384cab3 1332(defun Info-extract-pointer (name &optional errorname)
fdf4b680
DL
1333 "Extract the value of the node-pointer named NAME.
1334If there is none, use ERRORNAME in the error message;
1335if ERRORNAME is nil, just return nil.
1336Bind this in case the user sets it to nil."
1bcedb3b
RS
1337 (let ((case-fold-search t))
1338 (save-excursion
50ac70af
MB
1339 (save-restriction
1340 (goto-char (point-min))
50ac70af
MB
1341 (let ((bound (point)))
1342 (forward-line 1)
c1699282 1343 (cond ((re-search-backward (concat name ":") bound t)
0cb39153
MB
1344 (goto-char (match-end 0))
1345 (Info-following-node-name))
50ac70af
MB
1346 ((not (eq errorname t))
1347 (error "Node has no %s"
1348 (capitalize (or errorname name))))))))))
a384cab3
JB
1349
1350(defun Info-following-node-name (&optional allowedchars)
fdf4b680
DL
1351 "Return the node name in the buffer following point.
1352ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1353saying which chars may appear in the node name."
a384cab3 1354 (skip-chars-forward " \t")
70d78eb6 1355 (buffer-substring-no-properties
a384cab3
JB
1356 (point)
1357 (progn
1358 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1359 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1360 (if (looking-at "(")
1361 (skip-chars-forward "^)")))
1362 (skip-chars-backward " ")
1363 (point))))
1364
1365(defun Info-next ()
1366 "Go to the next node of this node."
1367 (interactive)
1368 (Info-goto-node (Info-extract-pointer "next")))
1369
1370(defun Info-prev ()
1371 "Go to the previous node of this node."
1372 (interactive)
1373 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1374
5dab2fb4
RS
1375(defun Info-up (&optional same-file)
1376 "Go to the superior node of this node.
1377If SAME-FILE is non-nil, do not move to a different Info file."
a384cab3 1378 (interactive)
5dab2fb4 1379 (let ((node (Info-extract-pointer "up")))
4fceda3c 1380 (and (or same-file (not (stringp Info-current-file)))
5dab2fb4
RS
1381 (string-match "^(" node)
1382 (error "Up node is in another Info file"))
1383 (Info-goto-node node))
aea2a8da 1384 (Info-restore-point Info-history))
a384cab3
JB
1385
1386(defun Info-last ()
1387 "Go back to the last node visited."
1388 (interactive)
1389 (or Info-history
1390 (error "This is the first Info node you looked at"))
1391 (let (filename nodename opoint)
1392 (setq filename (car (car Info-history)))
1393 (setq nodename (car (cdr (car Info-history))))
1394 (setq opoint (car (cdr (cdr (car Info-history)))))
1395 (setq Info-history (cdr Info-history))
1396 (Info-find-node filename nodename)
1397 (setq Info-history (cdr Info-history))
1398 (goto-char opoint)))
1399
48e5b471 1400;;;###autoload
a384cab3
JB
1401(defun Info-directory ()
1402 "Go to the Info directory node."
1403 (interactive)
1404 (Info-find-node "dir" "top"))
1405\f
1406(defun Info-follow-reference (footnotename)
fdf4b680
DL
1407 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1408FOOTNOTENAME may be an abbreviation of the reference name."
a384cab3
JB
1409 (interactive
1410 (let ((completion-ignore-case t)
1bcedb3b 1411 (case-fold-search t)
67bc89ab 1412 completions default alt-default (start-point (point)) str i bol eol)
a384cab3 1413 (save-excursion
67bc89ab
RS
1414 ;; Store end and beginning of line.
1415 (end-of-line)
1416 (setq eol (point))
1417 (beginning-of-line)
1418 (setq bol (point))
1419
a384cab3
JB
1420 (goto-char (point-min))
1421 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
110d4e80 1422 (setq str (buffer-substring-no-properties
a384cab3
JB
1423 (match-beginning 1)
1424 (1- (point))))
1425 ;; See if this one should be the default.
1426 (and (null default)
1f179e27 1427 (<= (match-beginning 0) start-point)
a384cab3
JB
1428 (<= start-point (point))
1429 (setq default t))
67bc89ab
RS
1430 ;; See if this one should be the alternate default.
1431 (and (null alt-default)
1432 (and (<= bol (match-beginning 0))
1433 (<= (point) eol))
1434 (setq alt-default t))
a384cab3
JB
1435 (setq i 0)
1436 (while (setq i (string-match "[ \n\t]+" str i))
1437 (setq str (concat (substring str 0 i) " "
1438 (substring str (match-end 0))))
1439 (setq i (1+ i)))
1440 ;; Record as a completion and perhaps as default.
1441 (if (eq default t) (setq default str))
67bc89ab 1442 (if (eq alt-default t) (setq alt-default str))
ec6d29af
KH
1443 ;; Don't add this string if it's a duplicate.
1444 ;; We use a loop instead of "(assoc str completions)" because
1445 ;; we want to do a case-insensitive compare.
1446 (let ((tail completions)
1447 (tem (downcase str)))
1448 (while (and tail
1449 (not (string-equal tem (downcase (car (car tail))))))
1450 (setq tail (cdr tail)))
1451 (or tail
1452 (setq completions
1453 (cons (cons str nil)
1454 completions))))))
67bc89ab
RS
1455 ;; If no good default was found, try an alternate.
1456 (or default
1457 (setq default alt-default))
1458 ;; If only one cross-reference found, then make it default.
1459 (if (eq (length completions) 1)
1460 (setq default (car (car completions))))
a384cab3 1461 (if completions
b0ebdfe5 1462 (let ((input (completing-read (if default
968b7671
MB
1463 (concat
1464 "Follow reference named: (default "
1465 default ") ")
b0ebdfe5
RS
1466 "Follow reference named: ")
1467 completions nil t)))
1468 (list (if (equal input "")
1469 default input)))
a384cab3 1470 (error "No cross-references in this node"))))
ebf8f7e1
RS
1471
1472 (unless footnotename
1473 (error "No reference was specified"))
1474
1bcedb3b
RS
1475 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
1476 (case-fold-search t))
a384cab3
JB
1477 (while (setq i (string-match " " str i))
1478 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1479 (setq i (+ i 6)))
1480 (save-excursion
1481 (goto-char (point-min))
1482 (or (re-search-forward str nil t)
1483 (error "No cross-reference named %s" footnotename))
1484 (goto-char (+ (match-beginning 0) 5))
1485 (setq target
1486 (Info-extract-menu-node-name "Bad format cross reference" t)))
1487 (while (setq i (string-match "[ \t\n]+" target i))
1488 (setq target (concat (substring target 0 i) " "
1489 (substring target (match-end 0))))
1490 (setq i (+ i 1)))
1491 (Info-goto-node target)))
1492
1493(defun Info-extract-menu-node-name (&optional errmessage multi-line)
1494 (skip-chars-forward " \t\n")
1495 (let ((beg (point))
1496 str i)
e9d3d47f 1497 (while (not (looking-at ":*[,.;() \t\n]"))
505b68d5
TTN
1498 (skip-chars-forward "^:")
1499 (forward-char 1))
a384cab3
JB
1500 (setq str
1501 (if (looking-at ":")
70d78eb6 1502 (buffer-substring-no-properties beg (1- (point)))
a384cab3 1503 (skip-chars-forward " \t\n")
4e5f958e 1504 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
f7d5479b 1505 (replace-regexp-in-string "[ \n]+" " " str)))
a384cab3 1506
e8adde3f 1507;; No one calls this.
9e5c2f50
RS
1508;;(defun Info-menu-item-sequence (list)
1509;; (while list
e8adde3f 1510;; (Info-menu (car list))
9e5c2f50 1511;; (setq list (cdr list))))
a384cab3 1512
6356e646 1513(defvar Info-complete-menu-buffer)
e4e8ee63
SM
1514(defvar Info-complete-next-re nil)
1515(defvar Info-complete-cache nil)
6356e646 1516
e8adde3f 1517(defun Info-complete-menu-item (string predicate action)
2d12f5c2
SM
1518 ;; This uses two dynamically bound variables:
1519 ;; - `Info-complete-menu-buffer' which contains the buffer in which
1520 ;; is the menu of items we're trying to complete.
1521 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
1522 ;; also look for menu items in subsequent nodes as long as those
1523 ;; nodes' names match `Info-complete-next-re'. This feature is currently
1524 ;; only used for completion in Info-index.
e4e8ee63
SM
1525 (save-excursion
1526 (set-buffer Info-complete-menu-buffer)
1527 (let ((completion-ignore-case t)
1528 (case-fold-search t)
1529 (orignode Info-current-node)
1530 nextnode)
1531 (goto-char (point-min))
1532 (search-forward "\n* Menu:")
1533 (if (not (memq action '(nil t)))
1534 (re-search-forward
1535 (concat "\n\\* +" (regexp-quote string) ":") nil t)
1536 (let ((pattern (concat "\n\\* +\\("
1537 (regexp-quote string)
505b68d5 1538 "[^\t\n]*\\):"))
e4e8ee63
SM
1539 completions)
1540 ;; Check the cache.
1541 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
1542 (equal (nth 1 Info-complete-cache) Info-current-node)
1543 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
1544 (let ((prev (nth 3 Info-complete-cache)))
1545 (eq t (compare-strings string 0 (length prev)
1546 prev 0 nil t))))
1547 ;; We can reuse the previous list.
1548 (setq completions (nth 4 Info-complete-cache))
1549 ;; The cache can't be used.
1550 (while
1551 (progn
1552 (while (re-search-forward pattern nil t)
365d2503 1553 (push (match-string-no-properties 1)
e4e8ee63
SM
1554 completions))
1555 ;; Check subsequent nodes if applicable.
1556 (and Info-complete-next-re
1557 (setq nextnode (Info-extract-pointer "next" t))
1558 (string-match Info-complete-next-re nextnode)))
1559 (Info-goto-node nextnode))
1560 ;; Go back to the start node (for the next completion).
1561 (unless (equal Info-current-node orignode)
1562 (Info-goto-node orignode))
1563 ;; Update the cache.
271f4a9e
MB
1564 (set (make-local-variable 'Info-complete-cache)
1565 (list Info-current-file Info-current-node
1566 Info-complete-next-re string completions)))
e4e8ee63
SM
1567 (if action
1568 (all-completions string completions predicate)
1569 (try-completion string completions predicate)))))))
e8adde3f
RS
1570
1571
4fceda3c 1572(defun Info-menu (menu-item &optional fork)
dc414be1
EZ
1573 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
1574The menu item should one of those listed in the current node's menu.
1575Completion is allowed, and the default menu item is the one point is on.
7210b6f5
DL
1576If FORK is non-nil (interactively with a prefix arg), show the node in
1577a new info buffer. If FORK is a string, it is the name to use for the
1578new buffer."
a384cab3
JB
1579 (interactive
1580 (let ((completions '())
1581 ;; If point is within a menu item, use that item as the default
1582 (default nil)
1583 (p (point))
211d6309 1584 beg
760d5cb3
GM
1585 (last nil)
1586 (case-fold-search t))
a384cab3
JB
1587 (save-excursion
1588 (goto-char (point-min))
1589 (if (not (search-forward "\n* menu:" nil t))
1590 (error "No menu in this node"))
e8adde3f
RS
1591 (setq beg (point))
1592 (and (< (point) p)
1593 (save-excursion
1594 (goto-char p)
1595 (end-of-line)
505b68d5 1596 (if (re-search-backward "\n\\* +\\([^\t\n]*\\):" beg t)
110d4e80 1597 (setq default (match-string-no-properties 1))))))
a384cab3
JB
1598 (let ((item nil))
1599 (while (null item)
e8adde3f
RS
1600 (setq item (let ((completion-ignore-case t)
1601 (Info-complete-menu-buffer (current-buffer)))
a384cab3
JB
1602 (completing-read (if default
1603 (format "Menu item (default %s): "
1604 default)
760d5cb3 1605 "Menu item: ")
e8adde3f 1606 'Info-complete-menu-item nil t)))
aea2a8da
JB
1607 ;; we rely on the fact that completing-read accepts an input
1608 ;; of "" even when the require-match argument is true and ""
1609 ;; is not a valid possibility
a384cab3
JB
1610 (if (string= item "")
1611 (if default
1612 (setq item default)
760d5cb3
GM
1613 ;; ask again
1614 (setq item nil))))
4fceda3c 1615 (list item current-prefix-arg))))
a384cab3
JB
1616 ;; there is a problem here in that if several menu items have the same
1617 ;; name you can only go to the node of the first with this command.
4fceda3c 1618 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
399c88ad 1619
a384cab3
JB
1620(defun Info-extract-menu-item (menu-item)
1621 (setq menu-item (regexp-quote menu-item))
1bcedb3b
RS
1622 (let ((case-fold-search t))
1623 (save-excursion
760d5cb3
GM
1624 (let ((case-fold-search t))
1625 (goto-char (point-min))
1626 (or (search-forward "\n* menu:" nil t)
1627 (error "No menu in this node"))
1628 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1629 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1630 (error "No such item in menu"))
1631 (beginning-of-line)
1632 (forward-char 2)
1633 (Info-extract-menu-node-name)))))
a384cab3
JB
1634
1635;; If COUNT is nil, use the last item in the menu.
1636(defun Info-extract-menu-counting (count)
1bcedb3b
RS
1637 (let ((case-fold-search t))
1638 (save-excursion
760d5cb3
GM
1639 (let ((case-fold-search t))
1640 (goto-char (point-min))
1641 (or (search-forward "\n* menu:" nil t)
1642 (error "No menu in this node"))
1643 (if count
1644 (or (search-forward "\n* " nil t count)
1645 (error "Too few items in menu"))
1646 (while (search-forward "\n* " nil t)
1647 nil))
1648 (Info-extract-menu-node-name)))))
a384cab3 1649
e38e7367
RM
1650(defun Info-nth-menu-item ()
1651 "Go to the node of the Nth menu item.
1652N is the digit argument used to invoke this command."
a384cab3 1653 (interactive)
e38e7367
RM
1654 (Info-goto-node
1655 (Info-extract-menu-counting
1656 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
a384cab3
JB
1657
1658(defun Info-top-node ()
1659 "Go to the Top node of this file."
1660 (interactive)
1661 (Info-goto-node "Top"))
1662
1663(defun Info-final-node ()
1664 "Go to the final node in this file."
1665 (interactive)
1666 (Info-goto-node "Top")
760d5cb3
GM
1667 (let ((Info-history nil)
1668 (case-fold-search t))
a384cab3
JB
1669 ;; Go to the last node in the menu of Top.
1670 (Info-goto-node (Info-extract-menu-counting nil))
1671 ;; If the last node in the menu is not last in pointer structure,
399c88ad 1672 ;; move forward until we can't go any farther.
a384cab3
JB
1673 (while (Info-forward-node t t) nil)
1674 ;; Then keep moving down to last subnode, unless we reach an index.
1675 (while (and (not (string-match "\\<index\\>" Info-current-node))
1676 (save-excursion (search-forward "\n* Menu:" nil t)))
1677 (Info-goto-node (Info-extract-menu-counting nil)))))
1678
1679(defun Info-forward-node (&optional not-down no-error)
1680 "Go forward one node, considering all nodes as forming one sequence."
1681 (interactive)
1682 (goto-char (point-min))
1683 (forward-line 1)
760d5cb3
GM
1684 (let ((case-fold-search t))
1685 ;; three possibilities, in order of priority:
1686 ;; 1. next node is in a menu in this node (but not in an index)
1687 ;; 2. next node is next at same level
1688 ;; 3. next node is up and next
1689 (cond ((and (not not-down)
1690 (save-excursion (search-forward "\n* menu:" nil t))
1691 (not (string-match "\\<index\\>" Info-current-node)))
1692 (Info-goto-node (Info-extract-menu-counting 1))
1693 t)
6af7040d 1694 ((save-excursion (search-backward "next:" nil t))
760d5cb3
GM
1695 (Info-next)
1696 t)
6af7040d 1697 ((and (save-excursion (search-backward "up:" nil t))
760d5cb3
GM
1698 ;; Use string-equal, not equal, to ignore text props.
1699 (not (string-equal (downcase (Info-extract-pointer "up"))
1700 "top")))
1701 (let ((old-node Info-current-node))
1702 (Info-up)
1703 (let (Info-history success)
1704 (unwind-protect
1705 (setq success (Info-forward-node t no-error))
1706 (or success (Info-goto-node old-node))))))
1707 (no-error nil)
1708 (t (error "No pointer forward from this node")))))
a384cab3
JB
1709
1710(defun Info-backward-node ()
1711 "Go backward one node, considering all nodes as forming one sequence."
1712 (interactive)
1713 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
760d5cb3
GM
1714 (upnode (Info-extract-pointer "up" t))
1715 (case-fold-search t))
a384cab3
JB
1716 (cond ((and upnode (string-match "(" upnode))
1717 (error "First node in file"))
1718 ((and upnode (or (null prevnode)
e90d1271
RS
1719 ;; Use string-equal, not equal,
1720 ;; to ignore text properties.
1721 (string-equal (downcase prevnode)
1722 (downcase upnode))))
a384cab3
JB
1723 (Info-up))
1724 (prevnode
1725 ;; If we move back at the same level,
1726 ;; go down to find the last subnode*.
1727 (Info-prev)
1728 (let (Info-history)
1729 (while (and (not (string-match "\\<index\\>" Info-current-node))
1730 (save-excursion (search-forward "\n* Menu:" nil t)))
1731 (Info-goto-node (Info-extract-menu-counting nil)))))
1732 (t
1733 (error "No pointer backward from this node")))))
1734
1735(defun Info-exit ()
1736 "Exit Info by selecting some other buffer."
1737 (interactive)
552775bd
RS
1738 (if Info-standalone
1739 (save-buffers-kill-emacs)
4643e92f 1740 (quit-window)))
a384cab3 1741
253db917 1742(defun Info-next-menu-item ()
3a8803c0 1743 "Go to the node of the next menu item."
253db917 1744 (interactive)
fdf4b680 1745 ;; Bind this in case the user sets it to nil.
760d5cb3
GM
1746 (let* ((case-fold-search t)
1747 (node
1748 (save-excursion
1749 (forward-line -1)
1750 (search-forward "\n* menu:" nil t)
1751 (and (search-forward "\n* " nil t)
1752 (Info-extract-menu-node-name)))))
fadfb77f
RS
1753 (if node (Info-goto-node node)
1754 (error "No more items in menu"))))
253db917
ER
1755
1756(defun Info-last-menu-item ()
3a8803c0 1757 "Go to the node of the previous menu item."
253db917
ER
1758 (interactive)
1759 (save-excursion
1760 (forward-line 1)
fdf4b680 1761 ;; Bind this in case the user sets it to nil.
760d5cb3
GM
1762 (let* ((case-fold-search t)
1763 (beg (save-excursion
1764 (and (search-backward "\n* menu:" nil t)
1765 (point)))))
0a56332b
RS
1766 (or (and beg (search-backward "\n* " beg t))
1767 (error "No previous items in menu")))
1768 (Info-goto-node (save-excursion
1769 (goto-char (match-end 0))
1770 (Info-extract-menu-node-name)))))
253db917 1771
552775bd 1772(defmacro Info-no-error (&rest body)
253db917
ER
1773 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1774
1775(defun Info-next-preorder ()
3c9179ea
RS
1776 "Go to the next subnode or the next node, or go up a level."
1777 (interactive)
1778 (cond ((Info-no-error (Info-next-menu-item)))
1779 ((Info-no-error (Info-next)))
5dab2fb4 1780 ((Info-no-error (Info-up t))
ed690657
KH
1781 ;; Since we have already gone thru all the items in this menu,
1782 ;; go up to the end of this node.
b54d0f0e
RS
1783 (goto-char (point-max))
1784 ;; Since logically we are done with the node with that menu,
1785 ;; move on from it.
1786 (Info-next-preorder))
3c9179ea
RS
1787 (t
1788 (error "No more nodes"))))
253db917
ER
1789
1790(defun Info-last-preorder ()
1791 "Go to the last node, popping up a level if there is none."
1792 (interactive)
0a56332b
RS
1793 (cond ((Info-no-error
1794 (Info-last-menu-item)
1795 ;; If we go down a menu item, go to the end of the node
1796 ;; so we can scroll back through it.
ed690657 1797 (goto-char (point-max)))
b54d0f0e
RS
1798 ;; Keep going down, as long as there are nested menu nodes.
1799 (while (Info-no-error
1800 (Info-last-menu-item)
1801 ;; If we go down a menu item, go to the end of the node
1802 ;; so we can scroll back through it.
1803 (goto-char (point-max))))
ed690657 1804 (recenter -1))
c2def7a0
MB
1805 ((and (Info-no-error (Info-extract-pointer "prev"))
1806 (not (equal (Info-extract-pointer "up")
5dab2fb4
RS
1807 (Info-extract-pointer "prev"))))
1808 (Info-no-error (Info-prev))
ed690657 1809 (goto-char (point-max))
b54d0f0e
RS
1810 (while (Info-no-error
1811 (Info-last-menu-item)
1812 ;; If we go down a menu item, go to the end of the node
1813 ;; so we can scroll back through it.
1814 (goto-char (point-max))))
ed690657 1815 (recenter -1))
5dab2fb4 1816 ((Info-no-error (Info-up t))
ed690657 1817 (goto-char (point-min))
760d5cb3
GM
1818 (let ((case-fold-search t))
1819 (or (search-forward "\n* Menu:" nil t)
1820 (goto-char (point-max)))))
ed690657 1821 (t (error "No previous nodes"))))
253db917
ER
1822
1823(defun Info-scroll-up ()
3f32dc86 1824 "Scroll one screenful forward in Info, considering all nodes as one sequence.
280d11ed 1825Once you scroll far enough in a node that its menu appears on the screen
7a53d8c8
EZ
1826but after point, the next scroll moves into its first subnode, unless
1827`Info-scroll-prefer-subnodes' is nil.
280d11ed 1828
7a53d8c8
EZ
1829When you scroll past the end of a node, that goes to the next node if
1830`Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
1831if this node has no successor, it moves to the parent node's successor,
1832and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
1833the menu of a node, it moves to subnode indicated by the following menu
1834item. (That case won't normally result from this command, but can happen
1835in other ways.)"
280d11ed 1836
253db917 1837 (interactive)
0a56332b
RS
1838 (if (or (< (window-start) (point-min))
1839 (> (window-start) (point-max)))
1840 (set-window-start (selected-window) (point)))
760d5cb3
GM
1841 (let* ((case-fold-search t)
1842 (virtual-end (save-excursion
1843 (goto-char (point-min))
7a53d8c8
EZ
1844 (if (and Info-scroll-prefer-subnodes
1845 (search-forward "\n* Menu:" nil t))
760d5cb3
GM
1846 (point)
1847 (point-max)))))
0a56332b
RS
1848 (if (or (< virtual-end (window-start))
1849 (pos-visible-in-window-p virtual-end))
7a53d8c8
EZ
1850 (cond
1851 (Info-scroll-prefer-subnodes (Info-next-preorder))
1852 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
1853 (t (Info-next-preorder)))
0a56332b 1854 (scroll-up))))
253db917
ER
1855
1856(defun Info-scroll-down ()
3f32dc86 1857 "Scroll one screenful back in Info, considering all nodes as one sequence.
c2def7a0
MB
1858If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
1859is non-nil, this goes to its last subnode. When you scroll past the
1860beginning of a node, that goes to the previous node or back up to the
1861parent node."
253db917 1862 (interactive)
0a56332b
RS
1863 (if (or (< (window-start) (point-min))
1864 (> (window-start) (point-max)))
1865 (set-window-start (selected-window) (point)))
760d5cb3
GM
1866 (let* ((case-fold-search t)
1867 (current-point (point))
c2def7a0
MB
1868 (virtual-end
1869 (and Info-scroll-prefer-subnodes
1870 (save-excursion
1871 (beginning-of-line)
1872 (setq current-point (point))
1873 (goto-char (point-min))
1874 (search-forward "\n* Menu:"
1875 current-point
1876 t)))))
3a8803c0 1877 (if (or virtual-end
7afe24e3 1878 (pos-visible-in-window-p (point-min) nil t))
0a56332b
RS
1879 (Info-last-preorder)
1880 (scroll-down))))
253db917 1881
56cda6f5 1882(defun Info-next-reference (&optional recur)
552775bd
RS
1883 "Move cursor to the next cross-reference or menu item in the node."
1884 (interactive)
1885 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1bcedb3b
RS
1886 (old-pt (point))
1887 (case-fold-search t))
552775bd
RS
1888 (or (eobp) (forward-char 1))
1889 (or (re-search-forward pat nil t)
1890 (progn
1891 (goto-char (point-min))
1892 (or (re-search-forward pat nil t)
1893 (progn
1894 (goto-char old-pt)
1895 (error "No cross references in this node")))))
1896 (goto-char (match-beginning 0))
1897 (if (looking-at "\\* Menu:")
56cda6f5
RS
1898 (if recur
1899 (error "No cross references in this node")
1900 (Info-next-reference t)))))
552775bd 1901
56cda6f5 1902(defun Info-prev-reference (&optional recur)
552775bd
RS
1903 "Move cursor to the previous cross-reference or menu item in the node."
1904 (interactive)
1905 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1bcedb3b
RS
1906 (old-pt (point))
1907 (case-fold-search t))
552775bd
RS
1908 (or (re-search-backward pat nil t)
1909 (progn
1910 (goto-char (point-max))
1911 (or (re-search-backward pat nil t)
1912 (progn
1913 (goto-char old-pt)
1914 (error "No cross references in this node")))))
1915 (goto-char (match-beginning 0))
1916 (if (looking-at "\\* Menu:")
56cda6f5
RS
1917 (if recur
1918 (error "No cross references in this node")
1919 (Info-prev-reference t)))))
552775bd 1920
e4e8ee63
SM
1921(defun Info-goto-index ()
1922 (Info-goto-node "Top")
1923 (or (search-forward "\n* menu:" nil t)
1924 (error "No index"))
1925 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1926 (error "No index"))
1927 (goto-char (match-beginning 1))
e700ec12
SM
1928 ;; Protect Info-history so that the current node (Top) is not added to it.
1929 (let ((Info-history nil))
1930 (Info-goto-node (Info-extract-menu-node-name))))
e4e8ee63 1931
1143a6b0 1932(defun Info-index (topic)
fdf4b680 1933 "Look up a string TOPIC in the index for this file.
e4e8ee63 1934The index is defined as the first node in the top level menu whose
1143a6b0
ER
1935name contains the word \"Index\", plus any immediately following
1936nodes whose names also contain the word \"Index\".
1937If there are no exact matches to the specified topic, this chooses
1938the first match which is a case-insensitive substring of a topic.
1939Use the `,' command to see the other matches.
1940Give a blank topic name to go to the Index node itself."
e4e8ee63
SM
1941 (interactive
1942 (list
1943 (let ((Info-complete-menu-buffer (clone-buffer))
1944 (Info-complete-next-re "\\<Index\\>"))
aebd1760
RS
1945 (if (equal Info-current-file "dir")
1946 (error "The Info directory node has no index; use m to select a manual"))
e4e8ee63
SM
1947 (unwind-protect
1948 (with-current-buffer Info-complete-menu-buffer
1949 (Info-goto-index)
1950 (completing-read "Index topic: " 'Info-complete-menu-item))
1951 (kill-buffer Info-complete-menu-buffer)))))
aebd1760
RS
1952 (if (equal Info-current-file "dir")
1953 (error "The Info directory node has no index; use m to select a manual"))
1143a6b0
ER
1954 (let ((orignode Info-current-node)
1955 (rnode nil)
35ab7deb 1956 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1143a6b0 1957 (regexp-quote topic)))
1bcedb3b
RS
1958 node
1959 (case-fold-search t))
e700ec12 1960 (Info-goto-index)
1143a6b0
ER
1961 (or (equal topic "")
1962 (let ((matches nil)
1963 (exact nil)
e700ec12
SM
1964 ;; We bind Info-history to nil for internal node-switches so
1965 ;; that we don't put junk in the history. In the first
1966 ;; Info-goto-index call, above, we do update the history
1967 ;; because that is what the user's previous node choice into it.
c696ac76 1968 (Info-history nil)
1143a6b0
ER
1969 found)
1970 (while
1971 (progn
1972 (goto-char (point-min))
1973 (while (re-search-forward pattern nil t)
983dfbf8
SM
1974 (push (list (match-string-no-properties 1)
1975 (match-string-no-properties 2)
1976 Info-current-node
3a8803c0
JPW
1977 (string-to-number (concat "0"
1978 (match-string 3))))
983dfbf8 1979 matches))
1143a6b0
ER
1980 (and (setq node (Info-extract-pointer "next" t))
1981 (string-match "\\<Index\\>" node)))
1982 (Info-goto-node node))
1983 (or matches
1984 (progn
81e14cb2 1985 (Info-goto-node orignode)
920bdaab 1986 (error "No `%s' in index" topic)))
1143a6b0
ER
1987 ;; Here it is a feature that assoc is case-sensitive.
1988 (while (setq found (assoc topic matches))
1989 (setq exact (cons found exact)
1990 matches (delq found matches)))
1991 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1992 (Info-index-next 0)))))
1993
1994(defun Info-index-next (num)
1995 "Go to the next matching index item from the last `i' command."
1996 (interactive "p")
1997 (or Info-index-alternatives
882e61bf 1998 (error "No previous `i' command"))
1143a6b0
ER
1999 (while (< num 0)
2000 (setq num (+ num (length Info-index-alternatives))))
2001 (while (> num 0)
2002 (setq Info-index-alternatives
2003 (nconc (cdr Info-index-alternatives)
2004 (list (car Info-index-alternatives)))
2005 num (1- num)))
2006 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2007 (if (> (nth 3 (car Info-index-alternatives)) 0)
2008 (forward-line (nth 3 (car Info-index-alternatives)))
760d5cb3 2009 (forward-line 3) ; don't search in headers
1143a6b0 2010 (let ((name (car (car Info-index-alternatives))))
920bdaab
RS
2011 (Info-find-index-name name)))
2012 (message "Found `%s' in %s. %s"
1143a6b0
ER
2013 (car (car Info-index-alternatives))
2014 (nth 2 (car Info-index-alternatives))
2015 (if (cdr Info-index-alternatives)
c702ed73 2016 "(`,' tries to find next)"
1143a6b0
ER
2017 "(Only match)")))
2018
920bdaab
RS
2019(defun Info-find-index-name (name)
2020 "Move point to the place within the current node where NAME is defined."
1bcedb3b
RS
2021 (let ((case-fold-search t))
2022 (if (or (re-search-forward (format
2023 "[a-zA-Z]+: %s\\( \\|$\\)"
2024 (regexp-quote name)) nil t)
d31c6ecf
RS
2025 ;; Find a function definition with a return type.
2026 (re-search-forward (format
f2fc5b0a 2027 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
d31c6ecf 2028 (regexp-quote name)) nil t)
1bcedb3b
RS
2029 (search-forward (format "`%s'" name) nil t)
2030 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2031 (search-forward
2032 (format "`%s'" (substring name 0 (match-beginning 1)))
2033 nil t))
2034 (search-forward name nil t))
2035 (beginning-of-line)
2036 (goto-char (point-min)))))
920bdaab 2037
a384cab3
JB
2038(defun Info-undefined ()
2039 "Make command be undefined in Info."
2040 (interactive)
2041 (ding))
2042
2043(defun Info-help ()
2044 "Enter the Info tutorial."
2045 (interactive)
2046 (delete-other-windows)
2047 (Info-find-node "info"
2048 (if (< (window-height) 23)
2049 "Help-Small-Screen"
2050 "Help")))
2051
2052(defun Info-summary ()
2053 "Display a brief summary of all Info commands."
2054 (interactive)
2055 (save-window-excursion
2056 (switch-to-buffer "*Help*")
881c84c7 2057 (setq buffer-read-only nil)
a384cab3
JB
2058 (erase-buffer)
2059 (insert (documentation 'Info-mode))
9d29f94c 2060 (help-mode)
a384cab3
JB
2061 (goto-char (point-min))
2062 (let (ch flag)
2063 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2064 (message (if flag "Type Space to see more"
2065 "Type Space to return to Info"))
1614c867 2066 (if (not (eq ?\ (setq ch (read-event))))
dbc4e1c1 2067 (progn (setq unread-command-events (list ch)) nil)
a384cab3 2068 flag))
552775bd
RS
2069 (scroll-up)))
2070 (bury-buffer "*Help*")))
a384cab3
JB
2071\f
2072(defun Info-get-token (pos start all &optional errorstring)
fdf4b680 2073 "Return the token around POS.
a384cab3
JB
2074POS must be somewhere inside the token
2075START is a regular expression which will match the
2076 beginning of the tokens delimited string
2077ALL is a regular expression with a single
90a715f0 2078 parenthesized subpattern which is the token to be
fdf4b680 2079 returned. E.g. '{\(.*\)}' would return any string
a384cab3 2080 enclosed in braces around POS.
fdf4b680 2081ERRORSTRING optional fourth argument, controls action on no match
a384cab3
JB
2082 nil: return nil
2083 t: beep
2084 a string: signal an error, using that string."
1bcedb3b
RS
2085 (let ((case-fold-search t))
2086 (save-excursion
2087 (goto-char pos)
2088 ;; First look for a match for START that goes across POS.
2089 (while (and (not (bobp)) (> (point) (- pos (length start)))
2090 (not (looking-at start)))
2091 (forward-char -1))
2092 ;; If we did not find one, search back for START
2093 ;; (this finds only matches that end at or before POS).
2094 (or (looking-at start)
2095 (progn
2096 (goto-char pos)
2097 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
2098 (let (found)
2099 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2100 (not (setq found (and (<= (match-beginning 0) pos)
2101 (> (match-end 0) pos))))))
2102 (if (and found (<= (match-beginning 0) pos)
2103 (> (match-end 0) pos))
110d4e80 2104 (match-string-no-properties 1)
1bcedb3b
RS
2105 (cond ((null errorstring)
2106 nil)
2107 ((eq errorstring t)
2108 (beep)
2109 nil)
2110 (t
2111 (error "No %s around position %d" errorstring pos))))))))
a384cab3 2112
981947af 2113(defun Info-mouse-follow-nearest-node (click)
f9969361
RS
2114 "\\<Info-mode-map>Follow a node reference near point.
2115Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
981947af 2116At end of the node's text, moves to the next node, or up if none."
f9969361 2117 (interactive "e")
d1268e52 2118 (mouse-set-point click)
981947af
KH
2119 (and (not (Info-try-follow-nearest-node))
2120 (save-excursion (forward-line 1) (eobp))
ed690657 2121 (Info-next-preorder)))
981947af
KH
2122
2123(defun Info-follow-nearest-node ()
d0b560c6
JB
2124 "Follow a node reference near point.
2125If point is on a reference, follow that reference. Otherwise,
2126if point is in a menu item description, follow that menu item."
981947af
KH
2127 (interactive)
2128 (or (Info-try-follow-nearest-node)
d0b560c6
JB
2129 (when (save-excursion
2130 (search-backward "\n* menu:" nil t))
2131 (save-excursion
2132 (beginning-of-line)
2133 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2134 (beginning-of-line 0))
2135 (when (looking-at "\\* +\\([^\t\n]*\\):")
2136 (Info-goto-node
2137 (Info-extract-menu-item (match-string-no-properties 1)))
2138 t)))
2139 (error "Point neither on reference nor in menu item description")))
981947af
KH
2140
2141;; Common subroutine.
2142(defun Info-try-follow-nearest-node ()
2143 "Follow a node reference near point. Return non-nil if successful."
6af7040d 2144 (let (node)
a384cab3 2145 (cond
981947af
KH
2146 ((setq node (Info-get-token (point) "\\*note[ \n]"
2147 "\\*note[ \n]\\([^:]*\\):"))
a384cab3 2148 (Info-follow-reference node))
505b68d5 2149 ;; menu item: node name
b37daea4 2150 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
a384cab3 2151 (Info-goto-node node))
505b68d5
TTN
2152 ;; menu item: index entry
2153 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
631ba13e
RS
2154 (beginning-of-line)
2155 (forward-char 2)
2156 (setq node (Info-extract-menu-node-name))
2157 (Info-goto-node node))
bc2ada62 2158 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
a384cab3 2159 (Info-goto-node node))
bc2ada62 2160 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
a384cab3 2161 (Info-goto-node node))
bc2ada62 2162 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
a384cab3 2163 (Info-goto-node "Top"))
bc2ada62 2164 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
981947af
KH
2165 (Info-goto-node node)))
2166 node))
a384cab3
JB
2167\f
2168(defvar Info-mode-map nil
2169 "Keymap containing Info commands.")
2170(if Info-mode-map
2171 nil
2172 (setq Info-mode-map (make-keymap))
2173 (suppress-keymap Info-mode-map)
2174 (define-key Info-mode-map "." 'beginning-of-buffer)
253db917 2175 (define-key Info-mode-map " " 'Info-scroll-up)
981947af 2176 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
552775bd
RS
2177 (define-key Info-mode-map "\t" 'Info-next-reference)
2178 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
e38e7367
RM
2179 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2180 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2181 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2182 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2183 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2184 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2185 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2186 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2187 (define-key Info-mode-map "9" 'Info-nth-menu-item)
82a4c008 2188 (define-key Info-mode-map "0" 'undefined)
a384cab3
JB
2189 (define-key Info-mode-map "?" 'Info-summary)
2190 (define-key Info-mode-map "]" 'Info-forward-node)
2191 (define-key Info-mode-map "[" 'Info-backward-node)
2192 (define-key Info-mode-map "<" 'Info-top-node)
2193 (define-key Info-mode-map ">" 'Info-final-node)
2194 (define-key Info-mode-map "b" 'beginning-of-buffer)
2ad63128 2195 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
a384cab3
JB
2196 (define-key Info-mode-map "d" 'Info-directory)
2197 (define-key Info-mode-map "e" 'Info-edit)
2198 (define-key Info-mode-map "f" 'Info-follow-reference)
2199 (define-key Info-mode-map "g" 'Info-goto-node)
2200 (define-key Info-mode-map "h" 'Info-help)
1143a6b0 2201 (define-key Info-mode-map "i" 'Info-index)
a384cab3
JB
2202 (define-key Info-mode-map "l" 'Info-last)
2203 (define-key Info-mode-map "m" 'Info-menu)
2204 (define-key Info-mode-map "n" 'Info-next)
2205 (define-key Info-mode-map "p" 'Info-prev)
2206 (define-key Info-mode-map "q" 'Info-exit)
2207 (define-key Info-mode-map "s" 'Info-search)
47fc33ca
RS
2208 ;; For consistency with Rmail.
2209 (define-key Info-mode-map "\M-s" 'Info-search)
4fceda3c 2210 (define-key Info-mode-map "\M-n" 'clone-buffer)
db0c9809 2211 (define-key Info-mode-map "t" 'Info-top-node)
a384cab3 2212 (define-key Info-mode-map "u" 'Info-up)
1143a6b0 2213 (define-key Info-mode-map "," 'Info-index-next)
803eaf50 2214 (define-key Info-mode-map "\177" 'Info-scroll-down)
981947af 2215 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
aea2a8da 2216 )
75a209d4
RS
2217
2218(defun Info-check-pointer (item)
fdf4b680 2219 "Non-nil if ITEM is present in this node."
75a209d4
RS
2220 (condition-case nil
2221 (Info-extract-pointer item)
2222 (error nil)))
2223
d4af987a
DL
2224(easy-menu-define
2225 Info-mode-menu Info-mode-map
2226 "Menu for info files."
2227 '("Info"
2228 ["Up" Info-up :active (Info-check-pointer "up")
2229 :help "Go up in the Info tree"]
2230 ["Next" Info-next :active (Info-check-pointer "next")
2231 :help "Go to the next node"]
2232 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
2233 :help "Go to the previous node"]
2234 ["Backward" Info-backward-node
2235 :help "Go backward one node, considering all as a sequence"]
2236 ["Forward" Info-forward-node
2237 :help "Go forward one node, considering all as a sequence"]
7210b6f5
DL
2238 ["Beginning" beginning-of-buffer
2239 :help "Go to beginning of this node"]
d4af987a
DL
2240 ["Top" Info-top-node
2241 :help "Go to top node of file"]
2242 ["Final Node" Info-final-node
2243 :help "Go to final node in this file"]
2244 ("Menu Item" ["You should never see this" report-emacs-bug t])
2245 ("Reference" ["You should never see this" report-emacs-bug t])
2246 ["Search..." Info-search
2247 :help "Search for regular expression in this Info file"]
d1268e52 2248 ["Go to Node..." Info-goto-node
d4af987a 2249 :help "Go to a named node"]
ec03f31e 2250 ["Last" Info-last :active Info-history
d4af987a
DL
2251 :help "Go to the last node you were at"]
2252 ("Index..."
2253 ["Lookup a String" Info-index
2254 :help "Look for a string in the index items"]
2255 ["Next Matching Item" Info-index-next
2256 :help "Look for another occurrence of previous item"])
7210b6f5
DL
2257 ["Edit" Info-edit :help "Edit contents of this node"
2258 :active Info-enable-edit]
126f5d4d
MB
2259 ["Copy Node Name" Info-copy-current-node-name
2260 :help "Copy the name of the current node into the kill ring"]
ec03f31e 2261 ["Exit" Info-exit :help "Stop reading Info"]))
75a209d4 2262
7210b6f5
DL
2263
2264(defvar info-tool-bar-map
2265 (if (display-graphic-p)
df6aed99
RS
2266 (let ((map (make-sparse-keymap)))
2267 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
2268 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
2269 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
2270 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
2271 (tool-bar-local-item-from-menu 'Info-last "undo" map Info-mode-map)
2272 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
2273 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
2274 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
2275 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
2276 map)))
7210b6f5 2277
75a209d4
RS
2278(defvar Info-menu-last-node nil)
2279;; Last node the menu was created for.
6d2c8e3e 2280;; Value is a list, (FILE-NAME NODE-NAME).
75a209d4
RS
2281
2282(defun Info-menu-update ()
fdf4b680 2283 "Update the Info menu for the current node."
75a209d4
RS
2284 (condition-case nil
2285 (if (or (not (eq major-mode 'Info-mode))
6d2c8e3e
RS
2286 (equal (list Info-current-file Info-current-node)
2287 Info-menu-last-node))
75a209d4
RS
2288 ()
2289 ;; Update menu menu.
2290 (let* ((Info-complete-menu-buffer (current-buffer))
2291 (items (nreverse (condition-case nil
e4e8ee63 2292 (Info-complete-menu-item "" nil t)
75a209d4 2293 (error nil))))
399c88ad 2294 entries current
75a209d4
RS
2295 (number 0))
2296 (while (and items (< number 9))
2297 (setq current (car items)
2298 items (cdr items)
2299 number (1+ number))
399c88ad 2300 (setq entries (cons `[,current
75a209d4
RS
2301 (Info-menu ,current)
2302 :keys ,(format "%d" number)]
2303 entries)))
2304 (if items
2305 (setq entries (cons ["Other..." Info-menu t] entries)))
2306 (or entries
5d5845dc 2307 (setq entries (list ["No menu" nil nil] nil :active)))
d4af987a 2308 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
75a209d4
RS
2309 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2310 (let ((items nil)
399c88ad 2311 str i entries current
1bcedb3b
RS
2312 (number 0)
2313 (case-fold-search t))
75a209d4
RS
2314 (save-excursion
2315 (goto-char (point-min))
2316 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
2317 (setq str (buffer-substring
2318 (match-beginning 1)
2319 (1- (point))))
2320 (setq i 0)
2321 (while (setq i (string-match "[ \n\t]+" str i))
2322 (setq str (concat (substring str 0 i) " "
2323 (substring str (match-end 0))))
2324 (setq i (1+ i)))
2325 (setq items
2326 (cons str items))))
2327 (while (and items (< number 9))
2328 (setq current (car items)
2329 items (cdr items)
2330 number (1+ number))
399c88ad 2331 (setq entries (cons `[,current
75a209d4
RS
2332 (Info-follow-reference ,current)
2333 t]
2334 entries)))
2335 (if items
2336 (setq entries (cons ["Other..." Info-follow-reference t]
2337 entries)))
2338 (or entries
5d5845dc 2339 (setq entries (list ["No references" nil nil] nil :active)))
75a209d4
RS
2340 (easy-menu-change '("Info") "Reference" (nreverse entries)))
2341 ;; Update last seen node.
6d2c8e3e 2342 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
75a209d4
RS
2343 ;; Try to avoid entering infinite beep mode in case of errors.
2344 (error (ding))))
2345
a384cab3 2346\f
126f5d4d
MB
2347(defun Info-copy-current-node-name ()
2348 "Put the name of the current info node into the kill ring.
2349The name of the info file is prepended to the node name in parentheses."
2350 (interactive)
2351 (unless Info-current-node
2352 (error "No current info node"))
2353 (kill-new
2354 (concat "("
2355 (file-name-nondirectory
2356 (if (stringp Info-current-file)
2357 Info-current-file
2358 (or buffer-file-name "")))
2359 ")"
2360 Info-current-node)))
2361
2362\f
a384cab3 2363;; Info mode is suitable only for specially formatted data.
68bc119c 2364(put 'Info-mode 'mode-class 'special)
2fa8f8a4 2365(put 'Info-mode 'no-clone-indirect t)
a384cab3
JB
2366
2367(defun Info-mode ()
fdf4b680 2368 "Info mode provides commands for browsing through the Info documentation tree.
a384cab3
JB
2369Documentation in Info is divided into \"nodes\", each of which discusses
2370one topic and contains references to other nodes which discuss related
2371topics. Info has commands to follow the references and show you other nodes.
2372
fdf4b680 2373\\<Info-mode-map>\
a384cab3 2374\\[Info-help] Invoke the Info tutorial.
6b136ab9 2375\\[Info-exit] Quit Info: reselect previously selected buffer.
a384cab3
JB
2376
2377Selecting other nodes:
21d5959f
RS
2378\\[Info-mouse-follow-nearest-node]
2379 Follow a node reference you click on.
2380 This works with menu items, cross references, and
2381 the \"next\", \"previous\" and \"up\", depending on where you click.
6b136ab9 2382\\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
a384cab3 2383\\[Info-next] Move to the \"next\" node of this node.
bc2ada62 2384\\[Info-prev] Move to the \"previous\" node of this node.
a384cab3
JB
2385\\[Info-up] Move \"up\" from this node.
2386\\[Info-menu] Pick menu item specified by name (or abbreviation).
e8042313 2387 Picking a menu item causes another node to be selected.
aea2a8da 2388\\[Info-directory] Go to the Info directory node.
a384cab3
JB
2389\\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2390\\[Info-last] Move to the last node you were at.
1143a6b0
ER
2391\\[Info-index] Look up a topic in this file's Index and move to that node.
2392\\[Info-index-next] (comma) Move to the next match from a previous `i' command.
6b136ab9
DL
2393\\[Info-top-node] Go to the Top node of this file.
2394\\[Info-final-node] Go to the final node in this file.
2395\\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2396\\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
a384cab3
JB
2397
2398Moving within a node:
177c3549 2399\\[Info-scroll-up] Normally, scroll forward a full screen.
e8042313
PJ
2400 Once you scroll far enough in a node that its menu appears on the
2401 screen but after point, the next scroll moves into its first
2402 subnode. When after all menu items (or if there is no menu),
2403 move up to the parent node.
177c3549 2404\\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
e8042313
PJ
2405 already visible, try to go to the previous menu entry, or up
2406 if there is none.
399c88ad 2407\\[beginning-of-buffer] Go to beginning of node.
a384cab3 2408
a384cab3
JB
2409Advanced commands:
2410\\[Info-exit] Quit Info: reselect previously selected buffer.
2411\\[Info-edit] Edit contents of selected node.
24121 Pick first item in node's menu.
24132, 3, 4, 5 Pick second ... fifth item in node's menu.
2414\\[Info-goto-node] Move to node specified by name.
e8042313 2415 You may include a filename as well, as (FILENAME)NODENAME.
552775bd 2416\\[universal-argument] \\[info] Move to new Info file with completion.
a384cab3 2417\\[Info-search] Search through this Info file for specified regexp,
e8042313 2418 and select the node in which the next occurrence is found.
552775bd
RS
2419\\[Info-next-reference] Move cursor to next cross-reference or menu item.
2420\\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
a384cab3
JB
2421 (kill-all-local-variables)
2422 (setq major-mode 'Info-mode)
2423 (setq mode-name "Info")
f73299f3 2424 (setq tab-width 8)
a384cab3 2425 (use-local-map Info-mode-map)
75a209d4 2426 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
a384cab3
JB
2427 (set-syntax-table text-mode-syntax-table)
2428 (setq local-abbrev-table text-mode-abbrev-table)
2429 (setq case-fold-search t)
2430 (setq buffer-read-only t)
a384cab3
JB
2431 (make-local-variable 'Info-current-file)
2432 (make-local-variable 'Info-current-subfile)
2433 (make-local-variable 'Info-current-node)
2434 (make-local-variable 'Info-tag-table-marker)
c5fe2ff1
RS
2435 (setq Info-tag-table-marker (make-marker))
2436 (make-local-variable 'Info-tag-table-buffer)
2437 (setq Info-tag-table-buffer nil)
a384cab3 2438 (make-local-variable 'Info-history)
1143a6b0 2439 (make-local-variable 'Info-index-alternatives)
246a06d3 2440 (make-local-variable 'Info-header-line)
6af7040d 2441 (setq header-line-format (if Info-use-header-line 'Info-header-line))
7210b6f5 2442 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
93480d70
RS
2443 ;; This is for the sake of the invisible text we use handling titles.
2444 (make-local-variable 'line-move-ignore-invisible)
2445 (setq line-move-ignore-invisible t)
b7aeabeb 2446 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
3d12b331 2447 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
a384cab3
JB
2448 (Info-set-mode-line)
2449 (run-hooks 'Info-mode-hook))
2450
4fceda3c
SM
2451(defun Info-clone-buffer-hook ()
2452 (when (bufferp Info-tag-table-buffer)
2453 (setq Info-tag-table-buffer
4ce5c223
SM
2454 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
2455 (let ((m Info-tag-table-marker))
2456 (when (markerp m)
15533ae2 2457 (setq Info-tag-table-marker
4ce5c223 2458 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
15533ae2
SM
2459 (with-current-buffer Info-tag-table-buffer
2460 (copy-marker (marker-position m)))
2461 (make-marker))))))
4fceda3c 2462
7210b6f5
DL
2463(defvar Info-edit-map (let ((map (make-sparse-keymap)))
2464 (set-keymap-parent map text-mode-map)
2465 (define-key map "\C-c\C-c" 'Info-cease-edit)
2466 map)
a384cab3 2467 "Local keymap used within `e' command of Info.")
a384cab3
JB
2468
2469;; Info-edit mode is suitable only for specially formatted data.
68bc119c 2470(put 'Info-edit-mode 'mode-class 'special)
a384cab3
JB
2471
2472(defun Info-edit-mode ()
2473 "Major mode for editing the contents of an Info node.
a426b157 2474Like text mode with the addition of `Info-cease-edit'
a384cab3
JB
2475which returns to Info mode for browsing.
2476\\{Info-edit-map}"
a384cab3
JB
2477 (use-local-map Info-edit-map)
2478 (setq major-mode 'Info-edit-mode)
2479 (setq mode-name "Info Edit")
2480 (kill-local-variable 'mode-line-buffer-identification)
2481 (setq buffer-read-only nil)
2c609f53 2482 (force-mode-line-update)
e82c28f9
KH
2483 (buffer-enable-undo (current-buffer))
2484 (run-hooks 'Info-edit-mode-hook))
2485
2486(defun Info-edit ()
2487 "Edit the contents of this Info node.
2488Allowed only if variable `Info-enable-edit' is non-nil."
2489 (interactive)
2490 (or Info-enable-edit
2491 (error "Editing info nodes is not enabled"))
2492 (Info-edit-mode)
8ab3e50b 2493 (message "%s" (substitute-command-keys
760d5cb3 2494 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
a384cab3
JB
2495
2496(defun Info-cease-edit ()
2497 "Finish editing Info node; switch back to Info proper."
2498 (interactive)
2499 ;; Do this first, so nothing has changed if user C-g's at query.
2500 (and (buffer-modified-p)
2501 (y-or-n-p "Save the file? ")
2502 (save-buffer))
2503 (use-local-map Info-mode-map)
2504 (setq major-mode 'Info-mode)
2505 (setq mode-name "Info")
2506 (Info-set-mode-line)
2507 (setq buffer-read-only t)
2c609f53 2508 (force-mode-line-update)
a384cab3
JB
2509 (and (marker-position Info-tag-table-marker)
2510 (buffer-modified-p)
2511 (message "Tags may have changed. Use Info-tagify if necessary")))
f0a8a3f1 2512\f
f88ab1c9 2513(defvar Info-file-list-for-emacs
906b3163
EZ
2514 '("ediff" "eudc" "forms" "gnus" "info" ("mh" . "mh-e")
2515 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
2516 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
2517 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
af718538
EZ
2518 ("skeleton" . "autotype") ("auto-insert" . "autotype")
2519 ("copyright" . "autotype") ("executable" . "autotype")
2520 ("time-stamp" . "autotype") ("quickurl" . "autotype")
2521 ("tempo" . "autotype") ("hippie-expand" . "autotype")
807378ad
EZ
2522 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
2523 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
906b3163
EZ
2524 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
2525 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
2526 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
2527 ("rfc2045" . "emacs-mime")
2528 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
2529 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
2530 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
2531 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
2532 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
2533 ("mml" . "emacs-mime"))
f88ab1c9
RS
2534 "List of Info files that describe Emacs commands.
2535An element can be a file name, or a list of the form (PREFIX . FILE)
2536where PREFIX is a name prefix and FILE is the file to look in.
2537If the element is just a file name, the file name also serves as the prefix.")
2538
f0a8a3f1 2539(defun Info-find-emacs-command-nodes (command)
f88ab1c9 2540 "Return a list of locations documenting COMMAND.
f57b2cd8
RS
2541The `info-file' property of COMMAND says which Info manual to search.
2542If COMMAND has no property, the variable `Info-file-list-for-emacs'
2543defines heuristics for which Info manual to try.
fdf4b680 2544The locations are of the format used in `Info-history', i.e.
f0a8a3f1 2545\(FILENAME NODENAME BUFFERPOS\)."
f0a8a3f1 2546 (let ((where '())
b37daea4 2547 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
218c2cc7 2548 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
f88ab1c9
RS
2549 (info-file "emacs")) ;default
2550 ;; Determine which info file this command is documented in.
2551 (if (get command 'info-file)
2552 (setq info-file (get command 'info-file))
2553 ;; If it doesn't say explicitly, test its name against
2554 ;; various prefixes that we know.
2555 (let ((file-list Info-file-list-for-emacs))
2556 (while file-list
2557 (let* ((elt (car file-list))
2558 (name (if (consp elt)
2559 (car elt)
2560 elt))
2561 (file (if (consp elt) (cdr elt) elt))
f57b2cd8 2562 (regexp (concat "\\`" (regexp-quote name)
f88ab1c9
RS
2563 "\\(\\'\\|-\\)")))
2564 (if (string-match regexp (symbol-name command))
2565 (setq info-file file file-list nil))
2566 (setq file-list (cdr file-list))))))
218c2cc7
EZ
2567 (Info-find-node info-file "Top")
2568 (or (and (search-forward "\n* menu:" nil t)
2569 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2570 (error "Info file `%s' appears to lack an index" info-file))
2571 (goto-char (match-beginning 1))
2572 ;; Bind Info-history to nil, to prevent the index nodes from
2573 ;; getting into the node history.
2574 (let ((Info-history nil)
2575 (exact nil)
2576 node found)
2577 (Info-goto-node (Info-extract-menu-node-name))
2578 (while
2579 (progn
2580 (goto-char (point-min))
2581 (while (re-search-forward cmd-desc nil t)
2582 (setq where
2583 (cons (list Info-current-file
2584 (match-string-no-properties 2)
760d5cb3
GM
2585 0)
2586 where)))
218c2cc7
EZ
2587 (and (setq node (Info-extract-pointer "next" t))
2588 (string-match "\\<Index\\>" node)))
2589 (Info-goto-node node)))
2590 where))
f0a8a3f1
RM
2591
2592;;;###autoload
2593(defun Info-goto-emacs-command-node (command)
e0568e86 2594 "Go to the Info node in the Emacs manual for command COMMAND.
30db89f9 2595The command is found by looking up in Emacs manual's indices
f57b2cd8 2596or in another manual found via COMMAND's `info-file' property or
fafb00dc
MY
2597the variable `Info-file-list-for-emacs'. COMMAND must be a symbol
2598or string."
f0a8a3f1 2599 (interactive "CFind documentation for command: ")
fafb00dc
MY
2600 ;; If command is given as a string, convert it to a symbol.
2601 (if (stringp command)
2602 (setq command (intern command)))
f0a8a3f1
RM
2603 (or (commandp command)
2604 (signal 'wrong-type-argument (list 'commandp command)))
2605 (let ((where (Info-find-emacs-command-nodes command)))
2606 (if where
2607 (let ((num-matches (length where)))
2608 ;; Get Info running, and pop to it in another window.
2609 (save-window-excursion
2610 (info))
c5fe2ff1
RS
2611 ;; FIXME It would be cool if this could use a buffer other
2612 ;; than *info*.
f0a8a3f1 2613 (pop-to-buffer "*info*")
218c2cc7
EZ
2614 ;; Bind Info-history to nil, to prevent the last Index node
2615 ;; visited by Info-find-emacs-command-nodes from being
2616 ;; pushed onto the history.
2617 (let ((Info-history nil))
2618 (Info-find-node (car (car where))
2619 (car (cdr (car where)))))
f0a8a3f1
RM
2620 (if (> num-matches 1)
2621 (progn
218c2cc7
EZ
2622 ;; (car where) will be pushed onto Info-history
2623 ;; when/if they go to another node. Put the other
2624 ;; nodes that were found on the history.
f0a8a3f1 2625 (setq Info-history (nconc (cdr where) Info-history))
8ab3e50b 2626 (message "Found %d other entr%s. Use %s to see %s."
cedb118c
RS
2627 (1- num-matches)
2628 (if (> num-matches 2) "ies" "y")
8ab3e50b 2629 (substitute-command-keys "\\[Info-last]")
cedb118c 2630 (if (> num-matches 2) "them" "it")))))
e9b81433 2631 (error "Couldn't find documentation for %s" command))))
f0a8a3f1
RM
2632
2633;;;###autoload
2634(defun Info-goto-emacs-key-command-node (key)
30db89f9
EZ
2635 "Go to the node in the Emacs manual which describes the command bound to KEY.
2636KEY is a string.
fdf4b680 2637Interactively, if the binding is `execute-extended-command', a command is read.
30db89f9 2638The command is found by looking up in Emacs manual's indices
f57b2cd8
RS
2639or in another manual found via COMMAND's `info-file' property or
2640the variable `Info-file-list-for-emacs'."
ea33749b 2641 (interactive "kFind documentation for key: ")
f0a8a3f1
RM
2642 (let ((command (key-binding key)))
2643 (cond ((null command)
9e5c2f50 2644 (message "%s is undefined" (key-description key)))
f0a8a3f1
RM
2645 ((and (interactive-p)
2646 (eq command 'execute-extended-command))
2647 (Info-goto-emacs-command-node
2648 (read-command "Find documentation for command: ")))
2649 (t
2650 (Info-goto-emacs-command-node command)))))
552775bd 2651\f
bbed5c3f 2652(defface Info-title-1-face
b250866f 2653 '((((type tty pc) (class color)) (:foreground "yellow" :weight bold))
333cd59e 2654 (t (:height 1.2 :inherit Info-title-2-face)))
bbed5c3f
GM
2655 "Face for Info titles at level 1."
2656 :group 'info)
2657
2658(defface Info-title-2-face
b250866f 2659 '((((type tty pc) (class color)) (:foreground "lightblue" :weight bold))
333cd59e 2660 (t (:height 1.2 :inherit Info-title-3-face)))
bbed5c3f
GM
2661 "Face for Info titles at level 2."
2662 :group 'info)
2663
2664(defface Info-title-3-face
b250866f 2665 '((((type tty pc) (class color)) (:weight bold))
a8b883c2 2666 (t (:height 1.2 :inherit Info-title-4-face)))
bbed5c3f
GM
2667 "Face for Info titles at level 3."
2668 :group 'info)
2669
a8b883c2
MB
2670(defface Info-title-4-face
2671 '((((type tty pc) (class color)) (:weight bold))
2672 (t (:weight bold :inherit variable-pitch)))
2673 "Face for Info titles at level 4."
2674 :group 'info)
2675
973a3104
MB
2676(defface info-menu-header
2677 '((((type tty pc))
42121c23
SZ
2678 :underline t
2679 :weight bold)
973a3104 2680 (t
42121c23
SZ
2681 :inherit variable-pitch
2682 :weight bold))
973a3104
MB
2683 "Face for headers in Info menus."
2684 :group 'info)
2685
2686(defun Info-fontify-menu-headers ()
2687 "Add the face `info-menu-header' to any header before a menu entry."
2688 (save-excursion
2689 (goto-char (point-min))
2690 (when (re-search-forward "\\* Menu:" nil t)
2691 (put-text-property (match-beginning 0) (match-end 0)
2a3f98a1 2692 'font-lock-face 'info-menu-header)
973a3104
MB
2693 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
2694 (put-text-property (match-beginning 1) (match-end 1)
2a3f98a1 2695 'font-lock-face 'info-menu-header)))))
973a3104 2696
efb21aab
RS
2697(defvar Info-next-link-keymap
2698 (let ((keymap (make-sparse-keymap)))
2699 (define-key keymap [header-line mouse-1] 'Info-next)
2700 (define-key keymap [header-line mouse-2] 'Info-next)
2701 (define-key keymap [header-line down-mouse-1] 'ignore)
2702 (define-key keymap [mouse-2] 'Info-next)
2703 keymap)
2704 "Keymap to put on the Next link in the text or the header line.")
2705
2706(defvar Info-prev-link-keymap
2707 (let ((keymap (make-sparse-keymap)))
2708 (define-key keymap [header-line mouse-1] 'Info-prev)
2709 (define-key keymap [header-line mouse-2] 'Info-prev)
2710 (define-key keymap [header-line down-mouse-1] 'ignore)
2711 (define-key keymap [mouse-2] 'Info-prev)
2712 keymap)
2713 "Keymap to put on the Prev link in the text or the header line.")
2714
2715
2716(defvar Info-up-link-keymap
2717 (let ((keymap (make-sparse-keymap)))
2718 (define-key keymap [header-line mouse-1] 'Info-up)
2719 (define-key keymap [header-line mouse-2] 'Info-up)
2720 (define-key keymap [header-line down-mouse-1] 'ignore)
2721 (define-key keymap [mouse-2] 'Info-up)
2722 keymap)
2723 "Keymap to put on the Up link in the text or the header line.")
2724
552775bd 2725(defun Info-fontify-node ()
6af7040d 2726 ;; Only fontify the node if it hasn't already been done.
505b68d5
TTN
2727 (unless (let ((where (next-property-change (point-min))))
2728 (and where (not (= where (point-max)))))
07becdb1 2729 (save-excursion
6af7040d 2730 (let ((inhibit-read-only t)
6a545cc7
KS
2731 (case-fold-search t)
2732 paragraph-markers)
07becdb1 2733 (goto-char (point-min))
6af7040d 2734 (when (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?")
35d2d241 2735 (goto-char (match-end 0))
07becdb1
MB
2736 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2737 (goto-char (match-end 0))
2738 (let* ((nbeg (match-beginning 2))
2739 (nend (match-end 2))
2740 (tbeg (match-beginning 1))
2741 (tag (buffer-substring tbeg (match-end 1))))
2742 (if (string-equal tag "Node")
2a3f98a1
CW
2743 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
2744 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
24f6a987 2745 (put-text-property tbeg nend 'mouse-face 'highlight)
07becdb1
MB
2746 (put-text-property tbeg nend
2747 'help-echo
2748 (concat "Go to node "
2749 (buffer-substring nbeg nend)))
246a06d3 2750 ;; Always set up the text property keymap.
efb21aab 2751 ;; It will either be used in the buffer
246a06d3 2752 ;; or copied in the header line.
6af7040d
SM
2753 (put-text-property tbeg nend 'keymap
2754 (cond
2755 ((equal tag "Prev") Info-prev-link-keymap)
2756 ((equal tag "Next") Info-next-link-keymap)
2757 ((equal tag "Up") Info-up-link-keymap))))))
2758 (when Info-use-header-line
2759 (goto-char (point-min))
2760 (let ((header-end (save-excursion (end-of-line) (point)))
2761 header)
2762 ;; If we find neither Next: nor Prev: link, show the entire
2763 ;; node header. Otherwise, don't show the File: and Node:
2764 ;; parts, to avoid wasting precious space on information that
2765 ;; is available in the mode line.
2766 (if (re-search-forward
2767 "\\(next\\|up\\|prev[ious]*\\): "
2768 header-end t)
2769 (progn
2770 (goto-char (match-beginning 1))
2771 (setq header (buffer-substring (point) header-end)))
2772 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" nil t)
2773 (setq header
2774 (concat "No next, prev or up links -- "
2775 (buffer-substring (point) header-end)))
2776 (setq header (buffer-substring (point) header-end))))
921e5fe6 2777
6af7040d
SM
2778 (put-text-property (point-min) (1+ (point-min))
2779 'header-line header)
2780 ;; Hide the part of the first line
2781 ;; that is in the header, if it is just part.
2782 (unless (bobp)
2783 ;; Hide the punctuation at the end, too.
2784 (skip-chars-backward " \t,")
2785 (put-text-property (point) header-end 'invisible t)))))
07becdb1
MB
2786 (goto-char (point-min))
2787 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
2788 nil t)
544e5562 2789 (let* ((c (preceding-char))
2a3f98a1 2790 (face
544e5562
CW
2791 (cond ((= c ?*) 'Info-title-1-face)
2792 ((= c ?=) 'Info-title-2-face)
2793 ((= c ?-) 'Info-title-3-face)
2794 (t 'Info-title-4-face))))
07becdb1 2795 (put-text-property (match-beginning 1) (match-end 1)
2a3f98a1 2796 'font-lock-face face))
07becdb1
MB
2797 ;; This is a serious problem for trying to handle multiple
2798 ;; frame types at once. We want this text to be invisible
2799 ;; on frames that can display the font above.
2800 (when (memq (framep (selected-frame)) '(x pc w32 mac))
6b7eef5c 2801 (add-text-properties (match-beginning 2) (1+ (match-end 2))
6af7040d 2802 '(invisible t))))
07becdb1 2803 (goto-char (point-min))
0452a274 2804 (while (re-search-forward "\\(\\*Note[ \t]*\\)\n?[ \t]*\\([^:]*\\)\\(:[^.,:(]*\\(([^)]*)[^.,:]*\\)?[,:]?\n?\\)" nil t)
9cb65411 2805 (unless (= (char-after (1- (match-beginning 0))) ?\") ; hack
6a545cc7
KS
2806 (let ((start (match-beginning 0))
2807 (next (point))
5f812a3c 2808 (hide-tag Info-hide-note-references)
9cb65411
KS
2809 other-tag)
2810 (when hide-tag
2811 ;; *Note is often used where *note should have been
6a545cc7 2812 (goto-char start)
9cb65411
KS
2813 (skip-syntax-backward " ")
2814 (setq other-tag
2815 (cond
2816 ((or (<= (point) (point-min))
2817 (memq (char-after (1- (point))) '( ?\. ?! )))
2818 "See ")
2819 ((memq (char-after (1- (point))) '( ?\( ?\[ ?\{ ?\, ?\; ?\: ))
2820 "see ")
2821 (t nil)))
2822 (goto-char next))
2823 (if hide-tag
2824 (add-text-properties (match-beginning 1) (match-end 1)
6a545cc7 2825 '(invisible t)))
9cb65411
KS
2826 (add-text-properties (match-beginning 2) (match-end 2)
2827 '(font-lock-face info-xref
2828 mouse-face highlight
2829 help-echo "mouse-2: go to this node"))
4991d703
KS
2830 (when (eq Info-hide-note-references t)
2831 (add-text-properties (match-beginning 3) (match-end 3)
6a545cc7
KS
2832 '(invisible t)))
2833 (when other-tag
0452a274
AS
2834 (save-excursion
2835 (goto-char (match-beginning 1))
2836 (insert other-tag)))
6a545cc7
KS
2837 (when (or hide-tag (eq Info-hide-note-references t))
2838 (setq paragraph-markers (cons (set-marker (make-marker) start)
2839 paragraph-markers))))))
2840
2841 (let ((fill-nobreak-invisible t))
2842 (goto-char (point-max))
2843 (while paragraph-markers
2844 (let ((m (car paragraph-markers)))
2845 (setq paragraph-markers (cdr paragraph-markers))
2846 (when (< m (point))
2847 (goto-char m)
2848 (fill-paragraph nil)
2849 (backward-paragraph 1))
2850 (set-marker m nil))))
9cb65411 2851
07becdb1
MB
2852 (goto-char (point-min))
2853 (if (and (search-forward "\n* Menu:" nil t)
2854 (not (string-match "\\<Index\\>" Info-current-node))
2855 ;; Don't take time to annotate huge menus
2856 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4991d703
KS
2857 (let ((n 0)
2858 cont)
2859 (while (re-search-forward "^\\* +\\([^:\t\n]*\\)\\(:[^.,:(]*\\(([^)]*)[^.,:]*\\)?[,:.][ \t]*\\)" nil t)
07becdb1 2860 (setq n (1+ n))
ed210b40 2861 (if (zerop (% n 3)) ; visual aids to help with 1-9 keys
07becdb1
MB
2862 (put-text-property (match-beginning 0)
2863 (1+ (match-beginning 0))
2a3f98a1 2864 'font-lock-face 'info-menu-5))
07becdb1 2865 (add-text-properties (match-beginning 1) (match-end 1)
2a3f98a1 2866 '(font-lock-face info-xref
07becdb1 2867 mouse-face highlight
9cb65411 2868 help-echo "mouse-2: go to this node"))
4991d703
KS
2869 (when (eq Info-hide-note-references t)
2870 (add-text-properties (match-beginning 2) (match-end 2)
2871 (list 'display
2872 (make-string (max 2 (- 22 (- (match-end 1) (match-beginning 1)))) ? )))
2873 (setq cont (looking-at "[ \t]*[^\n]")))
5f812a3c 2874 (if (eq Info-hide-note-references t)
4991d703
KS
2875 (while (and (= (forward-line 1) 0)
2876 (looking-at "\\([ \t]+\\)[^*\n]"))
2877 (add-text-properties (match-beginning 1) (match-end 1)
2878 (list 'display (make-string (+ 22 (if cont 4 2)) ? )))
2879 (setq cont t))))))
9cb65411 2880
07becdb1
MB
2881 (Info-fontify-menu-headers)
2882 (set-buffer-modified-p nil)))))
c5fe2ff1
RS
2883\f
2884
2885;; When an Info buffer is killed, make sure the associated tags buffer
2886;; is killed too.
2887(defun Info-kill-buffer ()
2888 (and (eq major-mode 'Info-mode)
2889 Info-tag-table-buffer
2890 (kill-buffer Info-tag-table-buffer)))
2891
2892(add-hook 'kill-buffer-hook 'Info-kill-buffer)
3cb6768f
EL
2893
2894;;; Speedbar support:
2895;; These functions permit speedbar to display the "tags" in the
2896;; current info node.
96ee3f29 2897(eval-when-compile (require 'speedbar))
3cb6768f 2898
96ee3f29
KH
2899(defvar Info-speedbar-key-map nil
2900 "Keymap used when in the info display mode.")
3cb6768f 2901
96ee3f29
KH
2902(defun Info-install-speedbar-variables ()
2903 "Install those variables used by speedbar to enhance Info."
2904 (if Info-speedbar-key-map
2905 nil
2906 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2907
2908 ;; Basic tree features
2909 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2910 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2911 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2912 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2913 )
2914
2915 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2916 Info-speedbar-key-map
2917 Info-speedbar-hierarchy-buttons)))
3cb6768f
EL
2918
2919(defvar Info-speedbar-menu-items
96ee3f29
KH
2920 '(["Browse Node" speedbar-edit-line t]
2921 ["Expand Node" speedbar-expand-line
2922 (save-excursion (beginning-of-line)
2923 (looking-at "[0-9]+: *.\\+. "))]
2924 ["Contract Node" speedbar-contract-line
2925 (save-excursion (beginning-of-line)
2926 (looking-at "[0-9]+: *.-. "))]
2927 )
3cb6768f
EL
2928 "Additional menu-items to add to speedbar frame.")
2929
96ee3f29
KH
2930;; Make sure our special speedbar major mode is loaded
2931(if (featurep 'speedbar)
2932 (Info-install-speedbar-variables)
2933 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2934
2935;;; Info hierarchy display method
2936;;;###autoload
2937(defun Info-speedbar-browser ()
2938 "Initialize speedbar to display an info node browser.
2939This will add a speedbar major display mode."
2940 (interactive)
2941 (require 'speedbar)
2942 ;; Make sure that speedbar is active
2943 (speedbar-frame-mode 1)
2944 ;; Now, throw us into Info mode on speedbar.
2945 (speedbar-change-initial-expansion-list "Info")
2946 )
2947
7210b6f5
DL
2948(eval-when-compile (defvar speedbar-attached-frame))
2949
96ee3f29
KH
2950(defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2951 "Display an Info directory hierarchy in speedbar.
2952DIRECTORY is the current directory in the attached frame.
2953DEPTH is the current indentation depth.
2954NODE is an optional argument that is used to represent the
2955specific node to expand."
2956 (if (and (not node)
2957 (save-excursion (goto-char (point-min))
1bcedb3b
RS
2958 (let ((case-fold-search t))
2959 (looking-at "Info Nodes:"))))
96ee3f29
KH
2960 ;; Update our "current node" maybe?
2961 nil
2962 ;; We cannot use the generic list code, that depends on all leaves
2963 ;; being known at creation time.
2964 (if (not node)
2965 (speedbar-with-writable (insert "Info Nodes:\n")))
5fdc7997
EL
2966 (let ((completions nil)
2967 (cf (selected-frame)))
2968 (select-frame speedbar-attached-frame)
2969 (save-window-excursion
2970 (setq completions
2971 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
2972 (select-frame cf)
96ee3f29
KH
2973 (if completions
2974 (speedbar-with-writable
2975 (while completions
2976 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2977 (cdr (car completions))
2978 (car (car completions))
2979 'Info-speedbar-goto-node
2980 (cdr (car completions))
2981 'info-xref depth)
2982 (setq completions (cdr completions)))
2983 t)
2984 nil))))
399c88ad 2985
96ee3f29 2986(defun Info-speedbar-goto-node (text node indent)
d1268e52 2987 "When user clicks on TEXT, go to an info NODE.
96ee3f29 2988The INDENT level is ignored."
760d5cb3
GM
2989 (select-frame speedbar-attached-frame)
2990 (let* ((buff (or (get-buffer "*info*")
2991 (progn (info) (get-buffer "*info*"))))
2992 (bwin (get-buffer-window buff 0)))
2993 (if bwin
2994 (progn
2995 (select-window bwin)
2996 (raise-frame (window-frame bwin)))
2997 (if speedbar-power-click
2998 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2999 (select-frame speedbar-attached-frame)
3000 (switch-to-buffer buff)))
3001 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
3002 (file (match-string 1 node))
3003 (node (match-string 2 node)))
3004 (Info-find-node file node)
3005 ;; If we do a find-node, and we were in info mode, restore
3006 ;; the old default method. Once we are in info mode, it makes
3007 ;; sense to return to whatever method the user was using before.
3008 (if (string= speedbar-initial-expansion-list-name "Info")
3009 (speedbar-change-initial-expansion-list
3010 speedbar-previously-used-expansion-list-name)))))
96ee3f29
KH
3011
3012(defun Info-speedbar-expand-node (text token indent)
3013 "Expand the node the user clicked on.
3014TEXT is the text of the button we clicked on, a + or - item.
3015TOKEN is data related to this node (NAME . FILE).
3016INDENT is the current indentation depth."
3017 (cond ((string-match "+" text) ;we have to expand this file
3018 (speedbar-change-expand-button-char ?-)
3019 (if (speedbar-with-writable
760d5cb3
GM
3020 (save-excursion
3021 (end-of-line) (forward-char 1)
3022 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
96ee3f29
KH
3023 (speedbar-change-expand-button-char ?-)
3024 (speedbar-change-expand-button-char ??)))
3025 ((string-match "-" text) ;we have to contract this node
3026 (speedbar-change-expand-button-char ?+)
3027 (speedbar-delete-subblock indent))
3028 (t (error "Ooops... not sure what to do")))
3029 (speedbar-center-buffer-smartly))
3030
3031(defun Info-speedbar-fetch-file-nodes (nodespec)
3032 "Fetch the subnodes from the info NODESPEC.
3033NODESPEC is a string of the form: (file)node.
3034Optional THISFILE represends the filename of"
3035 (save-excursion
3036 ;; Set up a buffer we can use to fake-out Info.
3037 (set-buffer (get-buffer-create "*info-browse-tmp*"))
3038 (if (not (equal major-mode 'Info-mode))
3039 (Info-mode))
3040 ;; Get the node into this buffer
3041 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
3042 (file (match-string 1 nodespec))
3043 (node (match-string 2 nodespec)))
3044 (Info-find-node file node))
3045 ;; Scan the created buffer
3046 (goto-char (point-min))
3047 (let ((completions nil)
1bcedb3b 3048 (case-fold-search t)
96ee3f29
KH
3049 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
3050 (match-string 1 nodespec))))
3051 ;; Always skip the first one...
3052 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3053 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3054 (let ((name (match-string 1)))
3055 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
3056 (setq name (cons name (match-string 1)))
3057 (if (looking-at " *\\(([^)]+)\\)\\.")
3058 (setq name (cons name (concat (match-string 1) "Top")))
3059 (if (looking-at " \\([^.]+\\).")
3060 (setq name
3061 (cons name (concat "(" thisfile ")" (match-string 1))))
3062 (setq name (cons name (concat "(" thisfile ")" name))))))
3063 (setq completions (cons name completions))))
3064 (nreverse completions))))
3065
3066;;; Info mode node listing
3cb6768f
EL
3067(defun Info-speedbar-buttons (buffer)
3068 "Create a speedbar display to help navigation in an Info file.
3069BUFFER is the buffer speedbar is requesting buttons for."
96ee3f29 3070 (if (save-excursion (goto-char (point-min))
1bcedb3b
RS
3071 (let ((case-fold-search t))
3072 (not (looking-at "Info Nodes:"))))
96ee3f29
KH
3073 (erase-buffer))
3074 (Info-speedbar-hierarchy-buttons nil 0)
3075 )
49116ac0 3076
48e5b471
DL
3077(dolist (mess '("^Node has no Previous$"
3078 "^No menu in this node$"
3079 "^Node has no Next$"
399c88ad
SS
3080 "^No cross-references in this node^"
3081 search-failed
48e5b471
DL
3082 "^No \".*\" in index$"))
3083 (add-to-list 'debug-ignored-errors mess))
3084
49116ac0
JB
3085(provide 'info)
3086
1a06eabd 3087;;; info.el ends here