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