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