(Fformat): Reword confusing error message.
[emacs.git] / lisp / info.el
blob0fe52e844e057a9321380cf813c07e2b972c2151
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
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 ;; Distinguish the dir file that comes with Emacs from all the
377 ;; others. Yes, that is really what this is supposed to do.
378 ;; If it doesn't work, fix it.
379 (setq buffer (car buffers)
380 others (cdr buffers))
382 ;; Insert the entire original dir file as a start; use its
383 ;; default directory as the default directory for the whole
384 ;; concatenation.
385 (insert-buffer buffer)
386 (setq Info-dir-contents-directory (save-excursion
387 (set-buffer buffer)
388 default-directory))
390 ;; Look at each of the other buffers one by one.
391 (while others
392 (let ((other (car others)))
393 ;; In each, find all the menus.
394 (save-excursion
395 (set-buffer other)
396 (goto-char (point-min))
397 ;; Find each menu, and add an elt to NODES for it.
398 (while (re-search-forward "^\\* Menu:" nil t)
399 (let (beg nodename end)
400 (forward-line 1)
401 (setq beg (point))
402 (search-backward "\n\^_")
403 (search-forward "Node: ")
404 (setq nodename (Info-following-node-name))
405 (search-forward "\n\^_" nil 'move)
406 (beginning-of-line)
407 (setq end (point))
408 (setq nodes (cons (list nodename other beg end) nodes))))))
409 (setq others (cdr others)))
410 ;; Add to the main menu a menu item for each other node.
411 (re-search-forward "^\\* Menu:")
412 (forward-line 1)
413 (let ((menu-items '("top"))
414 (nodes nodes)
415 (case-fold-search t)
416 (end (save-excursion (search-forward "\^_" nil t) (point))))
417 (while nodes
418 (let ((nodename (car (car nodes))))
419 (save-excursion
420 (or (member (downcase nodename) menu-items)
421 (re-search-forward (concat "^\\* "
422 (regexp-quote nodename)
423 "::")
424 end t)
425 (progn
426 (insert "* " nodename "::" "\n")
427 (setq menu-items (cons nodename menu-items))))))
428 (setq nodes (cdr nodes))))
429 ;; Now take each node of each of the other buffers
430 ;; and merge it into the main buffer.
431 (while nodes
432 (let ((nodename (car (car nodes))))
433 (goto-char (point-min))
434 ;; Find the like-named node in the main buffer.
435 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
436 (regexp-quote nodename)
437 "[,\n\t]")
438 nil t)
439 (progn
440 (search-forward "\n\^_" nil 'move)
441 (beginning-of-line))
442 ;; If none exists, add one.
443 (goto-char (point-max))
444 (insert "\^_\nFile: dir\tnode: " nodename "\n\n* Menu:\n\n"))
445 ;; Merge the text from the other buffer's menu
446 ;; into the menu in the like-named node in the main buffer.
447 (apply 'insert-buffer-substring (cdr (car nodes)))
448 (insert "\n"))
449 (setq nodes (cdr nodes)))
450 ;; Kill all the buffers we just made.
451 (while buffers
452 (kill-buffer (car buffers))
453 (setq buffers (cdr buffers))))
454 (setq Info-dir-contents (buffer-string)))
455 (setq default-directory Info-dir-contents-directory))
457 (defun Info-read-subfile (nodepos)
458 (set-buffer (marker-buffer Info-tag-table-marker))
459 (goto-char (point-min))
460 (search-forward "\n\^_")
461 (let (lastfilepos
462 lastfilename)
463 (forward-line 2)
464 (catch 'foo
465 (while (not (looking-at "\^_"))
466 (if (not (eolp))
467 (let ((beg (point))
468 thisfilepos thisfilename)
469 (search-forward ": ")
470 (setq thisfilename (buffer-substring beg (- (point) 2)))
471 (setq thisfilepos (read (current-buffer)))
472 ;; read in version 19 stops at the end of number.
473 ;; Advance to the next line.
474 (forward-line 1)
475 (if (> thisfilepos nodepos)
476 (throw 'foo t))
477 (setq lastfilename thisfilename)
478 (setq lastfilepos thisfilepos))
479 (forward-line 1))))
480 (set-buffer (get-buffer "*info*"))
481 (or (equal Info-current-subfile lastfilename)
482 (let ((buffer-read-only nil))
483 (setq buffer-file-name nil)
484 (widen)
485 (erase-buffer)
486 (info-insert-file-contents lastfilename)
487 (set-buffer-modified-p nil)
488 (setq Info-current-subfile lastfilename)))
489 (goto-char (point-min))
490 (search-forward "\n\^_")
491 (+ (- nodepos lastfilepos) (point))))
493 ;; Select the info node that point is in.
494 (defun Info-select-node ()
495 (save-excursion
496 ;; Find beginning of node.
497 (search-backward "\n\^_")
498 (forward-line 2)
499 ;; Get nodename spelled as it is in the node.
500 (re-search-forward "Node:[ \t]*")
501 (setq Info-current-node
502 (buffer-substring (point)
503 (progn
504 (skip-chars-forward "^,\t\n")
505 (point))))
506 (Info-set-mode-line)
507 ;; Find the end of it, and narrow.
508 (beginning-of-line)
509 (let (active-expression)
510 (narrow-to-region (point)
511 (if (re-search-forward "\n[\^_\f]" nil t)
512 (prog1
513 (1- (point))
514 (if (looking-at "[\n\^_\f]*execute: ")
515 (progn
516 (goto-char (match-end 0))
517 (setq active-expression
518 (read (current-buffer))))))
519 (point-max)))
520 (if Info-enable-active-nodes (eval active-expression))
521 (if Info-fontify (Info-fontify-node))
522 (run-hooks 'Info-selection-hook))))
524 (defun Info-set-mode-line ()
525 (setq mode-line-buffer-identification
526 (concat
527 "Info: ("
528 (if Info-current-file
529 (file-name-nondirectory Info-current-file)
532 (or Info-current-node ""))))
534 ;; Go to an info node specified with a filename-and-nodename string
535 ;; of the sort that is found in pointers in nodes.
537 (defun Info-goto-node (nodename)
538 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
539 (interactive (list (Info-read-node-name "Goto node: ")))
540 (let (filename)
541 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
542 nodename)
543 (setq filename (if (= (match-beginning 1) (match-end 1))
545 (substring nodename (match-beginning 2) (match-end 2)))
546 nodename (substring nodename (match-beginning 3) (match-end 3)))
547 (let ((trim (string-match "\\s *\\'" filename)))
548 (if trim (setq filename (substring filename 0 trim))))
549 (let ((trim (string-match "\\s *\\'" nodename)))
550 (if trim (setq nodename (substring nodename 0 trim))))
551 (Info-find-node (if (equal filename "") nil filename)
552 (if (equal nodename "") "Top" nodename))))
554 (defun Info-read-node-name (prompt &optional default)
555 (let* ((completion-ignore-case t)
556 (nodename (completing-read prompt (Info-build-node-completions))))
557 (if (equal nodename "")
558 (or default
559 (Info-read-node-name prompt))
560 nodename)))
562 (defun Info-build-node-completions ()
563 (or Info-current-file-completions
564 (let ((compl nil))
565 (save-excursion
566 (save-restriction
567 (if (marker-buffer Info-tag-table-marker)
568 (progn
569 (set-buffer (marker-buffer Info-tag-table-marker))
570 (widen)
571 (goto-char Info-tag-table-marker)
572 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
573 (setq compl
574 (cons (list (buffer-substring (match-beginning 1)
575 (match-end 1)))
576 compl))))
577 (widen)
578 (goto-char (point-min))
579 (while (search-forward "\n\^_" nil t)
580 (forward-line 1)
581 (let ((beg (point)))
582 (forward-line 1)
583 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
584 beg t)
585 (setq compl
586 (cons (list (buffer-substring (match-beginning 1)
587 (match-end 1)))
588 compl))))))))
589 (setq Info-current-file-completions compl))))
591 (defun Info-restore-point (hl)
592 "If this node has been visited, restore the point value when we left."
593 (while hl
594 (if (and (equal (nth 0 (car hl)) Info-current-file)
595 (equal (nth 1 (car hl)) Info-current-node))
596 (progn
597 (goto-char (nth 2 (car hl)))
598 (setq hl nil)) ;terminate the while at next iter
599 (setq hl (cdr hl)))))
601 (defvar Info-last-search nil
602 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
604 (defun Info-search (regexp)
605 "Search for REGEXP, starting from point, and select node it's found in."
606 (interactive "sSearch (regexp): ")
607 (if (equal regexp "")
608 (setq regexp Info-last-search)
609 (setq Info-last-search regexp))
610 (let ((found ()) current
611 (onode Info-current-node)
612 (ofile Info-current-file)
613 (opoint (point))
614 (osubfile Info-current-subfile))
615 (save-excursion
616 (save-restriction
617 (widen)
618 (if (null Info-current-subfile)
619 (progn (re-search-forward regexp) (setq found (point)))
620 (condition-case err
621 (progn (re-search-forward regexp) (setq found (point)))
622 (search-failed nil)))))
623 (if (not found) ;can only happen in subfile case -- else would have erred
624 (unwind-protect
625 (let ((list ()))
626 (set-buffer (marker-buffer Info-tag-table-marker))
627 (goto-char (point-min))
628 (search-forward "\n\^_\nIndirect:")
629 (save-restriction
630 (narrow-to-region (point)
631 (progn (search-forward "\n\^_")
632 (1- (point))))
633 (goto-char (point-min))
634 (search-forward (concat "\n" osubfile ": "))
635 (beginning-of-line)
636 (while (not (eobp))
637 (re-search-forward "\\(^.*\\): [0-9]+$")
638 (goto-char (+ (match-end 1) 2))
639 (setq list (cons (cons (read (current-buffer))
640 (buffer-substring (match-beginning 1)
641 (match-end 1)))
642 list))
643 (goto-char (1+ (match-end 0))))
644 (setq list (nreverse list)
645 current (car (car list))
646 list (cdr list)))
647 (while list
648 (message "Searching subfile %s..." (cdr (car list)))
649 (Info-read-subfile (car (car list)))
650 (setq list (cdr list))
651 (goto-char (point-min))
652 (if (re-search-forward regexp nil t)
653 (setq found (point) list ())))
654 (if found
655 (message "")
656 (signal 'search-failed (list regexp))))
657 (if (not found)
658 (progn (Info-read-subfile opoint)
659 (goto-char opoint)
660 (Info-select-node)))))
661 (widen)
662 (goto-char found)
663 (Info-select-node)
664 (or (and (equal onode Info-current-node)
665 (equal ofile Info-current-file))
666 (setq Info-history (cons (list ofile onode opoint)
667 Info-history)))))
669 ;; Extract the value of the node-pointer named NAME.
670 ;; If there is none, use ERRORNAME in the error message;
671 ;; if ERRORNAME is nil, just return nil.
672 (defun Info-extract-pointer (name &optional errorname)
673 (save-excursion
674 (goto-char (point-min))
675 (forward-line 1)
676 (if (re-search-backward (concat name ":") nil t)
677 (progn
678 (goto-char (match-end 0))
679 (Info-following-node-name))
680 (if (eq errorname t)
682 (error (concat "Node has no " (capitalize (or errorname name))))))))
684 ;; Return the node name in the buffer following point.
685 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
686 ;; saying which chas may appear in the node name.
687 (defun Info-following-node-name (&optional allowedchars)
688 (skip-chars-forward " \t")
689 (buffer-substring
690 (point)
691 (progn
692 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
693 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
694 (if (looking-at "(")
695 (skip-chars-forward "^)")))
696 (skip-chars-backward " ")
697 (point))))
699 (defun Info-next ()
700 "Go to the next node of this node."
701 (interactive)
702 (Info-goto-node (Info-extract-pointer "next")))
704 (defun Info-prev ()
705 "Go to the previous node of this node."
706 (interactive)
707 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
709 (defun Info-up ()
710 "Go to the superior node of this node."
711 (interactive)
712 (Info-goto-node (Info-extract-pointer "up"))
713 (Info-restore-point Info-history))
715 (defun Info-last ()
716 "Go back to the last node visited."
717 (interactive)
718 (or Info-history
719 (error "This is the first Info node you looked at"))
720 (let (filename nodename opoint)
721 (setq filename (car (car Info-history)))
722 (setq nodename (car (cdr (car Info-history))))
723 (setq opoint (car (cdr (cdr (car Info-history)))))
724 (setq Info-history (cdr Info-history))
725 (Info-find-node filename nodename)
726 (setq Info-history (cdr Info-history))
727 (goto-char opoint)))
729 (defun Info-directory ()
730 "Go to the Info directory node."
731 (interactive)
732 (Info-find-node "dir" "top"))
734 (defun Info-follow-reference (footnotename)
735 "Follow cross reference named NAME to the node it refers to.
736 NAME may be an abbreviation of the reference name."
737 (interactive
738 (let ((completion-ignore-case t)
739 completions default alt-default (start-point (point)) str i bol eol)
740 (save-excursion
741 ;; Store end and beginning of line.
742 (end-of-line)
743 (setq eol (point))
744 (beginning-of-line)
745 (setq bol (point))
747 (goto-char (point-min))
748 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
749 (setq str (buffer-substring
750 (match-beginning 1)
751 (1- (point))))
752 ;; See if this one should be the default.
753 (and (null default)
754 (<= (match-beginning 0) start-point)
755 (<= start-point (point))
756 (setq default t))
757 ;; See if this one should be the alternate default.
758 (and (null alt-default)
759 (and (<= bol (match-beginning 0))
760 (<= (point) eol))
761 (setq alt-default t))
762 (setq i 0)
763 (while (setq i (string-match "[ \n\t]+" str i))
764 (setq str (concat (substring str 0 i) " "
765 (substring str (match-end 0))))
766 (setq i (1+ i)))
767 ;; Record as a completion and perhaps as default.
768 (if (eq default t) (setq default str))
769 (if (eq alt-default t) (setq alt-default str))
770 (setq completions
771 (cons (cons str nil)
772 completions))))
773 ;; If no good default was found, try an alternate.
774 (or default
775 (setq default alt-default))
776 ;; If only one cross-reference found, then make it default.
777 (if (eq (length completions) 1)
778 (setq default (car (car completions))))
779 (if completions
780 (let ((input (completing-read (if default
781 (concat "Follow reference named: ("
782 default ") ")
783 "Follow reference named: ")
784 completions nil t)))
785 (list (if (equal input "")
786 default input)))
787 (error "No cross-references in this node"))))
788 (let (target beg i (str (concat "\\*note " footnotename)))
789 (while (setq i (string-match " " str i))
790 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
791 (setq i (+ i 6)))
792 (save-excursion
793 (goto-char (point-min))
794 (or (re-search-forward str nil t)
795 (error "No cross-reference named %s" footnotename))
796 (goto-char (+ (match-beginning 0) 5))
797 (setq target
798 (Info-extract-menu-node-name "Bad format cross reference" t)))
799 (while (setq i (string-match "[ \t\n]+" target i))
800 (setq target (concat (substring target 0 i) " "
801 (substring target (match-end 0))))
802 (setq i (+ i 1)))
803 (Info-goto-node target)))
805 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
806 (skip-chars-forward " \t\n")
807 (let ((beg (point))
808 str i)
809 (skip-chars-forward "^:")
810 (forward-char 1)
811 (setq str
812 (if (looking-at ":")
813 (buffer-substring beg (1- (point)))
814 (skip-chars-forward " \t\n")
815 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
816 (while (setq i (string-match "\n" str i))
817 (aset str i ?\ ))
818 str))
820 ;; No one calls this and Info-menu-item doesn't exist.
821 ;;(defun Info-menu-item-sequence (list)
822 ;; (while list
823 ;; (Info-menu-item (car list))
824 ;; (setq list (cdr list))))
826 (defun Info-menu (menu-item)
827 "Go to node for menu item named (or abbreviated) NAME.
828 Completion is allowed, and the menu item point is on is the default."
829 (interactive
830 (let ((completions '())
831 ;; If point is within a menu item, use that item as the default
832 (default nil)
833 (p (point))
834 (last nil))
835 (save-excursion
836 (goto-char (point-min))
837 (if (not (search-forward "\n* menu:" nil t))
838 (error "No menu in this node"))
839 (while (re-search-forward
840 "\n\\* \\([^:\t\n]*\\):" nil t)
841 (if (and (null default)
842 (prog1 (if last (< last p) nil)
843 (setq last (match-beginning 0)))
844 (<= p last))
845 (setq default (car (car completions))))
846 (setq completions (cons (cons (buffer-substring
847 (match-beginning 1)
848 (match-end 1))
849 (match-beginning 1))
850 completions)))
851 (if (and (null default) last
852 (< last p)
853 (<= p (progn (end-of-line) (point))))
854 (setq default (car (car completions)))))
855 (let ((item nil))
856 (while (null item)
857 (setq item (let ((completion-ignore-case t))
858 (completing-read (if default
859 (format "Menu item (default %s): "
860 default)
861 "Menu item: ")
862 completions nil t)))
863 ;; we rely on the fact that completing-read accepts an input
864 ;; of "" even when the require-match argument is true and ""
865 ;; is not a valid possibility
866 (if (string= item "")
867 (if default
868 (setq item default)
869 ;; ask again
870 (setq item nil))))
871 (list item))))
872 ;; there is a problem here in that if several menu items have the same
873 ;; name you can only go to the node of the first with this command.
874 (Info-goto-node (Info-extract-menu-item menu-item)))
876 (defun Info-extract-menu-item (menu-item)
877 (setq menu-item (regexp-quote menu-item))
878 (save-excursion
879 (goto-char (point-min))
880 (or (search-forward "\n* menu:" nil t)
881 (error "No menu in this node"))
882 (or (re-search-forward (concat "\n\\* " menu-item ":") nil t)
883 (re-search-forward (concat "\n\\* " menu-item) nil t)
884 (error "No such item in menu"))
885 (beginning-of-line)
886 (forward-char 2)
887 (Info-extract-menu-node-name)))
889 ;; If COUNT is nil, use the last item in the menu.
890 (defun Info-extract-menu-counting (count)
891 (save-excursion
892 (goto-char (point-min))
893 (or (search-forward "\n* menu:" nil t)
894 (error "No menu in this node"))
895 (if count
896 (or (search-forward "\n* " nil t count)
897 (error "Too few items in menu"))
898 (while (search-forward "\n* " nil t)
899 nil))
900 (Info-extract-menu-node-name)))
902 (defun Info-nth-menu-item ()
903 "Go to the node of the Nth menu item.
904 N is the digit argument used to invoke this command."
905 (interactive)
906 (Info-goto-node
907 (Info-extract-menu-counting
908 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
910 (defun Info-top-node ()
911 "Go to the Top node of this file."
912 (interactive)
913 (Info-goto-node "Top"))
915 (defun Info-final-node ()
916 "Go to the final node in this file."
917 (interactive)
918 (Info-goto-node "Top")
919 (let (Info-history)
920 ;; Go to the last node in the menu of Top.
921 (Info-goto-node (Info-extract-menu-counting nil))
922 ;; If the last node in the menu is not last in pointer structure,
923 ;; move forward until we can't go any farther.
924 (while (Info-forward-node t t) nil)
925 ;; Then keep moving down to last subnode, unless we reach an index.
926 (while (and (not (string-match "\\<index\\>" Info-current-node))
927 (save-excursion (search-forward "\n* Menu:" nil t)))
928 (Info-goto-node (Info-extract-menu-counting nil)))))
930 (defun Info-forward-node (&optional not-down no-error)
931 "Go forward one node, considering all nodes as forming one sequence."
932 (interactive)
933 (goto-char (point-min))
934 (forward-line 1)
935 ;; three possibilities, in order of priority:
936 ;; 1. next node is in a menu in this node (but not in an index)
937 ;; 2. next node is next at same level
938 ;; 3. next node is up and next
939 (cond ((and (not not-down)
940 (save-excursion (search-forward "\n* menu:" nil t))
941 (not (string-match "\\<index\\>" Info-current-node)))
942 (Info-goto-node (Info-extract-menu-counting 1))
944 ((save-excursion (search-backward "next:" nil t))
945 (Info-next)
947 ((and (save-excursion (search-backward "up:" nil t))
948 (not (equal (downcase (Info-extract-pointer "up")) "top")))
949 (let ((old-node Info-current-node))
950 (Info-up)
951 (let (Info-history success)
952 (unwind-protect
953 (setq success (Info-forward-node t no-error))
954 (or success (Info-goto-node old-node))))))
955 (no-error nil)
956 (t (error "No pointer forward from this node"))))
958 (defun Info-backward-node ()
959 "Go backward one node, considering all nodes as forming one sequence."
960 (interactive)
961 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
962 (upnode (Info-extract-pointer "up" t)))
963 (cond ((and upnode (string-match "(" upnode))
964 (error "First node in file"))
965 ((and upnode (or (null prevnode)
966 (equal (downcase prevnode) (downcase upnode))))
967 (Info-up))
968 (prevnode
969 ;; If we move back at the same level,
970 ;; go down to find the last subnode*.
971 (Info-prev)
972 (let (Info-history)
973 (while (and (not (string-match "\\<index\\>" Info-current-node))
974 (save-excursion (search-forward "\n* Menu:" nil t)))
975 (Info-goto-node (Info-extract-menu-counting nil)))))
977 (error "No pointer backward from this node")))))
979 (defun Info-exit ()
980 "Exit Info by selecting some other buffer."
981 (interactive)
982 (if Info-standalone
983 (save-buffers-kill-emacs)
984 (switch-to-buffer (prog1 (other-buffer (current-buffer))
985 (bury-buffer (current-buffer))))))
987 (defun Info-next-menu-item ()
988 (interactive)
989 (save-excursion
990 (forward-line -1)
991 (search-forward "\n* menu:" nil t)
992 (or (search-forward "\n* " nil t)
993 (error "No more items in menu"))
994 (Info-goto-node (Info-extract-menu-node-name))))
996 (defun Info-last-menu-item ()
997 (interactive)
998 (save-excursion
999 (forward-line 1)
1000 (search-backward "\n* menu:" nil t)
1001 (or (search-backward "\n* " nil t)
1002 (error "No previous items in menu"))
1003 (Info-goto-node (Info-extract-menu-node-name))))
1005 (defmacro Info-no-error (&rest body)
1006 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1008 (defun Info-next-preorder ()
1009 "Go to the next node, popping up a level if there is none."
1010 (interactive)
1011 (cond ((looking-at "\\*note[ \n]*\\([^:]*\\):")
1012 (Info-follow-reference
1013 (buffer-substring (match-beginning 1) (match-end 1))))
1014 ((Info-no-error (Info-next-menu-item)) )
1015 ((Info-no-error (Info-up)) (forward-line 1))
1016 (t (error "No more nodes"))))
1018 (defun Info-last-preorder ()
1019 "Go to the last node, popping up a level if there is none."
1020 (interactive)
1021 (cond ((Info-no-error (Info-last-menu-item)) )
1022 ((Info-no-error (Info-up)) (forward-line -1))
1023 (t (error "No previous nodes"))))
1025 (defun Info-scroll-up ()
1026 "Read the next screen. If end of buffer is visible, go to next entry."
1027 (interactive)
1028 (if (pos-visible-in-window-p (point-max))
1029 (Info-next-preorder)
1030 (scroll-up))
1033 (defun Info-scroll-down ()
1034 "Read the previous screen. If start of buffer is visible, go to last entry."
1035 (interactive)
1036 (if (pos-visible-in-window-p (point-min))
1037 (Info-last-preorder)
1038 (scroll-down))
1041 (defun Info-next-reference ()
1042 "Move cursor to the next cross-reference or menu item in the node."
1043 (interactive)
1044 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1045 (old-pt (point)))
1046 (or (eobp) (forward-char 1))
1047 (or (re-search-forward pat nil t)
1048 (progn
1049 (goto-char (point-min))
1050 (or (re-search-forward pat nil t)
1051 (progn
1052 (goto-char old-pt)
1053 (error "No cross references in this node")))))
1054 (goto-char (match-beginning 0))
1055 (if (looking-at "\\* Menu:")
1056 (Info-next-reference))))
1058 (defun Info-prev-reference ()
1059 "Move cursor to the previous cross-reference or menu item in the node."
1060 (interactive)
1061 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1062 (old-pt (point)))
1063 (or (re-search-backward pat nil t)
1064 (progn
1065 (goto-char (point-max))
1066 (or (re-search-backward pat nil t)
1067 (progn
1068 (goto-char old-pt)
1069 (error "No cross references in this node")))))
1070 (goto-char (match-beginning 0))
1071 (if (looking-at "\\* Menu:")
1072 (Info-prev-reference))))
1074 (defun Info-index (topic)
1075 "Look up a string in the index for this file.
1076 The index is defined as the first node in the top-level menu whose
1077 name contains the word \"Index\", plus any immediately following
1078 nodes whose names also contain the word \"Index\".
1079 If there are no exact matches to the specified topic, this chooses
1080 the first match which is a case-insensitive substring of a topic.
1081 Use the `,' command to see the other matches.
1082 Give a blank topic name to go to the Index node itself."
1083 (interactive "sIndex topic: ")
1084 (let ((orignode Info-current-node)
1085 (rnode nil)
1086 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"
1087 (regexp-quote topic)))
1088 node)
1089 (Info-goto-node "Top")
1090 (or (search-forward "\n* menu:" nil t)
1091 (error "No index"))
1092 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1093 (error "No index"))
1094 (goto-char (match-beginning 1))
1095 (let ((Info-keeping-history nil))
1096 (Info-goto-node (Info-extract-menu-node-name)))
1097 (or (equal topic "")
1098 (let ((matches nil)
1099 (exact nil)
1100 (Info-keeping-history nil)
1101 found)
1102 (while
1103 (progn
1104 (goto-char (point-min))
1105 (while (re-search-forward pattern nil t)
1106 (setq matches
1107 (cons (list (buffer-substring (match-beginning 1)
1108 (match-end 1))
1109 (buffer-substring (match-beginning 2)
1110 (match-end 2))
1111 Info-current-node
1112 (string-to-int (concat "0"
1113 (buffer-substring
1114 (match-beginning 3)
1115 (match-end 3)))))
1116 matches)))
1117 (and (setq node (Info-extract-pointer "next" t))
1118 (string-match "\\<Index\\>" node)))
1119 (Info-goto-node node))
1120 (or matches
1121 (progn
1122 (Info-last)
1123 (error "No \"%s\" in index" topic)))
1124 ;; Here it is a feature that assoc is case-sensitive.
1125 (while (setq found (assoc topic matches))
1126 (setq exact (cons found exact)
1127 matches (delq found matches)))
1128 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1129 (Info-index-next 0)))))
1131 (defun Info-index-next (num)
1132 "Go to the next matching index item from the last `i' command."
1133 (interactive "p")
1134 (or Info-index-alternatives
1135 (error "No previous `i' command in this file"))
1136 (while (< num 0)
1137 (setq num (+ num (length Info-index-alternatives))))
1138 (while (> num 0)
1139 (setq Info-index-alternatives
1140 (nconc (cdr Info-index-alternatives)
1141 (list (car Info-index-alternatives)))
1142 num (1- num)))
1143 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1144 (if (> (nth 3 (car Info-index-alternatives)) 0)
1145 (forward-line (nth 3 (car Info-index-alternatives)))
1146 (forward-line 3) ; don't search in headers
1147 (let ((name (car (car Info-index-alternatives))))
1148 (if (or (re-search-forward (format
1149 "\\(Function\\|Command\\): %s\\( \\|$\\)"
1150 (regexp-quote name)) nil t)
1151 (search-forward (format "`%s'" name) nil t)
1152 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1153 (search-forward
1154 (format "`%s'" (substring name 0 (match-beginning 1)))
1155 nil t))
1156 (search-forward name nil t))
1157 (beginning-of-line)
1158 (goto-char (point-min)))))
1159 (message "Found \"%s\" in %s. %s"
1160 (car (car Info-index-alternatives))
1161 (nth 2 (car Info-index-alternatives))
1162 (if (cdr Info-index-alternatives)
1163 "(Press `,' for more)"
1164 "(Only match)")))
1166 (defun Info-undefined ()
1167 "Make command be undefined in Info."
1168 (interactive)
1169 (ding))
1171 (defun Info-help ()
1172 "Enter the Info tutorial."
1173 (interactive)
1174 (delete-other-windows)
1175 (Info-find-node "info"
1176 (if (< (window-height) 23)
1177 "Help-Small-Screen"
1178 "Help")))
1180 (defun Info-summary ()
1181 "Display a brief summary of all Info commands."
1182 (interactive)
1183 (save-window-excursion
1184 (switch-to-buffer "*Help*")
1185 (erase-buffer)
1186 (insert (documentation 'Info-mode))
1187 (goto-char (point-min))
1188 (let (ch flag)
1189 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1190 (message (if flag "Type Space to see more"
1191 "Type Space to return to Info"))
1192 (if (not (eq ?\ (setq ch (read-event))))
1193 (progn (setq unread-command-events (list ch)) nil)
1194 flag))
1195 (scroll-up)))
1196 (bury-buffer "*Help*")))
1198 (defun Info-get-token (pos start all &optional errorstring)
1199 "Return the token around POS,
1200 POS must be somewhere inside the token
1201 START is a regular expression which will match the
1202 beginning of the tokens delimited string
1203 ALL is a regular expression with a single
1204 parenthized subpattern which is the token to be
1205 returned. E.g. '{\(.*\)}' would return any string
1206 enclosed in braces around POS.
1207 SIG optional fourth argument, controls action on no match
1208 nil: return nil
1209 t: beep
1210 a string: signal an error, using that string."
1211 (save-excursion
1212 (goto-char pos)
1213 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
1214 (let (found)
1215 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1216 (not (setq found (and (<= (match-beginning 0) pos)
1217 (> (match-end 0) pos))))))
1218 (if (and found (<= (match-beginning 0) pos)
1219 (> (match-end 0) pos))
1220 (buffer-substring (match-beginning 1) (match-end 1))
1221 (cond ((null errorstring)
1222 nil)
1223 ((eq errorstring t)
1224 (beep)
1225 nil)
1227 (error "No %s around position %d" errorstring pos)))))))
1229 (defun Info-follow-nearest-node (click)
1230 "\\<Info-mode-map>Follow a node reference near point.
1231 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1232 At end of the node's text, moves to the next node."
1233 (interactive "e")
1234 (let* ((start (event-start click))
1235 (window (car start))
1236 (pos (car (cdr start))))
1237 (select-window window)
1238 (goto-char pos))
1239 (let (node)
1240 (cond
1241 ((setq node (Info-get-token (point) "\\*note[ \n]" "\\*note[ \n]\\([^:]*\\):"))
1242 (Info-follow-reference node))
1243 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1244 (Info-goto-node node))
1245 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1246 (Info-menu node))
1247 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1248 (Info-goto-node node))
1249 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1250 (Info-goto-node node))
1251 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1252 (Info-goto-node "Top"))
1253 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1254 (Info-goto-node node))
1255 ((save-excursion (forward-line 1) (eobp))
1256 (Info-next)))
1259 (defvar Info-mode-map nil
1260 "Keymap containing Info commands.")
1261 (if Info-mode-map
1263 (setq Info-mode-map (make-keymap))
1264 (suppress-keymap Info-mode-map)
1265 (define-key Info-mode-map "." 'beginning-of-buffer)
1266 (define-key Info-mode-map " " 'Info-scroll-up)
1267 (define-key Info-mode-map "\C-m" 'Info-next-preorder)
1268 (define-key Info-mode-map "\t" 'Info-next-reference)
1269 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1270 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1271 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1272 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1273 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1274 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1275 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1276 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1277 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1278 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1279 (define-key Info-mode-map "0" 'undefined)
1280 (define-key Info-mode-map "?" 'Info-summary)
1281 (define-key Info-mode-map "]" 'Info-forward-node)
1282 (define-key Info-mode-map "[" 'Info-backward-node)
1283 (define-key Info-mode-map "<" 'Info-top-node)
1284 (define-key Info-mode-map ">" 'Info-final-node)
1285 (define-key Info-mode-map "b" 'beginning-of-buffer)
1286 (define-key Info-mode-map "d" 'Info-directory)
1287 (define-key Info-mode-map "e" 'Info-edit)
1288 (define-key Info-mode-map "f" 'Info-follow-reference)
1289 (define-key Info-mode-map "g" 'Info-goto-node)
1290 (define-key Info-mode-map "h" 'Info-help)
1291 (define-key Info-mode-map "i" 'Info-index)
1292 (define-key Info-mode-map "l" 'Info-last)
1293 (define-key Info-mode-map "m" 'Info-menu)
1294 (define-key Info-mode-map "n" 'Info-next)
1295 (define-key Info-mode-map "p" 'Info-prev)
1296 (define-key Info-mode-map "q" 'Info-exit)
1297 (define-key Info-mode-map "s" 'Info-search)
1298 (define-key Info-mode-map "t" 'Info-top-node)
1299 (define-key Info-mode-map "u" 'Info-up)
1300 (define-key Info-mode-map "," 'Info-index-next)
1301 (define-key Info-mode-map "\177" 'Info-scroll-down)
1302 (define-key Info-mode-map [mouse-2] 'Info-follow-nearest-node)
1305 ;; Info mode is suitable only for specially formatted data.
1306 (put 'info-mode 'mode-class 'special)
1308 (defun Info-mode ()
1309 "\\<Info-mode-map>
1310 Info mode provides commands for browsing through the Info documentation tree.
1311 Documentation in Info is divided into \"nodes\", each of which discusses
1312 one topic and contains references to other nodes which discuss related
1313 topics. Info has commands to follow the references and show you other nodes.
1315 \\[Info-help] Invoke the Info tutorial.
1317 Selecting other nodes:
1318 \\[Info-next] Move to the \"next\" node of this node.
1319 \\[Info-prev] Move to the \"previous\" node of this node.
1320 \\[Info-up] Move \"up\" from this node.
1321 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1322 Picking a menu item causes another node to be selected.
1323 \\[Info-directory] Go to the Info directory node.
1324 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1325 \\[Info-last] Move to the last node you were at.
1326 \\[Info-index] Look up a topic in this file's Index and move to that node.
1327 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1329 Moving within a node:
1330 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1331 already visible, try to go to the next menu entry, or up if there is none.
1332 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1333 already visible, try to go to the previous menu entry, or up if there is none.
1334 \\[beginning-of-buffer] Go to beginning of node.
1336 Advanced commands:
1337 \\[Info-exit] Quit Info: reselect previously selected buffer.
1338 \\[Info-edit] Edit contents of selected node.
1339 1 Pick first item in node's menu.
1340 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1341 \\[Info-goto-node] Move to node specified by name.
1342 You may include a filename as well, as (FILENAME)NODENAME.
1343 \\[universal-argument] \\[info] Move to new Info file with completion.
1344 \\[Info-search] Search through this Info file for specified regexp,
1345 and select the node in which the next occurrence is found.
1346 \\[Info-next-preorder] Next-preorder; that is, try to go to the next menu item,
1347 and if that fails try to move up, and if that fails, tell user
1348 he/she is done reading.
1349 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1350 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1351 (kill-all-local-variables)
1352 (setq major-mode 'Info-mode)
1353 (setq mode-name "Info")
1354 (use-local-map Info-mode-map)
1355 (set-syntax-table text-mode-syntax-table)
1356 (setq local-abbrev-table text-mode-abbrev-table)
1357 (setq case-fold-search t)
1358 (setq buffer-read-only t)
1359 (make-local-variable 'Info-current-file)
1360 (make-local-variable 'Info-current-subfile)
1361 (make-local-variable 'Info-current-node)
1362 (make-local-variable 'Info-tag-table-marker)
1363 (make-local-variable 'Info-history)
1364 (make-local-variable 'Info-index-alternatives)
1365 (if (fboundp 'make-face)
1366 (progn
1367 (make-face 'info-node)
1368 (make-face 'info-menu-5)
1369 (make-face 'info-xref)
1370 (or (face-differs-from-default-p 'info-node)
1371 (if (face-differs-from-default-p 'bold-italic)
1372 (copy-face 'bold-italic 'info-node)
1373 (copy-face 'bold 'info-node)))
1374 (or (face-differs-from-default-p 'info-menu-5)
1375 (set-face-underline-p 'info-menu-5 t))
1376 (or (face-differs-from-default-p 'info-xref)
1377 (copy-face 'bold 'info-xref)))
1378 (setq Info-fontify nil))
1379 (Info-set-mode-line)
1380 (run-hooks 'Info-mode-hook))
1382 (defvar Info-edit-map nil
1383 "Local keymap used within `e' command of Info.")
1384 (if Info-edit-map
1386 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1387 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1389 ;; Info-edit mode is suitable only for specially formatted data.
1390 (put 'info-edit-mode 'mode-class 'special)
1392 (defun Info-edit-mode ()
1393 "Major mode for editing the contents of an Info node.
1394 Like text mode with the addition of `Info-cease-edit'
1395 which returns to Info mode for browsing.
1396 \\{Info-edit-map}"
1399 (defun Info-edit ()
1400 "Edit the contents of this Info node.
1401 Allowed only if variable `Info-enable-edit' is non-nil."
1402 (interactive)
1403 (or Info-enable-edit
1404 (error "Editing info nodes is not enabled"))
1405 (use-local-map Info-edit-map)
1406 (setq major-mode 'Info-edit-mode)
1407 (setq mode-name "Info Edit")
1408 (kill-local-variable 'mode-line-buffer-identification)
1409 (setq buffer-read-only nil)
1410 ;; Make mode line update.
1411 (set-buffer-modified-p (buffer-modified-p))
1412 (message (substitute-command-keys
1413 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1415 (defun Info-cease-edit ()
1416 "Finish editing Info node; switch back to Info proper."
1417 (interactive)
1418 ;; Do this first, so nothing has changed if user C-g's at query.
1419 (and (buffer-modified-p)
1420 (y-or-n-p "Save the file? ")
1421 (save-buffer))
1422 (use-local-map Info-mode-map)
1423 (setq major-mode 'Info-mode)
1424 (setq mode-name "Info")
1425 (Info-set-mode-line)
1426 (setq buffer-read-only t)
1427 ;; Make mode line update.
1428 (set-buffer-modified-p (buffer-modified-p))
1429 (and (marker-position Info-tag-table-marker)
1430 (buffer-modified-p)
1431 (message "Tags may have changed. Use Info-tagify if necessary")))
1433 (defun Info-find-emacs-command-nodes (command)
1434 "Return a list of locations documenting COMMAND in the Emacs Info manual.
1435 The locations are of the format used in Info-history, i.e.
1436 \(FILENAME NODENAME BUFFERPOS\)."
1437 (require 'info)
1438 (let ((where '())
1439 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
1440 ":\\s *\\(.*\\)\\.$")))
1441 (save-excursion
1442 (Info-find-node "emacs" "Command Index")
1443 ;; Take the index node off the Info history.
1444 (setq Info-history (cdr Info-history))
1445 (goto-char (point-max))
1446 (while (re-search-backward cmd-desc nil t)
1447 (setq where (cons (list Info-current-file
1448 (buffer-substring
1449 (match-beginning 1)
1450 (match-end 1))
1452 where)))
1453 where)))
1455 ;;;###autoload
1456 (defun Info-goto-emacs-command-node (command)
1457 "Go to the Info node in the Emacs manual for command COMMAND.
1458 The command is found by looking up in Emacs manual's Command Index."
1459 (interactive "CFind documentation for command: ")
1460 (or (commandp command)
1461 (signal 'wrong-type-argument (list 'commandp command)))
1462 (let ((where (Info-find-emacs-command-nodes command)))
1463 (if where
1464 (let ((num-matches (length where)))
1465 ;; Get Info running, and pop to it in another window.
1466 (save-window-excursion
1467 (info))
1468 (pop-to-buffer "*info*")
1469 (Info-find-node (car (car where))
1470 (car (cdr (car where))))
1471 (if (> num-matches 1)
1472 (progn
1473 ;; Info-find-node already pushed (car where) onto
1474 ;; Info-history. Put the other nodes that were found on
1475 ;; the history.
1476 (setq Info-history (nconc (cdr where) Info-history))
1477 (message (substitute-command-keys
1478 "Found %d other entr%s. Use \\[Info-last] to see %s.")
1479 (1- num-matches)
1480 (if (> num-matches 2) "ies" "y")
1481 (if (> num-matches 2) "them" "it")))))
1482 (error "Couldn't find documentation for %s." command))))
1484 ;;;###autoload
1485 (defun Info-goto-emacs-key-command-node (key)
1486 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1487 Interactively, if the binding is execute-extended-command, a command is read.
1488 The command is found by looking up in Emacs manual's Command Index."
1489 (interactive "kFind documentation for key:")
1490 (let ((command (key-binding key)))
1491 (cond ((null command)
1492 (message "%s is undefined" (key-description key)))
1493 ((and (interactive-p)
1494 (eq command 'execute-extended-command))
1495 (Info-goto-emacs-command-node
1496 (read-command "Find documentation for command: ")))
1498 (Info-goto-emacs-command-node command)))))
1500 (defun Info-fontify-node ()
1501 (save-excursion
1502 (let ((buffer-read-only nil))
1503 (goto-char (point-min))
1504 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1505 (progn
1506 (goto-char (match-end 0))
1507 (while
1508 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1509 (goto-char (match-end 0))
1510 (put-text-property (match-beginning 1) (match-end 1)
1511 'face 'info-xref)
1512 (put-text-property (match-beginning 1) (match-end 1)
1513 'mouse-face 'highlight))))
1514 (goto-char (point-min))
1515 (while (re-search-forward "\\*Note[ \n\t]*\\([^:]*\\):" nil t)
1516 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
1518 (put-text-property (match-beginning 1) (match-end 1)
1519 'face 'info-xref)
1520 (put-text-property (match-beginning 1) (match-end 1)
1521 'mouse-face 'highlight)))
1522 (goto-char (point-min))
1523 (if (and (search-forward "\n* Menu:" nil t)
1524 (not (string-match "\\<Index\\>" Info-current-node))
1525 ;; Don't take time to annotate huge menus
1526 (< (- (point-max) (point)) 30000))
1527 (let ((n 0))
1528 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
1529 (setq n (1+ n))
1530 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
1531 (put-text-property (match-beginning 0)
1532 (1+ (match-beginning 0))
1533 'face 'info-menu-5))
1534 (put-text-property (match-beginning 1) (match-end 1)
1535 'face 'info-node)
1536 (put-text-property (match-beginning 1) (match-end 1)
1537 'mouse-face 'highlight))))
1538 (set-buffer-modified-p nil))))
1540 (provide 'info)
1542 ;;; info.el ends here