1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994 Free Software Foundation, Inc.
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;;; Note that nowadays we expect info files to be made using makeinfo.
30 (defvar Info-history nil
31 "List of info nodes user has visited.
32 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
34 (defvar Info-enable-edit nil
35 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
36 This is convenient if you want to write info files by hand.
37 However, we recommend that you not do this.
38 It is better to write a Texinfo file and generate the Info file from that,
39 because that gives you a printed manual as well.")
41 (defvar Info-enable-active-nodes t
42 "Non-nil allows Info to execute Lisp code associated with nodes.
43 The Lisp code is executed when the node is selected.")
45 (defvar Info-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-fontify t
51 "*Non-nil enables highlighting and fonts in Info nodes.")
53 (defvar Info-fontify-maximum-menu-size
30000
54 "*Maximum size of menu to fontify if `Info-fontify' is non-nil.")
56 (defvar Info-directory-list
57 (let ((path (getenv "INFOPATH"))
58 (sep (if (or (eq system-type
'ms-dos
)
59 (eq system-type
'windows-nt
))
61 (sibling (expand-file-name "../info/" (invocation-directory))))
65 (while (> (length path
) 0)
66 (setq idx
(or (string-match sep path
) (length path
))
67 list
(cons (substring path
0 idx
) list
)
68 path
(substring path
(min (1+ idx
)
71 (if (or (member sibling Info-default-directory-list
)
72 (not (file-exists-p sibling
))
73 ;; On DOS/NT, we use movable executables always,
74 ;; and we must always find the Info dir at run time.
75 (if (or (eq system-type
'ms-dos
) (eq system-type
'windows-nt
))
77 ;; Use invocation-directory for Info only if we used it for
78 ;; exec-directory also.
79 (not (string= exec-directory
80 (expand-file-name "../lib-src/"
81 (invocation-directory))))))
82 Info-default-directory-list
83 (reverse (cons sibling
(cdr (reverse Info-default-directory-list
)))))))
84 "List of directories to search for Info documentation files.
85 nil means not yet initialized. In this case, Info uses the environment
86 variable INFOPATH to initialize it, or `Info-default-directory-list'
87 if there is no INFOPATH variable in the environment.
88 The last element of `Info-default-directory-list' is the directory
89 where Emacs installs the Info files that come with it.
91 If you run the Emacs executable from the `src' directory in the Emacs
92 source tree, the `info' directory in the source tree is used as the last
93 element, in place of the installation Info directory. This is useful
94 when you run a version of Emacs without installing it.")
96 (defvar Info-additional-directory-list nil
97 "List of additional directories to search for Info documentation files.
98 These directories are not searched for merging the `dir' file.")
100 (defvar Info-current-file nil
101 "Info file that Info is now looking at, or nil.")
103 (defvar Info-current-subfile nil
104 "Info subfile that is actually in the *info* buffer now,
105 or nil if current info file is not split into subfiles.")
107 (defvar Info-current-node nil
108 "Name of node that Info is now looking at, or nil.")
110 (defvar Info-tag-table-marker
(make-marker)
111 "Marker pointing at beginning of current Info file's tag table.
112 Marker points nowhere if file has no tag table.")
114 (defvar Info-current-file-completions nil
115 "Cached completion list for current Info file.")
117 (defvar Info-index-alternatives nil
118 "List of possible matches for last Info-index command.")
120 (defvar Info-standalone nil
121 "Non-nil if Emacs was started solely as an Info browser.")
123 (defvar Info-suffix-list
'( (".info.Z" .
"uncompress")
124 (".info.Y" .
"unyabba")
125 (".info.gz" .
"gunzip")
126 (".info.z" .
"gunzip")
128 (".Z" .
"uncompress")
133 "List of file name suffixes and associated decoding commands.
134 Each entry should be (SUFFIX . STRING); the file is given to
135 the command as standard input. If STRING is nil, no decoding is done.
136 Because the SUFFIXes are tried in order, the empty string should
137 be last in the list.")
139 (defun info-insert-file-contents (filename &optional visit
)
140 "Insert the contents of an info file in the current buffer.
141 Do the right thing if the file has been compressed or zipped."
142 (let ((tail Info-suffix-list
)
144 (if (file-exists-p filename
)
148 (concat (regexp-quote (car (car tail
))) "$")
150 (setq tail
(cdr tail
)))
151 (setq fullname filename
152 decoder
(cdr (car tail
))))
154 (not (file-exists-p (concat filename
(car (car tail
))))))
155 (setq tail
(cdr tail
)))
156 (setq fullname
(concat filename
(car (car tail
)))
157 decoder
(cdr (car tail
)))
159 (error "Can't find %s or any compressed version of it!" filename
)))
160 ;; check for conflict with jka-compr
161 (if (and (featurep 'jka-compr
)
162 (jka-compr-installed-p)
163 (jka-compr-get-compression-info fullname
))
165 (insert-file-contents fullname visit
)
167 (let ((buffer-read-only nil
))
168 (shell-command-on-region (point-min) (point-max) decoder t
)))))
171 (defun info (&optional file
)
172 "Enter Info, the documentation browser.
173 Optional argument FILE specifies the file to examine;
174 the default is the top-level directory of Info.
176 In interactive use, a prefix argument directs this command
177 to read a file name from the minibuffer."
178 (interactive (if current-prefix-arg
179 (list (read-file-name "Info file name: " nil nil t
))))
181 (Info-goto-node (concat "(" file
")"))
182 (if (get-buffer "*info*")
183 (switch-to-buffer "*info*")
187 (defun info-standalone ()
188 "Run Emacs as a standalone Info reader.
189 Usage: emacs -f info-standalone [filename]
190 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
191 (setq Info-standalone t
)
192 (if (and command-line-args-left
193 (not (string-match "^-" (car command-line-args-left
))))
196 (info (car command-line-args-left
))
197 (setq command-line-args-left
(cdr command-line-args-left
)))
198 (error (send-string-to-terminal
199 (format "%s\n" (if (eq (car-safe err
) 'error
)
201 (save-buffers-kill-emacs)))
204 ;; Go to an info node specified as separate filename and nodename.
205 ;; no-going-back is non-nil if recovering from an error in this function;
206 ;; it says do not attempt further (recursive) error recovery.
207 (defun Info-find-node (filename nodename
&optional no-going-back
)
208 ;; Convert filename to lower case if not found as specified.
211 (let (temp temp-downcase found
)
212 (setq filename
(substitute-in-file-name filename
))
213 (if (string= (downcase (file-name-nondirectory filename
)) "dir")
215 (let ((dirs (if (string-match "^\\./" filename
)
216 ;; If specified name starts with `./'
217 ;; then just try current directory.
219 (if (file-name-absolute-p filename
)
220 ;; No point in searching for an
221 ;; absolute file name
223 (if Info-additional-directory-list
224 (append Info-directory-list
225 Info-additional-directory-list
)
226 Info-directory-list
)))))
227 ;; Search the directory list for file FILENAME.
228 (while (and dirs
(not found
))
229 (setq temp
(expand-file-name filename
(car dirs
)))
231 (expand-file-name (downcase filename
) (car dirs
)))
232 ;; Try several variants of specified name.
233 (let ((suffix-list Info-suffix-list
))
234 (while (and suffix-list
(not found
))
235 (cond ((file-exists-p
236 (concat temp
(car (car suffix-list
))))
239 (concat temp-downcase
(car (car suffix-list
))))
240 (setq found temp-downcase
)))
241 (setq suffix-list
(cdr suffix-list
))))
242 (setq dirs
(cdr dirs
)))))
244 (setq filename found
)
245 (error "Info file %s does not exist" filename
))))
246 ;; Record the node we are leaving.
247 (if (and Info-current-file
(not no-going-back
))
249 (cons (list Info-current-file Info-current-node
(point))
251 ;; Go into info buffer.
252 (switch-to-buffer "*info*")
253 (buffer-disable-undo (current-buffer))
254 (or (eq major-mode
'Info-mode
)
257 (setq Info-current-node nil
)
260 ;; Switch files if necessary
262 (equal Info-current-file filename
)
263 (let ((buffer-read-only nil
))
264 (setq Info-current-file nil
265 Info-current-subfile nil
266 Info-current-file-completions nil
267 Info-index-alternatives nil
268 buffer-file-name nil
)
272 (info-insert-file-contents filename t
)
273 (setq default-directory
(file-name-directory filename
)))
274 (set-buffer-modified-p nil
)
275 ;; See whether file has a tag table. Record the location if yes.
276 (set-marker Info-tag-table-marker nil
)
277 (goto-char (point-max))
279 (or (equal nodename
"*")
280 (not (search-forward "\^_\nEnd tag table\n" nil t
))
282 ;; We have a tag table. Find its beginning.
283 ;; Is this an indirect file?
284 (search-backward "\nTag table:\n")
288 (looking-at "(Indirect)\n"))
289 ;; It is indirect. Copy it to another buffer
290 ;; and record that the tag table is in that buffer.
292 (let ((buf (current-buffer)))
293 (set-buffer (get-buffer-create " *info tag table*"))
294 (buffer-disable-undo (current-buffer))
295 (setq case-fold-search t
)
297 (insert-buffer-substring buf
)
298 (set-marker Info-tag-table-marker
300 (set-marker Info-tag-table-marker pos
))))
301 (setq Info-current-file
302 (if (eq filename t
) "dir"
303 (file-name-sans-versions buffer-file-name
)))))
304 (if (equal nodename
"*")
305 (progn (setq Info-current-node nodename
)
306 (Info-set-mode-line))
307 ;; Search file for a suitable node.
308 (let ((guesspos (point-min))
309 (regexp (concat "Node: *" (regexp-quote nodename
) " *[,\t\n\177]")))
310 ;; First get advice from tag table if file has one.
311 ;; Also, if this is an indirect info file,
312 ;; read the proper subfile into this buffer.
313 (if (marker-position Info-tag-table-marker
)
315 (set-buffer (marker-buffer Info-tag-table-marker
))
316 (goto-char Info-tag-table-marker
)
317 (if (re-search-forward regexp nil t
)
319 (setq guesspos
(read (current-buffer)))
320 ;; If this is an indirect file,
321 ;; determine which file really holds this node
323 (if (not (eq (current-buffer) (get-buffer "*info*")))
325 (Info-read-subfile guesspos
))))
326 (error "No such node: \"%s\"" nodename
))))
327 (goto-char (max (point-min) (- guesspos
1000)))
328 ;; Now search from our advised position (or from beg of buffer)
329 ;; to find the actual node.
331 (while (search-forward "\n\^_" nil t
)
335 (if (re-search-backward regexp beg t
)
337 (error "No such node: %s" nodename
)))
339 ;; If we did not finish finding the specified node,
340 ;; go back to the previous one.
341 (or Info-current-node no-going-back
(null Info-history
)
342 (let ((hist (car Info-history
)))
343 (setq Info-history
(cdr Info-history
))
344 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
345 (goto-char (nth 2 hist
)))))
346 (goto-char (point-min)))
348 ;; Cache the contents of the (virtual) dir file, once we have merged
349 ;; it for the first time, so we can save time subsequently.
350 (defvar Info-dir-contents nil
)
352 ;; Cache for the directory we decided to use for the default-directory
353 ;; of the merged dir text.
354 (defvar Info-dir-contents-directory nil
)
356 ;; Record the file attributes of all the files from which we
357 ;; constructed Info-dir-contents.
358 (defvar Info-dir-file-attributes nil
)
360 ;; Construct the Info directory node by merging the files named `dir'
361 ;; from various directories. Set the *info* buffer's
362 ;; default-directory to the first directory we actually get any text
364 (defun Info-insert-dir ()
365 (if (and Info-dir-contents Info-dir-file-attributes
366 ;; Verify that none of the files we used has changed
369 (mapcar '(lambda (elt)
370 (let ((curr (file-attributes (car elt
))))
371 ;; Don't compare the access time.
372 (if curr
(setcar (nthcdr 4 curr
) 0))
373 (setcar (nthcdr 4 (cdr elt
)) 0)
374 (equal (cdr elt
) curr
)))
375 Info-dir-file-attributes
))))
376 (insert Info-dir-contents
)
377 (let ((dirs Info-directory-list
)
378 buffers buffer others nodes dirs-done
)
380 (setq Info-dir-file-attributes nil
)
382 ;; Search the directory list for the directory file.
384 (let ((truename (file-truename (expand-file-name (car dirs
)))))
385 (or (member truename dirs-done
)
386 (member (directory-file-name truename
) dirs-done
)
387 ;; Try several variants of specified name.
388 ;; Try upcasing, appending `.info', or both.
392 (progn (setq file
(expand-file-name "dir" truename
))
393 (file-attributes file
))
394 (progn (setq file
(expand-file-name "DIR" truename
))
395 (file-attributes file
))
396 (progn (setq file
(expand-file-name "dir.info" truename
))
397 (file-attributes file
))
398 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
399 (file-attributes file
)))))
402 (cons (directory-file-name truename
)
407 (message "Composing main Info directory..."))
408 (set-buffer (generate-new-buffer "info dir"))
409 (insert-file-contents file
)
410 (setq buffers
(cons (current-buffer) buffers
)
411 Info-dir-file-attributes
412 (cons (cons file attrs
)
413 Info-dir-file-attributes
))))))
414 (setq dirs
(cdr dirs
))))
417 (error "Can't find the info directory node"))
418 ;; Distinguish the dir file that comes with Emacs from all the
419 ;; others. Yes, that is really what this is supposed to do.
420 ;; If it doesn't work, fix it.
421 (setq buffer
(car buffers
)
422 others
(cdr buffers
))
424 ;; Insert the entire original dir file as a start; use its
425 ;; default directory as the default directory for the whole
427 (insert-buffer buffer
)
428 (setq Info-dir-contents-directory
(save-excursion
432 ;; Look at each of the other buffers one by one.
434 (let ((other (car others
)))
435 ;; In each, find all the menus.
438 (goto-char (point-min))
439 ;; Find each menu, and add an elt to NODES for it.
440 (while (re-search-forward "^\\* Menu:" nil t
)
441 (let (beg nodename end
)
444 (search-backward "\n\^_")
445 (search-forward "Node: ")
446 (setq nodename
(Info-following-node-name))
447 (search-forward "\n\^_" nil
'move
)
450 (setq nodes
(cons (list nodename other beg end
) nodes
))))))
451 (setq others
(cdr others
)))
452 ;; Add to the main menu a menu item for each other node.
453 (re-search-forward "^\\* Menu:")
455 (let ((menu-items '("top"))
458 (end (save-excursion (search-forward "\^_" nil t
) (point))))
460 (let ((nodename (car (car nodes
))))
462 (or (member (downcase nodename
) menu-items
)
463 (re-search-forward (concat "^\\* "
464 (regexp-quote nodename
)
468 (insert "* " nodename
"::" "\n")
469 (setq menu-items
(cons nodename menu-items
))))))
470 (setq nodes
(cdr nodes
))))
471 ;; Now take each node of each of the other buffers
472 ;; and merge it into the main buffer.
474 (let ((nodename (car (car nodes
))))
475 (goto-char (point-min))
476 ;; Find the like-named node in the main buffer.
477 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
478 (regexp-quote nodename
)
482 (search-forward "\n\^_" nil
'move
)
485 ;; If none exists, add one.
486 (goto-char (point-max))
487 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
488 ;; Merge the text from the other buffer's menu
489 ;; into the menu in the like-named node in the main buffer.
490 (apply 'insert-buffer-substring
(cdr (car nodes
))))
491 (setq nodes
(cdr nodes
)))
492 ;; Kill all the buffers we just made.
494 (kill-buffer (car buffers
))
495 (setq buffers
(cdr buffers
)))
496 (message "Composing main Info directory...done"))
497 (setq Info-dir-contents
(buffer-string)))
498 (setq default-directory Info-dir-contents-directory
))
500 (defun Info-read-subfile (nodepos)
501 (set-buffer (marker-buffer Info-tag-table-marker
))
502 (goto-char (point-min))
503 (search-forward "\n\^_")
508 (while (not (looking-at "\^_"))
511 thisfilepos thisfilename
)
512 (search-forward ": ")
513 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
514 (setq thisfilepos
(read (current-buffer)))
515 ;; read in version 19 stops at the end of number.
516 ;; Advance to the next line.
518 (if (> thisfilepos nodepos
)
520 (setq lastfilename thisfilename
)
521 (setq lastfilepos thisfilepos
))
523 (set-buffer (get-buffer "*info*"))
524 (or (equal Info-current-subfile lastfilename
)
525 (let ((buffer-read-only nil
))
526 (setq buffer-file-name nil
)
529 (info-insert-file-contents lastfilename
)
530 (set-buffer-modified-p nil
)
531 (setq Info-current-subfile lastfilename
)))
532 (goto-char (point-min))
533 (search-forward "\n\^_")
534 (+ (- nodepos lastfilepos
) (point))))
536 ;; Select the info node that point is in.
537 (defun Info-select-node ()
539 ;; Find beginning of node.
540 (search-backward "\n\^_")
542 ;; Get nodename spelled as it is in the node.
543 (re-search-forward "Node:[ \t]*")
544 (setq Info-current-node
545 (buffer-substring (point)
547 (skip-chars-forward "^,\t\n")
550 ;; Find the end of it, and narrow.
552 (let (active-expression)
553 (narrow-to-region (point)
554 (if (re-search-forward "\n[\^_\f]" nil t
)
557 (if (looking-at "[\n\^_\f]*execute: ")
559 (goto-char (match-end 0))
560 (setq active-expression
561 (read (current-buffer))))))
563 (if Info-enable-active-nodes
(eval active-expression
))
564 (if Info-fontify
(Info-fontify-node))
565 (run-hooks 'Info-selection-hook
))))
567 (defun Info-set-mode-line ()
568 (setq mode-line-buffer-identification
571 (if Info-current-file
572 (file-name-nondirectory Info-current-file
)
575 (or Info-current-node
""))))
577 ;; Go to an info node specified with a filename-and-nodename string
578 ;; of the sort that is found in pointers in nodes.
580 (defun Info-goto-node (nodename)
581 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
582 (interactive (list (Info-read-node-name "Goto node: ")))
584 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
586 (setq filename
(if (= (match-beginning 1) (match-end 1))
588 (substring nodename
(match-beginning 2) (match-end 2)))
589 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
590 (let ((trim (string-match "\\s *\\'" filename
)))
591 (if trim
(setq filename
(substring filename
0 trim
))))
592 (let ((trim (string-match "\\s *\\'" nodename
)))
593 (if trim
(setq nodename
(substring nodename
0 trim
))))
594 (Info-find-node (if (equal filename
"") nil filename
)
595 (if (equal nodename
"") "Top" nodename
))))
597 (defun Info-read-node-name (prompt &optional default
)
598 (let* ((completion-ignore-case t
)
599 (nodename (completing-read prompt
(Info-build-node-completions))))
600 (if (equal nodename
"")
602 (Info-read-node-name prompt
))
605 (defun Info-build-node-completions ()
606 (or Info-current-file-completions
610 (if (marker-buffer Info-tag-table-marker
)
612 (set-buffer (marker-buffer Info-tag-table-marker
))
614 (goto-char Info-tag-table-marker
)
615 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t
)
617 (cons (list (buffer-substring (match-beginning 1)
621 (goto-char (point-min))
622 (while (search-forward "\n\^_" nil t
)
626 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
629 (cons (list (buffer-substring (match-beginning 1)
632 (setq Info-current-file-completions compl
))))
634 (defun Info-restore-point (hl)
635 "If this node has been visited, restore the point value when we left."
637 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
638 (equal (nth 1 (car hl
)) Info-current-node
))
640 (goto-char (nth 2 (car hl
)))
641 (setq hl nil
)) ;terminate the while at next iter
642 (setq hl
(cdr hl
)))))
644 (defvar Info-last-search nil
645 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
647 (defun Info-search (regexp)
648 "Search for REGEXP, starting from point, and select node it's found in."
649 (interactive "sSearch (regexp): ")
650 (if (equal regexp
"")
651 (setq regexp Info-last-search
)
652 (setq Info-last-search regexp
))
653 (let ((found ()) current
654 (onode Info-current-node
)
655 (ofile Info-current-file
)
657 (osubfile Info-current-subfile
))
661 (if (null Info-current-subfile
)
662 (progn (re-search-forward regexp
) (setq found
(point)))
664 (progn (re-search-forward regexp
) (setq found
(point)))
665 (search-failed nil
)))))
666 (if (not found
) ;can only happen in subfile case -- else would have erred
669 (set-buffer (marker-buffer Info-tag-table-marker
))
670 (goto-char (point-min))
671 (search-forward "\n\^_\nIndirect:")
673 (narrow-to-region (point)
674 (progn (search-forward "\n\^_")
676 (goto-char (point-min))
677 (search-forward (concat "\n" osubfile
": "))
680 (re-search-forward "\\(^.*\\): [0-9]+$")
681 (goto-char (+ (match-end 1) 2))
682 (setq list
(cons (cons (read (current-buffer))
683 (buffer-substring (match-beginning 1)
686 (goto-char (1+ (match-end 0))))
687 (setq list
(nreverse list
)
688 current
(car (car list
))
691 (message "Searching subfile %s..." (cdr (car list
)))
692 (Info-read-subfile (car (car list
)))
693 (setq list
(cdr list
))
694 ;; (goto-char (point-min))
695 (if (re-search-forward regexp nil t
)
696 (setq found
(point) list
())))
699 (signal 'search-failed
(list regexp
))))
701 (progn (Info-read-subfile opoint
)
703 (Info-select-node)))))
707 (or (and (equal onode Info-current-node
)
708 (equal ofile Info-current-file
))
709 (setq Info-history
(cons (list ofile onode opoint
)
712 ;; Extract the value of the node-pointer named NAME.
713 ;; If there is none, use ERRORNAME in the error message;
714 ;; if ERRORNAME is nil, just return nil.
715 (defun Info-extract-pointer (name &optional errorname
)
717 (goto-char (point-min))
719 (if (re-search-backward (concat name
":") nil t
)
721 (goto-char (match-end 0))
722 (Info-following-node-name))
725 (error (concat "Node has no " (capitalize (or errorname name
))))))))
727 ;; Return the node name in the buffer following point.
728 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
729 ;; saying which chas may appear in the node name.
730 (defun Info-following-node-name (&optional allowedchars
)
731 (skip-chars-forward " \t")
735 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
736 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
738 (skip-chars-forward "^)")))
739 (skip-chars-backward " ")
743 "Go to the next node of this node."
745 (Info-goto-node (Info-extract-pointer "next")))
748 "Go to the previous node of this node."
750 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
753 "Go to the superior node of this node."
755 (Info-goto-node (Info-extract-pointer "up"))
756 (Info-restore-point Info-history
))
759 "Go back to the last node visited."
762 (error "This is the first Info node you looked at"))
763 (let (filename nodename opoint
)
764 (setq filename
(car (car Info-history
)))
765 (setq nodename
(car (cdr (car Info-history
))))
766 (setq opoint
(car (cdr (cdr (car Info-history
)))))
767 (setq Info-history
(cdr Info-history
))
768 (Info-find-node filename nodename
)
769 (setq Info-history
(cdr Info-history
))
772 (defun Info-directory ()
773 "Go to the Info directory node."
775 (Info-find-node "dir" "top"))
777 (defun Info-follow-reference (footnotename)
778 "Follow cross reference named NAME to the node it refers to.
779 NAME may be an abbreviation of the reference name."
781 (let ((completion-ignore-case t
)
782 completions default alt-default
(start-point (point)) str i bol eol
)
784 ;; Store end and beginning of line.
790 (goto-char (point-min))
791 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
792 (setq str
(buffer-substring
795 ;; See if this one should be the default.
797 (<= (match-beginning 0) start-point
)
798 (<= start-point
(point))
800 ;; See if this one should be the alternate default.
801 (and (null alt-default
)
802 (and (<= bol
(match-beginning 0))
804 (setq alt-default t
))
806 (while (setq i
(string-match "[ \n\t]+" str i
))
807 (setq str
(concat (substring str
0 i
) " "
808 (substring str
(match-end 0))))
810 ;; Record as a completion and perhaps as default.
811 (if (eq default t
) (setq default str
))
812 (if (eq alt-default t
) (setq alt-default str
))
816 ;; If no good default was found, try an alternate.
818 (setq default alt-default
))
819 ;; If only one cross-reference found, then make it default.
820 (if (eq (length completions
) 1)
821 (setq default
(car (car completions
))))
823 (let ((input (completing-read (if default
824 (concat "Follow reference named: ("
826 "Follow reference named: ")
828 (list (if (equal input
"")
830 (error "No cross-references in this node"))))
831 (let (target beg i
(str (concat "\\*note " (regexp-quote footnotename
))))
832 (while (setq i
(string-match " " str i
))
833 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
836 (goto-char (point-min))
837 (or (re-search-forward str nil t
)
838 (error "No cross-reference named %s" footnotename
))
839 (goto-char (+ (match-beginning 0) 5))
841 (Info-extract-menu-node-name "Bad format cross reference" t
)))
842 (while (setq i
(string-match "[ \t\n]+" target i
))
843 (setq target
(concat (substring target
0 i
) " "
844 (substring target
(match-end 0))))
846 (Info-goto-node target
)))
848 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
849 (skip-chars-forward " \t\n")
852 (skip-chars-forward "^:")
856 (buffer-substring beg
(1- (point)))
857 (skip-chars-forward " \t\n")
858 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
859 (while (setq i
(string-match "\n" str i
))
863 ;; No one calls this.
864 ;;(defun Info-menu-item-sequence (list)
866 ;; (Info-menu (car list))
867 ;; (setq list (cdr list))))
869 (defun Info-complete-menu-item (string predicate action
)
870 (let ((case-fold-search t
))
871 (cond ((eq action nil
)
873 (pattern (concat "\n\\* \\("
874 (regexp-quote string
)
877 (set-buffer Info-complete-menu-buffer
)
878 (goto-char (point-min))
879 (while (re-search-forward pattern nil t
)
880 (setq completions
(cons (cons (format "%s"
886 (try-completion string completions predicate
)))
889 (pattern (concat "\n\\* \\("
890 (regexp-quote string
)
893 (set-buffer Info-complete-menu-buffer
)
894 (goto-char (point-min))
895 (while (re-search-forward pattern nil t
)
896 (setq completions
(cons (cons (format "%s"
902 (all-completions string completions predicate
)))
905 (set-buffer Info-complete-menu-buffer
)
906 (goto-char (point-min))
907 (re-search-forward (concat "\n\\* "
908 (regexp-quote string
)
913 (defun Info-menu (menu-item)
914 "Go to node for menu item named (or abbreviated) NAME.
915 Completion is allowed, and the menu item point is on is the default."
917 (let ((completions '())
918 ;; If point is within a menu item, use that item as the default
923 (goto-char (point-min))
924 (if (not (search-forward "\n* menu:" nil t
))
925 (error "No menu in this node"))
931 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t
)
932 (setq default
(format "%s" (buffer-substring
937 (setq item
(let ((completion-ignore-case t
)
938 (Info-complete-menu-buffer (current-buffer)))
939 (completing-read (if default
940 (format "Menu item (default %s): "
943 'Info-complete-menu-item nil t
)))
944 ;; we rely on the fact that completing-read accepts an input
945 ;; of "" even when the require-match argument is true and ""
946 ;; is not a valid possibility
947 (if (string= item
"")
953 ;; there is a problem here in that if several menu items have the same
954 ;; name you can only go to the node of the first with this command.
955 (Info-goto-node (Info-extract-menu-item menu-item
)))
957 (defun Info-extract-menu-item (menu-item)
958 (setq menu-item
(regexp-quote menu-item
))
960 (goto-char (point-min))
961 (or (search-forward "\n* menu:" nil t
)
962 (error "No menu in this node"))
963 (or (re-search-forward (concat "\n\\* " menu-item
":") nil t
)
964 (re-search-forward (concat "\n\\* " menu-item
) nil t
)
965 (error "No such item in menu"))
968 (Info-extract-menu-node-name)))
970 ;; If COUNT is nil, use the last item in the menu.
971 (defun Info-extract-menu-counting (count)
973 (goto-char (point-min))
974 (or (search-forward "\n* menu:" nil t
)
975 (error "No menu in this node"))
977 (or (search-forward "\n* " nil t count
)
978 (error "Too few items in menu"))
979 (while (search-forward "\n* " nil t
)
981 (Info-extract-menu-node-name)))
983 (defun Info-nth-menu-item ()
984 "Go to the node of the Nth menu item.
985 N is the digit argument used to invoke this command."
988 (Info-extract-menu-counting
989 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
991 (defun Info-top-node ()
992 "Go to the Top node of this file."
994 (Info-goto-node "Top"))
996 (defun Info-final-node ()
997 "Go to the final node in this file."
999 (Info-goto-node "Top")
1001 ;; Go to the last node in the menu of Top.
1002 (Info-goto-node (Info-extract-menu-counting nil
))
1003 ;; If the last node in the menu is not last in pointer structure,
1004 ;; move forward until we can't go any farther.
1005 (while (Info-forward-node t t
) nil
)
1006 ;; Then keep moving down to last subnode, unless we reach an index.
1007 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1008 (save-excursion (search-forward "\n* Menu:" nil t
)))
1009 (Info-goto-node (Info-extract-menu-counting nil
)))))
1011 (defun Info-forward-node (&optional not-down no-error
)
1012 "Go forward one node, considering all nodes as forming one sequence."
1014 (goto-char (point-min))
1016 ;; three possibilities, in order of priority:
1017 ;; 1. next node is in a menu in this node (but not in an index)
1018 ;; 2. next node is next at same level
1019 ;; 3. next node is up and next
1020 (cond ((and (not not-down
)
1021 (save-excursion (search-forward "\n* menu:" nil t
))
1022 (not (string-match "\\<index\\>" Info-current-node
)))
1023 (Info-goto-node (Info-extract-menu-counting 1))
1025 ((save-excursion (search-backward "next:" nil t
))
1028 ((and (save-excursion (search-backward "up:" nil t
))
1029 (not (equal (downcase (Info-extract-pointer "up")) "top")))
1030 (let ((old-node Info-current-node
))
1032 (let (Info-history success
)
1034 (setq success
(Info-forward-node t no-error
))
1035 (or success
(Info-goto-node old-node
))))))
1037 (t (error "No pointer forward from this node"))))
1039 (defun Info-backward-node ()
1040 "Go backward one node, considering all nodes as forming one sequence."
1042 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1043 (upnode (Info-extract-pointer "up" t
)))
1044 (cond ((and upnode
(string-match "(" upnode
))
1045 (error "First node in file"))
1046 ((and upnode
(or (null prevnode
)
1047 (equal (downcase prevnode
) (downcase upnode
))))
1050 ;; If we move back at the same level,
1051 ;; go down to find the last subnode*.
1054 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1055 (save-excursion (search-forward "\n* Menu:" nil t
)))
1056 (Info-goto-node (Info-extract-menu-counting nil
)))))
1058 (error "No pointer backward from this node")))))
1061 "Exit Info by selecting some other buffer."
1064 (save-buffers-kill-emacs)
1065 (switch-to-buffer (prog1 (other-buffer (current-buffer))
1066 (bury-buffer (current-buffer))))))
1068 (defun Info-next-menu-item ()
1072 (search-forward "\n* menu:" nil t
)
1073 (or (search-forward "\n* " nil t
)
1074 (error "No more items in menu"))
1075 (Info-goto-node (Info-extract-menu-node-name))))
1077 (defun Info-last-menu-item ()
1081 (let ((beg (save-excursion
1082 (and (search-backward "\n* menu:" nil t
)
1084 (or (and beg
(search-backward "\n* " beg t
))
1085 (error "No previous items in menu")))
1086 (Info-goto-node (save-excursion
1087 (goto-char (match-end 0))
1088 (Info-extract-menu-node-name)))))
1090 (defmacro Info-no-error
(&rest body
)
1091 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1093 (defun Info-next-preorder ()
1094 "Go to the next subnode, popping up a level if there is none."
1096 (cond ((Info-no-error (Info-next-menu-item)))
1097 ((Info-no-error (Info-up))
1100 (error "No more nodes"))))
1102 (defun Info-next-preorder-1 ()
1103 "Go to the next subnode or the next node, or go up a level."
1105 (cond ((Info-no-error (Info-next-menu-item)))
1106 ((Info-no-error (Info-next)))
1107 ((Info-no-error (Info-up))
1110 (error "No more nodes"))))
1112 (defun Info-last-preorder ()
1113 "Go to the last node, popping up a level if there is none."
1115 (cond ((Info-no-error
1116 (Info-last-menu-item)
1117 ;; If we go down a menu item, go to the end of the node
1118 ;; so we can scroll back through it.
1119 (goto-char (point-max))))
1120 ((Info-no-error (Info-up)) (forward-line -
1))
1121 (t (error "No previous nodes"))))
1123 (defun Info-scroll-up ()
1124 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1125 Once you scroll far enough in a node that its menu appears on the screen,
1126 the next scroll moves into its first subnode. When you scroll past
1127 the end of a node, that goes back to the parent node."
1129 (if (or (< (window-start) (point-min))
1130 (> (window-start) (point-max)))
1131 (set-window-start (selected-window) (point)))
1132 (let ((virtual-end (save-excursion
1133 (goto-char (point-min))
1134 (if (search-forward "\n* Menu:" nil t
)
1137 (if (or (< virtual-end
(window-start))
1138 (pos-visible-in-window-p virtual-end
))
1139 (Info-next-preorder)
1142 (defun Info-scroll-down ()
1143 "Scroll one screenful back in Info, considering all nodes as one sequence.
1144 If you are within the menu of a node, this follows the previous
1145 menu item, so that you scroll through all the subnodes, ordered
1146 as if they appeared in place of the menu. When you scroll past
1147 the beginning of a node, that goes back to the parent node."
1149 (if (or (< (window-start) (point-min))
1150 (> (window-start) (point-max)))
1151 (set-window-start (selected-window) (point)))
1152 (let ((virtual-end (save-excursion
1153 (goto-char (point-min))
1154 (search-forward "\n* Menu:" nil t
))))
1155 (if (or virtual-end
(pos-visible-in-window-p (point-min)))
1156 (Info-last-preorder)
1159 (defun Info-next-reference ()
1160 "Move cursor to the next cross-reference or menu item in the node."
1162 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1164 (or (eobp) (forward-char 1))
1165 (or (re-search-forward pat nil t
)
1167 (goto-char (point-min))
1168 (or (re-search-forward pat nil t
)
1171 (error "No cross references in this node")))))
1172 (goto-char (match-beginning 0))
1173 (if (looking-at "\\* Menu:")
1174 (Info-next-reference))))
1176 (defun Info-prev-reference ()
1177 "Move cursor to the previous cross-reference or menu item in the node."
1179 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1181 (or (re-search-backward pat nil t
)
1183 (goto-char (point-max))
1184 (or (re-search-backward pat nil t
)
1187 (error "No cross references in this node")))))
1188 (goto-char (match-beginning 0))
1189 (if (looking-at "\\* Menu:")
1190 (Info-prev-reference))))
1192 (defun Info-index (topic)
1193 "Look up a string in the index for this file.
1194 The index is defined as the first node in the top-level menu whose
1195 name contains the word \"Index\", plus any immediately following
1196 nodes whose names also contain the word \"Index\".
1197 If there are no exact matches to the specified topic, this chooses
1198 the first match which is a case-insensitive substring of a topic.
1199 Use the `,' command to see the other matches.
1200 Give a blank topic name to go to the Index node itself."
1201 (interactive "sIndex topic: ")
1202 (let ((orignode Info-current-node
)
1204 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1205 (regexp-quote topic
)))
1207 (Info-goto-node "Top")
1208 (or (search-forward "\n* menu:" nil t
)
1210 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
1212 (goto-char (match-beginning 1))
1213 (let ((Info-keeping-history nil
))
1214 (Info-goto-node (Info-extract-menu-node-name)))
1215 (or (equal topic
"")
1218 (Info-keeping-history nil
)
1222 (goto-char (point-min))
1223 (while (re-search-forward pattern nil t
)
1225 (cons (list (buffer-substring (match-beginning 1)
1227 (buffer-substring (match-beginning 2)
1230 (string-to-int (concat "0"
1235 (and (setq node
(Info-extract-pointer "next" t
))
1236 (string-match "\\<Index\\>" node
)))
1237 (Info-goto-node node
))
1241 (error "No \"%s\" in index" topic
)))
1242 ;; Here it is a feature that assoc is case-sensitive.
1243 (while (setq found
(assoc topic matches
))
1244 (setq exact
(cons found exact
)
1245 matches
(delq found matches
)))
1246 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
1247 (Info-index-next 0)))))
1249 (defun Info-index-next (num)
1250 "Go to the next matching index item from the last `i' command."
1252 (or Info-index-alternatives
1253 (error "No previous `i' command in this file"))
1255 (setq num
(+ num
(length Info-index-alternatives
))))
1257 (setq Info-index-alternatives
1258 (nconc (cdr Info-index-alternatives
)
1259 (list (car Info-index-alternatives
)))
1261 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
1262 (if (> (nth 3 (car Info-index-alternatives
)) 0)
1263 (forward-line (nth 3 (car Info-index-alternatives
)))
1264 (forward-line 3) ; don't search in headers
1265 (let ((name (car (car Info-index-alternatives
))))
1266 (if (or (re-search-forward (format
1267 "\\(Function\\|Command\\): %s\\( \\|$\\)"
1268 (regexp-quote name
)) nil t
)
1269 (search-forward (format "`%s'" name
) nil t
)
1270 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
1272 (format "`%s'" (substring name
0 (match-beginning 1)))
1274 (search-forward name nil t
))
1276 (goto-char (point-min)))))
1277 (message "Found \"%s\" in %s. %s"
1278 (car (car Info-index-alternatives
))
1279 (nth 2 (car Info-index-alternatives
))
1280 (if (cdr Info-index-alternatives
)
1281 "(Press `,' for more)"
1284 (defun Info-undefined ()
1285 "Make command be undefined in Info."
1290 "Enter the Info tutorial."
1292 (delete-other-windows)
1293 (Info-find-node "info"
1294 (if (< (window-height) 23)
1298 (defun Info-summary ()
1299 "Display a brief summary of all Info commands."
1301 (save-window-excursion
1302 (switch-to-buffer "*Help*")
1304 (insert (documentation 'Info-mode
))
1306 (goto-char (point-min))
1308 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
1309 (message (if flag
"Type Space to see more"
1310 "Type Space to return to Info"))
1311 (if (not (eq ?\
(setq ch
(read-event))))
1312 (progn (setq unread-command-events
(list ch
)) nil
)
1315 (bury-buffer "*Help*")))
1317 (defun Info-get-token (pos start all
&optional errorstring
)
1318 "Return the token around POS,
1319 POS must be somewhere inside the token
1320 START is a regular expression which will match the
1321 beginning of the tokens delimited string
1322 ALL is a regular expression with a single
1323 parenthized subpattern which is the token to be
1324 returned. E.g. '{\(.*\)}' would return any string
1325 enclosed in braces around POS.
1326 SIG optional fourth argument, controls action on no match
1329 a string: signal an error, using that string."
1332 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)
1334 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
1335 (not (setq found
(and (<= (match-beginning 0) pos
)
1336 (> (match-end 0) pos
))))))
1337 (if (and found
(<= (match-beginning 0) pos
)
1338 (> (match-end 0) pos
))
1339 (buffer-substring (match-beginning 1) (match-end 1))
1340 (cond ((null errorstring
)
1346 (error "No %s around position %d" errorstring pos
)))))))
1348 (defun Info-mouse-follow-nearest-node (click)
1349 "\\<Info-mode-map>Follow a node reference near point.
1350 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1351 At end of the node's text, moves to the next node, or up if none."
1353 (let* ((start (event-start click
))
1354 (window (car start
))
1355 (pos (car (cdr start
))))
1356 (select-window window
)
1358 (and (not (Info-try-follow-nearest-node))
1359 (save-excursion (forward-line 1) (eobp))
1360 (Info-next-preorder-1)))
1362 (defun Info-follow-nearest-node ()
1363 "\\<Info-mode-map>Follow a node reference near point.
1364 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1365 If no reference to follow, moves to the next node, or up if none."
1367 (or (Info-try-follow-nearest-node)
1368 (Info-next-preorder-1)))
1370 ;; Common subroutine.
1371 (defun Info-try-follow-nearest-node ()
1372 "Follow a node reference near point. Return non-nil if successful."
1375 ((setq node
(Info-get-token (point) "\\*note[ \n]"
1376 "\\*note[ \n]\\([^:]*\\):"))
1377 (Info-follow-reference node
))
1378 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1379 (Info-goto-node node
))
1380 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1382 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1383 (Info-goto-node node
))
1384 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1385 (Info-goto-node node
))
1386 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1387 (Info-goto-node "Top"))
1388 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1389 (Info-goto-node node
)))
1392 (defvar Info-mode-map nil
1393 "Keymap containing Info commands.")
1396 (setq Info-mode-map
(make-keymap))
1397 (suppress-keymap Info-mode-map
)
1398 (define-key Info-mode-map
"." 'beginning-of-buffer
)
1399 (define-key Info-mode-map
" " 'Info-scroll-up
)
1400 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
1401 (define-key Info-mode-map
"\t" 'Info-next-reference
)
1402 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
1403 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
1404 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
1405 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
1406 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
1407 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
1408 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
1409 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
1410 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
1411 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
1412 (define-key Info-mode-map
"0" 'undefined
)
1413 (define-key Info-mode-map
"?" 'Info-summary
)
1414 (define-key Info-mode-map
"]" 'Info-forward-node
)
1415 (define-key Info-mode-map
"[" 'Info-backward-node
)
1416 (define-key Info-mode-map
"<" 'Info-top-node
)
1417 (define-key Info-mode-map
">" 'Info-final-node
)
1418 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
1419 (define-key Info-mode-map
"d" 'Info-directory
)
1420 (define-key Info-mode-map
"e" 'Info-edit
)
1421 (define-key Info-mode-map
"f" 'Info-follow-reference
)
1422 (define-key Info-mode-map
"g" 'Info-goto-node
)
1423 (define-key Info-mode-map
"h" 'Info-help
)
1424 (define-key Info-mode-map
"i" 'Info-index
)
1425 (define-key Info-mode-map
"l" 'Info-last
)
1426 (define-key Info-mode-map
"m" 'Info-menu
)
1427 (define-key Info-mode-map
"n" 'Info-next
)
1428 (define-key Info-mode-map
"p" 'Info-prev
)
1429 (define-key Info-mode-map
"q" 'Info-exit
)
1430 (define-key Info-mode-map
"s" 'Info-search
)
1431 ;; For consistency with Rmail.
1432 (define-key Info-mode-map
"\M-s" 'Info-search
)
1433 (define-key Info-mode-map
"t" 'Info-top-node
)
1434 (define-key Info-mode-map
"u" 'Info-up
)
1435 (define-key Info-mode-map
"," 'Info-index-next
)
1436 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
1437 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
1440 ;; Info mode is suitable only for specially formatted data.
1441 (put 'info-mode
'mode-class
'special
)
1445 Info mode provides commands for browsing through the Info documentation tree.
1446 Documentation in Info is divided into \"nodes\", each of which discusses
1447 one topic and contains references to other nodes which discuss related
1448 topics. Info has commands to follow the references and show you other nodes.
1450 \\[Info-help] Invoke the Info tutorial.
1452 Selecting other nodes:
1453 \\[Info-mouse-follow-nearest-node]
1454 Follow a node reference you click on.
1455 This works with menu items, cross references, and
1456 the \"next\", \"previous\" and \"up\", depending on where you click.
1457 \\[Info-next] Move to the \"next\" node of this node.
1458 \\[Info-prev] Move to the \"previous\" node of this node.
1459 \\[Info-up] Move \"up\" from this node.
1460 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1461 Picking a menu item causes another node to be selected.
1462 \\[Info-directory] Go to the Info directory node.
1463 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1464 \\[Info-last] Move to the last node you were at.
1465 \\[Info-index] Look up a topic in this file's Index and move to that node.
1466 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1468 Moving within a node:
1469 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1470 already visible, try to go to the next menu entry, or up if there is none.
1471 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1472 already visible, try to go to the previous menu entry, or up if there is none.
1473 \\[beginning-of-buffer] Go to beginning of node.
1476 \\[Info-exit] Quit Info: reselect previously selected buffer.
1477 \\[Info-edit] Edit contents of selected node.
1478 1 Pick first item in node's menu.
1479 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1480 \\[Info-goto-node] Move to node specified by name.
1481 You may include a filename as well, as (FILENAME)NODENAME.
1482 \\[universal-argument] \\[info] Move to new Info file with completion.
1483 \\[Info-search] Search through this Info file for specified regexp,
1484 and select the node in which the next occurrence is found.
1485 \\[Info-next-preorder] Next-preorder; that is, try to go to the next menu item,
1486 and if that fails try to move up, and if that fails, tell user
1487 he/she is done reading.
1488 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1489 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1490 (kill-all-local-variables)
1491 (setq major-mode
'Info-mode
)
1492 (setq mode-name
"Info")
1493 (use-local-map Info-mode-map
)
1494 (set-syntax-table text-mode-syntax-table
)
1495 (setq local-abbrev-table text-mode-abbrev-table
)
1496 (setq case-fold-search t
)
1497 (setq buffer-read-only t
)
1498 (make-local-variable 'Info-current-file
)
1499 (make-local-variable 'Info-current-subfile
)
1500 (make-local-variable 'Info-current-node
)
1501 (make-local-variable 'Info-tag-table-marker
)
1502 (make-local-variable 'Info-history
)
1503 (make-local-variable 'Info-index-alternatives
)
1504 (if (memq (framep (selected-frame)) '(x pc
))
1506 (make-face 'info-node
)
1507 (make-face 'info-menu-5
)
1508 (make-face 'info-xref
)
1509 (or (face-differs-from-default-p 'info-node
)
1510 (if (face-differs-from-default-p 'bold-italic
)
1511 (copy-face 'bold-italic
'info-node
)
1512 (copy-face 'bold
'info-node
)))
1513 (or (face-differs-from-default-p 'info-menu-5
)
1514 (set-face-underline-p 'info-menu-5 t
))
1515 (or (face-differs-from-default-p 'info-xref
)
1516 (copy-face 'bold
'info-xref
)))
1517 (setq Info-fontify nil
))
1518 (Info-set-mode-line)
1519 (run-hooks 'Info-mode-hook
))
1521 (defvar Info-edit-map nil
1522 "Local keymap used within `e' command of Info.")
1525 (setq Info-edit-map
(nconc (make-sparse-keymap) text-mode-map
))
1526 (define-key Info-edit-map
"\C-c\C-c" 'Info-cease-edit
))
1528 ;; Info-edit mode is suitable only for specially formatted data.
1529 (put 'info-edit-mode
'mode-class
'special
)
1531 (defun Info-edit-mode ()
1532 "Major mode for editing the contents of an Info node.
1533 Like text mode with the addition of `Info-cease-edit'
1534 which returns to Info mode for browsing.
1536 (use-local-map Info-edit-map
)
1537 (setq major-mode
'Info-edit-mode
)
1538 (setq mode-name
"Info Edit")
1539 (kill-local-variable 'mode-line-buffer-identification
)
1540 (setq buffer-read-only nil
)
1541 ;; Make mode line update.
1542 (set-buffer-modified-p (buffer-modified-p))
1543 (buffer-enable-undo (current-buffer))
1544 (run-hooks 'Info-edit-mode-hook
))
1547 "Edit the contents of this Info node.
1548 Allowed only if variable `Info-enable-edit' is non-nil."
1550 (or Info-enable-edit
1551 (error "Editing info nodes is not enabled"))
1553 (message (substitute-command-keys
1554 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1556 (defun Info-cease-edit ()
1557 "Finish editing Info node; switch back to Info proper."
1559 ;; Do this first, so nothing has changed if user C-g's at query.
1560 (and (buffer-modified-p)
1561 (y-or-n-p "Save the file? ")
1563 (use-local-map Info-mode-map
)
1564 (setq major-mode
'Info-mode
)
1565 (setq mode-name
"Info")
1566 (Info-set-mode-line)
1567 (setq buffer-read-only t
)
1568 ;; Make mode line update.
1569 (set-buffer-modified-p (buffer-modified-p))
1570 (and (marker-position Info-tag-table-marker
)
1572 (message "Tags may have changed. Use Info-tagify if necessary")))
1574 (defun Info-find-emacs-command-nodes (command)
1575 "Return a list of locations documenting COMMAND in the Emacs Info manual.
1576 The locations are of the format used in Info-history, i.e.
1577 \(FILENAME NODENAME BUFFERPOS\)."
1580 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command
))
1581 ":\\s *\\(.*\\)\\.$")))
1583 (Info-find-node "emacs" "Command Index")
1584 ;; Take the index node off the Info history.
1585 (setq Info-history
(cdr Info-history
))
1586 (goto-char (point-max))
1587 (while (re-search-backward cmd-desc nil t
)
1588 (setq where
(cons (list Info-current-file
1597 (defun Info-goto-emacs-command-node (command)
1598 "Go to the Info node in the Emacs manual for command COMMAND.
1599 The command is found by looking up in Emacs manual's Command Index."
1600 (interactive "CFind documentation for command: ")
1601 (or (commandp command
)
1602 (signal 'wrong-type-argument
(list 'commandp command
)))
1603 (let ((where (Info-find-emacs-command-nodes command
)))
1605 (let ((num-matches (length where
)))
1606 ;; Get Info running, and pop to it in another window.
1607 (save-window-excursion
1609 (pop-to-buffer "*info*")
1610 (Info-find-node (car (car where
))
1611 (car (cdr (car where
))))
1612 (if (> num-matches
1)
1614 ;; Info-find-node already pushed (car where) onto
1615 ;; Info-history. Put the other nodes that were found on
1617 (setq Info-history
(nconc (cdr where
) Info-history
))
1618 (message (substitute-command-keys
1619 "Found %d other entr%s. Use \\[Info-last] to see %s.")
1621 (if (> num-matches
2) "ies" "y")
1622 (if (> num-matches
2) "them" "it")))))
1623 (error "Couldn't find documentation for %s." command
))))
1626 (defun Info-goto-emacs-key-command-node (key)
1627 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1628 Interactively, if the binding is execute-extended-command, a command is read.
1629 The command is found by looking up in Emacs manual's Command Index."
1630 (interactive "kFind documentation for key:")
1631 (let ((command (key-binding key
)))
1632 (cond ((null command
)
1633 (message "%s is undefined" (key-description key
)))
1634 ((and (interactive-p)
1635 (eq command
'execute-extended-command
))
1636 (Info-goto-emacs-command-node
1637 (read-command "Find documentation for command: ")))
1639 (Info-goto-emacs-command-node command
)))))
1641 (defun Info-fontify-node ()
1643 (let ((buffer-read-only nil
))
1644 (goto-char (point-min))
1645 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1647 (goto-char (match-end 0))
1649 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1650 (goto-char (match-end 0))
1651 (put-text-property (match-beginning 1) (match-end 1)
1653 (put-text-property (match-beginning 1) (match-end 1)
1654 'mouse-face
'highlight
))))
1655 (goto-char (point-min))
1656 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t
)
1657 (if (= (char-after (1- (match-beginning 0))) ?
\") ; hack
1659 (put-text-property (match-beginning 1) (match-end 1)
1661 (put-text-property (match-beginning 1) (match-end 1)
1662 'mouse-face
'highlight
)))
1663 (goto-char (point-min))
1664 (if (and (search-forward "\n* Menu:" nil t
)
1665 (not (string-match "\\<Index\\>" Info-current-node
))
1666 ;; Don't take time to annotate huge menus
1667 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
1669 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t
)
1671 (if (memq n
'(5 9)) ; visual aids to help with 1-9 keys
1672 (put-text-property (match-beginning 0)
1673 (1+ (match-beginning 0))
1674 'face
'info-menu-5
))
1675 (put-text-property (match-beginning 1) (match-end 1)
1677 (put-text-property (match-beginning 1) (match-end 1)
1678 'mouse-face
'highlight
))))
1679 (set-buffer-modified-p nil
))))
1683 ;;; info.el ends here