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