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