(easy-mmode-pretty-mode-name): Prettier.
[emacs.git] / lisp / info.el
blob67fdec75f889326f43cda17f3f237b62c35bf454
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, show the node in a new info buffer.
967 If FORK is a string, it is the name to use for the new buffer."
968 (interactive (list (Info-read-node-name "Goto node: ") current-prefix-arg))
969 (info-initialize)
970 (if fork
971 (set-buffer
972 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
973 (let (filename)
974 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
975 nodename)
976 (setq filename (if (= (match-beginning 1) (match-end 1))
978 (substring nodename (match-beginning 2) (match-end 2)))
979 nodename (substring nodename (match-beginning 3) (match-end 3)))
980 (let ((trim (string-match "\\s *\\'" filename)))
981 (if trim (setq filename (substring filename 0 trim))))
982 (let ((trim (string-match "\\s *\\'" nodename)))
983 (if trim (setq nodename (substring nodename 0 trim))))
984 (if transient-mark-mode (deactivate-mark))
985 (Info-find-node (if (equal filename "") nil filename)
986 (if (equal nodename "") "Top" nodename))))
988 (defvar Info-read-node-completion-table)
990 ;; This function is used as the "completion table" while reading a node name.
991 ;; It does completion using the alist in Info-read-node-completion-table
992 ;; unless STRING starts with an open-paren.
993 (defun Info-read-node-name-1 (string predicate code)
994 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
995 (cond ((eq code nil)
996 (if no-completion
997 string
998 (try-completion string Info-read-node-completion-table predicate)))
999 ((eq code t)
1000 (if no-completion
1002 (all-completions string Info-read-node-completion-table predicate)))
1003 ((eq code 'lambda)
1004 (if no-completion
1006 (assoc string Info-read-node-completion-table))))))
1008 (defun Info-read-node-name (prompt &optional default)
1009 (let* ((completion-ignore-case t)
1010 (Info-read-node-completion-table (Info-build-node-completions))
1011 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1012 (if (equal nodename "")
1013 (or default
1014 (Info-read-node-name prompt))
1015 nodename)))
1017 (defun Info-build-node-completions ()
1018 (or Info-current-file-completions
1019 (let ((compl nil)
1020 ;; Bind this in case the user sets it to nil.
1021 (case-fold-search t)
1022 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1023 (save-excursion
1024 (save-restriction
1025 (if (marker-buffer Info-tag-table-marker)
1026 (let ((marker Info-tag-table-marker))
1027 (set-buffer (marker-buffer marker))
1028 (widen)
1029 (goto-char marker)
1030 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1031 (setq compl
1032 (cons (list (match-string-no-properties 2))
1033 compl))))
1034 (widen)
1035 (goto-char (point-min))
1036 ;; If the buffer begins with a node header, process that first.
1037 (if (Info-node-at-bob-matching node-regexp)
1038 (setq compl (list (match-string-no-properties 1))))
1039 ;; Now for the rest of the nodes.
1040 (while (search-forward "\n\^_" nil t)
1041 (forward-line 1)
1042 (let ((beg (point)))
1043 (forward-line 1)
1044 (if (re-search-backward node-regexp beg t)
1045 (setq compl
1046 (cons (list (match-string-no-properties 1))
1047 compl))))))))
1048 (setq compl (cons '("*") compl))
1049 (setq Info-current-file-completions compl))))
1051 (defun Info-restore-point (hl)
1052 "If this node has been visited, restore the point value when we left."
1053 (while hl
1054 (if (and (equal (nth 0 (car hl)) Info-current-file)
1055 ;; Use string-equal, not equal, to ignore text props.
1056 (string-equal (nth 1 (car hl)) Info-current-node))
1057 (progn
1058 (goto-char (nth 2 (car hl)))
1059 (setq hl nil)) ;terminate the while at next iter
1060 (setq hl (cdr hl)))))
1062 (defvar Info-search-history nil
1063 "The history list for `Info-search'.")
1065 (defun Info-search (regexp)
1066 "Search for REGEXP, starting from point, and select node it's found in."
1067 (interactive (list (read-string "Regexp search: "
1068 nil 'Info-search-history)))
1069 (when transient-mark-mode
1070 (deactivate-mark))
1071 (when (equal regexp "")
1072 (setq regexp (car Info-search-history)))
1073 (when regexp
1074 (let ((found ()) current
1075 (onode Info-current-node)
1076 (ofile Info-current-file)
1077 (opoint (point))
1078 (ostart (window-start))
1079 (osubfile Info-current-subfile))
1080 (save-excursion
1081 (save-restriction
1082 (widen)
1083 (if (null Info-current-subfile)
1084 (progn (re-search-forward regexp) (setq found (point)))
1085 (condition-case err
1086 (progn (re-search-forward regexp) (setq found (point)))
1087 (search-failed nil)))))
1088 (if (not found) ;can only happen in subfile case -- else would have erred
1089 (unwind-protect
1090 (let ((list ()))
1091 (save-excursion
1092 (set-buffer (marker-buffer Info-tag-table-marker))
1093 (goto-char (point-min))
1094 (search-forward "\n\^_\nIndirect:")
1095 (save-restriction
1096 (narrow-to-region (point)
1097 (progn (search-forward "\n\^_")
1098 (1- (point))))
1099 (goto-char (point-min))
1100 (search-forward (concat "\n" osubfile ": "))
1101 (beginning-of-line)
1102 (while (not (eobp))
1103 (re-search-forward "\\(^.*\\): [0-9]+$")
1104 (goto-char (+ (match-end 1) 2))
1105 (setq list (cons (cons (read (current-buffer))
1106 (match-string-no-properties 1))
1107 list))
1108 (goto-char (1+ (match-end 0))))
1109 (setq list (nreverse list)
1110 current (car (car list))
1111 list (cdr list))))
1112 (while list
1113 (message "Searching subfile %s..." (cdr (car list)))
1114 (Info-read-subfile (car (car list)))
1115 (setq list (cdr list))
1116 ;;; (goto-char (point-min))
1117 (if (re-search-forward regexp nil t)
1118 (setq found (point) list ())))
1119 (if found
1120 (message "")
1121 (signal 'search-failed (list regexp))))
1122 (if (not found)
1123 (progn (Info-read-subfile osubfile)
1124 (goto-char opoint)
1125 (Info-select-node)
1126 (set-window-start (selected-window) ostart)))))
1127 (widen)
1128 (goto-char found)
1129 (Info-select-node)
1130 ;; Use string-equal, not equal, to ignore text props.
1131 (or (and (string-equal onode Info-current-node)
1132 (equal ofile Info-current-file))
1133 (setq Info-history (cons (list ofile onode opoint)
1134 Info-history))))))
1136 (defun Info-extract-pointer (name &optional errorname)
1137 "Extract the value of the node-pointer named NAME.
1138 If there is none, use ERRORNAME in the error message;
1139 if ERRORNAME is nil, just return nil.
1140 Bind this in case the user sets it to nil."
1141 (let ((case-fold-search t))
1142 (save-excursion
1143 (save-restriction
1144 (goto-char (point-min))
1145 (when Info-header-line
1146 ;; expose the header line in the buffer
1147 (widen)
1148 (forward-line -1))
1149 (let ((bound (point)))
1150 (forward-line 1)
1151 (cond ((re-search-backward (concat name ":") bound t)
1152 (goto-char (match-end 0))
1153 (Info-following-node-name))
1154 ((not (eq errorname t))
1155 (error "Node has no %s"
1156 (capitalize (or errorname name))))))))))
1158 (defun Info-following-node-name (&optional allowedchars)
1159 "Return the node name in the buffer following point.
1160 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1161 saying which chars may appear in the node name."
1162 (skip-chars-forward " \t")
1163 (buffer-substring-no-properties
1164 (point)
1165 (progn
1166 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1167 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1168 (if (looking-at "(")
1169 (skip-chars-forward "^)")))
1170 (skip-chars-backward " ")
1171 (point))))
1173 (defun Info-next ()
1174 "Go to the next node of this node."
1175 (interactive)
1176 (Info-goto-node (Info-extract-pointer "next")))
1178 (defun Info-prev ()
1179 "Go to the previous node of this node."
1180 (interactive)
1181 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1183 (defun Info-up (&optional same-file)
1184 "Go to the superior node of this node.
1185 If SAME-FILE is non-nil, do not move to a different Info file."
1186 (interactive)
1187 (let ((node (Info-extract-pointer "up")))
1188 (and (or same-file (not (stringp Info-current-file)))
1189 (string-match "^(" node)
1190 (error "Up node is in another Info file"))
1191 (Info-goto-node node))
1192 (Info-restore-point Info-history))
1194 (defun Info-last ()
1195 "Go back to the last node visited."
1196 (interactive)
1197 (or Info-history
1198 (error "This is the first Info node you looked at"))
1199 (let (filename nodename opoint)
1200 (setq filename (car (car Info-history)))
1201 (setq nodename (car (cdr (car Info-history))))
1202 (setq opoint (car (cdr (cdr (car Info-history)))))
1203 (setq Info-history (cdr Info-history))
1204 (Info-find-node filename nodename)
1205 (setq Info-history (cdr Info-history))
1206 (goto-char opoint)))
1208 ;;;###autoload
1209 (defun Info-directory ()
1210 "Go to the Info directory node."
1211 (interactive)
1212 (Info-find-node "dir" "top"))
1214 (defun Info-follow-reference (footnotename)
1215 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1216 FOOTNOTENAME may be an abbreviation of the reference name."
1217 (interactive
1218 (let ((completion-ignore-case t)
1219 (case-fold-search t)
1220 completions default alt-default (start-point (point)) str i bol eol)
1221 (save-excursion
1222 ;; Store end and beginning of line.
1223 (end-of-line)
1224 (setq eol (point))
1225 (beginning-of-line)
1226 (setq bol (point))
1228 (goto-char (point-min))
1229 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1230 (setq str (buffer-substring-no-properties
1231 (match-beginning 1)
1232 (1- (point))))
1233 ;; See if this one should be the default.
1234 (and (null default)
1235 (<= (match-beginning 0) start-point)
1236 (<= start-point (point))
1237 (setq default t))
1238 ;; See if this one should be the alternate default.
1239 (and (null alt-default)
1240 (and (<= bol (match-beginning 0))
1241 (<= (point) eol))
1242 (setq alt-default t))
1243 (setq i 0)
1244 (while (setq i (string-match "[ \n\t]+" str i))
1245 (setq str (concat (substring str 0 i) " "
1246 (substring str (match-end 0))))
1247 (setq i (1+ i)))
1248 ;; Record as a completion and perhaps as default.
1249 (if (eq default t) (setq default str))
1250 (if (eq alt-default t) (setq alt-default str))
1251 ;; Don't add this string if it's a duplicate.
1252 ;; We use a loop instead of "(assoc str completions)" because
1253 ;; we want to do a case-insensitive compare.
1254 (let ((tail completions)
1255 (tem (downcase str)))
1256 (while (and tail
1257 (not (string-equal tem (downcase (car (car tail))))))
1258 (setq tail (cdr tail)))
1259 (or tail
1260 (setq completions
1261 (cons (cons str nil)
1262 completions))))))
1263 ;; If no good default was found, try an alternate.
1264 (or default
1265 (setq default alt-default))
1266 ;; If only one cross-reference found, then make it default.
1267 (if (eq (length completions) 1)
1268 (setq default (car (car completions))))
1269 (if completions
1270 (let ((input (completing-read (if default
1271 (concat "Follow reference named: ("
1272 default ") ")
1273 "Follow reference named: ")
1274 completions nil t)))
1275 (list (if (equal input "")
1276 default input)))
1277 (error "No cross-references in this node"))))
1279 (unless footnotename
1280 (error "No reference was specified"))
1282 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
1283 (case-fold-search t))
1284 (while (setq i (string-match " " str i))
1285 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1286 (setq i (+ i 6)))
1287 (save-excursion
1288 (goto-char (point-min))
1289 (or (re-search-forward str nil t)
1290 (error "No cross-reference named %s" footnotename))
1291 (goto-char (+ (match-beginning 0) 5))
1292 (setq target
1293 (Info-extract-menu-node-name "Bad format cross reference" t)))
1294 (while (setq i (string-match "[ \t\n]+" target i))
1295 (setq target (concat (substring target 0 i) " "
1296 (substring target (match-end 0))))
1297 (setq i (+ i 1)))
1298 (Info-goto-node target)))
1300 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1301 (skip-chars-forward " \t\n")
1302 (let ((beg (point))
1303 str i)
1304 (skip-chars-forward "^:")
1305 (forward-char 1)
1306 (setq str
1307 (if (looking-at ":")
1308 (buffer-substring-no-properties beg (1- (point)))
1309 (skip-chars-forward " \t\n")
1310 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1311 (while (setq i (string-match "\n" str i))
1312 (aset str i ?\ ))
1313 ;; Collapse multiple spaces.
1314 (while (string-match " +" str)
1315 (setq str (replace-match " " t t str)))
1316 str))
1318 ;; No one calls this.
1319 ;;(defun Info-menu-item-sequence (list)
1320 ;; (while list
1321 ;; (Info-menu (car list))
1322 ;; (setq list (cdr list))))
1324 (defvar Info-complete-menu-buffer)
1326 (defun Info-complete-menu-item (string predicate action)
1327 (let ((completion-ignore-case t)
1328 (case-fold-search t))
1329 (cond ((eq action nil)
1330 (let (completions
1331 (pattern (concat "\n\\* +\\("
1332 (regexp-quote string)
1333 "[^:\t\n]*\\):")))
1334 (save-excursion
1335 (set-buffer Info-complete-menu-buffer)
1336 (goto-char (point-min))
1337 (search-forward "\n* Menu:")
1338 (while (re-search-forward pattern nil t)
1339 (setq completions
1340 (cons (cons (match-string-no-properties 1)
1341 (match-beginning 1))
1342 completions))))
1343 (try-completion string completions predicate)))
1344 ((eq action t)
1345 (let (completions
1346 (pattern (concat "\n\\* +\\("
1347 (regexp-quote string)
1348 "[^:\t\n]*\\):")))
1349 (save-excursion
1350 (set-buffer Info-complete-menu-buffer)
1351 (goto-char (point-min))
1352 (search-forward "\n* Menu:")
1353 (while (re-search-forward pattern nil t)
1354 (setq completions (cons (cons
1355 (match-string-no-properties 1)
1356 (match-beginning 1))
1357 completions))))
1358 (all-completions string completions predicate)))
1360 (save-excursion
1361 (set-buffer Info-complete-menu-buffer)
1362 (goto-char (point-min))
1363 (search-forward "\n* Menu:")
1364 (re-search-forward (concat "\n\\* +"
1365 (regexp-quote string)
1366 ":")
1367 nil t))))))
1370 (defun Info-menu (menu-item &optional fork)
1371 "Go to node for menu item named (or abbreviated) NAME.
1372 Completion is allowed, and the menu item point is on is the default."
1373 (interactive
1374 (let ((completions '())
1375 ;; If point is within a menu item, use that item as the default
1376 (default nil)
1377 (p (point))
1379 (last nil)
1380 (case-fold-search t))
1381 (save-excursion
1382 (goto-char (point-min))
1383 (if (not (search-forward "\n* menu:" nil t))
1384 (error "No menu in this node"))
1385 (setq beg (point))
1386 (and (< (point) p)
1387 (save-excursion
1388 (goto-char p)
1389 (end-of-line)
1390 (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
1391 (setq default (match-string-no-properties 1))))))
1392 (let ((item nil))
1393 (while (null item)
1394 (setq item (let ((completion-ignore-case t)
1395 (Info-complete-menu-buffer (current-buffer)))
1396 (completing-read (if default
1397 (format "Menu item (default %s): "
1398 default)
1399 "Menu item: ")
1400 'Info-complete-menu-item nil t)))
1401 ;; we rely on the fact that completing-read accepts an input
1402 ;; of "" even when the require-match argument is true and ""
1403 ;; is not a valid possibility
1404 (if (string= item "")
1405 (if default
1406 (setq item default)
1407 ;; ask again
1408 (setq item nil))))
1409 (list item current-prefix-arg))))
1410 ;; there is a problem here in that if several menu items have the same
1411 ;; name you can only go to the node of the first with this command.
1412 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
1414 (defun Info-extract-menu-item (menu-item)
1415 (setq menu-item (regexp-quote menu-item))
1416 (let ((case-fold-search t))
1417 (save-excursion
1418 (let ((case-fold-search t))
1419 (goto-char (point-min))
1420 (or (search-forward "\n* menu:" nil t)
1421 (error "No menu in this node"))
1422 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1423 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1424 (error "No such item in menu"))
1425 (beginning-of-line)
1426 (forward-char 2)
1427 (Info-extract-menu-node-name)))))
1429 ;; If COUNT is nil, use the last item in the menu.
1430 (defun Info-extract-menu-counting (count)
1431 (let ((case-fold-search t))
1432 (save-excursion
1433 (let ((case-fold-search t))
1434 (goto-char (point-min))
1435 (or (search-forward "\n* menu:" nil t)
1436 (error "No menu in this node"))
1437 (if count
1438 (or (search-forward "\n* " nil t count)
1439 (error "Too few items in menu"))
1440 (while (search-forward "\n* " nil t)
1441 nil))
1442 (Info-extract-menu-node-name)))))
1444 (defun Info-nth-menu-item ()
1445 "Go to the node of the Nth menu item.
1446 N is the digit argument used to invoke this command."
1447 (interactive)
1448 (Info-goto-node
1449 (Info-extract-menu-counting
1450 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1452 (defun Info-top-node ()
1453 "Go to the Top node of this file."
1454 (interactive)
1455 (Info-goto-node "Top"))
1457 (defun Info-final-node ()
1458 "Go to the final node in this file."
1459 (interactive)
1460 (Info-goto-node "Top")
1461 (let ((Info-history nil)
1462 (case-fold-search t))
1463 ;; Go to the last node in the menu of Top.
1464 (Info-goto-node (Info-extract-menu-counting nil))
1465 ;; If the last node in the menu is not last in pointer structure,
1466 ;; move forward until we can't go any farther.
1467 (while (Info-forward-node t t) nil)
1468 ;; Then keep moving down to last subnode, unless we reach an index.
1469 (while (and (not (string-match "\\<index\\>" Info-current-node))
1470 (save-excursion (search-forward "\n* Menu:" nil t)))
1471 (Info-goto-node (Info-extract-menu-counting nil)))))
1473 (defun Info-forward-node (&optional not-down no-error)
1474 "Go forward one node, considering all nodes as forming one sequence."
1475 (interactive)
1476 (goto-char (point-min))
1477 (forward-line 1)
1478 (let ((case-fold-search t))
1479 ;; three possibilities, in order of priority:
1480 ;; 1. next node is in a menu in this node (but not in an index)
1481 ;; 2. next node is next at same level
1482 ;; 3. next node is up and next
1483 (cond ((and (not not-down)
1484 (save-excursion (search-forward "\n* menu:" nil t))
1485 (not (string-match "\\<index\\>" Info-current-node)))
1486 (Info-goto-node (Info-extract-menu-counting 1))
1488 ((save-excursion (search-backward "next:" nil t))
1489 (Info-next)
1491 ((and (save-excursion (search-backward "up:" nil t))
1492 ;; Use string-equal, not equal, to ignore text props.
1493 (not (string-equal (downcase (Info-extract-pointer "up"))
1494 "top")))
1495 (let ((old-node Info-current-node))
1496 (Info-up)
1497 (let (Info-history success)
1498 (unwind-protect
1499 (setq success (Info-forward-node t no-error))
1500 (or success (Info-goto-node old-node))))))
1501 (no-error nil)
1502 (t (error "No pointer forward from this node")))))
1504 (defun Info-backward-node ()
1505 "Go backward one node, considering all nodes as forming one sequence."
1506 (interactive)
1507 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1508 (upnode (Info-extract-pointer "up" t))
1509 (case-fold-search t))
1510 (cond ((and upnode (string-match "(" upnode))
1511 (error "First node in file"))
1512 ((and upnode (or (null prevnode)
1513 ;; Use string-equal, not equal,
1514 ;; to ignore text properties.
1515 (string-equal (downcase prevnode)
1516 (downcase upnode))))
1517 (Info-up))
1518 (prevnode
1519 ;; If we move back at the same level,
1520 ;; go down to find the last subnode*.
1521 (Info-prev)
1522 (let (Info-history)
1523 (while (and (not (string-match "\\<index\\>" Info-current-node))
1524 (save-excursion (search-forward "\n* Menu:" nil t)))
1525 (Info-goto-node (Info-extract-menu-counting nil)))))
1527 (error "No pointer backward from this node")))))
1529 (defun Info-exit ()
1530 "Exit Info by selecting some other buffer."
1531 (interactive)
1532 (if Info-standalone
1533 (save-buffers-kill-emacs)
1534 (quit-window)))
1536 (defun Info-next-menu-item ()
1537 (interactive)
1538 ;; Bind this in case the user sets it to nil.
1539 (let* ((case-fold-search t)
1540 (node
1541 (save-excursion
1542 (forward-line -1)
1543 (search-forward "\n* menu:" nil t)
1544 (and (search-forward "\n* " nil t)
1545 (Info-extract-menu-node-name)))))
1546 (if node (Info-goto-node node)
1547 (error "No more items in menu"))))
1549 (defun Info-last-menu-item ()
1550 (interactive)
1551 (save-excursion
1552 (forward-line 1)
1553 ;; Bind this in case the user sets it to nil.
1554 (let* ((case-fold-search t)
1555 (beg (save-excursion
1556 (and (search-backward "\n* menu:" nil t)
1557 (point)))))
1558 (or (and beg (search-backward "\n* " beg t))
1559 (error "No previous items in menu")))
1560 (Info-goto-node (save-excursion
1561 (goto-char (match-end 0))
1562 (Info-extract-menu-node-name)))))
1564 (defmacro Info-no-error (&rest body)
1565 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1567 (defun Info-next-preorder ()
1568 "Go to the next subnode or the next node, or go up a level."
1569 (interactive)
1570 (cond ((Info-no-error (Info-next-menu-item)))
1571 ((Info-no-error (Info-next)))
1572 ((Info-no-error (Info-up t))
1573 ;; Since we have already gone thru all the items in this menu,
1574 ;; go up to the end of this node.
1575 (goto-char (point-max))
1576 ;; Since logically we are done with the node with that menu,
1577 ;; move on from it.
1578 (Info-next-preorder))
1580 (error "No more nodes"))))
1582 (defun Info-last-preorder ()
1583 "Go to the last node, popping up a level if there is none."
1584 (interactive)
1585 (cond ((Info-no-error
1586 (Info-last-menu-item)
1587 ;; If we go down a menu item, go to the end of the node
1588 ;; so we can scroll back through it.
1589 (goto-char (point-max)))
1590 ;; Keep going down, as long as there are nested menu nodes.
1591 (while (Info-no-error
1592 (Info-last-menu-item)
1593 ;; If we go down a menu item, go to the end of the node
1594 ;; so we can scroll back through it.
1595 (goto-char (point-max))))
1596 (recenter -1))
1597 ((and (not (equal (Info-extract-pointer "up")
1598 (Info-extract-pointer "prev"))))
1599 (Info-no-error (Info-prev))
1600 (goto-char (point-max))
1601 (while (Info-no-error
1602 (Info-last-menu-item)
1603 ;; If we go down a menu item, go to the end of the node
1604 ;; so we can scroll back through it.
1605 (goto-char (point-max))))
1606 (recenter -1))
1607 ((Info-no-error (Info-up t))
1608 (goto-char (point-min))
1609 (let ((case-fold-search t))
1610 (or (search-forward "\n* Menu:" nil t)
1611 (goto-char (point-max)))))
1612 (t (error "No previous nodes"))))
1614 (defun Info-scroll-up ()
1615 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1616 Once you scroll far enough in a node that its menu appears on the screen
1617 but after point, the next scroll moves into its first subnode.
1619 When you scroll past the end of a node, that goes to the next node; if
1620 this node has no successor, it moves to the parent node's successor,
1621 and so on. If point is inside the menu of a node, it moves to
1622 subnode indicated by the following menu item. (That case won't
1623 normally result from this command, but can happen in other ways.)"
1625 (interactive)
1626 (if (or (< (window-start) (point-min))
1627 (> (window-start) (point-max)))
1628 (set-window-start (selected-window) (point)))
1629 (let* ((case-fold-search t)
1630 (virtual-end (save-excursion
1631 (goto-char (point-min))
1632 (if (search-forward "\n* Menu:" nil t)
1633 (point)
1634 (point-max)))))
1635 (if (or (< virtual-end (window-start))
1636 (pos-visible-in-window-p virtual-end))
1637 (Info-next-preorder)
1638 (scroll-up))))
1640 (defun Info-scroll-down ()
1641 "Scroll one screenful back in Info, considering all nodes as one sequence.
1642 Within the menu of a node, this goes to its last subnode.
1643 When you scroll past the beginning of a node, that goes to the
1644 previous node or back up to the parent node."
1645 (interactive)
1646 (if (or (< (window-start) (point-min))
1647 (> (window-start) (point-max)))
1648 (set-window-start (selected-window) (point)))
1649 (let* ((case-fold-search t)
1650 (current-point (point))
1651 (virtual-end (save-excursion
1652 (beginning-of-line)
1653 (setq current-point (point))
1654 (goto-char (point-min))
1655 (search-forward "\n* Menu:"
1656 current-point
1657 t))))
1658 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1659 (Info-last-preorder)
1660 (scroll-down))))
1662 (defun Info-next-reference (&optional recur)
1663 "Move cursor to the next cross-reference or menu item in the node."
1664 (interactive)
1665 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1666 (old-pt (point))
1667 (case-fold-search t))
1668 (or (eobp) (forward-char 1))
1669 (or (re-search-forward pat nil t)
1670 (progn
1671 (goto-char (point-min))
1672 (or (re-search-forward pat nil t)
1673 (progn
1674 (goto-char old-pt)
1675 (error "No cross references in this node")))))
1676 (goto-char (match-beginning 0))
1677 (if (looking-at "\\* Menu:")
1678 (if recur
1679 (error "No cross references in this node")
1680 (Info-next-reference t)))))
1682 (defun Info-prev-reference (&optional recur)
1683 "Move cursor to the previous cross-reference or menu item in the node."
1684 (interactive)
1685 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1686 (old-pt (point))
1687 (case-fold-search t))
1688 (or (re-search-backward pat nil t)
1689 (progn
1690 (goto-char (point-max))
1691 (or (re-search-backward pat nil t)
1692 (progn
1693 (goto-char old-pt)
1694 (error "No cross references in this node")))))
1695 (goto-char (match-beginning 0))
1696 (if (looking-at "\\* Menu:")
1697 (if recur
1698 (error "No cross references in this node")
1699 (Info-prev-reference t)))))
1701 (defun Info-index (topic)
1702 "Look up a string TOPIC in the index for this file.
1703 The index is defined as the first node in the top-level menu whose
1704 name contains the word \"Index\", plus any immediately following
1705 nodes whose names also contain the word \"Index\".
1706 If there are no exact matches to the specified topic, this chooses
1707 the first match which is a case-insensitive substring of a topic.
1708 Use the `,' command to see the other matches.
1709 Give a blank topic name to go to the Index node itself."
1710 (interactive "sIndex topic: ")
1711 (let ((orignode Info-current-node)
1712 (rnode nil)
1713 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1714 (regexp-quote topic)))
1715 node
1716 (case-fold-search t))
1717 (Info-goto-node "Top")
1718 (or (search-forward "\n* menu:" nil t)
1719 (error "No index"))
1720 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1721 (error "No index"))
1722 (goto-char (match-beginning 1))
1723 ;; Here, and subsequently in this function,
1724 ;; we bind Info-history to nil for internal node-switches
1725 ;; so that we don't put junk in the history.
1726 ;; In the first Info-goto-node call, above, we do update the history
1727 ;; because that is what the user's previous node choice into it.
1728 (let ((Info-history nil))
1729 (Info-goto-node (Info-extract-menu-node-name)))
1730 (or (equal topic "")
1731 (let ((matches nil)
1732 (exact nil)
1733 (Info-history nil)
1734 found)
1735 (while
1736 (progn
1737 (goto-char (point-min))
1738 (while (re-search-forward pattern nil t)
1739 (push (list (match-string-no-properties 1)
1740 (match-string-no-properties 2)
1741 Info-current-node
1742 (string-to-int (concat "0"
1743 (match-string 3))))
1744 matches))
1745 (and (setq node (Info-extract-pointer "next" t))
1746 (string-match "\\<Index\\>" node)))
1747 (Info-goto-node node))
1748 (or matches
1749 (progn
1750 (Info-goto-node orignode)
1751 (error "No `%s' in index" topic)))
1752 ;; Here it is a feature that assoc is case-sensitive.
1753 (while (setq found (assoc topic matches))
1754 (setq exact (cons found exact)
1755 matches (delq found matches)))
1756 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1757 (Info-index-next 0)))))
1759 (defun Info-index-next (num)
1760 "Go to the next matching index item from the last `i' command."
1761 (interactive "p")
1762 (or Info-index-alternatives
1763 (error "No previous `i' command"))
1764 (while (< num 0)
1765 (setq num (+ num (length Info-index-alternatives))))
1766 (while (> num 0)
1767 (setq Info-index-alternatives
1768 (nconc (cdr Info-index-alternatives)
1769 (list (car Info-index-alternatives)))
1770 num (1- num)))
1771 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1772 (if (> (nth 3 (car Info-index-alternatives)) 0)
1773 (forward-line (nth 3 (car Info-index-alternatives)))
1774 (forward-line 3) ; don't search in headers
1775 (let ((name (car (car Info-index-alternatives))))
1776 (Info-find-index-name name)))
1777 (message "Found `%s' in %s. %s"
1778 (car (car Info-index-alternatives))
1779 (nth 2 (car Info-index-alternatives))
1780 (if (cdr Info-index-alternatives)
1781 "(Press `,' for more)"
1782 "(Only match)")))
1784 (defun Info-find-index-name (name)
1785 "Move point to the place within the current node where NAME is defined."
1786 (let ((case-fold-search t))
1787 (if (or (re-search-forward (format
1788 "[a-zA-Z]+: %s\\( \\|$\\)"
1789 (regexp-quote name)) nil t)
1790 (search-forward (format "`%s'" name) nil t)
1791 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1792 (search-forward
1793 (format "`%s'" (substring name 0 (match-beginning 1)))
1794 nil t))
1795 (search-forward name nil t))
1796 (beginning-of-line)
1797 (goto-char (point-min)))))
1799 (defun Info-undefined ()
1800 "Make command be undefined in Info."
1801 (interactive)
1802 (ding))
1804 (defun Info-help ()
1805 "Enter the Info tutorial."
1806 (interactive)
1807 (delete-other-windows)
1808 (Info-find-node "info"
1809 (if (< (window-height) 23)
1810 "Help-Small-Screen"
1811 "Help")))
1813 (defun Info-summary ()
1814 "Display a brief summary of all Info commands."
1815 (interactive)
1816 (save-window-excursion
1817 (switch-to-buffer "*Help*")
1818 (setq buffer-read-only nil)
1819 (erase-buffer)
1820 (insert (documentation 'Info-mode))
1821 (help-mode)
1822 (goto-char (point-min))
1823 (let (ch flag)
1824 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1825 (message (if flag "Type Space to see more"
1826 "Type Space to return to Info"))
1827 (if (not (eq ?\ (setq ch (read-event))))
1828 (progn (setq unread-command-events (list ch)) nil)
1829 flag))
1830 (scroll-up)))
1831 (bury-buffer "*Help*")))
1833 (defun Info-get-token (pos start all &optional errorstring)
1834 "Return the token around POS.
1835 POS must be somewhere inside the token
1836 START is a regular expression which will match the
1837 beginning of the tokens delimited string
1838 ALL is a regular expression with a single
1839 parenthesized subpattern which is the token to be
1840 returned. E.g. '{\(.*\)}' would return any string
1841 enclosed in braces around POS.
1842 ERRORSTRING optional fourth argument, controls action on no match
1843 nil: return nil
1844 t: beep
1845 a string: signal an error, using that string."
1846 (let ((case-fold-search t))
1847 (save-excursion
1848 (goto-char pos)
1849 ;; First look for a match for START that goes across POS.
1850 (while (and (not (bobp)) (> (point) (- pos (length start)))
1851 (not (looking-at start)))
1852 (forward-char -1))
1853 ;; If we did not find one, search back for START
1854 ;; (this finds only matches that end at or before POS).
1855 (or (looking-at start)
1856 (progn
1857 (goto-char pos)
1858 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
1859 (let (found)
1860 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1861 (not (setq found (and (<= (match-beginning 0) pos)
1862 (> (match-end 0) pos))))))
1863 (if (and found (<= (match-beginning 0) pos)
1864 (> (match-end 0) pos))
1865 (match-string-no-properties 1)
1866 (cond ((null errorstring)
1867 nil)
1868 ((eq errorstring t)
1869 (beep)
1870 nil)
1872 (error "No %s around position %d" errorstring pos))))))))
1874 (defun Info-mouse-follow-nearest-node (click)
1875 "\\<Info-mode-map>Follow a node reference near point.
1876 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1877 At end of the node's text, moves to the next node, or up if none."
1878 (interactive "e")
1879 (let* ((start (event-start click))
1880 (window (car start))
1881 (pos (car (cdr start))))
1882 (select-window window)
1883 (goto-char pos))
1884 (and (not (Info-try-follow-nearest-node))
1885 (save-excursion (forward-line 1) (eobp))
1886 (Info-next-preorder)))
1888 (defun Info-follow-nearest-node ()
1889 "\\<Info-mode-map>Follow a node reference near point.
1890 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1891 If no reference to follow, moves to the next node, or up if none."
1892 (interactive)
1893 (or (Info-try-follow-nearest-node)
1894 (Info-next-preorder)))
1896 ;; Common subroutine.
1897 (defun Info-try-follow-nearest-node ()
1898 "Follow a node reference near point. Return non-nil if successful."
1899 (let (node)
1900 (cond
1901 ((setq node (Info-get-token (point) "\\*note[ \n]"
1902 "\\*note[ \n]\\([^:]*\\):"))
1903 (Info-follow-reference node))
1904 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1905 (Info-goto-node node))
1906 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
1907 (beginning-of-line)
1908 (forward-char 2)
1909 (setq node (Info-extract-menu-node-name))
1910 (Info-goto-node node))
1911 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1912 (Info-goto-node node))
1913 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1914 (Info-goto-node node))
1915 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1916 (Info-goto-node "Top"))
1917 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1918 (Info-goto-node node)))
1919 node))
1921 (defvar Info-mode-map nil
1922 "Keymap containing Info commands.")
1923 (if Info-mode-map
1925 (setq Info-mode-map (make-keymap))
1926 (suppress-keymap Info-mode-map)
1927 (define-key Info-mode-map "." 'beginning-of-buffer)
1928 (define-key Info-mode-map " " 'Info-scroll-up)
1929 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1930 (define-key Info-mode-map "\t" 'Info-next-reference)
1931 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1932 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1933 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1934 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1935 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1936 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1937 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1938 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1939 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1940 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1941 (define-key Info-mode-map "0" 'undefined)
1942 (define-key Info-mode-map "?" 'Info-summary)
1943 (define-key Info-mode-map "]" 'Info-forward-node)
1944 (define-key Info-mode-map "[" 'Info-backward-node)
1945 (define-key Info-mode-map "<" 'Info-top-node)
1946 (define-key Info-mode-map ">" 'Info-final-node)
1947 (define-key Info-mode-map "b" 'beginning-of-buffer)
1948 (define-key Info-mode-map "d" 'Info-directory)
1949 (define-key Info-mode-map "e" 'Info-edit)
1950 (define-key Info-mode-map "f" 'Info-follow-reference)
1951 (define-key Info-mode-map "g" 'Info-goto-node)
1952 (define-key Info-mode-map "h" 'Info-help)
1953 (define-key Info-mode-map "i" 'Info-index)
1954 (define-key Info-mode-map "l" 'Info-last)
1955 (define-key Info-mode-map "m" 'Info-menu)
1956 (define-key Info-mode-map "n" 'Info-next)
1957 (define-key Info-mode-map "p" 'Info-prev)
1958 (define-key Info-mode-map "q" 'Info-exit)
1959 (define-key Info-mode-map "s" 'Info-search)
1960 ;; For consistency with Rmail.
1961 (define-key Info-mode-map "\M-s" 'Info-search)
1962 (define-key Info-mode-map "\M-n" 'clone-buffer)
1963 (define-key Info-mode-map "t" 'Info-top-node)
1964 (define-key Info-mode-map "u" 'Info-up)
1965 (define-key Info-mode-map "," 'Info-index-next)
1966 (define-key Info-mode-map "\177" 'Info-scroll-down)
1967 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1970 (defun Info-check-pointer (item)
1971 "Non-nil if ITEM is present in this node."
1972 (condition-case nil
1973 (Info-extract-pointer item)
1974 (error nil)))
1976 (easy-menu-define
1977 Info-mode-menu Info-mode-map
1978 "Menu for info files."
1979 '("Info"
1980 ["Up" Info-up :active (Info-check-pointer "up")
1981 :help "Go up in the Info tree"]
1982 ["Next" Info-next :active (Info-check-pointer "next")
1983 :help "Go to the next node"]
1984 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
1985 :help "Go to the previous node"]
1986 ["Backward" Info-backward-node
1987 :help "Go backward one node, considering all as a sequence"]
1988 ["Forward" Info-forward-node
1989 :help "Go forward one node, considering all as a sequence"]
1990 ["Top" Info-top-node
1991 :help "Go to top node of file"]
1992 ["Final Node" Info-final-node
1993 :help "Go to final node in this file"]
1994 ("Menu Item" ["You should never see this" report-emacs-bug t])
1995 ("Reference" ["You should never see this" report-emacs-bug t])
1996 ["Search..." Info-search
1997 :help "Search for regular expression in this Info file"]
1998 ["Goto Node..." Info-goto-node
1999 :help "Go to a named node"]
2000 ["Last" Info-last Info-history
2001 :help "Go to the last node you were at"]
2002 ("Index..."
2003 ["Lookup a String" Info-index
2004 :help "Look for a string in the index items"]
2005 ["Next Matching Item" Info-index-next
2006 :help "Look for another occurrence of previous item"])
2007 ["Exit" Info-exit t]))
2009 (defvar Info-menu-last-node nil)
2010 ;; Last node the menu was created for.
2011 ;; Value is a list, (FILE-NAME NODE-NAME).
2013 (defun Info-menu-update ()
2014 "Update the Info menu for the current node."
2015 (condition-case nil
2016 (if (or (not (eq major-mode 'Info-mode))
2017 (equal (list Info-current-file Info-current-node)
2018 Info-menu-last-node))
2020 ;; Update menu menu.
2021 (let* ((Info-complete-menu-buffer (current-buffer))
2022 (items (nreverse (condition-case nil
2023 (Info-complete-menu-item
2024 "" (lambda (e) t) t)
2025 (error nil))))
2026 entries current
2027 (number 0))
2028 (while (and items (< number 9))
2029 (setq current (car items)
2030 items (cdr items)
2031 number (1+ number))
2032 (setq entries (cons `[,current
2033 (Info-menu ,current)
2034 :keys ,(format "%d" number)]
2035 entries)))
2036 (if items
2037 (setq entries (cons ["Other..." Info-menu t] entries)))
2038 (or entries
2039 (setq entries (list ["No menu" nil nil])))
2040 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
2041 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2042 (let ((items nil)
2043 str i entries current
2044 (number 0)
2045 (case-fold-search t))
2046 (save-excursion
2047 (goto-char (point-min))
2048 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
2049 (setq str (buffer-substring
2050 (match-beginning 1)
2051 (1- (point))))
2052 (setq i 0)
2053 (while (setq i (string-match "[ \n\t]+" str i))
2054 (setq str (concat (substring str 0 i) " "
2055 (substring str (match-end 0))))
2056 (setq i (1+ i)))
2057 (setq items
2058 (cons str items))))
2059 (while (and items (< number 9))
2060 (setq current (car items)
2061 items (cdr items)
2062 number (1+ number))
2063 (setq entries (cons `[,current
2064 (Info-follow-reference ,current)
2066 entries)))
2067 (if items
2068 (setq entries (cons ["Other..." Info-follow-reference t]
2069 entries)))
2070 (or entries
2071 (setq entries (list ["No references" nil nil])))
2072 (easy-menu-change '("Info") "Reference" (nreverse entries)))
2073 ;; Update last seen node.
2074 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
2075 ;; Try to avoid entering infinite beep mode in case of errors.
2076 (error (ding))))
2079 ;; Info mode is suitable only for specially formatted data.
2080 (put 'Info-mode 'mode-class 'special)
2082 (defun Info-mode ()
2083 "Info mode provides commands for browsing through the Info documentation tree.
2084 Documentation in Info is divided into \"nodes\", each of which discusses
2085 one topic and contains references to other nodes which discuss related
2086 topics. Info has commands to follow the references and show you other nodes.
2088 \\<Info-mode-map>\
2089 \\[Info-help] Invoke the Info tutorial.
2090 \\[Info-exit] Quit Info: reselect previously selected buffer.
2092 Selecting other nodes:
2093 \\[Info-mouse-follow-nearest-node]
2094 Follow a node reference you click on.
2095 This works with menu items, cross references, and
2096 the \"next\", \"previous\" and \"up\", depending on where you click.
2097 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2098 \\[Info-next] Move to the \"next\" node of this node.
2099 \\[Info-prev] Move to the \"previous\" node of this node.
2100 \\[Info-up] Move \"up\" from this node.
2101 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2102 Picking a menu item causes another node to be selected.
2103 \\[Info-directory] Go to the Info directory node.
2104 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2105 \\[Info-last] Move to the last node you were at.
2106 \\[Info-index] Look up a topic in this file's Index and move to that node.
2107 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2108 \\[Info-top-node] Go to the Top node of this file.
2109 \\[Info-final-node] Go to the final node in this file.
2110 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2111 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2113 Moving within a node:
2114 \\[Info-scroll-up] Normally, scroll forward a full screen.
2115 Once you scroll far enough in a node that its menu appears on the screen
2116 but after point, the next scroll moves into its first subnode.
2117 When after all menu items (or if their is no menu), move up to
2118 the parent node.
2119 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2120 already visible, try to go to the previous menu entry, or up if there is none.
2121 \\[beginning-of-buffer] Go to beginning of node.
2123 Advanced commands:
2124 \\[Info-exit] Quit Info: reselect previously selected buffer.
2125 \\[Info-edit] Edit contents of selected node.
2126 1 Pick first item in node's menu.
2127 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2128 \\[Info-goto-node] Move to node specified by name.
2129 You may include a filename as well, as (FILENAME)NODENAME.
2130 \\[universal-argument] \\[info] Move to new Info file with completion.
2131 \\[Info-search] Search through this Info file for specified regexp,
2132 and select the node in which the next occurrence is found.
2133 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2134 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2135 (kill-all-local-variables)
2136 (setq major-mode 'Info-mode)
2137 (setq mode-name "Info")
2138 (setq tab-width 8)
2139 (use-local-map Info-mode-map)
2140 (make-local-hook 'activate-menubar-hook)
2141 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
2142 (set-syntax-table text-mode-syntax-table)
2143 (setq local-abbrev-table text-mode-abbrev-table)
2144 (setq case-fold-search t)
2145 (setq buffer-read-only t)
2146 (make-local-variable 'Info-current-file)
2147 (make-local-variable 'Info-current-subfile)
2148 (make-local-variable 'Info-current-node)
2149 (make-local-variable 'Info-tag-table-marker)
2150 (setq Info-tag-table-marker (make-marker))
2151 (make-local-variable 'Info-tag-table-buffer)
2152 (setq Info-tag-table-buffer nil)
2153 (make-local-variable 'Info-history)
2154 (make-local-variable 'Info-index-alternatives)
2155 ;; This is for the sake of the invisible text we use handling titles.
2156 (make-local-variable 'line-move-ignore-invisible)
2157 (setq line-move-ignore-invisible t)
2158 (add-hook (make-local-hook 'clone-buffer-hook) 'Info-clone-buffer-hook nil t)
2159 (Info-set-mode-line)
2160 (run-hooks 'Info-mode-hook))
2162 (defun Info-clone-buffer-hook ()
2163 (when (bufferp Info-tag-table-buffer)
2164 (setq Info-tag-table-buffer
2165 (with-current-buffer Info-tag-table-buffer (clone-buffer)))
2166 (let ((m Info-tag-table-marker))
2167 (when (and (markerp m) (marker-position m))
2168 (setq Info-tag-table-marker
2169 (with-current-buffer Info-tag-table-buffer
2170 (copy-marker (marker-position m))))))))
2172 (defvar Info-edit-map nil
2173 "Local keymap used within `e' command of Info.")
2174 (if Info-edit-map
2176 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
2177 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
2179 ;; Info-edit mode is suitable only for specially formatted data.
2180 (put 'Info-edit-mode 'mode-class 'special)
2182 (defun Info-edit-mode ()
2183 "Major mode for editing the contents of an Info node.
2184 Like text mode with the addition of `Info-cease-edit'
2185 which returns to Info mode for browsing.
2186 \\{Info-edit-map}"
2187 (use-local-map Info-edit-map)
2188 (setq major-mode 'Info-edit-mode)
2189 (setq mode-name "Info Edit")
2190 (kill-local-variable 'mode-line-buffer-identification)
2191 (setq buffer-read-only nil)
2192 (force-mode-line-update)
2193 (buffer-enable-undo (current-buffer))
2194 (run-hooks 'Info-edit-mode-hook))
2196 (defun Info-edit ()
2197 "Edit the contents of this Info node.
2198 Allowed only if variable `Info-enable-edit' is non-nil."
2199 (interactive)
2200 (or Info-enable-edit
2201 (error "Editing info nodes is not enabled"))
2202 (Info-edit-mode)
2203 (message "%s" (substitute-command-keys
2204 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2206 (defun Info-cease-edit ()
2207 "Finish editing Info node; switch back to Info proper."
2208 (interactive)
2209 ;; Do this first, so nothing has changed if user C-g's at query.
2210 (and (buffer-modified-p)
2211 (y-or-n-p "Save the file? ")
2212 (save-buffer))
2213 (use-local-map Info-mode-map)
2214 (setq major-mode 'Info-mode)
2215 (setq mode-name "Info")
2216 (Info-set-mode-line)
2217 (setq buffer-read-only t)
2218 (force-mode-line-update)
2219 (and (marker-position Info-tag-table-marker)
2220 (buffer-modified-p)
2221 (message "Tags may have changed. Use Info-tagify if necessary")))
2223 (defvar Info-file-list-for-emacs
2224 '("ediff" "forms" "gnus" ("mh" . "mh-e") "sc" "message"
2225 ("dired" . "dired-x") ("c" . "ccmode") "viper" "vip"
2226 ("skeleton" . "autotype") ("auto-insert" . "autotype")
2227 ("copyright" . "autotype") ("executable" . "autotype")
2228 ("time-stamp" . "autotype") ("quickurl" . "autotype")
2229 ("tempo" . "autotype") ("hippie-expand" . "autotype")
2230 ("cvs" . "pcl-cvs")
2231 "ebrowse" "cl" "idlwave" "reftex" "widget" "woman")
2232 "List of Info files that describe Emacs commands.
2233 An element can be a file name, or a list of the form (PREFIX . FILE)
2234 where PREFIX is a name prefix and FILE is the file to look in.
2235 If the element is just a file name, the file name also serves as the prefix.")
2237 (defun Info-find-emacs-command-nodes (command)
2238 "Return a list of locations documenting COMMAND.
2239 The `info-file' property of COMMAND says which Info manual to search.
2240 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2241 defines heuristics for which Info manual to try.
2242 The locations are of the format used in `Info-history', i.e.
2243 \(FILENAME NODENAME BUFFERPOS\)."
2244 (let ((where '())
2245 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
2246 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
2247 (info-file "emacs")) ;default
2248 ;; Determine which info file this command is documented in.
2249 (if (get command 'info-file)
2250 (setq info-file (get command 'info-file))
2251 ;; If it doesn't say explicitly, test its name against
2252 ;; various prefixes that we know.
2253 (let ((file-list Info-file-list-for-emacs))
2254 (while file-list
2255 (let* ((elt (car file-list))
2256 (name (if (consp elt)
2257 (car elt)
2258 elt))
2259 (file (if (consp elt) (cdr elt) elt))
2260 (regexp (concat "\\`" (regexp-quote name)
2261 "\\(\\'\\|-\\)")))
2262 (if (string-match regexp (symbol-name command))
2263 (setq info-file file file-list nil))
2264 (setq file-list (cdr file-list))))))
2265 (Info-find-node info-file "Top")
2266 (or (and (search-forward "\n* menu:" nil t)
2267 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2268 (error "Info file `%s' appears to lack an index" info-file))
2269 (goto-char (match-beginning 1))
2270 ;; Bind Info-history to nil, to prevent the index nodes from
2271 ;; getting into the node history.
2272 (let ((Info-history nil)
2273 (exact nil)
2274 node found)
2275 (Info-goto-node (Info-extract-menu-node-name))
2276 (while
2277 (progn
2278 (goto-char (point-min))
2279 (while (re-search-forward cmd-desc nil t)
2280 (setq where
2281 (cons (list Info-current-file
2282 (match-string-no-properties 2)
2284 where)))
2285 (and (setq node (Info-extract-pointer "next" t))
2286 (string-match "\\<Index\\>" node)))
2287 (Info-goto-node node)))
2288 where))
2290 ;;;###autoload
2291 (defun Info-goto-emacs-command-node (command)
2292 "Go to the Info node in the Emacs manual for command COMMAND.
2293 The command is found by looking up in Emacs manual's Command Index
2294 or in another manual found via COMMAND's `info-file' property or
2295 the variable `Info-file-list-for-emacs'."
2296 (interactive "CFind documentation for command: ")
2297 (or (commandp command)
2298 (signal 'wrong-type-argument (list 'commandp command)))
2299 (let ((where (Info-find-emacs-command-nodes command)))
2300 (if where
2301 (let ((num-matches (length where)))
2302 ;; Get Info running, and pop to it in another window.
2303 (save-window-excursion
2304 (info))
2305 ;; FIXME It would be cool if this could use a buffer other
2306 ;; than *info*.
2307 (pop-to-buffer "*info*")
2308 ;; Bind Info-history to nil, to prevent the last Index node
2309 ;; visited by Info-find-emacs-command-nodes from being
2310 ;; pushed onto the history.
2311 (let ((Info-history nil))
2312 (Info-find-node (car (car where))
2313 (car (cdr (car where)))))
2314 (if (> num-matches 1)
2315 (progn
2316 ;; (car where) will be pushed onto Info-history
2317 ;; when/if they go to another node. Put the other
2318 ;; nodes that were found on the history.
2319 (setq Info-history (nconc (cdr where) Info-history))
2320 (message "Found %d other entr%s. Use %s to see %s."
2321 (1- num-matches)
2322 (if (> num-matches 2) "ies" "y")
2323 (substitute-command-keys "\\[Info-last]")
2324 (if (> num-matches 2) "them" "it")))))
2325 (error "Couldn't find documentation for %s" command))))
2327 ;;;###autoload
2328 (defun Info-goto-emacs-key-command-node (key)
2329 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2330 Interactively, if the binding is `execute-extended-command', a command is read.
2331 The command is found by looking up in Emacs manual's Command Index
2332 or in another manual found via COMMAND's `info-file' property or
2333 the variable `Info-file-list-for-emacs'."
2334 (interactive "kFind documentation for key: ")
2335 (let ((command (key-binding key)))
2336 (cond ((null command)
2337 (message "%s is undefined" (key-description key)))
2338 ((and (interactive-p)
2339 (eq command 'execute-extended-command))
2340 (Info-goto-emacs-command-node
2341 (read-command "Find documentation for command: ")))
2343 (Info-goto-emacs-command-node command)))))
2345 (defface Info-title-1-face
2346 '((t (:height 1.2 :inherit Info-title-2-face)))
2347 "Face for Info titles at level 1."
2348 :group 'info)
2350 (defface Info-title-2-face
2351 '((t (:height 1.2 :inherit Info-title-3-face)))
2352 "Face for Info titles at level 2."
2353 :group 'info)
2355 (defface Info-title-3-face
2356 '((t (:height 1.2 :weight bold :inherit variable-pitch)))
2357 "Face for Info titles at level 3."
2358 :group 'info)
2360 (defun Info-fontify-node ()
2361 (save-excursion
2362 (let ((buffer-read-only nil)
2363 (case-fold-search t))
2364 (goto-char (point-min))
2365 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2366 (goto-char (match-end 0))
2367 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2368 (goto-char (match-end 0))
2369 (let* ((nbeg (match-beginning 2))
2370 (nend (match-end 2))
2371 (tbeg (match-beginning 1))
2372 (tag (buffer-substring tbeg (match-end 1))))
2373 (if (string-equal tag "Node")
2374 (put-text-property nbeg nend 'face 'info-header-node)
2375 (put-text-property nbeg nend 'face 'info-header-xref)
2376 (put-text-property nbeg nend 'mouse-face 'highlight)
2377 (put-text-property tbeg nend
2378 'help-echo
2379 (concat "Goto node "
2380 (buffer-substring nbeg nend)))
2381 (let ((fun (cdr (assoc tag '(("Prev" . Info-prev)
2382 ("Next" . Info-next)
2383 ("Up" . Info-up))))))
2384 (when fun
2385 (let ((keymap (make-sparse-keymap)))
2386 (define-key keymap [header-line mouse-1] fun)
2387 (define-key keymap [header-line mouse-2] fun)
2388 (put-text-property tbeg nend 'local-map keymap))))
2389 ))))
2390 (goto-char (point-min))
2391 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2392 nil t)
2393 (let ((c (preceding-char))
2394 face)
2395 (cond ((= c ?*) (setq face 'Info-title-1-face))
2396 ((= c ?=) (setq face 'Info-title-2-face))
2397 (t (setq face 'Info-title-3-face)))
2398 (put-text-property (match-beginning 1) (match-end 1)
2399 'face face))
2400 ;; This is a serious problem for trying to handle multiple
2401 ;; frame types at once. We want this text to be invisible
2402 ;; on frames that can display the font above.
2403 (if (memq (framep (selected-frame)) '(x pc w32))
2404 (add-text-properties (match-end 1) (match-end 2)
2405 '(invisible t intangible t))))
2406 (goto-char (point-min))
2407 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
2408 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2410 (put-text-property (match-beginning 1) (match-end 1)
2411 'face 'info-xref)
2412 (put-text-property (match-beginning 1) (match-end 1)
2413 'mouse-face 'highlight)))
2414 (goto-char (point-min))
2415 (if (and (search-forward "\n* Menu:" nil t)
2416 (not (string-match "\\<Index\\>" Info-current-node))
2417 ;; Don't take time to annotate huge menus
2418 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2419 (let ((n 0))
2420 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
2421 (setq n (1+ n))
2422 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
2423 (put-text-property (match-beginning 0)
2424 (1+ (match-beginning 0))
2425 'face 'info-menu-5))
2426 (put-text-property (match-beginning 1) (match-end 1)
2427 'face 'info-xref)
2428 (put-text-property (match-beginning 1) (match-end 1)
2429 'mouse-face 'highlight))))
2430 (set-buffer-modified-p nil))))
2433 ;; When an Info buffer is killed, make sure the associated tags buffer
2434 ;; is killed too.
2435 (defun Info-kill-buffer ()
2436 (and (eq major-mode 'Info-mode)
2437 Info-tag-table-buffer
2438 (kill-buffer Info-tag-table-buffer)))
2440 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2442 ;;; Speedbar support:
2443 ;; These functions permit speedbar to display the "tags" in the
2444 ;; current info node.
2445 (eval-when-compile (require 'speedbar))
2447 (defvar Info-speedbar-key-map nil
2448 "Keymap used when in the info display mode.")
2450 (defun Info-install-speedbar-variables ()
2451 "Install those variables used by speedbar to enhance Info."
2452 (if Info-speedbar-key-map
2454 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2456 ;; Basic tree features
2457 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2458 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2459 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2460 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2463 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2464 Info-speedbar-key-map
2465 Info-speedbar-hierarchy-buttons)))
2467 (defvar Info-speedbar-menu-items
2468 '(["Browse Node" speedbar-edit-line t]
2469 ["Expand Node" speedbar-expand-line
2470 (save-excursion (beginning-of-line)
2471 (looking-at "[0-9]+: *.\\+. "))]
2472 ["Contract Node" speedbar-contract-line
2473 (save-excursion (beginning-of-line)
2474 (looking-at "[0-9]+: *.-. "))]
2476 "Additional menu-items to add to speedbar frame.")
2478 ;; Make sure our special speedbar major mode is loaded
2479 (if (featurep 'speedbar)
2480 (Info-install-speedbar-variables)
2481 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2483 ;;; Info hierarchy display method
2484 ;;;###autoload
2485 (defun Info-speedbar-browser ()
2486 "Initialize speedbar to display an info node browser.
2487 This will add a speedbar major display mode."
2488 (interactive)
2489 (require 'speedbar)
2490 ;; Make sure that speedbar is active
2491 (speedbar-frame-mode 1)
2492 ;; Now, throw us into Info mode on speedbar.
2493 (speedbar-change-initial-expansion-list "Info")
2496 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2497 "Display an Info directory hierarchy in speedbar.
2498 DIRECTORY is the current directory in the attached frame.
2499 DEPTH is the current indentation depth.
2500 NODE is an optional argument that is used to represent the
2501 specific node to expand."
2502 (if (and (not node)
2503 (save-excursion (goto-char (point-min))
2504 (let ((case-fold-search t))
2505 (looking-at "Info Nodes:"))))
2506 ;; Update our "current node" maybe?
2508 ;; We cannot use the generic list code, that depends on all leaves
2509 ;; being known at creation time.
2510 (if (not node)
2511 (speedbar-with-writable (insert "Info Nodes:\n")))
2512 (let ((completions nil)
2513 (cf (selected-frame)))
2514 (select-frame speedbar-attached-frame)
2515 (save-window-excursion
2516 (setq completions
2517 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
2518 (select-frame cf)
2519 (if completions
2520 (speedbar-with-writable
2521 (while completions
2522 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2523 (cdr (car completions))
2524 (car (car completions))
2525 'Info-speedbar-goto-node
2526 (cdr (car completions))
2527 'info-xref depth)
2528 (setq completions (cdr completions)))
2530 nil))))
2532 (defun Info-speedbar-goto-node (text node indent)
2533 "When user clicks on TEXT, goto an info NODE.
2534 The INDENT level is ignored."
2535 (select-frame speedbar-attached-frame)
2536 (let* ((buff (or (get-buffer "*info*")
2537 (progn (info) (get-buffer "*info*"))))
2538 (bwin (get-buffer-window buff 0)))
2539 (if bwin
2540 (progn
2541 (select-window bwin)
2542 (raise-frame (window-frame bwin)))
2543 (if speedbar-power-click
2544 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2545 (select-frame speedbar-attached-frame)
2546 (switch-to-buffer buff)))
2547 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
2548 (file (match-string 1 node))
2549 (node (match-string 2 node)))
2550 (Info-find-node file node)
2551 ;; If we do a find-node, and we were in info mode, restore
2552 ;; the old default method. Once we are in info mode, it makes
2553 ;; sense to return to whatever method the user was using before.
2554 (if (string= speedbar-initial-expansion-list-name "Info")
2555 (speedbar-change-initial-expansion-list
2556 speedbar-previously-used-expansion-list-name)))))
2558 (defun Info-speedbar-expand-node (text token indent)
2559 "Expand the node the user clicked on.
2560 TEXT is the text of the button we clicked on, a + or - item.
2561 TOKEN is data related to this node (NAME . FILE).
2562 INDENT is the current indentation depth."
2563 (cond ((string-match "+" text) ;we have to expand this file
2564 (speedbar-change-expand-button-char ?-)
2565 (if (speedbar-with-writable
2566 (save-excursion
2567 (end-of-line) (forward-char 1)
2568 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
2569 (speedbar-change-expand-button-char ?-)
2570 (speedbar-change-expand-button-char ??)))
2571 ((string-match "-" text) ;we have to contract this node
2572 (speedbar-change-expand-button-char ?+)
2573 (speedbar-delete-subblock indent))
2574 (t (error "Ooops... not sure what to do")))
2575 (speedbar-center-buffer-smartly))
2577 (defun Info-speedbar-fetch-file-nodes (nodespec)
2578 "Fetch the subnodes from the info NODESPEC.
2579 NODESPEC is a string of the form: (file)node.
2580 Optional THISFILE represends the filename of"
2581 (save-excursion
2582 ;; Set up a buffer we can use to fake-out Info.
2583 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2584 (if (not (equal major-mode 'Info-mode))
2585 (Info-mode))
2586 ;; Get the node into this buffer
2587 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
2588 (file (match-string 1 nodespec))
2589 (node (match-string 2 nodespec)))
2590 (Info-find-node file node))
2591 ;; Scan the created buffer
2592 (goto-char (point-min))
2593 (let ((completions nil)
2594 (case-fold-search t)
2595 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
2596 (match-string 1 nodespec))))
2597 ;; Always skip the first one...
2598 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2599 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2600 (let ((name (match-string 1)))
2601 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2602 (setq name (cons name (match-string 1)))
2603 (if (looking-at " *\\(([^)]+)\\)\\.")
2604 (setq name (cons name (concat (match-string 1) "Top")))
2605 (if (looking-at " \\([^.]+\\).")
2606 (setq name
2607 (cons name (concat "(" thisfile ")" (match-string 1))))
2608 (setq name (cons name (concat "(" thisfile ")" name))))))
2609 (setq completions (cons name completions))))
2610 (nreverse completions))))
2612 ;;; Info mode node listing
2613 (defun Info-speedbar-buttons (buffer)
2614 "Create a speedbar display to help navigation in an Info file.
2615 BUFFER is the buffer speedbar is requesting buttons for."
2616 (if (save-excursion (goto-char (point-min))
2617 (let ((case-fold-search t))
2618 (not (looking-at "Info Nodes:"))))
2619 (erase-buffer))
2620 (Info-speedbar-hierarchy-buttons nil 0)
2623 (dolist (mess '("^Node has no Previous$"
2624 "^No menu in this node$"
2625 "^Node has no Next$"
2626 "^No cross-references in this node^"
2627 search-failed
2628 "^No \".*\" in index$"))
2629 (add-to-list 'debug-ignored-errors mess))
2631 (provide 'info)
2633 ;;; info.el ends here