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-forward nil
51 "Stack of info nodes user has visited with `Info-history-back' command.
52 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
54 (defvar Info-history-list nil
55 "List of all info nodes user has visited.
56 Each element of list is a list (FILENAME NODENAME).")
58 (defcustom Info-enable-edit nil
59 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
60 This is convenient if you want to write info files by hand.
61 However, we recommend that you not do this.
62 It is better to write a Texinfo file and generate the Info file from that,
63 because that gives you a printed manual as well."
67 (defvar Info-enable-active-nodes nil
68 "Non-nil allows Info to execute Lisp code associated with nodes.
69 The Lisp code is executed when the node is selected.")
70 (put 'Info-enable-active-nodes
'risky-local-variable t
)
73 '((((class color
) (background light
)) :foreground
"brown" :weight bold
:slant italic
)
74 (((class color
) (background dark
)) :foreground
"white" :weight bold
:slant italic
)
75 (t :weight bold
:slant italic
))
76 "Face for Info node names."
80 '((((class color
)) :foreground
"red1")
82 "Face for every third `*' in an Info menu."
86 '((((class color
) (background light
)) :foreground
"blue" :underline t
)
87 (((class color
) (background dark
)) :foreground
"cyan" :underline t
)
89 "Face for Info cross-references."
92 (defface info-xref-visited
93 '((default :inherit info-xref
)
94 (((class color
) (background light
)) :foreground
"magenta4")
95 (((class color
) (background dark
)) :foreground
"magenta3")) ;"violet"?
96 "Face for visited Info cross-references."
99 (defcustom Info-fontify-visited-nodes t
100 "*Non-nil means to fontify visited nodes in a different face."
105 (defcustom Info-fontify-maximum-menu-size
100000
106 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
110 (defcustom Info-use-header-line t
111 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
112 A header-line does not scroll with the rest of the buffer."
116 (defface info-header-xref
117 '((t :inherit info-xref
))
118 "Face for Info cross-references in a node header."
121 (defface info-header-node
122 '((t :inherit info-node
))
123 "Face for Info nodes in a node header."
126 (defvar Info-directory-list nil
127 "List of directories to search for Info documentation files.
128 If nil, meaning not yet initialized, Info uses the environment
129 variable INFOPATH to initialize it, or `Info-default-directory-list'
130 if there is no INFOPATH variable in the environment, or the
131 concatenation of the two if INFOPATH ends with a colon.
133 When `Info-directory-list' is initialized from the value of
134 `Info-default-directory-list', and Emacs is installed in one of the
135 standard directories, the directory of Info files that come with Emacs
136 is put last (so that local Info files override standard ones).
138 When `Info-directory-list' is initialized from the value of
139 `Info-default-directory-list', and Emacs is not installed in one
140 of the standard directories, the first element of the resulting
141 list is the directory where Emacs installs the Info files that
142 come with it. This is so that Emacs's own manual, which suits the
143 version of Emacs you are using, will always be found first. This
144 is useful when you install an experimental version of Emacs without
145 removing the standard installation.
147 If you want to override the order of directories in
148 `Info-default-directory-list', set INFOPATH in the environment.
150 If you run the Emacs executable from the `src' directory in the Emacs
151 source tree, and INFOPATH is not defined, the `info' directory in the
152 source tree is used as the first element of `Info-directory-list', in
153 place of the installation Info directory. This is useful when you run
154 a version of Emacs without installing it.")
156 (defcustom Info-additional-directory-list nil
157 "List of additional directories to search for Info documentation files.
158 These directories are searched after those in `Info-directory-list'."
159 :type
'(repeat directory
)
162 (defcustom Info-scroll-prefer-subnodes nil
163 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
164 If this is non-nil, and you scroll far enough in a node that its menu
165 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
166 moves to a subnode indicated by the following menu item. This means
167 that you visit a subnode before getting to the end of the menu.
169 Setting this option to nil results in behavior similar to the stand-alone
170 Info reader program, which visits the first subnode from the menu only
171 when you hit the end of the current node."
176 (defcustom Info-hide-note-references t
177 "*If non-nil, hide the tag and section reference in *note and * menu items.
178 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
179 If value is non-nil but not t or `hide', the reference section is still shown."
181 :type
'(choice (const :tag
"No hiding" nil
)
182 (const :tag
"Replace tag and hide reference" t
)
183 (const :tag
"Hide tag and reference" hide
)
184 (other :tag
"Only replace tag" tag
))
187 (defcustom Info-refill-paragraphs nil
188 "*If non-nil, attempt to refill paragraphs with hidden references.
189 This refilling may accidentally remove explicit line breaks in the info
190 file, so be prepared for a few surprises if you enable this feature."
195 (defcustom Info-search-whitespace-regexp
"\\s-+"
196 "*If non-nil, regular expression to match a sequence of whitespace chars.
197 This applies to Info search for regular expressions.
198 You might want to use something like \"[ \\t\\r\\n]+\" instead.
199 In the Customization buffer, that is `[' followed by a space,
200 a tab, a carriage return (control-M), a newline, and `]+'."
204 (defcustom Info-isearch-search t
205 "*If non-nil, isearch invoked in Info mode uses `Info-search' function.
206 This allows isearch to search through multiple nodes.
207 When isearch fails, it wraps and restarts the search from the
208 top/final node depending on search direction."
213 (defcustom Info-mode-hook
214 ;; Try to obey obsolete Info-fontify settings.
215 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
216 '(turn-on-font-lock))
217 "Hooks run when `Info-mode' is called."
221 (defcustom Info-selection-hook nil
222 "Hooks run when `Info-select-node' is called."
226 (defvar Info-edit-mode-hook nil
227 "Hooks run when `Info-edit-mode' is called.")
229 (defvar Info-current-file nil
230 "Info file that Info is now looking at, or nil.
231 This is the name that was specified in Info, not the actual file name.
232 It doesn't contain directory names or file name extensions added by Info.
233 Can also be t when using `Info-on-current-buffer'.")
235 (defvar Info-current-subfile nil
236 "Info subfile that is actually in the *info* buffer now.
237 nil if current info file is not split into subfiles.")
239 (defvar Info-current-node nil
240 "Name of node that Info is now looking at, or nil.")
242 (defvar Info-tag-table-marker nil
243 "Marker pointing at beginning of current Info file's tag table.
244 Marker points nowhere if file has no tag table.")
246 (defvar Info-tag-table-buffer nil
247 "Buffer used for indirect tag tables.")
249 (defvar Info-current-file-completions nil
250 "Cached completion list for current Info file.")
252 (defvar Info-index-alternatives nil
253 "List of possible matches for last `Info-index' command.")
255 (defvar Info-point-loc nil
256 "Point location within a selected node.
257 If string, the point is moved to the proper occurrence of the
258 name of the followed cross reference within a selected node.
259 If number, the point is moved to the corresponding line.")
261 (defvar Info-standalone nil
262 "Non-nil if Emacs was started solely as an Info browser.")
264 (defvar Info-suffix-list
265 ;; The MS-DOS list should work both when long file names are
266 ;; supported (Windows 9X), and when only 8+3 file names are available.
267 (if (eq system-type
'ms-dos
)
268 '( (".gz" .
"gunzip")
270 (".bz2" .
("bzip2" "-dc"))
273 (".info.Z" .
"gunzip")
274 (".info.gz" .
"gunzip")
275 ("-info.Z" .
"gunzip")
276 ("-info.gz" .
"gunzip")
277 ("/index.gz".
"gunzip")
278 ("/index.z" .
"gunzip")
284 '( (".info.Z".
"uncompress")
285 (".info.Y".
"unyabba")
286 (".info.gz".
"gunzip")
287 (".info.z".
"gunzip")
288 (".info.bz2" .
("bzip2" "-dc"))
290 ("-info.Z".
"uncompress")
291 ("-info.Y".
"unyabba")
292 ("-info.gz".
"gunzip")
293 ("-info.bz2" .
("bzip2" "-dc"))
294 ("-info.z".
"gunzip")
296 ("/index.Z".
"uncompress")
297 ("/index.Y".
"unyabba")
298 ("/index.gz".
"gunzip")
299 ("/index.z".
"gunzip")
300 ("/index.bz2".
("bzip2" "-dc"))
306 (".bz2" .
("bzip2" "-dc"))
308 "List of file name suffixes and associated decoding commands.
309 Each entry should be (SUFFIX . STRING); the file is given to
310 the command as standard input.
312 STRING may be a list of strings. In that case, the first element is
313 the command name, and the rest are arguments to that command.
315 If STRING is nil, no decoding is done.
316 Because the SUFFIXes are tried in order, the empty string should
317 be last in the list.")
319 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
320 ;; First, on MS-DOS with no long file names support, delete some of
321 ;; the extension in FILENAME to make room.
322 (defun info-insert-file-contents-1 (filename suffix lfn
)
323 (if lfn
; long file names are supported
324 (concat filename suffix
)
325 (let* ((sans-exts (file-name-sans-extension filename
))
326 ;; How long is the extension in FILENAME (not counting the dot).
327 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
329 ;; SUFFIX starts with a dot. If FILENAME already has one,
330 ;; get rid of the one in SUFFIX (unless suffix is empty).
331 (or (and (<= ext-len
0)
332 (not (eq (aref filename
(1- (length filename
))) ?.
)))
333 (= (length suffix
) 0)
334 (setq suffix
(substring suffix
1)))
335 ;; How many chars of that extension should we keep?
336 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
337 ;; Get rid of the rest of the extension, and add SUFFIX.
338 (concat (substring filename
0 (- (length filename
)
339 (- ext-len ext-left
)))
342 (defun info-file-exists-p (filename)
343 (and (file-exists-p filename
)
344 (not (file-directory-p filename
))))
346 (defun info-insert-file-contents (filename &optional visit
)
347 "Insert the contents of an info file in the current buffer.
348 Do the right thing if the file has been compressed or zipped."
349 (let* ((tail Info-suffix-list
)
350 (lfn (if (fboundp 'msdos-long-file-names
)
351 (msdos-long-file-names)
353 (check-short (and (fboundp 'msdos-long-file-names
)
355 fullname decoder done
)
356 (if (info-file-exists-p filename
)
357 ;; FILENAME exists--see if that name contains a suffix.
358 ;; If so, set DECODE accordingly.
362 (concat (regexp-quote (car (car tail
))) "$")
364 (setq tail
(cdr tail
)))
365 (setq fullname filename
366 decoder
(cdr (car tail
))))
367 ;; Try adding suffixes to FILENAME and see if we can find something.
368 (while (and tail
(not done
))
369 (setq fullname
(info-insert-file-contents-1 filename
370 (car (car tail
)) lfn
))
371 (if (info-file-exists-p fullname
)
373 ;; If we found a file with a suffix, set DECODER
374 ;; according to the suffix.
375 decoder
(cdr (car tail
)))
376 ;; When the MS-DOS port runs on Windows, we need to check
377 ;; the short variant of a long file name as well.
379 (setq fullname
(info-insert-file-contents-1 filename
380 (car (car tail
)) nil
))
381 (if (info-file-exists-p fullname
)
383 decoder
(cdr (car tail
))))))
384 (setq tail
(cdr tail
)))
386 (error "Can't find %s or any compressed version of it" filename
)))
387 ;; check for conflict with jka-compr
388 (if (and (featurep 'jka-compr
)
389 (jka-compr-installed-p)
390 (jka-compr-get-compression-info fullname
))
394 (insert-file-contents-literally fullname visit
)
395 (let ((buffer-read-only nil
)
396 (coding-system-for-write 'no-conversion
)
397 (default-directory (or (file-name-directory fullname
)
400 (setq decoder
(list decoder
)))
401 (apply 'call-process-region
(point-min) (point-max)
402 (car decoder
) t t nil
(cdr decoder
))))
403 (insert-file-contents fullname visit
))))
405 (defun Info-default-dirs ()
406 (let ((source (expand-file-name "info/" source-directory
))
407 (sibling (if installation-directory
408 (expand-file-name "info/" installation-directory
)
409 (if invocation-directory
410 (let ((infodir (expand-file-name
412 invocation-directory
)))
413 (if (file-exists-p infodir
)
415 (setq infodir
(expand-file-name
417 invocation-directory
))
418 (and (file-exists-p infodir
)
422 (if (and sibling
(file-exists-p sibling
))
423 ;; Uninstalled, Emacs builddir != srcdir.
425 ;; Uninstalled, builddir == srcdir
427 (if (or (member alternative Info-default-directory-list
)
428 ;; On DOS/NT, we use movable executables always,
429 ;; and we must always find the Info dir at run time.
430 (if (memq system-type
'(ms-dos windows-nt
))
432 ;; Use invocation-directory for Info
433 ;; only if we used it for exec-directory also.
434 (not (string= exec-directory
435 (expand-file-name "lib-src/"
436 installation-directory
))))
437 (not (file-exists-p alternative
)))
438 Info-default-directory-list
439 ;; `alternative' contains the Info files that came with this
440 ;; version, so we should look there first. `Info-insert-dir'
441 ;; currently expects to find `alternative' first on the list.
443 ;; Don't drop the last part, it might contain non-Emacs stuff.
444 ;; (reverse (cdr (reverse
445 Info-default-directory-list
)))) ;; )))
447 (defun info-initialize ()
448 "Initialize `Info-directory-list', if that hasn't been done yet."
449 (unless Info-directory-list
450 (let ((path (getenv "INFOPATH")))
451 (setq Info-directory-list
452 (prune-directory-list
454 (if (string-match ":\\'" path
)
455 (append (split-string (substring path
0 -
1)
456 (regexp-quote path-separator
))
458 (split-string path
(regexp-quote path-separator
)))
459 (Info-default-dirs)))))))
462 (defun info-other-window (&optional file
)
463 "Like `info' but show the Info buffer in another window."
464 (interactive (if current-prefix-arg
465 (list (read-file-name "Info file name: " nil nil t
))))
466 (let (same-window-buffer-names same-window-regexps
)
469 ;;;###autoload (add-hook 'same-window-regexps "\\*info\\*\\(\\|<[0-9]+>\\)")
471 ;;;###autoload (put 'info 'info-file "emacs")
473 (defun info (&optional file buffer
)
474 "Enter Info, the documentation browser.
475 Optional argument FILE specifies the file to examine;
476 the default is the top-level directory of Info.
477 Called from a program, FILE may specify an Info node of the form
478 `(FILENAME)NODENAME'.
479 Optional argument BUFFER specifies the Info buffer name;
480 the default buffer name is *info*. If BUFFER exists,
481 just switch to BUFFER. Otherwise, create a new buffer
482 with the top-level Info directory.
484 In interactive use, a non-numeric prefix argument directs
485 this command to read a file name from the minibuffer.
486 A numeric prefix argument selects an Info buffer with the prefix number
487 appended to the Info buffer name.
489 The search path for Info files is in the variable `Info-directory-list'.
490 The top-level Info directory is made by combining all the files named `dir'
491 in all the directories in that path."
493 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
494 (read-file-name "Info file name: " nil nil t
))
495 (if (numberp current-prefix-arg
)
496 (format "*info*<%s>" current-prefix-arg
))))
497 (pop-to-buffer (or buffer
"*info*"))
498 (if (and buffer
(not (eq major-mode
'Info-mode
)))
501 ;; If argument already contains parentheses, don't add another set
502 ;; since the argument will then be parsed improperly. This also
503 ;; has the added benefit of allowing node names to be included
504 ;; following the parenthesized filename.
505 (if (and (stringp file
) (string-match "(.*)" file
))
506 (Info-goto-node file
)
507 (Info-goto-node (concat "(" file
")")))
508 (if (zerop (buffer-size))
512 (defun info-emacs-manual ()
513 "Display the Emacs manual in Info mode."
518 (defun info-standalone ()
519 "Run Emacs as a standalone Info reader.
520 Usage: emacs -f info-standalone [filename]
521 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
522 (setq Info-standalone t
)
523 (if (and command-line-args-left
524 (not (string-match "^-" (car command-line-args-left
))))
527 (info (car command-line-args-left
))
528 (setq command-line-args-left
(cdr command-line-args-left
)))
529 (error (send-string-to-terminal
530 (format "%s\n" (if (eq (car-safe err
) 'error
)
532 (save-buffers-kill-emacs)))
535 ;; See if the accessible portion of the buffer begins with a node
536 ;; delimiter, and the node header line which follows matches REGEXP.
537 ;; Typically, this test will be followed by a loop that examines the
538 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
539 ;; to have the overhead of this special test inside the loop.
541 ;; This function changes match-data, but supposedly the caller might
542 ;; want to use the results of re-search-backward.
544 ;; The return value is the value of point at the beginning of matching
545 ;; REGEXP, if the function succeeds, nil otherwise.
546 (defun Info-node-at-bob-matching (regexp)
547 (and (bobp) ; are we at beginning of buffer?
548 (looking-at "\^_") ; does it begin with node delimiter?
552 (forward-line 1) ; does the line after delimiter match REGEXP?
553 (re-search-backward regexp beg t
))))
555 (defun Info-find-file (filename &optional noerror
)
556 "Return expanded FILENAME, or t, if FILENAME is \"dir\".
557 Optional second argument NOERROR, if t, means if file is not found
558 just return nil (no error)."
559 ;; Convert filename to lower case if not found as specified.
561 (if (stringp filename
)
562 (let (temp temp-downcase found
)
563 (setq filename
(substitute-in-file-name filename
))
565 ((string= (downcase filename
) "dir")
567 ((string= filename
"apropos")
568 (setq found
'apropos
))
569 ((string= filename
"history")
570 (setq found
'history
))
571 ((string= filename
"toc")
574 (let ((dirs (if (string-match "^\\./" filename
)
575 ;; If specified name starts with `./'
576 ;; then just try current directory.
578 (if (file-name-absolute-p filename
)
579 ;; No point in searching for an
580 ;; absolute file name
582 (if Info-additional-directory-list
583 (append Info-directory-list
584 Info-additional-directory-list
)
585 Info-directory-list
)))))
586 ;; Search the directory list for file FILENAME.
587 (while (and dirs
(not found
))
588 (setq temp
(expand-file-name filename
(car dirs
)))
590 (expand-file-name (downcase filename
) (car dirs
)))
591 ;; Try several variants of specified name.
592 (let ((suffix-list Info-suffix-list
)
593 (lfn (if (fboundp 'msdos-long-file-names
)
594 (msdos-long-file-names)
596 (while (and suffix-list
(not found
))
597 (cond ((info-file-exists-p
598 (info-insert-file-contents-1
599 temp
(car (car suffix-list
)) lfn
))
602 (info-insert-file-contents-1
603 temp-downcase
(car (car suffix-list
)) lfn
))
604 (setq found temp-downcase
))
605 ((and (fboundp 'msdos-long-file-names
)
608 (info-insert-file-contents-1
609 temp
(car (car suffix-list
)) nil
)))
611 (setq suffix-list
(cdr suffix-list
))))
612 (setq dirs
(cdr dirs
))))))
614 (setq filename found
)
617 (error "Info file %s does not exist" filename
)))
620 (defun Info-find-node (filename nodename
&optional no-going-back
)
621 "Go to an info node specified as separate FILENAME and NODENAME.
622 NO-GOING-BACK is non-nil if recovering from an error in this function;
623 it says do not attempt further (recursive) error recovery."
625 (setq filename
(Info-find-file filename
))
626 ;; Record the node we are leaving.
627 (if (and Info-current-file
(not no-going-back
))
629 (cons (list Info-current-file Info-current-node
(point))
631 ;; Go into info buffer.
632 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
633 (Info-find-node-2 filename nodename no-going-back
))
635 (defun Info-on-current-buffer (&optional nodename
)
636 "Use the `Info-mode' to browse the current info buffer.
637 If a prefix arg is provided, it queries for the NODENAME which
638 else defaults to \"Top\"."
640 (list (if current-prefix-arg
641 (completing-read "Node name: " (Info-build-node-completions)
643 (unless nodename
(setq nodename
"Top"))
646 (set (make-local-variable 'Info-current-file
) t
)
647 (Info-find-node-2 nil nodename
))
649 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
650 ;; but at least it keeps this routine (which is only for the benefit of
651 ;; makeinfo-buffer) out of the way of normal operations.
653 (defun Info-revert-find-node (filename nodename
)
654 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
655 When *info* is already displaying FILENAME and NODENAME, the window position
656 is preserved, if possible."
657 (pop-to-buffer "*info*")
658 (let ((old-filename Info-current-file
)
659 (old-nodename Info-current-node
)
660 (pcolumn (current-column))
661 (pline (count-lines (point-min) (line-beginning-position)))
662 (wline (count-lines (point-min) (window-start)))
663 (old-history Info-history
)
664 (new-history (and Info-current-file
665 (list Info-current-file Info-current-node
(point)))))
666 (kill-buffer (current-buffer))
667 (Info-find-node filename nodename
)
668 (setq Info-history old-history
)
669 (if (and (equal old-filename Info-current-file
)
670 (equal old-nodename Info-current-node
))
672 ;; note goto-line is no good, we want to measure from point-min
673 (goto-char (point-min))
675 (set-window-start (selected-window) (point))
676 (goto-char (point-min))
678 (move-to-column pcolumn
))
679 ;; only add to the history when coming from a different file+node
681 (setq Info-history
(cons new-history Info-history
))))))
683 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
684 "Find a node in a tag table.
685 MARKER specifies the buffer and position to start searching at.
686 REGEXP is a regular expression matching nodes or references. Its first
687 group should match `Node:' or `Ref:'.
688 CASE-FOLD t means search for a case-insensitive match.
689 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
690 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
691 where the match was found, and MODE is `major-mode' of the buffer in
692 which the match was found."
693 (let ((case-fold-search case-fold
))
695 (set-buffer (marker-buffer marker
))
700 (when (re-search-forward regexp nil t
)
701 (list (string-equal "Ref:" (match-string 1))
702 (+ (point-min) (read (current-buffer)))
705 (defun Info-find-in-tag-table (marker regexp
)
706 "Find a node in a tag table.
707 MARKER specifies the buffer and position to start searching at.
708 REGEXP is a regular expression matching nodes or references. Its first
709 group should match `Node:' or `Ref:'.
710 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
711 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
712 where the match was found, and MODE is `major-mode' of the buffer in
713 which the match was found.
714 This function tries to find a case-sensitive match first, then a
715 case-insensitive match is tried."
716 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
717 (when (null (car result
))
718 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
721 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
722 "Find a node or anchor in the current buffer.
723 REGEXP is a regular expression matching nodes or references. Its first
724 group should match `Node:' or `Ref:'.
725 CASE-FOLD t means search for a case-insensitive match.
726 Value is the position at which a match was found, or nil if not found."
727 (let ((case-fold-search case-fold
)
730 (when (Info-node-at-bob-matching regexp
)
731 (setq found
(point)))
732 (while (and (not found
)
733 (search-forward "\n\^_" nil t
))
737 (when (re-search-backward regexp beg t
)
739 (setq found
(point)))))
742 (defun Info-find-node-in-buffer (regexp)
743 "Find a node or anchor in the current buffer.
744 REGEXP is a regular expression matching nodes or references. Its first
745 group should match `Node:' or `Ref:'.
746 Value is the position at which a match was found, or nil if not found.
747 This function looks for a case-sensitive match first. If none is found,
748 a case-insensitive match is tried."
749 (or (Info-find-node-in-buffer-1 regexp nil
)
750 (Info-find-node-in-buffer-1 regexp t
)))
752 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
753 (buffer-disable-undo (current-buffer))
754 (or (eq major-mode
'Info-mode
)
757 (setq Info-current-node nil
)
759 (let ((case-fold-search t
)
761 ;; Switch files if necessary
763 (equal Info-current-file filename
)
764 (let ((buffer-read-only nil
))
765 (setq Info-current-file nil
766 Info-current-subfile nil
767 Info-current-file-completions nil
768 buffer-file-name nil
)
773 ((eq filename
'apropos
)
774 (insert-buffer-substring " *info-apropos*"))
775 ((eq filename
'history
)
776 (insert-buffer-substring " *info-history*"))
778 (insert-buffer-substring " *info-toc*"))
780 (info-insert-file-contents filename nil
)
781 (setq default-directory
(file-name-directory filename
))))
782 (set-buffer-modified-p nil
)
783 ;; See whether file has a tag table. Record the location if yes.
784 (goto-char (point-max))
786 ;; Use string-equal, not equal, to ignore text props.
787 (if (not (or (string-equal nodename
"*")
789 (search-forward "\^_\nEnd tag table\n" nil t
))))
791 ;; We have a tag table. Find its beginning.
792 ;; Is this an indirect file?
793 (search-backward "\nTag table:\n")
797 (looking-at "(Indirect)\n"))
798 ;; It is indirect. Copy it to another buffer
799 ;; and record that the tag table is in that buffer.
800 (let ((buf (current-buffer))
802 (or Info-tag-table-buffer
803 (generate-new-buffer " *info tag table*"))))
804 (setq Info-tag-table-buffer tagbuf
)
807 (buffer-disable-undo (current-buffer))
808 (setq case-fold-search t
)
810 (insert-buffer-substring buf
))
811 (set-marker Info-tag-table-marker
812 (match-end 0) tagbuf
))
813 (set-marker Info-tag-table-marker pos
)))
814 (set-marker Info-tag-table-marker nil
))
815 (setq Info-current-file
817 ((eq filename t
) "dir")
818 ((eq filename
'apropos
) "apropos")
819 ((eq filename
'history
) "history")
820 ((eq filename
'toc
) "toc")
823 ;; Use string-equal, not equal, to ignore text props.
824 (if (string-equal nodename
"*")
825 (progn (setq Info-current-node nodename
)
826 (Info-set-mode-line))
829 ;; 1. Anchor found in tag table
830 ;; 2. Anchor *not* in tag table
832 ;; 3. Node found in tag table
833 ;; 4. Node *not* found in tag table, but found in file
834 ;; 5. Node *not* in tag table, and *not* in file
836 ;; *Or* the same, but in an indirect subfile.
838 ;; Search file for a suitable node.
839 (let ((guesspos (point-min))
840 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
841 (if (stringp nodename
)
842 (regexp-quote nodename
)
844 "\\) *[,\t\n\177]")))
848 ;; First, search a tag table, if any
849 (when (marker-position Info-tag-table-marker
)
850 (let* ((m Info-tag-table-marker
)
851 (found (Info-find-in-tag-table m regexp
)))
854 ;; FOUND is (ANCHOR POS MODE).
855 (setq guesspos
(nth 1 found
))
857 ;; If this is an indirect file, determine which
858 ;; file really holds this node and read it in.
859 (unless (eq (nth 2 found
) 'Info-mode
)
860 ;; Note that the current buffer must be the
861 ;; *info* buffer on entry to
862 ;; Info-read-subfile. Thus the hackery above.
863 (setq guesspos
(Info-read-subfile guesspos
)))
867 (goto-char (setq anchorpos guesspos
))
870 ;; Else we may have a node, which we search for:
871 (goto-char (max (point-min)
872 (- (byte-to-position guesspos
) 1000)))
874 ;; Now search from our advised position (or from beg of
875 ;; buffer) to find the actual node. First, check
876 ;; whether the node is right where we are, in case the
877 ;; buffer begins with a node.
878 (let ((pos (Info-find-node-in-buffer regexp
)))
883 (when (string-match "\\([^.]+\\)\\." nodename
)
884 (let (Info-point-loc)
886 filename
(match-string 1 nodename
) no-going-back
))
890 ;; No such anchor in tag table or node in tag table or file
891 (error "No such node or anchor: %s" nodename
))
894 (goto-char (point-min))
896 (let ((new-history (list Info-current-file
897 (substring-no-properties nodename
))))
898 ;; Add anchors to the history too
899 (setq Info-history-list
901 (delete new-history Info-history-list
))))
902 (goto-char anchorpos
))
903 ((numberp Info-point-loc
)
904 (forward-line (1- Info-point-loc
))
905 (setq Info-point-loc nil
))
906 ((stringp Info-point-loc
)
907 (Info-find-index-name Info-point-loc
)
908 (setq Info-point-loc nil
))))))
909 ;; If we did not finish finding the specified node,
910 ;; go back to the previous one.
911 (or Info-current-node no-going-back
(null Info-history
)
912 (let ((hist (car Info-history
)))
913 (setq Info-history
(cdr Info-history
))
914 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
915 (goto-char (nth 2 hist
))))))
917 ;; Cache the contents of the (virtual) dir file, once we have merged
918 ;; it for the first time, so we can save time subsequently.
919 (defvar Info-dir-contents nil
)
921 ;; Cache for the directory we decided to use for the default-directory
922 ;; of the merged dir text.
923 (defvar Info-dir-contents-directory nil
)
925 ;; Record the file attributes of all the files from which we
926 ;; constructed Info-dir-contents.
927 (defvar Info-dir-file-attributes nil
)
929 (defvar Info-dir-file-name nil
)
931 ;; Construct the Info directory node by merging the files named `dir'
932 ;; from various directories. Set the *info* buffer's
933 ;; default-directory to the first directory we actually get any text
935 (defun Info-insert-dir ()
936 (if (and Info-dir-contents Info-dir-file-attributes
937 ;; Verify that none of the files we used has changed
940 (mapcar (lambda (elt)
941 (let ((curr (file-attributes
943 (file-truename (car elt
)))))
945 ;; Don't compare the access time.
946 (if curr
(setcar (nthcdr 4 curr
) 0))
947 (setcar (nthcdr 4 (cdr elt
)) 0)
948 (equal (cdr elt
) curr
)))
949 Info-dir-file-attributes
))))
951 (insert Info-dir-contents
)
952 (goto-char (point-min)))
953 (let ((dirs (if Info-additional-directory-list
954 (append Info-directory-list
955 Info-additional-directory-list
)
956 Info-directory-list
))
958 ;; Bind this in case the user sets it to nil.
960 ;; This is set non-nil if we find a problem in some input files.
962 buffers buffer others nodes dirs-done
)
964 ;; Search the directory list for the directory file.
966 (let ((truename (file-truename (expand-file-name (car dirs
)))))
967 (or (member truename dirs-done
)
968 (member (directory-file-name truename
) dirs-done
)
969 ;; Try several variants of specified name.
970 ;; Try upcasing, appending `.info', or both.
974 (progn (setq file
(expand-file-name "dir" truename
))
975 (file-attributes file
))
976 (progn (setq file
(expand-file-name "DIR" truename
))
977 (file-attributes file
))
978 (progn (setq file
(expand-file-name "dir.info" truename
))
979 (file-attributes file
))
980 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
981 (file-attributes file
)))))
984 (cons (directory-file-name truename
)
989 (message "Composing main Info directory..."))
990 (set-buffer (generate-new-buffer " info dir"))
993 (insert-file-contents file
)
994 (set (make-local-variable 'Info-dir-file-name
)
996 (push (current-buffer) buffers
)
997 (push (cons file attrs
) dir-file-attrs
))
998 (error (kill-buffer (current-buffer))))))))
1000 (set (make-local-variable 'Info-dir-contents-directory
)
1001 (file-name-as-directory (car dirs
))))
1002 (setq dirs
(cdr dirs
))))
1005 (error "Can't find the Info directory node"))
1007 ;; Distinguish the dir file that comes with Emacs from all the
1008 ;; others. Yes, that is really what this is supposed to do.
1009 ;; The definition of `Info-directory-list' puts it first on that
1010 ;; list and so last in `buffers' at this point.
1011 (setq buffer
(car (last buffers
))
1012 others
(delq buffer buffers
))
1014 ;; Insert the entire original dir file as a start; note that we've
1015 ;; already saved its default directory to use as the default
1016 ;; directory for the whole concatenation.
1017 (insert-buffer buffer
)
1019 ;; Look at each of the other buffers one by one.
1020 (dolist (other others
)
1021 (let (this-buffer-nodes)
1022 ;; In each, find all the menus.
1023 (with-current-buffer other
1024 (goto-char (point-min))
1025 ;; Find each menu, and add an elt to NODES for it.
1026 (while (re-search-forward "^\\* Menu:" nil t
)
1027 (while (and (zerop (forward-line 1)) (eolp)))
1030 (re-search-backward "^\^_")
1031 (search-forward "Node: ")
1032 (setq nodename
(Info-following-node-name))
1033 (search-forward "\n\^_" nil
'move
)
1036 (push (list nodename other beg end
) this-buffer-nodes
)))
1037 (if (assoc-string "top" this-buffer-nodes t
)
1038 (setq nodes
(nconc this-buffer-nodes nodes
))
1040 (message "No `top' node in %s" Info-dir-file-name
)))))
1041 ;; Add to the main menu a menu item for each other node.
1042 (re-search-forward "^\\* Menu:")
1044 (let ((menu-items '("top"))
1045 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1046 (dolist (node nodes
)
1047 (let ((nodename (car node
)))
1049 (or (member (downcase nodename
) menu-items
)
1050 (re-search-forward (concat "^\\* +"
1051 (regexp-quote nodename
)
1055 (insert "* " nodename
"::" "\n")
1056 (push nodename menu-items
)))))))
1057 ;; Now take each node of each of the other buffers
1058 ;; and merge it into the main buffer.
1059 (dolist (node nodes
)
1060 (let ((case-fold-search t
)
1061 (nodename (car node
)))
1062 (goto-char (point-min))
1063 ;; Find the like-named node in the main buffer.
1064 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1065 (regexp-quote nodename
)
1069 (search-forward "\n\^_" nil
'move
)
1072 ;; If none exists, add one.
1073 (goto-char (point-max))
1074 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1075 ;; Merge the text from the other buffer's menu
1076 ;; into the menu in the like-named node in the main buffer.
1077 (apply 'insert-buffer-substring
(cdr node
))))
1078 (Info-dir-remove-duplicates)
1079 ;; Kill all the buffers we just made, including the special one excised.
1080 (mapc 'kill-buffer
(cons buffer buffers
))
1081 (goto-char (point-min))
1083 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1084 (message "Composing main Info directory...done"))
1085 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
1086 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
1087 (setq default-directory Info-dir-contents-directory
))
1089 (defvar Info-streamline-headings
1090 '(("Emacs" .
"Emacs")
1091 ("Programming" .
"Programming")
1092 ("Libraries" .
"Libraries")
1093 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1094 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1096 (defun Info-dir-remove-duplicates ()
1098 (goto-char (point-min))
1099 ;; Remove duplicate headings in the same menu.
1100 (while (search-forward "\n* Menu:" nil t
)
1101 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1102 ;; Look for the next heading to unify.
1103 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1104 (let ((name (match-string 1))
1105 (start (match-beginning 0))
1107 ;; Check whether this heading should be streamlined.
1109 (dolist (x Info-streamline-headings
)
1110 (when (string-match (car x
) name
)
1112 (setq re
(car x
)))))
1113 (if re
(replace-match name t t nil
1))
1114 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1116 (or limit
(point-max))))
1117 ;; Look for other headings of the same category and merge them.
1119 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1120 (when (if re
(save-match-data (string-match re
(match-string 1)))
1121 (equal name
(match-string 1)))
1123 ;; Delete redundant heading.
1124 (delete-region (match-beginning 0) (point))
1125 ;; Push the entries onto `text'.
1127 (delete-and-extract-region
1129 (if (re-search-forward "^[^* \n\t]" nil t
)
1131 (or limit
(point-max)))) entries
))))
1132 ;; Insert the entries just found.
1133 (while (= (line-beginning-position 0) (1- (point)))
1135 (dolist (entry (nreverse entries
))
1137 (while (= (line-beginning-position 0) (1- (point)))
1138 (delete-region (1- (point)) (point))))
1140 ;; Now remove duplicate entries under the same heading.
1144 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1146 (let ((x (match-string 1)))
1147 (if (member-ignore-case x seen
)
1148 (delete-region (match-beginning 0)
1149 (progn (re-search-forward "^[^ \t]" nil t
)
1150 (match-beginning 0)))
1151 (push x seen
))))))))))
1153 ;; Note that on entry to this function the current-buffer must be the
1154 ;; *info* buffer; not the info tags buffer.
1155 (defun Info-read-subfile (nodepos)
1156 ;; NODEPOS is either a position (in the Info file as a whole,
1157 ;; not relative to a subfile) or the name of a subfile.
1160 (if (numberp nodepos
)
1162 (set-buffer (marker-buffer Info-tag-table-marker
))
1163 (goto-char (point-min))
1164 (or (looking-at "\^_")
1165 (search-forward "\n\^_"))
1168 (while (not (looking-at "\^_"))
1171 thisfilepos thisfilename
)
1172 (search-forward ": ")
1173 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1174 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1175 ;; read in version 19 stops at the end of number.
1176 ;; Advance to the next line.
1178 (if (> thisfilepos nodepos
)
1180 (setq lastfilename thisfilename
)
1181 (setq lastfilepos thisfilepos
))
1182 (forward-line 1)))))
1183 (setq lastfilename nodepos
)
1184 (setq lastfilepos
0))
1185 ;; Assume previous buffer is in Info-mode.
1186 ;; (set-buffer (get-buffer "*info*"))
1187 (or (equal Info-current-subfile lastfilename
)
1188 (let ((buffer-read-only nil
))
1189 (setq buffer-file-name nil
)
1192 (info-insert-file-contents lastfilename
)
1193 (set-buffer-modified-p nil
)
1194 (setq Info-current-subfile lastfilename
)))
1195 ;; Widen in case we are in the same subfile as before.
1197 (goto-char (point-min))
1198 (if (looking-at "\^_")
1200 (search-forward "\n\^_"))
1201 (if (numberp nodepos
)
1202 (+ (- nodepos lastfilepos
) (point)))))
1204 (defun Info-unescape-quotes (value)
1205 "Unescape double quotes and backslashes in VALUE."
1208 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1209 (setq unquote
(replace-match "" t t unquote
1))
1210 (setq start
(- (match-end 0) 1)))
1213 ;; As of Texinfo 4.6, makeinfo writes constructs like
1214 ;; \0\h[image param=value ...\h\0]
1215 ;; into the Info file for handling images.
1216 (defun Info-split-parameter-string (parameter-string)
1217 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1218 whitespace separated list of KEY=VALUE pairs. If VALUE contains
1219 whitespace or double quotes, it must be quoted in double quotes and
1220 any double quotes or backslashes must be escaped (\\\",\\\\)."
1223 (while (string-match
1224 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1225 parameter-string start
)
1226 (setq start
(match-end 0))
1227 (push (cons (match-string 1 parameter-string
)
1228 (or (match-string 2 parameter-string
)
1229 (Info-unescape-quotes
1230 (match-string 3 parameter-string
))))
1234 (defun Info-display-images-node ()
1235 "Display images in current node."
1237 (let ((inhibit-read-only t
)
1238 (case-fold-search t
))
1239 (goto-char (point-min))
1240 (while (re-search-forward
1241 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1243 (let* ((start (match-beginning 1))
1244 (parameter-alist (Info-split-parameter-string (match-string 2)))
1245 (src (cdr (assoc-string "src" parameter-alist
)))
1246 (image-file (if src
(if (file-name-absolute-p src
) src
1247 (concat default-directory src
))
1249 (image (if (file-exists-p image-file
)
1250 (create-image image-file
)
1252 (if (not (get-text-property start
'display
))
1253 (add-text-properties
1254 start
(point) `(display ,image rear-nonsticky
(display)))))))
1255 (set-buffer-modified-p nil
)))
1257 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1258 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1259 ;; including one optional trailing newline.
1260 (defun Info-hide-cookies-node ()
1261 "Hide unrecognised cookies in current node."
1263 (let ((inhibit-read-only t
)
1264 (case-fold-search t
))
1265 (goto-char (point-min))
1266 (while (re-search-forward
1267 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1269 (let* ((start (match-beginning 1)))
1270 (if (not (get-text-property start
'invisible
))
1271 (put-text-property start
(point) 'invisible t
)))))
1272 (set-buffer-modified-p nil
)))
1274 (defun Info-select-node ()
1275 "Select the info node that point is in."
1276 ;; Bind this in case the user sets it to nil.
1277 (let ((case-fold-search t
))
1279 ;; Find beginning of node.
1280 (if (search-backward "\n\^_" nil
'move
)
1282 (if (looking-at "\^_")
1284 (signal 'search-failed
(list "\n\^_"))))
1285 ;; Get nodename spelled as it is in the node.
1286 (re-search-forward "Node:[ \t]*")
1287 (setq Info-current-node
1288 (buffer-substring-no-properties (point)
1290 (skip-chars-forward "^,\t\n")
1292 (Info-set-mode-line)
1293 ;; Find the end of it, and narrow.
1295 (let (active-expression)
1296 ;; Narrow to the node contents
1297 (narrow-to-region (point)
1298 (if (re-search-forward "\n[\^_\f]" nil t
)
1301 (if (looking-at "[\n\^_\f]*execute: ")
1303 (goto-char (match-end 0))
1304 (setq active-expression
1305 (read (current-buffer))))))
1307 (if Info-enable-active-nodes
(eval active-expression
))
1308 ;; Add a new unique history item to full history list
1309 (let ((new-history (list Info-current-file Info-current-node
)))
1310 (setq Info-history-list
1311 (cons new-history
(delete new-history Info-history-list
)))
1312 (setq Info-history-forward nil
))
1313 (if (not (eq Info-fontify-maximum-menu-size nil
))
1314 (Info-fontify-node))
1315 (Info-display-images-node)
1316 (Info-hide-cookies-node)
1317 (run-hooks 'Info-selection-hook
)))))
1319 (defun Info-set-mode-line ()
1320 (setq mode-line-buffer-identification
1321 (nconc (propertized-buffer-identification "%b")
1324 (file-name-nondirectory
1325 (if (stringp Info-current-file
)
1327 (or buffer-file-name
"")))
1329 (or Info-current-node
""))))))
1331 ;; Go to an info node specified with a filename-and-nodename string
1332 ;; of the sort that is found in pointers in nodes.
1335 (defun Info-goto-node (nodename &optional fork
)
1336 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1337 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1338 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1340 Completion is available, but only for node names in the current Info file.
1341 If FORK is non-nil (interactively with a prefix arg), show the node in
1343 If FORK is a string, it is the name to use for the new buffer."
1344 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1348 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1350 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1352 (setq filename
(if (= (match-beginning 1) (match-end 1))
1354 (match-string 2 nodename
))
1355 nodename
(match-string 3 nodename
))
1356 (let ((trim (string-match "\\s +\\'" filename
)))
1357 (if trim
(setq filename
(substring filename
0 trim
))))
1358 (let ((trim (string-match "\\s +\\'" nodename
)))
1359 (if trim
(setq nodename
(substring nodename
0 trim
))))
1360 (if transient-mark-mode
(deactivate-mark))
1361 (Info-find-node (if (equal filename
"") nil filename
)
1362 (if (equal nodename
"") "Top" nodename
))))
1364 (defvar Info-read-node-completion-table
)
1366 ;; This function is used as the "completion table" while reading a node name.
1367 ;; It does completion using the alist in Info-read-node-completion-table
1368 ;; unless STRING starts with an open-paren.
1369 (defun Info-read-node-name-1 (string predicate code
)
1371 ;; First complete embedded file names.
1372 ((string-match "\\`([^)]*\\'" string
)
1373 (let ((file (substring string
1)))
1376 (let ((comp (try-completion file
'locate-file-completion
1377 (cons Info-directory-list
1378 (mapcar 'car Info-suffix-list
)))))
1380 ((eq comp t
) (concat string
")"))
1381 (comp (concat "(" comp
)))))
1382 ((eq code t
) (all-completions file
'locate-file-completion
1383 (cons Info-directory-list
1384 (mapcar 'car Info-suffix-list
))))
1386 ;; If a file name was given, then any node is fair game.
1387 ((string-match "\\`(" string
)
1389 ((eq code nil
) string
)
1392 ;; Otherwise use Info-read-node-completion-table.
1394 (try-completion string Info-read-node-completion-table predicate
))
1396 (all-completions string Info-read-node-completion-table predicate
))
1398 (test-completion string Info-read-node-completion-table predicate
))))
1400 (defun Info-read-node-name (prompt &optional default
)
1401 (let* ((completion-ignore-case t
)
1402 (Info-read-node-completion-table (Info-build-node-completions))
1403 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1404 (if (equal nodename
"")
1406 (Info-read-node-name prompt
))
1409 (defun Info-build-node-completions ()
1410 (or Info-current-file-completions
1412 ;; Bind this in case the user sets it to nil.
1413 (case-fold-search t
)
1414 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1417 (if (marker-buffer Info-tag-table-marker
)
1418 (let ((marker Info-tag-table-marker
))
1419 (set-buffer (marker-buffer marker
))
1422 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1424 (cons (list (match-string-no-properties 2))
1427 (goto-char (point-min))
1428 ;; If the buffer begins with a node header, process that first.
1429 (if (Info-node-at-bob-matching node-regexp
)
1430 (setq compl
(list (match-string-no-properties 1))))
1431 ;; Now for the rest of the nodes.
1432 (while (search-forward "\n\^_" nil t
)
1434 (let ((beg (point)))
1436 (if (re-search-backward node-regexp beg t
)
1438 (cons (list (match-string-no-properties 1))
1440 (setq compl
(cons '("*") compl
))
1441 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1443 (defun Info-restore-point (hl)
1444 "If this node has been visited, restore the point value when we left."
1446 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1447 ;; Use string-equal, not equal, to ignore text props.
1448 (string-equal (nth 1 (car hl
)) Info-current-node
))
1450 (goto-char (nth 2 (car hl
)))
1451 (setq hl nil
)) ;terminate the while at next iter
1452 (setq hl
(cdr hl
)))))
1454 (defvar Info-search-history nil
1455 "The history list for `Info-search'.")
1457 (defvar Info-search-case-fold nil
1458 "The value of `case-fold-search' from previous `Info-search' command.")
1460 (defun Info-search (regexp &optional bound noerror count direction
)
1461 "Search for REGEXP, starting from point, and select node it's found in.
1462 If DIRECTION is `backward', search in the reverse direction."
1463 (interactive (list (read-string
1464 (if Info-search-history
1465 (format "Regexp search%s (default `%s'): "
1466 (if case-fold-search
"" " case-sensitively")
1467 (car Info-search-history
))
1468 (format "Regexp search%s: "
1469 (if case-fold-search
"" " case-sensitively")))
1470 nil
'Info-search-history
)))
1471 (when transient-mark-mode
1473 (when (equal regexp
"")
1474 (setq regexp
(car Info-search-history
)))
1476 (let (found beg-found give-up
1477 (backward (eq direction
'backward
))
1478 (onode Info-current-node
)
1479 (ofile Info-current-file
)
1481 (opoint-min (point-min))
1482 (opoint-max (point-max))
1483 (ostart (window-start))
1484 (osubfile Info-current-subfile
))
1485 (setq Info-search-case-fold case-fold-search
)
1490 ;; Hide Info file header for backward search
1491 (narrow-to-region (save-excursion
1492 (goto-char (point-min))
1493 (search-forward "\n\^_")
1496 (while (and (not give-up
)
1500 (isearch-range-invisible found beg-found
)
1501 (isearch-range-invisible beg-found found
))
1502 ;; Skip node header line
1503 (and (save-excursion (forward-line -
1)
1506 ;; Skip Tag Table node
1508 (and (search-backward "\^_" nil t
)
1509 (looking-at "\^_\nTag Table"))))))
1510 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1512 (re-search-backward regexp bound t
)
1513 (re-search-forward regexp bound t
))
1514 (setq found
(point) beg-found
(if backward
(match-end 0)
1515 (match-beginning 0)))
1516 (setq give-up t
))))))
1517 ;; If no subfiles, give error now.
1519 (if (null Info-current-subfile
)
1520 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1522 (re-search-backward regexp
)
1523 (re-search-forward regexp
)))
1526 (unless (or found bound
)
1528 ;; Try other subfiles.
1531 (set-buffer (marker-buffer Info-tag-table-marker
))
1532 (goto-char (point-min))
1533 (search-forward "\n\^_\nIndirect:")
1535 (narrow-to-region (point)
1536 (progn (search-forward "\n\^_")
1538 (goto-char (point-min))
1539 ;; Find the subfile we just searched.
1540 (search-forward (concat "\n" osubfile
": "))
1542 (forward-line (if backward
0 1))
1543 ;; Make a list of all following subfiles.
1544 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1545 (while (not (if backward
(bobp) (eobp)))
1547 (re-search-backward "\\(^.*\\): [0-9]+$")
1548 (re-search-forward "\\(^.*\\): [0-9]+$"))
1549 (goto-char (+ (match-end 1) 2))
1550 (setq list
(cons (cons (+ (point-min)
1551 (read (current-buffer)))
1552 (match-string-no-properties 1))
1554 (goto-char (if backward
1555 (1- (match-beginning 0))
1556 (1+ (match-end 0)))))
1557 ;; Put in forward order
1558 (setq list
(nreverse list
))))
1560 (message "Searching subfile %s..." (cdr (car list
)))
1561 (Info-read-subfile (car (car list
)))
1563 ;; Hide Info file header for backward search
1564 (narrow-to-region (save-excursion
1565 (goto-char (point-min))
1566 (search-forward "\n\^_")
1569 (goto-char (point-max)))
1570 (setq list
(cdr list
))
1571 (setq give-up nil found nil
)
1572 (while (and (not give-up
)
1576 (isearch-range-invisible found beg-found
)
1577 (isearch-range-invisible beg-found found
))
1578 ;; Skip node header line
1579 (and (save-excursion (forward-line -
1)
1582 ;; Skip Tag Table node
1584 (and (search-backward "\^_" nil t
)
1585 (looking-at "\^_\nTag Table"))))))
1586 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1588 (re-search-backward regexp nil t
)
1589 (re-search-forward regexp nil t
))
1590 (setq found
(point) beg-found
(if backward
(match-end 0)
1591 (match-beginning 0)))
1599 (signal 'search-failed
(list regexp
))))
1601 (progn (Info-read-subfile osubfile
)
1604 (set-window-start (selected-window) ostart
)))))
1606 (if (and (string= osubfile Info-current-subfile
)
1607 (> found opoint-min
)
1608 (< found opoint-max
))
1609 ;; Search landed in the same node
1613 (save-match-data (Info-select-node)))
1615 ;; Use string-equal, not equal, to ignore text props.
1616 (or (and (string-equal onode Info-current-node
)
1617 (equal ofile Info-current-file
))
1618 (and isearch-mode isearch-wrapped
(eq opoint opoint-min
))
1619 (setq Info-history
(cons (list ofile onode opoint
)
1622 (defun Info-search-case-sensitively ()
1623 "Search for a regexp case-sensitively."
1625 (let ((case-fold-search nil
))
1626 (call-interactively 'Info-search
)))
1628 (defun Info-search-next ()
1629 "Search for next regexp from a previous `Info-search' command."
1631 (let ((case-fold-search Info-search-case-fold
))
1632 (if Info-search-history
1633 (Info-search (car Info-search-history
))
1634 (call-interactively 'Info-search
))))
1636 (defun Info-search-backward (regexp &optional bound noerror count
)
1637 "Search for REGEXP in the reverse direction."
1638 (interactive (list (read-string
1639 (if Info-search-history
1640 (format "Regexp search%s backward (default `%s'): "
1641 (if case-fold-search
"" " case-sensitively")
1642 (car Info-search-history
))
1643 (format "Regexp search%s backward: "
1644 (if case-fold-search
"" " case-sensitively")))
1645 nil
'Info-search-history
)))
1646 (Info-search regexp bound noerror count
'backward
))
1648 (defun Info-isearch-search ()
1649 (if (and Info-isearch-search
(not isearch-word
))
1650 (lambda (string &optional bound noerror count
)
1653 (Info-search (if isearch-regexp string
(regexp-quote string
))
1655 (unless isearch-forward
'backward
))
1658 (let ((isearch-search-fun-function nil
))
1659 (isearch-search-fun))))
1661 (defun Info-isearch-wrap ()
1662 (when (and Info-isearch-search
(not isearch-word
))
1663 (if isearch-forward
(Info-top-node) (Info-final-node))
1664 (goto-char (if isearch-forward
(point-min) (point-max)))))
1666 (defun Info-isearch-push-state ()
1668 (Info-isearch-pop-state cmd
,Info-current-file
,Info-current-node
)))
1670 (defun Info-isearch-pop-state (cmd file node
)
1671 (or (and (string= Info-current-file file
)
1672 (string= Info-current-node node
))
1673 (progn (Info-find-node file node
) (sit-for 0))))
1676 (defun Info-extract-pointer (name &optional errorname
)
1677 "Extract the value of the node-pointer named NAME.
1678 If there is none, use ERRORNAME in the error message;
1679 if ERRORNAME is nil, just return nil."
1680 ;; Bind this in case the user sets it to nil.
1681 (let ((case-fold-search t
))
1683 (goto-char (point-min))
1684 (let ((bound (point)))
1686 (cond ((re-search-backward
1687 (concat name
":" (Info-following-node-name-re)) bound t
)
1689 ((not (eq errorname t
))
1690 (error "Node has no %s"
1691 (capitalize (or errorname name
)))))))))
1693 (defun Info-following-node-name-re (&optional allowedchars
)
1694 "Return a regexp matching a node name.
1695 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1696 saying which chars may appear in the node name.
1697 Submatch 1 is the complete node name.
1698 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1699 Submatch 3 is the local part of the node name.
1700 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1701 (concat "[ \t]*" ;Skip leading space.
1702 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1703 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
1704 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
1705 "\\|\\)\\)")) ;Allow empty node names.
1707 ;;; For compatibility; other files have used this name.
1708 (defun Info-following-node-name ()
1709 (and (looking-at (Info-following-node-name-re))
1713 "Go to the next node of this node."
1715 (Info-goto-node (Info-extract-pointer "next")))
1718 "Go to the previous node of this node."
1720 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1722 (defun Info-up (&optional same-file
)
1723 "Go to the superior node of this node.
1724 If SAME-FILE is non-nil, do not move to a different Info file."
1726 (let ((old-node Info-current-node
)
1727 (old-file Info-current-file
)
1728 (node (Info-extract-pointer "up")) p
)
1729 (and (or same-file
(not (stringp Info-current-file
)))
1730 (string-match "^(" node
)
1731 (error "Up node is in another Info file"))
1732 (Info-goto-node node
)
1734 (goto-char (point-min))
1735 (if (and (search-forward "\n* Menu:" nil t
)
1737 (if (string-equal old-node
"Top")
1738 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
1739 (concat "\n\\* +\\(" (regexp-quote old-node
)
1740 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
1744 (Info-restore-point Info-history
))))
1746 (defun Info-history-back ()
1747 "Go back in the history to the last node visited."
1750 (error "This is the first Info node you looked at"))
1751 (let ((history-forward
1752 (cons (list Info-current-file Info-current-node
(point))
1753 Info-history-forward
))
1754 filename nodename opoint
)
1755 (setq filename
(car (car Info-history
)))
1756 (setq nodename
(car (cdr (car Info-history
))))
1757 (setq opoint
(car (cdr (cdr (car Info-history
)))))
1758 (setq Info-history
(cdr Info-history
))
1759 (Info-find-node filename nodename
)
1760 (setq Info-history
(cdr Info-history
))
1761 (setq Info-history-forward history-forward
)
1762 (goto-char opoint
)))
1764 (defalias 'Info-last
'Info-history-back
)
1766 (defun Info-history-forward ()
1767 "Go forward in the history of visited nodes."
1769 (or Info-history-forward
1770 (error "This is the last Info node you looked at"))
1771 (let ((history-forward (cdr Info-history-forward
))
1772 filename nodename opoint
)
1773 (setq filename
(car (car Info-history-forward
)))
1774 (setq nodename
(car (cdr (car Info-history-forward
))))
1775 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
1776 (Info-find-node filename nodename
)
1777 (setq Info-history-forward history-forward
)
1778 (goto-char opoint
)))
1781 (defun Info-directory ()
1782 "Go to the Info directory node."
1784 (Info-find-node "dir" "top"))
1786 (defun Info-history ()
1787 "Go to a node with a menu of visited nodes."
1789 (let ((curr-file Info-current-file
)
1790 (curr-node Info-current-node
)
1792 (with-current-buffer (get-buffer-create " *info-history*")
1793 (let ((inhibit-read-only t
))
1795 (goto-char (point-min))
1796 (insert "\n\^_\nFile: history, Node: Top, Up: (dir)\n\n")
1797 (insert "Recently Visited Nodes\n**********************\n\n")
1798 (insert "* Menu:\n\n")
1799 (let ((hl (delete '("history" "Top") Info-history-list
)))
1801 (let ((file (nth 0 (car hl
)))
1802 (node (nth 1 (car hl
))))
1803 (if (and (string-equal file curr-file
)
1804 (string-equal node curr-node
))
1806 (insert "* " node
": (" (file-name-nondirectory file
)
1808 (setq hl
(cdr hl
))))))
1809 (Info-find-node "history" "Top")
1810 (goto-char (or p
(point-min)))))
1813 "Go to a node with table of contents of the current Info file.
1814 Table of contents is created from the tree structure of menus."
1816 (let ((curr-file (substring-no-properties Info-current-file
))
1817 (curr-node (substring-no-properties Info-current-node
))
1819 (with-current-buffer (get-buffer-create " *info-toc*")
1820 (let ((inhibit-read-only t
)
1821 (node-list (Info-build-toc curr-file
)))
1823 (goto-char (point-min))
1824 (insert "\n\^_\nFile: toc, Node: Top, Up: (dir)\n\n")
1825 (insert "Table of Contents\n*****************\n\n")
1826 (insert "*Note Top: (" curr-file
")Top.\n")
1828 (nth 2 (assoc "Top" node-list
)) ; get Top nodes
1829 node-list
0 curr-file
))
1831 (let ((Info-hide-note-references 'hide
)
1832 (Info-fontify-visited-nodes nil
))
1834 (setq Info-current-file
"toc" Info-current-node
"Top")
1835 (goto-char (point-min))
1836 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
1841 (goto-char (point-min))
1842 (if (setq p
(search-forward (concat "*Note " curr-node
":") nil t
))
1843 (setq p
(- p
(length curr-node
) 2))))
1844 (Info-find-node "toc" "Top")
1845 (goto-char (or p
(point-min)))))
1847 (defun Info-insert-toc (nodes node-list level curr-file
)
1848 "Insert table of contents with references to nodes."
1849 (let ((section "Top"))
1851 (let ((node (assoc (car nodes
) node-list
)))
1852 (unless (member (nth 1 node
) (list nil section
))
1853 (insert (setq section
(nth 1 node
)) "\n"))
1854 (insert (make-string level ?
\t))
1855 (insert "*Note " (car nodes
) ": (" curr-file
")" (car nodes
) ".\n")
1856 (Info-insert-toc (nth 2 node
) node-list
(1+ level
) curr-file
)
1857 (setq nodes
(cdr nodes
))))))
1859 (defun Info-build-toc (file)
1860 "Build table of contents from menus of Info FILE and its subfiles."
1862 (let* ((file (and (stringp file
) (Info-find-file file
)))
1863 (default-directory (or (and (stringp file
)
1864 (file-name-directory file
))
1866 (main-file (and (stringp file
) file
))
1867 (sections '(("Top" "Top")))
1869 (while (or main-file subfiles
)
1870 (or main-file
(message "Searching subfile %s..." (car subfiles
)))
1872 (info-insert-file-contents (or main-file
(car subfiles
)))
1873 (goto-char (point-min))
1874 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
1875 (search-forward "Node: " nil
'move
))
1876 (let ((nodename (substring-no-properties (Info-following-node-name)))
1877 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
1881 (when (and (not (Info-index-node nodename file
))
1882 (re-search-forward "^\\* Menu:" bound t
))
1885 (setq bound
(or (and (equal nodename
"Top")
1888 "^[ \t-]*The Detailed Node Listing" nil t
)))
1890 (while (< (point) bound
)
1893 ((looking-at "^\\* +[^:]+:")
1896 (let ((menu-node-name (substring-no-properties
1897 (Info-extract-menu-node-name))))
1898 (setq menu-items
(cons menu-node-name menu-items
))
1899 (if (equal nodename
"Top")
1901 (cons (list menu-node-name section
) sections
)))))
1902 ;; Other non-empty strings in the Top node are section names
1903 ((and (equal nodename
"Top")
1904 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
1905 (setq section
(match-string-no-properties 1))))
1907 (beginning-of-line)))
1908 (setq nodes
(cons (list nodename
1909 (cadr (assoc nodename sections
))
1910 (nreverse menu-items
))
1915 (goto-char (point-min))
1916 (if (search-forward "\n\^_\nIndirect:" nil t
)
1917 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
1918 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
1919 (setq subfiles
(cons (match-string-no-properties 1)
1921 (setq subfiles
(nreverse subfiles
)
1923 (setq subfiles
(cdr subfiles
))))
1927 (defun Info-follow-reference (footnotename &optional fork
)
1928 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1929 FOOTNOTENAME may be an abbreviation of the reference name.
1930 If FORK is non-nil (interactively with a prefix arg), show the node in
1931 a new info buffer. If FORK is a string, it is the name to use for the
1934 (let ((completion-ignore-case t
)
1935 (case-fold-search t
)
1936 completions default alt-default
(start-point (point)) str i bol eol
)
1938 ;; Store end and beginning of line.
1944 (goto-char (point-min))
1945 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
1946 (setq str
(match-string-no-properties 1))
1947 ;; See if this one should be the default.
1949 (<= (match-beginning 0) start-point
)
1950 (<= start-point
(point))
1952 ;; See if this one should be the alternate default.
1953 (and (null alt-default
)
1954 (and (<= bol
(match-beginning 0))
1956 (setq alt-default t
))
1958 (while (setq i
(string-match "[ \n\t]+" str i
))
1959 (setq str
(concat (substring str
0 i
) " "
1960 (substring str
(match-end 0))))
1962 ;; Record as a completion and perhaps as default.
1963 (if (eq default t
) (setq default str
))
1964 (if (eq alt-default t
) (setq alt-default str
))
1965 ;; Don't add this string if it's a duplicate.
1966 (or (assoc-string str completions t
)
1967 (push str completions
))))
1968 ;; If no good default was found, try an alternate.
1970 (setq default alt-default
))
1971 ;; If only one cross-reference found, then make it default.
1972 (if (eq (length completions
) 1)
1973 (setq default
(car completions
)))
1975 (let ((input (completing-read (if default
1977 "Follow reference named: (default "
1979 "Follow reference named: ")
1980 completions nil t
)))
1981 (list (if (equal input
"")
1982 default input
) current-prefix-arg
))
1983 (error "No cross-references in this node"))))
1985 (unless footnotename
1986 (error "No reference was specified"))
1988 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
1989 (case-fold-search t
))
1990 (while (setq i
(string-match " " str i
))
1991 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
1994 ;; Move point to the beginning of reference if point is on reference
1995 (or (looking-at "\\*note[ \n\t]+")
1996 (and (looking-back "\\*note[ \n\t]+")
1997 (goto-char (match-beginning 0)))
1998 (if (and (save-excursion
1999 (goto-char (+ (point) 5)) ; skip a possible *note
2000 (re-search-backward "\\*note[ \n\t]+" nil t
)
2002 (<= (point) (match-end 0)))
2003 (goto-char (match-beginning 0))))
2004 ;; Go to the reference closest to point
2005 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2006 (+ (match-beginning 0) 5))))
2007 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2008 (+ (match-beginning 0) 5)))))
2009 (goto-char (cond ((and next-ref prev-ref
)
2010 (if (< (abs (- next-ref
(point)))
2011 (abs (- prev-ref
(point))))
2013 ((or next-ref prev-ref
))
2014 ((error "No cross-reference named %s" footnotename
))))
2015 (setq target
(Info-extract-menu-node-name t
))))
2016 (while (setq i
(string-match "[ \t\n]+" target i
))
2017 (setq target
(concat (substring target
0 i
) " "
2018 (substring target
(match-end 0))))
2020 (Info-goto-node target fork
)))
2022 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2023 ;; We allow newline because this is also used in Info-follow-reference,
2024 ;; where the xref name might be wrapped over two lines.
2025 "Regexp that matches a menu entry name upto but not including the colon.
2026 Because of ambiguities, this should be concatenated with something like
2027 `:' and `Info-following-node-name-re'.")
2029 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2030 (skip-chars-forward " \t\n")
2031 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2032 (Info-following-node-name-re
2034 (index-node "^,\t\n")
2035 (multi-line "^.,\t")
2039 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2042 (setq Info-point-loc
2043 (if (match-beginning 5)
2044 (string-to-number (match-string 5))
2045 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))
2046 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2047 ;;; (setq Info-point-loc
2048 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2050 (replace-regexp-in-string
2052 (or (match-string 2)
2053 ;; If the node name is the menu entry name (using `entry::').
2054 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))))
2056 ;; No one calls this.
2057 ;;(defun Info-menu-item-sequence (list)
2059 ;; (Info-menu (car list))
2060 ;; (setq list (cdr list))))
2062 (defvar Info-complete-menu-buffer
)
2063 (defvar Info-complete-next-re nil
)
2064 (defvar Info-complete-nodes nil
)
2065 (defvar Info-complete-cache nil
)
2067 (defconst Info-node-spec-re
2068 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2069 "Regexp to match the text after a : until the terminating `.'.")
2071 (defun Info-complete-menu-item (string predicate action
)
2072 ;; This uses two dynamically bound variables:
2073 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2074 ;; is the menu of items we're trying to complete.
2075 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2076 ;; also look for menu items in subsequent nodes as long as those
2077 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2079 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2080 ;; also look for menu items in these nodes. This feature is currently
2081 ;; only used for completion in Info-index.
2083 ;; Note that `Info-complete-menu-buffer' could be current already,
2084 ;; so we want to save point.
2086 (set-buffer Info-complete-menu-buffer
)
2087 (let ((completion-ignore-case t
)
2088 (case-fold-search t
)
2089 (orignode Info-current-node
)
2091 (goto-char (point-min))
2092 (search-forward "\n* Menu:")
2093 (if (not (memq action
'(nil t
)))
2095 (concat "\n\\* +" (regexp-quote string
) ":") nil t
)
2096 (let ((pattern (concat "\n\\* +\\("
2097 (regexp-quote string
)
2098 Info-menu-entry-name-re
"\\):" Info-node-spec-re
))
2101 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2102 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2103 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2104 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2105 (let ((prev (nth 3 Info-complete-cache
)))
2106 (eq t
(compare-strings string
0 (length prev
)
2108 ;; We can reuse the previous list.
2109 (setq completions
(nth 4 Info-complete-cache
))
2110 ;; The cache can't be used.
2113 (while (re-search-forward pattern nil t
)
2114 (push (match-string-no-properties 1)
2116 ;; Check subsequent nodes if applicable.
2117 (or (and Info-complete-next-re
2118 (setq nextnode
(Info-extract-pointer "next" t
))
2119 (string-match Info-complete-next-re nextnode
))
2120 (and Info-complete-nodes
2121 (setq Info-complete-nodes
(cdr Info-complete-nodes
)
2122 nextnode
(car Info-complete-nodes
)))))
2123 (Info-goto-node nextnode
))
2124 ;; Go back to the start node (for the next completion).
2125 (unless (equal Info-current-node orignode
)
2126 (Info-goto-node orignode
))
2127 ;; Update the cache.
2128 (set (make-local-variable 'Info-complete-cache
)
2129 (list Info-current-file Info-current-node
2130 Info-complete-next-re string completions
2131 Info-complete-nodes
)))
2133 (all-completions string completions predicate
)
2134 (try-completion string completions predicate
)))))))
2137 (defun Info-menu (menu-item &optional fork
)
2138 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2139 The menu item should one of those listed in the current node's menu.
2140 Completion is allowed, and the default menu item is the one point is on.
2141 If FORK is non-nil (interactively with a prefix arg), show the node in
2142 a new info buffer. If FORK is a string, it is the name to use for the
2145 (let ((completions '())
2146 ;; If point is within a menu item, use that item as the default
2151 (case-fold-search t
))
2153 (goto-char (point-min))
2154 (if (not (search-forward "\n* menu:" nil t
))
2155 (error "No menu in this node"))
2161 (if (re-search-backward (concat "\n\\* +\\("
2162 Info-menu-entry-name-re
2164 (setq default
(match-string-no-properties 1))))))
2167 (setq item
(let ((completion-ignore-case t
)
2168 (Info-complete-menu-buffer (current-buffer)))
2169 (completing-read (if default
2170 (format "Menu item (default %s): "
2173 'Info-complete-menu-item nil t
)))
2174 ;; we rely on the fact that completing-read accepts an input
2175 ;; of "" even when the require-match argument is true and ""
2176 ;; is not a valid possibility
2177 (if (string= item
"")
2182 (list item current-prefix-arg
))))
2183 ;; there is a problem here in that if several menu items have the same
2184 ;; name you can only go to the node of the first with this command.
2185 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
2187 (defun Info-extract-menu-item (menu-item)
2188 (setq menu-item
(regexp-quote menu-item
))
2189 (let ((case-fold-search t
))
2191 (let ((case-fold-search t
))
2192 (goto-char (point-min))
2193 (or (search-forward "\n* menu:" nil t
)
2194 (error "No menu in this node"))
2195 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2196 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2197 (error "No such item in menu"))
2200 (Info-extract-menu-node-name nil
(Info-index-node))))))
2202 ;; If COUNT is nil, use the last item in the menu.
2203 (defun Info-extract-menu-counting (count)
2204 (let ((case-fold-search t
))
2206 (let ((case-fold-search t
))
2207 (goto-char (point-min))
2208 (or (search-forward "\n* menu:" nil t
)
2209 (error "No menu in this node"))
2211 (or (search-forward "\n* " nil t count
)
2212 (error "Too few items in menu"))
2213 (while (search-forward "\n* " nil t
)
2215 (Info-extract-menu-node-name nil
(Info-index-node))))))
2217 (defun Info-nth-menu-item ()
2218 "Go to the node of the Nth menu item.
2219 N is the digit argument used to invoke this command."
2222 (Info-extract-menu-counting
2223 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2225 (defun Info-top-node ()
2226 "Go to the Top node of this file."
2228 (Info-goto-node "Top"))
2230 (defun Info-final-node ()
2231 "Go to the final node in this file."
2233 (Info-goto-node "Top")
2234 (let ((Info-history nil
)
2235 (case-fold-search t
))
2236 ;; Go to the last node in the menu of Top.
2237 (Info-goto-node (Info-extract-menu-counting nil
))
2238 ;; If the last node in the menu is not last in pointer structure,
2239 ;; move forward until we can't go any farther.
2240 (while (Info-forward-node t t
) nil
)
2241 ;; Then keep moving down to last subnode, unless we reach an index.
2242 (while (and (not (Info-index-node))
2243 (save-excursion (search-forward "\n* Menu:" nil t
)))
2244 (Info-goto-node (Info-extract-menu-counting nil
)))))
2246 (defun Info-forward-node (&optional not-down no-error
)
2247 "Go forward one node, considering all nodes as forming one sequence."
2249 (goto-char (point-min))
2251 (let ((case-fold-search t
))
2252 ;; three possibilities, in order of priority:
2253 ;; 1. next node is in a menu in this node (but not in an index)
2254 ;; 2. next node is next at same level
2255 ;; 3. next node is up and next
2256 (cond ((and (not not-down
)
2257 (save-excursion (search-forward "\n* menu:" nil t
))
2258 (not (Info-index-node)))
2259 (Info-goto-node (Info-extract-menu-counting 1))
2261 ((save-excursion (search-backward "next:" nil t
))
2264 ((and (save-excursion (search-backward "up:" nil t
))
2265 ;; Use string-equal, not equal, to ignore text props.
2266 (not (string-equal (downcase (Info-extract-pointer "up"))
2268 (let ((old-node Info-current-node
))
2270 (let (Info-history success
)
2272 (setq success
(Info-forward-node t no-error
))
2273 (or success
(Info-goto-node old-node
))))))
2275 (t (error "No pointer forward from this node")))))
2277 (defun Info-backward-node ()
2278 "Go backward one node, considering all nodes as forming one sequence."
2280 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2281 (upnode (Info-extract-pointer "up" t
))
2282 (case-fold-search t
))
2283 (cond ((and upnode
(string-match "(" upnode
))
2284 (error "First node in file"))
2285 ((and upnode
(or (null prevnode
)
2286 ;; Use string-equal, not equal,
2287 ;; to ignore text properties.
2288 (string-equal (downcase prevnode
)
2289 (downcase upnode
))))
2292 ;; If we move back at the same level,
2293 ;; go down to find the last subnode*.
2296 (while (and (not (Info-index-node))
2297 (save-excursion (search-forward "\n* Menu:" nil t
)))
2298 (Info-goto-node (Info-extract-menu-counting nil
)))))
2300 (error "No pointer backward from this node")))))
2303 "Exit Info by selecting some other buffer."
2306 (save-buffers-kill-emacs)
2309 (defun Info-next-menu-item ()
2310 "Go to the node of the next menu item."
2312 ;; Bind this in case the user sets it to nil.
2313 (let* ((case-fold-search t
)
2317 (search-forward "\n* menu:" nil t
)
2318 (and (search-forward "\n* " nil t
)
2319 (Info-extract-menu-node-name)))))
2320 (if node
(Info-goto-node node
)
2321 (error "No more items in menu"))))
2323 (defun Info-last-menu-item ()
2324 "Go to the node of the previous menu item."
2328 ;; Bind this in case the user sets it to nil.
2329 (let* ((case-fold-search t
)
2330 (beg (save-excursion
2331 (and (search-backward "\n* menu:" nil t
)
2333 (or (and beg
(search-backward "\n* " beg t
))
2334 (error "No previous items in menu")))
2335 (Info-goto-node (save-excursion
2336 (goto-char (match-end 0))
2337 (Info-extract-menu-node-name)))))
2339 (defmacro Info-no-error
(&rest body
)
2340 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
2342 (defun Info-next-preorder ()
2343 "Go to the next subnode or the next node, or go up a level."
2345 (cond ((Info-no-error (Info-next-menu-item)))
2346 ((Info-no-error (Info-next)))
2347 ((Info-no-error (Info-up t
))
2348 ;; Since we have already gone thru all the items in this menu,
2349 ;; go up to the end of this node.
2350 (goto-char (point-max))
2351 ;; Since logically we are done with the node with that menu,
2353 (Info-next-preorder))
2355 (error "No more nodes"))))
2357 (defun Info-last-preorder ()
2358 "Go to the last node, popping up a level if there is none."
2360 (cond ((Info-no-error
2361 (Info-last-menu-item)
2362 ;; If we go down a menu item, go to the end of the node
2363 ;; so we can scroll back through it.
2364 (goto-char (point-max)))
2365 ;; Keep going down, as long as there are nested menu nodes.
2366 (while (Info-no-error
2367 (Info-last-menu-item)
2368 ;; If we go down a menu item, go to the end of the node
2369 ;; so we can scroll back through it.
2370 (goto-char (point-max))))
2372 ((and (Info-no-error (Info-extract-pointer "prev"))
2373 (not (equal (Info-extract-pointer "up")
2374 (Info-extract-pointer "prev"))))
2375 (Info-no-error (Info-prev))
2376 (goto-char (point-max))
2377 (while (Info-no-error
2378 (Info-last-menu-item)
2379 ;; If we go down a menu item, go to the end of the node
2380 ;; so we can scroll back through it.
2381 (goto-char (point-max))))
2383 ((Info-no-error (Info-up t
))
2384 (goto-char (point-min))
2385 (let ((case-fold-search t
))
2386 (or (search-forward "\n* Menu:" nil t
)
2387 (goto-char (point-max)))))
2388 (t (error "No previous nodes"))))
2390 (defun Info-scroll-up ()
2391 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2392 Once you scroll far enough in a node that its menu appears on the screen
2393 but after point, the next scroll moves into its first subnode, unless
2394 `Info-scroll-prefer-subnodes' is nil.
2396 When you scroll past the end of a node, that goes to the next node if
2397 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2398 if this node has no successor, it moves to the parent node's successor,
2399 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2400 the menu of a node, it moves to subnode indicated by the following menu
2401 item. (That case won't normally result from this command, but can happen
2405 (if (or (< (window-start) (point-min))
2406 (> (window-start) (point-max)))
2407 (set-window-start (selected-window) (point)))
2408 (let* ((case-fold-search t
)
2409 (virtual-end (save-excursion
2410 (goto-char (point-min))
2411 (if (and Info-scroll-prefer-subnodes
2412 (search-forward "\n* Menu:" nil t
))
2415 (if (or (< virtual-end
(window-start))
2416 (pos-visible-in-window-p virtual-end
))
2418 (Info-scroll-prefer-subnodes (Info-next-preorder))
2419 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2420 (t (Info-next-preorder)))
2423 (defun Info-scroll-down ()
2424 "Scroll one screenful back in Info, considering all nodes as one sequence.
2425 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2426 is non-nil, this goes to its last subnode. When you scroll past the
2427 beginning of a node, that goes to the previous node or back up to the
2430 (if (or (< (window-start) (point-min))
2431 (> (window-start) (point-max)))
2432 (set-window-start (selected-window) (point)))
2433 (let* ((case-fold-search t
)
2434 (current-point (point))
2436 (and Info-scroll-prefer-subnodes
2439 (setq current-point
(point))
2440 (goto-char (point-min))
2441 (search-forward "\n* Menu:"
2445 (pos-visible-in-window-p (point-min) nil t
))
2446 (Info-last-preorder)
2449 (defun Info-next-reference (&optional recur
)
2450 "Move cursor to the next cross-reference or menu item in the node."
2452 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2454 (case-fold-search t
))
2455 (or (eobp) (forward-char 1))
2456 (or (re-search-forward pat nil t
)
2458 (goto-char (point-min))
2459 (or (re-search-forward pat nil t
)
2462 (error "No cross references in this node")))))
2463 (goto-char (or (match-beginning 1) (match-beginning 0)))
2464 (if (looking-at "\\* Menu:")
2466 (error "No cross references in this node")
2467 (Info-next-reference t
)))))
2469 (defun Info-prev-reference (&optional recur
)
2470 "Move cursor to the previous cross-reference or menu item in the node."
2472 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2474 (case-fold-search t
))
2475 (or (re-search-backward pat nil t
)
2477 (goto-char (point-max))
2478 (or (re-search-backward pat nil t
)
2481 (error "No cross references in this node")))))
2482 (goto-char (or (match-beginning 1) (match-beginning 0)))
2483 (if (looking-at "\\* Menu:")
2485 (error "No cross references in this node")
2486 (Info-prev-reference t
)))))
2488 (defvar Info-index-nodes nil
2489 "Alist of cached index node names of visited Info files.
2490 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2492 (defun Info-index-nodes (&optional file
)
2493 "Return a list of names of all index nodes in Info FILE.
2494 If FILE is omitted, it defaults to the current Info file.
2495 First look in a list of cached index node names. Then scan Info
2496 file and its subfiles for nodes with the index cookie. Then try
2497 to find index nodes starting from the first node in the top level
2498 menu whose name contains the word \"Index\", plus any immediately
2499 following nodes whose names also contain the word \"Index\"."
2500 (or file
(setq file Info-current-file
))
2501 (or (assoc file Info-index-nodes
)
2502 ;; Skip virtual Info files
2503 (and (member file
'("dir" "history" "toc" "apropos"))
2504 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2505 (not (stringp file
))
2506 ;; Find nodes with index cookie
2507 (let* ((default-directory (or (and (stringp file
)
2508 (file-name-directory
2509 (setq file
(Info-find-file file
))))
2511 Info-history Info-history-list Info-fontify-maximum-menu-size
2512 (main-file file
) subfiles nodes node
)
2515 (while (or main-file subfiles
)
2517 (info-insert-file-contents (or main-file
(car subfiles
)))
2518 (goto-char (point-min))
2519 (while (search-forward "\0\b[index\0\b]" nil
'move
)
2521 (re-search-backward "^\^_")
2522 (search-forward "Node: ")
2523 (setq nodes
(cons (Info-following-node-name) nodes
))))
2526 (goto-char (point-min))
2527 (if (search-forward "\n\^_\nIndirect:" nil t
)
2528 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2529 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2530 (setq subfiles
(cons (match-string-no-properties 1)
2532 (setq subfiles
(nreverse subfiles
)
2534 (setq subfiles
(cdr subfiles
)))))
2537 (setq nodes
(nreverse nodes
)
2538 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2540 ;; Find nodes with the word "Index" in the node name
2541 (let ((case-fold-search t
)
2542 Info-history Info-history-list Info-fontify-maximum-menu-size
2547 (Info-find-node file
"Top")
2548 (when (and (search-forward "\n* menu:" nil t
)
2549 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
2550 (goto-char (match-beginning 1))
2551 (setq nodes
(list (Info-extract-menu-node-name)))
2552 (Info-goto-node (car nodes
))
2553 (while (and (setq node
(Info-extract-pointer "next" t
))
2554 (string-match "\\<Index\\>" node
))
2555 (setq nodes
(cons node nodes
))
2556 (Info-goto-node node
))))
2559 (setq nodes
(nreverse nodes
)
2560 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2562 ;; If file has no index nodes, still add it to the cache
2563 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2564 (cdr (assoc file Info-index-nodes
)))
2566 (defun Info-index-node (&optional node file
)
2567 "Return non-nil value if NODE is an index node.
2568 If NODE is nil, check the current Info node.
2569 If FILE is nil, check the current Info file."
2570 (if (or (and node
(not (equal node Info-current-node
)))
2571 (assoc (or file Info-current-file
) Info-index-nodes
))
2572 (member (or node Info-current-node
) (Info-index-nodes file
))
2573 ;; Don't search all index nodes if request is only for the current node
2574 ;; and file is not in the cache of index nodes
2577 (string-match "\\<Index\\>" (or node Info-current-node
"")))
2579 (goto-char (+ (or (save-excursion
2580 (search-backward "\n\^_" nil t
))
2582 (search-forward "\0\b[index\0\b]"
2584 (search-forward "\n\^_" nil t
))
2587 (defun Info-goto-index ()
2588 "Go to the first index node."
2589 (let ((node (car (Info-index-nodes))))
2590 (or node
(error "No index"))
2591 (Info-goto-node node
)))
2594 (defun Info-index (topic)
2595 "Look up a string TOPIC in the index for this file.
2596 If there are no exact matches to the specified topic, this chooses
2597 the first match which is a case-insensitive substring of a topic.
2598 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
2599 Give a blank topic name to go to the Index node itself."
2602 (let ((Info-complete-menu-buffer (clone-buffer))
2603 (Info-complete-nodes (Info-index-nodes))
2604 (Info-history-list nil
))
2605 (if (equal Info-current-file
"dir")
2606 (error "The Info directory node has no index; use m to select a manual"))
2608 (with-current-buffer Info-complete-menu-buffer
2610 (completing-read "Index topic: " 'Info-complete-menu-item
))
2611 (kill-buffer Info-complete-menu-buffer
)))))
2612 (if (equal Info-current-file
"dir")
2613 (error "The Info directory node has no index; use m to select a manual"))
2614 (let ((orignode Info-current-node
)
2615 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
2616 (regexp-quote topic
)))
2617 node
(nodes (Info-index-nodes))
2618 (ohist-list Info-history-list
)
2619 (case-fold-search t
))
2621 (or (equal topic
"")
2624 ;; We bind Info-history to nil for internal node-switches so
2625 ;; that we don't put junk in the history. In the first
2626 ;; Info-goto-index call, above, we do update the history
2627 ;; because that is what the user's previous node choice into it.
2632 (goto-char (point-min))
2633 (while (re-search-forward pattern nil t
)
2634 (push (list (match-string-no-properties 1)
2635 (match-string-no-properties 2)
2637 (string-to-number (concat "0"
2640 (setq nodes
(cdr nodes
) node
(car nodes
)))
2641 (Info-goto-node node
))
2644 (Info-goto-node orignode
)
2645 (error "No `%s' in index" topic
)))
2646 ;; Here it is a feature that assoc is case-sensitive.
2647 (while (setq found
(assoc topic matches
))
2648 (setq exact
(cons found exact
)
2649 matches
(delq found matches
)))
2650 (setq Info-history-list ohist-list
)
2651 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
2652 (Info-index-next 0)))))
2654 (defun Info-index-next (num)
2655 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
2657 (or Info-index-alternatives
2658 (error "No previous `i' command"))
2660 (setq num
(+ num
(length Info-index-alternatives
))))
2662 (setq Info-index-alternatives
2663 (nconc (cdr Info-index-alternatives
)
2664 (list (car Info-index-alternatives
)))
2666 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
2667 (if (> (nth 3 (car Info-index-alternatives
)) 0)
2668 (forward-line (1- (nth 3 (car Info-index-alternatives
))))
2669 (forward-line 3) ; don't search in headers
2670 (let ((name (car (car Info-index-alternatives
))))
2671 (Info-find-index-name name
)))
2672 (message "Found `%s' in %s. %s"
2673 (car (car Info-index-alternatives
))
2674 (nth 2 (car Info-index-alternatives
))
2675 (if (cdr Info-index-alternatives
)
2676 "(`,' tries to find next)"
2679 (defun Info-find-index-name (name)
2680 "Move point to the place within the current node where NAME is defined."
2681 (let ((case-fold-search t
))
2682 (if (or (re-search-forward (format
2683 "[a-zA-Z]+: %s\\( \\|$\\)"
2684 (regexp-quote name
)) nil t
)
2685 ;; Find a function definition with a return type.
2686 (re-search-forward (format
2687 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2688 (regexp-quote name
)) nil t
)
2689 (search-forward (format "`%s'" name
) nil t
)
2690 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
2692 (format "`%s'" (substring name
0 (match-beginning 1)))
2694 (search-forward name nil t
)
2695 ;; Try again without the " <1>" makeinfo can append
2696 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
2697 (Info-find-index-name (match-string 1 name
))))
2698 (progn (beginning-of-line) t
) ;; non-nil for recursive call
2699 (goto-char (point-min)))))
2702 (defun info-apropos (string)
2703 "Grovel indices of all known Info files on your system for STRING.
2704 Build a menu of the possible matches."
2705 (interactive "sIndex apropos: ")
2706 (unless (string= string
"")
2707 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
2708 (regexp-quote string
)))
2709 (ohist Info-history
)
2710 (ohist-list Info-history-list
)
2711 (current-node Info-current-node
)
2712 (current-file Info-current-file
)
2713 manuals matches node nodes
)
2714 (let ((Info-fontify-maximum-menu-size nil
))
2716 (message "Searching indices...")
2717 (goto-char (point-min))
2718 (re-search-forward "\\* Menu: *\n" nil t
)
2719 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
2720 (add-to-list 'manuals
(match-string 1)))
2721 (dolist (manual manuals
)
2722 (message "Searching %s" manual
)
2723 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
2726 (Info-find-node manual
(car nodes
))
2729 (goto-char (point-min))
2730 (while (re-search-forward pattern nil t
)
2731 (add-to-list 'matches
2733 (match-string-no-properties 1)
2734 (match-string-no-properties 2)
2735 (match-string-no-properties 3))))
2736 (setq nodes
(cdr nodes
) node
(car nodes
)))
2737 (Info-goto-node node
)))
2739 (Info-goto-node (concat "(" current-file
")" current-node
))
2740 (setq Info-history ohist
2741 Info-history-list ohist-list
)
2742 (message "Searching indices...done")
2744 (message "No matches found")
2745 (with-current-buffer (get-buffer-create " *info-apropos*")
2747 (insert "\n\^_\nFile: apropos, Node: Index, Up: (dir)\n")
2748 (insert "* Menu: \nNodes whose indices contain \"" string
"\"\n\n")
2749 (dolist (entry matches
)
2751 (format "* %-38s (%s)%s.%s\n"
2752 (concat (nth 1 entry
) " [" (nth 0 entry
) "]:")
2756 (concat " (line " (nth 3 entry
) ")")
2758 (Info-find-node "apropos" "Index")
2759 (setq Info-complete-cache nil
)))))
2761 (defun Info-undefined ()
2762 "Make command be undefined in Info."
2767 "Enter the Info tutorial."
2769 (delete-other-windows)
2770 (Info-find-node "info"
2771 (if (< (window-height) 23)
2775 (defun Info-summary ()
2776 "Display a brief summary of all Info commands."
2778 (save-window-excursion
2779 (switch-to-buffer "*Help*")
2780 (setq buffer-read-only nil
)
2782 (insert (documentation 'Info-mode
))
2784 (goto-char (point-min))
2786 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
2787 (message (if flag
"Type Space to see more"
2788 "Type Space to return to Info"))
2789 (if (not (eq ?\
(setq ch
(read-event))))
2790 (progn (setq unread-command-events
(list ch
)) nil
)
2793 (bury-buffer "*Help*")))
2795 (defun Info-get-token (pos start all
&optional errorstring
)
2796 "Return the token around POS.
2797 POS must be somewhere inside the token
2798 START is a regular expression which will match the
2799 beginning of the tokens delimited string
2800 ALL is a regular expression with a single
2801 parenthesized subpattern which is the token to be
2802 returned. E.g. '{\(.*\)}' would return any string
2803 enclosed in braces around POS.
2804 ERRORSTRING optional fourth argument, controls action on no match
2807 a string: signal an error, using that string."
2808 (let ((case-fold-search t
))
2811 ;; First look for a match for START that goes across POS.
2812 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
2813 (not (looking-at start
)))
2815 ;; If we did not find one, search back for START
2816 ;; (this finds only matches that end at or before POS).
2817 (or (looking-at start
)
2820 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
2822 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
2823 (not (setq found
(and (<= (match-beginning 0) pos
)
2824 (> (match-end 0) pos
))))))
2825 (if (and found
(<= (match-beginning 0) pos
)
2826 (> (match-end 0) pos
))
2827 (match-string-no-properties 1)
2828 (cond ((null errorstring
)
2834 (error "No %s around position %d" errorstring pos
))))))))
2836 (defun Info-mouse-follow-nearest-node (click)
2837 "\\<Info-mode-map>Follow a node reference near point.
2838 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2839 At end of the node's text, moves to the next node, or up if none."
2841 (mouse-set-point click
)
2842 (and (not (Info-try-follow-nearest-node))
2843 (save-excursion (forward-line 1) (eobp))
2844 (Info-next-preorder)))
2846 (defun Info-follow-nearest-node (&optional fork
)
2847 "Follow a node reference near point.
2848 If point is on a reference, follow that reference. Otherwise,
2849 if point is in a menu item description, follow that menu item."
2851 (or (Info-try-follow-nearest-node fork
)
2852 (when (save-excursion
2853 (search-backward "\n* menu:" nil t
))
2856 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2857 (beginning-of-line 0))
2858 (when (looking-at "\\* +\\([^\t\n]*\\):")
2860 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
2862 (error "Point neither on reference nor in menu item description")))
2864 ;; Common subroutine.
2865 (defun Info-try-follow-nearest-node (&optional fork
)
2866 "Follow a node reference near point. Return non-nil if successful."
2869 ((Info-get-token (point) "[hf]t?tp://" "[hf]t?tp://\\([^ \t\n\"`({<>})']+\\)")
2871 (browse-url (browse-url-url-at-point)))
2872 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
2873 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
2874 (Info-follow-reference node fork
))
2875 ;; menu item: node name
2876 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2877 (Info-goto-node node fork
))
2878 ;; menu item: node name or index entry
2879 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
2882 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
2883 (Info-goto-node node fork
))
2884 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2885 (Info-goto-node node fork
))
2886 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2887 (Info-goto-node node fork
))
2888 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2889 (Info-goto-node "Top" fork
))
2890 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2891 (Info-goto-node node fork
)))
2894 (defvar Info-mode-map nil
2895 "Keymap containing Info commands.")
2898 (setq Info-mode-map
(make-keymap))
2899 (suppress-keymap Info-mode-map
)
2900 (define-key Info-mode-map
"." 'beginning-of-buffer
)
2901 (define-key Info-mode-map
" " 'Info-scroll-up
)
2902 (define-key Info-mode-map
"\C-m" 'Info-follow-nearest-node
)
2903 (define-key Info-mode-map
"\t" 'Info-next-reference
)
2904 (define-key Info-mode-map
[(shift tab
)] 'Info-prev-reference
)
2905 (define-key Info-mode-map
[backtab] 'Info-prev-reference)
2906 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2907 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2908 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2909 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2910 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2911 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2912 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2913 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2914 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2915 (define-key Info-mode-map "0" 'undefined)
2916 (define-key Info-mode-map "?" 'Info-summary)
2917 (define-key Info-mode-map "]" 'Info-forward-node)
2918 (define-key Info-mode-map "[" 'Info-backward-node)
2919 (define-key Info-mode-map "<" 'Info-top-node)
2920 (define-key Info-mode-map ">" 'Info-final-node)
2921 (define-key Info-mode-map "b" 'beginning-of-buffer)
2922 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
2923 (define-key Info-mode-map "d" 'Info-directory)
2924 (define-key Info-mode-map "e" 'Info-edit)
2925 (define-key Info-mode-map "f" 'Info-follow-reference)
2926 (define-key Info-mode-map "g" 'Info-goto-node)
2927 (define-key Info-mode-map "h" 'Info-help)
2928 (define-key Info-mode-map "i" 'Info-index)
2929 (define-key Info-mode-map "l" 'Info-history-back)
2930 (define-key Info-mode-map "L" 'Info-history)
2931 (define-key Info-mode-map "m" 'Info-menu)
2932 (define-key Info-mode-map "n" 'Info-next)
2933 (define-key Info-mode-map "p" 'Info-prev)
2934 (define-key Info-mode-map "q" 'Info-exit)
2935 (define-key Info-mode-map "r" 'Info-history-forward)
2936 (define-key Info-mode-map "s" 'Info-search)
2937 (define-key Info-mode-map "S" 'Info-search-case-sensitively)
2938 ;; For consistency with Rmail.
2939 (define-key Info-mode-map "\M-s" 'Info-search)
2940 (define-key Info-mode-map "\M-n" 'clone-buffer)
2941 (define-key Info-mode-map "t" 'Info-top-node)
2942 (define-key Info-mode-map "T" 'Info-toc)
2943 (define-key Info-mode-map "u" 'Info-up)
2944 ;; For consistency with dired-copy-filename-as-kill.
2945 (define-key Info-mode-map "w" 'Info-copy-current-node-name)
2946 (define-key Info-mode-map "," 'Info-index-next)
2947 (define-key Info-mode-map "\177" 'Info-scroll-down)
2948 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
2949 (define-key Info-mode-map [follow-link] 'mouse-face)
2952 (defun Info-check-pointer (item)
2953 "Non-nil if ITEM is present in this node."
2955 (Info-extract-pointer item)
2959 Info-mode-menu Info-mode-map
2960 "Menu for info files."
2962 ["Up" Info-up :active (Info-check-pointer "up")
2963 :help "Go up in the Info tree"]
2964 ["Next" Info-next :active (Info-check-pointer "next")
2965 :help "Go to the next node"]
2966 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
2967 :help "Go to the previous node"]
2968 ["Backward" Info-backward-node
2969 :help "Go backward one node, considering all as a sequence"]
2970 ["Forward" Info-forward-node
2971 :help "Go forward one node, considering all as a sequence"]
2972 ["Beginning" beginning-of-buffer
2973 :help "Go to beginning of this node"]
2974 ["Top" Info-top-node
2975 :help "Go to top node of file"]
2976 ["Final Node" Info-final-node
2977 :help "Go to final node in this file"]
2978 ("Menu Item" ["You should never see this" report-emacs-bug t])
2979 ("Reference" ["You should never see this" report-emacs-bug t])
2980 ["Search..." Info-search
2981 :help "Search for regular expression in this Info file"]
2982 ["Search Case-Sensitively..." Info-search-case-sensitively
2983 :help "Search for regular expression case sensitively"]
2984 ["Search Next" Info-search-next
2985 :help "Search for another occurrence of regular expression"]
2986 ["Go to Node..." Info-goto-node
2987 :help "Go to a named node"]
2988 ["Back in history" Info-history-back :active Info-history
2989 :help "Go back in history to the last node you were at"]
2990 ["Forward in history" Info-history-forward :active Info-history-forward
2991 :help "Go forward in history"]
2992 ["History" Info-history :active Info-history-list
2993 :help "Go to menu of visited nodes"]
2994 ["Table of Contents" Info-toc
2995 :help "Go to table of contents"]
2997 ["Lookup a String" Info-index
2998 :help "Look for a string in the index items"]
2999 ["Next Matching Item" Info-index-next
3000 :help "Look for another occurrence of previous item"]
3001 ["Lookup a string in all indices" info-apropos
3002 :help "Look for a string in the indices of all manuals"])
3003 ["Edit" Info-edit :help "Edit contents of this node"
3004 :active Info-enable-edit]
3005 ["Copy Node Name" Info-copy-current-node-name
3006 :help "Copy the name of the current node into the kill ring"]
3007 ["Clone Info buffer" clone-buffer
3008 :help "Create a twin copy of the current Info buffer."]
3009 ["Exit" Info-exit :help "Stop reading Info"]))
3012 (defvar info-tool-bar-map
3013 (if (display-graphic-p)
3014 (let ((map (make-sparse-keymap)))
3015 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
3016 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
3017 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
3018 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
3019 (tool-bar-local-item-from-menu 'Info-history-back "back_arrow" map Info-mode-map)
3020 (tool-bar-local-item-from-menu 'Info-history-forward "fwd_arrow" map Info-mode-map)
3021 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
3022 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
3023 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
3024 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
3027 (defvar Info-menu-last-node nil)
3028 ;; Last node the menu was created for.
3029 ;; Value is a list, (FILE-NAME NODE-NAME).
3031 (defun Info-menu-update ()
3032 "Update the Info menu for the current node."
3034 (if (or (not (eq major-mode 'Info-mode))
3035 (equal (list Info-current-file Info-current-node)
3036 Info-menu-last-node))
3038 ;; Update menu menu.
3039 (let* ((Info-complete-menu-buffer (current-buffer))
3040 (items (nreverse (condition-case nil
3041 (Info-complete-menu-item "" nil t)
3045 (while (and items (< number 9))
3046 (setq current (car items)
3049 (setq entries (cons `[,current
3050 (Info-menu ,current)
3051 :keys ,(format "%d" number)]
3054 (setq entries (cons ["Other..." Info-menu t] entries)))
3056 (setq entries (list ["No menu" nil nil] nil :active)))
3057 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3058 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3060 str i entries current
3062 (case-fold-search t))
3064 (goto-char (point-min))
3065 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3066 (setq str (match-string 1))
3068 (while (setq i (string-match "[ \n\t]+" str i))
3069 (setq str (concat (substring str 0 i) " "
3070 (substring str (match-end 0))))
3074 (while (and items (< number 9))
3075 (setq current (car items)
3078 (setq entries (cons `[,current
3079 (Info-follow-reference ,current)
3083 (setq entries (cons ["Other..." Info-follow-reference t]
3086 (setq entries (list ["No references" nil nil] nil :active)))
3087 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3088 ;; Update last seen node.
3089 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3090 ;; Try to avoid entering infinite beep mode in case of errors.
3094 (defun Info-copy-current-node-name (&optional arg)
3095 "Put the name of the current info node into the kill ring.
3096 The name of the info file is prepended to the node name in parentheses.
3097 With a zero prefix arg, put the name inside a function call to `info'."
3099 (unless Info-current-node
3100 (error "No current info node"))
3101 (let ((node (concat "(" (file-name-nondirectory
3102 (or (and (stringp Info-current-file)
3106 ")" Info-current-node)))
3107 (if (zerop (prefix-numeric-value arg))
3108 (setq node (concat "(info \"" node "\")")))
3110 (message "%s" node)))
3113 ;; Info mode is suitable only for specially formatted data.
3114 (put 'Info-mode 'mode-class 'special)
3115 (put 'Info-mode 'no-clone-indirect t)
3118 "Info mode provides commands for browsing through the Info documentation tree.
3119 Documentation in Info is divided into \"nodes\", each of which discusses
3120 one topic and contains references to other nodes which discuss related
3121 topics. Info has commands to follow the references and show you other nodes.
3124 \\[Info-help] Invoke the Info tutorial.
3125 \\[Info-exit] Quit Info: reselect previously selected buffer.
3127 Selecting other nodes:
3128 \\[Info-mouse-follow-nearest-node]
3129 Follow a node reference you click on.
3130 This works with menu items, cross references, and
3131 the \"next\", \"previous\" and \"up\", depending on where you click.
3132 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3133 \\[Info-next] Move to the \"next\" node of this node.
3134 \\[Info-prev] Move to the \"previous\" node of this node.
3135 \\[Info-up] Move \"up\" from this node.
3136 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3137 Picking a menu item causes another node to be selected.
3138 \\[Info-directory] Go to the Info directory node.
3139 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3140 \\[Info-history-back] Move back in history to the last node you were at.
3141 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3142 \\[Info-history] Go to menu of visited nodes.
3143 \\[Info-toc] Go to table of contents of the current Info file.
3144 \\[Info-top-node] Go to the Top node of this file.
3145 \\[Info-final-node] Go to the final node in this file.
3146 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3147 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3148 \\[Info-index] Look up a topic in this file's Index and move to that node.
3149 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3150 \\[info-apropos] Look for a string in the indices of all manuals.
3152 Moving within a node:
3153 \\[Info-scroll-up] Normally, scroll forward a full screen.
3154 Once you scroll far enough in a node that its menu appears on the
3155 screen but after point, the next scroll moves into its first
3156 subnode. When after all menu items (or if there is no menu),
3157 move up to the parent node.
3158 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3159 already visible, try to go to the previous menu entry, or up
3161 \\[beginning-of-buffer] Go to beginning of node.
3164 \\[Info-copy-current-node-name] Put name of current info node in the kill ring.
3165 \\[clone-buffer] Select a new cloned Info buffer in another window.
3166 \\[Info-edit] Edit contents of selected node.
3167 1 .. 9 Pick first ... ninth item in node's menu.
3168 Every third `*' is highlighted to help pick the right number.
3169 \\[Info-goto-node] Move to node specified by name.
3170 You may include a filename as well, as (FILENAME)NODENAME.
3171 \\[universal-argument] \\[info] Move to new Info file with completion.
3172 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>.
3173 \\[Info-search] Search through this Info file for specified regexp,
3174 and select the node in which the next occurrence is found.
3175 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3176 \\[Info-search-next] Search for another occurrence of regexp
3177 from a previous \\<Info-mode-map>\\[Info-search] command.
3178 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3179 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
3180 (kill-all-local-variables)
3181 (setq major-mode 'Info-mode)
3182 (setq mode-name "Info")
3184 (use-local-map Info-mode-map)
3185 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3186 (set-syntax-table text-mode-syntax-table)
3187 (setq local-abbrev-table text-mode-abbrev-table)
3188 (setq case-fold-search t)
3189 (setq buffer-read-only t)
3190 (make-local-variable 'Info-current-file)
3191 (make-local-variable 'Info-current-subfile)
3192 (make-local-variable 'Info-current-node)
3193 (make-local-variable 'Info-tag-table-marker)
3194 (setq Info-tag-table-marker (make-marker))
3195 (make-local-variable 'Info-tag-table-buffer)
3196 (setq Info-tag-table-buffer nil)
3197 (make-local-variable 'Info-history)
3198 (make-local-variable 'Info-history-forward)
3199 (make-local-variable 'Info-index-alternatives)
3200 (setq header-line-format
3201 (if Info-use-header-line
3202 '(:eval (get-text-property (point-min) 'header-line))
3203 nil)) ; so the header line isn't displayed
3204 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
3205 ;; This is for the sake of the invisible text we use handling titles.
3206 (make-local-variable 'line-move-ignore-invisible)
3207 (setq line-move-ignore-invisible t)
3208 (make-local-variable 'desktop-save-buffer)
3209 (setq desktop-save-buffer 'Info-desktop-buffer-misc-data)
3210 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
3211 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
3212 (set (make-local-variable 'isearch-search-fun-function)
3213 'Info-isearch-search)
3214 (set (make-local-variable 'isearch-wrap-function)
3216 (set (make-local-variable 'isearch-push-state-function)
3217 'Info-isearch-push-state)
3218 (set (make-local-variable 'search-whitespace-regexp)
3219 Info-search-whitespace-regexp)
3220 (Info-set-mode-line)
3221 (run-hooks 'Info-mode-hook))
3223 (defun Info-clone-buffer-hook ()
3224 (when (bufferp Info-tag-table-buffer)
3225 (setq Info-tag-table-buffer
3226 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
3227 (let ((m Info-tag-table-marker))
3229 (setq Info-tag-table-marker
3230 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
3231 (with-current-buffer Info-tag-table-buffer
3232 (copy-marker (marker-position m)))
3235 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
3236 (set-keymap-parent map text-mode-map)
3237 (define-key map "\C-c\C-c" 'Info-cease-edit)
3239 "Local keymap used within `e' command of Info.")
3241 ;; Info-edit mode is suitable only for specially formatted data.
3242 (put 'Info-edit-mode 'mode-class 'special)
3244 (defun Info-edit-mode ()
3245 "Major mode for editing the contents of an Info node.
3246 Like text mode with the addition of `Info-cease-edit'
3247 which returns to Info mode for browsing.
3249 (use-local-map Info-edit-map)
3250 (setq major-mode 'Info-edit-mode)
3251 (setq mode-name "Info Edit")
3252 (kill-local-variable 'mode-line-buffer-identification)
3253 (setq buffer-read-only nil)
3254 (force-mode-line-update)
3255 (buffer-enable-undo (current-buffer))
3256 (run-hooks 'Info-edit-mode-hook))
3259 "Edit the contents of this Info node.
3260 Allowed only if variable `Info-enable-edit' is non-nil."
3262 (or Info-enable-edit
3263 (error "Editing info nodes is not enabled"))
3265 (message "%s" (substitute-command-keys
3266 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
3268 (defun Info-cease-edit ()
3269 "Finish editing Info node; switch back to Info proper."
3271 ;; Do this first, so nothing has changed if user C-g's at query.
3272 (and (buffer-modified-p)
3273 (y-or-n-p "Save the file? ")
3275 (use-local-map Info-mode-map)
3276 (setq major-mode 'Info-mode)
3277 (setq mode-name "Info")
3278 (Info-set-mode-line)
3279 (setq buffer-read-only t)
3280 (force-mode-line-update)
3281 (and (marker-position Info-tag-table-marker)
3283 (message "Tags may have changed. Use Info-tagify if necessary")))
3285 (defvar Info-file-list-for-emacs
3286 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
3287 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
3288 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
3289 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
3290 ("skeleton" . "autotype") ("auto-insert" . "autotype")
3291 ("copyright" . "autotype") ("executable" . "autotype")
3292 ("time-stamp" . "autotype") ("quickurl" . "autotype")
3293 ("tempo" . "autotype") ("hippie-expand" . "autotype")
3294 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
3295 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
3296 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
3297 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
3298 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
3299 ("rfc2045" . "emacs-mime")
3300 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
3301 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
3302 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
3303 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
3304 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
3305 ("mml" . "emacs-mime"))
3306 "List of Info files that describe Emacs commands.
3307 An element can be a file name, or a list of the form (PREFIX . FILE)
3308 where PREFIX is a name prefix and FILE is the file to look in.
3309 If the element is just a file name, the file name also serves as the prefix.")
3311 (defun Info-find-emacs-command-nodes (command)
3312 "Return a list of locations documenting COMMAND.
3313 The `info-file' property of COMMAND says which Info manual to search.
3314 If COMMAND has no property, the variable `Info-file-list-for-emacs'
3315 defines heuristics for which Info manual to try.
3316 The locations are of the format used in `Info-history', i.e.
3317 \(FILENAME NODENAME BUFFERPOS\), where BUFFERPOS is the line number
3318 in the first element of the returned list (which is treated specially in
3319 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
3320 (let ((where '()) line-number
3321 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
3322 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
3323 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
3324 (info-file "emacs")) ;default
3325 ;; Determine which info file this command is documented in.
3326 (if (get command 'info-file)
3327 (setq info-file (get command 'info-file))
3328 ;; If it doesn't say explicitly, test its name against
3329 ;; various prefixes that we know.
3330 (let ((file-list Info-file-list-for-emacs))
3332 (let* ((elt (car file-list))
3333 (name (if (consp elt)
3336 (file (if (consp elt) (cdr elt) elt))
3337 (case-fold-search nil)
3338 (regexp (concat "\\`" (regexp-quote name)
3340 (if (string-match regexp (symbol-name command))
3341 (setq info-file file file-list nil))
3342 (setq file-list (cdr file-list))))))
3343 (Info-find-node info-file "Top")
3344 (or (and (search-forward "\n* menu:" nil t)
3345 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
3346 (error "Info file `%s' appears to lack an index" info-file))
3347 (goto-char (match-beginning 1))
3348 ;; Bind Info-history to nil, to prevent the index nodes from
3349 ;; getting into the node history.
3350 (let ((Info-history nil)
3351 (Info-history-list nil)
3352 node (nodes (Info-index-nodes)))
3353 (Info-goto-node (car nodes))
3356 (goto-char (point-min))
3357 (while (re-search-forward cmd-desc nil t)
3359 (cons (list Info-current-file
3360 (match-string-no-properties 2)
3363 (setq line-number (and (match-beginning 3)
3364 (string-to-number (match-string 3)))))
3365 (and (setq nodes (cdr nodes) node (car nodes))))
3366 (Info-goto-node node)))
3367 (if (and line-number where)
3368 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
3372 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file "emacs")
3374 (defun Info-goto-emacs-command-node (command)
3375 "Go to the Info node in the Emacs manual for command COMMAND.
3376 The command is found by looking up in Emacs manual's indices
3377 or in another manual found via COMMAND's `info-file' property or
3378 the variable `Info-file-list-for-emacs'.
3379 COMMAND must be a symbol or string."
3380 (interactive "CFind documentation for command: ")
3381 ;; If command is given as a string, convert it to a symbol.
3382 (if (stringp command)
3383 (setq command (intern command)))
3384 (or (commandp command)
3385 (signal 'wrong-type-argument (list 'commandp command)))
3386 (let ((where (Info-find-emacs-command-nodes command)))
3388 (let ((num-matches (length where)))
3389 ;; Get Info running, and pop to it in another window.
3390 (save-window-excursion
3392 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
3393 ;; Bind Info-history to nil, to prevent the last Index node
3394 ;; visited by Info-find-emacs-command-nodes from being
3395 ;; pushed onto the history.
3396 (let ((Info-history nil) (Info-history-list nil)
3397 (line-number (nth 2 (car where))))
3398 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
3399 (if (and (integerp line-number) (> line-number 0))
3400 (forward-line (1- line-number))))
3401 (if (> num-matches 1)
3403 ;; (car where) will be pushed onto Info-history
3404 ;; when/if they go to another node. Put the other
3405 ;; nodes that were found on the history.
3406 (setq Info-history (nconc (cdr where) Info-history))
3407 (message "Found %d other entr%s. Use %s to see %s."
3409 (if (> num-matches 2) "ies" "y")
3410 (substitute-command-keys "\\[Info-history-back]")
3411 (if (> num-matches 2) "them" "it")))))
3412 (error "Couldn't find documentation for %s" command))))
3414 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file "emacs")
3416 (defun Info-goto-emacs-key-command-node (key)
3417 "Go to the node in the Emacs manual which describes the command bound to KEY.
3419 Interactively, if the binding is `execute-extended-command', a command is read.
3420 The command is found by looking up in Emacs manual's indices
3421 or in another manual found via COMMAND's `info-file' property or
3422 the variable `Info-file-list-for-emacs'."
3423 (interactive "kFind documentation for key: ")
3424 (let ((command (key-binding key)))
3425 (cond ((null command)
3426 (message "%s is undefined" (key-description key)))
3427 ((and (interactive-p)
3428 (eq command 'execute-extended-command))
3429 (Info-goto-emacs-command-node
3430 (read-command "Find documentation for command: ")))
3432 (Info-goto-emacs-command-node command)))))
3434 (defface Info-title-1-face
3435 '((((type tty pc) (class color)) :foreground "yellow" :weight bold)
3436 (t :height 1.2 :inherit Info-title-2-face))
3437 "Face for Info titles at level 1."
3440 (defface Info-title-2-face
3441 '((((type tty pc) (class color)) :foreground "lightblue" :weight bold)
3442 (t :height 1.2 :inherit Info-title-3-face))
3443 "Face for Info titles at level 2."
3446 (defface Info-title-3-face
3447 '((((type tty pc) (class color)) :weight bold)
3448 (t :height 1.2 :inherit Info-title-4-face))
3449 "Face for Info titles at level 3."
3452 (defface Info-title-4-face
3453 '((((type tty pc) (class color)) :weight bold)
3454 (t :weight bold :inherit variable-pitch))
3455 "Face for Info titles at level 4."
3458 (defface info-menu-header
3463 :inherit variable-pitch
3465 "Face for headers in Info menus."
3468 (defun Info-escape-percent (string)
3469 "Double all occurrences of `%' in STRING.
3471 Return a new string with all `%' characters replaced by `%%'.
3472 Preserve text properties."
3474 (end (length string))
3477 (while (and (< start end) (string-match "%" string start))
3478 (setq mb (match-beginning 0)
3480 m (substring string mb me)
3483 (cons (substring string start mb)
3486 (push (substring string start end) matches)
3487 (apply #'concat (nreverse matches)))))
3489 (defvar Info-next-link-keymap
3490 (let ((keymap (make-sparse-keymap)))
3491 (define-key keymap [header-line mouse-1] 'Info-next)
3492 (define-key keymap [header-line mouse-2] 'Info-next)
3493 (define-key keymap [header-line down-mouse-1] 'ignore)
3494 (define-key keymap [mouse-2] 'Info-next)
3495 (define-key keymap [follow-link] 'mouse-face)
3497 "Keymap to put on the Next link in the text or the header line.")
3499 (defvar Info-prev-link-keymap
3500 (let ((keymap (make-sparse-keymap)))
3501 (define-key keymap [header-line mouse-1] 'Info-prev)
3502 (define-key keymap [header-line mouse-2] 'Info-prev)
3503 (define-key keymap [header-line down-mouse-1] 'ignore)
3504 (define-key keymap [mouse-2] 'Info-prev)
3505 (define-key keymap [follow-link] 'mouse-face)
3507 "Keymap to put on the Prev link in the text or the header line.")
3510 (defvar Info-up-link-keymap
3511 (let ((keymap (make-sparse-keymap)))
3512 (define-key keymap [header-line mouse-1] 'Info-up)
3513 (define-key keymap [header-line mouse-2] 'Info-up)
3514 (define-key keymap [header-line down-mouse-1] 'ignore)
3515 (define-key keymap [mouse-2] 'Info-up)
3516 (define-key keymap [follow-link] 'mouse-face)
3518 "Keymap to put on the Up link in the text or the header line.")
3520 (defun Info-fontify-node ()
3523 (let* ((inhibit-read-only t)
3524 (case-fold-search t)
3526 (not-fontified-p ; the node hasn't already been fontified
3527 (not (let ((where (next-property-change (point-min))))
3528 (and where (not (= where (point-max)))))))
3529 (fontify-visited-p ; visited nodes need to be re-fontified
3530 (and Info-fontify-visited-nodes
3531 ;; Don't take time to refontify visited nodes in huge nodes
3532 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
3535 ;; Fontify header line
3536 (goto-char (point-min))
3537 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
3538 (goto-char (match-end 0))
3539 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
3540 (goto-char (match-end 0))
3541 (let* ((nbeg (match-beginning 2))
3542 (nend (match-end 2))
3543 (tbeg (match-beginning 1))
3544 (tag (match-string 1)))
3545 (if (string-equal tag "Node")
3546 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
3547 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
3548 (put-text-property tbeg nend 'mouse-face 'highlight)
3549 (put-text-property tbeg nend
3551 (concat "mouse-2: Go to node "
3552 (buffer-substring nbeg nend)))
3553 ;; Always set up the text property keymap.
3554 ;; It will either be used in the buffer
3555 ;; or copied in the header line.
3556 (put-text-property tbeg nend 'keymap
3558 ((equal tag "Prev") Info-prev-link-keymap)
3559 ((equal tag "Next") Info-next-link-keymap)
3560 ((equal tag "Up") Info-up-link-keymap))))))
3561 (when Info-use-header-line
3562 (goto-char (point-min))
3563 (let ((header-end (line-end-position))
3565 ;; If we find neither Next: nor Prev: link, show the entire
3566 ;; node header. Otherwise, don't show the File: and Node:
3567 ;; parts, to avoid wasting precious space on information that
3568 ;; is available in the mode line.
3569 (if (re-search-forward
3570 "\\(next\\|up\\|prev[ious]*\\): "
3573 (goto-char (match-beginning 1))
3574 (setq header (buffer-substring (point) header-end)))
3575 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" header-end t)
3577 (concat "No next, prev or up links -- "
3578 (buffer-substring (point) header-end)))
3579 (setq header (buffer-substring (point) header-end))))
3580 (put-text-property (point-min) (1+ (point-min))
3581 'header-line (Info-escape-percent header))
3582 ;; Hide the part of the first line
3583 ;; that is in the header, if it is just part.
3585 ;; Hide the punctuation at the end, too.
3586 (skip-chars-backward " \t,")
3587 (put-text-property (point) header-end 'invisible t)))))
3590 (goto-char (point-min))
3591 (when not-fontified-p
3592 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
3594 (let* ((c (preceding-char))
3596 (cond ((= c ?*) 'Info-title-1-face)
3597 ((= c ?=) 'Info-title-2-face)
3598 ((= c ?-) 'Info-title-3-face)
3599 (t 'Info-title-4-face))))
3600 (put-text-property (match-beginning 1) (match-end 1)
3601 'font-lock-face face))
3602 ;; This is a serious problem for trying to handle multiple
3603 ;; frame types at once. We want this text to be invisible
3604 ;; on frames that can display the font above.
3605 (when (memq (framep (selected-frame)) '(x pc w32 mac))
3606 (add-text-properties (1- (match-beginning 2)) (match-end 2)
3607 '(invisible t front-sticky nil rear-nonsticky t)))))
3609 ;; Fontify cross references
3610 (goto-char (point-min))
3611 (when (or not-fontified-p fontify-visited-p)
3612 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
3613 (let ((start (match-beginning 0))
3616 (when not-fontified-p
3617 (when Info-hide-note-references
3618 (when (not (eq Info-hide-note-references 'hide))
3619 ;; *Note is often used where *note should have been
3621 (skip-syntax-backward " ")
3623 (cond ((memq (char-before) '(nil ?\. ?! ??))
3625 ((memq (char-before) '(?\, ?\; ?\: ?-))
3627 ((memq (char-before) '(?\( ?\[ ?\{))
3628 ;; Check whether the paren is preceded by
3629 ;; an end of sentence
3630 (skip-syntax-backward " (")
3631 (if (memq (char-before) '(nil ?\. ?! ??))
3634 ((save-match-data (looking-at "\n\n"))
3637 (add-text-properties
3639 (or (save-match-data
3640 ;; Don't hide \n after *Note
3641 (let ((start1 (match-beginning 1)))
3642 (if (string-match "\n" (match-string 1))
3643 (+ start1 (match-beginning 0)))))
3646 `(display ,other-tag front-sticky nil rear-nonsticky t)
3647 '(invisible t front-sticky nil rear-nonsticky t))))
3648 (add-text-properties
3649 (match-beginning 2) (match-end 2)
3651 'help-echo (if (or (match-end 5)
3652 (not (equal (match-string 4) "")))
3653 (concat "mouse-2: go to " (or (match-string 5)
3655 "mouse-2: go to this node")
3656 'mouse-face 'highlight)))
3657 (when (or not-fontified-p fontify-visited-p)
3658 (setq rbeg (match-beginning 2)
3663 ;; Display visited nodes in a different face
3664 (if (and Info-fontify-visited-nodes
3666 (let* ((node (replace-regexp-in-string
3668 (replace-regexp-in-string
3670 (or (match-string 5)
3671 (and (not (equal (match-string 4) ""))
3673 (match-string 2)))))
3674 (file (file-name-nondirectory
3676 (hl Info-history-list)
3678 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3679 (setq file (file-name-nondirectory
3680 (match-string 1 node))
3681 node (if (equal (match-string 2 node) "")
3683 (match-string 2 node))))
3685 (if (and (string-equal node (nth 1 (car hl)))
3687 (file-name-nondirectory
3689 (setq res (car hl) hl nil)
3690 (setq hl (cdr hl))))
3691 res))) 'info-xref-visited 'info-xref))
3692 ;; For multiline ref, unfontify newline and surrounding whitespace
3696 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
3697 (remove-text-properties (match-beginning 0)
3699 '(font-lock-face t))))))
3700 (when not-fontified-p
3701 (when (memq Info-hide-note-references '(t hide))
3702 (add-text-properties (match-beginning 3) (match-end 3)
3703 '(invisible t front-sticky nil rear-nonsticky t))
3704 ;; Unhide the file name of the external reference in parens
3705 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
3706 (remove-text-properties (match-beginning 6) (match-end 6)
3707 '(invisible t front-sticky nil rear-nonsticky t)))
3708 ;; Unhide newline because hidden newlines cause too long lines
3710 (let ((beg3 (match-beginning 3))
3711 (end3 (match-end 3)))
3712 (if (and (string-match "\n[ \t]*" (match-string 3))
3713 (not (save-match-data
3715 (goto-char (1+ end3))
3716 (looking-at "[.)]*$")))))
3717 (remove-text-properties (+ beg3 (match-beginning 0))
3718 (+ beg3 (match-end 0))
3719 '(invisible t front-sticky nil rear-nonsticky t))))))
3720 (when (and Info-refill-paragraphs Info-hide-note-references)
3721 (push (set-marker (make-marker) start)
3722 paragraph-markers))))))
3724 ;; Refill paragraphs (experimental feature)
3725 (when (and not-fontified-p
3726 Info-refill-paragraphs
3728 (let ((fill-nobreak-invisible t)
3729 (fill-individual-varying-indent nil)
3730 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
3731 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
3732 (adaptive-fill-mode nil))
3733 (goto-char (point-max))
3734 (while paragraph-markers
3735 (let ((m (car paragraph-markers)))
3736 (setq paragraph-markers (cdr paragraph-markers))
3740 (let ((beg (point)))
3741 (when (zerop (forward-paragraph))
3742 (fill-individual-paragraphs beg (point) nil nil)
3744 (set-marker m nil)))))
3746 ;; Fontify menu items
3747 (goto-char (point-min))
3748 (when (and (or not-fontified-p fontify-visited-p)
3749 (search-forward "\n* Menu:" nil t)
3750 (not (Info-index-node))
3751 ;; Don't take time to annotate huge menus
3752 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
3755 (while (re-search-forward
3756 (concat "^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
3757 Info-node-spec-re "\\([ \t]*\\)\\)")
3759 (when not-fontified-p
3761 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
3762 (put-text-property (match-beginning 0)
3763 (1+ (match-beginning 0))
3764 'font-lock-face 'info-menu-5)))
3765 (when not-fontified-p
3766 (add-text-properties
3767 (match-beginning 1) (match-end 1)
3769 'help-echo (if (match-end 3)
3770 (concat "mouse-2: go to " (match-string 3))
3771 "mouse-2: go to this node")
3772 'mouse-face 'highlight)))
3773 (when (or not-fontified-p fontify-visited-p)
3774 (add-text-properties
3775 (match-beginning 1) (match-end 1)
3778 ;; Display visited menu items in a different face
3779 (if (and Info-fontify-visited-nodes
3781 (let ((node (if (equal (match-string 3) "")
3784 (file (file-name-nondirectory Info-current-file))
3785 (hl Info-history-list)
3787 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3788 (setq file (file-name-nondirectory
3789 (match-string 1 node))
3790 node (if (equal (match-string 2 node) "")
3792 (match-string 2 node))))
3794 (if (and (string-equal node (nth 1 (car hl)))
3796 (file-name-nondirectory
3798 (setq res (car hl) hl nil)
3799 (setq hl (cdr hl))))
3800 res))) 'info-xref-visited 'info-xref))))
3801 (when (and not-fontified-p (memq Info-hide-note-references '(t hide)))
3802 (put-text-property (match-beginning 2) (1- (match-end 6))
3804 ;; Unhide the file name in parens
3805 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
3806 (remove-text-properties (match-beginning 4) (match-end 4)
3808 ;; We need a stretchable space like :align-to but with
3810 (put-text-property (1- (match-end 6)) (match-end 6) 'display
3811 (if (>= 22 (- (match-end 1)
3812 (match-beginning 0)))
3813 '(space :align-to 24)
3815 (setq cont (looking-at "."))
3816 (while (and (= (forward-line 1) 0)
3817 (looking-at "\\([ \t]+\\)[^*\n]"))
3818 (put-text-property (match-beginning 1) (1- (match-end 1))
3820 (put-text-property (1- (match-end 1)) (match-end 1)
3823 '(space :align-to 26)
3824 '(space :align-to 24)))
3827 ;; Fontify menu headers
3828 ;; Add the face `info-menu-header' to any header before a menu entry
3829 (goto-char (point-min))
3830 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
3831 (put-text-property (match-beginning 0) (match-end 0)
3832 'font-lock-face 'info-menu-header)
3833 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
3834 (put-text-property (match-beginning 1) (match-end 1)
3835 'font-lock-face 'info-menu-header)))
3837 ;; Hide index line numbers
3838 (goto-char (point-min))
3839 (when (and not-fontified-p (Info-index-node))
3840 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
3841 (put-text-property (match-beginning 0) (match-end 0)
3844 ;; Fontify http and ftp references
3845 (goto-char (point-min))
3846 (when not-fontified-p
3847 (while (re-search-forward "[hf]t?tp://[^ \t\n\"`({<>})']+" nil t)
3848 (add-text-properties (match-beginning 0) (match-end 0)
3849 '(font-lock-face info-xref
3850 mouse-face highlight
3851 help-echo "mouse-2: go to this URL"))))
3853 (set-buffer-modified-p nil))))
3856 ;; When an Info buffer is killed, make sure the associated tags buffer
3858 (defun Info-kill-buffer ()
3859 (and (eq major-mode 'Info-mode)
3860 Info-tag-table-buffer
3861 (kill-buffer Info-tag-table-buffer)))
3863 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
3865 ;;; Speedbar support:
3866 ;; These functions permit speedbar to display the "tags" in the
3867 ;; current info node.
3868 (eval-when-compile (require 'speedbar))
3870 (defvar Info-speedbar-key-map nil
3871 "Keymap used when in the info display mode.")
3873 (defun Info-install-speedbar-variables ()
3874 "Install those variables used by speedbar to enhance Info."
3875 (if Info-speedbar-key-map
3877 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
3879 ;; Basic tree features
3880 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
3881 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
3882 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
3883 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
3886 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
3887 Info-speedbar-key-map
3888 Info-speedbar-hierarchy-buttons)))
3890 (defvar Info-speedbar-menu-items
3891 '(["Browse Node" speedbar-edit-line t]
3892 ["Expand Node" speedbar-expand-line
3893 (save-excursion (beginning-of-line)
3894 (looking-at "[0-9]+: *.\\+. "))]
3895 ["Contract Node" speedbar-contract-line
3896 (save-excursion (beginning-of-line)
3897 (looking-at "[0-9]+: *.-. "))]
3899 "Additional menu-items to add to speedbar frame.")
3901 ;; Make sure our special speedbar major mode is loaded
3902 (if (featurep 'speedbar)
3903 (Info-install-speedbar-variables)
3904 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
3906 ;;; Info hierarchy display method
3908 (defun Info-speedbar-browser ()
3909 "Initialize speedbar to display an info node browser.
3910 This will add a speedbar major display mode."
3913 ;; Make sure that speedbar is active
3914 (speedbar-frame-mode 1)
3915 ;; Now, throw us into Info mode on speedbar.
3916 (speedbar-change-initial-expansion-list "Info")
3919 (eval-when-compile (defvar speedbar-attached-frame))
3921 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
3922 "Display an Info directory hierarchy in speedbar.
3923 DIRECTORY is the current directory in the attached frame.
3924 DEPTH is the current indentation depth.
3925 NODE is an optional argument that is used to represent the
3926 specific node to expand."
3928 (save-excursion (goto-char (point-min))
3929 (let ((case-fold-search t))
3930 (looking-at "Info Nodes:"))))
3931 ;; Update our "current node" maybe?
3933 ;; We cannot use the generic list code, that depends on all leaves
3934 ;; being known at creation time.
3936 (speedbar-with-writable (insert "Info Nodes:\n")))
3937 (let ((completions nil)
3938 (cf (selected-frame)))
3939 (select-frame speedbar-attached-frame)
3940 (save-window-excursion
3942 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
3945 (speedbar-with-writable
3946 (dolist (completion completions)
3947 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
3950 'Info-speedbar-goto-node
3956 (defun Info-speedbar-goto-node (text node indent)
3957 "When user clicks on TEXT, go to an info NODE.
3958 The INDENT level is ignored."
3959 (select-frame speedbar-attached-frame)
3960 (let* ((buff (or (get-buffer "*info*")
3961 (progn (info) (get-buffer "*info*"))))
3962 (bwin (get-buffer-window buff 0)))
3965 (select-window bwin)
3966 (raise-frame (window-frame bwin)))
3967 (if speedbar-power-click
3968 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
3969 (select-frame speedbar-attached-frame)
3970 (switch-to-buffer buff)))
3971 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
3972 (error "Invalid node %s" node)
3973 (Info-find-node (match-string 1 node) (match-string 2 node))
3974 ;; If we do a find-node, and we were in info mode, restore
3975 ;; the old default method. Once we are in info mode, it makes
3976 ;; sense to return to whatever method the user was using before.
3977 (if (string= speedbar-initial-expansion-list-name "Info")
3978 (speedbar-change-initial-expansion-list
3979 speedbar-previously-used-expansion-list-name)))))
3981 (defun Info-speedbar-expand-node (text token indent)
3982 "Expand the node the user clicked on.
3983 TEXT is the text of the button we clicked on, a + or - item.
3984 TOKEN is data related to this node (NAME . FILE).
3985 INDENT is the current indentation depth."
3986 (cond ((string-match "+" text) ;we have to expand this file
3987 (speedbar-change-expand-button-char ?-)
3988 (if (speedbar-with-writable
3990 (end-of-line) (forward-char 1)
3991 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
3992 (speedbar-change-expand-button-char ?-)
3993 (speedbar-change-expand-button-char ??)))
3994 ((string-match "-" text) ;we have to contract this node
3995 (speedbar-change-expand-button-char ?+)
3996 (speedbar-delete-subblock indent))
3997 (t (error "Ooops... not sure what to do")))
3998 (speedbar-center-buffer-smartly))
4000 (defun Info-speedbar-fetch-file-nodes (nodespec)
4001 "Fetch the subnodes from the info NODESPEC.
4002 NODESPEC is a string of the form: (file)node.
4003 Optional THISFILE represends the filename of"
4005 ;; Set up a buffer we can use to fake-out Info.
4006 (set-buffer (get-buffer-create "*info-browse-tmp*"))
4007 (if (not (equal major-mode 'Info-mode))
4009 ;; Get the node into this buffer
4010 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4011 (error "Invalid node specification %s" nodespec)
4012 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4013 ;; Scan the created buffer
4014 (goto-char (point-min))
4015 (let ((completions nil)
4016 (case-fold-search t)
4017 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4018 (match-string 1 nodespec))))
4019 ;; Always skip the first one...
4020 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4021 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4022 (let ((name (match-string 1)))
4024 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4026 (if (looking-at " *\\(([^)]+)\\)\\.")
4027 (concat (match-string 1) "Top")
4028 (concat "(" thisfile ")"
4029 (if (looking-at " \\([^.]+\\).")
4033 (nreverse completions))))
4035 ;;; Info mode node listing
4036 ;; FIXME: Seems not to be used. -stef
4037 (defun Info-speedbar-buttons (buffer)
4038 "Create a speedbar display to help navigation in an Info file.
4039 BUFFER is the buffer speedbar is requesting buttons for."
4040 (if (save-excursion (goto-char (point-min))
4041 (let ((case-fold-search t))
4042 (not (looking-at "Info Nodes:"))))
4044 (Info-speedbar-hierarchy-buttons nil 0)
4047 (dolist (mess '("^Node has no Previous$"
4048 "^No menu in this node$"
4049 "^Node has no Next$"
4050 "^No cross-references in this node^"
4052 "^No \".*\" in index$"))
4053 (add-to-list 'debug-ignored-errors mess))
4055 ;;;; Desktop support
4057 (defun Info-desktop-buffer-misc-data (desktop-dirname)
4058 "Auxiliary information to be saved in desktop file."
4059 (if (not (member Info-current-file '("apropos" "history" "toc")))
4060 (list Info-current-file Info-current-node)))
4063 (defun Info-restore-desktop-buffer (desktop-buffer-file-name
4065 desktop-buffer-misc)
4066 "Restore an info buffer specified in a desktop file."
4067 (let ((first (nth 0 desktop-buffer-misc))
4068 (second (nth 1 desktop-buffer-misc)))
4069 (when (and first second)
4070 (when desktop-buffer-name
4071 (set-buffer (get-buffer-create desktop-buffer-name))
4073 (Info-find-node first second)
4078 ;;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
4079 ;;; info.el ends here