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