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 ;; This is for older Emacs versions
59 ;; which might get this info.el from the Texinfo distribution.
60 (path-separator (if (boundp 'path-separator
) path-separator
61 (if (eq system-type
'ms-dos
) ";" ":")))
62 (sibling (if installation-directory
63 (expand-file-name "info/" installation-directory
))))
67 (while (> (length path
) 0)
68 (setq idx
(or (string-match path-separator path
) (length path
))
69 list
(cons (substring path
0 idx
) list
)
70 path
(substring path
(min (1+ idx
)
73 (if (or (null sibling
)
74 (member sibling Info-default-directory-list
)
75 (not (file-exists-p sibling
))
76 ;; On DOS/NT, we use movable executables always,
77 ;; and we must always find the Info dir at run time.
78 (if (or (eq system-type
'ms-dos
) (eq system-type
'windows-nt
))
80 ;; Use invocation-directory for Info only if we used it for
81 ;; exec-directory also.
82 (not (string= exec-directory
83 (expand-file-name "lib-src/"
84 installation-directory
)))))
85 Info-default-directory-list
86 (reverse (cons sibling
(cdr (reverse Info-default-directory-list
)))))))
87 "List of directories to search for Info documentation files.
88 nil means not yet initialized. In this case, Info uses the environment
89 variable INFOPATH to initialize it, or `Info-default-directory-list'
90 if there is no INFOPATH variable in the environment.
91 The last element of `Info-default-directory-list' is the directory
92 where Emacs installs the Info files that come with it.
94 If you run the Emacs executable from the `src' directory in the Emacs
95 source tree, the `info' directory in the source tree is used as the last
96 element, in place of the installation Info directory. This is useful
97 when you run a version of Emacs without installing it.")
99 (defvar Info-additional-directory-list nil
100 "List of additional directories to search for Info documentation files.
101 These directories are not searched for merging the `dir' file.")
103 (defvar Info-current-file nil
104 "Info file that Info is now looking at, or nil.
105 This is the name that was specified in Info, not the actual file name.
106 It doesn't contain directory names or file name extensions added by Info.")
108 (defvar Info-current-subfile nil
109 "Info subfile that is actually in the *info* buffer now,
110 or nil if current info file is not split into subfiles.")
112 (defvar Info-current-node nil
113 "Name of node that Info is now looking at, or nil.")
115 (defvar Info-tag-table-marker
(make-marker)
116 "Marker pointing at beginning of current Info file's tag table.
117 Marker points nowhere if file has no tag table.")
119 (defvar Info-current-file-completions nil
120 "Cached completion list for current Info file.")
122 (defvar Info-index-alternatives nil
123 "List of possible matches for last Info-index command.")
125 (defvar Info-standalone nil
126 "Non-nil if Emacs was started solely as an Info browser.")
128 (defvar Info-suffix-list
'( (".info.Z" .
"uncompress")
129 (".info.Y" .
"unyabba")
130 (".info.gz" .
"gunzip")
131 (".info.z" .
"gunzip")
133 (".Z" .
"uncompress")
138 "List of file name suffixes and associated decoding commands.
139 Each entry should be (SUFFIX . STRING); the file is given to
140 the command as standard input. If STRING is nil, no decoding is done.
141 Because the SUFFIXes are tried in order, the empty string should
142 be last in the list.")
144 (defun info-insert-file-contents (filename &optional visit
)
145 "Insert the contents of an info file in the current buffer.
146 Do the right thing if the file has been compressed or zipped."
147 (let ((tail Info-suffix-list
)
149 (if (file-exists-p filename
)
153 (concat (regexp-quote (car (car tail
))) "$")
155 (setq tail
(cdr tail
)))
156 (setq fullname filename
157 decoder
(cdr (car tail
))))
159 (not (file-exists-p (concat filename
(car (car tail
))))))
160 (setq tail
(cdr tail
)))
161 (setq fullname
(concat filename
(car (car tail
)))
162 decoder
(cdr (car tail
)))
164 (error "Can't find %s or any compressed version of it!" filename
)))
165 ;; check for conflict with jka-compr
166 (if (and (featurep 'jka-compr
)
167 (jka-compr-installed-p)
168 (jka-compr-get-compression-info fullname
))
170 (insert-file-contents fullname visit
)
172 (let ((buffer-read-only nil
)
173 (default-directory (or (file-name-directory fullname
)
175 (shell-command-on-region (point-min) (point-max) decoder t
)))))
177 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
180 (defun info (&optional file
)
181 "Enter Info, the documentation browser.
182 Optional argument FILE specifies the file to examine;
183 the default is the top-level directory of Info.
185 In interactive use, a prefix argument directs this command
186 to read a file name from the minibuffer."
187 (interactive (if current-prefix-arg
188 (list (read-file-name "Info file name: " nil nil t
))))
190 (Info-goto-node (concat "(" file
")"))
191 (if (get-buffer "*info*")
192 (pop-to-buffer "*info*")
196 (defun info-standalone ()
197 "Run Emacs as a standalone Info reader.
198 Usage: emacs -f info-standalone [filename]
199 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
200 (setq Info-standalone t
)
201 (if (and command-line-args-left
202 (not (string-match "^-" (car command-line-args-left
))))
205 (info (car command-line-args-left
))
206 (setq command-line-args-left
(cdr command-line-args-left
)))
207 (error (send-string-to-terminal
208 (format "%s\n" (if (eq (car-safe err
) 'error
)
210 (save-buffers-kill-emacs)))
213 ;; Go to an info node specified as separate filename and nodename.
214 ;; no-going-back is non-nil if recovering from an error in this function;
215 ;; it says do not attempt further (recursive) error recovery.
216 (defun Info-find-node (filename nodename
&optional no-going-back
)
217 ;; Convert filename to lower case if not found as specified.
220 (let (temp temp-downcase found
)
221 (setq filename
(substitute-in-file-name filename
))
222 (if (string= (downcase (file-name-nondirectory filename
)) "dir")
224 (let ((dirs (if (string-match "^\\./" filename
)
225 ;; If specified name starts with `./'
226 ;; then just try current directory.
228 (if (file-name-absolute-p filename
)
229 ;; No point in searching for an
230 ;; absolute file name
232 (if Info-additional-directory-list
233 (append Info-directory-list
234 Info-additional-directory-list
)
235 Info-directory-list
)))))
236 ;; Search the directory list for file FILENAME.
237 (while (and dirs
(not found
))
238 (setq temp
(expand-file-name filename
(car dirs
)))
240 (expand-file-name (downcase filename
) (car dirs
)))
241 ;; Try several variants of specified name.
242 (let ((suffix-list Info-suffix-list
))
243 (while (and suffix-list
(not found
))
244 (cond ((file-exists-p
245 (concat temp
(car (car suffix-list
))))
248 (concat temp-downcase
(car (car suffix-list
))))
249 (setq found temp-downcase
)))
250 (setq suffix-list
(cdr suffix-list
))))
251 (setq dirs
(cdr dirs
)))))
253 (setq filename found
)
254 (error "Info file %s does not exist" filename
))))
255 ;; Record the node we are leaving.
256 (if (and Info-current-file
(not no-going-back
))
258 (cons (list Info-current-file Info-current-node
(point))
260 ;; Go into info buffer.
261 (switch-to-buffer "*info*")
262 (buffer-disable-undo (current-buffer))
263 (or (eq major-mode
'Info-mode
)
266 (setq Info-current-node nil
)
269 ;; Switch files if necessary
271 (equal Info-current-file filename
)
272 (let ((buffer-read-only nil
))
273 (setq Info-current-file nil
274 Info-current-subfile nil
275 Info-current-file-completions nil
276 Info-index-alternatives nil
277 buffer-file-name nil
)
281 (info-insert-file-contents filename t
)
282 (setq default-directory
(file-name-directory filename
)))
283 (set-buffer-modified-p nil
)
284 ;; See whether file has a tag table. Record the location if yes.
285 (set-marker Info-tag-table-marker nil
)
286 (goto-char (point-max))
288 ;; Use string-equal, not equal, to ignore text props.
289 (or (string-equal nodename
"*")
290 (not (search-forward "\^_\nEnd tag table\n" nil t
))
292 ;; We have a tag table. Find its beginning.
293 ;; Is this an indirect file?
294 (search-backward "\nTag table:\n")
298 (looking-at "(Indirect)\n"))
299 ;; It is indirect. Copy it to another buffer
300 ;; and record that the tag table is in that buffer.
302 (let ((buf (current-buffer)))
303 (set-buffer (get-buffer-create " *info tag table*"))
304 (buffer-disable-undo (current-buffer))
305 (setq case-fold-search t
)
307 (insert-buffer-substring buf
)
308 (set-marker Info-tag-table-marker
310 (set-marker Info-tag-table-marker pos
))))
311 (setq Info-current-file
312 (if (eq filename t
) "dir" filename
))))
313 ;; Use string-equal, not equal, to ignore text props.
314 (if (string-equal nodename
"*")
315 (progn (setq Info-current-node nodename
)
316 (Info-set-mode-line))
317 ;; Search file for a suitable node.
318 (let ((guesspos (point-min))
319 (regexp (concat "Node: *" (regexp-quote nodename
) " *[,\t\n\177]")))
320 ;; First get advice from tag table if file has one.
321 ;; Also, if this is an indirect info file,
322 ;; read the proper subfile into this buffer.
323 (if (marker-position Info-tag-table-marker
)
325 (set-buffer (marker-buffer Info-tag-table-marker
))
326 (goto-char Info-tag-table-marker
)
327 (if (re-search-forward regexp nil t
)
329 (setq guesspos
(read (current-buffer)))
330 ;; If this is an indirect file,
331 ;; determine which file really holds this node
333 (if (not (eq (current-buffer) (get-buffer "*info*")))
335 (Info-read-subfile guesspos
))))
336 (error "No such node: \"%s\"" nodename
))))
337 (goto-char (max (point-min) (- guesspos
1000)))
338 ;; Now search from our advised position (or from beg of buffer)
339 ;; to find the actual node.
341 (while (search-forward "\n\^_" nil t
)
345 (if (re-search-backward regexp beg t
)
347 (error "No such node: %s" nodename
)))
349 ;; If we did not finish finding the specified node,
350 ;; go back to the previous one.
351 (or Info-current-node no-going-back
(null Info-history
)
352 (let ((hist (car Info-history
)))
353 (setq Info-history
(cdr Info-history
))
354 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
355 (goto-char (nth 2 hist
)))))
356 (goto-char (point-min)))
358 ;; Cache the contents of the (virtual) dir file, once we have merged
359 ;; it for the first time, so we can save time subsequently.
360 (defvar Info-dir-contents nil
)
362 ;; Cache for the directory we decided to use for the default-directory
363 ;; of the merged dir text.
364 (defvar Info-dir-contents-directory nil
)
366 ;; Record the file attributes of all the files from which we
367 ;; constructed Info-dir-contents.
368 (defvar Info-dir-file-attributes nil
)
370 ;; Construct the Info directory node by merging the files named `dir'
371 ;; from various directories. Set the *info* buffer's
372 ;; default-directory to the first directory we actually get any text
374 (defun Info-insert-dir ()
375 (if (and Info-dir-contents Info-dir-file-attributes
376 ;; Verify that none of the files we used has changed
379 (mapcar '(lambda (elt)
380 (let ((curr (file-attributes (car elt
))))
381 ;; Don't compare the access time.
382 (if curr
(setcar (nthcdr 4 curr
) 0))
383 (setcar (nthcdr 4 (cdr elt
)) 0)
384 (equal (cdr elt
) curr
)))
385 Info-dir-file-attributes
))))
386 (insert Info-dir-contents
)
387 (let ((dirs Info-directory-list
)
388 buffers buffer others nodes dirs-done
)
390 (setq Info-dir-file-attributes nil
)
392 ;; Search the directory list for the directory file.
394 (let ((truename (file-truename (expand-file-name (car dirs
)))))
395 (or (member truename dirs-done
)
396 (member (directory-file-name truename
) dirs-done
)
397 ;; Try several variants of specified name.
398 ;; Try upcasing, appending `.info', or both.
402 (progn (setq file
(expand-file-name "dir" truename
))
403 (file-attributes file
))
404 (progn (setq file
(expand-file-name "DIR" truename
))
405 (file-attributes file
))
406 (progn (setq file
(expand-file-name "dir.info" truename
))
407 (file-attributes file
))
408 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
409 (file-attributes file
)))))
412 (cons (directory-file-name truename
)
417 (message "Composing main Info directory..."))
418 (set-buffer (generate-new-buffer "info dir"))
419 (insert-file-contents file
)
420 (setq buffers
(cons (current-buffer) buffers
)
421 Info-dir-file-attributes
422 (cons (cons file attrs
)
423 Info-dir-file-attributes
))))))
424 (setq dirs
(cdr dirs
))))
427 (error "Can't find the info directory node"))
428 ;; Distinguish the dir file that comes with Emacs from all the
429 ;; others. Yes, that is really what this is supposed to do.
430 ;; If it doesn't work, fix it.
431 (setq buffer
(car buffers
)
432 others
(cdr buffers
))
434 ;; Insert the entire original dir file as a start; use its
435 ;; default directory as the default directory for the whole
437 (insert-buffer buffer
)
438 (setq Info-dir-contents-directory
(save-excursion
442 ;; Look at each of the other buffers one by one.
444 (let ((other (car others
)))
445 ;; In each, find all the menus.
448 (goto-char (point-min))
449 ;; Find each menu, and add an elt to NODES for it.
450 (while (re-search-forward "^\\* Menu:" nil t
)
451 (let (beg nodename end
)
454 (search-backward "\n\^_")
455 (search-forward "Node: ")
456 (setq nodename
(Info-following-node-name))
457 (search-forward "\n\^_" nil
'move
)
460 (setq nodes
(cons (list nodename other beg end
) nodes
))))))
461 (setq others
(cdr others
)))
462 ;; Add to the main menu a menu item for each other node.
463 (re-search-forward "^\\* Menu:")
465 (let ((menu-items '("top"))
468 (end (save-excursion (search-forward "\^_" nil t
) (point))))
470 (let ((nodename (car (car nodes
))))
472 (or (member (downcase nodename
) menu-items
)
473 (re-search-forward (concat "^\\* "
474 (regexp-quote nodename
)
478 (insert "* " nodename
"::" "\n")
479 (setq menu-items
(cons nodename menu-items
))))))
480 (setq nodes
(cdr nodes
))))
481 ;; Now take each node of each of the other buffers
482 ;; and merge it into the main buffer.
484 (let ((nodename (car (car nodes
))))
485 (goto-char (point-min))
486 ;; Find the like-named node in the main buffer.
487 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
488 (regexp-quote nodename
)
492 (search-forward "\n\^_" nil
'move
)
495 ;; If none exists, add one.
496 (goto-char (point-max))
497 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
498 ;; Merge the text from the other buffer's menu
499 ;; into the menu in the like-named node in the main buffer.
500 (apply 'insert-buffer-substring
(cdr (car nodes
))))
501 (setq nodes
(cdr nodes
)))
502 ;; Kill all the buffers we just made.
504 (kill-buffer (car buffers
))
505 (setq buffers
(cdr buffers
)))
506 (message "Composing main Info directory...done"))
507 (setq Info-dir-contents
(buffer-string)))
508 (setq default-directory Info-dir-contents-directory
))
510 (defun Info-read-subfile (nodepos)
511 (set-buffer (marker-buffer Info-tag-table-marker
))
512 (goto-char (point-min))
513 (search-forward "\n\^_")
518 (while (not (looking-at "\^_"))
521 thisfilepos thisfilename
)
522 (search-forward ": ")
523 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
524 (setq thisfilepos
(read (current-buffer)))
525 ;; read in version 19 stops at the end of number.
526 ;; Advance to the next line.
528 (if (> thisfilepos nodepos
)
530 (setq lastfilename thisfilename
)
531 (setq lastfilepos thisfilepos
))
533 (set-buffer (get-buffer "*info*"))
534 (or (equal Info-current-subfile lastfilename
)
535 (let ((buffer-read-only nil
))
536 (setq buffer-file-name nil
)
539 (info-insert-file-contents lastfilename
)
540 (set-buffer-modified-p nil
)
541 (setq Info-current-subfile lastfilename
)))
542 (goto-char (point-min))
543 (search-forward "\n\^_")
544 (+ (- nodepos lastfilepos
) (point))))
546 ;; Select the info node that point is in.
547 (defun Info-select-node ()
549 ;; Find beginning of node.
550 (search-backward "\n\^_")
552 ;; Get nodename spelled as it is in the node.
553 (re-search-forward "Node:[ \t]*")
554 (setq Info-current-node
555 (buffer-substring (point)
557 (skip-chars-forward "^,\t\n")
560 ;; Find the end of it, and narrow.
562 (let (active-expression)
563 (narrow-to-region (point)
564 (if (re-search-forward "\n[\^_\f]" nil t
)
567 (if (looking-at "[\n\^_\f]*execute: ")
569 (goto-char (match-end 0))
570 (setq active-expression
571 (read (current-buffer))))))
573 (if Info-enable-active-nodes
(eval active-expression
))
574 (if Info-fontify
(Info-fontify-node))
575 (run-hooks 'Info-selection-hook
))))
577 (defun Info-set-mode-line ()
578 (setq mode-line-buffer-identification
581 (if Info-current-file
582 (file-name-nondirectory Info-current-file
)
585 (or Info-current-node
""))))
587 ;; Go to an info node specified with a filename-and-nodename string
588 ;; of the sort that is found in pointers in nodes.
590 (defun Info-goto-node (nodename)
591 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
592 (interactive (list (Info-read-node-name "Goto node: ")))
594 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
596 (setq filename
(if (= (match-beginning 1) (match-end 1))
598 (substring nodename
(match-beginning 2) (match-end 2)))
599 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
600 (let ((trim (string-match "\\s *\\'" filename
)))
601 (if trim
(setq filename
(substring filename
0 trim
))))
602 (let ((trim (string-match "\\s *\\'" nodename
)))
603 (if trim
(setq nodename
(substring nodename
0 trim
))))
604 (if transient-mark-mode
(deactivate-mark))
605 (Info-find-node (if (equal filename
"") nil filename
)
606 (if (equal nodename
"") "Top" nodename
))))
608 ;; This function is used as the "completion table" while reading a node name.
609 ;; It does completion using the alist in completion-table
610 ;; unless STRING starts with an open-paren.
611 (defun Info-read-node-name-1 (string predicate code
)
612 (let ((no-completion (and (> (length string
) 0) (eq (aref string
0) ?\
())))
616 (try-completion string completion-table predicate
)))
620 (all-completions string completion-table predicate
)))
624 (assoc string completion-table
))))))
626 (defun Info-read-node-name (prompt &optional default
)
627 (let* ((completion-ignore-case t
)
628 (completion-table (Info-build-node-completions))
629 (nodename (completing-read prompt
'Info-read-node-name-1
)))
630 (if (equal nodename
"")
632 (Info-read-node-name prompt
))
635 (defun Info-build-node-completions ()
636 (or Info-current-file-completions
640 (if (marker-buffer Info-tag-table-marker
)
642 (set-buffer (marker-buffer Info-tag-table-marker
))
644 (goto-char Info-tag-table-marker
)
645 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t
)
647 (cons (list (buffer-substring (match-beginning 1)
651 (goto-char (point-min))
652 (while (search-forward "\n\^_" nil t
)
656 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
659 (cons (list (buffer-substring (match-beginning 1)
662 (setq Info-current-file-completions compl
))))
664 (defun Info-restore-point (hl)
665 "If this node has been visited, restore the point value when we left."
667 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
668 ;; Use string-equal, not equal, to ignore text props.
669 (string-equal (nth 1 (car hl
)) Info-current-node
))
671 (goto-char (nth 2 (car hl
)))
672 (setq hl nil
)) ;terminate the while at next iter
673 (setq hl
(cdr hl
)))))
675 (defvar Info-last-search nil
676 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
678 (defun Info-search (regexp)
679 "Search for REGEXP, starting from point, and select node it's found in."
680 (interactive "sSearch (regexp): ")
681 (if transient-mark-mode
(deactivate-mark))
682 (if (equal regexp
"")
683 (setq regexp Info-last-search
)
684 (setq Info-last-search regexp
))
685 (let ((found ()) current
686 (onode Info-current-node
)
687 (ofile Info-current-file
)
689 (osubfile Info-current-subfile
))
693 (if (null Info-current-subfile
)
694 (progn (re-search-forward regexp
) (setq found
(point)))
696 (progn (re-search-forward regexp
) (setq found
(point)))
697 (search-failed nil
)))))
698 (if (not found
) ;can only happen in subfile case -- else would have erred
701 (set-buffer (marker-buffer Info-tag-table-marker
))
702 (goto-char (point-min))
703 (search-forward "\n\^_\nIndirect:")
705 (narrow-to-region (point)
706 (progn (search-forward "\n\^_")
708 (goto-char (point-min))
709 (search-forward (concat "\n" osubfile
": "))
712 (re-search-forward "\\(^.*\\): [0-9]+$")
713 (goto-char (+ (match-end 1) 2))
714 (setq list
(cons (cons (read (current-buffer))
715 (buffer-substring (match-beginning 1)
718 (goto-char (1+ (match-end 0))))
719 (setq list
(nreverse list
)
720 current
(car (car list
))
723 (message "Searching subfile %s..." (cdr (car list
)))
724 (Info-read-subfile (car (car list
)))
725 (setq list
(cdr list
))
726 ;; (goto-char (point-min))
727 (if (re-search-forward regexp nil t
)
728 (setq found
(point) list
())))
731 (signal 'search-failed
(list regexp
))))
733 (progn (Info-read-subfile opoint
)
735 (Info-select-node)))))
739 ;; Use string-equal, not equal, to ignore text props.
740 (or (and (string-equal onode Info-current-node
)
741 (equal ofile Info-current-file
))
742 (setq Info-history
(cons (list ofile onode opoint
)
745 ;; Extract the value of the node-pointer named NAME.
746 ;; If there is none, use ERRORNAME in the error message;
747 ;; if ERRORNAME is nil, just return nil.
748 (defun Info-extract-pointer (name &optional errorname
)
750 (goto-char (point-min))
752 (if (re-search-backward (concat name
":") nil t
)
754 (goto-char (match-end 0))
755 (Info-following-node-name))
758 (error (concat "Node has no " (capitalize (or errorname name
))))))))
760 ;; Return the node name in the buffer following point.
761 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
762 ;; saying which chas may appear in the node name.
763 (defun Info-following-node-name (&optional allowedchars
)
764 (skip-chars-forward " \t")
768 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
769 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
771 (skip-chars-forward "^)")))
772 (skip-chars-backward " ")
776 "Go to the next node of this node."
778 (Info-goto-node (Info-extract-pointer "next")))
781 "Go to the previous node of this node."
783 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
786 "Go to the superior node of this node."
788 (Info-goto-node (Info-extract-pointer "up"))
789 (Info-restore-point Info-history
))
792 "Go back to the last node visited."
795 (error "This is the first Info node you looked at"))
796 (let (filename nodename opoint
)
797 (setq filename
(car (car Info-history
)))
798 (setq nodename
(car (cdr (car Info-history
))))
799 (setq opoint
(car (cdr (cdr (car Info-history
)))))
800 (setq Info-history
(cdr Info-history
))
801 (Info-find-node filename nodename
)
802 (setq Info-history
(cdr Info-history
))
805 (defun Info-directory ()
806 "Go to the Info directory node."
808 (Info-find-node "dir" "top"))
810 (defun Info-follow-reference (footnotename)
811 "Follow cross reference named NAME to the node it refers to.
812 NAME may be an abbreviation of the reference name."
814 (let ((completion-ignore-case t
)
815 completions default alt-default
(start-point (point)) str i bol eol
)
817 ;; Store end and beginning of line.
823 (goto-char (point-min))
824 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
825 (setq str
(buffer-substring
828 ;; See if this one should be the default.
830 (<= (match-beginning 0) start-point
)
831 (<= start-point
(point))
833 ;; See if this one should be the alternate default.
834 (and (null alt-default
)
835 (and (<= bol
(match-beginning 0))
837 (setq alt-default t
))
839 (while (setq i
(string-match "[ \n\t]+" str i
))
840 (setq str
(concat (substring str
0 i
) " "
841 (substring str
(match-end 0))))
843 ;; Record as a completion and perhaps as default.
844 (if (eq default t
) (setq default str
))
845 (if (eq alt-default t
) (setq alt-default str
))
849 ;; If no good default was found, try an alternate.
851 (setq default alt-default
))
852 ;; If only one cross-reference found, then make it default.
853 (if (eq (length completions
) 1)
854 (setq default
(car (car completions
))))
856 (let ((input (completing-read (if default
857 (concat "Follow reference named: ("
859 "Follow reference named: ")
861 (list (if (equal input
"")
863 (error "No cross-references in this node"))))
864 (let (target beg i
(str (concat "\\*note " (regexp-quote footnotename
))))
865 (while (setq i
(string-match " " str i
))
866 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
869 (goto-char (point-min))
870 (or (re-search-forward str nil t
)
871 (error "No cross-reference named %s" footnotename
))
872 (goto-char (+ (match-beginning 0) 5))
874 (Info-extract-menu-node-name "Bad format cross reference" t
)))
875 (while (setq i
(string-match "[ \t\n]+" target i
))
876 (setq target
(concat (substring target
0 i
) " "
877 (substring target
(match-end 0))))
879 (Info-goto-node target
)))
881 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
882 (skip-chars-forward " \t\n")
885 (skip-chars-forward "^:")
889 (buffer-substring beg
(1- (point)))
890 (skip-chars-forward " \t\n")
891 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
892 (while (setq i
(string-match "\n" str i
))
894 ;; Collapse multiple spaces.
895 (while (string-match " +" str
)
896 (setq str
(replace-match " " t t str
)))
899 ;; No one calls this.
900 ;;(defun Info-menu-item-sequence (list)
902 ;; (Info-menu (car list))
903 ;; (setq list (cdr list))))
905 (defun Info-complete-menu-item (string predicate action
)
906 (let ((case-fold-search t
))
907 (cond ((eq action nil
)
909 (pattern (concat "\n\\* \\("
910 (regexp-quote string
)
913 (set-buffer Info-complete-menu-buffer
)
914 (goto-char (point-min))
915 (while (re-search-forward pattern nil t
)
916 (setq completions
(cons (cons (format "%s"
922 (try-completion string completions predicate
)))
925 (pattern (concat "\n\\* \\("
926 (regexp-quote string
)
929 (set-buffer Info-complete-menu-buffer
)
930 (goto-char (point-min))
931 (while (re-search-forward pattern nil t
)
932 (setq completions
(cons (cons (format "%s"
938 (all-completions string completions predicate
)))
941 (set-buffer Info-complete-menu-buffer
)
942 (goto-char (point-min))
943 (re-search-forward (concat "\n\\* "
944 (regexp-quote string
)
949 (defun Info-menu (menu-item)
950 "Go to node for menu item named (or abbreviated) NAME.
951 Completion is allowed, and the menu item point is on is the default."
953 (let ((completions '())
954 ;; If point is within a menu item, use that item as the default
960 (goto-char (point-min))
961 (if (not (search-forward "\n* menu:" nil t
))
962 (error "No menu in this node"))
968 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t
)
969 (setq default
(format "%s" (buffer-substring
974 (setq item
(let ((completion-ignore-case t
)
975 (Info-complete-menu-buffer (current-buffer)))
976 (completing-read (if default
977 (format "Menu item (default %s): "
980 'Info-complete-menu-item nil t
)))
981 ;; we rely on the fact that completing-read accepts an input
982 ;; of "" even when the require-match argument is true and ""
983 ;; is not a valid possibility
984 (if (string= item
"")
990 ;; there is a problem here in that if several menu items have the same
991 ;; name you can only go to the node of the first with this command.
992 (Info-goto-node (Info-extract-menu-item menu-item
)))
994 (defun Info-extract-menu-item (menu-item)
995 (setq menu-item
(regexp-quote menu-item
))
997 (goto-char (point-min))
998 (or (search-forward "\n* menu:" nil t
)
999 (error "No menu in this node"))
1000 (or (re-search-forward (concat "\n\\* " menu-item
":") nil t
)
1001 (re-search-forward (concat "\n\\* " menu-item
) nil t
)
1002 (error "No such item in menu"))
1005 (Info-extract-menu-node-name)))
1007 ;; If COUNT is nil, use the last item in the menu.
1008 (defun Info-extract-menu-counting (count)
1010 (goto-char (point-min))
1011 (or (search-forward "\n* menu:" nil t
)
1012 (error "No menu in this node"))
1014 (or (search-forward "\n* " nil t count
)
1015 (error "Too few items in menu"))
1016 (while (search-forward "\n* " nil t
)
1018 (Info-extract-menu-node-name)))
1020 (defun Info-nth-menu-item ()
1021 "Go to the node of the Nth menu item.
1022 N is the digit argument used to invoke this command."
1025 (Info-extract-menu-counting
1026 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
1028 (defun Info-top-node ()
1029 "Go to the Top node of this file."
1031 (Info-goto-node "Top"))
1033 (defun Info-final-node ()
1034 "Go to the final node in this file."
1036 (Info-goto-node "Top")
1038 ;; Go to the last node in the menu of Top.
1039 (Info-goto-node (Info-extract-menu-counting nil
))
1040 ;; If the last node in the menu is not last in pointer structure,
1041 ;; move forward until we can't go any farther.
1042 (while (Info-forward-node t t
) nil
)
1043 ;; Then keep moving down to last subnode, unless we reach an index.
1044 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1045 (save-excursion (search-forward "\n* Menu:" nil t
)))
1046 (Info-goto-node (Info-extract-menu-counting nil
)))))
1048 (defun Info-forward-node (&optional not-down no-error
)
1049 "Go forward one node, considering all nodes as forming one sequence."
1051 (goto-char (point-min))
1053 ;; three possibilities, in order of priority:
1054 ;; 1. next node is in a menu in this node (but not in an index)
1055 ;; 2. next node is next at same level
1056 ;; 3. next node is up and next
1057 (cond ((and (not not-down
)
1058 (save-excursion (search-forward "\n* menu:" nil t
))
1059 (not (string-match "\\<index\\>" Info-current-node
)))
1060 (Info-goto-node (Info-extract-menu-counting 1))
1062 ((save-excursion (search-backward "next:" nil t
))
1065 ((and (save-excursion (search-backward "up:" nil t
))
1066 ;; Use string-equal, not equal, to ignore text props.
1067 (not (string-equal (downcase (Info-extract-pointer "up"))
1069 (let ((old-node Info-current-node
))
1071 (let (Info-history success
)
1073 (setq success
(Info-forward-node t no-error
))
1074 (or success
(Info-goto-node old-node
))))))
1076 (t (error "No pointer forward from this node"))))
1078 (defun Info-backward-node ()
1079 "Go backward one node, considering all nodes as forming one sequence."
1081 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1082 (upnode (Info-extract-pointer "up" t
)))
1083 (cond ((and upnode
(string-match "(" upnode
))
1084 (error "First node in file"))
1085 ((and upnode
(or (null prevnode
)
1086 ;; Use string-equal, not equal,
1087 ;; to ignore text properties.
1088 (string-equal (downcase prevnode
)
1089 (downcase upnode
))))
1092 ;; If we move back at the same level,
1093 ;; go down to find the last subnode*.
1096 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1097 (save-excursion (search-forward "\n* Menu:" nil t
)))
1098 (Info-goto-node (Info-extract-menu-counting nil
)))))
1100 (error "No pointer backward from this node")))))
1103 "Exit Info by selecting some other buffer."
1106 (save-buffers-kill-emacs)
1107 (switch-to-buffer (prog1 (other-buffer (current-buffer))
1108 (bury-buffer (current-buffer))))))
1110 (defun Info-next-menu-item ()
1114 (search-forward "\n* menu:" nil t
)
1115 (or (search-forward "\n* " nil t
)
1116 (error "No more items in menu"))
1117 (Info-goto-node (Info-extract-menu-node-name))))
1119 (defun Info-last-menu-item ()
1123 (let ((beg (save-excursion
1124 (and (search-backward "\n* menu:" nil t
)
1126 (or (and beg
(search-backward "\n* " beg t
))
1127 (error "No previous items in menu")))
1128 (Info-goto-node (save-excursion
1129 (goto-char (match-end 0))
1130 (Info-extract-menu-node-name)))))
1132 (defmacro Info-no-error
(&rest body
)
1133 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1135 (defun Info-next-preorder ()
1136 "Go to the next subnode or the next node, or go up a level."
1138 (cond ((Info-no-error (Info-next-menu-item)))
1139 ((Info-no-error (Info-next)))
1140 ((Info-no-error (Info-up))
1141 ;; Since we have already gone thru all the items in this menu,
1142 ;; go up to the end of this node.
1143 (goto-char (point-max)))
1145 (error "No more nodes"))))
1147 (defun Info-last-preorder ()
1148 "Go to the last node, popping up a level if there is none."
1150 (cond ((Info-no-error
1151 (Info-last-menu-item)
1152 ;; If we go down a menu item, go to the end of the node
1153 ;; so we can scroll back through it.
1154 (goto-char (point-max)))
1156 ((Info-no-error (Info-prev))
1157 (goto-char (point-max))
1159 ((Info-no-error (Info-up))
1160 (goto-char (point-min))
1161 (or (search-forward "\n* Menu:" nil t
)
1162 (goto-char (point-max))))
1163 (t (error "No previous nodes"))))
1165 (defun Info-scroll-up ()
1166 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1167 Once you scroll far enough in a node that its menu appears on the screen,
1168 the next scroll moves into its first subnode. When you scroll past
1169 the end of a node, that goes to the next node or back up to the parent node."
1171 (if (or (< (window-start) (point-min))
1172 (> (window-start) (point-max)))
1173 (set-window-start (selected-window) (point)))
1174 (let ((virtual-end (save-excursion
1175 (goto-char (point-min))
1176 (if (search-forward "\n* Menu:" nil t
)
1179 (if (or (< virtual-end
(window-start))
1180 (pos-visible-in-window-p virtual-end
))
1181 (Info-next-preorder)
1184 (defun Info-scroll-down ()
1185 "Scroll one screenful back in Info, considering all nodes as one sequence.
1186 Within the menu of a node, this goes to its last subnode.
1187 When you scroll past the beginning of a node, that goes to the
1188 previous node or back up to the parent node."
1190 (if (or (< (window-start) (point-min))
1191 (> (window-start) (point-max)))
1192 (set-window-start (selected-window) (point)))
1193 (let ((virtual-end (save-excursion
1194 (goto-char (point-min))
1195 (search-forward "\n* Menu:" nil t
))))
1196 (if (or virtual-end
(pos-visible-in-window-p (point-min)))
1197 (Info-last-preorder)
1200 (defun Info-next-reference ()
1201 "Move cursor to the next cross-reference or menu item in the node."
1203 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1205 (or (eobp) (forward-char 1))
1206 (or (re-search-forward pat nil t
)
1208 (goto-char (point-min))
1209 (or (re-search-forward pat nil t
)
1212 (error "No cross references in this node")))))
1213 (goto-char (match-beginning 0))
1214 (if (looking-at "\\* Menu:")
1215 (Info-next-reference))))
1217 (defun Info-prev-reference ()
1218 "Move cursor to the previous cross-reference or menu item in the node."
1220 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1222 (or (re-search-backward pat nil t
)
1224 (goto-char (point-max))
1225 (or (re-search-backward pat nil t
)
1228 (error "No cross references in this node")))))
1229 (goto-char (match-beginning 0))
1230 (if (looking-at "\\* Menu:")
1231 (Info-prev-reference))))
1233 (defun Info-index (topic)
1234 "Look up a string in the index for this file.
1235 The index is defined as the first node in the top-level menu whose
1236 name contains the word \"Index\", plus any immediately following
1237 nodes whose names also contain the word \"Index\".
1238 If there are no exact matches to the specified topic, this chooses
1239 the first match which is a case-insensitive substring of a topic.
1240 Use the `,' command to see the other matches.
1241 Give a blank topic name to go to the Index node itself."
1242 (interactive "sIndex topic: ")
1243 (let ((orignode Info-current-node
)
1245 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1246 (regexp-quote topic
)))
1248 (Info-goto-node "Top")
1249 (or (search-forward "\n* menu:" nil t
)
1251 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
1253 (goto-char (match-beginning 1))
1254 ;; Here, and subsequently in this function,
1255 ;; we bind Info-history to nil for internal node-switches
1256 ;; so that we don't put junk in the history.
1257 ;; In the first Info-goto-node call, above, we do update the history
1258 ;; because that is what the user's previous node choice into it.
1259 (let ((Info-history nil
))
1260 (Info-goto-node (Info-extract-menu-node-name)))
1261 (or (equal topic
"")
1268 (goto-char (point-min))
1269 (while (re-search-forward pattern nil t
)
1271 (cons (list (buffer-substring (match-beginning 1)
1273 (buffer-substring (match-beginning 2)
1276 (string-to-int (concat "0"
1281 (and (setq node
(Info-extract-pointer "next" t
))
1282 (string-match "\\<Index\\>" node
)))
1283 (Info-goto-node node
))
1287 (error "No \"%s\" in index" topic
)))
1288 ;; Here it is a feature that assoc is case-sensitive.
1289 (while (setq found
(assoc topic matches
))
1290 (setq exact
(cons found exact
)
1291 matches
(delq found matches
)))
1292 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
1293 (Info-index-next 0)))))
1295 (defun Info-index-next (num)
1296 "Go to the next matching index item from the last `i' command."
1298 (or Info-index-alternatives
1299 (error "No previous `i' command in this file"))
1301 (setq num
(+ num
(length Info-index-alternatives
))))
1303 (setq Info-index-alternatives
1304 (nconc (cdr Info-index-alternatives
)
1305 (list (car Info-index-alternatives
)))
1307 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
1308 (if (> (nth 3 (car Info-index-alternatives
)) 0)
1309 (forward-line (nth 3 (car Info-index-alternatives
)))
1310 (forward-line 3) ; don't search in headers
1311 (let ((name (car (car Info-index-alternatives
))))
1312 (if (or (re-search-forward (format
1313 "\\(Function\\|Command\\): %s\\( \\|$\\)"
1314 (regexp-quote name
)) nil t
)
1315 (search-forward (format "`%s'" name
) nil t
)
1316 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
1318 (format "`%s'" (substring name
0 (match-beginning 1)))
1320 (search-forward name nil t
))
1322 (goto-char (point-min)))))
1323 (message "Found \"%s\" in %s. %s"
1324 (car (car Info-index-alternatives
))
1325 (nth 2 (car Info-index-alternatives
))
1326 (if (cdr Info-index-alternatives
)
1327 "(Press `,' for more)"
1330 (defun Info-undefined ()
1331 "Make command be undefined in Info."
1336 "Enter the Info tutorial."
1338 (delete-other-windows)
1339 (Info-find-node "info"
1340 (if (< (window-height) 23)
1344 (defun Info-summary ()
1345 "Display a brief summary of all Info commands."
1347 (save-window-excursion
1348 (switch-to-buffer "*Help*")
1350 (insert (documentation 'Info-mode
))
1352 (goto-char (point-min))
1354 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
1355 (message (if flag
"Type Space to see more"
1356 "Type Space to return to Info"))
1357 (if (not (eq ?\
(setq ch
(read-event))))
1358 (progn (setq unread-command-events
(list ch
)) nil
)
1361 (bury-buffer "*Help*")))
1363 (defun Info-get-token (pos start all
&optional errorstring
)
1364 "Return the token around POS,
1365 POS must be somewhere inside the token
1366 START is a regular expression which will match the
1367 beginning of the tokens delimited string
1368 ALL is a regular expression with a single
1369 parenthized subpattern which is the token to be
1370 returned. E.g. '{\(.*\)}' would return any string
1371 enclosed in braces around POS.
1372 SIG optional fourth argument, controls action on no match
1375 a string: signal an error, using that string."
1378 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)
1380 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
1381 (not (setq found
(and (<= (match-beginning 0) pos
)
1382 (> (match-end 0) pos
))))))
1383 (if (and found
(<= (match-beginning 0) pos
)
1384 (> (match-end 0) pos
))
1385 (buffer-substring (match-beginning 1) (match-end 1))
1386 (cond ((null errorstring
)
1392 (error "No %s around position %d" errorstring pos
)))))))
1394 (defun Info-mouse-follow-nearest-node (click)
1395 "\\<Info-mode-map>Follow a node reference near point.
1396 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1397 At end of the node's text, moves to the next node, or up if none."
1399 (let* ((start (event-start click
))
1400 (window (car start
))
1401 (pos (car (cdr start
))))
1402 (select-window window
)
1404 (and (not (Info-try-follow-nearest-node))
1405 (save-excursion (forward-line 1) (eobp))
1406 (Info-next-preorder)))
1408 (defun Info-follow-nearest-node ()
1409 "\\<Info-mode-map>Follow a node reference near point.
1410 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1411 If no reference to follow, moves to the next node, or up if none."
1413 (or (Info-try-follow-nearest-node)
1414 (Info-next-preorder)))
1416 ;; Common subroutine.
1417 (defun Info-try-follow-nearest-node ()
1418 "Follow a node reference near point. Return non-nil if successful."
1421 ((setq node
(Info-get-token (point) "\\*note[ \n]"
1422 "\\*note[ \n]\\([^:]*\\):"))
1423 (Info-follow-reference node
))
1424 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1425 (Info-goto-node node
))
1426 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1428 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1429 (Info-goto-node node
))
1430 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1431 (Info-goto-node node
))
1432 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1433 (Info-goto-node "Top"))
1434 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1435 (Info-goto-node node
)))
1438 (defvar Info-mode-map nil
1439 "Keymap containing Info commands.")
1442 (setq Info-mode-map
(make-keymap))
1443 (suppress-keymap Info-mode-map
)
1444 (define-key Info-mode-map
"." 'beginning-of-buffer
)
1445 (define-key Info-mode-map
" " 'Info-scroll-up
)
1446 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
1447 (define-key Info-mode-map
"\t" 'Info-next-reference
)
1448 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
1449 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
1450 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
1451 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
1452 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
1453 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
1454 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
1455 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
1456 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
1457 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
1458 (define-key Info-mode-map
"0" 'undefined
)
1459 (define-key Info-mode-map
"?" 'Info-summary
)
1460 (define-key Info-mode-map
"]" 'Info-forward-node
)
1461 (define-key Info-mode-map
"[" 'Info-backward-node
)
1462 (define-key Info-mode-map
"<" 'Info-top-node
)
1463 (define-key Info-mode-map
">" 'Info-final-node
)
1464 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
1465 (define-key Info-mode-map
"d" 'Info-directory
)
1466 (define-key Info-mode-map
"e" 'Info-edit
)
1467 (define-key Info-mode-map
"f" 'Info-follow-reference
)
1468 (define-key Info-mode-map
"g" 'Info-goto-node
)
1469 (define-key Info-mode-map
"h" 'Info-help
)
1470 (define-key Info-mode-map
"i" 'Info-index
)
1471 (define-key Info-mode-map
"l" 'Info-last
)
1472 (define-key Info-mode-map
"m" 'Info-menu
)
1473 (define-key Info-mode-map
"n" 'Info-next
)
1474 (define-key Info-mode-map
"p" 'Info-prev
)
1475 (define-key Info-mode-map
"q" 'Info-exit
)
1476 (define-key Info-mode-map
"s" 'Info-search
)
1477 ;; For consistency with Rmail.
1478 (define-key Info-mode-map
"\M-s" 'Info-search
)
1479 (define-key Info-mode-map
"t" 'Info-top-node
)
1480 (define-key Info-mode-map
"u" 'Info-up
)
1481 (define-key Info-mode-map
"," 'Info-index-next
)
1482 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
1483 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
1486 ;; Info mode is suitable only for specially formatted data.
1487 (put 'info-mode
'mode-class
'special
)
1491 Info mode provides commands for browsing through the Info documentation tree.
1492 Documentation in Info is divided into \"nodes\", each of which discusses
1493 one topic and contains references to other nodes which discuss related
1494 topics. Info has commands to follow the references and show you other nodes.
1496 \\[Info-help] Invoke the Info tutorial.
1498 Selecting other nodes:
1499 \\[Info-mouse-follow-nearest-node]
1500 Follow a node reference you click on.
1501 This works with menu items, cross references, and
1502 the \"next\", \"previous\" and \"up\", depending on where you click.
1503 \\[Info-next] Move to the \"next\" node of this node.
1504 \\[Info-prev] Move to the \"previous\" node of this node.
1505 \\[Info-up] Move \"up\" from this node.
1506 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1507 Picking a menu item causes another node to be selected.
1508 \\[Info-directory] Go to the Info directory node.
1509 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1510 \\[Info-last] Move to the last node you were at.
1511 \\[Info-index] Look up a topic in this file's Index and move to that node.
1512 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1514 Moving within a node:
1515 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1516 already visible, try to go to the next menu entry, or up if there is none.
1517 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1518 already visible, try to go to the previous menu entry, or up if there is none.
1519 \\[beginning-of-buffer] Go to beginning of node.
1522 \\[Info-exit] Quit Info: reselect previously selected buffer.
1523 \\[Info-edit] Edit contents of selected node.
1524 1 Pick first item in node's menu.
1525 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1526 \\[Info-goto-node] Move to node specified by name.
1527 You may include a filename as well, as (FILENAME)NODENAME.
1528 \\[universal-argument] \\[info] Move to new Info file with completion.
1529 \\[Info-search] Search through this Info file for specified regexp,
1530 and select the node in which the next occurrence is found.
1531 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1532 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1533 (kill-all-local-variables)
1534 (setq major-mode
'Info-mode
)
1535 (setq mode-name
"Info")
1536 (use-local-map Info-mode-map
)
1537 (set-syntax-table text-mode-syntax-table
)
1538 (setq local-abbrev-table text-mode-abbrev-table
)
1539 (setq case-fold-search t
)
1540 (setq buffer-read-only t
)
1541 (make-local-variable 'Info-current-file
)
1542 (make-local-variable 'Info-current-subfile
)
1543 (make-local-variable 'Info-current-node
)
1544 (make-local-variable 'Info-tag-table-marker
)
1545 (make-local-variable 'Info-history
)
1546 (make-local-variable 'Info-index-alternatives
)
1547 (if (memq (framep (selected-frame)) '(x pc
))
1549 (make-face 'info-node
)
1550 (make-face 'info-menu-5
)
1551 (make-face 'info-xref
)
1552 (or (face-differs-from-default-p 'info-node
)
1553 (if (face-differs-from-default-p 'bold-italic
)
1554 (copy-face 'bold-italic
'info-node
)
1555 (copy-face 'bold
'info-node
)))
1556 (or (face-differs-from-default-p 'info-menu-5
)
1557 (set-face-underline-p 'info-menu-5 t
))
1558 (or (face-differs-from-default-p 'info-xref
)
1559 (copy-face 'bold
'info-xref
)))
1560 (setq Info-fontify nil
))
1561 (Info-set-mode-line)
1562 (run-hooks 'Info-mode-hook
))
1564 (defvar Info-edit-map nil
1565 "Local keymap used within `e' command of Info.")
1568 (setq Info-edit-map
(nconc (make-sparse-keymap) text-mode-map
))
1569 (define-key Info-edit-map
"\C-c\C-c" 'Info-cease-edit
))
1571 ;; Info-edit mode is suitable only for specially formatted data.
1572 (put 'info-edit-mode
'mode-class
'special
)
1574 (defun Info-edit-mode ()
1575 "Major mode for editing the contents of an Info node.
1576 Like text mode with the addition of `Info-cease-edit'
1577 which returns to Info mode for browsing.
1579 (use-local-map Info-edit-map
)
1580 (setq major-mode
'Info-edit-mode
)
1581 (setq mode-name
"Info Edit")
1582 (kill-local-variable 'mode-line-buffer-identification
)
1583 (setq buffer-read-only nil
)
1584 (force-mode-line-update)
1585 (buffer-enable-undo (current-buffer))
1586 (run-hooks 'Info-edit-mode-hook
))
1589 "Edit the contents of this Info node.
1590 Allowed only if variable `Info-enable-edit' is non-nil."
1592 (or Info-enable-edit
1593 (error "Editing info nodes is not enabled"))
1595 (message (substitute-command-keys
1596 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1598 (defun Info-cease-edit ()
1599 "Finish editing Info node; switch back to Info proper."
1601 ;; Do this first, so nothing has changed if user C-g's at query.
1602 (and (buffer-modified-p)
1603 (y-or-n-p "Save the file? ")
1605 (use-local-map Info-mode-map
)
1606 (setq major-mode
'Info-mode
)
1607 (setq mode-name
"Info")
1608 (Info-set-mode-line)
1609 (setq buffer-read-only t
)
1610 (force-mode-line-update)
1611 (and (marker-position Info-tag-table-marker
)
1613 (message "Tags may have changed. Use Info-tagify if necessary")))
1615 (defvar Info-file-list-for-emacs
1616 '("ediff" "forms" "gnus" "info" ("mh" .
"mh-e") "sc")
1617 "List of Info files that describe Emacs commands.
1618 An element can be a file name, or a list of the form (PREFIX . FILE)
1619 where PREFIX is a name prefix and FILE is the file to look in.
1620 If the element is just a file name, the file name also serves as the prefix.")
1622 (defun Info-find-emacs-command-nodes (command)
1623 "Return a list of locations documenting COMMAND.
1624 The `info-file' property of COMMAND says which Info manual to search.
1625 If COMMAND has no property, the variable `Info-file-list-for-emacs'
1626 defines heuristics for which Info manual to try.
1627 The locations are of the format used in Info-history, i.e.
1628 \(FILENAME NODENAME BUFFERPOS\)."
1630 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command
))
1631 ":\\s *\\(.*\\)\\.$"))
1632 (info-file "emacs")) ;default
1633 ;; Determine which info file this command is documented in.
1634 (if (get command
'info-file
)
1635 (setq info-file
(get command
'info-file
))
1636 ;; If it doesn't say explicitly, test its name against
1637 ;; various prefixes that we know.
1638 (let ((file-list Info-file-list-for-emacs
))
1640 (let* ((elt (car file-list
))
1641 (name (if (consp elt
)
1644 (file (if (consp elt
) (cdr elt
) elt
))
1645 (regexp (concat "\\`" (regexp-quote name
)
1647 (if (string-match regexp
(symbol-name command
))
1648 (setq info-file file file-list nil
))
1649 (setq file-list
(cdr file-list
))))))
1652 (Info-find-node info-file
"Command Index")
1653 ;; Some manuals may not have a separate Command Index node,
1654 ;; so try just Index instead.
1656 (Info-find-node info-file
"Index")))
1657 ;; Take the index node off the Info history.
1658 (setq Info-history
(cdr Info-history
))
1659 (goto-char (point-max))
1660 (while (re-search-backward cmd-desc nil t
)
1661 (setq where
(cons (list Info-current-file
1670 (defun Info-goto-emacs-command-node (command)
1671 "Go to the Info node in the Emacs manual for command COMMAND.
1672 The command is found by looking up in Emacs manual's Command Index
1673 or in another manual found via COMMAND's `info-file' property or
1674 the variable `Info-file-list-for-emacs'."
1675 (interactive "CFind documentation for command: ")
1676 (or (commandp command
)
1677 (signal 'wrong-type-argument
(list 'commandp command
)))
1678 (let ((where (Info-find-emacs-command-nodes command
)))
1680 (let ((num-matches (length where
)))
1681 ;; Get Info running, and pop to it in another window.
1682 (save-window-excursion
1684 (pop-to-buffer "*info*")
1685 (Info-find-node (car (car where
))
1686 (car (cdr (car where
))))
1687 (if (> num-matches
1)
1689 ;; Info-find-node already pushed (car where) onto
1690 ;; Info-history. Put the other nodes that were found on
1692 (setq Info-history
(nconc (cdr where
) Info-history
))
1693 (message (substitute-command-keys
1694 "Found %d other entr%s. Use \\[Info-last] to see %s.")
1696 (if (> num-matches
2) "ies" "y")
1697 (if (> num-matches
2) "them" "it")))))
1698 (error "Couldn't find documentation for %s." command
))))
1701 (defun Info-goto-emacs-key-command-node (key)
1702 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1703 Interactively, if the binding is execute-extended-command, a command is read.
1704 The command is found by looking up in Emacs manual's Command Index
1705 or in another manual found via COMMAND's `info-file' property or
1706 the variable `Info-file-list-for-emacs'."
1707 (interactive "kFind documentation for key:")
1708 (let ((command (key-binding key
)))
1709 (cond ((null command
)
1710 (message "%s is undefined" (key-description key
)))
1711 ((and (interactive-p)
1712 (eq command
'execute-extended-command
))
1713 (Info-goto-emacs-command-node
1714 (read-command "Find documentation for command: ")))
1716 (Info-goto-emacs-command-node command
)))))
1718 (defun Info-fontify-node ()
1720 (let ((buffer-read-only nil
))
1721 (goto-char (point-min))
1722 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1724 (goto-char (match-end 0))
1726 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1727 (goto-char (match-end 0))
1728 (put-text-property (match-beginning 1) (match-end 1)
1730 (put-text-property (match-beginning 1) (match-end 1)
1731 'mouse-face
'highlight
))))
1732 (goto-char (point-min))
1733 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t
)
1734 (if (= (char-after (1- (match-beginning 0))) ?
\") ; hack
1736 (put-text-property (match-beginning 1) (match-end 1)
1738 (put-text-property (match-beginning 1) (match-end 1)
1739 'mouse-face
'highlight
)))
1740 (goto-char (point-min))
1741 (if (and (search-forward "\n* Menu:" nil t
)
1742 (not (string-match "\\<Index\\>" Info-current-node
))
1743 ;; Don't take time to annotate huge menus
1744 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
1746 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t
)
1748 (if (memq n
'(5 9)) ; visual aids to help with 1-9 keys
1749 (put-text-property (match-beginning 0)
1750 (1+ (match-beginning 0))
1751 'face
'info-menu-5
))
1752 (put-text-property (match-beginning 1) (match-end 1)
1754 (put-text-property (match-beginning 1) (match-end 1)
1755 'mouse-face
'highlight
))))
1756 (set-buffer-modified-p nil
))))
1760 ;;; info.el ends here