]> code.delx.au - gnu-emacs/blob - lisp/info.el
(smtpmail-send-it): Add autoload cookie.
[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
1067 (unless footnotename
1068 (error "No reference was specified"))
1069
1070 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
1071 (case-fold-search t))
1072 (while (setq i (string-match " " str i))
1073 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1074 (setq i (+ i 6)))
1075 (save-excursion
1076 (goto-char (point-min))
1077 (or (re-search-forward str nil t)
1078 (error "No cross-reference named %s" footnotename))
1079 (goto-char (+ (match-beginning 0) 5))
1080 (setq target
1081 (Info-extract-menu-node-name "Bad format cross reference" t)))
1082 (while (setq i (string-match "[ \t\n]+" target i))
1083 (setq target (concat (substring target 0 i) " "
1084 (substring target (match-end 0))))
1085 (setq i (+ i 1)))
1086 (Info-goto-node target)))
1087
1088 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1089 (skip-chars-forward " \t\n")
1090 (let ((beg (point))
1091 str i)
1092 (skip-chars-forward "^:")
1093 (forward-char 1)
1094 (setq str
1095 (if (looking-at ":")
1096 (buffer-substring-no-properties beg (1- (point)))
1097 (skip-chars-forward " \t\n")
1098 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1099 (while (setq i (string-match "\n" str i))
1100 (aset str i ?\ ))
1101 ;; Collapse multiple spaces.
1102 (while (string-match " +" str)
1103 (setq str (replace-match " " t t str)))
1104 str))
1105
1106 ;; No one calls this.
1107 ;;(defun Info-menu-item-sequence (list)
1108 ;; (while list
1109 ;; (Info-menu (car list))
1110 ;; (setq list (cdr list))))
1111
1112 (defvar Info-complete-menu-buffer)
1113
1114 (defun Info-complete-menu-item (string predicate action)
1115 (let ((case-fold-search t))
1116 (cond ((eq action nil)
1117 (let (completions
1118 (pattern (concat "\n\\* +\\("
1119 (regexp-quote string)
1120 "[^:\t\n]*\\):")))
1121 (save-excursion
1122 (set-buffer Info-complete-menu-buffer)
1123 (goto-char (point-min))
1124 (search-forward "\n* Menu:")
1125 (while (re-search-forward pattern nil t)
1126 (setq completions (cons (cons (format "%s"
1127 (buffer-substring
1128 (match-beginning 1)
1129 (match-end 1)))
1130 (match-beginning 1))
1131 completions))))
1132 (try-completion string completions predicate)))
1133 ((eq action t)
1134 (let (completions
1135 (pattern (concat "\n\\* +\\("
1136 (regexp-quote string)
1137 "[^:\t\n]*\\):")))
1138 (save-excursion
1139 (set-buffer Info-complete-menu-buffer)
1140 (goto-char (point-min))
1141 (search-forward "\n* Menu:")
1142 (while (re-search-forward pattern nil t)
1143 (setq completions (cons (cons (format "%s"
1144 (buffer-substring
1145 (match-beginning 1)
1146 (match-end 1)))
1147 (match-beginning 1))
1148 completions))))
1149 (all-completions string completions predicate)))
1150 (t
1151 (save-excursion
1152 (set-buffer Info-complete-menu-buffer)
1153 (goto-char (point-min))
1154 (search-forward "\n* Menu:")
1155 (re-search-forward (concat "\n\\* +"
1156 (regexp-quote string)
1157 ":")
1158 nil t))))))
1159
1160
1161 (defun Info-menu (menu-item)
1162 "Go to node for menu item named (or abbreviated) NAME.
1163 Completion is allowed, and the menu item point is on is the default."
1164 (interactive
1165 (let ((completions '())
1166 ;; If point is within a menu item, use that item as the default
1167 (default nil)
1168 (p (point))
1169 beg
1170 (last nil))
1171 (save-excursion
1172 (goto-char (point-min))
1173 (if (not (search-forward "\n* menu:" nil t))
1174 (error "No menu in this node"))
1175 (setq beg (point))
1176 (and (< (point) p)
1177 (save-excursion
1178 (goto-char p)
1179 (end-of-line)
1180 (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
1181 (setq default (format "%s" (buffer-substring
1182 (match-beginning 1)
1183 (match-end 1)))))))
1184 (let ((item nil))
1185 (while (null item)
1186 (setq item (let ((completion-ignore-case t)
1187 (Info-complete-menu-buffer (current-buffer)))
1188 (completing-read (if default
1189 (format "Menu item (default %s): "
1190 default)
1191 "Menu item: ")
1192 'Info-complete-menu-item nil t)))
1193 ;; we rely on the fact that completing-read accepts an input
1194 ;; of "" even when the require-match argument is true and ""
1195 ;; is not a valid possibility
1196 (if (string= item "")
1197 (if default
1198 (setq item default)
1199 ;; ask again
1200 (setq item nil))))
1201 (list item))))
1202 ;; there is a problem here in that if several menu items have the same
1203 ;; name you can only go to the node of the first with this command.
1204 (Info-goto-node (Info-extract-menu-item menu-item)))
1205
1206 (defun Info-extract-menu-item (menu-item)
1207 (setq menu-item (regexp-quote menu-item))
1208 (let ((case-fold-search t))
1209 (save-excursion
1210 (goto-char (point-min))
1211 (or (search-forward "\n* menu:" nil t)
1212 (error "No menu in this node"))
1213 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1214 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1215 (error "No such item in menu"))
1216 (beginning-of-line)
1217 (forward-char 2)
1218 (Info-extract-menu-node-name))))
1219
1220 ;; If COUNT is nil, use the last item in the menu.
1221 (defun Info-extract-menu-counting (count)
1222 (let ((case-fold-search t))
1223 (save-excursion
1224 (goto-char (point-min))
1225 (or (search-forward "\n* menu:" nil t)
1226 (error "No menu in this node"))
1227 (if count
1228 (or (search-forward "\n* " nil t count)
1229 (error "Too few items in menu"))
1230 (while (search-forward "\n* " nil t)
1231 nil))
1232 (Info-extract-menu-node-name))))
1233
1234 (defun Info-nth-menu-item ()
1235 "Go to the node of the Nth menu item.
1236 N is the digit argument used to invoke this command."
1237 (interactive)
1238 (Info-goto-node
1239 (Info-extract-menu-counting
1240 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1241
1242 (defun Info-top-node ()
1243 "Go to the Top node of this file."
1244 (interactive)
1245 (Info-goto-node "Top"))
1246
1247 (defun Info-final-node ()
1248 "Go to the final node in this file."
1249 (interactive)
1250 (Info-goto-node "Top")
1251 (let (Info-history)
1252 ;; Go to the last node in the menu of Top.
1253 (Info-goto-node (Info-extract-menu-counting nil))
1254 ;; If the last node in the menu is not last in pointer structure,
1255 ;; move forward until we can't go any farther.
1256 (while (Info-forward-node t t) nil)
1257 ;; Then keep moving down to last subnode, unless we reach an index.
1258 (while (and (not (string-match "\\<index\\>" Info-current-node))
1259 (save-excursion (search-forward "\n* Menu:" nil t)))
1260 (Info-goto-node (Info-extract-menu-counting nil)))))
1261
1262 (defun Info-forward-node (&optional not-down no-error)
1263 "Go forward one node, considering all nodes as forming one sequence."
1264 (interactive)
1265 (goto-char (point-min))
1266 (forward-line 1)
1267 ;; three possibilities, in order of priority:
1268 ;; 1. next node is in a menu in this node (but not in an index)
1269 ;; 2. next node is next at same level
1270 ;; 3. next node is up and next
1271 (cond ((and (not not-down)
1272 (save-excursion (search-forward "\n* menu:" nil t))
1273 (not (string-match "\\<index\\>" Info-current-node)))
1274 (Info-goto-node (Info-extract-menu-counting 1))
1275 t)
1276 ((save-excursion (search-backward "next:" nil t))
1277 (Info-next)
1278 t)
1279 ((and (save-excursion (search-backward "up:" nil t))
1280 ;; Use string-equal, not equal, to ignore text props.
1281 (not (string-equal (downcase (Info-extract-pointer "up"))
1282 "top")))
1283 (let ((old-node Info-current-node))
1284 (Info-up)
1285 (let (Info-history success)
1286 (unwind-protect
1287 (setq success (Info-forward-node t no-error))
1288 (or success (Info-goto-node old-node))))))
1289 (no-error nil)
1290 (t (error "No pointer forward from this node"))))
1291
1292 (defun Info-backward-node ()
1293 "Go backward one node, considering all nodes as forming one sequence."
1294 (interactive)
1295 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1296 (upnode (Info-extract-pointer "up" t)))
1297 (cond ((and upnode (string-match "(" upnode))
1298 (error "First node in file"))
1299 ((and upnode (or (null prevnode)
1300 ;; Use string-equal, not equal,
1301 ;; to ignore text properties.
1302 (string-equal (downcase prevnode)
1303 (downcase upnode))))
1304 (Info-up))
1305 (prevnode
1306 ;; If we move back at the same level,
1307 ;; go down to find the last subnode*.
1308 (Info-prev)
1309 (let (Info-history)
1310 (while (and (not (string-match "\\<index\\>" Info-current-node))
1311 (save-excursion (search-forward "\n* Menu:" nil t)))
1312 (Info-goto-node (Info-extract-menu-counting nil)))))
1313 (t
1314 (error "No pointer backward from this node")))))
1315
1316 (defun Info-exit ()
1317 "Exit Info by selecting some other buffer."
1318 (interactive)
1319 (if Info-standalone
1320 (save-buffers-kill-emacs)
1321 (quit-window)))
1322
1323 (defun Info-next-menu-item ()
1324 (interactive)
1325 (save-excursion
1326 (forward-line -1)
1327 (search-forward "\n* menu:" nil t)
1328 (or (search-forward "\n* " nil t)
1329 (error "No more items in menu"))
1330 (Info-goto-node (Info-extract-menu-node-name))))
1331
1332 (defun Info-last-menu-item ()
1333 (interactive)
1334 (save-excursion
1335 (forward-line 1)
1336 (let ((beg (save-excursion
1337 (and (search-backward "\n* menu:" nil t)
1338 (point)))))
1339 (or (and beg (search-backward "\n* " beg t))
1340 (error "No previous items in menu")))
1341 (Info-goto-node (save-excursion
1342 (goto-char (match-end 0))
1343 (Info-extract-menu-node-name)))))
1344
1345 (defmacro Info-no-error (&rest body)
1346 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1347
1348 (defun Info-next-preorder ()
1349 "Go to the next subnode or the next node, or go up a level."
1350 (interactive)
1351 (cond ((Info-no-error (Info-next-menu-item)))
1352 ((Info-no-error (Info-next)))
1353 ((Info-no-error (Info-up t))
1354 ;; Since we have already gone thru all the items in this menu,
1355 ;; go up to the end of this node.
1356 (goto-char (point-max))
1357 ;; Since logically we are done with the node with that menu,
1358 ;; move on from it.
1359 (Info-next-preorder))
1360 (t
1361 (error "No more nodes"))))
1362
1363 (defun Info-last-preorder ()
1364 "Go to the last node, popping up a level if there is none."
1365 (interactive)
1366 (cond ((Info-no-error
1367 (Info-last-menu-item)
1368 ;; If we go down a menu item, go to the end of the node
1369 ;; so we can scroll back through it.
1370 (goto-char (point-max)))
1371 ;; Keep going down, as long as there are nested menu nodes.
1372 (while (Info-no-error
1373 (Info-last-menu-item)
1374 ;; If we go down a menu item, go to the end of the node
1375 ;; so we can scroll back through it.
1376 (goto-char (point-max))))
1377 (recenter -1))
1378 ((and (not (equal (Info-extract-pointer "up")
1379 (Info-extract-pointer "prev"))))
1380 (Info-no-error (Info-prev))
1381 (goto-char (point-max))
1382 (while (Info-no-error
1383 (Info-last-menu-item)
1384 ;; If we go down a menu item, go to the end of the node
1385 ;; so we can scroll back through it.
1386 (goto-char (point-max))))
1387 (recenter -1))
1388 ((Info-no-error (Info-up t))
1389 (goto-char (point-min))
1390 (or (search-forward "\n* Menu:" nil t)
1391 (goto-char (point-max))))
1392 (t (error "No previous nodes"))))
1393
1394 (defun Info-scroll-up ()
1395 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1396 Once you scroll far enough in a node that its menu appears on the screen
1397 but after point, the next scroll moves into its first subnode.
1398
1399 When you scroll past the end of a node, that goes to the next node; if
1400 this node has no successor, it moves to the parent node's successor,
1401 and so on. If point is inside the menu of a node, it moves to
1402 subnode indicated by the following menu item. (That case won't
1403 normally result from this command, but can happen in other ways.)"
1404
1405 (interactive)
1406 (if (or (< (window-start) (point-min))
1407 (> (window-start) (point-max)))
1408 (set-window-start (selected-window) (point)))
1409 (let ((virtual-end (save-excursion
1410 (goto-char (point-min))
1411 (if (search-forward "\n* Menu:" nil t)
1412 (point)
1413 (point-max)))))
1414 (if (or (< virtual-end (window-start))
1415 (pos-visible-in-window-p virtual-end))
1416 (Info-next-preorder)
1417 (scroll-up))))
1418
1419 (defun Info-scroll-down ()
1420 "Scroll one screenful back in Info, considering all nodes as one sequence.
1421 Within the menu of a node, this goes to its last subnode.
1422 When you scroll past the beginning of a node, that goes to the
1423 previous node or back up to the parent node."
1424 (interactive)
1425 (if (or (< (window-start) (point-min))
1426 (> (window-start) (point-max)))
1427 (set-window-start (selected-window) (point)))
1428 (let* ((current-point (point))
1429 (virtual-end (save-excursion
1430 (beginning-of-line)
1431 (setq current-point (point))
1432 (goto-char (point-min))
1433 (search-forward "\n* Menu:"
1434 current-point
1435 t))))
1436 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1437 (Info-last-preorder)
1438 (scroll-down))))
1439
1440 (defun Info-next-reference (&optional recur)
1441 "Move cursor to the next cross-reference or menu item in the node."
1442 (interactive)
1443 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1444 (old-pt (point))
1445 (case-fold-search t))
1446 (or (eobp) (forward-char 1))
1447 (or (re-search-forward pat nil t)
1448 (progn
1449 (goto-char (point-min))
1450 (or (re-search-forward pat nil t)
1451 (progn
1452 (goto-char old-pt)
1453 (error "No cross references in this node")))))
1454 (goto-char (match-beginning 0))
1455 (if (looking-at "\\* Menu:")
1456 (if recur
1457 (error "No cross references in this node")
1458 (Info-next-reference t)))))
1459
1460 (defun Info-prev-reference (&optional recur)
1461 "Move cursor to the previous cross-reference or menu item in the node."
1462 (interactive)
1463 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1464 (old-pt (point))
1465 (case-fold-search t))
1466 (or (re-search-backward pat nil t)
1467 (progn
1468 (goto-char (point-max))
1469 (or (re-search-backward pat nil t)
1470 (progn
1471 (goto-char old-pt)
1472 (error "No cross references in this node")))))
1473 (goto-char (match-beginning 0))
1474 (if (looking-at "\\* Menu:")
1475 (if recur
1476 (error "No cross references in this node")
1477 (Info-prev-reference t)))))
1478
1479 (defun Info-index (topic)
1480 "Look up a string in the index for this file.
1481 The index is defined as the first node in the top-level menu whose
1482 name contains the word \"Index\", plus any immediately following
1483 nodes whose names also contain the word \"Index\".
1484 If there are no exact matches to the specified topic, this chooses
1485 the first match which is a case-insensitive substring of a topic.
1486 Use the `,' command to see the other matches.
1487 Give a blank topic name to go to the Index node itself."
1488 (interactive "sIndex topic: ")
1489 (let ((orignode Info-current-node)
1490 (rnode nil)
1491 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1492 (regexp-quote topic)))
1493 node
1494 (case-fold-search t))
1495 (Info-goto-node "Top")
1496 (or (search-forward "\n* menu:" nil t)
1497 (error "No index"))
1498 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1499 (error "No index"))
1500 (goto-char (match-beginning 1))
1501 ;; Here, and subsequently in this function,
1502 ;; we bind Info-history to nil for internal node-switches
1503 ;; so that we don't put junk in the history.
1504 ;; In the first Info-goto-node call, above, we do update the history
1505 ;; because that is what the user's previous node choice into it.
1506 (let ((Info-history nil))
1507 (Info-goto-node (Info-extract-menu-node-name)))
1508 (or (equal topic "")
1509 (let ((matches nil)
1510 (exact nil)
1511 (Info-history nil)
1512 found)
1513 (while
1514 (progn
1515 (goto-char (point-min))
1516 (while (re-search-forward pattern nil t)
1517 (setq matches
1518 (cons (list (buffer-substring (match-beginning 1)
1519 (match-end 1))
1520 (buffer-substring (match-beginning 2)
1521 (match-end 2))
1522 Info-current-node
1523 (string-to-int (concat "0"
1524 (buffer-substring
1525 (match-beginning 3)
1526 (match-end 3)))))
1527 matches)))
1528 (and (setq node (Info-extract-pointer "next" t))
1529 (string-match "\\<Index\\>" node)))
1530 (Info-goto-node node))
1531 (or matches
1532 (progn
1533 (Info-goto-node orignode)
1534 (error "No `%s' in index" topic)))
1535 ;; Here it is a feature that assoc is case-sensitive.
1536 (while (setq found (assoc topic matches))
1537 (setq exact (cons found exact)
1538 matches (delq found matches)))
1539 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1540 (Info-index-next 0)))))
1541
1542 (defun Info-index-next (num)
1543 "Go to the next matching index item from the last `i' command."
1544 (interactive "p")
1545 (or Info-index-alternatives
1546 (error "No previous `i' command"))
1547 (while (< num 0)
1548 (setq num (+ num (length Info-index-alternatives))))
1549 (while (> num 0)
1550 (setq Info-index-alternatives
1551 (nconc (cdr Info-index-alternatives)
1552 (list (car Info-index-alternatives)))
1553 num (1- num)))
1554 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1555 (if (> (nth 3 (car Info-index-alternatives)) 0)
1556 (forward-line (nth 3 (car Info-index-alternatives)))
1557 (forward-line 3) ; don't search in headers
1558 (let ((name (car (car Info-index-alternatives))))
1559 (Info-find-index-name name)))
1560 (message "Found `%s' in %s. %s"
1561 (car (car Info-index-alternatives))
1562 (nth 2 (car Info-index-alternatives))
1563 (if (cdr Info-index-alternatives)
1564 "(Press `,' for more)"
1565 "(Only match)")))
1566
1567 (defun Info-find-index-name (name)
1568 "Move point to the place within the current node where NAME is defined."
1569 (let ((case-fold-search t))
1570 (if (or (re-search-forward (format
1571 "[a-zA-Z]+: %s\\( \\|$\\)"
1572 (regexp-quote name)) nil t)
1573 (search-forward (format "`%s'" name) nil t)
1574 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1575 (search-forward
1576 (format "`%s'" (substring name 0 (match-beginning 1)))
1577 nil t))
1578 (search-forward name nil t))
1579 (beginning-of-line)
1580 (goto-char (point-min)))))
1581
1582 (defun Info-undefined ()
1583 "Make command be undefined in Info."
1584 (interactive)
1585 (ding))
1586
1587 (defun Info-help ()
1588 "Enter the Info tutorial."
1589 (interactive)
1590 (delete-other-windows)
1591 (Info-find-node "info"
1592 (if (< (window-height) 23)
1593 "Help-Small-Screen"
1594 "Help")))
1595
1596 (defun Info-summary ()
1597 "Display a brief summary of all Info commands."
1598 (interactive)
1599 (save-window-excursion
1600 (switch-to-buffer "*Help*")
1601 (setq buffer-read-only nil)
1602 (erase-buffer)
1603 (insert (documentation 'Info-mode))
1604 (help-mode)
1605 (goto-char (point-min))
1606 (let (ch flag)
1607 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1608 (message (if flag "Type Space to see more"
1609 "Type Space to return to Info"))
1610 (if (not (eq ?\ (setq ch (read-event))))
1611 (progn (setq unread-command-events (list ch)) nil)
1612 flag))
1613 (scroll-up)))
1614 (bury-buffer "*Help*")))
1615 \f
1616 (defun Info-get-token (pos start all &optional errorstring)
1617 "Return the token around POS,
1618 POS must be somewhere inside the token
1619 START is a regular expression which will match the
1620 beginning of the tokens delimited string
1621 ALL is a regular expression with a single
1622 parenthesized subpattern which is the token to be
1623 returned. E.g. '{\(.*\)}' would return any string
1624 enclosed in braces around POS.
1625 SIG optional fourth argument, controls action on no match
1626 nil: return nil
1627 t: beep
1628 a string: signal an error, using that string."
1629 (let ((case-fold-search t))
1630 (save-excursion
1631 (goto-char pos)
1632 ;; First look for a match for START that goes across POS.
1633 (while (and (not (bobp)) (> (point) (- pos (length start)))
1634 (not (looking-at start)))
1635 (forward-char -1))
1636 ;; If we did not find one, search back for START
1637 ;; (this finds only matches that end at or before POS).
1638 (or (looking-at start)
1639 (progn
1640 (goto-char pos)
1641 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
1642 (let (found)
1643 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1644 (not (setq found (and (<= (match-beginning 0) pos)
1645 (> (match-end 0) pos))))))
1646 (if (and found (<= (match-beginning 0) pos)
1647 (> (match-end 0) pos))
1648 (buffer-substring (match-beginning 1) (match-end 1))
1649 (cond ((null errorstring)
1650 nil)
1651 ((eq errorstring t)
1652 (beep)
1653 nil)
1654 (t
1655 (error "No %s around position %d" errorstring pos))))))))
1656
1657 (defun Info-mouse-follow-nearest-node (click)
1658 "\\<Info-mode-map>Follow a node reference near point.
1659 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1660 At end of the node's text, moves to the next node, or up if none."
1661 (interactive "e")
1662 (let* ((start (event-start click))
1663 (window (car start))
1664 (pos (car (cdr start))))
1665 (select-window window)
1666 (goto-char pos))
1667 (and (not (Info-try-follow-nearest-node))
1668 (save-excursion (forward-line 1) (eobp))
1669 (Info-next-preorder)))
1670
1671 (defun Info-follow-nearest-node ()
1672 "\\<Info-mode-map>Follow a node reference near point.
1673 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1674 If no reference to follow, moves to the next node, or up if none."
1675 (interactive)
1676 (or (Info-try-follow-nearest-node)
1677 (Info-next-preorder)))
1678
1679 ;; Common subroutine.
1680 (defun Info-try-follow-nearest-node ()
1681 "Follow a node reference near point. Return non-nil if successful."
1682 (let (node)
1683 (cond
1684 ((setq node (Info-get-token (point) "\\*note[ \n]"
1685 "\\*note[ \n]\\([^:]*\\):"))
1686 (Info-follow-reference node))
1687 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1688 (Info-goto-node node))
1689 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
1690 (beginning-of-line)
1691 (forward-char 2)
1692 (setq node (Info-extract-menu-node-name))
1693 (Info-goto-node node))
1694 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1695 (Info-goto-node node))
1696 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1697 (Info-goto-node node))
1698 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1699 (Info-goto-node "Top"))
1700 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1701 (Info-goto-node node)))
1702 node))
1703 \f
1704 (defvar Info-mode-map nil
1705 "Keymap containing Info commands.")
1706 (if Info-mode-map
1707 nil
1708 (setq Info-mode-map (make-keymap))
1709 (suppress-keymap Info-mode-map)
1710 (define-key Info-mode-map "." 'beginning-of-buffer)
1711 (define-key Info-mode-map " " 'Info-scroll-up)
1712 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1713 (define-key Info-mode-map "\t" 'Info-next-reference)
1714 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1715 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1716 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1717 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1718 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1719 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1720 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1721 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1722 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1723 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1724 (define-key Info-mode-map "0" 'undefined)
1725 (define-key Info-mode-map "?" 'Info-summary)
1726 (define-key Info-mode-map "]" 'Info-forward-node)
1727 (define-key Info-mode-map "[" 'Info-backward-node)
1728 (define-key Info-mode-map "<" 'Info-top-node)
1729 (define-key Info-mode-map ">" 'Info-final-node)
1730 (define-key Info-mode-map "b" 'beginning-of-buffer)
1731 (define-key Info-mode-map "d" 'Info-directory)
1732 (define-key Info-mode-map "e" 'Info-edit)
1733 (define-key Info-mode-map "f" 'Info-follow-reference)
1734 (define-key Info-mode-map "g" 'Info-goto-node)
1735 (define-key Info-mode-map "h" 'Info-help)
1736 (define-key Info-mode-map "i" 'Info-index)
1737 (define-key Info-mode-map "l" 'Info-last)
1738 (define-key Info-mode-map "m" 'Info-menu)
1739 (define-key Info-mode-map "n" 'Info-next)
1740 (define-key Info-mode-map "p" 'Info-prev)
1741 (define-key Info-mode-map "q" 'Info-exit)
1742 (define-key Info-mode-map "s" 'Info-search)
1743 ;; For consistency with Rmail.
1744 (define-key Info-mode-map "\M-s" 'Info-search)
1745 (define-key Info-mode-map "t" 'Info-top-node)
1746 (define-key Info-mode-map "u" 'Info-up)
1747 (define-key Info-mode-map "," 'Info-index-next)
1748 (define-key Info-mode-map "\177" 'Info-scroll-down)
1749 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1750 )
1751
1752 (defun Info-check-pointer (item)
1753 ;; Non-nil if ITEM is present in this node.
1754 (condition-case nil
1755 (Info-extract-pointer item)
1756 (error nil)))
1757
1758 (easy-menu-define Info-mode-menu Info-mode-map
1759 "Menu for info files."
1760 '("Info"
1761 ["Up" Info-up (Info-check-pointer "up")]
1762 ["Next" Info-next (Info-check-pointer "next")]
1763 ["Previous" Info-prev (Info-check-pointer "prev[ious]*")]
1764 ("Menu item" ["You should never see this" report-emacs-bug t])
1765 ("Reference" ["You should never see this" report-emacs-bug t])
1766 ["Search..." Info-search t]
1767 ["Goto node..." Info-goto-node t]
1768 ["Last" Info-last Info-history]
1769 ["Exit" Info-exit t]))
1770
1771 (defvar Info-menu-last-node nil)
1772 ;; Last node the menu was created for.
1773 ;; Value is a list, (FILE-NAME NODE-NAME).
1774
1775 (defun Info-menu-update ()
1776 ;; Update the Info menu for the current node.
1777 (condition-case nil
1778 (if (or (not (eq major-mode 'Info-mode))
1779 (equal (list Info-current-file Info-current-node)
1780 Info-menu-last-node))
1781 ()
1782 ;; Update menu menu.
1783 (let* ((Info-complete-menu-buffer (current-buffer))
1784 (items (nreverse (condition-case nil
1785 (Info-complete-menu-item
1786 "" (lambda (e) t) t)
1787 (error nil))))
1788 entries current
1789 (number 0))
1790 (while (and items (< number 9))
1791 (setq current (car items)
1792 items (cdr items)
1793 number (1+ number))
1794 (setq entries (cons `[,current
1795 (Info-menu ,current)
1796 :keys ,(format "%d" number)]
1797 entries)))
1798 (if items
1799 (setq entries (cons ["Other..." Info-menu t] entries)))
1800 (or entries
1801 (setq entries (list ["No menu" nil nil])))
1802 (easy-menu-change '("Info") "Menu item" (nreverse entries)))
1803 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1804 (let ((items nil)
1805 str i entries current
1806 (number 0)
1807 (case-fold-search t))
1808 (save-excursion
1809 (goto-char (point-min))
1810 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1811 (setq str (buffer-substring
1812 (match-beginning 1)
1813 (1- (point))))
1814 (setq i 0)
1815 (while (setq i (string-match "[ \n\t]+" str i))
1816 (setq str (concat (substring str 0 i) " "
1817 (substring str (match-end 0))))
1818 (setq i (1+ i)))
1819 (setq items
1820 (cons str items))))
1821 (while (and items (< number 9))
1822 (setq current (car items)
1823 items (cdr items)
1824 number (1+ number))
1825 (setq entries (cons `[,current
1826 (Info-follow-reference ,current)
1827 t]
1828 entries)))
1829 (if items
1830 (setq entries (cons ["Other..." Info-follow-reference t]
1831 entries)))
1832 (or entries
1833 (setq entries (list ["No references" nil nil])))
1834 (easy-menu-change '("Info") "Reference" (nreverse entries)))
1835 ;; Update last seen node.
1836 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
1837 ;; Try to avoid entering infinite beep mode in case of errors.
1838 (error (ding))))
1839
1840 \f
1841 ;; Info mode is suitable only for specially formatted data.
1842 (put 'info-mode 'mode-class 'special)
1843
1844 (defun Info-mode ()
1845 "\\<Info-mode-map>
1846 Info mode provides commands for browsing through the Info documentation tree.
1847 Documentation in Info is divided into \"nodes\", each of which discusses
1848 one topic and contains references to other nodes which discuss related
1849 topics. Info has commands to follow the references and show you other nodes.
1850
1851 \\[Info-help] Invoke the Info tutorial.
1852 \\[Info-exit] Quit Info: reselect previously selected buffer.
1853
1854 Selecting other nodes:
1855 \\[Info-mouse-follow-nearest-node]
1856 Follow a node reference you click on.
1857 This works with menu items, cross references, and
1858 the \"next\", \"previous\" and \"up\", depending on where you click.
1859 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
1860 \\[Info-next] Move to the \"next\" node of this node.
1861 \\[Info-prev] Move to the \"previous\" node of this node.
1862 \\[Info-up] Move \"up\" from this node.
1863 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1864 Picking a menu item causes another node to be selected.
1865 \\[Info-directory] Go to the Info directory node.
1866 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1867 \\[Info-last] Move to the last node you were at.
1868 \\[Info-index] Look up a topic in this file's Index and move to that node.
1869 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1870 \\[Info-top-node] Go to the Top node of this file.
1871 \\[Info-final-node] Go to the final node in this file.
1872 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
1873 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
1874
1875 Moving within a node:
1876 \\[Info-scroll-up] Normally, scroll forward a full screen.
1877 Once you scroll far enough in a node that its menu appears on the screen
1878 but after point, the next scroll moves into its first subnode.
1879 When after all menu items (or if their is no menu), move up to
1880 the parent node.
1881 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1882 already visible, try to go to the previous menu entry, or up if there is none.
1883 \\[beginning-of-buffer] Go to beginning of node.
1884
1885 Advanced commands:
1886 \\[Info-exit] Quit Info: reselect previously selected buffer.
1887 \\[Info-edit] Edit contents of selected node.
1888 1 Pick first item in node's menu.
1889 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1890 \\[Info-goto-node] Move to node specified by name.
1891 You may include a filename as well, as (FILENAME)NODENAME.
1892 \\[universal-argument] \\[info] Move to new Info file with completion.
1893 \\[Info-search] Search through this Info file for specified regexp,
1894 and select the node in which the next occurrence is found.
1895 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1896 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1897 (kill-all-local-variables)
1898 (setq major-mode 'Info-mode)
1899 (setq mode-name "Info")
1900 (setq tab-width 8)
1901 (use-local-map Info-mode-map)
1902 (make-local-hook 'activate-menubar-hook)
1903 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
1904 (set-syntax-table text-mode-syntax-table)
1905 (setq local-abbrev-table text-mode-abbrev-table)
1906 (setq case-fold-search t)
1907 (setq buffer-read-only t)
1908 (make-local-variable 'Info-current-file)
1909 (make-local-variable 'Info-current-subfile)
1910 (make-local-variable 'Info-current-node)
1911 (make-local-variable 'Info-tag-table-marker)
1912 (setq Info-tag-table-marker (make-marker))
1913 (make-local-variable 'Info-tag-table-buffer)
1914 (setq Info-tag-table-buffer nil)
1915 (make-local-variable 'Info-history)
1916 (make-local-variable 'Info-index-alternatives)
1917 ;; This is for the sake of the invisible text we use handling titles.
1918 (make-local-variable 'line-move-ignore-invisible)
1919 (setq line-move-ignore-invisible t)
1920 (Info-set-mode-line)
1921 (run-hooks 'Info-mode-hook))
1922
1923 (defvar Info-edit-map nil
1924 "Local keymap used within `e' command of Info.")
1925 (if Info-edit-map
1926 nil
1927 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1928 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1929
1930 ;; Info-edit mode is suitable only for specially formatted data.
1931 (put 'info-edit-mode 'mode-class 'special)
1932
1933 (defun Info-edit-mode ()
1934 "Major mode for editing the contents of an Info node.
1935 Like text mode with the addition of `Info-cease-edit'
1936 which returns to Info mode for browsing.
1937 \\{Info-edit-map}"
1938 (use-local-map Info-edit-map)
1939 (setq major-mode 'Info-edit-mode)
1940 (setq mode-name "Info Edit")
1941 (kill-local-variable 'mode-line-buffer-identification)
1942 (setq buffer-read-only nil)
1943 (force-mode-line-update)
1944 (buffer-enable-undo (current-buffer))
1945 (run-hooks 'Info-edit-mode-hook))
1946
1947 (defun Info-edit ()
1948 "Edit the contents of this Info node.
1949 Allowed only if variable `Info-enable-edit' is non-nil."
1950 (interactive)
1951 (or Info-enable-edit
1952 (error "Editing info nodes is not enabled"))
1953 (Info-edit-mode)
1954 (message "%s" (substitute-command-keys
1955 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1956
1957 (defun Info-cease-edit ()
1958 "Finish editing Info node; switch back to Info proper."
1959 (interactive)
1960 ;; Do this first, so nothing has changed if user C-g's at query.
1961 (and (buffer-modified-p)
1962 (y-or-n-p "Save the file? ")
1963 (save-buffer))
1964 (use-local-map Info-mode-map)
1965 (setq major-mode 'Info-mode)
1966 (setq mode-name "Info")
1967 (Info-set-mode-line)
1968 (setq buffer-read-only t)
1969 (force-mode-line-update)
1970 (and (marker-position Info-tag-table-marker)
1971 (buffer-modified-p)
1972 (message "Tags may have changed. Use Info-tagify if necessary")))
1973 \f
1974 (defvar Info-file-list-for-emacs
1975 '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc")
1976 "List of Info files that describe Emacs commands.
1977 An element can be a file name, or a list of the form (PREFIX . FILE)
1978 where PREFIX is a name prefix and FILE is the file to look in.
1979 If the element is just a file name, the file name also serves as the prefix.")
1980
1981 (defun Info-find-emacs-command-nodes (command)
1982 "Return a list of locations documenting COMMAND.
1983 The `info-file' property of COMMAND says which Info manual to search.
1984 If COMMAND has no property, the variable `Info-file-list-for-emacs'
1985 defines heuristics for which Info manual to try.
1986 The locations are of the format used in Info-history, i.e.
1987 \(FILENAME NODENAME BUFFERPOS\)."
1988 (let ((where '())
1989 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
1990 ":\\s *\\(.*\\)\\.$"))
1991 (info-file "emacs")) ;default
1992 ;; Determine which info file this command is documented in.
1993 (if (get command 'info-file)
1994 (setq info-file (get command 'info-file))
1995 ;; If it doesn't say explicitly, test its name against
1996 ;; various prefixes that we know.
1997 (let ((file-list Info-file-list-for-emacs))
1998 (while file-list
1999 (let* ((elt (car file-list))
2000 (name (if (consp elt)
2001 (car elt)
2002 elt))
2003 (file (if (consp elt) (cdr elt) elt))
2004 (regexp (concat "\\`" (regexp-quote name)
2005 "\\(\\'\\|-\\)")))
2006 (if (string-match regexp (symbol-name command))
2007 (setq info-file file file-list nil))
2008 (setq file-list (cdr file-list))))))
2009 (save-excursion
2010 (condition-case nil
2011 (Info-find-node info-file "Command Index")
2012 ;; Some manuals may not have a separate Command Index node,
2013 ;; so try just Index instead.
2014 (error
2015 (Info-find-node info-file "Index")))
2016 ;; Take the index node off the Info history.
2017 (setq Info-history (cdr Info-history))
2018 (goto-char (point-max))
2019 (while (re-search-backward cmd-desc nil t)
2020 (setq where (cons (list Info-current-file
2021 (buffer-substring
2022 (match-beginning 1)
2023 (match-end 1))
2024 0)
2025 where)))
2026 where)))
2027
2028 ;;;###autoload
2029 (defun Info-goto-emacs-command-node (command)
2030 "Go to the Info node in the Emacs manual for command COMMAND.
2031 The command is found by looking up in Emacs manual's Command Index
2032 or in another manual found via COMMAND's `info-file' property or
2033 the variable `Info-file-list-for-emacs'."
2034 (interactive "CFind documentation for command: ")
2035 (or (commandp command)
2036 (signal 'wrong-type-argument (list 'commandp command)))
2037 (let ((where (Info-find-emacs-command-nodes command)))
2038 (if where
2039 (let ((num-matches (length where)))
2040 ;; Get Info running, and pop to it in another window.
2041 (save-window-excursion
2042 (info))
2043 ;; FIXME It would be cool if this could use a buffer other
2044 ;; than *info*.
2045 (pop-to-buffer "*info*")
2046 (Info-find-node (car (car where))
2047 (car (cdr (car where))))
2048 (if (> num-matches 1)
2049 (progn
2050 ;; Info-find-node already pushed (car where) onto
2051 ;; Info-history. Put the other nodes that were found on
2052 ;; the history.
2053 (setq Info-history (nconc (cdr where) Info-history))
2054 (message "Found %d other entr%s. Use %s to see %s."
2055 (1- num-matches)
2056 (if (> num-matches 2) "ies" "y")
2057 (substitute-command-keys "\\[Info-last]")
2058 (if (> num-matches 2) "them" "it")))))
2059 (error "Couldn't find documentation for %s" command))))
2060
2061 ;;;###autoload
2062 (defun Info-goto-emacs-key-command-node (key)
2063 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2064 Interactively, if the binding is execute-extended-command, a command is read.
2065 The command is found by looking up in Emacs manual's Command Index
2066 or in another manual found via COMMAND's `info-file' property or
2067 the variable `Info-file-list-for-emacs'."
2068 (interactive "kFind documentation for key:")
2069 (let ((command (key-binding key)))
2070 (cond ((null command)
2071 (message "%s is undefined" (key-description key)))
2072 ((and (interactive-p)
2073 (eq command 'execute-extended-command))
2074 (Info-goto-emacs-command-node
2075 (read-command "Find documentation for command: ")))
2076 (t
2077 (Info-goto-emacs-command-node command)))))
2078 \f
2079 (defcustom Info-title-face-alist
2080 '((?* bold underline)
2081 (?= bold-italic underline)
2082 (?- italic underline))
2083 "*Alist of face or list of faces to use for pseudo-underlined titles.
2084 The alist key is the character the title is underlined with (?*, ?= or ?-)."
2085 :type '(repeat (list character face face))
2086 :group 'info)
2087
2088 (defun Info-fontify-node ()
2089 (save-excursion
2090 (let ((buffer-read-only nil)
2091 (case-fold-search t))
2092 (goto-char (point-min))
2093 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2094 (goto-char (match-end 0))
2095 (while
2096 (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2097 (goto-char (match-end 0))
2098 (if (save-excursion
2099 (goto-char (match-beginning 1))
2100 (save-match-data (looking-at "Node:")))
2101 (put-text-property (match-beginning 2) (match-end 2)
2102 'face 'info-node)
2103 (put-text-property (match-beginning 2) (match-end 2)
2104 'face 'info-xref)
2105 (put-text-property (match-beginning 2) (match-end 2)
2106 'mouse-face 'highlight))))
2107 (goto-char (point-min))
2108 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2109 nil t)
2110 (put-text-property (match-beginning 1) (match-end 1)
2111 'face
2112 (cdr (assq (preceding-char) Info-title-face-alist)))
2113 ;; This is a serious problem for trying to handle multiple
2114 ;; frame types at once. We want this text to be invisible
2115 ;; on frames that can display the font above.
2116 (if (memq (framep (selected-frame)) '(x pc w32))
2117 (put-text-property (match-end 1) (match-end 2)
2118 'invisible t)))
2119 (goto-char (point-min))
2120 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
2121 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2122 nil
2123 (put-text-property (match-beginning 1) (match-end 1)
2124 'face 'info-xref)
2125 (put-text-property (match-beginning 1) (match-end 1)
2126 'mouse-face 'highlight)))
2127 (goto-char (point-min))
2128 (if (and (search-forward "\n* Menu:" nil t)
2129 (not (string-match "\\<Index\\>" Info-current-node))
2130 ;; Don't take time to annotate huge menus
2131 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2132 (let ((n 0))
2133 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
2134 (setq n (1+ n))
2135 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
2136 (put-text-property (match-beginning 0)
2137 (1+ (match-beginning 0))
2138 'face 'info-menu-5))
2139 (put-text-property (match-beginning 1) (match-end 1)
2140 'face 'info-xref)
2141 (put-text-property (match-beginning 1) (match-end 1)
2142 'mouse-face 'highlight))))
2143 (set-buffer-modified-p nil))))
2144 \f
2145
2146 ;; When an Info buffer is killed, make sure the associated tags buffer
2147 ;; is killed too.
2148 (defun Info-kill-buffer ()
2149 (and (eq major-mode 'Info-mode)
2150 Info-tag-table-buffer
2151 (kill-buffer Info-tag-table-buffer)))
2152
2153 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2154
2155 ;;; Speedbar support:
2156 ;; These functions permit speedbar to display the "tags" in the
2157 ;; current info node.
2158 (eval-when-compile (require 'speedbar))
2159
2160 (defvar Info-speedbar-key-map nil
2161 "Keymap used when in the info display mode.")
2162
2163 (defun Info-install-speedbar-variables ()
2164 "Install those variables used by speedbar to enhance Info."
2165 (if Info-speedbar-key-map
2166 nil
2167 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2168
2169 ;; Basic tree features
2170 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2171 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2172 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2173 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2174 )
2175
2176 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2177 Info-speedbar-key-map
2178 Info-speedbar-hierarchy-buttons)))
2179
2180 (defvar Info-speedbar-menu-items
2181 '(["Browse Node" speedbar-edit-line t]
2182 ["Expand Node" speedbar-expand-line
2183 (save-excursion (beginning-of-line)
2184 (looking-at "[0-9]+: *.\\+. "))]
2185 ["Contract Node" speedbar-contract-line
2186 (save-excursion (beginning-of-line)
2187 (looking-at "[0-9]+: *.-. "))]
2188 )
2189 "Additional menu-items to add to speedbar frame.")
2190
2191 ;; Make sure our special speedbar major mode is loaded
2192 (if (featurep 'speedbar)
2193 (Info-install-speedbar-variables)
2194 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2195
2196 ;;; Info hierarchy display method
2197 ;;;###autoload
2198 (defun Info-speedbar-browser ()
2199 "Initialize speedbar to display an info node browser.
2200 This will add a speedbar major display mode."
2201 (interactive)
2202 (require 'speedbar)
2203 ;; Make sure that speedbar is active
2204 (speedbar-frame-mode 1)
2205 ;; Now, throw us into Info mode on speedbar.
2206 (speedbar-change-initial-expansion-list "Info")
2207 )
2208
2209 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2210 "Display an Info directory hierarchy in speedbar.
2211 DIRECTORY is the current directory in the attached frame.
2212 DEPTH is the current indentation depth.
2213 NODE is an optional argument that is used to represent the
2214 specific node to expand."
2215 (if (and (not node)
2216 (save-excursion (goto-char (point-min))
2217 (let ((case-fold-search t))
2218 (looking-at "Info Nodes:"))))
2219 ;; Update our "current node" maybe?
2220 nil
2221 ;; We cannot use the generic list code, that depends on all leaves
2222 ;; being known at creation time.
2223 (if (not node)
2224 (speedbar-with-writable (insert "Info Nodes:\n")))
2225 (let ((completions nil)
2226 (cf (selected-frame)))
2227 (select-frame speedbar-attached-frame)
2228 (save-window-excursion
2229 (setq completions
2230 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
2231 (select-frame cf)
2232 (if completions
2233 (speedbar-with-writable
2234 (while completions
2235 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2236 (cdr (car completions))
2237 (car (car completions))
2238 'Info-speedbar-goto-node
2239 (cdr (car completions))
2240 'info-xref depth)
2241 (setq completions (cdr completions)))
2242 t)
2243 nil))))
2244
2245 (defun Info-speedbar-goto-node (text node indent)
2246 "When user clicks on TEXT, goto an info NODE.
2247 The INDENT level is ignored."
2248 (select-frame speedbar-attached-frame)
2249 (let* ((buff (or (get-buffer "*info*")
2250 (progn (info) (get-buffer "*info*"))))
2251 (bwin (get-buffer-window buff 0)))
2252 (if bwin
2253 (progn
2254 (select-window bwin)
2255 (raise-frame (window-frame bwin)))
2256 (if speedbar-power-click
2257 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2258 (select-frame speedbar-attached-frame)
2259 (switch-to-buffer buff)))
2260 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
2261 (file (match-string 1 node))
2262 (node (match-string 2 node)))
2263 (Info-find-node file node)
2264 ;; If we do a find-node, and we were in info mode, restore
2265 ;; the old default method. Once we are in info mode, it makes
2266 ;; sense to return to whatever method the user was using before.
2267 (if (string= speedbar-initial-expansion-list-name "Info")
2268 (speedbar-change-initial-expansion-list
2269 speedbar-previously-used-expansion-list-name)))))
2270
2271 (defun Info-speedbar-expand-node (text token indent)
2272 "Expand the node the user clicked on.
2273 TEXT is the text of the button we clicked on, a + or - item.
2274 TOKEN is data related to this node (NAME . FILE).
2275 INDENT is the current indentation depth."
2276 (cond ((string-match "+" text) ;we have to expand this file
2277 (speedbar-change-expand-button-char ?-)
2278 (if (speedbar-with-writable
2279 (save-excursion
2280 (end-of-line) (forward-char 1)
2281 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
2282 (speedbar-change-expand-button-char ?-)
2283 (speedbar-change-expand-button-char ??)))
2284 ((string-match "-" text) ;we have to contract this node
2285 (speedbar-change-expand-button-char ?+)
2286 (speedbar-delete-subblock indent))
2287 (t (error "Ooops... not sure what to do")))
2288 (speedbar-center-buffer-smartly))
2289
2290 (defun Info-speedbar-fetch-file-nodes (nodespec)
2291 "Fetch the subnodes from the info NODESPEC.
2292 NODESPEC is a string of the form: (file)node.
2293 Optional THISFILE represends the filename of"
2294 (save-excursion
2295 ;; Set up a buffer we can use to fake-out Info.
2296 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2297 (if (not (equal major-mode 'Info-mode))
2298 (Info-mode))
2299 ;; Get the node into this buffer
2300 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
2301 (file (match-string 1 nodespec))
2302 (node (match-string 2 nodespec)))
2303 (Info-find-node file node))
2304 ;; Scan the created buffer
2305 (goto-char (point-min))
2306 (let ((completions nil)
2307 (case-fold-search t)
2308 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
2309 (match-string 1 nodespec))))
2310 ;; Always skip the first one...
2311 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2312 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2313 (let ((name (match-string 1)))
2314 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2315 (setq name (cons name (match-string 1)))
2316 (if (looking-at " *\\(([^)]+)\\)\\.")
2317 (setq name (cons name (concat (match-string 1) "Top")))
2318 (if (looking-at " \\([^.]+\\).")
2319 (setq name
2320 (cons name (concat "(" thisfile ")" (match-string 1))))
2321 (setq name (cons name (concat "(" thisfile ")" name))))))
2322 (setq completions (cons name completions))))
2323 (nreverse completions))))
2324
2325 ;;; Info mode node listing
2326 (defun Info-speedbar-buttons (buffer)
2327 "Create a speedbar display to help navigation in an Info file.
2328 BUFFER is the buffer speedbar is requesting buttons for."
2329 (if (save-excursion (goto-char (point-min))
2330 (let ((case-fold-search t))
2331 (not (looking-at "Info Nodes:"))))
2332 (erase-buffer))
2333 (Info-speedbar-hierarchy-buttons nil 0)
2334 )
2335
2336 (provide 'info)
2337
2338 ;;; info.el ends here