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