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