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