Attempt to solve bug #17497 by minimizing cursor motion during TTY menu updates.
[emacs.git] / lisp / info.el
blob2b2490b5bdc11eebdff820073b22a7cb24293bf8
1 ;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985-1986, 1992-2014 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 N selects an Info buffer named
776 \"*info*<%s>\".
778 The search path for Info files is in the variable `Info-directory-list'.
779 The top-level Info directory is made by combining all the files named `dir'
780 in all the directories in that path.
782 See a list of available Info commands in `Info-mode'."
783 (interactive (list
784 (if (and current-prefix-arg (not (numberp current-prefix-arg)))
785 (read-file-name "Info file name: " nil nil t))
786 (if (numberp current-prefix-arg)
787 (format "*info*<%s>" current-prefix-arg))))
788 (info-setup file-or-node
789 (pop-to-buffer-same-window (or buffer "*info*"))))
791 (defun info-setup (file-or-node buffer)
792 "Display Info node FILE-OR-NODE in BUFFER."
793 (if (and buffer (not (derived-mode-p 'Info-mode)))
794 (Info-mode))
795 (if file-or-node
796 ;; If argument already contains parentheses, don't add another set
797 ;; since the argument will then be parsed improperly. This also
798 ;; has the added benefit of allowing node names to be included
799 ;; following the parenthesized filename.
800 (Info-goto-node
801 (if (and (stringp file-or-node) (string-match "(.*)" file-or-node))
802 file-or-node
803 (concat "(" file-or-node ")")))
804 (if (and (zerop (buffer-size))
805 (null Info-history))
806 ;; If we just created the Info buffer, go to the directory.
807 (Info-directory))))
809 ;;;###autoload
810 (defun info-emacs-manual ()
811 "Display the Emacs manual in Info mode."
812 (interactive)
813 (info "emacs"))
815 ;;;###autoload
816 (defun info-emacs-bug ()
817 "Display the \"Reporting Bugs\" section of the Emacs manual in Info mode."
818 (interactive)
819 (info "(emacs)Bugs"))
821 ;;;###autoload
822 (defun info-standalone ()
823 "Run Emacs as a standalone Info reader.
824 Usage: emacs -f info-standalone [filename]
825 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
826 (setq Info-standalone t)
827 (if (and command-line-args-left
828 (not (string-match "^-" (car command-line-args-left))))
829 (condition-case err
830 (progn
831 (info (car command-line-args-left))
832 (setq command-line-args-left (cdr command-line-args-left)))
833 (error (send-string-to-terminal
834 (format "%s\n" (if (eq (car-safe err) 'error)
835 (nth 1 err) err)))
836 (save-buffers-kill-emacs)))
837 (info)))
839 ;; See if the accessible portion of the buffer begins with a node
840 ;; delimiter, and the node header line which follows matches REGEXP.
841 ;; Typically, this test will be followed by a loop that examines the
842 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
843 ;; to have the overhead of this special test inside the loop.
845 ;; This function changes match-data, but supposedly the caller might
846 ;; want to use the results of re-search-backward.
848 ;; The return value is the value of point at the beginning of matching
849 ;; REGEXP, if the function succeeds, nil otherwise.
850 (defun Info-node-at-bob-matching (regexp)
851 (and (bobp) ; are we at beginning of buffer?
852 (looking-at "\^_") ; does it begin with node delimiter?
853 (let (beg)
854 (forward-line 1)
855 (setq beg (point))
856 (forward-line 1) ; does the line after delimiter match REGEXP?
857 (re-search-backward regexp beg t))))
859 (defun Info-find-file (filename &optional noerror)
860 "Return expanded FILENAME, or t if FILENAME is \"dir\".
861 Optional second argument NOERROR, if t, means if file is not found
862 just return nil (no error)."
863 ;; Convert filename to lower case if not found as specified.
864 ;; Expand it.
865 (cond
866 ((Info-virtual-call
867 (Info-virtual-fun 'find-file filename nil)
868 filename noerror))
869 ((stringp filename)
870 (let (temp temp-downcase found)
871 (setq filename (substitute-in-file-name filename))
872 (let ((dirs (if (string-match "^\\./" filename)
873 ;; If specified name starts with `./'
874 ;; then just try current directory.
875 '("./")
876 (if (file-name-absolute-p filename)
877 ;; No point in searching for an
878 ;; absolute file name
879 '(nil)
880 (if Info-additional-directory-list
881 (append Info-directory-list
882 Info-additional-directory-list)
883 Info-directory-list)))))
884 ;; Fall back on the installation directory if we can't find
885 ;; the info node anywhere else.
886 (when installation-directory
887 (setq dirs (append dirs (list (expand-file-name
888 "info" installation-directory)))))
889 ;; Search the directory list for file FILENAME.
890 (while (and dirs (not found))
891 (setq temp (expand-file-name filename (car dirs)))
892 (setq temp-downcase
893 (expand-file-name (downcase filename) (car dirs)))
894 ;; Try several variants of specified name.
895 (let ((suffix-list Info-suffix-list)
896 (lfn (if (fboundp 'msdos-long-file-names)
897 (msdos-long-file-names)
898 t)))
899 (while (and suffix-list (not found))
900 (cond ((info-file-exists-p
901 (info-insert-file-contents-1
902 temp (car (car suffix-list)) lfn))
903 (setq found temp))
904 ((info-file-exists-p
905 (info-insert-file-contents-1
906 temp-downcase (car (car suffix-list)) lfn))
907 (setq found temp-downcase))
908 ((and (fboundp 'msdos-long-file-names)
910 (info-file-exists-p
911 (info-insert-file-contents-1
912 temp (car (car suffix-list)) nil)))
913 (setq found temp)))
914 (setq suffix-list (cdr suffix-list))))
915 (setq dirs (cdr dirs))))
916 (if found
917 (setq filename found)
918 (if noerror
919 (setq filename nil)
920 ;; If there is no previous Info file, go to the directory.
921 (unless Info-current-file
922 (Info-directory))
923 (user-error "Info file %s does not exist" filename)))
924 filename))))
926 (defun Info-find-node (filename nodename &optional no-going-back strict-case)
927 "Go to an Info node specified as separate FILENAME and NODENAME.
928 NO-GOING-BACK is non-nil if recovering from an error in this function;
929 it says do not attempt further (recursive) error recovery.
931 This function first looks for a case-sensitive match for NODENAME;
932 if none is found it then tries a case-insensitive match (unless
933 STRICT-CASE is non-nil)."
934 (info-initialize)
935 (setq filename (Info-find-file filename))
936 ;; Go into Info buffer.
937 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
938 ;; Record the node we are leaving, if we were in one.
939 (and (not no-going-back)
940 Info-current-file
941 (push (list Info-current-file Info-current-node (point))
942 Info-history))
943 (Info-find-node-2 filename nodename no-going-back strict-case))
945 ;;;###autoload
946 (defun Info-on-current-buffer (&optional nodename)
947 "Use Info mode to browse the current Info buffer.
948 With a prefix arg, this queries for the node name to visit first;
949 otherwise, that defaults to `Top'."
950 (interactive
951 (list (if current-prefix-arg
952 (completing-read "Node name: " (Info-build-node-completions)
953 nil t "Top"))))
954 (unless nodename (setq nodename "Top"))
955 (info-initialize)
956 (Info-mode)
957 (set (make-local-variable 'Info-current-file)
958 (or buffer-file-name
959 ;; If called on a non-file buffer, make a fake file name.
960 (concat default-directory (buffer-name))))
961 (Info-find-node-2 nil nodename))
963 (defun Info-revert-find-node (filename nodename)
964 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
965 When *info* is already displaying FILENAME and NODENAME, the window position
966 is preserved, if possible."
967 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
968 (let ((old-filename Info-current-file)
969 (old-nodename Info-current-node)
970 (window-selected (eq (selected-window) (get-buffer-window)))
971 (pcolumn (current-column))
972 (pline (count-lines (point-min) (line-beginning-position)))
973 (wline (count-lines (point-min) (window-start)))
974 (new-history (and Info-current-file
975 (list Info-current-file Info-current-node (point)))))
976 ;; When `Info-current-file' is nil, `Info-find-node-2' rereads the file.
977 (setq Info-current-file nil)
978 (Info-find-node filename nodename)
979 (if (and (equal old-filename Info-current-file)
980 (equal old-nodename Info-current-node))
981 (progn
982 ;; note goto-line is no good, we want to measure from point-min
983 (when window-selected
984 (goto-char (point-min))
985 (forward-line wline)
986 (set-window-start (selected-window) (point)))
987 (goto-char (point-min))
988 (forward-line pline)
989 (move-to-column pcolumn))
990 ;; only add to the history when coming from a different file+node
991 (if new-history
992 (setq Info-history (cons new-history Info-history))))))
994 (defun Info-revert-buffer-function (_ignore-auto noconfirm)
995 (when (or noconfirm (y-or-n-p "Revert info buffer? "))
996 (Info-revert-find-node Info-current-file Info-current-node)
997 (message "Reverted %s" Info-current-file)))
999 (defun Info-find-in-tag-table-1 (marker regexp case-fold)
1000 "Find a node in a tag table.
1001 MARKER specifies the buffer and position to start searching at.
1002 REGEXP is a regular expression matching nodes or references. Its first
1003 group should match `Node:' or `Ref:'.
1004 CASE-FOLD t means search for a case-insensitive match.
1005 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1006 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
1007 where the match was found, and MODE is `major-mode' of the buffer in
1008 which the match was found."
1009 (let ((case-fold-search case-fold))
1010 (with-current-buffer (marker-buffer marker)
1011 (goto-char marker)
1013 ;; Search tag table
1014 (beginning-of-line)
1015 (when (re-search-forward regexp nil t)
1016 (list (string-equal "Ref:" (match-string 1))
1017 (+ (point-min) (read (current-buffer)))
1018 major-mode)))))
1020 (defun Info-find-in-tag-table (marker regexp &optional strict-case)
1021 "Find a node in a tag table.
1022 MARKER specifies the buffer and position to start searching at.
1023 REGEXP is a regular expression matching nodes or references. Its first
1024 group should match `Node:' or `Ref:'.
1025 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1026 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
1027 where the match was found, and MODE is `major-mode' of the buffer in
1028 which the match was found.
1029 This function tries to find a case-sensitive match first, then a
1030 case-insensitive match is tried (unless optional argument STRICT-CASE
1031 is non-nil)."
1032 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
1033 (or strict-case (car result)
1034 (setq result (Info-find-in-tag-table-1 marker regexp t)))
1035 result))
1037 (defun Info-find-node-in-buffer-1 (regexp case-fold)
1038 "Find a node or anchor in the current buffer.
1039 REGEXP is a regular expression matching nodes or references. Its first
1040 group should match `Node:' or `Ref:'.
1041 CASE-FOLD t means search for a case-insensitive match.
1042 Value is the position at which a match was found, or nil if not found."
1043 (let ((case-fold-search case-fold)
1044 found)
1045 (save-excursion
1046 (if (Info-node-at-bob-matching regexp)
1047 (setq found (point))
1048 (while (and (not found)
1049 (search-forward "\n\^_" nil t))
1050 (forward-line 1)
1051 (let ((beg (point)))
1052 (forward-line 1)
1053 (if (re-search-backward regexp beg t)
1054 (setq found (line-beginning-position)))))))
1055 found))
1057 (defun Info-find-node-in-buffer (regexp &optional strict-case)
1058 "Find a node or anchor in the current buffer.
1059 REGEXP is a regular expression matching nodes or references. Its first
1060 group should match `Node:' or `Ref:'.
1061 Value is the position at which a match was found, or nil if not found.
1062 This function looks for a case-sensitive match first. If none is found,
1063 a case-insensitive match is tried (unless optional argument STRICT-CASE
1064 is non-nil)."
1065 (or (Info-find-node-in-buffer-1 regexp nil)
1066 (and (not strict-case)
1067 (Info-find-node-in-buffer-1 regexp t))))
1069 (defun Info-find-node-2 (filename nodename &optional no-going-back strict-case)
1070 (buffer-disable-undo (current-buffer))
1071 (or (derived-mode-p 'Info-mode)
1072 (Info-mode))
1073 (widen)
1074 (setq Info-current-node nil)
1075 (unwind-protect
1076 (let ((case-fold-search t)
1077 (virtual-fun (Info-virtual-fun 'find-node
1078 (or filename Info-current-file)
1079 nodename))
1080 anchorpos)
1081 (cond
1082 ((functionp virtual-fun)
1083 (let ((filename (or filename Info-current-file)))
1084 (setq buffer-read-only nil)
1085 (setq Info-current-file filename
1086 Info-current-subfile nil
1087 Info-current-file-completions nil
1088 buffer-file-name nil)
1089 (erase-buffer)
1090 (Info-virtual-call virtual-fun filename nodename no-going-back)
1091 (set-marker Info-tag-table-marker nil)
1092 (setq buffer-read-only t)
1093 (set-buffer-modified-p nil)
1094 (set (make-local-variable 'Info-current-node-virtual) t)))
1095 ((not (and
1096 ;; Reread a file when moving from a virtual node.
1097 (not Info-current-node-virtual)
1098 (or (null filename)
1099 (equal Info-current-file filename))))
1100 ;; Switch files if necessary
1101 (let ((inhibit-read-only t))
1102 (when Info-current-node-virtual
1103 ;; When moving from a virtual node.
1104 (set (make-local-variable 'Info-current-node-virtual) nil)
1105 (if (null filename)
1106 (setq filename Info-current-file)))
1107 (setq Info-current-file nil
1108 Info-current-subfile nil
1109 Info-current-file-completions nil
1110 buffer-file-name nil)
1111 (erase-buffer)
1112 (info-insert-file-contents filename nil)
1113 (setq default-directory (file-name-directory filename))
1114 (set-buffer-modified-p nil)
1115 (set (make-local-variable 'Info-file-supports-index-cookies)
1116 (Info-file-supports-index-cookies filename))
1118 ;; See whether file has a tag table. Record the location if yes.
1119 (goto-char (point-max))
1120 (forward-line -8)
1121 ;; Use string-equal, not equal, to ignore text props.
1122 (if (not (or (string-equal nodename "*")
1123 (not
1124 (search-forward "\^_\nEnd tag table\n" nil t))))
1125 (let (pos)
1126 ;; We have a tag table. Find its beginning.
1127 ;; Is this an indirect file?
1128 (search-backward "\nTag table:\n")
1129 (setq pos (point))
1130 (if (save-excursion
1131 (forward-line 2)
1132 (looking-at "(Indirect)\n"))
1133 ;; It is indirect. Copy it to another buffer
1134 ;; and record that the tag table is in that buffer.
1135 (let ((buf (current-buffer))
1136 (tagbuf
1137 (or Info-tag-table-buffer
1138 (generate-new-buffer " *info tag table*"))))
1139 (setq Info-tag-table-buffer tagbuf)
1140 (with-current-buffer tagbuf
1141 (buffer-disable-undo (current-buffer))
1142 (setq case-fold-search t)
1143 (erase-buffer)
1144 (insert-buffer-substring buf))
1145 (set-marker Info-tag-table-marker
1146 (match-end 0) tagbuf))
1147 (set-marker Info-tag-table-marker pos)))
1148 (set-marker Info-tag-table-marker nil))
1149 (setq Info-current-file filename)
1152 ;; Use string-equal, not equal, to ignore text props.
1153 (if (string-equal nodename "*")
1154 (progn (setq Info-current-node nodename)
1155 (Info-set-mode-line))
1156 ;; Possibilities:
1158 ;; 1. Anchor found in tag table
1159 ;; 2. Anchor *not* in tag table
1161 ;; 3. Node found in tag table
1162 ;; 4. Node *not* found in tag table, but found in file
1163 ;; 5. Node *not* in tag table, and *not* in file
1165 ;; *Or* the same, but in an indirect subfile.
1167 ;; Search file for a suitable node.
1168 (let ((guesspos (point-min))
1169 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1170 (if (stringp nodename)
1171 (regexp-quote nodename)
1173 "\\) *[,\t\n\177]")))
1175 (catch 'foo
1177 ;; First, search a tag table, if any
1178 (when (marker-position Info-tag-table-marker)
1179 (let* ((m Info-tag-table-marker)
1180 (found (Info-find-in-tag-table m regexp strict-case)))
1182 (when found
1183 ;; FOUND is (ANCHOR POS MODE).
1184 (setq guesspos (nth 1 found))
1186 ;; If this is an indirect file, determine which
1187 ;; file really holds this node and read it in.
1188 (unless (eq (nth 2 found) 'Info-mode)
1189 ;; Note that the current buffer must be the
1190 ;; *info* buffer on entry to
1191 ;; Info-read-subfile. Thus the hackery above.
1192 (setq guesspos (Info-read-subfile guesspos)))
1194 ;; Handle anchor
1195 (when (nth 0 found)
1196 (goto-char (setq anchorpos guesspos))
1197 (throw 'foo t)))))
1199 ;; Else we may have a node, which we search for:
1200 (goto-char (max (point-min)
1201 (- (byte-to-position guesspos) 1000)))
1203 ;; Now search from our advised position (or from beg of
1204 ;; buffer) to find the actual node. First, check
1205 ;; whether the node is right where we are, in case the
1206 ;; buffer begins with a node.
1207 (let ((pos (Info-find-node-in-buffer regexp strict-case)))
1208 (when pos
1209 (goto-char pos)
1210 (throw 'foo t)))
1212 (when (string-match "\\([^.]+\\)\\." nodename)
1213 (let (Info-point-loc)
1214 (Info-find-node-2
1215 filename (match-string 1 nodename) no-going-back))
1216 (widen)
1217 (throw 'foo t))
1219 ;; No such anchor in tag table or node in tag table or file
1220 (user-error "No such node or anchor: %s" nodename))
1222 (Info-select-node)
1223 (goto-char (point-min))
1224 (forward-line 1) ; skip header line
1225 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1226 ;; (forward-line 1))
1228 (cond (anchorpos
1229 (let ((new-history (list Info-current-file
1230 (substring-no-properties nodename))))
1231 ;; Add anchors to the history too
1232 (setq Info-history-list
1233 (cons new-history
1234 (remove new-history Info-history-list))))
1235 (goto-char anchorpos))
1236 ((numberp Info-point-loc)
1237 (forward-line (- Info-point-loc 2))
1238 (setq Info-point-loc nil))
1239 ((stringp Info-point-loc)
1240 (Info-find-index-name Info-point-loc)
1241 (setq Info-point-loc nil))))))
1242 ;; If we did not finish finding the specified node,
1243 ;; go back to the previous one or to the Top node.
1244 (unless (or Info-current-node no-going-back)
1245 (if Info-history
1246 (let ((hist (car Info-history)))
1247 (setq Info-history (cdr Info-history))
1248 (Info-find-node (nth 0 hist) (nth 1 hist) t)
1249 (goto-char (nth 2 hist)))
1250 (Info-find-node Info-current-file "Top" t)))))
1252 ;; Cache the contents of the (virtual) dir file, once we have merged
1253 ;; it for the first time, so we can save time subsequently.
1254 (defvar Info-dir-contents nil)
1256 ;; Cache for the directory we decided to use for the default-directory
1257 ;; of the merged dir text.
1258 (defvar Info-dir-contents-directory nil)
1260 ;; Record the file attributes of all the files from which we
1261 ;; constructed Info-dir-contents.
1262 (defvar Info-dir-file-attributes nil)
1264 (defvar Info-dir-file-name nil)
1266 ;; Construct the Info directory node by merging the files named `dir'
1267 ;; from various directories. Set the *info* buffer's
1268 ;; default-directory to the first directory we actually get any text
1269 ;; from.
1270 (defun Info-insert-dir ()
1271 (if (and Info-dir-contents Info-dir-file-attributes
1272 ;; Verify that none of the files we used has changed
1273 ;; since we used it.
1274 (eval (cons 'and
1275 (mapcar (lambda (elt)
1276 (let ((curr (file-attributes
1277 ;; Handle symlinks
1278 (file-truename (car elt)))))
1280 ;; Don't compare the access time.
1281 (if curr (setcar (nthcdr 4 curr) 0))
1282 (setcar (nthcdr 4 (cdr elt)) 0)
1283 (equal (cdr elt) curr)))
1284 Info-dir-file-attributes))))
1285 (progn
1286 (insert Info-dir-contents)
1287 (goto-char (point-min)))
1288 (let ((dirs (if Info-additional-directory-list
1289 (append Info-directory-list
1290 Info-additional-directory-list)
1291 Info-directory-list))
1292 (dir-file-attrs nil)
1293 ;; Bind this in case the user sets it to nil.
1294 (case-fold-search t)
1295 ;; This is set non-nil if we find a problem in some input files.
1296 problems
1297 buffers buffer others nodes dirs-done)
1299 ;; Search the directory list for the directory file.
1300 (while dirs
1301 (let ((truename (file-truename (expand-file-name (car dirs)))))
1302 (or (member truename dirs-done)
1303 (member (directory-file-name truename) dirs-done)
1304 ;; Try several variants of specified name.
1305 ;; Try upcasing, appending `.info', or both.
1306 (let* (file
1307 (attrs
1309 (progn (setq file (expand-file-name "dir" truename))
1310 (file-attributes file))
1311 (progn (setq file (expand-file-name "DIR" truename))
1312 (file-attributes file))
1313 (progn (setq file (expand-file-name "dir.info" truename))
1314 (file-attributes file))
1315 (progn (setq file (expand-file-name "DIR.INFO" truename))
1316 (file-attributes file))
1317 ;; Shouldn't really happen, but sometimes does,
1318 ;; eg on Debian systems with buggy packages;
1319 ;; so may as well try it.
1320 ;; http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00005.html
1321 (progn (setq file (expand-file-name "dir.gz" truename))
1322 (file-attributes file)))))
1323 (setq dirs-done
1324 (cons truename
1325 (cons (directory-file-name truename)
1326 dirs-done)))
1327 (if attrs
1328 (with-current-buffer (generate-new-buffer " info dir")
1329 (or buffers
1330 (message "Composing main Info directory..."))
1331 (condition-case nil
1332 ;; Index nodes include null bytes. DIR
1333 ;; files should not have indices, but who
1334 ;; knows...
1335 (let ((inhibit-null-byte-detection t))
1336 (insert-file-contents file)
1337 (set (make-local-variable 'Info-dir-file-name)
1338 file)
1339 (push (current-buffer) buffers)
1340 (push (cons file attrs) dir-file-attrs))
1341 (error (kill-buffer (current-buffer))))))))
1342 (unless (cdr dirs)
1343 (set (make-local-variable 'Info-dir-contents-directory)
1344 (file-name-as-directory (car dirs))))
1345 (setq dirs (cdr dirs))))
1347 (or buffers
1348 (error "Can't find the Info directory node"))
1350 ;; Distinguish the dir file that comes with Emacs from all the
1351 ;; others. Yes, that is really what this is supposed to do.
1352 ;; The definition of `Info-directory-list' puts it first on that
1353 ;; list and so last in `buffers' at this point.
1354 (setq buffer (car (last buffers))
1355 others (delq buffer buffers))
1357 ;; Insert the entire original dir file as a start; note that we've
1358 ;; already saved its default directory to use as the default
1359 ;; directory for the whole concatenation.
1360 (save-excursion (insert-buffer-substring buffer))
1362 ;; Look at each of the other buffers one by one.
1363 (dolist (other others)
1364 (let (this-buffer-nodes)
1365 ;; In each, find all the menus.
1366 (with-current-buffer other
1367 (goto-char (point-min))
1368 ;; Find each menu, and add an elt to NODES for it.
1369 (while (re-search-forward "^\\* Menu:" nil t)
1370 (while (and (zerop (forward-line 1)) (eolp)))
1371 (let ((beg (point))
1372 nodename end)
1373 (re-search-backward "^\^_")
1374 (search-forward "Node: ")
1375 (setq nodename (Info-following-node-name))
1376 (search-forward "\n\^_" nil 'move)
1377 (beginning-of-line)
1378 (setq end (point))
1379 (push (list nodename other beg end) this-buffer-nodes)))
1380 (if (assoc-string "top" this-buffer-nodes t)
1381 (setq nodes (nconc this-buffer-nodes nodes))
1382 (setq problems t)
1383 (message "No `top' node in %s" Info-dir-file-name)))))
1384 ;; Add to the main menu a menu item for each other node.
1385 (re-search-forward "^\\* Menu:")
1386 (forward-line 1)
1387 (let ((menu-items '("top"))
1388 (end (save-excursion (search-forward "\^_" nil t) (point))))
1389 (dolist (node nodes)
1390 (let ((nodename (car node)))
1391 (save-excursion
1392 (or (member (downcase nodename) menu-items)
1393 (re-search-forward (concat "^\\* +"
1394 (regexp-quote nodename)
1395 "::")
1396 end t)
1397 (progn
1398 (insert "* " nodename "::" "\n")
1399 (push nodename menu-items)))))))
1400 ;; Now take each node of each of the other buffers
1401 ;; and merge it into the main buffer.
1402 (dolist (node nodes)
1403 (let ((case-fold-search t)
1404 (nodename (car node)))
1405 (goto-char (point-min))
1406 ;; Find the like-named node in the main buffer.
1407 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1408 (regexp-quote nodename)
1409 "[,\n\t]")
1410 nil t)
1411 (progn
1412 (search-forward "\n\^_" nil 'move)
1413 (beginning-of-line)
1414 (insert "\n"))
1415 ;; If none exists, add one.
1416 (goto-char (point-max))
1417 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
1418 ;; Merge the text from the other buffer's menu
1419 ;; into the menu in the like-named node in the main buffer.
1420 (apply 'insert-buffer-substring (cdr node))))
1421 (Info-dir-remove-duplicates)
1422 ;; Kill all the buffers we just made, including the special one excised.
1423 (mapc 'kill-buffer (cons buffer buffers))
1424 (goto-char (point-min))
1425 (if problems
1426 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1427 (message "Composing main Info directory...done"))
1428 (set (make-local-variable 'Info-dir-contents) (buffer-string))
1429 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
1430 (setq default-directory Info-dir-contents-directory))
1432 (defvar Info-streamline-headings
1433 '(("Emacs" . "Emacs")
1434 ("Programming" . "Programming")
1435 ("Libraries" . "Libraries")
1436 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
1437 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1439 (defun Info-dir-remove-duplicates ()
1440 (let (limit)
1441 (goto-char (point-min))
1442 ;; Remove duplicate headings in the same menu.
1443 (while (search-forward "\n* Menu:" nil t)
1444 (setq limit (save-excursion (search-forward "\n\^_" nil t)))
1445 ;; Look for the next heading to unify.
1446 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1447 (let ((name (match-string 1))
1448 (start (match-beginning 0))
1449 (entries nil) re)
1450 ;; Check whether this heading should be streamlined.
1451 (save-match-data
1452 (dolist (x Info-streamline-headings)
1453 (when (string-match (car x) name)
1454 (setq name (cdr x))
1455 (setq re (car x)))))
1456 (if re (replace-match name t t nil 1))
1457 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
1458 (match-beginning 0)
1459 (or limit (point-max))))
1460 ;; Look for other headings of the same category and merge them.
1461 (save-excursion
1462 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1463 (when (if re (save-match-data (string-match re (match-string 1)))
1464 (equal name (match-string 1)))
1465 (forward-line 0)
1466 ;; Delete redundant heading.
1467 (delete-region (match-beginning 0) (point))
1468 ;; Push the entries onto `text'.
1469 (push
1470 (delete-and-extract-region
1471 (point)
1472 (if (re-search-forward "^[^* \n\t]" nil t)
1473 (match-beginning 0)
1474 (or limit (point-max))))
1475 entries)
1476 (forward-line 0))))
1477 ;; Insert the entries just found.
1478 (while (= (line-beginning-position 0) (1- (point)))
1479 (backward-char))
1480 (dolist (entry (nreverse entries))
1481 (insert entry)
1482 (while (= (line-beginning-position 0) (1- (point)))
1483 (delete-region (1- (point)) (point))))
1485 ;; Now remove duplicate entries under the same heading.
1486 (let (seen)
1487 (save-restriction
1488 (narrow-to-region start (point))
1489 (goto-char (point-min))
1490 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil 'move)
1491 ;; Fold case straight away; `member-ignore-case' here wasteful.
1492 (let ((x (downcase (match-string 1))))
1493 (if (member x seen)
1494 (delete-region
1495 (match-beginning 0)
1496 (if (re-search-forward "^[^ \t]" nil 'move)
1497 (goto-char (match-beginning 0))
1498 (point-max)))
1499 (push x seen)))))))))))
1501 ;; Note that on entry to this function the current-buffer must be the
1502 ;; *info* buffer; not the info tags buffer.
1503 (defun Info-read-subfile (nodepos)
1504 ;; NODEPOS is either a position (in the Info file as a whole,
1505 ;; not relative to a subfile) or the name of a subfile.
1506 (let (lastfilepos
1507 lastfilename)
1508 (if (numberp nodepos)
1509 (with-current-buffer (marker-buffer Info-tag-table-marker)
1510 (goto-char (point-min))
1511 (or (looking-at "\^_")
1512 (search-forward "\n\^_"))
1513 (forward-line 2)
1514 (catch 'foo
1515 (while (not (looking-at "\^_"))
1516 (if (not (eolp))
1517 (let ((beg (point))
1518 thisfilepos thisfilename)
1519 (search-forward ": ")
1520 (setq thisfilename (buffer-substring beg (- (point) 2)))
1521 (setq thisfilepos (+ (point-min) (read (current-buffer))))
1522 ;; read in version 19 stops at the end of number.
1523 ;; Advance to the next line.
1524 (forward-line 1)
1525 (if (> thisfilepos nodepos)
1526 (throw 'foo t))
1527 (setq lastfilename thisfilename)
1528 (setq lastfilepos thisfilepos))
1529 (forward-line 1)))))
1530 (setq lastfilename nodepos)
1531 (setq lastfilepos 0))
1532 ;; Assume previous buffer is in Info-mode.
1533 ;; (set-buffer (get-buffer "*info*"))
1534 (or (equal Info-current-subfile lastfilename)
1535 (let ((inhibit-read-only t))
1536 (setq buffer-file-name nil)
1537 (widen)
1538 (erase-buffer)
1539 (info-insert-file-contents lastfilename)
1540 (set-buffer-modified-p nil)
1541 (setq Info-current-subfile lastfilename)))
1542 ;; Widen in case we are in the same subfile as before.
1543 (widen)
1544 (goto-char (point-min))
1545 ;; Skip the summary segment for `Info-search'.
1546 (if (looking-at "\^_")
1547 (forward-char 1)
1548 (search-forward "\n\^_"))
1549 ;; Don't add the length of the skipped summary segment to
1550 ;; the value returned to `Info-find-node-2'. (Bug#14125)
1551 (if (numberp nodepos)
1552 (+ (- nodepos lastfilepos) (point-min)))))
1554 (defun Info-unescape-quotes (value)
1555 "Unescape double quotes and backslashes in VALUE."
1556 (let ((start 0)
1557 (unquote value))
1558 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start)
1559 (setq unquote (replace-match "" t t unquote 1))
1560 (setq start (- (match-end 0) 1)))
1561 unquote))
1563 ;; As of Texinfo 4.6, makeinfo writes constructs like
1564 ;; \0\h[image param=value ...\h\0]
1565 ;; into the Info file for handling images.
1566 (defun Info-split-parameter-string (parameter-string)
1567 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
1568 PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
1569 If VALUE contains whitespace or double quotes, it must be quoted
1570 in double quotes and any double quotes or backslashes must be
1571 escaped (\\\",\\\\)."
1572 (let ((start 0)
1573 (parameter-alist))
1574 (while (string-match
1575 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1576 parameter-string start)
1577 (setq start (match-end 0))
1578 (push (cons (match-string 1 parameter-string)
1579 (or (match-string 2 parameter-string)
1580 (Info-unescape-quotes
1581 (match-string 3 parameter-string))))
1582 parameter-alist))
1583 parameter-alist))
1585 (defun Info-display-images-node ()
1586 "Display images in current node."
1587 (save-excursion
1588 (let ((inhibit-read-only t)
1589 (case-fold-search t))
1590 (goto-char (point-min))
1591 (while (re-search-forward
1592 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1593 nil t)
1594 (let* ((start (match-beginning 1))
1595 (parameter-alist (Info-split-parameter-string (match-string 2)))
1596 (src (cdr (assoc-string "src" parameter-alist))))
1597 (if (display-images-p)
1598 (let* ((image-file (if src (if (file-name-absolute-p src) src
1599 (concat default-directory src))
1600 ""))
1601 (image (if (file-exists-p image-file)
1602 (create-image image-file)
1603 (or (cdr (assoc-string "text" parameter-alist))
1604 (and src (concat "[broken image:" src "]"))
1605 "[broken image]"))))
1606 (if (not (get-text-property start 'display))
1607 (add-text-properties
1608 start (point)
1609 `(display ,image rear-nonsticky (display)
1610 help-echo ,(cdr (assoc-string "alt" parameter-alist))))))
1611 ;; text-only display, show alternative text if provided, or
1612 ;; otherwise a clue that there's meant to be a picture
1613 (delete-region start (point))
1614 (insert (or (cdr (assoc-string "text" parameter-alist))
1615 (cdr (assoc-string "alt" parameter-alist))
1616 (and src (concat "[image:" src "]"))
1617 "[image]"))))))
1618 (set-buffer-modified-p nil)))
1620 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1621 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1622 ;; including one optional trailing newline.
1623 (defun Info-hide-cookies-node ()
1624 "Hide unrecognized cookies in current node."
1625 (save-excursion
1626 (let ((inhibit-read-only t)
1627 (case-fold-search t))
1628 (goto-char (point-min))
1629 (while (re-search-forward
1630 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1631 nil t)
1632 (let* ((start (match-beginning 1)))
1633 (if (and (not (get-text-property start 'invisible))
1634 (not (get-text-property start 'display)))
1635 (put-text-property start (point) 'invisible t)))))
1636 (set-buffer-modified-p nil)))
1638 (defun Info-select-node ()
1639 "Select the Info node that point is in."
1640 ;; Bind this in case the user sets it to nil.
1641 (let ((case-fold-search t))
1642 (save-excursion
1643 ;; Find beginning of node.
1644 (if (search-backward "\n\^_" nil 'move)
1645 (forward-line 2)
1646 (if (looking-at "\^_")
1647 (forward-line 1)
1648 (signal 'search-failed (list "\n\^_"))))
1649 ;; Get nodename spelled as it is in the node.
1650 (re-search-forward "Node:[ \t]*")
1651 (setq Info-current-node
1652 (buffer-substring-no-properties (point)
1653 (progn
1654 (skip-chars-forward "^,\t\n")
1655 (point))))
1656 (Info-set-mode-line)
1657 ;; Find the end of it, and narrow.
1658 (beginning-of-line)
1659 (let (active-expression)
1660 ;; Narrow to the node contents
1661 (narrow-to-region (point)
1662 (if (re-search-forward "\n[\^_\f]" nil t)
1663 (prog1
1664 (1- (point))
1665 (if (looking-at "[\n\^_\f]*execute: ")
1666 (progn
1667 (goto-char (match-end 0))
1668 (setq active-expression
1669 (read (current-buffer))))))
1670 (point-max)))
1671 (if Info-enable-active-nodes (eval active-expression))
1672 ;; Add a new unique history item to full history list
1673 (let ((new-history (list Info-current-file Info-current-node)))
1674 (setq Info-history-list
1675 (cons new-history (remove new-history Info-history-list)))
1676 (setq Info-history-forward nil))
1677 (if (not (eq Info-fontify-maximum-menu-size nil))
1678 (Info-fontify-node))
1679 (Info-display-images-node)
1680 (Info-hide-cookies-node)
1681 (run-hooks 'Info-selection-hook)))))
1683 (defvar Info-mode-line-node-keymap
1684 (let ((map (make-sparse-keymap)))
1685 (define-key map [mode-line mouse-1] 'Info-mouse-scroll-up)
1686 (define-key map [mode-line mouse-3] 'Info-mouse-scroll-down)
1687 map)
1688 "Keymap to put on the Info node name in the mode line.")
1690 (defun Info-set-mode-line ()
1691 (setq mode-line-buffer-identification
1692 (nconc (propertized-buffer-identification "%b")
1693 (list
1694 (concat
1695 " ("
1696 (if (stringp Info-current-file)
1697 (replace-regexp-in-string
1698 "%" "%%"
1699 (file-name-sans-extension
1700 (file-name-nondirectory Info-current-file)))
1701 (format "*%S*" Info-current-file))
1702 ") "
1703 (if Info-current-node
1704 (propertize (replace-regexp-in-string
1705 "%" "%%" Info-current-node)
1706 'face 'mode-line-buffer-id
1707 'help-echo
1708 "mouse-1: scroll forward, mouse-3: scroll back"
1709 'mouse-face 'mode-line-highlight
1710 'local-map Info-mode-line-node-keymap)
1711 ""))))))
1713 ;; Go to an Info node specified with a filename-and-nodename string
1714 ;; of the sort that is found in pointers in nodes.
1716 ;; Don't autoload this function: the correct entry point for other packages
1717 ;; to use is `info'. --Stef
1718 ;; ;;;###autoload
1719 (defun Info-goto-node (nodename &optional fork strict-case)
1720 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1721 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1722 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1723 its sub-files).
1724 Completion is available for node names in the current Info file as well as
1725 in the Info file FILENAME after the closing parenthesis in (FILENAME).
1726 Empty NODENAME in (FILENAME) defaults to the Top node.
1727 If FORK is non-nil (interactively with a prefix arg), show the node in
1728 a new Info buffer.
1729 If FORK is a string, it is the name to use for the new buffer.
1731 This function first looks for a case-sensitive match for the node part
1732 of NODENAME; if none is found it then tries a case-insensitive match
1733 \(unless STRICT-CASE is non-nil)."
1734 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
1735 (info-initialize)
1736 (if fork
1737 (set-buffer
1738 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
1739 (let (filename)
1740 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1741 nodename)
1742 (setq filename (if (= (match-beginning 1) (match-end 1))
1744 (match-string 2 nodename))
1745 nodename (match-string 3 nodename))
1746 (let ((trim (string-match "\\s +\\'" filename)))
1747 (if trim (setq filename (substring filename 0 trim))))
1748 (let ((trim (string-match "\\s +\\'" nodename)))
1749 (if trim (setq nodename (substring nodename 0 trim))))
1750 (if transient-mark-mode (deactivate-mark))
1751 (Info-find-node (if (equal filename "") nil filename)
1752 (if (equal nodename "") "Top" nodename) nil strict-case)))
1754 (defvar Info-read-node-completion-table)
1756 (defun Info-read-node-name-2 (dirs suffixes string pred action)
1757 "Internal function used to complete Info node names.
1758 Return a completion table for Info files---the FILENAME part of a
1759 node named \"(FILENAME)NODENAME\". DIRS is a list of Info
1760 directories to search if FILENAME is not absolute; SUFFIXES is a
1761 list of valid filename suffixes for Info files. See
1762 `try-completion' for a description of the remaining arguments."
1763 (setq suffixes (remove "" suffixes))
1764 (when (file-name-absolute-p string)
1765 (setq dirs (list (file-name-directory string))))
1766 (let ((names nil)
1767 (names-sans-suffix nil)
1768 (suffix (concat (regexp-opt suffixes t) "\\'"))
1769 (string-dir (file-name-directory string)))
1770 (dolist (dir dirs)
1771 (unless dir
1772 (setq dir default-directory))
1773 (if string-dir (setq dir (expand-file-name string-dir dir)))
1774 (when (file-directory-p dir)
1775 (dolist (file (file-name-all-completions
1776 (file-name-nondirectory string) dir))
1777 ;; If the file name has no suffix or a standard suffix,
1778 ;; include it.
1779 (and (or (null (file-name-extension file))
1780 (string-match suffix file))
1781 ;; But exclude subfiles of split Info files.
1782 (not (string-match "-[0-9]+\\'" file))
1783 ;; And exclude backup files.
1784 (not (string-match "~\\'" file))
1785 (push (if string-dir (concat string-dir file) file) names))
1786 ;; If the file name ends in a standard suffix,
1787 ;; add the unsuffixed name as a completion option.
1788 (when (string-match suffix file)
1789 (setq file (substring file 0 (match-beginning 0)))
1790 (push (if string-dir (concat string-dir file) file)
1791 names-sans-suffix)))))
1792 ;; If there is just one file, don't duplicate it with suffixes,
1793 ;; so `Info-read-node-name-1' will be able to complete a single
1794 ;; candidate and to add the terminating ")".
1795 (if (and (= (length names) 1) (= (length names-sans-suffix) 1))
1796 (setq names names-sans-suffix)
1797 (setq names (append names-sans-suffix names)))
1798 (complete-with-action action names string pred)))
1800 (defun Info-read-node-name-1 (string predicate code)
1801 "Internal function used by `Info-read-node-name'.
1802 See `completing-read' for a description of arguments and usage."
1803 (cond
1804 ;; First complete embedded file names.
1805 ((string-match "\\`([^)]*\\'" string)
1806 (completion-table-with-context
1808 (apply-partially 'completion-table-with-terminator ")"
1809 (apply-partially 'Info-read-node-name-2
1810 Info-directory-list
1811 (mapcar 'car Info-suffix-list)))
1812 (substring string 1)
1813 predicate
1814 code))
1815 ;; If a file name was given, complete nodes in the file.
1816 ((string-match "\\`(\\([^)]+\\))" string)
1817 (let ((file0 (match-string 0 string))
1818 (file1 (match-string 1 string))
1819 (nodename (substring string (match-end 0))))
1820 (if (and (equal nodename "") (eq code 'lambda))
1821 ;; Empty node name is permitted that means "Top".
1823 (completion-table-with-context
1824 file0
1825 (apply-partially
1826 (lambda (string pred action)
1827 (complete-with-action
1828 action
1829 (Info-build-node-completions (Info-find-file file1))
1830 string pred)))
1831 nodename predicate code))))
1832 ;; Otherwise use Info-read-node-completion-table.
1833 (t (complete-with-action
1834 code Info-read-node-completion-table string predicate))))
1836 ;; Arrange to highlight the proper letters in the completion list buffer.
1837 (defun Info-read-node-name (prompt)
1838 "Read an Info node name with completion, prompting with PROMPT.
1839 A node name can have the form \"NODENAME\", referring to a node
1840 in the current Info file, or \"(FILENAME)NODENAME\", referring to
1841 a node in FILENAME. \"(FILENAME)\" is a short format to go to
1842 the Top node in FILENAME."
1843 (let* ((completion-ignore-case t)
1844 (Info-read-node-completion-table (Info-build-node-completions))
1845 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1846 (if (equal nodename "")
1847 (Info-read-node-name prompt)
1848 nodename)))
1850 (defun Info-build-node-completions (&optional filename)
1851 (if filename
1852 (or (cdr (assoc filename Info-file-completions))
1853 (with-temp-buffer
1854 (Info-mode)
1855 (Info-goto-node (format "(%s)Top" filename))
1856 (Info-build-node-completions-1)
1857 (push (cons filename Info-current-file-completions) Info-file-completions)
1858 Info-current-file-completions))
1859 (or Info-current-file-completions
1860 (Info-build-node-completions-1))))
1862 (defun Info-build-node-completions-1 ()
1863 (let ((compl nil)
1864 ;; Bind this in case the user sets it to nil.
1865 (case-fold-search t)
1866 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1867 (save-excursion
1868 (save-restriction
1869 (or Info-tag-table-marker
1870 (error "No Info tags found"))
1871 (if (marker-buffer Info-tag-table-marker)
1872 (let ((marker Info-tag-table-marker))
1873 (set-buffer (marker-buffer marker))
1874 (widen)
1875 (goto-char marker)
1876 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1877 (setq compl
1878 (cons (list (match-string-no-properties 2))
1879 compl))))
1880 (widen)
1881 (goto-char (point-min))
1882 ;; If the buffer begins with a node header, process that first.
1883 (if (Info-node-at-bob-matching node-regexp)
1884 (setq compl (list (match-string-no-properties 1))))
1885 ;; Now for the rest of the nodes.
1886 (while (search-forward "\n\^_" nil t)
1887 (forward-line 1)
1888 (let ((beg (point)))
1889 (forward-line 1)
1890 (if (re-search-backward node-regexp beg t)
1891 (setq compl
1892 (cons (list (match-string-no-properties 1))
1893 compl))))))))
1894 (setq compl (cons '("*") (nreverse compl)))
1895 (set (make-local-variable 'Info-current-file-completions) compl)
1896 compl))
1899 (defun Info-restore-point (hl)
1900 "If this node has been visited, restore the point value when we left."
1901 (while hl
1902 (if (and (equal (nth 0 (car hl)) Info-current-file)
1903 ;; Use string-equal, not equal, to ignore text props.
1904 (string-equal (nth 1 (car hl)) Info-current-node))
1905 (progn
1906 (goto-char (nth 2 (car hl)))
1907 (setq hl nil)) ;terminate the while at next iter
1908 (setq hl (cdr hl)))))
1910 (defvar Info-search-history nil
1911 "The history list for `Info-search'.")
1913 (defvar Info-search-case-fold nil
1914 "The value of `case-fold-search' from previous `Info-search' command.")
1916 (defun Info--search-loop (regexp bound backward)
1917 (when backward
1918 ;; Hide Info file header for backward search.
1919 (narrow-to-region (save-excursion
1920 (goto-char (point-min))
1921 (search-forward "\n\^_")
1922 (1- (point)))
1923 (point-max)))
1924 (let ((give-up nil)
1925 (found nil)
1926 (beg-found nil))
1927 (while (not (or give-up
1928 (and found
1929 (funcall isearch-filter-predicate
1930 beg-found found))))
1931 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1932 (if (funcall
1933 (if backward #'re-search-backward #'re-search-forward)
1934 regexp bound t)
1935 (setq found (point) beg-found (if backward (match-end 0)
1936 (match-beginning 0)))
1937 (setq give-up t found nil))))
1938 found))
1940 (defun Info-search (regexp &optional bound _noerror _count direction)
1941 "Search for REGEXP, starting from point, and select node it's found in.
1942 If DIRECTION is `backward', search in the reverse direction."
1943 (interactive (list (read-string
1944 (if Info-search-history
1945 (format "Regexp search%s (default %s): "
1946 (if case-fold-search "" " case-sensitively")
1947 (car Info-search-history))
1948 (format "Regexp search%s: "
1949 (if case-fold-search "" " case-sensitively")))
1950 nil 'Info-search-history)))
1951 (deactivate-mark)
1952 (when (equal regexp "")
1953 (setq regexp (car Info-search-history)))
1954 (when regexp
1955 (setq Info-search-case-fold case-fold-search)
1956 (let* ((backward (eq direction 'backward))
1957 (onode Info-current-node)
1958 (ofile Info-current-file)
1959 (opoint (point))
1960 (opoint-min (point-min))
1961 (opoint-max (point-max))
1962 (ostart (window-start))
1963 (osubfile Info-current-subfile)
1964 (found
1965 (save-excursion
1966 (save-restriction
1967 (widen)
1968 (Info--search-loop regexp bound backward)))))
1970 (unless (or (not isearch-mode) (not Info-isearch-search)
1971 Info-isearch-initial-node
1972 bound
1973 (and found (> found opoint-min) (< found opoint-max)))
1974 (signal 'search-failed (list regexp "end of node")))
1976 ;; If no subfiles, give error now.
1977 (unless (or found Info-current-subfile)
1978 (if isearch-mode
1979 (signal 'search-failed (list regexp "end of manual"))
1980 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1981 (if backward
1982 (re-search-backward regexp)
1983 (re-search-forward regexp)))))
1985 (if (and bound (not found))
1986 (signal 'search-failed (list regexp)))
1988 (unless (or found bound)
1989 (unwind-protect
1990 ;; Try other subfiles.
1991 (let ((list ()))
1992 (with-current-buffer (marker-buffer Info-tag-table-marker)
1993 (goto-char (point-min))
1994 (search-forward "\n\^_\nIndirect:")
1995 (save-restriction
1996 (narrow-to-region (point)
1997 (progn (search-forward "\n\^_")
1998 (1- (point))))
1999 (goto-char (point-min))
2000 ;; Find the subfile we just searched.
2001 (search-forward (concat "\n" osubfile ": "))
2002 ;; Skip that one.
2003 (forward-line (if backward 0 1))
2004 (if backward (forward-char -1))
2005 ;; Make a list of all following subfiles.
2006 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
2007 (while (not (if backward (bobp) (eobp)))
2008 (if backward
2009 (re-search-backward "\\(^.*\\): [0-9]+$")
2010 (re-search-forward "\\(^.*\\): [0-9]+$"))
2011 (goto-char (+ (match-end 1) 2))
2012 (setq list (cons (cons (+ (point-min)
2013 (read (current-buffer)))
2014 (match-string-no-properties 1))
2015 list))
2016 (goto-char (if backward
2017 (1- (match-beginning 0))
2018 (1+ (match-end 0)))))
2019 ;; Put in forward order
2020 (setq list (nreverse list))))
2021 (while list
2022 (message "Searching subfile %s..." (cdr (car list)))
2023 (Info-read-subfile (car (car list)))
2024 (when backward (goto-char (point-max)))
2025 (setq list (cdr list))
2026 (setq found (Info--search-loop regexp nil backward))
2027 (if found
2028 (setq list nil)))
2029 (if found
2030 (message "")
2031 (signal 'search-failed (if isearch-mode
2032 (list regexp "end of manual")
2033 (list regexp)))))
2034 (if (not found)
2035 (progn (Info-read-subfile osubfile)
2036 (goto-char opoint)
2037 (Info-select-node)
2038 (set-window-start (selected-window) ostart)))))
2040 (if (and (string= osubfile Info-current-subfile)
2041 (> found opoint-min)
2042 (< found opoint-max))
2043 ;; Search landed in the same node
2044 (goto-char found)
2045 (widen)
2046 (goto-char found)
2047 (save-match-data (Info-select-node)))
2049 ;; Use string-equal, not equal, to ignore text props.
2050 (or (and (string-equal onode Info-current-node)
2051 (equal ofile Info-current-file))
2052 (and isearch-mode isearch-wrapped
2053 (eq opoint (if isearch-forward opoint-min opoint-max)))
2054 (setq Info-history (cons (list ofile onode opoint)
2055 Info-history))))))
2057 (defun Info-search-case-sensitively ()
2058 "Search for a regexp case-sensitively."
2059 (interactive)
2060 (let ((case-fold-search nil))
2061 (call-interactively 'Info-search)))
2063 (defun Info-search-next ()
2064 "Search for next regexp from a previous `Info-search' command."
2065 (interactive)
2066 (let ((case-fold-search Info-search-case-fold))
2067 (if Info-search-history
2068 (Info-search (car Info-search-history))
2069 (call-interactively 'Info-search))))
2071 (defun Info-search-backward (regexp &optional bound noerror count)
2072 "Search for REGEXP in the reverse direction."
2073 (interactive (list (read-string
2074 (if Info-search-history
2075 (format "Regexp search%s backward (default %s): "
2076 (if case-fold-search "" " case-sensitively")
2077 (car Info-search-history))
2078 (format "Regexp search%s backward: "
2079 (if case-fold-search "" " case-sensitively")))
2080 nil 'Info-search-history)))
2081 (Info-search regexp bound noerror count 'backward))
2083 (defun Info-isearch-search ()
2084 (if Info-isearch-search
2085 (lambda (string &optional bound noerror count)
2086 (let ((Info-search-whitespace-regexp
2087 (if (if isearch-regexp
2088 isearch-regexp-lax-whitespace
2089 isearch-lax-whitespace)
2090 search-whitespace-regexp)))
2091 (Info-search
2092 (cond
2093 (isearch-word
2094 ;; Lax version of word search
2095 (let ((lax (not (or isearch-nonincremental
2096 (eq (length string)
2097 (length (isearch--state-string
2098 (car isearch-cmds))))))))
2099 (if (functionp isearch-word)
2100 (funcall isearch-word string lax)
2101 (word-search-regexp string lax))))
2102 (isearch-regexp string)
2103 (t (regexp-quote string)))
2104 bound noerror count
2105 (unless isearch-forward 'backward)))
2106 (point))
2107 (isearch-search-fun-default)))
2109 (defun Info-isearch-wrap ()
2110 (if Info-isearch-search
2111 (if Info-isearch-initial-node
2112 (progn
2113 (if isearch-forward (Info-top-node) (Info-final-node))
2114 (goto-char (if isearch-forward (point-min) (point-max))))
2115 (setq Info-isearch-initial-node Info-current-node)
2116 (setq isearch-wrapped nil))
2117 (goto-char (if isearch-forward (point-min) (point-max)))))
2119 (defun Info-isearch-push-state ()
2120 `(lambda (cmd)
2121 (Info-isearch-pop-state cmd ',Info-current-file ',Info-current-node)))
2123 (defun Info-isearch-pop-state (_cmd file node)
2124 (or (and (equal Info-current-file file)
2125 (equal Info-current-node node))
2126 (progn (Info-find-node file node) (sit-for 0))))
2128 (defun Info-isearch-start ()
2129 (setq Info-isearch-initial-node
2130 ;; Don't stop at initial node for nonincremental search.
2131 ;; Otherwise this variable is set after first search failure.
2132 (and isearch-nonincremental Info-current-node))
2133 (setq Info-isearch-initial-history Info-history
2134 Info-isearch-initial-history-list Info-history-list)
2135 (add-hook 'isearch-mode-end-hook 'Info-isearch-end nil t))
2137 (defun Info-isearch-end ()
2138 ;; Remove intermediate nodes (visited while searching)
2139 ;; from the history. Add only the last node (where Isearch ended).
2140 (if (> (length Info-history)
2141 (length Info-isearch-initial-history))
2142 (setq Info-history
2143 (nthcdr (- (length Info-history)
2144 (length Info-isearch-initial-history)
2146 Info-history)))
2147 (if (> (length Info-history-list)
2148 (length Info-isearch-initial-history-list))
2149 (setq Info-history-list
2150 (cons (car Info-history-list)
2151 Info-isearch-initial-history-list)))
2152 (remove-hook 'isearch-mode-end-hook 'Info-isearch-end t))
2154 (defun Info-isearch-filter (beg-found found)
2155 "Test whether the current search hit is a visible useful text.
2156 Return non-nil if the text from BEG-FOUND to FOUND is visible
2157 and is not in the header line or a tag table."
2158 (save-match-data
2159 (let ((backward (< found beg-found)))
2160 (not
2162 (and (not search-invisible)
2163 (if backward
2164 (or (text-property-not-all found beg-found 'invisible nil)
2165 (text-property-not-all found beg-found 'display nil))
2166 (or (text-property-not-all beg-found found 'invisible nil)
2167 (text-property-not-all beg-found found 'display nil))))
2168 ;; Skip node header line
2169 (and (save-excursion (forward-line -1)
2170 (looking-at "\^_"))
2171 (forward-line (if backward -1 1)))
2172 ;; Skip Tag Table node
2173 (save-excursion
2174 (and (search-backward "\^_" nil t)
2175 (looking-at
2176 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
2179 (defun Info-extract-pointer (name &optional errorname)
2180 "Extract the value of the node-pointer named NAME.
2181 If there is none, use ERRORNAME in the error message;
2182 if ERRORNAME is nil, just return nil."
2183 ;; Bind this in case the user sets it to nil.
2184 (let ((case-fold-search t))
2185 (save-excursion
2186 (goto-char (point-min))
2187 (let ((bound (point)))
2188 (forward-line 1)
2189 (cond ((re-search-backward
2190 (concat name ":" (Info-following-node-name-re)) bound t)
2191 (match-string-no-properties 1))
2192 ((not (eq errorname t))
2193 (user-error "Node has no %s"
2194 (capitalize (or errorname name)))))))))
2196 (defun Info-following-node-name-re (&optional allowedchars)
2197 "Return a regexp matching a node name.
2198 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
2199 saying which chars may appear in the node name.
2200 Submatch 1 is the complete node name.
2201 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2202 Submatch 3 is the local part of the node name.
2203 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2204 (concat "[ \t\n]*" ;Skip leading space.
2205 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2206 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
2207 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
2208 "\\|\\)\\)")) ;Allow empty node names.
2210 ;;; For compatibility; other files have used this name.
2211 (defun Info-following-node-name ()
2212 (and (looking-at (Info-following-node-name-re))
2213 (match-string-no-properties 1)))
2215 (defun Info-next ()
2216 "Go to the next node of this node."
2217 (interactive)
2218 ;; In case another window is currently selected
2219 (save-window-excursion
2220 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
2221 (Info-goto-node (Info-extract-pointer "next"))))
2223 (defun Info-prev ()
2224 "Go to the previous node of this node."
2225 (interactive)
2226 ;; In case another window is currently selected
2227 (save-window-excursion
2228 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
2229 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2231 (defun Info-up (&optional same-file)
2232 "Go to the superior node of this node.
2233 If SAME-FILE is non-nil, do not move to a different Info file."
2234 (interactive)
2235 ;; In case another window is currently selected
2236 (save-window-excursion
2237 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
2238 (let ((old-node Info-current-node)
2239 (old-file Info-current-file)
2240 (node (Info-extract-pointer "up")) p)
2241 (and same-file
2242 (string-match "^(" node)
2243 (error "Up node is in another Info file"))
2244 (Info-goto-node node)
2245 (setq p (point))
2246 (goto-char (point-min))
2247 (if (and (stringp old-file)
2248 (search-forward "\n* Menu:" nil t)
2249 (re-search-forward
2250 (if (string-equal old-node "Top")
2251 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
2252 (concat "\n\\* +\\(" (regexp-quote old-node)
2253 ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
2254 nil t))
2255 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2256 (goto-char p)
2257 (Info-restore-point Info-history)))))
2259 (defun Info-history-back ()
2260 "Go back in the history to the last node visited."
2261 (interactive)
2262 (or Info-history
2263 (user-error "This is the first Info node you looked at"))
2264 (let ((history-forward
2265 (cons (list Info-current-file Info-current-node (point))
2266 Info-history-forward))
2267 filename nodename opoint)
2268 (setq filename (car (car Info-history)))
2269 (setq nodename (car (cdr (car Info-history))))
2270 (setq opoint (car (cdr (cdr (car Info-history)))))
2271 (setq Info-history (cdr Info-history))
2272 (Info-find-node filename nodename)
2273 (setq Info-history (cdr Info-history))
2274 (setq Info-history-forward history-forward)
2275 (goto-char opoint)))
2277 (defalias 'Info-last 'Info-history-back)
2279 (defun Info-history-forward ()
2280 "Go forward in the history of visited nodes."
2281 (interactive)
2282 (or Info-history-forward
2283 (user-error "This is the last Info node you looked at"))
2284 (let ((history-forward (cdr Info-history-forward))
2285 filename nodename opoint)
2286 (setq filename (car (car Info-history-forward)))
2287 (setq nodename (car (cdr (car Info-history-forward))))
2288 (setq opoint (car (cdr (cdr (car Info-history-forward)))))
2289 (Info-find-node filename nodename)
2290 (setq Info-history-forward history-forward)
2291 (goto-char opoint)))
2293 (add-to-list 'Info-virtual-files
2294 '("\\`dir\\'"
2295 (toc-nodes . Info-directory-toc-nodes)
2296 (find-file . Info-directory-find-file)
2297 (find-node . Info-directory-find-node)
2300 (defun Info-directory-toc-nodes (filename)
2301 "Directory-specific implementation of `Info-toc-nodes'."
2302 `(,filename
2303 ("Top" nil nil nil)))
2305 (defun Info-directory-find-file (filename &optional _noerror)
2306 "Directory-specific implementation of `Info-find-file'."
2307 filename)
2309 (defun Info-directory-find-node (_filename _nodename &optional _no-going-back)
2310 "Directory-specific implementation of `Info-find-node-2'."
2311 (Info-insert-dir))
2313 ;;;###autoload
2314 (defun Info-directory ()
2315 "Go to the Info directory node."
2316 (interactive)
2317 (Info-find-node "dir" "top"))
2319 (add-to-list 'Info-virtual-files
2320 '("\\`\\*History\\*\\'"
2321 (toc-nodes . Info-history-toc-nodes)
2322 (find-file . Info-history-find-file)
2323 (find-node . Info-history-find-node)
2326 (defun Info-history-toc-nodes (filename)
2327 "History-specific implementation of `Info-toc-nodes'."
2328 `(,filename
2329 ("Top" nil nil nil)))
2331 (defun Info-history-find-file (filename &optional _noerror)
2332 "History-specific implementation of `Info-find-file'."
2333 filename)
2335 (defun Info-history-find-node (filename nodename &optional _no-going-back)
2336 "History-specific implementation of `Info-find-node-2'."
2337 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2338 (or filename Info-current-file) nodename))
2339 (insert "Recently Visited Nodes\n")
2340 (insert "**********************\n\n")
2341 (insert "* Menu:\n\n")
2342 (let ((hl (remove '("*History*" "Top") Info-history-list)))
2343 (while hl
2344 (let ((file (nth 0 (car hl)))
2345 (node (nth 1 (car hl))))
2346 (if (stringp file)
2347 (insert "* " node ": ("
2348 (propertize (or (file-name-directory file) "") 'invisible t)
2349 (file-name-nondirectory file)
2350 ")" node ".\n")))
2351 (setq hl (cdr hl)))))
2353 (defun Info-history ()
2354 "Go to a node with a menu of visited nodes."
2355 (interactive)
2356 (Info-find-node "*History*" "Top")
2357 (Info-next-reference)
2358 (Info-next-reference))
2360 (add-to-list 'Info-virtual-nodes
2361 '("\\`\\*TOC\\*\\'"
2362 (find-node . Info-toc-find-node)
2365 (defun Info-toc-find-node (filename nodename &optional _no-going-back)
2366 "Toc-specific implementation of `Info-find-node-2'."
2367 (let* ((curr-file (substring-no-properties (or filename Info-current-file)))
2368 (curr-node (substring-no-properties (or nodename Info-current-node)))
2369 (node-list (Info-toc-nodes curr-file)))
2370 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2371 curr-file curr-node))
2372 (insert "Table of Contents\n")
2373 (insert "*****************\n\n")
2374 (insert "*Note Top::\n")
2375 (Info-toc-insert
2376 (nth 3 (assoc "Top" node-list)) ; get Top nodes
2377 node-list 0 curr-file)
2378 (unless (bobp)
2379 (let ((Info-hide-note-references 'hide)
2380 (Info-fontify-visited-nodes nil))
2381 (setq Info-current-file filename Info-current-node "*TOC*")
2382 (goto-char (point-min))
2383 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t)
2384 (point-min))
2385 (point-max))
2386 (Info-fontify-node)
2387 (widen)))))
2389 (defun Info-toc ()
2390 "Go to a node with table of contents of the current Info file.
2391 Table of contents is created from the tree structure of menus."
2392 (interactive)
2393 (Info-find-node Info-current-file "*TOC*")
2394 (let ((prev-node (nth 1 (car Info-history))) p)
2395 (goto-char (point-min))
2396 (if (setq p (search-forward (concat "*Note " prev-node ":") nil t))
2397 (setq p (- p (length prev-node) 2)))
2398 (goto-char (or p (point-min)))))
2400 (defun Info-toc-insert (nodes node-list level curr-file)
2401 "Insert table of contents with references to nodes."
2402 (let ((section "Top"))
2403 (while nodes
2404 (let ((node (assoc (car nodes) node-list)))
2405 (unless (member (nth 2 node) (list nil section))
2406 (insert (setq section (nth 2 node)) "\n"))
2407 (insert (make-string level ?\t))
2408 (insert "*Note " (car nodes) ":: \n")
2409 (Info-toc-insert (nth 3 node) node-list (1+ level) curr-file)
2410 (setq nodes (cdr nodes))))))
2412 (defun Info-toc-build (file)
2413 "Build table of contents from menus of Info FILE and its subfiles."
2414 (with-temp-buffer
2415 (let* ((file (and (stringp file) (Info-find-file file)))
2416 (default-directory (or (and (stringp file)
2417 (file-name-directory file))
2418 default-directory))
2419 (main-file (and (stringp file) file))
2420 (sections '(("Top" "Top")))
2421 nodes subfiles)
2422 (while (or main-file subfiles)
2423 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2424 (erase-buffer)
2425 (info-insert-file-contents (or main-file (car subfiles)))
2426 (goto-char (point-min))
2427 (while (and (search-forward "\n\^_\nFile:" nil 'move)
2428 (search-forward "Node: " nil 'move))
2429 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2430 (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
2431 (point-max)) 2))
2432 (upnode (and (re-search-forward
2433 (concat "Up:" (Info-following-node-name-re))
2434 bound t)
2435 (match-string-no-properties 1)))
2436 (section "Top")
2437 menu-items)
2438 (when (and upnode (string-match "(" upnode)) (setq upnode nil))
2439 (when (and (not (Info-index-node nodename file))
2440 (re-search-forward "^\\* Menu:" bound t))
2441 (forward-line 1)
2442 (beginning-of-line)
2443 (setq bound (or (and (equal nodename "Top")
2444 (save-excursion
2445 (re-search-forward
2446 "^[ \t-]*The Detailed Node Listing" nil t)))
2447 bound))
2448 (while (< (point) bound)
2449 (cond
2450 ;; Menu item line
2451 ((looking-at "^\\* +[^:]+:")
2452 (beginning-of-line)
2453 (forward-char 2)
2454 (let ((menu-node-name (substring-no-properties
2455 (Info-extract-menu-node-name))))
2456 (setq menu-items (cons menu-node-name menu-items))
2457 (if (equal nodename "Top")
2458 (setq sections
2459 (cons (list menu-node-name section) sections)))))
2460 ;; Other non-empty strings in the Top node are section names
2461 ((and (equal nodename "Top")
2462 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2463 (setq section (match-string-no-properties 1))))
2464 (forward-line 1)
2465 (beginning-of-line)))
2466 (setq nodes (cons (list nodename upnode
2467 (cadr (assoc nodename sections))
2468 (nreverse menu-items))
2469 nodes))
2470 (goto-char bound)))
2471 (if main-file
2472 (save-excursion
2473 (goto-char (point-min))
2474 (if (search-forward "\n\^_\nIndirect:" nil t)
2475 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2476 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2477 (setq subfiles (cons (match-string-no-properties 1)
2478 subfiles)))))
2479 (setq subfiles (nreverse subfiles)
2480 main-file nil))
2481 (setq subfiles (cdr subfiles))))
2482 (message "")
2483 (nreverse nodes))))
2485 (defun Info-toc-nodes (filename)
2486 "Return a node list of Info FILENAME with parent-children information.
2487 This information is cached in the variable `Info-toc-nodes' with the help
2488 of the function `Info-toc-build'."
2489 (cond
2490 ((Info-virtual-call
2491 (Info-virtual-fun 'toc-nodes (or filename Info-current-file) nil)
2492 filename))
2494 (or filename (setq filename Info-current-file))
2495 (or (assoc filename Info-toc-nodes)
2496 ;; Skip virtual Info files
2497 (and (or (not (stringp filename))
2498 (Info-virtual-file-p filename))
2499 (push (cons filename nil) Info-toc-nodes))
2500 ;; Scan the entire manual and cache the result in Info-toc-nodes
2501 (let ((nodes (Info-toc-build filename)))
2502 (push (cons filename nodes) Info-toc-nodes)
2503 nodes)
2504 ;; If there is an error, still add nil to the cache
2505 (push (cons filename nil) Info-toc-nodes))
2506 (cdr (assoc filename Info-toc-nodes)))))
2509 (defun Info-follow-reference (footnotename &optional fork)
2510 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2511 FOOTNOTENAME may be an abbreviation of the reference name.
2512 If FORK is non-nil (interactively with a prefix arg), show the node in
2513 a new Info buffer. If FORK is a string, it is the name to use for the
2514 new buffer."
2515 (interactive
2516 (let ((completion-ignore-case t)
2517 (case-fold-search t)
2518 completions default alt-default (start-point (point)) str i bol eol)
2519 (save-excursion
2520 ;; Store end and beginning of line.
2521 (setq eol (line-end-position)
2522 bol (line-beginning-position))
2523 (goto-char (point-min))
2524 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
2525 (setq str (match-string-no-properties 1))
2526 ;; See if this one should be the default.
2527 (and (null default)
2528 (<= (match-beginning 0) start-point)
2529 (<= start-point (point))
2530 (setq default t))
2531 ;; See if this one should be the alternate default.
2532 (and (null alt-default)
2533 (and (<= bol (match-beginning 0))
2534 (<= (point) eol))
2535 (setq alt-default t))
2536 (setq i 0)
2537 (while (setq i (string-match "[ \n\t]+" str i))
2538 (setq str (concat (substring str 0 i) " "
2539 (substring str (match-end 0))))
2540 (setq i (1+ i)))
2541 ;; Record as a completion and perhaps as default.
2542 (if (eq default t) (setq default str))
2543 (if (eq alt-default t) (setq alt-default str))
2544 ;; Don't add this string if it's a duplicate.
2545 (or (assoc-string str completions t)
2546 (push str completions))))
2547 ;; If no good default was found, try an alternate.
2548 (or default
2549 (setq default alt-default))
2550 ;; If only one cross-reference found, then make it default.
2551 (if (eq (length completions) 1)
2552 (setq default (car completions)))
2553 (if completions
2554 (let ((input (completing-read (if default
2555 (concat
2556 "Follow reference named (default "
2557 default "): ")
2558 "Follow reference named: ")
2559 completions nil t)))
2560 (list (if (equal input "")
2561 default input) current-prefix-arg))
2562 (user-error "No cross-references in this node"))))
2564 (unless footnotename
2565 (error "No reference was specified"))
2567 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
2568 (case-fold-search t))
2569 (while (setq i (string-match " " str i))
2570 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
2571 (setq i (+ i 6)))
2572 (save-excursion
2573 ;; Move point to the beginning of reference if point is on reference
2574 (or (looking-at "\\*note[ \n\t]+")
2575 (and (looking-back "\\*note[ \n\t]+")
2576 (goto-char (match-beginning 0)))
2577 (if (and (save-excursion
2578 (goto-char (+ (point) 5)) ; skip a possible *note
2579 (re-search-backward "\\*note[ \n\t]+" nil t)
2580 (looking-at str))
2581 (<= (point) (match-end 0)))
2582 (goto-char (match-beginning 0))))
2583 ;; Go to the reference closest to point
2584 (let ((next-ref (save-excursion (and (re-search-forward str nil t)
2585 (+ (match-beginning 0) 5))))
2586 (prev-ref (save-excursion (and (re-search-backward str nil t)
2587 (+ (match-beginning 0) 5)))))
2588 (goto-char (cond ((and next-ref prev-ref)
2589 (if (< (abs (- next-ref (point)))
2590 (abs (- prev-ref (point))))
2591 next-ref prev-ref))
2592 ((or next-ref prev-ref))
2593 ((user-error "No cross-reference named %s"
2594 footnotename))))
2595 (setq target (Info-extract-menu-node-name t))))
2596 (while (setq i (string-match "[ \t\n]+" target i))
2597 (setq target (concat (substring target 0 i) " "
2598 (substring target (match-end 0))))
2599 (setq i (+ i 1)))
2600 (Info-goto-node target fork)))
2602 (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2603 ;; We allow newline because this is also used in Info-follow-reference,
2604 ;; where the xref name might be wrapped over two lines.
2605 "Regexp that matches a menu entry name upto but not including the colon.
2606 Because of ambiguities, this should be concatenated with something like
2607 `:' and `Info-following-node-name-re'.")
2609 (defun Info-extract-menu-node-name (&optional multi-line index-node)
2610 (skip-chars-forward " \t\n")
2611 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
2612 (Info-following-node-name-re
2613 (cond
2614 (index-node "^,\t\n")
2615 (multi-line "^.,\t")
2616 (t "^.,\t\n")))
2617 "\\)"
2618 (if index-node
2619 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2620 "")))
2621 (if index-node
2622 (setq Info-point-loc
2623 (if (match-beginning 5)
2624 (string-to-number (match-string 5))
2625 (buffer-substring-no-properties
2626 (match-beginning 0) (1- (match-beginning 1)))))
2627 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2628 ;;; (setq Info-point-loc
2629 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2631 (replace-regexp-in-string
2632 "[ \n]+" " "
2633 (or (and (not (equal (match-string-no-properties 2) ""))
2634 (match-string-no-properties 2))
2635 ;; If the node name is the menu entry name (using `entry::').
2636 (buffer-substring-no-properties
2637 (match-beginning 0) (1- (match-beginning 1)))))))
2639 ;; No one calls this.
2640 ;;(defun Info-menu-item-sequence (list)
2641 ;; (while list
2642 ;; (Info-menu (car list))
2643 ;; (setq list (cdr list))))
2645 (defvar Info-complete-menu-buffer)
2646 (defvar Info-complete-next-re nil)
2647 (defvar Info-complete-nodes nil)
2648 (defvar Info-complete-cache nil)
2650 (defconst Info-node-spec-re
2651 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2652 "Regexp to match the text after a : until the terminating `.'.")
2654 (defun Info-complete-menu-item (string predicate action)
2655 ;; This uses two dynamically bound variables:
2656 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2657 ;; is the menu of items we're trying to complete.
2658 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2659 ;; also look for menu items in subsequent nodes as long as those
2660 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2661 ;; not used.
2662 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2663 ;; also look for menu items in these nodes. This feature is currently
2664 ;; only used for completion in Info-index.
2666 ;; Note that `Info-complete-menu-buffer' could be current already,
2667 ;; so we want to save point.
2668 (with-current-buffer Info-complete-menu-buffer
2669 (save-excursion
2670 (let ((completion-ignore-case t)
2671 (case-fold-search t)
2672 (orignode Info-current-node)
2673 nextnode)
2674 (goto-char (point-min))
2675 (search-forward "\n* Menu:")
2676 (cond
2677 ((eq (car-safe action) 'boundaries) nil)
2678 ((eq action 'lambda)
2679 (re-search-forward
2680 (concat "\n\\* +" (regexp-quote string) ":") nil t))
2682 (let ((pattern (concat "\n\\* +\\("
2683 (regexp-quote string)
2684 Info-menu-entry-name-re "\\):"
2685 Info-node-spec-re))
2686 completions
2687 (complete-nodes Info-complete-nodes))
2688 ;; Check the cache.
2689 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
2690 (equal (nth 1 Info-complete-cache) Info-current-node)
2691 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
2692 (equal (nth 5 Info-complete-cache) Info-complete-nodes)
2693 (let ((prev (nth 3 Info-complete-cache)))
2694 (eq t (compare-strings string 0 (length prev)
2695 prev 0 nil t))))
2696 ;; We can reuse the previous list.
2697 (setq completions (nth 4 Info-complete-cache))
2698 ;; The cache can't be used.
2699 (while
2700 (progn
2701 (while (re-search-forward pattern nil t)
2702 (push (match-string-no-properties 1)
2703 completions))
2704 (setq completions (delete-dups completions))
2705 ;; Check subsequent nodes if applicable.
2706 (or (and Info-complete-next-re
2707 (setq nextnode (Info-extract-pointer "next" t))
2708 (string-match Info-complete-next-re nextnode))
2709 (and complete-nodes
2710 (setq complete-nodes (cdr complete-nodes)
2711 nextnode (car complete-nodes)))))
2712 (Info-goto-node nextnode))
2713 ;; Go back to the start node (for the next completion).
2714 (unless (equal Info-current-node orignode)
2715 (Info-goto-node orignode))
2716 ;; Update the cache.
2717 (set (make-local-variable 'Info-complete-cache)
2718 (list Info-current-file Info-current-node
2719 Info-complete-next-re string completions
2720 Info-complete-nodes)))
2721 (complete-with-action action completions string predicate))))))))
2724 (defun Info-menu (menu-item &optional fork)
2725 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2726 The menu item should one of those listed in the current node's menu.
2727 Completion is allowed, and the default menu item is the one point is on.
2728 If FORK is non-nil (interactively with a prefix arg), show the node in
2729 a new Info buffer. If FORK is a string, it is the name to use for the
2730 new buffer."
2731 (interactive
2732 (let (;; If point is within a menu item, use that item as the default
2733 (default nil)
2734 (p (point))
2736 (case-fold-search t))
2737 (save-excursion
2738 (goto-char (point-min))
2739 (if (not (search-forward "\n* menu:" nil t))
2740 (user-error "No menu in this node"))
2741 (setq beg (point))
2742 (and (< (point) p)
2743 (save-excursion
2744 (goto-char p)
2745 (end-of-line)
2746 (if (re-search-backward (concat "\n\\* +\\("
2747 Info-menu-entry-name-re
2748 "\\):") beg t)
2749 (setq default (match-string-no-properties 1))))))
2750 (let ((item nil))
2751 (while (null item)
2752 (setq item (let ((completion-ignore-case t)
2753 (Info-complete-menu-buffer (current-buffer)))
2754 (completing-read (if default
2755 (format "Menu item (default %s): "
2756 default)
2757 "Menu item: ")
2758 'Info-complete-menu-item nil t)))
2759 ;; we rely on the fact that completing-read accepts an input
2760 ;; of "" even when the require-match argument is true and ""
2761 ;; is not a valid possibility
2762 (if (string= item "")
2763 (if default
2764 (setq item default)
2765 ;; ask again
2766 (setq item nil))))
2767 (list item current-prefix-arg))))
2768 ;; there is a problem here in that if several menu items have the same
2769 ;; name you can only go to the node of the first with this command.
2770 (Info-goto-node (Info-extract-menu-item menu-item)
2771 (and fork
2772 (if (stringp fork) fork menu-item))))
2774 (defun Info-extract-menu-item (menu-item)
2775 (setq menu-item (regexp-quote menu-item))
2776 (let ((case-fold-search t))
2777 (save-excursion
2778 (let ((case-fold-search t))
2779 (goto-char (point-min))
2780 (or (search-forward "\n* menu:" nil t)
2781 (user-error "No menu in this node"))
2782 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
2783 (re-search-forward (concat "\n\\* +" menu-item) nil t)
2784 (user-error "No such item in menu"))
2785 (beginning-of-line)
2786 (forward-char 2)
2787 (Info-extract-menu-node-name nil (Info-index-node))))))
2789 ;; If COUNT is nil, use the last item in the menu.
2790 (defun Info-extract-menu-counting (count &optional no-detail)
2791 (let ((case-fold-search t))
2792 (save-excursion
2793 (let ((case-fold-search t)
2794 (bound (when (and no-detail
2795 (re-search-forward
2796 "^[ \t-]*The Detailed Node Listing" nil t))
2797 (match-beginning 0))))
2798 (goto-char (point-min))
2799 (or (search-forward "\n* menu:" bound t)
2800 (user-error "No menu in this node"))
2801 (if count
2802 (or (search-forward "\n* " bound t count)
2803 (error "Too few items in menu"))
2804 (while (search-forward "\n* " bound t)
2805 nil))
2806 (Info-extract-menu-node-name nil (Info-index-node))))))
2808 (defun Info-nth-menu-item ()
2809 "Go to the node of the Nth menu item.
2810 N is the digit argument used to invoke this command."
2811 (interactive)
2812 (Info-goto-node
2813 (Info-extract-menu-counting
2814 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
2816 (defun Info-top-node ()
2817 "Go to the Top node of this file."
2818 (interactive)
2819 (Info-goto-node "Top"))
2821 (defun Info-final-node ()
2822 "Go to the final node in this file."
2823 (interactive)
2824 (Info-goto-node "Top")
2825 (let ((Info-history nil)
2826 (case-fold-search t))
2827 ;; Go to the last node in the menu of Top. But don't delve into
2828 ;; detailed node listings.
2829 (Info-goto-node (Info-extract-menu-counting nil t))
2830 ;; If the last node in the menu is not last in pointer structure,
2831 ;; move forward (but not down- or upward - see bug#1116) until we
2832 ;; can't go any farther.
2833 (while (Info-forward-node t t t) nil)
2834 ;; Then keep moving down to last subnode, unless we reach an index.
2835 (while (and (not (Info-index-node))
2836 (save-excursion (search-forward "\n* Menu:" nil t)))
2837 (Info-goto-node (Info-extract-menu-counting nil)))))
2839 (defun Info-forward-node (&optional not-down not-up no-error)
2840 "Go forward one node, considering all nodes as forming one sequence."
2841 (interactive)
2842 (goto-char (point-min))
2843 (forward-line 1)
2844 (let ((case-fold-search t))
2845 ;; three possibilities, in order of priority:
2846 ;; 1. next node is in a menu in this node (but not in an index)
2847 ;; 2. next node is next at same level
2848 ;; 3. next node is up and next
2849 (cond ((and (not not-down)
2850 (save-excursion (search-forward "\n* menu:" nil t))
2851 (not (Info-index-node)))
2852 (Info-goto-node (Info-extract-menu-counting 1))
2854 ((save-excursion (search-backward "next:" nil t))
2855 (Info-next)
2857 ((and (not not-up)
2858 (save-excursion (search-backward "up:" nil t))
2859 ;; Use string-equal, not equal, to ignore text props.
2860 (not (string-equal (downcase (Info-extract-pointer "up"))
2861 "top")))
2862 (let ((old-node Info-current-node))
2863 (Info-up)
2864 (let ((old-history Info-history)
2865 success)
2866 (unwind-protect
2867 (setq success (Info-forward-node t nil no-error))
2868 (or success (Info-goto-node old-node)))
2869 (if Info-history-skip-intermediate-nodes
2870 (setq Info-history old-history)))))
2871 (no-error nil)
2872 (t (user-error "No pointer forward from this node")))))
2874 (defun Info-backward-node ()
2875 "Go backward one node, considering all nodes as forming one sequence."
2876 (interactive)
2877 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
2878 (upnode (Info-extract-pointer "up" t))
2879 (case-fold-search t))
2880 (cond ((and upnode (string-match "(" upnode))
2881 (user-error "First node in file"))
2882 ((and upnode (or (null prevnode)
2883 ;; Use string-equal, not equal,
2884 ;; to ignore text properties.
2885 (string-equal (downcase prevnode)
2886 (downcase upnode))))
2887 (Info-up))
2888 (prevnode
2889 ;; If we move back at the same level,
2890 ;; go down to find the last subnode*.
2891 (Info-prev)
2892 (let ((old-history Info-history))
2893 (while (and (not (Info-index-node))
2894 (save-excursion (search-forward "\n* Menu:" nil t)))
2895 (Info-goto-node (Info-extract-menu-counting nil)))
2896 (if Info-history-skip-intermediate-nodes
2897 (setq Info-history old-history))))
2899 (user-error "No pointer backward from this node")))))
2901 (defun Info-exit ()
2902 "Exit Info by selecting some other buffer."
2903 (interactive)
2904 (if Info-standalone
2905 (save-buffers-kill-emacs)
2906 (quit-window)))
2908 (defun Info-next-menu-item ()
2909 "Go to the node of the next menu item."
2910 (interactive)
2911 ;; Bind this in case the user sets it to nil.
2912 (let* ((case-fold-search t)
2913 (node
2914 (save-excursion
2915 (forward-line -1)
2916 (search-forward "\n* menu:" nil t)
2917 (and (search-forward "\n* " nil t)
2918 (Info-extract-menu-node-name)))))
2919 (if node (Info-goto-node node)
2920 (user-error "No more items in menu"))))
2922 (defun Info-last-menu-item ()
2923 "Go to the node of the previous menu item."
2924 (interactive)
2925 (save-excursion
2926 (forward-line 1)
2927 ;; Bind this in case the user sets it to nil.
2928 (let* ((case-fold-search t)
2929 (beg (save-excursion
2930 (and (search-backward "\n* menu:" nil t)
2931 (point)))))
2932 (or (and beg (search-backward "\n* " beg t))
2933 (user-error "No previous items in menu")))
2934 (Info-goto-node (save-excursion
2935 (goto-char (match-end 0))
2936 (Info-extract-menu-node-name)))))
2938 (defmacro Info-no-error (&rest body)
2939 `(condition-case nil (progn ,@body t) (error nil)))
2941 (defun Info-next-preorder ()
2942 "Go to the next subnode or the next node, or go up a level."
2943 (interactive)
2944 (cond ((Info-no-error (Info-next-menu-item)))
2945 ((Info-no-error (Info-next)))
2946 ((Info-no-error (Info-up t))
2947 ;; Since we have already gone thru all the items in this menu,
2948 ;; go up to the end of this node.
2949 (goto-char (point-max))
2950 ;; Since logically we are done with the node with that menu,
2951 ;; move on from it. But don't add intermediate nodes
2952 ;; to the history on recursive calls.
2953 (let ((old-history Info-history))
2954 (Info-next-preorder)
2955 (if Info-history-skip-intermediate-nodes
2956 (setq Info-history old-history))))
2958 (user-error "No more nodes"))))
2960 (defun Info-last-preorder ()
2961 "Go to the last node, popping up a level if there is none."
2962 (interactive)
2963 (cond ((and Info-scroll-prefer-subnodes
2964 (Info-no-error
2965 (Info-last-menu-item)
2966 ;; If we go down a menu item, go to the end of the node
2967 ;; so we can scroll back through it.
2968 (goto-char (point-max))))
2969 ;; Keep going down, as long as there are nested menu nodes.
2970 (let ((old-history Info-history))
2971 (while (Info-no-error
2972 (Info-last-menu-item)
2973 ;; If we go down a menu item, go to the end of the node
2974 ;; so we can scroll back through it.
2975 (goto-char (point-max))))
2976 (if Info-history-skip-intermediate-nodes
2977 (setq Info-history old-history)))
2978 (recenter -1))
2979 ((and (Info-no-error (Info-extract-pointer "prev"))
2980 (not (equal (Info-extract-pointer "up")
2981 (Info-extract-pointer "prev"))))
2982 (Info-no-error (Info-prev))
2983 (goto-char (point-max))
2984 (let ((old-history Info-history))
2985 (while (Info-no-error
2986 (Info-last-menu-item)
2987 ;; If we go down a menu item, go to the end of the node
2988 ;; so we can scroll back through it.
2989 (goto-char (point-max))))
2990 (if Info-history-skip-intermediate-nodes
2991 (setq Info-history old-history)))
2992 (recenter -1))
2993 ((Info-no-error (Info-up t))
2994 (goto-char (point-min))
2995 (let ((case-fold-search t))
2996 (or (search-forward "\n* Menu:" nil t)
2997 (goto-char (point-max)))))
2998 (t (user-error "No previous nodes"))))
3000 (defun Info-scroll-up ()
3001 "Scroll one screenful forward in Info, considering all nodes as one sequence.
3002 Once you scroll far enough in a node that its menu appears on the screen
3003 but after point, the next scroll moves into its first subnode, unless
3004 `Info-scroll-prefer-subnodes' is nil.
3006 When you scroll past the end of a node, that goes to the next node if
3007 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
3008 if this node has no successor, it moves to the parent node's successor,
3009 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
3010 the menu of a node, it moves to subnode indicated by the following menu
3011 item. (That case won't normally result from this command, but can happen
3012 in other ways.)"
3014 (interactive)
3015 (if (or (< (window-start) (point-min))
3016 (> (window-start) (point-max)))
3017 (set-window-start (selected-window) (point)))
3018 (let* ((case-fold-search t)
3019 (virtual-end (save-excursion
3020 (goto-char (point-min))
3021 (if (and Info-scroll-prefer-subnodes
3022 (search-forward "\n* Menu:" nil t))
3023 (point)
3024 (point-max)))))
3025 (if (or (< virtual-end (window-start))
3026 (pos-visible-in-window-p virtual-end))
3027 (cond
3028 (Info-scroll-prefer-subnodes (Info-next-preorder))
3029 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
3030 (t (Info-next-preorder)))
3031 (scroll-up))))
3033 (defun Info-mouse-scroll-up (e)
3034 "Scroll one screenful forward in Info, using the mouse.
3035 See `Info-scroll-up'."
3036 (interactive "e")
3037 (save-selected-window
3038 (if (eventp e)
3039 (select-window (posn-window (event-start e))))
3040 (Info-scroll-up)))
3042 (defun Info-scroll-down ()
3043 "Scroll one screenful back in Info, considering all nodes as one sequence.
3044 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
3045 is non-nil, this goes to its last subnode. When you scroll past the
3046 beginning of a node, that goes to the previous node or back up to the
3047 parent node."
3048 (interactive)
3049 (if (or (< (window-start) (point-min))
3050 (> (window-start) (point-max)))
3051 (set-window-start (selected-window) (point)))
3052 (let* ((case-fold-search t)
3053 (current-point (point))
3054 (virtual-end
3055 (and Info-scroll-prefer-subnodes
3056 (save-excursion
3057 (setq current-point (line-beginning-position))
3058 (goto-char (point-min))
3059 (search-forward "\n* Menu:" current-point t)))))
3060 (if (or virtual-end
3061 (pos-visible-in-window-p (point-min) nil t))
3062 (Info-last-preorder)
3063 (scroll-down))))
3065 (defun Info-mouse-scroll-down (e)
3066 "Scroll one screenful backward in Info, using the mouse.
3067 See `Info-scroll-down'."
3068 (interactive "e")
3069 (save-selected-window
3070 (if (eventp e)
3071 (select-window (posn-window (event-start e))))
3072 (Info-scroll-down)))
3074 (defun Info-next-reference-or-link (pat prop)
3075 "Move point to the next pattern-based cross-reference or property-based link.
3076 The next cross-reference is searched using the regexp PAT, and the next link
3077 is searched using the text property PROP. Move point to the closest found position
3078 of either a cross-reference found by `re-search-forward' or a link found by
3079 `next-single-char-property-change'. Return the new position of point, or nil."
3080 (let ((pxref (save-excursion (re-search-forward pat nil t)))
3081 (plink (next-single-char-property-change (point) prop)))
3082 (when (and (< plink (point-max)) (not (get-char-property plink prop)))
3083 (setq plink (next-single-char-property-change plink prop)))
3084 (if (< plink (point-max))
3085 (if (and pxref (<= pxref plink))
3086 (goto-char (or (match-beginning 1) (match-beginning 0)))
3087 (goto-char plink))
3088 (if pxref (goto-char (or (match-beginning 1) (match-beginning 0)))))))
3090 (defun Info-prev-reference-or-link (pat prop)
3091 "Move point to the previous pattern-based cross-reference or property-based link.
3092 The previous cross-reference is searched using the regexp PAT, and the previous link
3093 is searched using the text property PROP. Move point to the closest found position
3094 of either a cross-reference found by `re-search-backward' or a link found by
3095 `previous-single-char-property-change'. Return the new position of point, or nil."
3096 (let ((pxref (save-excursion (re-search-backward pat nil t)))
3097 (plink (previous-single-char-property-change (point) prop)))
3098 (when (and (> plink (point-min)) (not (get-char-property plink prop)))
3099 (setq plink (previous-single-char-property-change plink prop)))
3100 (if (> plink (point-min))
3101 (if (and pxref (>= pxref plink))
3102 (goto-char (or (match-beginning 1) (match-beginning 0)))
3103 (goto-char plink))
3104 (if pxref (goto-char (or (match-beginning 1) (match-beginning 0)))))))
3106 (defun Info-next-reference (&optional recur count)
3107 "Move cursor to the next cross-reference or menu item in the node.
3108 If COUNT is non-nil (interactively with a prefix arg), jump over
3109 COUNT cross-references."
3110 (interactive "i\np")
3111 (unless count
3112 (setq count 1))
3113 (if (< count 0)
3114 (Info-prev-reference recur (- count))
3115 (while (unless (zerop count) (setq count (1- count)))
3116 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3117 (old-pt (point))
3118 (case-fold-search t))
3119 (or (eobp) (forward-char 1))
3120 (or (Info-next-reference-or-link pat 'link)
3121 (progn
3122 (goto-char (point-min))
3123 (or (Info-next-reference-or-link pat 'link)
3124 (progn
3125 (goto-char old-pt)
3126 (user-error "No cross references in this node")))))
3127 (if (looking-at "\\* Menu:")
3128 (if recur
3129 (user-error "No cross references in this node")
3130 (Info-next-reference t))
3131 (if (looking-at "^\\* ")
3132 (forward-char 2)))))))
3134 (defun Info-prev-reference (&optional recur count)
3135 "Move cursor to the previous cross-reference or menu item in the node.
3136 If COUNT is non-nil (interactively with a prefix arg), jump over
3137 COUNT cross-references."
3138 (interactive "i\np")
3139 (unless count
3140 (setq count 1))
3141 (if (< count 0)
3142 (Info-next-reference recur (- count))
3143 (while (unless (zerop count) (setq count (1- count)))
3144 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3145 (old-pt (point))
3146 (case-fold-search t))
3147 (or (Info-prev-reference-or-link pat 'link)
3148 (progn
3149 (goto-char (point-max))
3150 (or (Info-prev-reference-or-link pat 'link)
3151 (progn
3152 (goto-char old-pt)
3153 (user-error "No cross references in this node")))))
3154 (if (looking-at "\\* Menu:")
3155 (if recur
3156 (user-error "No cross references in this node")
3157 (Info-prev-reference t))
3158 (if (looking-at "^\\* ")
3159 (forward-char 2)))))))
3161 (defun Info-index-nodes (&optional file)
3162 "Return a list of names of all index nodes in Info FILE.
3163 If FILE is omitted, it defaults to the current Info file.
3164 First look in a list of cached index node names. Then scan Info
3165 file and its subfiles for nodes with the index cookie. Then try
3166 to find index nodes starting from the first node in the top level
3167 menu whose name contains the word \"Index\", plus any immediately
3168 following nodes whose names also contain the word \"Index\"."
3169 (or file (setq file Info-current-file))
3170 (or (assoc file Info-index-nodes)
3171 ;; Skip virtual Info files
3172 (and (or (not (stringp file))
3173 (Info-virtual-file-p file))
3174 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
3175 (if (Info-file-supports-index-cookies file)
3176 ;; Find nodes with index cookie
3177 (let* ((default-directory (or (and (stringp file)
3178 (file-name-directory
3179 (setq file (Info-find-file file))))
3180 default-directory))
3181 Info-history Info-history-list Info-fontify-maximum-menu-size
3182 (main-file file) subfiles nodes)
3183 (condition-case nil
3184 (with-temp-buffer
3185 (while (or main-file subfiles)
3186 (erase-buffer)
3187 (info-insert-file-contents (or main-file (car subfiles)))
3188 (goto-char (point-min))
3189 (while (search-forward "\0\b[index\0\b]" nil 'move)
3190 (save-excursion
3191 (re-search-backward "^\^_")
3192 (search-forward "Node: ")
3193 (setq nodes (cons (Info-following-node-name) nodes))))
3194 (if main-file
3195 (save-excursion
3196 (goto-char (point-min))
3197 (if (search-forward "\n\^_\nIndirect:" nil t)
3198 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
3199 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
3200 (setq subfiles (cons (match-string-no-properties 1)
3201 subfiles)))))
3202 (setq subfiles (nreverse subfiles)
3203 main-file nil))
3204 (setq subfiles (cdr subfiles)))))
3205 (error nil))
3206 (if nodes
3207 (setq nodes (nreverse nodes)
3208 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
3209 nodes)
3210 ;; Else find nodes with the word "Index" in the node name
3211 (let ((case-fold-search t)
3212 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
3213 nodes node)
3214 (condition-case nil
3215 (with-temp-buffer
3216 (Info-mode)
3217 (Info-find-node file "Top")
3218 (when (and (search-forward "\n* menu:" nil t)
3219 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
3220 (goto-char (match-beginning 1))
3221 (setq nodes (list (Info-extract-menu-node-name)))
3222 (Info-goto-node (car nodes))
3223 (while (and (setq node (Info-extract-pointer "next" t))
3224 (string-match "\\<Index\\>" node))
3225 (push node nodes)
3226 (Info-goto-node node))))
3227 (error nil))
3228 (if nodes
3229 (setq nodes (nreverse nodes)
3230 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
3231 nodes))
3232 ;; If file has no index nodes, still add it to the cache
3233 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
3234 (cdr (assoc file Info-index-nodes)))
3236 (defun Info-index-node (&optional node file)
3237 "Return non-nil value if NODE is an index node.
3238 If NODE is nil, check the current Info node.
3239 If FILE is nil, check the current Info file."
3240 (or file (setq file Info-current-file))
3241 (if (and (or (and node (not (equal node Info-current-node)))
3242 (assoc file Info-index-nodes))
3243 (not Info-current-node-virtual))
3244 (member (or node Info-current-node) (Info-index-nodes file))
3245 ;; Don't search all index nodes if request is only for the current node
3246 ;; and file is not in the cache of index nodes
3247 (save-match-data
3248 (if (Info-file-supports-index-cookies file)
3249 (save-excursion
3250 (goto-char (+ (or (save-excursion
3251 (search-backward "\n\^_" nil t))
3252 (point-min)) 2))
3253 (search-forward "\0\b[index\0\b]"
3254 (or (save-excursion
3255 (search-forward "\n\^_" nil t))
3256 (point-max)) t))
3257 (string-match "\\<Index\\>" (or node Info-current-node ""))))))
3259 (defun Info-goto-index ()
3260 "Go to the first index node."
3261 (let ((node (car (Info-index-nodes))))
3262 (or node (error "No index"))
3263 (Info-goto-node node)))
3265 ;;;###autoload
3266 (defun Info-index (topic)
3267 "Look up a string TOPIC in the index for this manual and go to that entry.
3268 If there are no exact matches to the specified topic, this chooses
3269 the first match which is a case-insensitive substring of a topic.
3270 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3271 Give an empty topic name to go to the Index node itself."
3272 (interactive
3273 (list
3274 (let ((completion-ignore-case t)
3275 (Info-complete-menu-buffer (clone-buffer))
3276 (Info-complete-nodes (Info-index-nodes))
3277 (Info-history-list nil))
3278 (if (equal Info-current-file "dir")
3279 (error "The Info directory node has no index; use m to select a manual"))
3280 (unwind-protect
3281 (with-current-buffer Info-complete-menu-buffer
3282 (Info-goto-index)
3283 (completing-read "Index topic: " 'Info-complete-menu-item))
3284 (kill-buffer Info-complete-menu-buffer)))))
3285 (if (equal Info-current-file "dir")
3286 (error "The Info directory node has no index; use m to select a manual"))
3287 ;; Strip leading colon in topic; index format does not allow them.
3288 (if (and (stringp topic)
3289 (> (length topic) 0)
3290 (= (aref topic 0) ?:))
3291 (setq topic (substring topic 1)))
3292 (let ((orignode Info-current-node)
3293 (pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3294 (regexp-quote topic)))
3295 node (nodes (Info-index-nodes))
3296 (ohist-list Info-history-list)
3297 (case-fold-search t))
3298 (Info-goto-index)
3299 (or (equal topic "")
3300 (let ((matches nil)
3301 (exact nil)
3302 ;; We bind Info-history to nil for internal node-switches so
3303 ;; that we don't put junk in the history. In the first
3304 ;; Info-goto-index call, above, we do update the history
3305 ;; because that is what the user's previous node choice into it.
3306 (Info-history nil)
3307 found)
3308 (while
3309 (progn
3310 (goto-char (point-min))
3311 (while (re-search-forward pattern nil t)
3312 (let ((entry (match-string-no-properties 1))
3313 (nodename (match-string-no-properties 3))
3314 (line (string-to-number (concat "0" (match-string 4)))))
3315 (add-text-properties
3316 (- (match-beginning 2) (match-beginning 1))
3317 (- (match-end 2) (match-beginning 1))
3318 '(face info-index-match) entry)
3319 (push (list entry nodename Info-current-node line) matches)))
3320 (setq nodes (cdr nodes) node (car nodes)))
3321 (Info-goto-node node))
3322 (or matches
3323 (progn
3324 (Info-goto-node orignode)
3325 (user-error "No `%s' in index" topic)))
3326 ;; Here it is a feature that assoc is case-sensitive.
3327 (while (setq found (assoc topic matches))
3328 (setq exact (cons found exact)
3329 matches (delq found matches)))
3330 (setq Info-history-list ohist-list)
3331 (setq Info-index-alternatives (nconc exact (nreverse matches)))
3332 (Info-index-next 0)))))
3334 (defun Info-index-next (num)
3335 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3336 (interactive "p")
3337 (or Info-index-alternatives
3338 (user-error "No previous `i' command"))
3339 (while (< num 0)
3340 (setq num (+ num (length Info-index-alternatives))))
3341 (while (> num 0)
3342 (setq Info-index-alternatives
3343 (nconc (cdr Info-index-alternatives)
3344 (list (car Info-index-alternatives)))
3345 num (1- num)))
3346 (Info-goto-node (nth 1 (car Info-index-alternatives)))
3347 (if (> (nth 3 (car Info-index-alternatives)) 0)
3348 ;; Forward 2 lines less because `Info-find-node-2' initially
3349 ;; puts point to the 2nd line.
3350 (forward-line (- (nth 3 (car Info-index-alternatives)) 2))
3351 (forward-line 3) ; don't search in headers
3352 (let ((name (car (car Info-index-alternatives))))
3353 (Info-find-index-name name)))
3354 (message "Found `%s' in %s. %s"
3355 (car (car Info-index-alternatives))
3356 (nth 2 (car Info-index-alternatives))
3357 (if (cdr Info-index-alternatives)
3358 (format "(%s total; use `%s' for next)"
3359 (length Info-index-alternatives)
3360 (key-description (where-is-internal
3361 'Info-index-next overriding-local-map
3362 t)))
3363 "(Only match)")))
3365 (defun Info-find-index-name (name)
3366 "Move point to the place within the current node where NAME is defined."
3367 (let ((case-fold-search t))
3368 (if (or (re-search-forward (format
3369 "[a-zA-Z]+: %s\\( \\|$\\)"
3370 (regexp-quote name)) nil t)
3371 ;; Find a function definition with a return type.
3372 (re-search-forward (format
3373 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3374 (regexp-quote name)) nil t)
3375 (search-forward (format "`%s'" name) nil t)
3376 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
3377 (search-forward
3378 (format "`%s'" (substring name 0 (match-beginning 1)))
3379 nil t))
3380 (search-forward name nil t)
3381 ;; Try again without the " <1>" makeinfo can append
3382 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
3383 (Info-find-index-name (match-string 1 name))))
3384 (progn (beginning-of-line) t) ;; non-nil for recursive call
3385 (goto-char (point-min)))))
3387 (add-to-list 'Info-virtual-nodes
3388 '("\\`\\*Index.*\\*\\'"
3389 (find-node . Info-virtual-index-find-node)
3390 (slow . t)
3393 (defvar Info-virtual-index-nodes nil
3394 "Alist of cached matched index search nodes.
3395 Each element is ((FILENAME . TOPIC) MATCHES) where
3396 FILENAME is the file name of the manual,
3397 TOPIC is the search string given as an argument to `Info-virtual-index',
3398 MATCHES is a list of index matches found by `Info-index'.")
3400 (defun Info-virtual-index-find-node (filename nodename &optional _no-going-back)
3401 "Index-specific implementation of `Info-find-node-2'."
3402 ;; Generate Index-like menu of matches
3403 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename)
3404 ;; Generate Index-like menu of matches
3405 (let* ((topic (match-string 1 nodename))
3406 (matches (cdr (assoc (cons (or filename Info-current-file) topic)
3407 Info-virtual-index-nodes))))
3408 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3409 (or filename Info-current-file) nodename))
3410 (insert "Info Virtual Index\n")
3411 (insert "******************\n\n")
3412 (insert "Index entries that match `" topic "':\n\n")
3413 (insert "\0\b[index\0\b]\n")
3414 (if (null matches)
3415 (insert "No matches found.\n")
3416 (insert "* Menu:\n\n")
3417 (dolist (entry matches)
3418 (insert (format "* %-38s %s.%s\n"
3419 (format "%s [%s]:" (nth 0 entry) (nth 2 entry))
3420 (nth 1 entry)
3421 (if (nth 3 entry)
3422 (format " (line %s)" (nth 3 entry))
3423 ""))))))
3424 ;; Else, Generate a list of previous search results
3425 (let ((nodes (reverse Info-virtual-index-nodes)))
3426 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3427 (or filename Info-current-file) nodename))
3428 (insert "Info Virtual Index\n")
3429 (insert "******************\n\n")
3430 (insert "This is a list of search results produced by\n"
3431 "`Info-virtual-index' for the current manual.\n\n")
3432 (insert "* Menu:\n\n")
3433 (dolist (nodeinfo nodes)
3434 (when (equal (car (nth 0 nodeinfo)) (or filename Info-current-file))
3435 (insert
3436 (format "* %-20s %s.\n"
3437 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo)))
3438 (cdr (nth 0 nodeinfo)))))))))
3440 (defun Info-virtual-index (topic)
3441 "Show a node with all lines in the index containing a string TOPIC.
3442 Like `Info-index' but displays a node with index search results.
3443 Give an empty topic name to go to the node with links to previous
3444 search results."
3445 ;; `interactive' is a copy from `Info-index'
3446 (interactive
3447 (list
3448 (let ((completion-ignore-case t)
3449 (Info-complete-menu-buffer (clone-buffer))
3450 (Info-complete-nodes (Info-index-nodes))
3451 (Info-history-list nil))
3452 (if (equal Info-current-file "dir")
3453 (error "The Info directory node has no index; use m to select a manual"))
3454 (unwind-protect
3455 (with-current-buffer Info-complete-menu-buffer
3456 (Info-goto-index)
3457 (completing-read "Index topic: " 'Info-complete-menu-item))
3458 (kill-buffer Info-complete-menu-buffer)))))
3459 (if (equal topic "")
3460 (Info-find-node Info-current-file "*Index*")
3461 (unless (assoc (cons Info-current-file topic) Info-virtual-index-nodes)
3462 (let ((orignode Info-current-node)
3463 (ohist-list Info-history-list))
3464 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3465 (Info-index topic)
3466 (push (cons (cons Info-current-file topic) Info-index-alternatives)
3467 Info-virtual-index-nodes)
3468 ;; Clean up unnecessary side-effects of `Info-index'.
3469 (setq Info-history-list ohist-list)
3470 (Info-goto-node orignode)
3471 (message "")))
3472 (Info-find-node Info-current-file (format "*Index for `%s'*" topic))))
3474 (add-to-list 'Info-virtual-files
3475 '("\\`\\*Apropos\\*\\'"
3476 (toc-nodes . Info-apropos-toc-nodes)
3477 (find-file . Info-apropos-find-file)
3478 (find-node . Info-apropos-find-node)
3479 (slow . t)
3482 (defvar Info-apropos-file "*Apropos*"
3483 "Info file name of the virtual manual for matches of `info-apropos'.")
3485 (defvar Info-apropos-nodes nil
3486 "Alist of cached apropos matched nodes.
3487 Each element is (NODENAME STRING MATCHES) where
3488 NODENAME is the name of the node that holds the search result,
3489 STRING is the search string given as an argument to `info-apropos',
3490 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3492 (defun Info-apropos-toc-nodes (filename)
3493 "Apropos-specific implementation of `Info-toc-nodes'."
3494 (let ((nodes (mapcar 'car (reverse Info-apropos-nodes))))
3495 `(,filename
3496 ("Top" nil nil ,nodes)
3497 ,@(mapcar (lambda (node) `(,node "Top" nil nil)) nodes))))
3499 (defun Info-apropos-find-file (filename &optional _noerror)
3500 "Apropos-specific implementation of `Info-find-file'."
3501 filename)
3503 (defun Info-apropos-find-node (_filename nodename &optional _no-going-back)
3504 "Apropos-specific implementation of `Info-find-node-2'."
3505 (if (equal nodename "Top")
3506 ;; Generate Top menu
3507 (let ((nodes (reverse Info-apropos-nodes)))
3508 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3509 Info-apropos-file nodename))
3510 (insert "Apropos Index\n")
3511 (insert "*************\n\n")
3512 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3513 (insert "* Menu:\n\n")
3514 (dolist (nodeinfo nodes)
3515 (insert (format "* %-20s %s.\n"
3516 (format "%s::" (nth 0 nodeinfo))
3517 (nth 1 nodeinfo)))))
3518 ;; Else, Generate Index-like menu of matches
3519 (let* ((nodeinfo (assoc nodename Info-apropos-nodes))
3520 (matches (nth 2 nodeinfo)))
3521 (when matches
3522 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3523 Info-apropos-file nodename))
3524 (insert "Apropos Index\n")
3525 (insert "*************\n\n")
3526 (insert "Index entries that match `" (nth 1 nodeinfo) "':\n\n")
3527 (insert "\0\b[index\0\b]\n")
3528 (if (eq matches t)
3529 (insert "No matches found.\n")
3530 (insert "* Menu:\n\n")
3531 (dolist (entry matches)
3532 (insert (format "* %-38s (%s)%s.%s\n"
3533 (format "%s [%s]:" (nth 1 entry) (nth 0 entry))
3534 (nth 0 entry)
3535 (nth 2 entry)
3536 (if (nth 3 entry)
3537 (format " (line %s)" (nth 3 entry))
3538 "")))))))))
3540 (defun Info-apropos-matches (string)
3541 "Collect STRING matches from all known Info files on your system.
3542 Return a list of matches where each element is in the format
3543 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3544 (unless (string= string "")
3545 (let ((pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3546 (regexp-quote string)))
3547 (ohist Info-history)
3548 (ohist-list Info-history-list)
3549 (current-node Info-current-node)
3550 (current-file Info-current-file)
3551 manuals matches node nodes)
3552 (let ((Info-fontify-maximum-menu-size nil))
3553 (Info-directory)
3554 ;; current-node and current-file are nil when they invoke info-apropos
3555 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3556 ;; case, we use (DIR)Top instead, to avoid signaling an error after
3557 ;; the search is complete.
3558 (when (null current-node)
3559 (setq current-file Info-current-file)
3560 (setq current-node Info-current-node))
3561 (message "Searching indices...")
3562 (goto-char (point-min))
3563 (re-search-forward "\\* Menu: *\n" nil t)
3564 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
3565 ;; add-to-list makes sure we don't have duplicates in `manuals',
3566 ;; so that the following dolist loop runs faster.
3567 (add-to-list 'manuals (match-string 1)))
3568 (dolist (manual (nreverse manuals))
3569 (message "Searching %s" manual)
3570 (condition-case err
3571 (if (setq nodes (Info-index-nodes (Info-find-file manual)))
3572 (save-excursion
3573 (Info-find-node manual (car nodes))
3574 (while
3575 (progn
3576 (goto-char (point-min))
3577 (while (re-search-forward pattern nil t)
3578 (let ((entry (match-string-no-properties 1))
3579 (nodename (match-string-no-properties 3))
3580 (line (match-string-no-properties 4)))
3581 (add-text-properties
3582 (- (match-beginning 2) (match-beginning 1))
3583 (- (match-end 2) (match-beginning 1))
3584 '(face info-index-match) entry)
3585 (setq matches (cons (list manual entry nodename line)
3586 matches))))
3587 (setq nodes (cdr nodes) node (car nodes)))
3588 (Info-goto-node node))))
3589 (error
3590 (message "%s" (if (eq (car-safe err) 'error)
3591 (nth 1 err) err))
3592 (sit-for 1 t)))))
3593 (Info-find-node current-file current-node)
3594 (setq Info-history ohist
3595 Info-history-list ohist-list)
3596 (message "Searching indices...done")
3597 (or (nreverse matches) t))))
3599 ;;;###autoload
3600 (defun info-apropos (string)
3601 "Grovel indices of all known Info files on your system for STRING.
3602 Build a menu of the possible matches."
3603 (interactive "sIndex apropos: ")
3604 (if (equal string "")
3605 (Info-find-node Info-apropos-file "Top")
3606 (let* ((nodes Info-apropos-nodes) nodename)
3607 (while (and nodes (not (equal string (nth 1 (car nodes)))))
3608 (setq nodes (cdr nodes)))
3609 (if nodes
3610 (Info-find-node Info-apropos-file (car (car nodes)))
3611 (setq nodename (format "Index for `%s'" string))
3612 (push (list nodename string (Info-apropos-matches string))
3613 Info-apropos-nodes)
3614 (Info-find-node Info-apropos-file nodename)))))
3616 (add-to-list 'Info-virtual-files
3617 '("\\`\\*Finder.*\\*\\'"
3618 (find-file . Info-finder-find-file)
3619 (find-node . Info-finder-find-node)
3622 (defvar Info-finder-file "*Finder*"
3623 "Info file name of the virtual Info keyword finder manual.")
3625 (defun Info-finder-find-file (filename &optional _noerror)
3626 "Finder-specific implementation of `Info-find-file'."
3627 filename)
3629 (defvar finder-known-keywords)
3630 (declare-function find-library-name "find-func" (library))
3631 (declare-function finder-unknown-keywords "finder" ())
3632 (declare-function lm-commentary "lisp-mnt" (&optional file))
3633 (defvar finder-keywords-hash)
3634 (defvar package--builtins) ; finder requires package
3636 (defun Info-finder-find-node (_filename nodename &optional _no-going-back)
3637 "Finder-specific implementation of `Info-find-node-2'."
3638 (require 'finder)
3639 (cond
3640 ((equal nodename "Top")
3641 ;; Display Top menu with descriptions of the keywords
3642 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3643 Info-finder-file nodename))
3644 (insert "Finder Keywords\n")
3645 (insert "***************\n\n")
3646 (insert "* Menu:\n\n")
3647 (dolist (assoc (append '((all . "All package info")
3648 (unknown . "Unknown keywords"))
3649 finder-known-keywords))
3650 (let ((keyword (car assoc)))
3651 (insert (format "* %s %s.\n"
3652 (concat (symbol-name keyword) ": "
3653 "Keyword " (symbol-name keyword) ".")
3654 (cdr assoc))))))
3655 ((equal nodename "Keyword unknown")
3656 ;; Display unknown keywords
3657 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3658 Info-finder-file nodename))
3659 (insert "Finder Unknown Keywords\n")
3660 (insert "***********************\n\n")
3661 (insert "* Menu:\n\n")
3662 (mapc
3663 (lambda (assoc)
3664 (insert (format "* %-14s %s.\n"
3665 (concat (symbol-name (car assoc)) ": "
3666 "Keyword " (symbol-name (car assoc)) ".")
3667 (cdr assoc))))
3668 (finder-unknown-keywords)))
3669 ((equal nodename "Keyword all")
3670 ;; Display all package info.
3671 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3672 Info-finder-file nodename))
3673 (insert "Finder Package Info\n")
3674 (insert "*******************\n\n")
3675 (insert "* Menu:\n\n")
3676 (let (desc)
3677 (dolist (package package--builtins)
3678 (setq desc (cdr-safe package))
3679 (when (vectorp desc)
3680 (insert (format "* %-16s %s.\n"
3681 (concat (symbol-name (car package)) "::")
3682 (aref desc 2)))))))
3683 ((string-match "\\`Keyword " nodename)
3684 (setq nodename (substring nodename (match-end 0)))
3685 ;; Display packages that match the keyword
3686 ;; or the list of keywords separated by comma.
3687 (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
3688 Info-finder-file nodename))
3689 (insert "Finder Packages\n")
3690 (insert "***************\n\n")
3691 (insert
3692 "The following packages match the keyword `" nodename "':\n\n")
3693 (insert "* Menu:\n\n")
3694 (let ((keywords
3695 (mapcar 'intern (if (string-match-p "," nodename)
3696 (split-string nodename ",[ \t\n]*" t)
3697 (list nodename))))
3698 hits desc)
3699 (dolist (keyword keywords)
3700 (push (copy-tree (gethash keyword finder-keywords-hash)) hits))
3701 (setq hits (delete-dups (apply 'append hits))
3702 ;; Not a meaningful package.
3703 hits (delete 'emacs hits))
3704 (dolist (package hits)
3705 (setq desc (cdr-safe (assq package package--builtins)))
3706 (when (vectorp desc)
3707 (insert (format "* %-16s %s.\n"
3708 (concat (symbol-name package) "::")
3709 (aref desc 2)))))))
3711 ;; Display commentary section
3712 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3713 Info-finder-file nodename))
3714 (insert "Finder Commentary\n")
3715 (insert "*****************\n\n")
3716 (insert
3717 "Commentary section of the package `" nodename "':\n\n")
3718 ;; FIXME this assumes that a file named package.el exists,
3719 ;; which is not always true. E.g. for the nxml package,
3720 ;; there is no "nxml.el" (it's nxml-mode.el).
3721 (let ((str (lm-commentary (find-library-name nodename))))
3722 (if (null str)
3723 (insert "Can't find any Commentary section\n\n")
3724 (insert
3725 (with-temp-buffer
3726 (insert str)
3727 (goto-char (point-min))
3728 (delete-blank-lines)
3729 (goto-char (point-max))
3730 (delete-blank-lines)
3731 (goto-char (point-min))
3732 (while (re-search-forward "^;+ ?" nil t)
3733 (replace-match "" nil nil))
3734 (buffer-string))))))))
3736 ;;;###autoload
3737 (defun info-finder (&optional keywords)
3738 "Display descriptions of the keywords in the Finder virtual manual.
3739 In interactive use, a prefix argument directs this command to read
3740 a list of keywords separated by comma. After that, it displays a node
3741 with a list of packages that contain all specified keywords."
3742 (interactive
3743 (when current-prefix-arg
3744 (require 'finder)
3745 (list
3746 (completing-read-multiple
3747 "Keywords (separated by comma): "
3748 (mapcar 'symbol-name (mapcar 'car (append finder-known-keywords
3749 (finder-unknown-keywords))))
3750 nil t))))
3751 (require 'finder)
3752 (if keywords
3753 (Info-find-node Info-finder-file (mapconcat 'identity keywords ", "))
3754 (Info-find-node Info-finder-file "Top")))
3757 (defun Info-undefined ()
3758 "Make command be undefined in Info."
3759 (interactive)
3760 (ding))
3762 (defun Info-help ()
3763 "Enter the Info tutorial."
3764 (interactive)
3765 (delete-other-windows)
3766 (Info-find-node "info"
3767 (if (< (window-height) 23)
3768 "Help-Small-Screen"
3769 "Help")))
3771 (defun Info-summary ()
3772 "Display a brief summary of all Info commands."
3773 (interactive)
3774 (save-window-excursion
3775 (switch-to-buffer "*Help*")
3776 (setq buffer-read-only nil)
3777 (erase-buffer)
3778 (insert (documentation 'Info-mode))
3779 (help-mode)
3780 (goto-char (point-min))
3781 (let (ch flag)
3782 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
3783 (message (if flag "Type Space to see more"
3784 "Type Space to return to Info"))
3785 (if (not (eq ?\s (setq ch (read-event))))
3786 (progn (setq unread-command-events (list ch)) nil)
3787 flag))
3788 (scroll-up)))
3789 (bury-buffer "*Help*")))
3791 (defun Info-get-token (pos start all &optional errorstring)
3792 "Return the token around POS.
3793 POS must be somewhere inside the token.
3794 START is a regular expression which will match the
3795 beginning of the tokens delimited string.
3796 ALL is a regular expression with a single
3797 parenthesized subpattern which is the token to be
3798 returned. E.g. '{\(.*\)}' would return any string
3799 enclosed in braces around POS.
3800 ERRORSTRING optional fourth argument, controls action on no match:
3801 nil: return nil
3802 t: beep
3803 a string: signal an error, using that string."
3804 (let ((case-fold-search t))
3805 (save-excursion
3806 (goto-char pos)
3807 ;; First look for a match for START that goes across POS.
3808 (while (and (not (bobp)) (> (point) (- pos (length start)))
3809 (not (looking-at start)))
3810 (forward-char -1))
3811 ;; If we did not find one, search back for START
3812 ;; (this finds only matches that end at or before POS).
3813 (or (looking-at start)
3814 (progn
3815 (goto-char pos)
3816 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
3817 (let (found)
3818 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
3819 (not (setq found (and (<= (match-beginning 0) pos)
3820 (> (match-end 0) pos))))))
3821 (if (and found (<= (match-beginning 0) pos)
3822 (> (match-end 0) pos))
3823 (match-string-no-properties 1)
3824 (cond ((null errorstring)
3825 nil)
3826 ((eq errorstring t)
3827 (beep)
3828 nil)
3830 (error "No %s around position %d" errorstring pos))))))))
3832 (defun Info-mouse-follow-nearest-node (click)
3833 "\\<Info-mode-map>Follow a node reference near point.
3834 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3835 At end of the node's text, moves to the next node, or up if none."
3836 (interactive "e")
3837 (mouse-set-point click)
3838 (and (not (Info-follow-nearest-node))
3839 (save-excursion (forward-line 1) (eobp))
3840 (Info-next-preorder)))
3842 (defun Info-follow-nearest-node (&optional fork)
3843 "Follow a node reference near point.
3844 If point is on a reference, follow that reference. Otherwise,
3845 if point is in a menu item description, follow that menu item.
3847 If FORK is non-nil (interactively with a prefix arg), show the node in
3848 a new Info buffer.
3849 If FORK is a string, it is the name to use for the new buffer."
3850 (interactive "P")
3851 (or (Info-try-follow-nearest-node fork)
3852 (when (save-excursion
3853 (search-backward "\n* menu:" nil t))
3854 (save-excursion
3855 (beginning-of-line)
3856 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3857 (beginning-of-line 0))
3858 (when (looking-at "\\* +\\([^\t\n]*\\):")
3859 (Info-goto-node
3860 (Info-extract-menu-item (match-string-no-properties 1)) fork)
3861 t)))
3862 (and (eq this-command 'Info-mouse-follow-nearest-node)
3863 ;; Don't raise an error when mouse-1 is bound to this - it's
3864 ;; often used to simply select the window or frame.
3865 (eq 'mouse-1 (event-basic-type last-input-event)))
3866 (user-error "Point neither on reference nor in menu item description")))
3868 ;; Common subroutine.
3869 (defun Info-try-follow-nearest-node (&optional fork)
3870 "Follow a node reference near point. Return non-nil if successful.
3871 If FORK is non-nil, it is passed to `Info-goto-node'."
3872 (let (node)
3873 (cond
3874 ((setq node (Info-get-token (point) "[hf]t?tps?://"
3875 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3876 (browse-url node)
3877 (setq node t))
3878 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
3879 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3880 (Info-follow-reference node fork))
3881 ;; footnote
3882 ((setq node (Info-get-token (point) "(" "\\(([0-9]+)\\)"))
3883 (let ((old-point (point)) new-point)
3884 (save-excursion
3885 (goto-char (point-min))
3886 (when (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t)
3887 (setq new-point (if (< old-point (point))
3888 ;; Go to footnote reference
3889 (and (search-forward node nil t)
3890 ;; Put point at beginning of link
3891 (match-beginning 0))
3892 ;; Go to footnote definition
3893 (search-backward node nil t)))))
3894 (if new-point
3895 (progn
3896 (goto-char new-point)
3897 (setq node t))
3898 (setq node nil))))
3899 ;; menu item: node name
3900 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3901 (Info-goto-node node fork))
3902 ;; menu item: node name or index entry
3903 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3904 (beginning-of-line)
3905 (forward-char 2)
3906 (setq node (Info-extract-menu-node-name nil (Info-index-node)))
3907 (Info-goto-node node fork))
3908 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3909 (Info-goto-node node fork))
3910 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3911 (Info-goto-node node fork))
3912 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3913 (Info-goto-node "Top" fork))
3914 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3915 (Info-goto-node node fork)))
3916 node))
3918 (defun Info-mouse-follow-link (click)
3919 "Follow a link where you click."
3920 (interactive "@e")
3921 (let* ((position (event-start click))
3922 (posn-string (and position (posn-string position)))
3923 (link-args (if posn-string
3924 (get-text-property (cdr posn-string)
3925 'link-args
3926 (car posn-string))
3927 (get-char-property (posn-point position)
3928 'link-args))))
3929 (cond ((stringp link-args)
3930 (Info-goto-node link-args))
3931 ;; These special values of the `link-args' property are used
3932 ;; for navigation; see `Info-fontify-node'.
3933 ((eq link-args 'prev) (Info-prev))
3934 ((eq link-args 'next) (Info-next))
3935 ((eq link-args 'up) (Info-up)))))
3938 (defvar Info-mode-map
3939 (let ((map (make-keymap)))
3940 (suppress-keymap map)
3941 (define-key map "." 'beginning-of-buffer)
3942 (define-key map " " 'Info-scroll-up)
3943 (define-key map [?\S-\ ] 'Info-scroll-down)
3944 (define-key map "\C-m" 'Info-follow-nearest-node)
3945 (define-key map "\t" 'Info-next-reference)
3946 (define-key map "\e\t" 'Info-prev-reference)
3947 (define-key map [backtab] 'Info-prev-reference)
3948 (define-key map "1" 'Info-nth-menu-item)
3949 (define-key map "2" 'Info-nth-menu-item)
3950 (define-key map "3" 'Info-nth-menu-item)
3951 (define-key map "4" 'Info-nth-menu-item)
3952 (define-key map "5" 'Info-nth-menu-item)
3953 (define-key map "6" 'Info-nth-menu-item)
3954 (define-key map "7" 'Info-nth-menu-item)
3955 (define-key map "8" 'Info-nth-menu-item)
3956 (define-key map "9" 'Info-nth-menu-item)
3957 (define-key map "0" 'undefined)
3958 (define-key map "?" 'Info-summary)
3959 (define-key map "]" 'Info-forward-node)
3960 (define-key map "[" 'Info-backward-node)
3961 (define-key map "<" 'Info-top-node)
3962 (define-key map ">" 'Info-final-node)
3963 (define-key map "b" 'beginning-of-buffer)
3964 (put 'beginning-of-buffer :advertised-binding "b")
3965 (define-key map "d" 'Info-directory)
3966 (define-key map "e" 'end-of-buffer)
3967 (define-key map "f" 'Info-follow-reference)
3968 (define-key map "g" 'Info-goto-node)
3969 (define-key map "h" 'Info-help)
3970 ;; This is for compatibility with standalone info (>~ version 5.2).
3971 ;; Though for some time, standalone info had H and h reversed.
3972 ;; See <http://debbugs.gnu.org/16455>.
3973 (define-key map "H" 'describe-mode)
3974 (define-key map "i" 'Info-index)
3975 (define-key map "I" 'Info-virtual-index)
3976 (define-key map "l" 'Info-history-back)
3977 (define-key map "L" 'Info-history)
3978 (define-key map "m" 'Info-menu)
3979 (define-key map "n" 'Info-next)
3980 (define-key map "p" 'Info-prev)
3981 (define-key map "q" 'Info-exit)
3982 (define-key map "r" 'Info-history-forward)
3983 (define-key map "s" 'Info-search)
3984 (define-key map "S" 'Info-search-case-sensitively)
3985 (define-key map "\M-n" 'clone-buffer)
3986 (define-key map "t" 'Info-top-node)
3987 (define-key map "T" 'Info-toc)
3988 (define-key map "u" 'Info-up)
3989 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3990 (define-key map "w" 'Info-copy-current-node-name)
3991 (define-key map "c" 'Info-copy-current-node-name)
3992 ;; `^' for consistency with `dired-up-directory'.
3993 (define-key map "^" 'Info-up)
3994 (define-key map "," 'Info-index-next)
3995 (define-key map "\177" 'Info-scroll-down)
3996 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
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