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