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