1 ;;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985,86,92,93,94,95,96,97,98,99,2000,01,02,03,2004
4 ;; Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
28 ;; Note that nowadays we expect info files to be made using makeinfo.
29 ;; In particular we make these assumptions:
30 ;; - a menu item MAY contain colons but not colon-space ": "
31 ;; - a menu item ending with ": " (but not ":: ") is an index entry
32 ;; - a node name MAY NOT contain a colon
33 ;; This distinction is to support indexing of computer programming
34 ;; language terms that may contain ":" but not ": ".
38 (eval-when-compile (require 'jka-compr
))
46 (defvar Info-history nil
47 "Stack of info nodes user has visited.
48 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
50 (defvar Info-history-list nil
51 "List of all info nodes user has visited.
52 Each element of list is a list (FILENAME NODENAME).")
54 (defcustom Info-enable-edit nil
55 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
56 This is convenient if you want to write info files by hand.
57 However, we recommend that you not do this.
58 It is better to write a Texinfo file and generate the Info file from that,
59 because that gives you a printed manual as well."
63 (defvar Info-enable-active-nodes nil
64 "Non-nil allows Info to execute Lisp code associated with nodes.
65 The Lisp code is executed when the node is selected.")
66 (put 'Info-enable-active-nodes
'risky-local-variable t
)
69 '((((class color
) (background light
)) (:foreground
"brown" :weight bold
:slant italic
))
70 (((class color
) (background dark
)) (:foreground
"white" :weight bold
:slant italic
))
71 (t (:weight bold
:slant italic
)))
72 "Face for Info node names."
76 '((((class color
)) (:foreground
"red1"))
78 "Face for every third `*' in an Info menu."
82 '((((class color
) (background light
)) (:foreground
"blue"))
83 (((class color
) (background dark
)) (:foreground
"cyan"))
85 "Face for Info cross-references."
88 (defface info-xref-visited
89 '((((class color
) (background light
)) (:foreground
"magenta4"))
90 (((class color
) (background dark
)) (:foreground
"magenta4"))
92 "Face for visited Info cross-references."
95 (defcustom Info-fontify-visited-nodes t
96 "*Non-nil means to fontify visited nodes in a different face."
101 (defcustom Info-fontify-maximum-menu-size
100000
102 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
106 (defcustom Info-use-header-line t
107 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
108 A header-line does not scroll with the rest of the buffer."
112 (defface info-header-xref
113 '((t (:inherit info-xref
)))
114 "Face for Info cross-references in a node header."
117 (defface info-header-node
118 '((t (:inherit info-node
)))
119 "Face for Info nodes in a node header."
122 (defvar Info-directory-list nil
123 "List of directories to search for Info documentation files.
124 If nil, meaning not yet initialized, Info uses the environment
125 variable INFOPATH to initialize it, or `Info-default-directory-list'
126 if there is no INFOPATH variable in the environment, or the
127 concatenation of the two if INFOPATH ends with a colon.
129 When `Info-directory-list' is initialized from the value of
130 `Info-default-directory-list', and Emacs is installed in one of the
131 standard directories, the directory of Info files that come with Emacs
132 is put last (so that local Info files override standard ones).
134 When `Info-directory-list' is initialized from the value of
135 `Info-default-directory-list', and Emacs is not installed in one
136 of the standard directories, the first element of the resulting
137 list is the directory where Emacs installs the Info files that
138 come with it. This is so that Emacs's own manual, which suits the
139 version of Emacs you are using, will always be found first. This
140 is useful when you install an experimental version of Emacs without
141 removing the standard installation.
143 If you want to override the order of directories in
144 `Info-default-directory-list', set INFOPATH in the environment.
146 If you run the Emacs executable from the `src' directory in the Emacs
147 source tree, and INFOPATH is not defined, the `info' directory in the
148 source tree is used as the first element of `Info-directory-list', in
149 place of the installation Info directory. This is useful when you run
150 a version of Emacs without installing it.")
152 (defcustom Info-additional-directory-list nil
153 "List of additional directories to search for Info documentation files.
154 These directories are searched after those in `Info-directory-list'."
155 :type
'(repeat directory
)
158 (defcustom Info-scroll-prefer-subnodes nil
159 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
160 If this is non-nil, and you scroll far enough in a node that its menu
161 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
162 moves to a subnode indicated by the following menu item. This means
163 that you visit a subnode before getting to the end of the menu.
165 Setting this option to nil results in behavior similar to the stand-alone
166 Info reader program, which visits the first subnode from the menu only
167 when you hit the end of the current node."
172 (defcustom Info-hide-note-references t
173 "*If non-nil, hide the tag and section reference in *note and * menu items.
174 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
175 If value is non-nil but not t or `hide', the reference section is still shown."
177 :type
'(choice (const :tag
"No hiding" nil
)
178 (const :tag
"Replace tag and hide reference" t
)
179 (const :tag
"Hide tag and reference" hide
)
180 (other :tag
"Only replace tag" tag
))
183 (defcustom Info-refill-paragraphs nil
184 "*If non-nil, attempt to refill paragraphs with hidden references.
185 This refilling may accidentally remove explicit line breaks in the info
186 file, so be prepared for a few surprises if you enable this feature."
191 (defcustom Info-search-whitespace-regexp
"\\\\(?:\\\\s-+\\\\)"
192 "*If non-nil, regular expression to match a sequence of whitespace chars.
193 This applies to Info search for regular expressions.
194 You might want to use something like \"[ \\t\\r\\n]+\" instead.
195 In the Customization buffer, that is `[' followed by a space,
196 a tab, a carriage return (control-M), a newline, and `]+'."
200 (defcustom Info-mode-hook
201 ;; Try to obey obsolete Info-fontify settings.
202 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
203 '(turn-on-font-lock))
204 "Hooks run when `Info-mode' is called."
208 (defcustom Info-selection-hook nil
209 "Hooks run when `Info-select-node' is called."
213 (defvar Info-edit-mode-hook nil
214 "Hooks run when `Info-edit-mode' is called.")
216 (defvar Info-current-file nil
217 "Info file that Info is now looking at, or nil.
218 This is the name that was specified in Info, not the actual file name.
219 It doesn't contain directory names or file name extensions added by Info.
220 Can also be t when using `Info-on-current-buffer'.")
222 (defvar Info-current-subfile nil
223 "Info subfile that is actually in the *info* buffer now.
224 nil if current info file is not split into subfiles.")
226 (defvar Info-current-node nil
227 "Name of node that Info is now looking at, or nil.")
229 (defvar Info-tag-table-marker nil
230 "Marker pointing at beginning of current Info file's tag table.
231 Marker points nowhere if file has no tag table.")
233 (defvar Info-tag-table-buffer nil
234 "Buffer used for indirect tag tables.")
236 (defvar Info-current-file-completions nil
237 "Cached completion list for current Info file.")
239 (defvar Info-index-alternatives nil
240 "List of possible matches for last `Info-index' command.")
242 (defvar Info-reference-name nil
243 "Name of the selected cross-reference.
244 Point is moved to the proper occurrence of this name within a node
245 after selecting it.")
247 (defvar Info-standalone nil
248 "Non-nil if Emacs was started solely as an Info browser.")
250 (defvar Info-suffix-list
251 ;; The MS-DOS list should work both when long file names are
252 ;; supported (Windows 9X), and when only 8+3 file names are available.
253 (if (eq system-type
'ms-dos
)
254 '( (".gz" .
"gunzip")
256 (".bz2" .
("bzip2" "-dc"))
259 (".info.Z" .
"gunzip")
260 (".info.gz" .
"gunzip")
261 ("-info.Z" .
"gunzip")
262 ("-info.gz" .
"gunzip")
263 ("/index.gz".
"gunzip")
264 ("/index.z" .
"gunzip")
270 '( (".info.Z".
"uncompress")
271 (".info.Y".
"unyabba")
272 (".info.gz".
"gunzip")
273 (".info.z".
"gunzip")
274 (".info.bz2" .
("bzip2" "-dc"))
276 ("-info.Z".
"uncompress")
277 ("-info.Y".
"unyabba")
278 ("-info.gz".
"gunzip")
279 ("-info.bz2" .
("bzip2" "-dc"))
280 ("-info.z".
"gunzip")
282 ("/index.Z".
"uncompress")
283 ("/index.Y".
"unyabba")
284 ("/index.gz".
"gunzip")
285 ("/index.z".
"gunzip")
286 ("/index.bz2".
("bzip2" "-dc"))
292 (".bz2" .
("bzip2" "-dc"))
294 "List of file name suffixes and associated decoding commands.
295 Each entry should be (SUFFIX . STRING); the file is given to
296 the command as standard input.
298 STRING may be a list of strings. In that case, the first element is
299 the command name, and the rest are arguments to that command.
301 If STRING is nil, no decoding is done.
302 Because the SUFFIXes are tried in order, the empty string should
303 be last in the list.")
305 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
306 ;; First, on MS-DOS with no long file names support, delete some of
307 ;; the extension in FILENAME to make room.
308 (defun info-insert-file-contents-1 (filename suffix lfn
)
309 (if lfn
; long file names are supported
310 (concat filename suffix
)
311 (let* ((sans-exts (file-name-sans-extension filename
))
312 ;; How long is the extension in FILENAME (not counting the dot).
313 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
315 ;; SUFFIX starts with a dot. If FILENAME already has one,
316 ;; get rid of the one in SUFFIX (unless suffix is empty).
317 (or (and (<= ext-len
0)
318 (not (eq (aref filename
(1- (length filename
))) ?.
)))
319 (= (length suffix
) 0)
320 (setq suffix
(substring suffix
1)))
321 ;; How many chars of that extension should we keep?
322 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
323 ;; Get rid of the rest of the extension, and add SUFFIX.
324 (concat (substring filename
0 (- (length filename
)
325 (- ext-len ext-left
)))
328 (defun info-file-exists-p (filename)
329 (and (file-exists-p filename
)
330 (not (file-directory-p filename
))))
332 (defun info-insert-file-contents (filename &optional visit
)
333 "Insert the contents of an info file in the current buffer.
334 Do the right thing if the file has been compressed or zipped."
335 (let* ((tail Info-suffix-list
)
336 (lfn (if (fboundp 'msdos-long-file-names
)
337 (msdos-long-file-names)
339 (check-short (and (fboundp 'msdos-long-file-names
)
341 fullname decoder done
)
342 (if (info-file-exists-p filename
)
343 ;; FILENAME exists--see if that name contains a suffix.
344 ;; If so, set DECODE accordingly.
348 (concat (regexp-quote (car (car tail
))) "$")
350 (setq tail
(cdr tail
)))
351 (setq fullname filename
352 decoder
(cdr (car tail
))))
353 ;; Try adding suffixes to FILENAME and see if we can find something.
354 (while (and tail
(not done
))
355 (setq fullname
(info-insert-file-contents-1 filename
356 (car (car tail
)) lfn
))
357 (if (info-file-exists-p fullname
)
359 ;; If we found a file with a suffix, set DECODER
360 ;; according to the suffix.
361 decoder
(cdr (car tail
)))
362 ;; When the MS-DOS port runs on Windows, we need to check
363 ;; the short variant of a long file name as well.
365 (setq fullname
(info-insert-file-contents-1 filename
366 (car (car tail
)) nil
))
367 (if (info-file-exists-p fullname
)
369 decoder
(cdr (car tail
))))))
370 (setq tail
(cdr tail
)))
372 (error "Can't find %s or any compressed version of it" filename
)))
373 ;; check for conflict with jka-compr
374 (if (and (featurep 'jka-compr
)
375 (jka-compr-installed-p)
376 (jka-compr-get-compression-info fullname
))
380 (insert-file-contents-literally fullname visit
)
381 (let ((buffer-read-only nil
)
382 (coding-system-for-write 'no-conversion
)
383 (default-directory (or (file-name-directory fullname
)
386 (setq decoder
(list decoder
)))
387 (apply 'call-process-region
(point-min) (point-max)
388 (car decoder
) t t nil
(cdr decoder
))))
389 (insert-file-contents fullname visit
))))
391 (defun Info-default-dirs ()
392 (let ((source (expand-file-name "info/" source-directory
))
393 (sibling (if installation-directory
394 (expand-file-name "info/" installation-directory
)
395 (if invocation-directory
396 (let ((infodir (expand-file-name
398 invocation-directory
)))
399 (if (file-exists-p infodir
)
401 (setq infodir
(expand-file-name
403 invocation-directory
))
404 (and (file-exists-p infodir
)
408 (if (and sibling
(file-exists-p sibling
))
409 ;; Uninstalled, Emacs builddir != srcdir.
411 ;; Uninstalled, builddir == srcdir
413 (if (or (member alternative Info-default-directory-list
)
414 ;; On DOS/NT, we use movable executables always,
415 ;; and we must always find the Info dir at run time.
416 (if (memq system-type
'(ms-dos windows-nt
))
418 ;; Use invocation-directory for Info
419 ;; only if we used it for exec-directory also.
420 (not (string= exec-directory
421 (expand-file-name "lib-src/"
422 installation-directory
))))
423 (not (file-exists-p alternative
)))
424 Info-default-directory-list
425 ;; `alternative' contains the Info files that came with this
426 ;; version, so we should look there first. `Info-insert-dir'
427 ;; currently expects to find `alternative' first on the list.
429 ;; Don't drop the last part, it might contain non-Emacs stuff.
430 ;; (reverse (cdr (reverse
431 Info-default-directory-list
)))) ;; )))
433 (defun info-initialize ()
434 "Initialize `Info-directory-list', if that hasn't been done yet."
435 (unless Info-directory-list
436 (let ((path (getenv "INFOPATH")))
437 (setq Info-directory-list
438 (prune-directory-list
440 (if (string-match ":\\'" path
)
441 (append (split-string (substring path
0 -
1)
442 (regexp-quote path-separator
))
444 (split-string path
(regexp-quote path-separator
)))
445 (Info-default-dirs)))))))
448 (defun info-other-window (&optional file
)
449 "Like `info' but show the Info buffer in another window."
450 (interactive (if current-prefix-arg
451 (list (read-file-name "Info file name: " nil nil t
))))
452 (let (same-window-buffer-names)
455 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
458 (defun info (&optional file
)
459 "Enter Info, the documentation browser.
460 Optional argument FILE specifies the file to examine;
461 the default is the top-level directory of Info.
462 Called from a program, FILE may specify an Info node of the form
463 `(FILENAME)NODENAME'.
465 In interactive use, a prefix argument directs this command
466 to read a file name from the minibuffer.
468 The search path for Info files is in the variable `Info-directory-list'.
469 The top-level Info directory is made by combining all the files named `dir'
470 in all the directories in that path."
471 (interactive (if current-prefix-arg
472 (list (read-file-name "Info file name: " nil nil t
))))
473 (pop-to-buffer "*info*")
475 ;; If argument already contains parentheses, don't add another set
476 ;; since the argument will then be parsed improperly. This also
477 ;; has the added benefit of allowing node names to be included
478 ;; following the parenthesized filename.
479 (if (and (stringp file
) (string-match "(.*)" file
))
480 (Info-goto-node file
)
481 (Info-goto-node (concat "(" file
")")))
482 (if (zerop (buffer-size))
486 (defun info-emacs-manual ()
487 "Display the Emacs manual in Info mode."
492 (defun info-standalone ()
493 "Run Emacs as a standalone Info reader.
494 Usage: emacs -f info-standalone [filename]
495 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
496 (setq Info-standalone t
)
497 (if (and command-line-args-left
498 (not (string-match "^-" (car command-line-args-left
))))
501 (info (car command-line-args-left
))
502 (setq command-line-args-left
(cdr command-line-args-left
)))
503 (error (send-string-to-terminal
504 (format "%s\n" (if (eq (car-safe err
) 'error
)
506 (save-buffers-kill-emacs)))
509 ;; See if the accessible portion of the buffer begins with a node
510 ;; delimiter, and the node header line which follows matches REGEXP.
511 ;; Typically, this test will be followed by a loop that examines the
512 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
513 ;; to have the overhead of this special test inside the loop.
515 ;; This function changes match-data, but supposedly the caller might
516 ;; want to use the results of re-search-backward.
518 ;; The return value is the value of point at the beginning of matching
519 ;; REGEXP, if the function succeeds, nil otherwise.
520 (defun Info-node-at-bob-matching (regexp)
521 (and (bobp) ; are we at beginning of buffer?
522 (looking-at "\^_") ; does it begin with node delimiter?
526 (forward-line 1) ; does the line after delimiter match REGEXP?
527 (re-search-backward regexp beg t
))))
529 (defun Info-find-file (filename &optional noerror
)
530 "Return expanded FILENAME, or t, if FILENAME is \"dir\".
531 Optional second argument NOERROR, if t, means if file is not found
532 just return nil (no error)."
533 ;; Convert filename to lower case if not found as specified.
535 (if (stringp filename
)
536 (let (temp temp-downcase found
)
537 (setq filename
(substitute-in-file-name filename
))
539 ((string= (downcase filename
) "dir")
541 ((string= filename
"apropos")
542 (setq found
'apropos
))
544 (let ((dirs (if (string-match "^\\./" filename
)
545 ;; If specified name starts with `./'
546 ;; then just try current directory.
548 (if (file-name-absolute-p filename
)
549 ;; No point in searching for an
550 ;; absolute file name
552 (if Info-additional-directory-list
553 (append Info-directory-list
554 Info-additional-directory-list
)
555 Info-directory-list
)))))
556 ;; Search the directory list for file FILENAME.
557 (while (and dirs
(not found
))
558 (setq temp
(expand-file-name filename
(car dirs
)))
560 (expand-file-name (downcase filename
) (car dirs
)))
561 ;; Try several variants of specified name.
562 (let ((suffix-list Info-suffix-list
)
563 (lfn (if (fboundp 'msdos-long-file-names
)
564 (msdos-long-file-names)
566 (while (and suffix-list
(not found
))
567 (cond ((info-file-exists-p
568 (info-insert-file-contents-1
569 temp
(car (car suffix-list
)) lfn
))
572 (info-insert-file-contents-1
573 temp-downcase
(car (car suffix-list
)) lfn
))
574 (setq found temp-downcase
))
575 ((and (fboundp 'msdos-long-file-names
)
578 (info-insert-file-contents-1
579 temp
(car (car suffix-list
)) nil
)))
581 (setq suffix-list
(cdr suffix-list
))))
582 (setq dirs
(cdr dirs
))))))
584 (setq filename found
)
587 (error "Info file %s does not exist" filename
)))
590 (defun Info-find-node (filename nodename
&optional no-going-back
)
591 "Go to an info node specified as separate FILENAME and NODENAME.
592 NO-GOING-BACK is non-nil if recovering from an error in this function;
593 it says do not attempt further (recursive) error recovery."
595 (setq filename
(Info-find-file filename
))
596 ;; Record the node we are leaving.
597 (if (and Info-current-file
(not no-going-back
))
599 (cons (list Info-current-file Info-current-node
(point))
601 ;; Go into info buffer.
602 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
603 (Info-find-node-2 filename nodename no-going-back
))
605 (defun Info-on-current-buffer (&optional nodename
)
606 "Use the `Info-mode' to browse the current info buffer.
607 If a prefix arg is provided, it queries for the NODENAME which
608 else defaults to \"Top\"."
610 (list (if current-prefix-arg
611 (completing-read "Node name: " (Info-build-node-completions)
613 (unless nodename
(setq nodename
"Top"))
616 (set (make-local-variable 'Info-current-file
) t
)
617 (Info-find-node-2 nil nodename
))
619 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
620 ;; but at least it keeps this routine (which is only for the benefit of
621 ;; makeinfo-buffer) out of the way of normal operations.
623 (defun Info-revert-find-node (filename nodename
)
624 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
625 When *info* is already displaying FILENAME and NODENAME, the window position
626 is preserved, if possible."
627 (pop-to-buffer "*info*")
628 (let ((old-filename Info-current-file
)
629 (old-nodename Info-current-node
)
630 (pcolumn (current-column))
631 (pline (count-lines (point-min) (line-beginning-position)))
632 (wline (count-lines (point-min) (window-start)))
633 (old-history Info-history
)
634 (new-history (and Info-current-file
635 (list Info-current-file Info-current-node
(point)))))
636 (kill-buffer (current-buffer))
637 (Info-find-node filename nodename
)
638 (setq Info-history old-history
)
639 (if (and (equal old-filename Info-current-file
)
640 (equal old-nodename Info-current-node
))
642 ;; note goto-line is no good, we want to measure from point-min
643 (beginning-of-buffer)
645 (set-window-start (selected-window) (point))
646 (beginning-of-buffer)
648 (move-to-column pcolumn
))
649 ;; only add to the history when coming from a different file+node
651 (setq Info-history
(cons new-history Info-history
))))))
653 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
654 "Find a node in a tag table.
655 MARKER specifies the buffer and position to start searching at.
656 REGEXP is a regular expression matching nodes or references. Its first
657 group should match `Node:' or `Ref:'.
658 CASE-FOLD t means search for a case-insensitive match.
659 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
660 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
661 where the match was found, and MODE is `major-mode' of the buffer in
662 which the match was found."
663 (let ((case-fold-search case-fold
))
665 (set-buffer (marker-buffer marker
))
670 (when (re-search-forward regexp nil t
)
671 (list (string-equal "Ref:" (match-string 1))
672 (+ (point-min) (read (current-buffer)))
675 (defun Info-find-in-tag-table (marker regexp
)
676 "Find a node in a tag table.
677 MARKER specifies the buffer and position to start searching at.
678 REGEXP is a regular expression matching nodes or references. Its first
679 group should match `Node:' or `Ref:'.
680 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
681 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
682 where the match was found, and MODE is `major-mode' of the buffer in
683 which the match was found.
684 This function tries to find a case-sensitive match first, then a
685 case-insensitive match is tried."
686 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
687 (when (null (car result
))
688 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
691 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
692 "Find a node or anchor in the current buffer.
693 REGEXP is a regular expression matching nodes or references. Its first
694 group should match `Node:' or `Ref:'.
695 CASE-FOLD t means search for a case-insensitive match.
696 Value is the position at which a match was found, or nil if not found."
697 (let ((case-fold-search case-fold
)
700 (when (Info-node-at-bob-matching regexp
)
701 (setq found
(point)))
702 (while (and (not found
)
703 (search-forward "\n\^_" nil t
))
707 (when (re-search-backward regexp beg t
)
709 (setq found
(point)))))
712 (defun Info-find-node-in-buffer (regexp)
713 "Find a node or anchor in the current buffer.
714 REGEXP is a regular expression matching nodes or references. Its first
715 group should match `Node:' or `Ref:'.
716 Value is the position at which a match was found, or nil if not found.
717 This function looks for a case-sensitive match first. If none is found,
718 a case-insensitive match is tried."
719 (or (Info-find-node-in-buffer-1 regexp nil
)
720 (Info-find-node-in-buffer-1 regexp t
)))
722 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
723 (buffer-disable-undo (current-buffer))
724 (or (eq major-mode
'Info-mode
)
727 (setq Info-current-node nil
)
729 (let ((case-fold-search t
)
731 ;; Switch files if necessary
733 (equal Info-current-file filename
)
734 (let ((buffer-read-only nil
))
735 (setq Info-current-file nil
736 Info-current-subfile nil
737 Info-current-file-completions nil
738 buffer-file-name nil
)
743 ((eq filename
'apropos
)
744 (insert-buffer-substring " *info-apropos*"))
746 (info-insert-file-contents filename nil
)
747 (setq default-directory
(file-name-directory filename
))))
748 (set-buffer-modified-p nil
)
749 ;; See whether file has a tag table. Record the location if yes.
750 (goto-char (point-max))
752 ;; Use string-equal, not equal, to ignore text props.
753 (if (not (or (string-equal nodename
"*")
755 (search-forward "\^_\nEnd tag table\n" nil t
))))
757 ;; We have a tag table. Find its beginning.
758 ;; Is this an indirect file?
759 (search-backward "\nTag table:\n")
763 (looking-at "(Indirect)\n"))
764 ;; It is indirect. Copy it to another buffer
765 ;; and record that the tag table is in that buffer.
766 (let ((buf (current-buffer))
768 (or Info-tag-table-buffer
769 (generate-new-buffer " *info tag table*"))))
770 (setq Info-tag-table-buffer tagbuf
)
773 (buffer-disable-undo (current-buffer))
774 (setq case-fold-search t
)
776 (insert-buffer-substring buf
))
777 (set-marker Info-tag-table-marker
778 (match-end 0) tagbuf
))
779 (set-marker Info-tag-table-marker pos
)))
780 (set-marker Info-tag-table-marker nil
))
781 (setq Info-current-file
783 ((eq filename t
) "dir")
784 ((eq filename
'apropos
) "apropos")
787 ;; Use string-equal, not equal, to ignore text props.
788 (if (string-equal nodename
"*")
789 (progn (setq Info-current-node nodename
)
790 (Info-set-mode-line))
793 ;; 1. Anchor found in tag table
794 ;; 2. Anchor *not* in tag table
796 ;; 3. Node found in tag table
797 ;; 4. Node *not* found in tag table, but found in file
798 ;; 5. Node *not* in tag table, and *not* in file
800 ;; *Or* the same, but in an indirect subfile.
802 ;; Search file for a suitable node.
803 (let ((guesspos (point-min))
804 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
805 (if (stringp nodename
)
806 (regexp-quote nodename
)
808 "\\) *[,\t\n\177]")))
812 ;; First, search a tag table, if any
813 (when (marker-position Info-tag-table-marker
)
814 (let* ((m Info-tag-table-marker
)
815 (found (Info-find-in-tag-table m regexp
)))
818 ;; FOUND is (ANCHOR POS MODE).
819 (setq guesspos
(nth 1 found
))
821 ;; If this is an indirect file, determine which
822 ;; file really holds this node and read it in.
823 (unless (eq (nth 2 found
) 'Info-mode
)
824 ;; Note that the current buffer must be the
825 ;; *info* buffer on entry to
826 ;; Info-read-subfile. Thus the hackery above.
827 (setq guesspos
(Info-read-subfile guesspos
)))
831 (goto-char (setq anchorpos guesspos
))
834 ;; Else we may have a node, which we search for:
835 (goto-char (max (point-min)
836 (- (byte-to-position guesspos
) 1000)))
838 ;; Now search from our advised position (or from beg of
839 ;; buffer) to find the actual node. First, check
840 ;; whether the node is right where we are, in case the
841 ;; buffer begins with a node.
842 (let ((pos (Info-find-node-in-buffer regexp
)))
846 (error "No such anchor in tag table or node in tag table or file: %s"
850 (goto-char (point-min))
852 (let ((new-history (list Info-current-file
853 (substring-no-properties nodename
))))
854 ;; Add anchors to the history too
855 (setq Info-history-list
857 (delete new-history Info-history-list
))))
858 (goto-char anchorpos
))
860 (Info-find-index-name Info-reference-name
)
861 (setq Info-reference-name nil
))))))
862 ;; If we did not finish finding the specified node,
863 ;; go back to the previous one.
864 (or Info-current-node no-going-back
(null Info-history
)
865 (let ((hist (car Info-history
)))
866 (setq Info-history
(cdr Info-history
))
867 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
868 (goto-char (nth 2 hist
))))))
870 ;; Cache the contents of the (virtual) dir file, once we have merged
871 ;; it for the first time, so we can save time subsequently.
872 (defvar Info-dir-contents nil
)
874 ;; Cache for the directory we decided to use for the default-directory
875 ;; of the merged dir text.
876 (defvar Info-dir-contents-directory nil
)
878 ;; Record the file attributes of all the files from which we
879 ;; constructed Info-dir-contents.
880 (defvar Info-dir-file-attributes nil
)
882 (defvar Info-dir-file-name nil
)
884 ;; Construct the Info directory node by merging the files named `dir'
885 ;; from various directories. Set the *info* buffer's
886 ;; default-directory to the first directory we actually get any text
888 (defun Info-insert-dir ()
889 (if (and Info-dir-contents Info-dir-file-attributes
890 ;; Verify that none of the files we used has changed
893 (mapcar (lambda (elt)
894 (let ((curr (file-attributes
896 (file-truename (car elt
)))))
898 ;; Don't compare the access time.
899 (if curr
(setcar (nthcdr 4 curr
) 0))
900 (setcar (nthcdr 4 (cdr elt
)) 0)
901 (equal (cdr elt
) curr
)))
902 Info-dir-file-attributes
))))
904 (insert Info-dir-contents
)
905 (goto-char (point-min)))
906 (let ((dirs (if Info-additional-directory-list
907 (append Info-directory-list
908 Info-additional-directory-list
)
909 Info-directory-list
))
911 ;; Bind this in case the user sets it to nil.
913 ;; This is set non-nil if we find a problem in some input files.
915 buffers buffer others nodes dirs-done
)
917 ;; Search the directory list for the directory file.
919 (let ((truename (file-truename (expand-file-name (car dirs
)))))
920 (or (member truename dirs-done
)
921 (member (directory-file-name truename
) dirs-done
)
922 ;; Try several variants of specified name.
923 ;; Try upcasing, appending `.info', or both.
927 (progn (setq file
(expand-file-name "dir" truename
))
928 (file-attributes file
))
929 (progn (setq file
(expand-file-name "DIR" truename
))
930 (file-attributes file
))
931 (progn (setq file
(expand-file-name "dir.info" truename
))
932 (file-attributes file
))
933 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
934 (file-attributes file
)))))
937 (cons (directory-file-name truename
)
942 (message "Composing main Info directory..."))
943 (set-buffer (generate-new-buffer " info dir"))
946 (insert-file-contents file
)
947 (set (make-local-variable 'Info-dir-file-name
)
949 (push (current-buffer) buffers
)
950 (push (cons file attrs
) dir-file-attrs
))
951 (error (kill-buffer (current-buffer))))))))
953 (set (make-local-variable 'Info-dir-contents-directory
)
954 (file-name-as-directory (car dirs
))))
955 (setq dirs
(cdr dirs
))))
958 (error "Can't find the Info directory node"))
960 ;; Distinguish the dir file that comes with Emacs from all the
961 ;; others. Yes, that is really what this is supposed to do.
962 ;; The definition of `Info-directory-list' puts it first on that
963 ;; list and so last in `buffers' at this point.
964 (setq buffer
(car (last buffers
))
965 others
(delq buffer buffers
))
967 ;; Insert the entire original dir file as a start; note that we've
968 ;; already saved its default directory to use as the default
969 ;; directory for the whole concatenation.
970 (insert-buffer buffer
)
972 ;; Look at each of the other buffers one by one.
973 (dolist (other others
)
974 (let (this-buffer-nodes)
975 ;; In each, find all the menus.
976 (with-current-buffer other
977 (goto-char (point-min))
978 ;; Find each menu, and add an elt to NODES for it.
979 (while (re-search-forward "^\\* Menu:" nil t
)
980 (while (and (zerop (forward-line 1)) (eolp)))
983 (re-search-backward "^\^_")
984 (search-forward "Node: ")
986 (and (looking-at (Info-following-node-name-re))
988 (search-forward "\n\^_" nil
'move
)
991 (push (list nodename other beg end
) this-buffer-nodes
)))
992 (if (assoc-string "top" this-buffer-nodes t
)
993 (setq nodes
(nconc this-buffer-nodes nodes
))
995 (message "No `top' node in %s" Info-dir-file-name
)))))
996 ;; Add to the main menu a menu item for each other node.
997 (re-search-forward "^\\* Menu:")
999 (let ((menu-items '("top"))
1000 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1001 (dolist (node nodes
)
1002 (let ((nodename (car node
)))
1004 (or (member (downcase nodename
) menu-items
)
1005 (re-search-forward (concat "^\\* +"
1006 (regexp-quote nodename
)
1010 (insert "* " nodename
"::" "\n")
1011 (push nodename menu-items
)))))))
1012 ;; Now take each node of each of the other buffers
1013 ;; and merge it into the main buffer.
1014 (dolist (node nodes
)
1015 (let ((case-fold-search t
)
1016 (nodename (car node
)))
1017 (goto-char (point-min))
1018 ;; Find the like-named node in the main buffer.
1019 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1020 (regexp-quote nodename
)
1024 (search-forward "\n\^_" nil
'move
)
1027 ;; If none exists, add one.
1028 (goto-char (point-max))
1029 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1030 ;; Merge the text from the other buffer's menu
1031 ;; into the menu in the like-named node in the main buffer.
1032 (apply 'insert-buffer-substring
(cdr node
))))
1033 (Info-dir-remove-duplicates)
1034 ;; Kill all the buffers we just made.
1035 (mapc 'kill-buffer buffers
)
1036 (goto-char (point-min))
1038 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1039 (message "Composing main Info directory...done"))
1040 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
1041 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
1042 (setq default-directory Info-dir-contents-directory
))
1044 (defvar Info-streamline-headings
1045 '(("Emacs" .
"Emacs")
1046 ("Programming" .
"Programming")
1047 ("Libraries" .
"Libraries")
1048 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1049 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1051 (defun Info-dir-remove-duplicates ()
1053 (goto-char (point-min))
1054 ;; Remove duplicate headings in the same menu.
1055 (while (search-forward "\n* Menu:" nil t
)
1056 (setq limit
(save-excursion (search-forward "\n\x1f" nil t
)))
1057 ;; Look for the next heading to unify.
1058 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1059 (let ((name (match-string 1))
1060 (start (match-beginning 0))
1062 ;; Check whether this heading should be streamlined.
1064 (dolist (x Info-streamline-headings
)
1065 (when (string-match (car x
) name
)
1067 (setq re
(car x
)))))
1068 (if re
(replace-match name t t nil
1))
1069 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1071 (or limit
(point-max))))
1072 ;; Look for other headings of the same category and merge them.
1074 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1075 (when (if re
(save-match-data (string-match re
(match-string 1)))
1076 (equal name
(match-string 1)))
1078 ;; Delete redundant heading.
1079 (delete-region (match-beginning 0) (point))
1080 ;; Push the entries onto `text'.
1082 (delete-and-extract-region
1084 (if (re-search-forward "^[^* \n\t]" nil t
)
1086 (or limit
(point-max)))) entries
))))
1087 ;; Insert the entries just found.
1088 (while (= (line-beginning-position 0) (1- (point)))
1090 (dolist (entry (nreverse entries
))
1092 (while (= (line-beginning-position 0) (1- (point)))
1093 (delete-region (1- (point)) (point))))
1095 ;; Now remove duplicate entries under the same heading.
1099 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1101 (let ((x (match-string 1)))
1102 (if (member-ignore-case x seen
)
1103 (delete-region (match-beginning 0)
1104 (progn (re-search-forward "^[^ \t]" nil t
)
1105 (match-beginning 0)))
1106 (push x seen
))))))))))
1108 ;; Note that on entry to this function the current-buffer must be the
1109 ;; *info* buffer; not the info tags buffer.
1110 (defun Info-read-subfile (nodepos)
1111 ;; NODEPOS is either a position (in the Info file as a whole,
1112 ;; not relative to a subfile) or the name of a subfile.
1115 (if (numberp nodepos
)
1117 (set-buffer (marker-buffer Info-tag-table-marker
))
1118 (goto-char (point-min))
1119 (or (looking-at "\^_")
1120 (search-forward "\n\^_"))
1123 (while (not (looking-at "\^_"))
1126 thisfilepos thisfilename
)
1127 (search-forward ": ")
1128 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1129 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1130 ;; read in version 19 stops at the end of number.
1131 ;; Advance to the next line.
1133 (if (> thisfilepos nodepos
)
1135 (setq lastfilename thisfilename
)
1136 (setq lastfilepos thisfilepos
))
1137 (forward-line 1)))))
1138 (setq lastfilename nodepos
)
1139 (setq lastfilepos
0))
1140 ;; Assume previous buffer is in Info-mode.
1141 ;; (set-buffer (get-buffer "*info*"))
1142 (or (equal Info-current-subfile lastfilename
)
1143 (let ((buffer-read-only nil
))
1144 (setq buffer-file-name nil
)
1147 (info-insert-file-contents lastfilename
)
1148 (set-buffer-modified-p nil
)
1149 (setq Info-current-subfile lastfilename
)))
1150 ;; Widen in case we are in the same subfile as before.
1152 (goto-char (point-min))
1153 (if (looking-at "\^_")
1155 (search-forward "\n\^_"))
1156 (if (numberp nodepos
)
1157 (+ (- nodepos lastfilepos
) (point)))))
1159 (defun Info-unescape-quotes (value)
1160 "Unescape double quotes and backslashes in VALUE."
1163 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1164 (setq unquote
(replace-match "" t t unquote
1))
1165 (setq start
(- (match-end 0) 1)))
1168 ;; As of Texinfo 4.6, makeinfo writes constructs like
1169 ;; \0\h[image param=value ...\h\0]
1170 ;; into the Info file for handling images.
1171 (defun Info-split-parameter-string (parameter-string)
1172 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1173 whitespace separated list of KEY=VALUE pairs. If VALUE contains
1174 whitespace or double quotes, it must be quoted in double quotes and
1175 any double quotes or backslashes must be escaped (\\\",\\\\)."
1178 (while (string-match
1179 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1180 parameter-string start
)
1181 (setq start
(match-end 0))
1182 (push (cons (match-string 1 parameter-string
)
1183 (or (match-string 2 parameter-string
)
1184 (Info-unescape-quotes
1185 (match-string 3 parameter-string
))))
1189 (defun Info-display-images-node ()
1190 "Display images in current node."
1192 (let ((inhibit-read-only t
)
1193 (case-fold-search t
))
1194 (goto-char (point-min))
1195 (while (re-search-forward
1196 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1198 (let* ((start (match-beginning 1))
1199 (parameter-alist (Info-split-parameter-string (match-string 2)))
1200 (src (cdr (assoc-string "src" parameter-alist
)))
1201 (image-file (if src
(if (file-name-absolute-p src
) src
1202 (concat default-directory src
))
1204 (image (if (file-exists-p image-file
)
1205 (create-image image-file
)
1207 (if (not (get-text-property start
'display
))
1208 (add-text-properties
1209 start
(point) `(display ,image rear-nonsticky
(display)))))))
1210 (set-buffer-modified-p nil
)))
1212 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1213 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1214 ;; including one optional trailing newline.
1215 (defun Info-hide-cookies-node ()
1216 "Hide unrecognised cookies in current node."
1218 (let ((inhibit-read-only t
)
1219 (case-fold-search t
))
1220 (goto-char (point-min))
1221 (while (re-search-forward
1222 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1224 (let* ((start (match-beginning 1)))
1225 (if (not (get-text-property start
'invisible
))
1226 (put-text-property start
(point) 'invisible t
)))))
1227 (set-buffer-modified-p nil
)))
1229 (defun Info-select-node ()
1230 "Select the info node that point is in."
1231 ;; Bind this in case the user sets it to nil.
1232 (let ((case-fold-search t
))
1234 ;; Find beginning of node.
1235 (if (search-backward "\n\^_" nil
'move
)
1237 (if (looking-at "\^_")
1239 (signal 'search-failed
(list "\n\^_"))))
1240 ;; Get nodename spelled as it is in the node.
1241 (re-search-forward "Node:[ \t]*")
1242 (setq Info-current-node
1243 (buffer-substring-no-properties (point)
1245 (skip-chars-forward "^,\t\n")
1247 (Info-set-mode-line)
1248 ;; Find the end of it, and narrow.
1250 (let (active-expression)
1251 ;; Narrow to the node contents
1252 (narrow-to-region (point)
1253 (if (re-search-forward "\n[\^_\f]" nil t
)
1256 (if (looking-at "[\n\^_\f]*execute: ")
1258 (goto-char (match-end 0))
1259 (setq active-expression
1260 (read (current-buffer))))))
1262 (if Info-enable-active-nodes
(eval active-expression
))
1263 ;; Add a new unique history item to full history list
1264 (let ((new-history (list Info-current-file Info-current-node
)))
1265 (setq Info-history-list
1266 (cons new-history
(delete new-history Info-history-list
))))
1268 (Info-display-images-node)
1269 (Info-hide-cookies-node)
1270 (run-hooks 'Info-selection-hook
)))))
1272 (defun Info-set-mode-line ()
1273 (setq mode-line-buffer-identification
1274 (nconc (propertized-buffer-identification "%b")
1277 (file-name-nondirectory
1278 (if (stringp Info-current-file
)
1280 (or buffer-file-name
"")))
1282 (or Info-current-node
""))))))
1284 ;; Go to an info node specified with a filename-and-nodename string
1285 ;; of the sort that is found in pointers in nodes.
1287 (defun Info-goto-node (nodename &optional fork
)
1288 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1289 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1290 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1292 Completion is available, but only for node names in the current Info file.
1293 If FORK is non-nil (interactively with a prefix arg), show the node in
1295 If FORK is a string, it is the name to use for the new buffer."
1296 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1300 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1301 (if (member (buffer-name) '("*info-history*" "*info-toc*"))
1302 (switch-to-buffer "*info*"))
1304 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1306 (setq filename
(if (= (match-beginning 1) (match-end 1))
1308 (match-string 2 nodename
))
1309 nodename
(match-string 3 nodename
))
1310 (let ((trim (string-match "\\s *\\'" filename
)))
1311 (if trim
(setq filename
(substring filename
0 trim
))))
1312 (let ((trim (string-match "\\s *\\'" nodename
)))
1313 (if trim
(setq nodename
(substring nodename
0 trim
))))
1314 (if transient-mark-mode
(deactivate-mark))
1315 (Info-find-node (if (equal filename
"") nil filename
)
1316 (if (equal nodename
"") "Top" nodename
))))
1318 (defvar Info-read-node-completion-table
)
1320 ;; This function is used as the "completion table" while reading a node name.
1321 ;; It does completion using the alist in Info-read-node-completion-table
1322 ;; unless STRING starts with an open-paren.
1323 (defun Info-read-node-name-1 (string predicate code
)
1325 ;; First complete embedded file names.
1326 ((string-match "\\`([^)]*\\'" string
)
1327 (let ((file (substring string
1)))
1330 (let ((comp (try-completion file
'locate-file-completion
1331 (cons Info-directory-list
1332 (mapcar 'car Info-suffix-list
)))))
1334 ((eq comp t
) (concat string
")"))
1335 (comp (concat "(" comp
)))))
1336 ((eq code t
) (all-completions file
'locate-file-completion
1337 (cons Info-directory-list
1338 (mapcar 'car Info-suffix-list
))))
1340 ;; If a file name was given, then any node is fair game.
1341 ((string-match "\\`(" string
)
1343 ((eq code nil
) string
)
1346 ;; Otherwise use Info-read-node-completion-table.
1348 (try-completion string Info-read-node-completion-table predicate
))
1350 (all-completions string Info-read-node-completion-table predicate
))
1352 (test-completion string Info-read-node-completion-table predicate
))))
1354 (defun Info-read-node-name (prompt &optional default
)
1355 (let* ((completion-ignore-case t
)
1356 (Info-read-node-completion-table (Info-build-node-completions))
1357 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1358 (if (equal nodename
"")
1360 (Info-read-node-name prompt
))
1363 (defun Info-build-node-completions ()
1364 (or Info-current-file-completions
1366 ;; Bind this in case the user sets it to nil.
1367 (case-fold-search t
)
1368 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1371 (if (marker-buffer Info-tag-table-marker
)
1372 (let ((marker Info-tag-table-marker
))
1373 (set-buffer (marker-buffer marker
))
1376 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1378 (cons (list (match-string-no-properties 2))
1381 (goto-char (point-min))
1382 ;; If the buffer begins with a node header, process that first.
1383 (if (Info-node-at-bob-matching node-regexp
)
1384 (setq compl
(list (match-string-no-properties 1))))
1385 ;; Now for the rest of the nodes.
1386 (while (search-forward "\n\^_" nil t
)
1388 (let ((beg (point)))
1390 (if (re-search-backward node-regexp beg t
)
1392 (cons (list (match-string-no-properties 1))
1394 (setq compl
(cons '("*") compl
))
1395 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1397 (defun Info-restore-point (hl)
1398 "If this node has been visited, restore the point value when we left."
1400 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1401 ;; Use string-equal, not equal, to ignore text props.
1402 (string-equal (nth 1 (car hl
)) Info-current-node
))
1404 (goto-char (nth 2 (car hl
)))
1405 (setq hl nil
)) ;terminate the while at next iter
1406 (setq hl
(cdr hl
)))))
1408 (defvar Info-search-history nil
1409 "The history list for `Info-search'.")
1411 (defvar Info-search-case-fold nil
1412 "The value of `case-fold-search' from previous `Info-search' command.")
1414 (defun Info-search (regexp)
1415 "Search for REGEXP, starting from point, and select node it's found in."
1416 (interactive (list (read-string
1417 (if Info-search-history
1418 (format "Regexp search%s (default `%s'): "
1419 (if case-fold-search
"" " case-sensitively")
1420 (car Info-search-history
))
1421 (format "Regexp search%s: "
1422 (if case-fold-search
"" " case-sensitively")))
1423 nil
'Info-search-history
)))
1424 (when transient-mark-mode
1426 (when (equal regexp
"")
1427 (setq regexp
(car Info-search-history
)))
1429 (let (found beg-found give-up
1430 (onode Info-current-node
)
1431 (ofile Info-current-file
)
1433 (ostart (window-start))
1434 (osubfile Info-current-subfile
))
1435 (when Info-search-whitespace-regexp
1436 (setq regexp
(replace-regexp-in-string
1437 "[ \t\n]+" Info-search-whitespace-regexp regexp
)))
1438 (setq Info-search-case-fold case-fold-search
)
1442 (while (and (not give-up
)
1444 (isearch-range-invisible beg-found found
)))
1445 (if (re-search-forward regexp nil t
)
1446 (setq found
(point) beg-found
(match-beginning 0))
1447 (setq give-up t
)))))
1448 ;; If no subfiles, give error now.
1450 (if (null Info-current-subfile
)
1451 (re-search-forward regexp
)
1456 ;; Try other subfiles.
1459 (set-buffer (marker-buffer Info-tag-table-marker
))
1460 (goto-char (point-min))
1461 (search-forward "\n\^_\nIndirect:")
1463 (narrow-to-region (point)
1464 (progn (search-forward "\n\^_")
1466 (goto-char (point-min))
1467 ;; Find the subfile we just searched.
1468 (search-forward (concat "\n" osubfile
": "))
1471 ;; Make a list of all following subfiles.
1472 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1474 (re-search-forward "\\(^.*\\): [0-9]+$")
1475 (goto-char (+ (match-end 1) 2))
1476 (setq list
(cons (cons (+ (point-min)
1477 (read (current-buffer)))
1478 (match-string-no-properties 1))
1480 (goto-char (1+ (match-end 0))))
1481 ;; Put in forward order
1482 (setq list
(nreverse list
))))
1484 (message "Searching subfile %s..." (cdr (car list
)))
1485 (Info-read-subfile (car (car list
)))
1486 (setq list
(cdr list
))
1487 (setq give-up nil found nil
)
1488 (while (and (not give-up
)
1490 (isearch-range-invisible beg-found found
)))
1491 (if (re-search-forward regexp nil t
)
1492 (setq found
(point) beg-found
(match-beginning 0))
1500 (signal 'search-failed
(list regexp
))))
1502 (progn (Info-read-subfile osubfile
)
1505 (set-window-start (selected-window) ostart
)))))
1509 ;; Use string-equal, not equal, to ignore text props.
1510 (or (and (string-equal onode Info-current-node
)
1511 (equal ofile Info-current-file
))
1512 (setq Info-history
(cons (list ofile onode opoint
)
1515 (defun Info-search-case-sensitively ()
1516 "Search for a regexp case-sensitively."
1518 (let ((case-fold-search nil
))
1519 (call-interactively 'Info-search
)))
1521 (defun Info-search-next ()
1522 "Search for next regexp from a previous `Info-search' command."
1524 (let ((case-fold-search Info-search-case-fold
))
1525 (if Info-search-history
1526 (Info-search (car Info-search-history
))
1527 (call-interactively 'Info-search
))))
1529 (defun Info-extract-pointer (name &optional errorname
)
1530 "Extract the value of the node-pointer named NAME.
1531 If there is none, use ERRORNAME in the error message;
1532 if ERRORNAME is nil, just return nil."
1533 ;; Bind this in case the user sets it to nil.
1534 (let ((case-fold-search t
))
1536 (goto-char (point-min))
1537 (let ((bound (point)))
1539 (cond ((re-search-backward
1540 (concat name
":" (Info-following-node-name-re)) bound t
)
1542 ((not (eq errorname t
))
1543 (error "Node has no %s"
1544 (capitalize (or errorname name
)))))))))
1546 (defun Info-following-node-name-re (&optional allowedchars
)
1547 "Return a regexp matching a node name.
1548 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1549 saying which chars may appear in the node name.
1550 Submatch 1 is the complete node name.
1551 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1552 Submatch 3 is the local part of the node name.
1553 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1554 (concat "[ \t]*" ;Skip leading space.
1555 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1556 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
1557 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
1558 "\\|\\)\\)")) ;Allow empty node names.
1560 ;;; For compatibility; other files have used this name.
1561 (defun Info-following-node-name ()
1562 (and (looking-at (Info-following-node-name-re))
1566 "Go to the next node of this node."
1568 (Info-goto-node (Info-extract-pointer "next")))
1571 "Go to the previous node of this node."
1573 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1575 (defun Info-up (&optional same-file
)
1576 "Go to the superior node of this node.
1577 If SAME-FILE is non-nil, do not move to a different Info file."
1579 (let ((old-node Info-current-node
)
1580 (old-file Info-current-file
)
1581 (node (Info-extract-pointer "up")) p
)
1582 (and (or same-file
(not (stringp Info-current-file
)))
1583 (string-match "^(" node
)
1584 (error "Up node is in another Info file"))
1585 (Info-goto-node node
)
1587 (goto-char (point-min))
1588 (if (and (search-forward "\n* Menu:" nil t
)
1590 (if (string-equal old-node
"Top")
1591 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
1592 (concat "\n\\* +\\(" (regexp-quote old-node
)
1593 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
1597 (Info-restore-point Info-history
))))
1600 "Go back to the last node visited."
1603 (error "This is the first Info node you looked at"))
1604 (let (filename nodename opoint
)
1605 (setq filename
(car (car Info-history
)))
1606 (setq nodename
(car (cdr (car Info-history
))))
1607 (setq opoint
(car (cdr (cdr (car Info-history
)))))
1608 (setq Info-history
(cdr Info-history
))
1609 (Info-find-node filename nodename
)
1610 (setq Info-history
(cdr Info-history
))
1611 (goto-char opoint
)))
1614 (defun Info-directory ()
1615 "Go to the Info directory node."
1617 (Info-find-node "dir" "top"))
1619 ;;;###autoload (add-hook 'same-window-buffer-names "*info-history*")
1621 (defun Info-history ()
1622 "Create the buffer *info-history* with a menu of visited nodes."
1624 (let ((curr-file Info-current-file
)
1625 (curr-node Info-current-node
)
1628 (with-current-buffer (get-buffer-create "*info-history*")
1629 (let ((inhibit-read-only t
))
1631 (goto-char (point-min))
1632 (insert "Node: History\n\n")
1633 (insert "Recently Visited Nodes\n**********************\n\n")
1634 (insert "* Menu:\n\n")
1635 (let ((hl Info-history-list
))
1637 (let ((file (nth 0 (car hl
)))
1638 (node (nth 1 (car hl
))))
1639 (if (and (string-equal file curr-file
)
1640 (string-equal node curr-node
))
1642 (insert "* " node
": (" (file-name-nondirectory file
)
1644 (setq hl
(cdr hl
))))
1645 (or (eq major-mode
'Info-mode
) (Info-mode))
1646 (setq Info-current-file
"info-history")
1647 (setq Info-current-node
"Info History")
1648 (Info-set-mode-line)
1649 (if (not (bobp)) (Info-fontify-node))
1651 (goto-char (or p
(point-min)))))
1653 ;;;###autoload (add-hook 'same-window-buffer-names "*info-toc*")
1656 "Create the buffer *info-toc* with Info file's table of contents."
1658 (let ((curr-file Info-current-file
)
1659 (curr-node Info-current-node
)
1662 (with-current-buffer (get-buffer-create "*info-toc*")
1663 (if (not (equal Info-current-file curr-file
))
1664 (let ((inhibit-read-only t
)
1665 (node-list (Info-build-toc curr-file
)))
1667 (goto-char (point-min))
1668 (insert "Node: Contents\n\n")
1669 (insert "Table of Contents\n*****************\n\n")
1670 (insert "*Note Top::\n")
1672 (nth 2 (assoc "Top" node-list
)) ; get Top nodes
1674 (or (eq major-mode
'Info-mode
) (Info-mode))
1675 (setq Info-current-file curr-file
)
1676 (setq Info-current-node
"Contents")
1677 (Info-set-mode-line)))
1679 (let ((Info-hide-note-references 'hide
))
1680 (Info-fontify-node)))
1681 (goto-char (point-min))
1682 (if (setq p
(search-forward (concat "*Note " curr-node
"::") nil t
))
1683 (setq p
(- p
(length curr-node
) 2)))
1685 (goto-char (or p
(point-min)))))
1687 (defun Info-insert-toc (nodes node-list level
)
1688 "Insert table of contents with references to nodes."
1689 (let ((section "Top"))
1691 (let ((node (assoc (car nodes
) node-list
)))
1692 (unless (member (nth 1 node
) (list nil section
))
1693 (insert (setq section
(nth 1 node
)) "\n"))
1694 (insert (make-string level ?
\t))
1695 (insert "*Note " (car nodes
) "::\n")
1696 (Info-insert-toc (nth 2 node
) node-list
(1+ level
))
1697 (setq nodes
(cdr nodes
))))))
1699 (defun Info-build-toc (file)
1700 "Build table of contents from menus of Info FILE and its subfiles."
1701 (if (equal file
"dir")
1702 (error "Table of contents for Info directory is not supported yet"))
1704 (let ((default-directory (or (and (stringp file
)
1705 (file-name-directory
1706 (setq file
(Info-find-file file
))))
1708 (sections '(("Top" "Top")))
1710 (while (or file subfiles
)
1711 (or file
(message "Searching subfile %s..." (car subfiles
)))
1713 (info-insert-file-contents (or file
(car subfiles
)))
1714 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
1715 (search-forward "Node: " nil
'move
))
1716 (let ((nodename (substring-no-properties (Info-following-node-name)))
1717 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
1721 (when (and (not (string-match "\\<index\\>" nodename
))
1722 (re-search-forward "^\\* Menu:" bound t
))
1725 (setq bound
(or (and (equal nodename
"Top")
1728 "^[ \t-]*The Detailed Node Listing" nil t
)))
1730 (while (< (point) bound
)
1733 ((looking-at "^\\* +[^:]+:")
1736 (let ((menu-node-name (substring-no-properties
1737 (Info-extract-menu-node-name))))
1738 (setq menu-items
(cons menu-node-name menu-items
))
1739 (if (equal nodename
"Top")
1741 (cons (list menu-node-name section
) sections
)))))
1742 ;; Other non-empty strings in the Top node are section names
1743 ((and (equal nodename
"Top")
1744 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
1745 (setq section
(match-string-no-properties 1))))
1747 (beginning-of-line)))
1748 (setq nodes
(cons (list nodename
1749 (cadr (assoc nodename sections
))
1750 (nreverse menu-items
))
1755 (goto-char (point-min))
1756 (if (search-forward "\n\^_\nIndirect:" nil t
)
1757 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
1758 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
1759 (setq subfiles
(cons (match-string-no-properties 1)
1761 (setq subfiles
(nreverse subfiles
)
1763 (setq subfiles
(cdr subfiles
))))
1767 (defun Info-follow-reference (footnotename &optional fork
)
1768 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1769 FOOTNOTENAME may be an abbreviation of the reference name.
1770 If FORK is non-nil (interactively with a prefix arg), show the node in
1771 a new info buffer. If FORK is a string, it is the name to use for the
1774 (let ((completion-ignore-case t
)
1775 (case-fold-search t
)
1776 completions default alt-default
(start-point (point)) str i bol eol
)
1778 ;; Store end and beginning of line.
1784 (goto-char (point-min))
1785 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
1786 (setq str
(match-string-no-properties 1))
1787 ;; See if this one should be the default.
1789 (<= (match-beginning 0) start-point
)
1790 (<= start-point
(point))
1792 ;; See if this one should be the alternate default.
1793 (and (null alt-default
)
1794 (and (<= bol
(match-beginning 0))
1796 (setq alt-default t
))
1798 (while (setq i
(string-match "[ \n\t]+" str i
))
1799 (setq str
(concat (substring str
0 i
) " "
1800 (substring str
(match-end 0))))
1802 ;; Record as a completion and perhaps as default.
1803 (if (eq default t
) (setq default str
))
1804 (if (eq alt-default t
) (setq alt-default str
))
1805 ;; Don't add this string if it's a duplicate.
1806 (or (assoc-string str completions t
)
1807 (push str completions
))))
1808 ;; If no good default was found, try an alternate.
1810 (setq default alt-default
))
1811 ;; If only one cross-reference found, then make it default.
1812 (if (eq (length completions
) 1)
1813 (setq default
(car completions
)))
1815 (let ((input (completing-read (if default
1817 "Follow reference named: (default "
1819 "Follow reference named: ")
1820 completions nil t
)))
1821 (list (if (equal input
"")
1822 default input
) current-prefix-arg
))
1823 (error "No cross-references in this node"))))
1825 (unless footnotename
1826 (error "No reference was specified"))
1828 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
1829 (case-fold-search t
))
1830 (while (setq i
(string-match " " str i
))
1831 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
1834 ;; Move point to the beginning of reference if point is on reference
1835 (or (looking-at "\\*note[ \n\t]+")
1836 (and (looking-back "\\*note[ \n\t]+")
1837 (goto-char (match-beginning 0)))
1838 (if (and (save-excursion
1839 (goto-char (+ (point) 5)) ; skip a possible *note
1840 (re-search-backward "\\*note[ \n\t]+" nil t
)
1841 (looking-at (concat "\\*note[ \n\t]+"
1842 (Info-following-node-name-re "^.,\t"))))
1843 (<= (point) (match-end 0)))
1844 (goto-char (match-beginning 0))))
1845 ;; Go to the reference closest to point
1846 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
1847 (+ (match-beginning 0) 5))))
1848 (prev-ref (save-excursion (and (re-search-backward str nil t
)
1849 (+ (match-beginning 0) 5)))))
1850 (goto-char (cond ((and next-ref prev-ref
)
1851 (if (< (abs (- next-ref
(point)))
1852 (abs (- prev-ref
(point))))
1854 ((or next-ref prev-ref
))
1855 ((error "No cross-reference named %s" footnotename
))))
1856 (setq target
(Info-extract-menu-node-name t
))))
1857 (while (setq i
(string-match "[ \t\n]+" target i
))
1858 (setq target
(concat (substring target
0 i
) " "
1859 (substring target
(match-end 0))))
1861 (Info-goto-node target fork
)))
1863 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
1864 ;; We allow newline because this is also used in Info-follow-reference,
1865 ;; where the xref name might be wrapped over two lines.
1866 "Regexp that matches a menu entry name upto but not including the colon.
1867 Because of ambiguities, this should be concatenated with something like
1868 `:' and `Info-following-node-name-re'.")
1870 (defun Info-extract-menu-node-name (&optional multi-line
)
1871 (skip-chars-forward " \t\n")
1872 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
1873 (Info-following-node-name-re
1874 (if multi-line
"^.,\t" "^.,\t\n")) "\\)"))
1875 (replace-regexp-in-string
1877 (or (match-string 2)
1878 ;; If the node name is the menu entry name (using `entry::').
1879 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))))
1881 ;; No one calls this.
1882 ;;(defun Info-menu-item-sequence (list)
1884 ;; (Info-menu (car list))
1885 ;; (setq list (cdr list))))
1887 (defvar Info-complete-menu-buffer
)
1888 (defvar Info-complete-next-re nil
)
1889 (defvar Info-complete-cache nil
)
1891 (defconst Info-node-spec-re
1892 (concat (Info-following-node-name-re "^.,:") "[,:.]")
1893 "Regexp to match the text after a : until the terminating `.'.")
1895 (defun Info-complete-menu-item (string predicate action
)
1896 ;; This uses two dynamically bound variables:
1897 ;; - `Info-complete-menu-buffer' which contains the buffer in which
1898 ;; is the menu of items we're trying to complete.
1899 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
1900 ;; also look for menu items in subsequent nodes as long as those
1901 ;; nodes' names match `Info-complete-next-re'. This feature is currently
1902 ;; only used for completion in Info-index.
1904 ;; Note that `Info-complete-menu-buffer' could be current already,
1905 ;; so we want to save point.
1907 (set-buffer Info-complete-menu-buffer
)
1908 (let ((completion-ignore-case t
)
1909 (case-fold-search t
)
1910 (orignode Info-current-node
)
1912 (goto-char (point-min))
1913 (search-forward "\n* Menu:")
1914 (if (not (memq action
'(nil t
)))
1916 (concat "\n\\* +" (regexp-quote string
) ":") nil t
)
1917 (let ((pattern (concat "\n\\* +\\("
1918 (regexp-quote string
)
1919 Info-menu-entry-name-re
"\\):" Info-node-spec-re
))
1922 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
1923 (equal (nth 1 Info-complete-cache
) Info-current-node
)
1924 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
1925 (let ((prev (nth 3 Info-complete-cache
)))
1926 (eq t
(compare-strings string
0 (length prev
)
1928 ;; We can reuse the previous list.
1929 (setq completions
(nth 4 Info-complete-cache
))
1930 ;; The cache can't be used.
1933 (while (re-search-forward pattern nil t
)
1934 (push (match-string-no-properties 1)
1936 ;; Check subsequent nodes if applicable.
1937 (and Info-complete-next-re
1938 (setq nextnode
(Info-extract-pointer "next" t
))
1939 (string-match Info-complete-next-re nextnode
)))
1940 (Info-goto-node nextnode
))
1941 ;; Go back to the start node (for the next completion).
1942 (unless (equal Info-current-node orignode
)
1943 (Info-goto-node orignode
))
1944 ;; Update the cache.
1945 (set (make-local-variable 'Info-complete-cache
)
1946 (list Info-current-file Info-current-node
1947 Info-complete-next-re string completions
)))
1949 (all-completions string completions predicate
)
1950 (try-completion string completions predicate
)))))))
1953 (defun Info-menu (menu-item &optional fork
)
1954 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
1955 The menu item should one of those listed in the current node's menu.
1956 Completion is allowed, and the default menu item is the one point is on.
1957 If FORK is non-nil (interactively with a prefix arg), show the node in
1958 a new info buffer. If FORK is a string, it is the name to use for the
1961 (let ((completions '())
1962 ;; If point is within a menu item, use that item as the default
1967 (case-fold-search t
))
1969 (goto-char (point-min))
1970 (if (not (search-forward "\n* menu:" nil t
))
1971 (error "No menu in this node"))
1977 (if (re-search-backward (concat "\n\\* +\\("
1978 Info-menu-entry-name-re
1980 (setq default
(match-string-no-properties 1))))))
1983 (setq item
(let ((completion-ignore-case t
)
1984 (Info-complete-menu-buffer (current-buffer)))
1985 (completing-read (if default
1986 (format "Menu item (default %s): "
1989 'Info-complete-menu-item nil t
)))
1990 ;; we rely on the fact that completing-read accepts an input
1991 ;; of "" even when the require-match argument is true and ""
1992 ;; is not a valid possibility
1993 (if (string= item
"")
1998 (list item current-prefix-arg
))))
1999 ;; there is a problem here in that if several menu items have the same
2000 ;; name you can only go to the node of the first with this command.
2001 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
2003 (defun Info-extract-menu-item (menu-item)
2004 (setq menu-item
(regexp-quote menu-item
))
2005 (let ((case-fold-search t
))
2007 (let ((case-fold-search t
))
2008 (goto-char (point-min))
2009 (or (search-forward "\n* menu:" nil t
)
2010 (error "No menu in this node"))
2011 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2012 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2013 (error "No such item in menu"))
2016 (Info-extract-menu-node-name)))))
2018 ;; If COUNT is nil, use the last item in the menu.
2019 (defun Info-extract-menu-counting (count)
2020 (let ((case-fold-search t
))
2022 (let ((case-fold-search t
))
2023 (goto-char (point-min))
2024 (or (search-forward "\n* menu:" nil t
)
2025 (error "No menu in this node"))
2027 (or (search-forward "\n* " nil t count
)
2028 (error "Too few items in menu"))
2029 (while (search-forward "\n* " nil t
)
2031 (Info-extract-menu-node-name)))))
2033 (defun Info-nth-menu-item ()
2034 "Go to the node of the Nth menu item.
2035 N is the digit argument used to invoke this command."
2038 (Info-extract-menu-counting
2039 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2041 (defun Info-top-node ()
2042 "Go to the Top node of this file."
2044 (Info-goto-node "Top"))
2046 (defun Info-final-node ()
2047 "Go to the final node in this file."
2049 (Info-goto-node "Top")
2050 (let ((Info-history nil
)
2051 (case-fold-search t
))
2052 ;; Go to the last node in the menu of Top.
2053 (Info-goto-node (Info-extract-menu-counting nil
))
2054 ;; If the last node in the menu is not last in pointer structure,
2055 ;; move forward until we can't go any farther.
2056 (while (Info-forward-node t t
) nil
)
2057 ;; Then keep moving down to last subnode, unless we reach an index.
2058 (while (and (not (string-match "\\<index\\>" Info-current-node
))
2059 (save-excursion (search-forward "\n* Menu:" nil t
)))
2060 (Info-goto-node (Info-extract-menu-counting nil
)))))
2062 (defun Info-forward-node (&optional not-down no-error
)
2063 "Go forward one node, considering all nodes as forming one sequence."
2065 (goto-char (point-min))
2067 (let ((case-fold-search t
))
2068 ;; three possibilities, in order of priority:
2069 ;; 1. next node is in a menu in this node (but not in an index)
2070 ;; 2. next node is next at same level
2071 ;; 3. next node is up and next
2072 (cond ((and (not not-down
)
2073 (save-excursion (search-forward "\n* menu:" nil t
))
2074 (not (string-match "\\<index\\>" Info-current-node
)))
2075 (Info-goto-node (Info-extract-menu-counting 1))
2077 ((save-excursion (search-backward "next:" nil t
))
2080 ((and (save-excursion (search-backward "up:" nil t
))
2081 ;; Use string-equal, not equal, to ignore text props.
2082 (not (string-equal (downcase (Info-extract-pointer "up"))
2084 (let ((old-node Info-current-node
))
2086 (let (Info-history success
)
2088 (setq success
(Info-forward-node t no-error
))
2089 (or success
(Info-goto-node old-node
))))))
2091 (t (error "No pointer forward from this node")))))
2093 (defun Info-backward-node ()
2094 "Go backward one node, considering all nodes as forming one sequence."
2096 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2097 (upnode (Info-extract-pointer "up" t
))
2098 (case-fold-search t
))
2099 (cond ((and upnode
(string-match "(" upnode
))
2100 (error "First node in file"))
2101 ((and upnode
(or (null prevnode
)
2102 ;; Use string-equal, not equal,
2103 ;; to ignore text properties.
2104 (string-equal (downcase prevnode
)
2105 (downcase upnode
))))
2108 ;; If we move back at the same level,
2109 ;; go down to find the last subnode*.
2112 (while (and (not (string-match "\\<index\\>" Info-current-node
))
2113 (save-excursion (search-forward "\n* Menu:" nil t
)))
2114 (Info-goto-node (Info-extract-menu-counting nil
)))))
2116 (error "No pointer backward from this node")))))
2119 "Exit Info by selecting some other buffer."
2122 (save-buffers-kill-emacs)
2125 (defun Info-next-menu-item ()
2126 "Go to the node of the next menu item."
2128 ;; Bind this in case the user sets it to nil.
2129 (let* ((case-fold-search t
)
2133 (search-forward "\n* menu:" nil t
)
2134 (and (search-forward "\n* " nil t
)
2135 (Info-extract-menu-node-name)))))
2136 (if node
(Info-goto-node node
)
2137 (error "No more items in menu"))))
2139 (defun Info-last-menu-item ()
2140 "Go to the node of the previous menu item."
2144 ;; Bind this in case the user sets it to nil.
2145 (let* ((case-fold-search t
)
2146 (beg (save-excursion
2147 (and (search-backward "\n* menu:" nil t
)
2149 (or (and beg
(search-backward "\n* " beg t
))
2150 (error "No previous items in menu")))
2151 (Info-goto-node (save-excursion
2152 (goto-char (match-end 0))
2153 (Info-extract-menu-node-name)))))
2155 (defmacro Info-no-error
(&rest body
)
2156 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
2158 (defun Info-next-preorder ()
2159 "Go to the next subnode or the next node, or go up a level."
2161 (cond ((Info-no-error (Info-next-menu-item)))
2162 ((Info-no-error (Info-next)))
2163 ((Info-no-error (Info-up t
))
2164 ;; Since we have already gone thru all the items in this menu,
2165 ;; go up to the end of this node.
2166 (goto-char (point-max))
2167 ;; Since logically we are done with the node with that menu,
2169 (Info-next-preorder))
2171 (error "No more nodes"))))
2173 (defun Info-last-preorder ()
2174 "Go to the last node, popping up a level if there is none."
2176 (cond ((Info-no-error
2177 (Info-last-menu-item)
2178 ;; If we go down a menu item, go to the end of the node
2179 ;; so we can scroll back through it.
2180 (goto-char (point-max)))
2181 ;; Keep going down, as long as there are nested menu nodes.
2182 (while (Info-no-error
2183 (Info-last-menu-item)
2184 ;; If we go down a menu item, go to the end of the node
2185 ;; so we can scroll back through it.
2186 (goto-char (point-max))))
2188 ((and (Info-no-error (Info-extract-pointer "prev"))
2189 (not (equal (Info-extract-pointer "up")
2190 (Info-extract-pointer "prev"))))
2191 (Info-no-error (Info-prev))
2192 (goto-char (point-max))
2193 (while (Info-no-error
2194 (Info-last-menu-item)
2195 ;; If we go down a menu item, go to the end of the node
2196 ;; so we can scroll back through it.
2197 (goto-char (point-max))))
2199 ((Info-no-error (Info-up t
))
2200 (goto-char (point-min))
2201 (let ((case-fold-search t
))
2202 (or (search-forward "\n* Menu:" nil t
)
2203 (goto-char (point-max)))))
2204 (t (error "No previous nodes"))))
2206 (defun Info-scroll-up ()
2207 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2208 Once you scroll far enough in a node that its menu appears on the screen
2209 but after point, the next scroll moves into its first subnode, unless
2210 `Info-scroll-prefer-subnodes' is nil.
2212 When you scroll past the end of a node, that goes to the next node if
2213 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2214 if this node has no successor, it moves to the parent node's successor,
2215 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2216 the menu of a node, it moves to subnode indicated by the following menu
2217 item. (That case won't normally result from this command, but can happen
2221 (if (or (< (window-start) (point-min))
2222 (> (window-start) (point-max)))
2223 (set-window-start (selected-window) (point)))
2224 (let* ((case-fold-search t
)
2225 (virtual-end (save-excursion
2226 (goto-char (point-min))
2227 (if (and Info-scroll-prefer-subnodes
2228 (search-forward "\n* Menu:" nil t
))
2231 (if (or (< virtual-end
(window-start))
2232 (pos-visible-in-window-p virtual-end
))
2234 (Info-scroll-prefer-subnodes (Info-next-preorder))
2235 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2236 (t (Info-next-preorder)))
2239 (defun Info-scroll-down ()
2240 "Scroll one screenful back in Info, considering all nodes as one sequence.
2241 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2242 is non-nil, this goes to its last subnode. When you scroll past the
2243 beginning of a node, that goes to the previous node or back up to the
2246 (if (or (< (window-start) (point-min))
2247 (> (window-start) (point-max)))
2248 (set-window-start (selected-window) (point)))
2249 (let* ((case-fold-search t
)
2250 (current-point (point))
2252 (and Info-scroll-prefer-subnodes
2255 (setq current-point
(point))
2256 (goto-char (point-min))
2257 (search-forward "\n* Menu:"
2261 (pos-visible-in-window-p (point-min) nil t
))
2262 (Info-last-preorder)
2265 (defun Info-next-reference (&optional recur
)
2266 "Move cursor to the next cross-reference or menu item in the node."
2268 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2270 (case-fold-search t
))
2271 (or (eobp) (forward-char 1))
2272 (or (re-search-forward pat nil t
)
2274 (goto-char (point-min))
2275 (or (re-search-forward pat nil t
)
2278 (error "No cross references in this node")))))
2279 (goto-char (or (match-beginning 1) (match-beginning 0)))
2280 (if (looking-at "\\* Menu:")
2282 (error "No cross references in this node")
2283 (Info-next-reference t
)))))
2285 (defun Info-prev-reference (&optional recur
)
2286 "Move cursor to the previous cross-reference or menu item in the node."
2288 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2290 (case-fold-search t
))
2291 (or (re-search-backward pat nil t
)
2293 (goto-char (point-max))
2294 (or (re-search-backward pat nil t
)
2297 (error "No cross references in this node")))))
2298 (goto-char (or (match-beginning 1) (match-beginning 0)))
2299 (if (looking-at "\\* Menu:")
2301 (error "No cross references in this node")
2302 (Info-prev-reference t
)))))
2304 (defun Info-goto-index ()
2305 (Info-goto-node "Top")
2306 (or (search-forward "\n* menu:" nil t
)
2308 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
2310 (goto-char (match-beginning 1))
2311 ;; Protect Info-history so that the current node (Top) is not added to it.
2312 (let ((Info-history nil
))
2313 (Info-goto-node (Info-extract-menu-node-name))))
2316 (defun Info-index (topic)
2317 "Look up a string TOPIC in the index for this file.
2318 The index is defined as the first node in the top level menu whose
2319 name contains the word \"Index\", plus any immediately following
2320 nodes whose names also contain the word \"Index\".
2321 If there are no exact matches to the specified topic, this chooses
2322 the first match which is a case-insensitive substring of a topic.
2323 Use the `,' command to see the other matches.
2324 Give a blank topic name to go to the Index node itself."
2327 (let ((Info-complete-menu-buffer (clone-buffer))
2328 (Info-complete-next-re "\\<Index\\>"))
2329 (if (equal Info-current-file
"dir")
2330 (error "The Info directory node has no index; use m to select a manual"))
2332 (with-current-buffer Info-complete-menu-buffer
2334 (completing-read "Index topic: " 'Info-complete-menu-item
))
2335 (kill-buffer Info-complete-menu-buffer
)))))
2336 (if (equal Info-current-file
"dir")
2337 (error "The Info directory node has no index; use m to select a manual"))
2338 (let ((orignode Info-current-node
)
2339 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
2340 (regexp-quote topic
)))
2342 (case-fold-search t
))
2344 (or (equal topic
"")
2347 ;; We bind Info-history to nil for internal node-switches so
2348 ;; that we don't put junk in the history. In the first
2349 ;; Info-goto-index call, above, we do update the history
2350 ;; because that is what the user's previous node choice into it.
2355 (goto-char (point-min))
2356 (while (re-search-forward pattern nil t
)
2357 (push (list (match-string-no-properties 1)
2358 (match-string-no-properties 2)
2360 (string-to-number (concat "0"
2363 (and (setq node
(Info-extract-pointer "next" t
))
2364 (string-match "\\<Index\\>" node
)))
2365 (Info-goto-node node
))
2368 (Info-goto-node orignode
)
2369 (error "No `%s' in index" topic
)))
2370 ;; Here it is a feature that assoc is case-sensitive.
2371 (while (setq found
(assoc topic matches
))
2372 (setq exact
(cons found exact
)
2373 matches
(delq found matches
)))
2374 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
2375 (Info-index-next 0)))))
2377 (defun Info-index-next (num)
2378 "Go to the next matching index item from the last `i' command."
2380 (or Info-index-alternatives
2381 (error "No previous `i' command"))
2383 (setq num
(+ num
(length Info-index-alternatives
))))
2385 (setq Info-index-alternatives
2386 (nconc (cdr Info-index-alternatives
)
2387 (list (car Info-index-alternatives
)))
2389 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
2390 (if (> (nth 3 (car Info-index-alternatives
)) 0)
2391 (forward-line (nth 3 (car Info-index-alternatives
)))
2392 (forward-line 3) ; don't search in headers
2393 (let ((name (car (car Info-index-alternatives
))))
2394 (Info-find-index-name name
)))
2395 (message "Found `%s' in %s. %s"
2396 (car (car Info-index-alternatives
))
2397 (nth 2 (car Info-index-alternatives
))
2398 (if (cdr Info-index-alternatives
)
2399 "(`,' tries to find next)"
2402 (defun Info-find-index-name (name)
2403 "Move point to the place within the current node where NAME is defined."
2404 (let ((case-fold-search t
))
2405 (if (or (re-search-forward (format
2406 "[a-zA-Z]+: %s\\( \\|$\\)"
2407 (regexp-quote name
)) nil t
)
2408 ;; Find a function definition with a return type.
2409 (re-search-forward (format
2410 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2411 (regexp-quote name
)) nil t
)
2412 (search-forward (format "`%s'" name
) nil t
)
2413 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
2415 (format "`%s'" (substring name
0 (match-beginning 1)))
2417 (search-forward name nil t
)
2418 ;; Try again without the " <1>" makeinfo can append
2419 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
2420 (Info-find-index-name (match-string 1 name
))))
2421 (progn (beginning-of-line) t
) ;; non-nil for recursive call
2422 (goto-char (point-min)))))
2425 (defun info-apropos (string)
2426 "Grovel indices of all known Info files on your system for STRING.
2427 Build a menu of the possible matches."
2428 (interactive "sIndex apropos: ")
2429 (unless (string= string
"")
2430 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^.]+\\)."
2431 (regexp-quote string
)))
2432 (ohist Info-history
)
2433 (ohist-list Info-history-list
)
2434 (current-node Info-current-node
)
2435 (current-file Info-current-file
)
2436 manuals matches temp-file node
)
2437 (let ((Info-fontify-maximum-menu-size 0)
2438 Info-use-header-lines
2439 Info-hide-note-references
)
2441 (message "Searching indices...")
2442 (goto-char (point-min))
2443 (re-search-forward "\\* Menu: *\n" nil t
)
2444 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
2445 (add-to-list 'manuals
(match-string 1)))
2446 (dolist (manual manuals
)
2447 (message "Searching %s" manual
)
2450 (Info-find-node manual
"Top")
2451 (when (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
)
2452 (goto-char (match-beginning 1))
2453 (Info-goto-node (Info-extract-menu-node-name))
2456 (goto-char (point-min))
2457 (while (re-search-forward pattern nil t
)
2458 (add-to-list 'matches
2459 (list (match-string 1)
2462 (and (setq node
(Info-extract-pointer "next" t
))
2463 (string-match "\\<Index\\>" node
)))
2464 (Info-goto-node node
))))
2466 (Info-goto-node (concat "(" current-file
")" current-node
))
2467 (setq Info-history ohist
2468 Info-history-list ohist-list
)
2469 (message "Searching indices...done")
2471 (message "No matches found")
2472 (with-current-buffer (get-buffer-create " *info-apropos*")
2474 (insert "\n\x1f\nFile: apropos, Node: Top, Up: (dir)\n")
2475 (insert "* Menu: \nNodes whose indices contain \"" string
"\"\n\n")
2476 (dolist (entry matches
)
2477 (insert "* " (car entry
) " [" (nth 2 entry
)
2478 "]: (" (nth 2 entry
) ")" (nth 1 entry
) ".\n")))
2479 (Info-find-node "apropos" "top")))))
2481 (defun Info-undefined ()
2482 "Make command be undefined in Info."
2487 "Enter the Info tutorial."
2489 (delete-other-windows)
2490 (Info-find-node "info"
2491 (if (< (window-height) 23)
2495 (defun Info-summary ()
2496 "Display a brief summary of all Info commands."
2498 (save-window-excursion
2499 (switch-to-buffer "*Help*")
2500 (setq buffer-read-only nil
)
2502 (insert (documentation 'Info-mode
))
2504 (goto-char (point-min))
2506 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
2507 (message (if flag
"Type Space to see more"
2508 "Type Space to return to Info"))
2509 (if (not (eq ?\
(setq ch
(read-event))))
2510 (progn (setq unread-command-events
(list ch
)) nil
)
2513 (bury-buffer "*Help*")))
2515 (defun Info-get-token (pos start all
&optional errorstring
)
2516 "Return the token around POS.
2517 POS must be somewhere inside the token
2518 START is a regular expression which will match the
2519 beginning of the tokens delimited string
2520 ALL is a regular expression with a single
2521 parenthesized subpattern which is the token to be
2522 returned. E.g. '{\(.*\)}' would return any string
2523 enclosed in braces around POS.
2524 ERRORSTRING optional fourth argument, controls action on no match
2527 a string: signal an error, using that string."
2528 (let ((case-fold-search t
))
2531 ;; First look for a match for START that goes across POS.
2532 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
2533 (not (looking-at start
)))
2535 ;; If we did not find one, search back for START
2536 ;; (this finds only matches that end at or before POS).
2537 (or (looking-at start
)
2540 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
2542 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
2543 (not (setq found
(and (<= (match-beginning 0) pos
)
2544 (> (match-end 0) pos
))))))
2545 (if (and found
(<= (match-beginning 0) pos
)
2546 (> (match-end 0) pos
))
2547 (match-string-no-properties 1)
2548 (cond ((null errorstring
)
2554 (error "No %s around position %d" errorstring pos
))))))))
2556 (defun Info-mouse-follow-nearest-node (click)
2557 "\\<Info-mode-map>Follow a node reference near point.
2558 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2559 At end of the node's text, moves to the next node, or up if none."
2561 (mouse-set-point click
)
2562 (and (not (Info-try-follow-nearest-node))
2563 (save-excursion (forward-line 1) (eobp))
2564 (Info-next-preorder)))
2566 (defun Info-follow-nearest-node (&optional fork
)
2567 "Follow a node reference near point.
2568 If point is on a reference, follow that reference. Otherwise,
2569 if point is in a menu item description, follow that menu item."
2571 (or (Info-try-follow-nearest-node fork
)
2572 (when (save-excursion
2573 (search-backward "\n* menu:" nil t
))
2576 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2577 (beginning-of-line 0))
2578 (when (looking-at "\\* +\\([^\t\n]*\\):")
2580 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
2582 (error "Point neither on reference nor in menu item description")))
2584 ;; Common subroutine.
2585 (defun Info-try-follow-nearest-node (&optional fork
)
2586 "Follow a node reference near point. Return non-nil if successful."
2589 ((and (Info-get-token (point) "[hf]t?tp://" "[hf]t?tp://\\([^ \t\n\"`({<>})']+\\)")
2590 (or (featurep 'browse-url
) (require 'browse-url nil t
)))
2592 (browse-url (browse-url-url-at-point)))
2593 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
2594 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
2595 ;;; (or (match-string 2)
2596 ;;; (setq Info-reference-name
2597 ;;; (replace-regexp-in-string
2598 ;;; "[ \n\t]+" " " (match-string-no-properties 1))))
2599 (Info-follow-reference node fork
))
2600 ;; menu item: node name
2601 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2602 (Info-goto-node node fork
))
2603 ;; menu item: index entry
2604 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
2605 (if (save-match-data (string-match "\\<index\\>" Info-current-node
))
2606 (setq Info-reference-name
(match-string-no-properties 1)))
2609 (setq node
(Info-extract-menu-node-name))
2610 (Info-goto-node node fork
))
2611 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2612 (Info-goto-node node fork
))
2613 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2614 (Info-goto-node node fork
))
2615 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2616 (Info-goto-node "Top" fork
))
2617 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2618 (Info-goto-node node fork
)))
2621 (defvar Info-mode-map nil
2622 "Keymap containing Info commands.")
2625 (setq Info-mode-map
(make-keymap))
2626 (suppress-keymap Info-mode-map
)
2627 (define-key Info-mode-map
"." 'beginning-of-buffer
)
2628 (define-key Info-mode-map
" " 'Info-scroll-up
)
2629 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
2630 (define-key Info-mode-map
"\t" 'Info-next-reference
)
2631 (define-key Info-mode-map
[(shift tab
)] 'Info-prev-reference
)
2632 (define-key Info-mode-map
[backtab] 'Info-prev-reference)
2633 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2634 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2635 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2636 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2637 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2638 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2639 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2640 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2641 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2642 (define-key Info-mode-map "0" 'undefined)
2643 (define-key Info-mode-map "?" 'Info-summary)
2644 (define-key Info-mode-map "]" 'Info-forward-node)
2645 (define-key Info-mode-map "[" 'Info-backward-node)
2646 (define-key Info-mode-map "<" 'Info-top-node)
2647 (define-key Info-mode-map ">" 'Info-final-node)
2648 (define-key Info-mode-map "b" 'beginning-of-buffer)
2649 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
2650 (define-key Info-mode-map "d" 'Info-directory)
2651 (define-key Info-mode-map "e" 'Info-edit)
2652 (define-key Info-mode-map "f" 'Info-follow-reference)
2653 (define-key Info-mode-map "g" 'Info-goto-node)
2654 (define-key Info-mode-map "h" 'Info-help)
2655 (define-key Info-mode-map "i" 'Info-index)
2656 (define-key Info-mode-map "l" 'Info-last)
2657 (define-key Info-mode-map "m" 'Info-menu)
2658 (define-key Info-mode-map "n" 'Info-next)
2659 (define-key Info-mode-map "p" 'Info-prev)
2660 (define-key Info-mode-map "q" 'Info-exit)
2661 (define-key Info-mode-map "s" 'Info-search)
2662 ;; For consistency with Rmail.
2663 (define-key Info-mode-map "\M-s" 'Info-search)
2664 (define-key Info-mode-map "\M-n" 'clone-buffer)
2665 (define-key Info-mode-map "t" 'Info-top-node)
2666 (define-key Info-mode-map "u" 'Info-up)
2667 (define-key Info-mode-map "," 'Info-index-next)
2668 (define-key Info-mode-map "\177" 'Info-scroll-down)
2669 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
2672 (defun Info-check-pointer (item)
2673 "Non-nil if ITEM is present in this node."
2675 (Info-extract-pointer item)
2679 Info-mode-menu Info-mode-map
2680 "Menu for info files."
2682 ["Up" Info-up :active (Info-check-pointer "up")
2683 :help "Go up in the Info tree"]
2684 ["Next" Info-next :active (Info-check-pointer "next")
2685 :help "Go to the next node"]
2686 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
2687 :help "Go to the previous node"]
2688 ["Backward" Info-backward-node
2689 :help "Go backward one node, considering all as a sequence"]
2690 ["Forward" Info-forward-node
2691 :help "Go forward one node, considering all as a sequence"]
2692 ["Beginning" beginning-of-buffer
2693 :help "Go to beginning of this node"]
2694 ["Top" Info-top-node
2695 :help "Go to top node of file"]
2696 ["Final Node" Info-final-node
2697 :help "Go to final node in this file"]
2698 ("Menu Item" ["You should never see this" report-emacs-bug t])
2699 ("Reference" ["You should never see this" report-emacs-bug t])
2700 ["Search..." Info-search
2701 :help "Search for regular expression in this Info file"]
2702 ["Search Case-Sensitively..." Info-search-case-sensitively
2703 :help "Search for regular expression case sensitively"]
2704 ["Search Next" Info-search-next
2705 :help "Search for another occurrence of regular expression"]
2706 ["Go to Node..." Info-goto-node
2707 :help "Go to a named node"]
2708 ["Last" Info-last :active Info-history
2709 :help "Go to the last node you were at"]
2710 ["History" Info-history :active Info-history-list
2711 :help "Go to the history buffer"]
2712 ["Table of Contents" Info-toc
2713 :help "Go to the buffer with a table of contents"]
2715 ["Lookup a String" Info-index
2716 :help "Look for a string in the index items"]
2717 ["Next Matching Item" Info-index-next
2718 :help "Look for another occurrence of previous item"]
2719 ["Lookup a string in all indices" info-apropos
2720 :help "Look for a string in the indices of all manuals"])
2721 ["Edit" Info-edit :help "Edit contents of this node"
2722 :active Info-enable-edit]
2723 ["Copy Node Name" Info-copy-current-node-name
2724 :help "Copy the name of the current node into the kill ring"]
2725 ["Clone Info buffer" clone-buffer
2726 :help "Create a twin copy of the current Info buffer."]
2727 ["Exit" Info-exit :help "Stop reading Info"]))
2730 (defvar info-tool-bar-map
2731 (if (display-graphic-p)
2732 (let ((map (make-sparse-keymap)))
2733 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
2734 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
2735 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
2736 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
2737 (tool-bar-local-item-from-menu 'Info-last "undo" map Info-mode-map)
2738 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
2739 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
2740 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
2741 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
2744 (defvar Info-menu-last-node nil)
2745 ;; Last node the menu was created for.
2746 ;; Value is a list, (FILE-NAME NODE-NAME).
2748 (defun Info-menu-update ()
2749 "Update the Info menu for the current node."
2751 (if (or (not (eq major-mode 'Info-mode))
2752 (equal (list Info-current-file Info-current-node)
2753 Info-menu-last-node))
2755 ;; Update menu menu.
2756 (let* ((Info-complete-menu-buffer (current-buffer))
2757 (items (nreverse (condition-case nil
2758 (Info-complete-menu-item "" nil t)
2762 (while (and items (< number 9))
2763 (setq current (car items)
2766 (setq entries (cons `[,current
2767 (Info-menu ,current)
2768 :keys ,(format "%d" number)]
2771 (setq entries (cons ["Other..." Info-menu t] entries)))
2773 (setq entries (list ["No menu" nil nil] nil :active)))
2774 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
2775 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2777 str i entries current
2779 (case-fold-search t))
2781 (goto-char (point-min))
2782 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
2783 (setq str (match-string 1))
2785 (while (setq i (string-match "[ \n\t]+" str i))
2786 (setq str (concat (substring str 0 i) " "
2787 (substring str (match-end 0))))
2791 (while (and items (< number 9))
2792 (setq current (car items)
2795 (setq entries (cons `[,current
2796 (Info-follow-reference ,current)
2800 (setq entries (cons ["Other..." Info-follow-reference t]
2803 (setq entries (list ["No references" nil nil] nil :active)))
2804 (easy-menu-change '("Info") "Reference" (nreverse entries)))
2805 ;; Update last seen node.
2806 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
2807 ;; Try to avoid entering infinite beep mode in case of errors.
2811 (defun Info-copy-current-node-name ()
2812 "Put the name of the current info node into the kill ring.
2813 The name of the info file is prepended to the node name in parentheses."
2815 (unless Info-current-node
2816 (error "No current info node"))
2819 (file-name-nondirectory
2820 (if (stringp Info-current-file)
2822 (or buffer-file-name "")))
2824 Info-current-node)))
2827 ;; Info mode is suitable only for specially formatted data.
2828 (put 'Info-mode 'mode-class 'special)
2829 (put 'Info-mode 'no-clone-indirect t)
2832 "Info mode provides commands for browsing through the Info documentation tree.
2833 Documentation in Info is divided into \"nodes\", each of which discusses
2834 one topic and contains references to other nodes which discuss related
2835 topics. Info has commands to follow the references and show you other nodes.
2838 \\[Info-help] Invoke the Info tutorial.
2839 \\[Info-exit] Quit Info: reselect previously selected buffer.
2841 Selecting other nodes:
2842 \\[Info-mouse-follow-nearest-node]
2843 Follow a node reference you click on.
2844 This works with menu items, cross references, and
2845 the \"next\", \"previous\" and \"up\", depending on where you click.
2846 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2847 \\[Info-next] Move to the \"next\" node of this node.
2848 \\[Info-prev] Move to the \"previous\" node of this node.
2849 \\[Info-up] Move \"up\" from this node.
2850 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2851 Picking a menu item causes another node to be selected.
2852 \\[Info-directory] Go to the Info directory node.
2853 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2854 \\[Info-last] Move to the last node you were at.
2855 \\[Info-history] Go to the history buffer.
2856 \\[Info-toc] Go to the buffer with a table of contents.
2857 \\[Info-index] Look up a topic in this file's Index and move to that node.
2858 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2859 \\[Info-top-node] Go to the Top node of this file.
2860 \\[Info-final-node] Go to the final node in this file.
2861 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2862 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2864 Moving within a node:
2865 \\[Info-scroll-up] Normally, scroll forward a full screen.
2866 Once you scroll far enough in a node that its menu appears on the
2867 screen but after point, the next scroll moves into its first
2868 subnode. When after all menu items (or if there is no menu),
2869 move up to the parent node.
2870 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2871 already visible, try to go to the previous menu entry, or up
2873 \\[beginning-of-buffer] Go to beginning of node.
2876 \\[Info-copy-current-node-name] Put name of current info node in the kill ring.
2877 \\[clone-buffer] Select a new cloned Info buffer in another window.
2878 \\[Info-edit] Edit contents of selected node.
2879 1 Pick first item in node's menu.
2880 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2881 \\[Info-goto-node] Move to node specified by name.
2882 You may include a filename as well, as (FILENAME)NODENAME.
2883 \\[universal-argument] \\[info] Move to new Info file with completion.
2884 \\[Info-search] Search through this Info file for specified regexp,
2885 and select the node in which the next occurrence is found.
2886 \\[Info-search-case-sensitively] Search through this Info file
2887 for specified regexp case-sensitively.
2888 \\[Info-search-next] Search for another occurrence of regexp
2889 from a previous `Info-search' command.
2890 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2891 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2892 (kill-all-local-variables)
2893 (setq major-mode 'Info-mode)
2894 (setq mode-name "Info")
2896 (use-local-map Info-mode-map)
2897 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
2898 (set-syntax-table text-mode-syntax-table)
2899 (setq local-abbrev-table text-mode-abbrev-table)
2900 (setq case-fold-search t)
2901 (setq buffer-read-only t)
2902 (make-local-variable 'Info-current-file)
2903 (make-local-variable 'Info-current-subfile)
2904 (make-local-variable 'Info-current-node)
2905 (make-local-variable 'Info-tag-table-marker)
2906 (setq Info-tag-table-marker (make-marker))
2907 (make-local-variable 'Info-tag-table-buffer)
2908 (setq Info-tag-table-buffer nil)
2909 (make-local-variable 'Info-history)
2910 (make-local-variable 'Info-index-alternatives)
2911 (setq header-line-format
2912 (if Info-use-header-line
2913 '(:eval (get-text-property (point-min) 'header-line))
2914 nil)) ; so the header line isn't displayed
2915 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
2916 ;; This is for the sake of the invisible text we use handling titles.
2917 (make-local-variable 'line-move-ignore-invisible)
2918 (setq line-move-ignore-invisible t)
2919 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
2920 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
2921 (Info-set-mode-line)
2922 (run-hooks 'Info-mode-hook))
2924 (defun Info-clone-buffer-hook ()
2925 (when (bufferp Info-tag-table-buffer)
2926 (setq Info-tag-table-buffer
2927 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
2928 (let ((m Info-tag-table-marker))
2930 (setq Info-tag-table-marker
2931 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
2932 (with-current-buffer Info-tag-table-buffer
2933 (copy-marker (marker-position m)))
2936 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
2937 (set-keymap-parent map text-mode-map)
2938 (define-key map "\C-c\C-c" 'Info-cease-edit)
2940 "Local keymap used within `e' command of Info.")
2942 ;; Info-edit mode is suitable only for specially formatted data.
2943 (put 'Info-edit-mode 'mode-class 'special)
2945 (defun Info-edit-mode ()
2946 "Major mode for editing the contents of an Info node.
2947 Like text mode with the addition of `Info-cease-edit'
2948 which returns to Info mode for browsing.
2950 (use-local-map Info-edit-map)
2951 (setq major-mode 'Info-edit-mode)
2952 (setq mode-name "Info Edit")
2953 (kill-local-variable 'mode-line-buffer-identification)
2954 (setq buffer-read-only nil)
2955 (force-mode-line-update)
2956 (buffer-enable-undo (current-buffer))
2957 (run-hooks 'Info-edit-mode-hook))
2960 "Edit the contents of this Info node.
2961 Allowed only if variable `Info-enable-edit' is non-nil."
2963 (or Info-enable-edit
2964 (error "Editing info nodes is not enabled"))
2966 (message "%s" (substitute-command-keys
2967 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2969 (defun Info-cease-edit ()
2970 "Finish editing Info node; switch back to Info proper."
2972 ;; Do this first, so nothing has changed if user C-g's at query.
2973 (and (buffer-modified-p)
2974 (y-or-n-p "Save the file? ")
2976 (use-local-map Info-mode-map)
2977 (setq major-mode 'Info-mode)
2978 (setq mode-name "Info")
2979 (Info-set-mode-line)
2980 (setq buffer-read-only t)
2981 (force-mode-line-update)
2982 (and (marker-position Info-tag-table-marker)
2984 (message "Tags may have changed. Use Info-tagify if necessary")))
2986 (defvar Info-file-list-for-emacs
2987 '("ediff" "eudc" "forms" "gnus" "info" ("mh" . "mh-e")
2988 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
2989 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
2990 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
2991 ("skeleton" . "autotype") ("auto-insert" . "autotype")
2992 ("copyright" . "autotype") ("executable" . "autotype")
2993 ("time-stamp" . "autotype") ("quickurl" . "autotype")
2994 ("tempo" . "autotype") ("hippie-expand" . "autotype")
2995 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
2996 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
2997 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
2998 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
2999 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
3000 ("rfc2045" . "emacs-mime")
3001 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
3002 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
3003 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
3004 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
3005 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
3006 ("mml" . "emacs-mime"))
3007 "List of Info files that describe Emacs commands.
3008 An element can be a file name, or a list of the form (PREFIX . FILE)
3009 where PREFIX is a name prefix and FILE is the file to look in.
3010 If the element is just a file name, the file name also serves as the prefix.")
3012 (defun Info-find-emacs-command-nodes (command)
3013 "Return a list of locations documenting COMMAND.
3014 The `info-file' property of COMMAND says which Info manual to search.
3015 If COMMAND has no property, the variable `Info-file-list-for-emacs'
3016 defines heuristics for which Info manual to try.
3017 The locations are of the format used in `Info-history', i.e.
3018 \(FILENAME NODENAME BUFFERPOS\)."
3020 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
3021 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
3022 (info-file "emacs")) ;default
3023 ;; Determine which info file this command is documented in.
3024 (if (get command 'info-file)
3025 (setq info-file (get command 'info-file))
3026 ;; If it doesn't say explicitly, test its name against
3027 ;; various prefixes that we know.
3028 (let ((file-list Info-file-list-for-emacs))
3030 (let* ((elt (car file-list))
3031 (name (if (consp elt)
3034 (file (if (consp elt) (cdr elt) elt))
3035 (regexp (concat "\\`" (regexp-quote name)
3037 (if (string-match regexp (symbol-name command))
3038 (setq info-file file file-list nil))
3039 (setq file-list (cdr file-list))))))
3040 (Info-find-node info-file "Top")
3041 (or (and (search-forward "\n* menu:" nil t)
3042 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
3043 (error "Info file `%s' appears to lack an index" info-file))
3044 (goto-char (match-beginning 1))
3045 ;; Bind Info-history to nil, to prevent the index nodes from
3046 ;; getting into the node history.
3047 (let ((Info-history nil)
3049 (Info-goto-node (Info-extract-menu-node-name))
3052 (goto-char (point-min))
3053 (while (re-search-forward cmd-desc nil t)
3055 (cons (list Info-current-file
3056 (match-string-no-properties 2)
3059 (and (setq node (Info-extract-pointer "next" t))
3060 (string-match "\\<Index\\>" node)))
3061 (Info-goto-node node)))
3065 (defun Info-goto-emacs-command-node (command)
3066 "Go to the Info node in the Emacs manual for command COMMAND.
3067 The command is found by looking up in Emacs manual's indices
3068 or in another manual found via COMMAND's `info-file' property or
3069 the variable `Info-file-list-for-emacs'.
3070 COMMAND must be a symbol or string."
3071 (interactive "CFind documentation for command: ")
3072 ;; If command is given as a string, convert it to a symbol.
3073 (if (stringp command)
3074 (setq command (intern command)))
3075 (or (commandp command)
3076 (signal 'wrong-type-argument (list 'commandp command)))
3077 (let ((where (Info-find-emacs-command-nodes command)))
3079 (let ((num-matches (length where)))
3080 ;; Get Info running, and pop to it in another window.
3081 (save-window-excursion
3083 ;; FIXME It would be cool if this could use a buffer other
3085 (pop-to-buffer "*info*")
3086 ;; Bind Info-history to nil, to prevent the last Index node
3087 ;; visited by Info-find-emacs-command-nodes from being
3088 ;; pushed onto the history.
3089 (let ((Info-history nil))
3090 (Info-find-node (car (car where))
3091 (car (cdr (car where)))))
3092 (if (> num-matches 1)
3094 ;; (car where) will be pushed onto Info-history
3095 ;; when/if they go to another node. Put the other
3096 ;; nodes that were found on the history.
3097 (setq Info-history (nconc (cdr where) Info-history))
3098 (message "Found %d other entr%s. Use %s to see %s."
3100 (if (> num-matches 2) "ies" "y")
3101 (substitute-command-keys "\\[Info-last]")
3102 (if (> num-matches 2) "them" "it")))))
3103 (error "Couldn't find documentation for %s" command))))
3106 (defun Info-goto-emacs-key-command-node (key)
3107 "Go to the node in the Emacs manual which describes the command bound to KEY.
3109 Interactively, if the binding is `execute-extended-command', a command is read.
3110 The command is found by looking up in Emacs manual's indices
3111 or in another manual found via COMMAND's `info-file' property or
3112 the variable `Info-file-list-for-emacs'."
3113 (interactive "kFind documentation for key: ")
3114 (let ((command (key-binding key)))
3115 (cond ((null command)
3116 (message "%s is undefined" (key-description key)))
3117 ((and (interactive-p)
3118 (eq command 'execute-extended-command))
3119 (Info-goto-emacs-command-node
3120 (read-command "Find documentation for command: ")))
3122 (Info-goto-emacs-command-node command)))))
3124 (defface Info-title-1-face
3125 '((((type tty pc) (class color)) (:foreground "yellow" :weight bold))
3126 (t (:height 1.2 :inherit Info-title-2-face)))
3127 "Face for Info titles at level 1."
3130 (defface Info-title-2-face
3131 '((((type tty pc) (class color)) (:foreground "lightblue" :weight bold))
3132 (t (:height 1.2 :inherit Info-title-3-face)))
3133 "Face for Info titles at level 2."
3136 (defface Info-title-3-face
3137 '((((type tty pc) (class color)) (:weight bold))
3138 (t (:height 1.2 :inherit Info-title-4-face)))
3139 "Face for Info titles at level 3."
3142 (defface Info-title-4-face
3143 '((((type tty pc) (class color)) (:weight bold))
3144 (t (:weight bold :inherit variable-pitch)))
3145 "Face for Info titles at level 4."
3148 (defface info-menu-header
3153 :inherit variable-pitch
3155 "Face for headers in Info menus."
3158 (defun Info-escape-percent (string)
3159 "Double all occurrences of `%' in STRING.
3161 Return a new string with all `%' characters replaced by `%%'.
3162 Preserve text properties."
3164 (end (length string))
3167 (while (and (< start end) (string-match "%" string start))
3168 (setq mb (match-beginning 0)
3170 m (substring string mb me)
3173 (cons (substring string start mb)
3176 (push (substring string start end) matches)
3177 (apply #'concat (nreverse matches)))))
3179 (defvar Info-next-link-keymap
3180 (let ((keymap (make-sparse-keymap)))
3181 (define-key keymap [header-line mouse-1] 'Info-next)
3182 (define-key keymap [header-line mouse-2] 'Info-next)
3183 (define-key keymap [header-line down-mouse-1] 'ignore)
3184 (define-key keymap [mouse-2] 'Info-next)
3186 "Keymap to put on the Next link in the text or the header line.")
3188 (defvar Info-prev-link-keymap
3189 (let ((keymap (make-sparse-keymap)))
3190 (define-key keymap [header-line mouse-1] 'Info-prev)
3191 (define-key keymap [header-line mouse-2] 'Info-prev)
3192 (define-key keymap [header-line down-mouse-1] 'ignore)
3193 (define-key keymap [mouse-2] 'Info-prev)
3195 "Keymap to put on the Prev link in the text or the header line.")
3198 (defvar Info-up-link-keymap
3199 (let ((keymap (make-sparse-keymap)))
3200 (define-key keymap [header-line mouse-1] 'Info-up)
3201 (define-key keymap [header-line mouse-2] 'Info-up)
3202 (define-key keymap [header-line down-mouse-1] 'ignore)
3203 (define-key keymap [mouse-2] 'Info-up)
3205 "Keymap to put on the Up link in the text or the header line.")
3207 (defun Info-fontify-node ()
3210 (let* ((inhibit-read-only t)
3211 (case-fold-search t)
3213 (not-fontified-p ; the node hasn't already been fontified
3214 (not (let ((where (next-property-change (point-min))))
3215 (and where (not (= where (point-max)))))))
3216 (fontify-visited-p ; visited nodes need to be re-fontified
3217 (and Info-fontify-visited-nodes
3218 ;; Don't take time to refontify visited nodes in huge nodes
3219 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size))))
3221 ;; Fontify header line
3222 (goto-char (point-min))
3223 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
3224 (goto-char (match-end 0))
3225 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
3226 (goto-char (match-end 0))
3227 (let* ((nbeg (match-beginning 2))
3228 (nend (match-end 2))
3229 (tbeg (match-beginning 1))
3230 (tag (match-string 1)))
3231 (if (string-equal tag "Node")
3232 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
3233 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
3234 (put-text-property tbeg nend 'mouse-face 'highlight)
3235 (put-text-property tbeg nend
3237 (concat "Go to node "
3238 (buffer-substring nbeg nend)))
3239 ;; Always set up the text property keymap.
3240 ;; It will either be used in the buffer
3241 ;; or copied in the header line.
3242 (put-text-property tbeg nend 'keymap
3244 ((equal tag "Prev") Info-prev-link-keymap)
3245 ((equal tag "Next") Info-next-link-keymap)
3246 ((equal tag "Up") Info-up-link-keymap))))))
3247 (when Info-use-header-line
3248 (goto-char (point-min))
3249 (let ((header-end (line-end-position))
3251 ;; If we find neither Next: nor Prev: link, show the entire
3252 ;; node header. Otherwise, don't show the File: and Node:
3253 ;; parts, to avoid wasting precious space on information that
3254 ;; is available in the mode line.
3255 (if (re-search-forward
3256 "\\(next\\|up\\|prev[ious]*\\): "
3259 (goto-char (match-beginning 1))
3260 (setq header (buffer-substring (point) header-end)))
3261 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" header-end t)
3263 (concat "No next, prev or up links -- "
3264 (buffer-substring (point) header-end)))
3265 (setq header (buffer-substring (point) header-end))))
3266 (put-text-property (point-min) (1+ (point-min))
3267 'header-line (Info-escape-percent header))
3268 ;; Hide the part of the first line
3269 ;; that is in the header, if it is just part.
3271 ;; Hide the punctuation at the end, too.
3272 (skip-chars-backward " \t,")
3273 (put-text-property (point) header-end 'invisible t)))))
3276 (goto-char (point-min))
3277 (when not-fontified-p
3278 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
3280 (let* ((c (preceding-char))
3282 (cond ((= c ?*) 'Info-title-1-face)
3283 ((= c ?=) 'Info-title-2-face)
3284 ((= c ?-) 'Info-title-3-face)
3285 (t 'Info-title-4-face))))
3286 (put-text-property (match-beginning 1) (match-end 1)
3287 'font-lock-face face))
3288 ;; This is a serious problem for trying to handle multiple
3289 ;; frame types at once. We want this text to be invisible
3290 ;; on frames that can display the font above.
3291 (when (memq (framep (selected-frame)) '(x pc w32 mac))
3292 (add-text-properties (1- (match-beginning 2)) (match-end 2)
3293 '(invisible t front-sticky nil rear-nonsticky t)))))
3295 ;; Fontify cross references
3296 (goto-char (point-min))
3297 (when (or not-fontified-p fontify-visited-p)
3298 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
3299 (let ((start (match-beginning 0))
3302 (when not-fontified-p
3303 (when Info-hide-note-references
3304 ;; *Note is often used where *note should have been
3306 (skip-syntax-backward " ")
3308 (cond ((memq (char-before) '(nil ?\. ?! ??))
3310 ((memq (char-before) '(?\, ?\; ?\: ?-))
3312 ((memq (char-before) '(?\( ?\[ ?\{))
3313 ;; Check whether the paren is preceded by
3314 ;; an end of sentence
3315 (skip-syntax-backward " (")
3316 (if (memq (char-before) '(nil ?\. ?! ??))
3319 ((save-match-data (looking-at "\n\n"))
3322 (add-text-properties
3324 (or (save-match-data
3325 ;; Don't hide \n after *Note
3326 (let ((start1 (match-beginning 1)))
3327 (if (string-match "\n" (match-string 1))
3328 (+ start1 (match-beginning 0)))))
3330 (if (and other-tag (not (eq Info-hide-note-references 'hide)))
3331 `(display ,other-tag front-sticky nil rear-nonsticky t)
3332 '(invisible t front-sticky nil rear-nonsticky t))))
3333 (add-text-properties
3334 (match-beginning 2) (match-end 2)
3336 'help-echo (if (or (match-end 5)
3337 (not (equal (match-string 4) "")))
3338 (concat "mouse-2: go to " (or (match-string 5)
3340 "mouse-2: go to this node")
3341 'mouse-face 'highlight)))
3342 (when (or not-fontified-p fontify-visited-p)
3343 (add-text-properties
3344 (match-beginning 2) (match-end 2)
3347 ;; Display visited nodes in a different face
3348 (if (and Info-fontify-visited-nodes
3350 (let* ((node (replace-regexp-in-string
3352 (replace-regexp-in-string
3354 (or (match-string 5)
3355 (and (not (equal (match-string 4) ""))
3357 (match-string 2)))))
3358 (file (file-name-nondirectory
3360 (hl Info-history-list)
3362 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3363 (setq file (match-string 1 node)
3364 node (if (equal (match-string 2 node) "")
3366 (match-string 2 node))))
3368 (if (and (string-equal node (nth 1 (car hl)))
3370 (file-name-nondirectory
3372 (setq res (car hl) hl nil)
3373 (setq hl (cdr hl))))
3374 res))) 'info-xref-visited 'info-xref))))
3375 (when not-fontified-p
3376 (when (memq Info-hide-note-references '(t hide))
3377 (add-text-properties (match-beginning 3) (match-end 3)
3378 '(invisible t front-sticky nil rear-nonsticky t))
3379 ;; Unhide the file name of the external reference in parens
3380 (if (match-string 6)
3381 (remove-text-properties (match-beginning 6) (match-end 6)
3382 '(invisible t front-sticky nil rear-nonsticky t)))
3383 ;; Unhide newline because hidden newlines cause too long lines
3385 (let ((start3 (match-beginning 3)))
3386 (if (string-match "\n[ \t]*" (match-string 3))
3387 (remove-text-properties (+ start3 (match-beginning 0)) (+ start3 (match-end 0))
3388 '(invisible t front-sticky nil rear-nonsticky t))))))
3389 (when (and Info-refill-paragraphs Info-hide-note-references)
3390 (push (set-marker (make-marker) start)
3391 paragraph-markers))))))
3393 ;; Refill paragraphs (experimental feature)
3394 (when (and not-fontified-p
3395 Info-refill-paragraphs
3397 (let ((fill-nobreak-invisible t)
3398 (fill-individual-varying-indent nil)
3399 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
3400 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
3401 (adaptive-fill-mode nil))
3402 (goto-char (point-max))
3403 (while paragraph-markers
3404 (let ((m (car paragraph-markers)))
3405 (setq paragraph-markers (cdr paragraph-markers))
3409 (let ((beg (point)))
3410 (when (zerop (forward-paragraph))
3411 (fill-individual-paragraphs beg (point) nil nil)
3413 (set-marker m nil)))))
3415 ;; Fontify menu items
3416 (goto-char (point-min))
3417 (when (and (or not-fontified-p fontify-visited-p)
3418 (search-forward "\n* Menu:" nil t)
3419 (not (string-match "\\<Index\\>" Info-current-node))
3420 ;; Don't take time to annotate huge menus
3421 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
3424 (while (re-search-forward
3425 (concat "^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
3426 Info-node-spec-re "\\([ \t]*\\)\\)")
3428 (when not-fontified-p
3430 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
3431 (put-text-property (match-beginning 0)
3432 (1+ (match-beginning 0))
3433 'font-lock-face 'info-menu-5)))
3434 (when not-fontified-p
3435 (add-text-properties
3436 (match-beginning 1) (match-end 1)
3438 'help-echo (if (match-end 3)
3439 (concat "mouse-2: go to " (match-string 3))
3440 "mouse-2: go to this node")
3441 'mouse-face 'highlight)))
3442 (when (or not-fontified-p fontify-visited-p)
3443 (add-text-properties
3444 (match-beginning 1) (match-end 1)
3447 ;; Display visited menu items in a different face
3448 (if (and Info-fontify-visited-nodes
3450 (let ((node (if (equal (match-string 3) "")
3453 (file (file-name-nondirectory Info-current-file))
3454 (hl Info-history-list)
3456 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3457 (setq file (match-string 1 node)
3458 node (if (equal (match-string 2 node) "")
3460 (match-string 2 node))))
3462 (if (and (string-equal node (nth 1 (car hl)))
3464 (file-name-nondirectory
3466 (setq res (car hl) hl nil)
3467 (setq hl (cdr hl))))
3468 res))) 'info-xref-visited 'info-xref))))
3469 (when (and not-fontified-p (memq Info-hide-note-references '(t hide)))
3470 (put-text-property (match-beginning 2) (1- (match-end 6))
3472 ;; Unhide the file name in parens
3473 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
3474 (remove-text-properties (match-beginning 4) (match-end 4)
3476 ;; We need a stretchable space like :align-to but with
3478 (put-text-property (1- (match-end 6)) (match-end 6) 'display
3479 (if (>= 22 (- (match-end 1)
3480 (match-beginning 0)))
3481 '(space :align-to 24)
3483 (setq cont (looking-at "."))
3484 (while (and (= (forward-line 1) 0)
3485 (looking-at "\\([ \t]+\\)[^*\n]"))
3486 (put-text-property (match-beginning 1) (1- (match-end 1))
3488 (put-text-property (1- (match-end 1)) (match-end 1)
3491 '(space :align-to 26)
3492 '(space :align-to 24)))
3495 ;; Fontify menu headers
3496 ;; Add the face `info-menu-header' to any header before a menu entry
3497 (goto-char (point-min))
3498 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
3499 (put-text-property (match-beginning 0) (match-end 0)
3500 'font-lock-face 'info-menu-header)
3501 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
3502 (put-text-property (match-beginning 1) (match-end 1)
3503 'font-lock-face 'info-menu-header)))
3505 ;; Fontify http and ftp references
3506 (goto-char (point-min))
3507 (when not-fontified-p
3508 (while (re-search-forward "[hf]t?tp://[^ \t\n\"`({<>})']+" nil t)
3509 (add-text-properties (match-beginning 0) (match-end 0)
3510 '(font-lock-face info-xref
3511 mouse-face highlight
3512 help-echo "mouse-2: go to this URL"))))
3514 (set-buffer-modified-p nil))))
3517 ;; When an Info buffer is killed, make sure the associated tags buffer
3519 (defun Info-kill-buffer ()
3520 (and (eq major-mode 'Info-mode)
3521 Info-tag-table-buffer
3522 (kill-buffer Info-tag-table-buffer)))
3524 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
3526 ;;; Speedbar support:
3527 ;; These functions permit speedbar to display the "tags" in the
3528 ;; current info node.
3529 (eval-when-compile (require 'speedbar))
3531 (defvar Info-speedbar-key-map nil
3532 "Keymap used when in the info display mode.")
3534 (defun Info-install-speedbar-variables ()
3535 "Install those variables used by speedbar to enhance Info."
3536 (if Info-speedbar-key-map
3538 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
3540 ;; Basic tree features
3541 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
3542 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
3543 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
3544 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
3547 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
3548 Info-speedbar-key-map
3549 Info-speedbar-hierarchy-buttons)))
3551 (defvar Info-speedbar-menu-items
3552 '(["Browse Node" speedbar-edit-line t]
3553 ["Expand Node" speedbar-expand-line
3554 (save-excursion (beginning-of-line)
3555 (looking-at "[0-9]+: *.\\+. "))]
3556 ["Contract Node" speedbar-contract-line
3557 (save-excursion (beginning-of-line)
3558 (looking-at "[0-9]+: *.-. "))]
3560 "Additional menu-items to add to speedbar frame.")
3562 ;; Make sure our special speedbar major mode is loaded
3563 (if (featurep 'speedbar)
3564 (Info-install-speedbar-variables)
3565 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
3567 ;;; Info hierarchy display method
3569 (defun Info-speedbar-browser ()
3570 "Initialize speedbar to display an info node browser.
3571 This will add a speedbar major display mode."
3574 ;; Make sure that speedbar is active
3575 (speedbar-frame-mode 1)
3576 ;; Now, throw us into Info mode on speedbar.
3577 (speedbar-change-initial-expansion-list "Info")
3580 (eval-when-compile (defvar speedbar-attached-frame))
3582 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
3583 "Display an Info directory hierarchy in speedbar.
3584 DIRECTORY is the current directory in the attached frame.
3585 DEPTH is the current indentation depth.
3586 NODE is an optional argument that is used to represent the
3587 specific node to expand."
3589 (save-excursion (goto-char (point-min))
3590 (let ((case-fold-search t))
3591 (looking-at "Info Nodes:"))))
3592 ;; Update our "current node" maybe?
3594 ;; We cannot use the generic list code, that depends on all leaves
3595 ;; being known at creation time.
3597 (speedbar-with-writable (insert "Info Nodes:\n")))
3598 (let ((completions nil)
3599 (cf (selected-frame)))
3600 (select-frame speedbar-attached-frame)
3601 (save-window-excursion
3603 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
3606 (speedbar-with-writable
3607 (dolist (completion completions)
3608 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
3611 'Info-speedbar-goto-node
3617 (defun Info-speedbar-goto-node (text node indent)
3618 "When user clicks on TEXT, go to an info NODE.
3619 The INDENT level is ignored."
3620 (select-frame speedbar-attached-frame)
3621 (let* ((buff (or (get-buffer "*info*")
3622 (progn (info) (get-buffer "*info*"))))
3623 (bwin (get-buffer-window buff 0)))
3626 (select-window bwin)
3627 (raise-frame (window-frame bwin)))
3628 (if speedbar-power-click
3629 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
3630 (select-frame speedbar-attached-frame)
3631 (switch-to-buffer buff)))
3632 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
3633 (error "Invalid node %s" node)
3634 (Info-find-node (match-string 1 node) (match-string 2 node))
3635 ;; If we do a find-node, and we were in info mode, restore
3636 ;; the old default method. Once we are in info mode, it makes
3637 ;; sense to return to whatever method the user was using before.
3638 (if (string= speedbar-initial-expansion-list-name "Info")
3639 (speedbar-change-initial-expansion-list
3640 speedbar-previously-used-expansion-list-name)))))
3642 (defun Info-speedbar-expand-node (text token indent)
3643 "Expand the node the user clicked on.
3644 TEXT is the text of the button we clicked on, a + or - item.
3645 TOKEN is data related to this node (NAME . FILE).
3646 INDENT is the current indentation depth."
3647 (cond ((string-match "+" text) ;we have to expand this file
3648 (speedbar-change-expand-button-char ?-)
3649 (if (speedbar-with-writable
3651 (end-of-line) (forward-char 1)
3652 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
3653 (speedbar-change-expand-button-char ?-)
3654 (speedbar-change-expand-button-char ??)))
3655 ((string-match "-" text) ;we have to contract this node
3656 (speedbar-change-expand-button-char ?+)
3657 (speedbar-delete-subblock indent))
3658 (t (error "Ooops... not sure what to do")))
3659 (speedbar-center-buffer-smartly))
3661 (defun Info-speedbar-fetch-file-nodes (nodespec)
3662 "Fetch the subnodes from the info NODESPEC.
3663 NODESPEC is a string of the form: (file)node.
3664 Optional THISFILE represends the filename of"
3666 ;; Set up a buffer we can use to fake-out Info.
3667 (set-buffer (get-buffer-create "*info-browse-tmp*"))
3668 (if (not (equal major-mode 'Info-mode))
3670 ;; Get the node into this buffer
3671 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
3672 (error "Invalid node specification %s" nodespec)
3673 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
3674 ;; Scan the created buffer
3675 (goto-char (point-min))
3676 (let ((completions nil)
3677 (case-fold-search t)
3678 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
3679 (match-string 1 nodespec))))
3680 ;; Always skip the first one...
3681 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3682 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3683 (let ((name (match-string 1)))
3685 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
3687 (if (looking-at " *\\(([^)]+)\\)\\.")
3688 (concat (match-string 1) "Top")
3689 (concat "(" thisfile ")"
3690 (if (looking-at " \\([^.]+\\).")
3694 (nreverse completions))))
3696 ;;; Info mode node listing
3697 ;; FIXME: Seems not to be used. -stef
3698 (defun Info-speedbar-buttons (buffer)
3699 "Create a speedbar display to help navigation in an Info file.
3700 BUFFER is the buffer speedbar is requesting buttons for."
3701 (if (save-excursion (goto-char (point-min))
3702 (let ((case-fold-search t))
3703 (not (looking-at "Info Nodes:"))))
3705 (Info-speedbar-hierarchy-buttons nil 0)
3708 (dolist (mess '("^Node has no Previous$"
3709 "^No menu in this node$"
3710 "^Node has no Next$"
3711 "^No cross-references in this node^"
3713 "^No \".*\" in index$"))
3714 (add-to-list 'debug-ignored-errors mess))
3718 ;;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
3719 ;;; info.el ends here