1 ;;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
4 ;; Free Software Foundation, Inc.
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
) (background light
)) (:foreground
"brown" :weight bold
:slant italic
))
65 (((class color
) (background dark
)) (:foreground
"white" :weight bold
:slant italic
))
66 (t (:weight bold
:slant italic
)))
67 "Face for Info node names."
71 '((((class color
)) (:foreground
"red1"))
73 "Face for the fifth and nineth `*' in an Info menu."
77 '((((class color
) (background light
)) (:foreground
"magenta4" :weight bold
))
78 (((class color
) (background dark
)) (:foreground
"cyan" :weight bold
))
80 "Face for Info cross-references."
83 (defcustom Info-fontify-maximum-menu-size
100000
84 "*Maximum size of menu to fontify if `Info-fontify' is non-nil."
88 (defcustom Info-use-header-line t
89 "*Non-nil means to put the beginning-of-node links in an emacs header-line.
90 A header-line does not scroll with the rest of the buffer."
94 (defface info-header-xref
95 '((t (:inherit info-xref
)))
96 "Face for Info cross-references in a node header."
99 (defface info-header-node
100 '((t (:inherit info-node
)))
101 "Face for Info nodes in a node header."
104 (defvar Info-directory-list nil
105 "List of directories to search for Info documentation files.
106 nil means not yet initialized. In this case, Info uses the environment
107 variable INFOPATH to initialize it, or `Info-default-directory-list'
108 if there is no INFOPATH variable in the environment.
110 When `Info-directory-list' is initialized from the value of
111 `Info-default-directory-list', and Emacs is installed in one of the
112 standard directories, the directory of Info files that come with Emacs
113 is put last (so that local Info files override standard ones).
115 When `Info-directory-list' is initialized from the value of
116 `Info-default-directory-list', and Emacs is not installed in one
117 of the standard directories, the first element of the resulting
118 list is the directory where Emacs installs the Info files that
119 come with it. This is so that Emacs's own manual, which suits the
120 version of Emacs you are using, will always be found first. This
121 is useful when you install an experimental version of Emacs without
122 removing the standard installation.
124 If you want to override the order of directories in
125 `Info-default-directory-list', set INFOPATH in the environment.
127 If you run the Emacs executable from the `src' directory in the Emacs
128 source tree, and INFOPATH is not defined, the `info' directory in the
129 source tree is used as the first element of `Info-directory-list', in
130 place of the installation Info directory. This is useful when you run
131 a version of Emacs without installing it.")
133 (defcustom Info-additional-directory-list nil
134 "List of additional directories to search for Info documentation files.
135 These directories are searched after those in `Info-directory-list', and
136 they are not searched for merging the `dir' file."
137 :type
'(repeat directory
)
140 (defcustom Info-scroll-prefer-subnodes t
141 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
142 If this is non-nil, and you scroll far enough in a node that its menu
143 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
144 moves to a subnode indicated by the following menu item. This means
145 that you visit a subnode before getting to the end of the menu.
147 Setting this option to nil results in behavior similar to the stand-alone
148 Info reader program, which visits the first subnode from the menu only
149 when you hit the end of the current node."
153 (defvar Info-current-file nil
154 "Info file that Info is now looking at, or nil.
155 This is the name that was specified in Info, not the actual file name.
156 It doesn't contain directory names or file name extensions added by Info.
157 Can also be t when using `Info-on-current-buffer'.")
159 (defvar Info-current-subfile nil
160 "Info subfile that is actually in the *info* buffer now.
161 nil if current info file is not split into subfiles.")
163 (defvar Info-current-node nil
164 "Name of node that Info is now looking at, or nil.")
166 (defvar Info-tag-table-marker nil
167 "Marker pointing at beginning of current Info file's tag table.
168 Marker points nowhere if file has no tag table.")
170 (defvar Info-tag-table-buffer nil
171 "Buffer used for indirect tag tables.")
173 (defvar Info-current-file-completions nil
174 "Cached completion list for current Info file.")
176 (defvar Info-index-alternatives nil
177 "List of possible matches for last `Info-index' command.")
179 (defvar Info-standalone nil
180 "Non-nil if Emacs was started solely as an Info browser.")
182 (defvar Info-suffix-list
183 ;; The MS-DOS list should work both when long file names are
184 ;; supported (Windows 9X), and when only 8+3 file names are available.
185 (if (eq system-type
'ms-dos
)
186 '( (".gz" .
"gunzip")
188 (".bz2" .
("bzip2" "-dc"))
191 (".info.Z" .
"gunzip")
192 (".info.gz" .
"gunzip")
193 ("-info.Z" .
"gunzip")
194 ("-info.gz" .
"gunzip")
195 ("/index.gz".
"gunzip")
196 ("/index.z" .
"gunzip")
202 '( (".info.Z".
"uncompress")
203 (".info.Y".
"unyabba")
204 (".info.gz".
"gunzip")
205 (".info.z".
"gunzip")
206 (".info.bz2" .
("bzip2" "-dc"))
208 ("-info.Z".
"uncompress")
209 ("-info.Y".
"unyabba")
210 ("-info.gz".
"gunzip")
211 ("-info.bz2" .
("bzip2" "-dc"))
212 ("-info.z".
"gunzip")
214 ("/index.Z".
"uncompress")
215 ("/index.Y".
"unyabba")
216 ("/index.gz".
"gunzip")
217 ("/index.z".
"gunzip")
218 ("/index.bz2".
("bzip2" "-dc"))
224 (".bz2" .
("bzip2" "-dc"))
226 "List of file name suffixes and associated decoding commands.
227 Each entry should be (SUFFIX . STRING); the file is given to
228 the command as standard input.
230 STRING may be a list of strings. In that case, the first element is
231 the command name, and the rest are arguments to that command.
233 If STRING is nil, no decoding is done.
234 Because the SUFFIXes are tried in order, the empty string should
235 be last in the list.")
237 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
238 ;; First, on MS-DOS with no long file names support, delete some of
239 ;; the extension in FILENAME to make room.
240 (defun info-insert-file-contents-1 (filename suffix lfn
)
241 (if lfn
; long file names are supported
242 (concat filename suffix
)
243 (let* ((sans-exts (file-name-sans-extension filename
))
244 ;; How long is the extension in FILENAME (not counting the dot).
245 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
247 ;; SUFFIX starts with a dot. If FILENAME already has one,
248 ;; get rid of the one in SUFFIX (unless suffix is empty).
249 (or (and (<= ext-len
0)
250 (not (eq (aref filename
(1- (length filename
))) ?.
)))
251 (= (length suffix
) 0)
252 (setq suffix
(substring suffix
1)))
253 ;; How many chars of that extension should we keep?
254 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
255 ;; Get rid of the rest of the extension, and add SUFFIX.
256 (concat (substring filename
0 (- (length filename
)
257 (- ext-len ext-left
)))
260 (defun info-file-exists-p (filename)
261 (and (file-exists-p filename
)
262 (not (file-directory-p filename
))))
264 (defun info-insert-file-contents (filename &optional visit
)
265 "Insert the contents of an info file in the current buffer.
266 Do the right thing if the file has been compressed or zipped."
267 (let* ((tail Info-suffix-list
)
268 (lfn (or (not (fboundp 'msdos-long-file-names
))
269 (msdos-long-file-names)))
270 (check-short (and (fboundp 'msdos-long-file-names
)
272 fullname decoder done
)
273 (if (info-file-exists-p filename
)
274 ;; FILENAME exists--see if that name contains a suffix.
275 ;; If so, set DECODE accordingly.
279 (concat (regexp-quote (car (car tail
))) "$")
281 (setq tail
(cdr tail
)))
282 (setq fullname filename
283 decoder
(cdr (car tail
))))
284 ;; Try adding suffixes to FILENAME and see if we can find something.
285 (while (and tail
(not done
))
286 (setq fullname
(info-insert-file-contents-1 filename
287 (car (car tail
)) lfn
))
288 (if (info-file-exists-p fullname
)
290 ;; If we found a file with a suffix, set DECODER
291 ;; according to the suffix.
292 decoder
(cdr (car tail
)))
293 ;; When the MS-DOS port runs on Windows, we need to check
294 ;; the short variant of a long file name as well.
296 (setq fullname
(info-insert-file-contents-1 filename
297 (car (car tail
)) nil
))
298 (if (info-file-exists-p fullname
)
300 decoder
(cdr (car tail
))))))
301 (setq tail
(cdr tail
)))
303 (error "Can't find %s or any compressed version of it" filename
)))
304 ;; check for conflict with jka-compr
305 (if (and (featurep 'jka-compr
)
306 (jka-compr-installed-p)
307 (jka-compr-get-compression-info fullname
))
311 (insert-file-contents-literally fullname visit
)
312 (let ((buffer-read-only nil
)
313 (coding-system-for-write 'no-conversion
)
314 (default-directory (or (file-name-directory fullname
)
317 (setq decoder
(list decoder
)))
318 (apply 'call-process-region
(point-min) (point-max)
319 (car decoder
) t t nil
(cdr decoder
))))
320 (insert-file-contents fullname visit
))))
322 (defun info-initialize ()
323 "Initialize `Info-directory-list', if that hasn't been done yet."
324 (unless Info-directory-list
325 (let ((path (getenv "INFOPATH"))
326 (source (expand-file-name "info/" source-directory
))
327 (sibling (if installation-directory
328 (expand-file-name "info/" installation-directory
)
329 (if invocation-directory
330 (let ((infodir (expand-file-name
332 invocation-directory
)))
333 (if (file-exists-p infodir
)
335 (setq infodir
(expand-file-name
337 invocation-directory
))
338 (and (file-exists-p infodir
)
341 (setq Info-directory-list
342 (prune-directory-list
344 (split-string path
(regexp-quote path-separator
))
345 (if (and sibling
(file-exists-p sibling
))
346 ;; Uninstalled, Emacs builddir != srcdir.
347 (setq alternative sibling
)
348 ;; Uninstalled, builddir == srcdir
349 (setq alternative source
))
350 (if (or (member alternative Info-default-directory-list
)
351 ;; On DOS/NT, we use movable executables always,
352 ;; and we must always find the Info dir at run time.
353 (if (memq system-type
'(ms-dos windows-nt
))
355 ;; Use invocation-directory for Info
356 ;; only if we used it for exec-directory also.
357 (not (string= exec-directory
358 (expand-file-name "lib-src/"
359 installation-directory
))))
360 (not (file-exists-p alternative
)))
361 Info-default-directory-list
362 ;; `alternative' contains the Info files that came with this
363 ;; version, so we should look there first. `Info-insert-dir'
364 ;; currently expects to find `alternative' first on the list.
366 (reverse (cdr (reverse Info-default-directory-list
)))))))))))
369 (defun info-other-window (&optional file
)
370 "Like `info' but show the Info buffer in another window."
371 (interactive (if current-prefix-arg
372 (list (read-file-name "Info file name: " nil nil t
))))
373 (let (same-window-buffer-names)
376 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
379 (defun info (&optional file
)
380 "Enter Info, the documentation browser.
381 Optional argument FILE specifies the file to examine;
382 the default is the top-level directory of Info.
383 Called from a program, FILE may specify an Info node of the form
384 `(FILENAME)NODENAME'.
386 In interactive use, a prefix argument directs this command
387 to read a file name from the minibuffer.
389 The search path for Info files is in the variable `Info-directory-list'.
390 The top-level Info directory is made by combining all the files named `dir'
391 in all the directories in that path."
392 (interactive (if current-prefix-arg
393 (list (read-file-name "Info file name: " nil nil t
))))
396 (pop-to-buffer "*info*")
397 ;; If argument already contains parentheses, don't add another set
398 ;; since the argument will then be parsed improperly. This also
399 ;; has the added benefit of allowing node names to be included
400 ;; following the parenthesized filename.
401 (if (and (stringp file
) (string-match "(.*)" file
))
402 (Info-goto-node file
)
403 (Info-goto-node (concat "(" file
")"))))
404 (if (get-buffer "*info*")
405 (pop-to-buffer "*info*")
409 (defun info-standalone ()
410 "Run Emacs as a standalone Info reader.
411 Usage: emacs -f info-standalone [filename]
412 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
413 (setq Info-standalone t
)
414 (if (and command-line-args-left
415 (not (string-match "^-" (car command-line-args-left
))))
418 (info (car command-line-args-left
))
419 (setq command-line-args-left
(cdr command-line-args-left
)))
420 (error (send-string-to-terminal
421 (format "%s\n" (if (eq (car-safe err
) 'error
)
423 (save-buffers-kill-emacs)))
426 ;; See if the accessible portion of the buffer begins with a node
427 ;; delimiter, and the node header line which follows matches REGEXP.
428 ;; Typically, this test will be followed by a loop that examines the
429 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
430 ;; to have the overhead of this special test inside the loop.
432 ;; This function changes match-data, but supposedly the caller might
433 ;; want to use the results of re-search-backward.
435 ;; The return value is the value of point at the beginning of matching
436 ;; REGEXP, if the function succeeds, nil otherwise.
437 (defun Info-node-at-bob-matching (regexp)
438 (and (bobp) ; are we at beginning of buffer?
439 (looking-at "\^_") ; does it begin with node delimiter?
443 (forward-line 1) ; does the line after delimiter match REGEXP?
444 (re-search-backward regexp beg t
))))
446 (defun Info-find-node (filename nodename
&optional no-going-back
)
447 "Go to an info node specified as separate FILENAME and NODENAME.
448 NO-GOING-BACK is non-nil if recovering from an error in this function;
449 it says do not attempt further (recursive) error recovery."
451 ;; Convert filename to lower case if not found as specified.
453 (if (stringp filename
)
454 (let (temp temp-downcase found
)
455 (setq filename
(substitute-in-file-name filename
))
456 (if (string= (downcase filename
) "dir")
458 (let ((dirs (if (string-match "^\\./" filename
)
459 ;; If specified name starts with `./'
460 ;; then just try current directory.
462 (if (file-name-absolute-p filename
)
463 ;; No point in searching for an
464 ;; absolute file name
466 (if Info-additional-directory-list
467 (append Info-directory-list
468 Info-additional-directory-list
)
469 Info-directory-list
)))))
470 ;; Search the directory list for file FILENAME.
471 (while (and dirs
(not found
))
472 (setq temp
(expand-file-name filename
(car dirs
)))
474 (expand-file-name (downcase filename
) (car dirs
)))
475 ;; Try several variants of specified name.
476 (let ((suffix-list Info-suffix-list
)
477 (lfn (or (not (fboundp 'msdos-long-file-names
))
478 (msdos-long-file-names))))
479 (while (and suffix-list
(not found
))
480 (cond ((info-file-exists-p
481 (info-insert-file-contents-1
482 temp
(car (car suffix-list
)) lfn
))
485 (info-insert-file-contents-1
486 temp-downcase
(car (car suffix-list
)) lfn
))
487 (setq found temp-downcase
))
488 ((and (fboundp 'msdos-long-file-names
)
491 (info-insert-file-contents-1
492 temp
(car (car suffix-list
)) nil
)))
494 (setq suffix-list
(cdr suffix-list
))))
495 (setq dirs
(cdr dirs
)))))
497 (setq filename found
)
498 (error "Info file %s does not exist" filename
))))
499 ;; Record the node we are leaving.
500 (if (and Info-current-file
(not no-going-back
))
502 (cons (list Info-current-file Info-current-node
(point))
504 ;; Go into info buffer.
505 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
506 (Info-find-node-2 filename nodename no-going-back
))
508 (defun Info-on-current-buffer (&optional nodename
)
509 "Use the `Info-mode' to browse the current info buffer.
510 If a prefix arg is provided, it queries for the NODENAME which
511 else defaults to \"Top\"."
513 (list (if current-prefix-arg
514 (completing-read "Node name: " (Info-build-node-completions)
516 (unless nodename
(setq nodename
"Top"))
519 (set (make-local-variable 'Info-current-file
) t
)
520 (Info-find-node-2 nil nodename
))
522 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
523 "Find a node in a tag table.
524 MARKER specifies the buffer and position to start searching at.
525 REGEXP is a regular expression matching nodes or references. Its first
526 group should match `Node:' or `Ref:'.
527 CASE-FOLD t means search for a case-insensitive match.
528 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
529 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
530 where the match was found, and MODE is `major-mode' of the buffer in
531 which the match was found."
532 (let ((case-fold-search case-fold
)
533 found-mode guesspos found-anchor
)
535 (set-buffer (marker-buffer marker
))
540 (when (re-search-forward regexp nil t
)
541 (list (string-equal "Ref:" (match-string 1))
542 (+ (point-min) (read (current-buffer)))
545 (defun Info-find-in-tag-table (marker regexp
)
546 "Find a node in a tag table.
547 MARKER specifies the buffer and position to start searching at.
548 REGEXP is a regular expression matching nodes or references. Its first
549 group should match `Node:' or `Ref:'.
550 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
551 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
552 where the match was found, and MODE is `major-mode' of the buffer in
553 which the match was found.
554 This function tries to find a case-sensitive match first, then a
555 case-insensitive match is tried."
556 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
557 (when (null (car result
))
558 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
561 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
562 "Find a node or anchor in the current buffer.
563 REGEXP is a regular expression matching nodes or references. Its first
564 group should match `Node:' or `Ref:'.
565 CASE-FOLD t means search for a case-insensitive match.
566 Value is the position at which a match was found, or nil if not found."
567 (let ((case-fold-search case-fold
)
570 (when (Info-node-at-bob-matching regexp
)
571 (setq found
(point)))
572 (while (and (not found
)
573 (search-forward "\n\^_" nil t
))
577 (when (re-search-backward regexp beg t
)
579 (setq found
(point)))))
582 (defun Info-find-node-in-buffer (regexp)
583 "Find a node or anchor in the current buffer.
584 REGEXP is a regular expression matching nodes or references. Its first
585 group should match `Node:' or `Ref:'.
586 Value is the position at which a match was found, or nil if not found.
587 This function looks for a case-sensitive match first. If none is found,
588 a case-insensitive match is tried."
589 (or (Info-find-node-in-buffer-1 regexp nil
)
590 (Info-find-node-in-buffer-1 regexp t
)))
592 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
593 (buffer-disable-undo (current-buffer))
594 (or (eq major-mode
'Info-mode
)
597 (setq Info-current-node nil
)
599 (let ((case-fold-search t
)
601 ;; Switch files if necessary
603 (equal Info-current-file filename
)
604 (let ((buffer-read-only nil
))
605 (setq Info-current-file nil
606 Info-current-subfile nil
607 Info-current-file-completions nil
608 buffer-file-name nil
)
612 (info-insert-file-contents filename nil
)
613 (setq default-directory
(file-name-directory filename
)))
614 (set-buffer-modified-p nil
)
615 ;; See whether file has a tag table. Record the location if yes.
616 (goto-char (point-max))
618 ;; Use string-equal, not equal, to ignore text props.
619 (if (not (or (string-equal nodename
"*")
621 (search-forward "\^_\nEnd tag table\n" nil t
))))
623 ;; We have a tag table. Find its beginning.
624 ;; Is this an indirect file?
625 (search-backward "\nTag table:\n")
629 (looking-at "(Indirect)\n"))
630 ;; It is indirect. Copy it to another buffer
631 ;; and record that the tag table is in that buffer.
632 (let ((buf (current-buffer))
634 (or Info-tag-table-buffer
635 (generate-new-buffer " *info tag table*"))))
636 (setq Info-tag-table-buffer tagbuf
)
639 (buffer-disable-undo (current-buffer))
640 (setq case-fold-search t
)
642 (insert-buffer-substring buf
))
643 (set-marker Info-tag-table-marker
644 (match-end 0) tagbuf
))
645 (set-marker Info-tag-table-marker pos
)))
646 (set-marker Info-tag-table-marker nil
))
647 (setq Info-current-file
648 (if (eq filename t
) "dir" filename
))))
649 ;; Use string-equal, not equal, to ignore text props.
650 (if (string-equal nodename
"*")
651 (progn (setq Info-current-node nodename
)
652 (Info-set-mode-line))
655 ;; 1. Anchor found in tag table
656 ;; 2. Anchor *not* in tag table
658 ;; 3. Node found in tag table
659 ;; 4. Node *not* found in tag table, but found in file
660 ;; 5. Node *not* in tag table, and *not* in file
662 ;; *Or* the same, but in an indirect subfile.
664 ;; Search file for a suitable node.
665 (let ((guesspos (point-min))
666 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
667 (if (stringp nodename
)
668 (regexp-quote nodename
)
675 ;; First, search a tag table, if any
676 (when (marker-position Info-tag-table-marker
)
677 (let* ((m Info-tag-table-marker
)
678 (found (Info-find-in-tag-table m regexp
)))
681 ;; FOUND is (ANCHOR POS MODE).
682 (setq guesspos
(nth 1 found
))
684 ;; If this is an indirect file, determine which
685 ;; file really holds this node and read it in.
686 (unless (eq (nth 2 found
) 'Info-mode
)
687 ;; Note that the current buffer must be the
688 ;; *info* buffer on entry to
689 ;; Info-read-subfile. Thus the hackery above.
690 (setq guesspos
(Info-read-subfile guesspos
)))
694 (goto-char (setq anchorpos guesspos
))
697 ;; Else we may have a node, which we search for:
698 (goto-char (max (point-min)
699 (- (byte-to-position guesspos
) 1000)))
701 ;; Now search from our advised position (or from beg of
702 ;; buffer) to find the actual node. First, check
703 ;; whether the node is right where we are, in case the
704 ;; buffer begins with a node.
705 (let ((pos (Info-find-node-in-buffer regexp
)))
709 (error "No such anchor in tag table or node in tag table or file: %s"
713 (goto-char (or anchorpos
(point-min))))))
714 ;; If we did not finish finding the specified node,
715 ;; go back to the previous one.
716 (or Info-current-node no-going-back
(null Info-history
)
717 (let ((hist (car Info-history
)))
718 (setq Info-history
(cdr Info-history
))
719 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
720 (goto-char (nth 2 hist
))))))
722 ;; Cache the contents of the (virtual) dir file, once we have merged
723 ;; it for the first time, so we can save time subsequently.
724 (defvar Info-dir-contents nil
)
726 ;; Cache for the directory we decided to use for the default-directory
727 ;; of the merged dir text.
728 (defvar Info-dir-contents-directory nil
)
730 ;; Record the file attributes of all the files from which we
731 ;; constructed Info-dir-contents.
732 (defvar Info-dir-file-attributes nil
)
734 (defvar Info-dir-file-name nil
)
736 ;; Construct the Info directory node by merging the files named `dir'
737 ;; from various directories. Set the *info* buffer's
738 ;; default-directory to the first directory we actually get any text
740 (defun Info-insert-dir ()
741 (if (and Info-dir-contents Info-dir-file-attributes
742 ;; Verify that none of the files we used has changed
745 (mapcar (lambda (elt)
746 (let ((curr (file-attributes
748 (file-truename (car elt
)))))
750 ;; Don't compare the access time.
751 (if curr
(setcar (nthcdr 4 curr
) 0))
752 (setcar (nthcdr 4 (cdr elt
)) 0)
753 (equal (cdr elt
) curr
)))
754 Info-dir-file-attributes
))))
756 (insert Info-dir-contents
)
757 (goto-char (point-min)))
758 (let ((dirs (if Info-additional-directory-list
759 (append Info-directory-list
760 Info-additional-directory-list
)
761 Info-directory-list
))
762 ;; Bind this in case the user sets it to nil.
764 ;; This is set non-nil if we find a problem in some input files.
766 buffers buffer others nodes dirs-done
)
768 (setq Info-dir-file-attributes nil
)
770 ;; Search the directory list for the directory file.
772 (let ((truename (file-truename (expand-file-name (car dirs
)))))
773 (or (member truename dirs-done
)
774 (member (directory-file-name truename
) dirs-done
)
775 ;; Try several variants of specified name.
776 ;; Try upcasing, appending `.info', or both.
780 (progn (setq file
(expand-file-name "dir" truename
))
781 (file-attributes file
))
782 (progn (setq file
(expand-file-name "DIR" truename
))
783 (file-attributes file
))
784 (progn (setq file
(expand-file-name "dir.info" truename
))
785 (file-attributes file
))
786 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
787 (file-attributes file
)))))
790 (cons (directory-file-name truename
)
795 (message "Composing main Info directory..."))
796 (set-buffer (generate-new-buffer " info dir"))
799 (insert-file-contents file
)
800 (make-local-variable 'Info-dir-file-name
)
801 (setq Info-dir-file-name file
)
802 (setq buffers
(cons (current-buffer) buffers
)
803 Info-dir-file-attributes
804 (cons (cons file attrs
)
805 Info-dir-file-attributes
)))
806 (error (kill-buffer (current-buffer))))))))
807 (or (cdr dirs
) (setq Info-dir-contents-directory
808 (file-name-as-directory (car dirs
))))
809 (setq dirs
(cdr dirs
))))
812 (error "Can't find the Info directory node"))
813 ;; Distinguish the dir file that comes with Emacs from all the
814 ;; others. Yes, that is really what this is supposed to do.
815 ;; The definition of `Info-directory-list' puts it first on that
816 ;; list and so last in `buffers' at this point.
817 (setq buffer
(car (last buffers
))
818 others
(delq buffer buffers
))
820 ;; Insert the entire original dir file as a start; note that we've
821 ;; already saved its default directory to use as the default
822 ;; directory for the whole concatenation.
823 (insert-buffer buffer
)
825 ;; Look at each of the other buffers one by one.
827 (let ((other (car others
))
828 ;; Bind this in case the user sets it to nil.
831 ;; In each, find all the menus.
834 (goto-char (point-min))
835 ;; Find each menu, and add an elt to NODES for it.
836 (while (re-search-forward "^\\* Menu:" nil t
)
837 (let (beg nodename end
)
839 (while (and (eolp) (not (eobp)))
842 (or (search-backward "\n\^_" nil
'move
)
844 (signal 'search-failed
(list "\n\^_")))
845 (search-forward "Node: ")
846 (setq nodename
(Info-following-node-name))
847 (search-forward "\n\^_" nil
'move
)
850 (setq this-buffer-nodes
851 (cons (list nodename other beg end
)
852 this-buffer-nodes
))))
853 (if (assoc-ignore-case "top" this-buffer-nodes
)
854 (setq nodes
(nconc this-buffer-nodes nodes
))
856 (message "No `top' node in %s" Info-dir-file-name
))))
857 (setq others
(cdr others
)))
858 ;; Add to the main menu a menu item for each other node.
859 (let ((case-fold-search t
)
860 (re-search-forward "^\\* Menu:")))
862 (let ((menu-items '("top"))
865 (end (save-excursion (search-forward "\^_" nil t
) (point))))
867 (let ((nodename (car (car nodes
))))
869 (or (member (downcase nodename
) menu-items
)
870 (re-search-forward (concat "^\\* +"
871 (regexp-quote nodename
)
875 (insert "* " nodename
"::" "\n")
876 (setq menu-items
(cons nodename menu-items
))))))
877 (setq nodes
(cdr nodes
))))
878 ;; Now take each node of each of the other buffers
879 ;; and merge it into the main buffer.
881 (let ((case-fold-search t
)
882 (nodename (car (car nodes
))))
883 (goto-char (point-min))
884 ;; Find the like-named node in the main buffer.
885 (if (re-search-forward (concat "^\^_.*\n.*Node: "
886 (regexp-quote nodename
)
890 (search-forward "\n\^_" nil
'move
)
893 ;; If none exists, add one.
894 (goto-char (point-max))
895 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
896 ;; Merge the text from the other buffer's menu
897 ;; into the menu in the like-named node in the main buffer.
898 (apply 'insert-buffer-substring
(cdr (car nodes
))))
899 (setq nodes
(cdr nodes
)))
900 ;; Kill all the buffers we just made.
902 (kill-buffer (car buffers
))
903 (setq buffers
(cdr buffers
)))
904 (goto-char (point-min))
906 (message "Composing main Info directory...problems encountered, see `*Messages*'")
907 (message "Composing main Info directory...done")))
908 (setq Info-dir-contents
(buffer-string)))
909 (setq default-directory Info-dir-contents-directory
))
911 ;; Note that on entry to this function the current-buffer must be the
912 ;; *info* buffer; not the info tags buffer.
913 (defun Info-read-subfile (nodepos)
914 ;; NODEPOS is either a position (in the Info file as a whole,
915 ;; not relative to a subfile) or the name of a subfile.
918 (if (numberp nodepos
)
920 (set-buffer (marker-buffer Info-tag-table-marker
))
921 (goto-char (point-min))
922 (or (looking-at "\^_")
923 (search-forward "\n\^_"))
926 (while (not (looking-at "\^_"))
929 thisfilepos thisfilename
)
930 (search-forward ": ")
931 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
932 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
933 ;; read in version 19 stops at the end of number.
934 ;; Advance to the next line.
936 (if (> thisfilepos nodepos
)
938 (setq lastfilename thisfilename
)
939 (setq lastfilepos thisfilepos
))
941 (setq lastfilename nodepos
)
942 (setq lastfilepos
0))
943 ;; Assume previous buffer is in Info-mode.
944 ;; (set-buffer (get-buffer "*info*"))
945 (or (equal Info-current-subfile lastfilename
)
946 (let ((buffer-read-only nil
))
947 (setq buffer-file-name nil
)
950 (info-insert-file-contents lastfilename
)
951 (set-buffer-modified-p nil
)
952 (setq Info-current-subfile lastfilename
)))
953 ;; Widen in case we are in the same subfile as before.
955 (goto-char (point-min))
956 (if (looking-at "\^_")
958 (search-forward "\n\^_"))
959 (if (numberp nodepos
)
960 (+ (- nodepos lastfilepos
) (point)))))
962 (defvar Info-header-line nil
963 "If the info node header is hidden, the text of the header.")
964 (put 'Info-header-line
'risky-local-variable t
)
966 (defun Info-select-node ()
967 "Select the info node that point is in.
968 Bind this in case the user sets it to nil."
969 (let ((case-fold-search t
))
971 ;; Find beginning of node.
972 (if (search-backward "\n\^_" nil
'move
)
974 (if (looking-at "\^_")
976 (signal 'search-failed
(list "\n\^_"))))
977 ;; Get nodename spelled as it is in the node.
978 (re-search-forward "Node:[ \t]*")
979 (setq Info-current-node
980 (buffer-substring-no-properties (point)
982 (skip-chars-forward "^,\t\n")
985 ;; Find the end of it, and narrow.
987 (let (active-expression)
988 ;; Narrow to the node contents
989 (narrow-to-region (point)
990 (if (re-search-forward "\n[\^_\f]" nil t
)
993 (if (looking-at "[\n\^_\f]*execute: ")
995 (goto-char (match-end 0))
996 (setq active-expression
997 (read (current-buffer))))))
999 (if Info-enable-active-nodes
(eval active-expression
))
1000 (if Info-fontify
(Info-fontify-node))
1001 (if Info-use-header-line
1002 (Info-setup-header-line)
1003 (setq Info-header-line nil
)
1004 (setq header-line-format nil
)) ; so the header line isn't displayed
1005 (run-hooks 'Info-selection-hook
)))))
1007 (defun Info-set-mode-line ()
1008 (setq mode-line-buffer-identification
1009 (nconc (propertized-buffer-identification "%b")
1012 (file-name-nondirectory
1013 (if (stringp Info-current-file
)
1015 (or buffer-file-name
"")))
1017 (or Info-current-node
""))))))
1019 ;; Skip the node header and make it into a header-line. This function
1020 ;; should be called when the node is already narrowed.
1021 (defun Info-setup-header-line ()
1022 (goto-char (point-min))
1023 (let* ((case-fold-search t
)
1024 (header-end (save-excursion (forward-line 1) (1- (point))))
1025 ;; If we find neither Next: nor Prev: link, show the entire
1026 ;; node header. Otherwise, don't show the File: and Node:
1027 ;; parts, to avoid wasting precious space on information that
1028 ;; is available in the mode line.
1029 (header-beg (if (re-search-forward
1030 "\\(next\\|prev[ious]*\\): "
1034 (set (make-local-variable 'Info-header-line
)
1035 (buffer-substring header-beg header-end
))
1036 (setq header-line-format
'Info-header-line
)
1037 (narrow-to-region (1+ header-end
) (point-max))))
1039 ;; Go to an info node specified with a filename-and-nodename string
1040 ;; of the sort that is found in pointers in nodes.
1042 (defun Info-goto-node (nodename &optional fork
)
1043 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1044 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1045 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1047 Completion is available, but only for node names in the current Info file.
1048 If FORK is non-nil (interactively with a prefix arg), show the node in
1050 If FORK is a string, it is the name to use for the new buffer."
1051 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1055 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1057 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1059 (setq filename
(if (= (match-beginning 1) (match-end 1))
1061 (substring nodename
(match-beginning 2) (match-end 2)))
1062 nodename
(substring nodename
(match-beginning 3) (match-end 3)))
1063 (let ((trim (string-match "\\s *\\'" filename
)))
1064 (if trim
(setq filename
(substring filename
0 trim
))))
1065 (let ((trim (string-match "\\s *\\'" nodename
)))
1066 (if trim
(setq nodename
(substring nodename
0 trim
))))
1067 (if transient-mark-mode
(deactivate-mark))
1068 (Info-find-node (if (equal filename
"") nil filename
)
1069 (if (equal nodename
"") "Top" nodename
))))
1071 (defvar Info-read-node-completion-table
)
1073 ;; This function is used as the "completion table" while reading a node name.
1074 ;; It does completion using the alist in Info-read-node-completion-table
1075 ;; unless STRING starts with an open-paren.
1076 (defun Info-read-node-name-1 (string predicate code
)
1078 ;; First complete embedded file names.
1079 ((string-match "\\`([^)]*\\'" string
)
1080 (let ((file (substring string
1)))
1083 (let ((comp (try-completion file
'locate-file-completion
1084 (cons Info-directory-list
1085 (mapcar 'car Info-suffix-list
)))))
1087 ((eq comp t
) (concat string
")"))
1088 (comp (concat "(" comp
)))))
1089 ((eq code t
) (all-completions file
'locate-file-completion
1090 (cons Info-directory-list
1091 (mapcar 'car Info-suffix-list
))))
1093 ;; If a file name was given, then any node is fair game.
1094 ((string-match "\\`(" string
)
1096 ((eq code nil
) string
)
1099 ;; Otherwise use Info-read-node-completion-table.
1101 (try-completion string Info-read-node-completion-table predicate
))
1103 (all-completions string Info-read-node-completion-table predicate
))
1105 (test-completion string Info-read-node-completion-table predicate
))))
1107 (defun Info-read-node-name (prompt &optional default
)
1108 (let* ((completion-ignore-case t
)
1109 (Info-read-node-completion-table (Info-build-node-completions))
1110 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1111 (if (equal nodename
"")
1113 (Info-read-node-name prompt
))
1116 (defun Info-build-node-completions ()
1117 (or Info-current-file-completions
1119 ;; Bind this in case the user sets it to nil.
1120 (case-fold-search t
)
1121 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1124 (if (marker-buffer Info-tag-table-marker
)
1125 (let ((marker Info-tag-table-marker
))
1126 (set-buffer (marker-buffer marker
))
1129 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1131 (cons (list (match-string-no-properties 2))
1134 (goto-char (point-min))
1135 ;; If the buffer begins with a node header, process that first.
1136 (if (Info-node-at-bob-matching node-regexp
)
1137 (setq compl
(list (match-string-no-properties 1))))
1138 ;; Now for the rest of the nodes.
1139 (while (search-forward "\n\^_" nil t
)
1141 (let ((beg (point)))
1143 (if (re-search-backward node-regexp beg t
)
1145 (cons (list (match-string-no-properties 1))
1147 (setq compl
(cons '("*") compl
))
1148 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1150 (defun Info-restore-point (hl)
1151 "If this node has been visited, restore the point value when we left."
1153 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1154 ;; Use string-equal, not equal, to ignore text props.
1155 (string-equal (nth 1 (car hl
)) Info-current-node
))
1157 (goto-char (nth 2 (car hl
)))
1158 (setq hl nil
)) ;terminate the while at next iter
1159 (setq hl
(cdr hl
)))))
1161 (defvar Info-search-history nil
1162 "The history list for `Info-search'.")
1164 (defun Info-search (regexp)
1165 "Search for REGEXP, starting from point, and select node it's found in."
1166 (interactive (list (read-string
1167 (if Info-search-history
1168 (format "Regexp search (default `%s'): "
1169 (car Info-search-history
))
1171 nil
'Info-search-history
)))
1172 (when transient-mark-mode
1174 (when (equal regexp
"")
1175 (setq regexp
(car Info-search-history
)))
1177 (let ((found ()) current
1178 (onode Info-current-node
)
1179 (ofile Info-current-file
)
1181 (ostart (window-start))
1182 (osubfile Info-current-subfile
))
1186 (if (null Info-current-subfile
)
1187 (progn (re-search-forward regexp
) (setq found
(point)))
1189 (progn (re-search-forward regexp
) (setq found
(point)))
1190 (search-failed nil
)))))
1191 (if (not found
) ;can only happen in subfile case -- else would have erred
1195 (set-buffer (marker-buffer Info-tag-table-marker
))
1196 (goto-char (point-min))
1197 (search-forward "\n\^_\nIndirect:")
1199 (narrow-to-region (point)
1200 (progn (search-forward "\n\^_")
1202 (goto-char (point-min))
1203 (search-forward (concat "\n" osubfile
": "))
1206 (re-search-forward "\\(^.*\\): [0-9]+$")
1207 (goto-char (+ (match-end 1) 2))
1208 (setq list
(cons (cons (read (current-buffer))
1209 (match-string-no-properties 1))
1211 (goto-char (1+ (match-end 0))))
1212 (setq list
(nreverse list
)
1213 current
(car (car list
))
1216 (message "Searching subfile %s..." (cdr (car list
)))
1217 (Info-read-subfile (car (car list
)))
1218 (setq list
(cdr list
))
1219 (if (re-search-forward regexp nil t
)
1220 (setq found
(point) list
())))
1223 (signal 'search-failed
(list regexp
))))
1225 (progn (Info-read-subfile osubfile
)
1228 (set-window-start (selected-window) ostart
)))))
1232 ;; Use string-equal, not equal, to ignore text props.
1233 (or (and (string-equal onode Info-current-node
)
1234 (equal ofile Info-current-file
))
1235 (setq Info-history
(cons (list ofile onode opoint
)
1238 (defun Info-extract-pointer (name &optional errorname
)
1239 "Extract the value of the node-pointer named NAME.
1240 If there is none, use ERRORNAME in the error message;
1241 if ERRORNAME is nil, just return nil.
1242 Bind this in case the user sets it to nil."
1243 (let ((case-fold-search t
))
1246 (goto-char (point-min))
1247 (when Info-header-line
1248 ;; expose the header line in the buffer
1251 (let ((bound (point)))
1253 (cond ((re-search-backward (concat name
":") bound t
)
1254 (goto-char (match-end 0))
1255 (Info-following-node-name))
1256 ((not (eq errorname t
))
1257 (error "Node has no %s"
1258 (capitalize (or errorname name
))))))))))
1260 (defun Info-following-node-name (&optional allowedchars
)
1261 "Return the node name in the buffer following point.
1262 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1263 saying which chars may appear in the node name."
1264 (skip-chars-forward " \t")
1265 (buffer-substring-no-properties
1268 (while (looking-at (concat "[" (or allowedchars
"^,\t\n") "]"))
1269 (skip-chars-forward (concat (or allowedchars
"^,\t\n") "("))
1270 (if (looking-at "(")
1271 (skip-chars-forward "^)")))
1272 (skip-chars-backward " ")
1276 "Go to the next node of this node."
1278 (Info-goto-node (Info-extract-pointer "next")))
1281 "Go to the previous node of this node."
1283 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1285 (defun Info-up (&optional same-file
)
1286 "Go to the superior node of this node.
1287 If SAME-FILE is non-nil, do not move to a different Info file."
1289 (let ((node (Info-extract-pointer "up")))
1290 (and (or same-file
(not (stringp Info-current-file
)))
1291 (string-match "^(" node
)
1292 (error "Up node is in another Info file"))
1293 (Info-goto-node node
))
1294 (Info-restore-point Info-history
))
1297 "Go back to the last node visited."
1300 (error "This is the first Info node you looked at"))
1301 (let (filename nodename opoint
)
1302 (setq filename
(car (car Info-history
)))
1303 (setq nodename
(car (cdr (car Info-history
))))
1304 (setq opoint
(car (cdr (cdr (car Info-history
)))))
1305 (setq Info-history
(cdr Info-history
))
1306 (Info-find-node filename nodename
)
1307 (setq Info-history
(cdr Info-history
))
1308 (goto-char opoint
)))
1311 (defun Info-directory ()
1312 "Go to the Info directory node."
1314 (Info-find-node "dir" "top"))
1316 (defun Info-follow-reference (footnotename)
1317 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1318 FOOTNOTENAME may be an abbreviation of the reference name."
1320 (let ((completion-ignore-case t
)
1321 (case-fold-search t
)
1322 completions default alt-default
(start-point (point)) str i bol eol
)
1324 ;; Store end and beginning of line.
1330 (goto-char (point-min))
1331 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
1332 (setq str
(buffer-substring-no-properties
1335 ;; See if this one should be the default.
1337 (<= (match-beginning 0) start-point
)
1338 (<= start-point
(point))
1340 ;; See if this one should be the alternate default.
1341 (and (null alt-default
)
1342 (and (<= bol
(match-beginning 0))
1344 (setq alt-default t
))
1346 (while (setq i
(string-match "[ \n\t]+" str i
))
1347 (setq str
(concat (substring str
0 i
) " "
1348 (substring str
(match-end 0))))
1350 ;; Record as a completion and perhaps as default.
1351 (if (eq default t
) (setq default str
))
1352 (if (eq alt-default t
) (setq alt-default str
))
1353 ;; Don't add this string if it's a duplicate.
1354 ;; We use a loop instead of "(assoc str completions)" because
1355 ;; we want to do a case-insensitive compare.
1356 (let ((tail completions
)
1357 (tem (downcase str
)))
1359 (not (string-equal tem
(downcase (car (car tail
))))))
1360 (setq tail
(cdr tail
)))
1363 (cons (cons str nil
)
1365 ;; If no good default was found, try an alternate.
1367 (setq default alt-default
))
1368 ;; If only one cross-reference found, then make it default.
1369 (if (eq (length completions
) 1)
1370 (setq default
(car (car completions
))))
1372 (let ((input (completing-read (if default
1374 "Follow reference named: (default "
1376 "Follow reference named: ")
1377 completions nil t
)))
1378 (list (if (equal input
"")
1380 (error "No cross-references in this node"))))
1382 (unless footnotename
1383 (error "No reference was specified"))
1385 (let (target beg i
(str (concat "\\*note " (regexp-quote footnotename
)))
1386 (case-fold-search t
))
1387 (while (setq i
(string-match " " str i
))
1388 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
1391 (goto-char (point-min))
1392 (or (re-search-forward str nil t
)
1393 (error "No cross-reference named %s" footnotename
))
1394 (goto-char (+ (match-beginning 0) 5))
1396 (Info-extract-menu-node-name "Bad format cross reference" t
)))
1397 (while (setq i
(string-match "[ \t\n]+" target i
))
1398 (setq target
(concat (substring target
0 i
) " "
1399 (substring target
(match-end 0))))
1401 (Info-goto-node target
)))
1403 (defun Info-extract-menu-node-name (&optional errmessage multi-line
)
1404 (skip-chars-forward " \t\n")
1407 (skip-chars-forward "^:")
1410 (if (looking-at ":")
1411 (buffer-substring-no-properties beg
(1- (point)))
1412 (skip-chars-forward " \t\n")
1413 (Info-following-node-name (if multi-line
"^.,\t" "^.,\t\n"))))
1414 (replace-regexp-in-string "[ \n]+" " " str
)))
1416 ;; No one calls this.
1417 ;;(defun Info-menu-item-sequence (list)
1419 ;; (Info-menu (car list))
1420 ;; (setq list (cdr list))))
1422 (defvar Info-complete-menu-buffer
)
1423 (defvar Info-complete-next-re nil
)
1424 (defvar Info-complete-cache nil
)
1426 (defun Info-complete-menu-item (string predicate action
)
1427 ;; This uses two dynamically bound variables:
1428 ;; - `Info-complete-menu-buffer' which contains the buffer in which
1429 ;; is the menu of items we're trying to complete.
1430 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
1431 ;; also look for menu items in subsequent nodes as long as those
1432 ;; nodes' names match `Info-complete-next-re'. This feature is currently
1433 ;; only used for completion in Info-index.
1435 (set-buffer Info-complete-menu-buffer
)
1436 (let ((completion-ignore-case t
)
1437 (case-fold-search t
)
1438 (orignode Info-current-node
)
1440 (goto-char (point-min))
1441 (search-forward "\n* Menu:")
1442 (if (not (memq action
'(nil t
)))
1444 (concat "\n\\* +" (regexp-quote string
) ":") nil t
)
1445 (let ((pattern (concat "\n\\* +\\("
1446 (regexp-quote string
)
1450 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
1451 (equal (nth 1 Info-complete-cache
) Info-current-node
)
1452 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
1453 (let ((prev (nth 3 Info-complete-cache
)))
1454 (eq t
(compare-strings string
0 (length prev
)
1456 ;; We can reuse the previous list.
1457 (setq completions
(nth 4 Info-complete-cache
))
1458 ;; The cache can't be used.
1461 (while (re-search-forward pattern nil t
)
1462 (push (match-string-no-properties 1)
1464 ;; Check subsequent nodes if applicable.
1465 (and Info-complete-next-re
1466 (setq nextnode
(Info-extract-pointer "next" t
))
1467 (string-match Info-complete-next-re nextnode
)))
1468 (Info-goto-node nextnode
))
1469 ;; Go back to the start node (for the next completion).
1470 (unless (equal Info-current-node orignode
)
1471 (Info-goto-node orignode
))
1472 ;; Update the cache.
1473 (setq Info-complete-cache
1474 (list Info-current-file Info-current-node
1475 Info-complete-next-re string completions
)))
1477 (all-completions string completions predicate
)
1478 (try-completion string completions predicate
)))))))
1481 (defun Info-menu (menu-item &optional fork
)
1482 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
1483 The menu item should one of those listed in the current node's menu.
1484 Completion is allowed, and the default menu item is the one point is on.
1485 If FORK is non-nil (interactively with a prefix arg), show the node in
1486 a new info buffer. If FORK is a string, it is the name to use for the
1489 (let ((completions '())
1490 ;; If point is within a menu item, use that item as the default
1495 (case-fold-search t
))
1497 (goto-char (point-min))
1498 (if (not (search-forward "\n* menu:" nil t
))
1499 (error "No menu in this node"))
1505 (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t
)
1506 (setq default
(match-string-no-properties 1))))))
1509 (setq item
(let ((completion-ignore-case t
)
1510 (Info-complete-menu-buffer (current-buffer)))
1511 (completing-read (if default
1512 (format "Menu item (default %s): "
1515 'Info-complete-menu-item nil t
)))
1516 ;; we rely on the fact that completing-read accepts an input
1517 ;; of "" even when the require-match argument is true and ""
1518 ;; is not a valid possibility
1519 (if (string= item
"")
1524 (list item current-prefix-arg
))))
1525 ;; there is a problem here in that if several menu items have the same
1526 ;; name you can only go to the node of the first with this command.
1527 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
1529 (defun Info-extract-menu-item (menu-item)
1530 (setq menu-item
(regexp-quote menu-item
))
1531 (let ((case-fold-search t
))
1533 (let ((case-fold-search t
))
1534 (goto-char (point-min))
1535 (or (search-forward "\n* menu:" nil t
)
1536 (error "No menu in this node"))
1537 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
1538 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
1539 (error "No such item in menu"))
1542 (Info-extract-menu-node-name)))))
1544 ;; If COUNT is nil, use the last item in the menu.
1545 (defun Info-extract-menu-counting (count)
1546 (let ((case-fold-search t
))
1548 (let ((case-fold-search t
))
1549 (goto-char (point-min))
1550 (or (search-forward "\n* menu:" nil t
)
1551 (error "No menu in this node"))
1553 (or (search-forward "\n* " nil t count
)
1554 (error "Too few items in menu"))
1555 (while (search-forward "\n* " nil t
)
1557 (Info-extract-menu-node-name)))))
1559 (defun Info-nth-menu-item ()
1560 "Go to the node of the Nth menu item.
1561 N is the digit argument used to invoke this command."
1564 (Info-extract-menu-counting
1565 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
1567 (defun Info-top-node ()
1568 "Go to the Top node of this file."
1570 (Info-goto-node "Top"))
1572 (defun Info-final-node ()
1573 "Go to the final node in this file."
1575 (Info-goto-node "Top")
1576 (let ((Info-history nil
)
1577 (case-fold-search t
))
1578 ;; Go to the last node in the menu of Top.
1579 (Info-goto-node (Info-extract-menu-counting nil
))
1580 ;; If the last node in the menu is not last in pointer structure,
1581 ;; move forward until we can't go any farther.
1582 (while (Info-forward-node t t
) nil
)
1583 ;; Then keep moving down to last subnode, unless we reach an index.
1584 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1585 (save-excursion (search-forward "\n* Menu:" nil t
)))
1586 (Info-goto-node (Info-extract-menu-counting nil
)))))
1588 (defun Info-forward-node (&optional not-down no-error
)
1589 "Go forward one node, considering all nodes as forming one sequence."
1591 (goto-char (point-min))
1593 (let ((case-fold-search t
))
1594 ;; three possibilities, in order of priority:
1595 ;; 1. next node is in a menu in this node (but not in an index)
1596 ;; 2. next node is next at same level
1597 ;; 3. next node is up and next
1598 (cond ((and (not not-down
)
1599 (save-excursion (search-forward "\n* menu:" nil t
))
1600 (not (string-match "\\<index\\>" Info-current-node
)))
1601 (Info-goto-node (Info-extract-menu-counting 1))
1606 (when Info-header-line
1607 (goto-char (point-min))
1610 (setq limit
(point))
1612 (search-backward "next:" limit t
))))
1615 ((and (save-excursion
1618 (when Info-header-line
1619 (goto-char (point-min))
1622 (setq limit
(point))
1624 (search-backward "up:" limit t
))))
1625 ;; Use string-equal, not equal, to ignore text props.
1626 (not (string-equal (downcase (Info-extract-pointer "up"))
1628 (let ((old-node Info-current-node
))
1630 (let (Info-history success
)
1632 (setq success
(Info-forward-node t no-error
))
1633 (or success
(Info-goto-node old-node
))))))
1635 (t (error "No pointer forward from this node")))))
1637 (defun Info-backward-node ()
1638 "Go backward one node, considering all nodes as forming one sequence."
1640 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1641 (upnode (Info-extract-pointer "up" t
))
1642 (case-fold-search t
))
1643 (cond ((and upnode
(string-match "(" upnode
))
1644 (error "First node in file"))
1645 ((and upnode
(or (null prevnode
)
1646 ;; Use string-equal, not equal,
1647 ;; to ignore text properties.
1648 (string-equal (downcase prevnode
)
1649 (downcase upnode
))))
1652 ;; If we move back at the same level,
1653 ;; go down to find the last subnode*.
1656 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1657 (save-excursion (search-forward "\n* Menu:" nil t
)))
1658 (Info-goto-node (Info-extract-menu-counting nil
)))))
1660 (error "No pointer backward from this node")))))
1663 "Exit Info by selecting some other buffer."
1666 (save-buffers-kill-emacs)
1669 (defun Info-next-menu-item ()
1671 ;; Bind this in case the user sets it to nil.
1672 (let* ((case-fold-search t
)
1676 (search-forward "\n* menu:" nil t
)
1677 (and (search-forward "\n* " nil t
)
1678 (Info-extract-menu-node-name)))))
1679 (if node
(Info-goto-node node
)
1680 (error "No more items in menu"))))
1682 (defun Info-last-menu-item ()
1686 ;; Bind this in case the user sets it to nil.
1687 (let* ((case-fold-search t
)
1688 (beg (save-excursion
1689 (and (search-backward "\n* menu:" nil t
)
1691 (or (and beg
(search-backward "\n* " beg t
))
1692 (error "No previous items in menu")))
1693 (Info-goto-node (save-excursion
1694 (goto-char (match-end 0))
1695 (Info-extract-menu-node-name)))))
1697 (defmacro Info-no-error
(&rest body
)
1698 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1700 (defun Info-next-preorder ()
1701 "Go to the next subnode or the next node, or go up a level."
1703 (cond ((Info-no-error (Info-next-menu-item)))
1704 ((Info-no-error (Info-next)))
1705 ((Info-no-error (Info-up t
))
1706 ;; Since we have already gone thru all the items in this menu,
1707 ;; go up to the end of this node.
1708 (goto-char (point-max))
1709 ;; Since logically we are done with the node with that menu,
1711 (Info-next-preorder))
1713 (error "No more nodes"))))
1715 (defun Info-last-preorder ()
1716 "Go to the last node, popping up a level if there is none."
1718 (cond ((Info-no-error
1719 (Info-last-menu-item)
1720 ;; If we go down a menu item, go to the end of the node
1721 ;; so we can scroll back through it.
1722 (goto-char (point-max)))
1723 ;; Keep going down, as long as there are nested menu nodes.
1724 (while (Info-no-error
1725 (Info-last-menu-item)
1726 ;; If we go down a menu item, go to the end of the node
1727 ;; so we can scroll back through it.
1728 (goto-char (point-max))))
1730 ((and (Info-no-error (Info-extract-pointer "prev"))
1731 (not (equal (Info-extract-pointer "up")
1732 (Info-extract-pointer "prev"))))
1733 (Info-no-error (Info-prev))
1734 (goto-char (point-max))
1735 (while (Info-no-error
1736 (Info-last-menu-item)
1737 ;; If we go down a menu item, go to the end of the node
1738 ;; so we can scroll back through it.
1739 (goto-char (point-max))))
1741 ((Info-no-error (Info-up t
))
1742 (goto-char (point-min))
1743 (let ((case-fold-search t
))
1744 (or (search-forward "\n* Menu:" nil t
)
1745 (goto-char (point-max)))))
1746 (t (error "No previous nodes"))))
1748 (defun Info-scroll-up ()
1749 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1750 Once you scroll far enough in a node that its menu appears on the screen
1751 but after point, the next scroll moves into its first subnode, unless
1752 `Info-scroll-prefer-subnodes' is nil.
1754 When you scroll past the end of a node, that goes to the next node if
1755 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
1756 if this node has no successor, it moves to the parent node's successor,
1757 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
1758 the menu of a node, it moves to subnode indicated by the following menu
1759 item. (That case won't normally result from this command, but can happen
1763 (if (or (< (window-start) (point-min))
1764 (> (window-start) (point-max)))
1765 (set-window-start (selected-window) (point)))
1766 (let* ((case-fold-search t
)
1767 (virtual-end (save-excursion
1768 (goto-char (point-min))
1769 (if (and Info-scroll-prefer-subnodes
1770 (search-forward "\n* Menu:" nil t
))
1773 (if (or (< virtual-end
(window-start))
1774 (pos-visible-in-window-p virtual-end
))
1776 (Info-scroll-prefer-subnodes (Info-next-preorder))
1777 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
1778 (t (Info-next-preorder)))
1781 (defun Info-scroll-down ()
1782 "Scroll one screenful back in Info, considering all nodes as one sequence.
1783 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
1784 is non-nil, this goes to its last subnode. When you scroll past the
1785 beginning of a node, that goes to the previous node or back up to the
1788 (if (or (< (window-start) (point-min))
1789 (> (window-start) (point-max)))
1790 (set-window-start (selected-window) (point)))
1791 (let* ((case-fold-search t
)
1792 (current-point (point))
1794 (and Info-scroll-prefer-subnodes
1797 (setq current-point
(point))
1798 (goto-char (point-min))
1799 (search-forward "\n* Menu:"
1803 (pos-visible-in-window-p (point-min) nil t
))
1804 (Info-last-preorder)
1807 (defun Info-next-reference (&optional recur
)
1808 "Move cursor to the next cross-reference or menu item in the node."
1810 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1812 (case-fold-search t
))
1813 (or (eobp) (forward-char 1))
1814 (or (re-search-forward pat nil t
)
1816 (goto-char (point-min))
1817 (or (re-search-forward pat nil t
)
1820 (error "No cross references in this node")))))
1821 (goto-char (match-beginning 0))
1822 (if (looking-at "\\* Menu:")
1824 (error "No cross references in this node")
1825 (Info-next-reference t
)))))
1827 (defun Info-prev-reference (&optional recur
)
1828 "Move cursor to the previous cross-reference or menu item in the node."
1830 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1832 (case-fold-search t
))
1833 (or (re-search-backward pat nil t
)
1835 (goto-char (point-max))
1836 (or (re-search-backward pat nil t
)
1839 (error "No cross references in this node")))))
1840 (goto-char (match-beginning 0))
1841 (if (looking-at "\\* Menu:")
1843 (error "No cross references in this node")
1844 (Info-prev-reference t
)))))
1846 (defun Info-goto-index ()
1847 (Info-goto-node "Top")
1848 (or (search-forward "\n* menu:" nil t
)
1850 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
1852 (goto-char (match-beginning 1))
1853 ;; Protect Info-history so that the current node (Top) is not added to it.
1854 (let ((Info-history nil
))
1855 (Info-goto-node (Info-extract-menu-node-name))))
1857 (defun Info-index (topic)
1858 "Look up a string TOPIC in the index for this file.
1859 The index is defined as the first node in the top level menu whose
1860 name contains the word \"Index\", plus any immediately following
1861 nodes whose names also contain the word \"Index\".
1862 If there are no exact matches to the specified topic, this chooses
1863 the first match which is a case-insensitive substring of a topic.
1864 Use the `,' command to see the other matches.
1865 Give a blank topic name to go to the Index node itself."
1868 (let ((Info-complete-menu-buffer (clone-buffer))
1869 (Info-complete-next-re "\\<Index\\>"))
1871 (with-current-buffer Info-complete-menu-buffer
1873 (completing-read "Index topic: " 'Info-complete-menu-item
))
1874 (kill-buffer Info-complete-menu-buffer
)))))
1875 (let ((orignode Info-current-node
)
1877 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1878 (regexp-quote topic
)))
1880 (case-fold-search t
))
1882 (or (equal topic
"")
1885 ;; We bind Info-history to nil for internal node-switches so
1886 ;; that we don't put junk in the history. In the first
1887 ;; Info-goto-index call, above, we do update the history
1888 ;; because that is what the user's previous node choice into it.
1893 (goto-char (point-min))
1894 (while (re-search-forward pattern nil t
)
1895 (push (list (match-string-no-properties 1)
1896 (match-string-no-properties 2)
1898 (string-to-int (concat "0"
1901 (and (setq node
(Info-extract-pointer "next" t
))
1902 (string-match "\\<Index\\>" node
)))
1903 (Info-goto-node node
))
1906 (Info-goto-node orignode
)
1907 (error "No `%s' in index" topic
)))
1908 ;; Here it is a feature that assoc is case-sensitive.
1909 (while (setq found
(assoc topic matches
))
1910 (setq exact
(cons found exact
)
1911 matches
(delq found matches
)))
1912 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
1913 (Info-index-next 0)))))
1915 (defun Info-index-next (num)
1916 "Go to the next matching index item from the last `i' command."
1918 (or Info-index-alternatives
1919 (error "No previous `i' command"))
1921 (setq num
(+ num
(length Info-index-alternatives
))))
1923 (setq Info-index-alternatives
1924 (nconc (cdr Info-index-alternatives
)
1925 (list (car Info-index-alternatives
)))
1927 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
1928 (if (> (nth 3 (car Info-index-alternatives
)) 0)
1929 (forward-line (nth 3 (car Info-index-alternatives
)))
1930 (forward-line 3) ; don't search in headers
1931 (let ((name (car (car Info-index-alternatives
))))
1932 (Info-find-index-name name
)))
1933 (message "Found `%s' in %s. %s"
1934 (car (car Info-index-alternatives
))
1935 (nth 2 (car Info-index-alternatives
))
1936 (if (cdr Info-index-alternatives
)
1937 "(Press `,' for more)"
1940 (defun Info-find-index-name (name)
1941 "Move point to the place within the current node where NAME is defined."
1942 (let ((case-fold-search t
))
1943 (if (or (re-search-forward (format
1944 "[a-zA-Z]+: %s\\( \\|$\\)"
1945 (regexp-quote name
)) nil t
)
1946 (search-forward (format "`%s'" name
) nil t
)
1947 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
1949 (format "`%s'" (substring name
0 (match-beginning 1)))
1951 (search-forward name nil t
))
1953 (goto-char (point-min)))))
1955 (defun Info-undefined ()
1956 "Make command be undefined in Info."
1961 "Enter the Info tutorial."
1963 (delete-other-windows)
1964 (Info-find-node "info"
1965 (if (< (window-height) 23)
1969 (defun Info-summary ()
1970 "Display a brief summary of all Info commands."
1972 (save-window-excursion
1973 (switch-to-buffer "*Help*")
1974 (setq buffer-read-only nil
)
1976 (insert (documentation 'Info-mode
))
1978 (goto-char (point-min))
1980 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
1981 (message (if flag
"Type Space to see more"
1982 "Type Space to return to Info"))
1983 (if (not (eq ?\
(setq ch
(read-event))))
1984 (progn (setq unread-command-events
(list ch
)) nil
)
1987 (bury-buffer "*Help*")))
1989 (defun Info-get-token (pos start all
&optional errorstring
)
1990 "Return the token around POS.
1991 POS must be somewhere inside the token
1992 START is a regular expression which will match the
1993 beginning of the tokens delimited string
1994 ALL is a regular expression with a single
1995 parenthesized subpattern which is the token to be
1996 returned. E.g. '{\(.*\)}' would return any string
1997 enclosed in braces around POS.
1998 ERRORSTRING optional fourth argument, controls action on no match
2001 a string: signal an error, using that string."
2002 (let ((case-fold-search t
))
2005 ;; First look for a match for START that goes across POS.
2006 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
2007 (not (looking-at start
)))
2009 ;; If we did not find one, search back for START
2010 ;; (this finds only matches that end at or before POS).
2011 (or (looking-at start
)
2014 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
2016 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
2017 (not (setq found
(and (<= (match-beginning 0) pos
)
2018 (> (match-end 0) pos
))))))
2019 (if (and found
(<= (match-beginning 0) pos
)
2020 (> (match-end 0) pos
))
2021 (match-string-no-properties 1)
2022 (cond ((null errorstring
)
2028 (error "No %s around position %d" errorstring pos
))))))))
2030 (defun Info-mouse-follow-nearest-node (click)
2031 "\\<Info-mode-map>Follow a node reference near point.
2032 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2033 At end of the node's text, moves to the next node, or up if none."
2035 (mouse-set-point click
)
2036 (and (not (Info-try-follow-nearest-node))
2037 (save-excursion (forward-line 1) (eobp))
2038 (Info-next-preorder)))
2040 (defun Info-follow-nearest-node ()
2041 "\\<Info-mode-map>Follow a node reference near point.
2042 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
2043 If no reference to follow, moves to the next node, or up if none."
2045 (or (Info-try-follow-nearest-node)
2046 (Info-next-preorder)))
2048 ;; Common subroutine.
2049 (defun Info-try-follow-nearest-node ()
2050 "Follow a node reference near point. Return non-nil if successful."
2053 ((setq node
(Info-get-token (point) "\\*note[ \n]"
2054 "\\*note[ \n]\\([^:]*\\):"))
2055 (Info-follow-reference node
))
2056 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2057 (Info-goto-node node
))
2058 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
2061 (setq node
(Info-extract-menu-node-name))
2062 (Info-goto-node node
))
2063 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2064 (Info-goto-node node
))
2065 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2066 (Info-goto-node node
))
2067 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2068 (Info-goto-node "Top"))
2069 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2070 (Info-goto-node node
)))
2073 (defvar Info-mode-map nil
2074 "Keymap containing Info commands.")
2077 (setq Info-mode-map
(make-keymap))
2078 (suppress-keymap Info-mode-map
)
2079 (define-key Info-mode-map
"." 'beginning-of-buffer
)
2080 (define-key Info-mode-map
" " 'Info-scroll-up
)
2081 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
2082 (define-key Info-mode-map
"\t" 'Info-next-reference
)
2083 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
2084 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
2085 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
2086 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
2087 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
2088 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
2089 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
2090 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
2091 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
2092 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
2093 (define-key Info-mode-map
"0" 'undefined
)
2094 (define-key Info-mode-map
"?" 'Info-summary
)
2095 (define-key Info-mode-map
"]" 'Info-forward-node
)
2096 (define-key Info-mode-map
"[" 'Info-backward-node
)
2097 (define-key Info-mode-map
"<" 'Info-top-node
)
2098 (define-key Info-mode-map
">" 'Info-final-node
)
2099 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
2100 (define-key Info-mode-map
"c" 'Info-copy-current-node-name
)
2101 (define-key Info-mode-map
"d" 'Info-directory
)
2102 (define-key Info-mode-map
"e" 'Info-edit
)
2103 (define-key Info-mode-map
"f" 'Info-follow-reference
)
2104 (define-key Info-mode-map
"g" 'Info-goto-node
)
2105 (define-key Info-mode-map
"h" 'Info-help
)
2106 (define-key Info-mode-map
"i" 'Info-index
)
2107 (define-key Info-mode-map
"l" 'Info-last
)
2108 (define-key Info-mode-map
"m" 'Info-menu
)
2109 (define-key Info-mode-map
"n" 'Info-next
)
2110 (define-key Info-mode-map
"p" 'Info-prev
)
2111 (define-key Info-mode-map
"q" 'Info-exit
)
2112 (define-key Info-mode-map
"s" 'Info-search
)
2113 ;; For consistency with Rmail.
2114 (define-key Info-mode-map
"\M-s" 'Info-search
)
2115 (define-key Info-mode-map
"\M-n" 'clone-buffer
)
2116 (define-key Info-mode-map
"t" 'Info-top-node
)
2117 (define-key Info-mode-map
"u" 'Info-up
)
2118 (define-key Info-mode-map
"," 'Info-index-next
)
2119 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
2120 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
2123 (defun Info-check-pointer (item)
2124 "Non-nil if ITEM is present in this node."
2126 (Info-extract-pointer item
)
2130 Info-mode-menu Info-mode-map
2131 "Menu for info files."
2133 ["Up" Info-up
:active
(Info-check-pointer "up")
2134 :help
"Go up in the Info tree"]
2135 ["Next" Info-next
:active
(Info-check-pointer "next")
2136 :help
"Go to the next node"]
2137 ["Previous" Info-prev
:active
(Info-check-pointer "prev[ious]*")
2138 :help
"Go to the previous node"]
2139 ["Backward" Info-backward-node
2140 :help
"Go backward one node, considering all as a sequence"]
2141 ["Forward" Info-forward-node
2142 :help
"Go forward one node, considering all as a sequence"]
2143 ["Beginning" beginning-of-buffer
2144 :help
"Go to beginning of this node"]
2145 ["Top" Info-top-node
2146 :help
"Go to top node of file"]
2147 ["Final Node" Info-final-node
2148 :help
"Go to final node in this file"]
2149 ("Menu Item" ["You should never see this" report-emacs-bug t
])
2150 ("Reference" ["You should never see this" report-emacs-bug t
])
2151 ["Search..." Info-search
2152 :help
"Search for regular expression in this Info file"]
2153 ["Go to Node..." Info-goto-node
2154 :help
"Go to a named node"]
2155 ["Last" Info-last
:active Info-history
2156 :help
"Go to the last node you were at"]
2158 ["Lookup a String" Info-index
2159 :help
"Look for a string in the index items"]
2160 ["Next Matching Item" Info-index-next
2161 :help
"Look for another occurrence of previous item"])
2162 ["Edit" Info-edit
:help
"Edit contents of this node"
2163 :active Info-enable-edit
]
2164 ["Copy Node Name" Info-copy-current-node-name
2165 :help
"Copy the name of the current node into the kill ring"]
2166 ["Exit" Info-exit
:help
"Stop reading Info"]))
2169 (defvar info-tool-bar-map
2170 (if (display-graphic-p)
2171 (let ((map (make-sparse-keymap)))
2172 (tool-bar-local-item-from-menu 'Info-exit
"close" map Info-mode-map
)
2173 (tool-bar-local-item-from-menu 'Info-prev
"left_arrow" map Info-mode-map
)
2174 (tool-bar-local-item-from-menu 'Info-next
"right_arrow" map Info-mode-map
)
2175 (tool-bar-local-item-from-menu 'Info-up
"up_arrow" map Info-mode-map
)
2176 (tool-bar-local-item-from-menu 'Info-last
"undo" map Info-mode-map
)
2177 (tool-bar-local-item-from-menu 'Info-top-node
"home" map Info-mode-map
)
2178 (tool-bar-local-item-from-menu 'Info-index
"index" map Info-mode-map
)
2179 (tool-bar-local-item-from-menu 'Info-goto-node
"jump_to" map Info-mode-map
)
2180 (tool-bar-local-item-from-menu 'Info-search
"search" map Info-mode-map
)
2183 (defvar Info-menu-last-node nil
)
2184 ;; Last node the menu was created for.
2185 ;; Value is a list, (FILE-NAME NODE-NAME).
2187 (defun Info-menu-update ()
2188 "Update the Info menu for the current node."
2190 (if (or (not (eq major-mode
'Info-mode
))
2191 (equal (list Info-current-file Info-current-node
)
2192 Info-menu-last-node
))
2194 ;; Update menu menu.
2195 (let* ((Info-complete-menu-buffer (current-buffer))
2196 (items (nreverse (condition-case nil
2197 (Info-complete-menu-item "" nil t
)
2201 (while (and items
(< number
9))
2202 (setq current
(car items
)
2205 (setq entries
(cons `[,current
2206 (Info-menu ,current
)
2207 :keys
,(format "%d" number
)]
2210 (setq entries
(cons ["Other..." Info-menu t
] entries
)))
2212 (setq entries
(list ["No menu" nil nil
] nil
:active
)))
2213 (easy-menu-change '("Info") "Menu Item" (nreverse entries
)))
2214 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2216 str i entries current
2218 (case-fold-search t
))
2220 (goto-char (point-min))
2221 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
2222 (setq str
(buffer-substring
2226 (while (setq i
(string-match "[ \n\t]+" str i
))
2227 (setq str
(concat (substring str
0 i
) " "
2228 (substring str
(match-end 0))))
2232 (while (and items
(< number
9))
2233 (setq current
(car items
)
2236 (setq entries
(cons `[,current
2237 (Info-follow-reference ,current
)
2241 (setq entries
(cons ["Other..." Info-follow-reference t
]
2244 (setq entries
(list ["No references" nil nil
] nil
:active
)))
2245 (easy-menu-change '("Info") "Reference" (nreverse entries
)))
2246 ;; Update last seen node.
2247 (setq Info-menu-last-node
(list Info-current-file Info-current-node
)))
2248 ;; Try to avoid entering infinite beep mode in case of errors.
2252 (defun Info-copy-current-node-name ()
2253 "Put the name of the current info node into the kill ring.
2254 The name of the info file is prepended to the node name in parentheses."
2256 (unless Info-current-node
2257 (error "No current info node"))
2260 (file-name-nondirectory
2261 (if (stringp Info-current-file
)
2263 (or buffer-file-name
"")))
2265 Info-current-node
)))
2268 ;; Info mode is suitable only for specially formatted data.
2269 (put 'Info-mode
'mode-class
'special
)
2270 (put 'Info-mode
'no-clone-indirect t
)
2273 "Info mode provides commands for browsing through the Info documentation tree.
2274 Documentation in Info is divided into \"nodes\", each of which discusses
2275 one topic and contains references to other nodes which discuss related
2276 topics. Info has commands to follow the references and show you other nodes.
2279 \\[Info-help] Invoke the Info tutorial.
2280 \\[Info-exit] Quit Info: reselect previously selected buffer.
2282 Selecting other nodes:
2283 \\[Info-mouse-follow-nearest-node]
2284 Follow a node reference you click on.
2285 This works with menu items, cross references, and
2286 the \"next\", \"previous\" and \"up\", depending on where you click.
2287 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2288 \\[Info-next] Move to the \"next\" node of this node.
2289 \\[Info-prev] Move to the \"previous\" node of this node.
2290 \\[Info-up] Move \"up\" from this node.
2291 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2292 Picking a menu item causes another node to be selected.
2293 \\[Info-directory] Go to the Info directory node.
2294 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2295 \\[Info-last] Move to the last node you were at.
2296 \\[Info-index] Look up a topic in this file's Index and move to that node.
2297 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2298 \\[Info-top-node] Go to the Top node of this file.
2299 \\[Info-final-node] Go to the final node in this file.
2300 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2301 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2303 Moving within a node:
2304 \\[Info-scroll-up] Normally, scroll forward a full screen.
2305 Once you scroll far enough in a node that its menu appears on the
2306 screen but after point, the next scroll moves into its first
2307 subnode. When after all menu items (or if there is no menu),
2308 move up to the parent node.
2309 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2310 already visible, try to go to the previous menu entry, or up
2312 \\[beginning-of-buffer] Go to beginning of node.
2315 \\[Info-exit] Quit Info: reselect previously selected buffer.
2316 \\[Info-edit] Edit contents of selected node.
2317 1 Pick first item in node's menu.
2318 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2319 \\[Info-goto-node] Move to node specified by name.
2320 You may include a filename as well, as (FILENAME)NODENAME.
2321 \\[universal-argument] \\[info] Move to new Info file with completion.
2322 \\[Info-search] Search through this Info file for specified regexp,
2323 and select the node in which the next occurrence is found.
2324 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2325 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2326 (kill-all-local-variables)
2327 (setq major-mode
'Info-mode
)
2328 (setq mode-name
"Info")
2330 (use-local-map Info-mode-map
)
2331 (add-hook 'activate-menubar-hook
'Info-menu-update nil t
)
2332 (set-syntax-table text-mode-syntax-table
)
2333 (setq local-abbrev-table text-mode-abbrev-table
)
2334 (setq case-fold-search t
)
2335 (setq buffer-read-only t
)
2336 (make-local-variable 'Info-current-file
)
2337 (make-local-variable 'Info-current-subfile
)
2338 (make-local-variable 'Info-current-node
)
2339 (make-local-variable 'Info-tag-table-marker
)
2340 (setq Info-tag-table-marker
(make-marker))
2341 (make-local-variable 'Info-tag-table-buffer
)
2342 (setq Info-tag-table-buffer nil
)
2343 (make-local-variable 'Info-history
)
2344 (make-local-variable 'Info-index-alternatives
)
2345 (set (make-local-variable 'tool-bar-map
) info-tool-bar-map
)
2346 ;; This is for the sake of the invisible text we use handling titles.
2347 (make-local-variable 'line-move-ignore-invisible
)
2348 (setq line-move-ignore-invisible t
)
2349 (add-hook 'clone-buffer-hook
'Info-clone-buffer-hook nil t
)
2350 (Info-set-mode-line)
2351 (run-hooks 'Info-mode-hook
))
2353 (defun Info-clone-buffer-hook ()
2354 (when (bufferp Info-tag-table-buffer
)
2355 (setq Info-tag-table-buffer
2356 (with-current-buffer Info-tag-table-buffer
(clone-buffer))))
2357 (let ((m Info-tag-table-marker
))
2359 (setq Info-tag-table-marker
2360 (if (and (marker-position m
) (bufferp Info-tag-table-buffer
))
2361 (with-current-buffer Info-tag-table-buffer
2362 (copy-marker (marker-position m
)))
2365 (defvar Info-edit-map
(let ((map (make-sparse-keymap)))
2366 (set-keymap-parent map text-mode-map
)
2367 (define-key map
"\C-c\C-c" 'Info-cease-edit
)
2369 "Local keymap used within `e' command of Info.")
2371 ;; Info-edit mode is suitable only for specially formatted data.
2372 (put 'Info-edit-mode
'mode-class
'special
)
2374 (defun Info-edit-mode ()
2375 "Major mode for editing the contents of an Info node.
2376 Like text mode with the addition of `Info-cease-edit'
2377 which returns to Info mode for browsing.
2379 (use-local-map Info-edit-map
)
2380 (setq major-mode
'Info-edit-mode
)
2381 (setq mode-name
"Info Edit")
2382 (kill-local-variable 'mode-line-buffer-identification
)
2383 (setq buffer-read-only nil
)
2384 (force-mode-line-update)
2385 (buffer-enable-undo (current-buffer))
2386 (run-hooks 'Info-edit-mode-hook
))
2389 "Edit the contents of this Info node.
2390 Allowed only if variable `Info-enable-edit' is non-nil."
2392 (or Info-enable-edit
2393 (error "Editing info nodes is not enabled"))
2395 (message "%s" (substitute-command-keys
2396 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2398 (defun Info-cease-edit ()
2399 "Finish editing Info node; switch back to Info proper."
2401 ;; Do this first, so nothing has changed if user C-g's at query.
2402 (and (buffer-modified-p)
2403 (y-or-n-p "Save the file? ")
2405 (use-local-map Info-mode-map
)
2406 (setq major-mode
'Info-mode
)
2407 (setq mode-name
"Info")
2408 (Info-set-mode-line)
2409 (setq buffer-read-only t
)
2410 (force-mode-line-update)
2411 (and (marker-position Info-tag-table-marker
)
2413 (message "Tags may have changed. Use Info-tagify if necessary")))
2415 (defvar Info-file-list-for-emacs
2416 '("ediff" "eudc" "forms" "gnus" "info" ("mh" .
"mh-e")
2417 "sc" "message" ("dired" .
"dired-x") "viper" "vip" "idlwave"
2418 ("c" .
"ccmode") ("c++" .
"ccmode") ("objc" .
"ccmode")
2419 ("java" .
"ccmode") ("idl" .
"ccmode") ("pike" .
"ccmode")
2420 ("skeleton" .
"autotype") ("auto-insert" .
"autotype")
2421 ("copyright" .
"autotype") ("executable" .
"autotype")
2422 ("time-stamp" .
"autotype") ("quickurl" .
"autotype")
2423 ("tempo" .
"autotype") ("hippie-expand" .
"autotype")
2424 ("cvs" .
"pcl-cvs") ("ada" .
"ada-mode") "calc"
2425 ("calcAlg" .
"calc") ("calcDigit" .
"calc") ("calcVar" .
"calc")
2426 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
2427 ("mail-header" .
"emacs-mime") ("mail-content" .
"emacs-mime")
2428 ("mail-encode" .
"emacs-mime") ("mail-decode" .
"emacs-mime")
2429 ("rfc2045" .
"emacs-mime")
2430 ("rfc2231" .
"emacs-mime") ("rfc2047" .
"emacs-mime")
2431 ("rfc2045" .
"emacs-mime") ("rfc1843" .
"emacs-mime")
2432 ("ietf-drums" .
"emacs-mime") ("quoted-printable" .
"emacs-mime")
2433 ("binhex" .
"emacs-mime") ("uudecode" .
"emacs-mime")
2434 ("mailcap" .
"emacs-mime") ("mm" .
"emacs-mime")
2435 ("mml" .
"emacs-mime"))
2436 "List of Info files that describe Emacs commands.
2437 An element can be a file name, or a list of the form (PREFIX . FILE)
2438 where PREFIX is a name prefix and FILE is the file to look in.
2439 If the element is just a file name, the file name also serves as the prefix.")
2441 (defun Info-find-emacs-command-nodes (command)
2442 "Return a list of locations documenting COMMAND.
2443 The `info-file' property of COMMAND says which Info manual to search.
2444 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2445 defines heuristics for which Info manual to try.
2446 The locations are of the format used in `Info-history', i.e.
2447 \(FILENAME NODENAME BUFFERPOS\)."
2449 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command
))
2450 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
2451 (info-file "emacs")) ;default
2452 ;; Determine which info file this command is documented in.
2453 (if (get command
'info-file
)
2454 (setq info-file
(get command
'info-file
))
2455 ;; If it doesn't say explicitly, test its name against
2456 ;; various prefixes that we know.
2457 (let ((file-list Info-file-list-for-emacs
))
2459 (let* ((elt (car file-list
))
2460 (name (if (consp elt
)
2463 (file (if (consp elt
) (cdr elt
) elt
))
2464 (regexp (concat "\\`" (regexp-quote name
)
2466 (if (string-match regexp
(symbol-name command
))
2467 (setq info-file file file-list nil
))
2468 (setq file-list
(cdr file-list
))))))
2469 (Info-find-node info-file
"Top")
2470 (or (and (search-forward "\n* menu:" nil t
)
2471 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
2472 (error "Info file `%s' appears to lack an index" info-file
))
2473 (goto-char (match-beginning 1))
2474 ;; Bind Info-history to nil, to prevent the index nodes from
2475 ;; getting into the node history.
2476 (let ((Info-history nil
)
2479 (Info-goto-node (Info-extract-menu-node-name))
2482 (goto-char (point-min))
2483 (while (re-search-forward cmd-desc nil t
)
2485 (cons (list Info-current-file
2486 (match-string-no-properties 2)
2489 (and (setq node
(Info-extract-pointer "next" t
))
2490 (string-match "\\<Index\\>" node
)))
2491 (Info-goto-node node
)))
2495 (defun Info-goto-emacs-command-node (command)
2496 "Go to the Info node in the Emacs manual for command COMMAND.
2497 The command is found by looking up in Emacs manual's indices
2498 or in another manual found via COMMAND's `info-file' property or
2499 the variable `Info-file-list-for-emacs'."
2500 (interactive "CFind documentation for command: ")
2501 (or (commandp command
)
2502 (signal 'wrong-type-argument
(list 'commandp command
)))
2503 (let ((where (Info-find-emacs-command-nodes command
)))
2505 (let ((num-matches (length where
)))
2506 ;; Get Info running, and pop to it in another window.
2507 (save-window-excursion
2509 ;; FIXME It would be cool if this could use a buffer other
2511 (pop-to-buffer "*info*")
2512 ;; Bind Info-history to nil, to prevent the last Index node
2513 ;; visited by Info-find-emacs-command-nodes from being
2514 ;; pushed onto the history.
2515 (let ((Info-history nil
))
2516 (Info-find-node (car (car where
))
2517 (car (cdr (car where
)))))
2518 (if (> num-matches
1)
2520 ;; (car where) will be pushed onto Info-history
2521 ;; when/if they go to another node. Put the other
2522 ;; nodes that were found on the history.
2523 (setq Info-history
(nconc (cdr where
) Info-history
))
2524 (message "Found %d other entr%s. Use %s to see %s."
2526 (if (> num-matches
2) "ies" "y")
2527 (substitute-command-keys "\\[Info-last]")
2528 (if (> num-matches
2) "them" "it")))))
2529 (error "Couldn't find documentation for %s" command
))))
2532 (defun Info-goto-emacs-key-command-node (key)
2533 "Go to the node in the Emacs manual which describes the command bound to KEY.
2535 Interactively, if the binding is `execute-extended-command', a command is read.
2536 The command is found by looking up in Emacs manual's indices
2537 or in another manual found via COMMAND's `info-file' property or
2538 the variable `Info-file-list-for-emacs'."
2539 (interactive "kFind documentation for key: ")
2540 (let ((command (key-binding key
)))
2541 (cond ((null command
)
2542 (message "%s is undefined" (key-description key
)))
2543 ((and (interactive-p)
2544 (eq command
'execute-extended-command
))
2545 (Info-goto-emacs-command-node
2546 (read-command "Find documentation for command: ")))
2548 (Info-goto-emacs-command-node command
)))))
2550 (defface Info-title-1-face
2551 '((((type tty pc
) (class color
)) (:foreground
"yellow" :weight bold
))
2552 (t (:height
1.2 :inherit Info-title-2-face
)))
2553 "Face for Info titles at level 1."
2556 (defface Info-title-2-face
2557 '((((type tty pc
) (class color
)) (:foreground
"lightblue" :weight bold
))
2558 (t (:height
1.2 :inherit Info-title-3-face
)))
2559 "Face for Info titles at level 2."
2562 (defface Info-title-3-face
2563 '((((type tty pc
) (class color
)) (:weight bold
))
2564 (t (:height
1.2 :inherit Info-title-4-face
)))
2565 "Face for Info titles at level 3."
2568 (defface Info-title-4-face
2569 '((((type tty pc
) (class color
)) (:weight bold
))
2570 (t (:weight bold
:inherit variable-pitch
)))
2571 "Face for Info titles at level 4."
2574 (defface info-menu-header
2579 :inherit variable-pitch
2581 "Face for headers in Info menus."
2584 (defun Info-fontify-menu-headers ()
2585 "Add the face `info-menu-header' to any header before a menu entry."
2587 (goto-char (point-min))
2588 (when (re-search-forward "\\* Menu:" nil t
)
2589 (put-text-property (match-beginning 0) (match-end 0)
2590 'face
'info-menu-header
)
2591 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t
)
2592 (put-text-property (match-beginning 1) (match-end 1)
2593 'face
'info-menu-header
)))))
2595 (defun Info-fontify-node ()
2596 ;; Only fontify the node if it hasn't already been done. [We pass in
2597 ;; LIMIT arg to `next-property-change' because it seems to search past
2599 (unless (and (< (next-property-change (point-min) nil
(point-max))
2601 ;; But do put the text properties if the local-map property
2602 ;; is inconsistent with Info-use-header-line's value.
2604 (= (next-single-property-change
2605 (point-min) 'local-map nil
(point-max))
2607 (null Info-use-header-line
)))
2609 (let ((buffer-read-only nil
)
2610 (case-fold-search t
))
2611 (goto-char (point-min))
2612 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2613 (goto-char (match-end 0))
2614 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2615 (goto-char (match-end 0))
2616 (let* ((nbeg (match-beginning 2))
2617 (nend (match-end 2))
2618 (tbeg (match-beginning 1))
2619 (tag (buffer-substring tbeg
(match-end 1))))
2620 (if (string-equal tag
"Node")
2621 (put-text-property nbeg nend
'face
'info-header-node
)
2622 (put-text-property nbeg nend
'face
'info-header-xref
)
2623 (put-text-property tbeg nend
'mouse-face
'highlight
)
2624 (put-text-property tbeg nend
2626 (concat "Go to node "
2627 (buffer-substring nbeg nend
)))
2628 ;; Don't bind mouse events on the header line if we
2629 ;; aren't going to display the header line.
2630 (when Info-use-header-line
2631 (let ((fun (cdr (assoc tag
'(("Prev" . Info-prev
)
2632 ("Next" . Info-next
)
2633 ("Up" . Info-up
))))))
2635 (let ((keymap (make-sparse-keymap)))
2636 (define-key keymap
[header-line mouse-1
] fun
)
2637 (define-key keymap
[header-line mouse-2
] fun
)
2638 (put-text-property tbeg nend
'local-map keymap
)))))
2639 (if (not Info-use-header-line
)
2640 ;; In case they switched Info-use-header-line off
2641 ;; in the middle of an Info session, some text
2642 ;; properties may have been left lying around from
2643 ;; past visits of this node. Remove them.
2644 (remove-text-properties tbeg nend
'(local-map nil
)))
2646 (goto-char (point-min))
2647 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
2649 (let ((c (preceding-char))
2651 (cond ((= c ?
*) (setq face
'Info-title-1-face
))
2652 ((= c ?
=) (setq face
'Info-title-2-face
))
2653 ((= c ?-
) (setq face
'Info-title-3-face
))
2654 (t (setq face
'Info-title-4-face
)))
2655 (put-text-property (match-beginning 1) (match-end 1)
2657 ;; This is a serious problem for trying to handle multiple
2658 ;; frame types at once. We want this text to be invisible
2659 ;; on frames that can display the font above.
2660 (when (memq (framep (selected-frame)) '(x pc w32 mac
))
2661 (add-text-properties (match-beginning 2) (1+ (match-end 2))
2662 '(invisible t intangible t
))))
2663 (goto-char (point-min))
2664 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t
)
2665 (if (= (char-after (1- (match-beginning 0))) ?
\") ; hack
2667 (add-text-properties (match-beginning 1) (match-end 1)
2669 mouse-face highlight
2670 help-echo
"mouse-2: go to this node"))))
2671 (goto-char (point-min))
2672 (if (and (search-forward "\n* Menu:" nil t
)
2673 (not (string-match "\\<Index\\>" Info-current-node
))
2674 ;; Don't take time to annotate huge menus
2675 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
2677 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t
)
2679 (if (zerop (% n
3)) ; visual aids to help with 1-9 keys
2680 (put-text-property (match-beginning 0)
2681 (1+ (match-beginning 0))
2682 'face
'info-menu-5
))
2683 (add-text-properties (match-beginning 1) (match-end 1)
2685 mouse-face highlight
2686 help-echo
"mouse-2: go to this node")))))
2687 (Info-fontify-menu-headers)
2688 (set-buffer-modified-p nil
)))))
2691 ;; When an Info buffer is killed, make sure the associated tags buffer
2693 (defun Info-kill-buffer ()
2694 (and (eq major-mode
'Info-mode
)
2695 Info-tag-table-buffer
2696 (kill-buffer Info-tag-table-buffer
)))
2698 (add-hook 'kill-buffer-hook
'Info-kill-buffer
)
2700 ;;; Speedbar support:
2701 ;; These functions permit speedbar to display the "tags" in the
2702 ;; current info node.
2703 (eval-when-compile (require 'speedbar
))
2705 (defvar Info-speedbar-key-map nil
2706 "Keymap used when in the info display mode.")
2708 (defun Info-install-speedbar-variables ()
2709 "Install those variables used by speedbar to enhance Info."
2710 (if Info-speedbar-key-map
2712 (setq Info-speedbar-key-map
(speedbar-make-specialized-keymap))
2714 ;; Basic tree features
2715 (define-key Info-speedbar-key-map
"e" 'speedbar-edit-line
)
2716 (define-key Info-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
2717 (define-key Info-speedbar-key-map
"+" 'speedbar-expand-line
)
2718 (define-key Info-speedbar-key-map
"-" 'speedbar-contract-line
)
2721 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2722 Info-speedbar-key-map
2723 Info-speedbar-hierarchy-buttons
)))
2725 (defvar Info-speedbar-menu-items
2726 '(["Browse Node" speedbar-edit-line t
]
2727 ["Expand Node" speedbar-expand-line
2728 (save-excursion (beginning-of-line)
2729 (looking-at "[0-9]+: *.\\+. "))]
2730 ["Contract Node" speedbar-contract-line
2731 (save-excursion (beginning-of-line)
2732 (looking-at "[0-9]+: *.-. "))]
2734 "Additional menu-items to add to speedbar frame.")
2736 ;; Make sure our special speedbar major mode is loaded
2737 (if (featurep 'speedbar
)
2738 (Info-install-speedbar-variables)
2739 (add-hook 'speedbar-load-hook
'Info-install-speedbar-variables
))
2741 ;;; Info hierarchy display method
2743 (defun Info-speedbar-browser ()
2744 "Initialize speedbar to display an info node browser.
2745 This will add a speedbar major display mode."
2748 ;; Make sure that speedbar is active
2749 (speedbar-frame-mode 1)
2750 ;; Now, throw us into Info mode on speedbar.
2751 (speedbar-change-initial-expansion-list "Info")
2754 (eval-when-compile (defvar speedbar-attached-frame
))
2756 (defun Info-speedbar-hierarchy-buttons (directory depth
&optional node
)
2757 "Display an Info directory hierarchy in speedbar.
2758 DIRECTORY is the current directory in the attached frame.
2759 DEPTH is the current indentation depth.
2760 NODE is an optional argument that is used to represent the
2761 specific node to expand."
2763 (save-excursion (goto-char (point-min))
2764 (let ((case-fold-search t
))
2765 (looking-at "Info Nodes:"))))
2766 ;; Update our "current node" maybe?
2768 ;; We cannot use the generic list code, that depends on all leaves
2769 ;; being known at creation time.
2771 (speedbar-with-writable (insert "Info Nodes:\n")))
2772 (let ((completions nil
)
2773 (cf (selected-frame)))
2774 (select-frame speedbar-attached-frame
)
2775 (save-window-excursion
2777 (Info-speedbar-fetch-file-nodes (or node
'"(dir)top"))))
2780 (speedbar-with-writable
2782 (speedbar-make-tag-line 'bracket ?
+ 'Info-speedbar-expand-node
2783 (cdr (car completions
))
2784 (car (car completions
))
2785 'Info-speedbar-goto-node
2786 (cdr (car completions
))
2788 (setq completions
(cdr completions
)))
2792 (defun Info-speedbar-goto-node (text node indent
)
2793 "When user clicks on TEXT, go to an info NODE.
2794 The INDENT level is ignored."
2795 (select-frame speedbar-attached-frame
)
2796 (let* ((buff (or (get-buffer "*info*")
2797 (progn (info) (get-buffer "*info*"))))
2798 (bwin (get-buffer-window buff
0)))
2801 (select-window bwin
)
2802 (raise-frame (window-frame bwin
)))
2803 (if speedbar-power-click
2804 (let ((pop-up-frames t
)) (select-window (display-buffer buff
)))
2805 (select-frame speedbar-attached-frame
)
2806 (switch-to-buffer buff
)))
2807 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node
))
2808 (file (match-string 1 node
))
2809 (node (match-string 2 node
)))
2810 (Info-find-node file node
)
2811 ;; If we do a find-node, and we were in info mode, restore
2812 ;; the old default method. Once we are in info mode, it makes
2813 ;; sense to return to whatever method the user was using before.
2814 (if (string= speedbar-initial-expansion-list-name
"Info")
2815 (speedbar-change-initial-expansion-list
2816 speedbar-previously-used-expansion-list-name
)))))
2818 (defun Info-speedbar-expand-node (text token indent
)
2819 "Expand the node the user clicked on.
2820 TEXT is the text of the button we clicked on, a + or - item.
2821 TOKEN is data related to this node (NAME . FILE).
2822 INDENT is the current indentation depth."
2823 (cond ((string-match "+" text
) ;we have to expand this file
2824 (speedbar-change-expand-button-char ?-
)
2825 (if (speedbar-with-writable
2827 (end-of-line) (forward-char 1)
2828 (Info-speedbar-hierarchy-buttons nil
(1+ indent
) token
)))
2829 (speedbar-change-expand-button-char ?-
)
2830 (speedbar-change-expand-button-char ??
)))
2831 ((string-match "-" text
) ;we have to contract this node
2832 (speedbar-change-expand-button-char ?
+)
2833 (speedbar-delete-subblock indent
))
2834 (t (error "Ooops... not sure what to do")))
2835 (speedbar-center-buffer-smartly))
2837 (defun Info-speedbar-fetch-file-nodes (nodespec)
2838 "Fetch the subnodes from the info NODESPEC.
2839 NODESPEC is a string of the form: (file)node.
2840 Optional THISFILE represends the filename of"
2842 ;; Set up a buffer we can use to fake-out Info.
2843 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2844 (if (not (equal major-mode
'Info-mode
))
2846 ;; Get the node into this buffer
2847 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec
))
2848 (file (match-string 1 nodespec
))
2849 (node (match-string 2 nodespec
)))
2850 (Info-find-node file node
))
2851 ;; Scan the created buffer
2852 (goto-char (point-min))
2853 (let ((completions nil
)
2854 (case-fold-search t
)
2855 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec
)
2856 (match-string 1 nodespec
))))
2857 ;; Always skip the first one...
2858 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
2859 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
2860 (let ((name (match-string 1)))
2861 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2862 (setq name
(cons name
(match-string 1)))
2863 (if (looking-at " *\\(([^)]+)\\)\\.")
2864 (setq name
(cons name
(concat (match-string 1) "Top")))
2865 (if (looking-at " \\([^.]+\\).")
2867 (cons name
(concat "(" thisfile
")" (match-string 1))))
2868 (setq name
(cons name
(concat "(" thisfile
")" name
))))))
2869 (setq completions
(cons name completions
))))
2870 (nreverse completions
))))
2872 ;;; Info mode node listing
2873 (defun Info-speedbar-buttons (buffer)
2874 "Create a speedbar display to help navigation in an Info file.
2875 BUFFER is the buffer speedbar is requesting buttons for."
2876 (if (save-excursion (goto-char (point-min))
2877 (let ((case-fold-search t
))
2878 (not (looking-at "Info Nodes:"))))
2880 (Info-speedbar-hierarchy-buttons nil
0)
2883 (dolist (mess '("^Node has no Previous$"
2884 "^No menu in this node$"
2885 "^Node has no Next$"
2886 "^No cross-references in this node^"
2888 "^No \".*\" in index$"))
2889 (add-to-list 'debug-ignored-errors mess
))
2893 ;;; info.el ends here