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