(Fframe_parameters) [!MULTI_FRAME]: Unstub it again.
[emacs.git] / lisp / info.el
blob881aecccaa32c5b9ecdda8b6bea487f0ed880af9
1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 1986, 1992, 1993 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: help
8 ;; This file is part of GNU Emacs.
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.
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.
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
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 ;;; Commentary:
26 ;;; Note that nowadays we expect info files to be made using makeinfo.
28 ;;; Code:
30 (defvar Info-history nil
31 "List of info nodes user has visited.
32 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
34 (defvar Info-enable-edit nil
35 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
36 This is convenient if you want to write info files by hand.
37 However, we recommend that you not do this.
38 It is better to write a Texinfo file and generate the Info file from that,
39 because that gives you a printed manual as well.")
41 (defvar Info-enable-active-nodes t
42 "Non-nil allows Info to execute Lisp code associated with nodes.
43 The Lisp code is executed when the node is selected.")
45 (defvar Info-default-directory-list nil
46 "List of default directories to search for Info documentation files.
47 This value is used as the default for `Info-directory-list'. It is set
48 in paths.el.")
50 (defvar Info-fontify t
51 "*Non-nil enables highlighting and fonts in Info nodes.")
53 (defvar Info-directory-list
54 (let ((path (getenv "INFOPATH"))
55 (sibling (expand-file-name "../info/" (invocation-directory))))
56 (if path
57 (let ((list nil)
58 idx)
59 (while (> (length path) 0)
60 (setq idx (or (string-match ":" path) (length path))
61 list (cons (substring path 0 idx) list)
62 path (substring path (min (1+ idx)
63 (length path)))))
64 (nreverse list))
65 (if (or (member sibling Info-default-directory-list)
66 (not (file-exists-p sibling)))
67 Info-default-directory-list
68 (reverse (cons sibling (cdr (reverse Info-default-directory-list)))))))
69 "List of directories to search for Info documentation files.
70 nil means not yet initialized. In this case, Info uses the environment
71 variable INFOPATH to initialize it, or `Info-default-directory-list'
72 if there is no INFOPATH variable in the environment.")
74 (defvar Info-current-file nil
75 "Info file that Info is now looking at, or nil.")
77 (defvar Info-current-subfile nil
78 "Info subfile that is actually in the *info* buffer now,
79 or nil if current info file is not split into subfiles.")
81 (defvar Info-current-node nil
82 "Name of node that Info is now looking at, or nil.")
84 (defvar Info-tag-table-marker (make-marker)
85 "Marker pointing at beginning of current Info file's tag table.
86 Marker points nowhere if file has no tag table.")
88 (defvar Info-current-file-completions nil
89 "Cached completion list for current Info file.")
91 (defvar Info-index-alternatives nil
92 "List of possible matches for last Info-index command.")
94 (defvar Info-standalone nil
95 "Non-nil if Emacs was started solely as an Info browser.")
97 (defvar Info-suffix-list '( (".info.Z" . "uncompress")
98 (".info.Y" . "unyabba")
99 (".info.gz" . "gunzip")
100 (".info.z" . "gunzip")
101 (".info" . nil)
102 (".Z" . "uncompress")
103 (".Y" . "unyabba")
104 (".gz" . "gunzip")
105 (".z" . "gunzip")
106 ("" . nil))
107 "List of file name suffixes and associated decoding commands.
108 Each entry should be (SUFFIX . STRING); the file is given to
109 the command as standard input. If STRING is nil, no decoding is done.
110 Because the SUFFIXes are tried in order, the empty string should
111 be last in the list.")
113 (defun info-insert-file-contents (filename &optional visit)
114 "Insert the contents of an info file in the current buffer.
115 Do the right thing if the file has been compressed or zipped."
116 (let ((tail Info-suffix-list)
117 fullname decoder)
118 (if (file-exists-p filename)
119 (progn
120 (while (and tail
121 (not (string-match
122 (concat (regexp-quote (car (car tail))) "$")
123 filename)))
124 (setq tail (cdr tail)))
125 (setq fullname filename
126 decoder (cdr (car tail))))
127 (while (and tail
128 (not (file-exists-p (concat filename (car (car tail))))))
129 (setq tail (cdr tail)))
130 (setq fullname (concat filename (car (car tail)))
131 decoder (cdr (car tail)))
132 (or tail
133 (error "Can't find %s or any compressed version of it!" filename)))
134 (insert-file-contents fullname visit)
135 (if decoder
136 (let ((buffer-read-only nil))
137 (shell-command-on-region (point-min) (point-max) decoder t)))))
139 ;;;###autoload
140 (defun info (&optional file)
141 "Enter Info, the documentation browser.
142 Optional argument FILE specifies the file to examine;
143 the default is the top-level directory of Info.
145 In interactive use, a prefix argument directs this command
146 to read a file name from the minibuffer."
147 (interactive (if current-prefix-arg
148 (list (read-file-name "Info file name: " nil nil t))))
149 (if file
150 (Info-goto-node (concat "(" file ")"))
151 (if (get-buffer "*info*")
152 (switch-to-buffer "*info*")
153 (Info-directory))))
155 ;;;###autoload
156 (defun info-standalone ()
157 "Run Emacs as a standalone Info reader.
158 Usage: emacs -f info-standalone [filename]
159 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
160 (setq Info-standalone t)
161 (if (and command-line-args-left
162 (not (string-match "^-" (car command-line-args-left))))
163 (condition-case err
164 (progn
165 (info (car command-line-args-left))
166 (setq command-line-args-left (cdr command-line-args-left)))
167 (error (send-string-to-terminal
168 (format "%s\n" (if (eq (car-safe err) 'error)
169 (nth 1 err) err)))
170 (save-buffers-kill-emacs)))
171 (info)))
173 ;; Go to an info node specified as separate filename and nodename.
174 ;; no-going-back is non-nil if recovering from an error in this function;
175 ;; it says do not attempt further (recursive) error recovery.
176 (defun Info-find-node (filename nodename &optional no-going-back)
177 ;; Convert filename to lower case if not found as specified.
178 ;; Expand it.
179 (if filename
180 (let (temp temp-downcase found)
181 (setq filename (substitute-in-file-name filename))
182 (if (string= (downcase (file-name-nondirectory filename)) "dir")
183 (setq found t)
184 (let ((dirs (if (string-match "^\\./" filename)
185 ;; If specified name starts with `./'
186 ;; then just try current directory.
187 '("./")
188 Info-directory-list)))
189 ;; Search the directory list for file FILENAME.
190 (while (and dirs (not found))
191 (setq temp (expand-file-name filename (car dirs)))
192 (setq temp-downcase
193 (expand-file-name (downcase filename) (car dirs)))
194 ;; Try several variants of specified name.
195 (catch 'foundit
196 (mapcar
197 (function
198 (lambda (x)
199 (if (file-exists-p (concat temp (car x)))
200 (progn
201 (setq found temp)
202 (throw 'foundit nil)))
203 (if (file-exists-p (concat temp-downcase (car x)))
204 (progn
205 (setq found temp-downcase)
206 (throw 'foundit nil)))))
207 Info-suffix-list))
208 (setq dirs (cdr dirs)))))
209 (if found
210 (setq filename found)
211 (error "Info file %s does not exist" filename))))
212 ;; Record the node we are leaving.
213 (if (and Info-current-file (not no-going-back))
214 (setq Info-history
215 (cons (list Info-current-file Info-current-node (point))
216 Info-history)))
217 ;; Go into info buffer.
218 (switch-to-buffer "*info*")
219 (buffer-disable-undo (current-buffer))
220 (or (eq major-mode 'Info-mode)
221 (Info-mode))
222 (widen)
223 (setq Info-current-node nil)
224 (unwind-protect
225 (progn
226 ;; Switch files if necessary
227 (or (null filename)
228 (equal Info-current-file filename)
229 (let ((buffer-read-only nil))
230 (setq Info-current-file nil
231 Info-current-subfile nil
232 Info-current-file-completions nil
233 Info-index-alternatives nil
234 buffer-file-name nil)
235 (erase-buffer)
236 (if (eq filename t)
237 (Info-insert-dir)
238 (info-insert-file-contents filename t)
239 (setq default-directory (file-name-directory filename)))
240 (set-buffer-modified-p nil)
241 ;; See whether file has a tag table. Record the location if yes.
242 (set-marker Info-tag-table-marker nil)
243 (goto-char (point-max))
244 (forward-line -8)
245 (or (equal nodename "*")
246 (not (search-forward "\^_\nEnd tag table\n" nil t))
247 (let (pos)
248 ;; We have a tag table. Find its beginning.
249 ;; Is this an indirect file?
250 (search-backward "\nTag table:\n")
251 (setq pos (point))
252 (if (save-excursion
253 (forward-line 2)
254 (looking-at "(Indirect)\n"))
255 ;; It is indirect. Copy it to another buffer
256 ;; and record that the tag table is in that buffer.
257 (save-excursion
258 (let ((buf (current-buffer)))
259 (set-buffer (get-buffer-create " *info tag table*"))
260 (buffer-disable-undo (current-buffer))
261 (setq case-fold-search t)
262 (erase-buffer)
263 (insert-buffer-substring buf)
264 (set-marker Info-tag-table-marker
265 (match-end 0))))
266 (set-marker Info-tag-table-marker pos))))
267 (setq Info-current-file
268 (if (eq filename t) "dir"
269 (file-name-sans-versions buffer-file-name)))))
270 (if (equal nodename "*")
271 (progn (setq Info-current-node nodename)
272 (Info-set-mode-line))
273 ;; Search file for a suitable node.
274 (let ((guesspos (point-min))
275 (regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n\177]")))
276 ;; First get advice from tag table if file has one.
277 ;; Also, if this is an indirect info file,
278 ;; read the proper subfile into this buffer.
279 (if (marker-position Info-tag-table-marker)
280 (save-excursion
281 (set-buffer (marker-buffer Info-tag-table-marker))
282 (goto-char Info-tag-table-marker)
283 (if (re-search-forward regexp nil t)
284 (progn
285 (setq guesspos (read (current-buffer)))
286 ;; If this is an indirect file,
287 ;; determine which file really holds this node
288 ;; and read it in.
289 (if (not (eq (current-buffer) (get-buffer "*info*")))
290 (setq guesspos
291 (Info-read-subfile guesspos))))
292 (error "No such node: \"%s\"" nodename))))
293 (goto-char (max (point-min) (- guesspos 1000)))
294 ;; Now search from our advised position (or from beg of buffer)
295 ;; to find the actual node.
296 (catch 'foo
297 (while (search-forward "\n\^_" nil t)
298 (forward-line 1)
299 (let ((beg (point)))
300 (forward-line 1)
301 (if (re-search-backward regexp beg t)
302 (throw 'foo t))))
303 (error "No such node: %s" nodename)))
304 (Info-select-node)))
305 ;; If we did not finish finding the specified node,
306 ;; go back to the previous one.
307 (or Info-current-node no-going-back (null Info-history)
308 (let ((hist (car Info-history)))
309 (setq Info-history (cdr Info-history))
310 (Info-find-node (nth 0 hist) (nth 1 hist) t)
311 (goto-char (nth 2 hist)))))
312 (goto-char (point-min)))
314 ;; Cache the contents of the (virtual) dir file, once we have merged
315 ;; it for the first time, so we can save time subsequently.
316 (defvar Info-dir-contents nil)
318 ;; Cache for the directory we decided to use for the default-directory
319 ;; of the merged dir text.
320 (defvar Info-dir-contents-directory nil)
322 ;; Record the file attributes of all the files from which we
323 ;; constructed Info-dir-contents.
324 (defvar Info-dir-file-attributes nil)
326 ;; Construct the Info directory node by merging the files named `dir'
327 ;; from various directories. Set the *info* buffer's
328 ;; default-directory to the first directory we actually get any text
329 ;; from.
330 (defun Info-insert-dir ()
331 (if (and Info-dir-contents Info-dir-file-attributes
332 ;; Verify that none of the files we used has changed
333 ;; since we used it.
334 (eval (cons 'and
335 (mapcar '(lambda (elt)
336 (equal (cdr elt)
337 (file-attributes (car elt))))
338 Info-dir-file-attributes))))
339 (insert Info-dir-contents)
340 (let ((dirs Info-directory-list)
341 buffers buffer others nodes dirs-done)
343 ;; Search the directory list for the directory file.
344 (while dirs
345 (let ((truename (file-truename (expand-file-name (car dirs)))))
346 (or (member truename dirs-done)
347 (member (directory-file-name truename) dirs-done)
348 ;; Try several variants of specified name.
349 ;; Try upcasing, appending `.info', or both.
350 (let* (temp
351 (buffer
352 (cond
353 ((progn (setq temp (expand-file-name "DIR" (car dirs)))
354 (file-exists-p temp))
355 (find-file-noselect temp))
356 ((progn (setq temp (expand-file-name "dir" (car dirs)))
357 (file-exists-p temp))
358 (find-file-noselect temp))
359 ((progn (setq temp (expand-file-name "DIR.INFO" (car dirs)))
360 (file-exists-p temp))
361 (find-file-noselect temp))
362 ((progn (setq temp (expand-file-name "dir.info" (car dirs)))
363 (file-exists-p temp))
364 (find-file-noselect temp)))))
365 (setq dirs-done
366 (cons truename
367 (cons (directory-file-name truename)
368 dirs-done)))
369 (if buffer (setq buffers (cons buffer buffers)
370 Info-dir-file-attributes
371 (cons (cons (buffer-file-name buffer)
372 (file-attributes (buffer-file-name buffer)))
373 Info-dir-file-attributes))))))
374 (setq dirs (cdr dirs)))
376 (or buffers
377 (error "Can't find the info directory node"))
378 ;; Distinguish the dir file that comes with Emacs from all the
379 ;; others. Yes, that is really what this is supposed to do.
380 ;; If it doesn't work, fix it.
381 (setq buffer (car buffers)
382 others (cdr buffers))
384 ;; Insert the entire original dir file as a start; use its
385 ;; default directory as the default directory for the whole
386 ;; concatenation.
387 (insert-buffer buffer)
388 (setq Info-dir-contents-directory (save-excursion
389 (set-buffer buffer)
390 default-directory))
392 ;; Look at each of the other buffers one by one.
393 (while others
394 (let ((other (car others)))
395 ;; In each, find all the menus.
396 (save-excursion
397 (set-buffer other)
398 (goto-char (point-min))
399 ;; Find each menu, and add an elt to NODES for it.
400 (while (re-search-forward "^\\* Menu:" nil t)
401 (let (beg nodename end)
402 (forward-line 1)
403 (setq beg (point))
404 (search-backward "\n\^_")
405 (search-forward "Node: ")
406 (setq nodename (Info-following-node-name))
407 (search-forward "\n\^_" nil 'move)
408 (beginning-of-line)
409 (setq end (point))
410 (setq nodes (cons (list nodename other beg end) nodes))))))
411 (setq others (cdr others)))
412 ;; Add to the main menu a menu item for each other node.
413 (re-search-forward "^\\* Menu:")
414 (forward-line 1)
415 (let ((menu-items '("top"))
416 (nodes nodes)
417 (case-fold-search t)
418 (end (save-excursion (search-forward "\^_" nil t) (point))))
419 (while nodes
420 (let ((nodename (car (car nodes))))
421 (save-excursion
422 (or (member (downcase nodename) menu-items)
423 (re-search-forward (concat "^\\* "
424 (regexp-quote nodename)
425 "::")
426 end t)
427 (progn
428 (insert "* " nodename "::" "\n")
429 (setq menu-items (cons nodename menu-items))))))
430 (setq nodes (cdr nodes))))
431 ;; Now take each node of each of the other buffers
432 ;; and merge it into the main buffer.
433 (while nodes
434 (let ((nodename (car (car nodes))))
435 (goto-char (point-min))
436 ;; Find the like-named node in the main buffer.
437 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
438 (regexp-quote nodename)
439 "[,\n\t]")
440 nil t)
441 (progn
442 (search-forward "\n\^_" nil 'move)
443 (beginning-of-line))
444 ;; If none exists, add one.
445 (goto-char (point-max))
446 (insert "\^_\nFile: dir\tnode: " nodename "\n\n* Menu:\n\n"))
447 ;; Merge the text from the other buffer's menu
448 ;; into the menu in the like-named node in the main buffer.
449 (apply 'insert-buffer-substring (cdr (car nodes)))
450 (insert "\n"))
451 (setq nodes (cdr nodes)))
452 ;; Kill all the buffers we just made.
453 (while buffers
454 (kill-buffer (car buffers))
455 (setq buffers (cdr buffers))))
456 (setq Info-dir-contents (buffer-string)))
457 (setq default-directory Info-dir-contents-directory))
459 (defun Info-read-subfile (nodepos)
460 (set-buffer (marker-buffer Info-tag-table-marker))
461 (goto-char (point-min))
462 (search-forward "\n\^_")
463 (let (lastfilepos
464 lastfilename)
465 (forward-line 2)
466 (catch 'foo
467 (while (not (looking-at "\^_"))
468 (if (not (eolp))
469 (let ((beg (point))
470 thisfilepos thisfilename)
471 (search-forward ": ")
472 (setq thisfilename (buffer-substring beg (- (point) 2)))
473 (setq thisfilepos (read (current-buffer)))
474 ;; read in version 19 stops at the end of number.
475 ;; Advance to the next line.
476 (forward-line 1)
477 (if (> thisfilepos nodepos)
478 (throw 'foo t))
479 (setq lastfilename thisfilename)
480 (setq lastfilepos thisfilepos))
481 (forward-line 1))))
482 (set-buffer (get-buffer "*info*"))
483 (or (equal Info-current-subfile lastfilename)
484 (let ((buffer-read-only nil))
485 (setq buffer-file-name nil)
486 (widen)
487 (erase-buffer)
488 (info-insert-file-contents lastfilename)
489 (set-buffer-modified-p nil)
490 (setq Info-current-subfile lastfilename)))
491 (goto-char (point-min))
492 (search-forward "\n\^_")
493 (+ (- nodepos lastfilepos) (point))))
495 ;; Select the info node that point is in.
496 (defun Info-select-node ()
497 (save-excursion
498 ;; Find beginning of node.
499 (search-backward "\n\^_")
500 (forward-line 2)
501 ;; Get nodename spelled as it is in the node.
502 (re-search-forward "Node:[ \t]*")
503 (setq Info-current-node
504 (buffer-substring (point)
505 (progn
506 (skip-chars-forward "^,\t\n")
507 (point))))
508 (Info-set-mode-line)
509 ;; Find the end of it, and narrow.
510 (beginning-of-line)
511 (let (active-expression)
512 (narrow-to-region (point)
513 (if (re-search-forward "\n[\^_\f]" nil t)
514 (prog1
515 (1- (point))
516 (if (looking-at "[\n\^_\f]*execute: ")
517 (progn
518 (goto-char (match-end 0))
519 (setq active-expression
520 (read (current-buffer))))))
521 (point-max)))
522 (if Info-enable-active-nodes (eval active-expression))
523 (if Info-fontify (Info-fontify-node))
524 (run-hooks 'Info-selection-hook))))
526 (defun Info-set-mode-line ()
527 (setq mode-line-buffer-identification
528 (concat
529 "Info: ("
530 (if Info-current-file
531 (file-name-nondirectory Info-current-file)
534 (or Info-current-node ""))))
536 ;; Go to an info node specified with a filename-and-nodename string
537 ;; of the sort that is found in pointers in nodes.
539 (defun Info-goto-node (nodename)
540 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
541 (interactive (list (Info-read-node-name "Goto node: ")))
542 (let (filename)
543 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
544 nodename)
545 (setq filename (if (= (match-beginning 1) (match-end 1))
547 (substring nodename (match-beginning 2) (match-end 2)))
548 nodename (substring nodename (match-beginning 3) (match-end 3)))
549 (let ((trim (string-match "\\s *\\'" filename)))
550 (if trim (setq filename (substring filename 0 trim))))
551 (let ((trim (string-match "\\s *\\'" nodename)))
552 (if trim (setq nodename (substring nodename 0 trim))))
553 (Info-find-node (if (equal filename "") nil filename)
554 (if (equal nodename "") "Top" nodename))))
556 (defun Info-read-node-name (prompt &optional default)
557 (let* ((completion-ignore-case t)
558 (nodename (completing-read prompt (Info-build-node-completions))))
559 (if (equal nodename "")
560 (or default
561 (Info-read-node-name prompt))
562 nodename)))
564 (defun Info-build-node-completions ()
565 (or Info-current-file-completions
566 (let ((compl nil))
567 (save-excursion
568 (save-restriction
569 (if (marker-buffer Info-tag-table-marker)
570 (progn
571 (set-buffer (marker-buffer Info-tag-table-marker))
572 (widen)
573 (goto-char Info-tag-table-marker)
574 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
575 (setq compl
576 (cons (list (buffer-substring (match-beginning 1)
577 (match-end 1)))
578 compl))))
579 (widen)
580 (goto-char (point-min))
581 (while (search-forward "\n\^_" nil t)
582 (forward-line 1)
583 (let ((beg (point)))
584 (forward-line 1)
585 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
586 beg t)
587 (setq compl
588 (cons (list (buffer-substring (match-beginning 1)
589 (match-end 1)))
590 compl))))))))
591 (setq Info-current-file-completions compl))))
593 (defun Info-restore-point (hl)
594 "If this node has been visited, restore the point value when we left."
595 (while hl
596 (if (and (equal (nth 0 (car hl)) Info-current-file)
597 (equal (nth 1 (car hl)) Info-current-node))
598 (progn
599 (goto-char (nth 2 (car hl)))
600 (setq hl nil)) ;terminate the while at next iter
601 (setq hl (cdr hl)))))
603 (defvar Info-last-search nil
604 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
606 (defun Info-search (regexp)
607 "Search for REGEXP, starting from point, and select node it's found in."
608 (interactive "sSearch (regexp): ")
609 (if (equal regexp "")
610 (setq regexp Info-last-search)
611 (setq Info-last-search regexp))
612 (let ((found ()) current
613 (onode Info-current-node)
614 (ofile Info-current-file)
615 (opoint (point))
616 (osubfile Info-current-subfile))
617 (save-excursion
618 (save-restriction
619 (widen)
620 (if (null Info-current-subfile)
621 (progn (re-search-forward regexp) (setq found (point)))
622 (condition-case err
623 (progn (re-search-forward regexp) (setq found (point)))
624 (search-failed nil)))))
625 (if (not found) ;can only happen in subfile case -- else would have erred
626 (unwind-protect
627 (let ((list ()))
628 (set-buffer (marker-buffer Info-tag-table-marker))
629 (goto-char (point-min))
630 (search-forward "\n\^_\nIndirect:")
631 (save-restriction
632 (narrow-to-region (point)
633 (progn (search-forward "\n\^_")
634 (1- (point))))
635 (goto-char (point-min))
636 (search-forward (concat "\n" osubfile ": "))
637 (beginning-of-line)
638 (while (not (eobp))
639 (re-search-forward "\\(^.*\\): [0-9]+$")
640 (goto-char (+ (match-end 1) 2))
641 (setq list (cons (cons (read (current-buffer))
642 (buffer-substring (match-beginning 1)
643 (match-end 1)))
644 list))
645 (goto-char (1+ (match-end 0))))
646 (setq list (nreverse list)
647 current (car (car list))
648 list (cdr list)))
649 (while list
650 (message "Searching subfile %s..." (cdr (car list)))
651 (Info-read-subfile (car (car list)))
652 (setq list (cdr list))
653 (goto-char (point-min))
654 (if (re-search-forward regexp nil t)
655 (setq found (point) list ())))
656 (if found
657 (message "")
658 (signal 'search-failed (list regexp))))
659 (if (not found)
660 (progn (Info-read-subfile opoint)
661 (goto-char opoint)
662 (Info-select-node)))))
663 (widen)
664 (goto-char found)
665 (Info-select-node)
666 (or (and (equal onode Info-current-node)
667 (equal ofile Info-current-file))
668 (setq Info-history (cons (list ofile onode opoint)
669 Info-history)))))
671 ;; Extract the value of the node-pointer named NAME.
672 ;; If there is none, use ERRORNAME in the error message;
673 ;; if ERRORNAME is nil, just return nil.
674 (defun Info-extract-pointer (name &optional errorname)
675 (save-excursion
676 (goto-char (point-min))
677 (forward-line 1)
678 (if (re-search-backward (concat name ":") nil t)
679 (progn
680 (goto-char (match-end 0))
681 (Info-following-node-name))
682 (if (eq errorname t)
684 (error (concat "Node has no " (capitalize (or errorname name))))))))
686 ;; Return the node name in the buffer following point.
687 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
688 ;; saying which chas may appear in the node name.
689 (defun Info-following-node-name (&optional allowedchars)
690 (skip-chars-forward " \t")
691 (buffer-substring
692 (point)
693 (progn
694 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
695 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
696 (if (looking-at "(")
697 (skip-chars-forward "^)")))
698 (skip-chars-backward " ")
699 (point))))
701 (defun Info-next ()
702 "Go to the next node of this node."
703 (interactive)
704 (Info-goto-node (Info-extract-pointer "next")))
706 (defun Info-prev ()
707 "Go to the previous node of this node."
708 (interactive)
709 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
711 (defun Info-up ()
712 "Go to the superior node of this node."
713 (interactive)
714 (Info-goto-node (Info-extract-pointer "up"))
715 (Info-restore-point Info-history))
717 (defun Info-last ()
718 "Go back to the last node visited."
719 (interactive)
720 (or Info-history
721 (error "This is the first Info node you looked at"))
722 (let (filename nodename opoint)
723 (setq filename (car (car Info-history)))
724 (setq nodename (car (cdr (car Info-history))))
725 (setq opoint (car (cdr (cdr (car Info-history)))))
726 (setq Info-history (cdr Info-history))
727 (Info-find-node filename nodename)
728 (setq Info-history (cdr Info-history))
729 (goto-char opoint)))
731 (defun Info-directory ()
732 "Go to the Info directory node."
733 (interactive)
734 (Info-find-node "dir" "top"))
736 (defun Info-follow-reference (footnotename)
737 "Follow cross reference named NAME to the node it refers to.
738 NAME may be an abbreviation of the reference name."
739 (interactive
740 (let ((completion-ignore-case t)
741 completions default alt-default (start-point (point)) str i bol eol)
742 (save-excursion
743 ;; Store end and beginning of line.
744 (end-of-line)
745 (setq eol (point))
746 (beginning-of-line)
747 (setq bol (point))
749 (goto-char (point-min))
750 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
751 (setq str (buffer-substring
752 (match-beginning 1)
753 (1- (point))))
754 ;; See if this one should be the default.
755 (and (null default)
756 (<= (match-beginning 0) start-point)
757 (<= start-point (point))
758 (setq default t))
759 ;; See if this one should be the alternate default.
760 (and (null alt-default)
761 (and (<= bol (match-beginning 0))
762 (<= (point) eol))
763 (setq alt-default t))
764 (setq i 0)
765 (while (setq i (string-match "[ \n\t]+" str i))
766 (setq str (concat (substring str 0 i) " "
767 (substring str (match-end 0))))
768 (setq i (1+ i)))
769 ;; Record as a completion and perhaps as default.
770 (if (eq default t) (setq default str))
771 (if (eq alt-default t) (setq alt-default str))
772 (setq completions
773 (cons (cons str nil)
774 completions))))
775 ;; If no good default was found, try an alternate.
776 (or default
777 (setq default alt-default))
778 ;; If only one cross-reference found, then make it default.
779 (if (eq (length completions) 1)
780 (setq default (car (car completions))))
781 (if completions
782 (let ((input (completing-read (if default
783 (concat "Follow reference named: ("
784 default ") ")
785 "Follow reference named: ")
786 completions nil t)))
787 (list (if (equal input "")
788 default input)))
789 (error "No cross-references in this node"))))
790 (let (target beg i (str (concat "\\*note " footnotename)))
791 (while (setq i (string-match " " str i))
792 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
793 (setq i (+ i 6)))
794 (save-excursion
795 (goto-char (point-min))
796 (or (re-search-forward str nil t)
797 (error "No cross-reference named %s" footnotename))
798 (goto-char (+ (match-beginning 0) 5))
799 (setq target
800 (Info-extract-menu-node-name "Bad format cross reference" t)))
801 (while (setq i (string-match "[ \t\n]+" target i))
802 (setq target (concat (substring target 0 i) " "
803 (substring target (match-end 0))))
804 (setq i (+ i 1)))
805 (Info-goto-node target)))
807 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
808 (skip-chars-forward " \t\n")
809 (let ((beg (point))
810 str i)
811 (skip-chars-forward "^:")
812 (forward-char 1)
813 (setq str
814 (if (looking-at ":")
815 (buffer-substring beg (1- (point)))
816 (skip-chars-forward " \t\n")
817 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
818 (while (setq i (string-match "\n" str i))
819 (aset str i ?\ ))
820 str))
822 ;; No one calls this and Info-menu-item doesn't exist.
823 ;;(defun Info-menu-item-sequence (list)
824 ;; (while list
825 ;; (Info-menu-item (car list))
826 ;; (setq list (cdr list))))
828 (defun Info-menu (menu-item)
829 "Go to node for menu item named (or abbreviated) NAME.
830 Completion is allowed, and the menu item point is on is the default."
831 (interactive
832 (let ((completions '())
833 ;; If point is within a menu item, use that item as the default
834 (default nil)
835 (p (point))
836 (last nil))
837 (save-excursion
838 (goto-char (point-min))
839 (if (not (search-forward "\n* menu:" nil t))
840 (error "No menu in this node"))
841 (while (re-search-forward
842 "\n\\* \\([^:\t\n]*\\):" nil t)
843 (if (and (null default)
844 (prog1 (if last (< last p) nil)
845 (setq last (match-beginning 0)))
846 (<= p last))
847 (setq default (car (car completions))))
848 (setq completions (cons (cons (buffer-substring
849 (match-beginning 1)
850 (match-end 1))
851 (match-beginning 1))
852 completions)))
853 (if (and (null default) last
854 (< last p)
855 (<= p (progn (end-of-line) (point))))
856 (setq default (car (car completions)))))
857 (let ((item nil))
858 (while (null item)
859 (setq item (let ((completion-ignore-case t))
860 (completing-read (if default
861 (format "Menu item (default %s): "
862 default)
863 "Menu item: ")
864 completions nil t)))
865 ;; we rely on the fact that completing-read accepts an input
866 ;; of "" even when the require-match argument is true and ""
867 ;; is not a valid possibility
868 (if (string= item "")
869 (if default
870 (setq item default)
871 ;; ask again
872 (setq item nil))))
873 (list item))))
874 ;; there is a problem here in that if several menu items have the same
875 ;; name you can only go to the node of the first with this command.
876 (Info-goto-node (Info-extract-menu-item menu-item)))
878 (defun Info-extract-menu-item (menu-item)
879 (setq menu-item (regexp-quote menu-item))
880 (save-excursion
881 (goto-char (point-min))
882 (or (search-forward "\n* menu:" nil t)
883 (error "No menu in this node"))
884 (or (re-search-forward (concat "\n\\* " menu-item ":") nil t)
885 (re-search-forward (concat "\n\\* " menu-item) nil t)
886 (error "No such item in menu"))
887 (beginning-of-line)
888 (forward-char 2)
889 (Info-extract-menu-node-name)))
891 ;; If COUNT is nil, use the last item in the menu.
892 (defun Info-extract-menu-counting (count)
893 (save-excursion
894 (goto-char (point-min))
895 (or (search-forward "\n* menu:" nil t)
896 (error "No menu in this node"))
897 (if count
898 (or (search-forward "\n* " nil t count)
899 (error "Too few items in menu"))
900 (while (search-forward "\n* " nil t)
901 nil))
902 (Info-extract-menu-node-name)))
904 (defun Info-nth-menu-item ()
905 "Go to the node of the Nth menu item.
906 N is the digit argument used to invoke this command."
907 (interactive)
908 (Info-goto-node
909 (Info-extract-menu-counting
910 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
912 (defun Info-top-node ()
913 "Go to the Top node of this file."
914 (interactive)
915 (Info-goto-node "Top"))
917 (defun Info-final-node ()
918 "Go to the final node in this file."
919 (interactive)
920 (Info-goto-node "Top")
921 (let (Info-history)
922 ;; Go to the last node in the menu of Top.
923 (Info-goto-node (Info-extract-menu-counting nil))
924 ;; If the last node in the menu is not last in pointer structure,
925 ;; move forward until we can't go any farther.
926 (while (Info-forward-node t t) nil)
927 ;; Then keep moving down to last subnode, unless we reach an index.
928 (while (and (not (string-match "\\<index\\>" Info-current-node))
929 (save-excursion (search-forward "\n* Menu:" nil t)))
930 (Info-goto-node (Info-extract-menu-counting nil)))))
932 (defun Info-forward-node (&optional not-down no-error)
933 "Go forward one node, considering all nodes as forming one sequence."
934 (interactive)
935 (goto-char (point-min))
936 (forward-line 1)
937 ;; three possibilities, in order of priority:
938 ;; 1. next node is in a menu in this node (but not in an index)
939 ;; 2. next node is next at same level
940 ;; 3. next node is up and next
941 (cond ((and (not not-down)
942 (save-excursion (search-forward "\n* menu:" nil t))
943 (not (string-match "\\<index\\>" Info-current-node)))
944 (Info-goto-node (Info-extract-menu-counting 1))
946 ((save-excursion (search-backward "next:" nil t))
947 (Info-next)
949 ((and (save-excursion (search-backward "up:" nil t))
950 (not (equal (downcase (Info-extract-pointer "up")) "top")))
951 (let ((old-node Info-current-node))
952 (Info-up)
953 (let (Info-history success)
954 (unwind-protect
955 (setq success (Info-forward-node t no-error))
956 (or success (Info-goto-node old-node))))))
957 (no-error nil)
958 (t (error "No pointer forward from this node"))))
960 (defun Info-backward-node ()
961 "Go backward one node, considering all nodes as forming one sequence."
962 (interactive)
963 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
964 (upnode (Info-extract-pointer "up" t)))
965 (cond ((and upnode (string-match "(" upnode))
966 (error "First node in file"))
967 ((and upnode (or (null prevnode)
968 (equal (downcase prevnode) (downcase upnode))))
969 (Info-up))
970 (prevnode
971 ;; If we move back at the same level,
972 ;; go down to find the last subnode*.
973 (Info-prev)
974 (let (Info-history)
975 (while (and (not (string-match "\\<index\\>" Info-current-node))
976 (save-excursion (search-forward "\n* Menu:" nil t)))
977 (Info-goto-node (Info-extract-menu-counting nil)))))
979 (error "No pointer backward from this node")))))
981 (defun Info-exit ()
982 "Exit Info by selecting some other buffer."
983 (interactive)
984 (if Info-standalone
985 (save-buffers-kill-emacs)
986 (switch-to-buffer (prog1 (other-buffer (current-buffer))
987 (bury-buffer (current-buffer))))))
989 (defun Info-next-menu-item ()
990 (interactive)
991 (save-excursion
992 (forward-line -1)
993 (search-forward "\n* menu:" nil t)
994 (or (search-forward "\n* " nil t)
995 (error "No more items in menu"))
996 (Info-goto-node (Info-extract-menu-node-name))))
998 (defun Info-last-menu-item ()
999 (interactive)
1000 (save-excursion
1001 (forward-line 1)
1002 (search-backward "\n* menu:" nil t)
1003 (or (search-backward "\n* " nil t)
1004 (error "No previous items in menu"))
1005 (Info-goto-node (Info-extract-menu-node-name))))
1007 (defmacro Info-no-error (&rest body)
1008 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1010 (defun Info-next-preorder ()
1011 "Go to the next node, popping up a level if there is none."
1012 (interactive)
1013 (cond ((Info-no-error (Info-next-menu-item)) )
1014 ((Info-no-error (Info-up)) (forward-line 1))
1015 (t (error "No more nodes"))))
1017 (defun Info-last-preorder ()
1018 "Go to the last node, popping up a level if there is none."
1019 (interactive)
1020 (cond ((Info-no-error (Info-last-menu-item)) )
1021 ((Info-no-error (Info-up)) (forward-line -1))
1022 (t (error "No previous nodes"))))
1024 (defun Info-scroll-up ()
1025 "Read the next screen. If end of buffer is visible, go to next entry."
1026 (interactive)
1027 (if (pos-visible-in-window-p (point-max))
1028 (Info-next-preorder)
1029 (scroll-up)))
1031 (defun Info-scroll-down ()
1032 "Read the previous screen. If start of buffer is visible, go to last entry."
1033 (interactive)
1034 (if (pos-visible-in-window-p (point-min))
1035 (Info-last-preorder)
1036 (scroll-down)))
1038 (defun Info-next-reference ()
1039 "Move cursor to the next cross-reference or menu item in the node."
1040 (interactive)
1041 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1042 (old-pt (point)))
1043 (or (eobp) (forward-char 1))
1044 (or (re-search-forward pat nil t)
1045 (progn
1046 (goto-char (point-min))
1047 (or (re-search-forward pat nil t)
1048 (progn
1049 (goto-char old-pt)
1050 (error "No cross references in this node")))))
1051 (goto-char (match-beginning 0))
1052 (if (looking-at "\\* Menu:")
1053 (Info-next-reference))))
1055 (defun Info-prev-reference ()
1056 "Move cursor to the previous cross-reference or menu item in the node."
1057 (interactive)
1058 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1059 (old-pt (point)))
1060 (or (re-search-backward pat nil t)
1061 (progn
1062 (goto-char (point-max))
1063 (or (re-search-backward pat nil t)
1064 (progn
1065 (goto-char old-pt)
1066 (error "No cross references in this node")))))
1067 (goto-char (match-beginning 0))
1068 (if (looking-at "\\* Menu:")
1069 (Info-prev-reference))))
1071 (defun Info-index (topic)
1072 "Look up a string in the index for this file.
1073 The index is defined as the first node in the top-level menu whose
1074 name contains the word \"Index\", plus any immediately following
1075 nodes whose names also contain the word \"Index\".
1076 If there are no exact matches to the specified topic, this chooses
1077 the first match which is a case-insensitive substring of a topic.
1078 Use the `,' command to see the other matches.
1079 Give a blank topic name to go to the Index node itself."
1080 (interactive "sIndex topic: ")
1081 (let ((orignode Info-current-node)
1082 (rnode nil)
1083 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"
1084 (regexp-quote topic)))
1085 node)
1086 (Info-goto-node "Top")
1087 (or (search-forward "\n* menu:" nil t)
1088 (error "No index"))
1089 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1090 (error "No index"))
1091 (goto-char (match-beginning 1))
1092 (let ((Info-keeping-history nil))
1093 (Info-goto-node (Info-extract-menu-node-name)))
1094 (or (equal topic "")
1095 (let ((matches nil)
1096 (exact nil)
1097 (Info-keeping-history nil)
1098 found)
1099 (while
1100 (progn
1101 (goto-char (point-min))
1102 (while (re-search-forward pattern nil t)
1103 (setq matches
1104 (cons (list (buffer-substring (match-beginning 1)
1105 (match-end 1))
1106 (buffer-substring (match-beginning 2)
1107 (match-end 2))
1108 Info-current-node
1109 (string-to-int (concat "0"
1110 (buffer-substring
1111 (match-beginning 3)
1112 (match-end 3)))))
1113 matches)))
1114 (and (setq node (Info-extract-pointer "next" t))
1115 (string-match "\\<Index\\>" node)))
1116 (Info-goto-node node))
1117 (or matches
1118 (progn
1119 (Info-last)
1120 (error "No \"%s\" in index" topic)))
1121 ;; Here it is a feature that assoc is case-sensitive.
1122 (while (setq found (assoc topic matches))
1123 (setq exact (cons found exact)
1124 matches (delq found matches)))
1125 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1126 (Info-index-next 0)))))
1128 (defun Info-index-next (num)
1129 "Go to the next matching index item from the last `i' command."
1130 (interactive "p")
1131 (or Info-index-alternatives
1132 (error "No previous `i' command in this file"))
1133 (while (< num 0)
1134 (setq num (+ num (length Info-index-alternatives))))
1135 (while (> num 0)
1136 (setq Info-index-alternatives
1137 (nconc (cdr Info-index-alternatives)
1138 (list (car Info-index-alternatives)))
1139 num (1- num)))
1140 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1141 (if (> (nth 3 (car Info-index-alternatives)) 0)
1142 (forward-line (nth 3 (car Info-index-alternatives)))
1143 (forward-line 3) ; don't search in headers
1144 (let ((name (car (car Info-index-alternatives))))
1145 (if (or (re-search-forward (format
1146 "\\(Function\\|Command\\): %s\\( \\|$\\)"
1147 (regexp-quote name)) nil t)
1148 (search-forward (format "`%s'" name) nil t)
1149 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1150 (search-forward
1151 (format "`%s'" (substring name 0 (match-beginning 1)))
1152 nil t))
1153 (search-forward name nil t))
1154 (beginning-of-line)
1155 (goto-char (point-min)))))
1156 (message "Found \"%s\" in %s. %s"
1157 (car (car Info-index-alternatives))
1158 (nth 2 (car Info-index-alternatives))
1159 (if (cdr Info-index-alternatives)
1160 "(Press `,' for more)"
1161 "(Only match)")))
1163 (defun Info-undefined ()
1164 "Make command be undefined in Info."
1165 (interactive)
1166 (ding))
1168 (defun Info-help ()
1169 "Enter the Info tutorial."
1170 (interactive)
1171 (delete-other-windows)
1172 (Info-find-node "info"
1173 (if (< (window-height) 23)
1174 "Help-Small-Screen"
1175 "Help")))
1177 (defun Info-summary ()
1178 "Display a brief summary of all Info commands."
1179 (interactive)
1180 (save-window-excursion
1181 (switch-to-buffer "*Help*")
1182 (erase-buffer)
1183 (insert (documentation 'Info-mode))
1184 (goto-char (point-min))
1185 (let (ch flag)
1186 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1187 (message (if flag "Type Space to see more"
1188 "Type Space to return to Info"))
1189 (if (not (eq ?\ (setq ch (read-event))))
1190 (progn (setq unread-command-events (list ch)) nil)
1191 flag))
1192 (scroll-up)))
1193 (bury-buffer "*Help*")))
1195 (defun Info-get-token (pos start all &optional errorstring)
1196 "Return the token around POS,
1197 POS must be somewhere inside the token
1198 START is a regular expression which will match the
1199 beginning of the tokens delimited string
1200 ALL is a regular expression with a single
1201 parenthized subpattern which is the token to be
1202 returned. E.g. '{\(.*\)}' would return any string
1203 enclosed in braces around POS.
1204 SIG optional fourth argument, controls action on no match
1205 nil: return nil
1206 t: beep
1207 a string: signal an error, using that string."
1208 (save-excursion
1209 (goto-char pos)
1210 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
1211 (let (found)
1212 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1213 (not (setq found (and (<= (match-beginning 0) pos)
1214 (> (match-end 0) pos))))))
1215 (if (and found (<= (match-beginning 0) pos)
1216 (> (match-end 0) pos))
1217 (buffer-substring (match-beginning 1) (match-end 1))
1218 (cond ((null errorstring)
1219 nil)
1220 ((eq errorstring t)
1221 (beep)
1222 nil)
1224 (error "No %s around position %d" errorstring pos)))))))
1226 (defun Info-mouse-follow-nearest-node (click)
1227 "\\<Info-mode-map>Follow a node reference near point.
1228 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1229 At end of the node's text, moves to the next node, or up if none."
1230 (interactive "e")
1231 (let* ((start (event-start click))
1232 (window (car start))
1233 (pos (car (cdr start))))
1234 (select-window window)
1235 (goto-char pos))
1236 (and (not (Info-try-follow-nearest-node))
1237 (save-excursion (forward-line 1) (eobp))
1238 (Info-next-preorder)))
1240 (defun Info-follow-nearest-node ()
1241 "\\<Info-mode-map>Follow a node reference near point.
1242 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1243 If no reference to follow, moves to the next node, or up if none."
1244 (interactive)
1245 (or (Info-try-follow-nearest-node)
1246 (Info-next-preorder)))
1248 ;; Common subroutine.
1249 (defun Info-try-follow-nearest-node ()
1250 "Follow a node reference near point. Return non-nil if successful."
1251 (let (node)
1252 (cond
1253 ((setq node (Info-get-token (point) "\\*note[ \n]"
1254 "\\*note[ \n]\\([^:]*\\):"))
1255 (Info-follow-reference node))
1256 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1257 (Info-goto-node node))
1258 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1259 (Info-menu node))
1260 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1261 (Info-goto-node node))
1262 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1263 (Info-goto-node node))
1264 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1265 (Info-goto-node "Top"))
1266 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1267 (Info-goto-node node)))
1268 node))
1270 (defvar Info-mode-map nil
1271 "Keymap containing Info commands.")
1272 (if Info-mode-map
1274 (setq Info-mode-map (make-keymap))
1275 (suppress-keymap Info-mode-map)
1276 (define-key Info-mode-map "." 'beginning-of-buffer)
1277 (define-key Info-mode-map " " 'Info-scroll-up)
1278 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1279 (define-key Info-mode-map "\t" 'Info-next-reference)
1280 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1281 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1282 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1283 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1284 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1285 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1286 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1287 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1288 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1289 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1290 (define-key Info-mode-map "0" 'undefined)
1291 (define-key Info-mode-map "?" 'Info-summary)
1292 (define-key Info-mode-map "]" 'Info-forward-node)
1293 (define-key Info-mode-map "[" 'Info-backward-node)
1294 (define-key Info-mode-map "<" 'Info-top-node)
1295 (define-key Info-mode-map ">" 'Info-final-node)
1296 (define-key Info-mode-map "b" 'beginning-of-buffer)
1297 (define-key Info-mode-map "d" 'Info-directory)
1298 (define-key Info-mode-map "e" 'Info-edit)
1299 (define-key Info-mode-map "f" 'Info-follow-reference)
1300 (define-key Info-mode-map "g" 'Info-goto-node)
1301 (define-key Info-mode-map "h" 'Info-help)
1302 (define-key Info-mode-map "i" 'Info-index)
1303 (define-key Info-mode-map "l" 'Info-last)
1304 (define-key Info-mode-map "m" 'Info-menu)
1305 (define-key Info-mode-map "n" 'Info-next)
1306 (define-key Info-mode-map "p" 'Info-prev)
1307 (define-key Info-mode-map "q" 'Info-exit)
1308 (define-key Info-mode-map "s" 'Info-search)
1309 (define-key Info-mode-map "t" 'Info-top-node)
1310 (define-key Info-mode-map "u" 'Info-up)
1311 (define-key Info-mode-map "," 'Info-index-next)
1312 (define-key Info-mode-map "\177" 'Info-scroll-down)
1313 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1316 ;; Info mode is suitable only for specially formatted data.
1317 (put 'info-mode 'mode-class 'special)
1319 (defun Info-mode ()
1320 "\\<Info-mode-map>
1321 Info mode provides commands for browsing through the Info documentation tree.
1322 Documentation in Info is divided into \"nodes\", each of which discusses
1323 one topic and contains references to other nodes which discuss related
1324 topics. Info has commands to follow the references and show you other nodes.
1326 \\[Info-help] Invoke the Info tutorial.
1328 Selecting other nodes:
1329 \\[Info-next] Move to the \"next\" node of this node.
1330 \\[Info-prev] Move to the \"previous\" node of this node.
1331 \\[Info-up] Move \"up\" from this node.
1332 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1333 Picking a menu item causes another node to be selected.
1334 \\[Info-directory] Go to the Info directory node.
1335 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1336 \\[Info-last] Move to the last node you were at.
1337 \\[Info-index] Look up a topic in this file's Index and move to that node.
1338 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1340 Moving within a node:
1341 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1342 already visible, try to go to the next menu entry, or up if there is none.
1343 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1344 already visible, try to go to the previous menu entry, or up if there is none.
1345 \\[beginning-of-buffer] Go to beginning of node.
1347 Advanced commands:
1348 \\[Info-exit] Quit Info: reselect previously selected buffer.
1349 \\[Info-edit] Edit contents of selected node.
1350 1 Pick first item in node's menu.
1351 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1352 \\[Info-goto-node] Move to node specified by name.
1353 You may include a filename as well, as (FILENAME)NODENAME.
1354 \\[universal-argument] \\[info] Move to new Info file with completion.
1355 \\[Info-search] Search through this Info file for specified regexp,
1356 and select the node in which the next occurrence is found.
1357 \\[Info-next-preorder] Next-preorder; that is, try to go to the next menu item,
1358 and if that fails try to move up, and if that fails, tell user
1359 he/she is done reading.
1360 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1361 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1362 (kill-all-local-variables)
1363 (setq major-mode 'Info-mode)
1364 (setq mode-name "Info")
1365 (use-local-map Info-mode-map)
1366 (set-syntax-table text-mode-syntax-table)
1367 (setq local-abbrev-table text-mode-abbrev-table)
1368 (setq case-fold-search t)
1369 (setq buffer-read-only t)
1370 (make-local-variable 'Info-current-file)
1371 (make-local-variable 'Info-current-subfile)
1372 (make-local-variable 'Info-current-node)
1373 (make-local-variable 'Info-tag-table-marker)
1374 (make-local-variable 'Info-history)
1375 (make-local-variable 'Info-index-alternatives)
1376 (if (fboundp 'make-face)
1377 (progn
1378 (make-face 'info-node)
1379 (make-face 'info-menu-5)
1380 (make-face 'info-xref)
1381 (or (face-differs-from-default-p 'info-node)
1382 (if (face-differs-from-default-p 'bold-italic)
1383 (copy-face 'bold-italic 'info-node)
1384 (copy-face 'bold 'info-node)))
1385 (or (face-differs-from-default-p 'info-menu-5)
1386 (set-face-underline-p 'info-menu-5 t))
1387 (or (face-differs-from-default-p 'info-xref)
1388 (copy-face 'bold 'info-xref)))
1389 (setq Info-fontify nil))
1390 (Info-set-mode-line)
1391 (run-hooks 'Info-mode-hook))
1393 (defvar Info-edit-map nil
1394 "Local keymap used within `e' command of Info.")
1395 (if Info-edit-map
1397 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1398 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1400 ;; Info-edit mode is suitable only for specially formatted data.
1401 (put 'info-edit-mode 'mode-class 'special)
1403 (defun Info-edit-mode ()
1404 "Major mode for editing the contents of an Info node.
1405 Like text mode with the addition of `Info-cease-edit'
1406 which returns to Info mode for browsing.
1407 \\{Info-edit-map}"
1410 (defun Info-edit ()
1411 "Edit the contents of this Info node.
1412 Allowed only if variable `Info-enable-edit' is non-nil."
1413 (interactive)
1414 (or Info-enable-edit
1415 (error "Editing info nodes is not enabled"))
1416 (use-local-map Info-edit-map)
1417 (setq major-mode 'Info-edit-mode)
1418 (setq mode-name "Info Edit")
1419 (kill-local-variable 'mode-line-buffer-identification)
1420 (setq buffer-read-only nil)
1421 ;; Make mode line update.
1422 (set-buffer-modified-p (buffer-modified-p))
1423 (message (substitute-command-keys
1424 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1426 (defun Info-cease-edit ()
1427 "Finish editing Info node; switch back to Info proper."
1428 (interactive)
1429 ;; Do this first, so nothing has changed if user C-g's at query.
1430 (and (buffer-modified-p)
1431 (y-or-n-p "Save the file? ")
1432 (save-buffer))
1433 (use-local-map Info-mode-map)
1434 (setq major-mode 'Info-mode)
1435 (setq mode-name "Info")
1436 (Info-set-mode-line)
1437 (setq buffer-read-only t)
1438 ;; Make mode line update.
1439 (set-buffer-modified-p (buffer-modified-p))
1440 (and (marker-position Info-tag-table-marker)
1441 (buffer-modified-p)
1442 (message "Tags may have changed. Use Info-tagify if necessary")))
1444 (defun Info-find-emacs-command-nodes (command)
1445 "Return a list of locations documenting COMMAND in the Emacs Info manual.
1446 The locations are of the format used in Info-history, i.e.
1447 \(FILENAME NODENAME BUFFERPOS\)."
1448 (require 'info)
1449 (let ((where '())
1450 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
1451 ":\\s *\\(.*\\)\\.$")))
1452 (save-excursion
1453 (Info-find-node "emacs" "Command Index")
1454 ;; Take the index node off the Info history.
1455 (setq Info-history (cdr Info-history))
1456 (goto-char (point-max))
1457 (while (re-search-backward cmd-desc nil t)
1458 (setq where (cons (list Info-current-file
1459 (buffer-substring
1460 (match-beginning 1)
1461 (match-end 1))
1463 where)))
1464 where)))
1466 ;;;###autoload
1467 (defun Info-goto-emacs-command-node (command)
1468 "Go to the Info node in the Emacs manual for command COMMAND.
1469 The command is found by looking up in Emacs manual's Command Index."
1470 (interactive "CFind documentation for command: ")
1471 (or (commandp command)
1472 (signal 'wrong-type-argument (list 'commandp command)))
1473 (let ((where (Info-find-emacs-command-nodes command)))
1474 (if where
1475 (let ((num-matches (length where)))
1476 ;; Get Info running, and pop to it in another window.
1477 (save-window-excursion
1478 (info))
1479 (pop-to-buffer "*info*")
1480 (Info-find-node (car (car where))
1481 (car (cdr (car where))))
1482 (if (> num-matches 1)
1483 (progn
1484 ;; Info-find-node already pushed (car where) onto
1485 ;; Info-history. Put the other nodes that were found on
1486 ;; the history.
1487 (setq Info-history (nconc (cdr where) Info-history))
1488 (message (substitute-command-keys
1489 "Found %d other entr%s. Use \\[Info-last] to see %s.")
1490 (1- num-matches)
1491 (if (> num-matches 2) "ies" "y")
1492 (if (> num-matches 2) "them" "it")))))
1493 (error "Couldn't find documentation for %s." command))))
1495 ;;;###autoload
1496 (defun Info-goto-emacs-key-command-node (key)
1497 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1498 Interactively, if the binding is execute-extended-command, a command is read.
1499 The command is found by looking up in Emacs manual's Command Index."
1500 (interactive "kFind documentation for key:")
1501 (let ((command (key-binding key)))
1502 (cond ((null command)
1503 (message "%s is undefined" (key-description key)))
1504 ((and (interactive-p)
1505 (eq command 'execute-extended-command))
1506 (Info-goto-emacs-command-node
1507 (read-command "Find documentation for command: ")))
1509 (Info-goto-emacs-command-node command)))))
1511 (defun Info-fontify-node ()
1512 (save-excursion
1513 (let ((buffer-read-only nil))
1514 (goto-char (point-min))
1515 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1516 (progn
1517 (goto-char (match-end 0))
1518 (while
1519 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1520 (goto-char (match-end 0))
1521 (put-text-property (match-beginning 1) (match-end 1)
1522 'face 'info-xref)
1523 (put-text-property (match-beginning 1) (match-end 1)
1524 'mouse-face 'highlight))))
1525 (goto-char (point-min))
1526 (while (re-search-forward "\\*Note[ \n\t]*\\([^:]*\\):" nil t)
1527 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
1529 (put-text-property (match-beginning 1) (match-end 1)
1530 'face 'info-xref)
1531 (put-text-property (match-beginning 1) (match-end 1)
1532 'mouse-face 'highlight)))
1533 (goto-char (point-min))
1534 (if (and (search-forward "\n* Menu:" nil t)
1535 (not (string-match "\\<Index\\>" Info-current-node))
1536 ;; Don't take time to annotate huge menus
1537 (< (- (point-max) (point)) 30000))
1538 (let ((n 0))
1539 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
1540 (setq n (1+ n))
1541 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
1542 (put-text-property (match-beginning 0)
1543 (1+ (match-beginning 0))
1544 'face 'info-menu-5))
1545 (put-text-property (match-beginning 1) (match-end 1)
1546 'face 'info-node)
1547 (put-text-property (match-beginning 1) (match-end 1)
1548 'mouse-face 'highlight))))
1549 (set-buffer-modified-p nil))))
1551 (provide 'info)
1553 ;;; info.el ends here