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