1 ;;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001,
5 ;; Free Software Foundation, Inc.
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
29 ;; Note that nowadays we expect info files to be made using makeinfo.
30 ;; In particular we make these assumptions:
31 ;; - a menu item MAY contain colons but not colon-space ": "
32 ;; - a menu item ending with ": " (but not ":: ") is an index entry
33 ;; - a node name MAY NOT contain a colon
34 ;; This distinction is to support indexing of computer programming
35 ;; language terms that may contain ":" but not ": ".
39 (eval-when-compile (require 'jka-compr
))
47 (defvar Info-history nil
48 "List of info nodes user has visited.
49 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
51 (defcustom Info-enable-edit nil
52 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
53 This is convenient if you want to write info files by hand.
54 However, we recommend that you not do this.
55 It is better to write a Texinfo file and generate the Info file from that,
56 because that gives you a printed manual as well."
60 (defvar Info-enable-active-nodes nil
61 "Non-nil allows Info to execute Lisp code associated with nodes.
62 The Lisp code is executed when the node is selected.")
63 (put 'Info-enable-active-nodes
'risky-local-variable t
)
66 '((((class color
) (background light
)) (:foreground
"brown" :weight bold
:slant italic
))
67 (((class color
) (background dark
)) (:foreground
"white" :weight bold
:slant italic
))
68 (t (:weight bold
:slant italic
)))
69 "Face for Info node names."
73 '((((class color
)) (:foreground
"red1"))
75 "Face for every third `*' in an Info menu."
79 '((((class color
) (background light
)) (:foreground
"magenta4" :weight bold
))
80 (((class color
) (background dark
)) (:foreground
"cyan" :weight bold
))
82 "Face for Info cross-references."
85 (defcustom Info-fontify-maximum-menu-size
100000
86 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
90 (defcustom Info-use-header-line t
91 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
92 A header-line does not scroll with the rest of the buffer."
96 (defface info-header-xref
97 '((t (:inherit info-xref
)))
98 "Face for Info cross-references in a node header."
101 (defface info-header-node
102 '((t (:inherit info-node
)))
103 "Face for Info nodes in a node header."
106 (defvar Info-directory-list nil
107 "List of directories to search for Info documentation files.
108 If nil, meaning not yet initialized, Info uses the environment
109 variable INFOPATH to initialize it, or `Info-default-directory-list'
110 if there is no INFOPATH variable in the environment, or the
111 concatenation of the two if INFOPATH ends with a colon.
113 When `Info-directory-list' is initialized from the value of
114 `Info-default-directory-list', and Emacs is installed in one of the
115 standard directories, the directory of Info files that come with Emacs
116 is put last (so that local Info files override standard ones).
118 When `Info-directory-list' is initialized from the value of
119 `Info-default-directory-list', and Emacs is not installed in one
120 of the standard directories, the first element of the resulting
121 list is the directory where Emacs installs the Info files that
122 come with it. This is so that Emacs's own manual, which suits the
123 version of Emacs you are using, will always be found first. This
124 is useful when you install an experimental version of Emacs without
125 removing the standard installation.
127 If you want to override the order of directories in
128 `Info-default-directory-list', set INFOPATH in the environment.
130 If you run the Emacs executable from the `src' directory in the Emacs
131 source tree, and INFOPATH is not defined, the `info' directory in the
132 source tree is used as the first element of `Info-directory-list', in
133 place of the installation Info directory. This is useful when you run
134 a version of Emacs without installing it.")
136 (defcustom Info-additional-directory-list nil
137 "List of additional directories to search for Info documentation files.
138 These directories are searched after those in `Info-directory-list'."
139 :type
'(repeat directory
)
142 (defcustom Info-scroll-prefer-subnodes nil
143 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
144 If this is non-nil, and you scroll far enough in a node that its menu
145 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
146 moves to a subnode indicated by the following menu item. This means
147 that you visit a subnode before getting to the end of the menu.
149 Setting this option to nil results in behavior similar to the stand-alone
150 Info reader program, which visits the first subnode from the menu only
151 when you hit the end of the current node."
155 (defcustom Info-hide-note-references t
156 "*If non-nil, hide the tag and section reference in *note and * menu items.
157 Also replaces the \"*note\" text with \"see\".
158 If value is non-nil but not t, the reference section is still shown."
160 :type
'(choice (const :tag
"No reformatting" nil
)
161 (const :tag
"Replace tag and hide reference" t
)
162 (other :tag
"Replace only tag" tag
))
165 (defcustom Info-refill-paragraphs nil
166 "*If non-nil, attempt to refill paragraphs with hidden references.
167 This refilling may accidentally remove explicit line breaks in the info
168 file, so be prepared for a few surprises if you enable this feature."
173 (defcustom Info-mode-hook
174 ;; Try to obey obsolete Info-fontify settings.
175 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
176 '(turn-on-font-lock))
177 "Hooks run when `info-mode' is called."
181 (defvar Info-current-file nil
182 "Info file that Info is now looking at, or nil.
183 This is the name that was specified in Info, not the actual file name.
184 It doesn't contain directory names or file name extensions added by Info.
185 Can also be t when using `Info-on-current-buffer'.")
187 (defvar Info-current-subfile nil
188 "Info subfile that is actually in the *info* buffer now.
189 nil if current info file is not split into subfiles.")
191 (defvar Info-current-node nil
192 "Name of node that Info is now looking at, or nil.")
194 (defvar Info-tag-table-marker nil
195 "Marker pointing at beginning of current Info file's tag table.
196 Marker points nowhere if file has no tag table.")
198 (defvar Info-tag-table-buffer nil
199 "Buffer used for indirect tag tables.")
201 (defvar Info-current-file-completions nil
202 "Cached completion list for current Info file.")
204 (defvar Info-index-alternatives nil
205 "List of possible matches for last `Info-index' command.")
207 (defvar Info-standalone nil
208 "Non-nil if Emacs was started solely as an Info browser.")
210 (defvar Info-suffix-list
211 ;; The MS-DOS list should work both when long file names are
212 ;; supported (Windows 9X), and when only 8+3 file names are available.
213 (if (eq system-type
'ms-dos
)
214 '( (".gz" .
"gunzip")
216 (".bz2" .
("bzip2" "-dc"))
219 (".info.Z" .
"gunzip")
220 (".info.gz" .
"gunzip")
221 ("-info.Z" .
"gunzip")
222 ("-info.gz" .
"gunzip")
223 ("/index.gz".
"gunzip")
224 ("/index.z" .
"gunzip")
230 '( (".info.Z".
"uncompress")
231 (".info.Y".
"unyabba")
232 (".info.gz".
"gunzip")
233 (".info.z".
"gunzip")
234 (".info.bz2" .
("bzip2" "-dc"))
236 ("-info.Z".
"uncompress")
237 ("-info.Y".
"unyabba")
238 ("-info.gz".
"gunzip")
239 ("-info.bz2" .
("bzip2" "-dc"))
240 ("-info.z".
"gunzip")
242 ("/index.Z".
"uncompress")
243 ("/index.Y".
"unyabba")
244 ("/index.gz".
"gunzip")
245 ("/index.z".
"gunzip")
246 ("/index.bz2".
("bzip2" "-dc"))
252 (".bz2" .
("bzip2" "-dc"))
254 "List of file name suffixes and associated decoding commands.
255 Each entry should be (SUFFIX . STRING); the file is given to
256 the command as standard input.
258 STRING may be a list of strings. In that case, the first element is
259 the command name, and the rest are arguments to that command.
261 If STRING is nil, no decoding is done.
262 Because the SUFFIXes are tried in order, the empty string should
263 be last in the list.")
265 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
266 ;; First, on MS-DOS with no long file names support, delete some of
267 ;; the extension in FILENAME to make room.
268 (defun info-insert-file-contents-1 (filename suffix lfn
)
269 (if lfn
; long file names are supported
270 (concat filename suffix
)
271 (let* ((sans-exts (file-name-sans-extension filename
))
272 ;; How long is the extension in FILENAME (not counting the dot).
273 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
275 ;; SUFFIX starts with a dot. If FILENAME already has one,
276 ;; get rid of the one in SUFFIX (unless suffix is empty).
277 (or (and (<= ext-len
0)
278 (not (eq (aref filename
(1- (length filename
))) ?.
)))
279 (= (length suffix
) 0)
280 (setq suffix
(substring suffix
1)))
281 ;; How many chars of that extension should we keep?
282 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
283 ;; Get rid of the rest of the extension, and add SUFFIX.
284 (concat (substring filename
0 (- (length filename
)
285 (- ext-len ext-left
)))
288 (defun info-file-exists-p (filename)
289 (and (file-exists-p filename
)
290 (not (file-directory-p filename
))))
292 (defun info-insert-file-contents (filename &optional visit
)
293 "Insert the contents of an info file in the current buffer.
294 Do the right thing if the file has been compressed or zipped."
295 (let* ((tail Info-suffix-list
)
296 (lfn (if (fboundp 'msdos-long-file-names
)
297 (msdos-long-file-names)
299 (check-short (and (fboundp 'msdos-long-file-names
)
301 fullname decoder done
)
302 (if (info-file-exists-p filename
)
303 ;; FILENAME exists--see if that name contains a suffix.
304 ;; If so, set DECODE accordingly.
308 (concat (regexp-quote (car (car tail
))) "$")
310 (setq tail
(cdr tail
)))
311 (setq fullname filename
312 decoder
(cdr (car tail
))))
313 ;; Try adding suffixes to FILENAME and see if we can find something.
314 (while (and tail
(not done
))
315 (setq fullname
(info-insert-file-contents-1 filename
316 (car (car tail
)) lfn
))
317 (if (info-file-exists-p fullname
)
319 ;; If we found a file with a suffix, set DECODER
320 ;; according to the suffix.
321 decoder
(cdr (car tail
)))
322 ;; When the MS-DOS port runs on Windows, we need to check
323 ;; the short variant of a long file name as well.
325 (setq fullname
(info-insert-file-contents-1 filename
326 (car (car tail
)) nil
))
327 (if (info-file-exists-p fullname
)
329 decoder
(cdr (car tail
))))))
330 (setq tail
(cdr tail
)))
332 (error "Can't find %s or any compressed version of it" filename
)))
333 ;; check for conflict with jka-compr
334 (if (and (featurep 'jka-compr
)
335 (jka-compr-installed-p)
336 (jka-compr-get-compression-info fullname
))
340 (insert-file-contents-literally fullname visit
)
341 (let ((buffer-read-only nil
)
342 (coding-system-for-write 'no-conversion
)
343 (default-directory (or (file-name-directory fullname
)
346 (setq decoder
(list decoder
)))
347 (apply 'call-process-region
(point-min) (point-max)
348 (car decoder
) t t nil
(cdr decoder
))))
349 (insert-file-contents fullname visit
))))
351 (defun Info-default-dirs ()
352 (let ((source (expand-file-name "info/" source-directory
))
353 (sibling (if installation-directory
354 (expand-file-name "info/" installation-directory
)
355 (if invocation-directory
356 (let ((infodir (expand-file-name
358 invocation-directory
)))
359 (if (file-exists-p infodir
)
361 (setq infodir
(expand-file-name
363 invocation-directory
))
364 (and (file-exists-p infodir
)
368 (if (and sibling
(file-exists-p sibling
))
369 ;; Uninstalled, Emacs builddir != srcdir.
371 ;; Uninstalled, builddir == srcdir
373 (if (or (member alternative Info-default-directory-list
)
374 ;; On DOS/NT, we use movable executables always,
375 ;; and we must always find the Info dir at run time.
376 (if (memq system-type
'(ms-dos windows-nt
))
378 ;; Use invocation-directory for Info
379 ;; only if we used it for exec-directory also.
380 (not (string= exec-directory
381 (expand-file-name "lib-src/"
382 installation-directory
))))
383 (not (file-exists-p alternative
)))
384 Info-default-directory-list
385 ;; `alternative' contains the Info files that came with this
386 ;; version, so we should look there first. `Info-insert-dir'
387 ;; currently expects to find `alternative' first on the list.
389 (reverse (cdr (reverse Info-default-directory-list
)))))))
391 (defun info-initialize ()
392 "Initialize `Info-directory-list', if that hasn't been done yet."
393 (unless Info-directory-list
394 (let ((path (getenv "INFOPATH")))
395 (setq Info-directory-list
396 (prune-directory-list
398 (if (string-match ":\\'" path
)
399 (append (split-string (substring path
0 -
1)
400 (regexp-quote path-separator
))
402 (split-string path
(regexp-quote path-separator
)))
403 (Info-default-dirs)))))))
406 (defun info-other-window (&optional file
)
407 "Like `info' but show the Info buffer in another window."
408 (interactive (if current-prefix-arg
409 (list (read-file-name "Info file name: " nil nil t
))))
410 (let (same-window-buffer-names)
413 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
416 (defun info (&optional file
)
417 "Enter Info, the documentation browser.
418 Optional argument FILE specifies the file to examine;
419 the default is the top-level directory of Info.
420 Called from a program, FILE may specify an Info node of the form
421 `(FILENAME)NODENAME'.
423 In interactive use, a prefix argument directs this command
424 to read a file name from the minibuffer.
426 The search path for Info files is in the variable `Info-directory-list'.
427 The top-level Info directory is made by combining all the files named `dir'
428 in all the directories in that path."
429 (interactive (if current-prefix-arg
430 (list (read-file-name "Info file name: " nil nil t
))))
433 (pop-to-buffer "*info*")
434 ;; If argument already contains parentheses, don't add another set
435 ;; since the argument will then be parsed improperly. This also
436 ;; has the added benefit of allowing node names to be included
437 ;; following the parenthesized filename.
438 (if (and (stringp file
) (string-match "(.*)" file
))
439 (Info-goto-node file
)
440 (Info-goto-node (concat "(" file
")"))))
441 (if (get-buffer "*info*")
442 (pop-to-buffer "*info*")
446 (defun info-emacs-manual ()
447 "Display the Emacs manual in Info mode."
452 (defun info-standalone ()
453 "Run Emacs as a standalone Info reader.
454 Usage: emacs -f info-standalone [filename]
455 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
456 (setq Info-standalone t
)
457 (if (and command-line-args-left
458 (not (string-match "^-" (car command-line-args-left
))))
461 (info (car command-line-args-left
))
462 (setq command-line-args-left
(cdr command-line-args-left
)))
463 (error (send-string-to-terminal
464 (format "%s\n" (if (eq (car-safe err
) 'error
)
466 (save-buffers-kill-emacs)))
469 ;; See if the accessible portion of the buffer begins with a node
470 ;; delimiter, and the node header line which follows matches REGEXP.
471 ;; Typically, this test will be followed by a loop that examines the
472 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
473 ;; to have the overhead of this special test inside the loop.
475 ;; This function changes match-data, but supposedly the caller might
476 ;; want to use the results of re-search-backward.
478 ;; The return value is the value of point at the beginning of matching
479 ;; REGEXP, if the function succeeds, nil otherwise.
480 (defun Info-node-at-bob-matching (regexp)
481 (and (bobp) ; are we at beginning of buffer?
482 (looking-at "\^_") ; does it begin with node delimiter?
486 (forward-line 1) ; does the line after delimiter match REGEXP?
487 (re-search-backward regexp beg t
))))
489 (defun Info-find-node (filename nodename
&optional no-going-back
)
490 "Go to an info node specified as separate FILENAME and NODENAME.
491 NO-GOING-BACK is non-nil if recovering from an error in this function;
492 it says do not attempt further (recursive) error recovery."
494 ;; Convert filename to lower case if not found as specified.
496 (if (stringp filename
)
497 (let (temp temp-downcase found
)
498 (setq filename
(substitute-in-file-name filename
))
499 (if (string= (downcase filename
) "dir")
501 (let ((dirs (if (string-match "^\\./" filename
)
502 ;; If specified name starts with `./'
503 ;; then just try current directory.
505 (if (file-name-absolute-p filename
)
506 ;; No point in searching for an
507 ;; absolute file name
509 (if Info-additional-directory-list
510 (append Info-directory-list
511 Info-additional-directory-list
)
512 Info-directory-list
)))))
513 ;; Search the directory list for file FILENAME.
514 (while (and dirs
(not found
))
515 (setq temp
(expand-file-name filename
(car dirs
)))
517 (expand-file-name (downcase filename
) (car dirs
)))
518 ;; Try several variants of specified name.
519 (let ((suffix-list Info-suffix-list
)
520 (lfn (if (fboundp 'msdos-long-file-names
)
521 (msdos-long-file-names)
523 (while (and suffix-list
(not found
))
524 (cond ((info-file-exists-p
525 (info-insert-file-contents-1
526 temp
(car (car suffix-list
)) lfn
))
529 (info-insert-file-contents-1
530 temp-downcase
(car (car suffix-list
)) lfn
))
531 (setq found temp-downcase
))
532 ((and (fboundp 'msdos-long-file-names
)
535 (info-insert-file-contents-1
536 temp
(car (car suffix-list
)) nil
)))
538 (setq suffix-list
(cdr suffix-list
))))
539 (setq dirs
(cdr dirs
)))))
541 (setq filename found
)
542 (error "Info file %s does not exist" filename
))))
543 ;; Record the node we are leaving.
544 (if (and Info-current-file
(not no-going-back
))
546 (cons (list Info-current-file Info-current-node
(point))
548 ;; Go into info buffer.
549 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
550 (Info-find-node-2 filename nodename no-going-back
))
552 (defun Info-on-current-buffer (&optional nodename
)
553 "Use the `Info-mode' to browse the current info buffer.
554 If a prefix arg is provided, it queries for the NODENAME which
555 else defaults to \"Top\"."
557 (list (if current-prefix-arg
558 (completing-read "Node name: " (Info-build-node-completions)
560 (unless nodename
(setq nodename
"Top"))
563 (set (make-local-variable 'Info-current-file
) t
)
564 (Info-find-node-2 nil nodename
))
566 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
567 ;; but at least it keeps this routine (which is only for the benefit of
568 ;; makeinfo-buffer) out of the way of normal operations.
570 (defun Info-revert-find-node (filename nodename
)
571 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
572 When *info* is already displaying FILENAME and NODENAME, the window position
573 is preserved, if possible."
574 (pop-to-buffer "*info*")
575 (let ((old-filename Info-current-file
)
576 (old-nodename Info-current-node
)
577 (pcolumn (current-column))
578 (pline (count-lines (point-min) (line-beginning-position)))
579 (wline (count-lines (point-min) (window-start)))
580 (old-history Info-history
)
581 (new-history (and Info-current-file
582 (list Info-current-file Info-current-node
(point)))))
583 (kill-buffer (current-buffer))
584 (Info-find-node filename nodename
)
585 (setq Info-history old-history
)
586 (if (and (equal old-filename Info-current-file
)
587 (equal old-nodename Info-current-node
))
589 ;; note goto-line is no good, we want to measure from point-min
590 (beginning-of-buffer)
592 (set-window-start (selected-window) (point))
593 (beginning-of-buffer)
595 (move-to-column pcolumn
))
596 ;; only add to the history when coming from a different file+node
598 (setq Info-history
(cons new-history Info-history
))))))
600 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
601 "Find a node in a tag table.
602 MARKER specifies the buffer and position to start searching at.
603 REGEXP is a regular expression matching nodes or references. Its first
604 group should match `Node:' or `Ref:'.
605 CASE-FOLD t means search for a case-insensitive match.
606 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
607 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
608 where the match was found, and MODE is `major-mode' of the buffer in
609 which the match was found."
610 (let ((case-fold-search case-fold
))
612 (set-buffer (marker-buffer marker
))
617 (when (re-search-forward regexp nil t
)
618 (list (string-equal "Ref:" (match-string 1))
619 (+ (point-min) (read (current-buffer)))
622 (defun Info-find-in-tag-table (marker regexp
)
623 "Find a node in a tag table.
624 MARKER specifies the buffer and position to start searching at.
625 REGEXP is a regular expression matching nodes or references. Its first
626 group should match `Node:' or `Ref:'.
627 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
628 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
629 where the match was found, and MODE is `major-mode' of the buffer in
630 which the match was found.
631 This function tries to find a case-sensitive match first, then a
632 case-insensitive match is tried."
633 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
634 (when (null (car result
))
635 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
638 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
639 "Find a node or anchor in the current buffer.
640 REGEXP is a regular expression matching nodes or references. Its first
641 group should match `Node:' or `Ref:'.
642 CASE-FOLD t means search for a case-insensitive match.
643 Value is the position at which a match was found, or nil if not found."
644 (let ((case-fold-search case-fold
)
647 (when (Info-node-at-bob-matching regexp
)
648 (setq found
(point)))
649 (while (and (not found
)
650 (search-forward "\n\^_" nil t
))
654 (when (re-search-backward regexp beg t
)
656 (setq found
(point)))))
659 (defun Info-find-node-in-buffer (regexp)
660 "Find a node or anchor in the current buffer.
661 REGEXP is a regular expression matching nodes or references. Its first
662 group should match `Node:' or `Ref:'.
663 Value is the position at which a match was found, or nil if not found.
664 This function looks for a case-sensitive match first. If none is found,
665 a case-insensitive match is tried."
666 (or (Info-find-node-in-buffer-1 regexp nil
)
667 (Info-find-node-in-buffer-1 regexp t
)))
669 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
670 (buffer-disable-undo (current-buffer))
671 (or (eq major-mode
'Info-mode
)
674 (setq Info-current-node nil
)
676 (let ((case-fold-search t
)
678 ;; Switch files if necessary
680 (equal Info-current-file filename
)
681 (let ((buffer-read-only nil
))
682 (setq Info-current-file nil
683 Info-current-subfile nil
684 Info-current-file-completions nil
685 buffer-file-name nil
)
689 (info-insert-file-contents filename nil
)
690 (setq default-directory
(file-name-directory filename
)))
691 (set-buffer-modified-p nil
)
692 ;; See whether file has a tag table. Record the location if yes.
693 (goto-char (point-max))
695 ;; Use string-equal, not equal, to ignore text props.
696 (if (not (or (string-equal nodename
"*")
698 (search-forward "\^_\nEnd tag table\n" nil t
))))
700 ;; We have a tag table. Find its beginning.
701 ;; Is this an indirect file?
702 (search-backward "\nTag table:\n")
706 (looking-at "(Indirect)\n"))
707 ;; It is indirect. Copy it to another buffer
708 ;; and record that the tag table is in that buffer.
709 (let ((buf (current-buffer))
711 (or Info-tag-table-buffer
712 (generate-new-buffer " *info tag table*"))))
713 (setq Info-tag-table-buffer tagbuf
)
716 (buffer-disable-undo (current-buffer))
717 (setq case-fold-search t
)
719 (insert-buffer-substring buf
))
720 (set-marker Info-tag-table-marker
721 (match-end 0) tagbuf
))
722 (set-marker Info-tag-table-marker pos
)))
723 (set-marker Info-tag-table-marker nil
))
724 (setq Info-current-file
725 (if (eq filename t
) "dir" filename
))))
726 ;; Use string-equal, not equal, to ignore text props.
727 (if (string-equal nodename
"*")
728 (progn (setq Info-current-node nodename
)
729 (Info-set-mode-line))
732 ;; 1. Anchor found in tag table
733 ;; 2. Anchor *not* in tag table
735 ;; 3. Node found in tag table
736 ;; 4. Node *not* found in tag table, but found in file
737 ;; 5. Node *not* in tag table, and *not* in file
739 ;; *Or* the same, but in an indirect subfile.
741 ;; Search file for a suitable node.
742 (let ((guesspos (point-min))
743 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
744 (if (stringp nodename
)
745 (regexp-quote nodename
)
747 "\\) *[,\t\n\177]")))
751 ;; First, search a tag table, if any
752 (when (marker-position Info-tag-table-marker
)
753 (let* ((m Info-tag-table-marker
)
754 (found (Info-find-in-tag-table m regexp
)))
757 ;; FOUND is (ANCHOR POS MODE).
758 (setq guesspos
(nth 1 found
))
760 ;; If this is an indirect file, determine which
761 ;; file really holds this node and read it in.
762 (unless (eq (nth 2 found
) 'Info-mode
)
763 ;; Note that the current buffer must be the
764 ;; *info* buffer on entry to
765 ;; Info-read-subfile. Thus the hackery above.
766 (setq guesspos
(Info-read-subfile guesspos
)))
770 (goto-char (setq anchorpos guesspos
))
773 ;; Else we may have a node, which we search for:
774 (goto-char (max (point-min)
775 (- (byte-to-position guesspos
) 1000)))
777 ;; Now search from our advised position (or from beg of
778 ;; buffer) to find the actual node. First, check
779 ;; whether the node is right where we are, in case the
780 ;; buffer begins with a node.
781 (let ((pos (Info-find-node-in-buffer regexp
)))
785 (error "No such anchor in tag table or node in tag table or file: %s"
789 (goto-char (or anchorpos
(point-min))))))
790 ;; If we did not finish finding the specified node,
791 ;; go back to the previous one.
792 (or Info-current-node no-going-back
(null Info-history
)
793 (let ((hist (car Info-history
)))
794 (setq Info-history
(cdr Info-history
))
795 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
796 (goto-char (nth 2 hist
))))))
798 ;; Cache the contents of the (virtual) dir file, once we have merged
799 ;; it for the first time, so we can save time subsequently.
800 (defvar Info-dir-contents nil
)
802 ;; Cache for the directory we decided to use for the default-directory
803 ;; of the merged dir text.
804 (defvar Info-dir-contents-directory nil
)
806 ;; Record the file attributes of all the files from which we
807 ;; constructed Info-dir-contents.
808 (defvar Info-dir-file-attributes nil
)
810 (defvar Info-dir-file-name nil
)
812 ;; Construct the Info directory node by merging the files named `dir'
813 ;; from various directories. Set the *info* buffer's
814 ;; default-directory to the first directory we actually get any text
816 (defun Info-insert-dir ()
817 (if (and Info-dir-contents Info-dir-file-attributes
818 ;; Verify that none of the files we used has changed
821 (mapcar (lambda (elt)
822 (let ((curr (file-attributes
824 (file-truename (car elt
)))))
826 ;; Don't compare the access time.
827 (if curr
(setcar (nthcdr 4 curr
) 0))
828 (setcar (nthcdr 4 (cdr elt
)) 0)
829 (equal (cdr elt
) curr
)))
830 Info-dir-file-attributes
))))
832 (insert Info-dir-contents
)
833 (goto-char (point-min)))
834 (let ((dirs (if Info-additional-directory-list
835 (append Info-directory-list
836 Info-additional-directory-list
)
837 Info-directory-list
))
839 ;; Bind this in case the user sets it to nil.
841 ;; This is set non-nil if we find a problem in some input files.
843 buffers buffer others nodes dirs-done
)
845 ;; Search the directory list for the directory file.
847 (let ((truename (file-truename (expand-file-name (car dirs
)))))
848 (or (member truename dirs-done
)
849 (member (directory-file-name truename
) dirs-done
)
850 ;; Try several variants of specified name.
851 ;; Try upcasing, appending `.info', or both.
855 (progn (setq file
(expand-file-name "dir" truename
))
856 (file-attributes file
))
857 (progn (setq file
(expand-file-name "DIR" truename
))
858 (file-attributes file
))
859 (progn (setq file
(expand-file-name "dir.info" truename
))
860 (file-attributes file
))
861 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
862 (file-attributes file
)))))
865 (cons (directory-file-name truename
)
870 (message "Composing main Info directory..."))
871 (set-buffer (generate-new-buffer " info dir"))
874 (insert-file-contents file
)
875 (set (make-local-variable 'Info-dir-file-name
)
877 (push (current-buffer) buffers
)
878 (push (cons file attrs
) dir-file-attrs
))
879 (error (kill-buffer (current-buffer))))))))
881 (set (make-local-variable 'Info-dir-contents-directory
)
882 (file-name-as-directory (car dirs
))))
883 (setq dirs
(cdr dirs
))))
886 (error "Can't find the Info directory node"))
888 ;; Distinguish the dir file that comes with Emacs from all the
889 ;; others. Yes, that is really what this is supposed to do.
890 ;; The definition of `Info-directory-list' puts it first on that
891 ;; list and so last in `buffers' at this point.
892 (setq buffer
(car (last buffers
))
893 others
(delq buffer buffers
))
895 ;; Insert the entire original dir file as a start; note that we've
896 ;; already saved its default directory to use as the default
897 ;; directory for the whole concatenation.
898 (insert-buffer buffer
)
900 ;; Look at each of the other buffers one by one.
901 (dolist (other others
)
902 (let (this-buffer-nodes)
903 ;; In each, find all the menus.
904 (with-current-buffer other
905 (goto-char (point-min))
906 ;; Find each menu, and add an elt to NODES for it.
907 (while (re-search-forward "^\\* Menu:" nil t
)
908 (while (and (zerop (forward-line 1)) (eolp)))
911 (re-search-backward "^\^_")
912 (search-forward "Node: ")
914 (and (looking-at (Info-following-node-name-re))
916 (search-forward "\n\^_" nil
'move
)
919 (push (list nodename other beg end
) this-buffer-nodes
)))
920 (if (assoc-ignore-case "top" this-buffer-nodes
)
921 (setq nodes
(nconc this-buffer-nodes nodes
))
923 (message "No `top' node in %s" Info-dir-file-name
)))))
924 ;; Add to the main menu a menu item for each other node.
925 (re-search-forward "^\\* Menu:")
927 (let ((menu-items '("top"))
928 (end (save-excursion (search-forward "\^_" nil t
) (point))))
930 (let ((nodename (car node
)))
932 (or (member (downcase nodename
) menu-items
)
933 (re-search-forward (concat "^\\* +"
934 (regexp-quote nodename
)
938 (insert "* " nodename
"::" "\n")
939 (push nodename menu-items
)))))))
940 ;; Now take each node of each of the other buffers
941 ;; and merge it into the main buffer.
943 (let ((case-fold-search t
)
944 (nodename (car node
)))
945 (goto-char (point-min))
946 ;; Find the like-named node in the main buffer.
947 (if (re-search-forward (concat "^\^_.*\n.*Node: "
948 (regexp-quote nodename
)
952 (search-forward "\n\^_" nil
'move
)
955 ;; If none exists, add one.
956 (goto-char (point-max))
957 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
958 ;; Merge the text from the other buffer's menu
959 ;; into the menu in the like-named node in the main buffer.
960 (apply 'insert-buffer-substring
(cdr node
))))
961 (Info-dir-remove-duplicates)
962 ;; Kill all the buffers we just made.
963 (mapc 'kill-buffer buffers
)
964 (goto-char (point-min))
966 (message "Composing main Info directory...problems encountered, see `*Messages*'")
967 (message "Composing main Info directory...done"))
968 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
969 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
970 (setq default-directory Info-dir-contents-directory
))
972 (defvar Info-streamline-headings
973 '(("Emacs" .
"Emacs")
974 ("Programming" .
"Programming")
975 ("Libraries" .
"Libraries")
976 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
977 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
979 (defun Info-dir-remove-duplicates ()
981 (goto-char (point-min))
982 ;; Remove duplicate headings in the same menu.
983 (while (search-forward "\n* Menu:" nil t
)
984 (setq limit
(save-excursion (search-forward "\n\x1f" nil t
)))
985 ;; Look for the next heading to unify.
986 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
987 (let ((name (match-string 1))
988 (start (match-beginning 0))
990 ;; Check whether this heading should be streamlined.
992 (dolist (x Info-streamline-headings
)
993 (when (string-match (car x
) name
)
996 (if re
(replace-match name t t nil
1))
997 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
999 (or limit
(point-max))))
1000 ;; Look for other headings of the same category and merge them.
1002 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1003 (when (if re
(save-match-data (string-match re
(match-string 1)))
1004 (equal name
(match-string 1)))
1006 ;; Delete redundant heading.
1007 (delete-region (match-beginning 0) (point))
1008 ;; Push the entries onto `text'.
1010 (delete-and-extract-region
1012 (if (re-search-forward "^[^* \n\t]" nil t
)
1014 (or limit
(point-max)))) entries
))))
1015 ;; Insert the entries just found.
1016 (while (= (line-beginning-position 0) (1- (point)))
1018 (dolist (entry (nreverse entries
))
1020 (while (= (line-beginning-position 0) (1- (point)))
1021 (delete-region (1- (point)) (point))))
1023 ;; Now remove duplicate entries under the same heading.
1027 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1029 (let ((x (match-string 1)))
1030 (if (member-ignore-case x seen
)
1031 (delete-region (match-beginning 0)
1032 (progn (re-search-forward "^[^ \t]" nil t
)
1033 (match-beginning 0)))
1034 (push x seen
))))))))))
1036 ;; Note that on entry to this function the current-buffer must be the
1037 ;; *info* buffer; not the info tags buffer.
1038 (defun Info-read-subfile (nodepos)
1039 ;; NODEPOS is either a position (in the Info file as a whole,
1040 ;; not relative to a subfile) or the name of a subfile.
1043 (if (numberp nodepos
)
1045 (set-buffer (marker-buffer Info-tag-table-marker
))
1046 (goto-char (point-min))
1047 (or (looking-at "\^_")
1048 (search-forward "\n\^_"))
1051 (while (not (looking-at "\^_"))
1054 thisfilepos thisfilename
)
1055 (search-forward ": ")
1056 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1057 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1058 ;; read in version 19 stops at the end of number.
1059 ;; Advance to the next line.
1061 (if (> thisfilepos nodepos
)
1063 (setq lastfilename thisfilename
)
1064 (setq lastfilepos thisfilepos
))
1065 (forward-line 1)))))
1066 (setq lastfilename nodepos
)
1067 (setq lastfilepos
0))
1068 ;; Assume previous buffer is in Info-mode.
1069 ;; (set-buffer (get-buffer "*info*"))
1070 (or (equal Info-current-subfile lastfilename
)
1071 (let ((buffer-read-only nil
))
1072 (setq buffer-file-name nil
)
1075 (info-insert-file-contents lastfilename
)
1076 (set-buffer-modified-p nil
)
1077 (setq Info-current-subfile lastfilename
)))
1078 ;; Widen in case we are in the same subfile as before.
1080 (goto-char (point-min))
1081 (if (looking-at "\^_")
1083 (search-forward "\n\^_"))
1084 (if (numberp nodepos
)
1085 (+ (- nodepos lastfilepos
) (point)))))
1087 (defun Info-unescape-quotes (value)
1088 "Unescape double quotes and backslashes in VALUE"
1091 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1092 (setq unquote
(replace-match "" t t unquote
1))
1093 (setq start
(- (match-end 0) 1)))
1096 ;; As of Texinfo 4.6, makeinfo writes constructs like
1097 ;; \0\h[image param=value ...\h\0]
1098 ;; into the Info file for handling images.
1099 (defun Info-split-parameter-string (parameter-string)
1100 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1101 whitespace separated list of KEY=VALUE pairs. If VALUE
1102 contains whitespace or double quotes, it must be quoted in
1103 double quotes and any double quotes or backslashes must be
1104 escaped (\\\",\\\\)."
1107 (while (string-match
1108 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1109 parameter-string start
)
1110 (setq start
(match-end 0))
1111 (push (cons (match-string 1 parameter-string
)
1112 (or (match-string 2 parameter-string
)
1113 (Info-unescape-quotes
1114 (match-string 3 parameter-string
))))
1118 (defun Info-display-images-node ()
1119 "Display images in current node."
1121 (let ((inhibit-read-only t
)
1122 (case-fold-search t
))
1123 (goto-char (point-min))
1124 (while (re-search-forward
1125 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1127 (let* ((start (match-beginning 1))
1128 (parameter-alist (Info-split-parameter-string (match-string 2)))
1129 (src (cdr (assoc-string "src" parameter-alist
)))
1130 (image-file (if src
(if (file-name-absolute-p src
) src
1131 (concat default-directory src
))
1133 (image (if (file-exists-p image-file
)
1134 (create-image image-file
)
1136 (message "Found image: %S" image-file
)
1137 (if (not (get-text-property start
'display
))
1138 (add-text-properties
1139 start
(point) `(display ,image rear-nonsticky
(display)))))))
1140 (set-buffer-modified-p nil
)))
1142 (defun Info-select-node ()
1143 "Select the info node that point is in."
1144 ;; Bind this in case the user sets it to nil.
1145 (let ((case-fold-search t
))
1147 ;; Find beginning of node.
1148 (if (search-backward "\n\^_" nil
'move
)
1150 (if (looking-at "\^_")
1152 (signal 'search-failed
(list "\n\^_"))))
1153 ;; Get nodename spelled as it is in the node.
1154 (re-search-forward "Node:[ \t]*")
1155 (setq Info-current-node
1156 (buffer-substring-no-properties (point)
1158 (skip-chars-forward "^,\t\n")
1160 (Info-set-mode-line)
1161 ;; Find the end of it, and narrow.
1163 (let (active-expression)
1164 ;; Narrow to the node contents
1165 (narrow-to-region (point)
1166 (if (re-search-forward "\n[\^_\f]" nil t
)
1169 (if (looking-at "[\n\^_\f]*execute: ")
1171 (goto-char (match-end 0))
1172 (setq active-expression
1173 (read (current-buffer))))))
1175 (if Info-enable-active-nodes
(eval active-expression
))
1177 (Info-display-images-node)
1178 (run-hooks 'Info-selection-hook
)))))
1180 (defun Info-set-mode-line ()
1181 (setq mode-line-buffer-identification
1182 (nconc (propertized-buffer-identification "%b")
1185 (file-name-nondirectory
1186 (if (stringp Info-current-file
)
1188 (or buffer-file-name
"")))
1190 (or Info-current-node
""))))))
1192 ;; Go to an info node specified with a filename-and-nodename string
1193 ;; of the sort that is found in pointers in nodes.
1195 (defun Info-goto-node (nodename &optional fork
)
1196 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1197 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1198 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1200 Completion is available, but only for node names in the current Info file.
1201 If FORK is non-nil (interactively with a prefix arg), show the node in
1203 If FORK is a string, it is the name to use for the new buffer."
1204 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1208 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1210 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1212 (setq filename
(if (= (match-beginning 1) (match-end 1))
1214 (match-string 2 nodename
))
1215 nodename
(match-string 3 nodename
))
1216 (let ((trim (string-match "\\s *\\'" filename
)))
1217 (if trim
(setq filename
(substring filename
0 trim
))))
1218 (let ((trim (string-match "\\s *\\'" nodename
)))
1219 (if trim
(setq nodename
(substring nodename
0 trim
))))
1220 (if transient-mark-mode
(deactivate-mark))
1221 (Info-find-node (if (equal filename
"") nil filename
)
1222 (if (equal nodename
"") "Top" nodename
))))
1224 (defvar Info-read-node-completion-table
)
1226 ;; This function is used as the "completion table" while reading a node name.
1227 ;; It does completion using the alist in Info-read-node-completion-table
1228 ;; unless STRING starts with an open-paren.
1229 (defun Info-read-node-name-1 (string predicate code
)
1231 ;; First complete embedded file names.
1232 ((string-match "\\`([^)]*\\'" string
)
1233 (let ((file (substring string
1)))
1236 (let ((comp (try-completion file
'locate-file-completion
1237 (cons Info-directory-list
1238 (mapcar 'car Info-suffix-list
)))))
1240 ((eq comp t
) (concat string
")"))
1241 (comp (concat "(" comp
)))))
1242 ((eq code t
) (all-completions file
'locate-file-completion
1243 (cons Info-directory-list
1244 (mapcar 'car Info-suffix-list
))))
1246 ;; If a file name was given, then any node is fair game.
1247 ((string-match "\\`(" string
)
1249 ((eq code nil
) string
)
1252 ;; Otherwise use Info-read-node-completion-table.
1254 (try-completion string Info-read-node-completion-table predicate
))
1256 (all-completions string Info-read-node-completion-table predicate
))
1258 (test-completion string Info-read-node-completion-table predicate
))))
1260 (defun Info-read-node-name (prompt &optional default
)
1261 (let* ((completion-ignore-case t
)
1262 (Info-read-node-completion-table (Info-build-node-completions))
1263 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1264 (if (equal nodename
"")
1266 (Info-read-node-name prompt
))
1269 (defun Info-build-node-completions ()
1270 (or Info-current-file-completions
1272 ;; Bind this in case the user sets it to nil.
1273 (case-fold-search t
)
1274 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1277 (if (marker-buffer Info-tag-table-marker
)
1278 (let ((marker Info-tag-table-marker
))
1279 (set-buffer (marker-buffer marker
))
1282 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1284 (cons (list (match-string-no-properties 2))
1287 (goto-char (point-min))
1288 ;; If the buffer begins with a node header, process that first.
1289 (if (Info-node-at-bob-matching node-regexp
)
1290 (setq compl
(list (match-string-no-properties 1))))
1291 ;; Now for the rest of the nodes.
1292 (while (search-forward "\n\^_" nil t
)
1294 (let ((beg (point)))
1296 (if (re-search-backward node-regexp beg t
)
1298 (cons (list (match-string-no-properties 1))
1300 (setq compl
(cons '("*") compl
))
1301 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1303 (defun Info-restore-point (hl)
1304 "If this node has been visited, restore the point value when we left."
1306 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1307 ;; Use string-equal, not equal, to ignore text props.
1308 (string-equal (nth 1 (car hl
)) Info-current-node
))
1310 (goto-char (nth 2 (car hl
)))
1311 (setq hl nil
)) ;terminate the while at next iter
1312 (setq hl
(cdr hl
)))))
1314 (defvar Info-search-history nil
1315 "The history list for `Info-search'.")
1317 (defun Info-search (regexp)
1318 "Search for REGEXP, starting from point, and select node it's found in."
1319 (interactive (list (read-string
1320 (if Info-search-history
1321 (format "Regexp search (default `%s'): "
1322 (car Info-search-history
))
1324 nil
'Info-search-history
)))
1325 (when transient-mark-mode
1327 (when (equal regexp
"")
1328 (setq regexp
(car Info-search-history
)))
1330 (let (found beg-found give-up
1331 (onode Info-current-node
)
1332 (ofile Info-current-file
)
1334 (ostart (window-start))
1335 (osubfile Info-current-subfile
))
1339 (while (and (not give-up
)
1341 (isearch-range-invisible beg-found found
)))
1342 (if (re-search-forward regexp nil t
)
1343 (setq found
(point) beg-found
(match-beginning 0))
1344 (setq give-up t
)))))
1345 ;; If no subfiles, give error now.
1347 (if (null Info-current-subfile
)
1348 (re-search-forward regexp
)
1353 ;; Try other subfiles.
1356 (set-buffer (marker-buffer Info-tag-table-marker
))
1357 (goto-char (point-min))
1358 (search-forward "\n\^_\nIndirect:")
1360 (narrow-to-region (point)
1361 (progn (search-forward "\n\^_")
1363 (goto-char (point-min))
1364 ;; Find the subfile we just searched.
1365 (search-forward (concat "\n" osubfile
": "))
1368 ;; Make a list of all following subfiles.
1369 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1371 (re-search-forward "\\(^.*\\): [0-9]+$")
1372 (goto-char (+ (match-end 1) 2))
1373 (setq list
(cons (cons (+ (point-min)
1374 (read (current-buffer)))
1375 (match-string-no-properties 1))
1377 (goto-char (1+ (match-end 0))))
1378 ;; Put in forward order
1379 (setq list
(nreverse list
))))
1381 (message "Searching subfile %s..." (cdr (car list
)))
1382 (Info-read-subfile (car (car list
)))
1383 (setq list
(cdr list
))
1384 (setq give-up nil found nil
)
1385 (while (and (not give-up
)
1387 (isearch-range-invisible beg-found found
)))
1388 (if (re-search-forward regexp nil t
)
1389 (setq found
(point) beg-found
(match-beginning 0))
1397 (signal 'search-failed
(list regexp
))))
1399 (progn (Info-read-subfile osubfile
)
1402 (set-window-start (selected-window) ostart
)))))
1406 ;; Use string-equal, not equal, to ignore text props.
1407 (or (and (string-equal onode Info-current-node
)
1408 (equal ofile Info-current-file
))
1409 (setq Info-history
(cons (list ofile onode opoint
)
1412 (defun Info-extract-pointer (name &optional errorname
)
1413 "Extract the value of the node-pointer named NAME.
1414 If there is none, use ERRORNAME in the error message;
1415 if ERRORNAME is nil, just return nil."
1416 ;; Bind this in case the user sets it to nil.
1417 (let ((case-fold-search t
))
1419 (goto-char (point-min))
1420 (let ((bound (point)))
1422 (cond ((re-search-backward
1423 (concat name
":" (Info-following-node-name-re)) bound t
)
1425 ((not (eq errorname t
))
1426 (error "Node has no %s"
1427 (capitalize (or errorname name
)))))))))
1429 (defun Info-following-node-name-re (&optional allowedchars
)
1430 "Return a regexp matching a node name.
1431 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1432 saying which chars may appear in the node name.
1433 Submatch 1 is the complete node name.
1434 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1435 Submatch 3 is the local part of the node name.
1436 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1437 (concat "[ \t]*" ;Skip leading space.
1438 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1439 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
1440 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
1441 "\\|\\)\\)")) ;Allow empty node names.
1444 "Go to the next node of this node."
1446 (Info-goto-node (Info-extract-pointer "next")))
1449 "Go to the previous node of this node."
1451 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1453 (defun Info-up (&optional same-file
)
1454 "Go to the superior node of this node.
1455 If SAME-FILE is non-nil, do not move to a different Info file."
1457 (let ((node (Info-extract-pointer "up")))
1458 (and (or same-file
(not (stringp Info-current-file
)))
1459 (string-match "^(" node
)
1460 (error "Up node is in another Info file"))
1461 (Info-goto-node node
))
1462 (Info-restore-point Info-history
))
1465 "Go back to the last node visited."
1468 (error "This is the first Info node you looked at"))
1469 (let (filename nodename opoint
)
1470 (setq filename
(car (car Info-history
)))
1471 (setq nodename
(car (cdr (car Info-history
))))
1472 (setq opoint
(car (cdr (cdr (car Info-history
)))))
1473 (setq Info-history
(cdr Info-history
))
1474 (Info-find-node filename nodename
)
1475 (setq Info-history
(cdr Info-history
))
1476 (goto-char opoint
)))
1479 (defun Info-directory ()
1480 "Go to the Info directory node."
1482 (Info-find-node "dir" "top"))
1484 (defun Info-follow-reference (footnotename)
1485 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1486 FOOTNOTENAME may be an abbreviation of the reference name."
1488 (let ((completion-ignore-case t
)
1489 (case-fold-search t
)
1490 completions default alt-default
(start-point (point)) str i bol eol
)
1492 ;; Store end and beginning of line.
1498 (goto-char (point-min))
1499 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
1500 (setq str
(match-string-no-properties 1))
1501 ;; See if this one should be the default.
1503 (<= (match-beginning 0) start-point
)
1504 (<= start-point
(point))
1506 ;; See if this one should be the alternate default.
1507 (and (null alt-default
)
1508 (and (<= bol
(match-beginning 0))
1510 (setq alt-default t
))
1512 (while (setq i
(string-match "[ \n\t]+" str i
))
1513 (setq str
(concat (substring str
0 i
) " "
1514 (substring str
(match-end 0))))
1516 ;; Record as a completion and perhaps as default.
1517 (if (eq default t
) (setq default str
))
1518 (if (eq alt-default t
) (setq alt-default str
))
1519 ;; Don't add this string if it's a duplicate.
1520 (or (assoc-string str completions t
)
1521 (push str completions
))))
1522 ;; If no good default was found, try an alternate.
1524 (setq default alt-default
))
1525 ;; If only one cross-reference found, then make it default.
1526 (if (eq (length completions
) 1)
1527 (setq default
(car completions
)))
1529 (let ((input (completing-read (if default
1531 "Follow reference named: (default "
1533 "Follow reference named: ")
1534 completions nil t
)))
1535 (list (if (equal input
"")
1537 (error "No cross-references in this node"))))
1539 (unless footnotename
1540 (error "No reference was specified"))
1542 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
1543 (case-fold-search t
))
1544 (while (setq i
(string-match " " str i
))
1545 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
1548 (goto-char (point-min))
1549 (or (re-search-forward str nil t
)
1550 (error "No cross-reference named %s" footnotename
))
1551 (goto-char (+ (match-beginning 0) 5))
1553 (Info-extract-menu-node-name t
)))
1554 (while (setq i
(string-match "[ \t\n]+" target i
))
1555 (setq target
(concat (substring target
0 i
) " "
1556 (substring target
(match-end 0))))
1558 (Info-goto-node target
)))
1560 (defconst Info-menu-entry-name-re
"\\(?:[^:\n]\\|:[^:,.;() \t\n]\\)*"
1561 "Regexp that matches a menu entry name upto but not including the colon.
1562 Because of ambiguities, this should be concatenated with something like
1563 `:' and `Info-following-node-name-re'.")
1565 (defun Info-extract-menu-node-name (&optional multi-line
)
1566 (skip-chars-forward " \t\n")
1567 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
1568 (Info-following-node-name-re
1569 (if multi-line
"^.,\t" "^.,\t\n")) "\\)"))
1570 (replace-regexp-in-string
1572 (or (match-string 2)
1573 ;; If the node name is the menu entry name (using `entry::').
1574 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))))
1576 ;; No one calls this.
1577 ;;(defun Info-menu-item-sequence (list)
1579 ;; (Info-menu (car list))
1580 ;; (setq list (cdr list))))
1582 (defvar Info-complete-menu-buffer
)
1583 (defvar Info-complete-next-re nil
)
1584 (defvar Info-complete-cache nil
)
1586 (defconst Info-node-spec-re
1587 (concat (Info-following-node-name-re "^.,:") "[,:.]")
1588 "Regexp to match the text after a : until the terminating `.'.")
1590 (defun Info-complete-menu-item (string predicate action
)
1591 ;; This uses two dynamically bound variables:
1592 ;; - `Info-complete-menu-buffer' which contains the buffer in which
1593 ;; is the menu of items we're trying to complete.
1594 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
1595 ;; also look for menu items in subsequent nodes as long as those
1596 ;; nodes' names match `Info-complete-next-re'. This feature is currently
1597 ;; only used for completion in Info-index.
1599 ;; Note that `Info-complete-menu-buffer' could be current already,
1600 ;; so we want to save point.
1602 (set-buffer Info-complete-menu-buffer
)
1603 (let ((completion-ignore-case t
)
1604 (case-fold-search t
)
1605 (orignode Info-current-node
)
1607 (goto-char (point-min))
1608 (search-forward "\n* Menu:")
1609 (if (not (memq action
'(nil t
)))
1611 (concat "\n\\* +" (regexp-quote string
) ":") nil t
)
1612 (let ((pattern (concat "\n\\* +\\("
1613 (regexp-quote string
)
1614 Info-menu-entry-name-re
"\\):" Info-node-spec-re
))
1617 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
1618 (equal (nth 1 Info-complete-cache
) Info-current-node
)
1619 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
1620 (let ((prev (nth 3 Info-complete-cache
)))
1621 (eq t
(compare-strings string
0 (length prev
)
1623 ;; We can reuse the previous list.
1624 (setq completions
(nth 4 Info-complete-cache
))
1625 ;; The cache can't be used.
1628 (while (re-search-forward pattern nil t
)
1629 (push (match-string-no-properties 1)
1631 ;; Check subsequent nodes if applicable.
1632 (and Info-complete-next-re
1633 (setq nextnode
(Info-extract-pointer "next" t
))
1634 (string-match Info-complete-next-re nextnode
)))
1635 (Info-goto-node nextnode
))
1636 ;; Go back to the start node (for the next completion).
1637 (unless (equal Info-current-node orignode
)
1638 (Info-goto-node orignode
))
1639 ;; Update the cache.
1640 (set (make-local-variable 'Info-complete-cache
)
1641 (list Info-current-file Info-current-node
1642 Info-complete-next-re string completions
)))
1644 (all-completions string completions predicate
)
1645 (try-completion string completions predicate
)))))))
1648 (defun Info-menu (menu-item &optional fork
)
1649 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
1650 The menu item should one of those listed in the current node's menu.
1651 Completion is allowed, and the default menu item is the one point is on.
1652 If FORK is non-nil (interactively with a prefix arg), show the node in
1653 a new info buffer. If FORK is a string, it is the name to use for the
1656 (let ((completions '())
1657 ;; If point is within a menu item, use that item as the default
1662 (case-fold-search t
))
1664 (goto-char (point-min))
1665 (if (not (search-forward "\n* menu:" nil t
))
1666 (error "No menu in this node"))
1672 (if (re-search-backward (concat "\n\\* +\\("
1673 Info-menu-entry-name-re
1675 (setq default
(match-string-no-properties 1))))))
1678 (setq item
(let ((completion-ignore-case t
)
1679 (Info-complete-menu-buffer (current-buffer)))
1680 (completing-read (if default
1681 (format "Menu item (default %s): "
1684 'Info-complete-menu-item nil t
)))
1685 ;; we rely on the fact that completing-read accepts an input
1686 ;; of "" even when the require-match argument is true and ""
1687 ;; is not a valid possibility
1688 (if (string= item
"")
1693 (list item current-prefix-arg
))))
1694 ;; there is a problem here in that if several menu items have the same
1695 ;; name you can only go to the node of the first with this command.
1696 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
1698 (defun Info-extract-menu-item (menu-item)
1699 (setq menu-item
(regexp-quote menu-item
))
1700 (let ((case-fold-search t
))
1702 (let ((case-fold-search t
))
1703 (goto-char (point-min))
1704 (or (search-forward "\n* menu:" nil t
)
1705 (error "No menu in this node"))
1706 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
1707 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
1708 (error "No such item in menu"))
1711 (Info-extract-menu-node-name)))))
1713 ;; If COUNT is nil, use the last item in the menu.
1714 (defun Info-extract-menu-counting (count)
1715 (let ((case-fold-search t
))
1717 (let ((case-fold-search t
))
1718 (goto-char (point-min))
1719 (or (search-forward "\n* menu:" nil t
)
1720 (error "No menu in this node"))
1722 (or (search-forward "\n* " nil t count
)
1723 (error "Too few items in menu"))
1724 (while (search-forward "\n* " nil t
)
1726 (Info-extract-menu-node-name)))))
1728 (defun Info-nth-menu-item ()
1729 "Go to the node of the Nth menu item.
1730 N is the digit argument used to invoke this command."
1733 (Info-extract-menu-counting
1734 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
1736 (defun Info-top-node ()
1737 "Go to the Top node of this file."
1739 (Info-goto-node "Top"))
1741 (defun Info-final-node ()
1742 "Go to the final node in this file."
1744 (Info-goto-node "Top")
1745 (let ((Info-history nil
)
1746 (case-fold-search t
))
1747 ;; Go to the last node in the menu of Top.
1748 (Info-goto-node (Info-extract-menu-counting nil
))
1749 ;; If the last node in the menu is not last in pointer structure,
1750 ;; move forward until we can't go any farther.
1751 (while (Info-forward-node t t
) nil
)
1752 ;; Then keep moving down to last subnode, unless we reach an index.
1753 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1754 (save-excursion (search-forward "\n* Menu:" nil t
)))
1755 (Info-goto-node (Info-extract-menu-counting nil
)))))
1757 (defun Info-forward-node (&optional not-down no-error
)
1758 "Go forward one node, considering all nodes as forming one sequence."
1760 (goto-char (point-min))
1762 (let ((case-fold-search t
))
1763 ;; three possibilities, in order of priority:
1764 ;; 1. next node is in a menu in this node (but not in an index)
1765 ;; 2. next node is next at same level
1766 ;; 3. next node is up and next
1767 (cond ((and (not not-down
)
1768 (save-excursion (search-forward "\n* menu:" nil t
))
1769 (not (string-match "\\<index\\>" Info-current-node
)))
1770 (Info-goto-node (Info-extract-menu-counting 1))
1772 ((save-excursion (search-backward "next:" nil t
))
1775 ((and (save-excursion (search-backward "up:" nil t
))
1776 ;; Use string-equal, not equal, to ignore text props.
1777 (not (string-equal (downcase (Info-extract-pointer "up"))
1779 (let ((old-node Info-current-node
))
1781 (let (Info-history success
)
1783 (setq success
(Info-forward-node t no-error
))
1784 (or success
(Info-goto-node old-node
))))))
1786 (t (error "No pointer forward from this node")))))
1788 (defun Info-backward-node ()
1789 "Go backward one node, considering all nodes as forming one sequence."
1791 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
1792 (upnode (Info-extract-pointer "up" t
))
1793 (case-fold-search t
))
1794 (cond ((and upnode
(string-match "(" upnode
))
1795 (error "First node in file"))
1796 ((and upnode
(or (null prevnode
)
1797 ;; Use string-equal, not equal,
1798 ;; to ignore text properties.
1799 (string-equal (downcase prevnode
)
1800 (downcase upnode
))))
1803 ;; If we move back at the same level,
1804 ;; go down to find the last subnode*.
1807 (while (and (not (string-match "\\<index\\>" Info-current-node
))
1808 (save-excursion (search-forward "\n* Menu:" nil t
)))
1809 (Info-goto-node (Info-extract-menu-counting nil
)))))
1811 (error "No pointer backward from this node")))))
1814 "Exit Info by selecting some other buffer."
1817 (save-buffers-kill-emacs)
1820 (defun Info-next-menu-item ()
1821 "Go to the node of the next menu item."
1823 ;; Bind this in case the user sets it to nil.
1824 (let* ((case-fold-search t
)
1828 (search-forward "\n* menu:" nil t
)
1829 (and (search-forward "\n* " nil t
)
1830 (Info-extract-menu-node-name)))))
1831 (if node
(Info-goto-node node
)
1832 (error "No more items in menu"))))
1834 (defun Info-last-menu-item ()
1835 "Go to the node of the previous menu item."
1839 ;; Bind this in case the user sets it to nil.
1840 (let* ((case-fold-search t
)
1841 (beg (save-excursion
1842 (and (search-backward "\n* menu:" nil t
)
1844 (or (and beg
(search-backward "\n* " beg t
))
1845 (error "No previous items in menu")))
1846 (Info-goto-node (save-excursion
1847 (goto-char (match-end 0))
1848 (Info-extract-menu-node-name)))))
1850 (defmacro Info-no-error
(&rest body
)
1851 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
1853 (defun Info-next-preorder ()
1854 "Go to the next subnode or the next node, or go up a level."
1856 (cond ((Info-no-error (Info-next-menu-item)))
1857 ((Info-no-error (Info-next)))
1858 ((Info-no-error (Info-up t
))
1859 ;; Since we have already gone thru all the items in this menu,
1860 ;; go up to the end of this node.
1861 (goto-char (point-max))
1862 ;; Since logically we are done with the node with that menu,
1864 (Info-next-preorder))
1866 (error "No more nodes"))))
1868 (defun Info-last-preorder ()
1869 "Go to the last node, popping up a level if there is none."
1871 (cond ((Info-no-error
1872 (Info-last-menu-item)
1873 ;; If we go down a menu item, go to the end of the node
1874 ;; so we can scroll back through it.
1875 (goto-char (point-max)))
1876 ;; Keep going down, as long as there are nested menu nodes.
1877 (while (Info-no-error
1878 (Info-last-menu-item)
1879 ;; If we go down a menu item, go to the end of the node
1880 ;; so we can scroll back through it.
1881 (goto-char (point-max))))
1883 ((and (Info-no-error (Info-extract-pointer "prev"))
1884 (not (equal (Info-extract-pointer "up")
1885 (Info-extract-pointer "prev"))))
1886 (Info-no-error (Info-prev))
1887 (goto-char (point-max))
1888 (while (Info-no-error
1889 (Info-last-menu-item)
1890 ;; If we go down a menu item, go to the end of the node
1891 ;; so we can scroll back through it.
1892 (goto-char (point-max))))
1894 ((Info-no-error (Info-up t
))
1895 (goto-char (point-min))
1896 (let ((case-fold-search t
))
1897 (or (search-forward "\n* Menu:" nil t
)
1898 (goto-char (point-max)))))
1899 (t (error "No previous nodes"))))
1901 (defun Info-scroll-up ()
1902 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1903 Once you scroll far enough in a node that its menu appears on the screen
1904 but after point, the next scroll moves into its first subnode, unless
1905 `Info-scroll-prefer-subnodes' is nil.
1907 When you scroll past the end of a node, that goes to the next node if
1908 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
1909 if this node has no successor, it moves to the parent node's successor,
1910 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
1911 the menu of a node, it moves to subnode indicated by the following menu
1912 item. (That case won't normally result from this command, but can happen
1916 (if (or (< (window-start) (point-min))
1917 (> (window-start) (point-max)))
1918 (set-window-start (selected-window) (point)))
1919 (let* ((case-fold-search t
)
1920 (virtual-end (save-excursion
1921 (goto-char (point-min))
1922 (if (and Info-scroll-prefer-subnodes
1923 (search-forward "\n* Menu:" nil t
))
1926 (if (or (< virtual-end
(window-start))
1927 (pos-visible-in-window-p virtual-end
))
1929 (Info-scroll-prefer-subnodes (Info-next-preorder))
1930 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
1931 (t (Info-next-preorder)))
1934 (defun Info-scroll-down ()
1935 "Scroll one screenful back in Info, considering all nodes as one sequence.
1936 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
1937 is non-nil, this goes to its last subnode. When you scroll past the
1938 beginning of a node, that goes to the previous node or back up to the
1941 (if (or (< (window-start) (point-min))
1942 (> (window-start) (point-max)))
1943 (set-window-start (selected-window) (point)))
1944 (let* ((case-fold-search t
)
1945 (current-point (point))
1947 (and Info-scroll-prefer-subnodes
1950 (setq current-point
(point))
1951 (goto-char (point-min))
1952 (search-forward "\n* Menu:"
1956 (pos-visible-in-window-p (point-min) nil t
))
1957 (Info-last-preorder)
1960 (defun Info-next-reference (&optional recur
)
1961 "Move cursor to the next cross-reference or menu item in the node."
1963 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1965 (case-fold-search t
))
1966 (or (eobp) (forward-char 1))
1967 (or (re-search-forward pat nil t
)
1969 (goto-char (point-min))
1970 (or (re-search-forward pat nil t
)
1973 (error "No cross references in this node")))))
1974 (goto-char (match-beginning 0))
1975 (if (looking-at "\\* Menu:")
1977 (error "No cross references in this node")
1978 (Info-next-reference t
)))))
1980 (defun Info-prev-reference (&optional recur
)
1981 "Move cursor to the previous cross-reference or menu item in the node."
1983 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1985 (case-fold-search t
))
1986 (or (re-search-backward pat nil t
)
1988 (goto-char (point-max))
1989 (or (re-search-backward pat nil t
)
1992 (error "No cross references in this node")))))
1993 (goto-char (match-beginning 0))
1994 (if (looking-at "\\* Menu:")
1996 (error "No cross references in this node")
1997 (Info-prev-reference t
)))))
1999 (defun Info-goto-index ()
2000 (Info-goto-node "Top")
2001 (or (search-forward "\n* menu:" nil t
)
2003 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
2005 (goto-char (match-beginning 1))
2006 ;; Protect Info-history so that the current node (Top) is not added to it.
2007 (let ((Info-history nil
))
2008 (Info-goto-node (Info-extract-menu-node-name))))
2011 (defun Info-index (topic)
2012 "Look up a string TOPIC in the index for this file.
2013 The index is defined as the first node in the top level menu whose
2014 name contains the word \"Index\", plus any immediately following
2015 nodes whose names also contain the word \"Index\".
2016 If there are no exact matches to the specified topic, this chooses
2017 the first match which is a case-insensitive substring of a topic.
2018 Use the `,' command to see the other matches.
2019 Give a blank topic name to go to the Index node itself."
2022 (let ((Info-complete-menu-buffer (clone-buffer))
2023 (Info-complete-next-re "\\<Index\\>"))
2024 (if (equal Info-current-file
"dir")
2025 (error "The Info directory node has no index; use m to select a manual"))
2027 (with-current-buffer Info-complete-menu-buffer
2029 (completing-read "Index topic: " 'Info-complete-menu-item
))
2030 (kill-buffer Info-complete-menu-buffer
)))))
2031 (if (equal Info-current-file
"dir")
2032 (error "The Info directory node has no index; use m to select a manual"))
2033 (let ((orignode Info-current-node
)
2034 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
2035 (regexp-quote topic
)))
2037 (case-fold-search t
))
2039 (or (equal topic
"")
2042 ;; We bind Info-history to nil for internal node-switches so
2043 ;; that we don't put junk in the history. In the first
2044 ;; Info-goto-index call, above, we do update the history
2045 ;; because that is what the user's previous node choice into it.
2050 (goto-char (point-min))
2051 (while (re-search-forward pattern nil t
)
2052 (push (list (match-string-no-properties 1)
2053 (match-string-no-properties 2)
2055 (string-to-number (concat "0"
2058 (and (setq node
(Info-extract-pointer "next" t
))
2059 (string-match "\\<Index\\>" node
)))
2060 (Info-goto-node node
))
2063 (Info-goto-node orignode
)
2064 (error "No `%s' in index" topic
)))
2065 ;; Here it is a feature that assoc is case-sensitive.
2066 (while (setq found
(assoc topic matches
))
2067 (setq exact
(cons found exact
)
2068 matches
(delq found matches
)))
2069 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
2070 (Info-index-next 0)))))
2072 (defun Info-index-next (num)
2073 "Go to the next matching index item from the last `i' command."
2075 (or Info-index-alternatives
2076 (error "No previous `i' command"))
2078 (setq num
(+ num
(length Info-index-alternatives
))))
2080 (setq Info-index-alternatives
2081 (nconc (cdr Info-index-alternatives
)
2082 (list (car Info-index-alternatives
)))
2084 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
2085 (if (> (nth 3 (car Info-index-alternatives
)) 0)
2086 (forward-line (nth 3 (car Info-index-alternatives
)))
2087 (forward-line 3) ; don't search in headers
2088 (let ((name (car (car Info-index-alternatives
))))
2089 (Info-find-index-name name
)))
2090 (message "Found `%s' in %s. %s"
2091 (car (car Info-index-alternatives
))
2092 (nth 2 (car Info-index-alternatives
))
2093 (if (cdr Info-index-alternatives
)
2094 "(`,' tries to find next)"
2097 (defun Info-find-index-name (name)
2098 "Move point to the place within the current node where NAME is defined."
2099 (let ((case-fold-search t
))
2100 (if (or (re-search-forward (format
2101 "[a-zA-Z]+: %s\\( \\|$\\)"
2102 (regexp-quote name
)) nil t
)
2103 ;; Find a function definition with a return type.
2104 (re-search-forward (format
2105 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2106 (regexp-quote name
)) nil t
)
2107 (search-forward (format "`%s'" name
) nil t
)
2108 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
2110 (format "`%s'" (substring name
0 (match-beginning 1)))
2112 (search-forward name nil t
))
2114 (goto-char (point-min)))))
2116 (defun Info-undefined ()
2117 "Make command be undefined in Info."
2122 "Enter the Info tutorial."
2124 (delete-other-windows)
2125 (Info-find-node "info"
2126 (if (< (window-height) 23)
2130 (defun Info-summary ()
2131 "Display a brief summary of all Info commands."
2133 (save-window-excursion
2134 (switch-to-buffer "*Help*")
2135 (setq buffer-read-only nil
)
2137 (insert (documentation 'Info-mode
))
2139 (goto-char (point-min))
2141 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
2142 (message (if flag
"Type Space to see more"
2143 "Type Space to return to Info"))
2144 (if (not (eq ?\
(setq ch
(read-event))))
2145 (progn (setq unread-command-events
(list ch
)) nil
)
2148 (bury-buffer "*Help*")))
2150 (defun Info-get-token (pos start all
&optional errorstring
)
2151 "Return the token around POS.
2152 POS must be somewhere inside the token
2153 START is a regular expression which will match the
2154 beginning of the tokens delimited string
2155 ALL is a regular expression with a single
2156 parenthesized subpattern which is the token to be
2157 returned. E.g. '{\(.*\)}' would return any string
2158 enclosed in braces around POS.
2159 ERRORSTRING optional fourth argument, controls action on no match
2162 a string: signal an error, using that string."
2163 (let ((case-fold-search t
))
2166 ;; First look for a match for START that goes across POS.
2167 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
2168 (not (looking-at start
)))
2170 ;; If we did not find one, search back for START
2171 ;; (this finds only matches that end at or before POS).
2172 (or (looking-at start
)
2175 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
2177 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
2178 (not (setq found
(and (<= (match-beginning 0) pos
)
2179 (> (match-end 0) pos
))))))
2180 (if (and found
(<= (match-beginning 0) pos
)
2181 (> (match-end 0) pos
))
2182 (match-string-no-properties 1)
2183 (cond ((null errorstring
)
2189 (error "No %s around position %d" errorstring pos
))))))))
2191 (defun Info-mouse-follow-nearest-node (click)
2192 "\\<Info-mode-map>Follow a node reference near point.
2193 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2194 At end of the node's text, moves to the next node, or up if none."
2196 (mouse-set-point click
)
2197 (and (not (Info-try-follow-nearest-node))
2198 (save-excursion (forward-line 1) (eobp))
2199 (Info-next-preorder)))
2201 (defun Info-follow-nearest-node ()
2202 "Follow a node reference near point.
2203 If point is on a reference, follow that reference. Otherwise,
2204 if point is in a menu item description, follow that menu item."
2206 (or (Info-try-follow-nearest-node)
2207 (when (save-excursion
2208 (search-backward "\n* menu:" nil t
))
2211 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2212 (beginning-of-line 0))
2213 (when (looking-at "\\* +\\([^\t\n]*\\):")
2215 (Info-extract-menu-item (match-string-no-properties 1)))
2217 (error "Point neither on reference nor in menu item description")))
2219 ;; Common subroutine.
2220 (defun Info-try-follow-nearest-node ()
2221 "Follow a node reference near point. Return non-nil if successful."
2224 ((setq node
(Info-get-token (point) "\\*note[ \n]"
2225 "\\*note[ \n]\\([^:]*\\):"))
2226 (Info-follow-reference node
))
2227 ;; menu item: node name
2228 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2229 (Info-goto-node node
))
2230 ;; menu item: index entry
2231 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
2234 (setq node
(Info-extract-menu-node-name))
2235 (Info-goto-node node
))
2236 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2237 (Info-goto-node node
))
2238 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2239 (Info-goto-node node
))
2240 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2241 (Info-goto-node "Top"))
2242 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2243 (Info-goto-node node
)))
2246 (defvar Info-mode-map nil
2247 "Keymap containing Info commands.")
2250 (setq Info-mode-map
(make-keymap))
2251 (suppress-keymap Info-mode-map
)
2252 (define-key Info-mode-map
"." 'beginning-of-buffer
)
2253 (define-key Info-mode-map
" " 'Info-scroll-up
)
2254 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
2255 (define-key Info-mode-map
"\t" 'Info-next-reference
)
2256 (define-key Info-mode-map
"\e\t" 'Info-prev-reference
)
2257 (define-key Info-mode-map
"1" 'Info-nth-menu-item
)
2258 (define-key Info-mode-map
"2" 'Info-nth-menu-item
)
2259 (define-key Info-mode-map
"3" 'Info-nth-menu-item
)
2260 (define-key Info-mode-map
"4" 'Info-nth-menu-item
)
2261 (define-key Info-mode-map
"5" 'Info-nth-menu-item
)
2262 (define-key Info-mode-map
"6" 'Info-nth-menu-item
)
2263 (define-key Info-mode-map
"7" 'Info-nth-menu-item
)
2264 (define-key Info-mode-map
"8" 'Info-nth-menu-item
)
2265 (define-key Info-mode-map
"9" 'Info-nth-menu-item
)
2266 (define-key Info-mode-map
"0" 'undefined
)
2267 (define-key Info-mode-map
"?" 'Info-summary
)
2268 (define-key Info-mode-map
"]" 'Info-forward-node
)
2269 (define-key Info-mode-map
"[" 'Info-backward-node
)
2270 (define-key Info-mode-map
"<" 'Info-top-node
)
2271 (define-key Info-mode-map
">" 'Info-final-node
)
2272 (define-key Info-mode-map
"b" 'beginning-of-buffer
)
2273 (define-key Info-mode-map
"c" 'Info-copy-current-node-name
)
2274 (define-key Info-mode-map
"d" 'Info-directory
)
2275 (define-key Info-mode-map
"e" 'Info-edit
)
2276 (define-key Info-mode-map
"f" 'Info-follow-reference
)
2277 (define-key Info-mode-map
"g" 'Info-goto-node
)
2278 (define-key Info-mode-map
"h" 'Info-help
)
2279 (define-key Info-mode-map
"i" 'Info-index
)
2280 (define-key Info-mode-map
"l" 'Info-last
)
2281 (define-key Info-mode-map
"m" 'Info-menu
)
2282 (define-key Info-mode-map
"n" 'Info-next
)
2283 (define-key Info-mode-map
"p" 'Info-prev
)
2284 (define-key Info-mode-map
"q" 'Info-exit
)
2285 (define-key Info-mode-map
"s" 'Info-search
)
2286 ;; For consistency with Rmail.
2287 (define-key Info-mode-map
"\M-s" 'Info-search
)
2288 (define-key Info-mode-map
"\M-n" 'clone-buffer
)
2289 (define-key Info-mode-map
"t" 'Info-top-node
)
2290 (define-key Info-mode-map
"u" 'Info-up
)
2291 (define-key Info-mode-map
"," 'Info-index-next
)
2292 (define-key Info-mode-map
"\177" 'Info-scroll-down
)
2293 (define-key Info-mode-map
[mouse-2
] 'Info-mouse-follow-nearest-node
)
2296 (defun Info-check-pointer (item)
2297 "Non-nil if ITEM is present in this node."
2299 (Info-extract-pointer item
)
2303 Info-mode-menu Info-mode-map
2304 "Menu for info files."
2306 ["Up" Info-up
:active
(Info-check-pointer "up")
2307 :help
"Go up in the Info tree"]
2308 ["Next" Info-next
:active
(Info-check-pointer "next")
2309 :help
"Go to the next node"]
2310 ["Previous" Info-prev
:active
(Info-check-pointer "prev[ious]*")
2311 :help
"Go to the previous node"]
2312 ["Backward" Info-backward-node
2313 :help
"Go backward one node, considering all as a sequence"]
2314 ["Forward" Info-forward-node
2315 :help
"Go forward one node, considering all as a sequence"]
2316 ["Beginning" beginning-of-buffer
2317 :help
"Go to beginning of this node"]
2318 ["Top" Info-top-node
2319 :help
"Go to top node of file"]
2320 ["Final Node" Info-final-node
2321 :help
"Go to final node in this file"]
2322 ("Menu Item" ["You should never see this" report-emacs-bug t
])
2323 ("Reference" ["You should never see this" report-emacs-bug t
])
2324 ["Search..." Info-search
2325 :help
"Search for regular expression in this Info file"]
2326 ["Go to Node..." Info-goto-node
2327 :help
"Go to a named node"]
2328 ["Last" Info-last
:active Info-history
2329 :help
"Go to the last node you were at"]
2331 ["Lookup a String" Info-index
2332 :help
"Look for a string in the index items"]
2333 ["Next Matching Item" Info-index-next
2334 :help
"Look for another occurrence of previous item"])
2335 ["Edit" Info-edit
:help
"Edit contents of this node"
2336 :active Info-enable-edit
]
2337 ["Copy Node Name" Info-copy-current-node-name
2338 :help
"Copy the name of the current node into the kill ring"]
2339 ["Exit" Info-exit
:help
"Stop reading Info"]))
2342 (defvar info-tool-bar-map
2343 (if (display-graphic-p)
2344 (let ((map (make-sparse-keymap)))
2345 (tool-bar-local-item-from-menu 'Info-exit
"close" map Info-mode-map
)
2346 (tool-bar-local-item-from-menu 'Info-prev
"left_arrow" map Info-mode-map
)
2347 (tool-bar-local-item-from-menu 'Info-next
"right_arrow" map Info-mode-map
)
2348 (tool-bar-local-item-from-menu 'Info-up
"up_arrow" map Info-mode-map
)
2349 (tool-bar-local-item-from-menu 'Info-last
"undo" map Info-mode-map
)
2350 (tool-bar-local-item-from-menu 'Info-top-node
"home" map Info-mode-map
)
2351 (tool-bar-local-item-from-menu 'Info-index
"index" map Info-mode-map
)
2352 (tool-bar-local-item-from-menu 'Info-goto-node
"jump_to" map Info-mode-map
)
2353 (tool-bar-local-item-from-menu 'Info-search
"search" map Info-mode-map
)
2356 (defvar Info-menu-last-node nil
)
2357 ;; Last node the menu was created for.
2358 ;; Value is a list, (FILE-NAME NODE-NAME).
2360 (defun Info-menu-update ()
2361 "Update the Info menu for the current node."
2363 (if (or (not (eq major-mode
'Info-mode
))
2364 (equal (list Info-current-file Info-current-node
)
2365 Info-menu-last-node
))
2367 ;; Update menu menu.
2368 (let* ((Info-complete-menu-buffer (current-buffer))
2369 (items (nreverse (condition-case nil
2370 (Info-complete-menu-item "" nil t
)
2374 (while (and items
(< number
9))
2375 (setq current
(car items
)
2378 (setq entries
(cons `[,current
2379 (Info-menu ,current
)
2380 :keys
,(format "%d" number
)]
2383 (setq entries
(cons ["Other..." Info-menu t
] entries
)))
2385 (setq entries
(list ["No menu" nil nil
] nil
:active
)))
2386 (easy-menu-change '("Info") "Menu Item" (nreverse entries
)))
2387 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2389 str i entries current
2391 (case-fold-search t
))
2393 (goto-char (point-min))
2394 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t
)
2395 (setq str
(match-string 1))
2397 (while (setq i
(string-match "[ \n\t]+" str i
))
2398 (setq str
(concat (substring str
0 i
) " "
2399 (substring str
(match-end 0))))
2403 (while (and items
(< number
9))
2404 (setq current
(car items
)
2407 (setq entries
(cons `[,current
2408 (Info-follow-reference ,current
)
2412 (setq entries
(cons ["Other..." Info-follow-reference t
]
2415 (setq entries
(list ["No references" nil nil
] nil
:active
)))
2416 (easy-menu-change '("Info") "Reference" (nreverse entries
)))
2417 ;; Update last seen node.
2418 (setq Info-menu-last-node
(list Info-current-file Info-current-node
)))
2419 ;; Try to avoid entering infinite beep mode in case of errors.
2423 (defun Info-copy-current-node-name ()
2424 "Put the name of the current info node into the kill ring.
2425 The name of the info file is prepended to the node name in parentheses."
2427 (unless Info-current-node
2428 (error "No current info node"))
2431 (file-name-nondirectory
2432 (if (stringp Info-current-file
)
2434 (or buffer-file-name
"")))
2436 Info-current-node
)))
2439 ;; Info mode is suitable only for specially formatted data.
2440 (put 'Info-mode
'mode-class
'special
)
2441 (put 'Info-mode
'no-clone-indirect t
)
2444 "Info mode provides commands for browsing through the Info documentation tree.
2445 Documentation in Info is divided into \"nodes\", each of which discusses
2446 one topic and contains references to other nodes which discuss related
2447 topics. Info has commands to follow the references and show you other nodes.
2450 \\[Info-help] Invoke the Info tutorial.
2451 \\[Info-exit] Quit Info: reselect previously selected buffer.
2453 Selecting other nodes:
2454 \\[Info-mouse-follow-nearest-node]
2455 Follow a node reference you click on.
2456 This works with menu items, cross references, and
2457 the \"next\", \"previous\" and \"up\", depending on where you click.
2458 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2459 \\[Info-next] Move to the \"next\" node of this node.
2460 \\[Info-prev] Move to the \"previous\" node of this node.
2461 \\[Info-up] Move \"up\" from this node.
2462 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2463 Picking a menu item causes another node to be selected.
2464 \\[Info-directory] Go to the Info directory node.
2465 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2466 \\[Info-last] Move to the last node you were at.
2467 \\[Info-index] Look up a topic in this file's Index and move to that node.
2468 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2469 \\[Info-top-node] Go to the Top node of this file.
2470 \\[Info-final-node] Go to the final node in this file.
2471 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2472 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2474 Moving within a node:
2475 \\[Info-scroll-up] Normally, scroll forward a full screen.
2476 Once you scroll far enough in a node that its menu appears on the
2477 screen but after point, the next scroll moves into its first
2478 subnode. When after all menu items (or if there is no menu),
2479 move up to the parent node.
2480 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2481 already visible, try to go to the previous menu entry, or up
2483 \\[beginning-of-buffer] Go to beginning of node.
2486 \\[Info-copy-current-node-name] Put name of current info node in the kill ring.
2487 \\[Info-edit] Edit contents of selected node.
2488 1 Pick first item in node's menu.
2489 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2490 \\[Info-goto-node] Move to node specified by name.
2491 You may include a filename as well, as (FILENAME)NODENAME.
2492 \\[universal-argument] \\[info] Move to new Info file with completion.
2493 \\[Info-search] Search through this Info file for specified regexp,
2494 and select the node in which the next occurrence is found.
2495 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2496 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2497 (kill-all-local-variables)
2498 (setq major-mode
'Info-mode
)
2499 (setq mode-name
"Info")
2501 (use-local-map Info-mode-map
)
2502 (add-hook 'activate-menubar-hook
'Info-menu-update nil t
)
2503 (set-syntax-table text-mode-syntax-table
)
2504 (setq local-abbrev-table text-mode-abbrev-table
)
2505 (setq case-fold-search t
)
2506 (setq buffer-read-only t
)
2507 (make-local-variable 'Info-current-file
)
2508 (make-local-variable 'Info-current-subfile
)
2509 (make-local-variable 'Info-current-node
)
2510 (make-local-variable 'Info-tag-table-marker
)
2511 (setq Info-tag-table-marker
(make-marker))
2512 (make-local-variable 'Info-tag-table-buffer
)
2513 (setq Info-tag-table-buffer nil
)
2514 (make-local-variable 'Info-history
)
2515 (make-local-variable 'Info-index-alternatives
)
2516 (setq header-line-format
2517 (if Info-use-header-line
2518 '(:eval
(get-text-property (point-min) 'header-line
))
2519 nil
)) ; so the header line isn't displayed
2520 (set (make-local-variable 'tool-bar-map
) info-tool-bar-map
)
2521 ;; This is for the sake of the invisible text we use handling titles.
2522 (make-local-variable 'line-move-ignore-invisible
)
2523 (setq line-move-ignore-invisible t
)
2524 (add-hook 'clone-buffer-hook
'Info-clone-buffer-hook nil t
)
2525 (add-hook 'change-major-mode-hook
'font-lock-defontify nil t
)
2526 (Info-set-mode-line)
2527 (run-hooks 'Info-mode-hook
))
2529 (defun Info-clone-buffer-hook ()
2530 (when (bufferp Info-tag-table-buffer
)
2531 (setq Info-tag-table-buffer
2532 (with-current-buffer Info-tag-table-buffer
(clone-buffer))))
2533 (let ((m Info-tag-table-marker
))
2535 (setq Info-tag-table-marker
2536 (if (and (marker-position m
) (bufferp Info-tag-table-buffer
))
2537 (with-current-buffer Info-tag-table-buffer
2538 (copy-marker (marker-position m
)))
2541 (defvar Info-edit-map
(let ((map (make-sparse-keymap)))
2542 (set-keymap-parent map text-mode-map
)
2543 (define-key map
"\C-c\C-c" 'Info-cease-edit
)
2545 "Local keymap used within `e' command of Info.")
2547 ;; Info-edit mode is suitable only for specially formatted data.
2548 (put 'Info-edit-mode
'mode-class
'special
)
2550 (defun Info-edit-mode ()
2551 "Major mode for editing the contents of an Info node.
2552 Like text mode with the addition of `Info-cease-edit'
2553 which returns to Info mode for browsing.
2555 (use-local-map Info-edit-map
)
2556 (setq major-mode
'Info-edit-mode
)
2557 (setq mode-name
"Info Edit")
2558 (kill-local-variable 'mode-line-buffer-identification
)
2559 (setq buffer-read-only nil
)
2560 (force-mode-line-update)
2561 (buffer-enable-undo (current-buffer))
2562 (run-hooks 'Info-edit-mode-hook
))
2565 "Edit the contents of this Info node.
2566 Allowed only if variable `Info-enable-edit' is non-nil."
2568 (or Info-enable-edit
2569 (error "Editing info nodes is not enabled"))
2571 (message "%s" (substitute-command-keys
2572 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2574 (defun Info-cease-edit ()
2575 "Finish editing Info node; switch back to Info proper."
2577 ;; Do this first, so nothing has changed if user C-g's at query.
2578 (and (buffer-modified-p)
2579 (y-or-n-p "Save the file? ")
2581 (use-local-map Info-mode-map
)
2582 (setq major-mode
'Info-mode
)
2583 (setq mode-name
"Info")
2584 (Info-set-mode-line)
2585 (setq buffer-read-only t
)
2586 (force-mode-line-update)
2587 (and (marker-position Info-tag-table-marker
)
2589 (message "Tags may have changed. Use Info-tagify if necessary")))
2591 (defvar Info-file-list-for-emacs
2592 '("ediff" "eudc" "forms" "gnus" "info" ("mh" .
"mh-e")
2593 "sc" "message" ("dired" .
"dired-x") "viper" "vip" "idlwave"
2594 ("c" .
"ccmode") ("c++" .
"ccmode") ("objc" .
"ccmode")
2595 ("java" .
"ccmode") ("idl" .
"ccmode") ("pike" .
"ccmode")
2596 ("skeleton" .
"autotype") ("auto-insert" .
"autotype")
2597 ("copyright" .
"autotype") ("executable" .
"autotype")
2598 ("time-stamp" .
"autotype") ("quickurl" .
"autotype")
2599 ("tempo" .
"autotype") ("hippie-expand" .
"autotype")
2600 ("cvs" .
"pcl-cvs") ("ada" .
"ada-mode") "calc"
2601 ("calcAlg" .
"calc") ("calcDigit" .
"calc") ("calcVar" .
"calc")
2602 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
2603 ("mail-header" .
"emacs-mime") ("mail-content" .
"emacs-mime")
2604 ("mail-encode" .
"emacs-mime") ("mail-decode" .
"emacs-mime")
2605 ("rfc2045" .
"emacs-mime")
2606 ("rfc2231" .
"emacs-mime") ("rfc2047" .
"emacs-mime")
2607 ("rfc2045" .
"emacs-mime") ("rfc1843" .
"emacs-mime")
2608 ("ietf-drums" .
"emacs-mime") ("quoted-printable" .
"emacs-mime")
2609 ("binhex" .
"emacs-mime") ("uudecode" .
"emacs-mime")
2610 ("mailcap" .
"emacs-mime") ("mm" .
"emacs-mime")
2611 ("mml" .
"emacs-mime"))
2612 "List of Info files that describe Emacs commands.
2613 An element can be a file name, or a list of the form (PREFIX . FILE)
2614 where PREFIX is a name prefix and FILE is the file to look in.
2615 If the element is just a file name, the file name also serves as the prefix.")
2617 (defun Info-find-emacs-command-nodes (command)
2618 "Return a list of locations documenting COMMAND.
2619 The `info-file' property of COMMAND says which Info manual to search.
2620 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2621 defines heuristics for which Info manual to try.
2622 The locations are of the format used in `Info-history', i.e.
2623 \(FILENAME NODENAME BUFFERPOS\)."
2625 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command
))
2626 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
2627 (info-file "emacs")) ;default
2628 ;; Determine which info file this command is documented in.
2629 (if (get command
'info-file
)
2630 (setq info-file
(get command
'info-file
))
2631 ;; If it doesn't say explicitly, test its name against
2632 ;; various prefixes that we know.
2633 (let ((file-list Info-file-list-for-emacs
))
2635 (let* ((elt (car file-list
))
2636 (name (if (consp elt
)
2639 (file (if (consp elt
) (cdr elt
) elt
))
2640 (regexp (concat "\\`" (regexp-quote name
)
2642 (if (string-match regexp
(symbol-name command
))
2643 (setq info-file file file-list nil
))
2644 (setq file-list
(cdr file-list
))))))
2645 (Info-find-node info-file
"Top")
2646 (or (and (search-forward "\n* menu:" nil t
)
2647 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
2648 (error "Info file `%s' appears to lack an index" info-file
))
2649 (goto-char (match-beginning 1))
2650 ;; Bind Info-history to nil, to prevent the index nodes from
2651 ;; getting into the node history.
2652 (let ((Info-history nil
)
2654 (Info-goto-node (Info-extract-menu-node-name))
2657 (goto-char (point-min))
2658 (while (re-search-forward cmd-desc nil t
)
2660 (cons (list Info-current-file
2661 (match-string-no-properties 2)
2664 (and (setq node
(Info-extract-pointer "next" t
))
2665 (string-match "\\<Index\\>" node
)))
2666 (Info-goto-node node
)))
2670 (defun Info-goto-emacs-command-node (command)
2671 "Go to the Info node in the Emacs manual for command COMMAND.
2672 The command is found by looking up in Emacs manual's indices
2673 or in another manual found via COMMAND's `info-file' property or
2674 the variable `Info-file-list-for-emacs'. COMMAND must be a symbol
2676 (interactive "CFind documentation for command: ")
2677 ;; If command is given as a string, convert it to a symbol.
2678 (if (stringp command
)
2679 (setq command
(intern command
)))
2680 (or (commandp command
)
2681 (signal 'wrong-type-argument
(list 'commandp command
)))
2682 (let ((where (Info-find-emacs-command-nodes command
)))
2684 (let ((num-matches (length where
)))
2685 ;; Get Info running, and pop to it in another window.
2686 (save-window-excursion
2688 ;; FIXME It would be cool if this could use a buffer other
2690 (pop-to-buffer "*info*")
2691 ;; Bind Info-history to nil, to prevent the last Index node
2692 ;; visited by Info-find-emacs-command-nodes from being
2693 ;; pushed onto the history.
2694 (let ((Info-history nil
))
2695 (Info-find-node (car (car where
))
2696 (car (cdr (car where
)))))
2697 (if (> num-matches
1)
2699 ;; (car where) will be pushed onto Info-history
2700 ;; when/if they go to another node. Put the other
2701 ;; nodes that were found on the history.
2702 (setq Info-history
(nconc (cdr where
) Info-history
))
2703 (message "Found %d other entr%s. Use %s to see %s."
2705 (if (> num-matches
2) "ies" "y")
2706 (substitute-command-keys "\\[Info-last]")
2707 (if (> num-matches
2) "them" "it")))))
2708 (error "Couldn't find documentation for %s" command
))))
2711 (defun Info-goto-emacs-key-command-node (key)
2712 "Go to the node in the Emacs manual which describes the command bound to KEY.
2714 Interactively, if the binding is `execute-extended-command', a command is read.
2715 The command is found by looking up in Emacs manual's indices
2716 or in another manual found via COMMAND's `info-file' property or
2717 the variable `Info-file-list-for-emacs'."
2718 (interactive "kFind documentation for key: ")
2719 (let ((command (key-binding key
)))
2720 (cond ((null command
)
2721 (message "%s is undefined" (key-description key
)))
2722 ((and (interactive-p)
2723 (eq command
'execute-extended-command
))
2724 (Info-goto-emacs-command-node
2725 (read-command "Find documentation for command: ")))
2727 (Info-goto-emacs-command-node command
)))))
2729 (defface Info-title-1-face
2730 '((((type tty pc
) (class color
)) (:foreground
"yellow" :weight bold
))
2731 (t (:height
1.2 :inherit Info-title-2-face
)))
2732 "Face for Info titles at level 1."
2735 (defface Info-title-2-face
2736 '((((type tty pc
) (class color
)) (:foreground
"lightblue" :weight bold
))
2737 (t (:height
1.2 :inherit Info-title-3-face
)))
2738 "Face for Info titles at level 2."
2741 (defface Info-title-3-face
2742 '((((type tty pc
) (class color
)) (:weight bold
))
2743 (t (:height
1.2 :inherit Info-title-4-face
)))
2744 "Face for Info titles at level 3."
2747 (defface Info-title-4-face
2748 '((((type tty pc
) (class color
)) (:weight bold
))
2749 (t (:weight bold
:inherit variable-pitch
)))
2750 "Face for Info titles at level 4."
2753 (defface info-menu-header
2758 :inherit variable-pitch
2760 "Face for headers in Info menus."
2763 (defun Info-fontify-menu-headers ()
2764 "Add the face `info-menu-header' to any header before a menu entry."
2766 (goto-char (point-min))
2767 (when (re-search-forward "^\\* Menu:" nil t
)
2768 (put-text-property (match-beginning 0) (match-end 0)
2769 'font-lock-face
'info-menu-header
)
2770 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t
)
2771 (put-text-property (match-beginning 1) (match-end 1)
2772 'font-lock-face
'info-menu-header
)))))
2774 (defvar Info-next-link-keymap
2775 (let ((keymap (make-sparse-keymap)))
2776 (define-key keymap
[header-line mouse-1
] 'Info-next
)
2777 (define-key keymap
[header-line mouse-2
] 'Info-next
)
2778 (define-key keymap
[header-line down-mouse-1
] 'ignore
)
2779 (define-key keymap
[mouse-2
] 'Info-next
)
2781 "Keymap to put on the Next link in the text or the header line.")
2783 (defvar Info-prev-link-keymap
2784 (let ((keymap (make-sparse-keymap)))
2785 (define-key keymap
[header-line mouse-1
] 'Info-prev
)
2786 (define-key keymap
[header-line mouse-2
] 'Info-prev
)
2787 (define-key keymap
[header-line down-mouse-1
] 'ignore
)
2788 (define-key keymap
[mouse-2
] 'Info-prev
)
2790 "Keymap to put on the Prev link in the text or the header line.")
2793 (defvar Info-up-link-keymap
2794 (let ((keymap (make-sparse-keymap)))
2795 (define-key keymap
[header-line mouse-1
] 'Info-up
)
2796 (define-key keymap
[header-line mouse-2
] 'Info-up
)
2797 (define-key keymap
[header-line down-mouse-1
] 'ignore
)
2798 (define-key keymap
[mouse-2
] 'Info-up
)
2800 "Keymap to put on the Up link in the text or the header line.")
2802 (defun Info-fontify-node ()
2803 ;; Only fontify the node if it hasn't already been done.
2804 (unless (let ((where (next-property-change (point-min))))
2805 (and where
(not (= where
(point-max)))))
2807 (let ((inhibit-read-only t
)
2808 (case-fold-search t
)
2810 (goto-char (point-min))
2811 (when (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?")
2812 (goto-char (match-end 0))
2813 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2814 (goto-char (match-end 0))
2815 (let* ((nbeg (match-beginning 2))
2816 (nend (match-end 2))
2817 (tbeg (match-beginning 1))
2818 (tag (match-string 1)))
2819 (if (string-equal tag
"Node")
2820 (put-text-property nbeg nend
'font-lock-face
'info-header-node
)
2821 (put-text-property nbeg nend
'font-lock-face
'info-header-xref
)
2822 (put-text-property tbeg nend
'mouse-face
'highlight
)
2823 (put-text-property tbeg nend
2825 (concat "Go to node "
2826 (buffer-substring nbeg nend
)))
2827 ;; Always set up the text property keymap.
2828 ;; It will either be used in the buffer
2829 ;; or copied in the header line.
2830 (put-text-property tbeg nend
'keymap
2832 ((equal tag
"Prev") Info-prev-link-keymap
)
2833 ((equal tag
"Next") Info-next-link-keymap
)
2834 ((equal tag
"Up") Info-up-link-keymap
))))))
2835 (when Info-use-header-line
2836 (goto-char (point-min))
2837 (let ((header-end (line-end-position))
2839 ;; If we find neither Next: nor Prev: link, show the entire
2840 ;; node header. Otherwise, don't show the File: and Node:
2841 ;; parts, to avoid wasting precious space on information that
2842 ;; is available in the mode line.
2843 (if (re-search-forward
2844 "\\(next\\|up\\|prev[ious]*\\): "
2847 (goto-char (match-beginning 1))
2848 (setq header
(buffer-substring (point) header-end
)))
2849 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" header-end t
)
2851 (concat "No next, prev or up links -- "
2852 (buffer-substring (point) header-end
)))
2853 (setq header
(buffer-substring (point) header-end
))))
2855 (put-text-property (point-min) (1+ (point-min))
2856 'header-line header
)
2857 ;; Hide the part of the first line
2858 ;; that is in the header, if it is just part.
2860 ;; Hide the punctuation at the end, too.
2861 (skip-chars-backward " \t,")
2862 (put-text-property (point) header-end
'invisible t
)))))
2863 (goto-char (point-min))
2864 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
2866 (let* ((c (preceding-char))
2868 (cond ((= c ?
*) 'Info-title-1-face
)
2869 ((= c ?
=) 'Info-title-2-face
)
2870 ((= c ?-
) 'Info-title-3-face
)
2871 (t 'Info-title-4-face
))))
2872 (put-text-property (match-beginning 1) (match-end 1)
2873 'font-lock-face face
))
2874 ;; This is a serious problem for trying to handle multiple
2875 ;; frame types at once. We want this text to be invisible
2876 ;; on frames that can display the font above.
2877 (when (memq (framep (selected-frame)) '(x pc w32 mac
))
2878 (add-text-properties (1- (match-beginning 2)) (match-end 2)
2879 '(invisible t front-sticky nil rear-nonsticky t
))))
2880 (goto-char (point-min))
2881 (while (re-search-forward "\\(\\*Note[ \t]*\\)\n?[ \t]*\\([^:]*\\)\\(:[^.,:(]*\\(([^)]*)[^.,:]*\\)?[,:]?\n?\\)" nil t
)
2882 (unless (= (char-after (1- (match-beginning 0))) ?
\") ; hack
2883 (let ((start (match-beginning 0))
2885 (hide-tag Info-hide-note-references
)
2888 ;; *Note is often used where *note should have been
2890 (skip-syntax-backward " ")
2892 (cond ((memq (char-before) '(nil ?\. ?
! ??
))
2894 ((memq (char-before) '(?\
, ?\
; ?\: ?-))
2896 ((memq (char-before) '(?\
( ?\
[ ?\
{))
2897 ;; Check whether the paren is preceded by
2898 ;; an end of sentence
2899 (skip-syntax-backward " (")
2900 (if (memq (char-before) '(nil ?\. ?
! ??
))
2903 ((save-match-data (looking-at "\n\n"))
2907 (add-text-properties (match-beginning 1) (match-end 1)
2908 '(invisible t front-sticky nil rear-nonsticky t
)))
2909 (add-text-properties
2910 (match-beginning 2) (match-end 2)
2912 (cons (if (match-end 4)
2913 (concat "mouse-2: go to " (match-string 4))
2914 "mouse-2: go to this node")
2915 '(font-lock-face info-xref
2916 mouse-face highlight
))))
2917 (when (eq Info-hide-note-references t
)
2918 (add-text-properties (match-beginning 3) (match-end 3)
2919 '(invisible t front-sticky nil rear-nonsticky t
)))
2922 (goto-char (match-beginning 1))
2923 (insert other-tag
)))
2924 (when (and Info-refill-paragraphs
2925 (or hide-tag
(eq Info-hide-note-references t
)))
2926 (push (set-marker (make-marker) start
)
2927 paragraph-markers
)))))
2929 (when (and Info-refill-paragraphs
2931 (let ((fill-nobreak-invisible t
)
2932 (fill-individual-varying-indent nil
)
2933 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
2934 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
2935 (adaptive-fill-mode nil
))
2936 (goto-char (point-max))
2937 (while paragraph-markers
2938 (let ((m (car paragraph-markers
)))
2939 (setq paragraph-markers
(cdr paragraph-markers
))
2943 (let ((beg (point)))
2944 (when (zerop (forward-paragraph))
2945 (fill-individual-paragraphs beg
(point) nil nil
)
2947 (set-marker m nil
)))))
2949 (goto-char (point-min))
2950 (when (and (search-forward "\n* Menu:" nil t
)
2951 (not (string-match "\\<Index\\>" Info-current-node
))
2952 ;; Don't take time to annotate huge menus
2953 (< (- (point-max) (point)) Info-fontify-maximum-menu-size
))
2956 (while (re-search-forward
2957 (concat "^\\* +\\(" Info-menu-entry-name-re
"\\)\\(:"
2958 Info-node-spec-re
"\\([ \t]*\\)\\)")
2961 (if (and (<= n
9) (zerop (% n
3))) ; visual aids to help with 1-9 keys
2962 (put-text-property (match-beginning 0)
2963 (1+ (match-beginning 0))
2964 'font-lock-face
'info-menu-5
))
2965 (add-text-properties
2966 (match-beginning 1) (match-end 1)
2970 (concat "mouse-2: go to " (match-string 3))
2971 "mouse-2: go to this node")
2972 '(font-lock-face info-xref
2973 mouse-face highlight
))))
2974 (when (eq Info-hide-note-references t
)
2975 (put-text-property (match-beginning 2) (1- (match-end 6))
2977 ;; We need a stretchable space like :align-to but with
2979 (put-text-property (1- (match-end 6)) (match-end 6) 'display
2980 (if (>= 22 (- (match-end 1)
2981 (match-beginning 0)))
2982 '(space :align-to
24)
2984 (setq cont
(looking-at "."))
2985 (while (and (= (forward-line 1) 0)
2986 (looking-at "\\([ \t]+\\)[^*\n]"))
2987 (put-text-property (match-beginning 1) (1- (match-end 1))
2989 (put-text-property (1- (match-end 1)) (match-end 1)
2992 '(space :align-to
26)
2993 '(space :align-to
24)))
2996 (Info-fontify-menu-headers)
2997 (set-buffer-modified-p nil
)))))
3000 ;; When an Info buffer is killed, make sure the associated tags buffer
3002 (defun Info-kill-buffer ()
3003 (and (eq major-mode
'Info-mode
)
3004 Info-tag-table-buffer
3005 (kill-buffer Info-tag-table-buffer
)))
3007 (add-hook 'kill-buffer-hook
'Info-kill-buffer
)
3009 ;;; Speedbar support:
3010 ;; These functions permit speedbar to display the "tags" in the
3011 ;; current info node.
3012 (eval-when-compile (require 'speedbar
))
3014 (defvar Info-speedbar-key-map nil
3015 "Keymap used when in the info display mode.")
3017 (defun Info-install-speedbar-variables ()
3018 "Install those variables used by speedbar to enhance Info."
3019 (if Info-speedbar-key-map
3021 (setq Info-speedbar-key-map
(speedbar-make-specialized-keymap))
3023 ;; Basic tree features
3024 (define-key Info-speedbar-key-map
"e" 'speedbar-edit-line
)
3025 (define-key Info-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
3026 (define-key Info-speedbar-key-map
"+" 'speedbar-expand-line
)
3027 (define-key Info-speedbar-key-map
"-" 'speedbar-contract-line
)
3030 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
3031 Info-speedbar-key-map
3032 Info-speedbar-hierarchy-buttons
)))
3034 (defvar Info-speedbar-menu-items
3035 '(["Browse Node" speedbar-edit-line t
]
3036 ["Expand Node" speedbar-expand-line
3037 (save-excursion (beginning-of-line)
3038 (looking-at "[0-9]+: *.\\+. "))]
3039 ["Contract Node" speedbar-contract-line
3040 (save-excursion (beginning-of-line)
3041 (looking-at "[0-9]+: *.-. "))]
3043 "Additional menu-items to add to speedbar frame.")
3045 ;; Make sure our special speedbar major mode is loaded
3046 (if (featurep 'speedbar
)
3047 (Info-install-speedbar-variables)
3048 (add-hook 'speedbar-load-hook
'Info-install-speedbar-variables
))
3050 ;;; Info hierarchy display method
3052 (defun Info-speedbar-browser ()
3053 "Initialize speedbar to display an info node browser.
3054 This will add a speedbar major display mode."
3057 ;; Make sure that speedbar is active
3058 (speedbar-frame-mode 1)
3059 ;; Now, throw us into Info mode on speedbar.
3060 (speedbar-change-initial-expansion-list "Info")
3063 (eval-when-compile (defvar speedbar-attached-frame
))
3065 (defun Info-speedbar-hierarchy-buttons (directory depth
&optional node
)
3066 "Display an Info directory hierarchy in speedbar.
3067 DIRECTORY is the current directory in the attached frame.
3068 DEPTH is the current indentation depth.
3069 NODE is an optional argument that is used to represent the
3070 specific node to expand."
3072 (save-excursion (goto-char (point-min))
3073 (let ((case-fold-search t
))
3074 (looking-at "Info Nodes:"))))
3075 ;; Update our "current node" maybe?
3077 ;; We cannot use the generic list code, that depends on all leaves
3078 ;; being known at creation time.
3080 (speedbar-with-writable (insert "Info Nodes:\n")))
3081 (let ((completions nil
)
3082 (cf (selected-frame)))
3083 (select-frame speedbar-attached-frame
)
3084 (save-window-excursion
3086 (Info-speedbar-fetch-file-nodes (or node
'"(dir)top"))))
3089 (speedbar-with-writable
3090 (dolist (completion completions
)
3091 (speedbar-make-tag-line 'bracket ?
+ 'Info-speedbar-expand-node
3094 'Info-speedbar-goto-node
3100 (defun Info-speedbar-goto-node (text node indent
)
3101 "When user clicks on TEXT, go to an info NODE.
3102 The INDENT level is ignored."
3103 (select-frame speedbar-attached-frame
)
3104 (let* ((buff (or (get-buffer "*info*")
3105 (progn (info) (get-buffer "*info*"))))
3106 (bwin (get-buffer-window buff
0)))
3109 (select-window bwin
)
3110 (raise-frame (window-frame bwin
)))
3111 (if speedbar-power-click
3112 (let ((pop-up-frames t
)) (select-window (display-buffer buff
)))
3113 (select-frame speedbar-attached-frame
)
3114 (switch-to-buffer buff
)))
3115 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node
))
3116 (error "Invalid node %s" node
)
3117 (Info-find-node (match-string 1 node
) (match-string 2 node
))
3118 ;; If we do a find-node, and we were in info mode, restore
3119 ;; the old default method. Once we are in info mode, it makes
3120 ;; sense to return to whatever method the user was using before.
3121 (if (string= speedbar-initial-expansion-list-name
"Info")
3122 (speedbar-change-initial-expansion-list
3123 speedbar-previously-used-expansion-list-name
)))))
3125 (defun Info-speedbar-expand-node (text token indent
)
3126 "Expand the node the user clicked on.
3127 TEXT is the text of the button we clicked on, a + or - item.
3128 TOKEN is data related to this node (NAME . FILE).
3129 INDENT is the current indentation depth."
3130 (cond ((string-match "+" text
) ;we have to expand this file
3131 (speedbar-change-expand-button-char ?-
)
3132 (if (speedbar-with-writable
3134 (end-of-line) (forward-char 1)
3135 (Info-speedbar-hierarchy-buttons nil
(1+ indent
) token
)))
3136 (speedbar-change-expand-button-char ?-
)
3137 (speedbar-change-expand-button-char ??
)))
3138 ((string-match "-" text
) ;we have to contract this node
3139 (speedbar-change-expand-button-char ?
+)
3140 (speedbar-delete-subblock indent
))
3141 (t (error "Ooops... not sure what to do")))
3142 (speedbar-center-buffer-smartly))
3144 (defun Info-speedbar-fetch-file-nodes (nodespec)
3145 "Fetch the subnodes from the info NODESPEC.
3146 NODESPEC is a string of the form: (file)node.
3147 Optional THISFILE represends the filename of"
3149 ;; Set up a buffer we can use to fake-out Info.
3150 (set-buffer (get-buffer-create "*info-browse-tmp*"))
3151 (if (not (equal major-mode
'Info-mode
))
3153 ;; Get the node into this buffer
3154 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec
))
3155 (error "Invalid node specification %s" nodespec
)
3156 (Info-find-node (match-string 1 nodespec
) (match-string 2 nodespec
)))
3157 ;; Scan the created buffer
3158 (goto-char (point-min))
3159 (let ((completions nil
)
3160 (case-fold-search t
)
3161 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec
)
3162 (match-string 1 nodespec
))))
3163 ;; Always skip the first one...
3164 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
3165 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t
)
3166 (let ((name (match-string 1)))
3168 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
3170 (if (looking-at " *\\(([^)]+)\\)\\.")
3171 (concat (match-string 1) "Top")
3172 (concat "(" thisfile
")"
3173 (if (looking-at " \\([^.]+\\).")
3177 (nreverse completions
))))
3179 ;;; Info mode node listing
3180 ;; FIXME: Seems not to be used. -stef
3181 (defun Info-speedbar-buttons (buffer)
3182 "Create a speedbar display to help navigation in an Info file.
3183 BUFFER is the buffer speedbar is requesting buttons for."
3184 (if (save-excursion (goto-char (point-min))
3185 (let ((case-fold-search t
))
3186 (not (looking-at "Info Nodes:"))))
3188 (Info-speedbar-hierarchy-buttons nil
0)
3191 (dolist (mess '("^Node has no Previous$"
3192 "^No menu in this node$"
3193 "^Node has no Next$"
3194 "^No cross-references in this node^"
3196 "^No \".*\" in index$"))
3197 (add-to-list 'debug-ignored-errors mess
))
3201 ;;; info.el ends here