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