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