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.
92 When `Info-directory-list' is initialized from the value of
93 `Info-default-directory-list', the first element of the resulting
94 list is the directory where Emacs installs the Info files that
95 come with it. This is so that Emacs's own manual, which suits the
96 version of Emacs you are using, will always be found first. (If
97 you want to override that, set INFOPATH in the environment.)
99 If you run the Emacs executable from the `src' directory in the Emacs
100 source tree, and INFOPATH is not defined, the `info' directory in the
101 source tree is used as the first element of `Info-directory-list', in
102 place of the installation Info directory. This is useful when you run
103 a version of Emacs without installing it.")
105 (defcustom Info-additional-directory-list nil
106 "List of additional directories to search for Info documentation files.
107 These directories are not searched for merging the `dir' file."
108 :type
'(repeat directory
)
111 (defvar Info-current-file nil
112 "Info file that Info is now looking at, or nil.
113 This is the name that was specified in Info, not the actual file name.
114 It doesn't contain directory names or file name extensions added by Info.
115 Can also be t when using `Info-on-current-buffer'.")
117 (defvar Info-current-subfile nil
118 "Info subfile that is actually in the *info* buffer now.
119 nil if current info file is not split into subfiles.")
121 (defvar Info-current-node nil
122 "Name of node that Info is now looking at, or nil.")
124 (defvar Info-tag-table-marker nil
125 "Marker pointing at beginning of current Info file's tag table.
126 Marker points nowhere if file has no tag table.")
128 (defvar Info-tag-table-buffer nil
129 "Buffer used for indirect tag tables.")
131 (defvar Info-current-file-completions nil
132 "Cached completion list for current Info file.")
134 (defvar Info-index-alternatives nil
135 "List of possible matches for last `Info-index' command.")
137 (defvar Info-standalone nil
138 "Non-nil if Emacs was started solely as an Info browser.")
140 (defvar Info-suffix-list
141 ;; The MS-DOS list should work both when long file names are
142 ;; supported (Windows 9X), and when only 8+3 file names are available.
143 (if (eq system-type
'ms-dos
)
144 '( (".gz" .
"gunzip")
146 (".bz2" .
"bzip2 -dc")
149 (".info.Z" .
"gunzip")
150 (".info.gz" .
"gunzip")
151 ("-info.Z" .
"gunzip")
152 ("-info.gz" .
"gunzip")
153 ("/index.gz".
"gunzip")
154 ("/index.z" .
"gunzip")
160 '( (".info.Z".
"uncompress")
161 (".info.Y".
"unyabba")
162 (".info.gz".
"gunzip")
163 (".info.z".
"gunzip")
164 (".info.bz2" .
"bzip2 -dc")
166 ("-info.Z".
"uncompress")
167 ("-info.Y".
"unyabba")
168 ("-info.gz".
"gunzip")
169 ("-info.bz2" .
"bzip2 -dc")
170 ("-info.z".
"gunzip")
172 ("/index.Z".
"uncompress")
173 ("/index.Y".
"unyabba")
174 ("/index.gz".
"gunzip")
175 ("/index.z".
"gunzip")
176 ("/index.bz2".
"bzip2 -dc")
182 (".bz2" .
"bzip2 -dc")
184 "List of file name suffixes and associated decoding commands.
185 Each entry should be (SUFFIX . STRING); the file is given to
186 the command as standard input. If STRING is nil, no decoding is done.
187 Because the SUFFIXes are tried in order, the empty string should
188 be last in the list.")
190 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
191 ;; First, on ms-dos, delete some of the extension in FILENAME
193 (defun info-insert-file-contents-1 (filename suffix
)
194 (if (not (eq system-type
'ms-dos
))
195 (concat filename suffix
)
196 (let* ((sans-exts (file-name-sans-extension filename
))
197 ;; How long is the extension in FILENAME (not counting the dot).
198 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
200 ;; SUFFIX starts with a dot. If FILENAME already has one,
201 ;; get rid of the one in SUFFIX (unless suffix is empty).
202 (or (and (<= ext-len
0)
203 (not (eq (aref filename
(1- (length filename
))) ?.
)))
204 (= (length suffix
) 0)
205 (setq suffix
(substring suffix
1)))
206 ;; How many chars of that extension should we keep?
207 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
208 ;; Get rid of the rest of the extension, and add SUFFIX.
209 (concat (substring filename
0 (- (length filename
)
210 (- ext-len ext-left
)))
213 (defun info-file-exists-p (filename)
214 (and (file-exists-p filename
)
215 (not (file-directory-p filename
))))
217 (defun info-insert-file-contents (filename &optional visit
)
218 "Insert the contents of an info file in the current buffer.
219 Do the right thing if the file has been compressed or zipped."
220 (let ((tail Info-suffix-list
)
222 (if (file-exists-p filename
)
223 ;; FILENAME exists--see if that name contains a suffix.
224 ;; If so, set DECODE accordingly.
228 (concat (regexp-quote (car (car tail
))) "$")
230 (setq tail
(cdr tail
)))
231 (setq fullname filename
232 decoder
(cdr (car tail
))))
233 ;; Try adding suffixes to FILENAME and see if we can find something.
235 (not (info-file-exists-p (info-insert-file-contents-1
236 filename
(car (car tail
))))))
237 (setq tail
(cdr tail
)))
238 ;; If we found a file with a suffix, set DECODER according to the suffix
239 ;; and set FULLNAME to the file's actual name.
240 (setq fullname
(info-insert-file-contents-1 filename
(car (car tail
)))
241 decoder
(cdr (car tail
)))
243 (error "Can't find %s or any compressed version of it" filename
)))
244 ;; check for conflict with jka-compr
245 (if (and (featurep 'jka-compr
)
246 (jka-compr-installed-p)
247 (jka-compr-get-compression-info fullname
))
251 (insert-file-contents-literally fullname visit
)
252 (let ((buffer-read-only nil
)
253 (coding-system-for-write 'no-conversion
)
254 (default-directory (or (file-name-directory fullname
)
256 (call-process-region (point-min) (point-max) decoder t t
)))
257 (insert-file-contents fullname visit
))))
259 (defun info-initialize ()
260 "Initialize `Info-directory-list', if that hasn't been done yet."
261 (unless Info-directory-list
262 (let ((path (getenv "INFOPATH"))
263 (source (expand-file-name "info/" source-directory
))
264 (sibling (if installation-directory
265 (expand-file-name "info/" installation-directory
)))
267 (setq Info-directory-list
268 (prune-directory-list
270 (split-string path
(regexp-quote path-separator
))
271 (if (and sibling
(file-exists-p sibling
))
272 ;; Uninstalled, Emacs builddir != srcdir.
273 (setq alternative sibling
)
274 ;; Uninstalled, builddir == srcdir
275 (setq alternative source
))
276 (if (or (member alternative Info-default-directory-list
)
277 ;; On DOS/NT, we use movable executables always,
278 ;; and we must always find the Info dir at run time.
279 (if (memq system-type
'(ms-dos windows-nt
))
281 ;; Use invocation-directory for Info
282 ;; only if we used it for exec-directory also.
283 (not (string= exec-directory
284 (expand-file-name "lib-src/"
285 installation-directory
))))
286 (not (file-exists-p alternative
)))
287 Info-default-directory-list
288 ;; `alternative' contains the Info files that came with this
289 ;; version, so we should look there first. `Info-insert-dir'
290 ;; currently expects to find `alternative' first on the list.
292 (reverse (cdr (reverse Info-default-directory-list
)))))))))))
295 (defun info-other-window (&optional file
)
296 "Like `info' but show the Info buffer in another window."
297 (interactive (if current-prefix-arg
298 (list (read-file-name "Info file name: " nil nil t
))))
299 (let (same-window-buffer-names)
302 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
305 (defun info (&optional file
)
306 "Enter Info, the documentation browser.
307 Optional argument FILE specifies the file to examine;
308 the default is the top-level directory of Info.
309 Called from a program, FILE may specify an Info node of the form
310 `(FILENAME)NODENAME'.
312 In interactive use, a prefix argument directs this command
313 to read a file name from the minibuffer.
315 The search path for Info files is in the variable `Info-directory-list'.
316 The top-level Info directory is made by combining all the files named `dir'
317 in all the directories in that path."
318 (interactive (if current-prefix-arg
319 (list (read-file-name "Info file name: " nil nil t
))))
322 (pop-to-buffer "*info*")
323 ;; If argument already contains parentheses, don't add another set
324 ;; since the argument will then be parsed improperly. This also
325 ;; has the added benefit of allowing node names to be included
326 ;; following the parenthesized filename.
327 (if (and (stringp file
) (string-match "(.*)" file
))
328 (Info-goto-node file
)
329 (Info-goto-node (concat "(" file
")"))))
330 (if (get-buffer "*info*")
331 (pop-to-buffer "*info*")
335 (defun info-standalone ()
336 "Run Emacs as a standalone Info reader.
337 Usage: emacs -f info-standalone [filename]
338 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
339 (setq Info-standalone t
)
340 (if (and command-line-args-left
341 (not (string-match "^-" (car command-line-args-left
))))
344 (info (car command-line-args-left
))
345 (setq command-line-args-left
(cdr command-line-args-left
)))
346 (error (send-string-to-terminal
347 (format "%s\n" (if (eq (car-safe err
) 'error
)
349 (save-buffers-kill-emacs)))
352 ;; See if the the accessible portion of the buffer begins with a node
353 ;; delimiter, and the node header line which follows matches REGEXP.
354 ;; Typically, this test will be followed by a loop that examines the
355 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
356 ;; to have the overhead of this special test inside the loop.
358 ;; This function changes match-data, but supposedly the caller might
359 ;; want to use the results of re-search-backward.
361 ;; The return value is the value of point at the beginning of matching
362 ;; REGERXP, if the function succeeds, nil otherwise.
363 (defun Info-node-at-bob-matching (regexp)
364 (and (bobp) ; are we at beginning of buffer?
365 (looking-at "\^_") ; does it begin with node delimiter?
369 (forward-line 1) ; does the line after delimiter match REGEXP?
370 (re-search-backward regexp beg t
))))
372 (defun Info-find-node (filename nodename
&optional no-going-back
)
373 "Go to an info node specified as separate FILENAME and NODENAME.
374 NO-GOING-BACK is non-nil if recovering from an error in this function;
375 it says do not attempt further (recursive) error recovery."
377 ;; Convert filename to lower case if not found as specified.
379 (if (stringp filename
)
380 (let (temp temp-downcase found
)
381 (setq filename
(substitute-in-file-name filename
))
382 (if (string= (downcase filename
) "dir")
384 (let ((dirs (if (string-match "^\\./" filename
)
385 ;; If specified name starts with `./'
386 ;; then just try current directory.
388 (if (file-name-absolute-p filename
)
389 ;; No point in searching for an
390 ;; absolute file name
392 (if Info-additional-directory-list
393 (append Info-directory-list
394 Info-additional-directory-list
)
395 Info-directory-list
)))))
396 ;; Search the directory list for file FILENAME.
397 (while (and dirs
(not found
))
398 (setq temp
(expand-file-name filename
(car dirs
)))
400 (expand-file-name (downcase filename
) (car dirs
)))
401 ;; Try several variants of specified name.
402 (let ((suffix-list Info-suffix-list
))
403 (while (and suffix-list
(not found
))
404 (cond ((info-file-exists-p
405 (info-insert-file-contents-1
406 temp
(car (car suffix-list
))))
409 (info-insert-file-contents-1
410 temp-downcase
(car (car suffix-list
))))
411 (setq found temp-downcase
)))
412 (setq suffix-list
(cdr suffix-list
))))
413 (setq dirs
(cdr dirs
)))))
415 (setq filename found
)
416 (error "Info file %s does not exist" filename
))))
417 ;; Record the node we are leaving.
418 (if (and Info-current-file
(not no-going-back
))
420 (cons (list Info-current-file Info-current-node
(point))
422 ;; Go into info buffer.
423 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
424 (Info-find-node-2 filename nodename no-going-back
))
426 (defun Info-on-current-buffer (&optional nodename
)
427 "Use the `Info-mode' to browse the current info buffer.
428 If a prefix arg is provided, it queries for the NODENAME which
429 else defaults to `Top'."
431 (list (if current-prefix-arg
432 (completing-read "Node name: " (Info-build-node-completions)
437 (set (make-local-variable 'Info-current-file
) t
)
438 (Info-find-node-2 nil nodename
))
440 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
441 "Find a node in a tag table.
442 MARKER specifies the buffer and position to start searching at.
443 REGEXP is a regular expression matching nodes or references. Its first
444 group should match `Node:' or `Ref:'.
445 CASE-FOLD t means search for a case-insensitive match.
446 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
447 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
448 where the match was found, and MODE is `major-mode' of the buffer in
449 which the match was found."
450 (let ((case-fold-search case-fold
)
451 found-mode guesspos found-anchor
)
453 (set-buffer (marker-buffer marker
))
458 (when (re-search-forward regexp nil t
)
459 (list (string-equal "Ref:" (match-string 1))
460 (1+ (read (current-buffer)))
463 (defun Info-find-in-tag-table (marker regexp
)
464 "Find a node in a tag table.
465 MARKER specifies the buffer and position to start searching at.
466 REGEXP is a regular expression matching nodes or references. Its first
467 group should match `Node:' or `Ref:'.
468 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
469 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
470 where the match was found, and MODE is `major-mode' of the buffer in
471 which the match was found.
472 This function tries to find a case-sensitive match first, then a
473 case-insensitive match is tried."
474 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
475 (when (null (car result
))
476 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
479 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
480 "Find a node or anchor in the current buffer.
481 REGEXP is a regular expression matching nodes or references. Its first
482 group should match `Node:' or `Ref:'.
483 CASE-FOLD t means search for a case-insensitive match.
484 Value is the position at which a match was found, or nil if not found."
485 (let ((case-fold-search case-fold
)
488 (when (Info-node-at-bob-matching regexp
)
489 (setq found
(point)))
490 (while (and (not found
)
491 (search-forward "\n\^_" nil t
))
495 (when (re-search-backward regexp beg t
)
497 (setq found
(point)))))
500 (defun Info-find-node-in-buffer (regexp)
501 "Find a node or anchor in the current buffer.
502 REGEXP is a regular expression matching nodes or references. Its first
503 group should match `Node:' or `Ref:'.
504 Value is the position at which a match was found, or nil if not found.
505 This function looks for a case-sensitive match first. If none is found,
506 a case-insensitive match is tried."
507 (or (Info-find-node-in-buffer-1 regexp nil
)
508 (Info-find-node-in-buffer-1 regexp t
)))
510 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
511 (buffer-disable-undo (current-buffer))
512 (or (eq major-mode
'Info-mode
)
515 (setq Info-current-node nil
)
517 (let ((case-fold-search t
)
519 ;; Switch files if necessary
521 (equal Info-current-file filename
)
522 (let ((buffer-read-only nil
))
523 (setq Info-current-file nil
524 Info-current-subfile nil
525 Info-current-file-completions nil
526 buffer-file-name nil
)
530 (info-insert-file-contents filename t
)
531 (setq default-directory
(file-name-directory filename
)))
532 (set-buffer-modified-p nil
)
533 ;; See whether file has a tag table. Record the location if yes.
534 (goto-char (point-max))
536 ;; Use string-equal, not equal, to ignore text props.
537 (if (not (or (string-equal nodename
"*")
539 (search-forward "\^_\nEnd tag table\n" nil t
))))
541 ;; We have a tag table. Find its beginning.
542 ;; Is this an indirect file?
543 (search-backward "\nTag table:\n")
547 (looking-at "(Indirect)\n"))
548 ;; It is indirect. Copy it to another buffer
549 ;; and record that the tag table is in that buffer.
550 (let ((buf (current-buffer))
552 (or Info-tag-table-buffer
553 (generate-new-buffer " *info tag table*"))))
554 (setq Info-tag-table-buffer tagbuf
)
557 (buffer-disable-undo (current-buffer))
558 (setq case-fold-search t
)
560 (insert-buffer-substring buf
))
561 (set-marker Info-tag-table-marker
562 (match-end 0) tagbuf
))
563 (set-marker Info-tag-table-marker pos
)))
564 (set-marker Info-tag-table-marker nil
))
565 (setq Info-current-file
566 (if (eq filename t
) "dir" filename
))))
567 ;; Use string-equal, not equal, to ignore text props.
568 (if (string-equal nodename
"*")
569 (progn (setq Info-current-node nodename
)
570 (Info-set-mode-line))
573 ;; 1. Anchor found in tag table
574 ;; 2. Anchor *not* in tag table
576 ;; 3. Node found in tag table
577 ;; 4. Node *not* found in tag table, but found in file
578 ;; 5. Node *not* in tag table, and *not* in file
580 ;; *Or* the same, but in an indirect subfile.
582 ;; Search file for a suitable node.
583 (let ((guesspos (point-min))
584 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
585 (if (stringp nodename
)
586 (regexp-quote nodename
)
593 ;; First, search a tag table, if any
594 (when (marker-position Info-tag-table-marker
)
595 (let* ((m Info-tag-table-marker
)
596 (found (Info-find-in-tag-table m regexp
)))
599 ;; FOUND is (ANCHOR POS MODE).
600 (setq guesspos
(nth 1 found
))
602 ;; If this is an indirect file, determine which
603 ;; file really holds this node and read it in.
604 (unless (eq (nth 2 found
) 'Info-mode
)
605 ;; Note that the current buffer must be the
606 ;; *info* buffer on entry to
607 ;; Info-read-subfile. Thus the hackery above.
608 (setq guesspos
(Info-read-subfile guesspos
)))
612 (goto-char (setq anchorpos guesspos
))
615 ;; Else we may have a node, which we search for:
616 (goto-char (max (point-min)
617 (- (byte-to-position guesspos
) 1000)))
619 ;; Now search from our advised position (or from beg of
620 ;; buffer) to find the actual node. First, check
621 ;; whether the node is right where we are, in case the
622 ;; buffer begins with a node.
623 (let ((pos (Info-find-node-in-buffer regexp
)))
627 (error "No such anchor in tag table or node in tag table or file: %s"
631 (goto-char (or anchorpos
(point-min))))))
632 ;; If we did not finish finding the specified node,
633 ;; go back to the previous one.
634 (or Info-current-node no-going-back
(null Info-history
)
635 (let ((hist (car Info-history
)))
636 (setq Info-history
(cdr Info-history
))
637 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
638 (goto-char (nth 2 hist
))))))
640 ;; Cache the contents of the (virtual) dir file, once we have merged
641 ;; it for the first time, so we can save time subsequently.
642 (defvar Info-dir-contents nil
)
644 ;; Cache for the directory we decided to use for the default-directory
645 ;; of the merged dir text.
646 (defvar Info-dir-contents-directory nil
)
648 ;; Record the file attributes of all the files from which we
649 ;; constructed Info-dir-contents.
650 (defvar Info-dir-file-attributes nil
)
652 (defvar Info-dir-file-name nil
)
654 ;; Construct the Info directory node by merging the files named `dir'
655 ;; from various directories. Set the *info* buffer's
656 ;; default-directory to the first directory we actually get any text
658 (defun Info-insert-dir ()
659 (if (and Info-dir-contents Info-dir-file-attributes
660 ;; Verify that none of the files we used has changed
663 (mapcar (lambda (elt)
664 (let ((curr (file-attributes
666 (file-truename (car elt
)))))
668 ;; Don't compare the access time.
669 (if curr
(setcar (nthcdr 4 curr
) 0))
670 (setcar (nthcdr 4 (cdr elt
)) 0)
671 (equal (cdr elt
) curr
)))
672 Info-dir-file-attributes
))))
674 (insert Info-dir-contents
)
675 (goto-char (point-min)))
676 (let ((dirs (if Info-additional-directory-list
677 (append Info-directory-list
678 Info-additional-directory-list
)
679 Info-directory-list
))
680 ;; Bind this in case the user sets it to nil.
682 ;; This is set non-nil if we find a problem in some input files.
684 buffers buffer others nodes dirs-done
)
686 (setq Info-dir-file-attributes nil
)
688 ;; Search the directory list for the directory file.
690 (let ((truename (file-truename (expand-file-name (car dirs
)))))
691 (or (member truename dirs-done
)
692 (member (directory-file-name truename
) dirs-done
)
693 ;; Try several variants of specified name.
694 ;; Try upcasing, appending `.info', or both.
698 (progn (setq file
(expand-file-name "dir" truename
))
699 (file-attributes file
))
700 (progn (setq file
(expand-file-name "DIR" truename
))
701 (file-attributes file
))
702 (progn (setq file
(expand-file-name "dir.info" truename
))
703 (file-attributes file
))
704 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
705 (file-attributes file
)))))
708 (cons (directory-file-name truename
)
713 (message "Composing main Info directory..."))
714 (set-buffer (generate-new-buffer " info dir"))
717 (insert-file-contents file
)
718 (make-local-variable 'Info-dir-file-name
)
719 (setq Info-dir-file-name file
)
720 (setq buffers
(cons (current-buffer) buffers
)
721 Info-dir-file-attributes
722 (cons (cons file attrs
)
723 Info-dir-file-attributes
)))
724 (error (kill-buffer (current-buffer))))))))
725 (or (cdr dirs
) (setq Info-dir-contents-directory
726 (file-name-as-directory (car dirs
))))
727 (setq dirs
(cdr dirs
))))
730 (error "Can't find the Info directory node"))
731 ;; Distinguish the dir file that comes with Emacs from all the
732 ;; others. Yes, that is really what this is supposed to do.
733 ;; The definition of `Info-directory-list' puts it first on that
734 ;; list and so last in `buffers' at this point.
735 (setq buffer
(car (last buffers
))
736 others
(delq buffer buffers
))
738 ;; Insert the entire original dir file as a start; note that we've
739 ;; already saved its default directory to use as the default
740 ;; directory for the whole concatenation.
741 (insert-buffer buffer
)
743 ;; Look at each of the other buffers one by one.
745 (let ((other (car others
))
746 ;; Bind this in case the user sets it to nil.
749 ;; In each, find all the menus.
752 (goto-char (point-min))
753 ;; Find each menu, and add an elt to NODES for it.
754 (while (re-search-forward "^\\* Menu:" nil t
)
755 (let (beg nodename end
)
758 (or (search-backward "\n\^_" nil
'move
)
760 (signal 'search-failed
(list "\n\^_")))
761 (search-forward "Node: ")
762 (setq nodename
(Info-following-node-name))
763 (search-forward "\n\^_" nil
'move
)
766 (setq this-buffer-nodes
767 (cons (list nodename other beg end
)
768 this-buffer-nodes
))))
769 (if (assoc-ignore-case "top" this-buffer-nodes
)
770 (setq nodes
(nconc this-buffer-nodes nodes
))
772 (message "No `top' node in %s" Info-dir-file-name
))))
773 (setq others
(cdr others
)))
774 ;; Add to the main menu a menu item for each other node.
775 (let ((case-fold-search t
)
776 (re-search-forward "^\\* Menu:")))
778 (let ((menu-items '("top"))
781 (end (save-excursion (search-forward "\^_" nil t
) (point))))
783 (let ((nodename (car (car nodes
))))
785 (or (member (downcase nodename
) menu-items
)
786 (re-search-forward (concat "^\\* +"
787 (regexp-quote nodename
)
791 (insert "* " nodename
"::" "\n")
792 (setq menu-items
(cons nodename menu-items
))))))
793 (setq nodes
(cdr nodes
))))
794 ;; Now take each node of each of the other buffers
795 ;; and merge it into the main buffer.
797 (let ((case-fold-search t
)
798 (nodename (car (car nodes
))))
799 (goto-char (point-min))
800 ;; Find the like-named node in the main buffer.
801 (if (re-search-forward (concat "^\^_.*\n.*Node: "
802 (regexp-quote nodename
)
806 (search-forward "\n\^_" nil
'move
)
809 ;; If none exists, add one.
810 (goto-char (point-max))
811 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
812 ;; Merge the text from the other buffer's menu
813 ;; into the menu in the like-named node in the main buffer.
814 (apply 'insert-buffer-substring
(cdr (car nodes
))))
815 (setq nodes
(cdr nodes
)))
816 ;; Kill all the buffers we just made.
818 (kill-buffer (car buffers
))
819 (setq buffers
(cdr buffers
)))
820 (goto-char (point-min))
822 (message "Composing main Info directory...problems encountered, see `*Messages*'")
823 (message "Composing main Info directory...done")))
824 (setq Info-dir-contents
(buffer-string)))
825 (setq default-directory Info-dir-contents-directory
))
827 ;; Note that on entry to this function the current-buffer must be the
828 ;; *info* buffer; not the info tags buffer.
829 (defun Info-read-subfile (nodepos)
830 ;; NODEPOS is either a position (in the Info file as a whole,
831 ;; not relative to a subfile) or the name of a subfile.
834 (if (numberp nodepos
)
836 (set-buffer (marker-buffer Info-tag-table-marker
))
837 (goto-char (point-min))
838 (or (looking-at "\^_")
839 (search-forward "\n\^_"))
842 (while (not (looking-at "\^_"))
845 thisfilepos thisfilename
)
846 (search-forward ": ")
847 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
848 (setq thisfilepos
(read (current-buffer)))
849 ;; read in version 19 stops at the end of number.
850 ;; Advance to the next line.
852 (if (> thisfilepos nodepos
)
854 (setq lastfilename thisfilename
)
855 (setq lastfilepos thisfilepos
))
857 (setq lastfilename nodepos
)
858 (setq lastfilepos
0))
859 ;; Assume previous buffer is in Info-mode.
860 ;; (set-buffer (get-buffer "*info*"))
861 (or (equal Info-current-subfile lastfilename
)
862 (let ((buffer-read-only nil
))
863 (setq buffer-file-name nil
)
866 (info-insert-file-contents lastfilename
)
867 (set-buffer-modified-p nil
)
868 (setq Info-current-subfile lastfilename
)))
869 (goto-char (point-min))
870 (if (looking-at "\^_")
872 (search-forward "\n\^_"))
873 (if (numberp nodepos
)
874 (+ (- nodepos lastfilepos
) (point)))))
876 (defun Info-select-node ()
877 "Select the info node that point is in.
878 Bind this in case the user sets it to nil."
879 (let ((case-fold-search t
))
881 ;; Find beginning of node.
882 (if (search-backward "\n\^_" nil
'move
)
884 (if (looking-at "\^_")
886 (signal 'search-failed
(list "\n\^_"))))
887 ;; Get nodename spelled as it is in the node.
888 (re-search-forward "Node:[ \t]*")
889 (setq Info-current-node
890 (buffer-substring-no-properties (point)
892 (skip-chars-forward "^,\t\n")
895 ;; Find the end of it, and narrow.
897 (let (active-expression)
898 (narrow-to-region (point)
899 (if (re-search-forward "\n[\^_\f]" nil t
)
902 (if (looking-at "[\n\^_\f]*execute: ")
904 (goto-char (match-end 0))
905 (setq active-expression
906 (read (current-buffer))))))
908 (if Info-enable-active-nodes
(eval active-expression
))
909 (if Info-fontify
(Info-fontify-node))
910 (run-hooks 'Info-selection-hook
)))))
912 (defun Info-set-mode-line ()
913 (setq mode-line-buffer-identification
916 (file-name-nondirectory (if (stringp Info-current-file
)
918 (or buffer-file-name
"")))
920 (or Info-current-node
""))))
922 ;; Go to an info node specified with a filename-and-nodename string
923 ;; of the sort that is found in pointers in nodes.
925 (defun Info-goto-node (nodename &optional fork
)
926 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
927 If FORK is non-nil, show the node in a new info buffer.
928 If FORK is a string, it is the name to use for the new buffer."
929 (interactive (list (Info-read-node-name "Goto node: ") current-prefix-arg
))
933 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
935 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
937 (setq filename
(if (= (match-beginning 1) (match-end 1))
939 (substring nodename
(match-beginning 2) (match-end 2)))
940 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
941 (let ((trim (string-match "\\s *\\'" filename
)))
942 (if trim
(setq filename
(substring filename
0 trim
))))
943 (let ((trim (string-match "\\s *\\'" nodename
)))
944 (if trim
(setq nodename
(substring nodename
0 trim
))))
945 (if transient-mark-mode
(deactivate-mark))
946 (Info-find-node (if (equal filename
"") nil filename
)
947 (if (equal nodename
"") "Top" nodename
))))
949 (defvar Info-read-node-completion-table
)
951 ;; This function is used as the "completion table" while reading a node name.
952 ;; It does completion using the alist in Info-read-node-completion-table
953 ;; unless STRING starts with an open-paren.
954 (defun Info-read-node-name-1 (string predicate code
)
955 (let ((no-completion (and (> (length string
) 0) (eq (aref string
0) ?\
())))
959 (try-completion string Info-read-node-completion-table predicate
)))
963 (all-completions string Info-read-node-completion-table predicate
)))
967 (assoc string Info-read-node-completion-table
))))))
969 (defun Info-read-node-name (prompt &optional default
)
970 (let* ((completion-ignore-case t
)
971 (Info-read-node-completion-table (Info-build-node-completions))
972 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
973 (if (equal nodename
"")
975 (Info-read-node-name prompt
))
978 (defun Info-build-node-completions ()
979 (or Info-current-file-completions
981 ;; Bind this in case the user sets it to nil.
983 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
986 (if (marker-buffer Info-tag-table-marker
)
987 (let ((marker Info-tag-table-marker
))
988 (set-buffer (marker-buffer marker
))
991 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
993 (cons (list (match-string-no-properties 2))
996 (goto-char (point-min))
997 ;; If the buffer begins with a node header, process that first.
998 (if (Info-node-at-bob-matching node-regexp
)
999 (setq compl
(list (match-string-no-properties 1))))
1000 ;; Now for the rest of the nodes.
1001 (while (search-forward "\n\^_" nil t
)
1003 (let ((beg (point)))
1005 (if (re-search-backward node-regexp beg t
)
1007 (cons (list (match-string-no-properties 1))
1009 (setq compl
(cons '("*") compl
))
1010 (setq Info-current-file-completions compl
))))
1012 (defun Info-restore-point (hl)
1013 "If this node has been visited, restore the point value when we left."
1015 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1016 ;; Use string-equal, not equal, to ignore text props.
1017 (string-equal (nth 1 (car hl
)) Info-current-node
))
1019 (goto-char (nth 2 (car hl
)))
1020 (setq hl nil
)) ;terminate the while at next iter
1021 (setq hl
(cdr hl
)))))
1023 (defvar Info-search-history nil
1024 "The history list for `Info-search'.")
1026 (defun Info-search (regexp)
1027 "Search for REGEXP, starting from point, and select node it's found in."
1028 (interactive (list (read-string "Regexp search: "
1029 nil
'Info-search-history
)))
1030 (when transient-mark-mode
1032 (when (equal regexp
"")
1033 (setq regexp
(car Info-search-history
)))
1035 (let ((found ()) current
1036 (onode Info-current-node
)
1037 (ofile Info-current-file
)
1039 (ostart (window-start))
1040 (osubfile Info-current-subfile
))
1044 (if (null Info-current-subfile
)
1045 (progn (re-search-forward regexp
) (setq found
(point)))
1047 (progn (re-search-forward regexp
) (setq found
(point)))
1048 (search-failed nil
)))))
1049 (if (not found
) ;can only happen in subfile case -- else would have erred
1053 (set-buffer (marker-buffer Info-tag-table-marker
))
1054 (goto-char (point-min))
1055 (search-forward "\n\^_\nIndirect:")
1057 (narrow-to-region (point)
1058 (progn (search-forward "\n\^_")
1060 (goto-char (point-min))
1061 (search-forward (concat "\n" osubfile
": "))
1064 (re-search-forward "\\(^.*\\): [0-9]+$")
1065 (goto-char (+ (match-end 1) 2))
1066 (setq list
(cons (cons (read (current-buffer))
1067 (match-string-no-properties 1))
1069 (goto-char (1+ (match-end 0))))
1070 (setq list
(nreverse list
)
1071 current
(car (car list
))
1074 (message "Searching subfile %s..." (cdr (car list
)))
1075 (Info-read-subfile (car (car list
)))
1076 (setq list
(cdr list
))
1077 ;;; (goto-char (point-min))
1078 (if (re-search-forward regexp nil t
)
1079 (setq found
(point) list
())))
1082 (signal 'search-failed
(list regexp
))))
1084 (progn (Info-read-subfile osubfile
)
1087 (set-window-start (selected-window) ostart
)))))
1091 ;; Use string-equal, not equal, to ignore text props.
1092 (or (and (string-equal onode Info-current-node
)
1093 (equal ofile Info-current-file
))
1094 (setq Info-history
(cons (list ofile onode opoint
)
1097 (defun Info-extract-pointer (name &optional errorname
)
1098 "Extract the value of the node-pointer named NAME.
1099 If there is none, use ERRORNAME in the error message;
1100 if ERRORNAME is nil, just return nil.
1101 Bind this in case the user sets it to nil."
1102 (let ((case-fold-search t
))
1104 (goto-char (point-min))
1106 (if (re-search-backward (concat name
":") nil t
)
1108 (goto-char (match-end 0))
1109 (Info-following-node-name))
1110 (if (eq errorname t
)
1112 (error "Node has no %s" (capitalize (or errorname name
))))))))
1114 (defun Info-following-node-name (&optional allowedchars
)
1115 "Return the node name in the buffer following point.
1116 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1117 saying which chars may appear in the node name."
1118 (skip-chars-forward " \t")
1119 (buffer-substring-no-properties
1122 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
1123 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
1124 (if (looking-at "(")
1125 (skip-chars-forward "^)")))
1126 (skip-chars-backward " ")
1130 "Go to the next node of this node."
1132 (Info-goto-node (Info-extract-pointer "next")))
1135 "Go to the previous node of this node."
1137 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1139 (defun Info-up (&optional same-file
)
1140 "Go to the superior node of this node.
1141 If SAME-FILE is non-nil, do not move to a different Info file."
1143 (let ((node (Info-extract-pointer "up")))
1144 (and (or same-file
(not (stringp Info-current-file
)))
1145 (string-match "^(" node
)
1146 (error "Up node is in another Info file"))
1147 (Info-goto-node node
))
1148 (Info-restore-point Info-history
))
1151 "Go back to the last node visited."
1154 (error "This is the first Info node you looked at"))
1155 (let (filename nodename opoint
)
1156 (setq filename
(car (car Info-history
)))
1157 (setq nodename
(car (cdr (car Info-history
))))
1158 (setq opoint
(car (cdr (cdr (car Info-history
)))))
1159 (setq Info-history
(cdr Info-history
))
1160 (Info-find-node filename nodename
)
1161 (setq Info-history
(cdr Info-history
))
1162 (goto-char opoint
)))
1165 (defun Info-directory ()
1166 "Go to the Info directory node."
1168 (Info-find-node "dir" "top"))
1170 (defun Info-follow-reference (footnotename)
1171 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1172 FOOTNOTENAME may be an abbreviation of the reference name."
1174 (let ((completion-ignore-case t
)
1175 (case-fold-search t
)
1176 completions default alt-default
(start-point (point)) str i bol eol
)
1178 ;; Store end and beginning of line.
1184 (goto-char (point-min))
1185 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
1186 (setq str
(buffer-substring-no-properties
1189 ;; See if this one should be the default.
1191 (<= (match-beginning 0) start-point
)
1192 (<= start-point
(point))
1194 ;; See if this one should be the alternate default.
1195 (and (null alt-default
)
1196 (and (<= bol
(match-beginning 0))
1198 (setq alt-default t
))
1200 (while (setq i
(string-match "[ \n\t]+" str i
))
1201 (setq str
(concat (substring str
0 i
) " "
1202 (substring str
(match-end 0))))
1204 ;; Record as a completion and perhaps as default.
1205 (if (eq default t
) (setq default str
))
1206 (if (eq alt-default t
) (setq alt-default str
))
1207 ;; Don't add this string if it's a duplicate.
1208 ;; We use a loop instead of "(assoc str completions)" because
1209 ;; we want to do a case-insensitive compare.
1210 (let ((tail completions
)
1211 (tem (downcase str
)))
1213 (not (string-equal tem
(downcase (car (car tail
))))))
1214 (setq tail
(cdr tail
)))
1217 (cons (cons str nil
)
1219 ;; If no good default was found, try an alternate.
1221 (setq default alt-default
))
1222 ;; If only one cross-reference found, then make it default.
1223 (if (eq (length completions
) 1)
1224 (setq default
(car (car completions
))))
1226 (let ((input (completing-read (if default
1227 (concat "Follow reference named: ("
1229 "Follow reference named: ")
1230 completions nil t
)))
1231 (list (if (equal input
"")
1233 (error "No cross-references in this node"))))
1235 (unless footnotename
1236 (error "No reference was specified"))
1238 (let (target beg i
(str (concat "\\*note " (regexp-quote footnotename
)))
1239 (case-fold-search t
))
1240 (while (setq i
(string-match " " str i
))
1241 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
1244 (goto-char (point-min))
1245 (or (re-search-forward str nil t
)
1246 (error "No cross-reference named %s" footnotename
))
1247 (goto-char (+ (match-beginning 0) 5))
1249 (Info-extract-menu-node-name "Bad format cross reference" t
)))
1250 (while (setq i
(string-match "[ \t\n]+" target i
))
1251 (setq target
(concat (substring target
0 i
) " "
1252 (substring target
(match-end 0))))
1254 (Info-goto-node target
)))
1256 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
1257 (skip-chars-forward " \t\n")
1260 (skip-chars-forward "^:")
1263 (if (looking-at ":")
1264 (buffer-substring-no-properties beg
(1- (point)))
1265 (skip-chars-forward " \t\n")
1266 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
1267 (while (setq i
(string-match "\n" str i
))
1269 ;; Collapse multiple spaces.
1270 (while (string-match " +" str
)
1271 (setq str
(replace-match " " t t str
)))
1274 ;; No one calls this.
1275 ;;(defun Info-menu-item-sequence (list)
1277 ;; (Info-menu (car list))
1278 ;; (setq list (cdr list))))
1280 (defvar Info-complete-menu-buffer
)
1282 (defun Info-complete-menu-item (string predicate action
)
1283 (let ((completion-ignore-case t
)
1284 (case-fold-search t
))
1285 (cond ((eq action nil
)
1287 (pattern (concat "\n\\* +\\("
1288 (regexp-quote string
)
1291 (set-buffer Info-complete-menu-buffer
)
1292 (goto-char (point-min))
1293 (search-forward "\n* Menu:")
1294 (while (re-search-forward pattern nil t
)
1296 (cons (cons (match-string-no-properties 1)
1297 (match-beginning 1))
1299 (try-completion string completions predicate
)))
1302 (pattern (concat "\n\\* +\\("
1303 (regexp-quote string
)
1306 (set-buffer Info-complete-menu-buffer
)
1307 (goto-char (point-min))
1308 (search-forward "\n* Menu:")
1309 (while (re-search-forward pattern nil t
)
1310 (setq completions
(cons (cons
1311 (match-string-no-properties 1)
1312 (match-beginning 1))
1314 (all-completions string completions predicate
)))
1317 (set-buffer Info-complete-menu-buffer
)
1318 (goto-char (point-min))
1319 (search-forward "\n* Menu:")
1320 (re-search-forward (concat "\n\\* +"
1321 (regexp-quote string
)
1326 (defun Info-menu (menu-item &optional fork
)
1327 "Go to node for menu item named (or abbreviated) NAME.
1328 Completion is allowed, and the menu item point is on is the default."
1330 (let ((completions '())
1331 ;; If point is within a menu item, use that item as the default
1336 (case-fold-search t
))
1338 (goto-char (point-min))
1339 (if (not (search-forward "\n* menu:" nil t
))
1340 (error "No menu in this node"))
1346 (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t
)
1347 (setq default
(match-string-no-properties 1))))))
1350 (setq item
(let ((completion-ignore-case t
)
1351 (Info-complete-menu-buffer (current-buffer)))
1352 (completing-read (if default
1353 (format "Menu item (default %s): "
1356 'Info-complete-menu-item nil t
)))
1357 ;; we rely on the fact that completing-read accepts an input
1358 ;; of "" even when the require-match argument is true and ""
1359 ;; is not a valid possibility
1360 (if (string= item
"")
1365 (list item current-prefix-arg
))))
1366 ;; there is a problem here in that if several menu items have the same
1367 ;; name you can only go to the node of the first with this command.
1368 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
1370 (defun Info-extract-menu-item (menu-item)
1371 (setq menu-item
(regexp-quote menu-item
))
1372 (let ((case-fold-search t
))
1374 (let ((case-fold-search t
))
1375 (goto-char (point-min))
1376 (or (search-forward "\n* menu:" nil t
)
1377 (error "No menu in this node"))
1378 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
1379 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
1380 (error "No such item in menu"))
1383 (Info-extract-menu-node-name)))))
1385 ;; If COUNT is nil, use the last item in the menu.
1386 (defun Info-extract-menu-counting (count)
1387 (let ((case-fold-search t
))
1389 (let ((case-fold-search t
))
1390 (goto-char (point-min))
1391 (or (search-forward "\n* menu:" nil t
)
1392 (error "No menu in this node"))
1394 (or (search-forward "\n* " nil t count
)
1395 (error "Too few items in menu"))
1396 (while (search-forward "\n* " nil t
)
1398 (Info-extract-menu-node-name)))))
1400 (defun Info-nth-menu-item ()
1401 "Go to the node of the Nth menu item.
1402 N is the digit argument used to invoke this command."
1405 (Info-extract-menu-counting
1406 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
1408 (defun Info-top-node ()
1409 "Go to the Top node of this file."
1411 (Info-goto-node "Top"))
1413 (defun Info-final-node ()
1414 "Go to the final node in this file."
1416 (Info-goto-node "Top")
1417 (let ((Info-history nil
)
1418 (case-fold-search t
))
1419 ;; Go to the last node in the menu of Top.
1420 (Info-goto-node (Info-extract-menu-counting nil
))
1421 ;; If the last node in the menu is not last in pointer structure,
1422 ;; move forward until we can't go any farther.
1423 (while (Info-forward-node t t
) nil
)
1424 ;; Then keep moving down to last subnode, unless we reach an index.
1425 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1426 (save-excursion (search-forward "\n* Menu:" nil t
)))
1427 (Info-goto-node (Info-extract-menu-counting nil
)))))
1429 (defun Info-forward-node (&optional not-down no-error
)
1430 "Go forward one node, considering all nodes as forming one sequence."
1432 (goto-char (point-min))
1434 (let ((case-fold-search t
))
1435 ;; three possibilities, in order of priority:
1436 ;; 1. next node is in a menu in this node (but not in an index)
1437 ;; 2. next node is next at same level
1438 ;; 3. next node is up and next
1439 (cond ((and (not not-down
)
1440 (save-excursion (search-forward "\n* menu:" nil t
))
1441 (not (string-match "\\<index\\>" Info-current-node
)))
1442 (Info-goto-node (Info-extract-menu-counting 1))
1444 ((save-excursion (search-backward "next:" nil t
))
1447 ((and (save-excursion (search-backward "up:" nil t
))
1448 ;; Use string-equal, not equal, to ignore text props.
1449 (not (string-equal (downcase (Info-extract-pointer "up"))
1451 (let ((old-node Info-current-node
))
1453 (let (Info-history success
)
1455 (setq success
(Info-forward-node t no-error
))
1456 (or success
(Info-goto-node old-node
))))))
1458 (t (error "No pointer forward from this node")))))
1460 (defun Info-backward-node ()
1461 "Go backward one node, considering all nodes as forming one sequence."
1463 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1464 (upnode (Info-extract-pointer "up" t
))
1465 (case-fold-search t
))
1466 (cond ((and upnode
(string-match "(" upnode
))
1467 (error "First node in file"))
1468 ((and upnode
(or (null prevnode
)
1469 ;; Use string-equal, not equal,
1470 ;; to ignore text properties.
1471 (string-equal (downcase prevnode
)
1472 (downcase upnode
))))
1475 ;; If we move back at the same level,
1476 ;; go down to find the last subnode*.
1479 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1480 (save-excursion (search-forward "\n* Menu:" nil t
)))
1481 (Info-goto-node (Info-extract-menu-counting nil
)))))
1483 (error "No pointer backward from this node")))))
1486 "Exit Info by selecting some other buffer."
1489 (save-buffers-kill-emacs)
1492 (defun Info-next-menu-item ()
1494 ;; Bind this in case the user sets it to nil.
1495 (let* ((case-fold-search t
)
1499 (search-forward "\n* menu:" nil t
)
1500 (and (search-forward "\n* " nil t
)
1501 (Info-extract-menu-node-name)))))
1502 (if node
(Info-goto-node node
)
1503 (error "No more items in menu"))))
1505 (defun Info-last-menu-item ()
1509 ;; Bind this in case the user sets it to nil.
1510 (let* ((case-fold-search t
)
1511 (beg (save-excursion
1512 (and (search-backward "\n* menu:" nil t
)
1514 (or (and beg
(search-backward "\n* " beg t
))
1515 (error "No previous items in menu")))
1516 (Info-goto-node (save-excursion
1517 (goto-char (match-end 0))
1518 (Info-extract-menu-node-name)))))
1520 (defmacro Info-no-error
(&rest body
)
1521 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1523 (defun Info-next-preorder ()
1524 "Go to the next subnode or the next node, or go up a level."
1526 (cond ((Info-no-error (Info-next-menu-item)))
1527 ((Info-no-error (Info-next)))
1528 ((Info-no-error (Info-up t
))
1529 ;; Since we have already gone thru all the items in this menu,
1530 ;; go up to the end of this node.
1531 (goto-char (point-max))
1532 ;; Since logically we are done with the node with that menu,
1534 (Info-next-preorder))
1536 (error "No more nodes"))))
1538 (defun Info-last-preorder ()
1539 "Go to the last node, popping up a level if there is none."
1541 (cond ((Info-no-error
1542 (Info-last-menu-item)
1543 ;; If we go down a menu item, go to the end of the node
1544 ;; so we can scroll back through it.
1545 (goto-char (point-max)))
1546 ;; Keep going down, as long as there are nested menu nodes.
1547 (while (Info-no-error
1548 (Info-last-menu-item)
1549 ;; If we go down a menu item, go to the end of the node
1550 ;; so we can scroll back through it.
1551 (goto-char (point-max))))
1553 ((and (not (equal (Info-extract-pointer "up")
1554 (Info-extract-pointer "prev"))))
1555 (Info-no-error (Info-prev))
1556 (goto-char (point-max))
1557 (while (Info-no-error
1558 (Info-last-menu-item)
1559 ;; If we go down a menu item, go to the end of the node
1560 ;; so we can scroll back through it.
1561 (goto-char (point-max))))
1563 ((Info-no-error (Info-up t
))
1564 (goto-char (point-min))
1565 (let ((case-fold-search t
))
1566 (or (search-forward "\n* Menu:" nil t
)
1567 (goto-char (point-max)))))
1568 (t (error "No previous nodes"))))
1570 (defun Info-scroll-up ()
1571 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1572 Once you scroll far enough in a node that its menu appears on the screen
1573 but after point, the next scroll moves into its first subnode.
1575 When you scroll past the end of a node, that goes to the next node; if
1576 this node has no successor, it moves to the parent node's successor,
1577 and so on. If point is inside the menu of a node, it moves to
1578 subnode indicated by the following menu item. (That case won't
1579 normally result from this command, but can happen in other ways.)"
1582 (if (or (< (window-start) (point-min))
1583 (> (window-start) (point-max)))
1584 (set-window-start (selected-window) (point)))
1585 (let* ((case-fold-search t
)
1586 (virtual-end (save-excursion
1587 (goto-char (point-min))
1588 (if (search-forward "\n* Menu:" nil t
)
1591 (if (or (< virtual-end
(window-start))
1592 (pos-visible-in-window-p virtual-end
))
1593 (Info-next-preorder)
1596 (defun Info-scroll-down ()
1597 "Scroll one screenful back in Info, considering all nodes as one sequence.
1598 Within the menu of a node, this goes to its last subnode.
1599 When you scroll past the beginning of a node, that goes to the
1600 previous node or back up to the parent node."
1602 (if (or (< (window-start) (point-min))
1603 (> (window-start) (point-max)))
1604 (set-window-start (selected-window) (point)))
1605 (let* ((case-fold-search t
)
1606 (current-point (point))
1607 (virtual-end (save-excursion
1609 (setq current-point
(point))
1610 (goto-char (point-min))
1611 (search-forward "\n* Menu:"
1614 (if (or virtual-end
(pos-visible-in-window-p (point-min)))
1615 (Info-last-preorder)
1618 (defun Info-next-reference (&optional recur
)
1619 "Move cursor to the next cross-reference or menu item in the node."
1621 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1623 (case-fold-search t
))
1624 (or (eobp) (forward-char 1))
1625 (or (re-search-forward pat nil t
)
1627 (goto-char (point-min))
1628 (or (re-search-forward pat nil t
)
1631 (error "No cross references in this node")))))
1632 (goto-char (match-beginning 0))
1633 (if (looking-at "\\* Menu:")
1635 (error "No cross references in this node")
1636 (Info-next-reference t
)))))
1638 (defun Info-prev-reference (&optional recur
)
1639 "Move cursor to the previous cross-reference or menu item in the node."
1641 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1643 (case-fold-search t
))
1644 (or (re-search-backward pat nil t
)
1646 (goto-char (point-max))
1647 (or (re-search-backward pat nil t
)
1650 (error "No cross references in this node")))))
1651 (goto-char (match-beginning 0))
1652 (if (looking-at "\\* Menu:")
1654 (error "No cross references in this node")
1655 (Info-prev-reference t
)))))
1657 (defun Info-index (topic)
1658 "Look up a string TOPIC in the index for this file.
1659 The index is defined as the first node in the top-level menu whose
1660 name contains the word \"Index\", plus any immediately following
1661 nodes whose names also contain the word \"Index\".
1662 If there are no exact matches to the specified topic, this chooses
1663 the first match which is a case-insensitive substring of a topic.
1664 Use the `,' command to see the other matches.
1665 Give a blank topic name to go to the Index node itself."
1666 (interactive "sIndex topic: ")
1667 (let ((orignode Info-current-node
)
1669 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1670 (regexp-quote topic
)))
1672 (case-fold-search t
))
1673 (Info-goto-node "Top")
1674 (or (search-forward "\n* menu:" nil t
)
1676 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
1678 (goto-char (match-beginning 1))
1679 ;; Here, and subsequently in this function,
1680 ;; we bind Info-history to nil for internal node-switches
1681 ;; so that we don't put junk in the history.
1682 ;; In the first Info-goto-node call, above, we do update the history
1683 ;; because that is what the user's previous node choice into it.
1684 (let ((Info-history nil
))
1685 (Info-goto-node (Info-extract-menu-node-name)))
1686 (or (equal topic
"")
1693 (goto-char (point-min))
1694 (while (re-search-forward pattern nil t
)
1696 (cons (list (match-string-no-properties 1)
1697 (match-string-no-properties 2)
1699 (string-to-int (concat "0"
1702 (and (setq node
(Info-extract-pointer "next" t
))
1703 (string-match "\\<Index\\>" node
)))
1704 (Info-goto-node node
))
1707 (Info-goto-node orignode
)
1708 (error "No `%s' in index" topic
)))
1709 ;; Here it is a feature that assoc is case-sensitive.
1710 (while (setq found
(assoc topic matches
))
1711 (setq exact
(cons found exact
)
1712 matches
(delq found matches
)))
1713 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
1714 (Info-index-next 0)))))
1716 (defun Info-index-next (num)
1717 "Go to the next matching index item from the last `i' command."
1719 (or Info-index-alternatives
1720 (error "No previous `i' command"))
1722 (setq num
(+ num
(length Info-index-alternatives
))))
1724 (setq Info-index-alternatives
1725 (nconc (cdr Info-index-alternatives
)
1726 (list (car Info-index-alternatives
)))
1728 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
1729 (if (> (nth 3 (car Info-index-alternatives
)) 0)
1730 (forward-line (nth 3 (car Info-index-alternatives
)))
1731 (forward-line 3) ; don't search in headers
1732 (let ((name (car (car Info-index-alternatives
))))
1733 (Info-find-index-name name
)))
1734 (message "Found `%s' in %s. %s"
1735 (car (car Info-index-alternatives
))
1736 (nth 2 (car Info-index-alternatives
))
1737 (if (cdr Info-index-alternatives
)
1738 "(Press `,' for more)"
1741 (defun Info-find-index-name (name)
1742 "Move point to the place within the current node where NAME is defined."
1743 (let ((case-fold-search t
))
1744 (if (or (re-search-forward (format
1745 "[a-zA-Z]+: %s\\( \\|$\\)"
1746 (regexp-quote name
)) nil t
)
1747 (search-forward (format "`%s'" name
) nil t
)
1748 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
1750 (format "`%s'" (substring name
0 (match-beginning 1)))
1752 (search-forward name nil t
))
1754 (goto-char (point-min)))))
1756 (defun Info-undefined ()
1757 "Make command be undefined in Info."
1762 "Enter the Info tutorial."
1764 (delete-other-windows)
1765 (Info-find-node "info"
1766 (if (< (window-height) 23)
1770 (defun Info-summary ()
1771 "Display a brief summary of all Info commands."
1773 (save-window-excursion
1774 (switch-to-buffer "*Help*")
1775 (setq buffer-read-only nil
)
1777 (insert (documentation 'Info-mode
))
1779 (goto-char (point-min))
1781 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
1782 (message (if flag
"Type Space to see more"
1783 "Type Space to return to Info"))
1784 (if (not (eq ?\
(setq ch
(read-event))))
1785 (progn (setq unread-command-events
(list ch
)) nil
)
1788 (bury-buffer "*Help*")))
1790 (defun Info-get-token (pos start all
&optional errorstring
)
1791 "Return the token around POS.
1792 POS must be somewhere inside the token
1793 START is a regular expression which will match the
1794 beginning of the tokens delimited string
1795 ALL is a regular expression with a single
1796 parenthesized subpattern which is the token to be
1797 returned. E.g. '{\(.*\)}' would return any string
1798 enclosed in braces around POS.
1799 ERRORSTRING optional fourth argument, controls action on no match
1802 a string: signal an error, using that string."
1803 (let ((case-fold-search t
))
1806 ;; First look for a match for START that goes across POS.
1807 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
1808 (not (looking-at start
)))
1810 ;; If we did not find one, search back for START
1811 ;; (this finds only matches that end at or before POS).
1812 (or (looking-at start
)
1815 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
1817 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
1818 (not (setq found
(and (<= (match-beginning 0) pos
)
1819 (> (match-end 0) pos
))))))
1820 (if (and found
(<= (match-beginning 0) pos
)
1821 (> (match-end 0) pos
))
1822 (match-string-no-properties 1)
1823 (cond ((null errorstring
)
1829 (error "No %s around position %d" errorstring pos
))))))))
1831 (defun Info-mouse-follow-nearest-node (click)
1832 "\\<Info-mode-map>Follow a node reference near point.
1833 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1834 At end of the node's text, moves to the next node, or up if none."
1836 (let* ((start (event-start click
))
1837 (window (car start
))
1838 (pos (car (cdr start
))))
1839 (select-window window
)
1841 (and (not (Info-try-follow-nearest-node))
1842 (save-excursion (forward-line 1) (eobp))
1843 (Info-next-preorder)))
1845 (defun Info-follow-nearest-node ()
1846 "\\<Info-mode-map>Follow a node reference near point.
1847 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1848 If no reference to follow, moves to the next node, or up if none."
1850 (or (Info-try-follow-nearest-node)
1851 (Info-next-preorder)))
1853 ;; Common subroutine.
1854 (defun Info-try-follow-nearest-node ()
1855 "Follow a node reference near point. Return non-nil if successful."
1858 ((setq node
(Info-get-token (point) "\\*note[ \n]"
1859 "\\*note[ \n]\\([^:]*\\):"))
1860 (Info-follow-reference node
))
1861 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1862 (Info-goto-node node
))
1863 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
1866 (setq node
(Info-extract-menu-node-name))
1867 (Info-goto-node node
))
1868 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1869 (Info-goto-node node
))
1870 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1871 (Info-goto-node node
))
1872 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1873 (Info-goto-node "Top"))
1874 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1875 (Info-goto-node node
)))
1878 (defvar Info-mode-map nil
1879 "Keymap containing Info commands.")
1882 (setq Info-mode-map
(make-keymap))
1883 (suppress-keymap Info-mode-map
)
1884 (define-key Info-mode-map
"." 'beginning-of-buffer
)
1885 (define-key Info-mode-map
" " 'Info-scroll-up
)
1886 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
1887 (define-key Info-mode-map
"\t" 'Info-next-reference
)
1888 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
1889 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
1890 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
1891 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
1892 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
1893 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
1894 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
1895 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
1896 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
1897 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
1898 (define-key Info-mode-map
"0" 'undefined
)
1899 (define-key Info-mode-map
"?" 'Info-summary
)
1900 (define-key Info-mode-map
"]" 'Info-forward-node
)
1901 (define-key Info-mode-map
"[" 'Info-backward-node
)
1902 (define-key Info-mode-map
"<" 'Info-top-node
)
1903 (define-key Info-mode-map
">" 'Info-final-node
)
1904 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
1905 (define-key Info-mode-map
"d" 'Info-directory
)
1906 (define-key Info-mode-map
"e" 'Info-edit
)
1907 (define-key Info-mode-map
"f" 'Info-follow-reference
)
1908 (define-key Info-mode-map
"g" 'Info-goto-node
)
1909 (define-key Info-mode-map
"h" 'Info-help
)
1910 (define-key Info-mode-map
"i" 'Info-index
)
1911 (define-key Info-mode-map
"l" 'Info-last
)
1912 (define-key Info-mode-map
"m" 'Info-menu
)
1913 (define-key Info-mode-map
"n" 'Info-next
)
1914 (define-key Info-mode-map
"p" 'Info-prev
)
1915 (define-key Info-mode-map
"q" 'Info-exit
)
1916 (define-key Info-mode-map
"s" 'Info-search
)
1917 ;; For consistency with Rmail.
1918 (define-key Info-mode-map
"\M-s" 'Info-search
)
1919 (define-key Info-mode-map
"\M-n" 'clone-buffer
)
1920 (define-key Info-mode-map
"t" 'Info-top-node
)
1921 (define-key Info-mode-map
"u" 'Info-up
)
1922 (define-key Info-mode-map
"," 'Info-index-next
)
1923 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
1924 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
1927 (defun Info-check-pointer (item)
1928 "Non-nil if ITEM is present in this node."
1930 (Info-extract-pointer item
)
1934 Info-mode-menu Info-mode-map
1935 "Menu for info files."
1937 ["Up" Info-up
:active
(Info-check-pointer "up")
1938 :help
"Go up in the Info tree"]
1939 ["Next" Info-next
:active
(Info-check-pointer "next")
1940 :help
"Go to the next node"]
1941 ["Previous" Info-prev
:active
(Info-check-pointer "prev[ious]*")
1942 :help
"Go to the previous node"]
1943 ["Backward" Info-backward-node
1944 :help
"Go backward one node, considering all as a sequence"]
1945 ["Forward" Info-forward-node
1946 :help
"Go forward one node, considering all as a sequence"]
1947 ["Top" Info-top-node
1948 :help
"Go to top node of file"]
1949 ["Final Node" Info-final-node
1950 :help
"Go to final node in this file"]
1951 ("Menu Item" ["You should never see this" report-emacs-bug t
])
1952 ("Reference" ["You should never see this" report-emacs-bug t
])
1953 ["Search..." Info-search
1954 :help
"Search for regular expression in this Info file"]
1955 ["Goto Node..." Info-goto-node
1956 :help
"Go to a named node"]
1957 ["Last" Info-last Info-history
1958 :help
"Go to the last node you were at"]
1960 ["Lookup a String" Info-index
1961 :help
"Look for a string in the index items"]
1962 ["Next Matching Item" Info-index-next
1963 :help
"Look for another occurrence of previous item"])
1964 ["Exit" Info-exit t
]))
1966 (defvar Info-menu-last-node nil
)
1967 ;; Last node the menu was created for.
1968 ;; Value is a list, (FILE-NAME NODE-NAME).
1970 (defun Info-menu-update ()
1971 "Update the Info menu for the current node."
1973 (if (or (not (eq major-mode
'Info-mode
))
1974 (equal (list Info-current-file Info-current-node
)
1975 Info-menu-last-node
))
1977 ;; Update menu menu.
1978 (let* ((Info-complete-menu-buffer (current-buffer))
1979 (items (nreverse (condition-case nil
1980 (Info-complete-menu-item
1981 "" (lambda (e) t
) t
)
1985 (while (and items
(< number
9))
1986 (setq current
(car items
)
1989 (setq entries
(cons `[,current
1990 (Info-menu ,current
)
1991 :keys
,(format "%d" number
)]
1994 (setq entries
(cons ["Other..." Info-menu t
] entries
)))
1996 (setq entries
(list ["No menu" nil nil
])))
1997 (easy-menu-change '("Info") "Menu Item" (nreverse entries
)))
1998 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2000 str i entries current
2002 (case-fold-search t
))
2004 (goto-char (point-min))
2005 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
2006 (setq str
(buffer-substring
2010 (while (setq i
(string-match "[ \n\t]+" str i
))
2011 (setq str
(concat (substring str
0 i
) " "
2012 (substring str
(match-end 0))))
2016 (while (and items
(< number
9))
2017 (setq current
(car items
)
2020 (setq entries
(cons `[,current
2021 (Info-follow-reference ,current
)
2025 (setq entries
(cons ["Other..." Info-follow-reference t
]
2028 (setq entries
(list ["No references" nil nil
])))
2029 (easy-menu-change '("Info") "Reference" (nreverse entries
)))
2030 ;; Update last seen node.
2031 (setq Info-menu-last-node
(list Info-current-file Info-current-node
)))
2032 ;; Try to avoid entering infinite beep mode in case of errors.
2036 ;; Info mode is suitable only for specially formatted data.
2037 (put 'info-mode
'mode-class
'special
)
2040 "Info mode provides commands for browsing through the Info documentation tree.
2041 Documentation in Info is divided into \"nodes\", each of which discusses
2042 one topic and contains references to other nodes which discuss related
2043 topics. Info has commands to follow the references and show you other nodes.
2046 \\[Info-help] Invoke the Info tutorial.
2047 \\[Info-exit] Quit Info: reselect previously selected buffer.
2049 Selecting other nodes:
2050 \\[Info-mouse-follow-nearest-node]
2051 Follow a node reference you click on.
2052 This works with menu items, cross references, and
2053 the \"next\", \"previous\" and \"up\", depending on where you click.
2054 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2055 \\[Info-next] Move to the \"next\" node of this node.
2056 \\[Info-prev] Move to the \"previous\" node of this node.
2057 \\[Info-up] Move \"up\" from this node.
2058 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2059 Picking a menu item causes another node to be selected.
2060 \\[Info-directory] Go to the Info directory node.
2061 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2062 \\[Info-last] Move to the last node you were at.
2063 \\[Info-index] Look up a topic in this file's Index and move to that node.
2064 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2065 \\[Info-top-node] Go to the Top node of this file.
2066 \\[Info-final-node] Go to the final node in this file.
2067 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2068 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2070 Moving within a node:
2071 \\[Info-scroll-up] Normally, scroll forward a full screen.
2072 Once you scroll far enough in a node that its menu appears on the screen
2073 but after point, the next scroll moves into its first subnode.
2074 When after all menu items (or if their is no menu), move up to
2076 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2077 already visible, try to go to the previous menu entry, or up if there is none.
2078 \\[beginning-of-buffer] Go to beginning of node.
2081 \\[Info-exit] Quit Info: reselect previously selected buffer.
2082 \\[Info-edit] Edit contents of selected node.
2083 1 Pick first item in node's menu.
2084 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2085 \\[Info-goto-node] Move to node specified by name.
2086 You may include a filename as well, as (FILENAME)NODENAME.
2087 \\[universal-argument] \\[info] Move to new Info file with completion.
2088 \\[Info-search] Search through this Info file for specified regexp,
2089 and select the node in which the next occurrence is found.
2090 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2091 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2092 (kill-all-local-variables)
2093 (setq major-mode
'Info-mode
)
2094 (setq mode-name
"Info")
2096 (use-local-map Info-mode-map
)
2097 (make-local-hook 'activate-menubar-hook
)
2098 (add-hook 'activate-menubar-hook
'Info-menu-update nil t
)
2099 (set-syntax-table text-mode-syntax-table
)
2100 (setq local-abbrev-table text-mode-abbrev-table
)
2101 (setq case-fold-search t
)
2102 (setq buffer-read-only t
)
2103 (make-local-variable 'Info-current-file
)
2104 (make-local-variable 'Info-current-subfile
)
2105 (make-local-variable 'Info-current-node
)
2106 (make-local-variable 'Info-tag-table-marker
)
2107 (setq Info-tag-table-marker
(make-marker))
2108 (make-local-variable 'Info-tag-table-buffer
)
2109 (setq Info-tag-table-buffer nil
)
2110 (make-local-variable 'Info-history
)
2111 (make-local-variable 'Info-index-alternatives
)
2112 ;; This is for the sake of the invisible text we use handling titles.
2113 (make-local-variable 'line-move-ignore-invisible
)
2114 (setq line-move-ignore-invisible t
)
2115 (add-hook (make-local-hook 'clone-buffer-hook
) 'Info-clone-buffer-hook nil t
)
2116 (Info-set-mode-line)
2117 (run-hooks 'Info-mode-hook
))
2119 (defun Info-clone-buffer-hook ()
2120 (when (bufferp Info-tag-table-buffer
)
2121 (setq Info-tag-table-buffer
2122 (with-current-buffer Info-tag-table-buffer
(clone-buffer)))
2123 (let ((m Info-tag-table-marker
))
2124 (when (and (markerp m
) (marker-position m
))
2125 (setq Info-tag-table-marker
2126 (with-current-buffer Info-tag-table-buffer
2127 (copy-marker (marker-position m
))))))))
2129 (defvar Info-edit-map nil
2130 "Local keymap used within `e' command of Info.")
2133 (setq Info-edit-map
(nconc (make-sparse-keymap) text-mode-map
))
2134 (define-key Info-edit-map
"\C-c\C-c" 'Info-cease-edit
))
2136 ;; Info-edit mode is suitable only for specially formatted data.
2137 (put 'info-edit-mode
'mode-class
'special
)
2139 (defun Info-edit-mode ()
2140 "Major mode for editing the contents of an Info node.
2141 Like text mode with the addition of `Info-cease-edit'
2142 which returns to Info mode for browsing.
2144 (use-local-map Info-edit-map
)
2145 (setq major-mode
'Info-edit-mode
)
2146 (setq mode-name
"Info Edit")
2147 (kill-local-variable 'mode-line-buffer-identification
)
2148 (setq buffer-read-only nil
)
2149 (force-mode-line-update)
2150 (buffer-enable-undo (current-buffer))
2151 (run-hooks 'Info-edit-mode-hook
))
2154 "Edit the contents of this Info node.
2155 Allowed only if variable `Info-enable-edit' is non-nil."
2157 (or Info-enable-edit
2158 (error "Editing info nodes is not enabled"))
2160 (message "%s" (substitute-command-keys
2161 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2163 (defun Info-cease-edit ()
2164 "Finish editing Info node; switch back to Info proper."
2166 ;; Do this first, so nothing has changed if user C-g's at query.
2167 (and (buffer-modified-p)
2168 (y-or-n-p "Save the file? ")
2170 (use-local-map Info-mode-map
)
2171 (setq major-mode
'Info-mode
)
2172 (setq mode-name
"Info")
2173 (Info-set-mode-line)
2174 (setq buffer-read-only t
)
2175 (force-mode-line-update)
2176 (and (marker-position Info-tag-table-marker
)
2178 (message "Tags may have changed. Use Info-tagify if necessary")))
2180 (defvar Info-file-list-for-emacs
2181 '("ediff" "forms" "gnus" ("mh" .
"mh-e") "sc" "message"
2182 ("dired" .
"dired-x") ("c" .
"ccmode") "viper" "vip"
2183 ("skeleton" .
"autotype") ("auto-insert" .
"autotype")
2184 ("copyright" .
"autotype") ("executable" .
"autotype")
2185 ("time-stamp" .
"autotype") ("quickurl" .
"autotype")
2186 ("tempo" .
"autotype") ("hippie-expand" .
"autotype")
2188 "ebrowse" "cl" "idlwave" "reftex" "widget" "woman")
2189 "List of Info files that describe Emacs commands.
2190 An element can be a file name, or a list of the form (PREFIX . FILE)
2191 where PREFIX is a name prefix and FILE is the file to look in.
2192 If the element is just a file name, the file name also serves as the prefix.")
2194 (defun Info-find-emacs-command-nodes (command)
2195 "Return a list of locations documenting COMMAND.
2196 The `info-file' property of COMMAND says which Info manual to search.
2197 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2198 defines heuristics for which Info manual to try.
2199 The locations are of the format used in `Info-history', i.e.
2200 \(FILENAME NODENAME BUFFERPOS\)."
2202 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command
))
2203 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
2204 (info-file "emacs")) ;default
2205 ;; Determine which info file this command is documented in.
2206 (if (get command
'info-file
)
2207 (setq info-file
(get command
'info-file
))
2208 ;; If it doesn't say explicitly, test its name against
2209 ;; various prefixes that we know.
2210 (let ((file-list Info-file-list-for-emacs
))
2212 (let* ((elt (car file-list
))
2213 (name (if (consp elt
)
2216 (file (if (consp elt
) (cdr elt
) elt
))
2217 (regexp (concat "\\`" (regexp-quote name
)
2219 (if (string-match regexp
(symbol-name command
))
2220 (setq info-file file file-list nil
))
2221 (setq file-list
(cdr file-list
))))))
2222 (Info-find-node info-file
"Top")
2223 (or (and (search-forward "\n* menu:" nil t
)
2224 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
2225 (error "Info file `%s' appears to lack an index" info-file
))
2226 (goto-char (match-beginning 1))
2227 ;; Bind Info-history to nil, to prevent the index nodes from
2228 ;; getting into the node history.
2229 (let ((Info-history nil
)
2232 (Info-goto-node (Info-extract-menu-node-name))
2235 (goto-char (point-min))
2236 (while (re-search-forward cmd-desc nil t
)
2238 (cons (list Info-current-file
2239 (match-string-no-properties 2)
2242 (and (setq node
(Info-extract-pointer "next" t
))
2243 (string-match "\\<Index\\>" node
)))
2244 (Info-goto-node node
)))
2248 (defun Info-goto-emacs-command-node (command)
2249 "Go to the Info node in the Emacs manual for command COMMAND.
2250 The command is found by looking up in Emacs manual's Command Index
2251 or in another manual found via COMMAND's `info-file' property or
2252 the variable `Info-file-list-for-emacs'."
2253 (interactive "CFind documentation for command: ")
2254 (or (commandp command
)
2255 (signal 'wrong-type-argument
(list 'commandp command
)))
2256 (let ((where (Info-find-emacs-command-nodes command
)))
2258 (let ((num-matches (length where
)))
2259 ;; Get Info running, and pop to it in another window.
2260 (save-window-excursion
2262 ;; FIXME It would be cool if this could use a buffer other
2264 (pop-to-buffer "*info*")
2265 ;; Bind Info-history to nil, to prevent the last Index node
2266 ;; visited by Info-find-emacs-command-nodes from being
2267 ;; pushed onto the history.
2268 (let ((Info-history nil
))
2269 (Info-find-node (car (car where
))
2270 (car (cdr (car where
)))))
2271 (if (> num-matches
1)
2273 ;; (car where) will be pushed onto Info-history
2274 ;; when/if they go to another node. Put the other
2275 ;; nodes that were found on the history.
2276 (setq Info-history
(nconc (cdr where
) Info-history
))
2277 (message "Found %d other entr%s. Use %s to see %s."
2279 (if (> num-matches
2) "ies" "y")
2280 (substitute-command-keys "\\[Info-last]")
2281 (if (> num-matches
2) "them" "it")))))
2282 (error "Couldn't find documentation for %s" command
))))
2285 (defun Info-goto-emacs-key-command-node (key)
2286 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2287 Interactively, if the binding is `execute-extended-command', a command is read.
2288 The command is found by looking up in Emacs manual's Command Index
2289 or in another manual found via COMMAND's `info-file' property or
2290 the variable `Info-file-list-for-emacs'."
2291 (interactive "kFind documentation for key: ")
2292 (let ((command (key-binding key
)))
2293 (cond ((null command
)
2294 (message "%s is undefined" (key-description key
)))
2295 ((and (interactive-p)
2296 (eq command
'execute-extended-command
))
2297 (Info-goto-emacs-command-node
2298 (read-command "Find documentation for command: ")))
2300 (Info-goto-emacs-command-node command
)))))
2302 (defface Info-title-1-face
2303 '((t (:family
"helv" :height
240 :weight bold
)))
2304 "Face for Info titles at level 1."
2307 (defface Info-title-2-face
2308 '((t (:family
"helv" :height
180 :weight bold
)))
2309 "Face for Info titles at level 2."
2312 (defface Info-title-3-face
2313 '((t (:family
"helv" :height
160 :weight bold
)))
2314 "Face for Info titles at level 3."
2317 (defun Info-fontify-node ()
2319 (let ((buffer-read-only nil
)
2320 (case-fold-search t
))
2321 (goto-char (point-min))
2322 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2323 (goto-char (match-end 0))
2325 (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2326 (goto-char (match-end 0))
2328 (goto-char (match-beginning 1))
2329 (save-match-data (looking-at "Node:")))
2330 (put-text-property (match-beginning 2) (match-end 2)
2332 (put-text-property (match-beginning 2) (match-end 2)
2334 (put-text-property (match-beginning 2) (match-end 2)
2335 'mouse-face
'highlight
))))
2336 (goto-char (point-min))
2337 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2339 (let ((c (preceding-char))
2341 (cond ((= c ?
*) (setq face
'Info-title-1-face
))
2342 ((= c ?
=) (setq face
'Info-title-2-face
))
2343 (t (setq face
'Info-title-3-face
)))
2344 (put-text-property (match-beginning 1) (match-end 1)
2346 ;; This is a serious problem for trying to handle multiple
2347 ;; frame types at once. We want this text to be invisible
2348 ;; on frames that can display the font above.
2349 (if (memq (framep (selected-frame)) '(x pc w32
))
2350 (add-text-properties (match-end 1) (match-end 2)
2351 '(invisible t intangible t
))))
2352 (goto-char (point-min))
2353 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t
)
2354 (if (= (char-after (1- (match-beginning 0))) ?
\") ; hack
2356 (put-text-property (match-beginning 1) (match-end 1)
2358 (put-text-property (match-beginning 1) (match-end 1)
2359 'mouse-face
'highlight
)))
2360 (goto-char (point-min))
2361 (if (and (search-forward "\n* Menu:" nil t
)
2362 (not (string-match "\\<Index\\>" Info-current-node
))
2363 ;; Don't take time to annotate huge menus
2364 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
2366 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t
)
2368 (if (memq n
'(5 9)) ; visual aids to help with 1-9 keys
2369 (put-text-property (match-beginning 0)
2370 (1+ (match-beginning 0))
2371 'face
'info-menu-5
))
2372 (put-text-property (match-beginning 1) (match-end 1)
2374 (put-text-property (match-beginning 1) (match-end 1)
2375 'mouse-face
'highlight
))))
2376 (set-buffer-modified-p nil
))))
2379 ;; When an Info buffer is killed, make sure the associated tags buffer
2381 (defun Info-kill-buffer ()
2382 (and (eq major-mode
'Info-mode
)
2383 Info-tag-table-buffer
2384 (kill-buffer Info-tag-table-buffer
)))
2386 (add-hook 'kill-buffer-hook
'Info-kill-buffer
)
2388 ;;; Speedbar support:
2389 ;; These functions permit speedbar to display the "tags" in the
2390 ;; current info node.
2391 (eval-when-compile (require 'speedbar
))
2393 (defvar Info-speedbar-key-map nil
2394 "Keymap used when in the info display mode.")
2396 (defun Info-install-speedbar-variables ()
2397 "Install those variables used by speedbar to enhance Info."
2398 (if Info-speedbar-key-map
2400 (setq Info-speedbar-key-map
(speedbar-make-specialized-keymap))
2402 ;; Basic tree features
2403 (define-key Info-speedbar-key-map
"e" 'speedbar-edit-line
)
2404 (define-key Info-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
2405 (define-key Info-speedbar-key-map
"+" 'speedbar-expand-line
)
2406 (define-key Info-speedbar-key-map
"-" 'speedbar-contract-line
)
2409 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2410 Info-speedbar-key-map
2411 Info-speedbar-hierarchy-buttons
)))
2413 (defvar Info-speedbar-menu-items
2414 '(["Browse Node" speedbar-edit-line t
]
2415 ["Expand Node" speedbar-expand-line
2416 (save-excursion (beginning-of-line)
2417 (looking-at "[0-9]+: *.\\+. "))]
2418 ["Contract Node" speedbar-contract-line
2419 (save-excursion (beginning-of-line)
2420 (looking-at "[0-9]+: *.-. "))]
2422 "Additional menu-items to add to speedbar frame.")
2424 ;; Make sure our special speedbar major mode is loaded
2425 (if (featurep 'speedbar
)
2426 (Info-install-speedbar-variables)
2427 (add-hook 'speedbar-load-hook
'Info-install-speedbar-variables
))
2429 ;;; Info hierarchy display method
2431 (defun Info-speedbar-browser ()
2432 "Initialize speedbar to display an info node browser.
2433 This will add a speedbar major display mode."
2436 ;; Make sure that speedbar is active
2437 (speedbar-frame-mode 1)
2438 ;; Now, throw us into Info mode on speedbar.
2439 (speedbar-change-initial-expansion-list "Info")
2442 (defun Info-speedbar-hierarchy-buttons (directory depth
&optional node
)
2443 "Display an Info directory hierarchy in speedbar.
2444 DIRECTORY is the current directory in the attached frame.
2445 DEPTH is the current indentation depth.
2446 NODE is an optional argument that is used to represent the
2447 specific node to expand."
2449 (save-excursion (goto-char (point-min))
2450 (let ((case-fold-search t
))
2451 (looking-at "Info Nodes:"))))
2452 ;; Update our "current node" maybe?
2454 ;; We cannot use the generic list code, that depends on all leaves
2455 ;; being known at creation time.
2457 (speedbar-with-writable (insert "Info Nodes:\n")))
2458 (let ((completions nil
)
2459 (cf (selected-frame)))
2460 (select-frame speedbar-attached-frame
)
2461 (save-window-excursion
2463 (Info-speedbar-fetch-file-nodes (or node
'"(dir)top"))))
2466 (speedbar-with-writable
2468 (speedbar-make-tag-line 'bracket ?
+ 'Info-speedbar-expand-node
2469 (cdr (car completions
))
2470 (car (car completions
))
2471 'Info-speedbar-goto-node
2472 (cdr (car completions
))
2474 (setq completions
(cdr completions
)))
2478 (defun Info-speedbar-goto-node (text node indent
)
2479 "When user clicks on TEXT, goto an info NODE.
2480 The INDENT level is ignored."
2481 (select-frame speedbar-attached-frame
)
2482 (let* ((buff (or (get-buffer "*info*")
2483 (progn (info) (get-buffer "*info*"))))
2484 (bwin (get-buffer-window buff
0)))
2487 (select-window bwin
)
2488 (raise-frame (window-frame bwin
)))
2489 (if speedbar-power-click
2490 (let ((pop-up-frames t
)) (select-window (display-buffer buff
)))
2491 (select-frame speedbar-attached-frame
)
2492 (switch-to-buffer buff
)))
2493 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node
))
2494 (file (match-string 1 node
))
2495 (node (match-string 2 node
)))
2496 (Info-find-node file node
)
2497 ;; If we do a find-node, and we were in info mode, restore
2498 ;; the old default method. Once we are in info mode, it makes
2499 ;; sense to return to whatever method the user was using before.
2500 (if (string= speedbar-initial-expansion-list-name
"Info")
2501 (speedbar-change-initial-expansion-list
2502 speedbar-previously-used-expansion-list-name
)))))
2504 (defun Info-speedbar-expand-node (text token indent
)
2505 "Expand the node the user clicked on.
2506 TEXT is the text of the button we clicked on, a + or - item.
2507 TOKEN is data related to this node (NAME . FILE).
2508 INDENT is the current indentation depth."
2509 (cond ((string-match "+" text
) ;we have to expand this file
2510 (speedbar-change-expand-button-char ?-
)
2511 (if (speedbar-with-writable
2513 (end-of-line) (forward-char 1)
2514 (Info-speedbar-hierarchy-buttons nil
(1+ indent
) token
)))
2515 (speedbar-change-expand-button-char ?-
)
2516 (speedbar-change-expand-button-char ??
)))
2517 ((string-match "-" text
) ;we have to contract this node
2518 (speedbar-change-expand-button-char ?
+)
2519 (speedbar-delete-subblock indent
))
2520 (t (error "Ooops... not sure what to do")))
2521 (speedbar-center-buffer-smartly))
2523 (defun Info-speedbar-fetch-file-nodes (nodespec)
2524 "Fetch the subnodes from the info NODESPEC.
2525 NODESPEC is a string of the form: (file)node.
2526 Optional THISFILE represends the filename of"
2528 ;; Set up a buffer we can use to fake-out Info.
2529 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2530 (if (not (equal major-mode
'Info-mode
))
2532 ;; Get the node into this buffer
2533 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec
))
2534 (file (match-string 1 nodespec
))
2535 (node (match-string 2 nodespec
)))
2536 (Info-find-node file node
))
2537 ;; Scan the created buffer
2538 (goto-char (point-min))
2539 (let ((completions nil
)
2540 (case-fold-search t
)
2541 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec
)
2542 (match-string 1 nodespec
))))
2543 ;; Always skip the first one...
2544 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
2545 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
2546 (let ((name (match-string 1)))
2547 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2548 (setq name
(cons name
(match-string 1)))
2549 (if (looking-at " *\\(([^)]+)\\)\\.")
2550 (setq name
(cons name
(concat (match-string 1) "Top")))
2551 (if (looking-at " \\([^.]+\\).")
2553 (cons name
(concat "(" thisfile
")" (match-string 1))))
2554 (setq name
(cons name
(concat "(" thisfile
")" name
))))))
2555 (setq completions
(cons name completions
))))
2556 (nreverse completions
))))
2558 ;;; Info mode node listing
2559 (defun Info-speedbar-buttons (buffer)
2560 "Create a speedbar display to help navigation in an Info file.
2561 BUFFER is the buffer speedbar is requesting buttons for."
2562 (if (save-excursion (goto-char (point-min))
2563 (let ((case-fold-search t
))
2564 (not (looking-at "Info Nodes:"))))
2566 (Info-speedbar-hierarchy-buttons nil
0)
2569 (dolist (mess '("^Node has no Previous$"
2570 "^No menu in this node$"
2571 "^Node has no Next$"
2572 "^No cross-references in this node^"
2574 "^No \".*\" in index$"))
2575 (add-to-list 'debug-ignored-errors mess
))
2579 ;;; info.el ends here