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