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