Don't require isearch-update before isearch-done
[emacs.git] / lisp / info.el
blobbb259bd59eb345b814678abf059268db8ca63327
1 ;; info.el --- Info package for Emacs -*- lexical-binding:t -*-
3 ;; Copyright (C) 1985-1986, 1992-2016 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-display-images-node ()
1603 "Display images in current node."
1604 (save-excursion
1605 (let ((inhibit-read-only t)
1606 (case-fold-search t))
1607 (goto-char (point-min))
1608 (while (re-search-forward
1609 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1610 nil t)
1611 (let* ((start (match-beginning 1))
1612 (parameter-alist (Info-split-parameter-string (match-string 2)))
1613 (src (cdr (assoc-string "src" parameter-alist))))
1614 (if (display-images-p)
1615 (let* ((image-file (if src (if (file-name-absolute-p src) src
1616 (concat default-directory src))
1617 ""))
1618 (image (if (file-exists-p image-file)
1619 (create-image image-file)
1620 (or (cdr (assoc-string "text" parameter-alist))
1621 (and src (concat "[broken image:" src "]"))
1622 "[broken image]"))))
1623 (if (not (get-text-property start 'display))
1624 (add-text-properties
1625 start (point)
1626 `(display ,image rear-nonsticky (display)
1627 help-echo ,(cdr (assoc-string "alt" parameter-alist))))))
1628 ;; text-only display, show alternative text if provided, or
1629 ;; otherwise a clue that there's meant to be a picture
1630 (delete-region start (point))
1631 (insert (or (cdr (assoc-string "text" parameter-alist))
1632 (cdr (assoc-string "alt" parameter-alist))
1633 (and src (concat "[image:" src "]"))
1634 "[image]"))))))
1635 (set-buffer-modified-p nil)))
1637 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1638 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1639 ;; including one optional trailing newline.
1640 (defun Info-hide-cookies-node ()
1641 "Hide unrecognized cookies in current node."
1642 (save-excursion
1643 (let ((inhibit-read-only t)
1644 (case-fold-search t))
1645 (goto-char (point-min))
1646 (while (re-search-forward
1647 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1648 nil t)
1649 (let* ((start (match-beginning 1)))
1650 (if (and (not (get-text-property start 'invisible))
1651 (not (get-text-property start 'display)))
1652 (put-text-property start (point) 'invisible t)))))
1653 (set-buffer-modified-p nil)))
1655 (defun Info-select-node ()
1656 "Select the Info node that point is in."
1657 ;; Bind this in case the user sets it to nil.
1658 (let ((case-fold-search t))
1659 (save-excursion
1660 ;; Find beginning of node.
1661 (if (search-backward "\n\^_" nil 'move)
1662 (forward-line 2)
1663 (if (looking-at "\^_")
1664 (forward-line 1)
1665 (signal 'search-failed (list "\n\^_"))))
1666 ;; Get nodename spelled as it is in the node.
1667 (re-search-forward "Node:[ \t]*")
1668 (setq Info-current-node
1669 (buffer-substring-no-properties (point)
1670 (progn
1671 (skip-chars-forward "^,\t\n")
1672 (point))))
1673 (Info-set-mode-line)
1674 ;; Find the end of it, and narrow.
1675 (beginning-of-line)
1676 (let (active-expression)
1677 ;; Narrow to the node contents
1678 (narrow-to-region (point)
1679 (if (re-search-forward "\n[\^_\f]" nil t)
1680 (prog1
1681 (1- (point))
1682 (if (looking-at "[\n\^_\f]*execute: ")
1683 (progn
1684 (goto-char (match-end 0))
1685 (setq active-expression
1686 (read (current-buffer))))))
1687 (point-max)))
1688 (if Info-enable-active-nodes (eval active-expression))
1689 ;; Add a new unique history item to full history list
1690 (let ((new-history (list Info-current-file Info-current-node)))
1691 (setq Info-history-list
1692 (cons new-history (remove new-history Info-history-list)))
1693 (setq Info-history-forward nil))
1694 (if (not (eq Info-fontify-maximum-menu-size nil))
1695 (Info-fontify-node))
1696 (Info-display-images-node)
1697 (Info-hide-cookies-node)
1698 (run-hooks 'Info-selection-hook)))))
1700 (defvar Info-mode-line-node-keymap
1701 (let ((map (make-sparse-keymap)))
1702 (define-key map [mode-line mouse-1] 'Info-mouse-scroll-up)
1703 (define-key map [mode-line mouse-3] 'Info-mouse-scroll-down)
1704 map)
1705 "Keymap to put on the Info node name in the mode line.")
1707 (defun Info-set-mode-line ()
1708 (setq mode-line-buffer-identification
1709 (nconc (propertized-buffer-identification "%b")
1710 (list
1711 (concat
1712 " ("
1713 (if (stringp Info-current-file)
1714 (replace-regexp-in-string
1715 "%" "%%"
1716 (file-name-sans-extension
1717 (file-name-nondirectory Info-current-file)))
1718 (format "*%S*" Info-current-file))
1719 ") "
1720 (if Info-current-node
1721 (propertize (replace-regexp-in-string
1722 "%" "%%" Info-current-node)
1723 'face 'mode-line-buffer-id
1724 'help-echo
1725 "mouse-1: scroll forward, mouse-3: scroll back"
1726 'mouse-face 'mode-line-highlight
1727 'local-map Info-mode-line-node-keymap)
1728 ""))))))
1730 ;; Go to an Info node specified with a filename-and-nodename string
1731 ;; of the sort that is found in pointers in nodes.
1733 ;; Don't autoload this function: the correct entry point for other packages
1734 ;; to use is `info'. --Stef
1735 ;; ;;;###autoload
1736 (defun Info-goto-node (nodename &optional fork strict-case)
1737 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1738 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1739 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1740 its sub-files).
1741 Completion is available for node names in the current Info file as well as
1742 in the Info file FILENAME after the closing parenthesis in (FILENAME).
1743 Empty NODENAME in (FILENAME) defaults to the Top node.
1744 If FORK is non-nil (interactively with a prefix arg), show the node in
1745 a new Info buffer.
1746 If FORK is a string, it is the name to use for the new buffer.
1748 This function first looks for a case-sensitive match for the node part
1749 of NODENAME; if none is found it then tries a case-insensitive match
1750 \(unless STRICT-CASE is non-nil)."
1751 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
1752 (info-initialize)
1753 (if fork
1754 (set-buffer
1755 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
1756 (let (filename)
1757 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1758 nodename)
1759 (setq filename (if (= (match-beginning 1) (match-end 1))
1761 (match-string 2 nodename))
1762 nodename (match-string 3 nodename))
1763 (let ((trim (string-match "\\s +\\'" filename)))
1764 (if trim (setq filename (substring filename 0 trim))))
1765 (let ((trim (string-match "\\s +\\'" nodename)))
1766 (if trim (setq nodename (substring nodename 0 trim))))
1767 (if transient-mark-mode (deactivate-mark))
1768 (Info-find-node (if (equal filename "") nil filename)
1769 (if (equal nodename "") "Top" nodename) nil strict-case)))
1771 (defvar Info-read-node-completion-table)
1773 (defun Info-read-node-name-2 (dirs suffixes string pred action)
1774 "Internal function used to complete Info node names.
1775 Return a completion table for Info files---the FILENAME part of a
1776 node named \"(FILENAME)NODENAME\". DIRS is a list of Info
1777 directories to search if FILENAME is not absolute; SUFFIXES is a
1778 list of valid filename suffixes for Info files. See
1779 `try-completion' for a description of the remaining arguments."
1780 (setq suffixes (remove "" suffixes))
1781 (when (file-name-absolute-p string)
1782 (setq dirs (list (file-name-directory string))))
1783 (let ((names nil)
1784 (names-sans-suffix nil)
1785 (suffix (concat (regexp-opt suffixes t) "\\'"))
1786 (string-dir (file-name-directory string)))
1787 (dolist (dir dirs)
1788 (unless dir
1789 (setq dir default-directory))
1790 (if string-dir (setq dir (expand-file-name string-dir dir)))
1791 (when (file-directory-p dir)
1792 (dolist (file (file-name-all-completions
1793 (file-name-nondirectory string) dir))
1794 ;; If the file name has no suffix or a standard suffix,
1795 ;; include it.
1796 (and (or (null (file-name-extension file))
1797 (string-match suffix file))
1798 ;; But exclude subfiles of split Info files.
1799 (not (string-match "-[0-9]+\\'" file))
1800 ;; And exclude backup files.
1801 (not (string-match "~\\'" file))
1802 (push (if string-dir (concat string-dir file) file) names))
1803 ;; If the file name ends in a standard suffix,
1804 ;; add the unsuffixed name as a completion option.
1805 (when (string-match suffix file)
1806 (setq file (substring file 0 (match-beginning 0)))
1807 (push (if string-dir (concat string-dir file) file)
1808 names-sans-suffix)))))
1809 ;; If there is just one file, don't duplicate it with suffixes,
1810 ;; so `Info-read-node-name-1' will be able to complete a single
1811 ;; candidate and to add the terminating ")".
1812 (if (and (= (length names) 1) (= (length names-sans-suffix) 1))
1813 (setq names names-sans-suffix)
1814 (setq names (append names-sans-suffix names)))
1815 (complete-with-action action names string pred)))
1817 (defun Info-read-node-name-1 (string predicate code)
1818 "Internal function used by `Info-read-node-name'.
1819 See `completing-read' for a description of arguments and usage."
1820 (cond
1821 ;; First complete embedded file names.
1822 ((string-match "\\`([^)]*\\'" string)
1823 (completion-table-with-context
1825 (apply-partially #'completion-table-with-terminator ")"
1826 (apply-partially #'Info-read-node-name-2
1827 Info-directory-list
1828 (mapcar #'car Info-suffix-list)))
1829 (substring string 1)
1830 predicate
1831 code))
1832 ;; If a file name was given, complete nodes in the file.
1833 ((string-match "\\`(\\([^)]+\\))" string)
1834 (let ((file0 (match-string 0 string))
1835 (file1 (match-string 1 string))
1836 (nodename (substring string (match-end 0))))
1837 (if (and (equal nodename "") (eq code 'lambda))
1838 ;; Empty node name is permitted that means "Top".
1840 (completion-table-with-context
1841 file0
1842 (lambda (string pred action)
1843 (complete-with-action
1844 action
1845 (Info-build-node-completions (Info-find-file file1))
1846 string pred))
1847 nodename predicate code))))
1848 ;; Otherwise use Info-read-node-completion-table.
1849 (t (complete-with-action
1850 code Info-read-node-completion-table string predicate))))
1852 ;; Arrange to highlight the proper letters in the completion list buffer.
1853 (defun Info-read-node-name (prompt)
1854 "Read an Info node name with completion, prompting with PROMPT.
1855 A node name can have the form \"NODENAME\", referring to a node
1856 in the current Info file, or \"(FILENAME)NODENAME\", referring to
1857 a node in FILENAME. \"(FILENAME)\" is a short format to go to
1858 the Top node in FILENAME."
1859 (let* ((completion-ignore-case t)
1860 (Info-read-node-completion-table (Info-build-node-completions))
1861 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1862 (if (equal nodename "")
1863 (Info-read-node-name prompt)
1864 nodename)))
1866 (defun Info-build-node-completions (&optional filename)
1867 (if filename
1868 (or (cdr (assoc filename Info-file-completions))
1869 (with-temp-buffer
1870 (Info-mode)
1871 (Info-goto-node (format "(%s)Top" filename))
1872 (Info-build-node-completions-1)
1873 (push (cons filename Info-current-file-completions) Info-file-completions)
1874 Info-current-file-completions))
1875 (or Info-current-file-completions
1876 (Info-build-node-completions-1))))
1878 (defun Info-build-node-completions-1 ()
1879 (let ((compl nil)
1880 ;; Bind this in case the user sets it to nil.
1881 (case-fold-search t)
1882 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1883 (save-excursion
1884 (save-restriction
1885 (or Info-tag-table-marker
1886 (error "No Info tags found"))
1887 (if (marker-buffer Info-tag-table-marker)
1888 (let ((marker Info-tag-table-marker))
1889 (set-buffer (marker-buffer marker))
1890 (widen)
1891 (goto-char marker)
1892 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1893 (setq compl
1894 (cons (list (match-string-no-properties 2))
1895 compl))))
1896 (widen)
1897 (goto-char (point-min))
1898 ;; If the buffer begins with a node header, process that first.
1899 (if (Info-node-at-bob-matching node-regexp)
1900 (setq compl (list (match-string-no-properties 1))))
1901 ;; Now for the rest of the nodes.
1902 (while (search-forward "\n\^_" nil t)
1903 (forward-line 1)
1904 (let ((beg (point)))
1905 (forward-line 1)
1906 (if (re-search-backward node-regexp beg t)
1907 (setq compl
1908 (cons (list (match-string-no-properties 1))
1909 compl))))))))
1910 (setq compl (cons '("*") (nreverse compl)))
1911 (setq Info-current-file-completions compl)
1912 compl))
1915 (defun Info-restore-point (hl)
1916 "If this node has been visited, restore the point value when we left."
1917 (while hl
1918 (if (and (equal (nth 0 (car hl)) Info-current-file)
1919 ;; Use string-equal, not equal, to ignore text props.
1920 (string-equal (nth 1 (car hl)) Info-current-node))
1921 (progn
1922 (goto-char (nth 2 (car hl)))
1923 (setq hl nil)) ;terminate the while at next iter
1924 (setq hl (cdr hl)))))
1926 (defvar Info-search-history nil
1927 "The history list for `Info-search'.")
1929 (defvar Info-search-case-fold nil
1930 "The value of `case-fold-search' from previous `Info-search' command.")
1932 (defun Info--search-loop (regexp bound backward)
1933 (when backward
1934 ;; Hide Info file header for backward search.
1935 (narrow-to-region (save-excursion
1936 (goto-char (point-min))
1937 (search-forward "\n\^_")
1938 (1- (point)))
1939 (point-max)))
1940 (let ((give-up nil)
1941 (found nil)
1942 (beg-found nil))
1943 (while (not (or give-up
1944 (and found
1945 (funcall isearch-filter-predicate
1946 beg-found found))))
1947 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1948 (if (funcall
1949 (if backward #'re-search-backward #'re-search-forward)
1950 regexp bound t)
1951 (setq found (point) beg-found (if backward (match-end 0)
1952 (match-beginning 0)))
1953 (setq give-up t found nil))))
1954 found))
1956 (defun Info-search (regexp &optional bound _noerror _count direction)
1957 "Search for REGEXP, starting from point, and select node it's found in.
1958 If DIRECTION is `backward', search in the reverse direction."
1959 (interactive (list (read-string
1960 (if Info-search-history
1961 (format "Regexp search%s (default %s): "
1962 (if case-fold-search "" " case-sensitively")
1963 (car Info-search-history))
1964 (format "Regexp search%s: "
1965 (if case-fold-search "" " case-sensitively")))
1966 nil 'Info-search-history)))
1967 (deactivate-mark)
1968 (when (equal regexp "")
1969 (setq regexp (car Info-search-history)))
1970 (when regexp
1971 (setq Info-search-case-fold case-fold-search)
1972 (let* ((backward (eq direction 'backward))
1973 (onode Info-current-node)
1974 (ofile Info-current-file)
1975 (opoint (point))
1976 (opoint-min (point-min))
1977 (opoint-max (point-max))
1978 (ostart (window-start))
1979 (osubfile Info-current-subfile)
1980 (found
1981 (save-excursion
1982 (save-restriction
1983 (widen)
1984 (Info--search-loop regexp bound backward)))))
1986 (unless (or (not isearch-mode) (not Info-isearch-search)
1987 Info-isearch-initial-node
1988 bound
1989 (and found (> found opoint-min) (< found opoint-max)))
1990 (signal 'search-failed (list regexp "end of node")))
1992 ;; If no subfiles, give error now.
1993 (unless (or found Info-current-subfile)
1994 (if isearch-mode
1995 (signal 'search-failed (list regexp "end of manual"))
1996 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1997 (if backward
1998 (re-search-backward regexp)
1999 (re-search-forward regexp)))))
2001 (if (and bound (not found))
2002 (signal 'search-failed (list regexp)))
2004 (unless (or found bound)
2005 (unwind-protect
2006 ;; Try other subfiles.
2007 (let ((list ()))
2008 (with-current-buffer (marker-buffer Info-tag-table-marker)
2009 (goto-char (point-min))
2010 (search-forward "\n\^_\nIndirect:")
2011 (save-restriction
2012 (narrow-to-region (point)
2013 (progn (search-forward "\n\^_")
2014 (1- (point))))
2015 (goto-char (point-min))
2016 ;; Find the subfile we just searched.
2017 (search-forward (concat "\n" osubfile ": "))
2018 ;; Skip that one.
2019 (forward-line (if backward 0 1))
2020 (if backward (forward-char -1))
2021 ;; Make a list of all following subfiles.
2022 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
2023 (while (not (if backward (bobp) (eobp)))
2024 (if backward
2025 (re-search-backward "\\(^.*\\): [0-9]+$")
2026 (re-search-forward "\\(^.*\\): [0-9]+$"))
2027 (goto-char (+ (match-end 1) 2))
2028 (push (cons (read (current-buffer))
2029 (match-string-no-properties 1))
2030 list)
2031 (goto-char (if backward
2032 (1- (match-beginning 0))
2033 (1+ (match-end 0)))))
2034 ;; Put in forward order
2035 (setq list (nreverse list))))
2036 (while list
2037 (message "Searching subfile %s..." (cdr (car list)))
2038 (Info-read-subfile (car (car list)))
2039 (when backward (goto-char (point-max)))
2040 (setq list (cdr list))
2041 (setq found (Info--search-loop regexp nil backward))
2042 (if found
2043 (setq list nil)))
2044 (if found
2045 (message "")
2046 (signal 'search-failed (if isearch-mode
2047 (list regexp "end of manual")
2048 (list regexp)))))
2049 (if (not found)
2050 (progn (Info-read-subfile osubfile)
2051 (goto-char opoint)
2052 (Info-select-node)
2053 (set-window-start (selected-window) ostart)))))
2055 (if (and (string= osubfile Info-current-subfile)
2056 (> found opoint-min)
2057 (< found opoint-max))
2058 ;; Search landed in the same node
2059 (goto-char found)
2060 (widen)
2061 (goto-char found)
2062 (save-match-data (Info-select-node)))
2064 ;; Use string-equal, not equal, to ignore text props.
2065 (or (and (string-equal onode Info-current-node)
2066 (equal ofile Info-current-file))
2067 (and isearch-mode isearch-wrapped
2068 (eq opoint (if isearch-forward opoint-min opoint-max)))
2069 (setq Info-history (cons (list ofile onode opoint)
2070 Info-history))))))
2072 (defun Info-search-case-sensitively ()
2073 "Search for a regexp case-sensitively."
2074 (interactive)
2075 (let ((case-fold-search nil))
2076 (call-interactively 'Info-search)))
2078 (defun Info-search-next ()
2079 "Search for next regexp from a previous `Info-search' command."
2080 (interactive)
2081 (let ((case-fold-search Info-search-case-fold))
2082 (if Info-search-history
2083 (Info-search (car Info-search-history))
2084 (call-interactively 'Info-search))))
2086 (defun Info-search-backward (regexp &optional bound noerror count)
2087 "Search for REGEXP in the reverse direction."
2088 (interactive (list (read-string
2089 (if Info-search-history
2090 (format "Regexp search%s backward (default %s): "
2091 (if case-fold-search "" " case-sensitively")
2092 (car Info-search-history))
2093 (format "Regexp search%s backward: "
2094 (if case-fold-search "" " case-sensitively")))
2095 nil 'Info-search-history)))
2096 (Info-search regexp bound noerror count 'backward))
2098 (defun Info-isearch-search ()
2099 (if Info-isearch-search
2100 (lambda (string &optional bound noerror count)
2101 (let ((Info-search-whitespace-regexp
2102 (if (if isearch-regexp
2103 isearch-regexp-lax-whitespace
2104 isearch-lax-whitespace)
2105 search-whitespace-regexp)))
2106 (Info-search
2107 (cond
2108 (isearch-regexp-function
2109 ;; Lax version of word search
2110 (let ((lax (not (or isearch-nonincremental
2111 (eq (length string)
2112 (length (isearch--state-string
2113 (car isearch-cmds))))))))
2114 (if (functionp isearch-regexp-function)
2115 (funcall isearch-regexp-function string lax)
2116 (word-search-regexp string lax))))
2117 (isearch-regexp string)
2118 (t (regexp-quote string)))
2119 bound noerror count
2120 (unless isearch-forward 'backward)))
2121 (point))
2122 (isearch-search-fun-default)))
2124 (defun Info-isearch-wrap ()
2125 (if Info-isearch-search
2126 (if Info-isearch-initial-node
2127 (progn
2128 (if isearch-forward (Info-top-node) (Info-final-node))
2129 (goto-char (if isearch-forward (point-min) (point-max))))
2130 (setq Info-isearch-initial-node Info-current-node)
2131 (setq isearch-wrapped nil))
2132 (goto-char (if isearch-forward (point-min) (point-max)))))
2134 (defun Info-isearch-push-state ()
2135 `(lambda (cmd)
2136 (Info-isearch-pop-state cmd ',Info-current-file ',Info-current-node)))
2138 (defun Info-isearch-pop-state (_cmd file node)
2139 (or (and (equal Info-current-file file)
2140 (equal Info-current-node node))
2141 (progn (Info-find-node file node) (sit-for 0))))
2143 (defun Info-isearch-start ()
2144 (setq Info-isearch-initial-node
2145 ;; Don't stop at initial node for nonincremental search.
2146 ;; Otherwise this variable is set after first search failure.
2147 (and isearch-nonincremental Info-current-node))
2148 (setq Info-isearch-initial-history Info-history
2149 Info-isearch-initial-history-list Info-history-list)
2150 (add-hook 'isearch-mode-end-hook 'Info-isearch-end nil t))
2152 (defun Info-isearch-end ()
2153 ;; Remove intermediate nodes (visited while searching)
2154 ;; from the history. Add only the last node (where Isearch ended).
2155 (if (> (length Info-history)
2156 (length Info-isearch-initial-history))
2157 (setq Info-history
2158 (nthcdr (- (length Info-history)
2159 (length Info-isearch-initial-history)
2161 Info-history)))
2162 (if (> (length Info-history-list)
2163 (length Info-isearch-initial-history-list))
2164 (setq Info-history-list
2165 (cons (car Info-history-list)
2166 Info-isearch-initial-history-list)))
2167 (remove-hook 'isearch-mode-end-hook 'Info-isearch-end t))
2169 (defun Info-isearch-filter (beg-found found)
2170 "Test whether the current search hit is a visible useful text.
2171 Return non-nil if the text from BEG-FOUND to FOUND is visible
2172 and is not in the header line or a tag table."
2173 (save-match-data
2174 (let ((backward (< found beg-found)))
2175 (not
2177 (and (not search-invisible)
2178 (if backward
2179 (or (text-property-not-all found beg-found 'invisible nil)
2180 (text-property-not-all found beg-found 'display nil))
2181 (or (text-property-not-all beg-found found 'invisible nil)
2182 (text-property-not-all beg-found found 'display nil))))
2183 ;; Skip node header line
2184 (and (save-excursion (forward-line -1)
2185 (looking-at "\^_"))
2186 (forward-line (if backward -1 1)))
2187 ;; Skip Tag Table node
2188 (save-excursion
2189 (and (search-backward "\^_" nil t)
2190 (looking-at
2191 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
2194 (defun Info-extract-pointer (name &optional errorname)
2195 "Extract the value of the node-pointer named NAME.
2196 If there is none, use ERRORNAME in the error message;
2197 if ERRORNAME is nil, just return nil."
2198 ;; Bind this in case the user sets it to nil.
2199 (let ((case-fold-search t))
2200 (save-excursion
2201 (goto-char (point-min))
2202 (let ((bound (point)))
2203 (forward-line 1)
2204 (cond ((re-search-backward
2205 (concat name ":" (Info-following-node-name-re)) bound t)
2206 (match-string-no-properties 1))
2207 ((not (eq errorname t))
2208 (user-error "Node has no %s"
2209 (capitalize (or errorname name)))))))))
2211 (defun Info-following-node-name-re (&optional allowedchars)
2212 "Return a regexp matching a node name.
2213 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
2214 saying which chars may appear in the node name.
2215 Submatch 1 is the complete node name.
2216 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2217 Submatch 3 is the local part of the node name.
2218 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2219 (concat "[ \t\n]*" ;Skip leading space.
2220 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2221 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
2222 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
2223 "\\|\\)\\)")) ;Allow empty node names.
2225 ;; For compatibility; other files have used this name.
2226 (defun Info-following-node-name ()
2227 (and (looking-at (Info-following-node-name-re))
2228 (match-string-no-properties 1)))
2230 (defun Info-next ()
2231 "Go to the next node of this node."
2232 (interactive)
2233 ;; In case another window is currently selected
2234 (save-window-excursion
2235 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
2236 (Info-goto-node (Info-extract-pointer "next"))))
2238 (defun Info-prev ()
2239 "Go to the previous node of this node."
2240 (interactive)
2241 ;; In case another window is currently selected
2242 (save-window-excursion
2243 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
2244 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2246 (defun Info-up (&optional same-file)
2247 "Go to the superior node of this node.
2248 If SAME-FILE is non-nil, do not move to a different Info file."
2249 (interactive)
2250 ;; In case another window is currently selected
2251 (save-window-excursion
2252 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
2253 (let ((old-node Info-current-node)
2254 (old-file Info-current-file)
2255 (node (Info-extract-pointer "up")) p)
2256 (and same-file
2257 (string-match "^(" node)
2258 (error "Up node is in another Info file"))
2259 (Info-goto-node node)
2260 (setq p (point))
2261 (goto-char (point-min))
2262 (if (and (stringp old-file)
2263 (search-forward "\n* Menu:" nil t)
2264 (re-search-forward
2265 (if (string-equal old-node "Top")
2266 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
2267 (concat "\n\\* +\\(" (regexp-quote old-node)
2268 ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
2269 nil t))
2270 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2271 (goto-char p)
2272 (Info-restore-point Info-history)))))
2274 (defun Info-history-back ()
2275 "Go back in the history to the last node visited."
2276 (interactive)
2277 (or Info-history
2278 (user-error "This is the first Info node you looked at"))
2279 (let ((history-forward
2280 (cons (list Info-current-file Info-current-node (point))
2281 Info-history-forward))
2282 filename nodename opoint)
2283 (setq filename (car (car Info-history)))
2284 (setq nodename (car (cdr (car Info-history))))
2285 (setq opoint (car (cdr (cdr (car Info-history)))))
2286 (setq Info-history (cdr Info-history))
2287 (Info-find-node filename nodename)
2288 (setq Info-history (cdr Info-history))
2289 (setq Info-history-forward history-forward)
2290 (goto-char opoint)))
2292 (defalias 'Info-last 'Info-history-back)
2294 (defun Info-history-forward ()
2295 "Go forward in the history of visited nodes."
2296 (interactive)
2297 (or Info-history-forward
2298 (user-error "This is the last Info node you looked at"))
2299 (let ((history-forward (cdr Info-history-forward))
2300 filename nodename opoint)
2301 (setq filename (car (car Info-history-forward)))
2302 (setq nodename (car (cdr (car Info-history-forward))))
2303 (setq opoint (car (cdr (cdr (car Info-history-forward)))))
2304 (Info-find-node filename nodename)
2305 (setq Info-history-forward history-forward)
2306 (goto-char opoint)))
2308 (add-to-list 'Info-virtual-files
2309 '("\\`dir\\'"
2310 (toc-nodes . Info-directory-toc-nodes)
2311 (find-file . Info-directory-find-file)
2312 (find-node . Info-directory-find-node)
2315 (defun Info-directory-toc-nodes (filename)
2316 "Directory-specific implementation of `Info-toc-nodes'."
2317 `(,filename
2318 ("Top" nil nil nil)))
2320 (defun Info-directory-find-file (filename &optional _noerror)
2321 "Directory-specific implementation of `Info-find-file'."
2322 filename)
2324 (defun Info-directory-find-node (_filename _nodename &optional _no-going-back)
2325 "Directory-specific implementation of `Info-find-node-2'."
2326 (Info-insert-dir))
2328 ;;;###autoload
2329 (defun Info-directory ()
2330 "Go to the Info directory node."
2331 (interactive)
2332 (Info-find-node "dir" "top"))
2334 (add-to-list 'Info-virtual-files
2335 '("\\`\\*History\\*\\'"
2336 (toc-nodes . Info-history-toc-nodes)
2337 (find-file . Info-history-find-file)
2338 (find-node . Info-history-find-node)
2341 (defun Info-history-toc-nodes (filename)
2342 "History-specific implementation of `Info-toc-nodes'."
2343 `(,filename
2344 ("Top" nil nil nil)))
2346 (defun Info-history-find-file (filename &optional _noerror)
2347 "History-specific implementation of `Info-find-file'."
2348 filename)
2350 (defun Info-history-find-node (filename nodename &optional _no-going-back)
2351 "History-specific implementation of `Info-find-node-2'."
2352 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2353 (or filename Info-current-file) nodename))
2354 (insert "Recently Visited Nodes\n")
2355 (insert "**********************\n\n")
2356 (insert "* Menu:\n\n")
2357 (let ((hl (remove '("*History*" "Top") Info-history-list)))
2358 (while hl
2359 (let ((file (nth 0 (car hl)))
2360 (node (nth 1 (car hl))))
2361 (if (stringp file)
2362 (insert "* " node ": ("
2363 (propertize (or (file-name-directory file) "") 'invisible t)
2364 (file-name-nondirectory file)
2365 ")" node ".\n")))
2366 (setq hl (cdr hl)))))
2368 (defun Info-history ()
2369 "Go to a node with a menu of visited nodes."
2370 (interactive)
2371 (Info-find-node "*History*" "Top")
2372 (Info-next-reference)
2373 (Info-next-reference))
2375 (add-to-list 'Info-virtual-nodes
2376 '("\\`\\*TOC\\*\\'"
2377 (find-node . Info-toc-find-node)
2380 (defun Info-toc-find-node (filename nodename &optional _no-going-back)
2381 "Toc-specific implementation of `Info-find-node-2'."
2382 (let* ((curr-file (substring-no-properties (or filename Info-current-file)))
2383 (curr-node (substring-no-properties (or nodename Info-current-node)))
2384 (node-list (Info-toc-nodes curr-file)))
2385 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2386 curr-file curr-node))
2387 (insert "Table of Contents\n")
2388 (insert "*****************\n\n")
2389 (insert "*Note Top::\n")
2390 (Info-toc-insert
2391 (nth 3 (assoc "Top" node-list)) ; get Top nodes
2392 node-list 0 curr-file)
2393 (unless (bobp)
2394 (let ((Info-hide-note-references 'hide)
2395 (Info-fontify-visited-nodes nil))
2396 (setq Info-current-file filename Info-current-node "*TOC*")
2397 (goto-char (point-min))
2398 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t)
2399 (point-min))
2400 (point-max))
2401 (Info-fontify-node)
2402 (widen)))))
2404 (defun Info-toc ()
2405 "Go to a node with table of contents of the current Info file.
2406 Table of contents is created from the tree structure of menus."
2407 (interactive)
2408 (Info-find-node Info-current-file "*TOC*")
2409 (let ((prev-node (nth 1 (car Info-history))) p)
2410 (goto-char (point-min))
2411 (if (setq p (search-forward (concat "*Note " prev-node ":") nil t))
2412 (setq p (- p (length prev-node) 2)))
2413 (goto-char (or p (point-min)))))
2415 (defun Info-toc-insert (nodes node-list level curr-file)
2416 "Insert table of contents with references to nodes."
2417 (let ((section "Top"))
2418 (while nodes
2419 (let ((node (assoc (car nodes) node-list)))
2420 (unless (member (nth 2 node) (list nil section))
2421 (insert (setq section (nth 2 node)) "\n"))
2422 (insert (make-string level ?\t))
2423 (insert "*Note " (car nodes) ":: \n")
2424 (Info-toc-insert (nth 3 node) node-list (1+ level) curr-file)
2425 (setq nodes (cdr nodes))))))
2427 (defun Info-toc-build (file)
2428 "Build table of contents from menus of Info FILE and its subfiles."
2429 (with-temp-buffer
2430 (let* ((file (and (stringp file) (Info-find-file file)))
2431 (default-directory (or (and (stringp file)
2432 (file-name-directory file))
2433 default-directory))
2434 (main-file (and (stringp file) file))
2435 (sections '(("Top" "Top")))
2436 nodes subfiles)
2437 (while (or main-file subfiles)
2438 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2439 (erase-buffer)
2440 (info-insert-file-contents (or main-file (car subfiles)))
2441 (goto-char (point-min))
2442 (while (and (search-forward "\n\^_\nFile:" nil 'move)
2443 (search-forward "Node: " nil 'move))
2444 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2445 (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
2446 (point-max)) 2))
2447 (upnode (and (re-search-forward
2448 (concat "Up:" (Info-following-node-name-re))
2449 bound t)
2450 (match-string-no-properties 1)))
2451 (section "Top")
2452 menu-items)
2453 (when (and upnode (string-match "(" upnode)) (setq upnode nil))
2454 (when (and (not (Info-index-node nodename file))
2455 (re-search-forward "^\\* Menu:" bound t))
2456 (forward-line 1)
2457 (beginning-of-line)
2458 (setq bound (or (and (equal nodename "Top")
2459 (save-excursion
2460 (re-search-forward
2461 "^[ \t-]*The Detailed Node Listing" nil t)))
2462 bound))
2463 (while (< (point) bound)
2464 (cond
2465 ;; Menu item line
2466 ((looking-at "^\\* +[^:]+:")
2467 (beginning-of-line)
2468 (forward-char 2)
2469 (let ((menu-node-name (substring-no-properties
2470 (Info-extract-menu-node-name))))
2471 (setq menu-items (cons menu-node-name menu-items))
2472 (if (equal nodename "Top")
2473 (setq sections
2474 (cons (list menu-node-name section) sections)))))
2475 ;; Other non-empty strings in the Top node are section names
2476 ((and (equal nodename "Top")
2477 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2478 (setq section (match-string-no-properties 1))))
2479 (forward-line 1)
2480 (beginning-of-line)))
2481 (setq nodes (cons (list nodename upnode
2482 (cadr (assoc nodename sections))
2483 (nreverse menu-items))
2484 nodes))
2485 (goto-char bound)))
2486 (if main-file
2487 (save-excursion
2488 (goto-char (point-min))
2489 (if (search-forward "\n\^_\nIndirect:" nil t)
2490 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2491 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2492 (setq subfiles (cons (match-string-no-properties 1)
2493 subfiles)))))
2494 (setq subfiles (nreverse subfiles)
2495 main-file nil))
2496 (setq subfiles (cdr subfiles))))
2497 (message "")
2498 (nreverse nodes))))
2500 (defun Info-toc-nodes (filename)
2501 "Return a node list of Info FILENAME with parent-children information.
2502 This information is cached in the variable `Info-toc-nodes' with the help
2503 of the function `Info-toc-build'."
2504 (cond
2505 ((Info-virtual-call
2506 (Info-virtual-fun 'toc-nodes (or filename Info-current-file) nil)
2507 filename))
2509 (or filename (setq filename Info-current-file))
2510 (or (assoc filename Info-toc-nodes)
2511 ;; Skip virtual Info files
2512 (and (or (not (stringp filename))
2513 (Info-virtual-file-p filename))
2514 (push (cons filename nil) Info-toc-nodes))
2515 ;; Scan the entire manual and cache the result in Info-toc-nodes
2516 (let ((nodes (Info-toc-build filename)))
2517 (push (cons filename nodes) Info-toc-nodes)
2518 nodes)
2519 ;; If there is an error, still add nil to the cache
2520 (push (cons filename nil) Info-toc-nodes))
2521 (cdr (assoc filename Info-toc-nodes)))))
2524 (defun Info-follow-reference (footnotename &optional fork)
2525 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2526 FOOTNOTENAME may be an abbreviation of the reference name.
2527 If FORK is non-nil (interactively with a prefix arg), show the node in
2528 a new Info buffer. If FORK is a string, it is the name to use for the
2529 new buffer."
2530 (interactive
2531 (let ((completion-ignore-case t)
2532 (case-fold-search t)
2533 completions default alt-default (start-point (point)) str i bol eol)
2534 (save-excursion
2535 ;; Store end and beginning of line.
2536 (setq eol (line-end-position)
2537 bol (line-beginning-position))
2538 (goto-char (point-min))
2539 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
2540 (setq str (match-string-no-properties 1))
2541 ;; See if this one should be the default.
2542 (and (null default)
2543 (<= (match-beginning 0) start-point)
2544 (<= start-point (point))
2545 (setq default t))
2546 ;; See if this one should be the alternate default.
2547 (and (null alt-default)
2548 (and (<= bol (match-beginning 0))
2549 (<= (point) eol))
2550 (setq alt-default t))
2551 (setq i 0)
2552 (while (setq i (string-match "[ \n\t]+" str i))
2553 (setq str (concat (substring str 0 i) " "
2554 (substring str (match-end 0))))
2555 (setq i (1+ i)))
2556 ;; Record as a completion and perhaps as default.
2557 (if (eq default t) (setq default str))
2558 (if (eq alt-default t) (setq alt-default str))
2559 ;; Don't add this string if it's a duplicate.
2560 (or (assoc-string str completions t)
2561 (push str completions))))
2562 ;; If no good default was found, try an alternate.
2563 (or default
2564 (setq default alt-default))
2565 ;; If only one cross-reference found, then make it default.
2566 (if (eq (length completions) 1)
2567 (setq default (car completions)))
2568 (if completions
2569 (let ((input (completing-read (if default
2570 (concat
2571 "Follow reference named (default "
2572 default "): ")
2573 "Follow reference named: ")
2574 completions nil t)))
2575 (list (if (equal input "")
2576 default input) current-prefix-arg))
2577 (user-error "No cross-references in this node"))))
2579 (unless footnotename
2580 (error "No reference was specified"))
2582 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
2583 (case-fold-search t))
2584 (while (setq i (string-match " " str i))
2585 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
2586 (setq i (+ i 6)))
2587 (save-excursion
2588 ;; Move point to the beginning of reference if point is on reference
2589 (or (looking-at "\\*note[ \n\t]+")
2590 (and (looking-back "\\*note[ \n\t]+"
2591 (save-excursion (skip-chars-backward " \n\t")
2592 (line-beginning-position)))
2593 (goto-char (match-beginning 0)))
2594 (if (and (save-excursion
2595 (goto-char (+ (point) 5)) ; skip a possible *note
2596 (re-search-backward "\\*note[ \n\t]+" nil t)
2597 (looking-at str))
2598 (<= (point) (match-end 0)))
2599 (goto-char (match-beginning 0))))
2600 ;; Go to the reference closest to point
2601 (let ((next-ref (save-excursion (and (re-search-forward str nil t)
2602 (+ (match-beginning 0) 5))))
2603 (prev-ref (save-excursion (and (re-search-backward str nil t)
2604 (+ (match-beginning 0) 5)))))
2605 (goto-char (cond ((and next-ref prev-ref)
2606 (if (< (abs (- next-ref (point)))
2607 (abs (- prev-ref (point))))
2608 next-ref prev-ref))
2609 ((or next-ref prev-ref))
2610 ((user-error "No cross-reference named %s"
2611 footnotename))))
2612 (setq target (Info-extract-menu-node-name t))))
2613 (while (setq i (string-match "[ \t\n]+" target i))
2614 (setq target (concat (substring target 0 i) " "
2615 (substring target (match-end 0))))
2616 (setq i (+ i 1)))
2617 (Info-goto-node target fork)))
2619 (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2620 ;; We allow newline because this is also used in Info-follow-reference,
2621 ;; where the xref name might be wrapped over two lines.
2622 "Regexp that matches a menu entry name upto but not including the colon.
2623 Because of ambiguities, this should be concatenated with something like
2624 `:' and `Info-following-node-name-re'.")
2626 (defun Info-extract-menu-node-name (&optional multi-line index-node)
2627 (skip-chars-forward " \t\n")
2628 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
2629 (Info-following-node-name-re
2630 (cond
2631 (index-node "^,\t\n")
2632 (multi-line "^.,\t")
2633 (t "^.,\t\n")))
2634 "\\)"
2635 (if index-node
2636 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2637 "")))
2638 (if index-node
2639 (setq Info-point-loc
2640 (if (match-beginning 5)
2641 (string-to-number (match-string 5))
2642 (buffer-substring-no-properties
2643 (match-beginning 0) (1- (match-beginning 1)))))
2644 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2645 ;;; (setq Info-point-loc
2646 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2648 (replace-regexp-in-string
2649 "[ \n]+" " "
2650 (or (and (not (equal (match-string-no-properties 2) ""))
2651 (match-string-no-properties 2))
2652 ;; If the node name is the menu entry name (using `entry::').
2653 (buffer-substring-no-properties
2654 (match-beginning 0) (1- (match-beginning 1)))))))
2656 ;; No one calls this.
2657 ;;(defun Info-menu-item-sequence (list)
2658 ;; (while list
2659 ;; (Info-menu (car list))
2660 ;; (setq list (cdr list))))
2662 (defvar Info-complete-menu-buffer)
2663 (defvar Info-complete-next-re nil)
2664 (defvar Info-complete-nodes nil)
2665 (defvar-local Info-complete-cache nil)
2667 (defconst Info-node-spec-re
2668 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2669 "Regexp to match the text after a : until the terminating `.'.")
2671 (defun Info-complete-menu-item (string predicate action)
2672 ;; This uses two dynamically bound variables:
2673 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2674 ;; is the menu of items we're trying to complete.
2675 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2676 ;; also look for menu items in subsequent nodes as long as those
2677 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2678 ;; not used.
2679 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2680 ;; also look for menu items in these nodes. This feature is currently
2681 ;; only used for completion in Info-index.
2683 ;; Note that `Info-complete-menu-buffer' could be current already,
2684 ;; so we want to save point.
2685 (with-current-buffer Info-complete-menu-buffer
2686 (save-excursion
2687 (let ((completion-ignore-case t)
2688 (case-fold-search t)
2689 (orignode Info-current-node)
2690 nextnode)
2691 (goto-char (point-min))
2692 (search-forward "\n* Menu:")
2693 (cond
2694 ((eq (car-safe action) 'boundaries) nil)
2695 ((eq action 'lambda)
2696 (re-search-forward
2697 (concat "\n\\* +" (regexp-quote string) ":") nil t))
2699 (let ((pattern (concat "\n\\* +\\("
2700 (regexp-quote string)
2701 Info-menu-entry-name-re "\\):"
2702 Info-node-spec-re))
2703 completions
2704 (complete-nodes Info-complete-nodes))
2705 ;; Check the cache.
2706 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
2707 (equal (nth 1 Info-complete-cache) Info-current-node)
2708 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
2709 (equal (nth 5 Info-complete-cache) Info-complete-nodes)
2710 (string-prefix-p (nth 3 Info-complete-cache) string) t)
2711 ;; We can reuse the previous list.
2712 (setq completions (nth 4 Info-complete-cache))
2713 ;; The cache can't be used.
2714 (while
2715 (progn
2716 (while (re-search-forward pattern nil t)
2717 (push (match-string-no-properties 1)
2718 completions))
2719 (setq completions (delete-dups completions))
2720 ;; Check subsequent nodes if applicable.
2721 (or (and Info-complete-next-re
2722 (setq nextnode (Info-extract-pointer "next" t))
2723 (string-match Info-complete-next-re nextnode))
2724 (and complete-nodes
2725 (setq complete-nodes (cdr complete-nodes)
2726 nextnode (car complete-nodes)))))
2727 (Info-goto-node nextnode))
2728 ;; Go back to the start node (for the next completion).
2729 (unless (equal Info-current-node orignode)
2730 (Info-goto-node orignode))
2731 ;; Update the cache.
2732 (setq Info-complete-cache
2733 (list Info-current-file Info-current-node
2734 Info-complete-next-re string completions
2735 Info-complete-nodes)))
2736 (complete-with-action action completions string predicate))))))))
2739 (defun Info-menu (menu-item &optional fork)
2740 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2741 The menu item should one of those listed in the current node's menu.
2742 Completion is allowed, and the default menu item is the one point is on.
2743 If FORK is non-nil (interactively with a prefix arg), show the node in
2744 a new Info buffer. If FORK is a string, it is the name to use for the
2745 new buffer."
2746 (interactive
2747 (let (;; If point is within a menu item, use that item as the default
2748 (default nil)
2749 (p (point))
2751 (case-fold-search t))
2752 (save-excursion
2753 (goto-char (point-min))
2754 (if (not (search-forward "\n* menu:" nil t))
2755 (user-error "No menu in this node"))
2756 (setq beg (point))
2757 (and (< (point) p)
2758 (save-excursion
2759 (goto-char p)
2760 (end-of-line)
2761 (if (re-search-backward (concat "\n\\* +\\("
2762 Info-menu-entry-name-re
2763 "\\):")
2764 beg t)
2765 (setq default (match-string-no-properties 1))))))
2766 (let ((item nil))
2767 (while (null item)
2768 (setq item (let ((completion-ignore-case t)
2769 (Info-complete-menu-buffer (current-buffer)))
2770 (completing-read (if default
2771 (format "Menu item (default %s): "
2772 default)
2773 "Menu item: ")
2774 #'Info-complete-menu-item nil t nil nil
2775 default)))
2776 ;; we rely on the fact that completing-read accepts an input
2777 ;; of "" even when the require-match argument is true and ""
2778 ;; is not a valid possibility
2779 (if (string= item "")
2780 (if default
2781 (setq item default)
2782 ;; ask again
2783 (setq item nil))))
2784 (list item current-prefix-arg))))
2785 ;; there is a problem here in that if several menu items have the same
2786 ;; name you can only go to the node of the first with this command.
2787 (Info-goto-node (Info-extract-menu-item menu-item)
2788 (and fork
2789 (if (stringp fork) fork menu-item))))
2791 (defun Info-extract-menu-item (menu-item)
2792 (setq menu-item (regexp-quote menu-item))
2793 (let ((case-fold-search t))
2794 (save-excursion
2795 (let ((case-fold-search t))
2796 (goto-char (point-min))
2797 (or (search-forward "\n* menu:" nil t)
2798 (user-error "No menu in this node"))
2799 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
2800 (re-search-forward (concat "\n\\* +" menu-item) nil t)
2801 (user-error "No such item in menu"))
2802 (beginning-of-line)
2803 (forward-char 2)
2804 (Info-extract-menu-node-name nil (Info-index-node))))))
2806 ;; If COUNT is nil, use the last item in the menu.
2807 (defun Info-extract-menu-counting (count &optional no-detail)
2808 (let ((case-fold-search t))
2809 (save-excursion
2810 (let ((case-fold-search t)
2811 (bound (when (and no-detail
2812 (re-search-forward
2813 "^[ \t-]*The Detailed Node Listing" nil t))
2814 (match-beginning 0))))
2815 (goto-char (point-min))
2816 (or (search-forward "\n* menu:" bound t)
2817 (user-error "No menu in this node"))
2818 (if count
2819 (or (search-forward "\n* " bound t count)
2820 (error "Too few items in menu"))
2821 (while (search-forward "\n* " bound t)
2822 nil))
2823 (Info-extract-menu-node-name nil (Info-index-node))))))
2825 (defun Info-nth-menu-item ()
2826 "Go to the node of the Nth menu item.
2827 N is the digit argument used to invoke this command."
2828 (interactive)
2829 (Info-goto-node
2830 (Info-extract-menu-counting
2831 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
2833 (defun Info-top-node ()
2834 "Go to the Top node of this file."
2835 (interactive)
2836 (Info-goto-node "Top"))
2838 (defun Info-final-node ()
2839 "Go to the final node in this file."
2840 (interactive)
2841 (Info-goto-node "Top")
2842 (let ((Info-history nil)
2843 (case-fold-search t))
2844 ;; Go to the last node in the menu of Top. But don't delve into
2845 ;; detailed node listings.
2846 (Info-goto-node (Info-extract-menu-counting nil t))
2847 ;; If the last node in the menu is not last in pointer structure,
2848 ;; move forward (but not down- or upward - see bug#1116) until we
2849 ;; can't go any farther.
2850 (while (Info-forward-node t t t) nil)
2851 ;; Then keep moving down to last subnode, unless we reach an index.
2852 (while (and (not (Info-index-node))
2853 (save-excursion (search-forward "\n* Menu:" nil t)))
2854 (Info-goto-node (Info-extract-menu-counting nil)))))
2856 (defun Info-forward-node (&optional not-down not-up no-error)
2857 "Go forward one node, considering all nodes as forming one sequence."
2858 (interactive)
2859 (goto-char (point-min))
2860 (forward-line 1)
2861 (let ((case-fold-search t))
2862 ;; three possibilities, in order of priority:
2863 ;; 1. next node is in a menu in this node (but not in an index)
2864 ;; 2. next node is next at same level
2865 ;; 3. next node is up and next
2866 (cond ((and (not not-down)
2867 (save-excursion (search-forward "\n* menu:" nil t))
2868 (not (Info-index-node)))
2869 (Info-goto-node (Info-extract-menu-counting 1))
2871 ((save-excursion (search-backward "next:" nil t))
2872 (Info-next)
2874 ((and (not not-up)
2875 (save-excursion (search-backward "up:" nil t))
2876 ;; Use string-equal, not equal, to ignore text props.
2877 (not (string-equal (downcase (Info-extract-pointer "up"))
2878 "top")))
2879 (let ((old-node Info-current-node))
2880 (Info-up)
2881 (let ((old-history Info-history)
2882 success)
2883 (unwind-protect
2884 (setq success (Info-forward-node t nil no-error))
2885 (or success (Info-goto-node old-node)))
2886 (if Info-history-skip-intermediate-nodes
2887 (setq Info-history old-history)))))
2888 (no-error nil)
2889 (t (user-error "No pointer forward from this node")))))
2891 (defun Info-backward-node ()
2892 "Go backward one node, considering all nodes as forming one sequence."
2893 (interactive)
2894 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
2895 (upnode (Info-extract-pointer "up" t))
2896 (case-fold-search t))
2897 (cond ((and upnode (string-match "(" upnode))
2898 (user-error "First node in file"))
2899 ((and upnode (or (null prevnode)
2900 ;; Use string-equal, not equal,
2901 ;; to ignore text properties.
2902 (string-equal (downcase prevnode)
2903 (downcase upnode))))
2904 (Info-up))
2905 (prevnode
2906 ;; If we move back at the same level,
2907 ;; go down to find the last subnode*.
2908 (Info-prev)
2909 (let ((old-history Info-history))
2910 (while (and (not (Info-index-node))
2911 (save-excursion (search-forward "\n* Menu:" nil t)))
2912 (Info-goto-node (Info-extract-menu-counting nil)))
2913 (if Info-history-skip-intermediate-nodes
2914 (setq Info-history old-history))))
2916 (user-error "No pointer backward from this node")))))
2918 (defun Info-exit ()
2919 "Exit Info by selecting some other buffer."
2920 (interactive)
2921 (if Info-standalone
2922 (save-buffers-kill-emacs)
2923 (quit-window)))
2925 (defun Info-next-menu-item ()
2926 "Go to the node of the next menu item."
2927 (interactive)
2928 ;; Bind this in case the user sets it to nil.
2929 (let* ((case-fold-search t)
2930 (node
2931 (save-excursion
2932 (forward-line -1)
2933 (search-forward "\n* menu:" nil t)
2934 (and (search-forward "\n* " nil t)
2935 (Info-extract-menu-node-name)))))
2936 (if node (Info-goto-node node)
2937 (user-error "No more items in menu"))))
2939 (defun Info-last-menu-item ()
2940 "Go to the node of the previous menu item."
2941 (interactive)
2942 (save-excursion
2943 (forward-line 1)
2944 ;; Bind this in case the user sets it to nil.
2945 (let* ((case-fold-search t)
2946 (beg (save-excursion
2947 (and (search-backward "\n* menu:" nil t)
2948 (point)))))
2949 (or (and beg (search-backward "\n* " beg t))
2950 (user-error "No previous items in menu")))
2951 (Info-goto-node (save-excursion
2952 (goto-char (match-end 0))
2953 (Info-extract-menu-node-name)))))
2955 (defmacro Info-no-error (&rest body)
2956 `(condition-case nil (progn ,@body t) (error nil)))
2958 (defun Info-next-preorder ()
2959 "Go to the next subnode or the next node, or go up a level."
2960 (interactive)
2961 (cond ((Info-no-error (Info-next-menu-item)))
2962 ((Info-no-error (Info-next)))
2963 ((Info-no-error (Info-up t))
2964 ;; Since we have already gone thru all the items in this menu,
2965 ;; go up to the end of this node.
2966 (goto-char (point-max))
2967 ;; Since logically we are done with the node with that menu,
2968 ;; move on from it. But don't add intermediate nodes
2969 ;; to the history on recursive calls.
2970 (let ((old-history Info-history))
2971 (Info-next-preorder)
2972 (if Info-history-skip-intermediate-nodes
2973 (setq Info-history old-history))))
2975 (user-error "No more nodes"))))
2977 (defun Info-last-preorder ()
2978 "Go to the last node, popping up a level if there is none."
2979 (interactive)
2980 (cond ((and Info-scroll-prefer-subnodes
2981 (Info-no-error
2982 (Info-last-menu-item)
2983 ;; If we go down a menu item, go to the end of the node
2984 ;; so we can scroll back through it.
2985 (goto-char (point-max))))
2986 ;; Keep going down, as long as there are nested menu nodes.
2987 (let ((old-history Info-history))
2988 (while (Info-no-error
2989 (Info-last-menu-item)
2990 ;; If we go down a menu item, go to the end of the node
2991 ;; so we can scroll back through it.
2992 (goto-char (point-max))))
2993 (if Info-history-skip-intermediate-nodes
2994 (setq Info-history old-history)))
2995 (recenter -1))
2996 ((and (Info-no-error (Info-extract-pointer "prev"))
2997 (not (equal (Info-extract-pointer "up")
2998 (Info-extract-pointer "prev"))))
2999 (Info-no-error (Info-prev))
3000 (goto-char (point-max))
3001 (let ((old-history Info-history))
3002 (while (Info-no-error
3003 (Info-last-menu-item)
3004 ;; If we go down a menu item, go to the end of the node
3005 ;; so we can scroll back through it.
3006 (goto-char (point-max))))
3007 (if Info-history-skip-intermediate-nodes
3008 (setq Info-history old-history)))
3009 (recenter -1))
3010 ((Info-no-error (Info-up t))
3011 (goto-char (point-min))
3012 (let ((case-fold-search t))
3013 (or (search-forward "\n* Menu:" nil t)
3014 (goto-char (point-max)))))
3015 (t (user-error "No previous nodes"))))
3017 (defun Info-scroll-up ()
3018 "Scroll one screenful forward in Info, considering all nodes as one sequence.
3019 Once you scroll far enough in a node that its menu appears on the screen
3020 but after point, the next scroll moves into its first subnode, unless
3021 `Info-scroll-prefer-subnodes' is nil.
3023 When you scroll past the end of a node, that goes to the next node if
3024 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
3025 if this node has no successor, it moves to the parent node's successor,
3026 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
3027 the menu of a node, it moves to subnode indicated by the following menu
3028 item. (That case won't normally result from this command, but can happen
3029 in other ways.)"
3031 (interactive)
3032 (if (or (< (window-start) (point-min))
3033 (> (window-start) (point-max)))
3034 (set-window-start (selected-window) (point)))
3035 (let* ((case-fold-search t)
3036 (virtual-end (save-excursion
3037 (goto-char (point-min))
3038 (if (and Info-scroll-prefer-subnodes
3039 (search-forward "\n* Menu:" nil t))
3040 (point)
3041 (point-max)))))
3042 (if (or (< virtual-end (window-start))
3043 (pos-visible-in-window-p virtual-end))
3044 (cond
3045 (Info-scroll-prefer-subnodes (Info-next-preorder))
3046 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
3047 (t (Info-next-preorder)))
3048 (scroll-up))))
3050 (defun Info-mouse-scroll-up (e)
3051 "Scroll one screenful forward in Info, using the mouse.
3052 See `Info-scroll-up'."
3053 (interactive "e")
3054 (save-selected-window
3055 (if (eventp e)
3056 (select-window (posn-window (event-start e))))
3057 (Info-scroll-up)))
3059 (defun Info-scroll-down ()
3060 "Scroll one screenful back in Info, considering all nodes as one sequence.
3061 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
3062 is non-nil, this goes to its last subnode. When you scroll past the
3063 beginning of a node, that goes to the previous node or back up to the
3064 parent node."
3065 (interactive)
3066 (if (or (< (window-start) (point-min))
3067 (> (window-start) (point-max)))
3068 (set-window-start (selected-window) (point)))
3069 (let* ((case-fold-search t)
3070 (current-point (point))
3071 (virtual-end
3072 (and Info-scroll-prefer-subnodes
3073 (save-excursion
3074 (setq current-point (line-beginning-position))
3075 (goto-char (point-min))
3076 (search-forward "\n* Menu:" current-point t)))))
3077 (if (or virtual-end
3078 (pos-visible-in-window-p (point-min) nil t))
3079 (Info-last-preorder)
3080 (scroll-down))))
3082 (defun Info-mouse-scroll-down (e)
3083 "Scroll one screenful backward in Info, using the mouse.
3084 See `Info-scroll-down'."
3085 (interactive "e")
3086 (save-selected-window
3087 (if (eventp e)
3088 (select-window (posn-window (event-start e))))
3089 (Info-scroll-down)))
3091 (defun Info-next-reference-or-link (pat prop)
3092 "Move point to the next pattern-based cross-reference or property-based link.
3093 The next cross-reference is searched using the regexp PAT, and the next link
3094 is searched using the text property PROP. Move point to the closest found position
3095 of either a cross-reference found by `re-search-forward' or a link found by
3096 `next-single-char-property-change'. Return the new position of point, or nil."
3097 (let ((pxref (save-excursion (re-search-forward pat nil t)))
3098 (plink (next-single-char-property-change (point) prop)))
3099 (when (and (< plink (point-max)) (not (get-char-property plink prop)))
3100 (setq plink (next-single-char-property-change plink prop)))
3101 (if (< plink (point-max))
3102 (if (and pxref (<= pxref plink))
3103 (goto-char (or (match-beginning 1) (match-beginning 0)))
3104 (goto-char plink))
3105 (if pxref (goto-char (or (match-beginning 1) (match-beginning 0)))))))
3107 (defun Info-prev-reference-or-link (pat prop)
3108 "Move point to the previous pattern-based cross-reference or property-based link.
3109 The previous cross-reference is searched using the regexp PAT, and the previous link
3110 is searched using the text property PROP. Move point to the closest found position
3111 of either a cross-reference found by `re-search-backward' or a link found by
3112 `previous-single-char-property-change'. Return the new position of point, or nil."
3113 (let ((pxref (save-excursion (re-search-backward pat nil t)))
3114 (plink (previous-single-char-property-change (point) prop)))
3115 (when (and (> plink (point-min)) (not (get-char-property plink prop)))
3116 (setq plink (previous-single-char-property-change plink prop)))
3117 (if (> plink (point-min))
3118 (if (and pxref (>= pxref plink))
3119 (goto-char (or (match-beginning 1) (match-beginning 0)))
3120 (goto-char plink))
3121 (if pxref (goto-char (or (match-beginning 1) (match-beginning 0)))))))
3123 (defun Info-next-reference (&optional recur count)
3124 "Move cursor to the next cross-reference or menu item in the node.
3125 If COUNT is non-nil (interactively with a prefix arg), jump over
3126 COUNT cross-references."
3127 (interactive "i\np")
3128 (unless count
3129 (setq count 1))
3130 (if (< count 0)
3131 (Info-prev-reference recur (- count))
3132 (while (unless (zerop count) (setq count (1- count)))
3133 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3134 (old-pt (point))
3135 (case-fold-search t))
3136 (or (eobp) (forward-char 1))
3137 (or (Info-next-reference-or-link pat 'link)
3138 (progn
3139 (goto-char (point-min))
3140 (or (Info-next-reference-or-link pat 'link)
3141 (progn
3142 (goto-char old-pt)
3143 (user-error "No cross references in this node")))))
3144 (if (looking-at "\\* Menu:")
3145 (if recur
3146 (user-error "No cross references in this node")
3147 (Info-next-reference t))
3148 (if (looking-at "^\\* ")
3149 (forward-char 2)))))))
3151 (defun Info-prev-reference (&optional recur count)
3152 "Move cursor to the previous cross-reference or menu item in the node.
3153 If COUNT is non-nil (interactively with a prefix arg), jump over
3154 COUNT cross-references."
3155 (interactive "i\np")
3156 (unless count
3157 (setq count 1))
3158 (if (< count 0)
3159 (Info-next-reference recur (- count))
3160 (while (unless (zerop count) (setq count (1- count)))
3161 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3162 (old-pt (point))
3163 (case-fold-search t))
3164 (or (Info-prev-reference-or-link pat 'link)
3165 (progn
3166 (goto-char (point-max))
3167 (or (Info-prev-reference-or-link pat 'link)
3168 (progn
3169 (goto-char old-pt)
3170 (user-error "No cross references in this node")))))
3171 (if (looking-at "\\* Menu:")
3172 (if recur
3173 (user-error "No cross references in this node")
3174 (Info-prev-reference t))
3175 (if (looking-at "^\\* ")
3176 (forward-char 2)))))))
3178 (defun Info-index-nodes (&optional file)
3179 "Return a list of names of all index nodes in Info FILE.
3180 If FILE is omitted, it defaults to the current Info file.
3181 First look in a list of cached index node names. Then scan Info
3182 file and its subfiles for nodes with the index cookie. Then try
3183 to find index nodes starting from the first node in the top level
3184 menu whose name contains the word \"Index\", plus any immediately
3185 following nodes whose names also contain the word \"Index\"."
3186 (or file (setq file Info-current-file))
3187 (or (assoc file Info-index-nodes)
3188 ;; Skip virtual Info files
3189 (and (or (not (stringp file))
3190 (Info-virtual-file-p file))
3191 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
3192 (if (Info-file-supports-index-cookies file)
3193 ;; Find nodes with index cookie
3194 (let* ((default-directory (or (and (stringp file)
3195 (file-name-directory
3196 (setq file (Info-find-file file))))
3197 default-directory))
3198 Info-history Info-history-list Info-fontify-maximum-menu-size
3199 (main-file file) subfiles nodes)
3200 (condition-case nil
3201 (with-temp-buffer
3202 (while (or main-file subfiles)
3203 (erase-buffer)
3204 (info-insert-file-contents (or main-file (car subfiles)))
3205 (goto-char (point-min))
3206 (while (search-forward "\0\b[index\0\b]" nil 'move)
3207 (save-excursion
3208 (re-search-backward "^\^_")
3209 (search-forward "Node: ")
3210 (setq nodes (cons (Info-following-node-name) nodes))))
3211 (if main-file
3212 (save-excursion
3213 (goto-char (point-min))
3214 (if (search-forward "\n\^_\nIndirect:" nil t)
3215 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
3216 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
3217 (setq subfiles (cons (match-string-no-properties 1)
3218 subfiles)))))
3219 (setq subfiles (nreverse subfiles)
3220 main-file nil))
3221 (setq subfiles (cdr subfiles)))))
3222 (error nil))
3223 (if nodes
3224 (setq nodes (nreverse nodes)
3225 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
3226 nodes)
3227 ;; Else find nodes with the word "Index" in the node name
3228 (let ((case-fold-search t)
3229 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
3230 nodes node)
3231 (condition-case nil
3232 (with-temp-buffer
3233 (Info-mode)
3234 (Info-find-node file "Top")
3235 (when (and (search-forward "\n* menu:" nil t)
3236 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
3237 (goto-char (match-beginning 1))
3238 (setq nodes (list (Info-extract-menu-node-name)))
3239 (Info-goto-node (car nodes))
3240 (while (and (setq node (Info-extract-pointer "next" t))
3241 (string-match "\\<Index\\>" node))
3242 (push node nodes)
3243 (Info-goto-node node))))
3244 (error nil))
3245 (if nodes
3246 (setq nodes (nreverse nodes)
3247 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
3248 nodes))
3249 ;; If file has no index nodes, still add it to the cache
3250 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
3251 (cdr (assoc file Info-index-nodes)))
3253 (defun Info-index-node (&optional node file)
3254 "Return non-nil value if NODE is an index node.
3255 If NODE is nil, check the current Info node.
3256 If FILE is nil, check the current Info file."
3257 (or file (setq file Info-current-file))
3258 (if (and (or (and node (not (equal node Info-current-node)))
3259 (assoc file Info-index-nodes))
3260 (not Info-current-node-virtual))
3261 (member (or node Info-current-node) (Info-index-nodes file))
3262 ;; Don't search all index nodes if request is only for the current node
3263 ;; and file is not in the cache of index nodes
3264 (save-match-data
3265 (if (Info-file-supports-index-cookies file)
3266 (save-excursion
3267 (goto-char (+ (or (save-excursion
3268 (search-backward "\n\^_" nil t))
3269 (point-min)) 2))
3270 (search-forward "\0\b[index\0\b]"
3271 (or (save-excursion
3272 (search-forward "\n\^_" nil t))
3273 (point-max)) t))
3274 (string-match "\\<Index\\>" (or node Info-current-node ""))))))
3276 (defun Info-goto-index ()
3277 "Go to the first index node."
3278 (let ((node (car (Info-index-nodes))))
3279 (or node (error "No index"))
3280 (Info-goto-node node)))
3282 ;;;###autoload
3283 (defun Info-index (topic)
3284 "Look up a string TOPIC in the index for this manual and go to that entry.
3285 If there are no exact matches to the specified topic, this chooses
3286 the first match which is a case-insensitive substring of a topic.
3287 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3288 Give an empty topic name to go to the Index node itself."
3289 (interactive
3290 (list
3291 (let ((completion-ignore-case t)
3292 (Info-complete-menu-buffer (clone-buffer))
3293 (Info-complete-nodes (Info-index-nodes))
3294 (Info-history-list nil))
3295 (if (equal Info-current-file "dir")
3296 (error "The Info directory node has no index; use m to select a manual"))
3297 (unwind-protect
3298 (with-current-buffer Info-complete-menu-buffer
3299 (Info-goto-index)
3300 (completing-read "Index topic: " 'Info-complete-menu-item))
3301 (kill-buffer Info-complete-menu-buffer)))))
3302 (if (equal Info-current-file "dir")
3303 (error "The Info directory node has no index; use m to select a manual"))
3304 ;; Strip leading colon in topic; index format does not allow them.
3305 (if (and (stringp topic)
3306 (> (length topic) 0)
3307 (= (aref topic 0) ?:))
3308 (setq topic (substring topic 1)))
3309 (let ((orignode Info-current-node)
3310 (pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3311 (regexp-quote topic)))
3312 node (nodes (Info-index-nodes))
3313 (ohist-list Info-history-list)
3314 (case-fold-search t))
3315 (Info-goto-index)
3316 (or (equal topic "")
3317 (let ((matches nil)
3318 (exact nil)
3319 ;; We bind Info-history to nil for internal node-switches so
3320 ;; that we don't put junk in the history. In the first
3321 ;; Info-goto-index call, above, we do update the history
3322 ;; because that is what the user's previous node choice into it.
3323 (Info-history nil)
3324 found)
3325 (while
3326 (progn
3327 (goto-char (point-min))
3328 (while (re-search-forward pattern nil t)
3329 (let ((entry (match-string-no-properties 1))
3330 (nodename (match-string-no-properties 3))
3331 (line (string-to-number (concat "0" (match-string 4)))))
3332 (add-text-properties
3333 (- (match-beginning 2) (match-beginning 1))
3334 (- (match-end 2) (match-beginning 1))
3335 '(face info-index-match) entry)
3336 (push (list entry nodename Info-current-node line) matches)))
3337 (setq nodes (cdr nodes) node (car nodes)))
3338 (Info-goto-node node))
3339 (or matches
3340 (progn
3341 (Info-goto-node orignode)
3342 (user-error "No `%s' in index" topic)))
3343 ;; Here it is a feature that assoc is case-sensitive.
3344 (while (setq found (assoc topic matches))
3345 (setq exact (cons found exact)
3346 matches (delq found matches)))
3347 (setq Info-history-list ohist-list)
3348 (setq Info-index-alternatives (nconc exact (nreverse matches)))
3349 (Info-index-next 0)))))
3351 (defun Info-index-next (num)
3352 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3353 (interactive "p")
3354 (or Info-index-alternatives
3355 (user-error "No previous `i' command"))
3356 (while (< num 0)
3357 (setq num (+ num (length Info-index-alternatives))))
3358 (while (> num 0)
3359 (setq Info-index-alternatives
3360 (nconc (cdr Info-index-alternatives)
3361 (list (car Info-index-alternatives)))
3362 num (1- num)))
3363 (Info-goto-node (nth 1 (car Info-index-alternatives)))
3364 (if (> (nth 3 (car Info-index-alternatives)) 0)
3365 ;; Forward 2 lines less because `Info-find-node-2' initially
3366 ;; puts point to the 2nd line.
3367 (forward-line (- (nth 3 (car Info-index-alternatives)) 2))
3368 (forward-line 3) ; don't search in headers
3369 (let ((name (car (car Info-index-alternatives))))
3370 (Info-find-index-name name)))
3371 (message "Found `%s' in %s. %s"
3372 (car (car Info-index-alternatives))
3373 (nth 2 (car Info-index-alternatives))
3374 (if (cdr Info-index-alternatives)
3375 (format-message
3376 "(%s total; use `%s' for next)"
3377 (length Info-index-alternatives)
3378 (key-description (where-is-internal
3379 'Info-index-next overriding-local-map t)))
3380 "(Only match)")))
3382 (defun Info-find-index-name (name)
3383 "Move point to the place within the current node where NAME is defined."
3384 (let ((case-fold-search t))
3385 (if (or (re-search-forward (format
3386 "[a-zA-Z]+: %s\\( \\|$\\)"
3387 (regexp-quote name)) nil t)
3388 ;; Find a function definition with a return type.
3389 (re-search-forward (format
3390 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3391 (regexp-quote name)) nil t)
3392 (search-forward (format "['`‘]%s['’]" name) nil t)
3393 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
3394 (search-forward
3395 (format "['`‘]%s['’]" (substring name 0 (match-beginning 1)))
3396 nil t))
3397 (search-forward name nil t)
3398 ;; Try again without the " <1>" makeinfo can append
3399 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
3400 (Info-find-index-name (match-string 1 name))))
3401 (progn (beginning-of-line) t) ;; non-nil for recursive call
3402 (goto-char (point-min)))))
3404 (add-to-list 'Info-virtual-nodes
3405 '("\\`\\*Index.*\\*\\'"
3406 (find-node . Info-virtual-index-find-node)
3407 (slow . t)
3410 (defvar Info-virtual-index-nodes nil
3411 "Alist of cached matched index search nodes.
3412 Each element is ((FILENAME . TOPIC) MATCHES) where
3413 FILENAME is the file name of the manual,
3414 TOPIC is the search string given as an argument to `Info-virtual-index',
3415 MATCHES is a list of index matches found by `Info-index'.")
3417 (defun Info-virtual-index-find-node (filename nodename &optional _no-going-back)
3418 "Index-specific implementation of `Info-find-node-2'."
3419 ;; Generate Index-like menu of matches
3420 (if (string-match "^\\*Index for ‘\\(.+\\)’\\*$" nodename)
3421 ;; Generate Index-like menu of matches
3422 (let* ((topic (match-string 1 nodename))
3423 (matches (cdr (assoc (cons (or filename Info-current-file) topic)
3424 Info-virtual-index-nodes))))
3425 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3426 (or filename Info-current-file) nodename))
3427 (insert "Info Virtual Index\n")
3428 (insert "******************\n\n")
3429 (insert "Index entries that match ‘" topic "’:\n\n")
3430 (insert "\0\b[index\0\b]\n")
3431 (if (null matches)
3432 (insert "No matches found.\n")
3433 (insert "* Menu:\n\n")
3434 (dolist (entry matches)
3435 (insert (format "* %-38s %s.%s\n"
3436 (format "%s [%s]:" (nth 0 entry) (nth 2 entry))
3437 (nth 1 entry)
3438 (if (nth 3 entry)
3439 (format " (line %s)" (nth 3 entry))
3440 ""))))))
3441 ;; Else, Generate a list of previous search results
3442 (let ((nodes (reverse Info-virtual-index-nodes)))
3443 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3444 (or filename Info-current-file) nodename))
3445 (insert "Info Virtual Index\n")
3446 (insert "******************\n\n")
3447 (insert "This is a list of search results produced by\n"
3448 "‘Info-virtual-index’ for the current manual.\n\n")
3449 (insert "* Menu:\n\n")
3450 (dolist (nodeinfo nodes)
3451 (when (equal (car (nth 0 nodeinfo)) (or filename Info-current-file))
3452 (insert
3453 (format "* %-20s %s.\n"
3454 (format "*Index for ‘%s’*::" (cdr (nth 0 nodeinfo)))
3455 (cdr (nth 0 nodeinfo)))))))))
3457 (defun Info-virtual-index (topic)
3458 "Show a node with all lines in the index containing a string TOPIC.
3459 Like `Info-index' but displays a node with index search results.
3460 Give an empty topic name to go to the node with links to previous
3461 search results."
3462 ;; `interactive' is a copy from `Info-index'
3463 (interactive
3464 (list
3465 (let ((completion-ignore-case t)
3466 (Info-complete-menu-buffer (clone-buffer))
3467 (Info-complete-nodes (Info-index-nodes))
3468 (Info-history-list nil))
3469 (if (equal Info-current-file "dir")
3470 (error "The Info directory node has no index; use m to select a manual"))
3471 (unwind-protect
3472 (with-current-buffer Info-complete-menu-buffer
3473 (Info-goto-index)
3474 (completing-read "Index topic: " 'Info-complete-menu-item))
3475 (kill-buffer Info-complete-menu-buffer)))))
3476 (if (equal topic "")
3477 (Info-find-node Info-current-file "*Index*")
3478 (unless (assoc (cons Info-current-file topic) Info-virtual-index-nodes)
3479 (let ((orignode Info-current-node)
3480 (ohist-list Info-history-list))
3481 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3482 (Info-index topic)
3483 (push (cons (cons Info-current-file topic) Info-index-alternatives)
3484 Info-virtual-index-nodes)
3485 ;; Clean up unnecessary side-effects of `Info-index'.
3486 (setq Info-history-list ohist-list)
3487 (Info-goto-node orignode)
3488 (message "")))
3489 (Info-find-node Info-current-file
3490 (format "*Index for ‘%s’*" topic))))
3492 (add-to-list 'Info-virtual-files
3493 '("\\`\\*Apropos\\*\\'"
3494 (toc-nodes . Info-apropos-toc-nodes)
3495 (find-file . Info-apropos-find-file)
3496 (find-node . Info-apropos-find-node)
3497 (slow . t)
3500 (defvar Info-apropos-file "*Apropos*"
3501 "Info file name of the virtual manual for matches of `info-apropos'.")
3503 (defvar Info-apropos-nodes nil
3504 "Alist of cached apropos matched nodes.
3505 Each element is (NODENAME STRING MATCHES) where
3506 NODENAME is the name of the node that holds the search result,
3507 STRING is the search string given as an argument to `info-apropos',
3508 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3510 (defun Info-apropos-toc-nodes (filename)
3511 "Apropos-specific implementation of `Info-toc-nodes'."
3512 (let ((nodes (mapcar #'car (reverse Info-apropos-nodes))))
3513 `(,filename
3514 ("Top" nil nil ,nodes)
3515 ,@(mapcar (lambda (node) `(,node "Top" nil nil)) nodes))))
3517 (defun Info-apropos-find-file (filename &optional _noerror)
3518 "Apropos-specific implementation of `Info-find-file'."
3519 filename)
3521 (defun Info-apropos-find-node (_filename nodename &optional _no-going-back)
3522 "Apropos-specific implementation of `Info-find-node-2'."
3523 (if (equal nodename "Top")
3524 ;; Generate Top menu
3525 (let ((nodes (reverse Info-apropos-nodes)))
3526 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3527 Info-apropos-file nodename))
3528 (insert "Apropos Index\n")
3529 (insert "*************\n\n")
3530 (insert "This is a list of search results produced by ‘info-apropos’.\n\n")
3531 (insert "* Menu:\n\n")
3532 (dolist (nodeinfo nodes)
3533 (insert (format "* %-20s %s.\n"
3534 (format "%s::" (nth 0 nodeinfo))
3535 (nth 1 nodeinfo)))))
3536 ;; Else, Generate Index-like menu of matches
3537 (let* ((nodeinfo (assoc nodename Info-apropos-nodes))
3538 (matches (nth 2 nodeinfo)))
3539 (when matches
3540 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3541 Info-apropos-file nodename))
3542 (insert "Apropos Index\n")
3543 (insert "*************\n\n")
3544 (insert "Index entries that match ‘" (nth 1 nodeinfo) "’:\n\n")
3545 (insert "\0\b[index\0\b]\n")
3546 (if (eq matches t)
3547 (insert "No matches found.\n")
3548 (insert "* Menu:\n\n")
3549 (dolist (entry matches)
3550 (insert (format "* %-38s (%s)%s.%s\n"
3551 (format "%s [%s]:" (nth 1 entry) (nth 0 entry))
3552 (nth 0 entry)
3553 (nth 2 entry)
3554 (if (nth 3 entry)
3555 (format " (line %s)" (nth 3 entry))
3556 "")))))))))
3558 (defun Info-apropos-matches (string)
3559 "Collect STRING matches from all known Info files on your system.
3560 Return a list of matches where each element is in the format
3561 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3562 (unless (string= string "")
3563 (let ((pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3564 (regexp-quote string)))
3565 (ohist Info-history)
3566 (ohist-list Info-history-list)
3567 (current-node Info-current-node)
3568 (current-file Info-current-file)
3569 manuals matches node nodes)
3570 (let ((Info-fontify-maximum-menu-size nil))
3571 (Info-directory)
3572 ;; current-node and current-file are nil when they invoke info-apropos
3573 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3574 ;; case, we use (DIR)Top instead, to avoid signaling an error after
3575 ;; the search is complete.
3576 (when (null current-node)
3577 (setq current-file Info-current-file)
3578 (setq current-node Info-current-node))
3579 (message "Searching indices...")
3580 (goto-char (point-min))
3581 (re-search-forward "\\* Menu: *\n" nil t)
3582 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
3583 ;; Make sure we don't have duplicates in `manuals',
3584 ;; so that the following dolist loop runs faster.
3585 (cl-pushnew (match-string 1) manuals :test #'equal))
3586 (dolist (manual (nreverse manuals))
3587 (message "Searching %s" manual)
3588 (condition-case err
3589 (if (setq nodes (Info-index-nodes (Info-find-file manual)))
3590 (save-excursion
3591 (Info-find-node manual (car nodes))
3592 (while
3593 (progn
3594 (goto-char (point-min))
3595 (while (re-search-forward pattern nil t)
3596 (let ((entry (match-string-no-properties 1))
3597 (nodename (match-string-no-properties 3))
3598 (line (match-string-no-properties 4)))
3599 (add-text-properties
3600 (- (match-beginning 2) (match-beginning 1))
3601 (- (match-end 2) (match-beginning 1))
3602 '(face info-index-match) entry)
3603 (setq matches (cons (list manual entry nodename line)
3604 matches))))
3605 (setq nodes (cdr nodes) node (car nodes)))
3606 (Info-goto-node node))))
3607 (error
3608 (message "%s" (if (eq (car-safe err) 'error)
3609 (nth 1 err) err))
3610 (sit-for 1 t)))))
3611 (Info-find-node current-file current-node)
3612 (setq Info-history ohist
3613 Info-history-list ohist-list)
3614 (message "Searching indices...done")
3615 (or (nreverse matches) t))))
3617 ;;;###autoload
3618 (defun info-apropos (string)
3619 "Grovel indices of all known Info files on your system for STRING.
3620 Build a menu of the possible matches."
3621 (interactive "sIndex apropos: ")
3622 (if (equal string "")
3623 (Info-find-node Info-apropos-file "Top")
3624 (let* ((nodes Info-apropos-nodes) nodename)
3625 (while (and nodes (not (equal string (nth 1 (car nodes)))))
3626 (setq nodes (cdr nodes)))
3627 (if nodes
3628 (Info-find-node Info-apropos-file (car (car nodes)))
3629 (setq nodename (format "Index for ‘%s’" string))
3630 (push (list nodename string (Info-apropos-matches string))
3631 Info-apropos-nodes)
3632 (Info-find-node Info-apropos-file nodename)))))
3634 (add-to-list 'Info-virtual-files
3635 '("\\`\\*Finder.*\\*\\'"
3636 (find-file . Info-finder-find-file)
3637 (find-node . Info-finder-find-node)
3640 (defvar Info-finder-file "*Finder*"
3641 "Info file name of the virtual Info keyword finder manual.")
3643 (defun Info-finder-find-file (filename &optional _noerror)
3644 "Finder-specific implementation of `Info-find-file'."
3645 filename)
3647 (defvar finder-known-keywords)
3648 (declare-function find-library-name "find-func" (library))
3649 (declare-function finder-unknown-keywords "finder" ())
3650 (declare-function lm-commentary "lisp-mnt" (&optional file))
3651 (defvar finder-keywords-hash)
3652 (defvar package--builtins) ; finder requires package
3654 (defun info--prettify-description (desc)
3655 (if (stringp desc)
3656 (with-temp-buffer
3657 (insert (substitute-command-keys desc))
3658 (if (equal ?. (char-before))
3659 (delete-char -1))
3660 (goto-char (point-min))
3661 (or (let (case-fold-search) (looking-at-p "\\.\\|[[:upper:]]"))
3662 (capitalize-word 1))
3663 (buffer-string))
3664 desc))
3666 (defun Info-finder-find-node (_filename nodename &optional _no-going-back)
3667 "Finder-specific implementation of `Info-find-node-2'."
3668 (require 'finder)
3669 (cond
3670 ((equal nodename "Top")
3671 ;; Display Top menu with descriptions of the keywords
3672 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3673 Info-finder-file nodename))
3674 (insert "Finder Keywords\n")
3675 (insert "***************\n\n")
3676 (insert "* Menu:\n\n")
3677 (dolist (assoc (append '((all . "All package info")
3678 (unknown . "Unknown keywords"))
3679 finder-known-keywords))
3680 (let ((keyword (car assoc)))
3681 (insert (format "* %s %s.\n"
3682 (concat (symbol-name keyword) ": "
3683 "Keyword " (symbol-name keyword) ".")
3684 (info--prettify-description (cdr assoc)))))))
3685 ((equal nodename "Keyword unknown")
3686 ;; Display unknown keywords
3687 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3688 Info-finder-file nodename))
3689 (insert "Finder Unknown Keywords\n")
3690 (insert "***********************\n\n")
3691 (insert "* Menu:\n\n")
3692 (mapc
3693 (lambda (assoc)
3694 (insert (format "* %-14s %s.\n"
3695 (concat (symbol-name (car assoc)) ": "
3696 "Keyword " (symbol-name (car assoc)) ".")
3697 (cdr assoc))))
3698 (finder-unknown-keywords)))
3699 ((equal nodename "Keyword all")
3700 ;; Display all package info.
3701 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3702 Info-finder-file nodename))
3703 (insert "Finder Package Info\n")
3704 (insert "*******************\n\n")
3705 (insert "* Menu:\n\n")
3706 (let (desc)
3707 (dolist (package package--builtins)
3708 (setq desc (cdr-safe package))
3709 (when (vectorp desc)
3710 (insert (format "* %-16s %s.\n"
3711 (concat (symbol-name (car package)) "::")
3712 (info--prettify-description (aref desc 2))))))))
3713 ((string-match "\\`Keyword " nodename)
3714 (setq nodename (substring nodename (match-end 0)))
3715 ;; Display packages that match the keyword
3716 ;; or the list of keywords separated by comma.
3717 (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
3718 Info-finder-file nodename))
3719 (insert "Finder Packages\n")
3720 (insert "***************\n\n")
3721 (insert
3722 "The following packages match the keyword ‘" nodename "’:\n\n")
3723 (insert "* Menu:\n\n")
3724 (let ((keywords
3725 (mapcar #'intern (if (string-match-p "," nodename)
3726 (split-string nodename ",[ \t\n]*" t)
3727 (list nodename))))
3728 hits desc)
3729 (dolist (keyword keywords)
3730 (push (copy-tree (gethash keyword finder-keywords-hash)) hits))
3731 (setq hits (delete-dups (apply #'append hits))
3732 ;; Not a meaningful package.
3733 hits (delete 'emacs hits)
3734 hits (sort hits (lambda (a b) (string< (symbol-name a)
3735 (symbol-name b)))))
3736 (dolist (package hits)
3737 (setq desc (cdr-safe (assq package package--builtins)))
3738 (when (vectorp desc)
3739 (insert (format "* %-16s %s.\n"
3740 (concat (symbol-name package) "::")
3741 (info--prettify-description (aref desc 2))))))))
3743 ;; Display commentary section
3744 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3745 Info-finder-file nodename))
3746 (insert "Package Description\n")
3747 (insert "*******************\n\n")
3748 (insert
3749 "Description of the package ‘" nodename "’:\n\n")
3750 ;; This assumes that a file named package.el exists,
3751 ;; which is not always true. E.g. for the nxml package,
3752 ;; there is no "nxml.el" (it's nxml-mode.el).
3753 ;; But package.el makes the same assumption.
3754 ;; I think nxml is the only exception - maybe it should be just be renamed.
3755 (let ((str (ignore-errors (lm-commentary (find-library-name nodename)))))
3756 (if (null str)
3757 (insert "Can’t find package description.\n\n")
3758 (insert
3759 (with-temp-buffer
3760 (insert str)
3761 (goto-char (point-min))
3762 (delete-blank-lines)
3763 (goto-char (point-max))
3764 (delete-blank-lines)
3765 (goto-char (point-min))
3766 (while (re-search-forward "^;+ ?" nil t)
3767 (replace-match "" nil nil))
3768 (buffer-string))))))))
3770 ;;;###autoload
3771 (defun info-finder (&optional keywords)
3772 "Display descriptions of the keywords in the Finder virtual manual.
3773 In interactive use, a prefix argument directs this command to read
3774 a list of keywords separated by comma. After that, it displays a node
3775 with a list of packages that contain all specified keywords."
3776 (interactive
3777 (when current-prefix-arg
3778 (require 'finder)
3779 (list
3780 (completing-read-multiple
3781 "Keywords (separated by comma): "
3782 (mapcar #'symbol-name (mapcar #'car (append finder-known-keywords
3783 (finder-unknown-keywords))))
3784 nil t))))
3785 (require 'finder)
3786 (if keywords
3787 (Info-find-node Info-finder-file (mapconcat 'identity keywords ", "))
3788 (Info-find-node Info-finder-file "Top")))
3791 (defun Info-undefined ()
3792 "Make command be undefined in Info."
3793 (interactive)
3794 (ding))
3796 (defun Info-help ()
3797 "Enter the Info tutorial."
3798 (interactive)
3799 (delete-other-windows)
3800 (Info-find-node "info"
3801 (if (< (window-height) 23)
3802 "Help-Small-Screen"
3803 "Help")))
3805 (defun Info-summary ()
3806 "Display a brief summary of all Info commands."
3807 (interactive)
3808 (save-window-excursion
3809 (switch-to-buffer "*Help*")
3810 (setq buffer-read-only nil)
3811 (erase-buffer)
3812 (insert (documentation 'Info-mode))
3813 (help-mode)
3814 (goto-char (point-min))
3815 (let (ch flag)
3816 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
3817 (message (if flag "Type Space to see more"
3818 "Type Space to return to Info"))
3819 (if (not (eq ?\s (setq ch (read-event))))
3820 (progn (push ch unread-command-events) nil)
3821 flag))
3822 (scroll-up)))
3823 (bury-buffer "*Help*")))
3825 (defun Info-get-token (pos start all &optional errorstring)
3826 "Return the token around POS.
3827 POS must be somewhere inside the token.
3828 START is a regular expression which will match the
3829 beginning of the tokens delimited string.
3830 ALL is a regular expression with a single
3831 parenthesized subpattern which is the token to be
3832 returned. E.g. `{(.*)}' would return any string
3833 enclosed in braces around POS.
3834 ERRORSTRING optional fourth argument, controls action on no match:
3835 nil: return nil
3836 t: beep
3837 a string: signal an error, using that string."
3838 (let ((case-fold-search t))
3839 (save-excursion
3840 (goto-char pos)
3841 ;; First look for a match for START that goes across POS.
3842 (while (and (not (bobp)) (> (point) (- pos (length start)))
3843 (not (looking-at start)))
3844 (forward-char -1))
3845 ;; If we did not find one, search back for START
3846 ;; (this finds only matches that end at or before POS).
3847 (or (looking-at start)
3848 (progn
3849 (goto-char pos)
3850 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
3851 (let (found)
3852 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
3853 (not (setq found (and (<= (match-beginning 0) pos)
3854 (> (match-end 0) pos))))))
3855 (if (and found (<= (match-beginning 0) pos)
3856 (> (match-end 0) pos))
3857 (match-string-no-properties 1)
3858 (cond ((null errorstring)
3859 nil)
3860 ((eq errorstring t)
3861 (beep)
3862 nil)
3864 (error "No %s around position %d" errorstring pos))))))))
3866 (defun Info-mouse-follow-nearest-node (click)
3867 "\\<Info-mode-map>Follow a node reference near point.
3868 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3869 At end of the node's text, moves to the next node, or up if none."
3870 (interactive "e")
3871 (mouse-set-point click)
3872 (and (not (Info-follow-nearest-node))
3873 (save-excursion (forward-line 1) (eobp))
3874 (Info-next-preorder)))
3876 (defun Info-follow-nearest-node (&optional fork)
3877 "Follow a node reference near point.
3878 If point is on a reference, follow that reference. Otherwise,
3879 if point is in a menu item description, follow that menu item.
3881 If FORK is non-nil (interactively with a prefix arg), show the node in
3882 a new Info buffer.
3883 If FORK is a string, it is the name to use for the new buffer."
3884 (interactive "P")
3885 (or (Info-try-follow-nearest-node fork)
3886 (when (save-excursion
3887 (search-backward "\n* menu:" nil t))
3888 (save-excursion
3889 (beginning-of-line)
3890 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3891 (beginning-of-line 0))
3892 (when (looking-at "\\* +\\([^\t\n]*\\):")
3893 (Info-goto-node
3894 (Info-extract-menu-item (match-string-no-properties 1)) fork)
3895 t)))
3896 (and (eq this-command 'Info-mouse-follow-nearest-node)
3897 ;; Don't raise an error when mouse-1 is bound to this - it's
3898 ;; often used to simply select the window or frame.
3899 (eq 'mouse-1 (event-basic-type last-input-event)))
3900 (user-error "Point neither on reference nor in menu item description")))
3902 ;; Common subroutine.
3903 (defun Info-try-follow-nearest-node (&optional fork)
3904 "Follow a node reference near point. Return non-nil if successful.
3905 If FORK is non-nil, it is passed to `Info-goto-node'."
3906 (let (node)
3907 (cond
3908 ((setq node (Info-get-token (point) "[hf]t?tps?://"
3909 "\\([hf]t?tps?://[^ \t\n\"`‘({<>})’']+\\)"))
3910 (browse-url node)
3911 (setq node t))
3912 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
3913 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3914 (Info-follow-reference node fork))
3915 ;; footnote
3916 ((setq node (Info-get-token (point) "(" "\\(([0-9]+)\\)"))
3917 (let ((old-point (point)) new-point)
3918 (save-excursion
3919 (goto-char (point-min))
3920 (when (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t)
3921 (setq new-point (if (< old-point (point))
3922 ;; Go to footnote reference
3923 (and (search-forward node nil t)
3924 ;; Put point at beginning of link
3925 (match-beginning 0))
3926 ;; Go to footnote definition
3927 (search-backward node nil t)))))
3928 (if new-point
3929 (progn
3930 (goto-char new-point)
3931 (setq node t))
3932 (setq node nil))))
3933 ;; menu item: node name
3934 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3935 (Info-goto-node node fork))
3936 ;; menu item: node name or index entry
3937 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3938 (beginning-of-line)
3939 (forward-char 2)
3940 (setq node (Info-extract-menu-node-name nil (Info-index-node)))
3941 (Info-goto-node node fork))
3942 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3943 (Info-goto-node node fork))
3944 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3945 (Info-goto-node node fork))
3946 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3947 (Info-goto-node "Top" fork))
3948 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3949 (Info-goto-node node fork)))
3950 node))
3952 (defun Info-mouse-follow-link (click)
3953 "Follow a link where you click."
3954 (interactive "@e")
3955 (let* ((position (event-start click))
3956 (posn-string (and position (posn-string position)))
3957 (link-args (if posn-string
3958 (get-text-property (cdr posn-string)
3959 'link-args
3960 (car posn-string))
3961 (get-char-property (posn-point position)
3962 'link-args))))
3963 (cond ((stringp link-args)
3964 (Info-goto-node link-args))
3965 ;; These special values of the `link-args' property are used
3966 ;; for navigation; see `Info-fontify-node'.
3967 ((eq link-args 'prev) (Info-prev))
3968 ((eq link-args 'next) (Info-next))
3969 ((eq link-args 'up) (Info-up)))))
3972 (defvar Info-mode-map
3973 (let ((map (make-keymap)))
3974 (suppress-keymap map)
3975 (define-key map "." 'beginning-of-buffer)
3976 (define-key map " " 'Info-scroll-up)
3977 (define-key map [?\S-\ ] 'Info-scroll-down)
3978 (define-key map "\C-m" 'Info-follow-nearest-node)
3979 (define-key map "\t" 'Info-next-reference)
3980 (define-key map "\e\t" 'Info-prev-reference)
3981 (define-key map [backtab] 'Info-prev-reference)
3982 (define-key map "1" 'Info-nth-menu-item)
3983 (define-key map "2" 'Info-nth-menu-item)
3984 (define-key map "3" 'Info-nth-menu-item)
3985 (define-key map "4" 'Info-nth-menu-item)
3986 (define-key map "5" 'Info-nth-menu-item)
3987 (define-key map "6" 'Info-nth-menu-item)
3988 (define-key map "7" 'Info-nth-menu-item)
3989 (define-key map "8" 'Info-nth-menu-item)
3990 (define-key map "9" 'Info-nth-menu-item)
3991 (define-key map "0" 'undefined)
3992 (define-key map "?" 'Info-summary)
3993 (define-key map "]" 'Info-forward-node)
3994 (define-key map "[" 'Info-backward-node)
3995 (define-key map "<" 'Info-top-node)
3996 (define-key map ">" 'Info-final-node)
3997 (define-key map "b" 'beginning-of-buffer)
3998 (put 'beginning-of-buffer :advertised-binding "b")
3999 (define-key map "d" 'Info-directory)
4000 (define-key map "e" 'end-of-buffer)
4001 (define-key map "f" 'Info-follow-reference)
4002 (define-key map "g" 'Info-goto-node)
4003 (define-key map "h" 'Info-help)
4004 ;; This is for compatibility with standalone info (>~ version 5.2).
4005 ;; Though for some time, standalone info had H and h reversed.
4006 ;; See <http://debbugs.gnu.org/16455>.
4007 (define-key map "H" 'describe-mode)
4008 (define-key map "i" 'Info-index)
4009 (define-key map "I" 'Info-virtual-index)
4010 (define-key map "l" 'Info-history-back)
4011 (define-key map "L" 'Info-history)
4012 (define-key map "m" 'Info-menu)
4013 (define-key map "n" 'Info-next)
4014 (define-key map "p" 'Info-prev)
4015 (define-key map "q" 'Info-exit)
4016 (define-key map "r" 'Info-history-forward)
4017 (define-key map "s" 'Info-search)
4018 (define-key map "S" 'Info-search-case-sensitively)
4019 (define-key map "\M-n" 'clone-buffer)
4020 (define-key map "t" 'Info-top-node)
4021 (define-key map "T" 'Info-toc)
4022 (define-key map "u" 'Info-up)
4023 ;; `w' for consistency with `dired-copy-filename-as-kill'.
4024 (define-key map "w" 'Info-copy-current-node-name)
4025 (define-key map "c" 'Info-copy-current-node-name)
4026 ;; `^' for consistency with `dired-up-directory'.
4027 (define-key map "^" 'Info-up)
4028 (define-key map "," 'Info-index-next)
4029 (define-key map "\177" 'Info-scroll-down)
4030 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
4031 (define-key map [follow-link] 'mouse-face)
4032 (define-key map [XF86Back] 'Info-history-back)
4033 (define-key map [XF86Forward] 'Info-history-forward)
4034 map)
4035 "Keymap containing Info commands.")
4038 (defun Info-check-pointer (item)
4039 "Non-nil if ITEM is present in this node."
4040 (condition-case nil
4041 (Info-extract-pointer item)
4042 (error nil)))
4044 (easy-menu-define
4045 Info-mode-menu Info-mode-map
4046 "Menu for Info files."
4047 '("Info"
4048 ["Up" Info-up :active (Info-check-pointer "up")
4049 :help "Go up in the Info tree"]
4050 ["Next" Info-next :active (Info-check-pointer "next")
4051 :help "Go to the next node"]
4052 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
4053 :help "Go to the previous node"]
4054 ["Backward" Info-backward-node
4055 :help "Go backward one node, considering all as a sequence"]
4056 ["Forward" Info-forward-node
4057 :help "Go forward one node, considering all as a sequence"]
4058 ["Beginning" beginning-of-buffer
4059 :help "Go to beginning of this node"]
4060 ["Top" Info-top-node
4061 :help "Go to top node of file"]
4062 ["Final Node" Info-final-node
4063 :help "Go to final node in this file"]
4064 ("Menu Item" ["You should never see this" report-emacs-bug t])
4065 ("Reference" ["You should never see this" report-emacs-bug t])
4066 ["Search..." Info-search
4067 :help "Search for regular expression in this Info file"]
4068 ["Search Next" Info-search-next
4069 :help "Search for another occurrence of regular expression"]
4070 ["Go to Node..." Info-goto-node
4071 :help "Go to a named node"]
4072 ["Back in history" Info-history-back :active Info-history
4073 :help "Go back in history to the last node you were at"]
4074 ["Forward in history" Info-history-forward :active Info-history-forward
4075 :help "Go forward in history"]
4076 ["History" Info-history :active Info-history-list
4077 :help "Go to menu of visited nodes"]
4078 ["Table of Contents" Info-toc
4079 :help "Go to table of contents"]
4080 ("Index"
4081 ["Lookup a String..." Info-index
4082 :help "Look for a string in the index items"]
4083 ["Next Matching Item" Info-index-next :active Info-index-alternatives
4084 :help "Look for another occurrence of previous item"]
4085 ["Lookup a string and display index of results..." Info-virtual-index
4086 :help "Look for a string in the index items and display node with results"]
4087 ["Lookup a string in all indices..." info-apropos
4088 :help "Look for a string in the indices of all manuals"])
4089 ["Copy Node Name" Info-copy-current-node-name
4090 :help "Copy the name of the current node into the kill ring"]
4091 ["Clone Info buffer" clone-buffer
4092 :help "Create a twin copy of the current Info buffer."]
4093 ["Exit" Info-exit :help "Stop reading Info"]))
4096 (defvar info-tool-bar-map
4097 (let ((map (make-sparse-keymap)))
4098 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
4099 :rtl "right-arrow"
4100 :label "Back"
4101 :vert-only t)
4102 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
4103 :rtl "left-arrow"
4104 :label "Forward"
4105 :vert-only t)
4106 (define-key-after map [separator-1] menu-bar-separator)
4107 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
4108 :rtl "next-node")
4109 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
4110 :rtl "prev-node")
4111 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
4112 :vert-only t)
4113 (define-key-after map [separator-2] menu-bar-separator)
4114 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
4115 :vert-only t)
4116 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
4117 (define-key-after map [separator-3] menu-bar-separator)
4118 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
4119 :label "Index")
4120 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
4121 :vert-only t)
4122 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
4123 :vert-only t)
4124 map))
4126 (defvar Info-menu-last-node nil)
4127 ;; Last node the menu was created for.
4128 ;; Value is a list, (FILE-NAME NODE-NAME).
4130 (defun Info-menu-update ()
4131 "Update the Info menu for the current node."
4132 (condition-case nil
4133 (if (or (not (derived-mode-p 'Info-mode))
4134 (equal (list Info-current-file Info-current-node)
4135 Info-menu-last-node))
4137 ;; Update menu menu.
4138 (let* ((Info-complete-menu-buffer (current-buffer))
4139 (items (nreverse (condition-case nil
4140 (Info-complete-menu-item "" nil t)
4141 (error nil))))
4142 entries current
4143 (number 0))
4144 (while (and items (< number 9))
4145 (setq current (car items)
4146 items (cdr items)
4147 number (1+ number))
4148 (setq entries (cons `[,current
4149 (Info-menu ,current)
4150 :keys ,(format "%d" number)]
4151 entries)))
4152 (if items
4153 (setq entries (cons ["Other..." Info-menu t] entries)))
4154 (or entries
4155 (setq entries (list ["No menu" nil nil] nil :active)))
4156 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
4157 ;; Update reference menu. Code stolen from `Info-follow-reference'.
4158 (let ((items nil)
4159 str i entries current
4160 (number 0)
4161 (case-fold-search t))
4162 (save-excursion
4163 (goto-char (point-min))
4164 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
4165 (setq str (match-string 1))
4166 (setq i 0)
4167 (while (setq i (string-match "[ \n\t]+" str i))
4168 (setq str (concat (substring str 0 i) " "
4169 (substring str (match-end 0))))
4170 (setq i (1+ i)))
4171 (setq items
4172 (cons str items))))
4173 (while (and items (< number 9))
4174 (setq current (car items)
4175 items (cdr items)
4176 number (1+ number))
4177 (setq entries (cons `[,current
4178 (Info-follow-reference ,current)
4180 entries)))
4181 (if items
4182 (setq entries (cons ["Other..." Info-follow-reference t]
4183 entries)))
4184 (or entries
4185 (setq entries (list ["No references" nil nil] nil :active)))
4186 (easy-menu-change '("Info") "Reference" (nreverse entries)))
4187 ;; Update last seen node.
4188 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
4189 ;; Try to avoid entering infinite beep mode in case of errors.
4190 (error (ding))))
4193 (defun Info-copy-current-node-name (&optional arg)
4194 "Put the name of the current Info node into the kill ring.
4195 The name of the Info file is prepended to the node name in parentheses.
4196 With a zero prefix arg, put the name inside a function call to `info'."
4197 (interactive "P")
4198 (unless Info-current-node
4199 (user-error "No current Info node"))
4200 (let ((node (if (stringp Info-current-file)
4201 (concat "(" (file-name-sans-extension
4202 (file-name-nondirectory Info-current-file))
4203 ") "
4204 Info-current-node))))
4205 (if (zerop (prefix-numeric-value arg))
4206 (setq node (concat "(info \"" node "\")")))
4207 (unless (stringp Info-current-file)
4208 (setq node (format "(Info-find-node '%S '%S)"
4209 Info-current-file Info-current-node)))
4210 (kill-new node)
4211 (message "%s" node)))
4214 ;; Info mode is suitable only for specially formatted data.
4215 (put 'Info-mode 'mode-class 'special)
4216 (put 'Info-mode 'no-clone-indirect t)
4218 (defvar tool-bar-map)
4219 (defvar bookmark-make-record-function)
4221 (defvar Info-mode-syntax-table
4222 (let ((st (copy-syntax-table text-mode-syntax-table)))
4223 ;; Use punctuation syntax for apostrophe because of
4224 ;; extensive use of quotes like `this' in Info manuals.
4225 (modify-syntax-entry ?' "." st)
4227 "Syntax table used in `Info-mode'.")
4229 (defface Info-quoted
4230 '((t :inherit fixed-pitch-serif))
4231 "Face used for quoted elements.")
4233 (defvar Info-mode-font-lock-keywords
4234 '(("‘\\([^’]*\\)’" (1 'Info-quoted))))
4236 ;; Autoload cookie needed by desktop.el
4237 ;;;###autoload
4238 (define-derived-mode Info-mode nil "Info" ;FIXME: Derive from special-mode?
4239 "Info mode provides commands for browsing through the Info documentation tree.
4240 Documentation in Info is divided into \"nodes\", each of which discusses
4241 one topic and contains references to other nodes which discuss related
4242 topics. Info has commands to follow the references and show you other nodes.
4244 \\<Info-mode-map>\
4245 \\[Info-help] Invoke the Info tutorial.
4246 \\[Info-exit] Quit Info: reselect previously selected buffer.
4248 Selecting other nodes:
4249 \\[Info-mouse-follow-nearest-node]
4250 Follow a node reference you click on.
4251 This works with menu items, cross references, and
4252 the \"next\", \"previous\" and \"up\", depending on where you click.
4253 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
4254 \\[Info-next] Move to the \"next\" node of this node.
4255 \\[Info-prev] Move to the \"previous\" node of this node.
4256 \\[Info-up] Move \"up\" from this node.
4257 \\[Info-menu] Pick menu item specified by name (or abbreviation).
4258 Picking a menu item causes another node to be selected.
4259 \\[Info-directory] Go to the Info directory node.
4260 \\[Info-top-node] Go to the Top node of this file.
4261 \\[Info-final-node] Go to the final node in this file.
4262 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
4263 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
4264 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
4265 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
4266 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
4267 \\[Info-history-back] Move back in history to the last node you were at.
4268 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
4269 \\[Info-history] Go to menu of visited nodes.
4270 \\[Info-toc] Go to table of contents of the current Info file.
4272 Moving within a node:
4273 \\[Info-scroll-up] Normally, scroll forward a full screen.
4274 Once you scroll far enough in a node that its menu appears on the
4275 screen but after point, the next scroll moves into its first
4276 subnode. When after all menu items (or if there is no menu),
4277 move up to the parent node.
4278 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
4279 already visible, try to go to the previous menu entry, or up
4280 if there is none.
4281 \\[beginning-of-buffer] Go to beginning of node.
4283 Advanced commands:
4284 \\[Info-search] Search through this Info file for specified regexp,
4285 and select the node in which the next occurrence is found.
4286 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
4287 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
4288 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
4289 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
4290 \\[Info-virtual-index] Look for a string and display the index node with results.
4291 \\[info-apropos] Look for a string in the indices of all manuals.
4292 \\[Info-goto-node] Move to node specified by name.
4293 You may include a filename as well, as (FILENAME)NODENAME.
4294 1 .. 9 Pick first ... ninth item in node's menu.
4295 Every third `*' is highlighted to help pick the right number.
4296 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
4297 \\[clone-buffer] Select a new cloned Info buffer in another window.
4298 \\[universal-argument] \\[info] Move to new Info file with completion.
4299 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
4300 :syntax-table Info-mode-syntax-table
4301 :abbrev-table text-mode-abbrev-table
4302 (setq tab-width 8)
4303 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
4304 (setq case-fold-search t)
4305 (setq buffer-read-only t)
4306 (setq Info-tag-table-marker (make-marker))
4307 (if Info-use-header-line ; do not override global header lines
4308 (setq header-line-format
4309 '(:eval (get-text-property (point-min) 'header-line))))
4310 (setq-local tool-bar-map info-tool-bar-map)
4311 ;; This is for the sake of the invisible text we use handling titles.
4312 (setq-local line-move-ignore-invisible t)
4313 (setq-local desktop-save-buffer 'Info-desktop-buffer-misc-data)
4314 (setq-local widen-automatically nil)
4315 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
4316 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
4317 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
4318 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
4319 (setq-local isearch-search-fun-function #'Info-isearch-search)
4320 (setq-local isearch-wrap-function #'Info-isearch-wrap)
4321 (setq-local isearch-push-state-function #'Info-isearch-push-state)
4322 (setq-local isearch-filter-predicate #'Info-isearch-filter)
4323 (setq-local revert-buffer-function #'Info-revert-buffer-function)
4324 (setq-local font-lock-defaults '(Info-mode-font-lock-keywords t t))
4325 (Info-set-mode-line)
4326 (setq-local bookmark-make-record-function #'Info-bookmark-make-record))
4328 ;; When an Info buffer is killed, make sure the associated tags buffer
4329 ;; is killed too.
4330 (defun Info-kill-buffer ()
4331 (and (derived-mode-p 'Info-mode)
4332 Info-tag-table-buffer
4333 (kill-buffer Info-tag-table-buffer)))
4335 ;; Placed on `clone-buffer-hook'.
4336 (defun Info-clone-buffer ()
4337 (when (bufferp Info-tag-table-buffer)
4338 (setq Info-tag-table-buffer
4339 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4340 (let ((m Info-tag-table-marker))
4341 (when (markerp m)
4342 (setq Info-tag-table-marker
4343 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4344 (with-current-buffer Info-tag-table-buffer
4345 (copy-marker (marker-position m)))
4346 (make-marker))))))
4348 (define-obsolete-variable-alias 'Info-edit-map 'Info-edit-mode-map "24.1")
4349 (defvar Info-edit-mode-map (let ((map (make-sparse-keymap)))
4350 (set-keymap-parent map text-mode-map)
4351 (define-key map "\C-c\C-c" 'Info-cease-edit)
4352 map)
4353 "Local keymap used within `e' command of Info.")
4355 (make-obsolete-variable 'Info-edit-mode-map
4356 "editing Info nodes by hand is not recommended."
4357 "24.4")
4359 ;; Info-edit mode is suitable only for specially formatted data.
4360 (put 'Info-edit-mode 'mode-class 'special)
4362 (define-derived-mode Info-edit-mode text-mode "Info Edit"
4363 "Major mode for editing the contents of an Info node.
4364 Like text mode with the addition of `Info-cease-edit'
4365 which returns to Info mode for browsing."
4366 (setq buffer-read-only nil)
4367 (force-mode-line-update)
4368 (buffer-enable-undo (current-buffer)))
4370 (make-obsolete 'Info-edit-mode
4371 "editing Info nodes by hand is not recommended." "24.4")
4373 (defun Info-edit ()
4374 "Edit the contents of this Info node."
4375 (interactive)
4376 (Info-edit-mode)
4377 (message "%s" (substitute-command-keys
4378 "Editing: Type \\<Info-edit-mode-map>\\[Info-cease-edit] to return to info")))
4380 (put 'Info-edit 'disabled "Editing Info nodes by hand is not recommended.
4381 This feature will be removed in future.")
4383 (make-obsolete 'Info-edit
4384 "editing Info nodes by hand is not recommended." "24.4")
4386 (defun Info-cease-edit ()
4387 "Finish editing Info node; switch back to Info proper."
4388 (interactive)
4389 ;; Do this first, so nothing has changed if user C-g's at query.
4390 (and (buffer-modified-p)
4391 (y-or-n-p "Save the file? ")
4392 (save-buffer))
4393 (Info-mode)
4394 (force-mode-line-update)
4395 (and (marker-position Info-tag-table-marker)
4396 (buffer-modified-p)
4397 (message "Tags may have changed. Use Info-tagify if necessary")))
4399 (make-obsolete 'Info-cease-edit
4400 "editing Info nodes by hand is not recommended." "24.4")
4402 (defvar Info-file-list-for-emacs
4403 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4404 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4405 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4406 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4407 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4408 ("copyright" . "autotype") ("executable" . "autotype")
4409 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4410 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4411 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4412 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4413 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4414 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4415 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4416 ("rfc2045" . "emacs-mime")
4417 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4418 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4419 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4420 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4421 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4422 ("mml" . "emacs-mime")
4423 "tramp" "dbus")
4424 "List of Info files that describe Emacs commands.
4425 An element can be a file name, or a list of the form (PREFIX . FILE)
4426 where PREFIX is a name prefix and FILE is the file to look in.
4427 If the element is just a file name, the file name also serves as the prefix.")
4429 (defun Info-find-emacs-command-nodes (command)
4430 "Return a list of locations documenting COMMAND.
4431 The `info-file' property of COMMAND says which Info manual to search.
4432 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4433 defines heuristics for which Info manual to try.
4434 The locations are of the format used in the variable `Info-history', i.e.
4435 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4436 in the first element of the returned list (which is treated specially in
4437 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4438 (let ((where '()) line-number
4439 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4440 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4441 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4442 (info-file "emacs")) ;default
4443 ;; Determine which Info file this command is documented in.
4444 (if (get command 'info-file)
4445 (setq info-file (get command 'info-file))
4446 ;; If it doesn't say explicitly, test its name against
4447 ;; various prefixes that we know.
4448 (let ((file-list Info-file-list-for-emacs))
4449 (while file-list
4450 (let* ((elt (car file-list))
4451 (name (if (consp elt)
4452 (car elt)
4453 elt))
4454 (file (if (consp elt) (cdr elt) elt))
4455 (case-fold-search nil)
4456 (regexp (concat "\\`" (regexp-quote name)
4457 "\\(\\'\\|-\\)")))
4458 (if (string-match regexp (symbol-name command))
4459 (setq info-file file file-list nil))
4460 (setq file-list (cdr file-list))))))
4461 (Info-find-node info-file "Top")
4462 ;; Bind Info-history to nil, to prevent the index nodes from
4463 ;; getting into the node history.
4464 (let ((Info-history nil)
4465 (Info-history-list nil)
4466 node (nodes (Info-index-nodes)))
4467 (Info-goto-node (car nodes))
4468 (while
4469 (progn
4470 (goto-char (point-min))
4471 (while (re-search-forward cmd-desc nil t)
4472 (setq where
4473 (cons (list Info-current-file
4474 (match-string-no-properties 2)
4476 where))
4477 (setq line-number (and (match-beginning 3)
4478 (string-to-number (match-string 3)))))
4479 (and (setq nodes (cdr nodes) node (car nodes))))
4480 (Info-goto-node node)))
4481 (if (and line-number where)
4482 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4483 (cdr where))
4484 where)))
4486 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4487 ;;;###autoload
4488 (defun Info-goto-emacs-command-node (command)
4489 "Go to the Info node in the Emacs manual for command COMMAND.
4490 The command is found by looking up in Emacs manual's indices
4491 or in another manual found via COMMAND's `info-file' property or
4492 the variable `Info-file-list-for-emacs'.
4493 COMMAND must be a symbol or string."
4494 (interactive "CFind documentation for command: ")
4495 ;; If command is given as a string, convert it to a symbol.
4496 (if (stringp command)
4497 (setq command (intern command)))
4498 (or (commandp command)
4499 (signal 'wrong-type-argument (list 'commandp command)))
4500 (let ((where (Info-find-emacs-command-nodes command)))
4501 (if where
4502 (let ((num-matches (length where)))
4503 ;; Get Info running, and pop to it in another window.
4504 (save-window-excursion
4505 (info))
4506 (or (derived-mode-p 'Info-mode) (pop-to-buffer "*info*"))
4507 ;; Bind Info-history to nil, to prevent the last Index node
4508 ;; visited by Info-find-emacs-command-nodes from being
4509 ;; pushed onto the history.
4510 (let ((Info-history nil) (Info-history-list nil)
4511 (line-number (nth 2 (car where))))
4512 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4513 (if (and (integerp line-number) (> line-number 0))
4514 (forward-line (1- line-number))))
4515 (if (> num-matches 1)
4516 (progn
4517 ;; (car where) will be pushed onto Info-history
4518 ;; when/if they go to another node. Put the other
4519 ;; nodes that were found on the history.
4520 (setq Info-history (nconc (cdr where) Info-history))
4521 (message "Found %d other entr%s. Use %s to see %s."
4522 (1- num-matches)
4523 (if (> num-matches 2) "ies" "y")
4524 (substitute-command-keys "\\[Info-history-back]")
4525 (if (> num-matches 2) "them" "it")))))
4526 (error "Couldn't find documentation for %s" command))))
4528 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4529 ;;;###autoload
4530 (defun Info-goto-emacs-key-command-node (key)
4531 "Go to the node in the Emacs manual which describes the command bound to KEY.
4532 KEY is a string.
4533 Interactively, if the binding is `execute-extended-command', a command is read.
4534 The command is found by looking up in Emacs manual's indices
4535 or in another manual found via COMMAND's `info-file' property or
4536 the variable `Info-file-list-for-emacs'."
4537 (interactive "kFind documentation for key: ")
4538 (let ((command (key-binding key)))
4539 (cond ((null command)
4540 (message "%s is undefined" (key-description key)))
4541 ((and (called-interactively-p 'interactive)
4542 (eq command 'execute-extended-command))
4543 (Info-goto-emacs-command-node
4544 (read-command "Find documentation for command: ")))
4546 (Info-goto-emacs-command-node command)))))
4548 (defvar Info-link-keymap
4549 (let ((keymap (make-sparse-keymap)))
4550 (define-key keymap [header-line down-mouse-1] 'mouse-drag-header-line)
4551 (define-key keymap [header-line mouse-1] 'mouse-select-window)
4552 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4553 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4554 (define-key keymap [follow-link] 'mouse-face)
4555 keymap)
4556 "Keymap to put on Info links.
4557 This is used for the \"Next\", \"Prev\", and \"Up\" links in the
4558 first line or header line, and for breadcrumb links.")
4560 (defun Info-breadcrumbs ()
4561 (let ((nodes (Info-toc-nodes Info-current-file))
4562 (node Info-current-node)
4563 (crumbs ())
4564 (depth Info-breadcrumbs-depth)
4565 line)
4567 ;; Get ancestors from the cached parent-children node info
4568 (while (and (not (equal "Top" node)) (> depth 0))
4569 (setq node (nth 1 (assoc node nodes)))
4570 (if node (push node crumbs))
4571 (setq depth (1- depth)))
4573 ;; Add bottom node.
4574 (when Info-use-header-line
4575 ;; Let it disappear if crumbs is nil.
4576 (nconc crumbs (list Info-current-node)))
4577 (when (or Info-use-header-line crumbs)
4578 ;; Add top node (and continuation if needed).
4579 (setq crumbs
4580 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4581 crumbs (cons nil crumbs))))
4582 ;; Eliminate duplicate.
4583 (forward-line 1)
4584 (dolist (node crumbs)
4585 (let ((text
4586 (if (not (equal node "Top")) node
4587 (format "(%s)Top"
4588 (if (stringp Info-current-file)
4589 (file-name-sans-extension
4590 (file-name-nondirectory Info-current-file))
4591 ;; Some legacy code can still use a symbol.
4592 Info-current-file)))))
4593 (setq line (concat
4594 line
4595 (if (null line) "" " > ")
4596 (cond
4597 ((null node) "...")
4598 ((equal node Info-current-node)
4599 ;; No point linking to ourselves.
4600 (propertize text 'font-lock-face 'info-header-node))
4602 (propertize text
4603 'mouse-face 'highlight
4604 'font-lock-face 'info-header-xref
4605 'help-echo "mouse-2: Go to node"
4606 'keymap Info-link-keymap
4607 'link-args text)))))))
4608 (setq line (concat line "\n")))
4609 ;; (font-lock-append-text-property 0 (length line)
4610 ;; 'font-lock-face 'header-line line)
4611 line))
4613 (defun Info-fontify-node ()
4614 "Fontify the node."
4615 (save-excursion
4616 (let* ((inhibit-read-only t)
4617 (case-fold-search t)
4618 paragraph-markers
4619 (not-fontified-p ; the node hasn't already been fontified
4620 (not (let ((where (next-single-property-change (point-min)
4621 'font-lock-face)))
4622 (and where (not (= where (point-max)))))))
4623 (fontify-visited-p ; visited nodes need to be re-fontified
4624 (and Info-fontify-visited-nodes
4625 ;; Don't take time to refontify visited nodes in huge nodes
4626 Info-fontify-maximum-menu-size
4627 (or (eq Info-fontify-maximum-menu-size t)
4628 (< (- (point-max) (point-min))
4629 Info-fontify-maximum-menu-size))))
4630 rbeg rend)
4632 ;; Fontify header line
4633 (goto-char (point-min))
4634 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4635 (goto-char (match-end 0))
4636 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4637 (goto-char (match-end 0))
4638 (let* ((nbeg (match-beginning 2))
4639 (nend (match-end 2))
4640 (tbeg (match-beginning 1))
4641 (tag (match-string 1)))
4642 (if (string-equal (downcase tag) "node")
4643 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4644 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4645 (put-text-property tbeg nend 'mouse-face 'highlight)
4646 (put-text-property tbeg nend
4647 'help-echo
4648 (concat "mouse-2: Go to node "
4649 (buffer-substring nbeg nend)))
4650 ;; Set up the text property keymap. Depending on
4651 ;; `Info-use-header-line', it is either used in the
4652 ;; buffer, or copied to the header line. A symbol value
4653 ;; of the `link-args' property is handled specially by
4654 ;; `Info-mouse-follow-link'.
4655 (put-text-property tbeg nend 'keymap Info-link-keymap)
4656 (put-text-property tbeg nend 'link-args
4657 (intern (downcase tag))))))
4659 ;; (when (> Info-breadcrumbs-depth 0)
4660 ;; (insert (Info-breadcrumbs)))
4662 ;; Treat header line.
4663 (when Info-use-header-line
4664 (goto-char (point-min))
4665 (let* ((header-end (line-end-position))
4666 (header
4667 ;; If we find neither Next: nor Prev: link, show the entire
4668 ;; node header. Otherwise, don't show the File: and Node:
4669 ;; parts, to avoid wasting precious space on information that
4670 ;; is available in the mode line.
4671 (if (re-search-forward
4672 "\\(next\\|up\\|prev[ious]*\\): "
4673 header-end t)
4674 (progn
4675 (goto-char (match-beginning 1))
4676 (buffer-substring (point) header-end))
4677 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4678 header-end t)
4679 (concat "No next, prev or up links -- "
4680 (buffer-substring (point) header-end))
4681 (buffer-substring (point) header-end)))))
4682 (put-text-property (point-min) (1+ (point-min))
4683 'header-line
4684 (replace-regexp-in-string
4686 ;; Preserve text properties on duplicated `%'.
4687 (lambda (s) (concat s s)) header))
4688 ;; Hide the part of the first line
4689 ;; that is in the header, if it is just part.
4690 (cond
4691 ((> Info-breadcrumbs-depth 0)
4692 (let ((ov (make-overlay (point-min) (1+ header-end))))
4693 (overlay-put ov 'display (Info-breadcrumbs))
4694 (overlay-put ov 'evaporate t)))
4695 ((not (bobp))
4696 ;; Hide the punctuation at the end, too.
4697 (skip-chars-backward " \t,")
4698 (put-text-property (point) header-end 'invisible t)
4699 ;; Hide the suffix of the Info file name.
4700 (beginning-of-line)
4701 (if (re-search-forward
4702 (format "File: %s\\([^,\n\t]+\\),"
4703 (if (stringp Info-current-file)
4704 (file-name-sans-extension
4705 (file-name-nondirectory Info-current-file))
4706 Info-current-file))
4707 header-end t)
4708 (put-text-property (match-beginning 1) (match-end 1)
4709 'invisible t)))))))
4711 ;; Fontify titles
4712 (goto-char (point-min))
4713 (when (and font-lock-mode not-fontified-p)
4714 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4715 nil t)
4716 ;; Only consider it as an underlined title if the ASCII
4717 ;; underline has the same size as the text. A typical
4718 ;; counter example is when a continuation "..." is alone
4719 ;; on a line.
4720 (when (= (string-width (match-string 1))
4721 (string-width (match-string 2)))
4722 (let* ((c (preceding-char))
4723 (face
4724 (cond ((= c ?*) 'info-title-1)
4725 ((= c ?=) 'info-title-2)
4726 ((= c ?-) 'info-title-3)
4727 (t 'info-title-4))))
4728 (put-text-property (match-beginning 1) (match-end 1)
4729 'font-lock-face face))
4730 ;; This is a serious problem for trying to handle multiple
4731 ;; frame types at once. We want this text to be invisible
4732 ;; on frames that can display the font above.
4733 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4734 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4735 '(invisible t front-sticky nil rear-nonsticky t))))))
4737 ;; Fontify cross references
4738 (goto-char (point-min))
4739 (when (or not-fontified-p fontify-visited-p)
4740 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4741 (let ((start (match-beginning 0))
4742 (next (point))
4743 other-tag)
4744 (when not-fontified-p
4745 (when Info-hide-note-references
4746 (when (and (not (eq Info-hide-note-references 'hide))
4747 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4748 ;; *Note is often used where *note should have been
4749 (goto-char start)
4750 (skip-syntax-backward " ")
4751 (when (memq (char-before) '(?\( ?\[ ?\{))
4752 ;; Check whether the paren is preceded by
4753 ;; an end of sentence
4754 (skip-syntax-backward " ("))
4755 (setq other-tag
4756 (cond ((save-match-data (looking-back "\\<see"
4757 (- (point) 3)))
4759 ((save-match-data (looking-back "\\<in"
4760 (- (point) 2)))
4762 ((memq (char-before) '(nil ?\. ?! ??))
4763 "See ")
4764 ((save-match-data
4765 (save-excursion
4766 (search-forward "\n\n" start t)))
4767 "See ")
4768 (t "see "))))
4769 (goto-char next)
4770 (add-text-properties
4771 (match-beginning 1)
4772 (or (save-match-data
4773 ;; Don't hide \n after *Note
4774 (let ((start1 (match-beginning 1)))
4775 (if (string-match "\n" (match-string 1))
4776 (+ start1 (match-beginning 0)))))
4777 (match-end 1))
4778 (if other-tag
4779 `(display ,other-tag front-sticky nil rear-nonsticky t)
4780 '(invisible t front-sticky nil rear-nonsticky t))))
4781 (add-text-properties
4782 (match-beginning 2) (match-end 2)
4783 (list
4784 'help-echo (if (or (match-end 5)
4785 (not (equal (match-string 4) "")))
4786 (concat "mouse-2: go to " (or (match-string 5)
4787 (match-string 4)))
4788 "mouse-2: go to this node")
4789 'mouse-face 'highlight)))
4790 (when (or not-fontified-p fontify-visited-p)
4791 (setq rbeg (match-beginning 2)
4792 rend (match-end 2))
4793 (put-text-property
4794 rbeg rend
4795 'font-lock-face
4796 ;; Display visited nodes in a different face
4797 (if (and Info-fontify-visited-nodes
4798 (save-match-data
4799 (let* ((node (replace-regexp-in-string
4800 "^[ \t]+" ""
4801 (replace-regexp-in-string
4802 "[ \t\n]+" " "
4803 (or (match-string-no-properties 5)
4804 (and (not (equal (match-string 4) ""))
4805 (match-string-no-properties 4))
4806 (match-string-no-properties 2)))))
4807 (external-link-p
4808 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4809 (file (if external-link-p
4810 (file-name-nondirectory
4811 (match-string-no-properties 1 node))
4812 Info-current-file))
4813 (hl Info-history-list)
4814 res)
4815 (if external-link-p
4816 (setq node (if (equal (match-string 2 node) "")
4817 "Top"
4818 (match-string-no-properties 2 node))))
4819 (while hl
4820 (if (and (string-equal node (nth 1 (car hl)))
4821 (equal file
4822 (if (and external-link-p
4823 (stringp (caar hl)))
4824 (file-name-nondirectory
4825 (caar hl))
4826 (caar hl))))
4827 (setq res (car hl) hl nil)
4828 (setq hl (cdr hl))))
4829 res))) 'info-xref-visited 'info-xref))
4830 ;; For multiline ref, unfontify newline and surrounding whitespace
4831 (save-excursion
4832 (goto-char rbeg)
4833 (save-match-data
4834 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4835 (remove-text-properties (match-beginning 0)
4836 (match-end 0)
4837 '(font-lock-face t))))))
4838 (when not-fontified-p
4839 (when (memq Info-hide-note-references '(t hide))
4840 (add-text-properties (match-beginning 3) (match-end 3)
4841 '(invisible t front-sticky nil rear-nonsticky t))
4842 ;; Unhide the file name of the external reference in parens
4843 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4844 (remove-text-properties (match-beginning 6) (match-end 6)
4845 '(invisible t front-sticky nil rear-nonsticky t)))
4846 ;; Unhide newline because hidden newlines cause too long lines
4847 (save-match-data
4848 (let ((beg3 (match-beginning 3))
4849 (end3 (match-end 3)))
4850 (if (and (string-match "\n[ \t]*" (match-string 3))
4851 (not (save-match-data
4852 (save-excursion
4853 (goto-char (1+ end3))
4854 (looking-at "[.)]*$")))))
4855 (remove-text-properties (+ beg3 (match-beginning 0))
4856 (+ beg3 (match-end 0))
4857 '(invisible t front-sticky nil rear-nonsticky t))))))
4858 (when (and Info-refill-paragraphs Info-hide-note-references)
4859 (push (set-marker (make-marker) start)
4860 paragraph-markers))))))
4862 ;; Refill paragraphs (experimental feature)
4863 (when (and not-fontified-p
4864 Info-refill-paragraphs
4865 paragraph-markers)
4866 (let ((fill-nobreak-invisible t)
4867 (fill-individual-varying-indent nil)
4868 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4869 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4870 (adaptive-fill-mode nil))
4871 (goto-char (point-max))
4872 (dolist (m paragraph-markers)
4873 (when (< m (point))
4874 (goto-char m)
4875 (beginning-of-line)
4876 (let ((beg (point)))
4877 (when (zerop (forward-paragraph))
4878 (fill-individual-paragraphs beg (point) nil nil)
4879 (goto-char beg))))
4880 (set-marker m nil))))
4882 ;; Fontify menu items
4883 (goto-char (point-min))
4884 (when (and (or not-fontified-p fontify-visited-p)
4885 (search-forward "\n* Menu:" nil t)
4886 ;; Don't take time to annotate huge menus
4887 Info-fontify-maximum-menu-size
4888 (or (eq Info-fontify-maximum-menu-size t)
4889 (< (- (point-max) (point))
4890 Info-fontify-maximum-menu-size)))
4891 (let ((n 0)
4892 cont)
4893 (while (re-search-forward
4894 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4895 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4896 nil t)
4897 (when (match-beginning 1)
4898 (when not-fontified-p
4899 (setq n (1+ n))
4900 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4901 (put-text-property (match-beginning 0)
4902 (1+ (match-beginning 0))
4903 'font-lock-face 'info-menu-star)))
4904 (when not-fontified-p
4905 (add-text-properties
4906 (match-beginning 1) (match-end 1)
4907 (list
4908 'help-echo (if (and (match-end 3)
4909 (not (equal (match-string 3) "")))
4910 (concat "mouse-2: go to " (match-string 3))
4911 "mouse-2: go to this node")
4912 'mouse-face 'highlight)))
4913 (when (or not-fontified-p fontify-visited-p)
4914 (put-text-property
4915 (match-beginning 1) (match-end 1)
4916 'font-lock-face
4917 ;; Display visited menu items in a different face
4918 (if (and Info-fontify-visited-nodes
4919 (save-match-data
4920 (let* ((node (if (equal (match-string 3) "")
4921 (match-string-no-properties 1)
4922 (match-string-no-properties 3)))
4923 (external-link-p
4924 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4925 (file (if external-link-p
4926 (file-name-nondirectory
4927 (match-string-no-properties 1 node))
4928 Info-current-file))
4929 (hl Info-history-list)
4930 res)
4931 (if external-link-p
4932 (setq node (if (equal (match-string 2 node) "")
4933 "Top"
4934 (match-string-no-properties 2 node))))
4935 (while hl
4936 (if (and (string-equal node (nth 1 (car hl)))
4937 (equal file
4938 (if (and external-link-p
4939 (stringp (caar hl)))
4940 (file-name-nondirectory
4941 (caar hl))
4942 (caar hl))))
4943 (setq res (car hl) hl nil)
4944 (setq hl (cdr hl))))
4945 res))) 'info-xref-visited 'info-xref)))
4946 (when (and not-fontified-p
4947 (memq Info-hide-note-references '(t hide))
4948 (not (Info-index-node)))
4949 (put-text-property (match-beginning 2) (1- (match-end 6))
4950 'invisible t)
4951 ;; Unhide the file name in parens
4952 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4953 (remove-text-properties (match-beginning 4) (match-end 4)
4954 '(invisible t)))
4955 ;; We need a stretchable space like :align-to but with
4956 ;; a minimum value.
4957 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4958 (if (>= 22 (- (match-end 1)
4959 (match-beginning 0)))
4960 '(space :align-to 24)
4961 '(space :width 2)))
4962 (setq cont (looking-at "."))
4963 (while (and (= (forward-line 1) 0)
4964 (looking-at "\\([ \t]+\\)[^*\n]"))
4965 (put-text-property (match-beginning 1) (1- (match-end 1))
4966 'invisible t)
4967 (put-text-property (1- (match-end 1)) (match-end 1)
4968 'display
4969 (if cont
4970 '(space :align-to 26)
4971 '(space :align-to 24)))
4972 (setq cont t)))))))
4974 ;; Fontify menu headers
4975 ;; Add the face `info-menu-header' to any header before a menu entry
4976 (goto-char (point-min))
4977 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4978 (put-text-property (match-beginning 0) (match-end 0)
4979 'font-lock-face 'info-menu-header)
4980 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4981 (put-text-property (match-beginning 1) (match-end 1)
4982 'font-lock-face 'info-menu-header)))
4984 ;; Hide index line numbers
4985 (goto-char (point-min))
4986 (when (and not-fontified-p (Info-index-node))
4987 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4988 (put-text-property (match-beginning 0) (match-end 0)
4989 'invisible t)))
4991 ;; Fontify http and ftp references
4992 (goto-char (point-min))
4993 (when not-fontified-p
4994 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`‘({<>})’']+"
4995 nil t)
4996 (add-text-properties (match-beginning 0) (match-end 0)
4997 '(font-lock-face info-xref
4998 mouse-face highlight
4999 help-echo "mouse-2: go to this URL"))))
5001 ;; Fontify footnotes
5002 (goto-char (point-min))
5003 (when (and not-fontified-p (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t))
5004 (let ((limit (point)))
5005 (goto-char (point-min))
5006 (while (re-search-forward "\\(([0-9]+)\\)" nil t)
5007 (add-text-properties (match-beginning 0) (match-end 0)
5008 `(font-lock-face info-xref
5009 link t
5010 mouse-face highlight
5011 help-echo
5012 ,(if (< (point) limit)
5013 "mouse-2: go to footnote definition"
5014 "mouse-2: go to footnote reference"))))))
5016 ;; Hide empty lines at the end of the node.
5017 (goto-char (point-max))
5018 (skip-chars-backward "\n")
5019 (when (< (point) (1- (point-max)))
5020 (put-text-property (point) (1- (point-max)) 'invisible t))
5022 (set-buffer-modified-p nil))))
5024 ;;; Speedbar support:
5025 ;; These functions permit speedbar to display the "tags" in the
5026 ;; current Info node.
5027 (eval-when-compile (require 'speedbar)) ; for speedbar-with-writable
5029 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
5030 (declare-function speedbar-center-buffer-smartly "speedbar" ())
5031 (declare-function speedbar-change-expand-button-char "speedbar" (char))
5032 (declare-function speedbar-change-initial-expansion-list "speedbar" (new-default))
5033 (declare-function speedbar-delete-subblock "speedbar" (indent))
5034 (declare-function speedbar-make-specialized-keymap "speedbar" ())
5035 (declare-function speedbar-make-tag-line "speedbar"
5036 (exp-button-type exp-button-char exp-button-function
5037 exp-button-data tag-button tag-button-function
5038 tag-button-data tag-button-face depth))
5040 (defvar Info-speedbar-key-map nil
5041 "Keymap used when in the Info display mode.")
5043 (defun Info-install-speedbar-variables ()
5044 "Install those variables used by speedbar to enhance Info."
5045 (if Info-speedbar-key-map
5047 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
5049 ;; Basic tree features
5050 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
5051 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
5052 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
5053 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
5056 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
5057 Info-speedbar-key-map
5058 Info-speedbar-hierarchy-buttons)))
5060 (defvar Info-speedbar-menu-items
5061 '(["Browse Node" speedbar-edit-line t]
5062 ["Expand Node" speedbar-expand-line
5063 (save-excursion (beginning-of-line)
5064 (looking-at "[0-9]+: *.\\+. "))]
5065 ["Contract Node" speedbar-contract-line
5066 (save-excursion (beginning-of-line)
5067 (looking-at "[0-9]+: *.-. "))]
5069 "Additional menu-items to add to speedbar frame.")
5071 ;; Make sure our special speedbar major mode is loaded
5072 (if (featurep 'speedbar)
5073 (Info-install-speedbar-variables)
5074 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
5076 ;;; Info hierarchy display method
5077 ;;;###autoload
5078 (defun Info-speedbar-browser ()
5079 "Initialize speedbar to display an Info node browser.
5080 This will add a speedbar major display mode."
5081 (interactive)
5082 (require 'speedbar)
5083 ;; Make sure that speedbar is active
5084 (speedbar-frame-mode 1)
5085 ;; Now, throw us into Info mode on speedbar.
5086 (speedbar-change-initial-expansion-list "Info")
5089 ;; speedbar loads dframe at runtime.
5090 (declare-function dframe-select-attached-frame "dframe" (&optional frame))
5091 (declare-function dframe-current-frame "dframe" (frame-var desired-major-mode))
5093 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
5094 "Display an Info directory hierarchy in speedbar.
5095 DIRECTORY is the current directory in the attached frame.
5096 DEPTH is the current indentation depth.
5097 NODE is an optional argument that is used to represent the
5098 specific node to expand."
5099 (if (and (not node)
5100 (save-excursion (goto-char (point-min))
5101 (let ((case-fold-search t))
5102 (looking-at "Info Nodes:"))))
5103 ;; Update our "current node" maybe?
5105 ;; We cannot use the generic list code, that depends on all leaves
5106 ;; being known at creation time.
5107 (if (not node)
5108 (speedbar-with-writable (insert "Info Nodes:\n")))
5109 (let ((completions nil))
5110 (speedbar-select-attached-frame)
5111 (save-window-excursion
5112 (setq completions
5113 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
5114 (select-frame (speedbar-current-frame))
5115 (if completions
5116 (speedbar-with-writable
5117 (dolist (completion completions)
5118 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
5119 (cdr completion)
5120 (car completion)
5121 'Info-speedbar-goto-node
5122 (cdr completion)
5123 'info-xref depth))
5125 nil))))
5127 (defun Info-speedbar-goto-node (_text node _indent)
5128 "When user clicks on TEXT, go to an info NODE.
5129 The INDENT level is ignored."
5130 (speedbar-select-attached-frame)
5131 (let* ((buff (or (get-buffer "*info*")
5132 (progn (info) (get-buffer "*info*"))))
5133 (bwin (get-buffer-window buff 0)))
5134 (if bwin
5135 (progn
5136 (select-window bwin)
5137 (raise-frame (window-frame bwin)))
5138 (if speedbar-power-click
5139 (switch-to-buffer-other-frame buff)
5140 (speedbar-select-attached-frame)
5141 (switch-to-buffer buff)))
5142 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
5143 (error "Invalid node %s" node)
5144 (Info-find-node (match-string 1 node) (match-string 2 node))
5145 ;; If we do a find-node, and we were in info mode, restore
5146 ;; the old default method. Once we are in info mode, it makes
5147 ;; sense to return to whatever method the user was using before.
5148 (if (string= speedbar-initial-expansion-list-name "Info")
5149 (speedbar-change-initial-expansion-list
5150 speedbar-previously-used-expansion-list-name)))))
5152 (defun Info-speedbar-expand-node (text token indent)
5153 "Expand the node the user clicked on.
5154 TEXT is the text of the button we clicked on, a + or - item.
5155 TOKEN is data related to this node (NAME . FILE).
5156 INDENT is the current indentation depth."
5157 (cond ((string-match "+" text) ;we have to expand this file
5158 (speedbar-change-expand-button-char ?-)
5159 (if (speedbar-with-writable
5160 (save-excursion
5161 (end-of-line) (forward-char 1)
5162 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
5163 (speedbar-change-expand-button-char ?-)
5164 (speedbar-change-expand-button-char ??)))
5165 ((string-match "-" text) ;we have to contract this node
5166 (speedbar-change-expand-button-char ?+)
5167 (speedbar-delete-subblock indent))
5168 (t (error "Ooops... not sure what to do")))
5169 (speedbar-center-buffer-smartly))
5171 (defun Info-speedbar-fetch-file-nodes (nodespec)
5172 "Fetch the subnodes from the info NODESPEC.
5173 NODESPEC is a string of the form: (file)node."
5174 ;; Set up a buffer we can use to fake-out Info.
5175 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
5176 (if (not (derived-mode-p 'Info-mode))
5177 (Info-mode))
5178 ;; Get the node into this buffer
5179 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
5180 (error "Invalid node specification %s" nodespec)
5181 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
5182 ;; Scan the created buffer
5183 (goto-char (point-min))
5184 (let ((completions nil)
5185 (case-fold-search t)
5186 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
5187 (match-string 1 nodespec))))
5188 ;; Always skip the first one...
5189 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5190 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5191 (let ((name (match-string 1)))
5192 (push (cons name
5193 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
5194 (match-string 1)
5195 (if (looking-at " *\\(([^)]+)\\)\\.")
5196 (concat (match-string 1) "Top")
5197 (concat "(" thisfile ")"
5198 (if (looking-at " \\([^.]+\\).")
5199 (match-string 1)
5200 name)))))
5201 completions)))
5202 (nreverse completions))))
5204 ;;; Info mode node listing
5205 ;; This is called by `speedbar-add-localized-speedbar-support'
5206 (defun Info-speedbar-buttons (_buffer)
5207 "Create a speedbar display to help navigation in an Info file.
5208 BUFFER is the buffer speedbar is requesting buttons for."
5209 (if (save-excursion (goto-char (point-min))
5210 (let ((case-fold-search t))
5211 (not (looking-at "Info Nodes:"))))
5212 (erase-buffer))
5213 (Info-speedbar-hierarchy-buttons nil 0))
5215 ;; FIXME: Really? Why here?
5216 (add-to-list 'debug-ignored-errors 'search-failed)
5218 ;;;; Desktop support
5220 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
5221 "Auxiliary information to be saved in desktop file."
5222 (list Info-current-file
5223 Info-current-node
5224 ;; Additional data as an association list.
5225 (delq nil (list
5226 (and Info-history
5227 (cons 'history Info-history))
5228 (and (Info-virtual-fun
5229 'slow Info-current-file Info-current-node)
5230 (cons 'slow t))))))
5232 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
5233 desktop-buffer-name
5234 desktop-buffer-misc)
5235 "Restore an Info buffer specified in a desktop file."
5236 (let* ((file (nth 0 desktop-buffer-misc))
5237 (node (nth 1 desktop-buffer-misc))
5238 (data (nth 2 desktop-buffer-misc))
5239 (hist (assq 'history data))
5240 (slow (assq 'slow data)))
5241 ;; Don't restore nodes slow to regenerate.
5242 (unless slow
5243 (when (and file node)
5244 (when desktop-buffer-name
5245 (set-buffer (get-buffer-create desktop-buffer-name))
5246 (Info-mode))
5247 (Info-find-node file node)
5248 (when hist
5249 (setq Info-history (cdr hist)))
5250 (current-buffer)))))
5252 (add-to-list 'desktop-buffer-mode-handlers
5253 '(Info-mode . Info-restore-desktop-buffer))
5255 ;;;; Bookmark support
5256 (declare-function bookmark-make-record-default
5257 "bookmark" (&optional no-file no-context posn))
5258 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
5259 (declare-function bookmark-default-handler "bookmark" (bmk))
5260 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
5262 (defun Info-bookmark-make-record ()
5263 "This implements the `bookmark-make-record-function' type (which see)
5264 for Info nodes."
5265 (let* ((file (and (stringp Info-current-file)
5266 (file-name-sans-extension
5267 (file-name-nondirectory Info-current-file))))
5268 (bookmark-name (if file
5269 (concat "(" file ") " Info-current-node)
5270 Info-current-node))
5271 (defaults (delq nil (list bookmark-name file Info-current-node))))
5272 `(,bookmark-name
5273 ,@(bookmark-make-record-default 'no-file)
5274 (filename . ,Info-current-file)
5275 (info-node . ,Info-current-node)
5276 (handler . Info-bookmark-jump)
5277 (defaults . ,defaults))))
5279 ;;;###autoload
5280 (defun Info-bookmark-jump (bmk)
5281 "This implements the `handler' function interface for the record
5282 type returned by `Info-bookmark-make-record', which see."
5283 (let* ((file (bookmark-prop-get bmk 'filename))
5284 (info-node (bookmark-prop-get bmk 'info-node))
5285 (buf (save-window-excursion ;FIXME: doesn't work with frames!
5286 (Info-find-node file info-node) (current-buffer))))
5287 ;; Use bookmark-default-handler to move to the appropriate location
5288 ;; within the node.
5289 (bookmark-default-handler
5290 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
5293 ;;;###autoload
5294 (defun info-display-manual (manual)
5295 "Display an Info buffer displaying MANUAL.
5296 If there is an existing Info buffer for MANUAL, display it.
5297 Otherwise, visit the manual in a new Info buffer. In interactive
5298 use, a prefix argument directs this command to limit the
5299 completion alternatives to currently visited manuals."
5300 (interactive
5301 (list
5302 (progn
5303 (info-initialize)
5304 (completing-read "Manual name: "
5305 (info--manual-names current-prefix-arg)
5306 nil t))))
5307 (let ((blist (buffer-list))
5308 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
5309 (case-fold-search t)
5310 found)
5311 (dolist (buffer blist)
5312 (with-current-buffer buffer
5313 (when (and (eq major-mode 'Info-mode)
5314 (stringp Info-current-file)
5315 (string-match manual-re Info-current-file))
5316 (setq found buffer
5317 blist nil))))
5318 (if found
5319 (switch-to-buffer found)
5320 (info-initialize)
5321 (info (Info-find-file manual)
5322 (generate-new-buffer-name "*info*")))))
5324 (defun info--manual-names (visited-only)
5325 (let (names)
5326 (dolist (buffer (buffer-list))
5327 (with-current-buffer buffer
5328 (and (eq major-mode 'Info-mode)
5329 (stringp Info-current-file)
5330 (not (string= (substring (buffer-name) 0 1) " "))
5331 (push (file-name-sans-extension
5332 (file-name-nondirectory Info-current-file))
5333 names))))
5334 (delete-dups (append (nreverse names)
5335 (when (not visited-only)
5336 (all-completions
5338 (apply-partially #'Info-read-node-name-2
5339 Info-directory-list
5340 (mapcar #'car Info-suffix-list))))))))
5342 (provide 'info)
5344 ;;; info.el ends here