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 the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; Note that nowadays we expect info files to be made using makeinfo.
31 (defvar Info-history nil
32 "List of info nodes user has visited.
33 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
35 (defvar Info-enable-edit nil
36 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
37 This is convenient if you want to write info files by hand.
38 However, we recommend that you not do this.
39 It is better to write a Texinfo file and generate the Info file from that,
40 because that gives you a printed manual as well.")
42 (defvar Info-enable-active-nodes t
43 "Non-nil allows Info to execute Lisp code associated with nodes.
44 The Lisp code is executed when the node is selected.")
46 (defvar Info-fontify t
47 "*Non-nil enables highlighting and fonts in Info nodes.")
49 (defvar Info-fontify-maximum-menu-size
30000
50 "*Maximum size of menu to fontify if `Info-fontify' is non-nil.")
52 (defvar Info-directory-list
53 (let ((path (getenv "INFOPATH"))
54 ;; This is for older Emacs versions
55 ;; which might get this info.el from the Texinfo distribution.
56 (path-separator (if (boundp 'path-separator
) path-separator
57 (if (eq system-type
'ms-dos
) ";" ":")))
58 (source (expand-file-name "info/" source-directory
))
59 (sibling (if installation-directory
60 (expand-file-name "info/" installation-directory
)))
65 (while (> (length path
) 0)
66 (setq idx
(or (string-match path-separator path
) (length path
))
67 list
(cons (substring path
0 idx
) list
)
68 path
(substring path
(min (1+ idx
)
71 (if (and sibling
(file-exists-p sibling
))
72 (setq alternative sibling
)
73 (setq alternative source
))
74 (if (or (member alternative Info-default-directory-list
)
75 (not (file-exists-p alternative
))
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 alternative
87 (cdr (reverse Info-default-directory-list
)))))))
88 "List of directories to search for Info documentation files.
89 nil means not yet initialized. In this case, Info uses the environment
90 variable INFOPATH to initialize it, or `Info-default-directory-list'
91 if there is no INFOPATH variable in the environment.
92 The last element of `Info-default-directory-list' is the directory
93 where Emacs installs the Info files that come with it.
95 If you run the Emacs executable from the `src' directory in the Emacs
96 source tree, the `info' directory in the source tree is used as the last
97 element, in place of the installation Info directory. This is useful
98 when you run a version of Emacs without installing it.")
100 (defvar Info-additional-directory-list nil
101 "List of additional directories to search for Info documentation files.
102 These directories are not searched for merging the `dir' file.")
104 (defvar Info-current-file nil
105 "Info file that Info is now looking at, or nil.
106 This is the name that was specified in Info, not the actual file name.
107 It doesn't contain directory names or file name extensions added by Info.")
109 (defvar Info-current-subfile nil
110 "Info subfile that is actually in the *info* buffer now,
111 or nil if current info file is not split into subfiles.")
113 (defvar Info-current-node nil
114 "Name of node that Info is now looking at, or nil.")
116 (defvar Info-tag-table-marker
(make-marker)
117 "Marker pointing at beginning of current Info file's tag table.
118 Marker points nowhere if file has no tag table.")
120 (defvar Info-current-file-completions nil
121 "Cached completion list for current Info file.")
123 (defvar Info-index-alternatives nil
124 "List of possible matches for last Info-index command.")
126 (defvar Info-standalone nil
127 "Non-nil if Emacs was started solely as an Info browser.")
129 (defvar Info-suffix-list
130 (if (eq system-type
'ms-dos
)
131 '( (".gz" .
"gunzip")
135 '( (".info.Z" .
"uncompress")
136 (".info.Y" .
"unyabba")
137 (".info.gz" .
"gunzip")
138 (".info.z" .
"gunzip")
140 (".Z" .
"uncompress")
145 "List of file name suffixes and associated decoding commands.
146 Each entry should be (SUFFIX . STRING); the file is given to
147 the command as standard input. If STRING is nil, no decoding is done.
148 Because the SUFFIXes are tried in order, the empty string should
149 be last in the list.")
151 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
152 ;; First, on ms-dos, delete some of the extension in FILENAME
154 (defun info-insert-file-contents-1 (filename suffix
)
155 (if (not (eq system-type
'ms-dos
))
156 (concat filename suffix
)
157 (let* ((sans-exts (file-name-sans-extension filename
))
158 ;; How long is the extension in FILENAME (not counting the dot).
159 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
161 ;; SUFFIX starts with a dot. If FILENAME already has one,
162 ;; get rid of the one in SUFFIX.
163 (or (and (<= ext-len
0)
164 (not (eq (aref filename
(1- (length filename
))) ?.
)))
165 (setq suffix
(substring suffix
1)))
166 ;; How many chars of that extension should we keep?
167 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
168 ;; Get rid of the rest of the extension, and add SUFFIX.
169 (concat (substring filename
0 (- (length filename
)
170 (- ext-len ext-left
)))
173 (defun info-insert-file-contents (filename &optional visit
)
174 "Insert the contents of an info file in the current buffer.
175 Do the right thing if the file has been compressed or zipped."
176 (let ((tail Info-suffix-list
)
178 (if (file-exists-p filename
)
179 ;; FILENAME exists--see if that name contains a suffix.
180 ;; If so, set DECODE accordingly.
184 (concat (regexp-quote (car (car tail
))) "$")
186 (setq tail
(cdr tail
)))
187 (setq fullname filename
188 decoder
(cdr (car tail
))))
189 ;; Try adding suffixes to FILENAME and see if we can find something.
191 (not (file-exists-p (info-insert-file-contents-1
192 filename
(car (car tail
))))))
193 (setq tail
(cdr tail
)))
194 ;; If we found a file with a suffix, set DECODER according to the suffix
195 ;; and set FULLNAME to the file's actual name.
196 (setq fullname
(info-insert-file-contents-1 filename
(car (car tail
)))
197 decoder
(cdr (car tail
)))
199 (error "Can't find %s or any compressed version of it" filename
)))
200 ;; check for conflict with jka-compr
201 (if (and (featurep 'jka-compr
)
202 (jka-compr-installed-p)
203 (jka-compr-get-compression-info fullname
))
205 (insert-file-contents fullname visit
)
207 (let ((buffer-read-only nil
)
208 (default-directory (or (file-name-directory fullname
)
210 (call-process-region (point-min) (point-max) decoder t t
)))))
212 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
215 (defun info (&optional file
)
216 "Enter Info, the documentation browser.
217 Optional argument FILE specifies the file to examine;
218 the default is the top-level directory of Info.
220 In interactive use, a prefix argument directs this command
221 to read a file name from the minibuffer."
222 (interactive (if current-prefix-arg
223 (list (read-file-name "Info file name: " nil nil t
))))
225 (Info-goto-node (concat "(" file
")"))
226 (if (get-buffer "*info*")
227 (pop-to-buffer "*info*")
231 (defun info-standalone ()
232 "Run Emacs as a standalone Info reader.
233 Usage: emacs -f info-standalone [filename]
234 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
235 (setq Info-standalone t
)
236 (if (and command-line-args-left
237 (not (string-match "^-" (car command-line-args-left
))))
240 (info (car command-line-args-left
))
241 (setq command-line-args-left
(cdr command-line-args-left
)))
242 (error (send-string-to-terminal
243 (format "%s\n" (if (eq (car-safe err
) 'error
)
245 (save-buffers-kill-emacs)))
248 ;; Go to an info node specified as separate filename and nodename.
249 ;; no-going-back is non-nil if recovering from an error in this function;
250 ;; it says do not attempt further (recursive) error recovery.
251 (defun Info-find-node (filename nodename
&optional no-going-back
)
252 ;; Convert filename to lower case if not found as specified.
255 (let (temp temp-downcase found
)
256 (setq filename
(substitute-in-file-name filename
))
257 (if (string= (downcase (file-name-nondirectory filename
)) "dir")
259 (let ((dirs (if (string-match "^\\./" filename
)
260 ;; If specified name starts with `./'
261 ;; then just try current directory.
263 (if (file-name-absolute-p filename
)
264 ;; No point in searching for an
265 ;; absolute file name
267 (if Info-additional-directory-list
268 (append Info-directory-list
269 Info-additional-directory-list
)
270 Info-directory-list
)))))
271 ;; Search the directory list for file FILENAME.
272 (while (and dirs
(not found
))
273 (setq temp
(expand-file-name filename
(car dirs
)))
275 (expand-file-name (downcase filename
) (car dirs
)))
276 ;; Try several variants of specified name.
277 (let ((suffix-list Info-suffix-list
))
278 (while (and suffix-list
(not found
))
279 (cond ((file-exists-p
280 (info-insert-file-contents-1
281 temp
(car (car suffix-list
))))
284 (info-insert-file-contents-1
285 temp-downcase
(car (car suffix-list
))))
286 (setq found temp-downcase
)))
287 (setq suffix-list
(cdr suffix-list
))))
288 (setq dirs
(cdr dirs
)))))
290 (setq filename found
)
291 (error "Info file %s does not exist" filename
))))
292 ;; Record the node we are leaving.
293 (if (and Info-current-file
(not no-going-back
))
295 (cons (list Info-current-file Info-current-node
(point))
297 ;; Go into info buffer.
298 (switch-to-buffer "*info*")
299 (buffer-disable-undo (current-buffer))
300 (or (eq major-mode
'Info-mode
)
303 (setq Info-current-node nil
)
306 ;; Switch files if necessary
308 (equal Info-current-file filename
)
309 (let ((buffer-read-only nil
))
310 (setq Info-current-file nil
311 Info-current-subfile nil
312 Info-current-file-completions nil
313 Info-index-alternatives nil
314 buffer-file-name nil
)
318 (info-insert-file-contents filename t
)
319 (setq default-directory
(file-name-directory filename
)))
320 (set-buffer-modified-p nil
)
321 ;; See whether file has a tag table. Record the location if yes.
322 (set-marker Info-tag-table-marker nil
)
323 (goto-char (point-max))
325 ;; Use string-equal, not equal, to ignore text props.
326 (or (string-equal nodename
"*")
327 (not (search-forward "\^_\nEnd tag table\n" nil t
))
329 ;; We have a tag table. Find its beginning.
330 ;; Is this an indirect file?
331 (search-backward "\nTag table:\n")
335 (looking-at "(Indirect)\n"))
336 ;; It is indirect. Copy it to another buffer
337 ;; and record that the tag table is in that buffer.
339 (let ((buf (current-buffer)))
340 (set-buffer (get-buffer-create " *info tag table*"))
341 (buffer-disable-undo (current-buffer))
342 (setq case-fold-search t
)
344 (insert-buffer-substring buf
)
345 (set-marker Info-tag-table-marker
347 (set-marker Info-tag-table-marker pos
))))
348 (setq Info-current-file
349 (if (eq filename t
) "dir" filename
))))
350 ;; Use string-equal, not equal, to ignore text props.
351 (if (string-equal nodename
"*")
352 (progn (setq Info-current-node nodename
)
353 (Info-set-mode-line))
354 ;; Search file for a suitable node.
355 (let ((guesspos (point-min))
356 (regexp (concat "Node: *" (regexp-quote nodename
) " *[,\t\n\177]")))
357 ;; First get advice from tag table if file has one.
358 ;; Also, if this is an indirect info file,
359 ;; read the proper subfile into this buffer.
360 (if (marker-position Info-tag-table-marker
)
362 (set-buffer (marker-buffer Info-tag-table-marker
))
363 (goto-char Info-tag-table-marker
)
364 (if (re-search-forward regexp nil t
)
366 (setq guesspos
(read (current-buffer)))
367 ;; If this is an indirect file,
368 ;; determine which file really holds this node
370 (if (not (eq (current-buffer) (get-buffer "*info*")))
372 (Info-read-subfile guesspos
))))
373 (error "No such node: \"%s\"" nodename
))))
374 (goto-char (max (point-min) (- guesspos
1000)))
375 ;; Now search from our advised position (or from beg of buffer)
376 ;; to find the actual node.
378 (while (search-forward "\n\^_" nil t
)
382 (if (re-search-backward regexp beg t
)
384 (error "No such node: %s" nodename
)))
386 ;; If we did not finish finding the specified node,
387 ;; go back to the previous one.
388 (or Info-current-node no-going-back
(null Info-history
)
389 (let ((hist (car Info-history
)))
390 (setq Info-history
(cdr Info-history
))
391 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
392 (goto-char (nth 2 hist
)))))
393 (goto-char (point-min)))
395 ;; Cache the contents of the (virtual) dir file, once we have merged
396 ;; it for the first time, so we can save time subsequently.
397 (defvar Info-dir-contents nil
)
399 ;; Cache for the directory we decided to use for the default-directory
400 ;; of the merged dir text.
401 (defvar Info-dir-contents-directory nil
)
403 ;; Record the file attributes of all the files from which we
404 ;; constructed Info-dir-contents.
405 (defvar Info-dir-file-attributes nil
)
407 ;; Construct the Info directory node by merging the files named `dir'
408 ;; from various directories. Set the *info* buffer's
409 ;; default-directory to the first directory we actually get any text
411 (defun Info-insert-dir ()
412 (if (and Info-dir-contents Info-dir-file-attributes
413 ;; Verify that none of the files we used has changed
416 (mapcar '(lambda (elt)
417 (let ((curr (file-attributes (car elt
))))
418 ;; Don't compare the access time.
419 (if curr
(setcar (nthcdr 4 curr
) 0))
420 (setcar (nthcdr 4 (cdr elt
)) 0)
421 (equal (cdr elt
) curr
)))
422 Info-dir-file-attributes
))))
423 (insert Info-dir-contents
)
424 (let ((dirs Info-directory-list
)
425 buffers buffer others nodes dirs-done
)
427 (setq Info-dir-file-attributes nil
)
429 ;; Search the directory list for the directory file.
431 (let ((truename (file-truename (expand-file-name (car dirs
)))))
432 (or (member truename dirs-done
)
433 (member (directory-file-name truename
) dirs-done
)
434 ;; Try several variants of specified name.
435 ;; Try upcasing, appending `.info', or both.
439 (progn (setq file
(expand-file-name "dir" truename
))
440 (file-attributes file
))
441 (progn (setq file
(expand-file-name "DIR" truename
))
442 (file-attributes file
))
443 (progn (setq file
(expand-file-name "dir.info" truename
))
444 (file-attributes file
))
445 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
446 (file-attributes file
)))))
449 (cons (directory-file-name truename
)
454 (message "Composing main Info directory..."))
455 (set-buffer (generate-new-buffer "info dir"))
456 (insert-file-contents file
)
457 (setq buffers
(cons (current-buffer) buffers
)
458 Info-dir-file-attributes
459 (cons (cons file attrs
)
460 Info-dir-file-attributes
))))))
461 (setq dirs
(cdr dirs
))))
464 (error "Can't find the info directory node"))
465 ;; Distinguish the dir file that comes with Emacs from all the
466 ;; others. Yes, that is really what this is supposed to do.
467 ;; If it doesn't work, fix it.
468 (setq buffer
(car buffers
)
469 others
(cdr buffers
))
471 ;; Insert the entire original dir file as a start; use its
472 ;; default directory as the default directory for the whole
474 (insert-buffer buffer
)
475 (setq Info-dir-contents-directory
(save-excursion
479 ;; Look at each of the other buffers one by one.
481 (let ((other (car others
)))
482 ;; In each, find all the menus.
485 (goto-char (point-min))
486 ;; Find each menu, and add an elt to NODES for it.
487 (while (re-search-forward "^\\* Menu:" nil t
)
488 (let (beg nodename end
)
491 (search-backward "\n\^_")
492 (search-forward "Node: ")
493 (setq nodename
(Info-following-node-name))
494 (search-forward "\n\^_" nil
'move
)
497 (setq nodes
(cons (list nodename other beg end
) nodes
))))))
498 (setq others
(cdr others
)))
499 ;; Add to the main menu a menu item for each other node.
500 (re-search-forward "^\\* Menu:")
502 (let ((menu-items '("top"))
505 (end (save-excursion (search-forward "\^_" nil t
) (point))))
507 (let ((nodename (car (car nodes
))))
509 (or (member (downcase nodename
) menu-items
)
510 (re-search-forward (concat "^\\* "
511 (regexp-quote nodename
)
515 (insert "* " nodename
"::" "\n")
516 (setq menu-items
(cons nodename menu-items
))))))
517 (setq nodes
(cdr nodes
))))
518 ;; Now take each node of each of the other buffers
519 ;; and merge it into the main buffer.
521 (let ((nodename (car (car nodes
))))
522 (goto-char (point-min))
523 ;; Find the like-named node in the main buffer.
524 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
525 (regexp-quote nodename
)
529 (search-forward "\n\^_" nil
'move
)
532 ;; If none exists, add one.
533 (goto-char (point-max))
534 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
535 ;; Merge the text from the other buffer's menu
536 ;; into the menu in the like-named node in the main buffer.
537 (apply 'insert-buffer-substring
(cdr (car nodes
))))
538 (setq nodes
(cdr nodes
)))
539 ;; Kill all the buffers we just made.
541 (kill-buffer (car buffers
))
542 (setq buffers
(cdr buffers
)))
543 (message "Composing main Info directory...done"))
544 (setq Info-dir-contents
(buffer-string)))
545 (setq default-directory Info-dir-contents-directory
))
547 (defun Info-read-subfile (nodepos)
548 (set-buffer (marker-buffer Info-tag-table-marker
))
549 (goto-char (point-min))
550 (search-forward "\n\^_")
555 (while (not (looking-at "\^_"))
558 thisfilepos thisfilename
)
559 (search-forward ": ")
560 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
561 (setq thisfilepos
(read (current-buffer)))
562 ;; read in version 19 stops at the end of number.
563 ;; Advance to the next line.
565 (if (> thisfilepos nodepos
)
567 (setq lastfilename thisfilename
)
568 (setq lastfilepos thisfilepos
))
570 (set-buffer (get-buffer "*info*"))
571 (or (equal Info-current-subfile lastfilename
)
572 (let ((buffer-read-only nil
))
573 (setq buffer-file-name nil
)
576 (info-insert-file-contents lastfilename
)
577 (set-buffer-modified-p nil
)
578 (setq Info-current-subfile lastfilename
)))
579 (goto-char (point-min))
580 (search-forward "\n\^_")
581 (+ (- nodepos lastfilepos
) (point))))
583 ;; Select the info node that point is in.
584 (defun Info-select-node ()
586 ;; Find beginning of node.
587 (search-backward "\n\^_")
589 ;; Get nodename spelled as it is in the node.
590 (re-search-forward "Node:[ \t]*")
591 (setq Info-current-node
592 (buffer-substring-no-properties (point)
594 (skip-chars-forward "^,\t\n")
597 ;; Find the end of it, and narrow.
599 (let (active-expression)
600 (narrow-to-region (point)
601 (if (re-search-forward "\n[\^_\f]" nil t
)
604 (if (looking-at "[\n\^_\f]*execute: ")
606 (goto-char (match-end 0))
607 (setq active-expression
608 (read (current-buffer))))))
610 (if Info-enable-active-nodes
(eval active-expression
))
611 (if Info-fontify
(Info-fontify-node))
612 (run-hooks 'Info-selection-hook
))))
614 (defun Info-set-mode-line ()
615 (setq mode-line-buffer-identification
618 (if Info-current-file
619 (file-name-nondirectory Info-current-file
)
622 (or Info-current-node
""))))
624 ;; Go to an info node specified with a filename-and-nodename string
625 ;; of the sort that is found in pointers in nodes.
627 (defun Info-goto-node (nodename)
628 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
629 (interactive (list (Info-read-node-name "Goto node: ")))
631 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
633 (setq filename
(if (= (match-beginning 1) (match-end 1))
635 (substring nodename
(match-beginning 2) (match-end 2)))
636 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
637 (let ((trim (string-match "\\s *\\'" filename
)))
638 (if trim
(setq filename
(substring filename
0 trim
))))
639 (let ((trim (string-match "\\s *\\'" nodename
)))
640 (if trim
(setq nodename
(substring nodename
0 trim
))))
641 (if transient-mark-mode
(deactivate-mark))
642 (Info-find-node (if (equal filename
"") nil filename
)
643 (if (equal nodename
"") "Top" nodename
))))
645 ;; This function is used as the "completion table" while reading a node name.
646 ;; It does completion using the alist in completion-table
647 ;; unless STRING starts with an open-paren.
648 (defun Info-read-node-name-1 (string predicate code
)
649 (let ((no-completion (and (> (length string
) 0) (eq (aref string
0) ?\
())))
653 (try-completion string completion-table predicate
)))
657 (all-completions string completion-table predicate
)))
661 (assoc string completion-table
))))))
663 (defun Info-read-node-name (prompt &optional default
)
664 (let* ((completion-ignore-case t
)
665 (completion-table (Info-build-node-completions))
666 (nodename (completing-read prompt
'Info-read-node-name-1
)))
667 (if (equal nodename
"")
669 (Info-read-node-name prompt
))
672 (defun Info-build-node-completions ()
673 (or Info-current-file-completions
677 (if (marker-buffer Info-tag-table-marker
)
679 (set-buffer (marker-buffer Info-tag-table-marker
))
681 (goto-char Info-tag-table-marker
)
682 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t
)
684 (cons (list (buffer-substring (match-beginning 1)
688 (goto-char (point-min))
689 (while (search-forward "\n\^_" nil t
)
693 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
696 (cons (list (buffer-substring (match-beginning 1)
699 (setq Info-current-file-completions compl
))))
701 (defun Info-restore-point (hl)
702 "If this node has been visited, restore the point value when we left."
704 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
705 ;; Use string-equal, not equal, to ignore text props.
706 (string-equal (nth 1 (car hl
)) Info-current-node
))
708 (goto-char (nth 2 (car hl
)))
709 (setq hl nil
)) ;terminate the while at next iter
710 (setq hl
(cdr hl
)))))
712 (defvar Info-last-search nil
713 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
715 (defun Info-search (regexp)
716 "Search for REGEXP, starting from point, and select node it's found in."
717 (interactive "sSearch (regexp): ")
718 (if transient-mark-mode
(deactivate-mark))
719 (if (equal regexp
"")
720 (setq regexp Info-last-search
)
721 (setq Info-last-search regexp
))
722 (let ((found ()) current
723 (onode Info-current-node
)
724 (ofile Info-current-file
)
726 (osubfile Info-current-subfile
))
730 (if (null Info-current-subfile
)
731 (progn (re-search-forward regexp
) (setq found
(point)))
733 (progn (re-search-forward regexp
) (setq found
(point)))
734 (search-failed nil
)))))
735 (if (not found
) ;can only happen in subfile case -- else would have erred
738 (set-buffer (marker-buffer Info-tag-table-marker
))
739 (goto-char (point-min))
740 (search-forward "\n\^_\nIndirect:")
742 (narrow-to-region (point)
743 (progn (search-forward "\n\^_")
745 (goto-char (point-min))
746 (search-forward (concat "\n" osubfile
": "))
749 (re-search-forward "\\(^.*\\): [0-9]+$")
750 (goto-char (+ (match-end 1) 2))
751 (setq list
(cons (cons (read (current-buffer))
752 (buffer-substring (match-beginning 1)
755 (goto-char (1+ (match-end 0))))
756 (setq list
(nreverse list
)
757 current
(car (car list
))
760 (message "Searching subfile %s..." (cdr (car list
)))
761 (Info-read-subfile (car (car list
)))
762 (setq list
(cdr list
))
763 ;; (goto-char (point-min))
764 (if (re-search-forward regexp nil t
)
765 (setq found
(point) list
())))
768 (signal 'search-failed
(list regexp
))))
770 (progn (Info-read-subfile opoint
)
772 (Info-select-node)))))
776 ;; Use string-equal, not equal, to ignore text props.
777 (or (and (string-equal onode Info-current-node
)
778 (equal ofile Info-current-file
))
779 (setq Info-history
(cons (list ofile onode opoint
)
782 ;; Extract the value of the node-pointer named NAME.
783 ;; If there is none, use ERRORNAME in the error message;
784 ;; if ERRORNAME is nil, just return nil.
785 (defun Info-extract-pointer (name &optional errorname
)
787 (goto-char (point-min))
789 (if (re-search-backward (concat name
":") nil t
)
791 (goto-char (match-end 0))
792 (Info-following-node-name))
795 (error (concat "Node has no " (capitalize (or errorname name
))))))))
797 ;; Return the node name in the buffer following point.
798 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
799 ;; saying which chas may appear in the node name.
800 (defun Info-following-node-name (&optional allowedchars
)
801 (skip-chars-forward " \t")
802 (buffer-substring-no-properties
805 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
806 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
808 (skip-chars-forward "^)")))
809 (skip-chars-backward " ")
813 "Go to the next node of this node."
815 (Info-goto-node (Info-extract-pointer "next")))
818 "Go to the previous node of this node."
820 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
823 "Go to the superior node of this node."
825 (Info-goto-node (Info-extract-pointer "up"))
826 (Info-restore-point Info-history
))
829 "Go back to the last node visited."
832 (error "This is the first Info node you looked at"))
833 (let (filename nodename opoint
)
834 (setq filename
(car (car Info-history
)))
835 (setq nodename
(car (cdr (car Info-history
))))
836 (setq opoint
(car (cdr (cdr (car Info-history
)))))
837 (setq Info-history
(cdr Info-history
))
838 (Info-find-node filename nodename
)
839 (setq Info-history
(cdr Info-history
))
842 (defun Info-directory ()
843 "Go to the Info directory node."
845 (Info-find-node "dir" "top"))
847 (defun Info-follow-reference (footnotename)
848 "Follow cross reference named NAME to the node it refers to.
849 NAME may be an abbreviation of the reference name."
851 (let ((completion-ignore-case t
)
852 completions default alt-default
(start-point (point)) str i bol eol
)
854 ;; Store end and beginning of line.
860 (goto-char (point-min))
861 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
862 (setq str
(buffer-substring
865 ;; See if this one should be the default.
867 (<= (match-beginning 0) start-point
)
868 (<= start-point
(point))
870 ;; See if this one should be the alternate default.
871 (and (null alt-default
)
872 (and (<= bol
(match-beginning 0))
874 (setq alt-default t
))
876 (while (setq i
(string-match "[ \n\t]+" str i
))
877 (setq str
(concat (substring str
0 i
) " "
878 (substring str
(match-end 0))))
880 ;; Record as a completion and perhaps as default.
881 (if (eq default t
) (setq default str
))
882 (if (eq alt-default t
) (setq alt-default str
))
886 ;; If no good default was found, try an alternate.
888 (setq default alt-default
))
889 ;; If only one cross-reference found, then make it default.
890 (if (eq (length completions
) 1)
891 (setq default
(car (car completions
))))
893 (let ((input (completing-read (if default
894 (concat "Follow reference named: ("
896 "Follow reference named: ")
898 (list (if (equal input
"")
900 (error "No cross-references in this node"))))
901 (let (target beg i
(str (concat "\\*note " (regexp-quote footnotename
))))
902 (while (setq i
(string-match " " str i
))
903 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
906 (goto-char (point-min))
907 (or (re-search-forward str nil t
)
908 (error "No cross-reference named %s" footnotename
))
909 (goto-char (+ (match-beginning 0) 5))
911 (Info-extract-menu-node-name "Bad format cross reference" t
)))
912 (while (setq i
(string-match "[ \t\n]+" target i
))
913 (setq target
(concat (substring target
0 i
) " "
914 (substring target
(match-end 0))))
916 (Info-goto-node target
)))
918 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
919 (skip-chars-forward " \t\n")
922 (skip-chars-forward "^:")
926 (buffer-substring-no-properties beg
(1- (point)))
927 (skip-chars-forward " \t\n")
928 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
929 (while (setq i
(string-match "\n" str i
))
931 ;; Collapse multiple spaces.
932 (while (string-match " +" str
)
933 (setq str
(replace-match " " t t str
)))
936 ;; No one calls this.
937 ;;(defun Info-menu-item-sequence (list)
939 ;; (Info-menu (car list))
940 ;; (setq list (cdr list))))
942 (defun Info-complete-menu-item (string predicate action
)
943 (let ((case-fold-search t
))
944 (cond ((eq action nil
)
946 (pattern (concat "\n\\* \\("
947 (regexp-quote string
)
950 (set-buffer Info-complete-menu-buffer
)
951 (goto-char (point-min))
952 (search-forward "\n* Menu:")
953 (while (re-search-forward pattern nil t
)
954 (setq completions
(cons (cons (format "%s"
960 (try-completion string completions predicate
)))
963 (pattern (concat "\n\\* \\("
964 (regexp-quote string
)
967 (set-buffer Info-complete-menu-buffer
)
968 (goto-char (point-min))
969 (search-forward "\n* Menu:")
970 (while (re-search-forward pattern nil t
)
971 (setq completions
(cons (cons (format "%s"
977 (all-completions string completions predicate
)))
980 (set-buffer Info-complete-menu-buffer
)
981 (goto-char (point-min))
982 (search-forward "\n* Menu:")
983 (re-search-forward (concat "\n\\* "
984 (regexp-quote string
)
989 (defun Info-menu (menu-item)
990 "Go to node for menu item named (or abbreviated) NAME.
991 Completion is allowed, and the menu item point is on is the default."
993 (let ((completions '())
994 ;; If point is within a menu item, use that item as the default
1000 (goto-char (point-min))
1001 (if (not (search-forward "\n* menu:" nil t
))
1002 (error "No menu in this node"))
1008 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t
)
1009 (setq default
(format "%s" (buffer-substring
1014 (setq item
(let ((completion-ignore-case t
)
1015 (Info-complete-menu-buffer (current-buffer)))
1016 (completing-read (if default
1017 (format "Menu item (default %s): "
1020 'Info-complete-menu-item nil t
)))
1021 ;; we rely on the fact that completing-read accepts an input
1022 ;; of "" even when the require-match argument is true and ""
1023 ;; is not a valid possibility
1024 (if (string= item
"")
1030 ;; there is a problem here in that if several menu items have the same
1031 ;; name you can only go to the node of the first with this command.
1032 (Info-goto-node (Info-extract-menu-item menu-item
)))
1034 (defun Info-extract-menu-item (menu-item)
1035 (setq menu-item
(regexp-quote menu-item
))
1037 (goto-char (point-min))
1038 (or (search-forward "\n* menu:" nil t
)
1039 (error "No menu in this node"))
1040 (or (re-search-forward (concat "\n\\* " menu-item
":") nil t
)
1041 (re-search-forward (concat "\n\\* " menu-item
) nil t
)
1042 (error "No such item in menu"))
1045 (Info-extract-menu-node-name)))
1047 ;; If COUNT is nil, use the last item in the menu.
1048 (defun Info-extract-menu-counting (count)
1050 (goto-char (point-min))
1051 (or (search-forward "\n* menu:" nil t
)
1052 (error "No menu in this node"))
1054 (or (search-forward "\n* " nil t count
)
1055 (error "Too few items in menu"))
1056 (while (search-forward "\n* " nil t
)
1058 (Info-extract-menu-node-name)))
1060 (defun Info-nth-menu-item ()
1061 "Go to the node of the Nth menu item.
1062 N is the digit argument used to invoke this command."
1065 (Info-extract-menu-counting
1066 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
1068 (defun Info-top-node ()
1069 "Go to the Top node of this file."
1071 (Info-goto-node "Top"))
1073 (defun Info-final-node ()
1074 "Go to the final node in this file."
1076 (Info-goto-node "Top")
1078 ;; Go to the last node in the menu of Top.
1079 (Info-goto-node (Info-extract-menu-counting nil
))
1080 ;; If the last node in the menu is not last in pointer structure,
1081 ;; move forward until we can't go any farther.
1082 (while (Info-forward-node t t
) nil
)
1083 ;; Then keep moving down to last subnode, unless we reach an index.
1084 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1085 (save-excursion (search-forward "\n* Menu:" nil t
)))
1086 (Info-goto-node (Info-extract-menu-counting nil
)))))
1088 (defun Info-forward-node (&optional not-down no-error
)
1089 "Go forward one node, considering all nodes as forming one sequence."
1091 (goto-char (point-min))
1093 ;; three possibilities, in order of priority:
1094 ;; 1. next node is in a menu in this node (but not in an index)
1095 ;; 2. next node is next at same level
1096 ;; 3. next node is up and next
1097 (cond ((and (not not-down
)
1098 (save-excursion (search-forward "\n* menu:" nil t
))
1099 (not (string-match "\\<index\\>" Info-current-node
)))
1100 (Info-goto-node (Info-extract-menu-counting 1))
1102 ((save-excursion (search-backward "next:" nil t
))
1105 ((and (save-excursion (search-backward "up:" nil t
))
1106 ;; Use string-equal, not equal, to ignore text props.
1107 (not (string-equal (downcase (Info-extract-pointer "up"))
1109 (let ((old-node Info-current-node
))
1111 (let (Info-history success
)
1113 (setq success
(Info-forward-node t no-error
))
1114 (or success
(Info-goto-node old-node
))))))
1116 (t (error "No pointer forward from this node"))))
1118 (defun Info-backward-node ()
1119 "Go backward one node, considering all nodes as forming one sequence."
1121 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1122 (upnode (Info-extract-pointer "up" t
)))
1123 (cond ((and upnode
(string-match "(" upnode
))
1124 (error "First node in file"))
1125 ((and upnode
(or (null prevnode
)
1126 ;; Use string-equal, not equal,
1127 ;; to ignore text properties.
1128 (string-equal (downcase prevnode
)
1129 (downcase upnode
))))
1132 ;; If we move back at the same level,
1133 ;; go down to find the last subnode*.
1136 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1137 (save-excursion (search-forward "\n* Menu:" nil t
)))
1138 (Info-goto-node (Info-extract-menu-counting nil
)))))
1140 (error "No pointer backward from this node")))))
1143 "Exit Info by selecting some other buffer."
1146 (save-buffers-kill-emacs)
1147 (switch-to-buffer (prog1 (other-buffer (current-buffer))
1148 (bury-buffer (current-buffer))))))
1150 (defun Info-next-menu-item ()
1154 (search-forward "\n* menu:" nil t
)
1155 (or (search-forward "\n* " nil t
)
1156 (error "No more items in menu"))
1157 (Info-goto-node (Info-extract-menu-node-name))))
1159 (defun Info-last-menu-item ()
1163 (let ((beg (save-excursion
1164 (and (search-backward "\n* menu:" nil t
)
1166 (or (and beg
(search-backward "\n* " beg t
))
1167 (error "No previous items in menu")))
1168 (Info-goto-node (save-excursion
1169 (goto-char (match-end 0))
1170 (Info-extract-menu-node-name)))))
1172 (defmacro Info-no-error
(&rest body
)
1173 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1175 (defun Info-next-preorder ()
1176 "Go to the next subnode or the next node, or go up a level."
1178 (cond ((Info-no-error (Info-next-menu-item)))
1179 ((Info-no-error (Info-next)))
1180 ((Info-no-error (Info-up))
1181 ;; Since we have already gone thru all the items in this menu,
1182 ;; go up to the end of this node.
1183 (goto-char (point-max)))
1185 (error "No more nodes"))))
1187 (defun Info-last-preorder ()
1188 "Go to the last node, popping up a level if there is none."
1190 (cond ((Info-no-error
1191 (Info-last-menu-item)
1192 ;; If we go down a menu item, go to the end of the node
1193 ;; so we can scroll back through it.
1194 (goto-char (point-max)))
1196 ((Info-no-error (Info-prev))
1197 (goto-char (point-max))
1199 ((Info-no-error (Info-up))
1200 (goto-char (point-min))
1201 (or (search-forward "\n* Menu:" nil t
)
1202 (goto-char (point-max))))
1203 (t (error "No previous nodes"))))
1205 (defun Info-scroll-up ()
1206 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1207 Once you scroll far enough in a node that its menu appears on the screen,
1208 the next scroll moves into its first subnode. When you scroll past
1209 the end of a node, that goes to the next node or back up to the parent node."
1211 (if (or (< (window-start) (point-min))
1212 (> (window-start) (point-max)))
1213 (set-window-start (selected-window) (point)))
1214 (let ((virtual-end (save-excursion
1215 (goto-char (point-min))
1216 (if (search-forward "\n* Menu:" nil t
)
1219 (if (or (< virtual-end
(window-start))
1220 (pos-visible-in-window-p virtual-end
))
1221 (Info-next-preorder)
1224 (defun Info-scroll-down ()
1225 "Scroll one screenful back in Info, considering all nodes as one sequence.
1226 Within the menu of a node, this goes to its last subnode.
1227 When you scroll past the beginning of a node, that goes to the
1228 previous node or back up to the parent node."
1230 (if (or (< (window-start) (point-min))
1231 (> (window-start) (point-max)))
1232 (set-window-start (selected-window) (point)))
1233 (let ((virtual-end (save-excursion
1234 (goto-char (point-min))
1235 (search-forward "\n* Menu:" nil t
))))
1236 (if (or virtual-end
(pos-visible-in-window-p (point-min)))
1237 (Info-last-preorder)
1240 (defun Info-next-reference ()
1241 "Move cursor to the next cross-reference or menu item in the node."
1243 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1245 (or (eobp) (forward-char 1))
1246 (or (re-search-forward pat nil t
)
1248 (goto-char (point-min))
1249 (or (re-search-forward pat nil t
)
1252 (error "No cross references in this node")))))
1253 (goto-char (match-beginning 0))
1254 (if (looking-at "\\* Menu:")
1255 (Info-next-reference))))
1257 (defun Info-prev-reference ()
1258 "Move cursor to the previous cross-reference or menu item in the node."
1260 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1262 (or (re-search-backward pat nil t
)
1264 (goto-char (point-max))
1265 (or (re-search-backward pat nil t
)
1268 (error "No cross references in this node")))))
1269 (goto-char (match-beginning 0))
1270 (if (looking-at "\\* Menu:")
1271 (Info-prev-reference))))
1273 (defun Info-index (topic)
1274 "Look up a string in the index for this file.
1275 The index is defined as the first node in the top-level menu whose
1276 name contains the word \"Index\", plus any immediately following
1277 nodes whose names also contain the word \"Index\".
1278 If there are no exact matches to the specified topic, this chooses
1279 the first match which is a case-insensitive substring of a topic.
1280 Use the `,' command to see the other matches.
1281 Give a blank topic name to go to the Index node itself."
1282 (interactive "sIndex topic: ")
1283 (let ((orignode Info-current-node
)
1285 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1286 (regexp-quote topic
)))
1288 (Info-goto-node "Top")
1289 (or (search-forward "\n* menu:" nil t
)
1291 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
1293 (goto-char (match-beginning 1))
1294 ;; Here, and subsequently in this function,
1295 ;; we bind Info-history to nil for internal node-switches
1296 ;; so that we don't put junk in the history.
1297 ;; In the first Info-goto-node call, above, we do update the history
1298 ;; because that is what the user's previous node choice into it.
1299 (let ((Info-history nil
))
1300 (Info-goto-node (Info-extract-menu-node-name)))
1301 (or (equal topic
"")
1308 (goto-char (point-min))
1309 (while (re-search-forward pattern nil t
)
1311 (cons (list (buffer-substring (match-beginning 1)
1313 (buffer-substring (match-beginning 2)
1316 (string-to-int (concat "0"
1321 (and (setq node
(Info-extract-pointer "next" t
))
1322 (string-match "\\<Index\\>" node
)))
1323 (Info-goto-node node
))
1327 (error "No \"%s\" in index" topic
)))
1328 ;; Here it is a feature that assoc is case-sensitive.
1329 (while (setq found
(assoc topic matches
))
1330 (setq exact
(cons found exact
)
1331 matches
(delq found matches
)))
1332 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
1333 (Info-index-next 0)))))
1335 (defun Info-index-next (num)
1336 "Go to the next matching index item from the last `i' command."
1338 (or Info-index-alternatives
1339 (error "No previous `i' command in this file"))
1341 (setq num
(+ num
(length Info-index-alternatives
))))
1343 (setq Info-index-alternatives
1344 (nconc (cdr Info-index-alternatives
)
1345 (list (car Info-index-alternatives
)))
1347 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
1348 (if (> (nth 3 (car Info-index-alternatives
)) 0)
1349 (forward-line (nth 3 (car Info-index-alternatives
)))
1350 (forward-line 3) ; don't search in headers
1351 (let ((name (car (car Info-index-alternatives
))))
1352 (if (or (re-search-forward (format
1353 "\\(Function\\|Command\\): %s\\( \\|$\\)"
1354 (regexp-quote name
)) nil t
)
1355 (search-forward (format "`%s'" name
) nil t
)
1356 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
1358 (format "`%s'" (substring name
0 (match-beginning 1)))
1360 (search-forward name nil t
))
1362 (goto-char (point-min)))))
1363 (message "Found \"%s\" in %s. %s"
1364 (car (car Info-index-alternatives
))
1365 (nth 2 (car Info-index-alternatives
))
1366 (if (cdr Info-index-alternatives
)
1367 "(Press `,' for more)"
1370 (defun Info-undefined ()
1371 "Make command be undefined in Info."
1376 "Enter the Info tutorial."
1378 (delete-other-windows)
1379 (Info-find-node "info"
1380 (if (< (window-height) 23)
1384 (defun Info-summary ()
1385 "Display a brief summary of all Info commands."
1387 (save-window-excursion
1388 (switch-to-buffer "*Help*")
1390 (insert (documentation 'Info-mode
))
1392 (goto-char (point-min))
1394 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
1395 (message (if flag
"Type Space to see more"
1396 "Type Space to return to Info"))
1397 (if (not (eq ?\
(setq ch
(read-event))))
1398 (progn (setq unread-command-events
(list ch
)) nil
)
1401 (bury-buffer "*Help*")))
1403 (defun Info-get-token (pos start all
&optional errorstring
)
1404 "Return the token around POS,
1405 POS must be somewhere inside the token
1406 START is a regular expression which will match the
1407 beginning of the tokens delimited string
1408 ALL is a regular expression with a single
1409 parenthesized subpattern which is the token to be
1410 returned. E.g. '{\(.*\)}' would return any string
1411 enclosed in braces around POS.
1412 SIG optional fourth argument, controls action on no match
1415 a string: signal an error, using that string."
1418 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)
1420 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
1421 (not (setq found
(and (<= (match-beginning 0) pos
)
1422 (> (match-end 0) pos
))))))
1423 (if (and found
(<= (match-beginning 0) pos
)
1424 (> (match-end 0) pos
))
1425 (buffer-substring (match-beginning 1) (match-end 1))
1426 (cond ((null errorstring
)
1432 (error "No %s around position %d" errorstring pos
)))))))
1434 (defun Info-mouse-follow-nearest-node (click)
1435 "\\<Info-mode-map>Follow a node reference near point.
1436 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1437 At end of the node's text, moves to the next node, or up if none."
1439 (let* ((start (event-start click
))
1440 (window (car start
))
1441 (pos (car (cdr start
))))
1442 (select-window window
)
1444 (and (not (Info-try-follow-nearest-node))
1445 (save-excursion (forward-line 1) (eobp))
1446 (Info-next-preorder)))
1448 (defun Info-follow-nearest-node ()
1449 "\\<Info-mode-map>Follow a node reference near point.
1450 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1451 If no reference to follow, moves to the next node, or up if none."
1453 (or (Info-try-follow-nearest-node)
1454 (Info-next-preorder)))
1456 ;; Common subroutine.
1457 (defun Info-try-follow-nearest-node ()
1458 "Follow a node reference near point. Return non-nil if successful."
1461 ((setq node
(Info-get-token (point) "\\*note[ \n]"
1462 "\\*note[ \n]\\([^:]*\\):"))
1463 (Info-follow-reference node
))
1464 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1465 (Info-goto-node node
))
1466 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1468 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1469 (Info-goto-node node
))
1470 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1471 (Info-goto-node node
))
1472 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1473 (Info-goto-node "Top"))
1474 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1475 (Info-goto-node node
)))
1478 (defvar Info-mode-map nil
1479 "Keymap containing Info commands.")
1482 (setq Info-mode-map
(make-keymap))
1483 (suppress-keymap Info-mode-map
)
1484 (define-key Info-mode-map
"." 'beginning-of-buffer
)
1485 (define-key Info-mode-map
" " 'Info-scroll-up
)
1486 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
1487 (define-key Info-mode-map
"\t" 'Info-next-reference
)
1488 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
1489 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
1490 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
1491 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
1492 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
1493 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
1494 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
1495 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
1496 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
1497 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
1498 (define-key Info-mode-map
"0" 'undefined
)
1499 (define-key Info-mode-map
"?" 'Info-summary
)
1500 (define-key Info-mode-map
"]" 'Info-forward-node
)
1501 (define-key Info-mode-map
"[" 'Info-backward-node
)
1502 (define-key Info-mode-map
"<" 'Info-top-node
)
1503 (define-key Info-mode-map
">" 'Info-final-node
)
1504 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
1505 (define-key Info-mode-map
"d" 'Info-directory
)
1506 (define-key Info-mode-map
"e" 'Info-edit
)
1507 (define-key Info-mode-map
"f" 'Info-follow-reference
)
1508 (define-key Info-mode-map
"g" 'Info-goto-node
)
1509 (define-key Info-mode-map
"h" 'Info-help
)
1510 (define-key Info-mode-map
"i" 'Info-index
)
1511 (define-key Info-mode-map
"l" 'Info-last
)
1512 (define-key Info-mode-map
"m" 'Info-menu
)
1513 (define-key Info-mode-map
"n" 'Info-next
)
1514 (define-key Info-mode-map
"p" 'Info-prev
)
1515 (define-key Info-mode-map
"q" 'Info-exit
)
1516 (define-key Info-mode-map
"s" 'Info-search
)
1517 ;; For consistency with Rmail.
1518 (define-key Info-mode-map
"\M-s" 'Info-search
)
1519 (define-key Info-mode-map
"t" 'Info-top-node
)
1520 (define-key Info-mode-map
"u" 'Info-up
)
1521 (define-key Info-mode-map
"," 'Info-index-next
)
1522 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
1523 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
1526 ;; Info mode is suitable only for specially formatted data.
1527 (put 'info-mode
'mode-class
'special
)
1531 Info mode provides commands for browsing through the Info documentation tree.
1532 Documentation in Info is divided into \"nodes\", each of which discusses
1533 one topic and contains references to other nodes which discuss related
1534 topics. Info has commands to follow the references and show you other nodes.
1536 \\[Info-help] Invoke the Info tutorial.
1538 Selecting other nodes:
1539 \\[Info-mouse-follow-nearest-node]
1540 Follow a node reference you click on.
1541 This works with menu items, cross references, and
1542 the \"next\", \"previous\" and \"up\", depending on where you click.
1543 \\[Info-next] Move to the \"next\" node of this node.
1544 \\[Info-prev] Move to the \"previous\" node of this node.
1545 \\[Info-up] Move \"up\" from this node.
1546 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1547 Picking a menu item causes another node to be selected.
1548 \\[Info-directory] Go to the Info directory node.
1549 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1550 \\[Info-last] Move to the last node you were at.
1551 \\[Info-index] Look up a topic in this file's Index and move to that node.
1552 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1554 Moving within a node:
1555 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1556 already visible, try to go to the next menu entry, or up if there is none.
1557 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1558 already visible, try to go to the previous menu entry, or up if there is none.
1559 \\[beginning-of-buffer] Go to beginning of node.
1562 \\[Info-exit] Quit Info: reselect previously selected buffer.
1563 \\[Info-edit] Edit contents of selected node.
1564 1 Pick first item in node's menu.
1565 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1566 \\[Info-goto-node] Move to node specified by name.
1567 You may include a filename as well, as (FILENAME)NODENAME.
1568 \\[universal-argument] \\[info] Move to new Info file with completion.
1569 \\[Info-search] Search through this Info file for specified regexp,
1570 and select the node in which the next occurrence is found.
1571 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1572 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1573 (kill-all-local-variables)
1574 (setq major-mode
'Info-mode
)
1575 (setq mode-name
"Info")
1576 (use-local-map Info-mode-map
)
1577 (set-syntax-table text-mode-syntax-table
)
1578 (setq local-abbrev-table text-mode-abbrev-table
)
1579 (setq case-fold-search t
)
1580 (setq buffer-read-only t
)
1581 (make-local-variable 'Info-current-file
)
1582 (make-local-variable 'Info-current-subfile
)
1583 (make-local-variable 'Info-current-node
)
1584 (make-local-variable 'Info-tag-table-marker
)
1585 (make-local-variable 'Info-history
)
1586 (make-local-variable 'Info-index-alternatives
)
1587 (if (memq (framep (selected-frame)) '(x pc
))
1589 (make-face 'info-node
)
1590 (make-face 'info-menu-5
)
1591 (make-face 'info-xref
)
1592 (or (face-differs-from-default-p 'info-node
)
1593 (if (face-differs-from-default-p 'bold-italic
)
1594 (copy-face 'bold-italic
'info-node
)
1595 (copy-face 'bold
'info-node
)))
1596 (or (face-differs-from-default-p 'info-menu-5
)
1597 (set-face-underline-p 'info-menu-5 t
))
1598 (or (face-differs-from-default-p 'info-xref
)
1599 (copy-face 'bold
'info-xref
)))
1600 (setq Info-fontify nil
))
1601 (Info-set-mode-line)
1602 (run-hooks 'Info-mode-hook
))
1604 (defvar Info-edit-map nil
1605 "Local keymap used within `e' command of Info.")
1608 (setq Info-edit-map
(nconc (make-sparse-keymap) text-mode-map
))
1609 (define-key Info-edit-map
"\C-c\C-c" 'Info-cease-edit
))
1611 ;; Info-edit mode is suitable only for specially formatted data.
1612 (put 'info-edit-mode
'mode-class
'special
)
1614 (defun Info-edit-mode ()
1615 "Major mode for editing the contents of an Info node.
1616 Like text mode with the addition of `Info-cease-edit'
1617 which returns to Info mode for browsing.
1619 (use-local-map Info-edit-map
)
1620 (setq major-mode
'Info-edit-mode
)
1621 (setq mode-name
"Info Edit")
1622 (kill-local-variable 'mode-line-buffer-identification
)
1623 (setq buffer-read-only nil
)
1624 (force-mode-line-update)
1625 (buffer-enable-undo (current-buffer))
1626 (run-hooks 'Info-edit-mode-hook
))
1629 "Edit the contents of this Info node.
1630 Allowed only if variable `Info-enable-edit' is non-nil."
1632 (or Info-enable-edit
1633 (error "Editing info nodes is not enabled"))
1635 (message "%s" (substitute-command-keys
1636 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1638 (defun Info-cease-edit ()
1639 "Finish editing Info node; switch back to Info proper."
1641 ;; Do this first, so nothing has changed if user C-g's at query.
1642 (and (buffer-modified-p)
1643 (y-or-n-p "Save the file? ")
1645 (use-local-map Info-mode-map
)
1646 (setq major-mode
'Info-mode
)
1647 (setq mode-name
"Info")
1648 (Info-set-mode-line)
1649 (setq buffer-read-only t
)
1650 (force-mode-line-update)
1651 (and (marker-position Info-tag-table-marker
)
1653 (message "Tags may have changed. Use Info-tagify if necessary")))
1655 (defvar Info-file-list-for-emacs
1656 '("ediff" "forms" "gnus" "info" ("mh" .
"mh-e") "sc")
1657 "List of Info files that describe Emacs commands.
1658 An element can be a file name, or a list of the form (PREFIX . FILE)
1659 where PREFIX is a name prefix and FILE is the file to look in.
1660 If the element is just a file name, the file name also serves as the prefix.")
1662 (defun Info-find-emacs-command-nodes (command)
1663 "Return a list of locations documenting COMMAND.
1664 The `info-file' property of COMMAND says which Info manual to search.
1665 If COMMAND has no property, the variable `Info-file-list-for-emacs'
1666 defines heuristics for which Info manual to try.
1667 The locations are of the format used in Info-history, i.e.
1668 \(FILENAME NODENAME BUFFERPOS\)."
1670 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command
))
1671 ":\\s *\\(.*\\)\\.$"))
1672 (info-file "emacs")) ;default
1673 ;; Determine which info file this command is documented in.
1674 (if (get command
'info-file
)
1675 (setq info-file
(get command
'info-file
))
1676 ;; If it doesn't say explicitly, test its name against
1677 ;; various prefixes that we know.
1678 (let ((file-list Info-file-list-for-emacs
))
1680 (let* ((elt (car file-list
))
1681 (name (if (consp elt
)
1684 (file (if (consp elt
) (cdr elt
) elt
))
1685 (regexp (concat "\\`" (regexp-quote name
)
1687 (if (string-match regexp
(symbol-name command
))
1688 (setq info-file file file-list nil
))
1689 (setq file-list
(cdr file-list
))))))
1692 (Info-find-node info-file
"Command Index")
1693 ;; Some manuals may not have a separate Command Index node,
1694 ;; so try just Index instead.
1696 (Info-find-node info-file
"Index")))
1697 ;; Take the index node off the Info history.
1698 (setq Info-history
(cdr Info-history
))
1699 (goto-char (point-max))
1700 (while (re-search-backward cmd-desc nil t
)
1701 (setq where
(cons (list Info-current-file
1710 (defun Info-goto-emacs-command-node (command)
1711 "Go to the Info node in the Emacs manual for command COMMAND.
1712 The command is found by looking up in Emacs manual's Command Index
1713 or in another manual found via COMMAND's `info-file' property or
1714 the variable `Info-file-list-for-emacs'."
1715 (interactive "CFind documentation for command: ")
1716 (or (commandp command
)
1717 (signal 'wrong-type-argument
(list 'commandp command
)))
1718 (let ((where (Info-find-emacs-command-nodes command
)))
1720 (let ((num-matches (length where
)))
1721 ;; Get Info running, and pop to it in another window.
1722 (save-window-excursion
1724 (pop-to-buffer "*info*")
1725 (Info-find-node (car (car where
))
1726 (car (cdr (car where
))))
1727 (if (> num-matches
1)
1729 ;; Info-find-node already pushed (car where) onto
1730 ;; Info-history. Put the other nodes that were found on
1732 (setq Info-history
(nconc (cdr where
) Info-history
))
1733 (message "Found %d other entr%s. Use %s to see %s."
1735 (if (> num-matches
2) "ies" "y")
1736 (substitute-command-keys "\\[Info-last]")
1737 (if (> num-matches
2) "them" "it")))))
1738 (error "Couldn't find documentation for %s" command
))))
1741 (defun Info-goto-emacs-key-command-node (key)
1742 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1743 Interactively, if the binding is execute-extended-command, a command is read.
1744 The command is found by looking up in Emacs manual's Command Index
1745 or in another manual found via COMMAND's `info-file' property or
1746 the variable `Info-file-list-for-emacs'."
1747 (interactive "kFind documentation for key:")
1748 (let ((command (key-binding key
)))
1749 (cond ((null command
)
1750 (message "%s is undefined" (key-description key
)))
1751 ((and (interactive-p)
1752 (eq command
'execute-extended-command
))
1753 (Info-goto-emacs-command-node
1754 (read-command "Find documentation for command: ")))
1756 (Info-goto-emacs-command-node command
)))))
1758 (defvar Info-title-face-alist
1759 '((?
* bold underline
)
1760 (?
= bold-italic underline
)
1761 (?- italic underline
))
1762 "*Alist of face or list of faces to use for pseudo-underlined titles.
1763 The alist key is the character the title is underlined with (?*, ?= or ?-).")
1765 (defun Info-fontify-node ()
1767 (let ((buffer-read-only nil
))
1768 (goto-char (point-min))
1769 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1771 (goto-char (match-end 0))
1773 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1774 (goto-char (match-end 0))
1775 (put-text-property (match-beginning 1) (match-end 1)
1777 (put-text-property (match-beginning 1) (match-end 1)
1778 'mouse-face
'highlight
))))
1779 (goto-char (point-min))
1780 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
1782 (put-text-property (match-beginning 1) (match-end 1)
1784 (cdr (assq (preceding-char) Info-title-face-alist
)))
1785 (put-text-property (match-end 1) (match-end 2)
1787 (goto-char (point-min))
1788 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t
)
1789 (if (= (char-after (1- (match-beginning 0))) ?
\") ; hack
1791 (put-text-property (match-beginning 1) (match-end 1)
1793 (put-text-property (match-beginning 1) (match-end 1)
1794 'mouse-face
'highlight
)))
1795 (goto-char (point-min))
1796 (if (and (search-forward "\n* Menu:" nil t
)
1797 (not (string-match "\\<Index\\>" Info-current-node
))
1798 ;; Don't take time to annotate huge menus
1799 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
1801 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t
)
1803 (if (memq n
'(5 9)) ; visual aids to help with 1-9 keys
1804 (put-text-property (match-beginning 0)
1805 (1+ (match-beginning 0))
1806 'face
'info-menu-5
))
1807 (put-text-property (match-beginning 1) (match-end 1)
1809 (put-text-property (match-beginning 1) (match-end 1)
1810 'mouse-face
'highlight
))))
1811 (set-buffer-modified-p nil
))))
1815 ;;; info.el ends here