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.")
106 (defvar Info-current-subfile nil
107 "Info subfile that is actually in the *info* buffer now,
108 or nil if current info file is not split into subfiles.")
110 (defvar Info-current-node nil
111 "Name of node that Info is now looking at, or nil.")
113 (defvar Info-tag-table-marker
(make-marker)
114 "Marker pointing at beginning of current Info file's tag table.
115 Marker points nowhere if file has no tag table.")
117 (defvar Info-current-file-completions nil
118 "Cached completion list for current Info file.")
120 (defvar Info-index-alternatives nil
121 "List of possible matches for last Info-index command.")
123 (defvar Info-standalone nil
124 "Non-nil if Emacs was started solely as an Info browser.")
126 (defvar Info-suffix-list
'( (".info.Z" .
"uncompress")
127 (".info.Y" .
"unyabba")
128 (".info.gz" .
"gunzip")
129 (".info.z" .
"gunzip")
131 (".Z" .
"uncompress")
136 "List of file name suffixes and associated decoding commands.
137 Each entry should be (SUFFIX . STRING); the file is given to
138 the command as standard input. If STRING is nil, no decoding is done.
139 Because the SUFFIXes are tried in order, the empty string should
140 be last in the list.")
142 (defun info-insert-file-contents (filename &optional visit
)
143 "Insert the contents of an info file in the current buffer.
144 Do the right thing if the file has been compressed or zipped."
145 (let ((tail Info-suffix-list
)
147 (if (file-exists-p filename
)
151 (concat (regexp-quote (car (car tail
))) "$")
153 (setq tail
(cdr tail
)))
154 (setq fullname filename
155 decoder
(cdr (car tail
))))
157 (not (file-exists-p (concat filename
(car (car tail
))))))
158 (setq tail
(cdr tail
)))
159 (setq fullname
(concat filename
(car (car tail
)))
160 decoder
(cdr (car tail
)))
162 (error "Can't find %s or any compressed version of it!" filename
)))
163 ;; check for conflict with jka-compr
164 (if (and (featurep 'jka-compr
)
165 (jka-compr-installed-p)
166 (jka-compr-get-compression-info fullname
))
168 (insert-file-contents fullname visit
)
170 (let ((buffer-read-only nil
)
171 (default-directory (or (file-name-directory fullname
)
173 (shell-command-on-region (point-min) (point-max) decoder t
)))))
175 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
178 (defun info (&optional file
)
179 "Enter Info, the documentation browser.
180 Optional argument FILE specifies the file to examine;
181 the default is the top-level directory of Info.
183 In interactive use, a prefix argument directs this command
184 to read a file name from the minibuffer."
185 (interactive (if current-prefix-arg
186 (list (read-file-name "Info file name: " nil nil t
))))
188 (Info-goto-node (concat "(" file
")"))
189 (if (get-buffer "*info*")
190 (pop-to-buffer "*info*")
194 (defun info-standalone ()
195 "Run Emacs as a standalone Info reader.
196 Usage: emacs -f info-standalone [filename]
197 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
198 (setq Info-standalone t
)
199 (if (and command-line-args-left
200 (not (string-match "^-" (car command-line-args-left
))))
203 (info (car command-line-args-left
))
204 (setq command-line-args-left
(cdr command-line-args-left
)))
205 (error (send-string-to-terminal
206 (format "%s\n" (if (eq (car-safe err
) 'error
)
208 (save-buffers-kill-emacs)))
211 ;; Go to an info node specified as separate filename and nodename.
212 ;; no-going-back is non-nil if recovering from an error in this function;
213 ;; it says do not attempt further (recursive) error recovery.
214 (defun Info-find-node (filename nodename
&optional no-going-back
)
215 ;; Convert filename to lower case if not found as specified.
218 (let (temp temp-downcase found
)
219 (setq filename
(substitute-in-file-name filename
))
220 (if (string= (downcase (file-name-nondirectory filename
)) "dir")
222 (let ((dirs (if (string-match "^\\./" filename
)
223 ;; If specified name starts with `./'
224 ;; then just try current directory.
226 (if (file-name-absolute-p filename
)
227 ;; No point in searching for an
228 ;; absolute file name
230 (if Info-additional-directory-list
231 (append Info-directory-list
232 Info-additional-directory-list
)
233 Info-directory-list
)))))
234 ;; Search the directory list for file FILENAME.
235 (while (and dirs
(not found
))
236 (setq temp
(expand-file-name filename
(car dirs
)))
238 (expand-file-name (downcase filename
) (car dirs
)))
239 ;; Try several variants of specified name.
240 (let ((suffix-list Info-suffix-list
))
241 (while (and suffix-list
(not found
))
242 (cond ((file-exists-p
243 (concat temp
(car (car suffix-list
))))
246 (concat temp-downcase
(car (car suffix-list
))))
247 (setq found temp-downcase
)))
248 (setq suffix-list
(cdr suffix-list
))))
249 (setq dirs
(cdr dirs
)))))
251 (setq filename found
)
252 (error "Info file %s does not exist" filename
))))
253 ;; Record the node we are leaving.
254 (if (and Info-current-file
(not no-going-back
))
256 (cons (list Info-current-file Info-current-node
(point))
258 ;; Go into info buffer.
259 (switch-to-buffer "*info*")
260 (buffer-disable-undo (current-buffer))
261 (or (eq major-mode
'Info-mode
)
264 (setq Info-current-node nil
)
267 ;; Switch files if necessary
269 (equal Info-current-file filename
)
270 (let ((buffer-read-only nil
))
271 (setq Info-current-file nil
272 Info-current-subfile nil
273 Info-current-file-completions nil
274 Info-index-alternatives nil
275 buffer-file-name nil
)
279 (info-insert-file-contents filename t
)
280 (setq default-directory
(file-name-directory filename
)))
281 (set-buffer-modified-p nil
)
282 ;; See whether file has a tag table. Record the location if yes.
283 (set-marker Info-tag-table-marker nil
)
284 (goto-char (point-max))
286 ;; Use string-equal, not equal, to ignore text props.
287 (or (string-equal nodename
"*")
288 (not (search-forward "\^_\nEnd tag table\n" nil t
))
290 ;; We have a tag table. Find its beginning.
291 ;; Is this an indirect file?
292 (search-backward "\nTag table:\n")
296 (looking-at "(Indirect)\n"))
297 ;; It is indirect. Copy it to another buffer
298 ;; and record that the tag table is in that buffer.
300 (let ((buf (current-buffer)))
301 (set-buffer (get-buffer-create " *info tag table*"))
302 (buffer-disable-undo (current-buffer))
303 (setq case-fold-search t
)
305 (insert-buffer-substring buf
)
306 (set-marker Info-tag-table-marker
308 (set-marker Info-tag-table-marker pos
))))
309 (setq Info-current-file
310 (if (eq filename t
) "dir"
311 (file-name-sans-versions buffer-file-name
)))))
312 ;; Use string-equal, not equal, to ignore text props.
313 (if (string-equal nodename
"*")
314 (progn (setq Info-current-node nodename
)
315 (Info-set-mode-line))
316 ;; Search file for a suitable node.
317 (let ((guesspos (point-min))
318 (regexp (concat "Node: *" (regexp-quote nodename
) " *[,\t\n\177]")))
319 ;; First get advice from tag table if file has one.
320 ;; Also, if this is an indirect info file,
321 ;; read the proper subfile into this buffer.
322 (if (marker-position Info-tag-table-marker
)
324 (set-buffer (marker-buffer Info-tag-table-marker
))
325 (goto-char Info-tag-table-marker
)
326 (if (re-search-forward regexp nil t
)
328 (setq guesspos
(read (current-buffer)))
329 ;; If this is an indirect file,
330 ;; determine which file really holds this node
332 (if (not (eq (current-buffer) (get-buffer "*info*")))
334 (Info-read-subfile guesspos
))))
335 (error "No such node: \"%s\"" nodename
))))
336 (goto-char (max (point-min) (- guesspos
1000)))
337 ;; Now search from our advised position (or from beg of buffer)
338 ;; to find the actual node.
340 (while (search-forward "\n\^_" nil t
)
344 (if (re-search-backward regexp beg t
)
346 (error "No such node: %s" nodename
)))
348 ;; If we did not finish finding the specified node,
349 ;; go back to the previous one.
350 (or Info-current-node no-going-back
(null Info-history
)
351 (let ((hist (car Info-history
)))
352 (setq Info-history
(cdr Info-history
))
353 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
354 (goto-char (nth 2 hist
)))))
355 (goto-char (point-min)))
357 ;; Cache the contents of the (virtual) dir file, once we have merged
358 ;; it for the first time, so we can save time subsequently.
359 (defvar Info-dir-contents nil
)
361 ;; Cache for the directory we decided to use for the default-directory
362 ;; of the merged dir text.
363 (defvar Info-dir-contents-directory nil
)
365 ;; Record the file attributes of all the files from which we
366 ;; constructed Info-dir-contents.
367 (defvar Info-dir-file-attributes nil
)
369 ;; Construct the Info directory node by merging the files named `dir'
370 ;; from various directories. Set the *info* buffer's
371 ;; default-directory to the first directory we actually get any text
373 (defun Info-insert-dir ()
374 (if (and Info-dir-contents Info-dir-file-attributes
375 ;; Verify that none of the files we used has changed
378 (mapcar '(lambda (elt)
379 (let ((curr (file-attributes (car elt
))))
380 ;; Don't compare the access time.
381 (if curr
(setcar (nthcdr 4 curr
) 0))
382 (setcar (nthcdr 4 (cdr elt
)) 0)
383 (equal (cdr elt
) curr
)))
384 Info-dir-file-attributes
))))
385 (insert Info-dir-contents
)
386 (let ((dirs Info-directory-list
)
387 buffers buffer others nodes dirs-done
)
389 (setq Info-dir-file-attributes nil
)
391 ;; Search the directory list for the directory file.
393 (let ((truename (file-truename (expand-file-name (car dirs
)))))
394 (or (member truename dirs-done
)
395 (member (directory-file-name truename
) dirs-done
)
396 ;; Try several variants of specified name.
397 ;; Try upcasing, appending `.info', or both.
401 (progn (setq file
(expand-file-name "dir" truename
))
402 (file-attributes file
))
403 (progn (setq file
(expand-file-name "DIR" truename
))
404 (file-attributes file
))
405 (progn (setq file
(expand-file-name "dir.info" truename
))
406 (file-attributes file
))
407 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
408 (file-attributes file
)))))
411 (cons (directory-file-name truename
)
416 (message "Composing main Info directory..."))
417 (set-buffer (generate-new-buffer "info dir"))
418 (insert-file-contents file
)
419 (setq buffers
(cons (current-buffer) buffers
)
420 Info-dir-file-attributes
421 (cons (cons file attrs
)
422 Info-dir-file-attributes
))))))
423 (setq dirs
(cdr dirs
))))
426 (error "Can't find the info directory node"))
427 ;; Distinguish the dir file that comes with Emacs from all the
428 ;; others. Yes, that is really what this is supposed to do.
429 ;; If it doesn't work, fix it.
430 (setq buffer
(car buffers
)
431 others
(cdr buffers
))
433 ;; Insert the entire original dir file as a start; use its
434 ;; default directory as the default directory for the whole
436 (insert-buffer buffer
)
437 (setq Info-dir-contents-directory
(save-excursion
441 ;; Look at each of the other buffers one by one.
443 (let ((other (car others
)))
444 ;; In each, find all the menus.
447 (goto-char (point-min))
448 ;; Find each menu, and add an elt to NODES for it.
449 (while (re-search-forward "^\\* Menu:" nil t
)
450 (let (beg nodename end
)
453 (search-backward "\n\^_")
454 (search-forward "Node: ")
455 (setq nodename
(Info-following-node-name))
456 (search-forward "\n\^_" nil
'move
)
459 (setq nodes
(cons (list nodename other beg end
) nodes
))))))
460 (setq others
(cdr others
)))
461 ;; Add to the main menu a menu item for each other node.
462 (re-search-forward "^\\* Menu:")
464 (let ((menu-items '("top"))
467 (end (save-excursion (search-forward "\^_" nil t
) (point))))
469 (let ((nodename (car (car nodes
))))
471 (or (member (downcase nodename
) menu-items
)
472 (re-search-forward (concat "^\\* "
473 (regexp-quote nodename
)
477 (insert "* " nodename
"::" "\n")
478 (setq menu-items
(cons nodename menu-items
))))))
479 (setq nodes
(cdr nodes
))))
480 ;; Now take each node of each of the other buffers
481 ;; and merge it into the main buffer.
483 (let ((nodename (car (car nodes
))))
484 (goto-char (point-min))
485 ;; Find the like-named node in the main buffer.
486 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
487 (regexp-quote nodename
)
491 (search-forward "\n\^_" nil
'move
)
494 ;; If none exists, add one.
495 (goto-char (point-max))
496 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
497 ;; Merge the text from the other buffer's menu
498 ;; into the menu in the like-named node in the main buffer.
499 (apply 'insert-buffer-substring
(cdr (car nodes
))))
500 (setq nodes
(cdr nodes
)))
501 ;; Kill all the buffers we just made.
503 (kill-buffer (car buffers
))
504 (setq buffers
(cdr buffers
)))
505 (message "Composing main Info directory...done"))
506 (setq Info-dir-contents
(buffer-string)))
507 (setq default-directory Info-dir-contents-directory
))
509 (defun Info-read-subfile (nodepos)
510 (set-buffer (marker-buffer Info-tag-table-marker
))
511 (goto-char (point-min))
512 (search-forward "\n\^_")
517 (while (not (looking-at "\^_"))
520 thisfilepos thisfilename
)
521 (search-forward ": ")
522 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
523 (setq thisfilepos
(read (current-buffer)))
524 ;; read in version 19 stops at the end of number.
525 ;; Advance to the next line.
527 (if (> thisfilepos nodepos
)
529 (setq lastfilename thisfilename
)
530 (setq lastfilepos thisfilepos
))
532 (set-buffer (get-buffer "*info*"))
533 (or (equal Info-current-subfile lastfilename
)
534 (let ((buffer-read-only nil
))
535 (setq buffer-file-name nil
)
538 (info-insert-file-contents lastfilename
)
539 (set-buffer-modified-p nil
)
540 (setq Info-current-subfile lastfilename
)))
541 (goto-char (point-min))
542 (search-forward "\n\^_")
543 (+ (- nodepos lastfilepos
) (point))))
545 ;; Select the info node that point is in.
546 (defun Info-select-node ()
548 ;; Find beginning of node.
549 (search-backward "\n\^_")
551 ;; Get nodename spelled as it is in the node.
552 (re-search-forward "Node:[ \t]*")
553 (setq Info-current-node
554 (buffer-substring (point)
556 (skip-chars-forward "^,\t\n")
559 ;; Find the end of it, and narrow.
561 (let (active-expression)
562 (narrow-to-region (point)
563 (if (re-search-forward "\n[\^_\f]" nil t
)
566 (if (looking-at "[\n\^_\f]*execute: ")
568 (goto-char (match-end 0))
569 (setq active-expression
570 (read (current-buffer))))))
572 (if Info-enable-active-nodes
(eval active-expression
))
573 (if Info-fontify
(Info-fontify-node))
574 (run-hooks 'Info-selection-hook
))))
576 (defun Info-set-mode-line ()
577 (setq mode-line-buffer-identification
580 (if Info-current-file
581 (file-name-nondirectory Info-current-file
)
584 (or Info-current-node
""))))
586 ;; Go to an info node specified with a filename-and-nodename string
587 ;; of the sort that is found in pointers in nodes.
589 (defun Info-goto-node (nodename)
590 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
591 (interactive (list (Info-read-node-name "Goto node: ")))
593 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
595 (setq filename
(if (= (match-beginning 1) (match-end 1))
597 (substring nodename
(match-beginning 2) (match-end 2)))
598 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
599 (let ((trim (string-match "\\s *\\'" filename
)))
600 (if trim
(setq filename
(substring filename
0 trim
))))
601 (let ((trim (string-match "\\s *\\'" nodename
)))
602 (if trim
(setq nodename
(substring nodename
0 trim
))))
603 (if transient-mark-mode
(deactivate-mark))
604 (Info-find-node (if (equal filename
"") nil filename
)
605 (if (equal nodename
"") "Top" nodename
))))
607 (defun Info-read-node-name (prompt &optional default
)
608 (let* ((completion-ignore-case t
)
609 (nodename (completing-read prompt
(Info-build-node-completions))))
610 (if (equal nodename
"")
612 (Info-read-node-name prompt
))
615 (defun Info-build-node-completions ()
616 (or Info-current-file-completions
620 (if (marker-buffer Info-tag-table-marker
)
622 (set-buffer (marker-buffer Info-tag-table-marker
))
624 (goto-char Info-tag-table-marker
)
625 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t
)
627 (cons (list (buffer-substring (match-beginning 1)
631 (goto-char (point-min))
632 (while (search-forward "\n\^_" nil t
)
636 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
639 (cons (list (buffer-substring (match-beginning 1)
642 (setq Info-current-file-completions compl
))))
644 (defun Info-restore-point (hl)
645 "If this node has been visited, restore the point value when we left."
647 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
648 ;; Use string-equal, not equal, to ignore text props.
649 (string-equal (nth 1 (car hl
)) Info-current-node
))
651 (goto-char (nth 2 (car hl
)))
652 (setq hl nil
)) ;terminate the while at next iter
653 (setq hl
(cdr hl
)))))
655 (defvar Info-last-search nil
656 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
658 (defun Info-search (regexp)
659 "Search for REGEXP, starting from point, and select node it's found in."
660 (interactive "sSearch (regexp): ")
661 (if transient-mark-mode
(deactivate-mark))
662 (if (equal regexp
"")
663 (setq regexp Info-last-search
)
664 (setq Info-last-search regexp
))
665 (let ((found ()) current
666 (onode Info-current-node
)
667 (ofile Info-current-file
)
669 (osubfile Info-current-subfile
))
673 (if (null Info-current-subfile
)
674 (progn (re-search-forward regexp
) (setq found
(point)))
676 (progn (re-search-forward regexp
) (setq found
(point)))
677 (search-failed nil
)))))
678 (if (not found
) ;can only happen in subfile case -- else would have erred
681 (set-buffer (marker-buffer Info-tag-table-marker
))
682 (goto-char (point-min))
683 (search-forward "\n\^_\nIndirect:")
685 (narrow-to-region (point)
686 (progn (search-forward "\n\^_")
688 (goto-char (point-min))
689 (search-forward (concat "\n" osubfile
": "))
692 (re-search-forward "\\(^.*\\): [0-9]+$")
693 (goto-char (+ (match-end 1) 2))
694 (setq list
(cons (cons (read (current-buffer))
695 (buffer-substring (match-beginning 1)
698 (goto-char (1+ (match-end 0))))
699 (setq list
(nreverse list
)
700 current
(car (car list
))
703 (message "Searching subfile %s..." (cdr (car list
)))
704 (Info-read-subfile (car (car list
)))
705 (setq list
(cdr list
))
706 ;; (goto-char (point-min))
707 (if (re-search-forward regexp nil t
)
708 (setq found
(point) list
())))
711 (signal 'search-failed
(list regexp
))))
713 (progn (Info-read-subfile opoint
)
715 (Info-select-node)))))
719 ;; Use string-equal, not equal, to ignore text props.
720 (or (and (string-equal onode Info-current-node
)
721 (equal ofile Info-current-file
))
722 (setq Info-history
(cons (list ofile onode opoint
)
725 ;; Extract the value of the node-pointer named NAME.
726 ;; If there is none, use ERRORNAME in the error message;
727 ;; if ERRORNAME is nil, just return nil.
728 (defun Info-extract-pointer (name &optional errorname
)
730 (goto-char (point-min))
732 (if (re-search-backward (concat name
":") nil t
)
734 (goto-char (match-end 0))
735 (Info-following-node-name))
738 (error (concat "Node has no " (capitalize (or errorname name
))))))))
740 ;; Return the node name in the buffer following point.
741 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
742 ;; saying which chas may appear in the node name.
743 (defun Info-following-node-name (&optional allowedchars
)
744 (skip-chars-forward " \t")
748 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
749 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
751 (skip-chars-forward "^)")))
752 (skip-chars-backward " ")
756 "Go to the next node of this node."
758 (Info-goto-node (Info-extract-pointer "next")))
761 "Go to the previous node of this node."
763 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
766 "Go to the superior node of this node."
768 (Info-goto-node (Info-extract-pointer "up"))
769 (Info-restore-point Info-history
))
772 "Go back to the last node visited."
775 (error "This is the first Info node you looked at"))
776 (let (filename nodename opoint
)
777 (setq filename
(car (car Info-history
)))
778 (setq nodename
(car (cdr (car Info-history
))))
779 (setq opoint
(car (cdr (cdr (car Info-history
)))))
780 (setq Info-history
(cdr Info-history
))
781 (Info-find-node filename nodename
)
782 (setq Info-history
(cdr Info-history
))
785 (defun Info-directory ()
786 "Go to the Info directory node."
788 (Info-find-node "dir" "top"))
790 (defun Info-follow-reference (footnotename)
791 "Follow cross reference named NAME to the node it refers to.
792 NAME may be an abbreviation of the reference name."
794 (let ((completion-ignore-case t
)
795 completions default alt-default
(start-point (point)) str i bol eol
)
797 ;; Store end and beginning of line.
803 (goto-char (point-min))
804 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
805 (setq str
(buffer-substring
808 ;; See if this one should be the default.
810 (<= (match-beginning 0) start-point
)
811 (<= start-point
(point))
813 ;; See if this one should be the alternate default.
814 (and (null alt-default
)
815 (and (<= bol
(match-beginning 0))
817 (setq alt-default t
))
819 (while (setq i
(string-match "[ \n\t]+" str i
))
820 (setq str
(concat (substring str
0 i
) " "
821 (substring str
(match-end 0))))
823 ;; Record as a completion and perhaps as default.
824 (if (eq default t
) (setq default str
))
825 (if (eq alt-default t
) (setq alt-default str
))
829 ;; If no good default was found, try an alternate.
831 (setq default alt-default
))
832 ;; If only one cross-reference found, then make it default.
833 (if (eq (length completions
) 1)
834 (setq default
(car (car completions
))))
836 (let ((input (completing-read (if default
837 (concat "Follow reference named: ("
839 "Follow reference named: ")
841 (list (if (equal input
"")
843 (error "No cross-references in this node"))))
844 (let (target beg i
(str (concat "\\*note " (regexp-quote footnotename
))))
845 (while (setq i
(string-match " " str i
))
846 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
849 (goto-char (point-min))
850 (or (re-search-forward str nil t
)
851 (error "No cross-reference named %s" footnotename
))
852 (goto-char (+ (match-beginning 0) 5))
854 (Info-extract-menu-node-name "Bad format cross reference" t
)))
855 (while (setq i
(string-match "[ \t\n]+" target i
))
856 (setq target
(concat (substring target
0 i
) " "
857 (substring target
(match-end 0))))
859 (Info-goto-node target
)))
861 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
862 (skip-chars-forward " \t\n")
865 (skip-chars-forward "^:")
869 (buffer-substring beg
(1- (point)))
870 (skip-chars-forward " \t\n")
871 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
872 (while (setq i
(string-match "\n" str i
))
874 ;; Collapse multiple spaces.
875 (while (string-match " +" str
)
876 (setq str
(replace-match " " t t str
)))
879 ;; No one calls this.
880 ;;(defun Info-menu-item-sequence (list)
882 ;; (Info-menu (car list))
883 ;; (setq list (cdr list))))
885 (defun Info-complete-menu-item (string predicate action
)
886 (let ((case-fold-search t
))
887 (cond ((eq action nil
)
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 (try-completion string completions predicate
)))
905 (pattern (concat "\n\\* \\("
906 (regexp-quote string
)
909 (set-buffer Info-complete-menu-buffer
)
910 (goto-char (point-min))
911 (while (re-search-forward pattern nil t
)
912 (setq completions
(cons (cons (format "%s"
918 (all-completions string completions predicate
)))
921 (set-buffer Info-complete-menu-buffer
)
922 (goto-char (point-min))
923 (re-search-forward (concat "\n\\* "
924 (regexp-quote string
)
929 (defun Info-menu (menu-item)
930 "Go to node for menu item named (or abbreviated) NAME.
931 Completion is allowed, and the menu item point is on is the default."
933 (let ((completions '())
934 ;; If point is within a menu item, use that item as the default
940 (goto-char (point-min))
941 (if (not (search-forward "\n* menu:" nil t
))
942 (error "No menu in this node"))
948 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t
)
949 (setq default
(format "%s" (buffer-substring
954 (setq item
(let ((completion-ignore-case t
)
955 (Info-complete-menu-buffer (current-buffer)))
956 (completing-read (if default
957 (format "Menu item (default %s): "
960 'Info-complete-menu-item nil t
)))
961 ;; we rely on the fact that completing-read accepts an input
962 ;; of "" even when the require-match argument is true and ""
963 ;; is not a valid possibility
964 (if (string= item
"")
970 ;; there is a problem here in that if several menu items have the same
971 ;; name you can only go to the node of the first with this command.
972 (Info-goto-node (Info-extract-menu-item menu-item
)))
974 (defun Info-extract-menu-item (menu-item)
975 (setq menu-item
(regexp-quote menu-item
))
977 (goto-char (point-min))
978 (or (search-forward "\n* menu:" nil t
)
979 (error "No menu in this node"))
980 (or (re-search-forward (concat "\n\\* " menu-item
":") nil t
)
981 (re-search-forward (concat "\n\\* " menu-item
) nil t
)
982 (error "No such item in menu"))
985 (Info-extract-menu-node-name)))
987 ;; If COUNT is nil, use the last item in the menu.
988 (defun Info-extract-menu-counting (count)
990 (goto-char (point-min))
991 (or (search-forward "\n* menu:" nil t
)
992 (error "No menu in this node"))
994 (or (search-forward "\n* " nil t count
)
995 (error "Too few items in menu"))
996 (while (search-forward "\n* " nil t
)
998 (Info-extract-menu-node-name)))
1000 (defun Info-nth-menu-item ()
1001 "Go to the node of the Nth menu item.
1002 N is the digit argument used to invoke this command."
1005 (Info-extract-menu-counting
1006 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
1008 (defun Info-top-node ()
1009 "Go to the Top node of this file."
1011 (Info-goto-node "Top"))
1013 (defun Info-final-node ()
1014 "Go to the final node in this file."
1016 (Info-goto-node "Top")
1018 ;; Go to the last node in the menu of Top.
1019 (Info-goto-node (Info-extract-menu-counting nil
))
1020 ;; If the last node in the menu is not last in pointer structure,
1021 ;; move forward until we can't go any farther.
1022 (while (Info-forward-node t t
) nil
)
1023 ;; Then keep moving down to last subnode, unless we reach an index.
1024 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1025 (save-excursion (search-forward "\n* Menu:" nil t
)))
1026 (Info-goto-node (Info-extract-menu-counting nil
)))))
1028 (defun Info-forward-node (&optional not-down no-error
)
1029 "Go forward one node, considering all nodes as forming one sequence."
1031 (goto-char (point-min))
1033 ;; three possibilities, in order of priority:
1034 ;; 1. next node is in a menu in this node (but not in an index)
1035 ;; 2. next node is next at same level
1036 ;; 3. next node is up and next
1037 (cond ((and (not not-down
)
1038 (save-excursion (search-forward "\n* menu:" nil t
))
1039 (not (string-match "\\<index\\>" Info-current-node
)))
1040 (Info-goto-node (Info-extract-menu-counting 1))
1042 ((save-excursion (search-backward "next:" nil t
))
1045 ((and (save-excursion (search-backward "up:" nil t
))
1046 ;; Use string-equal, not equal, to ignore text props.
1047 (not (string-equal (downcase (Info-extract-pointer "up"))
1049 (let ((old-node Info-current-node
))
1051 (let (Info-history success
)
1053 (setq success
(Info-forward-node t no-error
))
1054 (or success
(Info-goto-node old-node
))))))
1056 (t (error "No pointer forward from this node"))))
1058 (defun Info-backward-node ()
1059 "Go backward one node, considering all nodes as forming one sequence."
1061 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1062 (upnode (Info-extract-pointer "up" t
)))
1063 (cond ((and upnode
(string-match "(" upnode
))
1064 (error "First node in file"))
1065 ((and upnode
(or (null prevnode
)
1066 ;; Use string-equal, not equal,
1067 ;; to ignore text properties.
1068 (string-equal (downcase prevnode
)
1069 (downcase upnode
))))
1072 ;; If we move back at the same level,
1073 ;; go down to find the last subnode*.
1076 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1077 (save-excursion (search-forward "\n* Menu:" nil t
)))
1078 (Info-goto-node (Info-extract-menu-counting nil
)))))
1080 (error "No pointer backward from this node")))))
1083 "Exit Info by selecting some other buffer."
1086 (save-buffers-kill-emacs)
1087 (switch-to-buffer (prog1 (other-buffer (current-buffer))
1088 (bury-buffer (current-buffer))))))
1090 (defun Info-next-menu-item ()
1094 (search-forward "\n* menu:" nil t
)
1095 (or (search-forward "\n* " nil t
)
1096 (error "No more items in menu"))
1097 (Info-goto-node (Info-extract-menu-node-name))))
1099 (defun Info-last-menu-item ()
1103 (let ((beg (save-excursion
1104 (and (search-backward "\n* menu:" nil t
)
1106 (or (and beg
(search-backward "\n* " beg t
))
1107 (error "No previous items in menu")))
1108 (Info-goto-node (save-excursion
1109 (goto-char (match-end 0))
1110 (Info-extract-menu-node-name)))))
1112 (defmacro Info-no-error
(&rest body
)
1113 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1115 (defun Info-next-preorder ()
1116 "Go to the next subnode or the next node, or go up a level."
1118 (cond ((Info-no-error (Info-next-menu-item)))
1119 ((Info-no-error (Info-next)))
1120 ((Info-no-error (Info-up))
1121 ;; Since we have already gone thru all the items in this menu,
1122 ;; go up to the end of this node.
1123 (goto-char (point-max)))
1125 (error "No more nodes"))))
1127 (defun Info-last-preorder ()
1128 "Go to the last node, popping up a level if there is none."
1130 (cond ((Info-no-error
1131 (Info-last-menu-item)
1132 ;; If we go down a menu item, go to the end of the node
1133 ;; so we can scroll back through it.
1134 (goto-char (point-max)))
1136 ((Info-no-error (Info-prev))
1137 (goto-char (point-max))
1139 ((Info-no-error (Info-up))
1140 (goto-char (point-min))
1141 (or (search-forward "\n* Menu:" nil t
)
1142 (goto-char (point-max))))
1143 (t (error "No previous nodes"))))
1145 (defun Info-scroll-up ()
1146 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1147 Once you scroll far enough in a node that its menu appears on the screen,
1148 the next scroll moves into its first subnode. When you scroll past
1149 the end of a node, that goes to the next node or back up to the parent node."
1151 (if (or (< (window-start) (point-min))
1152 (> (window-start) (point-max)))
1153 (set-window-start (selected-window) (point)))
1154 (let ((virtual-end (save-excursion
1155 (goto-char (point-min))
1156 (if (search-forward "\n* Menu:" nil t
)
1159 (if (or (< virtual-end
(window-start))
1160 (pos-visible-in-window-p virtual-end
))
1161 (Info-next-preorder)
1164 (defun Info-scroll-down ()
1165 "Scroll one screenful back in Info, considering all nodes as one sequence.
1166 Within the menu of a node, this goes to its last subnode.
1167 When you scroll past the beginning of a node, that goes to the
1168 previous node or back up to the parent node."
1170 (if (or (< (window-start) (point-min))
1171 (> (window-start) (point-max)))
1172 (set-window-start (selected-window) (point)))
1173 (let ((virtual-end (save-excursion
1174 (goto-char (point-min))
1175 (search-forward "\n* Menu:" nil t
))))
1176 (if (or virtual-end
(pos-visible-in-window-p (point-min)))
1177 (Info-last-preorder)
1180 (defun Info-next-reference ()
1181 "Move cursor to the next cross-reference or menu item in the node."
1183 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1185 (or (eobp) (forward-char 1))
1186 (or (re-search-forward pat nil t
)
1188 (goto-char (point-min))
1189 (or (re-search-forward pat nil t
)
1192 (error "No cross references in this node")))))
1193 (goto-char (match-beginning 0))
1194 (if (looking-at "\\* Menu:")
1195 (Info-next-reference))))
1197 (defun Info-prev-reference ()
1198 "Move cursor to the previous cross-reference or menu item in the node."
1200 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1202 (or (re-search-backward pat nil t
)
1204 (goto-char (point-max))
1205 (or (re-search-backward pat nil t
)
1208 (error "No cross references in this node")))))
1209 (goto-char (match-beginning 0))
1210 (if (looking-at "\\* Menu:")
1211 (Info-prev-reference))))
1213 (defun Info-index (topic)
1214 "Look up a string in the index for this file.
1215 The index is defined as the first node in the top-level menu whose
1216 name contains the word \"Index\", plus any immediately following
1217 nodes whose names also contain the word \"Index\".
1218 If there are no exact matches to the specified topic, this chooses
1219 the first match which is a case-insensitive substring of a topic.
1220 Use the `,' command to see the other matches.
1221 Give a blank topic name to go to the Index node itself."
1222 (interactive "sIndex topic: ")
1223 (let ((orignode Info-current-node
)
1225 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1226 (regexp-quote topic
)))
1228 (Info-goto-node "Top")
1229 (or (search-forward "\n* menu:" nil t
)
1231 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
1233 (goto-char (match-beginning 1))
1234 ;; Here, and subsequently in this function,
1235 ;; we bind Info-history to nil for internal node-switches
1236 ;; so that we don't put junk in the history.
1237 ;; In the first Info-goto-node call, above, we do update the history
1238 ;; because that is what the user's previous node choice into it.
1239 (let ((Info-history nil
))
1240 (Info-goto-node (Info-extract-menu-node-name)))
1241 (or (equal topic
"")
1248 (goto-char (point-min))
1249 (while (re-search-forward pattern nil t
)
1251 (cons (list (buffer-substring (match-beginning 1)
1253 (buffer-substring (match-beginning 2)
1256 (string-to-int (concat "0"
1261 (and (setq node
(Info-extract-pointer "next" t
))
1262 (string-match "\\<Index\\>" node
)))
1263 (Info-goto-node node
))
1267 (error "No \"%s\" in index" topic
)))
1268 ;; Here it is a feature that assoc is case-sensitive.
1269 (while (setq found
(assoc topic matches
))
1270 (setq exact
(cons found exact
)
1271 matches
(delq found matches
)))
1272 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
1273 (Info-index-next 0)))))
1275 (defun Info-index-next (num)
1276 "Go to the next matching index item from the last `i' command."
1278 (or Info-index-alternatives
1279 (error "No previous `i' command in this file"))
1281 (setq num
(+ num
(length Info-index-alternatives
))))
1283 (setq Info-index-alternatives
1284 (nconc (cdr Info-index-alternatives
)
1285 (list (car Info-index-alternatives
)))
1287 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
1288 (if (> (nth 3 (car Info-index-alternatives
)) 0)
1289 (forward-line (nth 3 (car Info-index-alternatives
)))
1290 (forward-line 3) ; don't search in headers
1291 (let ((name (car (car Info-index-alternatives
))))
1292 (if (or (re-search-forward (format
1293 "\\(Function\\|Command\\): %s\\( \\|$\\)"
1294 (regexp-quote name
)) nil t
)
1295 (search-forward (format "`%s'" name
) nil t
)
1296 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
1298 (format "`%s'" (substring name
0 (match-beginning 1)))
1300 (search-forward name nil t
))
1302 (goto-char (point-min)))))
1303 (message "Found \"%s\" in %s. %s"
1304 (car (car Info-index-alternatives
))
1305 (nth 2 (car Info-index-alternatives
))
1306 (if (cdr Info-index-alternatives
)
1307 "(Press `,' for more)"
1310 (defun Info-undefined ()
1311 "Make command be undefined in Info."
1316 "Enter the Info tutorial."
1318 (delete-other-windows)
1319 (Info-find-node "info"
1320 (if (< (window-height) 23)
1324 (defun Info-summary ()
1325 "Display a brief summary of all Info commands."
1327 (save-window-excursion
1328 (switch-to-buffer "*Help*")
1330 (insert (documentation 'Info-mode
))
1332 (goto-char (point-min))
1334 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
1335 (message (if flag
"Type Space to see more"
1336 "Type Space to return to Info"))
1337 (if (not (eq ?\
(setq ch
(read-event))))
1338 (progn (setq unread-command-events
(list ch
)) nil
)
1341 (bury-buffer "*Help*")))
1343 (defun Info-get-token (pos start all
&optional errorstring
)
1344 "Return the token around POS,
1345 POS must be somewhere inside the token
1346 START is a regular expression which will match the
1347 beginning of the tokens delimited string
1348 ALL is a regular expression with a single
1349 parenthized subpattern which is the token to be
1350 returned. E.g. '{\(.*\)}' would return any string
1351 enclosed in braces around POS.
1352 SIG optional fourth argument, controls action on no match
1355 a string: signal an error, using that string."
1358 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)
1360 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
1361 (not (setq found
(and (<= (match-beginning 0) pos
)
1362 (> (match-end 0) pos
))))))
1363 (if (and found
(<= (match-beginning 0) pos
)
1364 (> (match-end 0) pos
))
1365 (buffer-substring (match-beginning 1) (match-end 1))
1366 (cond ((null errorstring
)
1372 (error "No %s around position %d" errorstring pos
)))))))
1374 (defun Info-mouse-follow-nearest-node (click)
1375 "\\<Info-mode-map>Follow a node reference near point.
1376 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1377 At end of the node's text, moves to the next node, or up if none."
1379 (let* ((start (event-start click
))
1380 (window (car start
))
1381 (pos (car (cdr start
))))
1382 (select-window window
)
1384 (and (not (Info-try-follow-nearest-node))
1385 (save-excursion (forward-line 1) (eobp))
1386 (Info-next-preorder)))
1388 (defun Info-follow-nearest-node ()
1389 "\\<Info-mode-map>Follow a node reference near point.
1390 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1391 If no reference to follow, moves to the next node, or up if none."
1393 (or (Info-try-follow-nearest-node)
1394 (Info-next-preorder)))
1396 ;; Common subroutine.
1397 (defun Info-try-follow-nearest-node ()
1398 "Follow a node reference near point. Return non-nil if successful."
1401 ((setq node
(Info-get-token (point) "\\*note[ \n]"
1402 "\\*note[ \n]\\([^:]*\\):"))
1403 (Info-follow-reference node
))
1404 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1405 (Info-goto-node node
))
1406 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1408 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1409 (Info-goto-node node
))
1410 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1411 (Info-goto-node node
))
1412 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1413 (Info-goto-node "Top"))
1414 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1415 (Info-goto-node node
)))
1418 (defvar Info-mode-map nil
1419 "Keymap containing Info commands.")
1422 (setq Info-mode-map
(make-keymap))
1423 (suppress-keymap Info-mode-map
)
1424 (define-key Info-mode-map
"." 'beginning-of-buffer
)
1425 (define-key Info-mode-map
" " 'Info-scroll-up
)
1426 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
1427 (define-key Info-mode-map
"\t" 'Info-next-reference
)
1428 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
1429 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
1430 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
1431 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
1432 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
1433 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
1434 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
1435 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
1436 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
1437 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
1438 (define-key Info-mode-map
"0" 'undefined
)
1439 (define-key Info-mode-map
"?" 'Info-summary
)
1440 (define-key Info-mode-map
"]" 'Info-forward-node
)
1441 (define-key Info-mode-map
"[" 'Info-backward-node
)
1442 (define-key Info-mode-map
"<" 'Info-top-node
)
1443 (define-key Info-mode-map
">" 'Info-final-node
)
1444 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
1445 (define-key Info-mode-map
"d" 'Info-directory
)
1446 (define-key Info-mode-map
"e" 'Info-edit
)
1447 (define-key Info-mode-map
"f" 'Info-follow-reference
)
1448 (define-key Info-mode-map
"g" 'Info-goto-node
)
1449 (define-key Info-mode-map
"h" 'Info-help
)
1450 (define-key Info-mode-map
"i" 'Info-index
)
1451 (define-key Info-mode-map
"l" 'Info-last
)
1452 (define-key Info-mode-map
"m" 'Info-menu
)
1453 (define-key Info-mode-map
"n" 'Info-next
)
1454 (define-key Info-mode-map
"p" 'Info-prev
)
1455 (define-key Info-mode-map
"q" 'Info-exit
)
1456 (define-key Info-mode-map
"s" 'Info-search
)
1457 ;; For consistency with Rmail.
1458 (define-key Info-mode-map
"\M-s" 'Info-search
)
1459 (define-key Info-mode-map
"t" 'Info-top-node
)
1460 (define-key Info-mode-map
"u" 'Info-up
)
1461 (define-key Info-mode-map
"," 'Info-index-next
)
1462 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
1463 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
1466 ;; Info mode is suitable only for specially formatted data.
1467 (put 'info-mode
'mode-class
'special
)
1471 Info mode provides commands for browsing through the Info documentation tree.
1472 Documentation in Info is divided into \"nodes\", each of which discusses
1473 one topic and contains references to other nodes which discuss related
1474 topics. Info has commands to follow the references and show you other nodes.
1476 \\[Info-help] Invoke the Info tutorial.
1478 Selecting other nodes:
1479 \\[Info-mouse-follow-nearest-node]
1480 Follow a node reference you click on.
1481 This works with menu items, cross references, and
1482 the \"next\", \"previous\" and \"up\", depending on where you click.
1483 \\[Info-next] Move to the \"next\" node of this node.
1484 \\[Info-prev] Move to the \"previous\" node of this node.
1485 \\[Info-up] Move \"up\" from this node.
1486 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1487 Picking a menu item causes another node to be selected.
1488 \\[Info-directory] Go to the Info directory node.
1489 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1490 \\[Info-last] Move to the last node you were at.
1491 \\[Info-index] Look up a topic in this file's Index and move to that node.
1492 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1494 Moving within a node:
1495 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1496 already visible, try to go to the next menu entry, or up if there is none.
1497 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1498 already visible, try to go to the previous menu entry, or up if there is none.
1499 \\[beginning-of-buffer] Go to beginning of node.
1502 \\[Info-exit] Quit Info: reselect previously selected buffer.
1503 \\[Info-edit] Edit contents of selected node.
1504 1 Pick first item in node's menu.
1505 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1506 \\[Info-goto-node] Move to node specified by name.
1507 You may include a filename as well, as (FILENAME)NODENAME.
1508 \\[universal-argument] \\[info] Move to new Info file with completion.
1509 \\[Info-search] Search through this Info file for specified regexp,
1510 and select the node in which the next occurrence is found.
1511 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1512 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1513 (kill-all-local-variables)
1514 (setq major-mode
'Info-mode
)
1515 (setq mode-name
"Info")
1516 (use-local-map Info-mode-map
)
1517 (set-syntax-table text-mode-syntax-table
)
1518 (setq local-abbrev-table text-mode-abbrev-table
)
1519 (setq case-fold-search t
)
1520 (setq buffer-read-only t
)
1521 (make-local-variable 'Info-current-file
)
1522 (make-local-variable 'Info-current-subfile
)
1523 (make-local-variable 'Info-current-node
)
1524 (make-local-variable 'Info-tag-table-marker
)
1525 (make-local-variable 'Info-history
)
1526 (make-local-variable 'Info-index-alternatives
)
1527 (if (memq (framep (selected-frame)) '(x pc
))
1529 (make-face 'info-node
)
1530 (make-face 'info-menu-5
)
1531 (make-face 'info-xref
)
1532 (or (face-differs-from-default-p 'info-node
)
1533 (if (face-differs-from-default-p 'bold-italic
)
1534 (copy-face 'bold-italic
'info-node
)
1535 (copy-face 'bold
'info-node
)))
1536 (or (face-differs-from-default-p 'info-menu-5
)
1537 (set-face-underline-p 'info-menu-5 t
))
1538 (or (face-differs-from-default-p 'info-xref
)
1539 (copy-face 'bold
'info-xref
)))
1540 (setq Info-fontify nil
))
1541 (Info-set-mode-line)
1542 (run-hooks 'Info-mode-hook
))
1544 (defvar Info-edit-map nil
1545 "Local keymap used within `e' command of Info.")
1548 (setq Info-edit-map
(nconc (make-sparse-keymap) text-mode-map
))
1549 (define-key Info-edit-map
"\C-c\C-c" 'Info-cease-edit
))
1551 ;; Info-edit mode is suitable only for specially formatted data.
1552 (put 'info-edit-mode
'mode-class
'special
)
1554 (defun Info-edit-mode ()
1555 "Major mode for editing the contents of an Info node.
1556 Like text mode with the addition of `Info-cease-edit'
1557 which returns to Info mode for browsing.
1559 (use-local-map Info-edit-map
)
1560 (setq major-mode
'Info-edit-mode
)
1561 (setq mode-name
"Info Edit")
1562 (kill-local-variable 'mode-line-buffer-identification
)
1563 (setq buffer-read-only nil
)
1564 (force-mode-line-update)
1565 (buffer-enable-undo (current-buffer))
1566 (run-hooks 'Info-edit-mode-hook
))
1569 "Edit the contents of this Info node.
1570 Allowed only if variable `Info-enable-edit' is non-nil."
1572 (or Info-enable-edit
1573 (error "Editing info nodes is not enabled"))
1575 (message (substitute-command-keys
1576 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1578 (defun Info-cease-edit ()
1579 "Finish editing Info node; switch back to Info proper."
1581 ;; Do this first, so nothing has changed if user C-g's at query.
1582 (and (buffer-modified-p)
1583 (y-or-n-p "Save the file? ")
1585 (use-local-map Info-mode-map
)
1586 (setq major-mode
'Info-mode
)
1587 (setq mode-name
"Info")
1588 (Info-set-mode-line)
1589 (setq buffer-read-only t
)
1590 (force-mode-line-update)
1591 (and (marker-position Info-tag-table-marker
)
1593 (message "Tags may have changed. Use Info-tagify if necessary")))
1595 (defun Info-find-emacs-command-nodes (command)
1596 "Return a list of locations documenting COMMAND in the Emacs Info manual.
1597 The locations are of the format used in Info-history, i.e.
1598 \(FILENAME NODENAME BUFFERPOS\)."
1601 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command
))
1602 ":\\s *\\(.*\\)\\.$")))
1604 (Info-find-node "emacs" "Command Index")
1605 ;; Take the index node off the Info history.
1606 (setq Info-history
(cdr Info-history
))
1607 (goto-char (point-max))
1608 (while (re-search-backward cmd-desc nil t
)
1609 (setq where
(cons (list Info-current-file
1618 (defun Info-goto-emacs-command-node (command)
1619 "Go to the Info node in the Emacs manual for command COMMAND.
1620 The command is found by looking up in Emacs manual's Command Index."
1621 (interactive "CFind documentation for command: ")
1622 (or (commandp command
)
1623 (signal 'wrong-type-argument
(list 'commandp command
)))
1624 (let ((where (Info-find-emacs-command-nodes command
)))
1626 (let ((num-matches (length where
)))
1627 ;; Get Info running, and pop to it in another window.
1628 (save-window-excursion
1630 (pop-to-buffer "*info*")
1631 (Info-find-node (car (car where
))
1632 (car (cdr (car where
))))
1633 (if (> num-matches
1)
1635 ;; Info-find-node already pushed (car where) onto
1636 ;; Info-history. Put the other nodes that were found on
1638 (setq Info-history
(nconc (cdr where
) Info-history
))
1639 (message (substitute-command-keys
1640 "Found %d other entr%s. Use \\[Info-last] to see %s.")
1642 (if (> num-matches
2) "ies" "y")
1643 (if (> num-matches
2) "them" "it")))))
1644 (error "Couldn't find documentation for %s." command
))))
1647 (defun Info-goto-emacs-key-command-node (key)
1648 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1649 Interactively, if the binding is execute-extended-command, a command is read.
1650 The command is found by looking up in Emacs manual's Command Index."
1651 (interactive "kFind documentation for key:")
1652 (let ((command (key-binding key
)))
1653 (cond ((null command
)
1654 (message "%s is undefined" (key-description key
)))
1655 ((and (interactive-p)
1656 (eq command
'execute-extended-command
))
1657 (Info-goto-emacs-command-node
1658 (read-command "Find documentation for command: ")))
1660 (Info-goto-emacs-command-node command
)))))
1662 (defun Info-fontify-node ()
1664 (let ((buffer-read-only nil
))
1665 (goto-char (point-min))
1666 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1668 (goto-char (match-end 0))
1670 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1671 (goto-char (match-end 0))
1672 (put-text-property (match-beginning 1) (match-end 1)
1674 (put-text-property (match-beginning 1) (match-end 1)
1675 'mouse-face
'highlight
))))
1676 (goto-char (point-min))
1677 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t
)
1678 (if (= (char-after (1- (match-beginning 0))) ?
\") ; hack
1680 (put-text-property (match-beginning 1) (match-end 1)
1682 (put-text-property (match-beginning 1) (match-end 1)
1683 'mouse-face
'highlight
)))
1684 (goto-char (point-min))
1685 (if (and (search-forward "\n* Menu:" nil t
)
1686 (not (string-match "\\<Index\\>" Info-current-node
))
1687 ;; Don't take time to annotate huge menus
1688 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
1690 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t
)
1692 (if (memq n
'(5 9)) ; visual aids to help with 1-9 keys
1693 (put-text-property (match-beginning 0)
1694 (1+ (match-beginning 0))
1695 'face
'info-menu-5
))
1696 (put-text-property (match-beginning 1) (match-end 1)
1698 (put-text-property (match-beginning 1) (match-end 1)
1699 'mouse-face
'highlight
))))
1700 (set-buffer-modified-p nil
))))
1704 ;;; info.el ends here