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