1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
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)
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.
26 ;;; Note that nowadays we expect info files to be made using makeinfo.
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-fontify t
46 "*Non-nil enables highlighting and fonts in Info nodes.")
48 (defvar Info-fontify-maximum-menu-size 30000
49 "*Maximum size of menu to fontify if `Info-fontify' is non-nil.")
51 (defvar Info-directory-list
52 (let ((path (getenv "INFOPATH"))
53 ;; This is for older Emacs versions
54 ;; which might get this info.el from the Texinfo distribution.
55 (path-separator (if (boundp 'path-separator) path-separator
56 (if (eq system-type 'ms-dos) ";" ":")))
57 (sibling (if installation-directory
58 (expand-file-name "info/" installation-directory))))
62 (while (> (length path) 0)
63 (setq idx (or (string-match path-separator path) (length path))
64 list (cons (substring path 0 idx) list)
65 path (substring path (min (1+ idx)
68 (if (or (null sibling)
69 (member sibling Info-default-directory-list)
70 (not (file-exists-p sibling))
71 ;; On DOS/NT, we use movable executables always,
72 ;; and we must always find the Info dir at run time.
73 (if (or (eq system-type 'ms-dos) (eq system-type 'windows-nt))
75 ;; Use invocation-directory for Info only if we used it for
76 ;; exec-directory also.
77 (not (string= exec-directory
78 (expand-file-name "lib-src/"
79 installation-directory)))))
80 Info-default-directory-list
81 (reverse (cons sibling (cdr (reverse Info-default-directory-list)))))))
82 "List of directories to search for Info documentation files.
83 nil means not yet initialized. In this case, Info uses the environment
84 variable INFOPATH to initialize it, or `Info-default-directory-list'
85 if there is no INFOPATH variable in the environment.
86 The last element of `Info-default-directory-list' is the directory
87 where Emacs installs the Info files that come with it.
89 If you run the Emacs executable from the `src' directory in the Emacs
90 source tree, the `info' directory in the source tree is used as the last
91 element, in place of the installation Info directory. This is useful
92 when you run a version of Emacs without installing it.")
94 (defvar Info-additional-directory-list nil
95 "List of additional directories to search for Info documentation files.
96 These directories are not searched for merging the `dir' file.")
98 (defvar Info-current-file nil
99 "Info file that Info is now looking at, or nil.
100 This is the name that was specified in Info, not the actual file name.
101 It doesn't contain directory names or file name extensions added by Info.")
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
124 (if (eq system-type 'ms-dos)
125 '( (".gz" . "gunzip")
129 '( (".info.Z" . "uncompress")
130 (".info.Y" . "unyabba")
131 (".info.gz" . "gunzip")
132 (".info.z" . "gunzip")
134 (".Z" . "uncompress")
139 "List of file name suffixes and associated decoding commands.
140 Each entry should be (SUFFIX . STRING); the file is given to
141 the command as standard input. If STRING is nil, no decoding is done.
142 Because the SUFFIXes are tried in order, the empty string should
143 be last in the list.")
145 ;; Concatenate SUFFIX onto FILENAME.
146 ;; First, on ms-dos, delete some of the extension in FILENAME
148 (defun info-insert-file-contents-1 (filename suffix)
149 (if (not (eq system-type 'ms-dos))
150 (concat filename suffix)
151 (let* ((sans-exts (file-name-sans-extension filename))
152 ;; How long is the extension in FILENAME.
153 (ext-len (- (length filename) (length sans-exts) 1))
154 ;; How many chars of that extension should we keep?
155 (ext-left (max 0 (- 3 (length suffix)))))
156 ;; SUFFIX starts with a dot. If FILENAME already has one,
157 ;; get rid of the one in SUFFIX.
158 (or (and (zerop ext-len)
159 (not (eq (aref filename (1- (length filename))) ?.)))
160 (setq suffix (substring suffix 1)))
161 ;; Get rid of the rest of the extension, and add SUFFIX.
162 (concat (substring filename 0 (- (length filename)
163 (- ext-len ext-left)))
166 (defun info-insert-file-contents (filename &optional visit)
167 "Insert the contents of an info file in the current buffer.
168 Do the right thing if the file has been compressed or zipped."
169 (let ((tail Info-suffix-list)
171 (if (file-exists-p filename)
172 ;; FILENAME exists--see if that name contains a suffix.
173 ;; If so, set DECODE accordingly.
177 (concat (regexp-quote (car (car tail))) "$")
179 (setq tail (cdr tail)))
180 (setq fullname filename
181 decoder (cdr (car tail))))
182 ;; Try adding suffixes to FILENAME and see if we can find something.
184 (not (file-exists-p (info-insert-file-contents-1
185 filename (car (car tail))))))
186 (setq tail (cdr tail)))
187 ;; If we found a file with a suffix, set DECODER according to the suffix
188 ;; and set FULLNAME to the file's actual name.
189 (setq fullname (info-insert-file-contents-1 filename (car (car tail)))
190 decoder (cdr (car tail)))
192 (error "Can't find %s or any compressed version of it" filename)))
193 ;; check for conflict with jka-compr
194 (if (and (featurep 'jka-compr)
195 (jka-compr-installed-p)
196 (jka-compr-get-compression-info fullname))
198 (insert-file-contents fullname visit)
200 (let ((buffer-read-only nil)
201 (default-directory (or (file-name-directory fullname)
203 (call-process-region (point-min) (point-max) decoder t t)))))
205 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
208 (defun info (&optional file)
209 "Enter Info, the documentation browser.
210 Optional argument FILE specifies the file to examine;
211 the default is the top-level directory of Info.
213 In interactive use, a prefix argument directs this command
214 to read a file name from the minibuffer."
215 (interactive (if current-prefix-arg
216 (list (read-file-name "Info file name: " nil nil t))))
218 (Info-goto-node (concat "(" file ")"))
219 (if (get-buffer "*info*")
220 (pop-to-buffer "*info*")
224 (defun info-standalone ()
225 "Run Emacs as a standalone Info reader.
226 Usage: emacs -f info-standalone [filename]
227 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
228 (setq Info-standalone t)
229 (if (and command-line-args-left
230 (not (string-match "^-" (car command-line-args-left))))
233 (info (car command-line-args-left))
234 (setq command-line-args-left (cdr command-line-args-left)))
235 (error (send-string-to-terminal
236 (format "%s\n" (if (eq (car-safe err) 'error)
238 (save-buffers-kill-emacs)))
241 ;; Go to an info node specified as separate filename and nodename.
242 ;; no-going-back is non-nil if recovering from an error in this function;
243 ;; it says do not attempt further (recursive) error recovery.
244 (defun Info-find-node (filename nodename &optional no-going-back)
245 ;; Convert filename to lower case if not found as specified.
248 (let (temp temp-downcase found)
249 (setq filename (substitute-in-file-name filename))
250 (if (string= (downcase (file-name-nondirectory filename)) "dir")
252 (let ((dirs (if (string-match "^\\./" filename)
253 ;; If specified name starts with `./'
254 ;; then just try current directory.
256 (if (file-name-absolute-p filename)
257 ;; No point in searching for an
258 ;; absolute file name
260 (if Info-additional-directory-list
261 (append Info-directory-list
262 Info-additional-directory-list)
263 Info-directory-list)))))
264 ;; Search the directory list for file FILENAME.
265 (while (and dirs (not found))
266 (setq temp (expand-file-name filename (car dirs)))
268 (expand-file-name (downcase filename) (car dirs)))
269 ;; Try several variants of specified name.
270 (let ((suffix-list Info-suffix-list))
271 (while (and suffix-list (not found))
272 (cond ((file-exists-p
273 (info-insert-file-contents-1
274 temp (car (car suffix-list))))
277 (info-insert-file-contents-1
278 temp-downcase (car (car suffix-list))))
279 (setq found temp-downcase)))
280 (setq suffix-list (cdr suffix-list))))
281 (setq dirs (cdr dirs)))))
283 (setq filename found)
284 (error "Info file %s does not exist" filename))))
285 ;; Record the node we are leaving.
286 (if (and Info-current-file (not no-going-back))
288 (cons (list Info-current-file Info-current-node (point))
290 ;; Go into info buffer.
291 (switch-to-buffer "*info*")
292 (buffer-disable-undo (current-buffer))
293 (or (eq major-mode 'Info-mode)
296 (setq Info-current-node nil)
299 ;; Switch files if necessary
301 (equal Info-current-file filename)
302 (let ((buffer-read-only nil))
303 (setq Info-current-file nil
304 Info-current-subfile nil
305 Info-current-file-completions nil
306 Info-index-alternatives nil
307 buffer-file-name nil)
311 (info-insert-file-contents filename t)
312 (setq default-directory (file-name-directory filename)))
313 (set-buffer-modified-p nil)
314 ;; See whether file has a tag table. Record the location if yes.
315 (set-marker Info-tag-table-marker nil)
316 (goto-char (point-max))
318 ;; Use string-equal, not equal, to ignore text props.
319 (or (string-equal nodename "*")
320 (not (search-forward "\^_\nEnd tag table\n" nil t))
322 ;; We have a tag table. Find its beginning.
323 ;; Is this an indirect file?
324 (search-backward "\nTag table:\n")
328 (looking-at "(Indirect)\n"))
329 ;; It is indirect. Copy it to another buffer
330 ;; and record that the tag table is in that buffer.
332 (let ((buf (current-buffer)))
333 (set-buffer (get-buffer-create " *info tag table*"))
334 (buffer-disable-undo (current-buffer))
335 (setq case-fold-search t)
337 (insert-buffer-substring buf)
338 (set-marker Info-tag-table-marker
340 (set-marker Info-tag-table-marker pos))))
341 (setq Info-current-file
342 (if (eq filename t) "dir" filename))))
343 ;; Use string-equal, not equal, to ignore text props.
344 (if (string-equal nodename "*")
345 (progn (setq Info-current-node nodename)
346 (Info-set-mode-line))
347 ;; Search file for a suitable node.
348 (let ((guesspos (point-min))
349 (regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n\177]")))
350 ;; First get advice from tag table if file has one.
351 ;; Also, if this is an indirect info file,
352 ;; read the proper subfile into this buffer.
353 (if (marker-position Info-tag-table-marker)
355 (set-buffer (marker-buffer Info-tag-table-marker))
356 (goto-char Info-tag-table-marker)
357 (if (re-search-forward regexp nil t)
359 (setq guesspos (read (current-buffer)))
360 ;; If this is an indirect file,
361 ;; determine which file really holds this node
363 (if (not (eq (current-buffer) (get-buffer "*info*")))
365 (Info-read-subfile guesspos))))
366 (error "No such node: \"%s\"" nodename))))
367 (goto-char (max (point-min) (- guesspos 1000)))
368 ;; Now search from our advised position (or from beg of buffer)
369 ;; to find the actual node.
371 (while (search-forward "\n\^_" nil t)
375 (if (re-search-backward regexp beg t)
377 (error "No such node: %s" nodename)))
379 ;; If we did not finish finding the specified node,
380 ;; go back to the previous one.
381 (or Info-current-node no-going-back (null Info-history)
382 (let ((hist (car Info-history)))
383 (setq Info-history (cdr Info-history))
384 (Info-find-node (nth 0 hist) (nth 1 hist) t)
385 (goto-char (nth 2 hist)))))
386 (goto-char (point-min)))
388 ;; Cache the contents of the (virtual) dir file, once we have merged
389 ;; it for the first time, so we can save time subsequently.
390 (defvar Info-dir-contents nil)
392 ;; Cache for the directory we decided to use for the default-directory
393 ;; of the merged dir text.
394 (defvar Info-dir-contents-directory nil)
396 ;; Record the file attributes of all the files from which we
397 ;; constructed Info-dir-contents.
398 (defvar Info-dir-file-attributes nil)
400 ;; Construct the Info directory node by merging the files named `dir'
401 ;; from various directories. Set the *info* buffer's
402 ;; default-directory to the first directory we actually get any text
404 (defun Info-insert-dir ()
405 (if (and Info-dir-contents Info-dir-file-attributes
406 ;; Verify that none of the files we used has changed
409 (mapcar '(lambda (elt)
410 (let ((curr (file-attributes (car elt))))
411 ;; Don't compare the access time.
412 (if curr (setcar (nthcdr 4 curr) 0))
413 (setcar (nthcdr 4 (cdr elt)) 0)
414 (equal (cdr elt) curr)))
415 Info-dir-file-attributes))))
416 (insert Info-dir-contents)
417 (let ((dirs Info-directory-list)
418 buffers buffer others nodes dirs-done)
420 (setq Info-dir-file-attributes nil)
422 ;; Search the directory list for the directory file.
424 (let ((truename (file-truename (expand-file-name (car dirs)))))
425 (or (member truename dirs-done)
426 (member (directory-file-name truename) dirs-done)
427 ;; Try several variants of specified name.
428 ;; Try upcasing, appending `.info', or both.
432 (progn (setq file (expand-file-name "dir" truename))
433 (file-attributes file))
434 (progn (setq file (expand-file-name "DIR" truename))
435 (file-attributes file))
436 (progn (setq file (expand-file-name "dir.info" truename))
437 (file-attributes file))
438 (progn (setq file (expand-file-name "DIR.INFO" truename))
439 (file-attributes file)))))
442 (cons (directory-file-name truename)
447 (message "Composing main Info directory..."))
448 (set-buffer (generate-new-buffer "info dir"))
449 (insert-file-contents file)
450 (setq buffers (cons (current-buffer) buffers)
451 Info-dir-file-attributes
452 (cons (cons file attrs)
453 Info-dir-file-attributes))))))
454 (setq dirs (cdr dirs))))
457 (error "Can't find the info directory node"))
458 ;; Distinguish the dir file that comes with Emacs from all the
459 ;; others. Yes, that is really what this is supposed to do.
460 ;; If it doesn't work, fix it.
461 (setq buffer (car buffers)
462 others (cdr buffers))
464 ;; Insert the entire original dir file as a start; use its
465 ;; default directory as the default directory for the whole
467 (insert-buffer buffer)
468 (setq Info-dir-contents-directory (save-excursion
472 ;; Look at each of the other buffers one by one.
474 (let ((other (car others)))
475 ;; In each, find all the menus.
478 (goto-char (point-min))
479 ;; Find each menu, and add an elt to NODES for it.
480 (while (re-search-forward "^\\* Menu:" nil t)
481 (let (beg nodename end)
484 (search-backward "\n\^_")
485 (search-forward "Node: ")
486 (setq nodename (Info-following-node-name))
487 (search-forward "\n\^_" nil 'move)
490 (setq nodes (cons (list nodename other beg end) nodes))))))
491 (setq others (cdr others)))
492 ;; Add to the main menu a menu item for each other node.
493 (re-search-forward "^\\* Menu:")
495 (let ((menu-items '("top"))
498 (end (save-excursion (search-forward "\^_" nil t) (point))))
500 (let ((nodename (car (car nodes))))
502 (or (member (downcase nodename) menu-items)
503 (re-search-forward (concat "^\\* "
504 (regexp-quote nodename)
508 (insert "* " nodename "::" "\n")
509 (setq menu-items (cons nodename menu-items))))))
510 (setq nodes (cdr nodes))))
511 ;; Now take each node of each of the other buffers
512 ;; and merge it into the main buffer.
514 (let ((nodename (car (car nodes))))
515 (goto-char (point-min))
516 ;; Find the like-named node in the main buffer.
517 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
518 (regexp-quote nodename)
522 (search-forward "\n\^_" nil 'move)
525 ;; If none exists, add one.
526 (goto-char (point-max))
527 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
528 ;; Merge the text from the other buffer's menu
529 ;; into the menu in the like-named node in the main buffer.
530 (apply 'insert-buffer-substring (cdr (car nodes))))
531 (setq nodes (cdr nodes)))
532 ;; Kill all the buffers we just made.
534 (kill-buffer (car buffers))
535 (setq buffers (cdr buffers)))
536 (message "Composing main Info directory...done"))
537 (setq Info-dir-contents (buffer-string)))
538 (setq default-directory Info-dir-contents-directory))
540 (defun Info-read-subfile (nodepos)
541 (set-buffer (marker-buffer Info-tag-table-marker))
542 (goto-char (point-min))
543 (search-forward "\n\^_")
548 (while (not (looking-at "\^_"))
551 thisfilepos thisfilename)
552 (search-forward ": ")
553 (setq thisfilename (buffer-substring beg (- (point) 2)))
554 (setq thisfilepos (read (current-buffer)))
555 ;; read in version 19 stops at the end of number.
556 ;; Advance to the next line.
558 (if (> thisfilepos nodepos)
560 (setq lastfilename thisfilename)
561 (setq lastfilepos thisfilepos))
563 (set-buffer (get-buffer "*info*"))
564 (or (equal Info-current-subfile lastfilename)
565 (let ((buffer-read-only nil))
566 (setq buffer-file-name nil)
569 (info-insert-file-contents lastfilename)
570 (set-buffer-modified-p nil)
571 (setq Info-current-subfile lastfilename)))
572 (goto-char (point-min))
573 (search-forward "\n\^_")
574 (+ (- nodepos lastfilepos) (point))))
576 ;; Select the info node that point is in.
577 (defun Info-select-node ()
579 ;; Find beginning of node.
580 (search-backward "\n\^_")
582 ;; Get nodename spelled as it is in the node.
583 (re-search-forward "Node:[ \t]*")
584 (setq Info-current-node
585 (buffer-substring (point)
587 (skip-chars-forward "^,\t\n")
590 ;; Find the end of it, and narrow.
592 (let (active-expression)
593 (narrow-to-region (point)
594 (if (re-search-forward "\n[\^_\f]" nil t)
597 (if (looking-at "[\n\^_\f]*execute: ")
599 (goto-char (match-end 0))
600 (setq active-expression
601 (read (current-buffer))))))
603 (if Info-enable-active-nodes (eval active-expression))
604 (if Info-fontify (Info-fontify-node))
605 (run-hooks 'Info-selection-hook))))
607 (defun Info-set-mode-line ()
608 (setq mode-line-buffer-identification
611 (if Info-current-file
612 (file-name-nondirectory Info-current-file)
615 (or Info-current-node ""))))
617 ;; Go to an info node specified with a filename-and-nodename string
618 ;; of the sort that is found in pointers in nodes.
620 (defun Info-goto-node (nodename)
621 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
622 (interactive (list (Info-read-node-name "Goto node: ")))
624 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
626 (setq filename (if (= (match-beginning 1) (match-end 1))
628 (substring nodename (match-beginning 2) (match-end 2)))
629 nodename (substring nodename (match-beginning 3) (match-end 3)))
630 (let ((trim (string-match "\\s *\\'" filename)))
631 (if trim (setq filename (substring filename 0 trim))))
632 (let ((trim (string-match "\\s *\\'" nodename)))
633 (if trim (setq nodename (substring nodename 0 trim))))
634 (if transient-mark-mode (deactivate-mark))
635 (Info-find-node (if (equal filename "") nil filename)
636 (if (equal nodename "") "Top" nodename))))
638 ;; This function is used as the "completion table" while reading a node name.
639 ;; It does completion using the alist in completion-table
640 ;; unless STRING starts with an open-paren.
641 (defun Info-read-node-name-1 (string predicate code)
642 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
646 (try-completion string completion-table predicate)))
650 (all-completions string completion-table predicate)))
654 (assoc string completion-table))))))
656 (defun Info-read-node-name (prompt &optional default)
657 (let* ((completion-ignore-case t)
658 (completion-table (Info-build-node-completions))
659 (nodename (completing-read prompt 'Info-read-node-name-1)))
660 (if (equal nodename "")
662 (Info-read-node-name prompt))
665 (defun Info-build-node-completions ()
666 (or Info-current-file-completions
670 (if (marker-buffer Info-tag-table-marker)
672 (set-buffer (marker-buffer Info-tag-table-marker))
674 (goto-char Info-tag-table-marker)
675 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
677 (cons (list (buffer-substring (match-beginning 1)
681 (goto-char (point-min))
682 (while (search-forward "\n\^_" nil t)
686 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
689 (cons (list (buffer-substring (match-beginning 1)
692 (setq Info-current-file-completions compl))))
694 (defun Info-restore-point (hl)
695 "If this node has been visited, restore the point value when we left."
697 (if (and (equal (nth 0 (car hl)) Info-current-file)
698 ;; Use string-equal, not equal, to ignore text props.
699 (string-equal (nth 1 (car hl)) Info-current-node))
701 (goto-char (nth 2 (car hl)))
702 (setq hl nil)) ;terminate the while at next iter
703 (setq hl (cdr hl)))))
705 (defvar Info-last-search nil
706 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
708 (defun Info-search (regexp)
709 "Search for REGEXP, starting from point, and select node it's found in."
710 (interactive "sSearch (regexp): ")
711 (if transient-mark-mode (deactivate-mark))
712 (if (equal regexp "")
713 (setq regexp Info-last-search)
714 (setq Info-last-search regexp))
715 (let ((found ()) current
716 (onode Info-current-node)
717 (ofile Info-current-file)
719 (osubfile Info-current-subfile))
723 (if (null Info-current-subfile)
724 (progn (re-search-forward regexp) (setq found (point)))
726 (progn (re-search-forward regexp) (setq found (point)))
727 (search-failed nil)))))
728 (if (not found) ;can only happen in subfile case -- else would have erred
731 (set-buffer (marker-buffer Info-tag-table-marker))
732 (goto-char (point-min))
733 (search-forward "\n\^_\nIndirect:")
735 (narrow-to-region (point)
736 (progn (search-forward "\n\^_")
738 (goto-char (point-min))
739 (search-forward (concat "\n" osubfile ": "))
742 (re-search-forward "\\(^.*\\): [0-9]+$")
743 (goto-char (+ (match-end 1) 2))
744 (setq list (cons (cons (read (current-buffer))
745 (buffer-substring (match-beginning 1)
748 (goto-char (1+ (match-end 0))))
749 (setq list (nreverse list)
750 current (car (car list))
753 (message "Searching subfile %s..." (cdr (car list)))
754 (Info-read-subfile (car (car list)))
755 (setq list (cdr list))
756 ;; (goto-char (point-min))
757 (if (re-search-forward regexp nil t)
758 (setq found (point) list ())))
761 (signal 'search-failed (list regexp))))
763 (progn (Info-read-subfile opoint)
765 (Info-select-node)))))
769 ;; Use string-equal, not equal, to ignore text props.
770 (or (and (string-equal onode Info-current-node)
771 (equal ofile Info-current-file))
772 (setq Info-history (cons (list ofile onode opoint)
775 ;; Extract the value of the node-pointer named NAME.
776 ;; If there is none, use ERRORNAME in the error message;
777 ;; if ERRORNAME is nil, just return nil.
778 (defun Info-extract-pointer (name &optional errorname)
780 (goto-char (point-min))
782 (if (re-search-backward (concat name ":") nil t)
784 (goto-char (match-end 0))
785 (Info-following-node-name))
788 (error (concat "Node has no " (capitalize (or errorname name))))))))
790 ;; Return the node name in the buffer following point.
791 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
792 ;; saying which chas may appear in the node name.
793 (defun Info-following-node-name (&optional allowedchars)
794 (skip-chars-forward " \t")
798 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
799 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
801 (skip-chars-forward "^)")))
802 (skip-chars-backward " ")
806 "Go to the next node of this node."
808 (Info-goto-node (Info-extract-pointer "next")))
811 "Go to the previous node of this node."
813 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
816 "Go to the superior node of this node."
818 (Info-goto-node (Info-extract-pointer "up"))
819 (Info-restore-point Info-history))
822 "Go back to the last node visited."
825 (error "This is the first Info node you looked at"))
826 (let (filename nodename opoint)
827 (setq filename (car (car Info-history)))
828 (setq nodename (car (cdr (car Info-history))))
829 (setq opoint (car (cdr (cdr (car Info-history)))))
830 (setq Info-history (cdr Info-history))
831 (Info-find-node filename nodename)
832 (setq Info-history (cdr Info-history))
835 (defun Info-directory ()
836 "Go to the Info directory node."
838 (Info-find-node "dir" "top"))
840 (defun Info-follow-reference (footnotename)
841 "Follow cross reference named NAME to the node it refers to.
842 NAME may be an abbreviation of the reference name."
844 (let ((completion-ignore-case t)
845 completions default alt-default (start-point (point)) str i bol eol)
847 ;; Store end and beginning of line.
853 (goto-char (point-min))
854 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
855 (setq str (buffer-substring
858 ;; See if this one should be the default.
860 (<= (match-beginning 0) start-point)
861 (<= start-point (point))
863 ;; See if this one should be the alternate default.
864 (and (null alt-default)
865 (and (<= bol (match-beginning 0))
867 (setq alt-default t))
869 (while (setq i (string-match "[ \n\t]+" str i))
870 (setq str (concat (substring str 0 i) " "
871 (substring str (match-end 0))))
873 ;; Record as a completion and perhaps as default.
874 (if (eq default t) (setq default str))
875 (if (eq alt-default t) (setq alt-default str))
879 ;; If no good default was found, try an alternate.
881 (setq default alt-default))
882 ;; If only one cross-reference found, then make it default.
883 (if (eq (length completions) 1)
884 (setq default (car (car completions))))
886 (let ((input (completing-read (if default
887 (concat "Follow reference named: ("
889 "Follow reference named: ")
891 (list (if (equal input "")
893 (error "No cross-references in this node"))))
894 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename))))
895 (while (setq i (string-match " " str i))
896 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
899 (goto-char (point-min))
900 (or (re-search-forward str nil t)
901 (error "No cross-reference named %s" footnotename))
902 (goto-char (+ (match-beginning 0) 5))
904 (Info-extract-menu-node-name "Bad format cross reference" t)))
905 (while (setq i (string-match "[ \t\n]+" target i))
906 (setq target (concat (substring target 0 i) " "
907 (substring target (match-end 0))))
909 (Info-goto-node target)))
911 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
912 (skip-chars-forward " \t\n")
915 (skip-chars-forward "^:")
919 (buffer-substring beg (1- (point)))
920 (skip-chars-forward " \t\n")
921 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
922 (while (setq i (string-match "\n" str i))
924 ;; Collapse multiple spaces.
925 (while (string-match " +" str)
926 (setq str (replace-match " " t t str)))
929 ;; No one calls this.
930 ;;(defun Info-menu-item-sequence (list)
932 ;; (Info-menu (car list))
933 ;; (setq list (cdr list))))
935 (defun Info-complete-menu-item (string predicate action)
936 (let ((case-fold-search t))
937 (cond ((eq action nil)
939 (pattern (concat "\n\\* \\("
940 (regexp-quote string)
943 (set-buffer Info-complete-menu-buffer)
944 (goto-char (point-min))
945 (while (re-search-forward pattern nil t)
946 (setq completions (cons (cons (format "%s"
952 (try-completion string completions predicate)))
955 (pattern (concat "\n\\* \\("
956 (regexp-quote string)
959 (set-buffer Info-complete-menu-buffer)
960 (goto-char (point-min))
961 (while (re-search-forward pattern nil t)
962 (setq completions (cons (cons (format "%s"
968 (all-completions string completions predicate)))
971 (set-buffer Info-complete-menu-buffer)
972 (goto-char (point-min))
973 (re-search-forward (concat "\n\\* "
974 (regexp-quote string)
979 (defun Info-menu (menu-item)
980 "Go to node for menu item named (or abbreviated) NAME.
981 Completion is allowed, and the menu item point is on is the default."
983 (let ((completions '())
984 ;; If point is within a menu item, use that item as the default
990 (goto-char (point-min))
991 (if (not (search-forward "\n* menu:" nil t))
992 (error "No menu in this node"))
998 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t)
999 (setq default (format "%s" (buffer-substring
1004 (setq item (let ((completion-ignore-case t)
1005 (Info-complete-menu-buffer (current-buffer)))
1006 (completing-read (if default
1007 (format "Menu item (default %s): "
1010 'Info-complete-menu-item nil t)))
1011 ;; we rely on the fact that completing-read accepts an input
1012 ;; of "" even when the require-match argument is true and ""
1013 ;; is not a valid possibility
1014 (if (string= item "")
1020 ;; there is a problem here in that if several menu items have the same
1021 ;; name you can only go to the node of the first with this command.
1022 (Info-goto-node (Info-extract-menu-item menu-item)))
1024 (defun Info-extract-menu-item (menu-item)
1025 (setq menu-item (regexp-quote menu-item))
1027 (goto-char (point-min))
1028 (or (search-forward "\n* menu:" nil t)
1029 (error "No menu in this node"))
1030 (or (re-search-forward (concat "\n\\* " menu-item ":") nil t)
1031 (re-search-forward (concat "\n\\* " menu-item) nil t)
1032 (error "No such item in menu"))
1035 (Info-extract-menu-node-name)))
1037 ;; If COUNT is nil, use the last item in the menu.
1038 (defun Info-extract-menu-counting (count)
1040 (goto-char (point-min))
1041 (or (search-forward "\n* menu:" nil t)
1042 (error "No menu in this node"))
1044 (or (search-forward "\n* " nil t count)
1045 (error "Too few items in menu"))
1046 (while (search-forward "\n* " nil t)
1048 (Info-extract-menu-node-name)))
1050 (defun Info-nth-menu-item ()
1051 "Go to the node of the Nth menu item.
1052 N is the digit argument used to invoke this command."
1055 (Info-extract-menu-counting
1056 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1058 (defun Info-top-node ()
1059 "Go to the Top node of this file."
1061 (Info-goto-node "Top"))
1063 (defun Info-final-node ()
1064 "Go to the final node in this file."
1066 (Info-goto-node "Top")
1068 ;; Go to the last node in the menu of Top.
1069 (Info-goto-node (Info-extract-menu-counting nil))
1070 ;; If the last node in the menu is not last in pointer structure,
1071 ;; move forward until we can't go any farther.
1072 (while (Info-forward-node t t) nil)
1073 ;; Then keep moving down to last subnode, unless we reach an index.
1074 (while (and (not (string-match "\\<index\\>" Info-current-node))
1075 (save-excursion (search-forward "\n* Menu:" nil t)))
1076 (Info-goto-node (Info-extract-menu-counting nil)))))
1078 (defun Info-forward-node (&optional not-down no-error)
1079 "Go forward one node, considering all nodes as forming one sequence."
1081 (goto-char (point-min))
1083 ;; three possibilities, in order of priority:
1084 ;; 1. next node is in a menu in this node (but not in an index)
1085 ;; 2. next node is next at same level
1086 ;; 3. next node is up and next
1087 (cond ((and (not not-down)
1088 (save-excursion (search-forward "\n* menu:" nil t))
1089 (not (string-match "\\<index\\>" Info-current-node)))
1090 (Info-goto-node (Info-extract-menu-counting 1))
1092 ((save-excursion (search-backward "next:" nil t))
1095 ((and (save-excursion (search-backward "up:" nil t))
1096 ;; Use string-equal, not equal, to ignore text props.
1097 (not (string-equal (downcase (Info-extract-pointer "up"))
1099 (let ((old-node Info-current-node))
1101 (let (Info-history success)
1103 (setq success (Info-forward-node t no-error))
1104 (or success (Info-goto-node old-node))))))
1106 (t (error "No pointer forward from this node"))))
1108 (defun Info-backward-node ()
1109 "Go backward one node, considering all nodes as forming one sequence."
1111 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1112 (upnode (Info-extract-pointer "up" t)))
1113 (cond ((and upnode (string-match "(" upnode))
1114 (error "First node in file"))
1115 ((and upnode (or (null prevnode)
1116 ;; Use string-equal, not equal,
1117 ;; to ignore text properties.
1118 (string-equal (downcase prevnode)
1119 (downcase upnode))))
1122 ;; If we move back at the same level,
1123 ;; go down to find the last subnode*.
1126 (while (and (not (string-match "\\<index\\>" Info-current-node))
1127 (save-excursion (search-forward "\n* Menu:" nil t)))
1128 (Info-goto-node (Info-extract-menu-counting nil)))))
1130 (error "No pointer backward from this node")))))
1133 "Exit Info by selecting some other buffer."
1136 (save-buffers-kill-emacs)
1137 (switch-to-buffer (prog1 (other-buffer (current-buffer))
1138 (bury-buffer (current-buffer))))))
1140 (defun Info-next-menu-item ()
1144 (search-forward "\n* menu:" nil t)
1145 (or (search-forward "\n* " nil t)
1146 (error "No more items in menu"))
1147 (Info-goto-node (Info-extract-menu-node-name))))
1149 (defun Info-last-menu-item ()
1153 (let ((beg (save-excursion
1154 (and (search-backward "\n* menu:" nil t)
1156 (or (and beg (search-backward "\n* " beg t))
1157 (error "No previous items in menu")))
1158 (Info-goto-node (save-excursion
1159 (goto-char (match-end 0))
1160 (Info-extract-menu-node-name)))))
1162 (defmacro Info-no-error (&rest body)
1163 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1165 (defun Info-next-preorder ()
1166 "Go to the next subnode or the next node, or go up a level."
1168 (cond ((Info-no-error (Info-next-menu-item)))
1169 ((Info-no-error (Info-next)))
1170 ((Info-no-error (Info-up))
1171 ;; Since we have already gone thru all the items in this menu,
1172 ;; go up to the end of this node.
1173 (goto-char (point-max)))
1175 (error "No more nodes"))))
1177 (defun Info-last-preorder ()
1178 "Go to the last node, popping up a level if there is none."
1180 (cond ((Info-no-error
1181 (Info-last-menu-item)
1182 ;; If we go down a menu item, go to the end of the node
1183 ;; so we can scroll back through it.
1184 (goto-char (point-max)))
1186 ((Info-no-error (Info-prev))
1187 (goto-char (point-max))
1189 ((Info-no-error (Info-up))
1190 (goto-char (point-min))
1191 (or (search-forward "\n* Menu:" nil t)
1192 (goto-char (point-max))))
1193 (t (error "No previous nodes"))))
1195 (defun Info-scroll-up ()
1196 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1197 Once you scroll far enough in a node that its menu appears on the screen,
1198 the next scroll moves into its first subnode. When you scroll past
1199 the end of a node, that goes to the next node or back up to the parent node."
1201 (if (or (< (window-start) (point-min))
1202 (> (window-start) (point-max)))
1203 (set-window-start (selected-window) (point)))
1204 (let ((virtual-end (save-excursion
1205 (goto-char (point-min))
1206 (if (search-forward "\n* Menu:" nil t)
1209 (if (or (< virtual-end (window-start))
1210 (pos-visible-in-window-p virtual-end))
1211 (Info-next-preorder)
1214 (defun Info-scroll-down ()
1215 "Scroll one screenful back in Info, considering all nodes as one sequence.
1216 Within the menu of a node, this goes to its last subnode.
1217 When you scroll past the beginning of a node, that goes to the
1218 previous node or back up to the parent node."
1220 (if (or (< (window-start) (point-min))
1221 (> (window-start) (point-max)))
1222 (set-window-start (selected-window) (point)))
1223 (let ((virtual-end (save-excursion
1224 (goto-char (point-min))
1225 (search-forward "\n* Menu:" nil t))))
1226 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1227 (Info-last-preorder)
1230 (defun Info-next-reference ()
1231 "Move cursor to the next cross-reference or menu item in the node."
1233 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1235 (or (eobp) (forward-char 1))
1236 (or (re-search-forward pat nil t)
1238 (goto-char (point-min))
1239 (or (re-search-forward pat nil t)
1242 (error "No cross references in this node")))))
1243 (goto-char (match-beginning 0))
1244 (if (looking-at "\\* Menu:")
1245 (Info-next-reference))))
1247 (defun Info-prev-reference ()
1248 "Move cursor to the previous cross-reference or menu item in the node."
1250 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1252 (or (re-search-backward pat nil t)
1254 (goto-char (point-max))
1255 (or (re-search-backward pat nil t)
1258 (error "No cross references in this node")))))
1259 (goto-char (match-beginning 0))
1260 (if (looking-at "\\* Menu:")
1261 (Info-prev-reference))))
1263 (defun Info-index (topic)
1264 "Look up a string in the index for this file.
1265 The index is defined as the first node in the top-level menu whose
1266 name contains the word \"Index\", plus any immediately following
1267 nodes whose names also contain the word \"Index\".
1268 If there are no exact matches to the specified topic, this chooses
1269 the first match which is a case-insensitive substring of a topic.
1270 Use the `,' command to see the other matches.
1271 Give a blank topic name to go to the Index node itself."
1272 (interactive "sIndex topic: ")
1273 (let ((orignode Info-current-node)
1275 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1276 (regexp-quote topic)))
1278 (Info-goto-node "Top")
1279 (or (search-forward "\n* menu:" nil t)
1281 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1283 (goto-char (match-beginning 1))
1284 ;; Here, and subsequently in this function,
1285 ;; we bind Info-history to nil for internal node-switches
1286 ;; so that we don't put junk in the history.
1287 ;; In the first Info-goto-node call, above, we do update the history
1288 ;; because that is what the user's previous node choice into it.
1289 (let ((Info-history nil))
1290 (Info-goto-node (Info-extract-menu-node-name)))
1291 (or (equal topic "")
1298 (goto-char (point-min))
1299 (while (re-search-forward pattern nil t)
1301 (cons (list (buffer-substring (match-beginning 1)
1303 (buffer-substring (match-beginning 2)
1306 (string-to-int (concat "0"
1311 (and (setq node (Info-extract-pointer "next" t))
1312 (string-match "\\<Index\\>" node)))
1313 (Info-goto-node node))
1317 (error "No \"%s\" in index" topic)))
1318 ;; Here it is a feature that assoc is case-sensitive.
1319 (while (setq found (assoc topic matches))
1320 (setq exact (cons found exact)
1321 matches (delq found matches)))
1322 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1323 (Info-index-next 0)))))
1325 (defun Info-index-next (num)
1326 "Go to the next matching index item from the last `i' command."
1328 (or Info-index-alternatives
1329 (error "No previous `i' command in this file"))
1331 (setq num (+ num (length Info-index-alternatives))))
1333 (setq Info-index-alternatives
1334 (nconc (cdr Info-index-alternatives)
1335 (list (car Info-index-alternatives)))
1337 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1338 (if (> (nth 3 (car Info-index-alternatives)) 0)
1339 (forward-line (nth 3 (car Info-index-alternatives)))
1340 (forward-line 3) ; don't search in headers
1341 (let ((name (car (car Info-index-alternatives))))
1342 (if (or (re-search-forward (format
1343 "\\(Function\\|Command\\): %s\\( \\|$\\)"
1344 (regexp-quote name)) nil t)
1345 (search-forward (format "`%s'" name) nil t)
1346 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1348 (format "`%s'" (substring name 0 (match-beginning 1)))
1350 (search-forward name nil t))
1352 (goto-char (point-min)))))
1353 (message "Found \"%s\" in %s. %s"
1354 (car (car Info-index-alternatives))
1355 (nth 2 (car Info-index-alternatives))
1356 (if (cdr Info-index-alternatives)
1357 "(Press `,' for more)"
1360 (defun Info-undefined ()
1361 "Make command be undefined in Info."
1366 "Enter the Info tutorial."
1368 (delete-other-windows)
1369 (Info-find-node "info"
1370 (if (< (window-height) 23)
1374 (defun Info-summary ()
1375 "Display a brief summary of all Info commands."
1377 (save-window-excursion
1378 (switch-to-buffer "*Help*")
1380 (insert (documentation 'Info-mode))
1382 (goto-char (point-min))
1384 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1385 (message (if flag "Type Space to see more"
1386 "Type Space to return to Info"))
1387 (if (not (eq ?\ (setq ch (read-event))))
1388 (progn (setq unread-command-events (list ch)) nil)
1391 (bury-buffer "*Help*")))
1393 (defun Info-get-token (pos start all &optional errorstring)
1394 "Return the token around POS,
1395 POS must be somewhere inside the token
1396 START is a regular expression which will match the
1397 beginning of the tokens delimited string
1398 ALL is a regular expression with a single
1399 parenthized subpattern which is the token to be
1400 returned. E.g. '{\(.*\)}' would return any string
1401 enclosed in braces around POS.
1402 SIG optional fourth argument, controls action on no match
1405 a string: signal an error, using that string."
1408 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
1410 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1411 (not (setq found (and (<= (match-beginning 0) pos)
1412 (> (match-end 0) pos))))))
1413 (if (and found (<= (match-beginning 0) pos)
1414 (> (match-end 0) pos))
1415 (buffer-substring (match-beginning 1) (match-end 1))
1416 (cond ((null errorstring)
1422 (error "No %s around position %d" errorstring pos)))))))
1424 (defun Info-mouse-follow-nearest-node (click)
1425 "\\<Info-mode-map>Follow a node reference near point.
1426 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1427 At end of the node's text, moves to the next node, or up if none."
1429 (let* ((start (event-start click))
1430 (window (car start))
1431 (pos (car (cdr start))))
1432 (select-window window)
1434 (and (not (Info-try-follow-nearest-node))
1435 (save-excursion (forward-line 1) (eobp))
1436 (Info-next-preorder)))
1438 (defun Info-follow-nearest-node ()
1439 "\\<Info-mode-map>Follow a node reference near point.
1440 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1441 If no reference to follow, moves to the next node, or up if none."
1443 (or (Info-try-follow-nearest-node)
1444 (Info-next-preorder)))
1446 ;; Common subroutine.
1447 (defun Info-try-follow-nearest-node ()
1448 "Follow a node reference near point. Return non-nil if successful."
1451 ((setq node (Info-get-token (point) "\\*note[ \n]"
1452 "\\*note[ \n]\\([^:]*\\):"))
1453 (Info-follow-reference node))
1454 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1455 (Info-goto-node node))
1456 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1458 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1459 (Info-goto-node node))
1460 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1461 (Info-goto-node node))
1462 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1463 (Info-goto-node "Top"))
1464 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1465 (Info-goto-node node)))
1468 (defvar Info-mode-map nil
1469 "Keymap containing Info commands.")
1472 (setq Info-mode-map (make-keymap))
1473 (suppress-keymap Info-mode-map)
1474 (define-key Info-mode-map "." 'beginning-of-buffer)
1475 (define-key Info-mode-map " " 'Info-scroll-up)
1476 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1477 (define-key Info-mode-map "\t" 'Info-next-reference)
1478 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1479 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1480 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1481 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1482 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1483 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1484 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1485 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1486 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1487 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1488 (define-key Info-mode-map "0" 'undefined)
1489 (define-key Info-mode-map "?" 'Info-summary)
1490 (define-key Info-mode-map "]" 'Info-forward-node)
1491 (define-key Info-mode-map "[" 'Info-backward-node)
1492 (define-key Info-mode-map "<" 'Info-top-node)
1493 (define-key Info-mode-map ">" 'Info-final-node)
1494 (define-key Info-mode-map "b" 'beginning-of-buffer)
1495 (define-key Info-mode-map "d" 'Info-directory)
1496 (define-key Info-mode-map "e" 'Info-edit)
1497 (define-key Info-mode-map "f" 'Info-follow-reference)
1498 (define-key Info-mode-map "g" 'Info-goto-node)
1499 (define-key Info-mode-map "h" 'Info-help)
1500 (define-key Info-mode-map "i" 'Info-index)
1501 (define-key Info-mode-map "l" 'Info-last)
1502 (define-key Info-mode-map "m" 'Info-menu)
1503 (define-key Info-mode-map "n" 'Info-next)
1504 (define-key Info-mode-map "p" 'Info-prev)
1505 (define-key Info-mode-map "q" 'Info-exit)
1506 (define-key Info-mode-map "s" 'Info-search)
1507 ;; For consistency with Rmail.
1508 (define-key Info-mode-map "\M-s" 'Info-search)
1509 (define-key Info-mode-map "t" 'Info-top-node)
1510 (define-key Info-mode-map "u" 'Info-up)
1511 (define-key Info-mode-map "," 'Info-index-next)
1512 (define-key Info-mode-map "\177" 'Info-scroll-down)
1513 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1516 ;; Info mode is suitable only for specially formatted data.
1517 (put 'info-mode 'mode-class 'special)
1521 Info mode provides commands for browsing through the Info documentation tree.
1522 Documentation in Info is divided into \"nodes\", each of which discusses
1523 one topic and contains references to other nodes which discuss related
1524 topics. Info has commands to follow the references and show you other nodes.
1526 \\[Info-help] Invoke the Info tutorial.
1528 Selecting other nodes:
1529 \\[Info-mouse-follow-nearest-node]
1530 Follow a node reference you click on.
1531 This works with menu items, cross references, and
1532 the \"next\", \"previous\" and \"up\", depending on where you click.
1533 \\[Info-next] Move to the \"next\" node of this node.
1534 \\[Info-prev] Move to the \"previous\" node of this node.
1535 \\[Info-up] Move \"up\" from this node.
1536 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1537 Picking a menu item causes another node to be selected.
1538 \\[Info-directory] Go to the Info directory node.
1539 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1540 \\[Info-last] Move to the last node you were at.
1541 \\[Info-index] Look up a topic in this file's Index and move to that node.
1542 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1544 Moving within a node:
1545 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1546 already visible, try to go to the next menu entry, or up if there is none.
1547 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1548 already visible, try to go to the previous menu entry, or up if there is none.
1549 \\[beginning-of-buffer] Go to beginning of node.
1552 \\[Info-exit] Quit Info: reselect previously selected buffer.
1553 \\[Info-edit] Edit contents of selected node.
1554 1 Pick first item in node's menu.
1555 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1556 \\[Info-goto-node] Move to node specified by name.
1557 You may include a filename as well, as (FILENAME)NODENAME.
1558 \\[universal-argument] \\[info] Move to new Info file with completion.
1559 \\[Info-search] Search through this Info file for specified regexp,
1560 and select the node in which the next occurrence is found.
1561 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1562 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1563 (kill-all-local-variables)
1564 (setq major-mode 'Info-mode)
1565 (setq mode-name "Info")
1566 (use-local-map Info-mode-map)
1567 (set-syntax-table text-mode-syntax-table)
1568 (setq local-abbrev-table text-mode-abbrev-table)
1569 (setq case-fold-search t)
1570 (setq buffer-read-only t)
1571 (make-local-variable 'Info-current-file)
1572 (make-local-variable 'Info-current-subfile)
1573 (make-local-variable 'Info-current-node)
1574 (make-local-variable 'Info-tag-table-marker)
1575 (make-local-variable 'Info-history)
1576 (make-local-variable 'Info-index-alternatives)
1577 (if (memq (framep (selected-frame)) '(x pc))
1579 (make-face 'info-node)
1580 (make-face 'info-menu-5)
1581 (make-face 'info-xref)
1582 (or (face-differs-from-default-p 'info-node)
1583 (if (face-differs-from-default-p 'bold-italic)
1584 (copy-face 'bold-italic 'info-node)
1585 (copy-face 'bold 'info-node)))
1586 (or (face-differs-from-default-p 'info-menu-5)
1587 (set-face-underline-p 'info-menu-5 t))
1588 (or (face-differs-from-default-p 'info-xref)
1589 (copy-face 'bold 'info-xref)))
1590 (setq Info-fontify nil))
1591 (Info-set-mode-line)
1592 (run-hooks 'Info-mode-hook))
1594 (defvar Info-edit-map nil
1595 "Local keymap used within `e' command of Info.")
1598 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
1599 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
1601 ;; Info-edit mode is suitable only for specially formatted data.
1602 (put 'info-edit-mode 'mode-class 'special)
1604 (defun Info-edit-mode ()
1605 "Major mode for editing the contents of an Info node.
1606 Like text mode with the addition of `Info-cease-edit'
1607 which returns to Info mode for browsing.
1609 (use-local-map Info-edit-map)
1610 (setq major-mode 'Info-edit-mode)
1611 (setq mode-name "Info Edit")
1612 (kill-local-variable 'mode-line-buffer-identification)
1613 (setq buffer-read-only nil)
1614 (force-mode-line-update)
1615 (buffer-enable-undo (current-buffer))
1616 (run-hooks 'Info-edit-mode-hook))
1619 "Edit the contents of this Info node.
1620 Allowed only if variable `Info-enable-edit' is non-nil."
1622 (or Info-enable-edit
1623 (error "Editing info nodes is not enabled"))
1625 (message (substitute-command-keys
1626 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1628 (defun Info-cease-edit ()
1629 "Finish editing Info node; switch back to Info proper."
1631 ;; Do this first, so nothing has changed if user C-g's at query.
1632 (and (buffer-modified-p)
1633 (y-or-n-p "Save the file? ")
1635 (use-local-map Info-mode-map)
1636 (setq major-mode 'Info-mode)
1637 (setq mode-name "Info")
1638 (Info-set-mode-line)
1639 (setq buffer-read-only t)
1640 (force-mode-line-update)
1641 (and (marker-position Info-tag-table-marker)
1643 (message "Tags may have changed. Use Info-tagify if necessary")))
1645 (defvar Info-file-list-for-emacs
1646 '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc")
1647 "List of Info files that describe Emacs commands.
1648 An element can be a file name, or a list of the form (PREFIX . FILE)
1649 where PREFIX is a name prefix and FILE is the file to look in.
1650 If the element is just a file name, the file name also serves as the prefix.")
1652 (defun Info-find-emacs-command-nodes (command)
1653 "Return a list of locations documenting COMMAND.
1654 The `info-file' property of COMMAND says which Info manual to search.
1655 If COMMAND has no property, the variable `Info-file-list-for-emacs'
1656 defines heuristics for which Info manual to try.
1657 The locations are of the format used in Info-history, i.e.
1658 \(FILENAME NODENAME BUFFERPOS\)."
1660 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
1661 ":\\s *\\(.*\\)\\.$"))
1662 (info-file "emacs")) ;default
1663 ;; Determine which info file this command is documented in.
1664 (if (get command 'info-file)
1665 (setq info-file (get command 'info-file))
1666 ;; If it doesn't say explicitly, test its name against
1667 ;; various prefixes that we know.
1668 (let ((file-list Info-file-list-for-emacs))
1670 (let* ((elt (car file-list))
1671 (name (if (consp elt)
1674 (file (if (consp elt) (cdr elt) elt))
1675 (regexp (concat "\\`" (regexp-quote name)
1677 (if (string-match regexp (symbol-name command))
1678 (setq info-file file file-list nil))
1679 (setq file-list (cdr file-list))))))
1682 (Info-find-node info-file "Command Index")
1683 ;; Some manuals may not have a separate Command Index node,
1684 ;; so try just Index instead.
1686 (Info-find-node info-file "Index")))
1687 ;; Take the index node off the Info history.
1688 (setq Info-history (cdr Info-history))
1689 (goto-char (point-max))
1690 (while (re-search-backward cmd-desc nil t)
1691 (setq where (cons (list Info-current-file
1700 (defun Info-goto-emacs-command-node (command)
1701 "Go to the Info node in the Emacs manual for command COMMAND.
1702 The command is found by looking up in Emacs manual's Command Index
1703 or in another manual found via COMMAND's `info-file' property or
1704 the variable `Info-file-list-for-emacs'."
1705 (interactive "CFind documentation for command: ")
1706 (or (commandp command)
1707 (signal 'wrong-type-argument (list 'commandp command)))
1708 (let ((where (Info-find-emacs-command-nodes command)))
1710 (let ((num-matches (length where)))
1711 ;; Get Info running, and pop to it in another window.
1712 (save-window-excursion
1714 (pop-to-buffer "*info*")
1715 (Info-find-node (car (car where))
1716 (car (cdr (car where))))
1717 (if (> num-matches 1)
1719 ;; Info-find-node already pushed (car where) onto
1720 ;; Info-history. Put the other nodes that were found on
1722 (setq Info-history (nconc (cdr where) Info-history))
1723 (message (substitute-command-keys
1724 "Found %d other entr%s. Use \\[Info-last] to see %s.")
1726 (if (> num-matches 2) "ies" "y")
1727 (if (> num-matches 2) "them" "it")))))
1728 (error "Couldn't find documentation for %s." command))))
1731 (defun Info-goto-emacs-key-command-node (key)
1732 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1733 Interactively, if the binding is execute-extended-command, a command is read.
1734 The command is found by looking up in Emacs manual's Command Index
1735 or in another manual found via COMMAND's `info-file' property or
1736 the variable `Info-file-list-for-emacs'."
1737 (interactive "kFind documentation for key:")
1738 (let ((command (key-binding key)))
1739 (cond ((null command)
1740 (message "%s is undefined" (key-description key)))
1741 ((and (interactive-p)
1742 (eq command 'execute-extended-command))
1743 (Info-goto-emacs-command-node
1744 (read-command "Find documentation for command: ")))
1746 (Info-goto-emacs-command-node command)))))
1748 (defun Info-fontify-node ()
1750 (let ((buffer-read-only nil))
1751 (goto-char (point-min))
1752 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1754 (goto-char (match-end 0))
1756 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1757 (goto-char (match-end 0))
1758 (put-text-property (match-beginning 1) (match-end 1)
1760 (put-text-property (match-beginning 1) (match-end 1)
1761 'mouse-face 'highlight))))
1762 (goto-char (point-min))
1763 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
1764 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
1766 (put-text-property (match-beginning 1) (match-end 1)
1768 (put-text-property (match-beginning 1) (match-end 1)
1769 'mouse-face 'highlight)))
1770 (goto-char (point-min))
1771 (if (and (search-forward "\n* Menu:" nil t)
1772 (not (string-match "\\<Index\\>" Info-current-node))
1773 ;; Don't take time to annotate huge menus
1774 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
1776 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t)
1778 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
1779 (put-text-property (match-beginning 0)
1780 (1+ (match-beginning 0))
1781 'face 'info-menu-5))
1782 (put-text-property (match-beginning 1) (match-end 1)
1784 (put-text-property (match-beginning 1) (match-end 1)
1785 'mouse-face 'highlight))))
1786 (set-buffer-modified-p nil))))
1790 ;;; info.el ends here