1 ;;; info.el --- info package for Emacs.
4 ;; Last-Modified: 30 Jun 1992
7 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
27 ;;; Note that nowadays we expect info files to be made using makeinfo.
31 (defvar Info-history nil
32 "List of info nodes user has visited.
33 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
35 (defvar Info-enable-edit nil
36 "*Non-nil means the \\<info-mode-map>\\[Info-edit] command in Info can edit the current node.
37 This is convenient if you want to write info files by hand.
38 However, we recommend that you not do this.
39 It is better to write a Texinfo file and generate the Info file from that,
40 because that gives you a printed manual as well.")
42 (defvar Info-enable-active-nodes t
43 "Non-nil allows Info to execute Lisp code associated with nodes.
44 The Lisp code is executed when the node is selected.")
46 (defvar Info-default-directory-list nil
47 "List of default directories to search for Info documentation files.
48 This value is used as the default for `Info-directory-list'. It is set
51 (defvar Info-directory-list nil
52 "List of directories to search for Info documentation files.
53 nil means not yet initialized. In this case, Info uses the environment
54 variable INFODIR to initialize it, or `Info-default-directory-list'
55 if there is no INFODIR variable in the environment.")
57 (defvar Info-current-file nil
58 "Info file that Info is now looking at, or nil.")
60 (defvar Info-current-subfile nil
61 "Info subfile that is actually in the *info* buffer now,
62 or nil if current info file is not split into subfiles.")
64 (defvar Info-current-node nil
65 "Name of node that Info is now looking at, or nil.")
67 (defvar Info-tag-table-marker (make-marker)
68 "Marker pointing at beginning of current Info file's tag table.
69 Marker points nowhere if file has no tag table.")
72 (defun info (&optional file)
73 "Enter Info, the documentation browser.
74 Optional argument FILE specifies the file to examine;
75 the default is the top-level directory of Info.
77 In interactive use, a prefix argument directs this command
78 to read a file name from the minibuffer."
79 (interactive (if current-prefix-arg
80 (list (read-file-name "Info file name: " nil nil t))))
81 (or Info-directory-list
82 (setq Info-directory-list
83 (let ((path (getenv "INFOPATH")))
87 (while (> (length path) 0)
88 (setq idx (or (string-match ":" path) (length path))
89 list (cons (substring path 0 idx) list)
90 path (substring path (min (1+ idx)
93 Info-default-directory-list))))
95 (Info-goto-node (concat "(" file ")"))
96 (if (get-buffer "*info*")
97 (switch-to-buffer "*info*")
100 ;; Go to an info node specified as separate filename and nodename.
101 ;; no-going-back is non-nil if recovering from an error in this function;
102 ;; it says do not attempt further (recursive) error recovery.
103 (defun Info-find-node (filename nodename &optional no-going-back)
104 ;; Convert filename to lower case if not found as specified.
107 (let (temp temp-downcase found)
108 (setq filename (substitute-in-file-name filename))
109 (let ((dirs (if (string-match "^\\./" filename)
110 ;; If specified name starts with `./'
111 ;; then just try current directory.
113 Info-directory-list)))
114 ;; Search the directory list for file FILENAME.
115 (while (and dirs (not found))
116 (setq temp (expand-file-name filename (car dirs)))
118 (expand-file-name (downcase filename) (car dirs)))
119 ;; Try several variants of specified name.
120 ;; Try downcasing, appending `.info', or both.
121 (cond ((file-exists-p temp)
123 ((file-exists-p temp-downcase)
124 (setq found temp-downcase))
125 ((file-exists-p (concat temp ".info"))
126 (setq found (concat temp ".info")))
127 ((file-exists-p (concat temp-downcase ".info"))
128 (setq found (concat temp-downcase ".info"))))
129 (setq dirs (cdr dirs))))
131 (setq filename found)
132 (error "Info file %s does not exist" filename))))
133 ;; Record the node we are leaving.
134 (if (and Info-current-file (not no-going-back))
136 (cons (list Info-current-file Info-current-node (point))
138 ;; Go into info buffer.
139 (switch-to-buffer "*info*")
140 (buffer-flush-undo (current-buffer))
141 (or (eq major-mode 'Info-mode)
144 (setq Info-current-node nil)
147 ;; Switch files if necessary
149 (equal Info-current-file filename)
150 (let ((buffer-read-only nil))
151 (setq Info-current-file nil
152 Info-current-subfile nil
153 buffer-file-name nil)
155 (insert-file-contents filename t)
156 (set-buffer-modified-p nil)
157 (setq default-directory (file-name-directory filename))
158 ;; See whether file has a tag table. Record the location if yes.
159 (set-marker Info-tag-table-marker nil)
160 (goto-char (point-max))
162 (or (equal nodename "*")
163 (not (search-forward "\^_\nEnd tag table\n" nil t))
165 ;; We have a tag table. Find its beginning.
166 ;; Is this an indirect file?
167 (search-backward "\nTag table:\n")
171 (looking-at "(Indirect)\n"))
172 ;; It is indirect. Copy it to another buffer
173 ;; and record that the tag table is in that buffer.
175 (let ((buf (current-buffer)))
176 (set-buffer (get-buffer-create " *info tag table*"))
177 (buffer-flush-undo (current-buffer))
178 (setq case-fold-search t)
180 (insert-buffer-substring buf)
181 (set-marker Info-tag-table-marker
183 (set-marker Info-tag-table-marker pos))))
184 (setq Info-current-file
185 (file-name-sans-versions buffer-file-name))))
186 (if (equal nodename "*")
187 (progn (setq Info-current-node nodename)
188 (Info-set-mode-line))
189 ;; Search file for a suitable node.
190 ;; First get advice from tag table if file has one.
191 ;; Also, if this is an indirect info file,
192 ;; read the proper subfile into this buffer.
193 (let ((guesspos (point-min)))
194 (if (marker-position Info-tag-table-marker)
196 (set-buffer (marker-buffer Info-tag-table-marker))
197 (goto-char Info-tag-table-marker)
198 (if (search-forward (concat "Node: " nodename "\177") nil t)
200 (setq guesspos (read (current-buffer)))
201 ;; If this is an indirect file,
202 ;; determine which file really holds this node
204 (if (not (eq (current-buffer) (get-buffer "*info*")))
206 (Info-read-subfile guesspos))))
207 (error "No such node: \"%s\"" nodename))))
208 (goto-char (max (point-min) (- guesspos 1000))))
209 ;; Now search from our advised position (or from beg of buffer)
210 ;; to find the actual node.
211 (let ((regexp (concat "Node: *" (regexp-quote nodename) " *[,\t\n]")))
213 (while (search-forward "\n\^_" nil t)
217 (if (re-search-backward regexp beg t)
219 (error "No such node: %s" nodename)))
221 ;; If we did not finish finding the specified node,
222 ;; go back to the previous one.
223 (or Info-current-node no-going-back
224 (let ((hist (car Info-history)))
225 (setq Info-history (cdr Info-history))
226 (Info-find-node (nth 0 hist) (nth 1 hist) t)
227 (goto-char (nth 2 hist)))))
228 (goto-char (point-min)))
230 (defun Info-read-subfile (nodepos)
231 (set-buffer (marker-buffer Info-tag-table-marker))
232 (goto-char (point-min))
233 (search-forward "\n\^_")
238 (while (not (looking-at "\^_"))
241 thisfilepos thisfilename)
242 (search-forward ": ")
243 (setq thisfilename (buffer-substring beg (- (point) 2)))
244 (setq thisfilepos (read (current-buffer)))
245 ;; read in version 19 stops at the end of number.
246 ;; Advance to the next line.
248 (if (> thisfilepos nodepos)
250 (setq lastfilename thisfilename)
251 (setq lastfilepos thisfilepos))
253 (set-buffer (get-buffer "*info*"))
254 (or (equal Info-current-subfile lastfilename)
255 (let ((buffer-read-only nil))
256 (setq buffer-file-name nil)
259 (insert-file-contents lastfilename)
260 (set-buffer-modified-p nil)
261 (setq Info-current-subfile lastfilename)))
262 (goto-char (point-min))
263 (search-forward "\n\^_")
264 (+ (- nodepos lastfilepos) (point))))
266 ;; Select the info node that point is in.
267 (defun Info-select-node ()
269 ;; Find beginning of node.
270 (search-backward "\n\^_")
272 ;; Get nodename spelled as it is in the node.
273 (re-search-forward "Node:[ \t]*")
274 (setq Info-current-node
275 (buffer-substring (point)
277 (skip-chars-forward "^,\t\n")
280 ;; Find the end of it, and narrow.
282 (let (active-expression)
283 (narrow-to-region (point)
284 (if (re-search-forward "\n[\^_\f]" nil t)
287 (if (looking-at "[\n\^_\f]*execute: ")
289 (goto-char (match-end 0))
290 (setq active-expression
291 (read (current-buffer))))))
293 (if Info-enable-active-nodes (eval active-expression)))))
295 (defun Info-set-mode-line ()
296 (setq mode-line-buffer-identification
299 (if Info-current-file
300 (file-name-nondirectory Info-current-file)
303 (or Info-current-node ""))))
305 ;; Go to an info node specified with a filename-and-nodename string
306 ;; of the sort that is found in pointers in nodes.
308 (defun Info-goto-node (nodename)
309 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
310 (interactive "sGoto node: ")
312 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
314 (setq filename (if (= (match-beginning 1) (match-end 1))
316 (substring nodename (match-beginning 2) (match-end 2)))
317 nodename (substring nodename (match-beginning 3) (match-end 3)))
318 (let ((trim (string-match "\\s *\\'" filename)))
319 (if trim (setq filename (substring filename 0 trim))))
320 (let ((trim (string-match "\\s *\\'" nodename)))
321 (if trim (setq nodename (substring nodename 0 trim))))
322 (Info-find-node (if (equal filename "") nil filename)
323 (if (equal nodename "") "Top" nodename))))
325 (defun Info-restore-point (hl)
326 "If this node has been visited, restore the point value when we left."
328 (if (and (equal (nth 0 (car hl)) Info-current-file)
329 (equal (nth 1 (car hl)) Info-current-node))
330 (goto-char (nth 2 (car hl)))
331 (Info-restore-point (cdr hl)))))
333 (defvar Info-last-search nil
334 "Default regexp for \\<info-mode-map>\\[Info-search] command to search for.")
336 (defun Info-search (regexp)
337 "Search for REGEXP, starting from point, and select node it's found in."
338 (interactive "sSearch (regexp): ")
339 (if (equal regexp "")
340 (setq regexp Info-last-search)
341 (setq Info-last-search regexp))
342 (let ((found ()) current
343 (onode Info-current-node)
344 (ofile Info-current-file)
346 (osubfile Info-current-subfile))
350 (if (null Info-current-subfile)
351 (progn (re-search-forward regexp) (setq found (point)))
353 (progn (re-search-forward regexp) (setq found (point)))
354 (search-failed nil)))))
355 (if (not found) ;can only happen in subfile case -- else would have erred
358 (set-buffer (marker-buffer Info-tag-table-marker))
359 (goto-char (point-min))
360 (search-forward "\n\^_\nIndirect:")
362 (narrow-to-region (point)
363 (progn (search-forward "\n\^_")
365 (goto-char (point-min))
366 (search-forward (concat "\n" osubfile ": "))
369 (re-search-forward "\\(^.*\\): [0-9]+$")
370 (goto-char (+ (match-end 1) 2))
371 (setq list (cons (cons (read (current-buffer))
372 (buffer-substring (match-beginning 1)
375 (goto-char (1+ (match-end 0))))
376 (setq list (nreverse list)
377 current (car (car list))
380 (message "Searching subfile %s..." (cdr (car list)))
381 (Info-read-subfile (car (car list)))
382 (setq list (cdr list))
383 (goto-char (point-min))
384 (if (re-search-forward regexp nil t)
385 (setq found (point) list ())))
388 (signal 'search-failed (list regexp))))
390 (progn (Info-read-subfile opoint)
392 (Info-select-node)))))
396 (or (and (equal onode Info-current-node)
397 (equal ofile Info-current-file))
398 (setq Info-history (cons (list ofile onode opoint)
401 ;; Extract the value of the node-pointer named NAME.
402 ;; If there is none, use ERRORNAME in the error message;
403 ;; if ERRORNAME is nil, just return nil.
404 (defun Info-extract-pointer (name &optional errorname)
406 (goto-char (point-min))
408 (if (re-search-backward (concat name ":") nil t)
410 (goto-char (match-end 0))
411 (Info-following-node-name))
414 (error (concat "Node has no " (capitalize (or errorname name))))))))
416 (defun Info-following-node-name (&optional allowedchars)
417 (skip-chars-forward " \t")
421 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
422 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
424 (skip-chars-forward "^)")))
425 (skip-chars-backward " ")
429 "Go to the next node of this node."
431 (Info-goto-node (Info-extract-pointer "next")))
434 "Go to the previous node of this node."
436 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
439 "Go to the superior node of this node."
441 (Info-goto-node (Info-extract-pointer "up"))
442 (Info-restore-point Info-history))
445 "Go back to the last node visited."
448 (error "This is the first Info node you looked at"))
449 (let (filename nodename opoint)
450 (setq filename (car (car Info-history)))
451 (setq nodename (car (cdr (car Info-history))))
452 (setq opoint (car (cdr (cdr (car Info-history)))))
453 (setq Info-history (cdr Info-history))
454 (Info-find-node filename nodename)
455 (setq Info-history (cdr Info-history))
458 (defun Info-directory ()
459 "Go to the Info directory node."
461 (Info-find-node "dir" "top"))
463 (defun Info-follow-reference (footnotename)
464 "Follow cross reference named NAME to the node it refers to.
465 NAME may be an abbreviation of the reference name."
467 (let ((completion-ignore-case t)
468 completions default (start-point (point)) str i)
470 (goto-char (point-min))
471 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
472 (setq str (buffer-substring
475 ;; See if this one should be the default.
477 (< (match-beginning 0) start-point)
478 (<= start-point (point))
481 (while (setq i (string-match "[ \n\t]+" str i))
482 (setq str (concat (substring str 0 i) " "
483 (substring str (match-end 0))))
485 ;; Record as a completion and perhaps as default.
486 (if (eq default t) (setq default str))
491 (list (completing-read (if default
492 (concat "Follow reference named: ("
494 "Follow reference named: ")
495 completions default t))
496 (error "No cross-references in this node"))))
497 (let (target beg i (str (concat "\\*note " footnotename)))
498 (while (setq i (string-match " " str i))
499 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
502 (goto-char (point-min))
503 (or (re-search-forward str nil t)
504 (error "No cross-reference named %s" footnotename))
505 (goto-char (+ (match-beginning 0) 5))
507 (Info-extract-menu-node-name "Bad format cross reference" t)))
508 (while (setq i (string-match "[ \t\n]+" target i))
509 (setq target (concat (substring target 0 i) " "
510 (substring target (match-end 0))))
512 (Info-goto-node target)))
514 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
515 (skip-chars-forward " \t\n")
518 (skip-chars-forward "^:")
522 (buffer-substring beg (1- (point)))
523 (skip-chars-forward " \t\n")
524 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
525 (while (setq i (string-match "\n" str i))
529 (defun Info-menu-item-sequence (list)
531 (Info-menu-item (car list))
532 (setq list (cdr list))))
534 (defun Info-menu (menu-item)
535 "Go to node for menu item named (or abbreviated) NAME.
536 Completion is allowed, and the menu item point is on is the default."
538 (let ((completions '())
539 ;; If point is within a menu item, use that item as the default
544 (goto-char (point-min))
545 (if (not (search-forward "\n* menu:" nil t))
546 (error "No menu in this node"))
547 (while (re-search-forward
548 "\n\\* \\([^:\t\n]*\\):" nil t)
549 (if (and (null default)
550 (prog1 (if last (< last p) nil)
551 (setq last (match-beginning 0)))
553 (setq default (car (car completions))))
554 (setq completions (cons (cons (buffer-substring
559 (if (and (null default) last
561 (<= p (progn (end-of-line) (point))))
562 (setq default (car (car completions)))))
565 (setq item (let ((completion-ignore-case t))
566 (completing-read (if default
567 (format "Menu item (default %s): "
571 ;; we rely on the fact that completing-read accepts an input
572 ;; of "" even when the require-match argument is true and ""
573 ;; is not a valid possibility
574 (if (string= item "")
580 ;; there is a problem here in that if several menu items have the same
581 ;; name you can only go to the node of the first with this command.
582 (Info-goto-node (Info-extract-menu-item menu-item)))
584 (defun Info-extract-menu-item (menu-item)
585 (setq menu-item (regexp-quote menu-item))
587 (goto-char (point-min))
588 (or (search-forward "\n* menu:" nil t)
589 (error "No menu in this node"))
590 (or (re-search-forward (concat "\n* " menu-item ":") nil t)
591 (re-search-forward (concat "\n* " menu-item) nil t)
592 (error "No such item in menu"))
595 (Info-extract-menu-node-name)))
597 ;; If COUNT is nil, use the last item in the menu.
598 (defun Info-extract-menu-counting (count)
600 (goto-char (point-min))
601 (or (search-forward "\n* menu:" nil t)
602 (error "No menu in this node"))
604 (or (search-forward "\n* " nil t count)
605 (error "Too few items in menu"))
606 (while (search-forward "\n* " nil t)
608 (Info-extract-menu-node-name)))
610 (defun Info-first-menu-item ()
611 "Go to the node of the first menu item."
613 (Info-goto-node (Info-extract-menu-counting 1)))
615 (defun Info-second-menu-item ()
616 "Go to the node of the second menu item."
618 (Info-goto-node (Info-extract-menu-counting 2)))
620 (defun Info-third-menu-item ()
621 "Go to the node of the third menu item."
623 (Info-goto-node (Info-extract-menu-counting 3)))
625 (defun Info-fourth-menu-item ()
626 "Go to the node of the fourth menu item."
628 (Info-goto-node (Info-extract-menu-counting 4)))
630 (defun Info-fifth-menu-item ()
631 "Go to the node of the fifth menu item."
633 (Info-goto-node (Info-extract-menu-counting 5)))
635 (defun Info-top-node ()
636 "Go to the Top node of this file."
638 (Info-goto-node "Top"))
640 (defun Info-final-node ()
641 "Go to the final node in this file."
643 (Info-goto-node "Top")
645 ;; Go to the last node in the menu of Top.
646 (Info-goto-node (Info-extract-menu-counting nil))
647 ;; If the last node in the menu is not last in pointer structure,
648 ;; move forward until we can't go any farther.
649 (while (Info-forward-node t t) nil)
650 ;; Then keep moving down to last subnode, unless we reach an index.
651 (while (and (not (string-match "\\<index\\>" Info-current-node))
652 (save-excursion (search-forward "\n* Menu:" nil t)))
653 (Info-goto-node (Info-extract-menu-counting nil)))))
655 (defun Info-forward-node (&optional not-down no-error)
656 "Go forward one node, considering all nodes as forming one sequence."
658 (goto-char (point-min))
660 ;; three possibilities, in order of priority:
661 ;; 1. next node is in a menu in this node (but not in an index)
662 ;; 2. next node is next at same level
663 ;; 3. next node is up and next
664 (cond ((and (not not-down)
665 (save-excursion (search-forward "\n* menu:" nil t))
666 (not (string-match "\\<index\\>" Info-current-node)))
667 (Info-first-menu-item)
669 ((save-excursion (search-backward "next:" nil t))
672 ((and (save-excursion (search-backward "up:" nil t))
673 (not (equal (downcase (Info-extract-pointer "up")) "top")))
674 (let ((old-node Info-current-node))
676 (let (Info-history success)
678 (setq success (Info-forward-node t no-error))
679 (or success (Info-goto-node old-node))))))
681 (t (error "No pointer forward from this node"))))
683 (defun Info-backward-node ()
684 "Go backward one node, considering all nodes as forming one sequence."
686 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
687 (upnode (Info-extract-pointer "up" t)))
688 (cond ((and upnode (string-match "(" upnode))
689 (error "First node in file"))
690 ((and upnode (or (null prevnode)
691 (equal (downcase prevnode) (downcase upnode))))
694 ;; If we move back at the same level,
695 ;; go down to find the last subnode*.
698 (while (and (not (string-match "\\<index\\>" Info-current-node))
699 (save-excursion (search-forward "\n* Menu:" nil t)))
700 (Info-goto-node (Info-extract-menu-counting nil)))))
702 (error "No pointer backward from this node")))))
705 "Exit Info by selecting some other buffer."
707 (switch-to-buffer (prog1 (other-buffer (current-buffer))
708 (bury-buffer (current-buffer)))))
710 (defun Info-undefined ()
711 "Make command be undefined in Info."
716 "Enter the Info tutorial."
718 (delete-other-windows)
719 (Info-find-node "info"
720 (if (< (window-height) 23)
724 (defun Info-summary ()
725 "Display a brief summary of all Info commands."
727 (save-window-excursion
728 (switch-to-buffer "*Help*")
730 (insert (documentation 'Info-mode))
731 (goto-char (point-min))
733 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
734 (message (if flag "Type Space to see more"
735 "Type Space to return to Info"))
736 (if (/= ?\ (setq ch (read-char)))
737 (progn (setq unread-command-char ch) nil)
741 (defun Info-get-token (pos start all &optional errorstring)
742 "Return the token around POS,
743 POS must be somewhere inside the token
744 START is a regular expression which will match the
745 beginning of the tokens delimited string
746 ALL is a regular expression with a single
747 parenthized subpattern which is the token to be
748 returned. E.g. '{\(.*\)}' would return any string
749 enclosed in braces around POS.
750 SIG optional fourth argument, controls action on no match
753 a string: signal an error, using that string."
756 (re-search-backward start (max (point-min) (- pos 200)) 'yes)
757 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
758 (not (and (<= (match-beginning 0) pos)
759 (> (match-end 0) pos)))))
760 (if (and (<= (match-beginning 0) pos)
761 (> (match-end 0) pos))
762 (buffer-substring (match-beginning 1) (match-end 1))
763 (cond ((null errorstring)
769 (error "No %s around position %d" errorstring pos))))))
771 (defun Info-follow-nearest-node (click)
772 "\\<Info-mode-map>Follow a node reference near point. Like \\[Info-menu], \\Info-follow-reference], \\[Info-next], \\[Info-previous] or \\Info-up] command.
773 At end of the node's text, moves to the next node."
775 (let* ((relative-coordinates (coordinates-in-window-p (mouse-coords click)
777 (rel-x (car relative-coordinates))
778 (rel-y (cdr relative-coordinates)))
779 (move-to-window-line rel-y)
780 (move-to-column rel-x))
783 ((setq node (Info-get-token (point) "\\*note " "\\*note \\([^:]*\\):" t))
784 (Info-follow-reference node))
785 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\)::" t))
786 (Info-goto-node node))
787 ((setq node (Info-get-token (point) "\\* " "\\* \\([^:]*\\):" t))
789 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)" t))
790 (Info-goto-node node))
791 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)" t))
792 (Info-goto-node node))
793 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)" t))
794 (Info-goto-node "Top"))
795 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)" t))
796 (Info-goto-node node))
797 ((save-excursion (forward-line 1) (eobp))
801 (defvar Info-mode-map nil
802 "Keymap containing Info commands.")
805 (setq Info-mode-map (make-keymap))
806 (suppress-keymap Info-mode-map)
807 (define-key Info-mode-map "." 'beginning-of-buffer)
808 (define-key Info-mode-map " " 'scroll-up)
809 (define-key Info-mode-map "1" 'Info-first-menu-item)
810 (define-key Info-mode-map "2" 'Info-second-menu-item)
811 (define-key Info-mode-map "3" 'Info-third-menu-item)
812 (define-key Info-mode-map "4" 'Info-fourth-menu-item)
813 (define-key Info-mode-map "5" 'Info-fifth-menu-item)
814 (define-key Info-mode-map "6" 'undefined)
815 (define-key Info-mode-map "7" 'undefined)
816 (define-key Info-mode-map "8" 'undefined)
817 (define-key Info-mode-map "9" 'undefined)
818 (define-key Info-mode-map "0" 'undefined)
819 (define-key Info-mode-map "?" 'Info-summary)
820 (define-key Info-mode-map "]" 'Info-forward-node)
821 (define-key Info-mode-map "[" 'Info-backward-node)
822 (define-key Info-mode-map "<" 'Info-top-node)
823 (define-key Info-mode-map ">" 'Info-final-node)
824 (define-key Info-mode-map "b" 'beginning-of-buffer)
825 (define-key Info-mode-map "d" 'Info-directory)
826 (define-key Info-mode-map "e" 'Info-edit)
827 (define-key Info-mode-map "f" 'Info-follow-reference)
828 (define-key Info-mode-map "g" 'Info-goto-node)
829 (define-key Info-mode-map "h" 'Info-help)
830 (define-key Info-mode-map "l" 'Info-last)
831 (define-key Info-mode-map "m" 'Info-menu)
832 (define-key Info-mode-map "n" 'Info-next)
833 (define-key Info-mode-map "p" 'Info-prev)
834 (define-key Info-mode-map "q" 'Info-exit)
835 (define-key Info-mode-map "s" 'Info-search)
836 (define-key Info-mode-map "u" 'Info-up)
837 (define-key Info-mode-map "\177" 'scroll-down)
840 ;; Info mode is suitable only for specially formatted data.
841 (put 'info-mode 'mode-class 'special)
845 Info mode provides commands for browsing through the Info documentation tree.
846 Documentation in Info is divided into \"nodes\", each of which discusses
847 one topic and contains references to other nodes which discuss related
848 topics. Info has commands to follow the references and show you other nodes.
850 \\[Info-help] Invoke the Info tutorial.
852 Selecting other nodes:
853 \\[Info-next] Move to the \"next\" node of this node.
854 \\[Info-previous] Move to the \"previous\" node of this node.
855 \\[Info-up] Move \"up\" from this node.
856 \\[Info-menu] Pick menu item specified by name (or abbreviation).
857 Picking a menu item causes another node to be selected.
858 \\[Info-directory] Go to the Info directory node.
859 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
860 \\[Info-last] Move to the last node you were at.
862 Moving within a node:
863 \\[scroll-up] scroll forward a full screen. \\[scroll-down] scroll backward.
864 \\[beginning-of-buffer] Go to beginning of node.
867 \\[Info-exit] Quit Info: reselect previously selected buffer.
868 \\[Info-edit] Edit contents of selected node.
869 1 Pick first item in node's menu.
870 2, 3, 4, 5 Pick second ... fifth item in node's menu.
871 \\[Info-goto-node] Move to node specified by name.
872 You may include a filename as well, as (FILENAME)NODENAME.
873 \\[Info-search] Search through this Info file for specified regexp,
874 and select the node in which the next occurrence is found."
875 (kill-all-local-variables)
876 (setq major-mode 'Info-mode)
877 (setq mode-name "Info")
878 (use-local-map Info-mode-map)
879 (set-syntax-table text-mode-syntax-table)
880 (setq local-abbrev-table text-mode-abbrev-table)
881 (setq case-fold-search t)
882 (setq buffer-read-only t)
883 (make-local-variable 'Info-current-file)
884 (make-local-variable 'Info-current-subfile)
885 (make-local-variable 'Info-current-node)
886 (make-local-variable 'Info-tag-table-marker)
887 (make-local-variable 'Info-history)
889 (run-hooks 'Info-mode-hook))
891 (defvar Info-edit-map nil
892 "Local keymap used within `e' command of Info.")
895 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
896 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
898 ;; Info-edit mode is suitable only for specially formatted data.
899 (put 'info-edit-mode 'mode-class 'special)
901 (defun Info-edit-mode ()
902 "Major mode for editing the contents of an Info node.
903 Like text mode with the addition of Info-cease-edit
904 which returns to Info mode for browsing.
909 "Edit the contents of this Info node.
910 Allowed only if variable `Info-enable-edit' is non-nil."
913 (error "Editing info nodes is not enabled"))
914 (use-local-map Info-edit-map)
915 (setq major-mode 'Info-edit-mode)
916 (setq mode-name "Info Edit")
917 (kill-local-variable 'mode-line-buffer-identification)
918 (setq buffer-read-only nil)
919 ;; Make mode line update.
920 (set-buffer-modified-p (buffer-modified-p))
921 (message (substitute-command-keys
922 "Editing: Type \\<info-mode-map>\\[Info-cease-edit] to return to info")))
924 (defun Info-cease-edit ()
925 "Finish editing Info node; switch back to Info proper."
927 ;; Do this first, so nothing has changed if user C-g's at query.
928 (and (buffer-modified-p)
929 (y-or-n-p "Save the file? ")
931 (use-local-map Info-mode-map)
932 (setq major-mode 'Info-mode)
933 (setq mode-name "Info")
935 (setq buffer-read-only t)
936 ;; Make mode line update.
937 (set-buffer-modified-p (buffer-modified-p))
938 (and (marker-position Info-tag-table-marker)
940 (message "Tags may have changed. Use Info-tagify if necessary")))
942 (defun Info-find-emacs-command-nodes (command)
943 "Return a list of locations documenting COMMAND in the Emacs Info manual.
944 The locations are of the format used in Info-history, i.e.
945 \(FILENAME NODENAME BUFFERPOS\)."
948 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command))
949 ":\\s *\\(.*\\)\\.$")))
951 (Info-find-node "emacs" "Command Index")
952 ;; Take the index node off the Info history.
953 (setq Info-history (cdr Info-history))
954 (goto-char (point-max))
955 (while (re-search-backward cmd-desc nil t)
956 (setq where (cons (list Info-current-file
965 (defun Info-goto-emacs-command-node (command)
966 "Go to the Info node in the Emacs manual for command COMMAND."
967 (interactive "CFind documentation for command: ")
968 (or (commandp command)
969 (signal 'wrong-type-argument (list 'commandp command)))
970 (let ((where (Info-find-emacs-command-nodes command)))
972 (let ((num-matches (length where)))
973 ;; Get Info running, and pop to it in another window.
974 (save-window-excursion
976 (pop-to-buffer "*info*")
977 (Info-find-node (car (car where))
978 (car (cdr (car where))))
979 (if (> num-matches 1)
981 ;; Info-find-node already pushed (car where) onto
982 ;; Info-history. Put the other nodes that were found on
984 (setq Info-history (nconc (cdr where) Info-history))
985 (message (substitute-command-keys
986 "Found %d other entr%. Use \\[Info-last] to see %s."
988 (if (> num-matches 2) "ies" "y")
989 (if (> num-matches 2) "them" "it"))))))
990 (error "Couldn't find documentation for %s." command))))
993 (defun Info-goto-emacs-key-command-node (key)
994 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
995 Interactively, if the binding is execute-extended-command, a command is read."
996 (interactive "kFind documentation for key:")
997 (let ((command (key-binding key)))
998 (cond ((null command)
999 (message "%s is undefined" (key-description keys)))
1000 ((and (interactive-p)
1001 (eq command 'execute-extended-command))
1002 (Info-goto-emacs-command-node
1003 (read-command "Find documentation for command: ")))
1005 (Info-goto-emacs-command-node command)))))
1009 ;;; info.el ends here