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