1 ;;; info.el --- info package for Emacs -- could use a "create node" feature.
3 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 1, or (at your option)
12 ;; GNU Emacs is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21 (defvar Info-history nil
22 "List of info nodes user has visited.
23 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
25 (defvar Info-enable-edit nil
26 "Non-nil means the \\<info-mode-map>\\[Info-edit] command in Info can edit the current node.")
28 (defvar Info-enable-active-nodes t
29 "Non-nil allows Info to execute Lisp code associated with nodes.
30 The Lisp code is executed when the node is selected.")
32 (defvar Info-default-directory-list nil
33 "List of default directories to search for Info documentation files.
34 This value is used as the default for `Info-directory-list'. It is set
37 (defvar Info-directory-list nil
38 "List of directories to search for Info documentation files.
39 nil means not yet initialized. In this case, Info uses the environment
40 variable INFODIR to initialize it, or `Info-default-directory-list'
41 if there is no INFODIR variable in the environment.")
43 (defvar Info-current-file nil
44 "Info file that Info is now looking at, or nil.")
46 (defvar Info-current-subfile nil
47 "Info subfile that is actually in the *info* buffer now,
48 or nil if current info file is not split into subfiles.")
50 (defvar Info-current-node nil
51 "Name of node that Info is now looking at, or nil.")
53 (defvar Info-tag-table-marker
(make-marker)
54 "Marker pointing at beginning of current Info file's tag table.
55 Marker points nowhere if file has no tag table.")
58 (defun info (&optional file
)
59 "Enter Info, the documentation browser.
60 Optional argument FILE specifies the file to examine;
61 the default is the top-level directory of Info.
63 In interactive use, a prefix argument directs this command
64 to read a file name from the minibuffer."
65 (interactive (if current-prefix-arg
66 (list (read-file-name "Info file name: " nil nil t
))))
67 (or Info-directory-list
68 (setq Info-directory-list
69 (let ((path (getenv "INFOPATH")))
73 (while (> (length path
) 0)
74 (setq idx
(or (string-match ":" path
) (length path
))
75 list
(cons (substring path
0 idx
) list
)
76 path
(substring path
(min (1+ idx
)
79 Info-default-directory-list
))))
81 (Info-goto-node (concat "(" file
")"))
82 (if (get-buffer "*info*")
83 (switch-to-buffer "*info*")
86 ;; Go to an info node specified as separate filename and nodename.
87 ;; no-going-back is non-nil if recovering from an error in this function;
88 ;; it says do not attempt further (recursive) error recovery.
89 (defun Info-find-node (filename nodename
&optional no-going-back
)
90 ;; Convert filename to lower case if not found as specified.
93 (let (temp temp-downcase found
)
94 (setq filename
(substitute-in-file-name filename
))
95 (let ((dirs (if (string-match "^\\./" filename
)
96 ;; If specified name starts with `./'
97 ;; then just try current directory.
99 Info-directory-list
)))
100 ;; Search the directory list for file FILENAME.
101 (while (and dirs
(not found
))
102 (setq temp
(expand-file-name filename
(car dirs
)))
104 (expand-file-name (downcase filename
) (car dirs
)))
105 ;; Try several variants of specified name.
106 ;; Try downcasing, appending `.info', or both.
107 (cond ((file-exists-p temp
)
109 ((file-exists-p temp-downcase
)
110 (setq found temp-downcase
))
111 ((file-exists-p (concat temp
".info"))
112 (setq found
(concat temp
".info")))
113 ((file-exists-p (concat temp-downcase
".info"))
114 (setq found
(concat temp-downcase
".info"))))
115 (setq dirs
(cdr dirs
))))
117 (setq filename found
)
118 (error "Info file %s does not exist" filename
))))
119 ;; Record the node we are leaving.
120 (if (and Info-current-file
(not no-going-back
))
122 (cons (list Info-current-file Info-current-node
(point))
124 ;; Go into info buffer.
125 (switch-to-buffer "*info*")
126 (buffer-flush-undo (current-buffer))
127 (or (eq major-mode
'Info-mode
)
130 (setq Info-current-node nil
)
133 ;; Switch files if necessary
135 (equal Info-current-file filename
)
136 (let ((buffer-read-only nil
))
137 (setq Info-current-file nil
138 Info-current-subfile nil
139 buffer-file-name nil
)
141 (insert-file-contents filename t
)
142 (set-buffer-modified-p nil
)
143 (setq default-directory
(file-name-directory filename
))
144 ;; See whether file has a tag table. Record the location if yes.
145 (set-marker Info-tag-table-marker nil
)
146 (goto-char (point-max))
148 (or (equal nodename
"*")
149 (not (search-forward "\^_\nEnd tag table\n" nil t
))
151 ;; We have a tag table. Find its beginning.
152 ;; Is this an indirect file?
153 (search-backward "\nTag table:\n")
157 (looking-at "(Indirect)\n"))
158 ;; It is indirect. Copy it to another buffer
159 ;; and record that the tag table is in that buffer.
161 (let ((buf (current-buffer)))
162 (set-buffer (get-buffer-create " *info tag table*"))
163 (buffer-flush-undo (current-buffer))
164 (setq case-fold-search t
)
166 (insert-buffer-substring buf
)
167 (set-marker Info-tag-table-marker
169 (set-marker Info-tag-table-marker pos
))))
170 (setq Info-current-file
171 (file-name-sans-versions buffer-file-name
))))
172 (if (equal nodename
"*")
173 (progn (setq Info-current-node nodename
)
174 (Info-set-mode-line))
175 ;; Search file for a suitable node.
176 ;; First get advice from tag table if file has one.
177 ;; Also, if this is an indirect info file,
178 ;; read the proper subfile into this buffer.
179 (let ((guesspos (point-min)))
180 (if (marker-position Info-tag-table-marker
)
182 (set-buffer (marker-buffer Info-tag-table-marker
))
183 (goto-char Info-tag-table-marker
)
184 (if (search-forward (concat "Node: " nodename
"\177") nil t
)
186 (setq guesspos
(read (current-buffer)))
187 ;; If this is an indirect file,
188 ;; determine which file really holds this node
190 (if (not (eq (current-buffer) (get-buffer "*info*")))
192 (Info-read-subfile guesspos
))))
193 (error "No such node: \"%s\"" nodename
))))
194 (goto-char (max (point-min) (- guesspos
1000))))
195 ;; Now search from our advised position (or from beg of buffer)
196 ;; to find the actual node.
197 (let ((regexp (concat "Node: *" (regexp-quote nodename
) " *[,\t\n]")))
199 (while (search-forward "\n\^_" nil t
)
203 (if (re-search-backward regexp beg t
)
205 (error "No such node: %s" nodename
)))
207 ;; If we did not finish finding the specified node,
208 ;; go back to the previous one.
209 (or Info-current-node no-going-back
210 (let ((hist (car Info-history
)))
211 (setq Info-history
(cdr Info-history
))
212 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
213 (goto-char (nth 2 hist
)))))
214 (goto-char (point-min)))
216 (defun Info-read-subfile (nodepos)
217 (set-buffer (marker-buffer Info-tag-table-marker
))
218 (goto-char (point-min))
219 (search-forward "\n\^_")
224 (while (not (looking-at "\^_"))
227 thisfilepos thisfilename
)
228 (search-forward ": ")
229 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
230 (setq thisfilepos
(read (current-buffer)))
231 ;; read in version 19 stops at the end of number.
232 ;; Advance to the next line.
234 (if (> thisfilepos nodepos
)
236 (setq lastfilename thisfilename
)
237 (setq lastfilepos thisfilepos
))
239 (set-buffer (get-buffer "*info*"))
240 (or (equal Info-current-subfile lastfilename
)
241 (let ((buffer-read-only nil
))
242 (setq buffer-file-name nil
)
245 (insert-file-contents lastfilename
)
246 (set-buffer-modified-p nil
)
247 (setq Info-current-subfile lastfilename
)))
248 (goto-char (point-min))
249 (search-forward "\n\^_")
250 (+ (- nodepos lastfilepos
) (point))))
252 ;; Select the info node that point is in.
253 (defun Info-select-node ()
255 ;; Find beginning of node.
256 (search-backward "\n\^_")
258 ;; Get nodename spelled as it is in the node.
259 (re-search-forward "Node:[ \t]*")
260 (setq Info-current-node
261 (buffer-substring (point)
263 (skip-chars-forward "^,\t\n")
266 ;; Find the end of it, and narrow.
268 (let (active-expression)
269 (narrow-to-region (point)
270 (if (re-search-forward "\n[\^_\f]" nil t
)
273 (if (looking-at "[\n\^_\f]*execute: ")
275 (goto-char (match-end 0))
276 (setq active-expression
277 (read (current-buffer))))))
279 (if Info-enable-active-nodes
(eval active-expression
)))))
281 (defun Info-set-mode-line ()
282 (setq mode-line-buffer-identification
285 (if Info-current-file
286 (file-name-nondirectory Info-current-file
)
289 (or Info-current-node
""))))
291 ;; Go to an info node specified with a filename-and-nodename string
292 ;; of the sort that is found in pointers in nodes.
294 (defun Info-goto-node (nodename)
295 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
296 (interactive "sGoto node: ")
298 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
300 (setq filename
(if (= (match-beginning 1) (match-end 1))
302 (substring nodename
(match-beginning 2) (match-end 2)))
303 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
304 (let ((trim (string-match "\\s *\\'" filename
)))
305 (if trim
(setq filename
(substring filename
0 trim
))))
306 (let ((trim (string-match "\\s *\\'" nodename
)))
307 (if trim
(setq nodename
(substring nodename
0 trim
))))
308 (Info-find-node (if (equal filename
"") nil filename
)
309 (if (equal nodename
"") "Top" nodename
))))
311 (defun Info-restore-point (hl)
312 "If this node has been visited, restore the point value when we left."
314 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
315 (equal (nth 1 (car hl
)) Info-current-node
))
316 (goto-char (nth 2 (car hl
)))
317 (Info-restore-point (cdr hl
)))))
319 (defvar Info-last-search nil
320 "Default regexp for \\<info-mode-map>\\[Info-search] command to search for.")
322 (defun Info-search (regexp)
323 "Search for REGEXP, starting from point, and select node it's found in."
324 (interactive "sSearch (regexp): ")
325 (if (equal regexp
"")
326 (setq regexp Info-last-search
)
327 (setq Info-last-search regexp
))
328 (let ((found ()) current
329 (onode Info-current-node
)
330 (ofile Info-current-file
)
332 (osubfile Info-current-subfile
))
336 (if (null Info-current-subfile
)
337 (progn (re-search-forward regexp
) (setq found
(point)))
339 (progn (re-search-forward regexp
) (setq found
(point)))
340 (search-failed nil
)))))
341 (if (not found
) ;can only happen in subfile case -- else would have erred
344 (set-buffer (marker-buffer Info-tag-table-marker
))
345 (goto-char (point-min))
346 (search-forward "\n\^_\nIndirect:")
348 (narrow-to-region (point)
349 (progn (search-forward "\n\^_")
351 (goto-char (point-min))
352 (search-forward (concat "\n" osubfile
": "))
355 (re-search-forward "\\(^.*\\): [0-9]+$")
356 (goto-char (+ (match-end 1) 2))
357 (setq list
(cons (cons (read (current-buffer))
358 (buffer-substring (match-beginning 1)
361 (goto-char (1+ (match-end 0))))
362 (setq list
(nreverse list
)
363 current
(car (car list
))
366 (message "Searching subfile %s..." (cdr (car list
)))
367 (Info-read-subfile (car (car list
)))
368 (setq list
(cdr list
))
369 (goto-char (point-min))
370 (if (re-search-forward regexp nil t
)
371 (setq found
(point) list
())))
374 (signal 'search-failed
(list regexp
))))
376 (progn (Info-read-subfile opoint
)
378 (Info-select-node)))))
382 (or (and (equal onode Info-current-node
)
383 (equal ofile Info-current-file
))
384 (setq Info-history
(cons (list ofile onode opoint
)
387 ;; Extract the value of the node-pointer named NAME.
388 ;; If there is none, use ERRORNAME in the error message;
389 ;; if ERRORNAME is nil, just return nil.
390 (defun Info-extract-pointer (name &optional errorname
)
392 (goto-char (point-min))
394 (if (re-search-backward (concat name
":") nil t
)
396 (goto-char (match-end 0))
397 (Info-following-node-name))
400 (error (concat "Node has no " (capitalize (or errorname name
))))))))
402 (defun Info-following-node-name (&optional allowedchars
)
403 (skip-chars-forward " \t")
407 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
408 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
410 (skip-chars-forward "^)")))
411 (skip-chars-backward " ")
415 "Go to the next node of this node."
417 (Info-goto-node (Info-extract-pointer "next")))
420 "Go to the previous node of this node."
422 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
425 "Go to the superior node of this node."
427 (Info-goto-node (Info-extract-pointer "up"))
428 (Info-restore-point Info-history
))
431 "Go back to the last node visited."
434 (error "This is the first Info node you looked at"))
435 (let (filename nodename opoint
)
436 (setq filename
(car (car Info-history
)))
437 (setq nodename
(car (cdr (car Info-history
))))
438 (setq opoint
(car (cdr (cdr (car Info-history
)))))
439 (setq Info-history
(cdr Info-history
))
440 (Info-find-node filename nodename
)
441 (setq Info-history
(cdr Info-history
))
444 (defun Info-directory ()
445 "Go to the Info directory node."
447 (Info-find-node "dir" "top"))
449 (defun Info-follow-reference (footnotename)
450 "Follow cross reference named NAME to the node it refers to.
451 NAME may be an abbreviation of the reference name."
453 (let ((completion-ignore-case t
)
454 completions default
(start-point (point)) str i
)
456 (goto-char (point-min))
457 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
458 (setq str
(buffer-substring
461 ;; See if this one should be the default.
463 (< (match-beginning 0) start-point
)
464 (<= start-point
(point))
467 (while (setq i
(string-match "[ \n\t]+" str i
))
468 (setq str
(concat (substring str
0 i
) " "
469 (substring str
(match-end 0))))
471 ;; Record as a completion and perhaps as default.
472 (if (eq default t
) (setq default str
))
477 (list (completing-read (if default
478 (concat "Follow reference named: ("
480 "Follow reference named: ")
481 completions default t
))
482 (error "No cross-references in this node"))))
483 (let (target beg i
(str (concat "\\*note " footnotename
)))
484 (while (setq i
(string-match " " str i
))
485 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
488 (goto-char (point-min))
489 (or (re-search-forward str nil t
)
490 (error "No cross-reference named %s" footnotename
))
491 (goto-char (+ (match-beginning 0) 5))
493 (Info-extract-menu-node-name "Bad format cross reference" t
)))
494 (while (setq i
(string-match "[ \t\n]+" target i
))
495 (setq target
(concat (substring target
0 i
) " "
496 (substring target
(match-end 0))))
498 (Info-goto-node target
)))
500 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
501 (skip-chars-forward " \t\n")
504 (skip-chars-forward "^:")
508 (buffer-substring beg
(1- (point)))
509 (skip-chars-forward " \t\n")
510 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
511 (while (setq i
(string-match "\n" str i
))
515 (defun Info-menu-item-sequence (list)
517 (Info-menu-item (car list
))
518 (setq list
(cdr list
))))
520 (defun Info-menu (menu-item)
521 "Go to node for menu item named (or abbreviated) NAME.
522 Completion is allowed, and the menu item point is on is the default."
524 (let ((completions '())
525 ;; If point is within a menu item, use that item as the default
530 (goto-char (point-min))
531 (if (not (search-forward "\n* menu:" nil t
))
532 (error "No menu in this node"))
533 (while (re-search-forward
534 "\n\\* \\([^:\t\n]*\\):" nil t
)
535 (if (and (null default
)
536 (prog1 (if last
(< last p
) nil
)
537 (setq last
(match-beginning 0)))
539 (setq default
(car (car completions
))))
540 (setq completions
(cons (cons (buffer-substring
545 (if (and (null default
) last
547 (<= p
(progn (end-of-line) (point))))
548 (setq default
(car (car completions
)))))
551 (setq item
(let ((completion-ignore-case t
))
552 (completing-read (if default
553 (format "Menu item (default %s): "
557 ;; we rely on the fact that completing-read accepts an input
558 ;; of "" even when the require-match argument is true and ""
559 ;; is not a valid possibility
560 (if (string= item
"")
566 ;; there is a problem here in that if several menu items have the same
567 ;; name you can only go to the node of the first with this command.
568 (Info-goto-node (Info-extract-menu-item menu-item
)))
570 (defun Info-extract-menu-item (menu-item)
571 (setq menu-item
(regexp-quote menu-item
))
573 (goto-char (point-min))
574 (or (search-forward "\n* menu:" nil t
)
575 (error "No menu in this node"))
576 (or (re-search-forward (concat "\n* " menu-item
":") nil t
)
577 (re-search-forward (concat "\n* " menu-item
) nil t
)
578 (error "No such item in menu"))
581 (Info-extract-menu-node-name)))
583 ;; If COUNT is nil, use the last item in the menu.
584 (defun Info-extract-menu-counting (count)
586 (goto-char (point-min))
587 (or (search-forward "\n* menu:" nil t
)
588 (error "No menu in this node"))
590 (or (search-forward "\n* " nil t count
)
591 (error "Too few items in menu"))
592 (while (search-forward "\n* " nil t
)
594 (Info-extract-menu-node-name)))
596 (defun Info-first-menu-item ()
597 "Go to the node of the first menu item."
599 (Info-goto-node (Info-extract-menu-counting 1)))
601 (defun Info-second-menu-item ()
602 "Go to the node of the second menu item."
604 (Info-goto-node (Info-extract-menu-counting 2)))
606 (defun Info-third-menu-item ()
607 "Go to the node of the third menu item."
609 (Info-goto-node (Info-extract-menu-counting 3)))
611 (defun Info-fourth-menu-item ()
612 "Go to the node of the fourth menu item."
614 (Info-goto-node (Info-extract-menu-counting 4)))
616 (defun Info-fifth-menu-item ()
617 "Go to the node of the fifth menu item."
619 (Info-goto-node (Info-extract-menu-counting 5)))
621 (defun Info-top-node ()
622 "Go to the Top node of this file."
624 (Info-goto-node "Top"))
626 (defun Info-final-node ()
627 "Go to the final node in this file."
629 (Info-goto-node "Top")
631 ;; Go to the last node in the menu of Top.
632 (Info-goto-node (Info-extract-menu-counting nil
))
633 ;; If the last node in the menu is not last in pointer structure,
634 ;; move forward until we can't go any farther.
635 (while (Info-forward-node t t
) nil
)
636 ;; Then keep moving down to last subnode, unless we reach an index.
637 (while (and (not (string-match "\\<index\\>" Info-current-node
))
638 (save-excursion (search-forward "\n* Menu:" nil t
)))
639 (Info-goto-node (Info-extract-menu-counting nil
)))))
641 (defun Info-forward-node (&optional not-down no-error
)
642 "Go forward one node, considering all nodes as forming one sequence."
644 (goto-char (point-min))
646 ;; three possibilities, in order of priority:
647 ;; 1. next node is in a menu in this node (but not in an index)
648 ;; 2. next node is next at same level
649 ;; 3. next node is up and next
650 (cond ((and (not not-down
)
651 (save-excursion (search-forward "\n* menu:" nil t
))
652 (not (string-match "\\<index\\>" Info-current-node
)))
653 (Info-first-menu-item)
655 ((save-excursion (search-backward "next:" nil t
))
658 ((and (save-excursion (search-backward "up:" nil t
))
659 (not (equal (downcase (Info-extract-pointer "up")) "top")))
660 (let ((old-node Info-current-node
))
662 (let (Info-history success
)
664 (setq success
(Info-forward-node t no-error
))
665 (or success
(Info-goto-node old-node
))))))
667 (t (error "No pointer forward from this node"))))
669 (defun Info-backward-node ()
670 "Go backward one node, considering all nodes as forming one sequence."
672 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
673 (upnode (Info-extract-pointer "up" t
)))
674 (cond ((and upnode
(string-match "(" upnode
))
675 (error "First node in file"))
676 ((and upnode
(or (null prevnode
)
677 (equal (downcase prevnode
) (downcase upnode
))))
680 ;; If we move back at the same level,
681 ;; go down to find the last subnode*.
684 (while (and (not (string-match "\\<index\\>" Info-current-node
))
685 (save-excursion (search-forward "\n* Menu:" nil t
)))
686 (Info-goto-node (Info-extract-menu-counting nil
)))))
688 (error "No pointer backward from this node")))))
691 "Exit Info by selecting some other buffer."
693 (switch-to-buffer (prog1 (other-buffer (current-buffer))
694 (bury-buffer (current-buffer)))))
696 (defun Info-undefined ()
697 "Make command be undefined in Info."
702 "Enter the Info tutorial."
704 (delete-other-windows)
705 (Info-find-node "info"
706 (if (< (window-height) 23)
710 (defun Info-summary ()
711 "Display a brief summary of all Info commands."
713 (save-window-excursion
714 (switch-to-buffer "*Help*")
716 (insert (documentation 'Info-mode
))
717 (goto-char (point-min))
719 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
720 (message (if flag
"Type Space to see more"
721 "Type Space to return to Info"))
722 (if (/= ?\
(setq ch
(read-char)))
723 (progn (setq unread-command-char ch
) nil
)
727 (defun Info-get-token (pos start all
&optional errorstring
)
728 "Return the token around POS,
729 POS must be somewhere inside the token
730 START is a regular expression which will match the
731 beginning of the tokens delimited string
732 ALL is a regular expression with a single
733 parenthized subpattern which is the token to be
734 returned. E.g. '{\(.*\)}' would return any string
735 enclosed in braces around POS.
736 SIG optional fourth argument, controls action on no match
739 a string: signal an error, using that string."
742 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)
743 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
744 (not (and (<= (match-beginning 0) pos
)
745 (> (match-end 0) pos
)))))
746 (if (and (<= (match-beginning 0) pos
)
747 (> (match-end 0) pos
))
748 (buffer-substring (match-beginning 1) (match-end 1))
749 (cond ((null errorstring
)
755 (error "No %s around position %d" errorstring pos
))))))
757 (defun Info-follow-nearest-node (click)
758 "\\<Info-mode-map>Follow a node reference near point. Like \\[Info-menu], \\Info-follow-reference], \\[Info-next], \\[Info-previous] or \\Info-up] command.
759 At end of the node's text, moves to the next node."
761 (let* ((relative-coordinates (coordinates-in-window-p (mouse-coords click
)
763 (rel-x (car relative-coordinates
))
764 (rel-y (cdr relative-coordinates
)))
765 (move-to-window-line rel-y
)
766 (move-to-column rel-x
))
769 ((setq node
(Info-get-token (point) "\\*note " "\\*note \\([^:]*\\):" t
))
770 (Info-follow-reference node
))
771 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\)::" t
))
772 (Info-goto-node node
))
773 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\):" t
))
775 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)" t
))
776 (Info-goto-node node
))
777 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)" t
))
778 (Info-goto-node node
))
779 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)" t
))
780 (Info-goto-node "Top"))
781 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)" t
))
782 (Info-goto-node node
))
783 ((save-excursion (forward-line 1) (eobp))
787 (defvar Info-mode-map nil
788 "Keymap containing Info commands.")
791 (setq Info-mode-map
(make-keymap))
792 (suppress-keymap Info-mode-map
)
793 (define-key Info-mode-map
"." 'beginning-of-buffer
)
794 (define-key Info-mode-map
" " 'scroll-up
)
795 (define-key Info-mode-map
"1" 'Info-first-menu-item
)
796 (define-key Info-mode-map
"2" 'Info-second-menu-item
)
797 (define-key Info-mode-map
"3" 'Info-third-menu-item
)
798 (define-key Info-mode-map
"4" 'Info-fourth-menu-item
)
799 (define-key Info-mode-map
"5" 'Info-fifth-menu-item
)
800 (define-key Info-mode-map
"6" 'undefined
)
801 (define-key Info-mode-map
"7" 'undefined
)
802 (define-key Info-mode-map
"8" 'undefined
)
803 (define-key Info-mode-map
"9" 'undefined
)
804 (define-key Info-mode-map
"0" 'undefined
)
805 (define-key Info-mode-map
"?" 'Info-summary
)
806 (define-key Info-mode-map
"]" 'Info-forward-node
)
807 (define-key Info-mode-map
"[" 'Info-backward-node
)
808 (define-key Info-mode-map
"<" 'Info-top-node
)
809 (define-key Info-mode-map
">" 'Info-final-node
)
810 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
811 (define-key Info-mode-map
"d" 'Info-directory
)
812 (define-key Info-mode-map
"e" 'Info-edit
)
813 (define-key Info-mode-map
"f" 'Info-follow-reference
)
814 (define-key Info-mode-map
"g" 'Info-goto-node
)
815 (define-key Info-mode-map
"h" 'Info-help
)
816 (define-key Info-mode-map
"l" 'Info-last
)
817 (define-key Info-mode-map
"m" 'Info-menu
)
818 (define-key Info-mode-map
"n" 'Info-next
)
819 (define-key Info-mode-map
"p" 'Info-prev
)
820 (define-key Info-mode-map
"q" 'Info-exit
)
821 (define-key Info-mode-map
"s" 'Info-search
)
822 (define-key Info-mode-map
"u" 'Info-up
)
823 (define-key Info-mode-map
"\177" 'scroll-down
)
826 ;; Info mode is suitable only for specially formatted data.
827 (put 'info-mode
'mode-class
'special
)
831 Info mode provides commands for browsing through the Info documentation tree.
832 Documentation in Info is divided into \"nodes\", each of which discusses
833 one topic and contains references to other nodes which discuss related
834 topics. Info has commands to follow the references and show you other nodes.
836 \\[Info-help] Invoke the Info tutorial.
838 Selecting other nodes:
839 \\[Info-next] Move to the \"next\" node of this node.
840 \\[Info-previous] Move to the \"previous\" node of this node.
841 \\[Info-up] Move \"up\" from this node.
842 \\[Info-menu] Pick menu item specified by name (or abbreviation).
843 Picking a menu item causes another node to be selected.
844 \\[Info-directory] Go to the Info directory node.
845 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
846 \\[Info-last] Move to the last node you were at.
848 Moving within a node:
849 \\[scroll-up] scroll forward a full screen. \\[scroll-down] scroll backward.
850 \\[beginning-of-buffer] Go to beginning of node.
853 \\[Info-exit] Quit Info: reselect previously selected buffer.
854 \\[Info-edit] Edit contents of selected node.
855 1 Pick first item in node's menu.
856 2, 3, 4, 5 Pick second ... fifth item in node's menu.
857 \\[Info-goto-node] Move to node specified by name.
858 You may include a filename as well, as (FILENAME)NODENAME.
859 \\[Info-search] Search through this Info file for specified regexp,
860 and select the node in which the next occurrence is found."
861 (kill-all-local-variables)
862 (setq major-mode
'Info-mode
)
863 (setq mode-name
"Info")
864 (use-local-map Info-mode-map
)
865 (set-syntax-table text-mode-syntax-table
)
866 (setq local-abbrev-table text-mode-abbrev-table
)
867 (setq case-fold-search t
)
868 (setq buffer-read-only t
)
869 (make-local-variable 'Info-current-file
)
870 (make-local-variable 'Info-current-subfile
)
871 (make-local-variable 'Info-current-node
)
872 (make-local-variable 'Info-tag-table-marker
)
873 (make-local-variable 'Info-history
)
875 (run-hooks 'Info-mode-hook
))
877 (defvar Info-edit-map nil
878 "Local keymap used within `e' command of Info.")
881 (setq Info-edit-map
(nconc (make-sparse-keymap) text-mode-map
))
882 (define-key Info-edit-map
"\C-c\C-c" 'Info-cease-edit
))
884 ;; Info-edit mode is suitable only for specially formatted data.
885 (put 'info-edit-mode
'mode-class
'special
)
887 (defun Info-edit-mode ()
888 "Major mode for editing the contents of an Info node.
889 Like text mode with the addition of Info-cease-edit
890 which returns to Info mode for browsing.
895 "Edit the contents of this Info node.
896 Allowed only if variable `Info-enable-edit' is non-nil."
899 (error "Editing info nodes is not enabled"))
900 (use-local-map Info-edit-map
)
901 (setq major-mode
'Info-edit-mode
)
902 (setq mode-name
"Info Edit")
903 (kill-local-variable 'mode-line-buffer-identification
)
904 (setq buffer-read-only nil
)
905 ;; Make mode line update.
906 (set-buffer-modified-p (buffer-modified-p))
907 (message (substitute-command-keys
908 "Editing: Type \\<info-mode-map>\\[Info-cease-edit] to return to info")))
910 (defun Info-cease-edit ()
911 "Finish editing Info node; switch back to Info proper."
913 ;; Do this first, so nothing has changed if user C-g's at query.
914 (and (buffer-modified-p)
915 (y-or-n-p "Save the file? ")
917 (use-local-map Info-mode-map
)
918 (setq major-mode
'Info-mode
)
919 (setq mode-name
"Info")
921 (setq buffer-read-only t
)
922 ;; Make mode line update.
923 (set-buffer-modified-p (buffer-modified-p))
924 (and (marker-position Info-tag-table-marker
)
926 (message "Tags may have changed. Use Info-tagify if necessary")))
928 (defun Info-find-emacs-command-nodes (command)
929 "Return a list of locations documenting COMMAND in the Emacs Info manual.
930 The locations are of the format used in Info-history, i.e.
931 \(FILENAME NODENAME BUFFERPOS\)."
934 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command
))
935 ":\\s *\\(.*\\)\\.$")))
937 (Info-find-node "emacs" "Command Index")
938 ;; Take the index node off the Info history.
939 (setq Info-history
(cdr Info-history
))
940 (goto-char (point-max))
941 (while (re-search-backward cmd-desc nil t
)
942 (setq where
(cons (list Info-current-file
951 (defun Info-goto-emacs-command-node (command)
952 "Go to the Info node in the Emacs manual for command COMMAND."
953 (interactive "CFind documentation for command: ")
954 (or (commandp command
)
955 (signal 'wrong-type-argument
(list 'commandp command
)))
956 (let ((where (Info-find-emacs-command-nodes command
)))
958 (let ((num-matches (length where
)))
959 ;; Get Info running, and pop to it in another window.
960 (save-window-excursion
962 (pop-to-buffer "*info*")
963 (Info-find-node (car (car where
))
964 (car (cdr (car where
))))
965 (if (> num-matches
1)
967 ;; Info-find-node already pushed (car where) onto
968 ;; Info-history. Put the other nodes that were found on
970 (setq Info-history
(nconc (cdr where
) Info-history
))
971 (message (substitute-command-keys
972 "Found %d other entr%. Use \\[Info-last] to see %s."
974 (if (> num-matches
2) "ies" "y")
975 (if (> num-matches
2) "them" "it"))))))
976 (error "Couldn't find documentation for %s." command
))))
978 (define-key help-map
"\C-f" 'Info-goto-emacs-command-node
)
981 (defun Info-goto-emacs-key-command-node (key)
982 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
983 Interactively, if the binding is execute-extended-command, a command is read."
984 (interactive "kFind documentation for key:")
985 (let ((command (key-binding key
)))
986 (cond ((null command
)
987 (message "%s is undefined" (key-description keys
)))
988 ((and (interactive-p)
989 (eq command
'execute-extended-command
))
990 (Info-goto-emacs-command-node
991 (read-command "Find documentation for command: ")))
993 (Info-goto-emacs-command-node command
)))))
995 (define-key help-map
"\C-k" 'Info-goto-emacs-key-command-node
)
999 ;;; info.el ends here