]> code.delx.au - gnu-emacs/blob - lisp/info.el
(time-stamp-string-preprocess): Add %U code.
[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 Free Software
4 ;; Foundation, Inc.
5
6 ;; Maintainer: FSF
7 ;; Keywords: help
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Note that nowadays we expect info files to be made using makeinfo.
29
30 ;;; Code:
31
32 (defgroup info nil
33 "Info subsystem"
34 :group 'help
35 :group 'docs)
36
37
38 (defvar Info-history nil
39 "List of info nodes user has visited.
40 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
41
42 (defcustom Info-enable-edit nil
43 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
44 This is convenient if you want to write info files by hand.
45 However, we recommend that you not do this.
46 It is better to write a Texinfo file and generate the Info file from that,
47 because that gives you a printed manual as well."
48 :type 'boolean
49 :group 'info)
50
51 (defvar Info-enable-active-nodes nil
52 "Non-nil allows Info to execute Lisp code associated with nodes.
53 The Lisp code is executed when the node is selected.")
54 (put 'Info-enable-active-nodes 'risky-local-variable t)
55
56 (defcustom Info-fontify t
57 "*Non-nil enables highlighting and fonts in Info nodes."
58 :type 'boolean
59 :group 'info)
60
61 (defface info-node
62 '((t (:bold t :italic t)))
63 "Face for Info node names."
64 :group 'info)
65
66 (defface info-menu-5
67 '((t (:underline t)))
68 "Face for the fifth and tenth `*' in an Info menu."
69 :group 'info)
70
71 (defface info-xref
72 '((t (:bold t)))
73 "Face for Info cross-references."
74 :group 'info)
75
76 (defcustom Info-fontify-maximum-menu-size 30000
77 "*Maximum size of menu to fontify if `Info-fontify' is non-nil."
78 :type 'integer
79 :group 'info)
80
81 (defvar Info-directory-list
82 (let ((path (getenv "INFOPATH"))
83 ;; This is for older Emacs versions
84 ;; which might get this info.el from the Texinfo distribution.
85 (path-separator (if (boundp 'path-separator) path-separator
86 (if (eq system-type 'ms-dos) ";" ":")))
87 (source (expand-file-name "info/" source-directory))
88 (sibling (if installation-directory
89 (expand-file-name "info/" installation-directory)))
90 alternative)
91 (if path
92 (let ((list nil)
93 idx)
94 (while (> (length path) 0)
95 (setq idx (or (string-match path-separator path) (length path))
96 list (cons (substring path 0 idx) list)
97 path (substring path (min (1+ idx)
98 (length path)))))
99 (nreverse list))
100 (if (and sibling (file-exists-p sibling))
101 (setq alternative sibling)
102 (setq alternative source))
103 (if (or (member alternative Info-default-directory-list)
104 (not (file-exists-p alternative))
105 ;; On DOS/NT, we use movable executables always,
106 ;; and we must always find the Info dir at run time.
107 (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
108 nil
109 ;; Use invocation-directory for Info only if we used it for
110 ;; exec-directory also.
111 (not (string= exec-directory
112 (expand-file-name "lib-src/"
113 installation-directory)))))
114 Info-default-directory-list
115 (reverse (cons alternative
116 (cdr (reverse Info-default-directory-list)))))))
117 "List of directories to search for Info documentation files.
118 nil means not yet initialized. In this case, Info uses the environment
119 variable INFOPATH to initialize it, or `Info-default-directory-list'
120 if there is no INFOPATH variable in the environment.
121 The last element of `Info-default-directory-list' is the directory
122 where Emacs installs the Info files that come with it.
123
124 If you run the Emacs executable from the `src' directory in the Emacs
125 source tree, the `info' directory in the source tree is used as the last
126 element, in place of the installation Info directory. This is useful
127 when you run a version of Emacs without installing it.")
128
129 (defcustom Info-additional-directory-list nil
130 "List of additional directories to search for Info documentation files.
131 These directories are not searched for merging the `dir' file."
132 :type '(repeat directory)
133 :group 'info)
134
135 (defvar Info-current-file nil
136 "Info file that Info is now looking at, or nil.
137 This is the name that was specified in Info, not the actual file name.
138 It doesn't contain directory names or file name extensions added by Info.")
139
140 (defvar Info-current-subfile nil
141 "Info subfile that is actually in the *info* buffer now,
142 or nil if current info file is not split into subfiles.")
143
144 (defvar Info-current-node nil
145 "Name of node that Info is now looking at, or nil.")
146
147 (defvar Info-tag-table-marker nil
148 "Marker pointing at beginning of current Info file's tag table.
149 Marker points nowhere if file has no tag table.")
150
151 (defvar Info-tag-table-buffer nil
152 "Buffer used for indirect tag tables.")
153
154 (defvar Info-current-file-completions nil
155 "Cached completion list for current Info file.")
156
157 (defvar Info-index-alternatives nil
158 "List of possible matches for last Info-index command.")
159
160 (defvar Info-standalone nil
161 "Non-nil if Emacs was started solely as an Info browser.")
162
163 (defvar Info-suffix-list
164 ;; The MS-DOS list should work both when long file names are
165 ;; supported (Windows 9X), and when only 8+3 file names are available.
166 (if (eq system-type 'ms-dos)
167 '( (".gz" . "gunzip")
168 (".z" . "gunzip")
169 (".inz" . "gunzip")
170 (".igz" . "gunzip")
171 (".info.Z" . "gunzip")
172 (".info.gz" . "gunzip")
173 ("-info.Z" . "gunzip")
174 ("-info.gz" . "gunzip")
175 ("/index.gz". "gunzip")
176 ("/index.z" . "gunzip")
177 (".inf" . nil)
178 (".info" . nil)
179 ("-info" . nil)
180 ("/index" . nil)
181 ("" . nil))
182 '( (".info.Z". "uncompress")
183 (".info.Y". "unyabba")
184 (".info.gz". "gunzip")
185 (".info.z". "gunzip")
186 (".info". nil)
187 ("-info.Z". "uncompress")
188 ("-info.Y". "unyabba")
189 ("-info.gz". "gunzip")
190 ("-info.z". "gunzip")
191 ("-info". nil)
192 ("/index.Z". "uncompress")
193 ("/index.Y". "unyabba")
194 ("/index.gz". "gunzip")
195 ("/index.z". "gunzip")
196 ("/index". nil)
197 (".Z". "uncompress")
198 (".Y". "unyabba")
199 (".gz". "gunzip")
200 (".z". "gunzip")
201 ("". nil)))
202 "List of file name suffixes and associated decoding commands.
203 Each entry should be (SUFFIX . STRING); the file is given to
204 the command as standard input. If STRING is nil, no decoding is done.
205 Because the SUFFIXes are tried in order, the empty string should
206 be last in the list.")
207
208 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
209 ;; First, on ms-dos, delete some of the extension in FILENAME
210 ;; to make room.
211 (defun info-insert-file-contents-1 (filename suffix)
212 (if (not (eq system-type 'ms-dos))
213 (concat filename suffix)
214 (let* ((sans-exts (file-name-sans-extension filename))
215 ;; How long is the extension in FILENAME (not counting the dot).
216 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
217 ext-left)
218 ;; SUFFIX starts with a dot. If FILENAME already has one,
219 ;; get rid of the one in SUFFIX (unless suffix is empty).
220 (or (and (<= ext-len 0)
221 (not (eq (aref filename (1- (length filename))) ?.)))
222 (= (length suffix) 0)
223 (setq suffix (substring suffix 1)))
224 ;; How many chars of that extension should we keep?
225 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
226 ;; Get rid of the rest of the extension, and add SUFFIX.
227 (concat (substring filename 0 (- (length filename)
228 (- ext-len ext-left)))
229 suffix))))
230
231 (defun info-file-exists-p (filename)
232 (and (file-exists-p filename)
233 (not (file-directory-p filename))))
234
235 (defun info-insert-file-contents (filename &optional visit)
236 "Insert the contents of an info file in the current buffer.
237 Do the right thing if the file has been compressed or zipped."
238 (let ((tail Info-suffix-list)
239 fullname decoder)
240 (if (file-exists-p filename)
241 ;; FILENAME exists--see if that name contains a suffix.
242 ;; If so, set DECODE accordingly.
243 (progn
244 (while (and tail
245 (not (string-match
246 (concat (regexp-quote (car (car tail))) "$")
247 filename)))
248 (setq tail (cdr tail)))
249 (setq fullname filename
250 decoder (cdr (car tail))))
251 ;; Try adding suffixes to FILENAME and see if we can find something.
252 (while (and tail
253 (not (info-file-exists-p (info-insert-file-contents-1
254 filename (car (car tail))))))
255 (setq tail (cdr tail)))
256 ;; If we found a file with a suffix, set DECODER according to the suffix
257 ;; and set FULLNAME to the file's actual name.
258 (setq fullname (info-insert-file-contents-1 filename (car (car tail)))
259 decoder (cdr (car tail)))
260 (or tail
261 (error "Can't find %s or any compressed version of it" filename)))
262 ;; check for conflict with jka-compr
263 (if (and (featurep 'jka-compr)
264 (jka-compr-installed-p)
265 (jka-compr-get-compression-info fullname))
266 (setq decoder nil))
267 (if decoder
268 (progn
269 (insert-file-contents-literally fullname visit)
270 (let ((buffer-read-only nil)
271 (coding-system-for-write 'no-conversion)
272 (default-directory (or (file-name-directory fullname)
273 default-directory)))
274 (call-process-region (point-min) (point-max) decoder t t)))
275 (insert-file-contents fullname visit))))
276
277 ;;;###autoload
278 (defun info-other-window (&optional file)
279 "Like `info' but show the Info buffer in another window."
280 (interactive (if current-prefix-arg
281 (list (read-file-name "Info file name: " nil nil t))))
282 (let (same-window-buffer-names)
283 (info file)))
284
285 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
286
287 ;;;###autoload
288 (defun info (&optional file)
289 "Enter Info, the documentation browser.
290 Optional argument FILE specifies the file to examine;
291 the default is the top-level directory of Info.
292
293 In interactive use, a prefix argument directs this command
294 to read a file name from the minibuffer.
295
296 The search path for Info files is in the variable `Info-directory-list'.
297 The top-level Info directory is made by combining all the files named `dir'
298 in all the directories in that path."
299 (interactive (if current-prefix-arg
300 (list (read-file-name "Info file name: " nil nil t))))
301 (if file
302 (progn (pop-to-buffer "*info*")
303 (Info-goto-node (concat "(" file ")")))
304 (if (get-buffer "*info*")
305 (pop-to-buffer "*info*")
306 (Info-directory))))
307
308 ;;;###autoload
309 (defun info-standalone ()
310 "Run Emacs as a standalone Info reader.
311 Usage: emacs -f info-standalone [filename]
312 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
313 (setq Info-standalone t)
314 (if (and command-line-args-left
315 (not (string-match "^-" (car command-line-args-left))))
316 (condition-case err
317 (progn
318 (info (car command-line-args-left))
319 (setq command-line-args-left (cdr command-line-args-left)))
320 (error (send-string-to-terminal
321 (format "%s\n" (if (eq (car-safe err) 'error)
322 (nth 1 err) err)))
323 (save-buffers-kill-emacs)))
324 (info)))
325
326 ;; Go to an info node specified as separate filename and nodename.
327 ;; no-going-back is non-nil if recovering from an error in this function;
328 ;; it says do not attempt further (recursive) error recovery.
329 (defun Info-find-node (filename nodename &optional no-going-back)
330 ;; Convert filename to lower case if not found as specified.
331 ;; Expand it.
332 (if filename
333 (let (temp temp-downcase found)
334 (setq filename (substitute-in-file-name filename))
335 (if (string= (downcase filename) "dir")
336 (setq found t)
337 (let ((dirs (if (string-match "^\\./" filename)
338 ;; If specified name starts with `./'
339 ;; then just try current directory.
340 '("./")
341 (if (file-name-absolute-p filename)
342 ;; No point in searching for an
343 ;; absolute file name
344 '(nil)
345 (if Info-additional-directory-list
346 (append Info-directory-list
347 Info-additional-directory-list)
348 Info-directory-list)))))
349 ;; Search the directory list for file FILENAME.
350 (while (and dirs (not found))
351 (setq temp (expand-file-name filename (car dirs)))
352 (setq temp-downcase
353 (expand-file-name (downcase filename) (car dirs)))
354 ;; Try several variants of specified name.
355 (let ((suffix-list Info-suffix-list))
356 (while (and suffix-list (not found))
357 (cond ((info-file-exists-p
358 (info-insert-file-contents-1
359 temp (car (car suffix-list))))
360 (setq found temp))
361 ((info-file-exists-p
362 (info-insert-file-contents-1
363 temp-downcase (car (car suffix-list))))
364 (setq found temp-downcase)))
365 (setq suffix-list (cdr suffix-list))))
366 (setq dirs (cdr dirs)))))
367 (if found
368 (setq filename found)
369 (error "Info file %s does not exist" filename))))
370 ;; Record the node we are leaving.
371 (if (and Info-current-file (not no-going-back))
372 (setq Info-history
373 (cons (list Info-current-file Info-current-node (point))
374 Info-history)))
375 ;; Go into info buffer.
376 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
377 (buffer-disable-undo (current-buffer))
378 (or (eq major-mode 'Info-mode)
379 (Info-mode))
380 (widen)
381 (setq Info-current-node nil)
382 (unwind-protect
383 ;; Bind case-fold-search in case the user sets it to nil.
384 (let ((case-fold-search t))
385 ;; Switch files if necessary
386 (or (null filename)
387 (equal Info-current-file filename)
388 (let ((buffer-read-only nil))
389 (setq Info-current-file nil
390 Info-current-subfile nil
391 Info-current-file-completions nil
392 buffer-file-name nil)
393 (erase-buffer)
394 (if (eq filename t)
395 (Info-insert-dir)
396 (info-insert-file-contents filename t)
397 (setq default-directory (file-name-directory filename)))
398 (set-buffer-modified-p nil)
399 ;; See whether file has a tag table. Record the location if yes.
400 (goto-char (point-max))
401 (forward-line -8)
402 ;; Use string-equal, not equal, to ignore text props.
403 (if (not (or (string-equal nodename "*")
404 (not
405 (search-forward "\^_\nEnd tag table\n" nil t))))
406 (let (pos)
407 ;; We have a tag table. Find its beginning.
408 ;; Is this an indirect file?
409 (search-backward "\nTag table:\n")
410 (setq pos (point))
411 (if (save-excursion
412 (forward-line 2)
413 (looking-at "(Indirect)\n"))
414 ;; It is indirect. Copy it to another buffer
415 ;; and record that the tag table is in that buffer.
416 (let ((buf (current-buffer))
417 (tagbuf
418 (or Info-tag-table-buffer
419 (generate-new-buffer " *info tag table*"))))
420 (setq Info-tag-table-buffer tagbuf)
421 (save-excursion
422 (set-buffer tagbuf)
423 (buffer-disable-undo (current-buffer))
424 (setq case-fold-search t)
425 (erase-buffer)
426 (insert-buffer-substring buf))
427 (set-marker Info-tag-table-marker
428 (match-end 0) tagbuf))
429 (set-marker Info-tag-table-marker pos)))
430 (set-marker Info-tag-table-marker nil))
431 (setq Info-current-file
432 (if (eq filename t) "dir" filename))))
433 ;; Use string-equal, not equal, to ignore text props.
434 (if (string-equal nodename "*")
435 (progn (setq Info-current-node nodename)
436 (Info-set-mode-line))
437 ;; Possibilities:
438 ;;
439 ;; 1. Anchor found in tag table
440 ;; 2. Anchor *not* in tag table
441 ;;
442 ;; 3. Node found in tag table
443 ;; 4. Node *not* found in tag table, but found in file
444 ;; 5. Node *not* in tag table, and *not* in file
445 ;;
446 ;; *Or* the same, but in an indirect subfile.
447
448 ;; Search file for a suitable node.
449 (let ((guesspos (point-min))
450 (regexp
451 (concat "\\(Node:\\|Ref:\\) *"
452 (regexp-quote nodename)
453 " *[,\t\n\177]")))
454
455 ;; First, search a tag table, if any
456 (if (marker-position Info-tag-table-marker)
457
458 (let (found-in-tag-table
459 found-mode
460 (m Info-tag-table-marker))
461 (save-excursion
462 (set-buffer (marker-buffer m))
463 (goto-char m)
464 (beginning-of-line) ; so re-search will work.
465
466 ;; Search tag table
467 (setq found-in-tag-table
468 (re-search-forward regexp nil t))
469 (if found-in-tag-table
470 (setq guesspos (read (current-buffer))))
471 (setq found-mode major-mode))
472
473 ;; Indirect file among split files
474 (if found-in-tag-table
475 (progn
476 ;; If this is an indirect file, determine
477 ;; which file really holds this node and
478 ;; read it in.
479 (if (not (eq found-mode 'Info-mode))
480 ;; Note that the current buffer must be
481 ;; the *info* buffer on entry to
482 ;; Info-read-subfile. Thus the hackery
483 ;; above.
484 (setq guesspos (Info-read-subfile guesspos)))))
485
486 ;; Handle anchor
487 (if (and found-in-tag-table
488 (string-equal "Ref:" (match-string 1)))
489 (goto-char guesspos)
490
491 ;; Else we may have a node, which we search for:
492 (goto-char (max (point-min)
493 (- (byte-to-position guesspos) 1000)))
494 ;; Now search from our advised position
495 ;; (or from beg of buffer)
496 ;; to find the actual node.
497 (catch 'foo
498 (while (search-forward "\n\^_" nil t)
499 (forward-line 1)
500 (let ((beg (point)))
501 (forward-line 1)
502 (if (re-search-backward regexp beg t)
503 (progn
504 (beginning-of-line)
505 (throw 'foo t)))))
506 (error
507 "No such anchor in tag table or node in tag table or file: %s"
508 nodename))))))
509
510 (Info-select-node)
511 (goto-char (point-min))))
512 ;; If we did not finish finding the specified node,
513 ;; go back to the previous one.
514 (or Info-current-node no-going-back (null Info-history)
515 (let ((hist (car Info-history)))
516 (setq Info-history (cdr Info-history))
517 (Info-find-node (nth 0 hist) (nth 1 hist) t)
518 (goto-char (nth 2 hist))))))
519
520 ;; Cache the contents of the (virtual) dir file, once we have merged
521 ;; it for the first time, so we can save time subsequently.
522 (defvar Info-dir-contents nil)
523
524 ;; Cache for the directory we decided to use for the default-directory
525 ;; of the merged dir text.
526 (defvar Info-dir-contents-directory nil)
527
528 ;; Record the file attributes of all the files from which we
529 ;; constructed Info-dir-contents.
530 (defvar Info-dir-file-attributes nil)
531
532 ;; Construct the Info directory node by merging the files named `dir'
533 ;; from various directories. Set the *info* buffer's
534 ;; default-directory to the first directory we actually get any text
535 ;; from.
536 (defun Info-insert-dir ()
537 (if (and Info-dir-contents Info-dir-file-attributes
538 ;; Verify that none of the files we used has changed
539 ;; since we used it.
540 (eval (cons 'and
541 (mapcar '(lambda (elt)
542 (let ((curr (file-attributes (car elt))))
543 ;; Don't compare the access time.
544 (if curr (setcar (nthcdr 4 curr) 0))
545 (setcar (nthcdr 4 (cdr elt)) 0)
546 (equal (cdr elt) curr)))
547 Info-dir-file-attributes))))
548 (insert Info-dir-contents)
549 (let ((dirs Info-directory-list)
550 ;; Bind this in case the user sets it to nil.
551 (case-fold-search t)
552 buffers buffer others nodes dirs-done)
553
554 (setq Info-dir-file-attributes nil)
555
556 ;; Search the directory list for the directory file.
557 (while dirs
558 (let ((truename (file-truename (expand-file-name (car dirs)))))
559 (or (member truename dirs-done)
560 (member (directory-file-name truename) dirs-done)
561 ;; Try several variants of specified name.
562 ;; Try upcasing, appending `.info', or both.
563 (let* (file
564 (attrs
565 (or
566 (progn (setq file (expand-file-name "dir" truename))
567 (file-attributes file))
568 (progn (setq file (expand-file-name "DIR" truename))
569 (file-attributes file))
570 (progn (setq file (expand-file-name "dir.info" truename))
571 (file-attributes file))
572 (progn (setq file (expand-file-name "DIR.INFO" truename))
573 (file-attributes file)))))
574 (setq dirs-done
575 (cons truename
576 (cons (directory-file-name truename)
577 dirs-done)))
578 (if attrs
579 (save-excursion
580 (or buffers
581 (message "Composing main Info directory..."))
582 (set-buffer (generate-new-buffer " info dir"))
583 (condition-case nil
584 (progn
585 (insert-file-contents file)
586 (setq buffers (cons (current-buffer) buffers)
587 Info-dir-file-attributes
588 (cons (cons file attrs)
589 Info-dir-file-attributes)))
590 (error (kill-buffer (current-buffer))))))))
591 (or (cdr dirs) (setq Info-dir-contents-directory
592 (file-name-as-directory (car dirs))))
593 (setq dirs (cdr dirs))))
594
595 (or buffers
596 (error "Can't find the Info directory node"))
597 ;; Distinguish the dir file that comes with Emacs from all the
598 ;; others. Yes, that is really what this is supposed to do.
599 ;; If it doesn't work, fix it.
600 (setq buffer (car buffers)
601 others (cdr buffers))
602
603 ;; Insert the entire original dir file as a start; note that we've
604 ;; already saved its default directory to use as the default
605 ;; directory for the whole concatenation.
606 (insert-buffer buffer)
607
608 ;; Look at each of the other buffers one by one.
609 (while others
610 (let ((other (car others)))
611 ;; In each, find all the menus.
612 (save-excursion
613 (set-buffer other)
614 (goto-char (point-min))
615 ;; Find each menu, and add an elt to NODES for it.
616 (while (re-search-forward "^\\* Menu:" nil t)
617 (let (beg nodename end)
618 (forward-line 1)
619 (setq beg (point))
620 (search-backward "\n\^_")
621 (search-forward "Node: ")
622 (setq nodename (Info-following-node-name))
623 (search-forward "\n\^_" nil 'move)
624 (beginning-of-line)
625 (setq end (point))
626 (setq nodes (cons (list nodename other beg end) nodes))))))
627 (setq others (cdr others)))
628 ;; Add to the main menu a menu item for each other node.
629 (re-search-forward "^\\* Menu:")
630 (forward-line 1)
631 (let ((menu-items '("top"))
632 (nodes nodes)
633 (case-fold-search t)
634 (end (save-excursion (search-forward "\^_" nil t) (point))))
635 (while nodes
636 (let ((nodename (car (car nodes))))
637 (save-excursion
638 (or (member (downcase nodename) menu-items)
639 (re-search-forward (concat "^\\* +"
640 (regexp-quote nodename)
641 "::")
642 end t)
643 (progn
644 (insert "* " nodename "::" "\n")
645 (setq menu-items (cons nodename menu-items))))))
646 (setq nodes (cdr nodes))))
647 ;; Now take each node of each of the other buffers
648 ;; and merge it into the main buffer.
649 (while nodes
650 (let ((nodename (car (car nodes))))
651 (goto-char (point-min))
652 ;; Find the like-named node in the main buffer.
653 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
654 (regexp-quote nodename)
655 "[,\n\t]")
656 nil t)
657 (progn
658 (search-forward "\n\^_" nil 'move)
659 (beginning-of-line)
660 (insert "\n"))
661 ;; If none exists, add one.
662 (goto-char (point-max))
663 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
664 ;; Merge the text from the other buffer's menu
665 ;; into the menu in the like-named node in the main buffer.
666 (apply 'insert-buffer-substring (cdr (car nodes))))
667 (setq nodes (cdr nodes)))
668 ;; Kill all the buffers we just made.
669 (while buffers
670 (kill-buffer (car buffers))
671 (setq buffers (cdr buffers)))
672 (message "Composing main Info directory...done"))
673 (setq Info-dir-contents (buffer-string)))
674 (setq default-directory Info-dir-contents-directory))
675
676 ;; Note that on entry to this function the current-buffer must be the
677 ;; *info* buffer; not the info tags buffer.
678 (defun Info-read-subfile (nodepos)
679 ;; NODEPOS is either a position (in the Info file as a whole,
680 ;; not relative to a subfile) or the name of a subfile.
681 (let (lastfilepos
682 lastfilename)
683 (if (numberp nodepos)
684 (save-excursion
685 (set-buffer (marker-buffer Info-tag-table-marker))
686 (goto-char (point-min))
687 (search-forward "\n\^_")
688 (forward-line 2)
689 (catch 'foo
690 (while (not (looking-at "\^_"))
691 (if (not (eolp))
692 (let ((beg (point))
693 thisfilepos thisfilename)
694 (search-forward ": ")
695 (setq thisfilename (buffer-substring beg (- (point) 2)))
696 (setq thisfilepos (read (current-buffer)))
697 ;; read in version 19 stops at the end of number.
698 ;; Advance to the next line.
699 (forward-line 1)
700 (if (> thisfilepos nodepos)
701 (throw 'foo t))
702 (setq lastfilename thisfilename)
703 (setq lastfilepos thisfilepos))
704 (forward-line 1)))))
705 (setq lastfilename nodepos)
706 (setq lastfilepos 0))
707 ;; Assume previous buffer is in Info-mode.
708 ;; (set-buffer (get-buffer "*info*"))
709 (or (equal Info-current-subfile lastfilename)
710 (let ((buffer-read-only nil))
711 (setq buffer-file-name nil)
712 (widen)
713 (erase-buffer)
714 (info-insert-file-contents lastfilename)
715 (set-buffer-modified-p nil)
716 (setq Info-current-subfile lastfilename)))
717 (goto-char (point-min))
718 (search-forward "\n\^_")
719 (if (numberp nodepos)
720 (+ (- nodepos lastfilepos) (point)))))
721
722 ;; Select the info node that point is in.
723 (defun Info-select-node ()
724 ;; Bind this in case the user sets it to nil.
725 (let ((case-fold-search t))
726 (save-excursion
727 ;; Find beginning of node.
728 (search-backward "\n\^_")
729 (forward-line 2)
730 ;; Get nodename spelled as it is in the node.
731 (re-search-forward "Node:[ \t]*")
732 (setq Info-current-node
733 (buffer-substring-no-properties (point)
734 (progn
735 (skip-chars-forward "^,\t\n")
736 (point))))
737 (Info-set-mode-line)
738 ;; Find the end of it, and narrow.
739 (beginning-of-line)
740 (let (active-expression)
741 (narrow-to-region (point)
742 (if (re-search-forward "\n[\^_\f]" nil t)
743 (prog1
744 (1- (point))
745 (if (looking-at "[\n\^_\f]*execute: ")
746 (progn
747 (goto-char (match-end 0))
748 (setq active-expression
749 (read (current-buffer))))))
750 (point-max)))
751 (if Info-enable-active-nodes (eval active-expression))
752 (if Info-fontify (Info-fontify-node))
753 (run-hooks 'Info-selection-hook)))))
754
755 (defun Info-set-mode-line ()
756 (setq mode-line-buffer-identification
757 (concat
758 " Info: ("
759 (if Info-current-file
760 (file-name-nondirectory Info-current-file)
761 "")
762 ")"
763 (or Info-current-node ""))))
764 \f
765 ;; Go to an info node specified with a filename-and-nodename string
766 ;; of the sort that is found in pointers in nodes.
767
768 (defun Info-goto-node (nodename)
769 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
770 (interactive (list (Info-read-node-name "Goto node: ")))
771 (let (filename)
772 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
773 nodename)
774 (setq filename (if (= (match-beginning 1) (match-end 1))
775 ""
776 (substring nodename (match-beginning 2) (match-end 2)))
777 nodename (substring nodename (match-beginning 3) (match-end 3)))
778 (let ((trim (string-match "\\s *\\'" filename)))
779 (if trim (setq filename (substring filename 0 trim))))
780 (let ((trim (string-match "\\s *\\'" nodename)))
781 (if trim (setq nodename (substring nodename 0 trim))))
782 (if transient-mark-mode (deactivate-mark))
783 (Info-find-node (if (equal filename "") nil filename)
784 (if (equal nodename "") "Top" nodename))))
785
786 (defvar Info-read-node-completion-table)
787
788 ;; This function is used as the "completion table" while reading a node name.
789 ;; It does completion using the alist in Info-read-node-completion-table
790 ;; unless STRING starts with an open-paren.
791 (defun Info-read-node-name-1 (string predicate code)
792 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
793 (cond ((eq code nil)
794 (if no-completion
795 string
796 (try-completion string Info-read-node-completion-table predicate)))
797 ((eq code t)
798 (if no-completion
799 nil
800 (all-completions string Info-read-node-completion-table predicate)))
801 ((eq code 'lambda)
802 (if no-completion
803 t
804 (assoc string Info-read-node-completion-table))))))
805
806 (defun Info-read-node-name (prompt &optional default)
807 (let* ((completion-ignore-case t)
808 (Info-read-node-completion-table (Info-build-node-completions))
809 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
810 (if (equal nodename "")
811 (or default
812 (Info-read-node-name prompt))
813 nodename)))
814
815 (defun Info-build-node-completions ()
816 (or Info-current-file-completions
817 (let ((compl nil)
818 ;; Bind this in case the user sets it to nil.
819 (case-fold-search t))
820 (save-excursion
821 (save-restriction
822 (if (marker-buffer Info-tag-table-marker)
823 (let ((marker Info-tag-table-marker))
824 (set-buffer (marker-buffer marker))
825 (widen)
826 (goto-char marker)
827 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
828 (setq compl
829 (cons (list (buffer-substring (match-beginning 1)
830 (match-end 1)))
831 compl))))
832 (widen)
833 (goto-char (point-min))
834 (while (search-forward "\n\^_" nil t)
835 (forward-line 1)
836 (let ((beg (point)))
837 (forward-line 1)
838 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
839 beg t)
840 (setq compl
841 (cons (list (buffer-substring (match-beginning 1)
842 (match-end 1)))
843 compl))))))))
844 (setq Info-current-file-completions compl))))
845 \f
846 (defun Info-restore-point (hl)
847 "If this node has been visited, restore the point value when we left."
848 (while hl
849 (if (and (equal (nth 0 (car hl)) Info-current-file)
850 ;; Use string-equal, not equal, to ignore text props.
851 (string-equal (nth 1 (car hl)) Info-current-node))
852 (progn
853 (goto-char (nth 2 (car hl)))
854 (setq hl nil)) ;terminate the while at next iter
855 (setq hl (cdr hl)))))
856 \f
857 (defvar Info-last-search nil
858 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
859
860 (defun Info-search (regexp)
861 "Search for REGEXP, starting from point, and select node it's found in."
862 (interactive "sSearch (regexp): ")
863 (if transient-mark-mode (deactivate-mark))
864 (if (equal regexp "")
865 (setq regexp Info-last-search)
866 (setq Info-last-search regexp))
867 (let ((found ()) current
868 (onode Info-current-node)
869 (ofile Info-current-file)
870 (opoint (point))
871 (ostart (window-start))
872 (osubfile Info-current-subfile))
873 (save-excursion
874 (save-restriction
875 (widen)
876 (if (null Info-current-subfile)
877 (progn (re-search-forward regexp) (setq found (point)))
878 (condition-case err
879 (progn (re-search-forward regexp) (setq found (point)))
880 (search-failed nil)))))
881 (if (not found) ;can only happen in subfile case -- else would have erred
882 (unwind-protect
883 (let ((list ()))
884 (save-excursion
885 (set-buffer (marker-buffer Info-tag-table-marker))
886 (goto-char (point-min))
887 (search-forward "\n\^_\nIndirect:")
888 (save-restriction
889 (narrow-to-region (point)
890 (progn (search-forward "\n\^_")
891 (1- (point))))
892 (goto-char (point-min))
893 (search-forward (concat "\n" osubfile ": "))
894 (beginning-of-line)
895 (while (not (eobp))
896 (re-search-forward "\\(^.*\\): [0-9]+$")
897 (goto-char (+ (match-end 1) 2))
898 (setq list (cons (cons (read (current-buffer))
899 (buffer-substring
900 (match-beginning 1) (match-end 1)))
901 list))
902 (goto-char (1+ (match-end 0))))
903 (setq list (nreverse list)
904 current (car (car list))
905 list (cdr list))))
906 (while list
907 (message "Searching subfile %s..." (cdr (car list)))
908 (Info-read-subfile (car (car list)))
909 (setq list (cdr list))
910 ;; (goto-char (point-min))
911 (if (re-search-forward regexp nil t)
912 (setq found (point) list ())))
913 (if found
914 (message "")
915 (signal 'search-failed (list regexp))))
916 (if (not found)
917 (progn (Info-read-subfile osubfile)
918 (goto-char opoint)
919 (Info-select-node)
920 (set-window-start (selected-window) ostart)))))
921 (widen)
922 (goto-char found)
923 (Info-select-node)
924 ;; Use string-equal, not equal, to ignore text props.
925 (or (and (string-equal onode Info-current-node)
926 (equal ofile Info-current-file))
927 (setq Info-history (cons (list ofile onode opoint)
928 Info-history)))))
929 \f
930 ;; Extract the value of the node-pointer named NAME.
931 ;; If there is none, use ERRORNAME in the error message;
932 ;; if ERRORNAME is nil, just return nil.
933 (defun Info-extract-pointer (name &optional errorname)
934 ;; Bind this in case the user sets it to nil.
935 (let ((case-fold-search t))
936 (save-excursion
937 (goto-char (point-min))
938 (forward-line 1)
939 (if (re-search-backward (concat name ":") nil t)
940 (progn
941 (goto-char (match-end 0))
942 (Info-following-node-name))
943 (if (eq errorname t)
944 nil
945 (error "Node has no %s" (capitalize (or errorname name))))))))
946
947 ;; Return the node name in the buffer following point.
948 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
949 ;; saying which chars may appear in the node name.
950 (defun Info-following-node-name (&optional allowedchars)
951 (skip-chars-forward " \t")
952 (buffer-substring-no-properties
953 (point)
954 (progn
955 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
956 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
957 (if (looking-at "(")
958 (skip-chars-forward "^)")))
959 (skip-chars-backward " ")
960 (point))))
961
962 (defun Info-next ()
963 "Go to the next node of this node."
964 (interactive)
965 (Info-goto-node (Info-extract-pointer "next")))
966
967 (defun Info-prev ()
968 "Go to the previous node of this node."
969 (interactive)
970 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
971
972 (defun Info-up (&optional same-file)
973 "Go to the superior node of this node.
974 If SAME-FILE is non-nil, do not move to a different Info file."
975 (interactive)
976 (let ((node (Info-extract-pointer "up")))
977 (and same-file
978 (string-match "^(" node)
979 (error "Up node is in another Info file"))
980 (Info-goto-node node))
981 (Info-restore-point Info-history))
982
983 (defun Info-last ()
984 "Go back to the last node visited."
985 (interactive)
986 (or Info-history
987 (error "This is the first Info node you looked at"))
988 (let (filename nodename opoint)
989 (setq filename (car (car Info-history)))
990 (setq nodename (car (cdr (car Info-history))))
991 (setq opoint (car (cdr (cdr (car Info-history)))))
992 (setq Info-history (cdr Info-history))
993 (Info-find-node filename nodename)
994 (setq Info-history (cdr Info-history))
995 (goto-char opoint)))
996
997 (defun Info-directory ()
998 "Go to the Info directory node."
999 (interactive)
1000 (Info-find-node "dir" "top"))
1001 \f
1002 (defun Info-follow-reference (footnotename)
1003 "Follow cross reference named NAME to the node it refers to.
1004 NAME may be an abbreviation of the reference name."
1005 (interactive
1006 (let ((completion-ignore-case t)
1007 (case-fold-search t)
1008 completions default alt-default (start-point (point)) str i bol eol)
1009 (save-excursion
1010 ;; Store end and beginning of line.
1011 (end-of-line)
1012 (setq eol (point))
1013 (beginning-of-line)
1014 (setq bol (point))
1015
1016 (goto-char (point-min))
1017 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1018 (setq str (buffer-substring
1019 (match-beginning 1)
1020 (1- (point))))
1021 ;; See if this one should be the default.
1022 (and (null default)
1023 (<= (match-beginning 0) start-point)
1024 (<= start-point (point))
1025 (setq default t))
1026 ;; See if this one should be the alternate default.
1027 (and (null alt-default)
1028 (and (<= bol (match-beginning 0))
1029 (<= (point) eol))
1030 (setq alt-default t))
1031 (setq i 0)
1032 (while (setq i (string-match "[ \n\t]+" str i))
1033 (setq str (concat (substring str 0 i) " "
1034 (substring str (match-end 0))))
1035 (setq i (1+ i)))
1036 ;; Record as a completion and perhaps as default.
1037 (if (eq default t) (setq default str))
1038 (if (eq alt-default t) (setq alt-default str))
1039 ;; Don't add this string if it's a duplicate.
1040 ;; We use a loop instead of "(assoc str completions)" because
1041 ;; we want to do a case-insensitive compare.
1042 (let ((tail completions)
1043 (tem (downcase str)))
1044 (while (and tail
1045 (not (string-equal tem (downcase (car (car tail))))))
1046 (setq tail (cdr tail)))
1047 (or tail
1048 (setq completions
1049 (cons (cons str nil)
1050 completions))))))
1051 ;; If no good default was found, try an alternate.
1052 (or default
1053 (setq default alt-default))
1054 ;; If only one cross-reference found, then make it default.
1055 (if (eq (length completions) 1)
1056 (setq default (car (car completions))))
1057 (if completions
1058 (let ((input (completing-read (if default
1059 (concat "Follow reference named: ("
1060 default ") ")
1061 "Follow reference named: ")
1062 completions nil t)))
1063 (list (if (equal input "")
1064 default input)))
1065 (error "No cross-references in this node"))))
1066 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
1067 (case-fold-search t))
1068 (while (setq i (string-match " " str i))
1069 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1070 (setq i (+ i 6)))
1071 (save-excursion
1072 (goto-char (point-min))
1073 (or (re-search-forward str nil t)
1074 (error "No cross-reference named %s" footnotename))
1075 (goto-char (+ (match-beginning 0) 5))
1076 (setq target
1077 (Info-extract-menu-node-name "Bad format cross reference" t)))
1078 (while (setq i (string-match "[ \t\n]+" target i))
1079 (setq target (concat (substring target 0 i) " "
1080 (substring target (match-end 0))))
1081 (setq i (+ i 1)))
1082 (Info-goto-node target)))
1083
1084 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1085 (skip-chars-forward " \t\n")
1086 (let ((beg (point))
1087 str i)
1088 (skip-chars-forward "^:")
1089 (forward-char 1)
1090 (setq str
1091 (if (looking-at ":")
1092 (buffer-substring-no-properties beg (1- (point)))
1093 (skip-chars-forward " \t\n")
1094 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1095 (while (setq i (string-match "\n" str i))
1096 (aset str i ?\ ))
1097 ;; Collapse multiple spaces.
1098 (while (string-match " +" str)
1099 (setq str (replace-match " " t t str)))
1100 str))
1101
1102 ;; No one calls this.
1103 ;;(defun Info-menu-item-sequence (list)
1104 ;; (while list
1105 ;; (Info-menu (car list))
1106 ;; (setq list (cdr list))))
1107
1108 (defvar Info-complete-menu-buffer)
1109
1110 (defun Info-complete-menu-item (string predicate action)
1111 (let ((case-fold-search t))
1112 (cond ((eq action nil)
1113 (let (completions
1114 (pattern (concat "\n\\* +\\("
1115 (regexp-quote string)
1116 "[^:\t\n]*\\):")))
1117 (save-excursion
1118 (set-buffer Info-complete-menu-buffer)
1119 (goto-char (point-min))
1120 (search-forward "\n* Menu:")
1121 (while (re-search-forward pattern nil t)
1122 (setq completions (cons (cons (format "%s"
1123 (buffer-substring
1124 (match-beginning 1)
1125 (match-end 1)))
1126 (match-beginning 1))
1127 completions))))
1128 (try-completion string completions predicate)))
1129 ((eq action t)
1130 (let (completions
1131 (pattern (concat "\n\\* +\\("
1132 (regexp-quote string)
1133 "[^:\t\n]*\\):")))
1134 (save-excursion
1135 (set-buffer Info-complete-menu-buffer)
1136 (goto-char (point-min))
1137 (search-forward "\n* Menu:")
1138 (while (re-search-forward pattern nil t)
1139 (setq completions (cons (cons (format "%s"
1140 (buffer-substring
1141 (match-beginning 1)
1142 (match-end 1)))
1143 (match-beginning 1))
1144 completions))))
1145 (all-completions string completions predicate)))
1146 (t
1147 (save-excursion
1148 (set-buffer Info-complete-menu-buffer)
1149 (goto-char (point-min))
1150 (search-forward "\n* Menu:")
1151 (re-search-forward (concat "\n\\* +"
1152 (regexp-quote string)
1153 ":")
1154 nil t))))))
1155
1156
1157 (defun Info-menu (menu-item)
1158 "Go to node for menu item named (or abbreviated) NAME.
1159 Completion is allowed, and the menu item point is on is the default."
1160 (interactive
1161 (let ((completions '())
1162 ;; If point is within a menu item, use that item as the default
1163 (default nil)
1164 (p (point))
1165 beg
1166 (last nil))
1167 (save-excursion
1168 (goto-char (point-min))
1169 (if (not (search-forward "\n* menu:" nil t))
1170 (error "No menu in this node"))
1171 (setq beg (point))
1172 (and (< (point) p)
1173 (save-excursion
1174 (goto-char p)
1175 (end-of-line)
1176 (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
1177 (setq default (format "%s" (buffer-substring
1178 (match-beginning 1)
1179 (match-end 1)))))))
1180 (let ((item nil))
1181 (while (null item)
1182 (setq item (let ((completion-ignore-case t)
1183 (Info-complete-menu-buffer (current-buffer)))
1184 (completing-read (if default
1185 (format "Menu item (default %s): "
1186 default)
1187 "Menu item: ")
1188 'Info-complete-menu-item nil t)))
1189 ;; we rely on the fact that completing-read accepts an input
1190 ;; of "" even when the require-match argument is true and ""
1191 ;; is not a valid possibility
1192 (if (string= item "")
1193 (if default
1194 (setq item default)
1195 ;; ask again
1196 (setq item nil))))
1197 (list item))))
1198 ;; there is a problem here in that if several menu items have the same
1199 ;; name you can only go to the node of the first with this command.
1200 (Info-goto-node (Info-extract-menu-item menu-item)))
1201
1202 (defun Info-extract-menu-item (menu-item)
1203 (setq menu-item (regexp-quote menu-item))
1204 (let ((case-fold-search t))
1205 (save-excursion
1206 (goto-char (point-min))
1207 (or (search-forward "\n* menu:" nil t)
1208 (error "No menu in this node"))
1209 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1210 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1211 (error "No such item in menu"))
1212 (beginning-of-line)
1213 (forward-char 2)
1214 (Info-extract-menu-node-name))))
1215
1216 ;; If COUNT is nil, use the last item in the menu.
1217 (defun Info-extract-menu-counting (count)
1218 (let ((case-fold-search t))
1219 (save-excursion
1220 (goto-char (point-min))
1221 (or (search-forward "\n* menu:" nil t)
1222 (error "No menu in this node"))
1223 (if count
1224 (or (search-forward "\n* " nil t count)
1225 (error "Too few items in menu"))
1226 (while (search-forward "\n* " nil t)
1227 nil))
1228 (Info-extract-menu-node-name))))
1229
1230 (defun Info-nth-menu-item ()
1231 "Go to the node of the Nth menu item.
1232 N is the digit argument used to invoke this command."
1233 (interactive)
1234 (Info-goto-node
1235 (Info-extract-menu-counting
1236 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1237
1238 (defun Info-top-node ()
1239 "Go to the Top node of this file."
1240 (interactive)
1241 (Info-goto-node "Top"))
1242
1243 (defun Info-final-node ()
1244 "Go to the final node in this file."
1245 (interactive)
1246 (Info-goto-node "Top")
1247 (let (Info-history)
1248 ;; Go to the last node in the menu of Top.
1249 (Info-goto-node (Info-extract-menu-counting nil))
1250 ;; If the last node in the menu is not last in pointer structure,
1251 ;; move forward until we can't go any farther.
1252 (while (Info-forward-node t t) nil)
1253 ;; Then keep moving down to last subnode, unless we reach an index.
1254 (while (and (not (string-match "\\<index\\>" Info-current-node))
1255 (save-excursion (search-forward "\n* Menu:" nil t)))
1256 (Info-goto-node (Info-extract-menu-counting nil)))))
1257
1258 (defun Info-forward-node (&optional not-down no-error)
1259 "Go forward one node, considering all nodes as forming one sequence."
1260 (interactive)
1261 (goto-char (point-min))
1262 (forward-line 1)
1263 ;; three possibilities, in order of priority:
1264 ;; 1. next node is in a menu in this node (but not in an index)
1265 ;; 2. next node is next at same level
1266 ;; 3. next node is up and next
1267 (cond ((and (not not-down)
1268 (save-excursion (search-forward "\n* menu:" nil t))
1269 (not (string-match "\\<index\\>" Info-current-node)))
1270 (Info-goto-node (Info-extract-menu-counting 1))
1271 t)
1272 ((save-excursion (search-backward "next:" nil t))
1273 (Info-next)
1274 t)
1275 ((and (save-excursion (search-backward "up:" nil t))
1276 ;; Use string-equal, not equal, to ignore text props.
1277 (not (string-equal (downcase (Info-extract-pointer "up"))
1278 "top")))
1279 (let ((old-node Info-current-node))
1280 (Info-up)
1281 (let (Info-history success)
1282 (unwind-protect
1283 (setq success (Info-forward-node t no-error))
1284 (or success (Info-goto-node old-node))))))
1285 (no-error nil)
1286 (t (error "No pointer forward from this node"))))
1287
1288 (defun Info-backward-node ()
1289 "Go backward one node, considering all nodes as forming one sequence."
1290 (interactive)
1291 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1292 (upnode (Info-extract-pointer "up" t)))
1293 (cond ((and upnode (string-match "(" upnode))
1294 (error "First node in file"))
1295 ((and upnode (or (null prevnode)
1296 ;; Use string-equal, not equal,
1297 ;; to ignore text properties.
1298 (string-equal (downcase prevnode)
1299 (downcase upnode))))
1300 (Info-up))
1301 (prevnode
1302 ;; If we move back at the same level,
1303 ;; go down to find the last subnode*.
1304 (Info-prev)
1305 (let (Info-history)
1306 (while (and (not (string-match "\\<index\\>" Info-current-node))
1307 (save-excursion (search-forward "\n* Menu:" nil t)))
1308 (Info-goto-node (Info-extract-menu-counting nil)))))
1309 (t
1310 (error "No pointer backward from this node")))))
1311
1312 (defun Info-exit ()
1313 "Exit Info by selecting some other buffer."
1314 (interactive)
1315 (if Info-standalone
1316 (save-buffers-kill-emacs)
1317 (quit-window)))
1318
1319 (defun Info-next-menu-item ()
1320 (interactive)
1321 (save-excursion
1322 (forward-line -1)
1323 (search-forward "\n* menu:" nil t)
1324 (or (search-forward "\n* " nil t)
1325 (error "No more items in menu"))
1326 (Info-goto-node (Info-extract-menu-node-name))))
1327
1328 (defun Info-last-menu-item ()
1329 (interactive)
1330 (save-excursion
1331 (forward-line 1)
1332 (let ((beg (save-excursion
1333 (and (search-backward "\n* menu:" nil t)
1334 (point)))))
1335 (or (and beg (search-backward "\n* " beg t))
1336 (error "No previous items in menu")))
1337 (Info-goto-node (save-excursion
1338 (goto-char (match-end 0))
1339 (Info-extract-menu-node-name)))))
1340
1341 (defmacro Info-no-error (&rest body)
1342 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1343
1344 (defun Info-next-preorder ()
1345 "Go to the next subnode or the next node, or go up a level."
1346 (interactive)
1347 (cond ((Info-no-error (Info-next-menu-item)))
1348 ((Info-no-error (Info-next)))
1349 ((Info-no-error (Info-up t))
1350 ;; Since we have already gone thru all the items in this menu,
1351 ;; go up to the end of this node.
1352 (goto-char (point-max))
1353 ;; Since logically we are done with the node with that menu,
1354 ;; move on from it.
1355 (Info-next-preorder))
1356 (t
1357 (error "No more nodes"))))
1358
1359 (defun Info-last-preorder ()
1360 "Go to the last node, popping up a level if there is none."
1361 (interactive)
1362 (cond ((Info-no-error
1363 (Info-last-menu-item)
1364 ;; If we go down a menu item, go to the end of the node
1365 ;; so we can scroll back through it.
1366 (goto-char (point-max)))
1367 ;; Keep going down, as long as there are nested menu nodes.
1368 (while (Info-no-error
1369 (Info-last-menu-item)
1370 ;; If we go down a menu item, go to the end of the node
1371 ;; so we can scroll back through it.
1372 (goto-char (point-max))))
1373 (recenter -1))
1374 ((and (not (equal (Info-extract-pointer "up")
1375 (Info-extract-pointer "prev"))))
1376 (Info-no-error (Info-prev))
1377 (goto-char (point-max))
1378 (while (Info-no-error
1379 (Info-last-menu-item)
1380 ;; If we go down a menu item, go to the end of the node
1381 ;; so we can scroll back through it.
1382 (goto-char (point-max))))
1383 (recenter -1))
1384 ((Info-no-error (Info-up t))
1385 (goto-char (point-min))
1386 (or (search-forward "\n* Menu:" nil t)
1387 (goto-char (point-max))))
1388 (t (error "No previous nodes"))))
1389
1390 (defun Info-scroll-up ()
1391 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1392 Once you scroll far enough in a node that its menu appears on the screen
1393 but after point, the next scroll moves into its first subnode.
1394
1395 When you scroll past the end of a node, that goes to the next node; if
1396 this node has no successor, it moves to the parent node's successor,
1397 and so on. If point is inside the menu of a node, it moves to
1398 subnode indicated by the following menu item. (That case won't
1399 normally result from this command, but can happen in other ways.)"
1400
1401 (interactive)
1402 (if (or (< (window-start) (point-min))
1403 (> (window-start) (point-max)))
1404 (set-window-start (selected-window) (point)))
1405 (let ((virtual-end (save-excursion
1406 (goto-char (point-min))
1407 (if (search-forward "\n* Menu:" nil t)
1408 (point)
1409 (point-max)))))
1410 (if (or (< virtual-end (window-start))
1411 (pos-visible-in-window-p virtual-end))
1412 (Info-next-preorder)
1413 (scroll-up))))
1414
1415 (defun Info-scroll-down ()
1416 "Scroll one screenful back in Info, considering all nodes as one sequence.
1417 Within the menu of a node, this goes to its last subnode.
1418 When you scroll past the beginning of a node, that goes to the
1419 previous node or back up to the parent node."
1420 (interactive)
1421 (if (or (< (window-start) (point-min))
1422 (> (window-start) (point-max)))
1423 (set-window-start (selected-window) (point)))
1424 (let* ((current-point (point))
1425 (virtual-end (save-excursion
1426 (beginning-of-line)
1427 (setq current-point (point))
1428 (goto-char (point-min))
1429 (search-forward "\n* Menu:"
1430 current-point
1431 t))))
1432 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1433 (Info-last-preorder)
1434 (scroll-down))))
1435
1436 (defun Info-next-reference (&optional recur)
1437 "Move cursor to the next cross-reference or menu item in the node."
1438 (interactive)
1439 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1440 (old-pt (point))
1441 (case-fold-search t))
1442 (or (eobp) (forward-char 1))
1443 (or (re-search-forward pat nil t)
1444 (progn
1445 (goto-char (point-min))
1446 (or (re-search-forward pat nil t)
1447 (progn
1448 (goto-char old-pt)
1449 (error "No cross references in this node")))))
1450 (goto-char (match-beginning 0))
1451 (if (looking-at "\\* Menu:")
1452 (if recur
1453 (error "No cross references in this node")
1454 (Info-next-reference t)))))
1455
1456 (defun Info-prev-reference (&optional recur)
1457 "Move cursor to the previous cross-reference or menu item in the node."
1458 (interactive)
1459 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1460 (old-pt (point))
1461 (case-fold-search t))
1462 (or (re-search-backward pat nil t)
1463 (progn
1464 (goto-char (point-max))
1465 (or (re-search-backward pat nil t)
1466 (progn
1467 (goto-char old-pt)
1468 (error "No cross references in this node")))))
1469 (goto-char (match-beginning 0))
1470 (if (looking-at "\\* Menu:")
1471 (if recur
1472 (error "No cross references in this node")
1473 (Info-prev-reference t)))))
1474
1475 (defun Info-index (topic)
1476 "Look up a string in the index for this file.
1477 The index is defined as the first node in the top-level menu whose
1478 name contains the word \"Index\", plus any immediately following
1479 nodes whose names also contain the word \"Index\".
1480 If there are no exact matches to the specified topic, this chooses
1481 the first match which is a case-insensitive substring of a topic.
1482 Use the `,' command to see the other matches.
1483 Give a blank topic name to go to the Index node itself."
1484 (interactive "sIndex topic: ")
1485 (let ((orignode Info-current-node)
1486 (rnode nil)
1487 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1488 (regexp-quote topic)))
1489 node
1490 (case-fold-search t))
1491 (Info-goto-node "Top")
1492 (or (search-forward "\n* menu:" nil t)
1493 (error "No index"))
1494 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1495 (error "No index"))
1496 (goto-char (match-beginning 1))
1497 ;; Here, and subsequently in this function,
1498 ;; we bind Info-history to nil for internal node-switches
1499 ;; so that we don't put junk in the history.
1500 ;; In the first Info-goto-node call, above, we do update the history
1501 ;; because that is what the user's previous node choice into it.
1502 (let ((Info-history nil))
1503 (Info-goto-node (Info-extract-menu-node-name)))
1504 (or (equal topic "")
1505 (let ((matches nil)
1506 (exact nil)
1507 (Info-history nil)
1508 found)
1509 (while
1510 (progn
1511 (goto-char (point-min))
1512 (while (re-search-forward pattern nil t)
1513 (setq matches
1514 (cons (list (buffer-substring (match-beginning 1)
1515 (match-end 1))
1516 (buffer-substring (match-beginning 2)
1517 (match-end 2))
1518 Info-current-node
1519 (string-to-int (concat "0"
1520 (buffer-substring
1521 (match-beginning 3)
1522 (match-end 3)))))
1523 matches)))
1524 (and (setq node (Info-extract-pointer "next" t))
1525 (string-match "\\<Index\\>" node)))
1526 (Info-goto-node node))
1527 (or matches
1528 (progn
1529 (Info-goto-node orignode)
1530 (error "No `%s' in index" topic)))
1531 ;; Here it is a feature that assoc is case-sensitive.
1532 (while (setq found (assoc topic matches))
1533 (setq exact (cons found exact)
1534 matches (delq found matches)))
1535 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1536 (Info-index-next 0)))))
1537
1538 (defun Info-index-next (num)
1539 "Go to the next matching index item from the last `i' command."
1540 (interactive "p")
1541 (or Info-index-alternatives
1542 (error "No previous `i' command"))
1543 (while (< num 0)
1544 (setq num (+ num (length Info-index-alternatives))))
1545 (while (> num 0)
1546 (setq Info-index-alternatives
1547 (nconc (cdr Info-index-alternatives)
1548 (list (car Info-index-alternatives)))
1549 num (1- num)))
1550 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1551 (if (> (nth 3 (car Info-index-alternatives)) 0)
1552 (forward-line (nth 3 (car Info-index-alternatives)))
1553 (forward-line 3) ; don't search in headers
1554 (let ((name (car (car Info-index-alternatives))))
1555 (Info-find-index-name name)))
1556 (message "Found `%s' in %s. %s"
1557 (car (car Info-index-alternatives))
1558 (nth 2 (car Info-index-alternatives))
1559 (if (cdr Info-index-alternatives)
1560 "(Press `,' for more)"
1561 "(Only match)")))
1562
1563 (defun Info-find-index-name (name)
1564 "Move point to the place within the current node where NAME is defined."
1565 (let ((case-fold-search t))
1566 (if (or (re-search-forward (format
1567 "[a-zA-Z]+: %s\\( \\|$\\)"
1568 (regexp-quote name)) nil t)
1569 (search-forward (format "`%s'" name) nil t)
1570 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1571 (search-forward
1572 (format "`%s'" (substring name 0 (match-beginning 1)))
1573 nil t))
1574 (search-forward name nil t))
1575 (beginning-of-line)
1576 (goto-char (point-min)))))
1577
1578 (defun Info-undefined ()
1579 "Make command be undefined in Info."
1580 (interactive)
1581 (ding))
1582
1583 (defun Info-help ()
1584 "Enter the Info tutorial."
1585 (interactive)
1586 (delete-other-windows)
1587 (Info-find-node "info"
1588 (if (< (window-height) 23)
1589 "Help-Small-Screen"
1590 "Help")))
1591
1592 (defun Info-summary ()
1593 "Display a brief summary of all Info commands."
1594 (interactive)
1595 (save-window-excursion
1596 (switch-to-buffer "*Help*")
1597 (setq buffer-read-only nil)
1598 (erase-buffer)
1599 (insert (documentation 'Info-mode))
1600 (help-mode)
1601 (goto-char (point-min))
1602 (let (ch flag)
1603 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1604 (message (if flag "Type Space to see more"
1605 "Type Space to return to Info"))
1606 (if (not (eq ?\ (setq ch (read-event))))
1607 (progn (setq unread-command-events (list ch)) nil)
1608 flag))
1609 (scroll-up)))
1610 (bury-buffer "*Help*")))
1611 \f
1612 (defun Info-get-token (pos start all &optional errorstring)
1613 "Return the token around POS,
1614 POS must be somewhere inside the token
1615 START is a regular expression which will match the
1616 beginning of the tokens delimited string
1617 ALL is a regular expression with a single
1618 parenthesized subpattern which is the token to be
1619 returned. E.g. '{\(.*\)}' would return any string
1620 enclosed in braces around POS.
1621 SIG optional fourth argument, controls action on no match
1622 nil: return nil
1623 t: beep
1624 a string: signal an error, using that string."
1625 (let ((case-fold-search t))
1626 (save-excursion
1627 (goto-char pos)
1628 ;; First look for a match for START that goes across POS.
1629 (while (and (not (bobp)) (> (point) (- pos (length start)))
1630 (not (looking-at start)))
1631 (forward-char -1))
1632 ;; If we did not find one, search back for START
1633 ;; (this finds only matches that end at or before POS).
1634 (or (looking-at start)
1635 (progn
1636 (goto-char pos)
1637 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
1638 (let (found)
1639 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1640 (not (setq found (and (<= (match-beginning 0) pos)
1641 (> (match-end 0) pos))))))
1642 (if (and found (<= (match-beginning 0) pos)
1643 (> (match-end 0) pos))
1644 (buffer-substring (match-beginning 1) (match-end 1))
1645 (cond ((null errorstring)
1646 nil)
1647 ((eq errorstring t)
1648 (beep)
1649 nil)
1650 (t
1651 (error "No %s around position %d" errorstring pos))))))))
1652
1653 (defun Info-mouse-follow-nearest-node (click)
1654 "\\<Info-mode-map>Follow a node reference near point.
1655 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1656 At end of the node's text, moves to the next node, or up if none."
1657 (interactive "e")
1658 (let* ((start (event-start click))
1659 (window (car start))
1660 (pos (car (cdr start))))
1661 (select-window window)
1662 (goto-char pos))
1663 (and (not (Info-try-follow-nearest-node))
1664 (save-excursion (forward-line 1) (eobp))
1665 (Info-next-preorder)))
1666
1667 (defun Info-follow-nearest-node ()
1668 "\\<Info-mode-map>Follow a node reference near point.
1669 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1670 If no reference to follow, moves to the next node, or up if none."
1671 (interactive)
1672 (or (Info-try-follow-nearest-node)
1673 (Info-next-preorder)))
1674
1675 ;; Common subroutine.
1676 (defun Info-try-follow-nearest-node ()
1677 "Follow a node reference near point. Return non-nil if successful."
1678 (let (node)
1679 (cond
1680 ((setq node (Info-get-token (point) "\\*note[ \n]"
1681 "\\*note[ \n]\\([^:]*\\):"))
1682 (Info-follow-reference node))
1683 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1684 (Info-goto-node node))
1685 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):"))
1686 (Info-menu node))
1687 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1688 (Info-goto-node node))
1689 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1690 (Info-goto-node node))
1691 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1692 (Info-goto-node "Top"))
1693 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1694 (Info-goto-node node)))
1695 node))
1696 \f
1697 (defvar Info-mode-map nil
1698 "Keymap containing Info commands.")
1699 (if Info-mode-map
1700 nil
1701 (setq Info-mode-map (make-keymap))
1702 (suppress-keymap Info-mode-map)
1703 (define-key Info-mode-map "." 'beginning-of-buffer)
1704 (define-key Info-mode-map " " 'Info-scroll-up)
1705 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1706 (define-key Info-mode-map "\t" 'Info-next-reference)
1707 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1708 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1709 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1710 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1711 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1712 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1713 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1714 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1715 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1716 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1717 (define-key Info-mode-map "0" 'undefined)
1718 (define-key Info-mode-map "?" 'Info-summary)
1719 (define-key Info-mode-map "]" 'Info-forward-node)
1720 (define-key Info-mode-map "[" 'Info-backward-node)
1721 (define-key Info-mode-map "<" 'Info-top-node)
1722 (define-key Info-mode-map ">" 'Info-final-node)
1723 (define-key Info-mode-map "b" 'beginning-of-buffer)
1724 (define-key Info-mode-map "d" 'Info-directory)
1725 (define-key Info-mode-map "e" 'Info-edit)
1726 (define-key Info-mode-map "f" 'Info-follow-reference)
1727 (define-key Info-mode-map "g" 'Info-goto-node)
1728 (define-key Info-mode-map "h" 'Info-help)
1729 (define-key Info-mode-map "i" 'Info-index)
1730 (define-key Info-mode-map "l" 'Info-last)
1731 (define-key Info-mode-map "m" 'Info-menu)
1732 (define-key Info-mode-map "n" 'Info-next)
1733 (define-key Info-mode-map "p" 'Info-prev)
1734 (define-key Info-mode-map "q" 'Info-exit)
1735 (define-key Info-mode-map "s" 'Info-search)
1736 ;; For consistency with Rmail.
1737 (define-key Info-mode-map "\M-s" 'Info-search)
1738 (define-key Info-mode-map "t" 'Info-top-node)
1739 (define-key Info-mode-map "u" 'Info-up)
1740 (define-key Info-mode-map "," 'Info-index-next)
1741 (define-key Info-mode-map "\177" 'Info-scroll-down)
1742 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1743 )
1744
1745 (defun Info-check-pointer (item)
1746 ;; Non-nil if ITEM is present in this node.
1747 (condition-case nil
1748 (Info-extract-pointer item)
1749 (error nil)))
1750
1751 (easy-menu-define Info-mode-menu Info-mode-map
1752 "Menu for info files."
1753 '("Info"
1754 ["Up" Info-up (Info-check-pointer "up")]
1755 ["Next" Info-next (Info-check-pointer "next")]
1756 ["Previous" Info-prev (Info-check-pointer "prev[ious]*")]
1757 ("Menu item" ["You should never see this" report-emacs-bug t])
1758 ("Reference" ["You should never see this" report-emacs-bug t])
1759 ["Search..." Info-search t]
1760 ["Goto node..." Info-goto-node t]
1761 ["Last" Info-last Info-history]
1762 ["Exit" Info-exit t]))
1763
1764 (defvar Info-menu-last-node nil)
1765 ;; Last node the menu was created for.
1766 ;; Value is a list, (FILE-NAME NODE-NAME).
1767
1768 (defun Info-menu-update ()
1769 ;; Update the Info menu for the current node.
1770 (condition-case nil
1771 (if (or (not (eq major-mode 'Info-mode))
1772 (equal (list Info-current-file Info-current-node)
1773 Info-menu-last-node))
1774 ()
1775 ;; Update menu menu.
1776 (let* ((Info-complete-menu-buffer (current-buffer))
1777 (items (nreverse (condition-case nil
1778 (Info-complete-menu-item
1779 "" (lambda (e) t) t)
1780 (error nil))))
1781 entries current
1782 (number 0))
1783 (while (and items (< number 9))
1784 (setq current (car items)
1785 items (cdr items)
1786 number (1+ number))
1787 (setq entries (cons `[,current
1788 (Info-menu ,current)
1789 :keys ,(format "%d" number)]
1790 entries)))
1791 (if items
1792 (setq entries (cons ["Other..." Info-menu t] entries)))
1793 (or entries
1794 (setq entries (list ["No menu" nil nil])))
1795 (easy-menu-change '("Info") "Menu item" (nreverse entries)))
1796 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1797 (let ((items nil)
1798 str i entries current
1799 (number 0)
1800 (case-fold-search t))
1801 (save-excursion
1802 (goto-char (point-min))
1803 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1804 (setq str (buffer-substring
1805 (match-beginning 1)
1806 (1- (point))))
1807 (setq i 0)
1808 (while (setq i (string-match "[ \n\t]+" str i))
1809 (setq str (concat (substring str 0 i) " "
1810 (substring str (match-end 0))))
1811 (setq i (1+ i)))
1812 (setq items
1813 (cons str items))))
1814 (while (and items (< number 9))
1815 (setq current (car items)
1816 items (cdr items)
1817 number (1+ number))
1818 (setq entries (cons `[,current
1819 (Info-follow-reference ,current)
1820 t]
1821 entries)))
1822 (if items
1823 (setq entries (cons ["Other..." Info-follow-reference t]
1824 entries)))
1825 (or entries
1826 (setq entries (list ["No references" nil nil])))
1827 (easy-menu-change '("Info") "Reference" (nreverse entries)))
1828 ;; Update last seen node.
1829 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
1830 ;; Try to avoid entering infinite beep mode in case of errors.
1831 (error (ding))))
1832
1833 \f
1834 ;; Info mode is suitable only for specially formatted data.
1835 (put 'info-mode 'mode-class 'special)
1836
1837 (defun Info-mode ()
1838 "\\<Info-mode-map>
1839 Info mode provides commands for browsing through the Info documentation tree.
1840 Documentation in Info is divided into \"nodes\", each of which discusses
1841 one topic and contains references to other nodes which discuss related
1842 topics. Info has commands to follow the references and show you other nodes.
1843
1844 \\[Info-help] Invoke the Info tutorial.
1845 \\[Info-exit] Quit Info: reselect previously selected buffer.
1846
1847 Selecting other nodes:
1848 \\[Info-mouse-follow-nearest-node]
1849 Follow a node reference you click on.
1850 This works with menu items, cross references, and
1851 the \"next\", \"previous\" and \"up\", depending on where you click.
1852 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
1853 \\[Info-next] Move to the \"next\" node of this node.
1854 \\[Info-prev] Move to the \"previous\" node of this node.
1855 \\[Info-up] Move \"up\" from this node.
1856 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1857 Picking a menu item causes another node to be selected.
1858 \\[Info-directory] Go to the Info directory node.
1859 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1860 \\[Info-last] Move to the last node you were at.
1861 \\[Info-index] Look up a topic in this file's Index and move to that node.
1862 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1863 \\[Info-top-node] Go to the Top node of this file.
1864 \\[Info-final-node] Go to the final node in this file.
1865 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
1866 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
1867
1868 Moving within a node:
1869 \\[Info-scroll-up] Normally, scroll forward a full screen.
1870 Once you scroll far enough in a node that its menu appears on the screen
1871 but after point, the next scroll moves into its first subnode.
1872 When after all menu items (or if their is no menu), move up to
1873 the parent node.
1874 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1875 already visible, try to go to the previous menu entry, or up if there is none.
1876 \\[beginning-of-buffer] Go to beginning of node.
1877
1878 Advanced commands:
1879 \\[Info-exit] Quit Info: reselect previously selected buffer.
1880 \\[Info-edit] Edit contents of selected node.
1881 1 Pick first item in node's menu.
1882 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1883 \\[Info-goto-node] Move to node specified by name.
1884 You may include a filename as well, as (FILENAME)NODENAME.
1885 \\[universal-argument] \\[info] Move to new Info file with completion.
1886 \\[Info-search] Search through this Info file for specified regexp,
1887 and select the node in which the next occurrence is found.
1888 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1889 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1890 (kill-all-local-variables)
1891 (setq major-mode 'Info-mode)
1892 (setq mode-name "Info")
1893 (setq tab-width 8)
1894 (use-local-map Info-mode-map)
1895 (make-local-hook 'activate-menubar-hook)
1896 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
1897 (set-syntax-table text-mode-syntax-table)
1898 (setq local-abbrev-table text-mode-abbrev-table)
1899 (setq case-fold-search t)
1900 (setq buffer-read-only t)
1901 (make-local-variable 'Info-current-file)
1902 (make-local-variable 'Info-current-subfile)
1903 (make-local-variable 'Info-current-node)
1904 (make-local-variable 'Info-tag-table-marker)
1905 (setq Info-tag-table-marker (make-marker))
1906 (make-local-variable 'Info-tag-table-buffer)
1907 (setq Info-tag-table-buffer nil)
1908 (make-local-variable 'Info-history)
1909 (make-local-variable 'Info-index-alternatives)
1910 ;; This is for the sake of the invisible text we use handling titles.
1911 (make-local-variable 'line-move-ignore-invisible)
1912 (setq line-move-ignore-invisible t)
1913 (Info-set-mode-line)
1914 (run-hooks 'Info-mode-hook))
1915
1916 (defvar Info-edit-map nil
1917 "Local keymap used within `e' command of Info.")
1918 (if Info-edit-map
1919 nil
1920 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1921 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1922
1923 ;; Info-edit mode is suitable only for specially formatted data.
1924 (put 'info-edit-mode 'mode-class 'special)
1925
1926 (defun Info-edit-mode ()
1927 "Major mode for editing the contents of an Info node.
1928 Like text mode with the addition of `Info-cease-edit'
1929 which returns to Info mode for browsing.
1930 \\{Info-edit-map}"
1931 (use-local-map Info-edit-map)
1932 (setq major-mode 'Info-edit-mode)
1933 (setq mode-name "Info Edit")
1934 (kill-local-variable 'mode-line-buffer-identification)
1935 (setq buffer-read-only nil)
1936 (force-mode-line-update)
1937 (buffer-enable-undo (current-buffer))
1938 (run-hooks 'Info-edit-mode-hook))
1939
1940 (defun Info-edit ()
1941 "Edit the contents of this Info node.
1942 Allowed only if variable `Info-enable-edit' is non-nil."
1943 (interactive)
1944 (or Info-enable-edit
1945 (error "Editing info nodes is not enabled"))
1946 (Info-edit-mode)
1947 (message "%s" (substitute-command-keys
1948 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1949
1950 (defun Info-cease-edit ()
1951 "Finish editing Info node; switch back to Info proper."
1952 (interactive)
1953 ;; Do this first, so nothing has changed if user C-g's at query.
1954 (and (buffer-modified-p)
1955 (y-or-n-p "Save the file? ")
1956 (save-buffer))
1957 (use-local-map Info-mode-map)
1958 (setq major-mode 'Info-mode)
1959 (setq mode-name "Info")
1960 (Info-set-mode-line)
1961 (setq buffer-read-only t)
1962 (force-mode-line-update)
1963 (and (marker-position Info-tag-table-marker)
1964 (buffer-modified-p)
1965 (message "Tags may have changed. Use Info-tagify if necessary")))
1966 \f
1967 (defvar Info-file-list-for-emacs
1968 '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc")
1969 "List of Info files that describe Emacs commands.
1970 An element can be a file name, or a list of the form (PREFIX . FILE)
1971 where PREFIX is a name prefix and FILE is the file to look in.
1972 If the element is just a file name, the file name also serves as the prefix.")
1973
1974 (defun Info-find-emacs-command-nodes (command)
1975 "Return a list of locations documenting COMMAND.
1976 The `info-file' property of COMMAND says which Info manual to search.
1977 If COMMAND has no property, the variable `Info-file-list-for-emacs'
1978 defines heuristics for which Info manual to try.
1979 The locations are of the format used in Info-history, i.e.
1980 \(FILENAME NODENAME BUFFERPOS\)."
1981 (let ((where '())
1982 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
1983 ":\\s *\\(.*\\)\\.$"))
1984 (info-file "emacs")) ;default
1985 ;; Determine which info file this command is documented in.
1986 (if (get command 'info-file)
1987 (setq info-file (get command 'info-file))
1988 ;; If it doesn't say explicitly, test its name against
1989 ;; various prefixes that we know.
1990 (let ((file-list Info-file-list-for-emacs))
1991 (while file-list
1992 (let* ((elt (car file-list))
1993 (name (if (consp elt)
1994 (car elt)
1995 elt))
1996 (file (if (consp elt) (cdr elt) elt))
1997 (regexp (concat "\\`" (regexp-quote name)
1998 "\\(\\'\\|-\\)")))
1999 (if (string-match regexp (symbol-name command))
2000 (setq info-file file file-list nil))
2001 (setq file-list (cdr file-list))))))
2002 (save-excursion
2003 (condition-case nil
2004 (Info-find-node info-file "Command Index")
2005 ;; Some manuals may not have a separate Command Index node,
2006 ;; so try just Index instead.
2007 (error
2008 (Info-find-node info-file "Index")))
2009 ;; Take the index node off the Info history.
2010 (setq Info-history (cdr Info-history))
2011 (goto-char (point-max))
2012 (while (re-search-backward cmd-desc nil t)
2013 (setq where (cons (list Info-current-file
2014 (buffer-substring
2015 (match-beginning 1)
2016 (match-end 1))
2017 0)
2018 where)))
2019 where)))
2020
2021 ;;;###autoload
2022 (defun Info-goto-emacs-command-node (command)
2023 "Go to the Info node in the Emacs manual for command COMMAND.
2024 The command is found by looking up in Emacs manual's Command Index
2025 or in another manual found via COMMAND's `info-file' property or
2026 the variable `Info-file-list-for-emacs'."
2027 (interactive "CFind documentation for command: ")
2028 (or (commandp command)
2029 (signal 'wrong-type-argument (list 'commandp command)))
2030 (let ((where (Info-find-emacs-command-nodes command)))
2031 (if where
2032 (let ((num-matches (length where)))
2033 ;; Get Info running, and pop to it in another window.
2034 (save-window-excursion
2035 (info))
2036 ;; FIXME It would be cool if this could use a buffer other
2037 ;; than *info*.
2038 (pop-to-buffer "*info*")
2039 (Info-find-node (car (car where))
2040 (car (cdr (car where))))
2041 (if (> num-matches 1)
2042 (progn
2043 ;; Info-find-node already pushed (car where) onto
2044 ;; Info-history. Put the other nodes that were found on
2045 ;; the history.
2046 (setq Info-history (nconc (cdr where) Info-history))
2047 (message "Found %d other entr%s. Use %s to see %s."
2048 (1- num-matches)
2049 (if (> num-matches 2) "ies" "y")
2050 (substitute-command-keys "\\[Info-last]")
2051 (if (> num-matches 2) "them" "it")))))
2052 (error "Couldn't find documentation for %s" command))))
2053
2054 ;;;###autoload
2055 (defun Info-goto-emacs-key-command-node (key)
2056 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2057 Interactively, if the binding is execute-extended-command, a command is read.
2058 The command is found by looking up in Emacs manual's Command Index
2059 or in another manual found via COMMAND's `info-file' property or
2060 the variable `Info-file-list-for-emacs'."
2061 (interactive "kFind documentation for key:")
2062 (let ((command (key-binding key)))
2063 (cond ((null command)
2064 (message "%s is undefined" (key-description key)))
2065 ((and (interactive-p)
2066 (eq command 'execute-extended-command))
2067 (Info-goto-emacs-command-node
2068 (read-command "Find documentation for command: ")))
2069 (t
2070 (Info-goto-emacs-command-node command)))))
2071 \f
2072 (defcustom Info-title-face-alist
2073 '((?* bold underline)
2074 (?= bold-italic underline)
2075 (?- italic underline))
2076 "*Alist of face or list of faces to use for pseudo-underlined titles.
2077 The alist key is the character the title is underlined with (?*, ?= or ?-)."
2078 :type '(repeat (list character face face))
2079 :group 'info)
2080
2081 (defun Info-fontify-node ()
2082 (save-excursion
2083 (let ((buffer-read-only nil)
2084 (case-fold-search t))
2085 (goto-char (point-min))
2086 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2087 (goto-char (match-end 0))
2088 (while
2089 (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2090 (goto-char (match-end 0))
2091 (if (save-excursion
2092 (goto-char (match-beginning 1))
2093 (save-match-data (looking-at "Node:")))
2094 (put-text-property (match-beginning 2) (match-end 2)
2095 'face 'info-node)
2096 (put-text-property (match-beginning 2) (match-end 2)
2097 'face 'info-xref)
2098 (put-text-property (match-beginning 2) (match-end 2)
2099 'mouse-face 'highlight))))
2100 (goto-char (point-min))
2101 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2102 nil t)
2103 (put-text-property (match-beginning 1) (match-end 1)
2104 'face
2105 (cdr (assq (preceding-char) Info-title-face-alist)))
2106 ;; This is a serious problem for trying to handle multiple
2107 ;; frame types at once. We want this text to be invisible
2108 ;; on frames that can display the font above.
2109 (if (memq (framep (selected-frame)) '(x pc w32))
2110 (put-text-property (match-end 1) (match-end 2)
2111 'invisible t)))
2112 (goto-char (point-min))
2113 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
2114 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2115 nil
2116 (put-text-property (match-beginning 1) (match-end 1)
2117 'face 'info-xref)
2118 (put-text-property (match-beginning 1) (match-end 1)
2119 'mouse-face 'highlight)))
2120 (goto-char (point-min))
2121 (if (and (search-forward "\n* Menu:" nil t)
2122 (not (string-match "\\<Index\\>" Info-current-node))
2123 ;; Don't take time to annotate huge menus
2124 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2125 (let ((n 0))
2126 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
2127 (setq n (1+ n))
2128 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
2129 (put-text-property (match-beginning 0)
2130 (1+ (match-beginning 0))
2131 'face 'info-menu-5))
2132 (put-text-property (match-beginning 1) (match-end 1)
2133 'face 'info-xref)
2134 (put-text-property (match-beginning 1) (match-end 1)
2135 'mouse-face 'highlight))))
2136 (set-buffer-modified-p nil))))
2137 \f
2138
2139 ;; When an Info buffer is killed, make sure the associated tags buffer
2140 ;; is killed too.
2141 (defun Info-kill-buffer ()
2142 (and (eq major-mode 'Info-mode)
2143 Info-tag-table-buffer
2144 (kill-buffer Info-tag-table-buffer)))
2145
2146 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2147
2148 ;;; Speedbar support:
2149 ;; These functions permit speedbar to display the "tags" in the
2150 ;; current info node.
2151 (eval-when-compile (require 'speedbar))
2152
2153 (defvar Info-speedbar-key-map nil
2154 "Keymap used when in the info display mode.")
2155
2156 (defun Info-install-speedbar-variables ()
2157 "Install those variables used by speedbar to enhance Info."
2158 (if Info-speedbar-key-map
2159 nil
2160 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2161
2162 ;; Basic tree features
2163 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2164 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2165 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2166 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2167 )
2168
2169 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2170 Info-speedbar-key-map
2171 Info-speedbar-hierarchy-buttons)))
2172
2173 (defvar Info-speedbar-menu-items
2174 '(["Browse Node" speedbar-edit-line t]
2175 ["Expand Node" speedbar-expand-line
2176 (save-excursion (beginning-of-line)
2177 (looking-at "[0-9]+: *.\\+. "))]
2178 ["Contract Node" speedbar-contract-line
2179 (save-excursion (beginning-of-line)
2180 (looking-at "[0-9]+: *.-. "))]
2181 )
2182 "Additional menu-items to add to speedbar frame.")
2183
2184 ;; Make sure our special speedbar major mode is loaded
2185 (if (featurep 'speedbar)
2186 (Info-install-speedbar-variables)
2187 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2188
2189 ;;; Info hierarchy display method
2190 ;;;###autoload
2191 (defun Info-speedbar-browser ()
2192 "Initialize speedbar to display an info node browser.
2193 This will add a speedbar major display mode."
2194 (interactive)
2195 (require 'speedbar)
2196 ;; Make sure that speedbar is active
2197 (speedbar-frame-mode 1)
2198 ;; Now, throw us into Info mode on speedbar.
2199 (speedbar-change-initial-expansion-list "Info")
2200 )
2201
2202 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2203 "Display an Info directory hierarchy in speedbar.
2204 DIRECTORY is the current directory in the attached frame.
2205 DEPTH is the current indentation depth.
2206 NODE is an optional argument that is used to represent the
2207 specific node to expand."
2208 (if (and (not node)
2209 (save-excursion (goto-char (point-min))
2210 (let ((case-fold-search t))
2211 (looking-at "Info Nodes:"))))
2212 ;; Update our "current node" maybe?
2213 nil
2214 ;; We cannot use the generic list code, that depends on all leaves
2215 ;; being known at creation time.
2216 (if (not node)
2217 (speedbar-with-writable (insert "Info Nodes:\n")))
2218 (let ((completions nil)
2219 (cf (selected-frame)))
2220 (select-frame speedbar-attached-frame)
2221 (save-window-excursion
2222 (setq completions
2223 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
2224 (select-frame cf)
2225 (if completions
2226 (speedbar-with-writable
2227 (while completions
2228 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2229 (cdr (car completions))
2230 (car (car completions))
2231 'Info-speedbar-goto-node
2232 (cdr (car completions))
2233 'info-xref depth)
2234 (setq completions (cdr completions)))
2235 t)
2236 nil))))
2237
2238 (defun Info-speedbar-goto-node (text node indent)
2239 "When user clicks on TEXT, goto an info NODE.
2240 The INDENT level is ignored."
2241 (select-frame speedbar-attached-frame)
2242 (let* ((buff (or (get-buffer "*info*")
2243 (progn (info) (get-buffer "*info*"))))
2244 (bwin (get-buffer-window buff 0)))
2245 (if bwin
2246 (progn
2247 (select-window bwin)
2248 (raise-frame (window-frame bwin)))
2249 (if speedbar-power-click
2250 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2251 (select-frame speedbar-attached-frame)
2252 (switch-to-buffer buff)))
2253 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
2254 (file (match-string 1 node))
2255 (node (match-string 2 node)))
2256 (Info-find-node file node)
2257 ;; If we do a find-node, and we were in info mode, restore
2258 ;; the old default method. Once we are in info mode, it makes
2259 ;; sense to return to whatever method the user was using before.
2260 (if (string= speedbar-initial-expansion-list-name "Info")
2261 (speedbar-change-initial-expansion-list
2262 speedbar-previously-used-expansion-list-name)))))
2263
2264 (defun Info-speedbar-expand-node (text token indent)
2265 "Expand the node the user clicked on.
2266 TEXT is the text of the button we clicked on, a + or - item.
2267 TOKEN is data related to this node (NAME . FILE).
2268 INDENT is the current indentation depth."
2269 (cond ((string-match "+" text) ;we have to expand this file
2270 (speedbar-change-expand-button-char ?-)
2271 (if (speedbar-with-writable
2272 (save-excursion
2273 (end-of-line) (forward-char 1)
2274 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
2275 (speedbar-change-expand-button-char ?-)
2276 (speedbar-change-expand-button-char ??)))
2277 ((string-match "-" text) ;we have to contract this node
2278 (speedbar-change-expand-button-char ?+)
2279 (speedbar-delete-subblock indent))
2280 (t (error "Ooops... not sure what to do")))
2281 (speedbar-center-buffer-smartly))
2282
2283 (defun Info-speedbar-fetch-file-nodes (nodespec)
2284 "Fetch the subnodes from the info NODESPEC.
2285 NODESPEC is a string of the form: (file)node.
2286 Optional THISFILE represends the filename of"
2287 (save-excursion
2288 ;; Set up a buffer we can use to fake-out Info.
2289 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2290 (if (not (equal major-mode 'Info-mode))
2291 (Info-mode))
2292 ;; Get the node into this buffer
2293 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
2294 (file (match-string 1 nodespec))
2295 (node (match-string 2 nodespec)))
2296 (Info-find-node file node))
2297 ;; Scan the created buffer
2298 (goto-char (point-min))
2299 (let ((completions nil)
2300 (case-fold-search t)
2301 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
2302 (match-string 1 nodespec))))
2303 ;; Always skip the first one...
2304 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2305 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2306 (let ((name (match-string 1)))
2307 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2308 (setq name (cons name (match-string 1)))
2309 (if (looking-at " *\\(([^)]+)\\)\\.")
2310 (setq name (cons name (concat (match-string 1) "Top")))
2311 (if (looking-at " \\([^.]+\\).")
2312 (setq name
2313 (cons name (concat "(" thisfile ")" (match-string 1))))
2314 (setq name (cons name (concat "(" thisfile ")" name))))))
2315 (setq completions (cons name completions))))
2316 (nreverse completions))))
2317
2318 ;;; Info mode node listing
2319 (defun Info-speedbar-buttons (buffer)
2320 "Create a speedbar display to help navigation in an Info file.
2321 BUFFER is the buffer speedbar is requesting buttons for."
2322 (if (save-excursion (goto-char (point-min))
2323 (let ((case-fold-search t))
2324 (not (looking-at "Info Nodes:"))))
2325 (erase-buffer))
2326 (Info-speedbar-hierarchy-buttons nil 0)
2327 )
2328
2329 (provide 'info)
2330
2331 ;;; info.el ends here