1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 1986, 1992 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-default-directory-list nil
46 "List of default directories to search for Info documentation files.
47 This value is used as the default for `Info-directory-list'. It is set
50 (defvar Info-directory-list
51 (let ((path (getenv "INFOPATH")))
55 (while (> (length path
) 0)
56 (setq idx
(or (string-match ":" path
) (length path
))
57 list
(cons (substring path
0 idx
) list
)
58 path
(substring path
(min (1+ idx
)
61 Info-default-directory-list
))
62 "List of directories to search for Info documentation files.
63 nil means not yet initialized. In this case, Info uses the environment
64 variable INFOPATH to initialize it, or `Info-default-directory-list'
65 if there is no INFOPATH variable in the environment.")
67 (defvar Info-current-file nil
68 "Info file that Info is now looking at, or nil.")
70 (defvar Info-current-subfile nil
71 "Info subfile that is actually in the *info* buffer now,
72 or nil if current info file is not split into subfiles.")
74 (defvar Info-current-node nil
75 "Name of node that Info is now looking at, or nil.")
77 (defvar Info-tag-table-marker
(make-marker)
78 "Marker pointing at beginning of current Info file's tag table.
79 Marker points nowhere if file has no tag table.")
81 (defvar Info-index-alternatives nil
82 "List of possible matches for last Info-index command.")
84 (defvar Info-suffix-list
'( ("" . nil
)
89 (".info.Z" .
"uncompress")
90 (".info.Y" .
"unyabba")
91 (".info.z" .
"gunzip"))
92 "List of file name suffixes and associated decoding commands.
93 Each entry should be (SUFFIX . STRING); the file is given to
94 the command as standard input. If STRING is nil, no decoding is done.")
96 (defun info-insert-file-contents (filename &optional visit
)
97 "Insert the contents of an info file in the current buffer.
98 Do the right thing if the file has been compressed or zipped."
103 (let ((compressed (concat filename
(car x
))))
104 (if (file-exists-p compressed
)
106 (insert-file-contents compressed visit
)
108 (let ((buffer-read-only nil
))
109 (shell-command-on-region
110 (point-min) (point-max) (cdr x
) t
)))
114 (error "Can't find %s or any compressed version of it!" filename
)))
117 (defun info (&optional file
)
118 "Enter Info, the documentation browser.
119 Optional argument FILE specifies the file to examine;
120 the default is the top-level directory of Info.
122 In interactive use, a prefix argument directs this command
123 to read a file name from the minibuffer."
124 (interactive (if current-prefix-arg
125 (list (read-file-name "Info file name: " nil nil t
))))
127 (Info-goto-node (concat "(" file
")"))
128 (if (get-buffer "*info*")
129 (switch-to-buffer "*info*")
132 ;; Go to an info node specified as separate filename and nodename.
133 ;; no-going-back is non-nil if recovering from an error in this function;
134 ;; it says do not attempt further (recursive) error recovery.
135 (defun Info-find-node (filename nodename
&optional no-going-back
)
136 ;; Convert filename to lower case if not found as specified.
139 (let (temp temp-downcase found
)
140 (setq filename
(substitute-in-file-name filename
))
141 (if (string= (downcase (file-name-nondirectory filename
)) "dir")
143 (let ((dirs (if (string-match "^\\./" filename
)
144 ;; If specified name starts with `./'
145 ;; then just try current directory.
147 Info-directory-list
)))
148 ;; Search the directory list for file FILENAME.
149 (while (and dirs
(not found
))
150 (setq temp
(expand-file-name filename
(car dirs
)))
152 (expand-file-name (downcase filename
) (car dirs
)))
153 ;; Try several variants of specified name.
158 (if (file-exists-p (concat temp
(car x
)))
161 (throw 'foundit nil
)))
162 (if (file-exists-p (concat temp-downcase
(car x
)))
164 (setq found temp-downcase
)
165 (throw 'foundit nil
)))))
167 (setq dirs
(cdr dirs
)))))
169 (setq filename found
)
170 (error "Info file %s does not exist" filename
))))
171 ;; Record the node we are leaving.
172 (if (and Info-current-file
(not no-going-back
))
174 (cons (list Info-current-file Info-current-node
(point))
176 ;; Go into info buffer.
177 (switch-to-buffer "*info*")
178 (buffer-disable-undo (current-buffer))
179 (or (eq major-mode
'Info-mode
)
182 (setq Info-current-node nil
)
185 ;; Switch files if necessary
187 (equal Info-current-file filename
)
188 (let ((buffer-read-only nil
))
189 (setq Info-current-file nil
190 Info-current-subfile nil
191 Info-index-alternatives nil
192 buffer-file-name nil
)
196 (info-insert-file-contents filename t
)
197 (setq default-directory
(file-name-directory filename
)))
198 (set-buffer-modified-p nil
)
199 ;; See whether file has a tag table. Record the location if yes.
200 (set-marker Info-tag-table-marker nil
)
201 (goto-char (point-max))
203 (or (equal nodename
"*")
204 (not (search-forward "\^_\nEnd tag table\n" nil t
))
206 ;; We have a tag table. Find its beginning.
207 ;; Is this an indirect file?
208 (search-backward "\nTag table:\n")
212 (looking-at "(Indirect)\n"))
213 ;; It is indirect. Copy it to another buffer
214 ;; and record that the tag table is in that buffer.
216 (let ((buf (current-buffer)))
217 (set-buffer (get-buffer-create " *info tag table*"))
218 (buffer-disable-undo (current-buffer))
219 (setq case-fold-search t
)
221 (insert-buffer-substring buf
)
222 (set-marker Info-tag-table-marker
224 (set-marker Info-tag-table-marker pos
))))
225 (setq Info-current-file
226 (if (eq filename t
) "dir"
227 (file-name-sans-versions buffer-file-name
)))))
228 (if (equal nodename
"*")
229 (progn (setq Info-current-node nodename
)
230 (Info-set-mode-line))
231 ;; Search file for a suitable node.
232 (let ((guesspos (point-min))
233 (regexp (concat "Node: *" (regexp-quote nodename
) " *[,\t\n\177]")))
234 ;; First get advice from tag table if file has one.
235 ;; Also, if this is an indirect info file,
236 ;; read the proper subfile into this buffer.
237 (if (marker-position Info-tag-table-marker
)
239 (set-buffer (marker-buffer Info-tag-table-marker
))
240 (goto-char Info-tag-table-marker
)
241 (if (re-search-forward regexp nil t
)
243 (setq guesspos
(read (current-buffer)))
244 ;; If this is an indirect file,
245 ;; determine which file really holds this node
247 (if (not (eq (current-buffer) (get-buffer "*info*")))
249 (Info-read-subfile guesspos
))))
250 (error "No such node: \"%s\"" nodename
))))
251 (goto-char (max (point-min) (- guesspos
1000)))
252 ;; Now search from our advised position (or from beg of buffer)
253 ;; to find the actual node.
255 (while (search-forward "\n\^_" nil t
)
259 (if (re-search-backward regexp beg t
)
261 (error "No such node: %s" nodename
)))
263 ;; If we did not finish finding the specified node,
264 ;; go back to the previous one.
265 (or Info-current-node no-going-back
266 (let ((hist (car Info-history
)))
267 (setq Info-history
(cdr Info-history
))
268 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
269 (goto-char (nth 2 hist
)))))
270 (goto-char (point-min)))
272 ;; Cache the contents of the (virtual) dir file, once we have merged
273 ;; it for the first time, so we can save time subsequently.
274 (defvar Info-dir-contents nil
)
276 ;; Cache for the directory we decided to use for the default-directory
277 ;; of the merged dir text.
278 (defvar Info-dir-contents-directory nil
)
280 ;; Construct the Info directory node by merging the files named `dir'
281 ;; from various directories. Set the *info* buffer's
282 ;; default-directory to the first directory we actually get any text
284 (defun Info-insert-dir ()
285 (if Info-dir-contents
286 (insert Info-dir-contents
)
287 (let ((dirs Info-directory-list
)
288 buffers buffer others nodes dirs-done
)
290 ;; Search the directory list for the directory file.
292 (or (member (file-truename (expand-file-name (car dirs
))) dirs-done
)
293 (member (directory-file-name (file-truename (expand-file-name (car dirs
))))
295 ;; Try several variants of specified name.
296 ;; Try upcasing, appending `.info', or both.
300 ((progn (setq temp
(expand-file-name "DIR" (car dirs
)))
301 (file-exists-p temp
))
302 (find-file-noselect temp
))
303 ((progn (setq temp
(expand-file-name "dir" (car dirs
)))
304 (file-exists-p temp
))
305 (find-file-noselect temp
))
306 ((progn (setq temp
(expand-file-name "DIR.INFO" (car dirs
)))
307 (file-exists-p temp
))
308 (find-file-noselect temp
))
309 ((progn (setq temp
(expand-file-name "dir.info" (car dirs
)))
310 (file-exists-p temp
))
311 (find-file-noselect temp
)))))
313 (cons (file-truename (expand-file-name (car dirs
)))
314 (cons (directory-file-name
315 (file-truename (expand-file-name (car dirs
))))
317 (if buffer
(setq buffers
(cons buffer buffers
)))))
318 (setq dirs
(cdr dirs
)))
320 ;; Distinguish the dir file that comes with Emacs from all the
321 ;; others. Yes, that is really what this is supposed to do.
322 ;; If it doesn't work, fix it.
323 (setq buffer
(car buffers
)
324 others
(cdr buffers
))
326 ;; Insert the entire original dir file as a start; use its
327 ;; default directory as the default directory for the whole
329 (insert-buffer buffer
)
330 (setq Info-dir-contents-directory
(save-excursion
334 ;; Look at each of the other buffers one by one.
336 (let ((other (car others
)))
337 ;; In each, find all the menus.
340 (goto-char (point-min))
341 ;; Find each menu, and add an elt to NODES for it.
342 (while (re-search-forward "^\\* Menu:" nil t
)
343 (let (beg nodename end
)
346 (search-backward "\n\x1f")
347 (search-forward "Node: ")
348 (setq nodename
(Info-following-node-name))
349 (search-forward "\n\x1f" nil
'move
)
352 (setq nodes
(cons (list nodename other beg end
) nodes
))))))
353 (setq others
(cdr others
)))
354 ;; Add to the main menu a menu item for each other node.
355 (re-search-forward "^\\* Menu:")
357 (let ((menu-items '("top"))
360 (end (save-excursion (search-forward "\x1f" nil t
) (point))))
362 (let ((nodename (car (car nodes
))))
363 (or (member (downcase nodename
) menu-items
)
364 (re-search-forward (concat "^\\* " (regexp-quote nodename
) ":")
367 (insert "* " nodename
"\n")
368 (setq menu-items
(cons nodename menu-items
)))))
369 (setq nodes
(cdr nodes
))))
370 ;; Now take each node of each of the other buffers
371 ;; and merge it into the main buffer.
373 (let ((nodename (car (car nodes
))))
374 (goto-char (point-min))
375 ;; Find the like-named node in the main buffer.
376 (if (re-search-forward (concat "\n\x1f.*\n.*Node: "
377 (regexp-quote nodename
)
381 (search-forward "\n\x1f" nil
'move
)
383 ;; If none exists, add one.
384 (goto-char (point-max))
385 (insert "\x1f\nFile: dir\tnode: " nodename
"\n\n* Menu:\n\n"))
386 ;; Merge the text from the other buffer's menu
387 ;; into the menu in the like-named node in the main buffer.
388 (apply 'insert-buffer-substring
(cdr (car nodes
)))
390 (setq nodes
(cdr nodes
)))
391 ;; Kill all the buffers we just made.
393 (kill-buffer (car buffers
))
394 (setq buffers
(cdr buffers
))))
395 (setq Info-dir-contents
(buffer-string)))
396 (setq default-directory Info-dir-contents-directory
))
398 (defun Info-read-subfile (nodepos)
399 (set-buffer (marker-buffer Info-tag-table-marker
))
400 (goto-char (point-min))
401 (search-forward "\n\^_")
406 (while (not (looking-at "\^_"))
409 thisfilepos thisfilename
)
410 (search-forward ": ")
411 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
412 (setq thisfilepos
(read (current-buffer)))
413 ;; read in version 19 stops at the end of number.
414 ;; Advance to the next line.
416 (if (> thisfilepos nodepos
)
418 (setq lastfilename thisfilename
)
419 (setq lastfilepos thisfilepos
))
421 (set-buffer (get-buffer "*info*"))
422 (or (equal Info-current-subfile lastfilename
)
423 (let ((buffer-read-only nil
))
424 (setq buffer-file-name nil
)
427 (info-insert-file-contents lastfilename
)
428 (set-buffer-modified-p nil
)
429 (setq Info-current-subfile lastfilename
)))
430 (goto-char (point-min))
431 (search-forward "\n\^_")
432 (+ (- nodepos lastfilepos
) (point))))
434 ;; Select the info node that point is in.
435 (defun Info-select-node ()
437 ;; Find beginning of node.
438 (search-backward "\n\^_")
440 ;; Get nodename spelled as it is in the node.
441 (re-search-forward "Node:[ \t]*")
442 (setq Info-current-node
443 (buffer-substring (point)
445 (skip-chars-forward "^,\t\n")
448 ;; Find the end of it, and narrow.
450 (let (active-expression)
451 (narrow-to-region (point)
452 (if (re-search-forward "\n[\^_\f]" nil t
)
455 (if (looking-at "[\n\^_\f]*execute: ")
457 (goto-char (match-end 0))
458 (setq active-expression
459 (read (current-buffer))))))
461 (if Info-enable-active-nodes
(eval active-expression
)))))
463 (defun Info-set-mode-line ()
464 (setq mode-line-buffer-identification
467 (if Info-current-file
468 (file-name-nondirectory Info-current-file
)
471 (or Info-current-node
""))))
473 ;; Go to an info node specified with a filename-and-nodename string
474 ;; of the sort that is found in pointers in nodes.
476 (defun Info-goto-node (nodename)
477 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
478 (interactive "sGoto node: ")
480 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
482 (setq filename
(if (= (match-beginning 1) (match-end 1))
484 (substring nodename
(match-beginning 2) (match-end 2)))
485 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
486 (let ((trim (string-match "\\s *\\'" filename
)))
487 (if trim
(setq filename
(substring filename
0 trim
))))
488 (let ((trim (string-match "\\s *\\'" nodename
)))
489 (if trim
(setq nodename
(substring nodename
0 trim
))))
490 (Info-find-node (if (equal filename
"") nil filename
)
491 (if (equal nodename
"") "Top" nodename
))))
493 (defun Info-restore-point (hl)
494 "If this node has been visited, restore the point value when we left."
496 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
497 (equal (nth 1 (car hl
)) Info-current-node
))
498 (goto-char (nth 2 (car hl
)))
499 (Info-restore-point (cdr hl
)))))
501 (defvar Info-last-search nil
502 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
504 (defun Info-search (regexp)
505 "Search for REGEXP, starting from point, and select node it's found in."
506 (interactive "sSearch (regexp): ")
507 (if (equal regexp
"")
508 (setq regexp Info-last-search
)
509 (setq Info-last-search regexp
))
510 (let ((found ()) current
511 (onode Info-current-node
)
512 (ofile Info-current-file
)
514 (osubfile Info-current-subfile
))
518 (if (null Info-current-subfile
)
519 (progn (re-search-forward regexp
) (setq found
(point)))
521 (progn (re-search-forward regexp
) (setq found
(point)))
522 (search-failed nil
)))))
523 (if (not found
) ;can only happen in subfile case -- else would have erred
526 (set-buffer (marker-buffer Info-tag-table-marker
))
527 (goto-char (point-min))
528 (search-forward "\n\^_\nIndirect:")
530 (narrow-to-region (point)
531 (progn (search-forward "\n\^_")
533 (goto-char (point-min))
534 (search-forward (concat "\n" osubfile
": "))
537 (re-search-forward "\\(^.*\\): [0-9]+$")
538 (goto-char (+ (match-end 1) 2))
539 (setq list
(cons (cons (read (current-buffer))
540 (buffer-substring (match-beginning 1)
543 (goto-char (1+ (match-end 0))))
544 (setq list
(nreverse list
)
545 current
(car (car list
))
548 (message "Searching subfile %s..." (cdr (car list
)))
549 (Info-read-subfile (car (car list
)))
550 (setq list
(cdr list
))
551 (goto-char (point-min))
552 (if (re-search-forward regexp nil t
)
553 (setq found
(point) list
())))
556 (signal 'search-failed
(list regexp
))))
558 (progn (Info-read-subfile opoint
)
560 (Info-select-node)))))
564 (or (and (equal onode Info-current-node
)
565 (equal ofile Info-current-file
))
566 (setq Info-history
(cons (list ofile onode opoint
)
569 ;; Extract the value of the node-pointer named NAME.
570 ;; If there is none, use ERRORNAME in the error message;
571 ;; if ERRORNAME is nil, just return nil.
572 (defun Info-extract-pointer (name &optional errorname
)
574 (goto-char (point-min))
576 (if (re-search-backward (concat name
":") nil t
)
578 (goto-char (match-end 0))
579 (Info-following-node-name))
582 (error (concat "Node has no " (capitalize (or errorname name
))))))))
584 ;; Return the node name in the buffer following point.
585 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
586 ;; saying which chas may appear in the node name.
587 (defun Info-following-node-name (&optional allowedchars
)
588 (skip-chars-forward " \t")
592 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
593 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
595 (skip-chars-forward "^)")))
596 (skip-chars-backward " ")
600 "Go to the next node of this node."
602 (Info-goto-node (Info-extract-pointer "next")))
605 "Go to the previous node of this node."
607 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
610 "Go to the superior node of this node."
612 (Info-goto-node (Info-extract-pointer "up"))
613 (Info-restore-point Info-history
))
616 "Go back to the last node visited."
619 (error "This is the first Info node you looked at"))
620 (let (filename nodename opoint
)
621 (setq filename
(car (car Info-history
)))
622 (setq nodename
(car (cdr (car Info-history
))))
623 (setq opoint
(car (cdr (cdr (car Info-history
)))))
624 (setq Info-history
(cdr Info-history
))
625 (Info-find-node filename nodename
)
626 (setq Info-history
(cdr Info-history
))
629 (defun Info-directory ()
630 "Go to the Info directory node."
632 (Info-find-node "dir" "top"))
634 (defun Info-follow-reference (footnotename)
635 "Follow cross reference named NAME to the node it refers to.
636 NAME may be an abbreviation of the reference name."
638 (let ((completion-ignore-case t
)
639 completions default
(start-point (point)) str i
)
641 (goto-char (point-min))
642 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
643 (setq str
(buffer-substring
646 ;; See if this one should be the default.
648 (< (match-beginning 0) start-point
)
649 (<= start-point
(point))
652 (while (setq i
(string-match "[ \n\t]+" str i
))
653 (setq str
(concat (substring str
0 i
) " "
654 (substring str
(match-end 0))))
656 ;; Record as a completion and perhaps as default.
657 (if (eq default t
) (setq default str
))
662 (list (completing-read (if default
663 (concat "Follow reference named: ("
665 "Follow reference named: ")
666 completions default t
))
667 (error "No cross-references in this node"))))
668 (let (target beg i
(str (concat "\\*note " footnotename
)))
669 (while (setq i
(string-match " " str i
))
670 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
673 (goto-char (point-min))
674 (or (re-search-forward str nil t
)
675 (error "No cross-reference named %s" footnotename
))
676 (goto-char (+ (match-beginning 0) 5))
678 (Info-extract-menu-node-name "Bad format cross reference" t
)))
679 (while (setq i
(string-match "[ \t\n]+" target i
))
680 (setq target
(concat (substring target
0 i
) " "
681 (substring target
(match-end 0))))
683 (Info-goto-node target
)))
685 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
686 (skip-chars-forward " \t\n")
689 (skip-chars-forward "^:")
693 (buffer-substring beg
(1- (point)))
694 (skip-chars-forward " \t\n")
695 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
696 (while (setq i
(string-match "\n" str i
))
700 ;; No one calls this and Info-menu-item doesn't exist.
701 ;;(defun Info-menu-item-sequence (list)
703 ;; (Info-menu-item (car list))
704 ;; (setq list (cdr list))))
706 (defun Info-menu (menu-item)
707 "Go to node for menu item named (or abbreviated) NAME.
708 Completion is allowed, and the menu item point is on is the default."
710 (let ((completions '())
711 ;; If point is within a menu item, use that item as the default
716 (goto-char (point-min))
717 (if (not (search-forward "\n* menu:" nil t
))
718 (error "No menu in this node"))
719 (while (re-search-forward
720 "\n\\* \\([^:\t\n]*\\):" nil t
)
721 (if (and (null default
)
722 (prog1 (if last
(< last p
) nil
)
723 (setq last
(match-beginning 0)))
725 (setq default
(car (car completions
))))
726 (setq completions
(cons (cons (buffer-substring
731 (if (and (null default
) last
733 (<= p
(progn (end-of-line) (point))))
734 (setq default
(car (car completions
)))))
737 (setq item
(let ((completion-ignore-case t
))
738 (completing-read (if default
739 (format "Menu item (default %s): "
743 ;; we rely on the fact that completing-read accepts an input
744 ;; of "" even when the require-match argument is true and ""
745 ;; is not a valid possibility
746 (if (string= item
"")
752 ;; there is a problem here in that if several menu items have the same
753 ;; name you can only go to the node of the first with this command.
754 (Info-goto-node (Info-extract-menu-item menu-item
)))
756 (defun Info-extract-menu-item (menu-item)
757 (setq menu-item
(regexp-quote menu-item
))
759 (goto-char (point-min))
760 (or (search-forward "\n* menu:" nil t
)
761 (error "No menu in this node"))
762 (or (re-search-forward (concat "\n* " menu-item
":") nil t
)
763 (re-search-forward (concat "\n* " menu-item
) nil t
)
764 (error "No such item in menu"))
767 (Info-extract-menu-node-name)))
769 ;; If COUNT is nil, use the last item in the menu.
770 (defun Info-extract-menu-counting (count)
772 (goto-char (point-min))
773 (or (search-forward "\n* menu:" nil t
)
774 (error "No menu in this node"))
776 (or (search-forward "\n* " nil t count
)
777 (error "Too few items in menu"))
778 (while (search-forward "\n* " nil t
)
780 (Info-extract-menu-node-name)))
782 (defun Info-nth-menu-item ()
783 "Go to the node of the Nth menu item.
784 N is the digit argument used to invoke this command."
787 (Info-extract-menu-counting
788 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
790 (defun Info-top-node ()
791 "Go to the Top node of this file."
793 (Info-goto-node "Top"))
795 (defun Info-final-node ()
796 "Go to the final node in this file."
798 (Info-goto-node "Top")
800 ;; Go to the last node in the menu of Top.
801 (Info-goto-node (Info-extract-menu-counting nil
))
802 ;; If the last node in the menu is not last in pointer structure,
803 ;; move forward until we can't go any farther.
804 (while (Info-forward-node t t
) nil
)
805 ;; Then keep moving down to last subnode, unless we reach an index.
806 (while (and (not (string-match "\\<index\\>" Info-current-node
))
807 (save-excursion (search-forward "\n* Menu:" nil t
)))
808 (Info-goto-node (Info-extract-menu-counting nil
)))))
810 (defun Info-forward-node (&optional not-down no-error
)
811 "Go forward one node, considering all nodes as forming one sequence."
813 (goto-char (point-min))
815 ;; three possibilities, in order of priority:
816 ;; 1. next node is in a menu in this node (but not in an index)
817 ;; 2. next node is next at same level
818 ;; 3. next node is up and next
819 (cond ((and (not not-down
)
820 (save-excursion (search-forward "\n* menu:" nil t
))
821 (not (string-match "\\<index\\>" Info-current-node
)))
822 (Info-goto-node (Info-extract-menu-counting 1))
824 ((save-excursion (search-backward "next:" nil t
))
827 ((and (save-excursion (search-backward "up:" nil t
))
828 (not (equal (downcase (Info-extract-pointer "up")) "top")))
829 (let ((old-node Info-current-node
))
831 (let (Info-history success
)
833 (setq success
(Info-forward-node t no-error
))
834 (or success
(Info-goto-node old-node
))))))
836 (t (error "No pointer forward from this node"))))
838 (defun Info-backward-node ()
839 "Go backward one node, considering all nodes as forming one sequence."
841 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
842 (upnode (Info-extract-pointer "up" t
)))
843 (cond ((and upnode
(string-match "(" upnode
))
844 (error "First node in file"))
845 ((and upnode
(or (null prevnode
)
846 (equal (downcase prevnode
) (downcase upnode
))))
849 ;; If we move back at the same level,
850 ;; go down to find the last subnode*.
853 (while (and (not (string-match "\\<index\\>" Info-current-node
))
854 (save-excursion (search-forward "\n* Menu:" nil t
)))
855 (Info-goto-node (Info-extract-menu-counting nil
)))))
857 (error "No pointer backward from this node")))))
860 "Exit Info by selecting some other buffer."
862 (switch-to-buffer (prog1 (other-buffer (current-buffer))
863 (bury-buffer (current-buffer)))))
865 (defun Info-next-menu-item ()
869 (search-forward "\n* menu:" nil t
)
870 (or (search-forward "\n* " nil t
)
871 (error "No more items in menu"))
872 (Info-goto-node (Info-extract-menu-node-name))))
874 (defun Info-last-menu-item ()
878 (search-backward "\n* menu:" nil t
)
879 (or (search-backward "\n* " nil t
)
880 (error "No previous items in menu"))
881 (Info-goto-node (Info-extract-menu-node-name))))
883 (defmacro no-error
(&rest body
)
884 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
886 (defun Info-next-preorder ()
887 "Go to the next node, popping up a level if there is none."
889 (cond ((no-error (Info-next-menu-item)) )
890 ((no-error (Info-up)) (forward-line 1))
891 (t (error "No more nodes"))))
893 (defun Info-last-preorder ()
894 "Go to the last node, popping up a level if there is none."
896 (cond ((no-error (Info-last-menu-item)) )
897 ((no-error (Info-up)) (forward-line -
1))
898 (t (error "No previous nodes"))))
900 (defun Info-scroll-up ()
901 "Read the next screen. If end of buffer is visible, go to next entry."
903 (if (pos-visible-in-window-p (point-max))
908 (defun Info-scroll-down ()
909 "Read the previous screen. If start of buffer is visible, go to last entry."
911 (if (pos-visible-in-window-p (point-min))
916 (defun Info-index (topic)
917 "Look up a string in the index for this file.
918 The index is defined as the first node in the top-level menu whose
919 name contains the word \"Index\", plus any immediately following
920 nodes whose names also contain the word \"Index\".
921 If there are no exact matches to the specified topic, this chooses
922 the first match which is a case-insensitive substring of a topic.
923 Use the `,' command to see the other matches.
924 Give a blank topic name to go to the Index node itself."
925 (interactive "sIndex topic: ")
926 (let ((orignode Info-current-node
)
928 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ t]*\\([0-9]*\\)"
929 (regexp-quote topic
)))
931 (Info-goto-node "Top")
932 (or (search-forward "\n* menu:" nil t
)
934 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
936 (goto-char (match-beginning 1))
937 (let ((Info-keeping-history nil
))
938 (Info-goto-node (Info-extract-menu-node-name)))
942 (Info-keeping-history nil
)
946 (goto-char (point-min))
947 (while (re-search-forward pattern nil t
)
949 (cons (list (buffer-substring (match-beginning 1)
951 (buffer-substring (match-beginning 2)
954 (string-to-int (concat "0"
959 (and (setq node
(Info-extract-pointer "next" t
))
960 (string-match "\\<Index\\>" node
)))
961 (Info-goto-node node
))
965 (error "No \"%s\" in index" topic
)))
966 ;; Here it is a feature that assoc is case-sensitive.
967 (while (setq found
(assoc topic matches
))
968 (setq exact
(cons found exact
)
969 matches
(delq found matches
)))
970 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
971 (Info-index-next 0)))))
973 (defun Info-index-next (num)
974 "Go to the next matching index item from the last `i' command."
976 (or Info-index-alternatives
977 (error "No previous `i' command in this file"))
979 (setq num
(+ num
(length Info-index-alternatives
))))
981 (setq Info-index-alternatives
982 (nconc (cdr Info-index-alternatives
)
983 (list (car Info-index-alternatives
)))
985 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
986 (if (> (nth 3 (car Info-index-alternatives
)) 0)
987 (forward-line (nth 3 (car Info-index-alternatives
)))
988 (forward-line 3) ; don't search in headers
989 (let ((name (car (car Info-index-alternatives
))))
990 (if (or (re-search-forward (format
991 "\\(Function\\|Command\\): %s\\( \\|$\\)"
992 (regexp-quote name
)) nil t
)
993 (search-forward (format "`%s'" name
) nil t
)
994 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
996 (format "`%s'" (substring name
0 (match-beginning 1)))
998 (search-forward name nil t
))
1000 (goto-char (point-min)))))
1001 (message "Found \"%s\" in %s. %s"
1002 (car (car Info-index-alternatives
))
1003 (nth 2 (car Info-index-alternatives
))
1004 (if (cdr Info-index-alternatives
)
1005 "(Press `,' for more)"
1008 (defun Info-undefined ()
1009 "Make command be undefined in Info."
1014 "Enter the Info tutorial."
1016 (delete-other-windows)
1017 (Info-find-node "info"
1018 (if (< (window-height) 23)
1022 (defun Info-summary ()
1023 "Display a brief summary of all Info commands."
1025 (save-window-excursion
1026 (switch-to-buffer "*Help*")
1028 (insert (documentation 'Info-mode
))
1029 (goto-char (point-min))
1031 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
1032 (message (if flag
"Type Space to see more"
1033 "Type Space to return to Info"))
1034 (if (not (eq ?\
(setq ch
(read-event))))
1035 (progn (setq unread-command-events
(list ch
)) nil
)
1039 (defun Info-get-token (pos start all
&optional errorstring
)
1040 "Return the token around POS,
1041 POS must be somewhere inside the token
1042 START is a regular expression which will match the
1043 beginning of the tokens delimited string
1044 ALL is a regular expression with a single
1045 parenthized subpattern which is the token to be
1046 returned. E.g. '{\(.*\)}' would return any string
1047 enclosed in braces around POS.
1048 SIG optional fourth argument, controls action on no match
1051 a string: signal an error, using that string."
1054 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)
1056 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
1057 (not (setq found
(and (<= (match-beginning 0) pos
)
1058 (> (match-end 0) pos
))))))
1059 (if (and found
(<= (match-beginning 0) pos
)
1060 (> (match-end 0) pos
))
1061 (buffer-substring (match-beginning 1) (match-end 1))
1062 (cond ((null errorstring
)
1068 (error "No %s around position %d" errorstring pos
)))))))
1070 (defun Info-follow-nearest-node (click)
1071 "\\<Info-mode-map>Follow a node reference near point.
1072 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1073 At end of the node's text, moves to the next node."
1075 (let* ((start (event-start click
))
1076 (window (car start
))
1077 (pos (car (cdr start
))))
1078 (select-window window
)
1082 ((setq node
(Info-get-token (point) "\\*note[ \n]" "\\*note[ \n]\\([^:]*\\):"))
1083 (Info-follow-reference node
))
1084 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1085 (Info-goto-node node
))
1086 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1088 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1089 (Info-goto-node node
))
1090 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1091 (Info-goto-node node
))
1092 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1093 (Info-goto-node "Top"))
1094 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1095 (Info-goto-node node
))
1096 ((save-excursion (forward-line 1) (eobp))
1100 (defvar Info-mode-map nil
1101 "Keymap containing Info commands.")
1104 (setq Info-mode-map
(make-keymap))
1105 (suppress-keymap Info-mode-map
)
1106 (define-key Info-mode-map
"." 'beginning-of-buffer
)
1107 (define-key Info-mode-map
" " 'Info-scroll-up
)
1108 (define-key Info-mode-map
"\C-m" 'Info-next-preorder
)
1109 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
1110 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
1111 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
1112 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
1113 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
1114 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
1115 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
1116 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
1117 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
1118 (define-key Info-mode-map
"0" 'undefined
)
1119 (define-key Info-mode-map
"?" 'Info-summary
)
1120 (define-key Info-mode-map
"]" 'Info-forward-node
)
1121 (define-key Info-mode-map
"[" 'Info-backward-node
)
1122 (define-key Info-mode-map
"<" 'Info-top-node
)
1123 (define-key Info-mode-map
">" 'Info-final-node
)
1124 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
1125 (define-key Info-mode-map
"d" 'Info-directory
)
1126 (define-key Info-mode-map
"e" 'Info-edit
)
1127 (define-key Info-mode-map
"f" 'Info-follow-reference
)
1128 (define-key Info-mode-map
"g" 'Info-goto-node
)
1129 (define-key Info-mode-map
"h" 'Info-help
)
1130 (define-key Info-mode-map
"i" 'Info-index
)
1131 (define-key Info-mode-map
"l" 'Info-last
)
1132 (define-key Info-mode-map
"m" 'Info-menu
)
1133 (define-key Info-mode-map
"n" 'Info-next
)
1134 (define-key Info-mode-map
"p" 'Info-prev
)
1135 (define-key Info-mode-map
"q" 'Info-exit
)
1136 (define-key Info-mode-map
"s" 'Info-search
)
1137 (define-key Info-mode-map
"t" 'Info-top-node
)
1138 (define-key Info-mode-map
"u" 'Info-up
)
1139 (define-key Info-mode-map
"," 'Info-index-next
)
1140 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
1141 (define-key Info-mode-map
[mouse-3
] 'Info-follow-nearest-node
)
1144 ;; Info mode is suitable only for specially formatted data.
1145 (put 'info-mode
'mode-class
'special
)
1149 Info mode provides commands for browsing through the Info documentation tree.
1150 Documentation in Info is divided into \"nodes\", each of which discusses
1151 one topic and contains references to other nodes which discuss related
1152 topics. Info has commands to follow the references and show you other nodes.
1154 \\[Info-help] Invoke the Info tutorial.
1156 Selecting other nodes:
1157 \\[Info-next] Move to the \"next\" node of this node.
1158 \\[Info-prev] Move to the \"previous\" node of this node.
1159 \\[Info-up] Move \"up\" from this node.
1160 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1161 Picking a menu item causes another node to be selected.
1162 \\[Info-directory] Go to the Info directory node.
1163 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1164 \\[Info-last] Move to the last node you were at.
1165 \\[Info-index] Look up a topic in this file's Index and move to that node.
1166 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1168 Moving within a node:
1169 \\[scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1170 already visible, try to go to the next menu entry, or up if there is none.
1171 \\[scroll-down] Normally, scroll backward. If the beginning of the buffer is
1172 already visible, try to go to the previous menu entry, or up if there is none.
1173 \\[beginning-of-buffer] Go to beginning of node.
1176 \\[Info-exit] Quit Info: reselect previously selected buffer.
1177 \\[Info-edit] Edit contents of selected node.
1178 1 Pick first item in node's menu.
1179 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1180 \\[Info-goto-node] Move to node specified by name.
1181 You may include a filename as well, as (FILENAME)NODENAME.
1182 \\[Info-search] Search through this Info file for specified regexp,
1183 and select the node in which the next occurrence is found.
1184 \\[Info-next-preorder] Next-preorder; that is, try to go to the next menu item,
1185 and if that fails try to move up, and if that fails, tell user
1186 he/she is done reading."
1187 (kill-all-local-variables)
1188 (setq major-mode
'Info-mode
)
1189 (setq mode-name
"Info")
1190 (use-local-map Info-mode-map
)
1191 (set-syntax-table text-mode-syntax-table
)
1192 (setq local-abbrev-table text-mode-abbrev-table
)
1193 (setq case-fold-search t
)
1194 (setq buffer-read-only t
)
1195 (make-local-variable 'Info-current-file
)
1196 (make-local-variable 'Info-current-subfile
)
1197 (make-local-variable 'Info-current-node
)
1198 (make-local-variable 'Info-tag-table-marker
)
1199 (make-local-variable 'Info-history
)
1200 (make-local-variable 'Info-index-alternatives
)
1201 (Info-set-mode-line)
1202 (run-hooks 'Info-mode-hook
))
1204 (defvar Info-edit-map nil
1205 "Local keymap used within `e' command of Info.")
1208 (setq Info-edit-map
(nconc (make-sparse-keymap) text-mode-map
))
1209 (define-key Info-edit-map
"\C-c\C-c" 'Info-cease-edit
))
1211 ;; Info-edit mode is suitable only for specially formatted data.
1212 (put 'info-edit-mode
'mode-class
'special
)
1214 (defun Info-edit-mode ()
1215 "Major mode for editing the contents of an Info node.
1216 Like text mode with the addition of `Info-cease-edit'
1217 which returns to Info mode for browsing.
1222 "Edit the contents of this Info node.
1223 Allowed only if variable `Info-enable-edit' is non-nil."
1225 (or Info-enable-edit
1226 (error "Editing info nodes is not enabled"))
1227 (use-local-map Info-edit-map
)
1228 (setq major-mode
'Info-edit-mode
)
1229 (setq mode-name
"Info Edit")
1230 (kill-local-variable 'mode-line-buffer-identification
)
1231 (setq buffer-read-only nil
)
1232 ;; Make mode line update.
1233 (set-buffer-modified-p (buffer-modified-p))
1234 (message (substitute-command-keys
1235 "Editing: Type \\<Info-mode-map>\\[Info-cease-edit] to return to info")))
1237 (defun Info-cease-edit ()
1238 "Finish editing Info node; switch back to Info proper."
1240 ;; Do this first, so nothing has changed if user C-g's at query.
1241 (and (buffer-modified-p)
1242 (y-or-n-p "Save the file? ")
1244 (use-local-map Info-mode-map
)
1245 (setq major-mode
'Info-mode
)
1246 (setq mode-name
"Info")
1247 (Info-set-mode-line)
1248 (setq buffer-read-only t
)
1249 ;; Make mode line update.
1250 (set-buffer-modified-p (buffer-modified-p))
1251 (and (marker-position Info-tag-table-marker
)
1253 (message "Tags may have changed. Use Info-tagify if necessary")))
1255 (defun Info-find-emacs-command-nodes (command)
1256 "Return a list of locations documenting COMMAND in the Emacs Info manual.
1257 The locations are of the format used in Info-history, i.e.
1258 \(FILENAME NODENAME BUFFERPOS\)."
1261 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command
))
1262 ":\\s *\\(.*\\)\\.$")))
1264 (Info-find-node "emacs" "Command Index")
1265 ;; Take the index node off the Info history.
1266 (setq Info-history
(cdr Info-history
))
1267 (goto-char (point-max))
1268 (while (re-search-backward cmd-desc nil t
)
1269 (setq where
(cons (list Info-current-file
1278 (defun Info-goto-emacs-command-node (command)
1279 "Go to the Info node in the Emacs manual for command COMMAND."
1280 (interactive "CFind documentation for command: ")
1281 (or (commandp command
)
1282 (signal 'wrong-type-argument
(list 'commandp command
)))
1283 (let ((where (Info-find-emacs-command-nodes command
)))
1285 (let ((num-matches (length where
)))
1286 ;; Get Info running, and pop to it in another window.
1287 (save-window-excursion
1289 (pop-to-buffer "*info*")
1290 (Info-find-node (car (car where
))
1291 (car (cdr (car where
))))
1292 (if (> num-matches
1)
1294 ;; Info-find-node already pushed (car where) onto
1295 ;; Info-history. Put the other nodes that were found on
1297 (setq Info-history
(nconc (cdr where
) Info-history
))
1298 (message (substitute-command-keys
1299 "Found %d other entr%. Use \\[Info-last] to see %s."
1301 (if (> num-matches
2) "ies" "y")
1302 (if (> num-matches
2) "them" "it"))))))
1303 (error "Couldn't find documentation for %s." command
))))
1306 (defun Info-goto-emacs-key-command-node (key)
1307 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1308 Interactively, if the binding is execute-extended-command, a command is read."
1309 (interactive "kFind documentation for key:")
1310 (let ((command (key-binding key
)))
1311 (cond ((null command
)
1312 (message "%s is undefined" (key-description key
)))
1313 ((and (interactive-p)
1314 (eq command
'execute-extended-command
))
1315 (Info-goto-emacs-command-node
1316 (read-command "Find documentation for command: ")))
1318 (Info-goto-emacs-command-node command
)))))
1322 ;;; info.el ends here