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