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