Fix 'dired-compress-files'
[emacs.git] / lisp / info.el
blob6426cfcf9ed93f295e91f56f812ffcf5bf7a01d1
1 ;; info.el --- Info package for Emacs -*- lexical-binding:t -*-
3 ;; Copyright (C) 1985-1986, 1992-2016 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
6 ;; Keywords: help
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Note that nowadays we expect Info files to be made using makeinfo.
26 ;; In particular we make these assumptions:
27 ;; - a menu item MAY contain colons but not colon-space ": "
28 ;; - a menu item ending with ": " (but not ":: ") is an index entry
29 ;; - a node name MAY NOT contain a colon
30 ;; This distinction is to support indexing of computer programming
31 ;; language terms that may contain ":" but not ": ".
33 ;;; Code:
35 (eval-when-compile (require 'cl-lib))
37 (defgroup info nil
38 "Info subsystem."
39 :group 'help
40 :group 'docs)
43 (defvar-local Info-history nil
44 "Stack of Info nodes user has visited.
45 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
47 (defvar-local Info-history-forward nil
48 "Stack of Info nodes user has visited with `Info-history-back' command.
49 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
51 (defvar Info-history-list nil
52 "List of all Info nodes user has visited.
53 Each element of the list is a list (FILENAME NODENAME).")
55 (defcustom Info-history-skip-intermediate-nodes t
56 "Non-nil means don't record intermediate Info nodes to the history.
57 Intermediate Info nodes are nodes visited by Info internally in the process of
58 searching the node to display. Intermediate nodes are not presented
59 to the user."
60 :type 'boolean
61 :group 'info
62 :version "24.1")
64 (defvar Info-enable-active-nodes nil
65 "Non-nil allows Info to execute Lisp code associated with nodes.
66 The Lisp code is executed when the node is selected.")
67 (put 'Info-enable-active-nodes 'risky-local-variable t)
69 (defface info-node
70 '((((class color) (background light)) :foreground "brown" :weight bold :slant italic)
71 (((class color) (background dark)) :foreground "white" :weight bold :slant italic)
72 (t :weight bold :slant italic))
73 "Face for Info node names."
74 :group 'info)
76 (defface info-title-1
77 '((((type tty pc) (class color) (background light))
78 :foreground "green" :weight bold)
79 (((type tty pc) (class color) (background dark))
80 :foreground "yellow" :weight bold)
81 (t :height 1.2 :inherit info-title-2))
82 "Face for info titles at level 1."
83 :group 'info)
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-regexp-function
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-regexp-function)
2124 (funcall isearch-regexp-function 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-message
3385 "(%s total; use `%s' for next)"
3386 (length Info-index-alternatives)
3387 (key-description (where-is-internal
3388 'Info-index-next overriding-local-map 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
3499 (format "*Index for ‘%s’*" topic))))
3501 (add-to-list 'Info-virtual-files
3502 '("\\`\\*Apropos\\*\\'"
3503 (toc-nodes . Info-apropos-toc-nodes)
3504 (find-file . Info-apropos-find-file)
3505 (find-node . Info-apropos-find-node)
3506 (slow . t)
3509 (defvar Info-apropos-file "*Apropos*"
3510 "Info file name of the virtual manual for matches of `info-apropos'.")
3512 (defvar Info-apropos-nodes nil
3513 "Alist of cached apropos matched nodes.
3514 Each element is (NODENAME STRING MATCHES) where
3515 NODENAME is the name of the node that holds the search result,
3516 STRING is the search string given as an argument to `info-apropos',
3517 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3519 (defun Info-apropos-toc-nodes (filename)
3520 "Apropos-specific implementation of `Info-toc-nodes'."
3521 (let ((nodes (mapcar #'car (reverse Info-apropos-nodes))))
3522 `(,filename
3523 ("Top" nil nil ,nodes)
3524 ,@(mapcar (lambda (node) `(,node "Top" nil nil)) nodes))))
3526 (defun Info-apropos-find-file (filename &optional _noerror)
3527 "Apropos-specific implementation of `Info-find-file'."
3528 filename)
3530 (defun Info-apropos-find-node (_filename nodename &optional _no-going-back)
3531 "Apropos-specific implementation of `Info-find-node-2'."
3532 (if (equal nodename "Top")
3533 ;; Generate Top menu
3534 (let ((nodes (reverse Info-apropos-nodes)))
3535 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3536 Info-apropos-file nodename))
3537 (insert "Apropos Index\n")
3538 (insert "*************\n\n")
3539 (insert "This is a list of search results produced by ‘info-apropos’.\n\n")
3540 (insert "* Menu:\n\n")
3541 (dolist (nodeinfo nodes)
3542 (insert (format "* %-20s %s.\n"
3543 (format "%s::" (nth 0 nodeinfo))
3544 (nth 1 nodeinfo)))))
3545 ;; Else, Generate Index-like menu of matches
3546 (let* ((nodeinfo (assoc nodename Info-apropos-nodes))
3547 (matches (nth 2 nodeinfo)))
3548 (when matches
3549 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3550 Info-apropos-file nodename))
3551 (insert "Apropos Index\n")
3552 (insert "*************\n\n")
3553 (insert "Index entries that match ‘" (nth 1 nodeinfo) "’:\n\n")
3554 (insert "\0\b[index\0\b]\n")
3555 (if (eq matches t)
3556 (insert "No matches found.\n")
3557 (insert "* Menu:\n\n")
3558 (dolist (entry matches)
3559 (insert (format "* %-38s (%s)%s.%s\n"
3560 (format "%s [%s]:" (nth 1 entry) (nth 0 entry))
3561 (nth 0 entry)
3562 (nth 2 entry)
3563 (if (nth 3 entry)
3564 (format " (line %s)" (nth 3 entry))
3565 "")))))))))
3567 (defun Info-apropos-matches (string)
3568 "Collect STRING matches from all known Info files on your system.
3569 Return a list of matches where each element is in the format
3570 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3571 (unless (string= string "")
3572 (let ((pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3573 (regexp-quote string)))
3574 (ohist Info-history)
3575 (ohist-list Info-history-list)
3576 (current-node Info-current-node)
3577 (current-file Info-current-file)
3578 manuals matches node nodes)
3579 (let ((Info-fontify-maximum-menu-size nil))
3580 (Info-directory)
3581 ;; current-node and current-file are nil when they invoke info-apropos
3582 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3583 ;; case, we use (DIR)Top instead, to avoid signaling an error after
3584 ;; the search is complete.
3585 (when (null current-node)
3586 (setq current-file Info-current-file)
3587 (setq current-node Info-current-node))
3588 (message "Searching indices...")
3589 (goto-char (point-min))
3590 (re-search-forward "\\* Menu: *\n" nil t)
3591 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
3592 ;; Make sure we don't have duplicates in `manuals',
3593 ;; so that the following dolist loop runs faster.
3594 (cl-pushnew (match-string 1) manuals :test #'equal))
3595 (dolist (manual (nreverse manuals))
3596 (message "Searching %s" manual)
3597 (condition-case err
3598 (if (setq nodes (Info-index-nodes (Info-find-file manual)))
3599 (save-excursion
3600 (Info-find-node manual (car nodes))
3601 (while
3602 (progn
3603 (goto-char (point-min))
3604 (while (re-search-forward pattern nil t)
3605 (let ((entry (match-string-no-properties 1))
3606 (nodename (match-string-no-properties 3))
3607 (line (match-string-no-properties 4)))
3608 (add-text-properties
3609 (- (match-beginning 2) (match-beginning 1))
3610 (- (match-end 2) (match-beginning 1))
3611 '(face info-index-match) entry)
3612 (setq matches (cons (list manual entry nodename line)
3613 matches))))
3614 (setq nodes (cdr nodes) node (car nodes)))
3615 (Info-goto-node node))))
3616 (error
3617 (message "%s" (if (eq (car-safe err) 'error)
3618 (nth 1 err) err))
3619 (sit-for 1 t)))))
3620 (Info-find-node current-file current-node)
3621 (setq Info-history ohist
3622 Info-history-list ohist-list)
3623 (message "Searching indices...done")
3624 (or (nreverse matches) t))))
3626 ;;;###autoload
3627 (defun info-apropos (string)
3628 "Grovel indices of all known Info files on your system for STRING.
3629 Build a menu of the possible matches."
3630 (interactive "sIndex apropos: ")
3631 (if (equal string "")
3632 (Info-find-node Info-apropos-file "Top")
3633 (let* ((nodes Info-apropos-nodes) nodename)
3634 (while (and nodes (not (equal string (nth 1 (car nodes)))))
3635 (setq nodes (cdr nodes)))
3636 (if nodes
3637 (Info-find-node Info-apropos-file (car (car nodes)))
3638 (setq nodename (format "Index for ‘%s’" string))
3639 (push (list nodename string (Info-apropos-matches string))
3640 Info-apropos-nodes)
3641 (Info-find-node Info-apropos-file nodename)))))
3643 (add-to-list 'Info-virtual-files
3644 '("\\`\\*Finder.*\\*\\'"
3645 (find-file . Info-finder-find-file)
3646 (find-node . Info-finder-find-node)
3649 (defvar Info-finder-file "*Finder*"
3650 "Info file name of the virtual Info keyword finder manual.")
3652 (defun Info-finder-find-file (filename &optional _noerror)
3653 "Finder-specific implementation of `Info-find-file'."
3654 filename)
3656 (defvar finder-known-keywords)
3657 (declare-function find-library-name "find-func" (library))
3658 (declare-function finder-unknown-keywords "finder" ())
3659 (declare-function lm-commentary "lisp-mnt" (&optional file))
3660 (defvar finder-keywords-hash)
3661 (defvar package--builtins) ; finder requires package
3663 (defun info--prettify-description (desc)
3664 (if (stringp desc)
3665 (with-temp-buffer
3666 (insert (substitute-command-keys desc))
3667 (if (equal ?. (char-before))
3668 (delete-char -1))
3669 (goto-char (point-min))
3670 (or (let (case-fold-search) (looking-at-p "\\.\\|[[:upper:]]"))
3671 (capitalize-word 1))
3672 (buffer-string))
3673 desc))
3675 (defun Info-finder-find-node (_filename nodename &optional _no-going-back)
3676 "Finder-specific implementation of `Info-find-node-2'."
3677 (require 'finder)
3678 (cond
3679 ((equal nodename "Top")
3680 ;; Display Top menu with descriptions of the keywords
3681 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3682 Info-finder-file nodename))
3683 (insert "Finder Keywords\n")
3684 (insert "***************\n\n")
3685 (insert "* Menu:\n\n")
3686 (dolist (assoc (append '((all . "All package info")
3687 (unknown . "Unknown keywords"))
3688 finder-known-keywords))
3689 (let ((keyword (car assoc)))
3690 (insert (format "* %s %s.\n"
3691 (concat (symbol-name keyword) ": "
3692 "Keyword " (symbol-name keyword) ".")
3693 (info--prettify-description (cdr assoc)))))))
3694 ((equal nodename "Keyword unknown")
3695 ;; Display unknown keywords
3696 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3697 Info-finder-file nodename))
3698 (insert "Finder Unknown Keywords\n")
3699 (insert "***********************\n\n")
3700 (insert "* Menu:\n\n")
3701 (mapc
3702 (lambda (assoc)
3703 (insert (format "* %-14s %s.\n"
3704 (concat (symbol-name (car assoc)) ": "
3705 "Keyword " (symbol-name (car assoc)) ".")
3706 (cdr assoc))))
3707 (finder-unknown-keywords)))
3708 ((equal nodename "Keyword all")
3709 ;; Display all package info.
3710 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3711 Info-finder-file nodename))
3712 (insert "Finder Package Info\n")
3713 (insert "*******************\n\n")
3714 (insert "* Menu:\n\n")
3715 (let (desc)
3716 (dolist (package package--builtins)
3717 (setq desc (cdr-safe package))
3718 (when (vectorp desc)
3719 (insert (format "* %-16s %s.\n"
3720 (concat (symbol-name (car package)) "::")
3721 (info--prettify-description (aref desc 2))))))))
3722 ((string-match "\\`Keyword " nodename)
3723 (setq nodename (substring nodename (match-end 0)))
3724 ;; Display packages that match the keyword
3725 ;; or the list of keywords separated by comma.
3726 (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
3727 Info-finder-file nodename))
3728 (insert "Finder Packages\n")
3729 (insert "***************\n\n")
3730 (insert
3731 "The following packages match the keyword ‘" nodename "’:\n\n")
3732 (insert "* Menu:\n\n")
3733 (let ((keywords
3734 (mapcar #'intern (if (string-match-p "," nodename)
3735 (split-string nodename ",[ \t\n]*" t)
3736 (list nodename))))
3737 hits desc)
3738 (dolist (keyword keywords)
3739 (push (copy-tree (gethash keyword finder-keywords-hash)) hits))
3740 (setq hits (delete-dups (apply #'append hits))
3741 ;; Not a meaningful package.
3742 hits (delete 'emacs hits)
3743 hits (sort hits (lambda (a b) (string< (symbol-name a)
3744 (symbol-name b)))))
3745 (dolist (package hits)
3746 (setq desc (cdr-safe (assq package package--builtins)))
3747 (when (vectorp desc)
3748 (insert (format "* %-16s %s.\n"
3749 (concat (symbol-name package) "::")
3750 (info--prettify-description (aref desc 2))))))))
3752 ;; Display commentary section
3753 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3754 Info-finder-file nodename))
3755 (insert "Package Description\n")
3756 (insert "*******************\n\n")
3757 (insert
3758 "Description of the package ‘" nodename "’:\n\n")
3759 ;; This assumes that a file named package.el exists,
3760 ;; which is not always true. E.g. for the nxml package,
3761 ;; there is no "nxml.el" (it's nxml-mode.el).
3762 ;; But package.el makes the same assumption.
3763 ;; I think nxml is the only exception - maybe it should be just be renamed.
3764 (let ((str (ignore-errors (lm-commentary (find-library-name nodename)))))
3765 (if (null str)
3766 (insert "Can’t find package description.\n\n")
3767 (insert
3768 (with-temp-buffer
3769 (insert str)
3770 (goto-char (point-min))
3771 (delete-blank-lines)
3772 (goto-char (point-max))
3773 (delete-blank-lines)
3774 (goto-char (point-min))
3775 (while (re-search-forward "^;+ ?" nil t)
3776 (replace-match "" nil nil))
3777 (buffer-string))))))))
3779 ;;;###autoload
3780 (defun info-finder (&optional keywords)
3781 "Display descriptions of the keywords in the Finder virtual manual.
3782 In interactive use, a prefix argument directs this command to read
3783 a list of keywords separated by comma. After that, it displays a node
3784 with a list of packages that contain all specified keywords."
3785 (interactive
3786 (when current-prefix-arg
3787 (require 'finder)
3788 (list
3789 (completing-read-multiple
3790 "Keywords (separated by comma): "
3791 (mapcar #'symbol-name (mapcar #'car (append finder-known-keywords
3792 (finder-unknown-keywords))))
3793 nil t))))
3794 (require 'finder)
3795 (if keywords
3796 (Info-find-node Info-finder-file (mapconcat 'identity keywords ", "))
3797 (Info-find-node Info-finder-file "Top")))
3800 (defun Info-undefined ()
3801 "Make command be undefined in Info."
3802 (interactive)
3803 (ding))
3805 (defun Info-help ()
3806 "Enter the Info tutorial."
3807 (interactive)
3808 (delete-other-windows)
3809 (Info-find-node "info"
3810 (if (< (window-height) 23)
3811 "Help-Small-Screen"
3812 "Help")))
3814 (defun Info-summary ()
3815 "Display a brief summary of all Info commands."
3816 (interactive)
3817 (save-window-excursion
3818 (switch-to-buffer "*Help*")
3819 (setq buffer-read-only nil)
3820 (erase-buffer)
3821 (insert (documentation 'Info-mode))
3822 (help-mode)
3823 (goto-char (point-min))
3824 (let (ch flag)
3825 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
3826 (message (if flag "Type Space to see more"
3827 "Type Space to return to Info"))
3828 (if (not (eq ?\s (setq ch (read-event))))
3829 (progn (push ch unread-command-events) nil)
3830 flag))
3831 (scroll-up)))
3832 (bury-buffer "*Help*")))
3834 (defun Info-get-token (pos start all &optional errorstring)
3835 "Return the token around POS.
3836 POS must be somewhere inside the token.
3837 START is a regular expression which will match the
3838 beginning of the tokens delimited string.
3839 ALL is a regular expression with a single
3840 parenthesized subpattern which is the token to be
3841 returned. E.g. `{(.*)}' would return any string
3842 enclosed in braces around POS.
3843 ERRORSTRING optional fourth argument, controls action on no match:
3844 nil: return nil
3845 t: beep
3846 a string: signal an error, using that string."
3847 (let ((case-fold-search t))
3848 (save-excursion
3849 (goto-char pos)
3850 ;; First look for a match for START that goes across POS.
3851 (while (and (not (bobp)) (> (point) (- pos (length start)))
3852 (not (looking-at start)))
3853 (forward-char -1))
3854 ;; If we did not find one, search back for START
3855 ;; (this finds only matches that end at or before POS).
3856 (or (looking-at start)
3857 (progn
3858 (goto-char pos)
3859 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
3860 (let (found)
3861 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
3862 (not (setq found (and (<= (match-beginning 0) pos)
3863 (> (match-end 0) pos))))))
3864 (if (and found (<= (match-beginning 0) pos)
3865 (> (match-end 0) pos))
3866 (match-string-no-properties 1)
3867 (cond ((null errorstring)
3868 nil)
3869 ((eq errorstring t)
3870 (beep)
3871 nil)
3873 (error "No %s around position %d" errorstring pos))))))))
3875 (defun Info-mouse-follow-nearest-node (click)
3876 "\\<Info-mode-map>Follow a node reference near point.
3877 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3878 At end of the node's text, moves to the next node, or up if none."
3879 (interactive "e")
3880 (mouse-set-point click)
3881 (and (not (Info-follow-nearest-node))
3882 (save-excursion (forward-line 1) (eobp))
3883 (Info-next-preorder)))
3885 (defun Info-follow-nearest-node (&optional fork)
3886 "Follow a node reference near point.
3887 If point is on a reference, follow that reference. Otherwise,
3888 if point is in a menu item description, follow that menu item.
3890 If FORK is non-nil (interactively with a prefix arg), show the node in
3891 a new Info buffer.
3892 If FORK is a string, it is the name to use for the new buffer."
3893 (interactive "P")
3894 (or (Info-try-follow-nearest-node fork)
3895 (when (save-excursion
3896 (search-backward "\n* menu:" nil t))
3897 (save-excursion
3898 (beginning-of-line)
3899 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3900 (beginning-of-line 0))
3901 (when (looking-at "\\* +\\([^\t\n]*\\):")
3902 (Info-goto-node
3903 (Info-extract-menu-item (match-string-no-properties 1)) fork)
3904 t)))
3905 (and (eq this-command 'Info-mouse-follow-nearest-node)
3906 ;; Don't raise an error when mouse-1 is bound to this - it's
3907 ;; often used to simply select the window or frame.
3908 (eq 'mouse-1 (event-basic-type last-input-event)))
3909 (user-error "Point neither on reference nor in menu item description")))
3911 ;; Common subroutine.
3912 (defun Info-try-follow-nearest-node (&optional fork)
3913 "Follow a node reference near point. Return non-nil if successful.
3914 If FORK is non-nil, it is passed to `Info-goto-node'."
3915 (let (node)
3916 (cond
3917 ((setq node (Info-get-token (point) "[hf]t?tps?://"
3918 "\\([hf]t?tps?://[^ \t\n\"`‘({<>})’']+\\)"))
3919 (browse-url node)
3920 (setq node t))
3921 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
3922 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3923 (Info-follow-reference node fork))
3924 ;; footnote
3925 ((setq node (Info-get-token (point) "(" "\\(([0-9]+)\\)"))
3926 (let ((old-point (point)) new-point)
3927 (save-excursion
3928 (goto-char (point-min))
3929 (when (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t)
3930 (setq new-point (if (< old-point (point))
3931 ;; Go to footnote reference
3932 (and (search-forward node nil t)
3933 ;; Put point at beginning of link
3934 (match-beginning 0))
3935 ;; Go to footnote definition
3936 (search-backward node nil t)))))
3937 (if new-point
3938 (progn
3939 (goto-char new-point)
3940 (setq node t))
3941 (setq node nil))))
3942 ;; menu item: node name
3943 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3944 (Info-goto-node node fork))
3945 ;; menu item: node name or index entry
3946 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3947 (beginning-of-line)
3948 (forward-char 2)
3949 (setq node (Info-extract-menu-node-name nil (Info-index-node)))
3950 (Info-goto-node node fork))
3951 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3952 (Info-goto-node node fork))
3953 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3954 (Info-goto-node node fork))
3955 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3956 (Info-goto-node "Top" fork))
3957 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3958 (Info-goto-node node fork)))
3959 node))
3961 (defun Info-mouse-follow-link (click)
3962 "Follow a link where you click."
3963 (interactive "@e")
3964 (let* ((position (event-start click))
3965 (posn-string (and position (posn-string position)))
3966 (link-args (if posn-string
3967 (get-text-property (cdr posn-string)
3968 'link-args
3969 (car posn-string))
3970 (get-char-property (posn-point position)
3971 'link-args))))
3972 (cond ((stringp link-args)
3973 (Info-goto-node link-args))
3974 ;; These special values of the `link-args' property are used
3975 ;; for navigation; see `Info-fontify-node'.
3976 ((eq link-args 'prev) (Info-prev))
3977 ((eq link-args 'next) (Info-next))
3978 ((eq link-args 'up) (Info-up)))))
3981 (defvar Info-mode-map
3982 (let ((map (make-keymap)))
3983 (suppress-keymap map)
3984 (define-key map "." 'beginning-of-buffer)
3985 (define-key map " " 'Info-scroll-up)
3986 (define-key map [?\S-\ ] 'Info-scroll-down)
3987 (define-key map "\C-m" 'Info-follow-nearest-node)
3988 (define-key map "\t" 'Info-next-reference)
3989 (define-key map "\e\t" 'Info-prev-reference)
3990 (define-key map [backtab] 'Info-prev-reference)
3991 (define-key map "1" 'Info-nth-menu-item)
3992 (define-key map "2" 'Info-nth-menu-item)
3993 (define-key map "3" 'Info-nth-menu-item)
3994 (define-key map "4" 'Info-nth-menu-item)
3995 (define-key map "5" 'Info-nth-menu-item)
3996 (define-key map "6" 'Info-nth-menu-item)
3997 (define-key map "7" 'Info-nth-menu-item)
3998 (define-key map "8" 'Info-nth-menu-item)
3999 (define-key map "9" 'Info-nth-menu-item)
4000 (define-key map "0" 'undefined)
4001 (define-key map "?" 'Info-summary)
4002 (define-key map "]" 'Info-forward-node)
4003 (define-key map "[" 'Info-backward-node)
4004 (define-key map "<" 'Info-top-node)
4005 (define-key map ">" 'Info-final-node)
4006 (define-key map "b" 'beginning-of-buffer)
4007 (put 'beginning-of-buffer :advertised-binding "b")
4008 (define-key map "d" 'Info-directory)
4009 (define-key map "e" 'end-of-buffer)
4010 (define-key map "f" 'Info-follow-reference)
4011 (define-key map "g" 'Info-goto-node)
4012 (define-key map "h" 'Info-help)
4013 ;; This is for compatibility with standalone info (>~ version 5.2).
4014 ;; Though for some time, standalone info had H and h reversed.
4015 ;; See <http://debbugs.gnu.org/16455>.
4016 (define-key map "H" 'describe-mode)
4017 (define-key map "i" 'Info-index)
4018 (define-key map "I" 'Info-virtual-index)
4019 (define-key map "l" 'Info-history-back)
4020 (define-key map "L" 'Info-history)
4021 (define-key map "m" 'Info-menu)
4022 (define-key map "n" 'Info-next)
4023 (define-key map "p" 'Info-prev)
4024 (define-key map "q" 'Info-exit)
4025 (define-key map "r" 'Info-history-forward)
4026 (define-key map "s" 'Info-search)
4027 (define-key map "S" 'Info-search-case-sensitively)
4028 (define-key map "\M-n" 'clone-buffer)
4029 (define-key map "t" 'Info-top-node)
4030 (define-key map "T" 'Info-toc)
4031 (define-key map "u" 'Info-up)
4032 ;; `w' for consistency with `dired-copy-filename-as-kill'.
4033 (define-key map "w" 'Info-copy-current-node-name)
4034 (define-key map "c" 'Info-copy-current-node-name)
4035 ;; `^' for consistency with `dired-up-directory'.
4036 (define-key map "^" 'Info-up)
4037 (define-key map "," 'Info-index-next)
4038 (define-key map "\177" 'Info-scroll-down)
4039 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
4040 (define-key map [follow-link] 'mouse-face)
4041 (define-key map [XF86Back] 'Info-history-back)
4042 (define-key map [XF86Forward] 'Info-history-forward)
4043 map)
4044 "Keymap containing Info commands.")
4047 (defun Info-check-pointer (item)
4048 "Non-nil if ITEM is present in this node."
4049 (condition-case nil
4050 (Info-extract-pointer item)
4051 (error nil)))
4053 (easy-menu-define
4054 Info-mode-menu Info-mode-map
4055 "Menu for Info files."
4056 '("Info"
4057 ["Up" Info-up :active (Info-check-pointer "up")
4058 :help "Go up in the Info tree"]
4059 ["Next" Info-next :active (Info-check-pointer "next")
4060 :help "Go to the next node"]
4061 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
4062 :help "Go to the previous node"]
4063 ["Backward" Info-backward-node
4064 :help "Go backward one node, considering all as a sequence"]
4065 ["Forward" Info-forward-node
4066 :help "Go forward one node, considering all as a sequence"]
4067 ["Beginning" beginning-of-buffer
4068 :help "Go to beginning of this node"]
4069 ["Top" Info-top-node
4070 :help "Go to top node of file"]
4071 ["Final Node" Info-final-node
4072 :help "Go to final node in this file"]
4073 ("Menu Item" ["You should never see this" report-emacs-bug t])
4074 ("Reference" ["You should never see this" report-emacs-bug t])
4075 ["Search..." Info-search
4076 :help "Search for regular expression in this Info file"]
4077 ["Search Next" Info-search-next
4078 :help "Search for another occurrence of regular expression"]
4079 ["Go to Node..." Info-goto-node
4080 :help "Go to a named node"]
4081 ["Back in history" Info-history-back :active Info-history
4082 :help "Go back in history to the last node you were at"]
4083 ["Forward in history" Info-history-forward :active Info-history-forward
4084 :help "Go forward in history"]
4085 ["History" Info-history :active Info-history-list
4086 :help "Go to menu of visited nodes"]
4087 ["Table of Contents" Info-toc
4088 :help "Go to table of contents"]
4089 ("Index"
4090 ["Lookup a String..." Info-index
4091 :help "Look for a string in the index items"]
4092 ["Next Matching Item" Info-index-next :active Info-index-alternatives
4093 :help "Look for another occurrence of previous item"]
4094 ["Lookup a string and display index of results..." Info-virtual-index
4095 :help "Look for a string in the index items and display node with results"]
4096 ["Lookup a string in all indices..." info-apropos
4097 :help "Look for a string in the indices of all manuals"])
4098 ["Copy Node Name" Info-copy-current-node-name
4099 :help "Copy the name of the current node into the kill ring"]
4100 ["Clone Info buffer" clone-buffer
4101 :help "Create a twin copy of the current Info buffer."]
4102 ["Exit" Info-exit :help "Stop reading Info"]))
4105 (defvar info-tool-bar-map
4106 (let ((map (make-sparse-keymap)))
4107 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
4108 :rtl "right-arrow"
4109 :label "Back"
4110 :vert-only t)
4111 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
4112 :rtl "left-arrow"
4113 :label "Forward"
4114 :vert-only t)
4115 (define-key-after map [separator-1] menu-bar-separator)
4116 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
4117 :rtl "next-node")
4118 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
4119 :rtl "prev-node")
4120 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
4121 :vert-only t)
4122 (define-key-after map [separator-2] menu-bar-separator)
4123 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
4124 :vert-only t)
4125 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
4126 (define-key-after map [separator-3] menu-bar-separator)
4127 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
4128 :label "Index")
4129 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
4130 :vert-only t)
4131 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
4132 :vert-only t)
4133 map))
4135 (defvar Info-menu-last-node nil)
4136 ;; Last node the menu was created for.
4137 ;; Value is a list, (FILE-NAME NODE-NAME).
4139 (defun Info-menu-update ()
4140 "Update the Info menu for the current node."
4141 (condition-case nil
4142 (if (or (not (derived-mode-p 'Info-mode))
4143 (equal (list Info-current-file Info-current-node)
4144 Info-menu-last-node))
4146 ;; Update menu menu.
4147 (let* ((Info-complete-menu-buffer (current-buffer))
4148 (items (nreverse (condition-case nil
4149 (Info-complete-menu-item "" nil t)
4150 (error nil))))
4151 entries current
4152 (number 0))
4153 (while (and items (< number 9))
4154 (setq current (car items)
4155 items (cdr items)
4156 number (1+ number))
4157 (setq entries (cons `[,current
4158 (Info-menu ,current)
4159 :keys ,(format "%d" number)]
4160 entries)))
4161 (if items
4162 (setq entries (cons ["Other..." Info-menu t] entries)))
4163 (or entries
4164 (setq entries (list ["No menu" nil nil] nil :active)))
4165 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
4166 ;; Update reference menu. Code stolen from `Info-follow-reference'.
4167 (let ((items nil)
4168 str i entries current
4169 (number 0)
4170 (case-fold-search t))
4171 (save-excursion
4172 (goto-char (point-min))
4173 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
4174 (setq str (match-string 1))
4175 (setq i 0)
4176 (while (setq i (string-match "[ \n\t]+" str i))
4177 (setq str (concat (substring str 0 i) " "
4178 (substring str (match-end 0))))
4179 (setq i (1+ i)))
4180 (setq items
4181 (cons str items))))
4182 (while (and items (< number 9))
4183 (setq current (car items)
4184 items (cdr items)
4185 number (1+ number))
4186 (setq entries (cons `[,current
4187 (Info-follow-reference ,current)
4189 entries)))
4190 (if items
4191 (setq entries (cons ["Other..." Info-follow-reference t]
4192 entries)))
4193 (or entries
4194 (setq entries (list ["No references" nil nil] nil :active)))
4195 (easy-menu-change '("Info") "Reference" (nreverse entries)))
4196 ;; Update last seen node.
4197 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
4198 ;; Try to avoid entering infinite beep mode in case of errors.
4199 (error (ding))))
4202 (defun Info-copy-current-node-name (&optional arg)
4203 "Put the name of the current Info node into the kill ring.
4204 The name of the Info file is prepended to the node name in parentheses.
4205 With a zero prefix arg, put the name inside a function call to `info'."
4206 (interactive "P")
4207 (unless Info-current-node
4208 (user-error "No current Info node"))
4209 (let ((node (if (stringp Info-current-file)
4210 (concat "(" (file-name-sans-extension
4211 (file-name-nondirectory Info-current-file))
4212 ") "
4213 Info-current-node))))
4214 (if (zerop (prefix-numeric-value arg))
4215 (setq node (concat "(info \"" node "\")")))
4216 (unless (stringp Info-current-file)
4217 (setq node (format "(Info-find-node '%S '%S)"
4218 Info-current-file Info-current-node)))
4219 (kill-new node)
4220 (message "%s" node)))
4223 ;; Info mode is suitable only for specially formatted data.
4224 (put 'Info-mode 'mode-class 'special)
4225 (put 'Info-mode 'no-clone-indirect t)
4227 (defvar tool-bar-map)
4228 (defvar bookmark-make-record-function)
4230 (defvar Info-mode-syntax-table
4231 (let ((st (copy-syntax-table text-mode-syntax-table)))
4232 ;; Use punctuation syntax for apostrophe because of
4233 ;; extensive use of quotes like `this' in Info manuals.
4234 (modify-syntax-entry ?' "." st)
4236 "Syntax table used in `Info-mode'.")
4238 (defface Info-quoted
4239 '((t :family "courier"))
4240 "Face used for quoted elements.")
4242 (defvar Info-mode-font-lock-keywords
4243 '(("‘\\([^’]*\\)’" (1 'Info-quoted))))
4245 ;; Autoload cookie needed by desktop.el
4246 ;;;###autoload
4247 (define-derived-mode Info-mode nil "Info" ;FIXME: Derive from special-mode?
4248 "Info mode provides commands for browsing through the Info documentation tree.
4249 Documentation in Info is divided into \"nodes\", each of which discusses
4250 one topic and contains references to other nodes which discuss related
4251 topics. Info has commands to follow the references and show you other nodes.
4253 \\<Info-mode-map>\
4254 \\[Info-help] Invoke the Info tutorial.
4255 \\[Info-exit] Quit Info: reselect previously selected buffer.
4257 Selecting other nodes:
4258 \\[Info-mouse-follow-nearest-node]
4259 Follow a node reference you click on.
4260 This works with menu items, cross references, and
4261 the \"next\", \"previous\" and \"up\", depending on where you click.
4262 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
4263 \\[Info-next] Move to the \"next\" node of this node.
4264 \\[Info-prev] Move to the \"previous\" node of this node.
4265 \\[Info-up] Move \"up\" from this node.
4266 \\[Info-menu] Pick menu item specified by name (or abbreviation).
4267 Picking a menu item causes another node to be selected.
4268 \\[Info-directory] Go to the Info directory node.
4269 \\[Info-top-node] Go to the Top node of this file.
4270 \\[Info-final-node] Go to the final node in this file.
4271 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
4272 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
4273 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
4274 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
4275 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
4276 \\[Info-history-back] Move back in history to the last node you were at.
4277 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
4278 \\[Info-history] Go to menu of visited nodes.
4279 \\[Info-toc] Go to table of contents of the current Info file.
4281 Moving within a node:
4282 \\[Info-scroll-up] Normally, scroll forward a full screen.
4283 Once you scroll far enough in a node that its menu appears on the
4284 screen but after point, the next scroll moves into its first
4285 subnode. When after all menu items (or if there is no menu),
4286 move up to the parent node.
4287 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
4288 already visible, try to go to the previous menu entry, or up
4289 if there is none.
4290 \\[beginning-of-buffer] Go to beginning of node.
4292 Advanced commands:
4293 \\[Info-search] Search through this Info file for specified regexp,
4294 and select the node in which the next occurrence is found.
4295 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
4296 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
4297 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
4298 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
4299 \\[Info-virtual-index] Look for a string and display the index node with results.
4300 \\[info-apropos] Look for a string in the indices of all manuals.
4301 \\[Info-goto-node] Move to node specified by name.
4302 You may include a filename as well, as (FILENAME)NODENAME.
4303 1 .. 9 Pick first ... ninth item in node's menu.
4304 Every third `*' is highlighted to help pick the right number.
4305 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
4306 \\[clone-buffer] Select a new cloned Info buffer in another window.
4307 \\[universal-argument] \\[info] Move to new Info file with completion.
4308 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
4309 :syntax-table Info-mode-syntax-table
4310 :abbrev-table text-mode-abbrev-table
4311 (setq tab-width 8)
4312 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
4313 (setq case-fold-search t)
4314 (setq buffer-read-only t)
4315 (setq Info-tag-table-marker (make-marker))
4316 (if Info-use-header-line ; do not override global header lines
4317 (setq header-line-format
4318 '(:eval (get-text-property (point-min) 'header-line))))
4319 (setq-local tool-bar-map info-tool-bar-map)
4320 ;; This is for the sake of the invisible text we use handling titles.
4321 (setq-local line-move-ignore-invisible t)
4322 (setq-local desktop-save-buffer 'Info-desktop-buffer-misc-data)
4323 (setq-local widen-automatically nil)
4324 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
4325 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
4326 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
4327 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
4328 (setq-local isearch-search-fun-function #'Info-isearch-search)
4329 (setq-local isearch-wrap-function #'Info-isearch-wrap)
4330 (setq-local isearch-push-state-function #'Info-isearch-push-state)
4331 (setq-local isearch-filter-predicate #'Info-isearch-filter)
4332 (setq-local revert-buffer-function #'Info-revert-buffer-function)
4333 (setq-local font-lock-defaults '(Info-mode-font-lock-keywords t t))
4334 (Info-set-mode-line)
4335 (setq-local bookmark-make-record-function #'Info-bookmark-make-record))
4337 ;; When an Info buffer is killed, make sure the associated tags buffer
4338 ;; is killed too.
4339 (defun Info-kill-buffer ()
4340 (and (derived-mode-p 'Info-mode)
4341 Info-tag-table-buffer
4342 (kill-buffer Info-tag-table-buffer)))
4344 ;; Placed on `clone-buffer-hook'.
4345 (defun Info-clone-buffer ()
4346 (when (bufferp Info-tag-table-buffer)
4347 (setq Info-tag-table-buffer
4348 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4349 (let ((m Info-tag-table-marker))
4350 (when (markerp m)
4351 (setq Info-tag-table-marker
4352 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4353 (with-current-buffer Info-tag-table-buffer
4354 (copy-marker (marker-position m)))
4355 (make-marker))))))
4357 (define-obsolete-variable-alias 'Info-edit-map 'Info-edit-mode-map "24.1")
4358 (defvar Info-edit-mode-map (let ((map (make-sparse-keymap)))
4359 (set-keymap-parent map text-mode-map)
4360 (define-key map "\C-c\C-c" 'Info-cease-edit)
4361 map)
4362 "Local keymap used within `e' command of Info.")
4364 (make-obsolete-variable 'Info-edit-mode-map
4365 "editing Info nodes by hand is not recommended."
4366 "24.4")
4368 ;; Info-edit mode is suitable only for specially formatted data.
4369 (put 'Info-edit-mode 'mode-class 'special)
4371 (define-derived-mode Info-edit-mode text-mode "Info Edit"
4372 "Major mode for editing the contents of an Info node.
4373 Like text mode with the addition of `Info-cease-edit'
4374 which returns to Info mode for browsing."
4375 (setq buffer-read-only nil)
4376 (force-mode-line-update)
4377 (buffer-enable-undo (current-buffer)))
4379 (make-obsolete 'Info-edit-mode
4380 "editing Info nodes by hand is not recommended." "24.4")
4382 (defun Info-edit ()
4383 "Edit the contents of this Info node."
4384 (interactive)
4385 (Info-edit-mode)
4386 (message "%s" (substitute-command-keys
4387 "Editing: Type \\<Info-edit-mode-map>\\[Info-cease-edit] to return to info")))
4389 (put 'Info-edit 'disabled "Editing Info nodes by hand is not recommended.
4390 This feature will be removed in future.")
4392 (make-obsolete 'Info-edit
4393 "editing Info nodes by hand is not recommended." "24.4")
4395 (defun Info-cease-edit ()
4396 "Finish editing Info node; switch back to Info proper."
4397 (interactive)
4398 ;; Do this first, so nothing has changed if user C-g's at query.
4399 (and (buffer-modified-p)
4400 (y-or-n-p "Save the file? ")
4401 (save-buffer))
4402 (Info-mode)
4403 (force-mode-line-update)
4404 (and (marker-position Info-tag-table-marker)
4405 (buffer-modified-p)
4406 (message "Tags may have changed. Use Info-tagify if necessary")))
4408 (make-obsolete 'Info-cease-edit
4409 "editing Info nodes by hand is not recommended." "24.4")
4411 (defvar Info-file-list-for-emacs
4412 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4413 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4414 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4415 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4416 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4417 ("copyright" . "autotype") ("executable" . "autotype")
4418 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4419 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4420 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4421 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4422 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4423 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4424 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4425 ("rfc2045" . "emacs-mime")
4426 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4427 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4428 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4429 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4430 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4431 ("mml" . "emacs-mime")
4432 "tramp" "dbus")
4433 "List of Info files that describe Emacs commands.
4434 An element can be a file name, or a list of the form (PREFIX . FILE)
4435 where PREFIX is a name prefix and FILE is the file to look in.
4436 If the element is just a file name, the file name also serves as the prefix.")
4438 (defun Info-find-emacs-command-nodes (command)
4439 "Return a list of locations documenting COMMAND.
4440 The `info-file' property of COMMAND says which Info manual to search.
4441 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4442 defines heuristics for which Info manual to try.
4443 The locations are of the format used in the variable `Info-history', i.e.
4444 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4445 in the first element of the returned list (which is treated specially in
4446 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4447 (let ((where '()) line-number
4448 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4449 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4450 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4451 (info-file "emacs")) ;default
4452 ;; Determine which Info file this command is documented in.
4453 (if (get command 'info-file)
4454 (setq info-file (get command 'info-file))
4455 ;; If it doesn't say explicitly, test its name against
4456 ;; various prefixes that we know.
4457 (let ((file-list Info-file-list-for-emacs))
4458 (while file-list
4459 (let* ((elt (car file-list))
4460 (name (if (consp elt)
4461 (car elt)
4462 elt))
4463 (file (if (consp elt) (cdr elt) elt))
4464 (case-fold-search nil)
4465 (regexp (concat "\\`" (regexp-quote name)
4466 "\\(\\'\\|-\\)")))
4467 (if (string-match regexp (symbol-name command))
4468 (setq info-file file file-list nil))
4469 (setq file-list (cdr file-list))))))
4470 (Info-find-node info-file "Top")
4471 ;; Bind Info-history to nil, to prevent the index nodes from
4472 ;; getting into the node history.
4473 (let ((Info-history nil)
4474 (Info-history-list nil)
4475 node (nodes (Info-index-nodes)))
4476 (Info-goto-node (car nodes))
4477 (while
4478 (progn
4479 (goto-char (point-min))
4480 (while (re-search-forward cmd-desc nil t)
4481 (setq where
4482 (cons (list Info-current-file
4483 (match-string-no-properties 2)
4485 where))
4486 (setq line-number (and (match-beginning 3)
4487 (string-to-number (match-string 3)))))
4488 (and (setq nodes (cdr nodes) node (car nodes))))
4489 (Info-goto-node node)))
4490 (if (and line-number where)
4491 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4492 (cdr where))
4493 where)))
4495 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4496 ;;;###autoload
4497 (defun Info-goto-emacs-command-node (command)
4498 "Go to the Info node in the Emacs manual for command COMMAND.
4499 The command is found by looking up in Emacs manual's indices
4500 or in another manual found via COMMAND's `info-file' property or
4501 the variable `Info-file-list-for-emacs'.
4502 COMMAND must be a symbol or string."
4503 (interactive "CFind documentation for command: ")
4504 ;; If command is given as a string, convert it to a symbol.
4505 (if (stringp command)
4506 (setq command (intern command)))
4507 (or (commandp command)
4508 (signal 'wrong-type-argument (list 'commandp command)))
4509 (let ((where (Info-find-emacs-command-nodes command)))
4510 (if where
4511 (let ((num-matches (length where)))
4512 ;; Get Info running, and pop to it in another window.
4513 (save-window-excursion
4514 (info))
4515 (or (derived-mode-p 'Info-mode) (pop-to-buffer "*info*"))
4516 ;; Bind Info-history to nil, to prevent the last Index node
4517 ;; visited by Info-find-emacs-command-nodes from being
4518 ;; pushed onto the history.
4519 (let ((Info-history nil) (Info-history-list nil)
4520 (line-number (nth 2 (car where))))
4521 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4522 (if (and (integerp line-number) (> line-number 0))
4523 (forward-line (1- line-number))))
4524 (if (> num-matches 1)
4525 (progn
4526 ;; (car where) will be pushed onto Info-history
4527 ;; when/if they go to another node. Put the other
4528 ;; nodes that were found on the history.
4529 (setq Info-history (nconc (cdr where) Info-history))
4530 (message "Found %d other entr%s. Use %s to see %s."
4531 (1- num-matches)
4532 (if (> num-matches 2) "ies" "y")
4533 (substitute-command-keys "\\[Info-history-back]")
4534 (if (> num-matches 2) "them" "it")))))
4535 (error "Couldn't find documentation for %s" command))))
4537 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4538 ;;;###autoload
4539 (defun Info-goto-emacs-key-command-node (key)
4540 "Go to the node in the Emacs manual which describes the command bound to KEY.
4541 KEY is a string.
4542 Interactively, if the binding is `execute-extended-command', a command is read.
4543 The command is found by looking up in Emacs manual's indices
4544 or in another manual found via COMMAND's `info-file' property or
4545 the variable `Info-file-list-for-emacs'."
4546 (interactive "kFind documentation for key: ")
4547 (let ((command (key-binding key)))
4548 (cond ((null command)
4549 (message "%s is undefined" (key-description key)))
4550 ((and (called-interactively-p 'interactive)
4551 (eq command 'execute-extended-command))
4552 (Info-goto-emacs-command-node
4553 (read-command "Find documentation for command: ")))
4555 (Info-goto-emacs-command-node command)))))
4557 (defvar Info-link-keymap
4558 (let ((keymap (make-sparse-keymap)))
4559 (define-key keymap [header-line down-mouse-1] 'mouse-drag-header-line)
4560 (define-key keymap [header-line mouse-1] 'mouse-select-window)
4561 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4562 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4563 (define-key keymap [follow-link] 'mouse-face)
4564 keymap)
4565 "Keymap to put on Info links.
4566 This is used for the \"Next\", \"Prev\", and \"Up\" links in the
4567 first line or header line, and for breadcrumb links.")
4569 (defun Info-breadcrumbs ()
4570 (let ((nodes (Info-toc-nodes Info-current-file))
4571 (node Info-current-node)
4572 (crumbs ())
4573 (depth Info-breadcrumbs-depth)
4574 line)
4576 ;; Get ancestors from the cached parent-children node info
4577 (while (and (not (equal "Top" node)) (> depth 0))
4578 (setq node (nth 1 (assoc node nodes)))
4579 (if node (push node crumbs))
4580 (setq depth (1- depth)))
4582 ;; Add bottom node.
4583 (when Info-use-header-line
4584 ;; Let it disappear if crumbs is nil.
4585 (nconc crumbs (list Info-current-node)))
4586 (when (or Info-use-header-line crumbs)
4587 ;; Add top node (and continuation if needed).
4588 (setq crumbs
4589 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4590 crumbs (cons nil crumbs))))
4591 ;; Eliminate duplicate.
4592 (forward-line 1)
4593 (dolist (node crumbs)
4594 (let ((text
4595 (if (not (equal node "Top")) node
4596 (format "(%s)Top"
4597 (if (stringp Info-current-file)
4598 (file-name-sans-extension
4599 (file-name-nondirectory Info-current-file))
4600 ;; Some legacy code can still use a symbol.
4601 Info-current-file)))))
4602 (setq line (concat
4603 line
4604 (if (null line) "" " > ")
4605 (cond
4606 ((null node) "...")
4607 ((equal node Info-current-node)
4608 ;; No point linking to ourselves.
4609 (propertize text 'font-lock-face 'info-header-node))
4611 (propertize text
4612 'mouse-face 'highlight
4613 'font-lock-face 'info-header-xref
4614 'help-echo "mouse-2: Go to node"
4615 'keymap Info-link-keymap
4616 'link-args text)))))))
4617 (setq line (concat line "\n")))
4618 ;; (font-lock-append-text-property 0 (length line)
4619 ;; 'font-lock-face 'header-line line)
4620 line))
4622 (defun Info-fontify-node ()
4623 "Fontify the node."
4624 (save-excursion
4625 (let* ((inhibit-read-only t)
4626 (case-fold-search t)
4627 paragraph-markers
4628 (not-fontified-p ; the node hasn't already been fontified
4629 (not (let ((where (next-single-property-change (point-min)
4630 'font-lock-face)))
4631 (and where (not (= where (point-max)))))))
4632 (fontify-visited-p ; visited nodes need to be re-fontified
4633 (and Info-fontify-visited-nodes
4634 ;; Don't take time to refontify visited nodes in huge nodes
4635 Info-fontify-maximum-menu-size
4636 (or (eq Info-fontify-maximum-menu-size t)
4637 (< (- (point-max) (point-min))
4638 Info-fontify-maximum-menu-size))))
4639 rbeg rend)
4641 ;; Fontify header line
4642 (goto-char (point-min))
4643 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4644 (goto-char (match-end 0))
4645 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4646 (goto-char (match-end 0))
4647 (let* ((nbeg (match-beginning 2))
4648 (nend (match-end 2))
4649 (tbeg (match-beginning 1))
4650 (tag (match-string 1)))
4651 (if (string-equal (downcase tag) "node")
4652 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4653 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4654 (put-text-property tbeg nend 'mouse-face 'highlight)
4655 (put-text-property tbeg nend
4656 'help-echo
4657 (concat "mouse-2: Go to node "
4658 (buffer-substring nbeg nend)))
4659 ;; Set up the text property keymap. Depending on
4660 ;; `Info-use-header-line', it is either used in the
4661 ;; buffer, or copied to the header line. A symbol value
4662 ;; of the `link-args' property is handled specially by
4663 ;; `Info-mouse-follow-link'.
4664 (put-text-property tbeg nend 'keymap Info-link-keymap)
4665 (put-text-property tbeg nend 'link-args
4666 (intern (downcase tag))))))
4668 ;; (when (> Info-breadcrumbs-depth 0)
4669 ;; (insert (Info-breadcrumbs)))
4671 ;; Treat header line.
4672 (when Info-use-header-line
4673 (goto-char (point-min))
4674 (let* ((header-end (line-end-position))
4675 (header
4676 ;; If we find neither Next: nor Prev: link, show the entire
4677 ;; node header. Otherwise, don't show the File: and Node:
4678 ;; parts, to avoid wasting precious space on information that
4679 ;; is available in the mode line.
4680 (if (re-search-forward
4681 "\\(next\\|up\\|prev[ious]*\\): "
4682 header-end t)
4683 (progn
4684 (goto-char (match-beginning 1))
4685 (buffer-substring (point) header-end))
4686 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4687 header-end t)
4688 (concat "No next, prev or up links -- "
4689 (buffer-substring (point) header-end))
4690 (buffer-substring (point) header-end)))))
4691 (put-text-property (point-min) (1+ (point-min))
4692 'header-line
4693 (replace-regexp-in-string
4695 ;; Preserve text properties on duplicated `%'.
4696 (lambda (s) (concat s s)) header))
4697 ;; Hide the part of the first line
4698 ;; that is in the header, if it is just part.
4699 (cond
4700 ((> Info-breadcrumbs-depth 0)
4701 (let ((ov (make-overlay (point-min) (1+ header-end))))
4702 (overlay-put ov 'display (Info-breadcrumbs))
4703 (overlay-put ov 'evaporate t)))
4704 ((not (bobp))
4705 ;; Hide the punctuation at the end, too.
4706 (skip-chars-backward " \t,")
4707 (put-text-property (point) header-end 'invisible t)
4708 ;; Hide the suffix of the Info file name.
4709 (beginning-of-line)
4710 (if (re-search-forward
4711 (format "File: %s\\([^,\n\t]+\\),"
4712 (if (stringp Info-current-file)
4713 (file-name-sans-extension
4714 (file-name-nondirectory Info-current-file))
4715 Info-current-file))
4716 header-end t)
4717 (put-text-property (match-beginning 1) (match-end 1)
4718 'invisible t)))))))
4720 ;; Fontify titles
4721 (goto-char (point-min))
4722 (when (and font-lock-mode not-fontified-p)
4723 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4724 nil t)
4725 ;; Only consider it as an underlined title if the ASCII
4726 ;; underline has the same size as the text. A typical
4727 ;; counter example is when a continuation "..." is alone
4728 ;; on a line.
4729 (when (= (string-width (match-string 1))
4730 (string-width (match-string 2)))
4731 (let* ((c (preceding-char))
4732 (face
4733 (cond ((= c ?*) 'info-title-1)
4734 ((= c ?=) 'info-title-2)
4735 ((= c ?-) 'info-title-3)
4736 (t 'info-title-4))))
4737 (put-text-property (match-beginning 1) (match-end 1)
4738 'font-lock-face face))
4739 ;; This is a serious problem for trying to handle multiple
4740 ;; frame types at once. We want this text to be invisible
4741 ;; on frames that can display the font above.
4742 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4743 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4744 '(invisible t front-sticky nil rear-nonsticky t))))))
4746 ;; Fontify cross references
4747 (goto-char (point-min))
4748 (when (or not-fontified-p fontify-visited-p)
4749 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4750 (let ((start (match-beginning 0))
4751 (next (point))
4752 other-tag)
4753 (when not-fontified-p
4754 (when Info-hide-note-references
4755 (when (and (not (eq Info-hide-note-references 'hide))
4756 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4757 ;; *Note is often used where *note should have been
4758 (goto-char start)
4759 (skip-syntax-backward " ")
4760 (when (memq (char-before) '(?\( ?\[ ?\{))
4761 ;; Check whether the paren is preceded by
4762 ;; an end of sentence
4763 (skip-syntax-backward " ("))
4764 (setq other-tag
4765 (cond ((save-match-data (looking-back "\\<see"
4766 (- (point) 3)))
4768 ((save-match-data (looking-back "\\<in"
4769 (- (point) 2)))
4771 ((memq (char-before) '(nil ?\. ?! ??))
4772 "See ")
4773 ((save-match-data
4774 (save-excursion
4775 (search-forward "\n\n" start t)))
4776 "See ")
4777 (t "see "))))
4778 (goto-char next)
4779 (add-text-properties
4780 (match-beginning 1)
4781 (or (save-match-data
4782 ;; Don't hide \n after *Note
4783 (let ((start1 (match-beginning 1)))
4784 (if (string-match "\n" (match-string 1))
4785 (+ start1 (match-beginning 0)))))
4786 (match-end 1))
4787 (if other-tag
4788 `(display ,other-tag front-sticky nil rear-nonsticky t)
4789 '(invisible t front-sticky nil rear-nonsticky t))))
4790 (add-text-properties
4791 (match-beginning 2) (match-end 2)
4792 (list
4793 'help-echo (if (or (match-end 5)
4794 (not (equal (match-string 4) "")))
4795 (concat "mouse-2: go to " (or (match-string 5)
4796 (match-string 4)))
4797 "mouse-2: go to this node")
4798 'mouse-face 'highlight)))
4799 (when (or not-fontified-p fontify-visited-p)
4800 (setq rbeg (match-beginning 2)
4801 rend (match-end 2))
4802 (put-text-property
4803 rbeg rend
4804 'font-lock-face
4805 ;; Display visited nodes in a different face
4806 (if (and Info-fontify-visited-nodes
4807 (save-match-data
4808 (let* ((node (replace-regexp-in-string
4809 "^[ \t]+" ""
4810 (replace-regexp-in-string
4811 "[ \t\n]+" " "
4812 (or (match-string-no-properties 5)
4813 (and (not (equal (match-string 4) ""))
4814 (match-string-no-properties 4))
4815 (match-string-no-properties 2)))))
4816 (external-link-p
4817 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4818 (file (if external-link-p
4819 (file-name-nondirectory
4820 (match-string-no-properties 1 node))
4821 Info-current-file))
4822 (hl Info-history-list)
4823 res)
4824 (if external-link-p
4825 (setq node (if (equal (match-string 2 node) "")
4826 "Top"
4827 (match-string-no-properties 2 node))))
4828 (while hl
4829 (if (and (string-equal node (nth 1 (car hl)))
4830 (equal file
4831 (if (and external-link-p
4832 (stringp (caar hl)))
4833 (file-name-nondirectory
4834 (caar hl))
4835 (caar hl))))
4836 (setq res (car hl) hl nil)
4837 (setq hl (cdr hl))))
4838 res))) 'info-xref-visited 'info-xref))
4839 ;; For multiline ref, unfontify newline and surrounding whitespace
4840 (save-excursion
4841 (goto-char rbeg)
4842 (save-match-data
4843 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4844 (remove-text-properties (match-beginning 0)
4845 (match-end 0)
4846 '(font-lock-face t))))))
4847 (when not-fontified-p
4848 (when (memq Info-hide-note-references '(t hide))
4849 (add-text-properties (match-beginning 3) (match-end 3)
4850 '(invisible t front-sticky nil rear-nonsticky t))
4851 ;; Unhide the file name of the external reference in parens
4852 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4853 (remove-text-properties (match-beginning 6) (match-end 6)
4854 '(invisible t front-sticky nil rear-nonsticky t)))
4855 ;; Unhide newline because hidden newlines cause too long lines
4856 (save-match-data
4857 (let ((beg3 (match-beginning 3))
4858 (end3 (match-end 3)))
4859 (if (and (string-match "\n[ \t]*" (match-string 3))
4860 (not (save-match-data
4861 (save-excursion
4862 (goto-char (1+ end3))
4863 (looking-at "[.)]*$")))))
4864 (remove-text-properties (+ beg3 (match-beginning 0))
4865 (+ beg3 (match-end 0))
4866 '(invisible t front-sticky nil rear-nonsticky t))))))
4867 (when (and Info-refill-paragraphs Info-hide-note-references)
4868 (push (set-marker (make-marker) start)
4869 paragraph-markers))))))
4871 ;; Refill paragraphs (experimental feature)
4872 (when (and not-fontified-p
4873 Info-refill-paragraphs
4874 paragraph-markers)
4875 (let ((fill-nobreak-invisible t)
4876 (fill-individual-varying-indent nil)
4877 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4878 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4879 (adaptive-fill-mode nil))
4880 (goto-char (point-max))
4881 (dolist (m paragraph-markers)
4882 (when (< m (point))
4883 (goto-char m)
4884 (beginning-of-line)
4885 (let ((beg (point)))
4886 (when (zerop (forward-paragraph))
4887 (fill-individual-paragraphs beg (point) nil nil)
4888 (goto-char beg))))
4889 (set-marker m nil))))
4891 ;; Fontify menu items
4892 (goto-char (point-min))
4893 (when (and (or not-fontified-p fontify-visited-p)
4894 (search-forward "\n* Menu:" nil t)
4895 ;; Don't take time to annotate huge menus
4896 Info-fontify-maximum-menu-size
4897 (or (eq Info-fontify-maximum-menu-size t)
4898 (< (- (point-max) (point))
4899 Info-fontify-maximum-menu-size)))
4900 (let ((n 0)
4901 cont)
4902 (while (re-search-forward
4903 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4904 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4905 nil t)
4906 (when (match-beginning 1)
4907 (when not-fontified-p
4908 (setq n (1+ n))
4909 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4910 (put-text-property (match-beginning 0)
4911 (1+ (match-beginning 0))
4912 'font-lock-face 'info-menu-star)))
4913 (when not-fontified-p
4914 (add-text-properties
4915 (match-beginning 1) (match-end 1)
4916 (list
4917 'help-echo (if (and (match-end 3)
4918 (not (equal (match-string 3) "")))
4919 (concat "mouse-2: go to " (match-string 3))
4920 "mouse-2: go to this node")
4921 'mouse-face 'highlight)))
4922 (when (or not-fontified-p fontify-visited-p)
4923 (put-text-property
4924 (match-beginning 1) (match-end 1)
4925 'font-lock-face
4926 ;; Display visited menu items in a different face
4927 (if (and Info-fontify-visited-nodes
4928 (save-match-data
4929 (let* ((node (if (equal (match-string 3) "")
4930 (match-string-no-properties 1)
4931 (match-string-no-properties 3)))
4932 (external-link-p
4933 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4934 (file (if external-link-p
4935 (file-name-nondirectory
4936 (match-string-no-properties 1 node))
4937 Info-current-file))
4938 (hl Info-history-list)
4939 res)
4940 (if external-link-p
4941 (setq node (if (equal (match-string 2 node) "")
4942 "Top"
4943 (match-string-no-properties 2 node))))
4944 (while hl
4945 (if (and (string-equal node (nth 1 (car hl)))
4946 (equal file
4947 (if (and external-link-p
4948 (stringp (caar hl)))
4949 (file-name-nondirectory
4950 (caar hl))
4951 (caar hl))))
4952 (setq res (car hl) hl nil)
4953 (setq hl (cdr hl))))
4954 res))) 'info-xref-visited 'info-xref)))
4955 (when (and not-fontified-p
4956 (memq Info-hide-note-references '(t hide))
4957 (not (Info-index-node)))
4958 (put-text-property (match-beginning 2) (1- (match-end 6))
4959 'invisible t)
4960 ;; Unhide the file name in parens
4961 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4962 (remove-text-properties (match-beginning 4) (match-end 4)
4963 '(invisible t)))
4964 ;; We need a stretchable space like :align-to but with
4965 ;; a minimum value.
4966 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4967 (if (>= 22 (- (match-end 1)
4968 (match-beginning 0)))
4969 '(space :align-to 24)
4970 '(space :width 2)))
4971 (setq cont (looking-at "."))
4972 (while (and (= (forward-line 1) 0)
4973 (looking-at "\\([ \t]+\\)[^*\n]"))
4974 (put-text-property (match-beginning 1) (1- (match-end 1))
4975 'invisible t)
4976 (put-text-property (1- (match-end 1)) (match-end 1)
4977 'display
4978 (if cont
4979 '(space :align-to 26)
4980 '(space :align-to 24)))
4981 (setq cont t)))))))
4983 ;; Fontify menu headers
4984 ;; Add the face `info-menu-header' to any header before a menu entry
4985 (goto-char (point-min))
4986 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4987 (put-text-property (match-beginning 0) (match-end 0)
4988 'font-lock-face 'info-menu-header)
4989 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4990 (put-text-property (match-beginning 1) (match-end 1)
4991 'font-lock-face 'info-menu-header)))
4993 ;; Hide index line numbers
4994 (goto-char (point-min))
4995 (when (and not-fontified-p (Info-index-node))
4996 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4997 (put-text-property (match-beginning 0) (match-end 0)
4998 'invisible t)))
5000 ;; Fontify http and ftp references
5001 (goto-char (point-min))
5002 (when not-fontified-p
5003 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`‘({<>})’']+"
5004 nil t)
5005 (add-text-properties (match-beginning 0) (match-end 0)
5006 '(font-lock-face info-xref
5007 mouse-face highlight
5008 help-echo "mouse-2: go to this URL"))))
5010 ;; Fontify footnotes
5011 (goto-char (point-min))
5012 (when (and not-fontified-p (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t))
5013 (let ((limit (point)))
5014 (goto-char (point-min))
5015 (while (re-search-forward "\\(([0-9]+)\\)" nil t)
5016 (add-text-properties (match-beginning 0) (match-end 0)
5017 `(font-lock-face info-xref
5018 link t
5019 mouse-face highlight
5020 help-echo
5021 ,(if (< (point) limit)
5022 "mouse-2: go to footnote definition"
5023 "mouse-2: go to footnote reference"))))))
5025 ;; Hide empty lines at the end of the node.
5026 (goto-char (point-max))
5027 (skip-chars-backward "\n")
5028 (when (< (point) (1- (point-max)))
5029 (put-text-property (point) (1- (point-max)) 'invisible t))
5031 (set-buffer-modified-p nil))))
5033 ;;; Speedbar support:
5034 ;; These functions permit speedbar to display the "tags" in the
5035 ;; current Info node.
5036 (eval-when-compile (require 'speedbar)) ; for speedbar-with-writable
5038 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
5039 (declare-function speedbar-center-buffer-smartly "speedbar" ())
5040 (declare-function speedbar-change-expand-button-char "speedbar" (char))
5041 (declare-function speedbar-change-initial-expansion-list "speedbar" (new-default))
5042 (declare-function speedbar-delete-subblock "speedbar" (indent))
5043 (declare-function speedbar-make-specialized-keymap "speedbar" ())
5044 (declare-function speedbar-make-tag-line "speedbar"
5045 (exp-button-type exp-button-char exp-button-function
5046 exp-button-data tag-button tag-button-function
5047 tag-button-data tag-button-face depth))
5049 (defvar Info-speedbar-key-map nil
5050 "Keymap used when in the Info display mode.")
5052 (defun Info-install-speedbar-variables ()
5053 "Install those variables used by speedbar to enhance Info."
5054 (if Info-speedbar-key-map
5056 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
5058 ;; Basic tree features
5059 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
5060 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
5061 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
5062 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
5065 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
5066 Info-speedbar-key-map
5067 Info-speedbar-hierarchy-buttons)))
5069 (defvar Info-speedbar-menu-items
5070 '(["Browse Node" speedbar-edit-line t]
5071 ["Expand Node" speedbar-expand-line
5072 (save-excursion (beginning-of-line)
5073 (looking-at "[0-9]+: *.\\+. "))]
5074 ["Contract Node" speedbar-contract-line
5075 (save-excursion (beginning-of-line)
5076 (looking-at "[0-9]+: *.-. "))]
5078 "Additional menu-items to add to speedbar frame.")
5080 ;; Make sure our special speedbar major mode is loaded
5081 (if (featurep 'speedbar)
5082 (Info-install-speedbar-variables)
5083 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
5085 ;;; Info hierarchy display method
5086 ;;;###autoload
5087 (defun Info-speedbar-browser ()
5088 "Initialize speedbar to display an Info node browser.
5089 This will add a speedbar major display mode."
5090 (interactive)
5091 (require 'speedbar)
5092 ;; Make sure that speedbar is active
5093 (speedbar-frame-mode 1)
5094 ;; Now, throw us into Info mode on speedbar.
5095 (speedbar-change-initial-expansion-list "Info")
5098 ;; speedbar loads dframe at runtime.
5099 (declare-function dframe-select-attached-frame "dframe" (&optional frame))
5100 (declare-function dframe-current-frame "dframe" (frame-var desired-major-mode))
5102 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
5103 "Display an Info directory hierarchy in speedbar.
5104 DIRECTORY is the current directory in the attached frame.
5105 DEPTH is the current indentation depth.
5106 NODE is an optional argument that is used to represent the
5107 specific node to expand."
5108 (if (and (not node)
5109 (save-excursion (goto-char (point-min))
5110 (let ((case-fold-search t))
5111 (looking-at "Info Nodes:"))))
5112 ;; Update our "current node" maybe?
5114 ;; We cannot use the generic list code, that depends on all leaves
5115 ;; being known at creation time.
5116 (if (not node)
5117 (speedbar-with-writable (insert "Info Nodes:\n")))
5118 (let ((completions nil))
5119 (speedbar-select-attached-frame)
5120 (save-window-excursion
5121 (setq completions
5122 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
5123 (select-frame (speedbar-current-frame))
5124 (if completions
5125 (speedbar-with-writable
5126 (dolist (completion completions)
5127 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
5128 (cdr completion)
5129 (car completion)
5130 'Info-speedbar-goto-node
5131 (cdr completion)
5132 'info-xref depth))
5134 nil))))
5136 (defun Info-speedbar-goto-node (_text node _indent)
5137 "When user clicks on TEXT, go to an info NODE.
5138 The INDENT level is ignored."
5139 (speedbar-select-attached-frame)
5140 (let* ((buff (or (get-buffer "*info*")
5141 (progn (info) (get-buffer "*info*"))))
5142 (bwin (get-buffer-window buff 0)))
5143 (if bwin
5144 (progn
5145 (select-window bwin)
5146 (raise-frame (window-frame bwin)))
5147 (if speedbar-power-click
5148 (switch-to-buffer-other-frame buff)
5149 (speedbar-select-attached-frame)
5150 (switch-to-buffer buff)))
5151 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
5152 (error "Invalid node %s" node)
5153 (Info-find-node (match-string 1 node) (match-string 2 node))
5154 ;; If we do a find-node, and we were in info mode, restore
5155 ;; the old default method. Once we are in info mode, it makes
5156 ;; sense to return to whatever method the user was using before.
5157 (if (string= speedbar-initial-expansion-list-name "Info")
5158 (speedbar-change-initial-expansion-list
5159 speedbar-previously-used-expansion-list-name)))))
5161 (defun Info-speedbar-expand-node (text token indent)
5162 "Expand the node the user clicked on.
5163 TEXT is the text of the button we clicked on, a + or - item.
5164 TOKEN is data related to this node (NAME . FILE).
5165 INDENT is the current indentation depth."
5166 (cond ((string-match "+" text) ;we have to expand this file
5167 (speedbar-change-expand-button-char ?-)
5168 (if (speedbar-with-writable
5169 (save-excursion
5170 (end-of-line) (forward-char 1)
5171 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
5172 (speedbar-change-expand-button-char ?-)
5173 (speedbar-change-expand-button-char ??)))
5174 ((string-match "-" text) ;we have to contract this node
5175 (speedbar-change-expand-button-char ?+)
5176 (speedbar-delete-subblock indent))
5177 (t (error "Ooops... not sure what to do")))
5178 (speedbar-center-buffer-smartly))
5180 (defun Info-speedbar-fetch-file-nodes (nodespec)
5181 "Fetch the subnodes from the info NODESPEC.
5182 NODESPEC is a string of the form: (file)node."
5183 ;; Set up a buffer we can use to fake-out Info.
5184 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
5185 (if (not (derived-mode-p 'Info-mode))
5186 (Info-mode))
5187 ;; Get the node into this buffer
5188 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
5189 (error "Invalid node specification %s" nodespec)
5190 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
5191 ;; Scan the created buffer
5192 (goto-char (point-min))
5193 (let ((completions nil)
5194 (case-fold-search t)
5195 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
5196 (match-string 1 nodespec))))
5197 ;; Always skip the first one...
5198 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5199 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5200 (let ((name (match-string 1)))
5201 (push (cons name
5202 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
5203 (match-string 1)
5204 (if (looking-at " *\\(([^)]+)\\)\\.")
5205 (concat (match-string 1) "Top")
5206 (concat "(" thisfile ")"
5207 (if (looking-at " \\([^.]+\\).")
5208 (match-string 1)
5209 name)))))
5210 completions)))
5211 (nreverse completions))))
5213 ;;; Info mode node listing
5214 ;; This is called by `speedbar-add-localized-speedbar-support'
5215 (defun Info-speedbar-buttons (_buffer)
5216 "Create a speedbar display to help navigation in an Info file.
5217 BUFFER is the buffer speedbar is requesting buttons for."
5218 (if (save-excursion (goto-char (point-min))
5219 (let ((case-fold-search t))
5220 (not (looking-at "Info Nodes:"))))
5221 (erase-buffer))
5222 (Info-speedbar-hierarchy-buttons nil 0))
5224 ;; FIXME: Really? Why here?
5225 (add-to-list 'debug-ignored-errors 'search-failed)
5227 ;;;; Desktop support
5229 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
5230 "Auxiliary information to be saved in desktop file."
5231 (list Info-current-file
5232 Info-current-node
5233 ;; Additional data as an association list.
5234 (delq nil (list
5235 (and Info-history
5236 (cons 'history Info-history))
5237 (and (Info-virtual-fun
5238 'slow Info-current-file Info-current-node)
5239 (cons 'slow t))))))
5241 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
5242 desktop-buffer-name
5243 desktop-buffer-misc)
5244 "Restore an Info buffer specified in a desktop file."
5245 (let* ((file (nth 0 desktop-buffer-misc))
5246 (node (nth 1 desktop-buffer-misc))
5247 (data (nth 2 desktop-buffer-misc))
5248 (hist (assq 'history data))
5249 (slow (assq 'slow data)))
5250 ;; Don't restore nodes slow to regenerate.
5251 (unless slow
5252 (when (and file node)
5253 (when desktop-buffer-name
5254 (set-buffer (get-buffer-create desktop-buffer-name))
5255 (Info-mode))
5256 (Info-find-node file node)
5257 (when hist
5258 (setq Info-history (cdr hist)))
5259 (current-buffer)))))
5261 (add-to-list 'desktop-buffer-mode-handlers
5262 '(Info-mode . Info-restore-desktop-buffer))
5264 ;;;; Bookmark support
5265 (declare-function bookmark-make-record-default
5266 "bookmark" (&optional no-file no-context posn))
5267 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
5268 (declare-function bookmark-default-handler "bookmark" (bmk))
5269 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
5271 (defun Info-bookmark-make-record ()
5272 "This implements the `bookmark-make-record-function' type (which see)
5273 for Info nodes."
5274 (let* ((file (and (stringp Info-current-file)
5275 (file-name-sans-extension
5276 (file-name-nondirectory Info-current-file))))
5277 (bookmark-name (if file
5278 (concat "(" file ") " Info-current-node)
5279 Info-current-node))
5280 (defaults (delq nil (list bookmark-name file Info-current-node))))
5281 `(,bookmark-name
5282 ,@(bookmark-make-record-default 'no-file)
5283 (filename . ,Info-current-file)
5284 (info-node . ,Info-current-node)
5285 (handler . Info-bookmark-jump)
5286 (defaults . ,defaults))))
5288 ;;;###autoload
5289 (defun Info-bookmark-jump (bmk)
5290 "This implements the `handler' function interface for the record
5291 type returned by `Info-bookmark-make-record', which see."
5292 (let* ((file (bookmark-prop-get bmk 'filename))
5293 (info-node (bookmark-prop-get bmk 'info-node))
5294 (buf (save-window-excursion ;FIXME: doesn't work with frames!
5295 (Info-find-node file info-node) (current-buffer))))
5296 ;; Use bookmark-default-handler to move to the appropriate location
5297 ;; within the node.
5298 (bookmark-default-handler
5299 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
5302 ;;;###autoload
5303 (defun info-display-manual (manual)
5304 "Display an Info buffer displaying MANUAL.
5305 If there is an existing Info buffer for MANUAL, display it.
5306 Otherwise, visit the manual in a new Info buffer. In interactive
5307 use, a prefix argument directs this command to limit the
5308 completion alternatives to currently visited manuals."
5309 (interactive
5310 (list
5311 (progn
5312 (info-initialize)
5313 (completing-read "Manual name: "
5314 (info--manual-names current-prefix-arg)
5315 nil t))))
5316 (let ((blist (buffer-list))
5317 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
5318 (case-fold-search t)
5319 found)
5320 (dolist (buffer blist)
5321 (with-current-buffer buffer
5322 (when (and (eq major-mode 'Info-mode)
5323 (stringp Info-current-file)
5324 (string-match manual-re Info-current-file))
5325 (setq found buffer
5326 blist nil))))
5327 (if found
5328 (switch-to-buffer found)
5329 (info-initialize)
5330 (info (Info-find-file manual)
5331 (generate-new-buffer-name "*info*")))))
5333 (defun info--manual-names (visited-only)
5334 (let (names)
5335 (dolist (buffer (buffer-list))
5336 (with-current-buffer buffer
5337 (and (eq major-mode 'Info-mode)
5338 (stringp Info-current-file)
5339 (not (string= (substring (buffer-name) 0 1) " "))
5340 (push (file-name-sans-extension
5341 (file-name-nondirectory Info-current-file))
5342 names))))
5343 (delete-dups (append (nreverse names)
5344 (when (not visited-only)
5345 (all-completions
5347 (apply-partially #'Info-read-node-name-2
5348 Info-directory-list
5349 (mapcar #'car Info-suffix-list))))))))
5351 (provide 'info)
5353 ;;; info.el ends here