* mail/unrmail.el (unrmail): Make sure the message ends with two
[emacs.git] / lisp / info.el
blob03618cc098d2e7318984432a0b123e13341d2a8a
1 ;;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 ;; Free Software Foundation, Inc.
7 ;; Maintainer: FSF
8 ;; Keywords: help
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Note that nowadays we expect Info files to be made using makeinfo.
28 ;; In particular we make these assumptions:
29 ;; - a menu item MAY contain colons but not colon-space ": "
30 ;; - a menu item ending with ": " (but not ":: ") is an index entry
31 ;; - a node name MAY NOT contain a colon
32 ;; This distinction is to support indexing of computer programming
33 ;; language terms that may contain ":" but not ": ".
35 ;;; Code:
37 (eval-when-compile (require 'jka-compr) (require 'cl))
39 (defgroup info nil
40 "Info subsystem."
41 :group 'help
42 :group 'docs)
45 (defvar Info-history nil
46 "Stack of Info nodes user has visited.
47 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
49 (defvar Info-history-forward nil
50 "Stack of Info nodes user has visited with `Info-history-back' command.
51 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
53 (defvar Info-history-list nil
54 "List of all Info nodes user has visited.
55 Each element of the list is a list (FILENAME NODENAME).")
57 (defcustom Info-enable-edit nil
58 "Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
59 This is convenient if you want to write Info files by hand.
60 However, we recommend that you not do this.
61 It is better to write a Texinfo file and generate the Info file from that,
62 because that gives you a printed manual as well."
63 :type 'boolean
64 :group 'info)
66 (defvar Info-enable-active-nodes nil
67 "Non-nil allows Info to execute Lisp code associated with nodes.
68 The Lisp code is executed when the node is selected.")
69 (put 'Info-enable-active-nodes 'risky-local-variable t)
71 (defface info-node
72 '((((class color) (background light)) :foreground "brown" :weight bold :slant italic)
73 (((class color) (background dark)) :foreground "white" :weight bold :slant italic)
74 (t :weight bold :slant italic))
75 "Face for Info node names."
76 :group 'info)
78 (defface info-title-1
79 '((((type tty pc) (class color) (background light))
80 :foreground "green" :weight bold)
81 (((type tty pc) (class color) (background dark))
82 :foreground "yellow" :weight bold)
83 (t :height 1.2 :inherit info-title-2))
84 "Face for info titles at level 1."
85 :group 'info)
86 ;; backward-compatibility alias
87 (put 'Info-title-1-face 'face-alias 'info-title-1)
89 (defface info-title-2
90 '((((type tty pc) (class color)) :foreground "lightblue" :weight bold)
91 (t :height 1.2 :inherit info-title-3))
92 "Face for info titles at level 2."
93 :group 'info)
94 ;; backward-compatibility alias
95 (put 'Info-title-2-face 'face-alias 'info-title-2)
97 (defface info-title-3
98 '((((type tty pc) (class color)) :weight bold)
99 (t :height 1.2 :inherit info-title-4))
100 "Face for info titles at level 3."
101 :group 'info)
102 ;; backward-compatibility alias
103 (put 'Info-title-3-face 'face-alias 'info-title-3)
105 (defface info-title-4
106 '((((type tty pc) (class color)) :weight bold)
107 (t :weight bold :inherit variable-pitch))
108 "Face for info titles at level 4."
109 :group 'info)
110 ;; backward-compatibility alias
111 (put 'Info-title-4-face 'face-alias 'info-title-4)
113 (defface info-menu-header
114 '((((type tty pc))
115 :underline t
116 :weight bold)
118 :inherit variable-pitch
119 :weight bold))
120 "Face for headers in Info menus."
121 :group 'info)
123 (defface info-menu-star
124 '((((class color)) :foreground "red1")
125 (t :underline t))
126 "Face for every third `*' in an Info menu."
127 :group 'info)
128 (put 'info-menu-5 'face-alias 'info-menu-star)
130 (defface info-xref
131 '((t :inherit link))
132 "Face for unvisited Info cross-references."
133 :group 'info)
135 (defface info-xref-visited
136 '((t :inherit (link-visited info-xref)))
137 "Face for visited Info cross-references."
138 :version "22.1"
139 :group 'info)
141 (defcustom Info-fontify-visited-nodes t
142 "Non-nil to fontify references to visited nodes in `info-xref-visited' face."
143 :version "22.1"
144 :type 'boolean
145 :group 'info)
147 (defcustom Info-fontify-maximum-menu-size 100000
148 "Maximum size of menu to fontify if `font-lock-mode' is non-nil.
149 Set to nil to disable node fontification."
150 :type 'integer
151 :group 'info)
153 (defcustom Info-use-header-line t
154 "Non-nil means to put the beginning-of-node links in an Emacs header-line.
155 A header-line does not scroll with the rest of the buffer."
156 :type 'boolean
157 :group 'info)
159 (defface info-header-xref
160 '((t :inherit info-xref))
161 "Face for Info cross-references in a node header."
162 :group 'info)
164 (defface info-header-node
165 '((t :inherit info-node))
166 "Face for Info nodes in a node header."
167 :group 'info)
169 (defvar Info-directory-list nil
170 "List of directories to search for Info documentation files.
171 If nil, meaning not yet initialized, Info uses the environment
172 variable INFOPATH to initialize it, or `Info-default-directory-list'
173 if there is no INFOPATH variable in the environment, or the
174 concatenation of the two if INFOPATH ends with a colon.
176 When `Info-directory-list' is initialized from the value of
177 `Info-default-directory-list', and Emacs is installed in one of the
178 standard directories, the directory of Info files that come with Emacs
179 is put last (so that local Info files override standard ones).
181 When `Info-directory-list' is initialized from the value of
182 `Info-default-directory-list', and Emacs is not installed in one
183 of the standard directories, the first element of the resulting
184 list is the directory where Emacs installs the Info files that
185 come with it. This is so that Emacs's own manual, which suits the
186 version of Emacs you are using, will always be found first. This
187 is useful when you install an experimental version of Emacs without
188 removing the standard installation.
190 If you want to override the order of directories in
191 `Info-default-directory-list', set INFOPATH in the environment.
193 If you run the Emacs executable from the `src' directory in the Emacs
194 source tree, and INFOPATH is not defined, the `info' directory in the
195 source tree is used as the first element of `Info-directory-list', in
196 place of the installation Info directory. This is useful when you run
197 a version of Emacs without installing it.")
199 (defcustom Info-additional-directory-list nil
200 "List of additional directories to search for Info documentation files.
201 These directories are searched after those in `Info-directory-list'."
202 :type '(repeat directory)
203 :group 'info)
205 (defcustom Info-scroll-prefer-subnodes nil
206 "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
208 If this is non-nil, and you scroll far enough in a node that its menu
209 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
210 moves to a subnode indicated by the following menu item. This means
211 that you visit a subnode before getting to the end of the menu.
213 Setting this option to nil results in behavior similar to the stand-alone
214 Info reader program, which visits the first subnode from the menu only
215 when you hit the end of the current node."
216 :version "22.1"
217 :type 'boolean
218 :group 'info)
220 (defcustom Info-hide-note-references t
221 "If non-nil, hide the tag and section reference in *note and * menu items.
222 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
223 If value is non-nil but not t or `hide', the reference section is still shown.
224 `nil' completely disables this feature. If this is non-nil, you might
225 want to set `Info-refill-paragraphs'."
226 :version "22.1"
227 :type '(choice (const :tag "No hiding" nil)
228 (const :tag "Replace tag and hide reference" t)
229 (const :tag "Hide tag and reference" hide)
230 (other :tag "Only replace tag" tag))
231 :group 'info)
233 (defcustom Info-refill-paragraphs nil
234 "If non-nil, attempt to refill paragraphs with hidden references.
235 This refilling may accidentally remove explicit line breaks in the Info
236 file, so be prepared for a few surprises if you enable this feature.
237 This only has an effect if `Info-hide-note-references' is non-nil."
238 :version "22.1"
239 :type 'boolean
240 :group 'info)
242 (defcustom Info-breadcrumbs-depth 4
243 "Depth of breadcrumbs to display.
244 0 means do not display breadcrumbs."
245 :type 'integer)
247 (defcustom Info-search-whitespace-regexp "\\s-+"
248 "If non-nil, regular expression to match a sequence of whitespace chars.
249 This applies to Info search for regular expressions.
250 You might want to use something like \"[ \\t\\r\\n]+\" instead.
251 In the Customization buffer, that is `[' followed by a space,
252 a tab, a carriage return (control-M), a newline, and `]+'."
253 :type 'regexp
254 :group 'info)
256 (defcustom Info-isearch-search t
257 "If non-nil, isearch in Info searches through multiple nodes.
258 Before leaving the initial Info node, where isearch was started,
259 it fails once with the error message [initial node], and with
260 subsequent C-s/C-r continues through other nodes without failing
261 with this error message in other nodes. When isearch fails for
262 the rest of the manual, it wraps aroung the whole manual and
263 restarts the search from the top/final node depending on
264 search direction.
266 Setting this option to nil restores the default isearch behavior
267 with wrapping around the current Info node."
268 :version "22.1"
269 :type 'boolean
270 :group 'info)
272 (defvar Info-isearch-initial-node nil)
274 (defcustom Info-mode-hook
275 ;; Try to obey obsolete Info-fontify settings.
276 (unless (and (boundp 'Info-fontify) (null Info-fontify))
277 '(turn-on-font-lock))
278 "Hooks run when `Info-mode' is called."
279 :type 'hook
280 :group 'info)
282 (defcustom Info-selection-hook nil
283 "Hooks run when `Info-select-node' is called."
284 :type 'hook
285 :group 'info)
287 (defvar Info-edit-mode-hook nil
288 "Hooks run when `Info-edit-mode' is called.")
290 (defvar Info-current-file nil
291 "Info file that Info is now looking at, or nil.
292 This is the name that was specified in Info, not the actual file name.
293 It doesn't contain directory names or file name extensions added by Info.")
295 (defvar Info-current-subfile nil
296 "Info subfile that is actually in the *info* buffer now.
297 It is nil if current Info file is not split into subfiles.")
299 (defvar Info-current-node nil
300 "Name of node that Info is now looking at, or nil.")
302 (defvar Info-tag-table-marker nil
303 "Marker pointing at beginning of current Info file's tag table.
304 Marker points nowhere if file has no tag table.")
306 (defvar Info-tag-table-buffer nil
307 "Buffer used for indirect tag tables.")
309 (defvar Info-current-file-completions nil
310 "Cached completion list for current Info file.")
312 (defvar Info-file-supports-index-cookies nil
313 "Non-nil if current Info file supports index cookies.")
315 (defvar Info-file-supports-index-cookies-list nil
316 "List of Info files with information about index cookies support.
317 Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
318 where SUPPORTS-INDEX-COOKIES can be either t or nil.")
320 (defvar Info-index-alternatives nil
321 "List of possible matches for last `Info-index' command.")
323 (defvar Info-point-loc nil
324 "Point location within a selected node.
325 If string, the point is moved to the proper occurrence of the
326 name of the followed cross reference within a selected node.
327 If number, the point is moved to the corresponding line.")
329 (defvar Info-standalone nil
330 "Non-nil if Emacs was started solely as an Info browser.")
332 (defvar Info-virtual-files nil
333 "List of definitions of virtual Info files.
334 Each element of the list has the format (FILENAME (OPERATION . HANDLER) ...)
335 where FILENAME is a regexp that matches a class of virtual Info file names.
336 It should be carefully chosen to not cause file name clashes with
337 existing file names. OPERATION is one of the following operation
338 symbols `find-file', `find-node', `toc-nodes' that define what HANDLER
339 function to call instead of calling the default corresponding function
340 to override it.")
342 (defvar Info-virtual-nodes nil
343 "List of definitions of virtual Info nodes.
344 Each element of the list has the format (NODENAME (OPERATION . HANDLER) ...)
345 where NODENAME is a regexp that matches a class of virtual Info node names.
346 It should be carefully chosen to not cause node name clashes with
347 existing node names. OPERATION is one of the following operation
348 symbols `find-node' that define what HANDLER
349 function to call instead of calling the default corresponding function
350 to override it.")
352 (defvar Info-current-node-virtual nil
353 "Non-nil if the current Info node is virtual.")
355 (defun Info-virtual-file-p (filename)
356 "Check if Info file FILENAME is virtual."
357 (Info-virtual-fun 'find-file filename nil))
359 (defun Info-virtual-fun (op filename nodename)
360 "Find a function that handles operations on virtual manuals.
361 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
362 FILENAME is a virtual Info file name, NODENAME is a virtual Info
363 node name. Return a function found either in `Info-virtual-files'
364 or `Info-virtual-nodes'."
365 (or (and (stringp filename) ; some legacy code can still use a symbol
366 (cdr-safe (assoc op (assoc-default filename
367 Info-virtual-files
368 'string-match))))
369 (and (stringp nodename) ; some legacy code can still use a symbol
370 (cdr-safe (assoc op (assoc-default nodename
371 Info-virtual-nodes
372 'string-match))))))
374 (defun Info-virtual-call (virtual-fun &rest args)
375 "Call a function that handles operations on virtual manuals."
376 (when (functionp virtual-fun)
377 (or (apply virtual-fun args) t)))
380 (defvar Info-suffix-list
381 ;; The MS-DOS list should work both when long file names are
382 ;; supported (Windows 9X), and when only 8+3 file names are available.
383 (if (eq system-type 'ms-dos)
384 '( (".gz" . "gunzip")
385 (".z" . "gunzip")
386 (".bz2" . ("bzip2" "-dc"))
387 (".inz" . "gunzip")
388 (".igz" . "gunzip")
389 (".info.Z" . "gunzip")
390 (".info.gz" . "gunzip")
391 ("-info.Z" . "gunzip")
392 ("-info.gz" . "gunzip")
393 ("/index.gz". "gunzip")
394 ("/index.z" . "gunzip")
395 (".inf" . nil)
396 (".info" . nil)
397 ("-info" . nil)
398 ("/index" . nil)
399 ("" . nil))
400 '( (".info.Z". "uncompress")
401 (".info.Y". "unyabba")
402 (".info.gz". "gunzip")
403 (".info.z". "gunzip")
404 (".info.bz2" . ("bzip2" "-dc"))
405 (".info". nil)
406 ("-info.Z". "uncompress")
407 ("-info.Y". "unyabba")
408 ("-info.gz". "gunzip")
409 ("-info.bz2" . ("bzip2" "-dc"))
410 ("-info.z". "gunzip")
411 ("-info". nil)
412 ("/index.Z". "uncompress")
413 ("/index.Y". "unyabba")
414 ("/index.gz". "gunzip")
415 ("/index.z". "gunzip")
416 ("/index.bz2". ("bzip2" "-dc"))
417 ("/index". nil)
418 (".Z". "uncompress")
419 (".Y". "unyabba")
420 (".gz". "gunzip")
421 (".z". "gunzip")
422 (".bz2" . ("bzip2" "-dc"))
423 ("". nil)))
424 "List of file name suffixes and associated decoding commands.
425 Each entry should be (SUFFIX . STRING); the file is given to
426 the command as standard input.
428 STRING may be a list of strings. In that case, the first element is
429 the command name, and the rest are arguments to that command.
431 If STRING is nil, no decoding is done.
432 Because the SUFFIXes are tried in order, the empty string should
433 be last in the list.")
435 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
436 ;; First, on MS-DOS with no long file names support, delete some of
437 ;; the extension in FILENAME to make room.
438 (defun info-insert-file-contents-1 (filename suffix lfn)
439 (if lfn ; long file names are supported
440 (concat filename suffix)
441 (let* ((sans-exts (file-name-sans-extension filename))
442 ;; How long is the extension in FILENAME (not counting the dot).
443 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
444 ext-left)
445 ;; SUFFIX starts with a dot. If FILENAME already has one,
446 ;; get rid of the one in SUFFIX (unless suffix is empty).
447 (or (and (<= ext-len 0)
448 (not (eq (aref filename (1- (length filename))) ?.)))
449 (= (length suffix) 0)
450 (setq suffix (substring suffix 1)))
451 ;; How many chars of that extension should we keep?
452 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
453 ;; Get rid of the rest of the extension, and add SUFFIX.
454 (concat (substring filename 0 (- (length filename)
455 (- ext-len ext-left)))
456 suffix))))
458 (defun info-file-exists-p (filename)
459 (and (file-exists-p filename)
460 (not (file-directory-p filename))))
462 (defun info-insert-file-contents (filename &optional visit)
463 "Insert the contents of an Info file in the current buffer.
464 Do the right thing if the file has been compressed or zipped."
465 (let* ((tail Info-suffix-list)
466 (lfn (if (fboundp 'msdos-long-file-names)
467 (msdos-long-file-names)
469 (check-short (and (fboundp 'msdos-long-file-names)
470 lfn))
471 fullname decoder done)
472 (if (info-file-exists-p filename)
473 ;; FILENAME exists--see if that name contains a suffix.
474 ;; If so, set DECODE accordingly.
475 (progn
476 (while (and tail
477 (not (string-match
478 (concat (regexp-quote (car (car tail))) "$")
479 filename)))
480 (setq tail (cdr tail)))
481 (setq fullname filename
482 decoder (cdr (car tail))))
483 ;; Try adding suffixes to FILENAME and see if we can find something.
484 (while (and tail (not done))
485 (setq fullname (info-insert-file-contents-1 filename
486 (car (car tail)) lfn))
487 (if (info-file-exists-p fullname)
488 (setq done t
489 ;; If we found a file with a suffix, set DECODER
490 ;; according to the suffix.
491 decoder (cdr (car tail)))
492 ;; When the MS-DOS port runs on Windows, we need to check
493 ;; the short variant of a long file name as well.
494 (when check-short
495 (setq fullname (info-insert-file-contents-1 filename
496 (car (car tail)) nil))
497 (if (info-file-exists-p fullname)
498 (setq done t
499 decoder (cdr (car tail))))))
500 (setq tail (cdr tail)))
501 (or tail
502 (error "Can't find %s or any compressed version of it" filename)))
503 ;; check for conflict with jka-compr
504 (if (and (jka-compr-installed-p)
505 (jka-compr-get-compression-info fullname))
506 (setq decoder nil))
507 (if decoder
508 (progn
509 (insert-file-contents-literally fullname visit)
510 (let ((inhibit-read-only t)
511 (coding-system-for-write 'no-conversion)
512 (inhibit-null-byte-detection t) ; Index nodes include null bytes
513 (default-directory (or (file-name-directory fullname)
514 default-directory)))
515 (or (consp decoder)
516 (setq decoder (list decoder)))
517 (apply 'call-process-region (point-min) (point-max)
518 (car decoder) t t nil (cdr decoder))))
519 (let ((inhibit-null-byte-detection t)) ; Index nodes include null bytes
520 (insert-file-contents fullname visit)))))
522 (defun Info-file-supports-index-cookies (&optional file)
523 "Return non-nil value if FILE supports Info index cookies.
524 Info index cookies were first introduced in 4.7, and all later
525 makeinfo versions output them in index nodes, so we can rely
526 solely on the makeinfo version. This function caches the information
527 in `Info-file-supports-index-cookies-list'."
528 (or file (setq file Info-current-file))
529 (or (assoc file Info-file-supports-index-cookies-list)
530 ;; Skip virtual Info files
531 (and (or (not (stringp file))
532 (Info-virtual-file-p file))
533 (setq Info-file-supports-index-cookies-list
534 (cons (cons file nil) Info-file-supports-index-cookies-list)))
535 (save-excursion
536 (let ((found nil))
537 (goto-char (point-min))
538 (condition-case ()
539 (if (and (re-search-forward
540 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
541 (line-beginning-position 3) t)
542 (not (version< (match-string 1) "4.7")))
543 (setq found t))
544 (error nil))
545 (setq Info-file-supports-index-cookies-list
546 (cons (cons file found) Info-file-supports-index-cookies-list)))))
547 (cdr (assoc file Info-file-supports-index-cookies-list)))
550 (defun Info-default-dirs ()
551 (let ((source (expand-file-name "info/" source-directory))
552 (sibling (if installation-directory
553 (expand-file-name "info/" installation-directory)
554 (if invocation-directory
555 (let ((infodir (expand-file-name
556 "../share/info/"
557 invocation-directory)))
558 (if (file-exists-p infodir)
559 infodir
560 (setq infodir (expand-file-name
561 "../../../share/info/"
562 invocation-directory))
563 (and (file-exists-p infodir)
564 infodir))))))
565 alternative)
566 (setq alternative
567 (if (and sibling (file-exists-p sibling))
568 ;; Uninstalled, Emacs builddir != srcdir.
569 sibling
570 ;; Uninstalled, builddir == srcdir
571 source))
572 (if (or (member alternative Info-default-directory-list)
573 ;; On DOS/NT, we use movable executables always,
574 ;; and we must always find the Info dir at run time.
575 (if (memq system-type '(ms-dos windows-nt))
577 ;; Use invocation-directory for Info
578 ;; only if we used it for exec-directory also.
579 (not (string= exec-directory
580 (expand-file-name "lib-src/"
581 installation-directory))))
582 (not (file-exists-p alternative)))
583 Info-default-directory-list
584 ;; `alternative' contains the Info files that came with this
585 ;; version, so we should look there first. `Info-insert-dir'
586 ;; currently expects to find `alternative' first on the list.
587 (cons alternative
588 ;; Don't drop the last part, it might contain non-Emacs stuff.
589 ;; (reverse (cdr (reverse
590 Info-default-directory-list)))) ;; )))
592 (defun info-initialize ()
593 "Initialize `Info-directory-list', if that hasn't been done yet."
594 (unless Info-directory-list
595 (let ((path (getenv "INFOPATH")))
596 (setq Info-directory-list
597 (prune-directory-list
598 (if path
599 (if (string-match ":\\'" path)
600 (append (split-string (substring path 0 -1)
601 (regexp-quote path-separator))
602 (Info-default-dirs))
603 (split-string path (regexp-quote path-separator)))
604 (Info-default-dirs)))))))
606 ;;;###autoload
607 (defun info-other-window (&optional file-or-node)
608 "Like `info' but show the Info buffer in another window."
609 (interactive (if current-prefix-arg
610 (list (read-file-name "Info file name: " nil nil t))))
611 (let (same-window-buffer-names same-window-regexps)
612 (info file-or-node)))
614 ;;;###autoload (add-hook 'same-window-regexps "\\*info\\*\\(\\|<[0-9]+>\\)")
616 ;;;###autoload (put 'info 'info-file "emacs")
617 ;;;###autoload
618 (defun info (&optional file-or-node buffer)
619 "Enter Info, the documentation browser.
620 Optional argument FILE-OR-NODE specifies the file to examine;
621 the default is the top-level directory of Info.
622 Called from a program, FILE-OR-NODE may specify an Info node of the form
623 `(FILENAME)NODENAME'.
624 Optional argument BUFFER specifies the Info buffer name;
625 the default buffer name is *info*. If BUFFER exists,
626 just switch to BUFFER. Otherwise, create a new buffer
627 with the top-level Info directory.
629 In interactive use, a non-numeric prefix argument directs
630 this command to read a file name from the minibuffer.
631 A numeric prefix argument selects an Info buffer with the prefix number
632 appended to the Info buffer name.
634 The search path for Info files is in the variable `Info-directory-list'.
635 The top-level Info directory is made by combining all the files named `dir'
636 in all the directories in that path.
638 See a list of available Info commands in `Info-mode'."
639 (interactive (list
640 (if (and current-prefix-arg (not (numberp current-prefix-arg)))
641 (read-file-name "Info file name: " nil nil t))
642 (if (numberp current-prefix-arg)
643 (format "*info*<%s>" current-prefix-arg))))
644 (pop-to-buffer (or buffer "*info*"))
645 (if (and buffer (not (eq major-mode 'Info-mode)))
646 (Info-mode))
647 (if file-or-node
648 ;; If argument already contains parentheses, don't add another set
649 ;; since the argument will then be parsed improperly. This also
650 ;; has the added benefit of allowing node names to be included
651 ;; following the parenthesized filename.
652 (Info-goto-node
653 (if (and (stringp file-or-node) (string-match "(.*)" file-or-node))
654 file-or-node
655 (concat "(" file-or-node ")")))
656 (if (and (zerop (buffer-size))
657 (null Info-history))
658 ;; If we just created the Info buffer, go to the directory.
659 (Info-directory))))
661 ;;;###autoload
662 (defun info-emacs-manual ()
663 "Display the Emacs manual in Info mode."
664 (interactive)
665 (info "emacs"))
667 ;;;###autoload
668 (defun info-standalone ()
669 "Run Emacs as a standalone Info reader.
670 Usage: emacs -f info-standalone [filename]
671 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
672 (setq Info-standalone t)
673 (if (and command-line-args-left
674 (not (string-match "^-" (car command-line-args-left))))
675 (condition-case err
676 (progn
677 (info (car command-line-args-left))
678 (setq command-line-args-left (cdr command-line-args-left)))
679 (error (send-string-to-terminal
680 (format "%s\n" (if (eq (car-safe err) 'error)
681 (nth 1 err) err)))
682 (save-buffers-kill-emacs)))
683 (info)))
685 ;; See if the accessible portion of the buffer begins with a node
686 ;; delimiter, and the node header line which follows matches REGEXP.
687 ;; Typically, this test will be followed by a loop that examines the
688 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
689 ;; to have the overhead of this special test inside the loop.
691 ;; This function changes match-data, but supposedly the caller might
692 ;; want to use the results of re-search-backward.
694 ;; The return value is the value of point at the beginning of matching
695 ;; REGEXP, if the function succeeds, nil otherwise.
696 (defun Info-node-at-bob-matching (regexp)
697 (and (bobp) ; are we at beginning of buffer?
698 (looking-at "\^_") ; does it begin with node delimiter?
699 (let (beg)
700 (forward-line 1)
701 (setq beg (point))
702 (forward-line 1) ; does the line after delimiter match REGEXP?
703 (re-search-backward regexp beg t))))
705 (defun Info-find-file (filename &optional noerror)
706 "Return expanded FILENAME, or t, if FILENAME is \"dir\".
707 Optional second argument NOERROR, if t, means if file is not found
708 just return nil (no error)."
709 ;; Convert filename to lower case if not found as specified.
710 ;; Expand it.
711 (cond
712 ((Info-virtual-call
713 (Info-virtual-fun 'find-file filename nil)
714 filename noerror))
715 ((stringp filename)
716 (let (temp temp-downcase found)
717 (setq filename (substitute-in-file-name filename))
718 (let ((dirs (if (string-match "^\\./" filename)
719 ;; If specified name starts with `./'
720 ;; then just try current directory.
721 '("./")
722 (if (file-name-absolute-p filename)
723 ;; No point in searching for an
724 ;; absolute file name
725 '(nil)
726 (if Info-additional-directory-list
727 (append Info-directory-list
728 Info-additional-directory-list)
729 Info-directory-list)))))
730 ;; Search the directory list for file FILENAME.
731 (while (and dirs (not found))
732 (setq temp (expand-file-name filename (car dirs)))
733 (setq temp-downcase
734 (expand-file-name (downcase filename) (car dirs)))
735 ;; Try several variants of specified name.
736 (let ((suffix-list Info-suffix-list)
737 (lfn (if (fboundp 'msdos-long-file-names)
738 (msdos-long-file-names)
739 t)))
740 (while (and suffix-list (not found))
741 (cond ((info-file-exists-p
742 (info-insert-file-contents-1
743 temp (car (car suffix-list)) lfn))
744 (setq found temp))
745 ((info-file-exists-p
746 (info-insert-file-contents-1
747 temp-downcase (car (car suffix-list)) lfn))
748 (setq found temp-downcase))
749 ((and (fboundp 'msdos-long-file-names)
751 (info-file-exists-p
752 (info-insert-file-contents-1
753 temp (car (car suffix-list)) nil)))
754 (setq found temp)))
755 (setq suffix-list (cdr suffix-list))))
756 (setq dirs (cdr dirs))))
757 (if found
758 (setq filename found)
759 (if noerror
760 (setq filename nil)
761 (error "Info file %s does not exist" filename)))
762 filename))))
764 (defun Info-find-node (filename nodename &optional no-going-back)
765 "Go to an Info node specified as separate FILENAME and NODENAME.
766 NO-GOING-BACK is non-nil if recovering from an error in this function;
767 it says do not attempt further (recursive) error recovery."
768 (info-initialize)
769 (setq filename (Info-find-file filename))
770 ;; Go into Info buffer.
771 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
772 ;; Record the node we are leaving, if we were in one.
773 (and (not no-going-back)
774 Info-current-file
775 (push (list Info-current-file Info-current-node (point))
776 Info-history))
777 (Info-find-node-2 filename nodename no-going-back))
779 ;;;###autoload
780 (defun Info-on-current-buffer (&optional nodename)
781 "Use Info mode to browse the current Info buffer.
782 With a prefix arg, this queries for the node name to visit first;
783 otherwise, that defaults to `Top'."
784 (interactive
785 (list (if current-prefix-arg
786 (completing-read "Node name: " (Info-build-node-completions)
787 nil t "Top"))))
788 (unless nodename (setq nodename "Top"))
789 (info-initialize)
790 (Info-mode)
791 (set (make-local-variable 'Info-current-file)
792 (or buffer-file-name
793 ;; If called on a non-file buffer, make a fake file name.
794 (concat default-directory (buffer-name))))
795 (Info-find-node-2 nil nodename))
797 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
798 ;; but at least it keeps this routine (which is for makeinfo-buffer and
799 ;; Info-revert-buffer-function) out of the way of normal operations.
801 (defun Info-revert-find-node (filename nodename)
802 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
803 When *info* is already displaying FILENAME and NODENAME, the window position
804 is preserved, if possible."
805 (pop-to-buffer "*info*")
806 (let ((old-filename Info-current-file)
807 (old-nodename Info-current-node)
808 (pcolumn (current-column))
809 (pline (count-lines (point-min) (line-beginning-position)))
810 (wline (count-lines (point-min) (window-start)))
811 (old-history Info-history)
812 (new-history (and Info-current-file
813 (list Info-current-file Info-current-node (point)))))
814 (kill-buffer (current-buffer))
815 (Info-find-node filename nodename)
816 (setq Info-history old-history)
817 (if (and (equal old-filename Info-current-file)
818 (equal old-nodename Info-current-node))
819 (progn
820 ;; note goto-line is no good, we want to measure from point-min
821 (goto-char (point-min))
822 (forward-line wline)
823 (set-window-start (selected-window) (point))
824 (goto-char (point-min))
825 (forward-line pline)
826 (move-to-column pcolumn))
827 ;; only add to the history when coming from a different file+node
828 (if new-history
829 (setq Info-history (cons new-history Info-history))))))
831 (defun Info-revert-buffer-function (ignore-auto noconfirm)
832 (when (or noconfirm (y-or-n-p "Revert info buffer? "))
833 (Info-revert-find-node Info-current-file Info-current-node)
834 (message "Reverted %s" Info-current-file)))
836 (defun Info-find-in-tag-table-1 (marker regexp case-fold)
837 "Find a node in a tag table.
838 MARKER specifies the buffer and position to start searching at.
839 REGEXP is a regular expression matching nodes or references. Its first
840 group should match `Node:' or `Ref:'.
841 CASE-FOLD t means search for a case-insensitive match.
842 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
843 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
844 where the match was found, and MODE is `major-mode' of the buffer in
845 which the match was found."
846 (let ((case-fold-search case-fold))
847 (with-current-buffer (marker-buffer marker)
848 (goto-char marker)
850 ;; Search tag table
851 (beginning-of-line)
852 (when (re-search-forward regexp nil t)
853 (list (string-equal "Ref:" (match-string 1))
854 (+ (point-min) (read (current-buffer)))
855 major-mode)))))
857 (defun Info-find-in-tag-table (marker regexp)
858 "Find a node in a tag table.
859 MARKER specifies the buffer and position to start searching at.
860 REGEXP is a regular expression matching nodes or references. Its first
861 group should match `Node:' or `Ref:'.
862 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
863 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
864 where the match was found, and MODE is `major-mode' of the buffer in
865 which the match was found.
866 This function tries to find a case-sensitive match first, then a
867 case-insensitive match is tried."
868 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
869 (when (null (car result))
870 (setq result (Info-find-in-tag-table-1 marker regexp t)))
871 result))
873 (defun Info-find-node-in-buffer-1 (regexp case-fold)
874 "Find a node or anchor in the current buffer.
875 REGEXP is a regular expression matching nodes or references. Its first
876 group should match `Node:' or `Ref:'.
877 CASE-FOLD t means search for a case-insensitive match.
878 Value is the position at which a match was found, or nil if not found."
879 (let ((case-fold-search case-fold)
880 found)
881 (save-excursion
882 (when (Info-node-at-bob-matching regexp)
883 (setq found (point)))
884 (while (and (not found)
885 (search-forward "\n\^_" nil t))
886 (forward-line 1)
887 (let ((beg (point)))
888 (forward-line 1)
889 (when (re-search-backward regexp beg t)
890 (beginning-of-line)
891 (setq found (point)))))
892 found)))
894 (defun Info-find-node-in-buffer (regexp)
895 "Find a node or anchor in the current buffer.
896 REGEXP is a regular expression matching nodes or references. Its first
897 group should match `Node:' or `Ref:'.
898 Value is the position at which a match was found, or nil if not found.
899 This function looks for a case-sensitive match first. If none is found,
900 a case-insensitive match is tried."
901 (or (Info-find-node-in-buffer-1 regexp nil)
902 (Info-find-node-in-buffer-1 regexp t)))
904 (defun Info-find-node-2 (filename nodename &optional no-going-back)
905 (buffer-disable-undo (current-buffer))
906 (or (eq major-mode 'Info-mode)
907 (Info-mode))
908 (widen)
909 (setq Info-current-node nil)
910 (unwind-protect
911 (let ((case-fold-search t)
912 (virtual-fun (Info-virtual-fun 'find-node
913 (or filename Info-current-file)
914 nodename))
915 anchorpos)
916 (cond
917 ((functionp virtual-fun)
918 (let ((filename (or filename Info-current-file)))
919 (setq buffer-file-name nil)
920 (setq buffer-read-only nil)
921 (erase-buffer)
922 (setq Info-current-file filename)
923 (Info-virtual-call virtual-fun filename nodename no-going-back)
924 (set-marker Info-tag-table-marker nil)
925 (setq buffer-read-only t)
926 (set-buffer-modified-p nil)
927 (set (make-local-variable 'Info-current-node-virtual) t)))
928 ((not (and
929 ;; Reread a file when moving from a virtual node.
930 (not Info-current-node-virtual)
931 (or (null filename)
932 (equal Info-current-file filename))))
933 ;; Switch files if necessary
934 (let ((inhibit-read-only t))
935 (if (and Info-current-node-virtual (null filename))
936 (setq filename Info-current-file))
937 (setq Info-current-file nil
938 Info-current-subfile nil
939 Info-current-file-completions nil
940 buffer-file-name nil)
941 (erase-buffer)
942 (info-insert-file-contents filename nil)
943 (setq default-directory (file-name-directory filename))
944 (set-buffer-modified-p nil)
945 (set (make-local-variable 'Info-file-supports-index-cookies)
946 (Info-file-supports-index-cookies filename))
948 ;; See whether file has a tag table. Record the location if yes.
949 (goto-char (point-max))
950 (forward-line -8)
951 ;; Use string-equal, not equal, to ignore text props.
952 (if (not (or (string-equal nodename "*")
953 (not
954 (search-forward "\^_\nEnd tag table\n" nil t))))
955 (let (pos)
956 ;; We have a tag table. Find its beginning.
957 ;; Is this an indirect file?
958 (search-backward "\nTag table:\n")
959 (setq pos (point))
960 (if (save-excursion
961 (forward-line 2)
962 (looking-at "(Indirect)\n"))
963 ;; It is indirect. Copy it to another buffer
964 ;; and record that the tag table is in that buffer.
965 (let ((buf (current-buffer))
966 (tagbuf
967 (or Info-tag-table-buffer
968 (generate-new-buffer " *info tag table*"))))
969 (setq Info-tag-table-buffer tagbuf)
970 (with-current-buffer tagbuf
971 (buffer-disable-undo (current-buffer))
972 (setq case-fold-search t)
973 (erase-buffer)
974 (insert-buffer-substring buf))
975 (set-marker Info-tag-table-marker
976 (match-end 0) tagbuf))
977 (set-marker Info-tag-table-marker pos)))
978 (set-marker Info-tag-table-marker nil))
979 (setq Info-current-file filename)
982 ;; Use string-equal, not equal, to ignore text props.
983 (if (string-equal nodename "*")
984 (progn (setq Info-current-node nodename)
985 (Info-set-mode-line))
986 ;; Possibilities:
988 ;; 1. Anchor found in tag table
989 ;; 2. Anchor *not* in tag table
991 ;; 3. Node found in tag table
992 ;; 4. Node *not* found in tag table, but found in file
993 ;; 5. Node *not* in tag table, and *not* in file
995 ;; *Or* the same, but in an indirect subfile.
997 ;; Search file for a suitable node.
998 (let ((guesspos (point-min))
999 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1000 (if (stringp nodename)
1001 (regexp-quote nodename)
1003 "\\) *[,\t\n\177]")))
1005 (catch 'foo
1007 ;; First, search a tag table, if any
1008 (when (marker-position Info-tag-table-marker)
1009 (let* ((m Info-tag-table-marker)
1010 (found (Info-find-in-tag-table m regexp)))
1012 (when found
1013 ;; FOUND is (ANCHOR POS MODE).
1014 (setq guesspos (nth 1 found))
1016 ;; If this is an indirect file, determine which
1017 ;; file really holds this node and read it in.
1018 (unless (eq (nth 2 found) 'Info-mode)
1019 ;; Note that the current buffer must be the
1020 ;; *info* buffer on entry to
1021 ;; Info-read-subfile. Thus the hackery above.
1022 (setq guesspos (Info-read-subfile guesspos)))
1024 ;; Handle anchor
1025 (when (nth 0 found)
1026 (goto-char (setq anchorpos guesspos))
1027 (throw 'foo t)))))
1029 ;; Else we may have a node, which we search for:
1030 (goto-char (max (point-min)
1031 (- (byte-to-position guesspos) 1000)))
1033 ;; Now search from our advised position (or from beg of
1034 ;; buffer) to find the actual node. First, check
1035 ;; whether the node is right where we are, in case the
1036 ;; buffer begins with a node.
1037 (let ((pos (Info-find-node-in-buffer regexp)))
1038 (when pos
1039 (goto-char pos)
1040 (throw 'foo t)))
1042 (when (string-match "\\([^.]+\\)\\." nodename)
1043 (let (Info-point-loc)
1044 (Info-find-node-2
1045 filename (match-string 1 nodename) no-going-back))
1046 (widen)
1047 (throw 'foo t))
1049 ;; No such anchor in tag table or node in tag table or file
1050 (error "No such node or anchor: %s" nodename))
1052 (Info-select-node)
1053 (goto-char (point-min))
1054 (forward-line 1) ; skip header line
1055 (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1056 (forward-line 1))
1058 (cond (anchorpos
1059 (let ((new-history (list Info-current-file
1060 (substring-no-properties nodename))))
1061 ;; Add anchors to the history too
1062 (setq Info-history-list
1063 (cons new-history
1064 (delete new-history Info-history-list))))
1065 (goto-char anchorpos))
1066 ((numberp Info-point-loc)
1067 (forward-line (- Info-point-loc 2))
1068 (setq Info-point-loc nil))
1069 ((stringp Info-point-loc)
1070 (Info-find-index-name Info-point-loc)
1071 (setq Info-point-loc nil))))))
1072 ;; If we did not finish finding the specified node,
1073 ;; go back to the previous one.
1074 (or Info-current-node no-going-back (null Info-history)
1075 (let ((hist (car Info-history)))
1076 (setq Info-history (cdr Info-history))
1077 (Info-find-node (nth 0 hist) (nth 1 hist) t)
1078 (goto-char (nth 2 hist))))))
1080 ;; Cache the contents of the (virtual) dir file, once we have merged
1081 ;; it for the first time, so we can save time subsequently.
1082 (defvar Info-dir-contents nil)
1084 ;; Cache for the directory we decided to use for the default-directory
1085 ;; of the merged dir text.
1086 (defvar Info-dir-contents-directory nil)
1088 ;; Record the file attributes of all the files from which we
1089 ;; constructed Info-dir-contents.
1090 (defvar Info-dir-file-attributes nil)
1092 (defvar Info-dir-file-name nil)
1094 ;; Construct the Info directory node by merging the files named `dir'
1095 ;; from various directories. Set the *info* buffer's
1096 ;; default-directory to the first directory we actually get any text
1097 ;; from.
1098 (defun Info-insert-dir ()
1099 (if (and Info-dir-contents Info-dir-file-attributes
1100 ;; Verify that none of the files we used has changed
1101 ;; since we used it.
1102 (eval (cons 'and
1103 (mapcar (lambda (elt)
1104 (let ((curr (file-attributes
1105 ;; Handle symlinks
1106 (file-truename (car elt)))))
1108 ;; Don't compare the access time.
1109 (if curr (setcar (nthcdr 4 curr) 0))
1110 (setcar (nthcdr 4 (cdr elt)) 0)
1111 (equal (cdr elt) curr)))
1112 Info-dir-file-attributes))))
1113 (progn
1114 (insert Info-dir-contents)
1115 (goto-char (point-min)))
1116 (let ((dirs (if Info-additional-directory-list
1117 (append Info-directory-list
1118 Info-additional-directory-list)
1119 Info-directory-list))
1120 (dir-file-attrs nil)
1121 ;; Bind this in case the user sets it to nil.
1122 (case-fold-search t)
1123 ;; This is set non-nil if we find a problem in some input files.
1124 problems
1125 buffers buffer others nodes dirs-done)
1127 ;; Search the directory list for the directory file.
1128 (while dirs
1129 (let ((truename (file-truename (expand-file-name (car dirs)))))
1130 (or (member truename dirs-done)
1131 (member (directory-file-name truename) dirs-done)
1132 ;; Try several variants of specified name.
1133 ;; Try upcasing, appending `.info', or both.
1134 (let* (file
1135 (attrs
1137 (progn (setq file (expand-file-name "dir" truename))
1138 (file-attributes file))
1139 (progn (setq file (expand-file-name "DIR" truename))
1140 (file-attributes file))
1141 (progn (setq file (expand-file-name "dir.info" truename))
1142 (file-attributes file))
1143 (progn (setq file (expand-file-name "DIR.INFO" truename))
1144 (file-attributes file)))))
1145 (setq dirs-done
1146 (cons truename
1147 (cons (directory-file-name truename)
1148 dirs-done)))
1149 (if attrs
1150 (with-current-buffer (generate-new-buffer " info dir")
1151 (or buffers
1152 (message "Composing main Info directory..."))
1153 (condition-case nil
1154 ;; Index nodes include null bytes. DIR
1155 ;; files should not have indices, but who
1156 ;; knows...
1157 (let ((inhibit-null-byte-detection t))
1158 (insert-file-contents file)
1159 (set (make-local-variable 'Info-dir-file-name)
1160 file)
1161 (push (current-buffer) buffers)
1162 (push (cons file attrs) dir-file-attrs))
1163 (error (kill-buffer (current-buffer))))))))
1164 (unless (cdr dirs)
1165 (set (make-local-variable 'Info-dir-contents-directory)
1166 (file-name-as-directory (car dirs))))
1167 (setq dirs (cdr dirs))))
1169 (or buffers
1170 (error "Can't find the Info directory node"))
1172 ;; Distinguish the dir file that comes with Emacs from all the
1173 ;; others. Yes, that is really what this is supposed to do.
1174 ;; The definition of `Info-directory-list' puts it first on that
1175 ;; list and so last in `buffers' at this point.
1176 (setq buffer (car (last buffers))
1177 others (delq buffer buffers))
1179 ;; Insert the entire original dir file as a start; note that we've
1180 ;; already saved its default directory to use as the default
1181 ;; directory for the whole concatenation.
1182 (save-excursion (insert-buffer-substring buffer))
1184 ;; Look at each of the other buffers one by one.
1185 (dolist (other others)
1186 (let (this-buffer-nodes)
1187 ;; In each, find all the menus.
1188 (with-current-buffer other
1189 (goto-char (point-min))
1190 ;; Find each menu, and add an elt to NODES for it.
1191 (while (re-search-forward "^\\* Menu:" nil t)
1192 (while (and (zerop (forward-line 1)) (eolp)))
1193 (let ((beg (point))
1194 nodename end)
1195 (re-search-backward "^\^_")
1196 (search-forward "Node: ")
1197 (setq nodename (Info-following-node-name))
1198 (search-forward "\n\^_" nil 'move)
1199 (beginning-of-line)
1200 (setq end (point))
1201 (push (list nodename other beg end) this-buffer-nodes)))
1202 (if (assoc-string "top" this-buffer-nodes t)
1203 (setq nodes (nconc this-buffer-nodes nodes))
1204 (setq problems t)
1205 (message "No `top' node in %s" Info-dir-file-name)))))
1206 ;; Add to the main menu a menu item for each other node.
1207 (re-search-forward "^\\* Menu:")
1208 (forward-line 1)
1209 (let ((menu-items '("top"))
1210 (end (save-excursion (search-forward "\^_" nil t) (point))))
1211 (dolist (node nodes)
1212 (let ((nodename (car node)))
1213 (save-excursion
1214 (or (member (downcase nodename) menu-items)
1215 (re-search-forward (concat "^\\* +"
1216 (regexp-quote nodename)
1217 "::")
1218 end t)
1219 (progn
1220 (insert "* " nodename "::" "\n")
1221 (push nodename menu-items)))))))
1222 ;; Now take each node of each of the other buffers
1223 ;; and merge it into the main buffer.
1224 (dolist (node nodes)
1225 (let ((case-fold-search t)
1226 (nodename (car node)))
1227 (goto-char (point-min))
1228 ;; Find the like-named node in the main buffer.
1229 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1230 (regexp-quote nodename)
1231 "[,\n\t]")
1232 nil t)
1233 (progn
1234 (search-forward "\n\^_" nil 'move)
1235 (beginning-of-line)
1236 (insert "\n"))
1237 ;; If none exists, add one.
1238 (goto-char (point-max))
1239 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
1240 ;; Merge the text from the other buffer's menu
1241 ;; into the menu in the like-named node in the main buffer.
1242 (apply 'insert-buffer-substring (cdr node))))
1243 (Info-dir-remove-duplicates)
1244 ;; Kill all the buffers we just made, including the special one excised.
1245 (mapc 'kill-buffer (cons buffer buffers))
1246 (goto-char (point-min))
1247 (if problems
1248 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1249 (message "Composing main Info directory...done"))
1250 (set (make-local-variable 'Info-dir-contents) (buffer-string))
1251 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
1252 (setq default-directory Info-dir-contents-directory))
1254 (defvar Info-streamline-headings
1255 '(("Emacs" . "Emacs")
1256 ("Programming" . "Programming")
1257 ("Libraries" . "Libraries")
1258 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
1259 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1261 (defun Info-dir-remove-duplicates ()
1262 (let (limit)
1263 (goto-char (point-min))
1264 ;; Remove duplicate headings in the same menu.
1265 (while (search-forward "\n* Menu:" nil t)
1266 (setq limit (save-excursion (search-forward "\n\^_" nil t)))
1267 ;; Look for the next heading to unify.
1268 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1269 (let ((name (match-string 1))
1270 (start (match-beginning 0))
1271 (entries nil) re)
1272 ;; Check whether this heading should be streamlined.
1273 (save-match-data
1274 (dolist (x Info-streamline-headings)
1275 (when (string-match (car x) name)
1276 (setq name (cdr x))
1277 (setq re (car x)))))
1278 (if re (replace-match name t t nil 1))
1279 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
1280 (match-beginning 0)
1281 (or limit (point-max))))
1282 ;; Look for other headings of the same category and merge them.
1283 (save-excursion
1284 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1285 (when (if re (save-match-data (string-match re (match-string 1)))
1286 (equal name (match-string 1)))
1287 (forward-line 0)
1288 ;; Delete redundant heading.
1289 (delete-region (match-beginning 0) (point))
1290 ;; Push the entries onto `text'.
1291 (push
1292 (delete-and-extract-region
1293 (point)
1294 (if (re-search-forward "^[^* \n\t]" nil t)
1295 (match-beginning 0)
1296 (or limit (point-max))))
1297 entries)
1298 (forward-line 0))))
1299 ;; Insert the entries just found.
1300 (while (= (line-beginning-position 0) (1- (point)))
1301 (backward-char))
1302 (dolist (entry (nreverse entries))
1303 (insert entry)
1304 (while (= (line-beginning-position 0) (1- (point)))
1305 (delete-region (1- (point)) (point))))
1307 ;; Now remove duplicate entries under the same heading.
1308 (let (seen)
1309 (save-restriction
1310 (narrow-to-region start (point))
1311 (goto-char (point-min))
1312 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil 'move)
1313 ;; Fold case straight away; `member-ignore-case' here wasteful.
1314 (let ((x (downcase (match-string 1))))
1315 (if (member x seen)
1316 (delete-region
1317 (match-beginning 0)
1318 (if (re-search-forward "^[^ \t]" nil 'move)
1319 (goto-char (match-beginning 0))
1320 (point-max)))
1321 (push x seen)))))))))))
1323 ;; Note that on entry to this function the current-buffer must be the
1324 ;; *info* buffer; not the info tags buffer.
1325 (defun Info-read-subfile (nodepos)
1326 ;; NODEPOS is either a position (in the Info file as a whole,
1327 ;; not relative to a subfile) or the name of a subfile.
1328 (let (lastfilepos
1329 lastfilename)
1330 (if (numberp nodepos)
1331 (with-current-buffer (marker-buffer Info-tag-table-marker)
1332 (goto-char (point-min))
1333 (or (looking-at "\^_")
1334 (search-forward "\n\^_"))
1335 (forward-line 2)
1336 (catch 'foo
1337 (while (not (looking-at "\^_"))
1338 (if (not (eolp))
1339 (let ((beg (point))
1340 thisfilepos thisfilename)
1341 (search-forward ": ")
1342 (setq thisfilename (buffer-substring beg (- (point) 2)))
1343 (setq thisfilepos (+ (point-min) (read (current-buffer))))
1344 ;; read in version 19 stops at the end of number.
1345 ;; Advance to the next line.
1346 (forward-line 1)
1347 (if (> thisfilepos nodepos)
1348 (throw 'foo t))
1349 (setq lastfilename thisfilename)
1350 (setq lastfilepos thisfilepos))
1351 (forward-line 1)))))
1352 (setq lastfilename nodepos)
1353 (setq lastfilepos 0))
1354 ;; Assume previous buffer is in Info-mode.
1355 ;; (set-buffer (get-buffer "*info*"))
1356 (or (equal Info-current-subfile lastfilename)
1357 (let ((inhibit-read-only t))
1358 (setq buffer-file-name nil)
1359 (widen)
1360 (erase-buffer)
1361 (info-insert-file-contents lastfilename)
1362 (set-buffer-modified-p nil)
1363 (setq Info-current-subfile lastfilename)))
1364 ;; Widen in case we are in the same subfile as before.
1365 (widen)
1366 (goto-char (point-min))
1367 (if (looking-at "\^_")
1368 (forward-char 1)
1369 (search-forward "\n\^_"))
1370 (if (numberp nodepos)
1371 (+ (- nodepos lastfilepos) (point)))))
1373 (defun Info-unescape-quotes (value)
1374 "Unescape double quotes and backslashes in VALUE."
1375 (let ((start 0)
1376 (unquote value))
1377 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start)
1378 (setq unquote (replace-match "" t t unquote 1))
1379 (setq start (- (match-end 0) 1)))
1380 unquote))
1382 ;; As of Texinfo 4.6, makeinfo writes constructs like
1383 ;; \0\h[image param=value ...\h\0]
1384 ;; into the Info file for handling images.
1385 (defun Info-split-parameter-string (parameter-string)
1386 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1387 whitespace separated list of KEY=VALUE pairs. If VALUE contains
1388 whitespace or double quotes, it must be quoted in double quotes and
1389 any double quotes or backslashes must be escaped (\\\",\\\\)."
1390 (let ((start 0)
1391 (parameter-alist))
1392 (while (string-match
1393 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1394 parameter-string start)
1395 (setq start (match-end 0))
1396 (push (cons (match-string 1 parameter-string)
1397 (or (match-string 2 parameter-string)
1398 (Info-unescape-quotes
1399 (match-string 3 parameter-string))))
1400 parameter-alist))
1401 parameter-alist))
1403 (defun Info-display-images-node ()
1404 "Display images in current node."
1405 (save-excursion
1406 (let ((inhibit-read-only t)
1407 (case-fold-search t))
1408 (goto-char (point-min))
1409 (while (re-search-forward
1410 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1411 nil t)
1412 (let* ((start (match-beginning 1))
1413 (parameter-alist (Info-split-parameter-string (match-string 2)))
1414 (src (cdr (assoc-string "src" parameter-alist))))
1415 (if (display-images-p)
1416 (let* ((image-file (if src (if (file-name-absolute-p src) src
1417 (concat default-directory src))
1418 ""))
1419 (image (if (file-exists-p image-file)
1420 (create-image image-file)
1421 "[broken image]")))
1422 (if (not (get-text-property start 'display))
1423 (add-text-properties
1424 start (point) `(display ,image rear-nonsticky (display)))))
1425 ;; text-only display, show alternative text if provided, or
1426 ;; otherwise a clue that there's meant to be a picture
1427 (delete-region start (point))
1428 (insert (or (cdr (assoc-string "text" parameter-alist))
1429 (cdr (assoc-string "alt" parameter-alist))
1430 (and src
1431 (concat "[image:" src "]"))
1432 "[image]"))))))
1433 (set-buffer-modified-p nil)))
1435 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1436 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1437 ;; including one optional trailing newline.
1438 (defun Info-hide-cookies-node ()
1439 "Hide unrecognized cookies in current node."
1440 (save-excursion
1441 (let ((inhibit-read-only t)
1442 (case-fold-search t))
1443 (goto-char (point-min))
1444 (while (re-search-forward
1445 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1446 nil t)
1447 (let* ((start (match-beginning 1)))
1448 (if (not (get-text-property start 'invisible))
1449 (put-text-property start (point) 'invisible t)))))
1450 (set-buffer-modified-p nil)))
1452 (defun Info-select-node ()
1453 "Select the Info node that point is in."
1454 ;; Bind this in case the user sets it to nil.
1455 (let ((case-fold-search t))
1456 (save-excursion
1457 ;; Find beginning of node.
1458 (if (search-backward "\n\^_" nil 'move)
1459 (forward-line 2)
1460 (if (looking-at "\^_")
1461 (forward-line 1)
1462 (signal 'search-failed (list "\n\^_"))))
1463 ;; Get nodename spelled as it is in the node.
1464 (re-search-forward "Node:[ \t]*")
1465 (setq Info-current-node
1466 (buffer-substring-no-properties (point)
1467 (progn
1468 (skip-chars-forward "^,\t\n")
1469 (point))))
1470 (Info-set-mode-line)
1471 ;; Find the end of it, and narrow.
1472 (beginning-of-line)
1473 (let (active-expression)
1474 ;; Narrow to the node contents
1475 (narrow-to-region (point)
1476 (if (re-search-forward "\n[\^_\f]" nil t)
1477 (prog1
1478 (1- (point))
1479 (if (looking-at "[\n\^_\f]*execute: ")
1480 (progn
1481 (goto-char (match-end 0))
1482 (setq active-expression
1483 (read (current-buffer))))))
1484 (point-max)))
1485 (if Info-enable-active-nodes (eval active-expression))
1486 ;; Add a new unique history item to full history list
1487 (let ((new-history (list Info-current-file Info-current-node)))
1488 (setq Info-history-list
1489 (cons new-history (delete new-history Info-history-list)))
1490 (setq Info-history-forward nil))
1491 (if (not (eq Info-fontify-maximum-menu-size nil))
1492 (Info-fontify-node))
1493 (Info-display-images-node)
1494 (Info-hide-cookies-node)
1495 (run-hooks 'Info-selection-hook)))))
1497 (defvar Info-mode-line-node-keymap
1498 (let ((map (make-sparse-keymap)))
1499 (define-key map [mode-line mouse-1] 'Info-mouse-scroll-up)
1500 (define-key map [mode-line mouse-3] 'Info-mouse-scroll-down)
1501 map)
1502 "Keymap to put on the Info node name in the mode line.")
1504 (defun Info-set-mode-line ()
1505 (setq mode-line-buffer-identification
1506 (nconc (propertized-buffer-identification "%b")
1507 (list
1508 (concat
1509 " ("
1510 (if (stringp Info-current-file)
1511 (replace-regexp-in-string
1512 "%" "%%" (file-name-nondirectory Info-current-file))
1513 (format "*%S*" Info-current-file))
1514 ") "
1515 (if Info-current-node
1516 (propertize (replace-regexp-in-string
1517 "%" "%%" Info-current-node)
1518 'face 'mode-line-buffer-id
1519 'help-echo
1520 "mouse-1: scroll forward, mouse-3: scroll back"
1521 'mouse-face 'mode-line-highlight
1522 'local-map Info-mode-line-node-keymap)
1523 ""))))))
1525 ;; Go to an Info node specified with a filename-and-nodename string
1526 ;; of the sort that is found in pointers in nodes.
1528 ;; Don't autoload this function: the correct entry point for other packages
1529 ;; to use is `info'. --Stef
1530 ;; ;;;###autoload
1531 (defun Info-goto-node (nodename &optional fork)
1532 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1533 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1534 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1535 its sub-files).
1536 Completion is available, but only for node names in the current Info file.
1537 If FORK is non-nil (interactively with a prefix arg), show the node in
1538 a new Info buffer.
1539 If FORK is a string, it is the name to use for the new buffer."
1540 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
1541 (info-initialize)
1542 (if fork
1543 (set-buffer
1544 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
1545 (let (filename)
1546 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1547 nodename)
1548 (setq filename (if (= (match-beginning 1) (match-end 1))
1550 (match-string 2 nodename))
1551 nodename (match-string 3 nodename))
1552 (let ((trim (string-match "\\s +\\'" filename)))
1553 (if trim (setq filename (substring filename 0 trim))))
1554 (let ((trim (string-match "\\s +\\'" nodename)))
1555 (if trim (setq nodename (substring nodename 0 trim))))
1556 (if transient-mark-mode (deactivate-mark))
1557 (Info-find-node (if (equal filename "") nil filename)
1558 (if (equal nodename "") "Top" nodename))))
1560 (defvar Info-read-node-completion-table)
1562 (defun Info-read-node-name-2 (dirs suffixes string pred action)
1563 "Virtual completion table for file names input in Info node names.
1564 PATH-AND-SUFFIXES is a pair of lists, (DIRECTORIES . SUFFIXES)."
1565 (setq suffixes (remove "" suffixes))
1566 (when (file-name-absolute-p string)
1567 (setq dirs (list (file-name-directory string))))
1568 (let ((names nil)
1569 (suffix (concat (regexp-opt suffixes t) "\\'"))
1570 (string-dir (file-name-directory string)))
1571 (dolist (dir dirs)
1572 (unless dir
1573 (setq dir default-directory))
1574 (if string-dir (setq dir (expand-file-name string-dir dir)))
1575 (when (file-directory-p dir)
1576 (dolist (file (file-name-all-completions
1577 (file-name-nondirectory string) dir))
1578 ;; If the file name has no suffix or a standard suffix,
1579 ;; include it.
1580 (and (or (null (file-name-extension file))
1581 (string-match suffix file))
1582 ;; But exclude subfiles of split Info files.
1583 (not (string-match "-[0-9]+\\'" file))
1584 ;; And exclude backup files.
1585 (not (string-match "~\\'" file))
1586 (push (if string-dir (concat string-dir file) file) names))
1587 ;; If the file name ends in a standard suffix,
1588 ;; add the unsuffixed name as a completion option.
1589 (when (string-match suffix file)
1590 (setq file (substring file 0 (match-beginning 0)))
1591 (push (if string-dir (concat string-dir file) file) names)))))
1592 (complete-with-action action names string pred)))
1594 ;; This function is used as the "completion table" while reading a node name.
1595 ;; It does completion using the alist in Info-read-node-completion-table
1596 ;; unless STRING starts with an open-paren.
1597 (defun Info-read-node-name-1 (string predicate code)
1598 (cond
1599 ;; First complete embedded file names.
1600 ((string-match "\\`([^)]*\\'" string)
1601 (completion-table-with-context
1603 (apply-partially 'completion-table-with-terminator ")"
1604 (apply-partially 'Info-read-node-name-2
1605 Info-directory-list
1606 (mapcar 'car Info-suffix-list)))
1607 (substring string 1)
1608 predicate
1609 code))
1611 ;; If a file name was given, then any node is fair game.
1612 ((string-match "\\`(" string)
1613 (cond
1614 ((eq code nil) string)
1615 ((eq code t) nil)
1616 (t t)))
1617 ;; Otherwise use Info-read-node-completion-table.
1618 (t (complete-with-action
1619 code Info-read-node-completion-table string predicate))))
1621 ;; Arrange to highlight the proper letters in the completion list buffer.
1624 (defun Info-read-node-name (prompt)
1625 (let* ((completion-ignore-case t)
1626 (Info-read-node-completion-table (Info-build-node-completions))
1627 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1628 (if (equal nodename "")
1629 (Info-read-node-name prompt)
1630 nodename)))
1632 (defun Info-build-node-completions ()
1633 (or Info-current-file-completions
1634 (let ((compl nil)
1635 ;; Bind this in case the user sets it to nil.
1636 (case-fold-search t)
1637 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1638 (save-excursion
1639 (save-restriction
1640 (or Info-tag-table-marker
1641 (error "No Info tags found"))
1642 (if (marker-buffer Info-tag-table-marker)
1643 (let ((marker Info-tag-table-marker))
1644 (set-buffer (marker-buffer marker))
1645 (widen)
1646 (goto-char marker)
1647 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1648 (setq compl
1649 (cons (list (match-string-no-properties 2))
1650 compl))))
1651 (widen)
1652 (goto-char (point-min))
1653 ;; If the buffer begins with a node header, process that first.
1654 (if (Info-node-at-bob-matching node-regexp)
1655 (setq compl (list (match-string-no-properties 1))))
1656 ;; Now for the rest of the nodes.
1657 (while (search-forward "\n\^_" nil t)
1658 (forward-line 1)
1659 (let ((beg (point)))
1660 (forward-line 1)
1661 (if (re-search-backward node-regexp beg t)
1662 (setq compl
1663 (cons (list (match-string-no-properties 1))
1664 compl))))))))
1665 (setq compl (cons '("*") compl))
1666 (set (make-local-variable 'Info-current-file-completions) compl))))
1668 (defun Info-restore-point (hl)
1669 "If this node has been visited, restore the point value when we left."
1670 (while hl
1671 (if (and (equal (nth 0 (car hl)) Info-current-file)
1672 ;; Use string-equal, not equal, to ignore text props.
1673 (string-equal (nth 1 (car hl)) Info-current-node))
1674 (progn
1675 (goto-char (nth 2 (car hl)))
1676 (setq hl nil)) ;terminate the while at next iter
1677 (setq hl (cdr hl)))))
1679 (defvar Info-search-history nil
1680 "The history list for `Info-search'.")
1682 (defvar Info-search-case-fold nil
1683 "The value of `case-fold-search' from previous `Info-search' command.")
1685 (defun Info-search (regexp &optional bound noerror count direction)
1686 "Search for REGEXP, starting from point, and select node it's found in.
1687 If DIRECTION is `backward', search in the reverse direction."
1688 (interactive (list (read-string
1689 (if Info-search-history
1690 (format "Regexp search%s (default %s): "
1691 (if case-fold-search "" " case-sensitively")
1692 (car Info-search-history))
1693 (format "Regexp search%s: "
1694 (if case-fold-search "" " case-sensitively")))
1695 nil 'Info-search-history)))
1696 (when transient-mark-mode
1697 (deactivate-mark))
1698 (when (equal regexp "")
1699 (setq regexp (car Info-search-history)))
1700 (when regexp
1701 (let (found beg-found give-up
1702 (backward (eq direction 'backward))
1703 (onode Info-current-node)
1704 (ofile Info-current-file)
1705 (opoint (point))
1706 (opoint-min (point-min))
1707 (opoint-max (point-max))
1708 (ostart (window-start))
1709 (osubfile Info-current-subfile))
1710 (setq Info-search-case-fold case-fold-search)
1711 (save-excursion
1712 (save-restriction
1713 (widen)
1714 (when backward
1715 ;; Hide Info file header for backward search
1716 (narrow-to-region (save-excursion
1717 (goto-char (point-min))
1718 (search-forward "\n\^_")
1719 (1- (point)))
1720 (point-max)))
1721 (while (and (not give-up)
1722 (or (null found)
1723 (not (funcall isearch-filter-predicate beg-found found))))
1724 (let ((search-spaces-regexp
1725 (if (or (not isearch-mode) isearch-regexp)
1726 Info-search-whitespace-regexp)))
1727 (if (if backward
1728 (re-search-backward regexp bound t)
1729 (re-search-forward regexp bound t))
1730 (setq found (point) beg-found (if backward (match-end 0)
1731 (match-beginning 0)))
1732 (setq give-up t))))))
1734 (when (and isearch-mode Info-isearch-search
1735 (not Info-isearch-initial-node)
1736 (not bound)
1737 (or give-up (and found (not (and (> found opoint-min)
1738 (< found opoint-max))))))
1739 (signal 'search-failed (list regexp "initial node")))
1741 ;; If no subfiles, give error now.
1742 (if give-up
1743 (if (null Info-current-subfile)
1744 (let ((search-spaces-regexp
1745 (if (or (not isearch-mode) isearch-regexp)
1746 Info-search-whitespace-regexp)))
1747 (if backward
1748 (re-search-backward regexp)
1749 (re-search-forward regexp)))
1750 (setq found nil)))
1752 (if (and bound (not found))
1753 (signal 'search-failed (list regexp)))
1755 (unless (or found bound)
1756 (unwind-protect
1757 ;; Try other subfiles.
1758 (let ((list ()))
1759 (with-current-buffer (marker-buffer Info-tag-table-marker)
1760 (goto-char (point-min))
1761 (search-forward "\n\^_\nIndirect:")
1762 (save-restriction
1763 (narrow-to-region (point)
1764 (progn (search-forward "\n\^_")
1765 (1- (point))))
1766 (goto-char (point-min))
1767 ;; Find the subfile we just searched.
1768 (search-forward (concat "\n" osubfile ": "))
1769 ;; Skip that one.
1770 (forward-line (if backward 0 1))
1771 (if backward (forward-char -1))
1772 ;; Make a list of all following subfiles.
1773 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1774 (while (not (if backward (bobp) (eobp)))
1775 (if backward
1776 (re-search-backward "\\(^.*\\): [0-9]+$")
1777 (re-search-forward "\\(^.*\\): [0-9]+$"))
1778 (goto-char (+ (match-end 1) 2))
1779 (setq list (cons (cons (+ (point-min)
1780 (read (current-buffer)))
1781 (match-string-no-properties 1))
1782 list))
1783 (goto-char (if backward
1784 (1- (match-beginning 0))
1785 (1+ (match-end 0)))))
1786 ;; Put in forward order
1787 (setq list (nreverse list))))
1788 (while list
1789 (message "Searching subfile %s..." (cdr (car list)))
1790 (Info-read-subfile (car (car list)))
1791 (when backward
1792 ;; Hide Info file header for backward search
1793 (narrow-to-region (save-excursion
1794 (goto-char (point-min))
1795 (search-forward "\n\^_")
1796 (1- (point)))
1797 (point-max))
1798 (goto-char (point-max)))
1799 (setq list (cdr list))
1800 (setq give-up nil found nil)
1801 (while (and (not give-up)
1802 (or (null found)
1803 (not (funcall isearch-filter-predicate beg-found found))))
1804 (let ((search-spaces-regexp
1805 (if (or (not isearch-mode) isearch-regexp)
1806 Info-search-whitespace-regexp)))
1807 (if (if backward
1808 (re-search-backward regexp nil t)
1809 (re-search-forward regexp nil t))
1810 (setq found (point) beg-found (if backward (match-end 0)
1811 (match-beginning 0)))
1812 (setq give-up t))))
1813 (if give-up
1814 (setq found nil))
1815 (if found
1816 (setq list nil)))
1817 (if found
1818 (message "")
1819 (signal 'search-failed (list regexp))))
1820 (if (not found)
1821 (progn (Info-read-subfile osubfile)
1822 (goto-char opoint)
1823 (Info-select-node)
1824 (set-window-start (selected-window) ostart)))))
1826 (if (and (string= osubfile Info-current-subfile)
1827 (> found opoint-min)
1828 (< found opoint-max))
1829 ;; Search landed in the same node
1830 (goto-char found)
1831 (widen)
1832 (goto-char found)
1833 (save-match-data (Info-select-node)))
1835 ;; Use string-equal, not equal, to ignore text props.
1836 (or (and (string-equal onode Info-current-node)
1837 (equal ofile Info-current-file))
1838 (and isearch-mode isearch-wrapped
1839 (eq opoint (if isearch-forward opoint-min opoint-max)))
1840 (setq Info-history (cons (list ofile onode opoint)
1841 Info-history))))))
1843 (defun Info-search-case-sensitively ()
1844 "Search for a regexp case-sensitively."
1845 (interactive)
1846 (let ((case-fold-search nil))
1847 (call-interactively 'Info-search)))
1849 (defun Info-search-next ()
1850 "Search for next regexp from a previous `Info-search' command."
1851 (interactive)
1852 (let ((case-fold-search Info-search-case-fold))
1853 (if Info-search-history
1854 (Info-search (car Info-search-history))
1855 (call-interactively 'Info-search))))
1857 (defun Info-search-backward (regexp &optional bound noerror count)
1858 "Search for REGEXP in the reverse direction."
1859 (interactive (list (read-string
1860 (if Info-search-history
1861 (format "Regexp search%s backward (default %s): "
1862 (if case-fold-search "" " case-sensitively")
1863 (car Info-search-history))
1864 (format "Regexp search%s backward: "
1865 (if case-fold-search "" " case-sensitively")))
1866 nil 'Info-search-history)))
1867 (Info-search regexp bound noerror count 'backward))
1869 (defun Info-isearch-search ()
1870 (if Info-isearch-search
1871 (lambda (string &optional bound noerror count)
1872 (if isearch-word
1873 (Info-search (concat "\\b" (replace-regexp-in-string
1874 "\\W+" "\\W+"
1875 (replace-regexp-in-string
1876 "^\\W+\\|\\W+$" "" string)
1877 nil t)
1878 ;; Lax version of word search
1879 (if (or isearch-nonincremental
1880 (eq (length string)
1881 (length (isearch-string-state
1882 (car isearch-cmds)))))
1883 "\\b"))
1884 bound noerror count
1885 (unless isearch-forward 'backward))
1886 (Info-search (if isearch-regexp string (regexp-quote string))
1887 bound noerror count
1888 (unless isearch-forward 'backward)))
1889 (point))
1890 (let ((isearch-search-fun-function nil))
1891 (isearch-search-fun))))
1893 (defun Info-isearch-wrap ()
1894 (if Info-isearch-search
1895 (if Info-isearch-initial-node
1896 (progn
1897 (if isearch-forward (Info-top-node) (Info-final-node))
1898 (goto-char (if isearch-forward (point-min) (point-max))))
1899 (setq Info-isearch-initial-node Info-current-node)
1900 (setq isearch-wrapped nil))
1901 (goto-char (if isearch-forward (point-min) (point-max)))))
1903 (defun Info-isearch-push-state ()
1904 `(lambda (cmd)
1905 (Info-isearch-pop-state cmd ',Info-current-file ',Info-current-node)))
1907 (defun Info-isearch-pop-state (cmd file node)
1908 (or (and (equal Info-current-file file)
1909 (equal Info-current-node node))
1910 (progn (Info-find-node file node) (sit-for 0))))
1912 (defun Info-isearch-start ()
1913 (setq Info-isearch-initial-node
1914 ;; Don't stop at initial node for nonincremental search.
1915 ;; Otherwise this variable is set after first search failure.
1916 (and isearch-nonincremental Info-current-node)))
1918 (defun Info-isearch-filter (beg-found found)
1919 "Test whether the current search hit is a visible useful text.
1920 Return non-nil if the text from BEG-FOUND to FOUND is visible
1921 and is not in the header line or a tag table."
1922 (save-match-data
1923 (let ((backward (< found beg-found)))
1924 (not
1926 (and (not (eq search-invisible t))
1927 (if backward
1928 (or (text-property-not-all found beg-found 'invisible nil)
1929 (text-property-not-all found beg-found 'display nil))
1930 (or (text-property-not-all beg-found found 'invisible nil)
1931 (text-property-not-all beg-found found 'display nil))))
1932 ;; Skip node header line
1933 (and (save-excursion (forward-line -1)
1934 (looking-at "\^_"))
1935 (forward-line (if backward -1 1)))
1936 ;; Skip Tag Table node
1937 (save-excursion
1938 (and (search-backward "\^_" nil t)
1939 (looking-at
1940 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
1943 (defun Info-extract-pointer (name &optional errorname)
1944 "Extract the value of the node-pointer named NAME.
1945 If there is none, use ERRORNAME in the error message;
1946 if ERRORNAME is nil, just return nil."
1947 ;; Bind this in case the user sets it to nil.
1948 (let ((case-fold-search t))
1949 (save-excursion
1950 (goto-char (point-min))
1951 (let ((bound (point)))
1952 (forward-line 1)
1953 (cond ((re-search-backward
1954 (concat name ":" (Info-following-node-name-re)) bound t)
1955 (match-string-no-properties 1))
1956 ((not (eq errorname t))
1957 (error "Node has no %s"
1958 (capitalize (or errorname name)))))))))
1960 (defun Info-following-node-name-re (&optional allowedchars)
1961 "Return a regexp matching a node name.
1962 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1963 saying which chars may appear in the node name.
1964 Submatch 1 is the complete node name.
1965 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1966 Submatch 3 is the local part of the node name.
1967 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1968 (concat "[ \t]*" ;Skip leading space.
1969 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1970 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
1971 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
1972 "\\|\\)\\)")) ;Allow empty node names.
1974 ;;; For compatibility; other files have used this name.
1975 (defun Info-following-node-name ()
1976 (and (looking-at (Info-following-node-name-re))
1977 (match-string-no-properties 1)))
1979 (defun Info-next ()
1980 "Go to the next node of this node."
1981 (interactive)
1982 ;; In case another window is currently selected
1983 (save-window-excursion
1984 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
1985 (Info-goto-node (Info-extract-pointer "next"))))
1987 (defun Info-prev ()
1988 "Go to the previous node of this node."
1989 (interactive)
1990 ;; In case another window is currently selected
1991 (save-window-excursion
1992 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
1993 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
1995 (defun Info-up (&optional same-file)
1996 "Go to the superior node of this node.
1997 If SAME-FILE is non-nil, do not move to a different Info file."
1998 (interactive)
1999 ;; In case another window is currently selected
2000 (save-window-excursion
2001 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
2002 (let ((old-node Info-current-node)
2003 (old-file Info-current-file)
2004 (node (Info-extract-pointer "up")) p)
2005 (and same-file
2006 (string-match "^(" node)
2007 (error "Up node is in another Info file"))
2008 (Info-goto-node node)
2009 (setq p (point))
2010 (goto-char (point-min))
2011 (if (and (stringp old-file)
2012 (search-forward "\n* Menu:" nil t)
2013 (re-search-forward
2014 (if (string-equal old-node "Top")
2015 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
2016 (concat "\n\\* +\\(" (regexp-quote old-node)
2017 ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
2018 nil t))
2019 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2020 (goto-char p)
2021 (Info-restore-point Info-history)))))
2023 (defun Info-history-back ()
2024 "Go back in the history to the last node visited."
2025 (interactive)
2026 (or Info-history
2027 (error "This is the first Info node you looked at"))
2028 (let ((history-forward
2029 (cons (list Info-current-file Info-current-node (point))
2030 Info-history-forward))
2031 filename nodename opoint)
2032 (setq filename (car (car Info-history)))
2033 (setq nodename (car (cdr (car Info-history))))
2034 (setq opoint (car (cdr (cdr (car Info-history)))))
2035 (setq Info-history (cdr Info-history))
2036 (Info-find-node filename nodename)
2037 (setq Info-history (cdr Info-history))
2038 (setq Info-history-forward history-forward)
2039 (goto-char opoint)))
2041 (defalias 'Info-last 'Info-history-back)
2043 (defun Info-history-forward ()
2044 "Go forward in the history of visited nodes."
2045 (interactive)
2046 (or Info-history-forward
2047 (error "This is the last Info node you looked at"))
2048 (let ((history-forward (cdr Info-history-forward))
2049 filename nodename opoint)
2050 (setq filename (car (car Info-history-forward)))
2051 (setq nodename (car (cdr (car Info-history-forward))))
2052 (setq opoint (car (cdr (cdr (car Info-history-forward)))))
2053 (Info-find-node filename nodename)
2054 (setq Info-history-forward history-forward)
2055 (goto-char opoint)))
2057 (add-to-list 'Info-virtual-files
2058 '("\\`dir\\'"
2059 (toc-nodes . Info-directory-toc-nodes)
2060 (find-file . Info-directory-find-file)
2061 (find-node . Info-directory-find-node)
2064 (defun Info-directory-toc-nodes (filename)
2065 "Directory-specific implementation of Info-directory-toc-nodes."
2066 `(,filename
2067 ("Top" nil nil nil)))
2069 (defun Info-directory-find-file (filename &optional noerror)
2070 "Directory-specific implementation of Info-find-file."
2071 filename)
2073 (defun Info-directory-find-node (filename nodename &optional no-going-back)
2074 "Directory-specific implementation of Info-find-node-2."
2075 (Info-insert-dir))
2077 ;;;###autoload
2078 (defun Info-directory ()
2079 "Go to the Info directory node."
2080 (interactive)
2081 (Info-find-node "dir" "top"))
2083 (add-to-list 'Info-virtual-files
2084 '("\\`\\*History\\*\\'"
2085 (toc-nodes . Info-history-toc-nodes)
2086 (find-file . Info-history-find-file)
2087 (find-node . Info-history-find-node)
2090 (defun Info-history-toc-nodes (filename)
2091 "History-specific implementation of Info-history-toc-nodes."
2092 `(,filename
2093 ("Top" nil nil nil)))
2095 (defun Info-history-find-file (filename &optional noerror)
2096 "History-specific implementation of Info-find-file."
2097 filename)
2099 (defun Info-history-find-node (filename nodename &optional no-going-back)
2100 "History-specific implementation of Info-find-node-2."
2101 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2102 (or filename Info-current-file) nodename))
2103 (insert "Recently Visited Nodes\n")
2104 (insert "**********************\n\n")
2105 (insert "* Menu:\n\n")
2106 (let ((hl (delete '("*History*" "Top") Info-history-list)))
2107 (while hl
2108 (let ((file (nth 0 (car hl)))
2109 (node (nth 1 (car hl))))
2110 (if (stringp file)
2111 (insert "* " node ": ("
2112 (propertize (or (file-name-directory file) "") 'invisible t)
2113 (file-name-nondirectory file)
2114 ")" node ".\n")))
2115 (setq hl (cdr hl)))))
2117 (defun Info-history ()
2118 "Go to a node with a menu of visited nodes."
2119 (interactive)
2120 (Info-find-node "*History*" "Top")
2121 (Info-next-reference)
2122 (Info-next-reference))
2124 (add-to-list 'Info-virtual-nodes
2125 '("\\`\\*TOC\\*\\'"
2126 (find-node . Info-toc-find-node)
2129 (defun Info-toc-find-node (filename nodename &optional no-going-back)
2130 "Toc-specific implementation of Info-find-node-2."
2131 (let* ((curr-file (substring-no-properties (or filename Info-current-file)))
2132 (curr-node (substring-no-properties (or nodename Info-current-node)))
2133 (node-list (Info-toc-nodes curr-file)))
2134 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2135 curr-file curr-node))
2136 (insert "Table of Contents\n")
2137 (insert "*****************\n\n")
2138 (insert "*Note Top::\n")
2139 (Info-toc-insert
2140 (nth 3 (assoc "Top" node-list)) ; get Top nodes
2141 node-list 0 curr-file)
2142 (unless (bobp)
2143 (let ((Info-hide-note-references 'hide)
2144 (Info-fontify-visited-nodes nil))
2145 (setq Info-current-file filename Info-current-node "*TOC*")
2146 (goto-char (point-min))
2147 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t)
2148 (point-min))
2149 (point-max))
2150 (Info-fontify-node)
2151 (widen)))))
2153 (defun Info-toc ()
2154 "Go to a node with table of contents of the current Info file.
2155 Table of contents is created from the tree structure of menus."
2156 (interactive)
2157 (Info-find-node Info-current-file "*TOC*")
2158 (let ((prev-node (nth 1 (car Info-history))) p)
2159 (goto-char (point-min))
2160 (if (setq p (search-forward (concat "*Note " prev-node ":") nil t))
2161 (setq p (- p (length prev-node) 2)))
2162 (goto-char (or p (point-min)))))
2164 (defun Info-toc-insert (nodes node-list level curr-file)
2165 "Insert table of contents with references to nodes."
2166 (let ((section "Top"))
2167 (while nodes
2168 (let ((node (assoc (car nodes) node-list)))
2169 (unless (member (nth 2 node) (list nil section))
2170 (insert (setq section (nth 2 node)) "\n"))
2171 (insert (make-string level ?\t))
2172 (insert "*Note " (car nodes) ":: \n")
2173 (Info-toc-insert (nth 3 node) node-list (1+ level) curr-file)
2174 (setq nodes (cdr nodes))))))
2176 (defun Info-toc-build (file)
2177 "Build table of contents from menus of Info FILE and its subfiles."
2178 (with-temp-buffer
2179 (let* ((file (and (stringp file) (Info-find-file file)))
2180 (default-directory (or (and (stringp file)
2181 (file-name-directory file))
2182 default-directory))
2183 (main-file (and (stringp file) file))
2184 (sections '(("Top" "Top")))
2185 nodes subfiles)
2186 (while (or main-file subfiles)
2187 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2188 (erase-buffer)
2189 (info-insert-file-contents (or main-file (car subfiles)))
2190 (goto-char (point-min))
2191 (while (and (search-forward "\n\^_\nFile:" nil 'move)
2192 (search-forward "Node: " nil 'move))
2193 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2194 (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
2195 (point-max)) 2))
2196 (upnode (and (re-search-forward
2197 (concat "Up:" (Info-following-node-name-re))
2198 bound t)
2199 (match-string-no-properties 1)))
2200 (section "Top")
2201 menu-items)
2202 (when (string-match "(" upnode) (setq upnode nil))
2203 (when (and (not (Info-index-node nodename file))
2204 (re-search-forward "^\\* Menu:" bound t))
2205 (forward-line 1)
2206 (beginning-of-line)
2207 (setq bound (or (and (equal nodename "Top")
2208 (save-excursion
2209 (re-search-forward
2210 "^[ \t-]*The Detailed Node Listing" nil t)))
2211 bound))
2212 (while (< (point) bound)
2213 (cond
2214 ;; Menu item line
2215 ((looking-at "^\\* +[^:]+:")
2216 (beginning-of-line)
2217 (forward-char 2)
2218 (let ((menu-node-name (substring-no-properties
2219 (Info-extract-menu-node-name))))
2220 (setq menu-items (cons menu-node-name menu-items))
2221 (if (equal nodename "Top")
2222 (setq sections
2223 (cons (list menu-node-name section) sections)))))
2224 ;; Other non-empty strings in the Top node are section names
2225 ((and (equal nodename "Top")
2226 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2227 (setq section (match-string-no-properties 1))))
2228 (forward-line 1)
2229 (beginning-of-line)))
2230 (setq nodes (cons (list nodename upnode
2231 (cadr (assoc nodename sections))
2232 (nreverse menu-items))
2233 nodes))
2234 (goto-char bound)))
2235 (if main-file
2236 (save-excursion
2237 (goto-char (point-min))
2238 (if (search-forward "\n\^_\nIndirect:" nil t)
2239 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2240 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2241 (setq subfiles (cons (match-string-no-properties 1)
2242 subfiles)))))
2243 (setq subfiles (nreverse subfiles)
2244 main-file nil))
2245 (setq subfiles (cdr subfiles))))
2246 (message "")
2247 (nreverse nodes))))
2249 (defvar Info-toc-nodes nil
2250 "Alist of cached parent-children node information in visited Info files.
2251 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
2252 where PARENT is the parent node extracted from the Up pointer,
2253 SECTION is the section name in the Top node where this node is placed,
2254 CHILDREN is a list of child nodes extracted from the node menu.")
2256 (defun Info-toc-nodes (filename)
2257 "Return a node list of Info FILENAME with parent-children information.
2258 This information is cached in the variable `Info-toc-nodes' with the help
2259 of the function `Info-toc-build'."
2260 (cond
2261 ((Info-virtual-call
2262 (Info-virtual-fun 'toc-nodes (or filename Info-current-file) nil)
2263 filename))
2265 (or filename (setq filename Info-current-file))
2266 (or (assoc filename Info-toc-nodes)
2267 ;; Skip virtual Info files
2268 (and (or (not (stringp filename))
2269 (Info-virtual-file-p filename))
2270 (push (cons filename nil) Info-toc-nodes))
2271 ;; Scan the entire manual and cache the result in Info-toc-nodes
2272 (let ((nodes (Info-toc-build filename)))
2273 (push (cons filename nodes) Info-toc-nodes)
2274 nodes)
2275 ;; If there is an error, still add nil to the cache
2276 (push (cons filename nil) Info-toc-nodes))
2277 (cdr (assoc filename Info-toc-nodes)))))
2280 (defun Info-follow-reference (footnotename &optional fork)
2281 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2282 FOOTNOTENAME may be an abbreviation of the reference name.
2283 If FORK is non-nil (interactively with a prefix arg), show the node in
2284 a new Info buffer. If FORK is a string, it is the name to use for the
2285 new buffer."
2286 (interactive
2287 (let ((completion-ignore-case t)
2288 (case-fold-search t)
2289 completions default alt-default (start-point (point)) str i bol eol)
2290 (save-excursion
2291 ;; Store end and beginning of line.
2292 (end-of-line)
2293 (setq eol (point))
2294 (beginning-of-line)
2295 (setq bol (point))
2297 (goto-char (point-min))
2298 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
2299 (setq str (match-string-no-properties 1))
2300 ;; See if this one should be the default.
2301 (and (null default)
2302 (<= (match-beginning 0) start-point)
2303 (<= start-point (point))
2304 (setq default t))
2305 ;; See if this one should be the alternate default.
2306 (and (null alt-default)
2307 (and (<= bol (match-beginning 0))
2308 (<= (point) eol))
2309 (setq alt-default t))
2310 (setq i 0)
2311 (while (setq i (string-match "[ \n\t]+" str i))
2312 (setq str (concat (substring str 0 i) " "
2313 (substring str (match-end 0))))
2314 (setq i (1+ i)))
2315 ;; Record as a completion and perhaps as default.
2316 (if (eq default t) (setq default str))
2317 (if (eq alt-default t) (setq alt-default str))
2318 ;; Don't add this string if it's a duplicate.
2319 (or (assoc-string str completions t)
2320 (push str completions))))
2321 ;; If no good default was found, try an alternate.
2322 (or default
2323 (setq default alt-default))
2324 ;; If only one cross-reference found, then make it default.
2325 (if (eq (length completions) 1)
2326 (setq default (car completions)))
2327 (if completions
2328 (let ((input (completing-read (if default
2329 (concat
2330 "Follow reference named (default "
2331 default "): ")
2332 "Follow reference named: ")
2333 completions nil t)))
2334 (list (if (equal input "")
2335 default input) current-prefix-arg))
2336 (error "No cross-references in this node"))))
2338 (unless footnotename
2339 (error "No reference was specified"))
2341 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
2342 (case-fold-search t))
2343 (while (setq i (string-match " " str i))
2344 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
2345 (setq i (+ i 6)))
2346 (save-excursion
2347 ;; Move point to the beginning of reference if point is on reference
2348 (or (looking-at "\\*note[ \n\t]+")
2349 (and (looking-back "\\*note[ \n\t]+")
2350 (goto-char (match-beginning 0)))
2351 (if (and (save-excursion
2352 (goto-char (+ (point) 5)) ; skip a possible *note
2353 (re-search-backward "\\*note[ \n\t]+" nil t)
2354 (looking-at str))
2355 (<= (point) (match-end 0)))
2356 (goto-char (match-beginning 0))))
2357 ;; Go to the reference closest to point
2358 (let ((next-ref (save-excursion (and (re-search-forward str nil t)
2359 (+ (match-beginning 0) 5))))
2360 (prev-ref (save-excursion (and (re-search-backward str nil t)
2361 (+ (match-beginning 0) 5)))))
2362 (goto-char (cond ((and next-ref prev-ref)
2363 (if (< (abs (- next-ref (point)))
2364 (abs (- prev-ref (point))))
2365 next-ref prev-ref))
2366 ((or next-ref prev-ref))
2367 ((error "No cross-reference named %s" footnotename))))
2368 (setq target (Info-extract-menu-node-name t))))
2369 (while (setq i (string-match "[ \t\n]+" target i))
2370 (setq target (concat (substring target 0 i) " "
2371 (substring target (match-end 0))))
2372 (setq i (+ i 1)))
2373 (Info-goto-node target fork)))
2375 (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2376 ;; We allow newline because this is also used in Info-follow-reference,
2377 ;; where the xref name might be wrapped over two lines.
2378 "Regexp that matches a menu entry name upto but not including the colon.
2379 Because of ambiguities, this should be concatenated with something like
2380 `:' and `Info-following-node-name-re'.")
2382 (defun Info-extract-menu-node-name (&optional multi-line index-node)
2383 (skip-chars-forward " \t\n")
2384 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
2385 (Info-following-node-name-re
2386 (cond
2387 (index-node "^,\t\n")
2388 (multi-line "^.,\t")
2389 (t "^.,\t\n")))
2390 "\\)"
2391 (if index-node
2392 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2393 "")))
2394 (if index-node
2395 (setq Info-point-loc
2396 (if (match-beginning 5)
2397 (string-to-number (match-string 5))
2398 (buffer-substring-no-properties
2399 (match-beginning 0) (1- (match-beginning 1)))))
2400 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2401 ;;; (setq Info-point-loc
2402 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2404 (replace-regexp-in-string
2405 "[ \n]+" " "
2406 (or (match-string-no-properties 2)
2407 ;; If the node name is the menu entry name (using `entry::').
2408 (buffer-substring-no-properties
2409 (match-beginning 0) (1- (match-beginning 1)))))))
2411 ;; No one calls this.
2412 ;;(defun Info-menu-item-sequence (list)
2413 ;; (while list
2414 ;; (Info-menu (car list))
2415 ;; (setq list (cdr list))))
2417 (defvar Info-complete-menu-buffer)
2418 (defvar Info-complete-next-re nil)
2419 (defvar Info-complete-nodes nil)
2420 (defvar Info-complete-cache nil)
2422 (defconst Info-node-spec-re
2423 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2424 "Regexp to match the text after a : until the terminating `.'.")
2426 (defun Info-complete-menu-item (string predicate action)
2427 ;; This uses two dynamically bound variables:
2428 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2429 ;; is the menu of items we're trying to complete.
2430 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2431 ;; also look for menu items in subsequent nodes as long as those
2432 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2433 ;; not used.
2434 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2435 ;; also look for menu items in these nodes. This feature is currently
2436 ;; only used for completion in Info-index.
2438 ;; Note that `Info-complete-menu-buffer' could be current already,
2439 ;; so we want to save point.
2440 (with-current-buffer Info-complete-menu-buffer
2441 (save-excursion
2442 (let ((completion-ignore-case t)
2443 (case-fold-search t)
2444 (orignode Info-current-node)
2445 nextnode)
2446 (goto-char (point-min))
2447 (search-forward "\n* Menu:")
2448 (if (not (memq action '(nil t)))
2449 (re-search-forward
2450 (concat "\n\\* +" (regexp-quote string) ":") nil t)
2451 (let ((pattern (concat "\n\\* +\\("
2452 (regexp-quote string)
2453 Info-menu-entry-name-re "\\):" Info-node-spec-re))
2454 completions
2455 (complete-nodes Info-complete-nodes))
2456 ;; Check the cache.
2457 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
2458 (equal (nth 1 Info-complete-cache) Info-current-node)
2459 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
2460 (equal (nth 5 Info-complete-cache) Info-complete-nodes)
2461 (let ((prev (nth 3 Info-complete-cache)))
2462 (eq t (compare-strings string 0 (length prev)
2463 prev 0 nil t))))
2464 ;; We can reuse the previous list.
2465 (setq completions (nth 4 Info-complete-cache))
2466 ;; The cache can't be used.
2467 (while
2468 (progn
2469 (while (re-search-forward pattern nil t)
2470 (push (match-string-no-properties 1)
2471 completions))
2472 ;; Check subsequent nodes if applicable.
2473 (or (and Info-complete-next-re
2474 (setq nextnode (Info-extract-pointer "next" t))
2475 (string-match Info-complete-next-re nextnode))
2476 (and complete-nodes
2477 (setq complete-nodes (cdr complete-nodes)
2478 nextnode (car complete-nodes)))))
2479 (Info-goto-node nextnode))
2480 ;; Go back to the start node (for the next completion).
2481 (unless (equal Info-current-node orignode)
2482 (Info-goto-node orignode))
2483 ;; Update the cache.
2484 (set (make-local-variable 'Info-complete-cache)
2485 (list Info-current-file Info-current-node
2486 Info-complete-next-re string completions
2487 Info-complete-nodes)))
2488 (if action
2489 (all-completions string completions predicate)
2490 (try-completion string completions predicate))))))))
2493 (defun Info-menu (menu-item &optional fork)
2494 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2495 The menu item should one of those listed in the current node's menu.
2496 Completion is allowed, and the default menu item is the one point is on.
2497 If FORK is non-nil (interactively with a prefix arg), show the node in
2498 a new Info buffer. If FORK is a string, it is the name to use for the
2499 new buffer."
2500 (interactive
2501 (let ((completions '())
2502 ;; If point is within a menu item, use that item as the default
2503 (default nil)
2504 (p (point))
2506 (last nil)
2507 (case-fold-search t))
2508 (save-excursion
2509 (goto-char (point-min))
2510 (if (not (search-forward "\n* menu:" nil t))
2511 (error "No menu in this node"))
2512 (setq beg (point))
2513 (and (< (point) p)
2514 (save-excursion
2515 (goto-char p)
2516 (end-of-line)
2517 (if (re-search-backward (concat "\n\\* +\\("
2518 Info-menu-entry-name-re
2519 "\\):") beg t)
2520 (setq default (match-string-no-properties 1))))))
2521 (let ((item nil))
2522 (while (null item)
2523 (setq item (let ((completion-ignore-case t)
2524 (Info-complete-menu-buffer (current-buffer)))
2525 (completing-read (if default
2526 (format "Menu item (default %s): "
2527 default)
2528 "Menu item: ")
2529 'Info-complete-menu-item nil t)))
2530 ;; we rely on the fact that completing-read accepts an input
2531 ;; of "" even when the require-match argument is true and ""
2532 ;; is not a valid possibility
2533 (if (string= item "")
2534 (if default
2535 (setq item default)
2536 ;; ask again
2537 (setq item nil))))
2538 (list item current-prefix-arg))))
2539 ;; there is a problem here in that if several menu items have the same
2540 ;; name you can only go to the node of the first with this command.
2541 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
2543 (defun Info-extract-menu-item (menu-item)
2544 (setq menu-item (regexp-quote menu-item))
2545 (let ((case-fold-search t))
2546 (save-excursion
2547 (let ((case-fold-search t))
2548 (goto-char (point-min))
2549 (or (search-forward "\n* menu:" nil t)
2550 (error "No menu in this node"))
2551 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
2552 (re-search-forward (concat "\n\\* +" menu-item) nil t)
2553 (error "No such item in menu"))
2554 (beginning-of-line)
2555 (forward-char 2)
2556 (Info-extract-menu-node-name nil (Info-index-node))))))
2558 ;; If COUNT is nil, use the last item in the menu.
2559 (defun Info-extract-menu-counting (count &optional no-detail)
2560 (let ((case-fold-search t))
2561 (save-excursion
2562 (let ((case-fold-search t)
2563 (bound (when (and no-detail
2564 (re-search-forward
2565 "^[ \t-]*The Detailed Node Listing" nil t))
2566 (match-beginning 0))))
2567 (goto-char (point-min))
2568 (or (search-forward "\n* menu:" bound t)
2569 (error "No menu in this node"))
2570 (if count
2571 (or (search-forward "\n* " bound t count)
2572 (error "Too few items in menu"))
2573 (while (search-forward "\n* " bound t)
2574 nil))
2575 (Info-extract-menu-node-name nil (Info-index-node))))))
2577 (defun Info-nth-menu-item ()
2578 "Go to the node of the Nth menu item.
2579 N is the digit argument used to invoke this command."
2580 (interactive)
2581 (Info-goto-node
2582 (Info-extract-menu-counting
2583 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
2585 (defun Info-top-node ()
2586 "Go to the Top node of this file."
2587 (interactive)
2588 (Info-goto-node "Top"))
2590 (defun Info-final-node ()
2591 "Go to the final node in this file."
2592 (interactive)
2593 (Info-goto-node "Top")
2594 (let ((Info-history nil)
2595 (case-fold-search t))
2596 ;; Go to the last node in the menu of Top. But don't delve into
2597 ;; detailed node listings.
2598 (Info-goto-node (Info-extract-menu-counting nil t))
2599 ;; If the last node in the menu is not last in pointer structure,
2600 ;; move forward (but not down- or upward - see bug#1116) until we
2601 ;; can't go any farther.
2602 (while (Info-forward-node t t t) nil)
2603 ;; Then keep moving down to last subnode, unless we reach an index.
2604 (while (and (not (Info-index-node))
2605 (save-excursion (search-forward "\n* Menu:" nil t)))
2606 (Info-goto-node (Info-extract-menu-counting nil)))))
2608 (defun Info-forward-node (&optional not-down not-up no-error)
2609 "Go forward one node, considering all nodes as forming one sequence."
2610 (interactive)
2611 (goto-char (point-min))
2612 (forward-line 1)
2613 (let ((case-fold-search t))
2614 ;; three possibilities, in order of priority:
2615 ;; 1. next node is in a menu in this node (but not in an index)
2616 ;; 2. next node is next at same level
2617 ;; 3. next node is up and next
2618 (cond ((and (not not-down)
2619 (save-excursion (search-forward "\n* menu:" nil t))
2620 (not (Info-index-node)))
2621 (Info-goto-node (Info-extract-menu-counting 1))
2623 ((save-excursion (search-backward "next:" nil t))
2624 (Info-next)
2626 ((and (not not-up)
2627 (save-excursion (search-backward "up:" nil t))
2628 ;; Use string-equal, not equal, to ignore text props.
2629 (not (string-equal (downcase (Info-extract-pointer "up"))
2630 "top")))
2631 (let ((old-node Info-current-node))
2632 (Info-up)
2633 (let (Info-history success)
2634 (unwind-protect
2635 (setq success (Info-forward-node t nil no-error))
2636 (or success (Info-goto-node old-node))))))
2637 (no-error nil)
2638 (t (error "No pointer forward from this node")))))
2640 (defun Info-backward-node ()
2641 "Go backward one node, considering all nodes as forming one sequence."
2642 (interactive)
2643 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
2644 (upnode (Info-extract-pointer "up" t))
2645 (case-fold-search t))
2646 (cond ((and upnode (string-match "(" upnode))
2647 (error "First node in file"))
2648 ((and upnode (or (null prevnode)
2649 ;; Use string-equal, not equal,
2650 ;; to ignore text properties.
2651 (string-equal (downcase prevnode)
2652 (downcase upnode))))
2653 (Info-up))
2654 (prevnode
2655 ;; If we move back at the same level,
2656 ;; go down to find the last subnode*.
2657 (Info-prev)
2658 (let (Info-history)
2659 (while (and (not (Info-index-node))
2660 (save-excursion (search-forward "\n* Menu:" nil t)))
2661 (Info-goto-node (Info-extract-menu-counting nil)))))
2663 (error "No pointer backward from this node")))))
2665 (defun Info-exit ()
2666 "Exit Info by selecting some other buffer."
2667 (interactive)
2668 (if Info-standalone
2669 (save-buffers-kill-emacs)
2670 (quit-window)))
2672 (defun Info-next-menu-item ()
2673 "Go to the node of the next menu item."
2674 (interactive)
2675 ;; Bind this in case the user sets it to nil.
2676 (let* ((case-fold-search t)
2677 (node
2678 (save-excursion
2679 (forward-line -1)
2680 (search-forward "\n* menu:" nil t)
2681 (and (search-forward "\n* " nil t)
2682 (Info-extract-menu-node-name)))))
2683 (if node (Info-goto-node node)
2684 (error "No more items in menu"))))
2686 (defun Info-last-menu-item ()
2687 "Go to the node of the previous menu item."
2688 (interactive)
2689 (save-excursion
2690 (forward-line 1)
2691 ;; Bind this in case the user sets it to nil.
2692 (let* ((case-fold-search t)
2693 (beg (save-excursion
2694 (and (search-backward "\n* menu:" nil t)
2695 (point)))))
2696 (or (and beg (search-backward "\n* " beg t))
2697 (error "No previous items in menu")))
2698 (Info-goto-node (save-excursion
2699 (goto-char (match-end 0))
2700 (Info-extract-menu-node-name)))))
2702 (defmacro Info-no-error (&rest body)
2703 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
2705 (defun Info-next-preorder ()
2706 "Go to the next subnode or the next node, or go up a level."
2707 (interactive)
2708 (cond ((Info-no-error (Info-next-menu-item)))
2709 ((Info-no-error (Info-next)))
2710 ((Info-no-error (Info-up t))
2711 ;; Since we have already gone thru all the items in this menu,
2712 ;; go up to the end of this node.
2713 (goto-char (point-max))
2714 ;; Since logically we are done with the node with that menu,
2715 ;; move on from it. But don't add intermediate nodes
2716 ;; to the history on recursive calls.
2717 (let (Info-history)
2718 (Info-next-preorder)))
2720 (error "No more nodes"))))
2722 (defun Info-last-preorder ()
2723 "Go to the last node, popping up a level if there is none."
2724 (interactive)
2725 (cond ((Info-no-error
2726 (Info-last-menu-item)
2727 ;; If we go down a menu item, go to the end of the node
2728 ;; so we can scroll back through it.
2729 (goto-char (point-max)))
2730 ;; Keep going down, as long as there are nested menu nodes.
2731 (while (Info-no-error
2732 (Info-last-menu-item)
2733 ;; If we go down a menu item, go to the end of the node
2734 ;; so we can scroll back through it.
2735 (goto-char (point-max))))
2736 (recenter -1))
2737 ((and (Info-no-error (Info-extract-pointer "prev"))
2738 (not (equal (Info-extract-pointer "up")
2739 (Info-extract-pointer "prev"))))
2740 (Info-no-error (Info-prev))
2741 (goto-char (point-max))
2742 (while (Info-no-error
2743 (Info-last-menu-item)
2744 ;; If we go down a menu item, go to the end of the node
2745 ;; so we can scroll back through it.
2746 (goto-char (point-max))))
2747 (recenter -1))
2748 ((Info-no-error (Info-up t))
2749 (goto-char (point-min))
2750 (let ((case-fold-search t))
2751 (or (search-forward "\n* Menu:" nil t)
2752 (goto-char (point-max)))))
2753 (t (error "No previous nodes"))))
2755 (defun Info-scroll-up ()
2756 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2757 Once you scroll far enough in a node that its menu appears on the screen
2758 but after point, the next scroll moves into its first subnode, unless
2759 `Info-scroll-prefer-subnodes' is nil.
2761 When you scroll past the end of a node, that goes to the next node if
2762 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2763 if this node has no successor, it moves to the parent node's successor,
2764 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2765 the menu of a node, it moves to subnode indicated by the following menu
2766 item. (That case won't normally result from this command, but can happen
2767 in other ways.)"
2769 (interactive)
2770 (if (or (< (window-start) (point-min))
2771 (> (window-start) (point-max)))
2772 (set-window-start (selected-window) (point)))
2773 (let* ((case-fold-search t)
2774 (virtual-end (save-excursion
2775 (goto-char (point-min))
2776 (if (and Info-scroll-prefer-subnodes
2777 (search-forward "\n* Menu:" nil t))
2778 (point)
2779 (point-max)))))
2780 (if (or (< virtual-end (window-start))
2781 (pos-visible-in-window-p virtual-end))
2782 (cond
2783 (Info-scroll-prefer-subnodes (Info-next-preorder))
2784 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2785 (t (Info-next-preorder)))
2786 (scroll-up))))
2788 (defun Info-mouse-scroll-up (e)
2789 "Scroll one screenful forward in Info, using the mouse.
2790 See `Info-scroll-up'."
2791 (interactive "e")
2792 (save-selected-window
2793 (if (eventp e)
2794 (select-window (posn-window (event-start e))))
2795 (Info-scroll-up)))
2797 (defun Info-scroll-down ()
2798 "Scroll one screenful back in Info, considering all nodes as one sequence.
2799 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2800 is non-nil, this goes to its last subnode. When you scroll past the
2801 beginning of a node, that goes to the previous node or back up to the
2802 parent node."
2803 (interactive)
2804 (if (or (< (window-start) (point-min))
2805 (> (window-start) (point-max)))
2806 (set-window-start (selected-window) (point)))
2807 (let* ((case-fold-search t)
2808 (current-point (point))
2809 (virtual-end
2810 (and Info-scroll-prefer-subnodes
2811 (save-excursion
2812 (beginning-of-line)
2813 (setq current-point (point))
2814 (goto-char (point-min))
2815 (search-forward "\n* Menu:"
2816 current-point
2817 t)))))
2818 (if (or virtual-end
2819 (pos-visible-in-window-p (point-min) nil t))
2820 (Info-last-preorder)
2821 (scroll-down))))
2823 (defun Info-mouse-scroll-down (e)
2824 "Scroll one screenful backward in Info, using the mouse.
2825 See `Info-scroll-down'."
2826 (interactive "e")
2827 (save-selected-window
2828 (if (eventp e)
2829 (select-window (posn-window (event-start e))))
2830 (Info-scroll-down)))
2832 (defun Info-next-reference (&optional recur)
2833 "Move cursor to the next cross-reference or menu item in the node."
2834 (interactive)
2835 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2836 (old-pt (point))
2837 (case-fold-search t))
2838 (or (eobp) (forward-char 1))
2839 (or (re-search-forward pat nil t)
2840 (progn
2841 (goto-char (point-min))
2842 (or (re-search-forward pat nil t)
2843 (progn
2844 (goto-char old-pt)
2845 (error "No cross references in this node")))))
2846 (goto-char (or (match-beginning 1) (match-beginning 0)))
2847 (if (looking-at "\\* Menu:")
2848 (if recur
2849 (error "No cross references in this node")
2850 (Info-next-reference t))
2851 (if (looking-at "^\\* ")
2852 (forward-char 2)))))
2854 (defun Info-prev-reference (&optional recur)
2855 "Move cursor to the previous cross-reference or menu item in the node."
2856 (interactive)
2857 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2858 (old-pt (point))
2859 (case-fold-search t))
2860 (or (re-search-backward pat nil t)
2861 (progn
2862 (goto-char (point-max))
2863 (or (re-search-backward pat nil t)
2864 (progn
2865 (goto-char old-pt)
2866 (error "No cross references in this node")))))
2867 (goto-char (or (match-beginning 1) (match-beginning 0)))
2868 (if (looking-at "\\* Menu:")
2869 (if recur
2870 (error "No cross references in this node")
2871 (Info-prev-reference t))
2872 (if (looking-at "^\\* ")
2873 (forward-char 2)))))
2875 (defvar Info-index-nodes nil
2876 "Alist of cached index node names of visited Info files.
2877 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2879 (defun Info-index-nodes (&optional file)
2880 "Return a list of names of all index nodes in Info FILE.
2881 If FILE is omitted, it defaults to the current Info file.
2882 First look in a list of cached index node names. Then scan Info
2883 file and its subfiles for nodes with the index cookie. Then try
2884 to find index nodes starting from the first node in the top level
2885 menu whose name contains the word \"Index\", plus any immediately
2886 following nodes whose names also contain the word \"Index\"."
2887 (or file (setq file Info-current-file))
2888 (or (assoc file Info-index-nodes)
2889 ;; Skip virtual Info files
2890 (and (or (not (stringp file))
2891 (Info-virtual-file-p file))
2892 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
2893 (if (Info-file-supports-index-cookies file)
2894 ;; Find nodes with index cookie
2895 (let* ((default-directory (or (and (stringp file)
2896 (file-name-directory
2897 (setq file (Info-find-file file))))
2898 default-directory))
2899 Info-history Info-history-list Info-fontify-maximum-menu-size
2900 (main-file file) subfiles nodes node)
2901 (condition-case nil
2902 (with-temp-buffer
2903 (while (or main-file subfiles)
2904 (erase-buffer)
2905 (info-insert-file-contents (or main-file (car subfiles)))
2906 (goto-char (point-min))
2907 (while (search-forward "\0\b[index\0\b]" nil 'move)
2908 (save-excursion
2909 (re-search-backward "^\^_")
2910 (search-forward "Node: ")
2911 (setq nodes (cons (Info-following-node-name) nodes))))
2912 (if main-file
2913 (save-excursion
2914 (goto-char (point-min))
2915 (if (search-forward "\n\^_\nIndirect:" nil t)
2916 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2917 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2918 (setq subfiles (cons (match-string-no-properties 1)
2919 subfiles)))))
2920 (setq subfiles (nreverse subfiles)
2921 main-file nil))
2922 (setq subfiles (cdr subfiles)))))
2923 (error nil))
2924 (if nodes
2925 (setq nodes (nreverse nodes)
2926 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2927 nodes)
2928 ;; Else find nodes with the word "Index" in the node name
2929 (let ((case-fold-search t)
2930 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
2931 nodes node)
2932 (condition-case nil
2933 (with-temp-buffer
2934 (Info-mode)
2935 (Info-find-node file "Top")
2936 (when (and (search-forward "\n* menu:" nil t)
2937 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2938 (goto-char (match-beginning 1))
2939 (setq nodes (list (Info-extract-menu-node-name)))
2940 (Info-goto-node (car nodes))
2941 (while (and (setq node (Info-extract-pointer "next" t))
2942 (string-match "\\<Index\\>" node))
2943 (setq nodes (cons node nodes))
2944 (Info-goto-node node))))
2945 (error nil))
2946 (if nodes
2947 (setq nodes (nreverse nodes)
2948 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2949 nodes))
2950 ;; If file has no index nodes, still add it to the cache
2951 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
2952 (cdr (assoc file Info-index-nodes)))
2954 (defun Info-index-node (&optional node file)
2955 "Return non-nil value if NODE is an index node.
2956 If NODE is nil, check the current Info node.
2957 If FILE is nil, check the current Info file."
2958 (or file (setq file Info-current-file))
2959 (if (and (or (and node (not (equal node Info-current-node)))
2960 (assoc file Info-index-nodes))
2961 (not Info-current-node-virtual))
2962 (member (or node Info-current-node) (Info-index-nodes file))
2963 ;; Don't search all index nodes if request is only for the current node
2964 ;; and file is not in the cache of index nodes
2965 (save-match-data
2966 (if (Info-file-supports-index-cookies file)
2967 (save-excursion
2968 (goto-char (+ (or (save-excursion
2969 (search-backward "\n\^_" nil t))
2970 (point-min)) 2))
2971 (search-forward "\0\b[index\0\b]"
2972 (or (save-excursion
2973 (search-forward "\n\^_" nil t))
2974 (point-max)) t))
2975 (string-match "\\<Index\\>" (or node Info-current-node ""))))))
2977 (defun Info-goto-index ()
2978 "Go to the first index node."
2979 (let ((node (car (Info-index-nodes))))
2980 (or node (error "No index"))
2981 (Info-goto-node node)))
2983 ;;;###autoload
2984 (defun Info-index (topic)
2985 "Look up a string TOPIC in the index for this manual and go to that entry.
2986 If there are no exact matches to the specified topic, this chooses
2987 the first match which is a case-insensitive substring of a topic.
2988 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
2989 Give an empty topic name to go to the Index node itself."
2990 (interactive
2991 (list
2992 (let ((completion-ignore-case t)
2993 (Info-complete-menu-buffer (clone-buffer))
2994 (Info-complete-nodes (Info-index-nodes))
2995 (Info-history-list nil))
2996 (if (equal Info-current-file "dir")
2997 (error "The Info directory node has no index; use m to select a manual"))
2998 (unwind-protect
2999 (with-current-buffer Info-complete-menu-buffer
3000 (Info-goto-index)
3001 (completing-read "Index topic: " 'Info-complete-menu-item))
3002 (kill-buffer Info-complete-menu-buffer)))))
3003 (if (equal Info-current-file "dir")
3004 (error "The Info directory node has no index; use m to select a manual"))
3005 ;; Strip leading colon in topic; index format does not allow them.
3006 (if (and (stringp topic)
3007 (> (length topic) 0)
3008 (= (aref topic 0) ?:))
3009 (setq topic (substring topic 1)))
3010 (let ((orignode Info-current-node)
3011 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3012 (regexp-quote topic)))
3013 node (nodes (Info-index-nodes))
3014 (ohist-list Info-history-list)
3015 (case-fold-search t))
3016 (Info-goto-index)
3017 (or (equal topic "")
3018 (let ((matches nil)
3019 (exact nil)
3020 ;; We bind Info-history to nil for internal node-switches so
3021 ;; that we don't put junk in the history. In the first
3022 ;; Info-goto-index call, above, we do update the history
3023 ;; because that is what the user's previous node choice into it.
3024 (Info-history nil)
3025 found)
3026 (while
3027 (progn
3028 (goto-char (point-min))
3029 (while (re-search-forward pattern nil t)
3030 (push (list (match-string-no-properties 1)
3031 (match-string-no-properties 2)
3032 Info-current-node
3033 (string-to-number (concat "0"
3034 (match-string 3))))
3035 matches))
3036 (setq nodes (cdr nodes) node (car nodes)))
3037 (Info-goto-node node))
3038 (or matches
3039 (progn
3040 (Info-goto-node orignode)
3041 (error "No `%s' in index" topic)))
3042 ;; Here it is a feature that assoc is case-sensitive.
3043 (while (setq found (assoc topic matches))
3044 (setq exact (cons found exact)
3045 matches (delq found matches)))
3046 (setq Info-history-list ohist-list)
3047 (setq Info-index-alternatives (nconc exact (nreverse matches)))
3048 (Info-index-next 0)))))
3050 (defun Info-index-next (num)
3051 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3052 (interactive "p")
3053 (or Info-index-alternatives
3054 (error "No previous `i' command"))
3055 (while (< num 0)
3056 (setq num (+ num (length Info-index-alternatives))))
3057 (while (> num 0)
3058 (setq Info-index-alternatives
3059 (nconc (cdr Info-index-alternatives)
3060 (list (car Info-index-alternatives)))
3061 num (1- num)))
3062 (Info-goto-node (nth 1 (car Info-index-alternatives)))
3063 (if (> (nth 3 (car Info-index-alternatives)) 0)
3064 (forward-line (1- (nth 3 (car Info-index-alternatives))))
3065 (forward-line 3) ; don't search in headers
3066 (let ((name (car (car Info-index-alternatives))))
3067 (Info-find-index-name name)))
3068 (message "Found `%s' in %s. %s"
3069 (car (car Info-index-alternatives))
3070 (nth 2 (car Info-index-alternatives))
3071 (if (cdr Info-index-alternatives)
3072 (format "(%s total; use `%s' for next)"
3073 (length Info-index-alternatives)
3074 (key-description (where-is-internal
3075 'Info-index-next overriding-local-map
3076 t)))
3077 "(Only match)")))
3079 (defun Info-find-index-name (name)
3080 "Move point to the place within the current node where NAME is defined."
3081 (let ((case-fold-search t))
3082 (if (or (re-search-forward (format
3083 "[a-zA-Z]+: %s\\( \\|$\\)"
3084 (regexp-quote name)) nil t)
3085 ;; Find a function definition with a return type.
3086 (re-search-forward (format
3087 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3088 (regexp-quote name)) nil t)
3089 (search-forward (format "`%s'" name) nil t)
3090 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
3091 (search-forward
3092 (format "`%s'" (substring name 0 (match-beginning 1)))
3093 nil t))
3094 (search-forward name nil t)
3095 ;; Try again without the " <1>" makeinfo can append
3096 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
3097 (Info-find-index-name (match-string 1 name))))
3098 (progn (beginning-of-line) t) ;; non-nil for recursive call
3099 (goto-char (point-min)))))
3101 (add-to-list 'Info-virtual-nodes
3102 '("\\`\\*Index.*\\*\\'"
3103 (find-node . Info-virtual-index-find-node)
3106 (defvar Info-virtual-index-nodes nil
3107 "Alist of cached matched index search nodes.
3108 Each element is ((FILENAME . TOPIC) MATCHES) where
3109 FILENAME is the file name of the manual,
3110 TOPIC is the search string given as an argument to `Info-virtual-index',
3111 MATCHES is a list of index matches found by `Info-index'.")
3113 (defun Info-virtual-index-find-node (filename nodename &optional no-going-back)
3114 "Index-specific implementation of Info-find-node-2."
3115 ;; Generate Index-like menu of matches
3116 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename)
3117 ;; Generate Index-like menu of matches
3118 (let* ((topic (match-string 1 nodename))
3119 (matches (cdr (assoc (cons (or filename Info-current-file) topic)
3120 Info-virtual-index-nodes))))
3121 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3122 (or filename Info-current-file) nodename))
3123 (insert "Info Virtual Index\n")
3124 (insert "******************\n\n")
3125 (insert "Index entries that match `" topic "':\n\n")
3126 (insert "\0\b[index\0\b]\n")
3127 (if (null matches)
3128 (insert "No matches found.\n")
3129 (insert "* Menu:\n\n")
3130 (dolist (entry matches)
3131 (insert (format "* %-38s %s.%s\n"
3132 (format "%s [%s]:" (nth 0 entry) (nth 2 entry))
3133 (nth 1 entry)
3134 (if (nth 3 entry)
3135 (format " (line %s)" (nth 3 entry))
3136 ""))))))
3137 ;; Else, Generate a list of previous search results
3138 (let ((nodes (reverse Info-virtual-index-nodes)))
3139 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3140 (or filename Info-current-file) nodename))
3141 (insert "Info Virtual Index\n")
3142 (insert "******************\n\n")
3143 (insert "This is a list of search results produced by\n"
3144 "`Info-virtual-index' for the current manual.\n\n")
3145 (insert "* Menu:\n\n")
3146 (dolist (nodeinfo nodes)
3147 (when (equal (car (nth 0 nodeinfo)) (or filename Info-current-file))
3148 (insert
3149 (format "* %-20s %s.\n"
3150 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo)))
3151 (cdr (nth 0 nodeinfo)))))))))
3153 (defun Info-virtual-index (topic)
3154 "Show a node with all lines in the index containing a string TOPIC.
3155 Like `Info-index' but displays a node with index search results.
3156 Give an empty topic name to go to the node with links to previous
3157 search results."
3158 ;; `interactive' is a copy from `Info-index'
3159 (interactive
3160 (list
3161 (let ((completion-ignore-case t)
3162 (Info-complete-menu-buffer (clone-buffer))
3163 (Info-complete-nodes (Info-index-nodes))
3164 (Info-history-list nil))
3165 (if (equal Info-current-file "dir")
3166 (error "The Info directory node has no index; use m to select a manual"))
3167 (unwind-protect
3168 (with-current-buffer Info-complete-menu-buffer
3169 (Info-goto-index)
3170 (completing-read "Index topic: " 'Info-complete-menu-item))
3171 (kill-buffer Info-complete-menu-buffer)))))
3172 (if (equal topic "")
3173 (Info-find-node Info-current-file "*Index*")
3174 (unless (assoc (cons Info-current-file topic) Info-virtual-index-nodes)
3175 (let ((orignode Info-current-node)
3176 (ohist-list Info-history-list)
3177 nodename)
3178 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3179 (Info-index topic)
3180 (push (cons (cons Info-current-file topic) Info-index-alternatives)
3181 Info-virtual-index-nodes)
3182 ;; Clean up unneccessary side-effects of `Info-index'.
3183 (setq Info-history-list ohist-list)
3184 (Info-goto-node orignode)
3185 (message "")))
3186 (Info-find-node Info-current-file (format "*Index for `%s'*" topic))))
3188 (add-to-list 'Info-virtual-files
3189 '("\\`\\*Apropos\\*\\'"
3190 (toc-nodes . Info-apropos-toc-nodes)
3191 (find-file . Info-apropos-find-file)
3192 (find-node . Info-apropos-find-node)
3195 (defvar Info-apropos-file "*Apropos*"
3196 "Info file name of the virtual manual for matches of `info-apropos'.")
3198 (defvar Info-apropos-nodes nil
3199 "Alist of cached apropos matched nodes.
3200 Each element is (NODENAME STRING MATCHES) where
3201 NODENAME is the name of the node that holds the search result,
3202 STRING is the search string given as an argument to `info-apropos',
3203 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3205 (defun Info-apropos-toc-nodes (filename)
3206 "Apropos-specific implementation of Info-apropos-toc-nodes."
3207 (let ((nodes (mapcar 'car (reverse Info-apropos-nodes))))
3208 `(,filename
3209 ("Top" nil nil ,nodes)
3210 ,@(mapcar (lambda (node) `(,node "Top" nil nil)) nodes))))
3212 (defun Info-apropos-find-file (filename &optional noerror)
3213 "Apropos-specific implementation of Info-find-file."
3214 filename)
3216 (defun Info-apropos-find-node (filename nodename &optional no-going-back)
3217 "Apropos-specific implementation of Info-find-node-2."
3218 (if (equal nodename "Top")
3219 ;; Generate Top menu
3220 (let ((nodes (reverse Info-apropos-nodes)))
3221 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3222 Info-apropos-file nodename))
3223 (insert "Apropos Index\n")
3224 (insert "*************\n\n")
3225 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3226 (insert "* Menu:\n\n")
3227 (dolist (nodeinfo nodes)
3228 (insert (format "* %-20s %s.\n"
3229 (format "%s::" (nth 0 nodeinfo))
3230 (nth 1 nodeinfo)))))
3231 ;; Else, Generate Index-like menu of matches
3232 (let* ((nodeinfo (assoc nodename Info-apropos-nodes))
3233 (matches (nth 2 nodeinfo)))
3234 (when matches
3235 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3236 Info-apropos-file nodename))
3237 (insert "Apropos Index\n")
3238 (insert "*************\n\n")
3239 (insert "Index entries that match `" (nth 1 nodeinfo) "':\n\n")
3240 (insert "\0\b[index\0\b]\n")
3241 (if (eq matches t)
3242 (insert "No matches found.\n")
3243 (insert "* Menu:\n\n")
3244 (dolist (entry matches)
3245 (insert (format "* %-38s (%s)%s.%s\n"
3246 (format "%s [%s]:" (nth 1 entry) (nth 0 entry))
3247 (nth 0 entry)
3248 (nth 2 entry)
3249 (if (nth 3 entry)
3250 (format " (line %s)" (nth 3 entry))
3251 "")))))))))
3253 (defun Info-apropos-matches (string)
3254 "Collect STRING matches from all known Info files on your system.
3255 Return a list of matches where each element is in the format
3256 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3257 (interactive "sIndex apropos: ")
3258 (unless (string= string "")
3259 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3260 (regexp-quote string)))
3261 (ohist Info-history)
3262 (ohist-list Info-history-list)
3263 (current-node Info-current-node)
3264 (current-file Info-current-file)
3265 manuals matches node nodes)
3266 (let ((Info-fontify-maximum-menu-size nil))
3267 (Info-directory)
3268 ;; current-node and current-file are nil when they invoke info-apropos
3269 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3270 ;; case, we use (DIR)Top instead, to avoid signalling an error after
3271 ;; the search is complete.
3272 (when (null current-node)
3273 (setq current-file Info-current-file)
3274 (setq current-node Info-current-node))
3275 (message "Searching indices...")
3276 (goto-char (point-min))
3277 (re-search-forward "\\* Menu: *\n" nil t)
3278 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
3279 ;; add-to-list makes sure we don't have duplicates in `manuals',
3280 ;; so that the following dolist loop runs faster.
3281 (add-to-list 'manuals (match-string 1)))
3282 (dolist (manual (nreverse manuals))
3283 (message "Searching %s" manual)
3284 (condition-case err
3285 (if (setq nodes (Info-index-nodes (Info-find-file manual)))
3286 (save-excursion
3287 (Info-find-node manual (car nodes))
3288 (while
3289 (progn
3290 (goto-char (point-min))
3291 (while (re-search-forward pattern nil t)
3292 (setq matches
3293 (cons (list manual
3294 (match-string-no-properties 1)
3295 (match-string-no-properties 2)
3296 (match-string-no-properties 3))
3297 matches)))
3298 (setq nodes (cdr nodes) node (car nodes)))
3299 (Info-goto-node node))))
3300 (error
3301 (message "%s" (if (eq (car-safe err) 'error)
3302 (nth 1 err) err))
3303 (sit-for 1 t)))))
3304 (Info-find-node current-file current-node)
3305 (setq Info-history ohist
3306 Info-history-list ohist-list)
3307 (message "Searching indices...done")
3308 (or (nreverse matches) t))))
3310 ;;;###autoload
3311 (defun info-apropos (string)
3312 "Grovel indices of all known Info files on your system for STRING.
3313 Build a menu of the possible matches."
3314 (interactive "sIndex apropos: ")
3315 (if (equal string "")
3316 (Info-find-node Info-apropos-file "Top")
3317 (let* ((nodes Info-apropos-nodes) nodename)
3318 (while (and nodes (not (equal string (nth 1 (car nodes)))))
3319 (setq nodes (cdr nodes)))
3320 (if nodes
3321 (Info-find-node Info-apropos-file (car (car nodes)))
3322 (setq nodename (format "Index for `%s'" string))
3323 (push (list nodename string (Info-apropos-matches string))
3324 Info-apropos-nodes)
3325 (Info-find-node Info-apropos-file nodename)))))
3327 (defun Info-undefined ()
3328 "Make command be undefined in Info."
3329 (interactive)
3330 (ding))
3332 (defun Info-help ()
3333 "Enter the Info tutorial."
3334 (interactive)
3335 (delete-other-windows)
3336 (Info-find-node "info"
3337 (if (< (window-height) 23)
3338 "Help-Small-Screen"
3339 "Help")))
3341 (defun Info-summary ()
3342 "Display a brief summary of all Info commands."
3343 (interactive)
3344 (save-window-excursion
3345 (switch-to-buffer "*Help*")
3346 (setq buffer-read-only nil)
3347 (erase-buffer)
3348 (insert (documentation 'Info-mode))
3349 (help-mode)
3350 (goto-char (point-min))
3351 (let (ch flag)
3352 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
3353 (message (if flag "Type Space to see more"
3354 "Type Space to return to Info"))
3355 (if (not (eq ?\s (setq ch (read-event))))
3356 (progn (setq unread-command-events (list ch)) nil)
3357 flag))
3358 (scroll-up)))
3359 (bury-buffer "*Help*")))
3361 (defun Info-get-token (pos start all &optional errorstring)
3362 "Return the token around POS.
3363 POS must be somewhere inside the token
3364 START is a regular expression which will match the
3365 beginning of the tokens delimited string
3366 ALL is a regular expression with a single
3367 parenthesized subpattern which is the token to be
3368 returned. E.g. '{\(.*\)}' would return any string
3369 enclosed in braces around POS.
3370 ERRORSTRING optional fourth argument, controls action on no match
3371 nil: return nil
3372 t: beep
3373 a string: signal an error, using that string."
3374 (let ((case-fold-search t))
3375 (save-excursion
3376 (goto-char pos)
3377 ;; First look for a match for START that goes across POS.
3378 (while (and (not (bobp)) (> (point) (- pos (length start)))
3379 (not (looking-at start)))
3380 (forward-char -1))
3381 ;; If we did not find one, search back for START
3382 ;; (this finds only matches that end at or before POS).
3383 (or (looking-at start)
3384 (progn
3385 (goto-char pos)
3386 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
3387 (let (found)
3388 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
3389 (not (setq found (and (<= (match-beginning 0) pos)
3390 (> (match-end 0) pos))))))
3391 (if (and found (<= (match-beginning 0) pos)
3392 (> (match-end 0) pos))
3393 (match-string-no-properties 1)
3394 (cond ((null errorstring)
3395 nil)
3396 ((eq errorstring t)
3397 (beep)
3398 nil)
3400 (error "No %s around position %d" errorstring pos))))))))
3402 (defun Info-mouse-follow-nearest-node (click)
3403 "\\<Info-mode-map>Follow a node reference near point.
3404 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3405 At end of the node's text, moves to the next node, or up if none."
3406 (interactive "e")
3407 (mouse-set-point click)
3408 (and (not (Info-follow-nearest-node))
3409 (save-excursion (forward-line 1) (eobp))
3410 (Info-next-preorder)))
3412 (defun Info-follow-nearest-node (&optional fork)
3413 "Follow a node reference near point.
3414 If point is on a reference, follow that reference. Otherwise,
3415 if point is in a menu item description, follow that menu item.
3417 If FORK is non-nil (interactively with a prefix arg), show the node in
3418 a new Info buffer.
3419 If FORK is a string, it is the name to use for the new buffer."
3420 (interactive "P")
3421 (or (Info-try-follow-nearest-node fork)
3422 (when (save-excursion
3423 (search-backward "\n* menu:" nil t))
3424 (save-excursion
3425 (beginning-of-line)
3426 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3427 (beginning-of-line 0))
3428 (when (looking-at "\\* +\\([^\t\n]*\\):")
3429 (Info-goto-node
3430 (Info-extract-menu-item (match-string-no-properties 1)) fork)
3431 t)))
3432 (and (eq this-command 'Info-mouse-follow-nearest-node)
3433 ;; Don't raise an error when mouse-1 is bound to this - it's
3434 ;; often used to simply select the window or frame.
3435 (eq 'mouse-1 (event-basic-type last-input-event)))
3436 (error "Point neither on reference nor in menu item description")))
3438 ;; Common subroutine.
3439 (defun Info-try-follow-nearest-node (&optional fork)
3440 "Follow a node reference near point. Return non-nil if successful.
3441 If FORK is non-nil, it is passed to `Info-goto-node'."
3442 (let (node)
3443 (cond
3444 ((Info-get-token (point) "[hf]t?tps?://" "[hf]t?tps?://\\([^ \t\n\"`({<>})']+\\)")
3445 (setq node t)
3446 (browse-url (browse-url-url-at-point)))
3447 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
3448 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3449 (Info-follow-reference node fork))
3450 ;; menu item: node name
3451 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3452 (Info-goto-node node fork))
3453 ;; menu item: node name or index entry
3454 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3455 (beginning-of-line)
3456 (forward-char 2)
3457 (setq node (Info-extract-menu-node-name nil (Info-index-node)))
3458 (Info-goto-node node fork))
3459 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3460 (Info-goto-node node fork))
3461 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3462 (Info-goto-node node fork))
3463 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3464 (Info-goto-node "Top" fork))
3465 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3466 (Info-goto-node node fork)))
3467 node))
3469 (defvar Info-mode-map
3470 (let ((map (make-keymap)))
3471 (suppress-keymap map)
3472 (define-key map "." 'beginning-of-buffer)
3473 (define-key map " " 'Info-scroll-up)
3474 (define-key map "\C-m" 'Info-follow-nearest-node)
3475 (define-key map "\t" 'Info-next-reference)
3476 (define-key map "\e\t" 'Info-prev-reference)
3477 (define-key map [(shift tab)] 'Info-prev-reference)
3478 (define-key map [backtab] 'Info-prev-reference)
3479 (define-key map "1" 'Info-nth-menu-item)
3480 (define-key map "2" 'Info-nth-menu-item)
3481 (define-key map "3" 'Info-nth-menu-item)
3482 (define-key map "4" 'Info-nth-menu-item)
3483 (define-key map "5" 'Info-nth-menu-item)
3484 (define-key map "6" 'Info-nth-menu-item)
3485 (define-key map "7" 'Info-nth-menu-item)
3486 (define-key map "8" 'Info-nth-menu-item)
3487 (define-key map "9" 'Info-nth-menu-item)
3488 (define-key map "0" 'undefined)
3489 (define-key map "?" 'Info-summary)
3490 (define-key map "]" 'Info-forward-node)
3491 (define-key map "[" 'Info-backward-node)
3492 (define-key map "<" 'Info-top-node)
3493 (define-key map ">" 'Info-final-node)
3494 (define-key map "b" 'beginning-of-buffer)
3495 (define-key map "d" 'Info-directory)
3496 (define-key map "e" 'Info-edit)
3497 (define-key map "f" 'Info-follow-reference)
3498 (define-key map "g" 'Info-goto-node)
3499 (define-key map "h" 'Info-help)
3500 (define-key map "i" 'Info-index)
3501 (define-key map "I" 'Info-virtual-index)
3502 (define-key map "l" 'Info-history-back)
3503 (define-key map "L" 'Info-history)
3504 (define-key map "m" 'Info-menu)
3505 (define-key map "n" 'Info-next)
3506 (define-key map "p" 'Info-prev)
3507 (define-key map "q" 'Info-exit)
3508 (define-key map "r" 'Info-history-forward)
3509 (define-key map "s" 'Info-search)
3510 (define-key map "S" 'Info-search-case-sensitively)
3511 (define-key map "\M-n" 'clone-buffer)
3512 (define-key map "t" 'Info-top-node)
3513 (define-key map "T" 'Info-toc)
3514 (define-key map "u" 'Info-up)
3515 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3516 (define-key map "w" 'Info-copy-current-node-name)
3517 (define-key map "c" 'Info-copy-current-node-name)
3518 ;; `^' for consistency with `dired-up-directory'.
3519 (define-key map "^" 'Info-up)
3520 (define-key map "," 'Info-index-next)
3521 (define-key map "\177" 'Info-scroll-down)
3522 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3523 (define-key map [follow-link] 'mouse-face)
3524 map)
3525 "Keymap containing Info commands.")
3528 (defun Info-check-pointer (item)
3529 "Non-nil if ITEM is present in this node."
3530 (condition-case nil
3531 (Info-extract-pointer item)
3532 (error nil)))
3534 (easy-menu-define
3535 Info-mode-menu Info-mode-map
3536 "Menu for Info files."
3537 '("Info"
3538 ["Up" Info-up :active (Info-check-pointer "up")
3539 :help "Go up in the Info tree"]
3540 ["Next" Info-next :active (Info-check-pointer "next")
3541 :help "Go to the next node"]
3542 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3543 :help "Go to the previous node"]
3544 ["Backward" Info-backward-node
3545 :help "Go backward one node, considering all as a sequence"]
3546 ["Forward" Info-forward-node
3547 :help "Go forward one node, considering all as a sequence"]
3548 ["Beginning" beginning-of-buffer
3549 :help "Go to beginning of this node"]
3550 ["Top" Info-top-node
3551 :help "Go to top node of file"]
3552 ["Final Node" Info-final-node
3553 :help "Go to final node in this file"]
3554 ("Menu Item" ["You should never see this" report-emacs-bug t])
3555 ("Reference" ["You should never see this" report-emacs-bug t])
3556 ["Search..." Info-search
3557 :help "Search for regular expression in this Info file"]
3558 ["Search Next" Info-search-next
3559 :help "Search for another occurrence of regular expression"]
3560 ["Go to Node..." Info-goto-node
3561 :help "Go to a named node"]
3562 ["Back in history" Info-history-back :active Info-history
3563 :help "Go back in history to the last node you were at"]
3564 ["Forward in history" Info-history-forward :active Info-history-forward
3565 :help "Go forward in history"]
3566 ["History" Info-history :active Info-history-list
3567 :help "Go to menu of visited nodes"]
3568 ["Table of Contents" Info-toc
3569 :help "Go to table of contents"]
3570 ("Index"
3571 ["Lookup a String..." Info-index
3572 :help "Look for a string in the index items"]
3573 ["Next Matching Item" Info-index-next :active Info-index-alternatives
3574 :help "Look for another occurrence of previous item"]
3575 ["Lookup a string in all indices..." info-apropos
3576 :help "Look for a string in the indices of all manuals"])
3577 ["Copy Node Name" Info-copy-current-node-name
3578 :help "Copy the name of the current node into the kill ring"]
3579 ["Clone Info buffer" clone-buffer
3580 :help "Create a twin copy of the current Info buffer."]
3581 ["Exit" Info-exit :help "Stop reading Info"]))
3584 (defvar info-tool-bar-map
3585 (let ((map (make-sparse-keymap)))
3586 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
3587 :rtl "right-arrow")
3588 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
3589 :rtl "left-arrow")
3590 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
3591 :rtl "next-node")
3592 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
3593 :rtl "prev-node")
3594 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map)
3595 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
3596 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
3597 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
3598 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
3599 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map)
3600 map))
3602 (defvar Info-menu-last-node nil)
3603 ;; Last node the menu was created for.
3604 ;; Value is a list, (FILE-NAME NODE-NAME).
3606 (defun Info-menu-update ()
3607 "Update the Info menu for the current node."
3608 (condition-case nil
3609 (if (or (not (eq major-mode 'Info-mode))
3610 (equal (list Info-current-file Info-current-node)
3611 Info-menu-last-node))
3613 ;; Update menu menu.
3614 (let* ((Info-complete-menu-buffer (current-buffer))
3615 (items (nreverse (condition-case nil
3616 (Info-complete-menu-item "" nil t)
3617 (error nil))))
3618 entries current
3619 (number 0))
3620 (while (and items (< number 9))
3621 (setq current (car items)
3622 items (cdr items)
3623 number (1+ number))
3624 (setq entries (cons `[,current
3625 (Info-menu ,current)
3626 :keys ,(format "%d" number)]
3627 entries)))
3628 (if items
3629 (setq entries (cons ["Other..." Info-menu t] entries)))
3630 (or entries
3631 (setq entries (list ["No menu" nil nil] nil :active)))
3632 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3633 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3634 (let ((items nil)
3635 str i entries current
3636 (number 0)
3637 (case-fold-search t))
3638 (save-excursion
3639 (goto-char (point-min))
3640 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3641 (setq str (match-string 1))
3642 (setq i 0)
3643 (while (setq i (string-match "[ \n\t]+" str i))
3644 (setq str (concat (substring str 0 i) " "
3645 (substring str (match-end 0))))
3646 (setq i (1+ i)))
3647 (setq items
3648 (cons str items))))
3649 (while (and items (< number 9))
3650 (setq current (car items)
3651 items (cdr items)
3652 number (1+ number))
3653 (setq entries (cons `[,current
3654 (Info-follow-reference ,current)
3656 entries)))
3657 (if items
3658 (setq entries (cons ["Other..." Info-follow-reference t]
3659 entries)))
3660 (or entries
3661 (setq entries (list ["No references" nil nil] nil :active)))
3662 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3663 ;; Update last seen node.
3664 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3665 ;; Try to avoid entering infinite beep mode in case of errors.
3666 (error (ding))))
3669 (defun Info-copy-current-node-name (&optional arg)
3670 "Put the name of the current Info node into the kill ring.
3671 The name of the Info file is prepended to the node name in parentheses.
3672 With a zero prefix arg, put the name inside a function call to `info'."
3673 (interactive "P")
3674 (unless Info-current-node
3675 (error "No current Info node"))
3676 (let ((node (if (stringp Info-current-file)
3677 (concat "(" (file-name-nondirectory Info-current-file) ") "
3678 Info-current-node))))
3679 (if (zerop (prefix-numeric-value arg))
3680 (setq node (concat "(info \"" node "\")")))
3681 (unless (stringp Info-current-file)
3682 (setq node (format "(Info-find-node '%S '%S)"
3683 Info-current-file Info-current-node)))
3684 (kill-new node)
3685 (message "%s" node)))
3688 ;; Info mode is suitable only for specially formatted data.
3689 (put 'Info-mode 'mode-class 'special)
3690 (put 'Info-mode 'no-clone-indirect t)
3692 (defvar tool-bar-map)
3693 (defvar bookmark-make-record-function)
3695 ;; Autoload cookie needed by desktop.el
3696 ;;;###autoload
3697 (defun Info-mode ()
3698 "Info mode provides commands for browsing through the Info documentation tree.
3699 Documentation in Info is divided into \"nodes\", each of which discusses
3700 one topic and contains references to other nodes which discuss related
3701 topics. Info has commands to follow the references and show you other nodes.
3703 \\<Info-mode-map>\
3704 \\[Info-help] Invoke the Info tutorial.
3705 \\[Info-exit] Quit Info: reselect previously selected buffer.
3707 Selecting other nodes:
3708 \\[Info-mouse-follow-nearest-node]
3709 Follow a node reference you click on.
3710 This works with menu items, cross references, and
3711 the \"next\", \"previous\" and \"up\", depending on where you click.
3712 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3713 \\[Info-next] Move to the \"next\" node of this node.
3714 \\[Info-prev] Move to the \"previous\" node of this node.
3715 \\[Info-up] Move \"up\" from this node.
3716 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3717 Picking a menu item causes another node to be selected.
3718 \\[Info-directory] Go to the Info directory node.
3719 \\[Info-top-node] Go to the Top node of this file.
3720 \\[Info-final-node] Go to the final node in this file.
3721 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3722 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3723 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3724 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
3725 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3726 \\[Info-history-back] Move back in history to the last node you were at.
3727 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3728 \\[Info-history] Go to menu of visited nodes.
3729 \\[Info-toc] Go to table of contents of the current Info file.
3731 Moving within a node:
3732 \\[Info-scroll-up] Normally, scroll forward a full screen.
3733 Once you scroll far enough in a node that its menu appears on the
3734 screen but after point, the next scroll moves into its first
3735 subnode. When after all menu items (or if there is no menu),
3736 move up to the parent node.
3737 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3738 already visible, try to go to the previous menu entry, or up
3739 if there is none.
3740 \\[beginning-of-buffer] Go to beginning of node.
3742 Advanced commands:
3743 \\[Info-search] Search through this Info file for specified regexp,
3744 and select the node in which the next occurrence is found.
3745 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3746 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
3747 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
3748 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3749 \\[info-apropos] Look for a string in the indices of all manuals.
3750 \\[Info-goto-node] Move to node specified by name.
3751 You may include a filename as well, as (FILENAME)NODENAME.
3752 1 .. 9 Pick first ... ninth item in node's menu.
3753 Every third `*' is highlighted to help pick the right number.
3754 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
3755 \\[clone-buffer] Select a new cloned Info buffer in another window.
3756 \\[universal-argument] \\[info] Move to new Info file with completion.
3757 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
3758 (kill-all-local-variables)
3759 (setq major-mode 'Info-mode)
3760 (setq mode-name "Info")
3761 (setq tab-width 8)
3762 (use-local-map Info-mode-map)
3763 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3764 (set-syntax-table text-mode-syntax-table)
3765 (setq local-abbrev-table text-mode-abbrev-table)
3766 (setq case-fold-search t)
3767 (setq buffer-read-only t)
3768 (make-local-variable 'Info-current-file)
3769 (make-local-variable 'Info-current-subfile)
3770 (make-local-variable 'Info-current-node)
3771 (make-local-variable 'Info-tag-table-marker)
3772 (setq Info-tag-table-marker (make-marker))
3773 (make-local-variable 'Info-tag-table-buffer)
3774 (setq Info-tag-table-buffer nil)
3775 (make-local-variable 'Info-history)
3776 (make-local-variable 'Info-history-forward)
3777 (make-local-variable 'Info-index-alternatives)
3778 (if Info-use-header-line ; do not override global header lines
3779 (setq header-line-format
3780 '(:eval (get-text-property (point-min) 'header-line))))
3781 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
3782 ;; This is for the sake of the invisible text we use handling titles.
3783 (make-local-variable 'line-move-ignore-invisible)
3784 (setq line-move-ignore-invisible t)
3785 (make-local-variable 'desktop-save-buffer)
3786 (make-local-variable 'widen-automatically)
3787 (setq widen-automatically nil)
3788 (setq desktop-save-buffer 'Info-desktop-buffer-misc-data)
3789 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
3790 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
3791 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
3792 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
3793 (set (make-local-variable 'isearch-search-fun-function)
3794 'Info-isearch-search)
3795 (set (make-local-variable 'isearch-wrap-function)
3796 'Info-isearch-wrap)
3797 (set (make-local-variable 'isearch-push-state-function)
3798 'Info-isearch-push-state)
3799 (set (make-local-variable 'isearch-filter-predicate)
3800 'Info-isearch-filter)
3801 (set (make-local-variable 'search-whitespace-regexp)
3802 Info-search-whitespace-regexp)
3803 (set (make-local-variable 'revert-buffer-function)
3804 'Info-revert-buffer-function)
3805 (Info-set-mode-line)
3806 (set (make-local-variable 'bookmark-make-record-function)
3807 'Info-bookmark-make-record)
3808 (run-mode-hooks 'Info-mode-hook))
3810 ;; When an Info buffer is killed, make sure the associated tags buffer
3811 ;; is killed too.
3812 (defun Info-kill-buffer ()
3813 (and (eq major-mode 'Info-mode)
3814 Info-tag-table-buffer
3815 (kill-buffer Info-tag-table-buffer)))
3817 ;; Placed on `clone-buffer-hook'.
3818 (defun Info-clone-buffer ()
3819 (when (bufferp Info-tag-table-buffer)
3820 (setq Info-tag-table-buffer
3821 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
3822 (let ((m Info-tag-table-marker))
3823 (when (markerp m)
3824 (setq Info-tag-table-marker
3825 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
3826 (with-current-buffer Info-tag-table-buffer
3827 (copy-marker (marker-position m)))
3828 (make-marker))))))
3830 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
3831 (set-keymap-parent map text-mode-map)
3832 (define-key map "\C-c\C-c" 'Info-cease-edit)
3833 map)
3834 "Local keymap used within `e' command of Info.")
3836 ;; Info-edit mode is suitable only for specially formatted data.
3837 (put 'Info-edit-mode 'mode-class 'special)
3839 (defun Info-edit-mode ()
3840 "Major mode for editing the contents of an Info node.
3841 Like text mode with the addition of `Info-cease-edit'
3842 which returns to Info mode for browsing.
3843 \\{Info-edit-map}"
3844 (use-local-map Info-edit-map)
3845 (setq major-mode 'Info-edit-mode)
3846 (setq mode-name "Info Edit")
3847 (kill-local-variable 'mode-line-buffer-identification)
3848 (setq buffer-read-only nil)
3849 (force-mode-line-update)
3850 (buffer-enable-undo (current-buffer))
3851 (run-mode-hooks 'Info-edit-mode-hook))
3853 (defun Info-edit ()
3854 "Edit the contents of this Info node.
3855 Allowed only if variable `Info-enable-edit' is non-nil."
3856 (interactive)
3857 (or Info-enable-edit
3858 (error "Editing Info nodes is not enabled"))
3859 (Info-edit-mode)
3860 (message "%s" (substitute-command-keys
3861 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
3863 (defun Info-cease-edit ()
3864 "Finish editing Info node; switch back to Info proper."
3865 (interactive)
3866 ;; Do this first, so nothing has changed if user C-g's at query.
3867 (and (buffer-modified-p)
3868 (y-or-n-p "Save the file? ")
3869 (save-buffer))
3870 (use-local-map Info-mode-map)
3871 (setq major-mode 'Info-mode)
3872 (setq mode-name "Info")
3873 (Info-set-mode-line)
3874 (setq buffer-read-only t)
3875 (force-mode-line-update)
3876 (and (marker-position Info-tag-table-marker)
3877 (buffer-modified-p)
3878 (message "Tags may have changed. Use Info-tagify if necessary")))
3880 (defvar Info-file-list-for-emacs
3881 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
3882 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
3883 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
3884 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
3885 ("skeleton" . "autotype") ("auto-insert" . "autotype")
3886 ("copyright" . "autotype") ("executable" . "autotype")
3887 ("time-stamp" . "autotype") ("quickurl" . "autotype")
3888 ("tempo" . "autotype") ("hippie-expand" . "autotype")
3889 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
3890 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
3891 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
3892 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
3893 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
3894 ("rfc2045" . "emacs-mime")
3895 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
3896 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
3897 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
3898 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
3899 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
3900 ("mml" . "emacs-mime"))
3901 "List of Info files that describe Emacs commands.
3902 An element can be a file name, or a list of the form (PREFIX . FILE)
3903 where PREFIX is a name prefix and FILE is the file to look in.
3904 If the element is just a file name, the file name also serves as the prefix.")
3906 (defun Info-find-emacs-command-nodes (command)
3907 "Return a list of locations documenting COMMAND.
3908 The `info-file' property of COMMAND says which Info manual to search.
3909 If COMMAND has no property, the variable `Info-file-list-for-emacs'
3910 defines heuristics for which Info manual to try.
3911 The locations are of the format used in `Info-history', i.e.
3912 \(FILENAME NODENAME BUFFERPOS\), where BUFFERPOS is the line number
3913 in the first element of the returned list (which is treated specially in
3914 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
3915 (let ((where '()) line-number
3916 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
3917 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
3918 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
3919 (info-file "emacs")) ;default
3920 ;; Determine which Info file this command is documented in.
3921 (if (get command 'info-file)
3922 (setq info-file (get command 'info-file))
3923 ;; If it doesn't say explicitly, test its name against
3924 ;; various prefixes that we know.
3925 (let ((file-list Info-file-list-for-emacs))
3926 (while file-list
3927 (let* ((elt (car file-list))
3928 (name (if (consp elt)
3929 (car elt)
3930 elt))
3931 (file (if (consp elt) (cdr elt) elt))
3932 (case-fold-search nil)
3933 (regexp (concat "\\`" (regexp-quote name)
3934 "\\(\\'\\|-\\)")))
3935 (if (string-match regexp (symbol-name command))
3936 (setq info-file file file-list nil))
3937 (setq file-list (cdr file-list))))))
3938 (Info-find-node info-file "Top")
3939 ;; Bind Info-history to nil, to prevent the index nodes from
3940 ;; getting into the node history.
3941 (let ((Info-history nil)
3942 (Info-history-list nil)
3943 node (nodes (Info-index-nodes)))
3944 (Info-goto-node (car nodes))
3945 (while
3946 (progn
3947 (goto-char (point-min))
3948 (while (re-search-forward cmd-desc nil t)
3949 (setq where
3950 (cons (list Info-current-file
3951 (match-string-no-properties 2)
3953 where))
3954 (setq line-number (and (match-beginning 3)
3955 (string-to-number (match-string 3)))))
3956 (and (setq nodes (cdr nodes) node (car nodes))))
3957 (Info-goto-node node)))
3958 (if (and line-number where)
3959 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
3960 (cdr where))
3961 where)))
3963 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file "emacs")
3964 ;;;###autoload
3965 (defun Info-goto-emacs-command-node (command)
3966 "Go to the Info node in the Emacs manual for command COMMAND.
3967 The command is found by looking up in Emacs manual's indices
3968 or in another manual found via COMMAND's `info-file' property or
3969 the variable `Info-file-list-for-emacs'.
3970 COMMAND must be a symbol or string."
3971 (interactive "CFind documentation for command: ")
3972 ;; If command is given as a string, convert it to a symbol.
3973 (if (stringp command)
3974 (setq command (intern command)))
3975 (or (commandp command)
3976 (signal 'wrong-type-argument (list 'commandp command)))
3977 (let ((where (Info-find-emacs-command-nodes command)))
3978 (if where
3979 (let ((num-matches (length where)))
3980 ;; Get Info running, and pop to it in another window.
3981 (save-window-excursion
3982 (info))
3983 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
3984 ;; Bind Info-history to nil, to prevent the last Index node
3985 ;; visited by Info-find-emacs-command-nodes from being
3986 ;; pushed onto the history.
3987 (let ((Info-history nil) (Info-history-list nil)
3988 (line-number (nth 2 (car where))))
3989 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
3990 (if (and (integerp line-number) (> line-number 0))
3991 (forward-line (1- line-number))))
3992 (if (> num-matches 1)
3993 (progn
3994 ;; (car where) will be pushed onto Info-history
3995 ;; when/if they go to another node. Put the other
3996 ;; nodes that were found on the history.
3997 (setq Info-history (nconc (cdr where) Info-history))
3998 (message "Found %d other entr%s. Use %s to see %s."
3999 (1- num-matches)
4000 (if (> num-matches 2) "ies" "y")
4001 (substitute-command-keys "\\[Info-history-back]")
4002 (if (> num-matches 2) "them" "it")))))
4003 (error "Couldn't find documentation for %s" command))))
4005 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file "emacs")
4006 ;;;###autoload
4007 (defun Info-goto-emacs-key-command-node (key)
4008 "Go to the node in the Emacs manual which describes the command bound to KEY.
4009 KEY is a string.
4010 Interactively, if the binding is `execute-extended-command', a command is read.
4011 The command is found by looking up in Emacs manual's indices
4012 or in another manual found via COMMAND's `info-file' property or
4013 the variable `Info-file-list-for-emacs'."
4014 (interactive "kFind documentation for key: ")
4015 (let ((command (key-binding key)))
4016 (cond ((null command)
4017 (message "%s is undefined" (key-description key)))
4018 ((and (interactive-p)
4019 (eq command 'execute-extended-command))
4020 (Info-goto-emacs-command-node
4021 (read-command "Find documentation for command: ")))
4023 (Info-goto-emacs-command-node command)))))
4025 (defvar Info-next-link-keymap
4026 (let ((keymap (make-sparse-keymap)))
4027 (define-key keymap [header-line mouse-1] 'Info-next)
4028 (define-key keymap [header-line mouse-2] 'Info-next)
4029 (define-key keymap [header-line down-mouse-1] 'ignore)
4030 (define-key keymap [mouse-2] 'Info-next)
4031 (define-key keymap [follow-link] 'mouse-face)
4032 keymap)
4033 "Keymap to put on the Next link in the text or the header line.")
4035 (defvar Info-prev-link-keymap
4036 (let ((keymap (make-sparse-keymap)))
4037 (define-key keymap [header-line mouse-1] 'Info-prev)
4038 (define-key keymap [header-line mouse-2] 'Info-prev)
4039 (define-key keymap [header-line down-mouse-1] 'ignore)
4040 (define-key keymap [mouse-2] 'Info-prev)
4041 (define-key keymap [follow-link] 'mouse-face)
4042 keymap)
4043 "Keymap to put on the Prev link in the text or the header line.")
4045 (defvar Info-up-link-keymap
4046 (let ((keymap (make-sparse-keymap)))
4047 (define-key keymap [header-line mouse-1] 'Info-up)
4048 (define-key keymap [header-line mouse-2] 'Info-up)
4049 (define-key keymap [header-line down-mouse-1] 'ignore)
4050 (define-key keymap [mouse-2] 'Info-up)
4051 (define-key keymap [follow-link] 'mouse-face)
4052 keymap)
4053 "Keymap to put on the Up link in the text or the header line.")
4055 (defun Info-insert-breadcrumbs ()
4056 (let ((nodes (Info-toc-nodes Info-current-file))
4057 (node Info-current-node)
4058 (crumbs ())
4059 (depth Info-breadcrumbs-depth))
4061 ;; Get ancestors from the cached parent-children node info
4062 (while (and (not (equal "Top" node)) (> depth 0))
4063 (setq node (nth 1 (assoc node nodes)))
4064 (if node (push node crumbs))
4065 (setq depth (1- depth)))
4067 ;; Add bottom node.
4068 (when Info-use-header-line
4069 ;; Let it disappear if crumbs is nil.
4070 (nconc crumbs (list Info-current-node)))
4071 (when (or Info-use-header-line crumbs)
4072 ;; Add top node (and continuation if needed).
4073 (setq crumbs
4074 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4075 crumbs (cons nil crumbs))))
4076 ;; Eliminate duplicate.
4077 (forward-line 1)
4078 (dolist (node crumbs)
4079 (let ((text
4080 (if (not (equal node "Top")) node
4081 (format "(%s)Top"
4082 (if (stringp Info-current-file)
4083 (file-name-nondirectory Info-current-file)
4084 ;; Some legacy code can still use a symbol.
4085 Info-current-file)))))
4086 (insert (if (bolp) "" " > ")
4087 (cond
4088 ((null node) "...")
4089 ((equal node Info-current-node)
4090 ;; No point linking to ourselves.
4091 (propertize text 'font-lock-face 'info-header-node))
4093 (concat "*Note " text "::"))))))
4094 (insert "\n"))))
4096 (defun Info-fontify-node ()
4097 "Fontify the node."
4098 (save-excursion
4099 (let* ((inhibit-read-only t)
4100 (case-fold-search t)
4101 paragraph-markers
4102 (not-fontified-p ; the node hasn't already been fontified
4103 (not (let ((where (next-single-property-change (point-min)
4104 'font-lock-face)))
4105 (and where (not (= where (point-max)))))))
4106 (fontify-visited-p ; visited nodes need to be re-fontified
4107 (and Info-fontify-visited-nodes
4108 ;; Don't take time to refontify visited nodes in huge nodes
4109 Info-fontify-maximum-menu-size
4110 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4111 rbeg rend)
4113 ;; Fontify header line
4114 (goto-char (point-min))
4115 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4116 (goto-char (match-end 0))
4117 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4118 (goto-char (match-end 0))
4119 (let* ((nbeg (match-beginning 2))
4120 (nend (match-end 2))
4121 (tbeg (match-beginning 1))
4122 (tag (match-string 1)))
4123 (if (string-equal (downcase tag) "node")
4124 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4125 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4126 (put-text-property tbeg nend 'mouse-face 'highlight)
4127 (put-text-property tbeg nend
4128 'help-echo
4129 (concat "mouse-2: Go to node "
4130 (buffer-substring nbeg nend)))
4131 ;; Always set up the text property keymap.
4132 ;; It will either be used in the buffer
4133 ;; or copied in the header line.
4134 (put-text-property
4135 tbeg nend 'keymap
4136 (cond
4137 ((string-equal (downcase tag) "prev") Info-prev-link-keymap)
4138 ((string-equal (downcase tag) "next") Info-next-link-keymap)
4139 ((string-equal (downcase tag) "up" ) Info-up-link-keymap))))))
4141 (when (> Info-breadcrumbs-depth 0)
4142 (Info-insert-breadcrumbs))
4144 ;; Treat header line.
4145 (when Info-use-header-line
4146 (goto-char (point-min))
4147 (let* ((header-end (line-end-position))
4148 (header
4149 ;; If we find neither Next: nor Prev: link, show the entire
4150 ;; node header. Otherwise, don't show the File: and Node:
4151 ;; parts, to avoid wasting precious space on information that
4152 ;; is available in the mode line.
4153 (if (re-search-forward
4154 "\\(next\\|up\\|prev[ious]*\\): "
4155 header-end t)
4156 (progn
4157 (goto-char (match-beginning 1))
4158 (buffer-substring (point) header-end))
4159 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4160 header-end t)
4161 (concat "No next, prev or up links -- "
4162 (buffer-substring (point) header-end))
4163 (buffer-substring (point) header-end)))))
4164 (put-text-property (point-min) (1+ (point-min))
4165 'header-line
4166 (replace-regexp-in-string
4168 ;; Preserve text properties on duplicated `%'.
4169 (lambda (s) (concat s s)) header))
4170 ;; Hide the part of the first line
4171 ;; that is in the header, if it is just part.
4172 (cond
4173 ((> Info-breadcrumbs-depth 0)
4174 (put-text-property (point-min) (1+ header-end) 'invisible t))
4175 ((not (bobp))
4176 ;; Hide the punctuation at the end, too.
4177 (skip-chars-backward " \t,")
4178 (put-text-property (point) header-end 'invisible t))))))
4180 ;; Fontify titles
4181 (goto-char (point-min))
4182 (when (and font-lock-mode not-fontified-p)
4183 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4184 nil t)
4185 ;; Only consider it as an underlined title if the ASCII
4186 ;; underline has the same size as the text. A typical
4187 ;; counter example is when a continuation "..." is alone
4188 ;; on a line.
4189 (= (string-width (match-string 1))
4190 (string-width (match-string 2))))
4191 (let* ((c (preceding-char))
4192 (face
4193 (cond ((= c ?*) 'info-title-1)
4194 ((= c ?=) 'info-title-2)
4195 ((= c ?-) 'info-title-3)
4196 (t 'info-title-4))))
4197 (put-text-property (match-beginning 1) (match-end 1)
4198 'font-lock-face face))
4199 ;; This is a serious problem for trying to handle multiple
4200 ;; frame types at once. We want this text to be invisible
4201 ;; on frames that can display the font above.
4202 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4203 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4204 '(invisible t front-sticky nil rear-nonsticky t)))))
4206 ;; Fontify cross references
4207 (goto-char (point-min))
4208 (when (or not-fontified-p fontify-visited-p)
4209 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4210 (let ((start (match-beginning 0))
4211 (next (point))
4212 other-tag)
4213 (when not-fontified-p
4214 (when Info-hide-note-references
4215 (when (and (not (eq Info-hide-note-references 'hide))
4216 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4217 ;; *Note is often used where *note should have been
4218 (goto-char start)
4219 (skip-syntax-backward " ")
4220 (when (memq (char-before) '(?\( ?\[ ?\{))
4221 ;; Check whether the paren is preceded by
4222 ;; an end of sentence
4223 (skip-syntax-backward " ("))
4224 (setq other-tag
4225 (cond ((save-match-data (looking-back "\\<see"))
4227 ((save-match-data (looking-back "\\<in"))
4229 ((memq (char-before) '(nil ?\. ?! ??))
4230 "See ")
4231 ((save-match-data
4232 (save-excursion
4233 (search-forward "\n\n" start t)))
4234 "See ")
4235 (t "see "))))
4236 (goto-char next)
4237 (add-text-properties
4238 (match-beginning 1)
4239 (or (save-match-data
4240 ;; Don't hide \n after *Note
4241 (let ((start1 (match-beginning 1)))
4242 (if (string-match "\n" (match-string 1))
4243 (+ start1 (match-beginning 0)))))
4244 (match-end 1))
4245 (if other-tag
4246 `(display ,other-tag front-sticky nil rear-nonsticky t)
4247 '(invisible t front-sticky nil rear-nonsticky t))))
4248 (add-text-properties
4249 (match-beginning 2) (match-end 2)
4250 (list
4251 'help-echo (if (or (match-end 5)
4252 (not (equal (match-string 4) "")))
4253 (concat "mouse-2: go to " (or (match-string 5)
4254 (match-string 4)))
4255 "mouse-2: go to this node")
4256 'mouse-face 'highlight)))
4257 (when (or not-fontified-p fontify-visited-p)
4258 (setq rbeg (match-beginning 2)
4259 rend (match-end 2))
4260 (put-text-property
4261 rbeg rend
4262 'font-lock-face
4263 ;; Display visited nodes in a different face
4264 (if (and Info-fontify-visited-nodes
4265 (save-match-data
4266 (let* ((node (replace-regexp-in-string
4267 "^[ \t]+" ""
4268 (replace-regexp-in-string
4269 "[ \t\n]+" " "
4270 (or (match-string-no-properties 5)
4271 (and (not (equal (match-string 4) ""))
4272 (match-string-no-properties 4))
4273 (match-string-no-properties 2)))))
4274 (external-link-p
4275 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4276 (file (if external-link-p
4277 (file-name-nondirectory
4278 (match-string-no-properties 1 node))
4279 Info-current-file))
4280 (hl Info-history-list)
4281 res)
4282 (if external-link-p
4283 (setq node (if (equal (match-string 2 node) "")
4284 "Top"
4285 (match-string-no-properties 2 node))))
4286 (while hl
4287 (if (and (string-equal node (nth 1 (car hl)))
4288 (equal file
4289 (if (and external-link-p
4290 (stringp (caar hl)))
4291 (file-name-nondirectory
4292 (caar hl))
4293 (caar hl))))
4294 (setq res (car hl) hl nil)
4295 (setq hl (cdr hl))))
4296 res))) 'info-xref-visited 'info-xref))
4297 ;; For multiline ref, unfontify newline and surrounding whitespace
4298 (save-excursion
4299 (goto-char rbeg)
4300 (save-match-data
4301 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4302 (remove-text-properties (match-beginning 0)
4303 (match-end 0)
4304 '(font-lock-face t))))))
4305 (when not-fontified-p
4306 (when (memq Info-hide-note-references '(t hide))
4307 (add-text-properties (match-beginning 3) (match-end 3)
4308 '(invisible t front-sticky nil rear-nonsticky t))
4309 ;; Unhide the file name of the external reference in parens
4310 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4311 (remove-text-properties (match-beginning 6) (match-end 6)
4312 '(invisible t front-sticky nil rear-nonsticky t)))
4313 ;; Unhide newline because hidden newlines cause too long lines
4314 (save-match-data
4315 (let ((beg3 (match-beginning 3))
4316 (end3 (match-end 3)))
4317 (if (and (string-match "\n[ \t]*" (match-string 3))
4318 (not (save-match-data
4319 (save-excursion
4320 (goto-char (1+ end3))
4321 (looking-at "[.)]*$")))))
4322 (remove-text-properties (+ beg3 (match-beginning 0))
4323 (+ beg3 (match-end 0))
4324 '(invisible t front-sticky nil rear-nonsticky t))))))
4325 (when (and Info-refill-paragraphs Info-hide-note-references)
4326 (push (set-marker (make-marker) start)
4327 paragraph-markers))))))
4329 ;; Refill paragraphs (experimental feature)
4330 (when (and not-fontified-p
4331 Info-refill-paragraphs
4332 paragraph-markers)
4333 (let ((fill-nobreak-invisible t)
4334 (fill-individual-varying-indent nil)
4335 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4336 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4337 (adaptive-fill-mode nil))
4338 (goto-char (point-max))
4339 (dolist (m paragraph-markers)
4340 (when (< m (point))
4341 (goto-char m)
4342 (beginning-of-line)
4343 (let ((beg (point)))
4344 (when (zerop (forward-paragraph))
4345 (fill-individual-paragraphs beg (point) nil nil)
4346 (goto-char beg))))
4347 (set-marker m nil))))
4349 ;; Fontify menu items
4350 (goto-char (point-min))
4351 (when (and (or not-fontified-p fontify-visited-p)
4352 (search-forward "\n* Menu:" nil t)
4353 ;; Don't take time to annotate huge menus
4354 Info-fontify-maximum-menu-size
4355 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4356 (let ((n 0)
4357 cont)
4358 (while (re-search-forward
4359 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4360 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4361 nil t)
4362 (when (match-beginning 1)
4363 (when not-fontified-p
4364 (setq n (1+ n))
4365 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4366 (put-text-property (match-beginning 0)
4367 (1+ (match-beginning 0))
4368 'font-lock-face 'info-menu-star)))
4369 (when not-fontified-p
4370 (add-text-properties
4371 (match-beginning 1) (match-end 1)
4372 (list
4373 'help-echo (if (and (match-end 3)
4374 (not (equal (match-string 3) "")))
4375 (concat "mouse-2: go to " (match-string 3))
4376 "mouse-2: go to this node")
4377 'mouse-face 'highlight)))
4378 (when (or not-fontified-p fontify-visited-p)
4379 (put-text-property
4380 (match-beginning 1) (match-end 1)
4381 'font-lock-face
4382 ;; Display visited menu items in a different face
4383 (if (and Info-fontify-visited-nodes
4384 (save-match-data
4385 (let* ((node (if (equal (match-string 3) "")
4386 (match-string-no-properties 1)
4387 (match-string-no-properties 3)))
4388 (external-link-p
4389 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4390 (file (if external-link-p
4391 (file-name-nondirectory
4392 (match-string-no-properties 1 node))
4393 Info-current-file))
4394 (hl Info-history-list)
4395 res)
4396 (if external-link-p
4397 (setq node (if (equal (match-string 2 node) "")
4398 "Top"
4399 (match-string-no-properties 2 node))))
4400 (while hl
4401 (if (and (string-equal node (nth 1 (car hl)))
4402 (equal file
4403 (if (and external-link-p
4404 (stringp (caar hl)))
4405 (file-name-nondirectory
4406 (caar hl))
4407 (caar hl))))
4408 (setq res (car hl) hl nil)
4409 (setq hl (cdr hl))))
4410 res))) 'info-xref-visited 'info-xref)))
4411 (when (and not-fontified-p
4412 (memq Info-hide-note-references '(t hide))
4413 (not (Info-index-node)))
4414 (put-text-property (match-beginning 2) (1- (match-end 6))
4415 'invisible t)
4416 ;; Unhide the file name in parens
4417 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4418 (remove-text-properties (match-beginning 4) (match-end 4)
4419 '(invisible t)))
4420 ;; We need a stretchable space like :align-to but with
4421 ;; a minimum value.
4422 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4423 (if (>= 22 (- (match-end 1)
4424 (match-beginning 0)))
4425 '(space :align-to 24)
4426 '(space :width 2)))
4427 (setq cont (looking-at "."))
4428 (while (and (= (forward-line 1) 0)
4429 (looking-at "\\([ \t]+\\)[^*\n]"))
4430 (put-text-property (match-beginning 1) (1- (match-end 1))
4431 'invisible t)
4432 (put-text-property (1- (match-end 1)) (match-end 1)
4433 'display
4434 (if cont
4435 '(space :align-to 26)
4436 '(space :align-to 24)))
4437 (setq cont t)))))))
4439 ;; Fontify menu headers
4440 ;; Add the face `info-menu-header' to any header before a menu entry
4441 (goto-char (point-min))
4442 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4443 (put-text-property (match-beginning 0) (match-end 0)
4444 'font-lock-face 'info-menu-header)
4445 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4446 (put-text-property (match-beginning 1) (match-end 1)
4447 'font-lock-face 'info-menu-header)))
4449 ;; Hide index line numbers
4450 (goto-char (point-min))
4451 (when (and not-fontified-p (Info-index-node))
4452 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4453 (put-text-property (match-beginning 0) (match-end 0)
4454 'invisible t)))
4456 ;; Fontify http and ftp references
4457 (goto-char (point-min))
4458 (when not-fontified-p
4459 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4460 nil t)
4461 (add-text-properties (match-beginning 0) (match-end 0)
4462 '(font-lock-face info-xref
4463 mouse-face highlight
4464 help-echo "mouse-2: go to this URL"))))
4466 (set-buffer-modified-p nil))))
4468 ;;; Speedbar support:
4469 ;; These functions permit speedbar to display the "tags" in the
4470 ;; current Info node.
4471 (eval-when-compile (require 'speedbar))
4473 (defvar Info-speedbar-key-map nil
4474 "Keymap used when in the info display mode.")
4476 (defun Info-install-speedbar-variables ()
4477 "Install those variables used by speedbar to enhance Info."
4478 (if Info-speedbar-key-map
4480 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
4482 ;; Basic tree features
4483 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
4484 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
4485 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
4486 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
4489 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
4490 Info-speedbar-key-map
4491 Info-speedbar-hierarchy-buttons)))
4493 (defvar Info-speedbar-menu-items
4494 '(["Browse Node" speedbar-edit-line t]
4495 ["Expand Node" speedbar-expand-line
4496 (save-excursion (beginning-of-line)
4497 (looking-at "[0-9]+: *.\\+. "))]
4498 ["Contract Node" speedbar-contract-line
4499 (save-excursion (beginning-of-line)
4500 (looking-at "[0-9]+: *.-. "))]
4502 "Additional menu-items to add to speedbar frame.")
4504 ;; Make sure our special speedbar major mode is loaded
4505 (if (featurep 'speedbar)
4506 (Info-install-speedbar-variables)
4507 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4509 ;;; Info hierarchy display method
4510 ;;;###autoload
4511 (defun Info-speedbar-browser ()
4512 "Initialize speedbar to display an Info node browser.
4513 This will add a speedbar major display mode."
4514 (interactive)
4515 (require 'speedbar)
4516 ;; Make sure that speedbar is active
4517 (speedbar-frame-mode 1)
4518 ;; Now, throw us into Info mode on speedbar.
4519 (speedbar-change-initial-expansion-list "Info")
4522 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
4523 "Display an Info directory hierarchy in speedbar.
4524 DIRECTORY is the current directory in the attached frame.
4525 DEPTH is the current indentation depth.
4526 NODE is an optional argument that is used to represent the
4527 specific node to expand."
4528 (if (and (not node)
4529 (save-excursion (goto-char (point-min))
4530 (let ((case-fold-search t))
4531 (looking-at "Info Nodes:"))))
4532 ;; Update our "current node" maybe?
4534 ;; We cannot use the generic list code, that depends on all leaves
4535 ;; being known at creation time.
4536 (if (not node)
4537 (speedbar-with-writable (insert "Info Nodes:\n")))
4538 (let ((completions nil))
4539 (speedbar-select-attached-frame)
4540 (save-window-excursion
4541 (setq completions
4542 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
4543 (select-frame (speedbar-current-frame))
4544 (if completions
4545 (speedbar-with-writable
4546 (dolist (completion completions)
4547 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
4548 (cdr completion)
4549 (car completion)
4550 'Info-speedbar-goto-node
4551 (cdr completion)
4552 'info-xref depth))
4554 nil))))
4556 (defun Info-speedbar-goto-node (text node indent)
4557 "When user clicks on TEXT, go to an info NODE.
4558 The INDENT level is ignored."
4559 (speedbar-select-attached-frame)
4560 (let* ((buff (or (get-buffer "*info*")
4561 (progn (info) (get-buffer "*info*"))))
4562 (bwin (get-buffer-window buff 0)))
4563 (if bwin
4564 (progn
4565 (select-window bwin)
4566 (raise-frame (window-frame bwin)))
4567 (if speedbar-power-click
4568 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
4569 (speedbar-select-attached-frame)
4570 (switch-to-buffer buff)))
4571 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4572 (error "Invalid node %s" node)
4573 (Info-find-node (match-string 1 node) (match-string 2 node))
4574 ;; If we do a find-node, and we were in info mode, restore
4575 ;; the old default method. Once we are in info mode, it makes
4576 ;; sense to return to whatever method the user was using before.
4577 (if (string= speedbar-initial-expansion-list-name "Info")
4578 (speedbar-change-initial-expansion-list
4579 speedbar-previously-used-expansion-list-name)))))
4581 (defun Info-speedbar-expand-node (text token indent)
4582 "Expand the node the user clicked on.
4583 TEXT is the text of the button we clicked on, a + or - item.
4584 TOKEN is data related to this node (NAME . FILE).
4585 INDENT is the current indentation depth."
4586 (cond ((string-match "+" text) ;we have to expand this file
4587 (speedbar-change-expand-button-char ?-)
4588 (if (speedbar-with-writable
4589 (save-excursion
4590 (end-of-line) (forward-char 1)
4591 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4592 (speedbar-change-expand-button-char ?-)
4593 (speedbar-change-expand-button-char ??)))
4594 ((string-match "-" text) ;we have to contract this node
4595 (speedbar-change-expand-button-char ?+)
4596 (speedbar-delete-subblock indent))
4597 (t (error "Ooops... not sure what to do")))
4598 (speedbar-center-buffer-smartly))
4600 (defun Info-speedbar-fetch-file-nodes (nodespec)
4601 "Fetch the subnodes from the info NODESPEC.
4602 NODESPEC is a string of the form: (file)node."
4603 ;; Set up a buffer we can use to fake-out Info.
4604 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
4605 (if (not (equal major-mode 'Info-mode))
4606 (Info-mode))
4607 ;; Get the node into this buffer
4608 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4609 (error "Invalid node specification %s" nodespec)
4610 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4611 ;; Scan the created buffer
4612 (goto-char (point-min))
4613 (let ((completions nil)
4614 (case-fold-search t)
4615 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4616 (match-string 1 nodespec))))
4617 ;; Always skip the first one...
4618 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4619 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4620 (let ((name (match-string 1)))
4621 (push (cons name
4622 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4623 (match-string 1)
4624 (if (looking-at " *\\(([^)]+)\\)\\.")
4625 (concat (match-string 1) "Top")
4626 (concat "(" thisfile ")"
4627 (if (looking-at " \\([^.]+\\).")
4628 (match-string 1)
4629 name)))))
4630 completions)))
4631 (nreverse completions))))
4633 ;;; Info mode node listing
4634 ;; This is called by `speedbar-add-localized-speedbar-support'
4635 (defun Info-speedbar-buttons (buffer)
4636 "Create a speedbar display to help navigation in an Info file.
4637 BUFFER is the buffer speedbar is requesting buttons for."
4638 (if (save-excursion (goto-char (point-min))
4639 (let ((case-fold-search t))
4640 (not (looking-at "Info Nodes:"))))
4641 (erase-buffer))
4642 (Info-speedbar-hierarchy-buttons nil 0))
4644 (dolist (mess '("^First node in file$"
4645 "^No `.*' in index$"
4646 "^No cross-reference named"
4647 "^No cross.references in this node$"
4648 "^No current Info node$"
4649 "^No menu in this node$"
4650 "^No more items in menu$"
4651 "^No more nodes$"
4652 "^No pointer \\(?:forward\\|backward\\) from this node$"
4653 "^No previous `i' command$"
4654 "^No previous items in menu$"
4655 "^No previous nodes$"
4656 "^No such item in menu$"
4657 "^No such node or anchor"
4658 "^Node has no"
4659 "^Point neither on reference nor in menu item description$"
4660 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4661 search-failed))
4662 (add-to-list 'debug-ignored-errors mess))
4664 ;;;; Desktop support
4666 (defun Info-desktop-buffer-misc-data (desktop-dirname)
4667 "Auxiliary information to be saved in desktop file."
4668 (unless (Info-virtual-file-p Info-current-file)
4669 (list Info-current-file Info-current-node)))
4671 (defun Info-restore-desktop-buffer (desktop-buffer-file-name
4672 desktop-buffer-name
4673 desktop-buffer-misc)
4674 "Restore an Info buffer specified in a desktop file."
4675 (let ((first (nth 0 desktop-buffer-misc))
4676 (second (nth 1 desktop-buffer-misc)))
4677 (when (and first second)
4678 (when desktop-buffer-name
4679 (set-buffer (get-buffer-create desktop-buffer-name))
4680 (Info-mode))
4681 (Info-find-node first second)
4682 (current-buffer))))
4684 (add-to-list 'desktop-buffer-mode-handlers
4685 '(Info-mode . Info-restore-desktop-buffer))
4687 ;;;; Bookmark support
4688 (declare-function bookmark-make-record-default "bookmark" (&optional pos-only))
4689 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
4690 (declare-function bookmark-default-handler "bookmark" (bmk))
4691 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
4693 (defun Info-bookmark-make-record ()
4694 `(,Info-current-node
4695 ,@(bookmark-make-record-default 'point-only)
4696 (filename . ,Info-current-file)
4697 (info-node . ,Info-current-node)
4698 (handler . Info-bookmark-jump)))
4700 ;;;###autoload
4701 (defun Info-bookmark-jump (bmk)
4702 ;; This implements the `handler' function interface for record type returned
4703 ;; by `Info-bookmark-make-record', which see.
4704 (let* ((file (bookmark-prop-get bmk 'filename))
4705 (info-node (bookmark-prop-get bmk 'info-node))
4706 (buf (save-window-excursion ;FIXME: doesn't work with frames!
4707 (Info-find-node file info-node) (current-buffer))))
4708 ;; Use bookmark-default-handler to move to the appropriate location
4709 ;; within the node.
4710 (bookmark-default-handler
4711 (list* "" `(buffer . ,buf) (bookmark-get-bookmark-record bmk)))))
4713 (provide 'info)
4715 ;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
4716 ;;; info.el ends here