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