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 (unless suffix is empty).
163 (or (and (<= ext-len
0)
164 (not (eq (aref filename
(1- (length filename
))) ?.
)))
165 (= (length suffix
) 0)
166 (setq suffix
(substring suffix
1)))
167 ;; How many chars of that extension should we keep?
168 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
169 ;; Get rid of the rest of the extension, and add SUFFIX.
170 (concat (substring filename
0 (- (length filename
)
171 (- ext-len ext-left
)))
174 (defun info-insert-file-contents (filename &optional visit
)
175 "Insert the contents of an info file in the current buffer.
176 Do the right thing if the file has been compressed or zipped."
177 (let ((tail Info-suffix-list
)
179 (if (file-exists-p filename
)
180 ;; FILENAME exists--see if that name contains a suffix.
181 ;; If so, set DECODE accordingly.
185 (concat (regexp-quote (car (car tail
))) "$")
187 (setq tail
(cdr tail
)))
188 (setq fullname filename
189 decoder
(cdr (car tail
))))
190 ;; Try adding suffixes to FILENAME and see if we can find something.
192 (not (file-exists-p (info-insert-file-contents-1
193 filename
(car (car tail
))))))
194 (setq tail
(cdr tail
)))
195 ;; If we found a file with a suffix, set DECODER according to the suffix
196 ;; and set FULLNAME to the file's actual name.
197 (setq fullname
(info-insert-file-contents-1 filename
(car (car tail
)))
198 decoder
(cdr (car tail
)))
200 (error "Can't find %s or any compressed version of it" filename
)))
201 ;; check for conflict with jka-compr
202 (if (and (featurep 'jka-compr
)
203 (jka-compr-installed-p)
204 (jka-compr-get-compression-info fullname
))
206 (insert-file-contents fullname visit
)
208 (let ((buffer-read-only nil
)
209 (default-directory (or (file-name-directory fullname
)
211 (call-process-region (point-min) (point-max) decoder t t
)))))
213 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
216 (defun info (&optional file
)
217 "Enter Info, the documentation browser.
218 Optional argument FILE specifies the file to examine;
219 the default is the top-level directory of Info.
221 In interactive use, a prefix argument directs this command
222 to read a file name from the minibuffer.
224 The search path for Info files is in the variable `Info-directory-list'.
225 The top-level Info directory is made by combining all the files named `dir'
226 in all the directories in that path."
227 (interactive (if current-prefix-arg
228 (list (read-file-name "Info file name: " nil nil t
))))
230 (Info-goto-node (concat "(" file
")"))
231 (if (get-buffer "*info*")
232 (pop-to-buffer "*info*")
236 (defun info-standalone ()
237 "Run Emacs as a standalone Info reader.
238 Usage: emacs -f info-standalone [filename]
239 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
240 (setq Info-standalone t
)
241 (if (and command-line-args-left
242 (not (string-match "^-" (car command-line-args-left
))))
245 (info (car command-line-args-left
))
246 (setq command-line-args-left
(cdr command-line-args-left
)))
247 (error (send-string-to-terminal
248 (format "%s\n" (if (eq (car-safe err
) 'error
)
250 (save-buffers-kill-emacs)))
253 ;; Go to an info node specified as separate filename and nodename.
254 ;; no-going-back is non-nil if recovering from an error in this function;
255 ;; it says do not attempt further (recursive) error recovery.
256 (defun Info-find-node (filename nodename
&optional no-going-back
)
257 ;; Convert filename to lower case if not found as specified.
260 (let (temp temp-downcase found
)
261 (setq filename
(substitute-in-file-name filename
))
262 (if (string= (downcase (file-name-nondirectory filename
)) "dir")
264 (let ((dirs (if (string-match "^\\./" filename
)
265 ;; If specified name starts with `./'
266 ;; then just try current directory.
268 (if (file-name-absolute-p filename
)
269 ;; No point in searching for an
270 ;; absolute file name
272 (if Info-additional-directory-list
273 (append Info-directory-list
274 Info-additional-directory-list
)
275 Info-directory-list
)))))
276 ;; Search the directory list for file FILENAME.
277 (while (and dirs
(not found
))
278 (setq temp
(expand-file-name filename
(car dirs
)))
280 (expand-file-name (downcase filename
) (car dirs
)))
281 ;; Try several variants of specified name.
282 (let ((suffix-list Info-suffix-list
))
283 (while (and suffix-list
(not found
))
284 (cond ((file-exists-p
285 (info-insert-file-contents-1
286 temp
(car (car suffix-list
))))
289 (info-insert-file-contents-1
290 temp-downcase
(car (car suffix-list
))))
291 (setq found temp-downcase
)))
292 (setq suffix-list
(cdr suffix-list
))))
293 (setq dirs
(cdr dirs
)))))
295 (setq filename found
)
296 (error "Info file %s does not exist" filename
))))
297 ;; Record the node we are leaving.
298 (if (and Info-current-file
(not no-going-back
))
300 (cons (list Info-current-file Info-current-node
(point))
302 ;; Go into info buffer.
303 (switch-to-buffer "*info*")
304 (buffer-disable-undo (current-buffer))
305 (or (eq major-mode
'Info-mode
)
308 (setq Info-current-node nil
)
311 ;; Switch files if necessary
313 (equal Info-current-file filename
)
314 (let ((buffer-read-only nil
))
315 (setq Info-current-file nil
316 Info-current-subfile nil
317 Info-current-file-completions nil
318 Info-index-alternatives nil
319 buffer-file-name nil
)
323 (info-insert-file-contents filename t
)
324 (setq default-directory
(file-name-directory filename
)))
325 (set-buffer-modified-p nil
)
326 ;; See whether file has a tag table. Record the location if yes.
327 (set-marker Info-tag-table-marker nil
)
328 (goto-char (point-max))
330 ;; Use string-equal, not equal, to ignore text props.
331 (or (string-equal nodename
"*")
332 (not (search-forward "\^_\nEnd tag table\n" nil t
))
334 ;; We have a tag table. Find its beginning.
335 ;; Is this an indirect file?
336 (search-backward "\nTag table:\n")
340 (looking-at "(Indirect)\n"))
341 ;; It is indirect. Copy it to another buffer
342 ;; and record that the tag table is in that buffer.
344 (let ((buf (current-buffer)))
345 (set-buffer (get-buffer-create " *info tag table*"))
346 (buffer-disable-undo (current-buffer))
347 (setq case-fold-search t
)
349 (insert-buffer-substring buf
)
350 (set-marker Info-tag-table-marker
352 (set-marker Info-tag-table-marker pos
))))
353 (setq Info-current-file
354 (if (eq filename t
) "dir" filename
))))
355 ;; Use string-equal, not equal, to ignore text props.
356 (if (string-equal nodename
"*")
357 (progn (setq Info-current-node nodename
)
358 (Info-set-mode-line))
359 ;; Search file for a suitable node.
360 (let ((guesspos (point-min))
361 (regexp (concat "Node: *" (regexp-quote nodename
) " *[,\t\n\177]")))
362 ;; First get advice from tag table if file has one.
363 ;; Also, if this is an indirect info file,
364 ;; read the proper subfile into this buffer.
365 (if (marker-position Info-tag-table-marker
)
367 (set-buffer (marker-buffer Info-tag-table-marker
))
368 (goto-char Info-tag-table-marker
)
369 (if (re-search-forward regexp nil t
)
371 (setq guesspos
(read (current-buffer)))
372 ;; If this is an indirect file,
373 ;; determine which file really holds this node
375 (if (not (eq (current-buffer) (get-buffer "*info*")))
377 (Info-read-subfile guesspos
))))
378 (error "No such node: %s" nodename
))))
379 (goto-char (max (point-min) (- guesspos
1000)))
380 ;; Now search from our advised position (or from beg of buffer)
381 ;; to find the actual node.
383 (while (search-forward "\n\^_" nil t
)
387 (if (re-search-backward regexp beg t
)
389 (error "No such node: %s" nodename
)))
391 ;; If we did not finish finding the specified node,
392 ;; go back to the previous one.
393 (or Info-current-node no-going-back
(null Info-history
)
394 (let ((hist (car Info-history
)))
395 (setq Info-history
(cdr Info-history
))
396 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
397 (goto-char (nth 2 hist
)))))
398 (goto-char (point-min)))
400 ;; Cache the contents of the (virtual) dir file, once we have merged
401 ;; it for the first time, so we can save time subsequently.
402 (defvar Info-dir-contents nil
)
404 ;; Cache for the directory we decided to use for the default-directory
405 ;; of the merged dir text.
406 (defvar Info-dir-contents-directory nil
)
408 ;; Record the file attributes of all the files from which we
409 ;; constructed Info-dir-contents.
410 (defvar Info-dir-file-attributes nil
)
412 ;; Construct the Info directory node by merging the files named `dir'
413 ;; from various directories. Set the *info* buffer's
414 ;; default-directory to the first directory we actually get any text
416 (defun Info-insert-dir ()
417 (if (and Info-dir-contents Info-dir-file-attributes
418 ;; Verify that none of the files we used has changed
421 (mapcar '(lambda (elt)
422 (let ((curr (file-attributes (car elt
))))
423 ;; Don't compare the access time.
424 (if curr
(setcar (nthcdr 4 curr
) 0))
425 (setcar (nthcdr 4 (cdr elt
)) 0)
426 (equal (cdr elt
) curr
)))
427 Info-dir-file-attributes
))))
428 (insert Info-dir-contents
)
429 (let ((dirs Info-directory-list
)
430 buffers buffer others nodes dirs-done
)
432 (setq Info-dir-file-attributes nil
)
434 ;; Search the directory list for the directory file.
436 (let ((truename (file-truename (expand-file-name (car dirs
)))))
437 (or (member truename dirs-done
)
438 (member (directory-file-name truename
) dirs-done
)
439 ;; Try several variants of specified name.
440 ;; Try upcasing, appending `.info', or both.
444 (progn (setq file
(expand-file-name "dir" truename
))
445 (file-attributes file
))
446 (progn (setq file
(expand-file-name "DIR" truename
))
447 (file-attributes file
))
448 (progn (setq file
(expand-file-name "dir.info" truename
))
449 (file-attributes file
))
450 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
451 (file-attributes file
)))))
454 (cons (directory-file-name truename
)
459 (message "Composing main Info directory..."))
460 (set-buffer (generate-new-buffer "info dir"))
461 (insert-file-contents file
)
462 (setq buffers
(cons (current-buffer) buffers
)
463 Info-dir-file-attributes
464 (cons (cons file attrs
)
465 Info-dir-file-attributes
))))))
466 (setq dirs
(cdr dirs
))))
469 (error "Can't find the Info directory node"))
470 ;; Distinguish the dir file that comes with Emacs from all the
471 ;; others. Yes, that is really what this is supposed to do.
472 ;; If it doesn't work, fix it.
473 (setq buffer
(car buffers
)
474 others
(cdr buffers
))
476 ;; Insert the entire original dir file as a start; use its
477 ;; default directory as the default directory for the whole
479 (insert-buffer buffer
)
480 (setq Info-dir-contents-directory
(save-excursion
484 ;; Look at each of the other buffers one by one.
486 (let ((other (car others
)))
487 ;; In each, find all the menus.
490 (goto-char (point-min))
491 ;; Find each menu, and add an elt to NODES for it.
492 (while (re-search-forward "^\\* Menu:" nil t
)
493 (let (beg nodename end
)
496 (search-backward "\n\^_")
497 (search-forward "Node: ")
498 (setq nodename
(Info-following-node-name))
499 (search-forward "\n\^_" nil
'move
)
502 (setq nodes
(cons (list nodename other beg end
) nodes
))))))
503 (setq others
(cdr others
)))
504 ;; Add to the main menu a menu item for each other node.
505 (re-search-forward "^\\* Menu:")
507 (let ((menu-items '("top"))
510 (end (save-excursion (search-forward "\^_" nil t
) (point))))
512 (let ((nodename (car (car nodes
))))
514 (or (member (downcase nodename
) menu-items
)
515 (re-search-forward (concat "^\\* "
516 (regexp-quote nodename
)
520 (insert "* " nodename
"::" "\n")
521 (setq menu-items
(cons nodename menu-items
))))))
522 (setq nodes
(cdr nodes
))))
523 ;; Now take each node of each of the other buffers
524 ;; and merge it into the main buffer.
526 (let ((nodename (car (car nodes
))))
527 (goto-char (point-min))
528 ;; Find the like-named node in the main buffer.
529 (if (re-search-forward (concat "\n\^_.*\n.*Node: "
530 (regexp-quote nodename
)
534 (search-forward "\n\^_" nil
'move
)
537 ;; If none exists, add one.
538 (goto-char (point-max))
539 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
540 ;; Merge the text from the other buffer's menu
541 ;; into the menu in the like-named node in the main buffer.
542 (apply 'insert-buffer-substring
(cdr (car nodes
))))
543 (setq nodes
(cdr nodes
)))
544 ;; Kill all the buffers we just made.
546 (kill-buffer (car buffers
))
547 (setq buffers
(cdr buffers
)))
548 (message "Composing main Info directory...done"))
549 (setq Info-dir-contents
(buffer-string)))
550 (setq default-directory Info-dir-contents-directory
))
552 (defun Info-read-subfile (nodepos)
553 (set-buffer (marker-buffer Info-tag-table-marker
))
554 (goto-char (point-min))
555 (search-forward "\n\^_")
560 (while (not (looking-at "\^_"))
563 thisfilepos thisfilename
)
564 (search-forward ": ")
565 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
566 (setq thisfilepos
(read (current-buffer)))
567 ;; read in version 19 stops at the end of number.
568 ;; Advance to the next line.
570 (if (> thisfilepos nodepos
)
572 (setq lastfilename thisfilename
)
573 (setq lastfilepos thisfilepos
))
575 (set-buffer (get-buffer "*info*"))
576 (or (equal Info-current-subfile lastfilename
)
577 (let ((buffer-read-only nil
))
578 (setq buffer-file-name nil
)
581 (info-insert-file-contents lastfilename
)
582 (set-buffer-modified-p nil
)
583 (setq Info-current-subfile lastfilename
)))
584 (goto-char (point-min))
585 (search-forward "\n\^_")
586 (+ (- nodepos lastfilepos
) (point))))
588 ;; Select the info node that point is in.
589 (defun Info-select-node ()
591 ;; Find beginning of node.
592 (search-backward "\n\^_")
594 ;; Get nodename spelled as it is in the node.
595 (re-search-forward "Node:[ \t]*")
596 (setq Info-current-node
597 (buffer-substring-no-properties (point)
599 (skip-chars-forward "^,\t\n")
602 ;; Find the end of it, and narrow.
604 (let (active-expression)
605 (narrow-to-region (point)
606 (if (re-search-forward "\n[\^_\f]" nil t
)
609 (if (looking-at "[\n\^_\f]*execute: ")
611 (goto-char (match-end 0))
612 (setq active-expression
613 (read (current-buffer))))))
615 (if Info-enable-active-nodes
(eval active-expression
))
616 (if Info-fontify
(Info-fontify-node))
617 (run-hooks 'Info-selection-hook
))))
619 (defun Info-set-mode-line ()
620 (setq mode-line-buffer-identification
623 (if Info-current-file
624 (file-name-nondirectory Info-current-file
)
627 (or Info-current-node
""))))
629 ;; Go to an info node specified with a filename-and-nodename string
630 ;; of the sort that is found in pointers in nodes.
632 (defun Info-goto-node (nodename)
633 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME."
634 (interactive (list (Info-read-node-name "Goto node: ")))
636 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
638 (setq filename
(if (= (match-beginning 1) (match-end 1))
640 (substring nodename
(match-beginning 2) (match-end 2)))
641 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
642 (let ((trim (string-match "\\s *\\'" filename
)))
643 (if trim
(setq filename
(substring filename
0 trim
))))
644 (let ((trim (string-match "\\s *\\'" nodename
)))
645 (if trim
(setq nodename
(substring nodename
0 trim
))))
646 (if transient-mark-mode
(deactivate-mark))
647 (Info-find-node (if (equal filename
"") nil filename
)
648 (if (equal nodename
"") "Top" nodename
))))
650 ;; This function is used as the "completion table" while reading a node name.
651 ;; It does completion using the alist in completion-table
652 ;; unless STRING starts with an open-paren.
653 (defun Info-read-node-name-1 (string predicate code
)
654 (let ((no-completion (and (> (length string
) 0) (eq (aref string
0) ?\
())))
658 (try-completion string completion-table predicate
)))
662 (all-completions string completion-table predicate
)))
666 (assoc string completion-table
))))))
668 (defun Info-read-node-name (prompt &optional default
)
669 (let* ((completion-ignore-case t
)
670 (completion-table (Info-build-node-completions))
671 (nodename (completing-read prompt
'Info-read-node-name-1
)))
672 (if (equal nodename
"")
674 (Info-read-node-name prompt
))
677 (defun Info-build-node-completions ()
678 (or Info-current-file-completions
682 (if (marker-buffer Info-tag-table-marker
)
684 (set-buffer (marker-buffer Info-tag-table-marker
))
686 (goto-char Info-tag-table-marker
)
687 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t
)
689 (cons (list (buffer-substring (match-beginning 1)
693 (goto-char (point-min))
694 (while (search-forward "\n\^_" nil t
)
698 (if (re-search-backward "Node: *\\([^,\n]*\\) *[,\n\t]"
701 (cons (list (buffer-substring (match-beginning 1)
704 (setq Info-current-file-completions compl
))))
706 (defun Info-restore-point (hl)
707 "If this node has been visited, restore the point value when we left."
709 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
710 ;; Use string-equal, not equal, to ignore text props.
711 (string-equal (nth 1 (car hl
)) Info-current-node
))
713 (goto-char (nth 2 (car hl
)))
714 (setq hl nil
)) ;terminate the while at next iter
715 (setq hl
(cdr hl
)))))
717 (defvar Info-last-search nil
718 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
720 (defun Info-search (regexp)
721 "Search for REGEXP, starting from point, and select node it's found in."
722 (interactive "sSearch (regexp): ")
723 (if transient-mark-mode
(deactivate-mark))
724 (if (equal regexp
"")
725 (setq regexp Info-last-search
)
726 (setq Info-last-search regexp
))
727 (let ((found ()) current
728 (onode Info-current-node
)
729 (ofile Info-current-file
)
731 (osubfile Info-current-subfile
))
735 (if (null Info-current-subfile
)
736 (progn (re-search-forward regexp
) (setq found
(point)))
738 (progn (re-search-forward regexp
) (setq found
(point)))
739 (search-failed nil
)))))
740 (if (not found
) ;can only happen in subfile case -- else would have erred
743 (set-buffer (marker-buffer Info-tag-table-marker
))
744 (goto-char (point-min))
745 (search-forward "\n\^_\nIndirect:")
747 (narrow-to-region (point)
748 (progn (search-forward "\n\^_")
750 (goto-char (point-min))
751 (search-forward (concat "\n" osubfile
": "))
754 (re-search-forward "\\(^.*\\): [0-9]+$")
755 (goto-char (+ (match-end 1) 2))
756 (setq list
(cons (cons (read (current-buffer))
757 (buffer-substring (match-beginning 1)
760 (goto-char (1+ (match-end 0))))
761 (setq list
(nreverse list
)
762 current
(car (car list
))
765 (message "Searching subfile %s..." (cdr (car list
)))
766 (Info-read-subfile (car (car list
)))
767 (setq list
(cdr list
))
768 ;; (goto-char (point-min))
769 (if (re-search-forward regexp nil t
)
770 (setq found
(point) list
())))
773 (signal 'search-failed
(list regexp
))))
775 (progn (Info-read-subfile opoint
)
777 (Info-select-node)))))
781 ;; Use string-equal, not equal, to ignore text props.
782 (or (and (string-equal onode Info-current-node
)
783 (equal ofile Info-current-file
))
784 (setq Info-history
(cons (list ofile onode opoint
)
787 ;; Extract the value of the node-pointer named NAME.
788 ;; If there is none, use ERRORNAME in the error message;
789 ;; if ERRORNAME is nil, just return nil.
790 (defun Info-extract-pointer (name &optional errorname
)
792 (goto-char (point-min))
794 (if (re-search-backward (concat name
":") nil t
)
796 (goto-char (match-end 0))
797 (Info-following-node-name))
800 (error "Node has no %s" (capitalize (or errorname name
)))))))
802 ;; Return the node name in the buffer following point.
803 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
804 ;; saying which chas may appear in the node name.
805 (defun Info-following-node-name (&optional allowedchars
)
806 (skip-chars-forward " \t")
807 (buffer-substring-no-properties
810 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
811 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
813 (skip-chars-forward "^)")))
814 (skip-chars-backward " ")
818 "Go to the next node of this node."
820 (Info-goto-node (Info-extract-pointer "next")))
823 "Go to the previous node of this node."
825 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
828 "Go to the superior node of this node."
830 (Info-goto-node (Info-extract-pointer "up"))
831 (Info-restore-point Info-history
))
834 "Go back to the last node visited."
837 (error "This is the first Info node you looked at"))
838 (let (filename nodename opoint
)
839 (setq filename
(car (car Info-history
)))
840 (setq nodename
(car (cdr (car Info-history
))))
841 (setq opoint
(car (cdr (cdr (car Info-history
)))))
842 (setq Info-history
(cdr Info-history
))
843 (Info-find-node filename nodename
)
844 (setq Info-history
(cdr Info-history
))
847 (defun Info-directory ()
848 "Go to the Info directory node."
850 (Info-find-node "dir" "top"))
852 (defun Info-follow-reference (footnotename)
853 "Follow cross reference named NAME to the node it refers to.
854 NAME may be an abbreviation of the reference name."
856 (let ((completion-ignore-case t
)
857 completions default alt-default
(start-point (point)) str i bol eol
)
859 ;; Store end and beginning of line.
865 (goto-char (point-min))
866 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
867 (setq str
(buffer-substring
870 ;; See if this one should be the default.
872 (<= (match-beginning 0) start-point
)
873 (<= start-point
(point))
875 ;; See if this one should be the alternate default.
876 (and (null alt-default
)
877 (and (<= bol
(match-beginning 0))
879 (setq alt-default t
))
881 (while (setq i
(string-match "[ \n\t]+" str i
))
882 (setq str
(concat (substring str
0 i
) " "
883 (substring str
(match-end 0))))
885 ;; Record as a completion and perhaps as default.
886 (if (eq default t
) (setq default str
))
887 (if (eq alt-default t
) (setq alt-default str
))
891 ;; If no good default was found, try an alternate.
893 (setq default alt-default
))
894 ;; If only one cross-reference found, then make it default.
895 (if (eq (length completions
) 1)
896 (setq default
(car (car completions
))))
898 (let ((input (completing-read (if default
899 (concat "Follow reference named: ("
901 "Follow reference named: ")
903 (list (if (equal input
"")
905 (error "No cross-references in this node"))))
906 (let (target beg i
(str (concat "\\*note " (regexp-quote footnotename
))))
907 (while (setq i
(string-match " " str i
))
908 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
911 (goto-char (point-min))
912 (or (re-search-forward str nil t
)
913 (error "No cross-reference named %s" footnotename
))
914 (goto-char (+ (match-beginning 0) 5))
916 (Info-extract-menu-node-name "Bad format cross reference" t
)))
917 (while (setq i
(string-match "[ \t\n]+" target i
))
918 (setq target
(concat (substring target
0 i
) " "
919 (substring target
(match-end 0))))
921 (Info-goto-node target
)))
923 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
924 (skip-chars-forward " \t\n")
927 (skip-chars-forward "^:")
931 (buffer-substring-no-properties beg
(1- (point)))
932 (skip-chars-forward " \t\n")
933 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
934 (while (setq i
(string-match "\n" str i
))
936 ;; Collapse multiple spaces.
937 (while (string-match " +" str
)
938 (setq str
(replace-match " " t t str
)))
941 ;; No one calls this.
942 ;;(defun Info-menu-item-sequence (list)
944 ;; (Info-menu (car list))
945 ;; (setq list (cdr list))))
947 (defun Info-complete-menu-item (string predicate action
)
948 (let ((case-fold-search t
))
949 (cond ((eq action nil
)
951 (pattern (concat "\n\\* \\("
952 (regexp-quote string
)
955 (set-buffer Info-complete-menu-buffer
)
956 (goto-char (point-min))
957 (search-forward "\n* Menu:")
958 (while (re-search-forward pattern nil t
)
959 (setq completions
(cons (cons (format "%s"
965 (try-completion string completions predicate
)))
968 (pattern (concat "\n\\* \\("
969 (regexp-quote string
)
972 (set-buffer Info-complete-menu-buffer
)
973 (goto-char (point-min))
974 (search-forward "\n* Menu:")
975 (while (re-search-forward pattern nil t
)
976 (setq completions
(cons (cons (format "%s"
982 (all-completions string completions predicate
)))
985 (set-buffer Info-complete-menu-buffer
)
986 (goto-char (point-min))
987 (search-forward "\n* Menu:")
988 (re-search-forward (concat "\n\\* "
989 (regexp-quote string
)
994 (defun Info-menu (menu-item)
995 "Go to node for menu item named (or abbreviated) NAME.
996 Completion is allowed, and the menu item point is on is the default."
998 (let ((completions '())
999 ;; If point is within a menu item, use that item as the default
1005 (goto-char (point-min))
1006 (if (not (search-forward "\n* menu:" nil t
))
1007 (error "No menu in this node"))
1013 (re-search-backward "\n\\* \\([^:\t\n]*\\):" beg t
)
1014 (setq default
(format "%s" (buffer-substring
1019 (setq item
(let ((completion-ignore-case t
)
1020 (Info-complete-menu-buffer (current-buffer)))
1021 (completing-read (if default
1022 (format "Menu item (default %s): "
1025 'Info-complete-menu-item nil t
)))
1026 ;; we rely on the fact that completing-read accepts an input
1027 ;; of "" even when the require-match argument is true and ""
1028 ;; is not a valid possibility
1029 (if (string= item
"")
1035 ;; there is a problem here in that if several menu items have the same
1036 ;; name you can only go to the node of the first with this command.
1037 (Info-goto-node (Info-extract-menu-item menu-item
)))
1039 (defun Info-extract-menu-item (menu-item)
1040 (setq menu-item
(regexp-quote menu-item
))
1042 (goto-char (point-min))
1043 (or (search-forward "\n* menu:" nil t
)
1044 (error "No menu in this node"))
1045 (or (re-search-forward (concat "\n\\* " menu-item
":") nil t
)
1046 (re-search-forward (concat "\n\\* " menu-item
) nil t
)
1047 (error "No such item in menu"))
1050 (Info-extract-menu-node-name)))
1052 ;; If COUNT is nil, use the last item in the menu.
1053 (defun Info-extract-menu-counting (count)
1055 (goto-char (point-min))
1056 (or (search-forward "\n* menu:" nil t
)
1057 (error "No menu in this node"))
1059 (or (search-forward "\n* " nil t count
)
1060 (error "Too few items in menu"))
1061 (while (search-forward "\n* " nil t
)
1063 (Info-extract-menu-node-name)))
1065 (defun Info-nth-menu-item ()
1066 "Go to the node of the Nth menu item.
1067 N is the digit argument used to invoke this command."
1070 (Info-extract-menu-counting
1071 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
1073 (defun Info-top-node ()
1074 "Go to the Top node of this file."
1076 (Info-goto-node "Top"))
1078 (defun Info-final-node ()
1079 "Go to the final node in this file."
1081 (Info-goto-node "Top")
1083 ;; Go to the last node in the menu of Top.
1084 (Info-goto-node (Info-extract-menu-counting nil
))
1085 ;; If the last node in the menu is not last in pointer structure,
1086 ;; move forward until we can't go any farther.
1087 (while (Info-forward-node t t
) nil
)
1088 ;; Then keep moving down to last subnode, unless we reach an index.
1089 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1090 (save-excursion (search-forward "\n* Menu:" nil t
)))
1091 (Info-goto-node (Info-extract-menu-counting nil
)))))
1093 (defun Info-forward-node (&optional not-down no-error
)
1094 "Go forward one node, considering all nodes as forming one sequence."
1096 (goto-char (point-min))
1098 ;; three possibilities, in order of priority:
1099 ;; 1. next node is in a menu in this node (but not in an index)
1100 ;; 2. next node is next at same level
1101 ;; 3. next node is up and next
1102 (cond ((and (not not-down
)
1103 (save-excursion (search-forward "\n* menu:" nil t
))
1104 (not (string-match "\\<index\\>" Info-current-node
)))
1105 (Info-goto-node (Info-extract-menu-counting 1))
1107 ((save-excursion (search-backward "next:" nil t
))
1110 ((and (save-excursion (search-backward "up:" nil t
))
1111 ;; Use string-equal, not equal, to ignore text props.
1112 (not (string-equal (downcase (Info-extract-pointer "up"))
1114 (let ((old-node Info-current-node
))
1116 (let (Info-history success
)
1118 (setq success
(Info-forward-node t no-error
))
1119 (or success
(Info-goto-node old-node
))))))
1121 (t (error "No pointer forward from this node"))))
1123 (defun Info-backward-node ()
1124 "Go backward one node, considering all nodes as forming one sequence."
1126 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1127 (upnode (Info-extract-pointer "up" t
)))
1128 (cond ((and upnode
(string-match "(" upnode
))
1129 (error "First node in file"))
1130 ((and upnode
(or (null prevnode
)
1131 ;; Use string-equal, not equal,
1132 ;; to ignore text properties.
1133 (string-equal (downcase prevnode
)
1134 (downcase upnode
))))
1137 ;; If we move back at the same level,
1138 ;; go down to find the last subnode*.
1141 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1142 (save-excursion (search-forward "\n* Menu:" nil t
)))
1143 (Info-goto-node (Info-extract-menu-counting nil
)))))
1145 (error "No pointer backward from this node")))))
1148 "Exit Info by selecting some other buffer."
1151 (save-buffers-kill-emacs)
1152 (switch-to-buffer (prog1 (other-buffer (current-buffer))
1153 (bury-buffer (current-buffer))))))
1155 (defun Info-next-menu-item ()
1159 (search-forward "\n* menu:" nil t
)
1160 (or (search-forward "\n* " nil t
)
1161 (error "No more items in menu"))
1162 (Info-goto-node (Info-extract-menu-node-name))))
1164 (defun Info-last-menu-item ()
1168 (let ((beg (save-excursion
1169 (and (search-backward "\n* menu:" nil t
)
1171 (or (and beg
(search-backward "\n* " beg t
))
1172 (error "No previous items in menu")))
1173 (Info-goto-node (save-excursion
1174 (goto-char (match-end 0))
1175 (Info-extract-menu-node-name)))))
1177 (defmacro Info-no-error
(&rest body
)
1178 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1180 (defun Info-next-preorder ()
1181 "Go to the next subnode or the next node, or go up a level."
1183 (cond ((Info-no-error (Info-next-menu-item)))
1184 ((Info-no-error (Info-next)))
1185 ((Info-no-error (Info-up))
1186 ;; Since we have already gone thru all the items in this menu,
1187 ;; go up to the end of this node.
1188 (goto-char (point-max)))
1190 (error "No more nodes"))))
1192 (defun Info-last-preorder ()
1193 "Go to the last node, popping up a level if there is none."
1195 (cond ((Info-no-error
1196 (Info-last-menu-item)
1197 ;; If we go down a menu item, go to the end of the node
1198 ;; so we can scroll back through it.
1199 (goto-char (point-max)))
1201 ((Info-no-error (Info-prev))
1202 (goto-char (point-max))
1204 ((Info-no-error (Info-up))
1205 (goto-char (point-min))
1206 (or (search-forward "\n* Menu:" nil t
)
1207 (goto-char (point-max))))
1208 (t (error "No previous nodes"))))
1210 (defun Info-scroll-up ()
1211 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1212 Once you scroll far enough in a node that its menu appears on the screen,
1213 the next scroll moves into its first subnode. When you scroll past
1214 the end of a node, that goes to the next node or back up to the parent node."
1216 (if (or (< (window-start) (point-min))
1217 (> (window-start) (point-max)))
1218 (set-window-start (selected-window) (point)))
1219 (let ((virtual-end (save-excursion
1220 (goto-char (point-min))
1221 (if (search-forward "\n* Menu:" nil t
)
1224 (if (or (< virtual-end
(window-start))
1225 (pos-visible-in-window-p virtual-end
))
1226 (Info-next-preorder)
1229 (defun Info-scroll-down ()
1230 "Scroll one screenful back in Info, considering all nodes as one sequence.
1231 Within the menu of a node, this goes to its last subnode.
1232 When you scroll past the beginning of a node, that goes to the
1233 previous node or back up to the parent node."
1235 (if (or (< (window-start) (point-min))
1236 (> (window-start) (point-max)))
1237 (set-window-start (selected-window) (point)))
1238 (let ((virtual-end (save-excursion
1239 (goto-char (point-min))
1240 (search-forward "\n* Menu:" nil t
))))
1241 (if (or virtual-end
(pos-visible-in-window-p (point-min)))
1242 (Info-last-preorder)
1245 (defun Info-next-reference ()
1246 "Move cursor to the next cross-reference or menu item in the node."
1248 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1250 (or (eobp) (forward-char 1))
1251 (or (re-search-forward pat nil t
)
1253 (goto-char (point-min))
1254 (or (re-search-forward pat nil t
)
1257 (error "No cross references in this node")))))
1258 (goto-char (match-beginning 0))
1259 (if (looking-at "\\* Menu:")
1260 (Info-next-reference))))
1262 (defun Info-prev-reference ()
1263 "Move cursor to the previous cross-reference or menu item in the node."
1265 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1267 (or (re-search-backward pat nil t
)
1269 (goto-char (point-max))
1270 (or (re-search-backward pat nil t
)
1273 (error "No cross references in this node")))))
1274 (goto-char (match-beginning 0))
1275 (if (looking-at "\\* Menu:")
1276 (Info-prev-reference))))
1278 (defun Info-index (topic)
1279 "Look up a string in the index for this file.
1280 The index is defined as the first node in the top-level menu whose
1281 name contains the word \"Index\", plus any immediately following
1282 nodes whose names also contain the word \"Index\".
1283 If there are no exact matches to the specified topic, this chooses
1284 the first match which is a case-insensitive substring of a topic.
1285 Use the `,' command to see the other matches.
1286 Give a blank topic name to go to the Index node itself."
1287 (interactive "sIndex topic: ")
1288 (let ((orignode Info-current-node
)
1290 (pattern (format "\n\\* \\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1291 (regexp-quote topic
)))
1293 (Info-goto-node "Top")
1294 (or (search-forward "\n* menu:" nil t
)
1296 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
1298 (goto-char (match-beginning 1))
1299 ;; Here, and subsequently in this function,
1300 ;; we bind Info-history to nil for internal node-switches
1301 ;; so that we don't put junk in the history.
1302 ;; In the first Info-goto-node call, above, we do update the history
1303 ;; because that is what the user's previous node choice into it.
1304 (let ((Info-history nil
))
1305 (Info-goto-node (Info-extract-menu-node-name)))
1306 (or (equal topic
"")
1313 (goto-char (point-min))
1314 (while (re-search-forward pattern nil t
)
1316 (cons (list (buffer-substring (match-beginning 1)
1318 (buffer-substring (match-beginning 2)
1321 (string-to-int (concat "0"
1326 (and (setq node
(Info-extract-pointer "next" t
))
1327 (string-match "\\<Index\\>" node
)))
1328 (Info-goto-node node
))
1331 (Info-goto-node orignode
)
1332 (error "No `%s' in index" topic
)))
1333 ;; Here it is a feature that assoc is case-sensitive.
1334 (while (setq found
(assoc topic matches
))
1335 (setq exact
(cons found exact
)
1336 matches
(delq found matches
)))
1337 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
1338 (Info-index-next 0)))))
1340 (defun Info-index-next (num)
1341 "Go to the next matching index item from the last `i' command."
1343 (or Info-index-alternatives
1344 (error "No previous `i' command in this file"))
1346 (setq num
(+ num
(length Info-index-alternatives
))))
1348 (setq Info-index-alternatives
1349 (nconc (cdr Info-index-alternatives
)
1350 (list (car Info-index-alternatives
)))
1352 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
1353 (if (> (nth 3 (car Info-index-alternatives
)) 0)
1354 (forward-line (nth 3 (car Info-index-alternatives
)))
1355 (forward-line 3) ; don't search in headers
1356 (let ((name (car (car Info-index-alternatives
))))
1357 (Info-find-index-name name
)))
1358 (message "Found `%s' in %s. %s"
1359 (car (car Info-index-alternatives
))
1360 (nth 2 (car Info-index-alternatives
))
1361 (if (cdr Info-index-alternatives
)
1362 "(Press `,' for more)"
1365 (defun Info-find-index-name (name)
1366 "Move point to the place within the current node where NAME is defined."
1367 (if (or (re-search-forward (format
1368 "[a-zA-Z]+: %s\\( \\|$\\)"
1369 (regexp-quote name
)) nil t
)
1370 (search-forward (format "`%s'" name
) nil t
)
1371 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
1373 (format "`%s'" (substring name
0 (match-beginning 1)))
1375 (search-forward name nil t
))
1377 (goto-char (point-min))))
1379 (defun Info-undefined ()
1380 "Make command be undefined in Info."
1385 "Enter the Info tutorial."
1387 (delete-other-windows)
1388 (Info-find-node "info"
1389 (if (< (window-height) 23)
1393 (defun Info-summary ()
1394 "Display a brief summary of all Info commands."
1396 (save-window-excursion
1397 (switch-to-buffer "*Help*")
1399 (insert (documentation 'Info-mode
))
1401 (goto-char (point-min))
1403 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
1404 (message (if flag
"Type Space to see more"
1405 "Type Space to return to Info"))
1406 (if (not (eq ?\
(setq ch
(read-event))))
1407 (progn (setq unread-command-events
(list ch
)) nil
)
1410 (bury-buffer "*Help*")))
1412 (defun Info-get-token (pos start all
&optional errorstring
)
1413 "Return the token around POS,
1414 POS must be somewhere inside the token
1415 START is a regular expression which will match the
1416 beginning of the tokens delimited string
1417 ALL is a regular expression with a single
1418 parenthesized subpattern which is the token to be
1419 returned. E.g. '{\(.*\)}' would return any string
1420 enclosed in braces around POS.
1421 SIG optional fourth argument, controls action on no match
1424 a string: signal an error, using that string."
1427 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)
1429 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
1430 (not (setq found
(and (<= (match-beginning 0) pos
)
1431 (> (match-end 0) pos
))))))
1432 (if (and found
(<= (match-beginning 0) pos
)
1433 (> (match-end 0) pos
))
1434 (buffer-substring (match-beginning 1) (match-end 1))
1435 (cond ((null errorstring
)
1441 (error "No %s around position %d" errorstring pos
)))))))
1443 (defun Info-mouse-follow-nearest-node (click)
1444 "\\<Info-mode-map>Follow a node reference near point.
1445 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1446 At end of the node's text, moves to the next node, or up if none."
1448 (let* ((start (event-start click
))
1449 (window (car start
))
1450 (pos (car (cdr start
))))
1451 (select-window window
)
1453 (and (not (Info-try-follow-nearest-node))
1454 (save-excursion (forward-line 1) (eobp))
1455 (Info-next-preorder)))
1457 (defun Info-follow-nearest-node ()
1458 "\\<Info-mode-map>Follow a node reference near point.
1459 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1460 If no reference to follow, moves to the next node, or up if none."
1462 (or (Info-try-follow-nearest-node)
1463 (Info-next-preorder)))
1465 ;; Common subroutine.
1466 (defun Info-try-follow-nearest-node ()
1467 "Follow a node reference near point. Return non-nil if successful."
1470 ((setq node
(Info-get-token (point) "\\*note[ \n]"
1471 "\\*note[ \n]\\([^:]*\\):"))
1472 (Info-follow-reference node
))
1473 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\)::"))
1474 (Info-goto-node node
))
1475 ((setq node
(Info-get-token (point) "\\* " "\\* \\([^:]*\\):"))
1477 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1478 (Info-goto-node node
))
1479 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1480 (Info-goto-node node
))
1481 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1482 (Info-goto-node "Top"))
1483 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1484 (Info-goto-node node
)))
1487 (defvar Info-mode-map nil
1488 "Keymap containing Info commands.")
1491 (setq Info-mode-map
(make-keymap))
1492 (suppress-keymap Info-mode-map
)
1493 (define-key Info-mode-map
"." 'beginning-of-buffer
)
1494 (define-key Info-mode-map
" " 'Info-scroll-up
)
1495 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
1496 (define-key Info-mode-map
"\t" 'Info-next-reference
)
1497 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
1498 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
1499 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
1500 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
1501 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
1502 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
1503 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
1504 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
1505 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
1506 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
1507 (define-key Info-mode-map
"0" 'undefined
)
1508 (define-key Info-mode-map
"?" 'Info-summary
)
1509 (define-key Info-mode-map
"]" 'Info-forward-node
)
1510 (define-key Info-mode-map
"[" 'Info-backward-node
)
1511 (define-key Info-mode-map
"<" 'Info-top-node
)
1512 (define-key Info-mode-map
">" 'Info-final-node
)
1513 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
1514 (define-key Info-mode-map
"d" 'Info-directory
)
1515 (define-key Info-mode-map
"e" 'Info-edit
)
1516 (define-key Info-mode-map
"f" 'Info-follow-reference
)
1517 (define-key Info-mode-map
"g" 'Info-goto-node
)
1518 (define-key Info-mode-map
"h" 'Info-help
)
1519 (define-key Info-mode-map
"i" 'Info-index
)
1520 (define-key Info-mode-map
"l" 'Info-last
)
1521 (define-key Info-mode-map
"m" 'Info-menu
)
1522 (define-key Info-mode-map
"n" 'Info-next
)
1523 (define-key Info-mode-map
"p" 'Info-prev
)
1524 (define-key Info-mode-map
"q" 'Info-exit
)
1525 (define-key Info-mode-map
"s" 'Info-search
)
1526 ;; For consistency with Rmail.
1527 (define-key Info-mode-map
"\M-s" 'Info-search
)
1528 (define-key Info-mode-map
"t" 'Info-top-node
)
1529 (define-key Info-mode-map
"u" 'Info-up
)
1530 (define-key Info-mode-map
"," 'Info-index-next
)
1531 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
1532 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
1535 ;; Info mode is suitable only for specially formatted data.
1536 (put 'info-mode
'mode-class
'special
)
1540 Info mode provides commands for browsing through the Info documentation tree.
1541 Documentation in Info is divided into \"nodes\", each of which discusses
1542 one topic and contains references to other nodes which discuss related
1543 topics. Info has commands to follow the references and show you other nodes.
1545 \\[Info-help] Invoke the Info tutorial.
1547 Selecting other nodes:
1548 \\[Info-mouse-follow-nearest-node]
1549 Follow a node reference you click on.
1550 This works with menu items, cross references, and
1551 the \"next\", \"previous\" and \"up\", depending on where you click.
1552 \\[Info-next] Move to the \"next\" node of this node.
1553 \\[Info-prev] Move to the \"previous\" node of this node.
1554 \\[Info-up] Move \"up\" from this node.
1555 \\[Info-menu] Pick menu item specified by name (or abbreviation).
1556 Picking a menu item causes another node to be selected.
1557 \\[Info-directory] Go to the Info directory node.
1558 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
1559 \\[Info-last] Move to the last node you were at.
1560 \\[Info-index] Look up a topic in this file's Index and move to that node.
1561 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
1563 Moving within a node:
1564 \\[Info-scroll-up] Normally, scroll forward a full screen. If the end of the buffer is
1565 already visible, try to go to the next menu entry, or up if there is none.
1566 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
1567 already visible, try to go to the previous menu entry, or up if there is none.
1568 \\[beginning-of-buffer] Go to beginning of node.
1571 \\[Info-exit] Quit Info: reselect previously selected buffer.
1572 \\[Info-edit] Edit contents of selected node.
1573 1 Pick first item in node's menu.
1574 2, 3, 4, 5 Pick second ... fifth item in node's menu.
1575 \\[Info-goto-node] Move to node specified by name.
1576 You may include a filename as well, as (FILENAME)NODENAME.
1577 \\[universal-argument] \\[info] Move to new Info file with completion.
1578 \\[Info-search] Search through this Info file for specified regexp,
1579 and select the node in which the next occurrence is found.
1580 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
1581 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
1582 (kill-all-local-variables)
1583 (setq major-mode
'Info-mode
)
1584 (setq mode-name
"Info")
1585 (use-local-map Info-mode-map
)
1586 (set-syntax-table text-mode-syntax-table
)
1587 (setq local-abbrev-table text-mode-abbrev-table
)
1588 (setq case-fold-search t
)
1589 (setq buffer-read-only t
)
1590 (make-local-variable 'Info-current-file
)
1591 (make-local-variable 'Info-current-subfile
)
1592 (make-local-variable 'Info-current-node
)
1593 (make-local-variable 'Info-tag-table-marker
)
1594 (make-local-variable 'Info-history
)
1595 (make-local-variable 'Info-index-alternatives
)
1596 (if (memq (framep (selected-frame)) '(x pc
))
1598 (make-face 'info-node
)
1599 (make-face 'info-menu-5
)
1600 (make-face 'info-xref
)
1601 (or (face-differs-from-default-p 'info-node
)
1602 (if (face-differs-from-default-p 'bold-italic
)
1603 (copy-face 'bold-italic
'info-node
)
1604 (copy-face 'bold
'info-node
)))
1605 (or (face-differs-from-default-p 'info-menu-5
)
1606 (set-face-underline-p 'info-menu-5 t
))
1607 (or (face-differs-from-default-p 'info-xref
)
1608 (copy-face 'bold
'info-xref
)))
1609 (setq Info-fontify nil
))
1610 (Info-set-mode-line)
1611 (run-hooks 'Info-mode-hook
))
1613 (defvar Info-edit-map nil
1614 "Local keymap used within `e' command of Info.")
1617 (setq Info-edit-map
(nconc (make-sparse-keymap) text-mode-map
))
1618 (define-key Info-edit-map
"\C-c\C-c" 'Info-cease-edit
))
1620 ;; Info-edit mode is suitable only for specially formatted data.
1621 (put 'info-edit-mode
'mode-class
'special
)
1623 (defun Info-edit-mode ()
1624 "Major mode for editing the contents of an Info node.
1625 Like text mode with the addition of `Info-cease-edit'
1626 which returns to Info mode for browsing.
1628 (use-local-map Info-edit-map
)
1629 (setq major-mode
'Info-edit-mode
)
1630 (setq mode-name
"Info Edit")
1631 (kill-local-variable 'mode-line-buffer-identification
)
1632 (setq buffer-read-only nil
)
1633 (force-mode-line-update)
1634 (buffer-enable-undo (current-buffer))
1635 (run-hooks 'Info-edit-mode-hook
))
1638 "Edit the contents of this Info node.
1639 Allowed only if variable `Info-enable-edit' is non-nil."
1641 (or Info-enable-edit
1642 (error "Editing info nodes is not enabled"))
1644 (message "%s" (substitute-command-keys
1645 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
1647 (defun Info-cease-edit ()
1648 "Finish editing Info node; switch back to Info proper."
1650 ;; Do this first, so nothing has changed if user C-g's at query.
1651 (and (buffer-modified-p)
1652 (y-or-n-p "Save the file? ")
1654 (use-local-map Info-mode-map
)
1655 (setq major-mode
'Info-mode
)
1656 (setq mode-name
"Info")
1657 (Info-set-mode-line)
1658 (setq buffer-read-only t
)
1659 (force-mode-line-update)
1660 (and (marker-position Info-tag-table-marker
)
1662 (message "Tags may have changed. Use Info-tagify if necessary")))
1664 (defvar Info-file-list-for-emacs
1665 '("ediff" "forms" "gnus" "info" ("mh" .
"mh-e") "sc")
1666 "List of Info files that describe Emacs commands.
1667 An element can be a file name, or a list of the form (PREFIX . FILE)
1668 where PREFIX is a name prefix and FILE is the file to look in.
1669 If the element is just a file name, the file name also serves as the prefix.")
1671 (defun Info-find-emacs-command-nodes (command)
1672 "Return a list of locations documenting COMMAND.
1673 The `info-file' property of COMMAND says which Info manual to search.
1674 If COMMAND has no property, the variable `Info-file-list-for-emacs'
1675 defines heuristics for which Info manual to try.
1676 The locations are of the format used in Info-history, i.e.
1677 \(FILENAME NODENAME BUFFERPOS\)."
1679 (cmd-desc (concat "^\\* " (regexp-quote (symbol-name command
))
1680 ":\\s *\\(.*\\)\\.$"))
1681 (info-file "emacs")) ;default
1682 ;; Determine which info file this command is documented in.
1683 (if (get command
'info-file
)
1684 (setq info-file
(get command
'info-file
))
1685 ;; If it doesn't say explicitly, test its name against
1686 ;; various prefixes that we know.
1687 (let ((file-list Info-file-list-for-emacs
))
1689 (let* ((elt (car file-list
))
1690 (name (if (consp elt
)
1693 (file (if (consp elt
) (cdr elt
) elt
))
1694 (regexp (concat "\\`" (regexp-quote name
)
1696 (if (string-match regexp
(symbol-name command
))
1697 (setq info-file file file-list nil
))
1698 (setq file-list
(cdr file-list
))))))
1701 (Info-find-node info-file
"Command Index")
1702 ;; Some manuals may not have a separate Command Index node,
1703 ;; so try just Index instead.
1705 (Info-find-node info-file
"Index")))
1706 ;; Take the index node off the Info history.
1707 (setq Info-history
(cdr Info-history
))
1708 (goto-char (point-max))
1709 (while (re-search-backward cmd-desc nil t
)
1710 (setq where
(cons (list Info-current-file
1719 (defun Info-goto-emacs-command-node (command)
1720 "Go to the Info node in the Emacs manual for command COMMAND.
1721 The command is found by looking up in Emacs manual's Command Index
1722 or in another manual found via COMMAND's `info-file' property or
1723 the variable `Info-file-list-for-emacs'."
1724 (interactive "CFind documentation for command: ")
1725 (or (commandp command
)
1726 (signal 'wrong-type-argument
(list 'commandp command
)))
1727 (let ((where (Info-find-emacs-command-nodes command
)))
1729 (let ((num-matches (length where
)))
1730 ;; Get Info running, and pop to it in another window.
1731 (save-window-excursion
1733 (pop-to-buffer "*info*")
1734 (Info-find-node (car (car where
))
1735 (car (cdr (car where
))))
1736 (if (> num-matches
1)
1738 ;; Info-find-node already pushed (car where) onto
1739 ;; Info-history. Put the other nodes that were found on
1741 (setq Info-history
(nconc (cdr where
) Info-history
))
1742 (message "Found %d other entr%s. Use %s to see %s."
1744 (if (> num-matches
2) "ies" "y")
1745 (substitute-command-keys "\\[Info-last]")
1746 (if (> num-matches
2) "them" "it")))))
1747 (error "Couldn't find documentation for %s" command
))))
1750 (defun Info-goto-emacs-key-command-node (key)
1751 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
1752 Interactively, if the binding is execute-extended-command, a command is read.
1753 The command is found by looking up in Emacs manual's Command Index
1754 or in another manual found via COMMAND's `info-file' property or
1755 the variable `Info-file-list-for-emacs'."
1756 (interactive "kFind documentation for key:")
1757 (let ((command (key-binding key
)))
1758 (cond ((null command
)
1759 (message "%s is undefined" (key-description key
)))
1760 ((and (interactive-p)
1761 (eq command
'execute-extended-command
))
1762 (Info-goto-emacs-command-node
1763 (read-command "Find documentation for command: ")))
1765 (Info-goto-emacs-command-node command
)))))
1767 (defvar Info-title-face-alist
1768 '((?
* bold underline
)
1769 (?
= bold-italic underline
)
1770 (?- italic underline
))
1771 "*Alist of face or list of faces to use for pseudo-underlined titles.
1772 The alist key is the character the title is underlined with (?*, ?= or ?-).")
1774 (defun Info-fontify-node ()
1776 (let ((buffer-read-only nil
))
1777 (goto-char (point-min))
1778 (if (looking-at "^File: [^,: \t]+,?[ \t]+")
1780 (goto-char (match-end 0))
1782 (looking-at "[ \t]*[^:, \t\n]+:[ \t]+\\([^:,\t\n]+\\),?")
1783 (goto-char (match-end 0))
1784 (put-text-property (match-beginning 1) (match-end 1)
1786 (put-text-property (match-beginning 1) (match-end 1)
1787 'mouse-face
'highlight
))))
1788 (goto-char (point-min))
1789 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
1791 (put-text-property (match-beginning 1) (match-end 1)
1793 (cdr (assq (preceding-char) Info-title-face-alist
)))
1794 (put-text-property (match-end 1) (match-end 2)
1796 (goto-char (point-min))
1797 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t
)
1798 (if (= (char-after (1- (match-beginning 0))) ?
\") ; hack
1800 (put-text-property (match-beginning 1) (match-end 1)
1802 (put-text-property (match-beginning 1) (match-end 1)
1803 'mouse-face
'highlight
)))
1804 (goto-char (point-min))
1805 (if (and (search-forward "\n* Menu:" nil t
)
1806 (not (string-match "\\<Index\\>" Info-current-node
))
1807 ;; Don't take time to annotate huge menus
1808 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
1810 (while (re-search-forward "^\\* \\([^:\t\n]*\\):" nil t
)
1812 (if (memq n
'(5 9)) ; visual aids to help with 1-9 keys
1813 (put-text-property (match-beginning 0)
1814 (1+ (match-beginning 0))
1815 'face
'info-menu-5
))
1816 (put-text-property (match-beginning 1) (match-end 1)
1818 (put-text-property (match-beginning 1) (match-end 1)
1819 'mouse-face
'highlight
))))
1820 (set-buffer-modified-p nil
))))
1824 ;;; info.el ends here