1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99, 2000 Free Software
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; Note that nowadays we expect info files to be made using makeinfo.
32 (eval-when-compile (require 'jka-compr
))
40 (defvar Info-history nil
41 "List of info nodes user has visited.
42 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
44 (defcustom Info-enable-edit nil
45 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
46 This is convenient if you want to write info files by hand.
47 However, we recommend that you not do this.
48 It is better to write a Texinfo file and generate the Info file from that,
49 because that gives you a printed manual as well."
53 (defvar Info-enable-active-nodes nil
54 "Non-nil allows Info to execute Lisp code associated with nodes.
55 The Lisp code is executed when the node is selected.")
56 (put 'Info-enable-active-nodes
'risky-local-variable t
)
58 (defcustom Info-fontify t
59 "*Non-nil enables highlighting and fonts in Info nodes."
64 '((((class color
)) (:foreground
"brown" :bold t
:italic t
))
65 (t (:bold t
:italic t
)))
66 "Face for Info node names."
70 '((((class color
)) (:foreground
"red1"))
72 "Face for the fifth and tenth `*' in an Info menu."
76 '((((class color
)) (:foreground
"magenta4" :bold t
))
78 "Face for Info cross-references."
81 (defcustom Info-fontify-maximum-menu-size
100000
82 "*Maximum size of menu to fontify if `Info-fontify' is non-nil."
86 (defvar Info-directory-list nil
87 "List of directories to search for Info documentation files.
88 nil means not yet initialized. In this case, Info uses the environment
89 variable INFOPATH to initialize it, or `Info-default-directory-list'
90 if there is no INFOPATH variable in the environment.
91 The last element of `Info-default-directory-list' is the directory
92 where Emacs installs the Info files that come with it.
94 If you run the Emacs executable from the `src' directory in the Emacs
95 source tree, the `info' directory in the source tree is used as the last
96 element, in place of the installation Info directory. This is useful
97 when you run a version of Emacs without installing it.")
99 (defcustom Info-additional-directory-list nil
100 "List of additional directories to search for Info documentation files.
101 These directories are not searched for merging the `dir' file."
102 :type
'(repeat directory
)
105 (defvar Info-current-file nil
106 "Info file that Info is now looking at, or nil.
107 This is the name that was specified in Info, not the actual file name.
108 It doesn't contain directory names or file name extensions added by Info.
109 Can also be t when using `Info-on-current-buffer'.")
111 (defvar Info-current-subfile nil
112 "Info subfile that is actually in the *info* buffer now,
113 or nil if current info file is not split into subfiles.")
115 (defvar Info-current-node nil
116 "Name of node that Info is now looking at, or nil.")
118 (defvar Info-tag-table-marker nil
119 "Marker pointing at beginning of current Info file's tag table.
120 Marker points nowhere if file has no tag table.")
122 (defvar Info-tag-table-buffer nil
123 "Buffer used for indirect tag tables.")
125 (defvar Info-current-file-completions nil
126 "Cached completion list for current Info file.")
128 (defvar Info-index-alternatives nil
129 "List of possible matches for last Info-index command.")
131 (defvar Info-standalone nil
132 "Non-nil if Emacs was started solely as an Info browser.")
134 (defvar Info-suffix-list
135 ;; The MS-DOS list should work both when long file names are
136 ;; supported (Windows 9X), and when only 8+3 file names are available.
137 (if (eq system-type
'ms-dos
)
138 '( (".gz" .
"gunzip")
140 (".bz2" .
"bzip2 -dc")
143 (".info.Z" .
"gunzip")
144 (".info.gz" .
"gunzip")
145 ("-info.Z" .
"gunzip")
146 ("-info.gz" .
"gunzip")
147 ("/index.gz".
"gunzip")
148 ("/index.z" .
"gunzip")
154 '( (".info.Z".
"uncompress")
155 (".info.Y".
"unyabba")
156 (".info.gz".
"gunzip")
157 (".info.z".
"gunzip")
158 (".info.bz2" .
"bzip2 -dc")
160 ("-info.Z".
"uncompress")
161 ("-info.Y".
"unyabba")
162 ("-info.gz".
"gunzip")
163 ("-info.bz2" .
"bzip2 -dc")
164 ("-info.z".
"gunzip")
166 ("/index.Z".
"uncompress")
167 ("/index.Y".
"unyabba")
168 ("/index.gz".
"gunzip")
169 ("/index.z".
"gunzip")
170 ("/index.bz2".
"bzip2 -dc")
176 (".bz2" .
"bzip2 -dc")
178 "List of file name suffixes and associated decoding commands.
179 Each entry should be (SUFFIX . STRING); the file is given to
180 the command as standard input. If STRING is nil, no decoding is done.
181 Because the SUFFIXes are tried in order, the empty string should
182 be last in the list.")
184 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
185 ;; First, on ms-dos, delete some of the extension in FILENAME
187 (defun info-insert-file-contents-1 (filename suffix
)
188 (if (not (eq system-type
'ms-dos
))
189 (concat filename suffix
)
190 (let* ((sans-exts (file-name-sans-extension filename
))
191 ;; How long is the extension in FILENAME (not counting the dot).
192 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
194 ;; SUFFIX starts with a dot. If FILENAME already has one,
195 ;; get rid of the one in SUFFIX (unless suffix is empty).
196 (or (and (<= ext-len
0)
197 (not (eq (aref filename
(1- (length filename
))) ?.
)))
198 (= (length suffix
) 0)
199 (setq suffix
(substring suffix
1)))
200 ;; How many chars of that extension should we keep?
201 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
202 ;; Get rid of the rest of the extension, and add SUFFIX.
203 (concat (substring filename
0 (- (length filename
)
204 (- ext-len ext-left
)))
207 (defun info-file-exists-p (filename)
208 (and (file-exists-p filename
)
209 (not (file-directory-p filename
))))
211 (defun info-insert-file-contents (filename &optional visit
)
212 "Insert the contents of an info file in the current buffer.
213 Do the right thing if the file has been compressed or zipped."
214 (let ((tail Info-suffix-list
)
216 (if (file-exists-p filename
)
217 ;; FILENAME exists--see if that name contains a suffix.
218 ;; If so, set DECODE accordingly.
222 (concat (regexp-quote (car (car tail
))) "$")
224 (setq tail
(cdr tail
)))
225 (setq fullname filename
226 decoder
(cdr (car tail
))))
227 ;; Try adding suffixes to FILENAME and see if we can find something.
229 (not (info-file-exists-p (info-insert-file-contents-1
230 filename
(car (car tail
))))))
231 (setq tail
(cdr tail
)))
232 ;; If we found a file with a suffix, set DECODER according to the suffix
233 ;; and set FULLNAME to the file's actual name.
234 (setq fullname
(info-insert-file-contents-1 filename
(car (car tail
)))
235 decoder
(cdr (car tail
)))
237 (error "Can't find %s or any compressed version of it" filename
)))
238 ;; check for conflict with jka-compr
239 (if (and (featurep 'jka-compr
)
240 (jka-compr-installed-p)
241 (jka-compr-get-compression-info fullname
))
245 (insert-file-contents-literally fullname visit
)
246 (let ((buffer-read-only nil
)
247 (coding-system-for-write 'no-conversion
)
248 (default-directory (or (file-name-directory fullname
)
250 (call-process-region (point-min) (point-max) decoder t t
)))
251 (insert-file-contents fullname visit
))))
253 ;; Initialize Info-directory-list, if that hasn't been done yet.
254 (defun info-initialize ()
255 (unless Info-directory-list
256 (let ((path (getenv "INFOPATH"))
257 (source (expand-file-name "info/" source-directory
))
258 (sibling (if installation-directory
259 (expand-file-name "info/" installation-directory
)))
261 (setq Info-directory-list
263 (split-string path
(regexp-quote path-separator
))
264 (if (and sibling
(file-exists-p sibling
))
265 ;; Uninstalled, Emacs builddir != srcdir.
266 (setq alternative sibling
)
267 ;; Uninstalled, builddir == srcdir
268 (setq alternative source
))
269 (if (or (member alternative Info-default-directory-list
)
270 ;; On DOS/NT, we use movable executables always,
271 ;; and we must always find the Info dir at run time.
272 (if (memq system-type
'(ms-dos windows-nt
))
274 ;; Use invocation-directory for Info
275 ;; only if we used it for exec-directory also.
276 (not (string= exec-directory
277 (expand-file-name "lib-src/"
278 installation-directory
))))
279 (not (file-exists-p alternative
)))
280 Info-default-directory-list
281 ;; `alternative' contains the Info files that came with this
282 ;; version, so we should look there first. `Info-insert-dir'
283 ;; currently expects to find `alternative' first on the list.
285 (reverse (cdr (reverse Info-default-directory-list
))))))))))
288 (defun info-other-window (&optional file
)
289 "Like `info' but show the Info buffer in another window."
290 (interactive (if current-prefix-arg
291 (list (read-file-name "Info file name: " nil nil t
))))
292 (let (same-window-buffer-names)
295 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
298 (defun info (&optional file
)
299 "Enter Info, the documentation browser.
300 Optional argument FILE specifies the file to examine;
301 the default is the top-level directory of Info.
302 Called from a program, FILE may specify an Info node of the form
303 `(FILENAME)NODENAME'.
305 In interactive use, a prefix argument directs this command
306 to read a file name from the minibuffer.
308 The search path for Info files is in the variable `Info-directory-list'.
309 The top-level Info directory is made by combining all the files named `dir'
310 in all the directories in that path."
311 (interactive (if current-prefix-arg
312 (list (read-file-name "Info file name: " nil nil t
))))
315 (pop-to-buffer "*info*")
316 ;; If argument already contains parentheses, don't add another set
317 ;; since the argument will then be parsed improperly. This also
318 ;; has the added benefit of allowing node names to be included
319 ;; following the parenthesized filename.
320 (if (and (stringp file
) (string-match "(.*)" file
))
321 (Info-goto-node file
)
322 (Info-goto-node (concat "(" file
")"))))
323 (if (get-buffer "*info*")
324 (pop-to-buffer "*info*")
328 (defun info-standalone ()
329 "Run Emacs as a standalone Info reader.
330 Usage: emacs -f info-standalone [filename]
331 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
332 (setq Info-standalone t
)
333 (if (and command-line-args-left
334 (not (string-match "^-" (car command-line-args-left
))))
337 (info (car command-line-args-left
))
338 (setq command-line-args-left
(cdr command-line-args-left
)))
339 (error (send-string-to-terminal
340 (format "%s\n" (if (eq (car-safe err
) 'error
)
342 (save-buffers-kill-emacs)))
345 ;; See if the the accessible portion of the buffer begins with a node
346 ;; delimiter, and the node header line which follows matches REGEXP.
347 ;; Typically, this test will be followed by a loop that examines the
348 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
349 ;; to have the overhead of this special test inside the loop.
351 ;; This function changes match-data, but supposedly the caller might
352 ;; want to use the results of re-search-backward.
354 ;; The return value is the value of point at the beginning of matching
355 ;; REGERXP, if the function succeeds, nil otherwise.
356 (defun Info-node-at-bob-matching (regexp)
357 (and (bobp) ; are we at beginning of buffer?
358 (looking-at "\^_") ; does it begin with node delimiter?
362 (forward-line 1) ; does the line after delimiter match REGEXP?
363 (re-search-backward regexp beg t
))))
365 ;; Go to an info node specified as separate filename and nodename.
366 ;; no-going-back is non-nil if recovering from an error in this function;
367 ;; it says do not attempt further (recursive) error recovery.
368 (defun Info-find-node (filename nodename
&optional no-going-back
)
370 ;; Convert filename to lower case if not found as specified.
372 (if (stringp filename
)
373 (let (temp temp-downcase found
)
374 (setq filename
(substitute-in-file-name filename
))
375 (if (string= (downcase filename
) "dir")
377 (let ((dirs (if (string-match "^\\./" filename
)
378 ;; If specified name starts with `./'
379 ;; then just try current directory.
381 (if (file-name-absolute-p filename
)
382 ;; No point in searching for an
383 ;; absolute file name
385 (if Info-additional-directory-list
386 (append Info-directory-list
387 Info-additional-directory-list
)
388 Info-directory-list
)))))
389 ;; Search the directory list for file FILENAME.
390 (while (and dirs
(not found
))
391 (setq temp
(expand-file-name filename
(car dirs
)))
393 (expand-file-name (downcase filename
) (car dirs
)))
394 ;; Try several variants of specified name.
395 (let ((suffix-list Info-suffix-list
))
396 (while (and suffix-list
(not found
))
397 (cond ((info-file-exists-p
398 (info-insert-file-contents-1
399 temp
(car (car suffix-list
))))
402 (info-insert-file-contents-1
403 temp-downcase
(car (car suffix-list
))))
404 (setq found temp-downcase
)))
405 (setq suffix-list
(cdr suffix-list
))))
406 (setq dirs
(cdr dirs
)))))
408 (setq filename found
)
409 (error "Info file %s does not exist" filename
))))
410 ;; Record the node we are leaving.
411 (if (and Info-current-file
(not no-going-back
))
413 (cons (list Info-current-file Info-current-node
(point))
415 ;; Go into info buffer.
416 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
417 (Info-find-node-2 filename nodename no-going-back
))
419 (defun Info-on-current-buffer (&optional nodename
)
420 "Use the `Info-mode' to browse the current info buffer.
421 If a prefix arg is provided, it queries for the NODENAME which
422 else defaults to `Top'."
424 (list (if current-prefix-arg
425 (completing-read "Node name: " (Info-build-node-completions)
429 (set (make-local-variable 'Info-current-file
) t
)
430 (Info-find-node-2 nil nodename
))
432 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
433 (buffer-disable-undo (current-buffer))
434 (or (eq major-mode
'Info-mode
)
437 (setq Info-current-node nil
)
439 ;; Bind case-fold-search in case the user sets it to nil.
440 (let ((case-fold-search t
)
442 ;; Switch files if necessary
444 (equal Info-current-file filename
)
445 (let ((buffer-read-only nil
))
446 (setq Info-current-file nil
447 Info-current-subfile nil
448 Info-current-file-completions nil
449 buffer-file-name nil
)
453 (info-insert-file-contents filename t
)
454 (setq default-directory
(file-name-directory filename
)))
455 (set-buffer-modified-p nil
)
456 ;; See whether file has a tag table. Record the location if yes.
457 (goto-char (point-max))
459 ;; Use string-equal, not equal, to ignore text props.
460 (if (not (or (string-equal nodename
"*")
462 (search-forward "\^_\nEnd tag table\n" nil t
))))
464 ;; We have a tag table. Find its beginning.
465 ;; Is this an indirect file?
466 (search-backward "\nTag table:\n")
470 (looking-at "(Indirect)\n"))
471 ;; It is indirect. Copy it to another buffer
472 ;; and record that the tag table is in that buffer.
473 (let ((buf (current-buffer))
475 (or Info-tag-table-buffer
476 (generate-new-buffer " *info tag table*"))))
477 (setq Info-tag-table-buffer tagbuf
)
480 (buffer-disable-undo (current-buffer))
481 (setq case-fold-search t
)
483 (insert-buffer-substring buf
))
484 (set-marker Info-tag-table-marker
485 (match-end 0) tagbuf
))
486 (set-marker Info-tag-table-marker pos
)))
487 (set-marker Info-tag-table-marker nil
))
488 (setq Info-current-file
489 (if (eq filename t
) "dir" filename
))))
490 ;; Use string-equal, not equal, to ignore text props.
491 (if (string-equal nodename
"*")
492 (progn (setq Info-current-node nodename
)
493 (Info-set-mode-line))
496 ;; 1. Anchor found in tag table
497 ;; 2. Anchor *not* in tag table
499 ;; 3. Node found in tag table
500 ;; 4. Node *not* found in tag table, but found in file
501 ;; 5. Node *not* in tag table, and *not* in file
503 ;; *Or* the same, but in an indirect subfile.
505 ;; Search file for a suitable node.
506 (let ((guesspos (point-min))
508 (concat "\\(Node:\\|Ref:\\) *\\("
509 (regexp-quote nodename
)
513 ;; First, search a tag table, if any
514 (if (marker-position Info-tag-table-marker
)
515 (let ((found-in-tag-table t
)
518 (m Info-tag-table-marker
))
520 (set-buffer (marker-buffer m
))
522 (beginning-of-line) ; so re-search will work.
526 (while (re-search-forward regexp nil t
)
528 (string-equal "Ref:" (match-string 1)))
529 (or nodepos
(setq nodepos
(point))
530 (if (string-equal (match-string 2) nodename
)
534 (setq found-in-tag-table nil
)))
535 (if found-in-tag-table
536 (setq guesspos
(1+ (read (current-buffer)))))
537 (setq found-mode major-mode
))
539 ;; Indirect file among split files
540 (if found-in-tag-table
542 ;; If this is an indirect file, determine
543 ;; which file really holds this node and
545 (if (not (eq found-mode
'Info-mode
))
546 ;; Note that the current buffer must be
547 ;; the *info* buffer on entry to
548 ;; Info-read-subfile. Thus the hackery
550 (setq guesspos
(Info-read-subfile guesspos
)))))
554 (goto-char (setq anchorpos guesspos
))
556 ;; Else we may have a node, which we search for:
558 (or (byte-to-position guesspos
)
559 (if (< (position-bytes (point-max)) guesspos
)
562 (goto-char (max (point-min)
563 (- guesschar
1000))))
564 ;; Now search from our advised position
565 ;; (or from beg of buffer)
566 ;; to find the actual node.
567 ;; First, check whether the node is right
568 ;; where we are, in case the buffer begins
571 (or (Info-node-at-bob-matching regexp
)
573 (while (search-forward "\n\^_" nil t
)
577 (if (re-search-backward regexp beg t
)
578 (if (string-equal (match-string 2) nodename
)
583 (setq nodepos
(point)))))))
589 "No such anchor in tag table or node in tag table or file: %s"
591 (goto-char (max (point-min) (- guesspos
1000)))
592 ;; Now search from our advised position (or from beg of buffer)
593 ;; to find the actual node.
594 ;; First, check whether the node is right where we are, in case
595 ;; the buffer begins with a node.
597 (or (Info-node-at-bob-matching regexp
)
599 (while (search-forward "\n\^_" nil t
)
603 (if (re-search-backward regexp beg t
)
604 (if (string-equal (match-string 2) nodename
)
607 (setq nodepos
(point)))))))
610 (error "No such node: %s" nodename
))))))
612 (goto-char (or anchorpos
(point-min)))))
613 ;; If we did not finish finding the specified node,
614 ;; go back to the previous one.
615 (or Info-current-node no-going-back
(null Info-history
)
616 (let ((hist (car Info-history
)))
617 (setq Info-history
(cdr Info-history
))
618 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
619 (goto-char (nth 2 hist
))))))
621 ;; Cache the contents of the (virtual) dir file, once we have merged
622 ;; it for the first time, so we can save time subsequently.
623 (defvar Info-dir-contents nil
)
625 ;; Cache for the directory we decided to use for the default-directory
626 ;; of the merged dir text.
627 (defvar Info-dir-contents-directory nil
)
629 ;; Record the file attributes of all the files from which we
630 ;; constructed Info-dir-contents.
631 (defvar Info-dir-file-attributes nil
)
633 (defvar Info-dir-file-name nil
)
635 ;; Construct the Info directory node by merging the files named `dir'
636 ;; from various directories. Set the *info* buffer's
637 ;; default-directory to the first directory we actually get any text
639 (defun Info-insert-dir ()
640 (if (and Info-dir-contents Info-dir-file-attributes
641 ;; Verify that none of the files we used has changed
644 (mapcar '(lambda (elt)
645 (let ((curr (file-attributes
647 (file-truename (car elt
)))))
649 ;; Don't compare the access time.
650 (if curr
(setcar (nthcdr 4 curr
) 0))
651 (setcar (nthcdr 4 (cdr elt
)) 0)
652 (equal (cdr elt
) curr
)))
653 Info-dir-file-attributes
))))
655 (insert Info-dir-contents
)
656 (goto-char (point-min)))
657 (let ((dirs Info-directory-list
)
658 ;; Bind this in case the user sets it to nil.
660 ;; This is set non-nil if we find a problem in some input files.
662 buffers buffer others nodes dirs-done
)
664 (setq Info-dir-file-attributes nil
)
666 ;; Search the directory list for the directory file.
668 (let ((truename (file-truename (expand-file-name (car dirs
)))))
669 (or (member truename dirs-done
)
670 (member (directory-file-name truename
) dirs-done
)
671 ;; Try several variants of specified name.
672 ;; Try upcasing, appending `.info', or both.
676 (progn (setq file
(expand-file-name "dir" truename
))
677 (file-attributes file
))
678 (progn (setq file
(expand-file-name "DIR" truename
))
679 (file-attributes file
))
680 (progn (setq file
(expand-file-name "dir.info" truename
))
681 (file-attributes file
))
682 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
683 (file-attributes file
)))))
686 (cons (directory-file-name truename
)
691 (message "Composing main Info directory..."))
692 (set-buffer (generate-new-buffer " info dir"))
695 (insert-file-contents file
)
696 (make-local-variable 'Info-dir-file-name
)
697 (setq Info-dir-file-name file
)
698 (setq buffers
(cons (current-buffer) buffers
)
699 Info-dir-file-attributes
700 (cons (cons file attrs
)
701 Info-dir-file-attributes
)))
702 (error (kill-buffer (current-buffer))))))))
703 (or (cdr dirs
) (setq Info-dir-contents-directory
704 (file-name-as-directory (car dirs
))))
705 (setq dirs
(cdr dirs
))))
708 (error "Can't find the Info directory node"))
709 ;; Distinguish the dir file that comes with Emacs from all the
710 ;; others. Yes, that is really what this is supposed to do.
711 ;; The definition of `Info-directory-list' puts it first on that
712 ;; list and so last in `buffers' at this point.
713 (setq buffer
(car (last buffers
))
714 others
(delq buffer buffers
))
716 ;; Insert the entire original dir file as a start; note that we've
717 ;; already saved its default directory to use as the default
718 ;; directory for the whole concatenation.
719 (insert-buffer buffer
)
721 ;; Look at each of the other buffers one by one.
723 (let ((other (car others
))
725 ;; In each, find all the menus.
728 (goto-char (point-min))
729 ;; Find each menu, and add an elt to NODES for it.
730 (while (re-search-forward "^\\* Menu:" nil t
)
731 (let (beg nodename end
)
734 (or (search-backward "\n\^_" nil
'move
)
736 (signal 'search-failed
(list "\n\^_")))
737 (search-forward "Node: ")
738 (setq nodename
(Info-following-node-name))
739 (search-forward "\n\^_" nil
'move
)
742 (setq this-buffer-nodes
743 (cons (list nodename other beg end
)
744 this-buffer-nodes
))))
745 (if (assoc-ignore-case "top" this-buffer-nodes
)
746 (setq nodes
(nconc this-buffer-nodes nodes
))
748 (message "No `top' node in %s" Info-dir-file-name
))))
749 (setq others
(cdr others
)))
750 ;; Add to the main menu a menu item for each other node.
751 (re-search-forward "^\\* Menu:")
753 (let ((menu-items '("top"))
756 (end (save-excursion (search-forward "\^_" nil t
) (point))))
758 (let ((nodename (car (car nodes
))))
760 (or (member (downcase nodename
) menu-items
)
761 (re-search-forward (concat "^\\* +"
762 (regexp-quote nodename
)
766 (insert "* " nodename
"::" "\n")
767 (setq menu-items
(cons nodename menu-items
))))))
768 (setq nodes
(cdr nodes
))))
769 ;; Now take each node of each of the other buffers
770 ;; and merge it into the main buffer.
772 (let ((nodename (car (car nodes
))))
773 (goto-char (point-min))
774 ;; Find the like-named node in the main buffer.
775 (if (re-search-forward (concat "^\^_.*\n.*Node: "
776 (regexp-quote nodename
)
780 (search-forward "\n\^_" nil
'move
)
783 ;; If none exists, add one.
784 (goto-char (point-max))
785 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
786 ;; Merge the text from the other buffer's menu
787 ;; into the menu in the like-named node in the main buffer.
788 (apply 'insert-buffer-substring
(cdr (car nodes
))))
789 (setq nodes
(cdr nodes
)))
790 ;; Kill all the buffers we just made.
792 (kill-buffer (car buffers
))
793 (setq buffers
(cdr buffers
)))
794 (goto-char (point-min))
796 (message "Composing main Info directory...problems encountered, see `*Messages*'")
797 (message "Composing main Info directory...done")))
798 (setq Info-dir-contents
(buffer-string)))
799 (setq default-directory Info-dir-contents-directory
))
801 ;; Note that on entry to this function the current-buffer must be the
802 ;; *info* buffer; not the info tags buffer.
803 (defun Info-read-subfile (nodepos)
804 ;; NODEPOS is either a position (in the Info file as a whole,
805 ;; not relative to a subfile) or the name of a subfile.
808 (if (numberp nodepos
)
810 (set-buffer (marker-buffer Info-tag-table-marker
))
811 (goto-char (point-min))
812 (or (looking-at "\^_")
813 (search-forward "\n\^_"))
816 (while (not (looking-at "\^_"))
819 thisfilepos thisfilename
)
820 (search-forward ": ")
821 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
822 (setq thisfilepos
(read (current-buffer)))
823 ;; read in version 19 stops at the end of number.
824 ;; Advance to the next line.
826 (if (> thisfilepos nodepos
)
828 (setq lastfilename thisfilename
)
829 (setq lastfilepos thisfilepos
))
831 (setq lastfilename nodepos
)
832 (setq lastfilepos
0))
833 ;; Assume previous buffer is in Info-mode.
834 ;; (set-buffer (get-buffer "*info*"))
835 (or (equal Info-current-subfile lastfilename
)
836 (let ((buffer-read-only nil
))
837 (setq buffer-file-name nil
)
840 (info-insert-file-contents lastfilename
)
841 (set-buffer-modified-p nil
)
842 (setq Info-current-subfile lastfilename
)))
843 (goto-char (point-min))
844 (if (looking-at "\^_")
846 (search-forward "\n\^_"))
847 (if (numberp nodepos
)
848 (+ (- nodepos lastfilepos
) (point)))))
850 ;; Select the info node that point is in.
851 (defun Info-select-node ()
852 ;; Bind this in case the user sets it to nil.
853 (let ((case-fold-search t
))
855 ;; Find beginning of node.
856 (if (search-backward "\n\^_" nil
'move
)
858 (if (looking-at "\^_")
860 (signal 'search-failed
(list "\n\^_"))))
861 ;; Get nodename spelled as it is in the node.
862 (re-search-forward "Node:[ \t]*")
863 (setq Info-current-node
864 (buffer-substring-no-properties (point)
866 (skip-chars-forward "^,\t\n")
869 ;; Find the end of it, and narrow.
871 (let (active-expression)
872 (narrow-to-region (point)
873 (if (re-search-forward "\n[\^_\f]" nil t
)
876 (if (looking-at "[\n\^_\f]*execute: ")
878 (goto-char (match-end 0))
879 (setq active-expression
880 (read (current-buffer))))))
882 (if Info-enable-active-nodes
(eval active-expression
))
883 (if Info-fontify
(Info-fontify-node))
884 (run-hooks 'Info-selection-hook
)))))
886 (defun Info-set-mode-line ()
887 (setq mode-line-buffer-identification
890 (if Info-current-file
891 (file-name-nondirectory (if (stringp Info-current-file
)
893 (or buffer-file-name
"")))
896 (or Info-current-node
""))))
898 ;; Go to an info node specified with a filename-and-nodename string
899 ;; of the sort that is found in pointers in nodes.
901 (defun Info-goto-node (nodename &optional fork
)
902 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
903 If FORK is non-nil, show the node in a new info buffer.
904 If FORK is a string, it is the name to use for the new buffer."
905 (interactive (list (Info-read-node-name "Goto node: ") current-prefix-arg
))
909 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
911 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
913 (setq filename
(if (= (match-beginning 1) (match-end 1))
915 (substring nodename
(match-beginning 2) (match-end 2)))
916 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
917 (let ((trim (string-match "\\s *\\'" filename
)))
918 (if trim
(setq filename
(substring filename
0 trim
))))
919 (let ((trim (string-match "\\s *\\'" nodename
)))
920 (if trim
(setq nodename
(substring nodename
0 trim
))))
921 (if transient-mark-mode
(deactivate-mark))
922 (Info-find-node (if (equal filename
"") nil filename
)
923 (if (equal nodename
"") "Top" nodename
))))
925 (defvar Info-read-node-completion-table
)
927 ;; This function is used as the "completion table" while reading a node name.
928 ;; It does completion using the alist in Info-read-node-completion-table
929 ;; unless STRING starts with an open-paren.
930 (defun Info-read-node-name-1 (string predicate code
)
931 (let ((no-completion (and (> (length string
) 0) (eq (aref string
0) ?\
())))
935 (try-completion string Info-read-node-completion-table predicate
)))
939 (all-completions string Info-read-node-completion-table predicate
)))
943 (assoc string Info-read-node-completion-table
))))))
945 (defun Info-read-node-name (prompt &optional default
)
946 (let* ((completion-ignore-case t
)
947 (Info-read-node-completion-table (Info-build-node-completions))
948 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
949 (if (equal nodename
"")
951 (Info-read-node-name prompt
))
954 (defun Info-build-node-completions ()
955 (or Info-current-file-completions
957 ;; Bind this in case the user sets it to nil.
959 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
962 (if (marker-buffer Info-tag-table-marker
)
963 (let ((marker Info-tag-table-marker
))
964 (set-buffer (marker-buffer marker
))
967 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t
)
969 (cons (list (match-string-no-properties 1))
972 (goto-char (point-min))
973 ;; If the buffer begins with a node header, process that first.
974 (if (Info-node-at-bob-matching node-regexp
)
975 (setq compl
(list (match-string-no-properties 1))))
976 ;; Now for the rest of the nodes.
977 (while (search-forward "\n\^_" nil t
)
981 (if (re-search-backward node-regexp beg t
)
983 (cons (list (match-string-no-properties 1))
985 (setq compl
(cons '("*") compl
))
986 (setq Info-current-file-completions compl
))))
988 (defun Info-restore-point (hl)
989 "If this node has been visited, restore the point value when we left."
991 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
992 ;; Use string-equal, not equal, to ignore text props.
993 (string-equal (nth 1 (car hl
)) Info-current-node
))
995 (goto-char (nth 2 (car hl
)))
996 (setq hl nil
)) ;terminate the while at next iter
997 (setq hl
(cdr hl
)))))
999 (defvar Info-last-search nil
1000 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1002 (defun Info-search (regexp)
1003 "Search for REGEXP, starting from point, and select node it's found in."
1004 (interactive "sSearch (regexp): ")
1005 (if transient-mark-mode
(deactivate-mark))
1006 (if (equal regexp
"")
1007 (setq regexp Info-last-search
)
1008 (setq Info-last-search regexp
))
1010 (let ((found ()) current
1011 (onode Info-current-node
)
1012 (ofile Info-current-file
)
1014 (ostart (window-start))
1015 (osubfile Info-current-subfile
))
1019 (if (null Info-current-subfile
)
1020 (progn (re-search-forward regexp
) (setq found
(point)))
1022 (progn (re-search-forward regexp
) (setq found
(point)))
1023 (search-failed nil
)))))
1024 (if (not found
) ;can only happen in subfile case -- else would have erred
1028 (set-buffer (marker-buffer Info-tag-table-marker
))
1029 (goto-char (point-min))
1030 (search-forward "\n\^_\nIndirect:")
1032 (narrow-to-region (point)
1033 (progn (search-forward "\n\^_")
1035 (goto-char (point-min))
1036 (search-forward (concat "\n" osubfile
": "))
1039 (re-search-forward "\\(^.*\\): [0-9]+$")
1040 (goto-char (+ (match-end 1) 2))
1041 (setq list
(cons (cons (read (current-buffer))
1042 (match-string-no-properties 1))
1044 (goto-char (1+ (match-end 0))))
1045 (setq list
(nreverse list
)
1046 current
(car (car list
))
1049 (message "Searching subfile %s..." (cdr (car list
)))
1050 (Info-read-subfile (car (car list
)))
1051 (setq list
(cdr list
))
1052 ;;; (goto-char (point-min))
1053 (if (re-search-forward regexp nil t
)
1054 (setq found
(point) list
())))
1057 (signal 'search-failed
(list regexp
))))
1059 (progn (Info-read-subfile osubfile
)
1062 (set-window-start (selected-window) ostart
)))))
1066 ;; Use string-equal, not equal, to ignore text props.
1067 (or (and (string-equal onode Info-current-node
)
1068 (equal ofile Info-current-file
))
1069 (setq Info-history
(cons (list ofile onode opoint
)
1072 ;; Extract the value of the node-pointer named NAME.
1073 ;; If there is none, use ERRORNAME in the error message;
1074 ;; if ERRORNAME is nil, just return nil.
1075 (defun Info-extract-pointer (name &optional errorname
)
1076 ;; Bind this in case the user sets it to nil.
1077 (let ((case-fold-search t
))
1079 (goto-char (point-min))
1081 (if (re-search-backward (concat name
":") nil t
)
1083 (goto-char (match-end 0))
1084 (Info-following-node-name))
1085 (if (eq errorname t
)
1087 (error "Node has no %s" (capitalize (or errorname name
))))))))
1089 ;; Return the node name in the buffer following point.
1090 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1091 ;; saying which chars may appear in the node name.
1092 (defun Info-following-node-name (&optional allowedchars
)
1093 (skip-chars-forward " \t")
1094 (buffer-substring-no-properties
1097 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
1098 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
1099 (if (looking-at "(")
1100 (skip-chars-forward "^)")))
1101 (skip-chars-backward " ")
1105 "Go to the next node of this node."
1107 (Info-goto-node (Info-extract-pointer "next")))
1110 "Go to the previous node of this node."
1112 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1114 (defun Info-up (&optional same-file
)
1115 "Go to the superior node of this node.
1116 If SAME-FILE is non-nil, do not move to a different Info file."
1118 (let ((node (Info-extract-pointer "up")))
1119 (and (or same-file
(not (stringp Info-current-file
)))
1120 (string-match "^(" node
)
1121 (error "Up node is in another Info file"))
1122 (Info-goto-node node
))
1123 (Info-restore-point Info-history
))
1126 "Go back to the last node visited."
1129 (error "This is the first Info node you looked at"))
1130 (let (filename nodename opoint
)
1131 (setq filename
(car (car Info-history
)))
1132 (setq nodename
(car (cdr (car Info-history
))))
1133 (setq opoint
(car (cdr (cdr (car Info-history
)))))
1134 (setq Info-history
(cdr Info-history
))
1135 (Info-find-node filename nodename
)
1136 (setq Info-history
(cdr Info-history
))
1137 (goto-char opoint
)))
1140 (defun Info-directory ()
1141 "Go to the Info directory node."
1143 (Info-find-node "dir" "top"))
1145 (defun Info-follow-reference (footnotename)
1146 "Follow cross reference named NAME to the node it refers to.
1147 NAME may be an abbreviation of the reference name."
1149 (let ((completion-ignore-case t
)
1150 (case-fold-search t
)
1151 completions default alt-default
(start-point (point)) str i bol eol
)
1153 ;; Store end and beginning of line.
1159 (goto-char (point-min))
1160 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
1161 (setq str
(buffer-substring-no-properties
1164 ;; See if this one should be the default.
1166 (<= (match-beginning 0) start-point
)
1167 (<= start-point
(point))
1169 ;; See if this one should be the alternate default.
1170 (and (null alt-default
)
1171 (and (<= bol
(match-beginning 0))
1173 (setq alt-default t
))
1175 (while (setq i
(string-match "[ \n\t]+" str i
))
1176 (setq str
(concat (substring str
0 i
) " "
1177 (substring str
(match-end 0))))
1179 ;; Record as a completion and perhaps as default.
1180 (if (eq default t
) (setq default str
))
1181 (if (eq alt-default t
) (setq alt-default str
))
1182 ;; Don't add this string if it's a duplicate.
1183 ;; We use a loop instead of "(assoc str completions)" because
1184 ;; we want to do a case-insensitive compare.
1185 (let ((tail completions
)
1186 (tem (downcase str
)))
1188 (not (string-equal tem
(downcase (car (car tail
))))))
1189 (setq tail
(cdr tail
)))
1192 (cons (cons str nil
)
1194 ;; If no good default was found, try an alternate.
1196 (setq default alt-default
))
1197 ;; If only one cross-reference found, then make it default.
1198 (if (eq (length completions
) 1)
1199 (setq default
(car (car completions
))))
1201 (let ((input (completing-read (if default
1202 (concat "Follow reference named: ("
1204 "Follow reference named: ")
1205 completions nil t
)))
1206 (list (if (equal input
"")
1208 (error "No cross-references in this node"))))
1210 (unless footnotename
1211 (error "No reference was specified"))
1213 (let (target beg i
(str (concat "\\*note " (regexp-quote footnotename
)))
1214 (case-fold-search t
))
1215 (while (setq i
(string-match " " str i
))
1216 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
1219 (goto-char (point-min))
1220 (or (re-search-forward str nil t
)
1221 (error "No cross-reference named %s" footnotename
))
1222 (goto-char (+ (match-beginning 0) 5))
1224 (Info-extract-menu-node-name "Bad format cross reference" t
)))
1225 (while (setq i
(string-match "[ \t\n]+" target i
))
1226 (setq target
(concat (substring target
0 i
) " "
1227 (substring target
(match-end 0))))
1229 (Info-goto-node target
)))
1231 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
1232 (skip-chars-forward " \t\n")
1235 (skip-chars-forward "^:")
1238 (if (looking-at ":")
1239 (buffer-substring-no-properties beg
(1- (point)))
1240 (skip-chars-forward " \t\n")
1241 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
1242 (while (setq i
(string-match "\n" str i
))
1244 ;; Collapse multiple spaces.
1245 (while (string-match " +" str
)
1246 (setq str
(replace-match " " t t str
)))
1249 ;; No one calls this.
1250 ;;(defun Info-menu-item-sequence (list)
1252 ;; (Info-menu (car list))
1253 ;; (setq list (cdr list))))
1255 (defvar Info-complete-menu-buffer
)
1257 (defun Info-complete-menu-item (string predicate action
)
1258 (let ((case-fold-search t
))
1259 (cond ((eq action nil
)
1261 (pattern (concat "\n\\* +\\("
1262 (regexp-quote string
)
1265 (set-buffer Info-complete-menu-buffer
)
1266 (goto-char (point-min))
1267 (search-forward "\n* Menu:")
1268 (while (re-search-forward pattern nil t
)
1270 (cons (cons (match-string-no-properties 1)
1271 (match-beginning 1))
1273 (try-completion string completions predicate
)))
1276 (pattern (concat "\n\\* +\\("
1277 (regexp-quote string
)
1280 (set-buffer Info-complete-menu-buffer
)
1281 (goto-char (point-min))
1282 (search-forward "\n* Menu:")
1283 (while (re-search-forward pattern nil t
)
1284 (setq completions
(cons (cons
1285 (match-string-no-properties 1)
1286 (match-beginning 1))
1288 (all-completions string completions predicate
)))
1291 (set-buffer Info-complete-menu-buffer
)
1292 (goto-char (point-min))
1293 (search-forward "\n* Menu:")
1294 (re-search-forward (concat "\n\\* +"
1295 (regexp-quote string
)
1300 (defun Info-menu (menu-item &optional fork
)
1301 "Go to node for menu item named (or abbreviated) NAME.
1302 Completion is allowed, and the menu item point is on is the default."
1304 (let ((completions '())
1305 ;; If point is within a menu item, use that item as the default
1311 (goto-char (point-min))
1312 (if (not (search-forward "\n* menu:" nil t
))
1313 (error "No menu in this node"))
1319 (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t
)
1320 (setq default
(match-string-no-properties 1))))))
1323 (setq item
(let ((completion-ignore-case t
)
1324 (Info-complete-menu-buffer (current-buffer)))
1325 (completing-read (if default
1326 (format "Menu item (default %s): "
1329 'Info-complete-menu-item nil t
)))
1330 ;; we rely on the fact that completing-read accepts an input
1331 ;; of "" even when the require-match argument is true and ""
1332 ;; is not a valid possibility
1333 (if (string= item
"")
1338 (list item current-prefix-arg
))))
1339 ;; there is a problem here in that if several menu items have the same
1340 ;; name you can only go to the node of the first with this command.
1341 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
1343 (defun Info-extract-menu-item (menu-item)
1344 (setq menu-item
(regexp-quote menu-item
))
1345 (let ((case-fold-search t
))
1347 (goto-char (point-min))
1348 (or (search-forward "\n* menu:" nil t
)
1349 (error "No menu in this node"))
1350 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
1351 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
1352 (error "No such item in menu"))
1355 (Info-extract-menu-node-name))))
1357 ;; If COUNT is nil, use the last item in the menu.
1358 (defun Info-extract-menu-counting (count)
1359 (let ((case-fold-search t
))
1361 (goto-char (point-min))
1362 (or (search-forward "\n* menu:" nil t
)
1363 (error "No menu in this node"))
1365 (or (search-forward "\n* " nil t count
)
1366 (error "Too few items in menu"))
1367 (while (search-forward "\n* " nil t
)
1369 (Info-extract-menu-node-name))))
1371 (defun Info-nth-menu-item ()
1372 "Go to the node of the Nth menu item.
1373 N is the digit argument used to invoke this command."
1376 (Info-extract-menu-counting
1377 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
1379 (defun Info-top-node ()
1380 "Go to the Top node of this file."
1382 (Info-goto-node "Top"))
1384 (defun Info-final-node ()
1385 "Go to the final node in this file."
1387 (Info-goto-node "Top")
1389 ;; Go to the last node in the menu of Top.
1390 (Info-goto-node (Info-extract-menu-counting nil
))
1391 ;; If the last node in the menu is not last in pointer structure,
1392 ;; move forward until we can't go any farther.
1393 (while (Info-forward-node t t
) nil
)
1394 ;; Then keep moving down to last subnode, unless we reach an index.
1395 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1396 (save-excursion (search-forward "\n* Menu:" nil t
)))
1397 (Info-goto-node (Info-extract-menu-counting nil
)))))
1399 (defun Info-forward-node (&optional not-down no-error
)
1400 "Go forward one node, considering all nodes as forming one sequence."
1402 (goto-char (point-min))
1404 ;; three possibilities, in order of priority:
1405 ;; 1. next node is in a menu in this node (but not in an index)
1406 ;; 2. next node is next at same level
1407 ;; 3. next node is up and next
1408 (cond ((and (not not-down
)
1409 (save-excursion (search-forward "\n* menu:" nil t
))
1410 (not (string-match "\\<index\\>" Info-current-node
)))
1411 (Info-goto-node (Info-extract-menu-counting 1))
1413 ((save-excursion (search-backward "next:" nil t
))
1416 ((and (save-excursion (search-backward "up:" nil t
))
1417 ;; Use string-equal, not equal, to ignore text props.
1418 (not (string-equal (downcase (Info-extract-pointer "up"))
1420 (let ((old-node Info-current-node
))
1422 (let (Info-history success
)
1424 (setq success
(Info-forward-node t no-error
))
1425 (or success
(Info-goto-node old-node
))))))
1427 (t (error "No pointer forward from this node"))))
1429 (defun Info-backward-node ()
1430 "Go backward one node, considering all nodes as forming one sequence."
1432 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1433 (upnode (Info-extract-pointer "up" t
)))
1434 (cond ((and upnode
(string-match "(" upnode
))
1435 (error "First node in file"))
1436 ((and upnode
(or (null prevnode
)
1437 ;; Use string-equal, not equal,
1438 ;; to ignore text properties.
1439 (string-equal (downcase prevnode
)
1440 (downcase upnode
))))
1443 ;; If we move back at the same level,
1444 ;; go down to find the last subnode*.
1447 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1448 (save-excursion (search-forward "\n* Menu:" nil t
)))
1449 (Info-goto-node (Info-extract-menu-counting nil
)))))
1451 (error "No pointer backward from this node")))))
1454 "Exit Info by selecting some other buffer."
1457 (save-buffers-kill-emacs)
1460 (defun Info-next-menu-item ()
1465 (search-forward "\n* menu:" nil t
)
1466 (and (search-forward "\n* " nil t
)
1467 (Info-extract-menu-node-name)))))
1468 (if node
(Info-goto-node node
)
1469 (error "No more items in menu"))))
1471 (defun Info-last-menu-item ()
1475 (let ((beg (save-excursion
1476 (and (search-backward "\n* menu:" nil t
)
1478 (or (and beg
(search-backward "\n* " beg t
))
1479 (error "No previous items in menu")))
1480 (Info-goto-node (save-excursion
1481 (goto-char (match-end 0))
1482 (Info-extract-menu-node-name)))))
1484 (defmacro Info-no-error
(&rest body
)
1485 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1487 (defun Info-next-preorder ()
1488 "Go to the next subnode or the next node, or go up a level."
1490 (cond ((Info-no-error (Info-next-menu-item)))
1491 ((Info-no-error (Info-next)))
1492 ((Info-no-error (Info-up t
))
1493 ;; Since we have already gone thru all the items in this menu,
1494 ;; go up to the end of this node.
1495 (goto-char (point-max))
1496 ;; Since logically we are done with the node with that menu,
1498 (Info-next-preorder))
1500 (error "No more nodes"))))
1502 (defun Info-last-preorder ()
1503 "Go to the last node, popping up a level if there is none."
1505 (cond ((Info-no-error
1506 (Info-last-menu-item)
1507 ;; If we go down a menu item, go to the end of the node
1508 ;; so we can scroll back through it.
1509 (goto-char (point-max)))
1510 ;; Keep going down, as long as there are nested menu nodes.
1511 (while (Info-no-error
1512 (Info-last-menu-item)
1513 ;; If we go down a menu item, go to the end of the node
1514 ;; so we can scroll back through it.
1515 (goto-char (point-max))))
1517 ((and (not (equal (Info-extract-pointer "up")
1518 (Info-extract-pointer "prev"))))
1519 (Info-no-error (Info-prev))
1520 (goto-char (point-max))
1521 (while (Info-no-error
1522 (Info-last-menu-item)
1523 ;; If we go down a menu item, go to the end of the node
1524 ;; so we can scroll back through it.
1525 (goto-char (point-max))))
1527 ((Info-no-error (Info-up t
))
1528 (goto-char (point-min))
1529 (or (search-forward "\n* Menu:" nil t
)
1530 (goto-char (point-max))))
1531 (t (error "No previous nodes"))))
1533 (defun Info-scroll-up ()
1534 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1535 Once you scroll far enough in a node that its menu appears on the screen
1536 but after point, the next scroll moves into its first subnode.
1538 When you scroll past the end of a node, that goes to the next node; if
1539 this node has no successor, it moves to the parent node's successor,
1540 and so on. If point is inside the menu of a node, it moves to
1541 subnode indicated by the following menu item. (That case won't
1542 normally result from this command, but can happen in other ways.)"
1545 (if (or (< (window-start) (point-min))
1546 (> (window-start) (point-max)))
1547 (set-window-start (selected-window) (point)))
1548 (let ((virtual-end (save-excursion
1549 (goto-char (point-min))
1550 (if (search-forward "\n* Menu:" nil t
)
1553 (if (or (< virtual-end
(window-start))
1554 (pos-visible-in-window-p virtual-end
))
1555 (Info-next-preorder)
1558 (defun Info-scroll-down ()
1559 "Scroll one screenful back in Info, considering all nodes as one sequence.
1560 Within the menu of a node, this goes to its last subnode.
1561 When you scroll past the beginning of a node, that goes to the
1562 previous node or back up to the parent node."
1564 (if (or (< (window-start) (point-min))
1565 (> (window-start) (point-max)))
1566 (set-window-start (selected-window) (point)))
1567 (let* ((current-point (point))
1568 (virtual-end (save-excursion
1570 (setq current-point
(point))
1571 (goto-char (point-min))
1572 (search-forward "\n* Menu:"
1575 (if (or virtual-end
(pos-visible-in-window-p (point-min)))
1576 (Info-last-preorder)
1579 (defun Info-next-reference (&optional recur
)
1580 "Move cursor to the next cross-reference or menu item in the node."
1582 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1584 (case-fold-search t
))
1585 (or (eobp) (forward-char 1))
1586 (or (re-search-forward pat nil t
)
1588 (goto-char (point-min))
1589 (or (re-search-forward pat nil t
)
1592 (error "No cross references in this node")))))
1593 (goto-char (match-beginning 0))
1594 (if (looking-at "\\* Menu:")
1596 (error "No cross references in this node")
1597 (Info-next-reference t
)))))
1599 (defun Info-prev-reference (&optional recur
)
1600 "Move cursor to the previous cross-reference or menu item in the node."
1602 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1604 (case-fold-search t
))
1605 (or (re-search-backward pat nil t
)
1607 (goto-char (point-max))
1608 (or (re-search-backward pat nil t
)
1611 (error "No cross references in this node")))))
1612 (goto-char (match-beginning 0))
1613 (if (looking-at "\\* Menu:")
1615 (error "No cross references in this node")
1616 (Info-prev-reference t
)))))
1618 (defun Info-index (topic)
1619 "Look up a string in the index for this file.
1620 The index is defined as the first node in the top-level menu whose
1621 name contains the word \"Index\", plus any immediately following
1622 nodes whose names also contain the word \"Index\".
1623 If there are no exact matches to the specified topic, this chooses
1624 the first match which is a case-insensitive substring of a topic.
1625 Use the `,' command to see the other matches.
1626 Give a blank topic name to go to the Index node itself."
1627 (interactive "sIndex topic: ")
1628 (let ((orignode Info-current-node
)
1630 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1631 (regexp-quote topic
)))
1633 (case-fold-search t
))
1634 (Info-goto-node "Top")
1635 (or (search-forward "\n* menu:" nil t
)
1637 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
1639 (goto-char (match-beginning 1))
1640 ;; Here, and subsequently in this function,
1641 ;; we bind Info-history to nil for internal node-switches
1642 ;; so that we don't put junk in the history.
1643 ;; In the first Info-goto-node call, above, we do update the history
1644 ;; because that is what the user's previous node choice into it.
1645 (let ((Info-history nil
))
1646 (Info-goto-node (Info-extract-menu-node-name)))
1647 (or (equal topic
"")
1654 (goto-char (point-min))
1655 (while (re-search-forward pattern nil t
)
1657 (cons (list (match-string-no-properties 1)
1658 (match-string-no-properties 2)
1660 (string-to-int (concat "0"
1663 (and (setq node
(Info-extract-pointer "next" t
))
1664 (string-match "\\<Index\\>" node
)))
1665 (Info-goto-node node
))
1668 (Info-goto-node orignode
)
1669 (error "No `%s' in index" topic
)))
1670 ;; Here it is a feature that assoc is case-sensitive.
1671 (while (setq found
(assoc topic matches
))
1672 (setq exact
(cons found exact
)
1673 matches
(delq found matches
)))
1674 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
1675 (Info-index-next 0)))))
1677 (defun Info-index-next (num)
1678 "Go to the next matching index item from the last `i' command."
1680 (or Info-index-alternatives
1681 (error "No previous `i' command"))
1683 (setq num
(+ num
(length Info-index-alternatives
))))
1685 (setq Info-index-alternatives
1686 (nconc (cdr Info-index-alternatives
)
1687 (list (car Info-index-alternatives
)))
1689 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
1690 (if (> (nth 3 (car Info-index-alternatives
)) 0)
1691 (forward-line (nth 3 (car Info-index-alternatives
)))
1692 (forward-line 3) ; don't search in headers
1693 (let ((name (car (car Info-index-alternatives
))))
1694 (Info-find-index-name name
)))
1695 (message "Found `%s' in %s. %s"
1696 (car (car Info-index-alternatives
))
1697 (nth 2 (car Info-index-alternatives
))
1698 (if (cdr Info-index-alternatives
)
1699 "(Press `,' for more)"
1702 (defun Info-find-index-name (name)
1703 "Move point to the place within the current node where NAME is defined."
1704 (let ((case-fold-search t
))
1705 (if (or (re-search-forward (format
1706 "[a-zA-Z]+: %s\\( \\|$\\)"
1707 (regexp-quote name
)) nil t
)
1708 (search-forward (format "`%s'" name
) nil t
)
1709 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
1711 (format "`%s'" (substring name
0 (match-beginning 1)))
1713 (search-forward name nil t
))
1715 (goto-char (point-min)))))
1717 (defun Info-undefined ()
1718 "Make command be undefined in Info."
1723 "Enter the Info tutorial."
1725 (delete-other-windows)
1726 (Info-find-node "info"
1727 (if (< (window-height) 23)
1731 (defun Info-summary ()
1732 "Display a brief summary of all Info commands."
1734 (save-window-excursion
1735 (switch-to-buffer "*Help*")
1736 (setq buffer-read-only nil
)
1738 (insert (documentation 'Info-mode
))
1740 (goto-char (point-min))
1742 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
1743 (message (if flag
"Type Space to see more"
1744 "Type Space to return to Info"))
1745 (if (not (eq ?\
(setq ch
(read-event))))
1746 (progn (setq unread-command-events
(list ch
)) nil
)
1749 (bury-buffer "*Help*")))
1751 (defun Info-get-token (pos start all
&optional errorstring
)
1752 "Return the token around POS,
1753 POS must be somewhere inside the token
1754 START is a regular expression which will match the
1755 beginning of the tokens delimited string
1756 ALL is a regular expression with a single
1757 parenthesized subpattern which is the token to be
1758 returned. E.g. '{\(.*\)}' would return any string
1759 enclosed in braces around POS.
1760 SIG optional fourth argument, controls action on no match
1763 a string: signal an error, using that string."
1764 (let ((case-fold-search t
))
1767 ;; First look for a match for START that goes across POS.
1768 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
1769 (not (looking-at start
)))
1771 ;; If we did not find one, search back for START
1772 ;; (this finds only matches that end at or before POS).
1773 (or (looking-at start
)
1776 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
1778 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
1779 (not (setq found
(and (<= (match-beginning 0) pos
)
1780 (> (match-end 0) pos
))))))
1781 (if (and found
(<= (match-beginning 0) pos
)
1782 (> (match-end 0) pos
))
1783 (match-string-no-properties 1)
1784 (cond ((null errorstring
)
1790 (error "No %s around position %d" errorstring pos
))))))))
1792 (defun Info-mouse-follow-nearest-node (click)
1793 "\\<Info-mode-map>Follow a node reference near point.
1794 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1795 At end of the node's text, moves to the next node, or up if none."
1797 (let* ((start (event-start click
))
1798 (window (car start
))
1799 (pos (car (cdr start
))))
1800 (select-window window
)
1802 (and (not (Info-try-follow-nearest-node))
1803 (save-excursion (forward-line 1) (eobp))
1804 (Info-next-preorder)))
1806 (defun Info-follow-nearest-node ()
1807 "\\<Info-mode-map>Follow a node reference near point.
1808 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1809 If no reference to follow, moves to the next node, or up if none."
1811 (or (Info-try-follow-nearest-node)
1812 (Info-next-preorder)))
1814 ;; Common subroutine.
1815 (defun Info-try-follow-nearest-node ()
1816 "Follow a node reference near point. Return non-nil if successful."
1819 ((setq node
(Info-get-token (point) "\\*note[ \n]"
1820 "\\*note[ \n]\\([^:]*\\):"))
1821 (Info-follow-reference node
))
1822 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1823 (Info-goto-node node
))
1824 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
1827 (setq node
(Info-extract-menu-node-name))
1828 (Info-goto-node node
))
1829 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1830 (Info-goto-node node
))
1831 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1832 (Info-goto-node node
))
1833 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1834 (Info-goto-node "Top"))
1835 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1836 (Info-goto-node node
)))
1839 (defvar Info-mode-map nil
1840 "Keymap containing Info commands.")
1843 (setq Info-mode-map
(make-keymap))
1844 (suppress-keymap Info-mode-map
)
1845 (define-key Info-mode-map
"." 'beginning-of-buffer
)
1846 (define-key Info-mode-map
" " 'Info-scroll-up
)
1847 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
1848 (define-key Info-mode-map
"\t" 'Info-next-reference
)
1849 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
1850 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
1851 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
1852 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
1853 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
1854 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
1855 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
1856 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
1857 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
1858 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
1859 (define-key Info-mode-map
"0" 'undefined
)
1860 (define-key Info-mode-map
"?" 'Info-summary
)
1861 (define-key Info-mode-map
"]" 'Info-forward-node
)
1862 (define-key Info-mode-map
"[" 'Info-backward-node
)
1863 (define-key Info-mode-map
"<" 'Info-top-node
)
1864 (define-key Info-mode-map
">" 'Info-final-node
)
1865 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
1866 (define-key Info-mode-map
"d" 'Info-directory
)
1867 (define-key Info-mode-map
"e" 'Info-edit
)
1868 (define-key Info-mode-map
"f" 'Info-follow-reference
)
1869 (define-key Info-mode-map
"g" 'Info-goto-node
)
1870 (define-key Info-mode-map
"h" 'Info-help
)
1871 (define-key Info-mode-map
"i" 'Info-index
)
1872 (define-key Info-mode-map
"l" 'Info-last
)
1873 (define-key Info-mode-map
"m" 'Info-menu
)
1874 (define-key Info-mode-map
"n" 'Info-next
)
1875 (define-key Info-mode-map
"p" 'Info-prev
)
1876 (define-key Info-mode-map
"q" 'Info-exit
)
1877 (define-key Info-mode-map
"s" 'Info-search
)
1878 ;; For consistency with Rmail.
1879 (define-key Info-mode-map
"\M-s" 'Info-search
)
1880 (define-key Info-mode-map
"\M-n" 'clone-buffer
)
1881 (define-key Info-mode-map
"t" 'Info-top-node
)
1882 (define-key Info-mode-map
"u" 'Info-up
)
1883 (define-key Info-mode-map
"," 'Info-index-next
)
1884 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
1885 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
1888 (defun Info-check-pointer (item)
1889 ;; Non-nil if ITEM is present in this node.
1891 (Info-extract-pointer item
)
1894 (easy-menu-define Info-mode-menu Info-mode-map
1895 "Menu for info files."
1897 ["Up" Info-up
(Info-check-pointer "up")
1898 :help
"Go up in the Info tree"]
1899 ["Next" Info-next
(Info-check-pointer "next")
1900 :help
"Go to the next node"]
1901 ["Previous" Info-prev
(Info-check-pointer "prev[ious]*")
1902 :help
"Go to the previous node"]
1903 ["Backward" Info-backward-node t
1904 :help
"Go backward one node, considering all as a sequence"]
1905 ["Forward" Info-forward-node t
1906 :help
"Go forward one node, considering all as a sequence"]
1907 ["Top" Info-top-node t
1908 :help
"Go to top node of file"]
1909 ["Final node" Info-final-node t
1910 :help
"Go to final node in this file"]
1911 ("Menu item" ["You should never see this" report-emacs-bug t
])
1912 ("Reference" ["You should never see this" report-emacs-bug t
])
1913 ["Search..." Info-search t
1914 :help
"Search for regular expression in this Info file"]
1915 ["Goto node..." Info-goto-node t
1916 :help
"Go to a named node]"]
1917 ["Last" Info-last Info-history
1918 :help
"Go to the last node you were at"]
1920 ["Lookup a String" Info-index t
1921 :help
"Look for a string in the index items"]
1922 ["Next Matching Item" Info-index-next t
1923 :help
"Look for another occurrence of previous item"])
1924 ["Exit" Info-exit t
]))
1926 (defvar Info-menu-last-node nil
)
1927 ;; Last node the menu was created for.
1928 ;; Value is a list, (FILE-NAME NODE-NAME).
1930 (defun Info-menu-update ()
1931 ;; Update the Info menu for the current node.
1933 (if (or (not (eq major-mode
'Info-mode
))
1934 (equal (list Info-current-file Info-current-node
)
1935 Info-menu-last-node
))
1937 ;; Update menu menu.
1938 (let* ((Info-complete-menu-buffer (current-buffer))
1939 (items (nreverse (condition-case nil
1940 (Info-complete-menu-item
1941 "" (lambda (e) t
) t
)
1945 (while (and items
(< number
9))
1946 (setq current
(car items
)
1949 (setq entries
(cons `[,current
1950 (Info-menu ,current
)
1951 :keys
,(format "%d" number
)]
1954 (setq entries
(cons ["Other..." Info-menu t
] entries
)))
1956 (setq entries
(list ["No menu" nil nil
])))
1957 (easy-menu-change '("Info") "Menu item" (nreverse entries
)))
1958 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1960 str i entries current
1962 (case-fold-search t
))
1964 (goto-char (point-min))
1965 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
1966 (setq str
(buffer-substring
1970 (while (setq i
(string-match "[ \n\t]+" str i
))
1971 (setq str
(concat (substring str
0 i
) " "
1972 (substring str
(match-end 0))))
1976 (while (and items
(< number
9))
1977 (setq current
(car items
)
1980 (setq entries
(cons `[,current
1981 (Info-follow-reference ,current
)
1985 (setq entries
(cons ["Other..." Info-follow-reference t
]
1988 (setq entries
(list ["No references" nil nil
])))
1989 (easy-menu-change '("Info") "Reference" (nreverse entries
)))
1990 ;; Update last seen node.
1991 (setq Info-menu-last-node
(list Info-current-file Info-current-node
)))
1992 ;; Try to avoid entering infinite beep mode in case of errors.
1996 ;; Info mode is suitable only for specially formatted data.
1997 (put 'info-mode
'mode-class
'special
)
2001 Info mode provides commands for browsing through the Info documentation tree.
2002 Documentation in Info is divided into \"nodes\", each of which discusses
2003 one topic and contains references to other nodes which discuss related
2004 topics. Info has commands to follow the references and show you other nodes.
2006 \\[Info-help] Invoke the Info tutorial.
2007 \\[Info-exit] Quit Info: reselect previously selected buffer.
2009 Selecting other nodes:
2010 \\[Info-mouse-follow-nearest-node]
2011 Follow a node reference you click on.
2012 This works with menu items, cross references, and
2013 the \"next\", \"previous\" and \"up\", depending on where you click.
2014 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2015 \\[Info-next] Move to the \"next\" node of this node.
2016 \\[Info-prev] Move to the \"previous\" node of this node.
2017 \\[Info-up] Move \"up\" from this node.
2018 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2019 Picking a menu item causes another node to be selected.
2020 \\[Info-directory] Go to the Info directory node.
2021 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2022 \\[Info-last] Move to the last node you were at.
2023 \\[Info-index] Look up a topic in this file's Index and move to that node.
2024 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2025 \\[Info-top-node] Go to the Top node of this file.
2026 \\[Info-final-node] Go to the final node in this file.
2027 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2028 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2030 Moving within a node:
2031 \\[Info-scroll-up] Normally, scroll forward a full screen.
2032 Once you scroll far enough in a node that its menu appears on the screen
2033 but after point, the next scroll moves into its first subnode.
2034 When after all menu items (or if their is no menu), move up to
2036 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2037 already visible, try to go to the previous menu entry, or up if there is none.
2038 \\[beginning-of-buffer] Go to beginning of node.
2041 \\[Info-exit] Quit Info: reselect previously selected buffer.
2042 \\[Info-edit] Edit contents of selected node.
2043 1 Pick first item in node's menu.
2044 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2045 \\[Info-goto-node] Move to node specified by name.
2046 You may include a filename as well, as (FILENAME)NODENAME.
2047 \\[universal-argument] \\[info] Move to new Info file with completion.
2048 \\[Info-search] Search through this Info file for specified regexp,
2049 and select the node in which the next occurrence is found.
2050 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2051 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2052 (kill-all-local-variables)
2053 (setq major-mode
'Info-mode
)
2054 (setq mode-name
"Info")
2056 (use-local-map Info-mode-map
)
2057 (make-local-hook 'activate-menubar-hook
)
2058 (add-hook 'activate-menubar-hook
'Info-menu-update nil t
)
2059 (set-syntax-table text-mode-syntax-table
)
2060 (setq local-abbrev-table text-mode-abbrev-table
)
2061 (setq case-fold-search t
)
2062 (setq buffer-read-only t
)
2063 (make-local-variable 'Info-current-file
)
2064 (make-local-variable 'Info-current-subfile
)
2065 (make-local-variable 'Info-current-node
)
2066 (make-local-variable 'Info-tag-table-marker
)
2067 (setq Info-tag-table-marker
(make-marker))
2068 (make-local-variable 'Info-tag-table-buffer
)
2069 (setq Info-tag-table-buffer nil
)
2070 (make-local-variable 'Info-history
)
2071 (make-local-variable 'Info-index-alternatives
)
2072 ;; This is for the sake of the invisible text we use handling titles.
2073 (make-local-variable 'line-move-ignore-invisible
)
2074 (setq line-move-ignore-invisible t
)
2075 (add-hook (make-local-hook 'clone-buffer-hook
) 'Info-clone-buffer-hook nil t
)
2076 (Info-set-mode-line)
2077 (run-hooks 'Info-mode-hook
))
2079 (defun Info-clone-buffer-hook ()
2080 (when (bufferp Info-tag-table-buffer
)
2081 (setq Info-tag-table-buffer
2082 (with-current-buffer Info-tag-table-buffer
(clone-buffer)))
2083 (let ((m Info-tag-table-marker
))
2084 (when (and (markerp m
) (marker-position m
))
2085 (setq Info-tag-table-marker
2086 (with-current-buffer Info-tag-table-buffer
2087 (copy-marker (marker-position m
))))))))
2089 (defvar Info-edit-map nil
2090 "Local keymap used within `e' command of Info.")
2093 (setq Info-edit-map
(nconc (make-sparse-keymap) text-mode-map
))
2094 (define-key Info-edit-map
"\C-c\C-c" 'Info-cease-edit
))
2096 ;; Info-edit mode is suitable only for specially formatted data.
2097 (put 'info-edit-mode
'mode-class
'special
)
2099 (defun Info-edit-mode ()
2100 "Major mode for editing the contents of an Info node.
2101 Like text mode with the addition of `Info-cease-edit'
2102 which returns to Info mode for browsing.
2104 (use-local-map Info-edit-map
)
2105 (setq major-mode
'Info-edit-mode
)
2106 (setq mode-name
"Info Edit")
2107 (kill-local-variable 'mode-line-buffer-identification
)
2108 (setq buffer-read-only nil
)
2109 (force-mode-line-update)
2110 (buffer-enable-undo (current-buffer))
2111 (run-hooks 'Info-edit-mode-hook
))
2114 "Edit the contents of this Info node.
2115 Allowed only if variable `Info-enable-edit' is non-nil."
2117 (or Info-enable-edit
2118 (error "Editing info nodes is not enabled"))
2120 (message "%s" (substitute-command-keys
2121 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2123 (defun Info-cease-edit ()
2124 "Finish editing Info node; switch back to Info proper."
2126 ;; Do this first, so nothing has changed if user C-g's at query.
2127 (and (buffer-modified-p)
2128 (y-or-n-p "Save the file? ")
2130 (use-local-map Info-mode-map
)
2131 (setq major-mode
'Info-mode
)
2132 (setq mode-name
"Info")
2133 (Info-set-mode-line)
2134 (setq buffer-read-only t
)
2135 (force-mode-line-update)
2136 (and (marker-position Info-tag-table-marker
)
2138 (message "Tags may have changed. Use Info-tagify if necessary")))
2140 (defvar Info-file-list-for-emacs
2141 '("ediff" "forms" "gnus" "info" ("mh" .
"mh-e") "sc" "message"
2142 ("dired" .
"dired-x") ("c" .
"ccmode") "viper")
2143 "List of Info files that describe Emacs commands.
2144 An element can be a file name, or a list of the form (PREFIX . FILE)
2145 where PREFIX is a name prefix and FILE is the file to look in.
2146 If the element is just a file name, the file name also serves as the prefix.")
2148 (defun Info-find-emacs-command-nodes (command)
2149 "Return a list of locations documenting COMMAND.
2150 The `info-file' property of COMMAND says which Info manual to search.
2151 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2152 defines heuristics for which Info manual to try.
2153 The locations are of the format used in Info-history, i.e.
2154 \(FILENAME NODENAME BUFFERPOS\)."
2156 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command
))
2157 ":\\s *\\(.*\\)\\.$"))
2158 (info-file "emacs")) ;default
2159 ;; Determine which info file this command is documented in.
2160 (if (get command
'info-file
)
2161 (setq info-file
(get command
'info-file
))
2162 ;; If it doesn't say explicitly, test its name against
2163 ;; various prefixes that we know.
2164 (let ((file-list Info-file-list-for-emacs
))
2166 (let* ((elt (car file-list
))
2167 (name (if (consp elt
)
2170 (file (if (consp elt
) (cdr elt
) elt
))
2171 (regexp (concat "\\`" (regexp-quote name
)
2173 (if (string-match regexp
(symbol-name command
))
2174 (setq info-file file file-list nil
))
2175 (setq file-list
(cdr file-list
))))))
2178 (Info-find-node info-file
"Command Index")
2179 ;; Some manuals may not have a separate Command Index node,
2180 ;; so try just Index instead.
2182 (Info-find-node info-file
"Index")))
2183 ;; Take the index node off the Info history.
2184 (setq Info-history
(cdr Info-history
))
2185 (goto-char (point-max))
2186 (while (re-search-backward cmd-desc nil t
)
2187 (setq where
(cons (list Info-current-file
2188 (match-string-no-properties 1)
2194 (defun Info-goto-emacs-command-node (command)
2195 "Go to the Info node in the Emacs manual for command COMMAND.
2196 The command is found by looking up in Emacs manual's Command Index
2197 or in another manual found via COMMAND's `info-file' property or
2198 the variable `Info-file-list-for-emacs'."
2199 (interactive "CFind documentation for command: ")
2200 (or (commandp command
)
2201 (signal 'wrong-type-argument
(list 'commandp command
)))
2202 (let ((where (Info-find-emacs-command-nodes command
)))
2204 (let ((num-matches (length where
)))
2205 ;; Get Info running, and pop to it in another window.
2206 (save-window-excursion
2208 ;; FIXME It would be cool if this could use a buffer other
2210 (pop-to-buffer "*info*")
2211 (Info-find-node (car (car where
))
2212 (car (cdr (car where
))))
2213 (if (> num-matches
1)
2215 ;; Info-find-node already pushed (car where) onto
2216 ;; Info-history. Put the other nodes that were found on
2218 (setq Info-history
(nconc (cdr where
) Info-history
))
2219 (message "Found %d other entr%s. Use %s to see %s."
2221 (if (> num-matches
2) "ies" "y")
2222 (substitute-command-keys "\\[Info-last]")
2223 (if (> num-matches
2) "them" "it")))))
2224 (error "Couldn't find documentation for %s" command
))))
2227 (defun Info-goto-emacs-key-command-node (key)
2228 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2229 Interactively, if the binding is execute-extended-command, a command is read.
2230 The command is found by looking up in Emacs manual's Command Index
2231 or in another manual found via COMMAND's `info-file' property or
2232 the variable `Info-file-list-for-emacs'."
2233 (interactive "kFind documentation for key:")
2234 (let ((command (key-binding key
)))
2235 (cond ((null command
)
2236 (message "%s is undefined" (key-description key
)))
2237 ((and (interactive-p)
2238 (eq command
'execute-extended-command
))
2239 (Info-goto-emacs-command-node
2240 (read-command "Find documentation for command: ")))
2242 (Info-goto-emacs-command-node command
)))))
2244 (defface Info-title-1-face
2245 '((t (:family
"helv" :height
240 :weight bold
)))
2246 "Face for Info titles at level 1."
2249 (defface Info-title-2-face
2250 '((t (:family
"helv" :height
180 :weight bold
)))
2251 "Face for Info titles at level 2."
2254 (defface Info-title-3-face
2255 '((t (:family
"helv" :height
160 :weight bold
)))
2256 "Face for Info titles at level 3."
2259 (defcustom Info-title-face-alist
2260 '((?
* (face (variable-pitch bold
) display
(height (+ 4))))
2261 (?
= (face (variable-pitch bold
) display
(height (+ 3))))
2262 (?-
(face (variable-pitch bold
) display
(height (+ 2)))))
2263 "*Alist of face or list of faces to use for pseudo-underlined titles.
2264 The alist key is the character the title is underlined with (?*, ?= or ?-)."
2265 :type
'(repeat (list character face face
))
2268 (defun Info-fontify-node ()
2270 (let ((buffer-read-only nil
)
2271 (case-fold-search t
))
2272 (goto-char (point-min))
2273 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2274 (goto-char (match-end 0))
2276 (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2277 (goto-char (match-end 0))
2279 (goto-char (match-beginning 1))
2280 (save-match-data (looking-at "Node:")))
2281 (put-text-property (match-beginning 2) (match-end 2)
2283 (put-text-property (match-beginning 2) (match-end 2)
2285 (put-text-property (match-beginning 2) (match-end 2)
2286 'mouse-face
'highlight
))))
2287 (goto-char (point-min))
2288 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2290 (let ((c (preceding-char))
2292 (cond ((= c ?
*) (setq face
'Info-title-1-face
))
2293 ((= c ?
=) (setq face
'Info-title-2-face
))
2294 (t (setq face
'Info-title-3-face
)))
2295 (put-text-property (match-beginning 1) (match-end 1)
2297 ;; This is a serious problem for trying to handle multiple
2298 ;; frame types at once. We want this text to be invisible
2299 ;; on frames that can display the font above.
2300 (if (memq (framep (selected-frame)) '(x pc w32
))
2301 (add-text-properties (match-end 1) (match-end 2)
2302 '(invisible t intangible t
))))
2303 (goto-char (point-min))
2304 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t
)
2305 (if (= (char-after (1- (match-beginning 0))) ?
\") ; hack
2307 (put-text-property (match-beginning 1) (match-end 1)
2309 (put-text-property (match-beginning 1) (match-end 1)
2310 'mouse-face
'highlight
)))
2311 (goto-char (point-min))
2312 (if (and (search-forward "\n* Menu:" nil t
)
2313 (not (string-match "\\<Index\\>" Info-current-node
))
2314 ;; Don't take time to annotate huge menus
2315 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
2317 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t
)
2319 (if (memq n
'(5 9)) ; visual aids to help with 1-9 keys
2320 (put-text-property (match-beginning 0)
2321 (1+ (match-beginning 0))
2322 'face
'info-menu-5
))
2323 (put-text-property (match-beginning 1) (match-end 1)
2325 (put-text-property (match-beginning 1) (match-end 1)
2326 'mouse-face
'highlight
))))
2327 (set-buffer-modified-p nil
))))
2330 ;; When an Info buffer is killed, make sure the associated tags buffer
2332 (defun Info-kill-buffer ()
2333 (and (eq major-mode
'Info-mode
)
2334 Info-tag-table-buffer
2335 (kill-buffer Info-tag-table-buffer
)))
2337 (add-hook 'kill-buffer-hook
'Info-kill-buffer
)
2339 ;;; Speedbar support:
2340 ;; These functions permit speedbar to display the "tags" in the
2341 ;; current info node.
2342 (eval-when-compile (require 'speedbar
))
2344 (defvar Info-speedbar-key-map nil
2345 "Keymap used when in the info display mode.")
2347 (defun Info-install-speedbar-variables ()
2348 "Install those variables used by speedbar to enhance Info."
2349 (if Info-speedbar-key-map
2351 (setq Info-speedbar-key-map
(speedbar-make-specialized-keymap))
2353 ;; Basic tree features
2354 (define-key Info-speedbar-key-map
"e" 'speedbar-edit-line
)
2355 (define-key Info-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
2356 (define-key Info-speedbar-key-map
"+" 'speedbar-expand-line
)
2357 (define-key Info-speedbar-key-map
"-" 'speedbar-contract-line
)
2360 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2361 Info-speedbar-key-map
2362 Info-speedbar-hierarchy-buttons
)))
2364 (defvar Info-speedbar-menu-items
2365 '(["Browse Node" speedbar-edit-line t
]
2366 ["Expand Node" speedbar-expand-line
2367 (save-excursion (beginning-of-line)
2368 (looking-at "[0-9]+: *.\\+. "))]
2369 ["Contract Node" speedbar-contract-line
2370 (save-excursion (beginning-of-line)
2371 (looking-at "[0-9]+: *.-. "))]
2373 "Additional menu-items to add to speedbar frame.")
2375 ;; Make sure our special speedbar major mode is loaded
2376 (if (featurep 'speedbar
)
2377 (Info-install-speedbar-variables)
2378 (add-hook 'speedbar-load-hook
'Info-install-speedbar-variables
))
2380 ;;; Info hierarchy display method
2382 (defun Info-speedbar-browser ()
2383 "Initialize speedbar to display an info node browser.
2384 This will add a speedbar major display mode."
2387 ;; Make sure that speedbar is active
2388 (speedbar-frame-mode 1)
2389 ;; Now, throw us into Info mode on speedbar.
2390 (speedbar-change-initial-expansion-list "Info")
2393 (defun Info-speedbar-hierarchy-buttons (directory depth
&optional node
)
2394 "Display an Info directory hierarchy in speedbar.
2395 DIRECTORY is the current directory in the attached frame.
2396 DEPTH is the current indentation depth.
2397 NODE is an optional argument that is used to represent the
2398 specific node to expand."
2400 (save-excursion (goto-char (point-min))
2401 (let ((case-fold-search t
))
2402 (looking-at "Info Nodes:"))))
2403 ;; Update our "current node" maybe?
2405 ;; We cannot use the generic list code, that depends on all leaves
2406 ;; being known at creation time.
2408 (speedbar-with-writable (insert "Info Nodes:\n")))
2409 (let ((completions nil
)
2410 (cf (selected-frame)))
2411 (select-frame speedbar-attached-frame
)
2412 (save-window-excursion
2414 (Info-speedbar-fetch-file-nodes (or node
'"(dir)top"))))
2417 (speedbar-with-writable
2419 (speedbar-make-tag-line 'bracket ?
+ 'Info-speedbar-expand-node
2420 (cdr (car completions
))
2421 (car (car completions
))
2422 'Info-speedbar-goto-node
2423 (cdr (car completions
))
2425 (setq completions
(cdr completions
)))
2429 (defun Info-speedbar-goto-node (text node indent
)
2430 "When user clicks on TEXT, goto an info NODE.
2431 The INDENT level is ignored."
2432 (select-frame speedbar-attached-frame
)
2433 (let* ((buff (or (get-buffer "*info*")
2434 (progn (info) (get-buffer "*info*"))))
2435 (bwin (get-buffer-window buff
0)))
2438 (select-window bwin
)
2439 (raise-frame (window-frame bwin
)))
2440 (if speedbar-power-click
2441 (let ((pop-up-frames t
)) (select-window (display-buffer buff
)))
2442 (select-frame speedbar-attached-frame
)
2443 (switch-to-buffer buff
)))
2444 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node
))
2445 (file (match-string 1 node
))
2446 (node (match-string 2 node
)))
2447 (Info-find-node file node
)
2448 ;; If we do a find-node, and we were in info mode, restore
2449 ;; the old default method. Once we are in info mode, it makes
2450 ;; sense to return to whatever method the user was using before.
2451 (if (string= speedbar-initial-expansion-list-name
"Info")
2452 (speedbar-change-initial-expansion-list
2453 speedbar-previously-used-expansion-list-name
)))))
2455 (defun Info-speedbar-expand-node (text token indent
)
2456 "Expand the node the user clicked on.
2457 TEXT is the text of the button we clicked on, a + or - item.
2458 TOKEN is data related to this node (NAME . FILE).
2459 INDENT is the current indentation depth."
2460 (cond ((string-match "+" text
) ;we have to expand this file
2461 (speedbar-change-expand-button-char ?-
)
2462 (if (speedbar-with-writable
2464 (end-of-line) (forward-char 1)
2465 (Info-speedbar-hierarchy-buttons nil
(1+ indent
) token
)))
2466 (speedbar-change-expand-button-char ?-
)
2467 (speedbar-change-expand-button-char ??
)))
2468 ((string-match "-" text
) ;we have to contract this node
2469 (speedbar-change-expand-button-char ?
+)
2470 (speedbar-delete-subblock indent
))
2471 (t (error "Ooops... not sure what to do")))
2472 (speedbar-center-buffer-smartly))
2474 (defun Info-speedbar-fetch-file-nodes (nodespec)
2475 "Fetch the subnodes from the info NODESPEC.
2476 NODESPEC is a string of the form: (file)node.
2477 Optional THISFILE represends the filename of"
2479 ;; Set up a buffer we can use to fake-out Info.
2480 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2481 (if (not (equal major-mode
'Info-mode
))
2483 ;; Get the node into this buffer
2484 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec
))
2485 (file (match-string 1 nodespec
))
2486 (node (match-string 2 nodespec
)))
2487 (Info-find-node file node
))
2488 ;; Scan the created buffer
2489 (goto-char (point-min))
2490 (let ((completions nil
)
2491 (case-fold-search t
)
2492 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec
)
2493 (match-string 1 nodespec
))))
2494 ;; Always skip the first one...
2495 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
2496 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
2497 (let ((name (match-string 1)))
2498 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2499 (setq name
(cons name
(match-string 1)))
2500 (if (looking-at " *\\(([^)]+)\\)\\.")
2501 (setq name
(cons name
(concat (match-string 1) "Top")))
2502 (if (looking-at " \\([^.]+\\).")
2504 (cons name
(concat "(" thisfile
")" (match-string 1))))
2505 (setq name
(cons name
(concat "(" thisfile
")" name
))))))
2506 (setq completions
(cons name completions
))))
2507 (nreverse completions
))))
2509 ;;; Info mode node listing
2510 (defun Info-speedbar-buttons (buffer)
2511 "Create a speedbar display to help navigation in an Info file.
2512 BUFFER is the buffer speedbar is requesting buttons for."
2513 (if (save-excursion (goto-char (point-min))
2514 (let ((case-fold-search t
))
2515 (not (looking-at "Info Nodes:"))))
2517 (Info-speedbar-hierarchy-buttons nil
0)
2520 (dolist (mess '("^Node has no Previous$"
2521 "^No menu in this node$"
2522 "^Node has no Next$"
2523 "^No cross-references in this node^"
2525 "^No \".*\" in index$"))
2526 (add-to-list 'debug-ignored-errors mess
))
2530 ;;; info.el ends here