Update copyright year to 2014 by running admin/update-copyright.
[emacs.git] / lisp / info.el
blob84fc13ccc7da4776211f92426f204022eb5421a3
1 ;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985-1986, 1992-2014 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
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 (error "Info file %s does not exist" filename)))
921 filename))))
923 (defun Info-find-node (filename nodename &optional no-going-back strict-case)
924 "Go to an Info node specified as separate FILENAME and NODENAME.
925 NO-GOING-BACK is non-nil if recovering from an error in this function;
926 it says do not attempt further (recursive) error recovery.
928 This function first looks for a case-sensitive match for NODENAME;
929 if none is found it then tries a case-insensitive match (unless
930 STRICT-CASE is non-nil)."
931 (info-initialize)
932 (setq filename (Info-find-file filename))
933 ;; Go into Info buffer.
934 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
935 ;; Record the node we are leaving, if we were in one.
936 (and (not no-going-back)
937 Info-current-file
938 (push (list Info-current-file Info-current-node (point))
939 Info-history))
940 (Info-find-node-2 filename nodename no-going-back strict-case))
942 ;;;###autoload
943 (defun Info-on-current-buffer (&optional nodename)
944 "Use Info mode to browse the current Info buffer.
945 With a prefix arg, this queries for the node name to visit first;
946 otherwise, that defaults to `Top'."
947 (interactive
948 (list (if current-prefix-arg
949 (completing-read "Node name: " (Info-build-node-completions)
950 nil t "Top"))))
951 (unless nodename (setq nodename "Top"))
952 (info-initialize)
953 (Info-mode)
954 (set (make-local-variable 'Info-current-file)
955 (or buffer-file-name
956 ;; If called on a non-file buffer, make a fake file name.
957 (concat default-directory (buffer-name))))
958 (Info-find-node-2 nil nodename))
960 (defun Info-revert-find-node (filename nodename)
961 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
962 When *info* is already displaying FILENAME and NODENAME, the window position
963 is preserved, if possible."
964 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
965 (let ((old-filename Info-current-file)
966 (old-nodename Info-current-node)
967 (window-selected (eq (selected-window) (get-buffer-window)))
968 (pcolumn (current-column))
969 (pline (count-lines (point-min) (line-beginning-position)))
970 (wline (count-lines (point-min) (window-start)))
971 (new-history (and Info-current-file
972 (list Info-current-file Info-current-node (point)))))
973 ;; When `Info-current-file' is nil, `Info-find-node-2' rereads the file.
974 (setq Info-current-file nil)
975 (Info-find-node filename nodename)
976 (if (and (equal old-filename Info-current-file)
977 (equal old-nodename Info-current-node))
978 (progn
979 ;; note goto-line is no good, we want to measure from point-min
980 (when window-selected
981 (goto-char (point-min))
982 (forward-line wline)
983 (set-window-start (selected-window) (point)))
984 (goto-char (point-min))
985 (forward-line pline)
986 (move-to-column pcolumn))
987 ;; only add to the history when coming from a different file+node
988 (if new-history
989 (setq Info-history (cons new-history Info-history))))))
991 (defun Info-revert-buffer-function (_ignore-auto noconfirm)
992 (when (or noconfirm (y-or-n-p "Revert info buffer? "))
993 (Info-revert-find-node Info-current-file Info-current-node)
994 (message "Reverted %s" Info-current-file)))
996 (defun Info-find-in-tag-table-1 (marker regexp case-fold)
997 "Find a node in a tag table.
998 MARKER specifies the buffer and position to start searching at.
999 REGEXP is a regular expression matching nodes or references. Its first
1000 group should match `Node:' or `Ref:'.
1001 CASE-FOLD t means search for a case-insensitive match.
1002 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1003 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
1004 where the match was found, and MODE is `major-mode' of the buffer in
1005 which the match was found."
1006 (let ((case-fold-search case-fold))
1007 (with-current-buffer (marker-buffer marker)
1008 (goto-char marker)
1010 ;; Search tag table
1011 (beginning-of-line)
1012 (when (re-search-forward regexp nil t)
1013 (list (string-equal "Ref:" (match-string 1))
1014 (+ (point-min) (read (current-buffer)))
1015 major-mode)))))
1017 (defun Info-find-in-tag-table (marker regexp &optional strict-case)
1018 "Find a node in a tag table.
1019 MARKER specifies the buffer and position to start searching at.
1020 REGEXP is a regular expression matching nodes or references. Its first
1021 group should match `Node:' or `Ref:'.
1022 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1023 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
1024 where the match was found, and MODE is `major-mode' of the buffer in
1025 which the match was found.
1026 This function tries to find a case-sensitive match first, then a
1027 case-insensitive match is tried (unless optional argument STRICT-CASE
1028 is non-nil)."
1029 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
1030 (or strict-case (car result)
1031 (setq result (Info-find-in-tag-table-1 marker regexp t)))
1032 result))
1034 (defun Info-find-node-in-buffer-1 (regexp case-fold)
1035 "Find a node or anchor in the current buffer.
1036 REGEXP is a regular expression matching nodes or references. Its first
1037 group should match `Node:' or `Ref:'.
1038 CASE-FOLD t means search for a case-insensitive match.
1039 Value is the position at which a match was found, or nil if not found."
1040 (let ((case-fold-search case-fold)
1041 found)
1042 (save-excursion
1043 (if (Info-node-at-bob-matching regexp)
1044 (setq found (point))
1045 (while (and (not found)
1046 (search-forward "\n\^_" nil t))
1047 (forward-line 1)
1048 (let ((beg (point)))
1049 (forward-line 1)
1050 (if (re-search-backward regexp beg t)
1051 (setq found (line-beginning-position)))))))
1052 found))
1054 (defun Info-find-node-in-buffer (regexp &optional strict-case)
1055 "Find a node or anchor in the current buffer.
1056 REGEXP is a regular expression matching nodes or references. Its first
1057 group should match `Node:' or `Ref:'.
1058 Value is the position at which a match was found, or nil if not found.
1059 This function looks for a case-sensitive match first. If none is found,
1060 a case-insensitive match is tried (unless optional argument STRICT-CASE
1061 is non-nil)."
1062 (or (Info-find-node-in-buffer-1 regexp nil)
1063 (and (not strict-case)
1064 (Info-find-node-in-buffer-1 regexp t))))
1066 (defun Info-find-node-2 (filename nodename &optional no-going-back strict-case)
1067 (buffer-disable-undo (current-buffer))
1068 (or (derived-mode-p 'Info-mode)
1069 (Info-mode))
1070 (widen)
1071 (setq Info-current-node nil)
1072 (unwind-protect
1073 (let ((case-fold-search t)
1074 (virtual-fun (Info-virtual-fun 'find-node
1075 (or filename Info-current-file)
1076 nodename))
1077 anchorpos)
1078 (cond
1079 ((functionp virtual-fun)
1080 (let ((filename (or filename Info-current-file)))
1081 (setq buffer-read-only nil)
1082 (setq Info-current-file filename
1083 Info-current-subfile nil
1084 Info-current-file-completions nil
1085 buffer-file-name nil)
1086 (erase-buffer)
1087 (Info-virtual-call virtual-fun filename nodename no-going-back)
1088 (set-marker Info-tag-table-marker nil)
1089 (setq buffer-read-only t)
1090 (set-buffer-modified-p nil)
1091 (set (make-local-variable 'Info-current-node-virtual) t)))
1092 ((not (and
1093 ;; Reread a file when moving from a virtual node.
1094 (not Info-current-node-virtual)
1095 (or (null filename)
1096 (equal Info-current-file filename))))
1097 ;; Switch files if necessary
1098 (let ((inhibit-read-only t))
1099 (when Info-current-node-virtual
1100 ;; When moving from a virtual node.
1101 (set (make-local-variable 'Info-current-node-virtual) nil)
1102 (if (null filename)
1103 (setq filename Info-current-file)))
1104 (setq Info-current-file nil
1105 Info-current-subfile nil
1106 Info-current-file-completions nil
1107 buffer-file-name nil)
1108 (erase-buffer)
1109 (info-insert-file-contents filename nil)
1110 (setq default-directory (file-name-directory filename))
1111 (set-buffer-modified-p nil)
1112 (set (make-local-variable 'Info-file-supports-index-cookies)
1113 (Info-file-supports-index-cookies filename))
1115 ;; See whether file has a tag table. Record the location if yes.
1116 (goto-char (point-max))
1117 (forward-line -8)
1118 ;; Use string-equal, not equal, to ignore text props.
1119 (if (not (or (string-equal nodename "*")
1120 (not
1121 (search-forward "\^_\nEnd tag table\n" nil t))))
1122 (let (pos)
1123 ;; We have a tag table. Find its beginning.
1124 ;; Is this an indirect file?
1125 (search-backward "\nTag table:\n")
1126 (setq pos (point))
1127 (if (save-excursion
1128 (forward-line 2)
1129 (looking-at "(Indirect)\n"))
1130 ;; It is indirect. Copy it to another buffer
1131 ;; and record that the tag table is in that buffer.
1132 (let ((buf (current-buffer))
1133 (tagbuf
1134 (or Info-tag-table-buffer
1135 (generate-new-buffer " *info tag table*"))))
1136 (setq Info-tag-table-buffer tagbuf)
1137 (with-current-buffer tagbuf
1138 (buffer-disable-undo (current-buffer))
1139 (setq case-fold-search t)
1140 (erase-buffer)
1141 (insert-buffer-substring buf))
1142 (set-marker Info-tag-table-marker
1143 (match-end 0) tagbuf))
1144 (set-marker Info-tag-table-marker pos)))
1145 (set-marker Info-tag-table-marker nil))
1146 (setq Info-current-file filename)
1149 ;; Use string-equal, not equal, to ignore text props.
1150 (if (string-equal nodename "*")
1151 (progn (setq Info-current-node nodename)
1152 (Info-set-mode-line))
1153 ;; Possibilities:
1155 ;; 1. Anchor found in tag table
1156 ;; 2. Anchor *not* in tag table
1158 ;; 3. Node found in tag table
1159 ;; 4. Node *not* found in tag table, but found in file
1160 ;; 5. Node *not* in tag table, and *not* in file
1162 ;; *Or* the same, but in an indirect subfile.
1164 ;; Search file for a suitable node.
1165 (let ((guesspos (point-min))
1166 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1167 (if (stringp nodename)
1168 (regexp-quote nodename)
1170 "\\) *[,\t\n\177]")))
1172 (catch 'foo
1174 ;; First, search a tag table, if any
1175 (when (marker-position Info-tag-table-marker)
1176 (let* ((m Info-tag-table-marker)
1177 (found (Info-find-in-tag-table m regexp strict-case)))
1179 (when found
1180 ;; FOUND is (ANCHOR POS MODE).
1181 (setq guesspos (nth 1 found))
1183 ;; If this is an indirect file, determine which
1184 ;; file really holds this node and read it in.
1185 (unless (eq (nth 2 found) 'Info-mode)
1186 ;; Note that the current buffer must be the
1187 ;; *info* buffer on entry to
1188 ;; Info-read-subfile. Thus the hackery above.
1189 (setq guesspos (Info-read-subfile guesspos)))
1191 ;; Handle anchor
1192 (when (nth 0 found)
1193 (goto-char (setq anchorpos guesspos))
1194 (throw 'foo t)))))
1196 ;; Else we may have a node, which we search for:
1197 (goto-char (max (point-min)
1198 (- (byte-to-position guesspos) 1000)))
1200 ;; Now search from our advised position (or from beg of
1201 ;; buffer) to find the actual node. First, check
1202 ;; whether the node is right where we are, in case the
1203 ;; buffer begins with a node.
1204 (let ((pos (Info-find-node-in-buffer regexp strict-case)))
1205 (when pos
1206 (goto-char pos)
1207 (throw 'foo t)))
1209 (when (string-match "\\([^.]+\\)\\." nodename)
1210 (let (Info-point-loc)
1211 (Info-find-node-2
1212 filename (match-string 1 nodename) no-going-back))
1213 (widen)
1214 (throw 'foo t))
1216 ;; No such anchor in tag table or node in tag table or file
1217 (user-error "No such node or anchor: %s" nodename))
1219 (Info-select-node)
1220 (goto-char (point-min))
1221 (forward-line 1) ; skip header line
1222 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1223 ;; (forward-line 1))
1225 (cond (anchorpos
1226 (let ((new-history (list Info-current-file
1227 (substring-no-properties nodename))))
1228 ;; Add anchors to the history too
1229 (setq Info-history-list
1230 (cons new-history
1231 (remove new-history Info-history-list))))
1232 (goto-char anchorpos))
1233 ((numberp Info-point-loc)
1234 (forward-line (- Info-point-loc 2))
1235 (setq Info-point-loc nil))
1236 ((stringp Info-point-loc)
1237 (Info-find-index-name Info-point-loc)
1238 (setq Info-point-loc nil))))))
1239 ;; If we did not finish finding the specified node,
1240 ;; go back to the previous one.
1241 (or Info-current-node no-going-back (null Info-history)
1242 (let ((hist (car Info-history)))
1243 (setq Info-history (cdr Info-history))
1244 (Info-find-node (nth 0 hist) (nth 1 hist) t)
1245 (goto-char (nth 2 hist))))))
1247 ;; Cache the contents of the (virtual) dir file, once we have merged
1248 ;; it for the first time, so we can save time subsequently.
1249 (defvar Info-dir-contents nil)
1251 ;; Cache for the directory we decided to use for the default-directory
1252 ;; of the merged dir text.
1253 (defvar Info-dir-contents-directory nil)
1255 ;; Record the file attributes of all the files from which we
1256 ;; constructed Info-dir-contents.
1257 (defvar Info-dir-file-attributes nil)
1259 (defvar Info-dir-file-name nil)
1261 ;; Construct the Info directory node by merging the files named `dir'
1262 ;; from various directories. Set the *info* buffer's
1263 ;; default-directory to the first directory we actually get any text
1264 ;; from.
1265 (defun Info-insert-dir ()
1266 (if (and Info-dir-contents Info-dir-file-attributes
1267 ;; Verify that none of the files we used has changed
1268 ;; since we used it.
1269 (eval (cons 'and
1270 (mapcar (lambda (elt)
1271 (let ((curr (file-attributes
1272 ;; Handle symlinks
1273 (file-truename (car elt)))))
1275 ;; Don't compare the access time.
1276 (if curr (setcar (nthcdr 4 curr) 0))
1277 (setcar (nthcdr 4 (cdr elt)) 0)
1278 (equal (cdr elt) curr)))
1279 Info-dir-file-attributes))))
1280 (progn
1281 (insert Info-dir-contents)
1282 (goto-char (point-min)))
1283 (let ((dirs (if Info-additional-directory-list
1284 (append Info-directory-list
1285 Info-additional-directory-list)
1286 Info-directory-list))
1287 (dir-file-attrs nil)
1288 ;; Bind this in case the user sets it to nil.
1289 (case-fold-search t)
1290 ;; This is set non-nil if we find a problem in some input files.
1291 problems
1292 buffers buffer others nodes dirs-done)
1294 ;; Search the directory list for the directory file.
1295 (while dirs
1296 (let ((truename (file-truename (expand-file-name (car dirs)))))
1297 (or (member truename dirs-done)
1298 (member (directory-file-name truename) dirs-done)
1299 ;; Try several variants of specified name.
1300 ;; Try upcasing, appending `.info', or both.
1301 (let* (file
1302 (attrs
1304 (progn (setq file (expand-file-name "dir" truename))
1305 (file-attributes file))
1306 (progn (setq file (expand-file-name "DIR" truename))
1307 (file-attributes file))
1308 (progn (setq file (expand-file-name "dir.info" truename))
1309 (file-attributes file))
1310 (progn (setq file (expand-file-name "DIR.INFO" truename))
1311 (file-attributes file))
1312 ;; Shouldn't really happen, but sometimes does,
1313 ;; eg on Debian systems with buggy packages;
1314 ;; so may as well try it.
1315 ;; http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00005.html
1316 (progn (setq file (expand-file-name "dir.gz" truename))
1317 (file-attributes file)))))
1318 (setq dirs-done
1319 (cons truename
1320 (cons (directory-file-name truename)
1321 dirs-done)))
1322 (if attrs
1323 (with-current-buffer (generate-new-buffer " info dir")
1324 (or buffers
1325 (message "Composing main Info directory..."))
1326 (condition-case nil
1327 ;; Index nodes include null bytes. DIR
1328 ;; files should not have indices, but who
1329 ;; knows...
1330 (let ((inhibit-null-byte-detection t))
1331 (insert-file-contents file)
1332 (set (make-local-variable 'Info-dir-file-name)
1333 file)
1334 (push (current-buffer) buffers)
1335 (push (cons file attrs) dir-file-attrs))
1336 (error (kill-buffer (current-buffer))))))))
1337 (unless (cdr dirs)
1338 (set (make-local-variable 'Info-dir-contents-directory)
1339 (file-name-as-directory (car dirs))))
1340 (setq dirs (cdr dirs))))
1342 (or buffers
1343 (error "Can't find the Info directory node"))
1345 ;; Distinguish the dir file that comes with Emacs from all the
1346 ;; others. Yes, that is really what this is supposed to do.
1347 ;; The definition of `Info-directory-list' puts it first on that
1348 ;; list and so last in `buffers' at this point.
1349 (setq buffer (car (last buffers))
1350 others (delq buffer buffers))
1352 ;; Insert the entire original dir file as a start; note that we've
1353 ;; already saved its default directory to use as the default
1354 ;; directory for the whole concatenation.
1355 (save-excursion (insert-buffer-substring buffer))
1357 ;; Look at each of the other buffers one by one.
1358 (dolist (other others)
1359 (let (this-buffer-nodes)
1360 ;; In each, find all the menus.
1361 (with-current-buffer other
1362 (goto-char (point-min))
1363 ;; Find each menu, and add an elt to NODES for it.
1364 (while (re-search-forward "^\\* Menu:" nil t)
1365 (while (and (zerop (forward-line 1)) (eolp)))
1366 (let ((beg (point))
1367 nodename end)
1368 (re-search-backward "^\^_")
1369 (search-forward "Node: ")
1370 (setq nodename (Info-following-node-name))
1371 (search-forward "\n\^_" nil 'move)
1372 (beginning-of-line)
1373 (setq end (point))
1374 (push (list nodename other beg end) this-buffer-nodes)))
1375 (if (assoc-string "top" this-buffer-nodes t)
1376 (setq nodes (nconc this-buffer-nodes nodes))
1377 (setq problems t)
1378 (message "No `top' node in %s" Info-dir-file-name)))))
1379 ;; Add to the main menu a menu item for each other node.
1380 (re-search-forward "^\\* Menu:")
1381 (forward-line 1)
1382 (let ((menu-items '("top"))
1383 (end (save-excursion (search-forward "\^_" nil t) (point))))
1384 (dolist (node nodes)
1385 (let ((nodename (car node)))
1386 (save-excursion
1387 (or (member (downcase nodename) menu-items)
1388 (re-search-forward (concat "^\\* +"
1389 (regexp-quote nodename)
1390 "::")
1391 end t)
1392 (progn
1393 (insert "* " nodename "::" "\n")
1394 (push nodename menu-items)))))))
1395 ;; Now take each node of each of the other buffers
1396 ;; and merge it into the main buffer.
1397 (dolist (node nodes)
1398 (let ((case-fold-search t)
1399 (nodename (car node)))
1400 (goto-char (point-min))
1401 ;; Find the like-named node in the main buffer.
1402 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1403 (regexp-quote nodename)
1404 "[,\n\t]")
1405 nil t)
1406 (progn
1407 (search-forward "\n\^_" nil 'move)
1408 (beginning-of-line)
1409 (insert "\n"))
1410 ;; If none exists, add one.
1411 (goto-char (point-max))
1412 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
1413 ;; Merge the text from the other buffer's menu
1414 ;; into the menu in the like-named node in the main buffer.
1415 (apply 'insert-buffer-substring (cdr node))))
1416 (Info-dir-remove-duplicates)
1417 ;; Kill all the buffers we just made, including the special one excised.
1418 (mapc 'kill-buffer (cons buffer buffers))
1419 (goto-char (point-min))
1420 (if problems
1421 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1422 (message "Composing main Info directory...done"))
1423 (set (make-local-variable 'Info-dir-contents) (buffer-string))
1424 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
1425 (setq default-directory Info-dir-contents-directory))
1427 (defvar Info-streamline-headings
1428 '(("Emacs" . "Emacs")
1429 ("Programming" . "Programming")
1430 ("Libraries" . "Libraries")
1431 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
1432 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1434 (defun Info-dir-remove-duplicates ()
1435 (let (limit)
1436 (goto-char (point-min))
1437 ;; Remove duplicate headings in the same menu.
1438 (while (search-forward "\n* Menu:" nil t)
1439 (setq limit (save-excursion (search-forward "\n\^_" nil t)))
1440 ;; Look for the next heading to unify.
1441 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1442 (let ((name (match-string 1))
1443 (start (match-beginning 0))
1444 (entries nil) re)
1445 ;; Check whether this heading should be streamlined.
1446 (save-match-data
1447 (dolist (x Info-streamline-headings)
1448 (when (string-match (car x) name)
1449 (setq name (cdr x))
1450 (setq re (car x)))))
1451 (if re (replace-match name t t nil 1))
1452 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
1453 (match-beginning 0)
1454 (or limit (point-max))))
1455 ;; Look for other headings of the same category and merge them.
1456 (save-excursion
1457 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1458 (when (if re (save-match-data (string-match re (match-string 1)))
1459 (equal name (match-string 1)))
1460 (forward-line 0)
1461 ;; Delete redundant heading.
1462 (delete-region (match-beginning 0) (point))
1463 ;; Push the entries onto `text'.
1464 (push
1465 (delete-and-extract-region
1466 (point)
1467 (if (re-search-forward "^[^* \n\t]" nil t)
1468 (match-beginning 0)
1469 (or limit (point-max))))
1470 entries)
1471 (forward-line 0))))
1472 ;; Insert the entries just found.
1473 (while (= (line-beginning-position 0) (1- (point)))
1474 (backward-char))
1475 (dolist (entry (nreverse entries))
1476 (insert entry)
1477 (while (= (line-beginning-position 0) (1- (point)))
1478 (delete-region (1- (point)) (point))))
1480 ;; Now remove duplicate entries under the same heading.
1481 (let (seen)
1482 (save-restriction
1483 (narrow-to-region start (point))
1484 (goto-char (point-min))
1485 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil 'move)
1486 ;; Fold case straight away; `member-ignore-case' here wasteful.
1487 (let ((x (downcase (match-string 1))))
1488 (if (member x seen)
1489 (delete-region
1490 (match-beginning 0)
1491 (if (re-search-forward "^[^ \t]" nil 'move)
1492 (goto-char (match-beginning 0))
1493 (point-max)))
1494 (push x seen)))))))))))
1496 ;; Note that on entry to this function the current-buffer must be the
1497 ;; *info* buffer; not the info tags buffer.
1498 (defun Info-read-subfile (nodepos)
1499 ;; NODEPOS is either a position (in the Info file as a whole,
1500 ;; not relative to a subfile) or the name of a subfile.
1501 (let (lastfilepos
1502 lastfilename)
1503 (if (numberp nodepos)
1504 (with-current-buffer (marker-buffer Info-tag-table-marker)
1505 (goto-char (point-min))
1506 (or (looking-at "\^_")
1507 (search-forward "\n\^_"))
1508 (forward-line 2)
1509 (catch 'foo
1510 (while (not (looking-at "\^_"))
1511 (if (not (eolp))
1512 (let ((beg (point))
1513 thisfilepos thisfilename)
1514 (search-forward ": ")
1515 (setq thisfilename (buffer-substring beg (- (point) 2)))
1516 (setq thisfilepos (+ (point-min) (read (current-buffer))))
1517 ;; read in version 19 stops at the end of number.
1518 ;; Advance to the next line.
1519 (forward-line 1)
1520 (if (> thisfilepos nodepos)
1521 (throw 'foo t))
1522 (setq lastfilename thisfilename)
1523 (setq lastfilepos thisfilepos))
1524 (forward-line 1)))))
1525 (setq lastfilename nodepos)
1526 (setq lastfilepos 0))
1527 ;; Assume previous buffer is in Info-mode.
1528 ;; (set-buffer (get-buffer "*info*"))
1529 (or (equal Info-current-subfile lastfilename)
1530 (let ((inhibit-read-only t))
1531 (setq buffer-file-name nil)
1532 (widen)
1533 (erase-buffer)
1534 (info-insert-file-contents lastfilename)
1535 (set-buffer-modified-p nil)
1536 (setq Info-current-subfile lastfilename)))
1537 ;; Widen in case we are in the same subfile as before.
1538 (widen)
1539 (goto-char (point-min))
1540 ;; Skip the summary segment for `Info-search'.
1541 (if (looking-at "\^_")
1542 (forward-char 1)
1543 (search-forward "\n\^_"))
1544 ;; Don't add the length of the skipped summary segment to
1545 ;; the value returned to `Info-find-node-2'. (Bug#14125)
1546 (if (numberp nodepos)
1547 (+ (- nodepos lastfilepos) (point-min)))))
1549 (defun Info-unescape-quotes (value)
1550 "Unescape double quotes and backslashes in VALUE."
1551 (let ((start 0)
1552 (unquote value))
1553 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start)
1554 (setq unquote (replace-match "" t t unquote 1))
1555 (setq start (- (match-end 0) 1)))
1556 unquote))
1558 ;; As of Texinfo 4.6, makeinfo writes constructs like
1559 ;; \0\h[image param=value ...\h\0]
1560 ;; into the Info file for handling images.
1561 (defun Info-split-parameter-string (parameter-string)
1562 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
1563 PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
1564 If VALUE contains whitespace or double quotes, it must be quoted
1565 in double quotes and any double quotes or backslashes must be
1566 escaped (\\\",\\\\)."
1567 (let ((start 0)
1568 (parameter-alist))
1569 (while (string-match
1570 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1571 parameter-string start)
1572 (setq start (match-end 0))
1573 (push (cons (match-string 1 parameter-string)
1574 (or (match-string 2 parameter-string)
1575 (Info-unescape-quotes
1576 (match-string 3 parameter-string))))
1577 parameter-alist))
1578 parameter-alist))
1580 (defun Info-display-images-node ()
1581 "Display images in current node."
1582 (save-excursion
1583 (let ((inhibit-read-only t)
1584 (case-fold-search t))
1585 (goto-char (point-min))
1586 (while (re-search-forward
1587 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1588 nil t)
1589 (let* ((start (match-beginning 1))
1590 (parameter-alist (Info-split-parameter-string (match-string 2)))
1591 (src (cdr (assoc-string "src" parameter-alist))))
1592 (if (display-images-p)
1593 (let* ((image-file (if src (if (file-name-absolute-p src) src
1594 (concat default-directory src))
1595 ""))
1596 (image (if (file-exists-p image-file)
1597 (create-image image-file)
1598 (or (cdr (assoc-string "text" parameter-alist))
1599 (and src (concat "[broken image:" src "]"))
1600 "[broken image]"))))
1601 (if (not (get-text-property start 'display))
1602 (add-text-properties
1603 start (point)
1604 `(display ,image rear-nonsticky (display)
1605 help-echo ,(cdr (assoc-string "alt" parameter-alist))))))
1606 ;; text-only display, show alternative text if provided, or
1607 ;; otherwise a clue that there's meant to be a picture
1608 (delete-region start (point))
1609 (insert (or (cdr (assoc-string "text" parameter-alist))
1610 (cdr (assoc-string "alt" parameter-alist))
1611 (and src (concat "[image:" src "]"))
1612 "[image]"))))))
1613 (set-buffer-modified-p nil)))
1615 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1616 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1617 ;; including one optional trailing newline.
1618 (defun Info-hide-cookies-node ()
1619 "Hide unrecognized cookies in current node."
1620 (save-excursion
1621 (let ((inhibit-read-only t)
1622 (case-fold-search t))
1623 (goto-char (point-min))
1624 (while (re-search-forward
1625 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1626 nil t)
1627 (let* ((start (match-beginning 1)))
1628 (if (and (not (get-text-property start 'invisible))
1629 (not (get-text-property start 'display)))
1630 (put-text-property start (point) 'invisible t)))))
1631 (set-buffer-modified-p nil)))
1633 (defun Info-select-node ()
1634 "Select the Info node that point is in."
1635 ;; Bind this in case the user sets it to nil.
1636 (let ((case-fold-search t))
1637 (save-excursion
1638 ;; Find beginning of node.
1639 (if (search-backward "\n\^_" nil 'move)
1640 (forward-line 2)
1641 (if (looking-at "\^_")
1642 (forward-line 1)
1643 (signal 'search-failed (list "\n\^_"))))
1644 ;; Get nodename spelled as it is in the node.
1645 (re-search-forward "Node:[ \t]*")
1646 (setq Info-current-node
1647 (buffer-substring-no-properties (point)
1648 (progn
1649 (skip-chars-forward "^,\t\n")
1650 (point))))
1651 (Info-set-mode-line)
1652 ;; Find the end of it, and narrow.
1653 (beginning-of-line)
1654 (let (active-expression)
1655 ;; Narrow to the node contents
1656 (narrow-to-region (point)
1657 (if (re-search-forward "\n[\^_\f]" nil t)
1658 (prog1
1659 (1- (point))
1660 (if (looking-at "[\n\^_\f]*execute: ")
1661 (progn
1662 (goto-char (match-end 0))
1663 (setq active-expression
1664 (read (current-buffer))))))
1665 (point-max)))
1666 (if Info-enable-active-nodes (eval active-expression))
1667 ;; Add a new unique history item to full history list
1668 (let ((new-history (list Info-current-file Info-current-node)))
1669 (setq Info-history-list
1670 (cons new-history (remove new-history Info-history-list)))
1671 (setq Info-history-forward nil))
1672 (if (not (eq Info-fontify-maximum-menu-size nil))
1673 (Info-fontify-node))
1674 (Info-display-images-node)
1675 (Info-hide-cookies-node)
1676 (run-hooks 'Info-selection-hook)))))
1678 (defvar Info-mode-line-node-keymap
1679 (let ((map (make-sparse-keymap)))
1680 (define-key map [mode-line mouse-1] 'Info-mouse-scroll-up)
1681 (define-key map [mode-line mouse-3] 'Info-mouse-scroll-down)
1682 map)
1683 "Keymap to put on the Info node name in the mode line.")
1685 (defun Info-set-mode-line ()
1686 (setq mode-line-buffer-identification
1687 (nconc (propertized-buffer-identification "%b")
1688 (list
1689 (concat
1690 " ("
1691 (if (stringp Info-current-file)
1692 (replace-regexp-in-string
1693 "%" "%%"
1694 (file-name-sans-extension
1695 (file-name-nondirectory Info-current-file)))
1696 (format "*%S*" Info-current-file))
1697 ") "
1698 (if Info-current-node
1699 (propertize (replace-regexp-in-string
1700 "%" "%%" Info-current-node)
1701 'face 'mode-line-buffer-id
1702 'help-echo
1703 "mouse-1: scroll forward, mouse-3: scroll back"
1704 'mouse-face 'mode-line-highlight
1705 'local-map Info-mode-line-node-keymap)
1706 ""))))))
1708 ;; Go to an Info node specified with a filename-and-nodename string
1709 ;; of the sort that is found in pointers in nodes.
1711 ;; Don't autoload this function: the correct entry point for other packages
1712 ;; to use is `info'. --Stef
1713 ;; ;;;###autoload
1714 (defun Info-goto-node (nodename &optional fork strict-case)
1715 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1716 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1717 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1718 its sub-files).
1719 Completion is available for node names in the current Info file as well as
1720 in the Info file FILENAME after the closing parenthesis in (FILENAME).
1721 Empty NODENAME in (FILENAME) defaults to the Top node.
1722 If FORK is non-nil (interactively with a prefix arg), show the node in
1723 a new Info buffer.
1724 If FORK is a string, it is the name to use for the new buffer.
1726 This function first looks for a case-sensitive match for the node part
1727 of NODENAME; if none is found it then tries a case-insensitive match
1728 \(unless STRICT-CASE is non-nil)."
1729 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
1730 (info-initialize)
1731 (if fork
1732 (set-buffer
1733 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
1734 (let (filename)
1735 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1736 nodename)
1737 (setq filename (if (= (match-beginning 1) (match-end 1))
1739 (match-string 2 nodename))
1740 nodename (match-string 3 nodename))
1741 (let ((trim (string-match "\\s +\\'" filename)))
1742 (if trim (setq filename (substring filename 0 trim))))
1743 (let ((trim (string-match "\\s +\\'" nodename)))
1744 (if trim (setq nodename (substring nodename 0 trim))))
1745 (if transient-mark-mode (deactivate-mark))
1746 (Info-find-node (if (equal filename "") nil filename)
1747 (if (equal nodename "") "Top" nodename) nil strict-case)))
1749 (defvar Info-read-node-completion-table)
1751 (defun Info-read-node-name-2 (dirs suffixes string pred action)
1752 "Internal function used to complete Info node names.
1753 Return a completion table for Info files---the FILENAME part of a
1754 node named \"(FILENAME)NODENAME\". DIRS is a list of Info
1755 directories to search if FILENAME is not absolute; SUFFIXES is a
1756 list of valid filename suffixes for Info files. See
1757 `try-completion' for a description of the remaining arguments."
1758 (setq suffixes (remove "" suffixes))
1759 (when (file-name-absolute-p string)
1760 (setq dirs (list (file-name-directory string))))
1761 (let ((names nil)
1762 (names-sans-suffix nil)
1763 (suffix (concat (regexp-opt suffixes t) "\\'"))
1764 (string-dir (file-name-directory string)))
1765 (dolist (dir dirs)
1766 (unless dir
1767 (setq dir default-directory))
1768 (if string-dir (setq dir (expand-file-name string-dir dir)))
1769 (when (file-directory-p dir)
1770 (dolist (file (file-name-all-completions
1771 (file-name-nondirectory string) dir))
1772 ;; If the file name has no suffix or a standard suffix,
1773 ;; include it.
1774 (and (or (null (file-name-extension file))
1775 (string-match suffix file))
1776 ;; But exclude subfiles of split Info files.
1777 (not (string-match "-[0-9]+\\'" file))
1778 ;; And exclude backup files.
1779 (not (string-match "~\\'" file))
1780 (push (if string-dir (concat string-dir file) file) names))
1781 ;; If the file name ends in a standard suffix,
1782 ;; add the unsuffixed name as a completion option.
1783 (when (string-match suffix file)
1784 (setq file (substring file 0 (match-beginning 0)))
1785 (push (if string-dir (concat string-dir file) file)
1786 names-sans-suffix)))))
1787 ;; If there is just one file, don't duplicate it with suffixes,
1788 ;; so `Info-read-node-name-1' will be able to complete a single
1789 ;; candidate and to add the terminating ")".
1790 (if (and (= (length names) 1) (= (length names-sans-suffix) 1))
1791 (setq names names-sans-suffix)
1792 (setq names (append names-sans-suffix names)))
1793 (complete-with-action action names string pred)))
1795 (defun Info-read-node-name-1 (string predicate code)
1796 "Internal function used by `Info-read-node-name'.
1797 See `completing-read' for a description of arguments and usage."
1798 (cond
1799 ;; First complete embedded file names.
1800 ((string-match "\\`([^)]*\\'" string)
1801 (completion-table-with-context
1803 (apply-partially 'completion-table-with-terminator ")"
1804 (apply-partially 'Info-read-node-name-2
1805 Info-directory-list
1806 (mapcar 'car Info-suffix-list)))
1807 (substring string 1)
1808 predicate
1809 code))
1810 ;; If a file name was given, complete nodes in the file.
1811 ((string-match "\\`(\\([^)]+\\))" string)
1812 (let ((file0 (match-string 0 string))
1813 (file1 (match-string 1 string))
1814 (nodename (substring string (match-end 0))))
1815 (if (and (equal nodename "") (eq code 'lambda))
1816 ;; Empty node name is permitted that means "Top".
1818 (completion-table-with-context
1819 file0
1820 (apply-partially
1821 (lambda (string pred action)
1822 (complete-with-action
1823 action
1824 (Info-build-node-completions (Info-find-file file1))
1825 string pred)))
1826 nodename predicate code))))
1827 ;; Otherwise use Info-read-node-completion-table.
1828 (t (complete-with-action
1829 code Info-read-node-completion-table string predicate))))
1831 ;; Arrange to highlight the proper letters in the completion list buffer.
1832 (defun Info-read-node-name (prompt)
1833 "Read an Info node name with completion, prompting with PROMPT.
1834 A node name can have the form \"NODENAME\", referring to a node
1835 in the current Info file, or \"(FILENAME)NODENAME\", referring to
1836 a node in FILENAME. \"(FILENAME)\" is a short format to go to
1837 the Top node in FILENAME."
1838 (let* ((completion-ignore-case t)
1839 (Info-read-node-completion-table (Info-build-node-completions))
1840 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1841 (if (equal nodename "")
1842 (Info-read-node-name prompt)
1843 nodename)))
1845 (defun Info-build-node-completions (&optional filename)
1846 (if filename
1847 (or (cdr (assoc filename Info-file-completions))
1848 (with-temp-buffer
1849 (Info-mode)
1850 (Info-goto-node (format "(%s)Top" filename))
1851 (Info-build-node-completions-1)
1852 (push (cons filename Info-current-file-completions) Info-file-completions)
1853 Info-current-file-completions))
1854 (or Info-current-file-completions
1855 (Info-build-node-completions-1))))
1857 (defun Info-build-node-completions-1 ()
1858 (let ((compl nil)
1859 ;; Bind this in case the user sets it to nil.
1860 (case-fold-search t)
1861 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1862 (save-excursion
1863 (save-restriction
1864 (or Info-tag-table-marker
1865 (error "No Info tags found"))
1866 (if (marker-buffer Info-tag-table-marker)
1867 (let ((marker Info-tag-table-marker))
1868 (set-buffer (marker-buffer marker))
1869 (widen)
1870 (goto-char marker)
1871 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1872 (setq compl
1873 (cons (list (match-string-no-properties 2))
1874 compl))))
1875 (widen)
1876 (goto-char (point-min))
1877 ;; If the buffer begins with a node header, process that first.
1878 (if (Info-node-at-bob-matching node-regexp)
1879 (setq compl (list (match-string-no-properties 1))))
1880 ;; Now for the rest of the nodes.
1881 (while (search-forward "\n\^_" nil t)
1882 (forward-line 1)
1883 (let ((beg (point)))
1884 (forward-line 1)
1885 (if (re-search-backward node-regexp beg t)
1886 (setq compl
1887 (cons (list (match-string-no-properties 1))
1888 compl))))))))
1889 (setq compl (cons '("*") (nreverse compl)))
1890 (set (make-local-variable 'Info-current-file-completions) compl)
1891 compl))
1894 (defun Info-restore-point (hl)
1895 "If this node has been visited, restore the point value when we left."
1896 (while hl
1897 (if (and (equal (nth 0 (car hl)) Info-current-file)
1898 ;; Use string-equal, not equal, to ignore text props.
1899 (string-equal (nth 1 (car hl)) Info-current-node))
1900 (progn
1901 (goto-char (nth 2 (car hl)))
1902 (setq hl nil)) ;terminate the while at next iter
1903 (setq hl (cdr hl)))))
1905 (defvar Info-search-history nil
1906 "The history list for `Info-search'.")
1908 (defvar Info-search-case-fold nil
1909 "The value of `case-fold-search' from previous `Info-search' command.")
1911 (defun Info--search-loop (regexp bound backward)
1912 (when backward
1913 ;; Hide Info file header for backward search.
1914 (narrow-to-region (save-excursion
1915 (goto-char (point-min))
1916 (search-forward "\n\^_")
1917 (1- (point)))
1918 (point-max)))
1919 (let ((give-up nil)
1920 (found nil)
1921 (beg-found nil))
1922 (while (not (or give-up
1923 (and found
1924 (funcall isearch-filter-predicate
1925 beg-found found))))
1926 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1927 (if (funcall
1928 (if backward #'re-search-backward #'re-search-forward)
1929 regexp bound t)
1930 (setq found (point) beg-found (if backward (match-end 0)
1931 (match-beginning 0)))
1932 (setq give-up t found nil))))
1933 found))
1935 (defun Info-search (regexp &optional bound _noerror _count direction)
1936 "Search for REGEXP, starting from point, and select node it's found in.
1937 If DIRECTION is `backward', search in the reverse direction."
1938 (interactive (list (read-string
1939 (if Info-search-history
1940 (format "Regexp search%s (default %s): "
1941 (if case-fold-search "" " case-sensitively")
1942 (car Info-search-history))
1943 (format "Regexp search%s: "
1944 (if case-fold-search "" " case-sensitively")))
1945 nil 'Info-search-history)))
1946 (deactivate-mark)
1947 (when (equal regexp "")
1948 (setq regexp (car Info-search-history)))
1949 (when regexp
1950 (setq Info-search-case-fold case-fold-search)
1951 (let* ((backward (eq direction 'backward))
1952 (onode Info-current-node)
1953 (ofile Info-current-file)
1954 (opoint (point))
1955 (opoint-min (point-min))
1956 (opoint-max (point-max))
1957 (ostart (window-start))
1958 (osubfile Info-current-subfile)
1959 (found
1960 (save-excursion
1961 (save-restriction
1962 (widen)
1963 (Info--search-loop regexp bound backward)))))
1965 (unless (or (not isearch-mode) (not Info-isearch-search)
1966 Info-isearch-initial-node
1967 bound
1968 (and found (> found opoint-min) (< found opoint-max)))
1969 (signal 'search-failed (list regexp "end of node")))
1971 ;; If no subfiles, give error now.
1972 (unless (or found Info-current-subfile)
1973 (if isearch-mode
1974 (signal 'search-failed (list regexp "end of manual"))
1975 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1976 (if backward
1977 (re-search-backward regexp)
1978 (re-search-forward regexp)))))
1980 (if (and bound (not found))
1981 (signal 'search-failed (list regexp)))
1983 (unless (or found bound)
1984 (unwind-protect
1985 ;; Try other subfiles.
1986 (let ((list ()))
1987 (with-current-buffer (marker-buffer Info-tag-table-marker)
1988 (goto-char (point-min))
1989 (search-forward "\n\^_\nIndirect:")
1990 (save-restriction
1991 (narrow-to-region (point)
1992 (progn (search-forward "\n\^_")
1993 (1- (point))))
1994 (goto-char (point-min))
1995 ;; Find the subfile we just searched.
1996 (search-forward (concat "\n" osubfile ": "))
1997 ;; Skip that one.
1998 (forward-line (if backward 0 1))
1999 (if backward (forward-char -1))
2000 ;; Make a list of all following subfiles.
2001 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
2002 (while (not (if backward (bobp) (eobp)))
2003 (if backward
2004 (re-search-backward "\\(^.*\\): [0-9]+$")
2005 (re-search-forward "\\(^.*\\): [0-9]+$"))
2006 (goto-char (+ (match-end 1) 2))
2007 (setq list (cons (cons (+ (point-min)
2008 (read (current-buffer)))
2009 (match-string-no-properties 1))
2010 list))
2011 (goto-char (if backward
2012 (1- (match-beginning 0))
2013 (1+ (match-end 0)))))
2014 ;; Put in forward order
2015 (setq list (nreverse list))))
2016 (while list
2017 (message "Searching subfile %s..." (cdr (car list)))
2018 (Info-read-subfile (car (car list)))
2019 (when backward (goto-char (point-max)))
2020 (setq list (cdr list))
2021 (setq found (Info--search-loop regexp nil backward))
2022 (if found
2023 (setq list nil)))
2024 (if found
2025 (message "")
2026 (signal 'search-failed (if isearch-mode
2027 (list regexp "end of manual")
2028 (list regexp)))))
2029 (if (not found)
2030 (progn (Info-read-subfile osubfile)
2031 (goto-char opoint)
2032 (Info-select-node)
2033 (set-window-start (selected-window) ostart)))))
2035 (if (and (string= osubfile Info-current-subfile)
2036 (> found opoint-min)
2037 (< found opoint-max))
2038 ;; Search landed in the same node
2039 (goto-char found)
2040 (widen)
2041 (goto-char found)
2042 (save-match-data (Info-select-node)))
2044 ;; Use string-equal, not equal, to ignore text props.
2045 (or (and (string-equal onode Info-current-node)
2046 (equal ofile Info-current-file))
2047 (and isearch-mode isearch-wrapped
2048 (eq opoint (if isearch-forward opoint-min opoint-max)))
2049 (setq Info-history (cons (list ofile onode opoint)
2050 Info-history))))))
2052 (defun Info-search-case-sensitively ()
2053 "Search for a regexp case-sensitively."
2054 (interactive)
2055 (let ((case-fold-search nil))
2056 (call-interactively 'Info-search)))
2058 (defun Info-search-next ()
2059 "Search for next regexp from a previous `Info-search' command."
2060 (interactive)
2061 (let ((case-fold-search Info-search-case-fold))
2062 (if Info-search-history
2063 (Info-search (car Info-search-history))
2064 (call-interactively 'Info-search))))
2066 (defun Info-search-backward (regexp &optional bound noerror count)
2067 "Search for REGEXP in the reverse direction."
2068 (interactive (list (read-string
2069 (if Info-search-history
2070 (format "Regexp search%s backward (default %s): "
2071 (if case-fold-search "" " case-sensitively")
2072 (car Info-search-history))
2073 (format "Regexp search%s backward: "
2074 (if case-fold-search "" " case-sensitively")))
2075 nil 'Info-search-history)))
2076 (Info-search regexp bound noerror count 'backward))
2078 (defun Info-isearch-search ()
2079 (if Info-isearch-search
2080 (lambda (string &optional bound noerror count)
2081 (let ((Info-search-whitespace-regexp
2082 (if (if isearch-regexp
2083 isearch-regexp-lax-whitespace
2084 isearch-lax-whitespace)
2085 search-whitespace-regexp)))
2086 (Info-search
2087 (cond
2088 (isearch-word
2089 ;; Lax version of word search
2090 (let ((lax (not (or isearch-nonincremental
2091 (eq (length string)
2092 (length (isearch--state-string
2093 (car isearch-cmds))))))))
2094 (if (functionp isearch-word)
2095 (funcall isearch-word string lax)
2096 (word-search-regexp string lax))))
2097 (isearch-regexp string)
2098 (t (regexp-quote string)))
2099 bound noerror count
2100 (unless isearch-forward 'backward)))
2101 (point))
2102 (isearch-search-fun-default)))
2104 (defun Info-isearch-wrap ()
2105 (if Info-isearch-search
2106 (if Info-isearch-initial-node
2107 (progn
2108 (if isearch-forward (Info-top-node) (Info-final-node))
2109 (goto-char (if isearch-forward (point-min) (point-max))))
2110 (setq Info-isearch-initial-node Info-current-node)
2111 (setq isearch-wrapped nil))
2112 (goto-char (if isearch-forward (point-min) (point-max)))))
2114 (defun Info-isearch-push-state ()
2115 `(lambda (cmd)
2116 (Info-isearch-pop-state cmd ',Info-current-file ',Info-current-node)))
2118 (defun Info-isearch-pop-state (_cmd file node)
2119 (or (and (equal Info-current-file file)
2120 (equal Info-current-node node))
2121 (progn (Info-find-node file node) (sit-for 0))))
2123 (defun Info-isearch-start ()
2124 (setq Info-isearch-initial-node
2125 ;; Don't stop at initial node for nonincremental search.
2126 ;; Otherwise this variable is set after first search failure.
2127 (and isearch-nonincremental Info-current-node))
2128 (setq Info-isearch-initial-history Info-history
2129 Info-isearch-initial-history-list Info-history-list)
2130 (add-hook 'isearch-mode-end-hook 'Info-isearch-end nil t))
2132 (defun Info-isearch-end ()
2133 ;; Remove intermediate nodes (visited while searching)
2134 ;; from the history. Add only the last node (where Isearch ended).
2135 (if (> (length Info-history)
2136 (length Info-isearch-initial-history))
2137 (setq Info-history
2138 (nthcdr (- (length Info-history)
2139 (length Info-isearch-initial-history)
2141 Info-history)))
2142 (if (> (length Info-history-list)
2143 (length Info-isearch-initial-history-list))
2144 (setq Info-history-list
2145 (cons (car Info-history-list)
2146 Info-isearch-initial-history-list)))
2147 (remove-hook 'isearch-mode-end-hook 'Info-isearch-end t))
2149 (defun Info-isearch-filter (beg-found found)
2150 "Test whether the current search hit is a visible useful text.
2151 Return non-nil if the text from BEG-FOUND to FOUND is visible
2152 and is not in the header line or a tag table."
2153 (save-match-data
2154 (let ((backward (< found beg-found)))
2155 (not
2157 (and (not search-invisible)
2158 (if backward
2159 (or (text-property-not-all found beg-found 'invisible nil)
2160 (text-property-not-all found beg-found 'display nil))
2161 (or (text-property-not-all beg-found found 'invisible nil)
2162 (text-property-not-all beg-found found 'display nil))))
2163 ;; Skip node header line
2164 (and (save-excursion (forward-line -1)
2165 (looking-at "\^_"))
2166 (forward-line (if backward -1 1)))
2167 ;; Skip Tag Table node
2168 (save-excursion
2169 (and (search-backward "\^_" nil t)
2170 (looking-at
2171 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
2174 (defun Info-extract-pointer (name &optional errorname)
2175 "Extract the value of the node-pointer named NAME.
2176 If there is none, use ERRORNAME in the error message;
2177 if ERRORNAME is nil, just return nil."
2178 ;; Bind this in case the user sets it to nil.
2179 (let ((case-fold-search t))
2180 (save-excursion
2181 (goto-char (point-min))
2182 (let ((bound (point)))
2183 (forward-line 1)
2184 (cond ((re-search-backward
2185 (concat name ":" (Info-following-node-name-re)) bound t)
2186 (match-string-no-properties 1))
2187 ((not (eq errorname t))
2188 (user-error "Node has no %s"
2189 (capitalize (or errorname name)))))))))
2191 (defun Info-following-node-name-re (&optional allowedchars)
2192 "Return a regexp matching a node name.
2193 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
2194 saying which chars may appear in the node name.
2195 Submatch 1 is the complete node name.
2196 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2197 Submatch 3 is the local part of the node name.
2198 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2199 (concat "[ \t\n]*" ;Skip leading space.
2200 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2201 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
2202 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
2203 "\\|\\)\\)")) ;Allow empty node names.
2205 ;;; For compatibility; other files have used this name.
2206 (defun Info-following-node-name ()
2207 (and (looking-at (Info-following-node-name-re))
2208 (match-string-no-properties 1)))
2210 (defun Info-next ()
2211 "Go to the next node of this node."
2212 (interactive)
2213 ;; In case another window is currently selected
2214 (save-window-excursion
2215 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
2216 (Info-goto-node (Info-extract-pointer "next"))))
2218 (defun Info-prev ()
2219 "Go to the previous node of this node."
2220 (interactive)
2221 ;; In case another window is currently selected
2222 (save-window-excursion
2223 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
2224 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2226 (defun Info-up (&optional same-file)
2227 "Go to the superior node of this node.
2228 If SAME-FILE is non-nil, do not move to a different Info file."
2229 (interactive)
2230 ;; In case another window is currently selected
2231 (save-window-excursion
2232 (or (derived-mode-p 'Info-mode) (switch-to-buffer "*info*"))
2233 (let ((old-node Info-current-node)
2234 (old-file Info-current-file)
2235 (node (Info-extract-pointer "up")) p)
2236 (and same-file
2237 (string-match "^(" node)
2238 (error "Up node is in another Info file"))
2239 (Info-goto-node node)
2240 (setq p (point))
2241 (goto-char (point-min))
2242 (if (and (stringp old-file)
2243 (search-forward "\n* Menu:" nil t)
2244 (re-search-forward
2245 (if (string-equal old-node "Top")
2246 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
2247 (concat "\n\\* +\\(" (regexp-quote old-node)
2248 ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
2249 nil t))
2250 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2251 (goto-char p)
2252 (Info-restore-point Info-history)))))
2254 (defun Info-history-back ()
2255 "Go back in the history to the last node visited."
2256 (interactive)
2257 (or Info-history
2258 (user-error "This is the first Info node you looked at"))
2259 (let ((history-forward
2260 (cons (list Info-current-file Info-current-node (point))
2261 Info-history-forward))
2262 filename nodename opoint)
2263 (setq filename (car (car Info-history)))
2264 (setq nodename (car (cdr (car Info-history))))
2265 (setq opoint (car (cdr (cdr (car Info-history)))))
2266 (setq Info-history (cdr Info-history))
2267 (Info-find-node filename nodename)
2268 (setq Info-history (cdr Info-history))
2269 (setq Info-history-forward history-forward)
2270 (goto-char opoint)))
2272 (defalias 'Info-last 'Info-history-back)
2274 (defun Info-history-forward ()
2275 "Go forward in the history of visited nodes."
2276 (interactive)
2277 (or Info-history-forward
2278 (user-error "This is the last Info node you looked at"))
2279 (let ((history-forward (cdr Info-history-forward))
2280 filename nodename opoint)
2281 (setq filename (car (car Info-history-forward)))
2282 (setq nodename (car (cdr (car Info-history-forward))))
2283 (setq opoint (car (cdr (cdr (car Info-history-forward)))))
2284 (Info-find-node filename nodename)
2285 (setq Info-history-forward history-forward)
2286 (goto-char opoint)))
2288 (add-to-list 'Info-virtual-files
2289 '("\\`dir\\'"
2290 (toc-nodes . Info-directory-toc-nodes)
2291 (find-file . Info-directory-find-file)
2292 (find-node . Info-directory-find-node)
2295 (defun Info-directory-toc-nodes (filename)
2296 "Directory-specific implementation of `Info-toc-nodes'."
2297 `(,filename
2298 ("Top" nil nil nil)))
2300 (defun Info-directory-find-file (filename &optional _noerror)
2301 "Directory-specific implementation of `Info-find-file'."
2302 filename)
2304 (defun Info-directory-find-node (_filename _nodename &optional _no-going-back)
2305 "Directory-specific implementation of `Info-find-node-2'."
2306 (Info-insert-dir))
2308 ;;;###autoload
2309 (defun Info-directory ()
2310 "Go to the Info directory node."
2311 (interactive)
2312 (Info-find-node "dir" "top"))
2314 (add-to-list 'Info-virtual-files
2315 '("\\`\\*History\\*\\'"
2316 (toc-nodes . Info-history-toc-nodes)
2317 (find-file . Info-history-find-file)
2318 (find-node . Info-history-find-node)
2321 (defun Info-history-toc-nodes (filename)
2322 "History-specific implementation of `Info-toc-nodes'."
2323 `(,filename
2324 ("Top" nil nil nil)))
2326 (defun Info-history-find-file (filename &optional _noerror)
2327 "History-specific implementation of `Info-find-file'."
2328 filename)
2330 (defun Info-history-find-node (filename nodename &optional _no-going-back)
2331 "History-specific implementation of `Info-find-node-2'."
2332 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2333 (or filename Info-current-file) nodename))
2334 (insert "Recently Visited Nodes\n")
2335 (insert "**********************\n\n")
2336 (insert "* Menu:\n\n")
2337 (let ((hl (remove '("*History*" "Top") Info-history-list)))
2338 (while hl
2339 (let ((file (nth 0 (car hl)))
2340 (node (nth 1 (car hl))))
2341 (if (stringp file)
2342 (insert "* " node ": ("
2343 (propertize (or (file-name-directory file) "") 'invisible t)
2344 (file-name-nondirectory file)
2345 ")" node ".\n")))
2346 (setq hl (cdr hl)))))
2348 (defun Info-history ()
2349 "Go to a node with a menu of visited nodes."
2350 (interactive)
2351 (Info-find-node "*History*" "Top")
2352 (Info-next-reference)
2353 (Info-next-reference))
2355 (add-to-list 'Info-virtual-nodes
2356 '("\\`\\*TOC\\*\\'"
2357 (find-node . Info-toc-find-node)
2360 (defun Info-toc-find-node (filename nodename &optional _no-going-back)
2361 "Toc-specific implementation of `Info-find-node-2'."
2362 (let* ((curr-file (substring-no-properties (or filename Info-current-file)))
2363 (curr-node (substring-no-properties (or nodename Info-current-node)))
2364 (node-list (Info-toc-nodes curr-file)))
2365 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2366 curr-file curr-node))
2367 (insert "Table of Contents\n")
2368 (insert "*****************\n\n")
2369 (insert "*Note Top::\n")
2370 (Info-toc-insert
2371 (nth 3 (assoc "Top" node-list)) ; get Top nodes
2372 node-list 0 curr-file)
2373 (unless (bobp)
2374 (let ((Info-hide-note-references 'hide)
2375 (Info-fontify-visited-nodes nil))
2376 (setq Info-current-file filename Info-current-node "*TOC*")
2377 (goto-char (point-min))
2378 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t)
2379 (point-min))
2380 (point-max))
2381 (Info-fontify-node)
2382 (widen)))))
2384 (defun Info-toc ()
2385 "Go to a node with table of contents of the current Info file.
2386 Table of contents is created from the tree structure of menus."
2387 (interactive)
2388 (Info-find-node Info-current-file "*TOC*")
2389 (let ((prev-node (nth 1 (car Info-history))) p)
2390 (goto-char (point-min))
2391 (if (setq p (search-forward (concat "*Note " prev-node ":") nil t))
2392 (setq p (- p (length prev-node) 2)))
2393 (goto-char (or p (point-min)))))
2395 (defun Info-toc-insert (nodes node-list level curr-file)
2396 "Insert table of contents with references to nodes."
2397 (let ((section "Top"))
2398 (while nodes
2399 (let ((node (assoc (car nodes) node-list)))
2400 (unless (member (nth 2 node) (list nil section))
2401 (insert (setq section (nth 2 node)) "\n"))
2402 (insert (make-string level ?\t))
2403 (insert "*Note " (car nodes) ":: \n")
2404 (Info-toc-insert (nth 3 node) node-list (1+ level) curr-file)
2405 (setq nodes (cdr nodes))))))
2407 (defun Info-toc-build (file)
2408 "Build table of contents from menus of Info FILE and its subfiles."
2409 (with-temp-buffer
2410 (let* ((file (and (stringp file) (Info-find-file file)))
2411 (default-directory (or (and (stringp file)
2412 (file-name-directory file))
2413 default-directory))
2414 (main-file (and (stringp file) file))
2415 (sections '(("Top" "Top")))
2416 nodes subfiles)
2417 (while (or main-file subfiles)
2418 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2419 (erase-buffer)
2420 (info-insert-file-contents (or main-file (car subfiles)))
2421 (goto-char (point-min))
2422 (while (and (search-forward "\n\^_\nFile:" nil 'move)
2423 (search-forward "Node: " nil 'move))
2424 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2425 (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
2426 (point-max)) 2))
2427 (upnode (and (re-search-forward
2428 (concat "Up:" (Info-following-node-name-re))
2429 bound t)
2430 (match-string-no-properties 1)))
2431 (section "Top")
2432 menu-items)
2433 (when (and upnode (string-match "(" upnode)) (setq upnode nil))
2434 (when (and (not (Info-index-node nodename file))
2435 (re-search-forward "^\\* Menu:" bound t))
2436 (forward-line 1)
2437 (beginning-of-line)
2438 (setq bound (or (and (equal nodename "Top")
2439 (save-excursion
2440 (re-search-forward
2441 "^[ \t-]*The Detailed Node Listing" nil t)))
2442 bound))
2443 (while (< (point) bound)
2444 (cond
2445 ;; Menu item line
2446 ((looking-at "^\\* +[^:]+:")
2447 (beginning-of-line)
2448 (forward-char 2)
2449 (let ((menu-node-name (substring-no-properties
2450 (Info-extract-menu-node-name))))
2451 (setq menu-items (cons menu-node-name menu-items))
2452 (if (equal nodename "Top")
2453 (setq sections
2454 (cons (list menu-node-name section) sections)))))
2455 ;; Other non-empty strings in the Top node are section names
2456 ((and (equal nodename "Top")
2457 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2458 (setq section (match-string-no-properties 1))))
2459 (forward-line 1)
2460 (beginning-of-line)))
2461 (setq nodes (cons (list nodename upnode
2462 (cadr (assoc nodename sections))
2463 (nreverse menu-items))
2464 nodes))
2465 (goto-char bound)))
2466 (if main-file
2467 (save-excursion
2468 (goto-char (point-min))
2469 (if (search-forward "\n\^_\nIndirect:" nil t)
2470 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2471 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2472 (setq subfiles (cons (match-string-no-properties 1)
2473 subfiles)))))
2474 (setq subfiles (nreverse subfiles)
2475 main-file nil))
2476 (setq subfiles (cdr subfiles))))
2477 (message "")
2478 (nreverse nodes))))
2480 (defun Info-toc-nodes (filename)
2481 "Return a node list of Info FILENAME with parent-children information.
2482 This information is cached in the variable `Info-toc-nodes' with the help
2483 of the function `Info-toc-build'."
2484 (cond
2485 ((Info-virtual-call
2486 (Info-virtual-fun 'toc-nodes (or filename Info-current-file) nil)
2487 filename))
2489 (or filename (setq filename Info-current-file))
2490 (or (assoc filename Info-toc-nodes)
2491 ;; Skip virtual Info files
2492 (and (or (not (stringp filename))
2493 (Info-virtual-file-p filename))
2494 (push (cons filename nil) Info-toc-nodes))
2495 ;; Scan the entire manual and cache the result in Info-toc-nodes
2496 (let ((nodes (Info-toc-build filename)))
2497 (push (cons filename nodes) Info-toc-nodes)
2498 nodes)
2499 ;; If there is an error, still add nil to the cache
2500 (push (cons filename nil) Info-toc-nodes))
2501 (cdr (assoc filename Info-toc-nodes)))))
2504 (defun Info-follow-reference (footnotename &optional fork)
2505 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2506 FOOTNOTENAME may be an abbreviation of the reference name.
2507 If FORK is non-nil (interactively with a prefix arg), show the node in
2508 a new Info buffer. If FORK is a string, it is the name to use for the
2509 new buffer."
2510 (interactive
2511 (let ((completion-ignore-case t)
2512 (case-fold-search t)
2513 completions default alt-default (start-point (point)) str i bol eol)
2514 (save-excursion
2515 ;; Store end and beginning of line.
2516 (setq eol (line-end-position)
2517 bol (line-beginning-position))
2518 (goto-char (point-min))
2519 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
2520 (setq str (match-string-no-properties 1))
2521 ;; See if this one should be the default.
2522 (and (null default)
2523 (<= (match-beginning 0) start-point)
2524 (<= start-point (point))
2525 (setq default t))
2526 ;; See if this one should be the alternate default.
2527 (and (null alt-default)
2528 (and (<= bol (match-beginning 0))
2529 (<= (point) eol))
2530 (setq alt-default t))
2531 (setq i 0)
2532 (while (setq i (string-match "[ \n\t]+" str i))
2533 (setq str (concat (substring str 0 i) " "
2534 (substring str (match-end 0))))
2535 (setq i (1+ i)))
2536 ;; Record as a completion and perhaps as default.
2537 (if (eq default t) (setq default str))
2538 (if (eq alt-default t) (setq alt-default str))
2539 ;; Don't add this string if it's a duplicate.
2540 (or (assoc-string str completions t)
2541 (push str completions))))
2542 ;; If no good default was found, try an alternate.
2543 (or default
2544 (setq default alt-default))
2545 ;; If only one cross-reference found, then make it default.
2546 (if (eq (length completions) 1)
2547 (setq default (car completions)))
2548 (if completions
2549 (let ((input (completing-read (if default
2550 (concat
2551 "Follow reference named (default "
2552 default "): ")
2553 "Follow reference named: ")
2554 completions nil t)))
2555 (list (if (equal input "")
2556 default input) current-prefix-arg))
2557 (user-error "No cross-references in this node"))))
2559 (unless footnotename
2560 (error "No reference was specified"))
2562 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
2563 (case-fold-search t))
2564 (while (setq i (string-match " " str i))
2565 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
2566 (setq i (+ i 6)))
2567 (save-excursion
2568 ;; Move point to the beginning of reference if point is on reference
2569 (or (looking-at "\\*note[ \n\t]+")
2570 (and (looking-back "\\*note[ \n\t]+")
2571 (goto-char (match-beginning 0)))
2572 (if (and (save-excursion
2573 (goto-char (+ (point) 5)) ; skip a possible *note
2574 (re-search-backward "\\*note[ \n\t]+" nil t)
2575 (looking-at str))
2576 (<= (point) (match-end 0)))
2577 (goto-char (match-beginning 0))))
2578 ;; Go to the reference closest to point
2579 (let ((next-ref (save-excursion (and (re-search-forward str nil t)
2580 (+ (match-beginning 0) 5))))
2581 (prev-ref (save-excursion (and (re-search-backward str nil t)
2582 (+ (match-beginning 0) 5)))))
2583 (goto-char (cond ((and next-ref prev-ref)
2584 (if (< (abs (- next-ref (point)))
2585 (abs (- prev-ref (point))))
2586 next-ref prev-ref))
2587 ((or next-ref prev-ref))
2588 ((user-error "No cross-reference named %s"
2589 footnotename))))
2590 (setq target (Info-extract-menu-node-name t))))
2591 (while (setq i (string-match "[ \t\n]+" target i))
2592 (setq target (concat (substring target 0 i) " "
2593 (substring target (match-end 0))))
2594 (setq i (+ i 1)))
2595 (Info-goto-node target fork)))
2597 (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2598 ;; We allow newline because this is also used in Info-follow-reference,
2599 ;; where the xref name might be wrapped over two lines.
2600 "Regexp that matches a menu entry name upto but not including the colon.
2601 Because of ambiguities, this should be concatenated with something like
2602 `:' and `Info-following-node-name-re'.")
2604 (defun Info-extract-menu-node-name (&optional multi-line index-node)
2605 (skip-chars-forward " \t\n")
2606 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
2607 (Info-following-node-name-re
2608 (cond
2609 (index-node "^,\t\n")
2610 (multi-line "^.,\t")
2611 (t "^.,\t\n")))
2612 "\\)"
2613 (if index-node
2614 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2615 "")))
2616 (if index-node
2617 (setq Info-point-loc
2618 (if (match-beginning 5)
2619 (string-to-number (match-string 5))
2620 (buffer-substring-no-properties
2621 (match-beginning 0) (1- (match-beginning 1)))))
2622 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2623 ;;; (setq Info-point-loc
2624 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2626 (replace-regexp-in-string
2627 "[ \n]+" " "
2628 (or (and (not (equal (match-string-no-properties 2) ""))
2629 (match-string-no-properties 2))
2630 ;; If the node name is the menu entry name (using `entry::').
2631 (buffer-substring-no-properties
2632 (match-beginning 0) (1- (match-beginning 1)))))))
2634 ;; No one calls this.
2635 ;;(defun Info-menu-item-sequence (list)
2636 ;; (while list
2637 ;; (Info-menu (car list))
2638 ;; (setq list (cdr list))))
2640 (defvar Info-complete-menu-buffer)
2641 (defvar Info-complete-next-re nil)
2642 (defvar Info-complete-nodes nil)
2643 (defvar Info-complete-cache nil)
2645 (defconst Info-node-spec-re
2646 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2647 "Regexp to match the text after a : until the terminating `.'.")
2649 (defun Info-complete-menu-item (string predicate action)
2650 ;; This uses two dynamically bound variables:
2651 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2652 ;; is the menu of items we're trying to complete.
2653 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2654 ;; also look for menu items in subsequent nodes as long as those
2655 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2656 ;; not used.
2657 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2658 ;; also look for menu items in these nodes. This feature is currently
2659 ;; only used for completion in Info-index.
2661 ;; Note that `Info-complete-menu-buffer' could be current already,
2662 ;; so we want to save point.
2663 (with-current-buffer Info-complete-menu-buffer
2664 (save-excursion
2665 (let ((completion-ignore-case t)
2666 (case-fold-search t)
2667 (orignode Info-current-node)
2668 nextnode)
2669 (goto-char (point-min))
2670 (search-forward "\n* Menu:")
2671 (cond
2672 ((eq (car-safe action) 'boundaries) nil)
2673 ((eq action 'lambda)
2674 (re-search-forward
2675 (concat "\n\\* +" (regexp-quote string) ":") nil t))
2677 (let ((pattern (concat "\n\\* +\\("
2678 (regexp-quote string)
2679 Info-menu-entry-name-re "\\):"
2680 Info-node-spec-re))
2681 completions
2682 (complete-nodes Info-complete-nodes))
2683 ;; Check the cache.
2684 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
2685 (equal (nth 1 Info-complete-cache) Info-current-node)
2686 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
2687 (equal (nth 5 Info-complete-cache) Info-complete-nodes)
2688 (let ((prev (nth 3 Info-complete-cache)))
2689 (eq t (compare-strings string 0 (length prev)
2690 prev 0 nil t))))
2691 ;; We can reuse the previous list.
2692 (setq completions (nth 4 Info-complete-cache))
2693 ;; The cache can't be used.
2694 (while
2695 (progn
2696 (while (re-search-forward pattern nil t)
2697 (push (match-string-no-properties 1)
2698 completions))
2699 (setq completions (delete-dups completions))
2700 ;; Check subsequent nodes if applicable.
2701 (or (and Info-complete-next-re
2702 (setq nextnode (Info-extract-pointer "next" t))
2703 (string-match Info-complete-next-re nextnode))
2704 (and complete-nodes
2705 (setq complete-nodes (cdr complete-nodes)
2706 nextnode (car complete-nodes)))))
2707 (Info-goto-node nextnode))
2708 ;; Go back to the start node (for the next completion).
2709 (unless (equal Info-current-node orignode)
2710 (Info-goto-node orignode))
2711 ;; Update the cache.
2712 (set (make-local-variable 'Info-complete-cache)
2713 (list Info-current-file Info-current-node
2714 Info-complete-next-re string completions
2715 Info-complete-nodes)))
2716 (complete-with-action action completions string predicate))))))))
2719 (defun Info-menu (menu-item &optional fork)
2720 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2721 The menu item should one of those listed in the current node's menu.
2722 Completion is allowed, and the default menu item is the one point is on.
2723 If FORK is non-nil (interactively with a prefix arg), show the node in
2724 a new Info buffer. If FORK is a string, it is the name to use for the
2725 new buffer."
2726 (interactive
2727 (let (;; If point is within a menu item, use that item as the default
2728 (default nil)
2729 (p (point))
2731 (case-fold-search t))
2732 (save-excursion
2733 (goto-char (point-min))
2734 (if (not (search-forward "\n* menu:" nil t))
2735 (user-error "No menu in this node"))
2736 (setq beg (point))
2737 (and (< (point) p)
2738 (save-excursion
2739 (goto-char p)
2740 (end-of-line)
2741 (if (re-search-backward (concat "\n\\* +\\("
2742 Info-menu-entry-name-re
2743 "\\):") beg t)
2744 (setq default (match-string-no-properties 1))))))
2745 (let ((item nil))
2746 (while (null item)
2747 (setq item (let ((completion-ignore-case t)
2748 (Info-complete-menu-buffer (current-buffer)))
2749 (completing-read (if default
2750 (format "Menu item (default %s): "
2751 default)
2752 "Menu item: ")
2753 'Info-complete-menu-item nil t)))
2754 ;; we rely on the fact that completing-read accepts an input
2755 ;; of "" even when the require-match argument is true and ""
2756 ;; is not a valid possibility
2757 (if (string= item "")
2758 (if default
2759 (setq item default)
2760 ;; ask again
2761 (setq item nil))))
2762 (list item current-prefix-arg))))
2763 ;; there is a problem here in that if several menu items have the same
2764 ;; name you can only go to the node of the first with this command.
2765 (Info-goto-node (Info-extract-menu-item menu-item)
2766 (and fork
2767 (if (stringp fork) fork menu-item))))
2769 (defun Info-extract-menu-item (menu-item)
2770 (setq menu-item (regexp-quote menu-item))
2771 (let ((case-fold-search t))
2772 (save-excursion
2773 (let ((case-fold-search t))
2774 (goto-char (point-min))
2775 (or (search-forward "\n* menu:" nil t)
2776 (user-error "No menu in this node"))
2777 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
2778 (re-search-forward (concat "\n\\* +" menu-item) nil t)
2779 (user-error "No such item in menu"))
2780 (beginning-of-line)
2781 (forward-char 2)
2782 (Info-extract-menu-node-name nil (Info-index-node))))))
2784 ;; If COUNT is nil, use the last item in the menu.
2785 (defun Info-extract-menu-counting (count &optional no-detail)
2786 (let ((case-fold-search t))
2787 (save-excursion
2788 (let ((case-fold-search t)
2789 (bound (when (and no-detail
2790 (re-search-forward
2791 "^[ \t-]*The Detailed Node Listing" nil t))
2792 (match-beginning 0))))
2793 (goto-char (point-min))
2794 (or (search-forward "\n* menu:" bound t)
2795 (user-error "No menu in this node"))
2796 (if count
2797 (or (search-forward "\n* " bound t count)
2798 (error "Too few items in menu"))
2799 (while (search-forward "\n* " bound t)
2800 nil))
2801 (Info-extract-menu-node-name nil (Info-index-node))))))
2803 (defun Info-nth-menu-item ()
2804 "Go to the node of the Nth menu item.
2805 N is the digit argument used to invoke this command."
2806 (interactive)
2807 (Info-goto-node
2808 (Info-extract-menu-counting
2809 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
2811 (defun Info-top-node ()
2812 "Go to the Top node of this file."
2813 (interactive)
2814 (Info-goto-node "Top"))
2816 (defun Info-final-node ()
2817 "Go to the final node in this file."
2818 (interactive)
2819 (Info-goto-node "Top")
2820 (let ((Info-history nil)
2821 (case-fold-search t))
2822 ;; Go to the last node in the menu of Top. But don't delve into
2823 ;; detailed node listings.
2824 (Info-goto-node (Info-extract-menu-counting nil t))
2825 ;; If the last node in the menu is not last in pointer structure,
2826 ;; move forward (but not down- or upward - see bug#1116) until we
2827 ;; can't go any farther.
2828 (while (Info-forward-node t t t) nil)
2829 ;; Then keep moving down to last subnode, unless we reach an index.
2830 (while (and (not (Info-index-node))
2831 (save-excursion (search-forward "\n* Menu:" nil t)))
2832 (Info-goto-node (Info-extract-menu-counting nil)))))
2834 (defun Info-forward-node (&optional not-down not-up no-error)
2835 "Go forward one node, considering all nodes as forming one sequence."
2836 (interactive)
2837 (goto-char (point-min))
2838 (forward-line 1)
2839 (let ((case-fold-search t))
2840 ;; three possibilities, in order of priority:
2841 ;; 1. next node is in a menu in this node (but not in an index)
2842 ;; 2. next node is next at same level
2843 ;; 3. next node is up and next
2844 (cond ((and (not not-down)
2845 (save-excursion (search-forward "\n* menu:" nil t))
2846 (not (Info-index-node)))
2847 (Info-goto-node (Info-extract-menu-counting 1))
2849 ((save-excursion (search-backward "next:" nil t))
2850 (Info-next)
2852 ((and (not not-up)
2853 (save-excursion (search-backward "up:" nil t))
2854 ;; Use string-equal, not equal, to ignore text props.
2855 (not (string-equal (downcase (Info-extract-pointer "up"))
2856 "top")))
2857 (let ((old-node Info-current-node))
2858 (Info-up)
2859 (let ((old-history Info-history)
2860 success)
2861 (unwind-protect
2862 (setq success (Info-forward-node t nil no-error))
2863 (or success (Info-goto-node old-node)))
2864 (if Info-history-skip-intermediate-nodes
2865 (setq Info-history old-history)))))
2866 (no-error nil)
2867 (t (user-error "No pointer forward from this node")))))
2869 (defun Info-backward-node ()
2870 "Go backward one node, considering all nodes as forming one sequence."
2871 (interactive)
2872 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
2873 (upnode (Info-extract-pointer "up" t))
2874 (case-fold-search t))
2875 (cond ((and upnode (string-match "(" upnode))
2876 (user-error "First node in file"))
2877 ((and upnode (or (null prevnode)
2878 ;; Use string-equal, not equal,
2879 ;; to ignore text properties.
2880 (string-equal (downcase prevnode)
2881 (downcase upnode))))
2882 (Info-up))
2883 (prevnode
2884 ;; If we move back at the same level,
2885 ;; go down to find the last subnode*.
2886 (Info-prev)
2887 (let ((old-history Info-history))
2888 (while (and (not (Info-index-node))
2889 (save-excursion (search-forward "\n* Menu:" nil t)))
2890 (Info-goto-node (Info-extract-menu-counting nil)))
2891 (if Info-history-skip-intermediate-nodes
2892 (setq Info-history old-history))))
2894 (user-error "No pointer backward from this node")))))
2896 (defun Info-exit ()
2897 "Exit Info by selecting some other buffer."
2898 (interactive)
2899 (if Info-standalone
2900 (save-buffers-kill-emacs)
2901 (quit-window)))
2903 (defun Info-next-menu-item ()
2904 "Go to the node of the next menu item."
2905 (interactive)
2906 ;; Bind this in case the user sets it to nil.
2907 (let* ((case-fold-search t)
2908 (node
2909 (save-excursion
2910 (forward-line -1)
2911 (search-forward "\n* menu:" nil t)
2912 (and (search-forward "\n* " nil t)
2913 (Info-extract-menu-node-name)))))
2914 (if node (Info-goto-node node)
2915 (user-error "No more items in menu"))))
2917 (defun Info-last-menu-item ()
2918 "Go to the node of the previous menu item."
2919 (interactive)
2920 (save-excursion
2921 (forward-line 1)
2922 ;; Bind this in case the user sets it to nil.
2923 (let* ((case-fold-search t)
2924 (beg (save-excursion
2925 (and (search-backward "\n* menu:" nil t)
2926 (point)))))
2927 (or (and beg (search-backward "\n* " beg t))
2928 (user-error "No previous items in menu")))
2929 (Info-goto-node (save-excursion
2930 (goto-char (match-end 0))
2931 (Info-extract-menu-node-name)))))
2933 (defmacro Info-no-error (&rest body)
2934 `(condition-case nil (progn ,@body t) (error nil)))
2936 (defun Info-next-preorder ()
2937 "Go to the next subnode or the next node, or go up a level."
2938 (interactive)
2939 (cond ((Info-no-error (Info-next-menu-item)))
2940 ((Info-no-error (Info-next)))
2941 ((Info-no-error (Info-up t))
2942 ;; Since we have already gone thru all the items in this menu,
2943 ;; go up to the end of this node.
2944 (goto-char (point-max))
2945 ;; Since logically we are done with the node with that menu,
2946 ;; move on from it. But don't add intermediate nodes
2947 ;; to the history on recursive calls.
2948 (let ((old-history Info-history))
2949 (Info-next-preorder)
2950 (if Info-history-skip-intermediate-nodes
2951 (setq Info-history old-history))))
2953 (user-error "No more nodes"))))
2955 (defun Info-last-preorder ()
2956 "Go to the last node, popping up a level if there is none."
2957 (interactive)
2958 (cond ((and Info-scroll-prefer-subnodes
2959 (Info-no-error
2960 (Info-last-menu-item)
2961 ;; If we go down a menu item, go to the end of the node
2962 ;; so we can scroll back through it.
2963 (goto-char (point-max))))
2964 ;; Keep going down, as long as there are nested menu nodes.
2965 (let ((old-history Info-history))
2966 (while (Info-no-error
2967 (Info-last-menu-item)
2968 ;; If we go down a menu item, go to the end of the node
2969 ;; so we can scroll back through it.
2970 (goto-char (point-max))))
2971 (if Info-history-skip-intermediate-nodes
2972 (setq Info-history old-history)))
2973 (recenter -1))
2974 ((and (Info-no-error (Info-extract-pointer "prev"))
2975 (not (equal (Info-extract-pointer "up")
2976 (Info-extract-pointer "prev"))))
2977 (Info-no-error (Info-prev))
2978 (goto-char (point-max))
2979 (let ((old-history Info-history))
2980 (while (Info-no-error
2981 (Info-last-menu-item)
2982 ;; If we go down a menu item, go to the end of the node
2983 ;; so we can scroll back through it.
2984 (goto-char (point-max))))
2985 (if Info-history-skip-intermediate-nodes
2986 (setq Info-history old-history)))
2987 (recenter -1))
2988 ((Info-no-error (Info-up t))
2989 (goto-char (point-min))
2990 (let ((case-fold-search t))
2991 (or (search-forward "\n* Menu:" nil t)
2992 (goto-char (point-max)))))
2993 (t (user-error "No previous nodes"))))
2995 (defun Info-scroll-up ()
2996 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2997 Once you scroll far enough in a node that its menu appears on the screen
2998 but after point, the next scroll moves into its first subnode, unless
2999 `Info-scroll-prefer-subnodes' is nil.
3001 When you scroll past the end of a node, that goes to the next node if
3002 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
3003 if this node has no successor, it moves to the parent node's successor,
3004 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
3005 the menu of a node, it moves to subnode indicated by the following menu
3006 item. (That case won't normally result from this command, but can happen
3007 in other ways.)"
3009 (interactive)
3010 (if (or (< (window-start) (point-min))
3011 (> (window-start) (point-max)))
3012 (set-window-start (selected-window) (point)))
3013 (let* ((case-fold-search t)
3014 (virtual-end (save-excursion
3015 (goto-char (point-min))
3016 (if (and Info-scroll-prefer-subnodes
3017 (search-forward "\n* Menu:" nil t))
3018 (point)
3019 (point-max)))))
3020 (if (or (< virtual-end (window-start))
3021 (pos-visible-in-window-p virtual-end))
3022 (cond
3023 (Info-scroll-prefer-subnodes (Info-next-preorder))
3024 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
3025 (t (Info-next-preorder)))
3026 (scroll-up))))
3028 (defun Info-mouse-scroll-up (e)
3029 "Scroll one screenful forward in Info, using the mouse.
3030 See `Info-scroll-up'."
3031 (interactive "e")
3032 (save-selected-window
3033 (if (eventp e)
3034 (select-window (posn-window (event-start e))))
3035 (Info-scroll-up)))
3037 (defun Info-scroll-down ()
3038 "Scroll one screenful back in Info, considering all nodes as one sequence.
3039 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
3040 is non-nil, this goes to its last subnode. When you scroll past the
3041 beginning of a node, that goes to the previous node or back up to the
3042 parent node."
3043 (interactive)
3044 (if (or (< (window-start) (point-min))
3045 (> (window-start) (point-max)))
3046 (set-window-start (selected-window) (point)))
3047 (let* ((case-fold-search t)
3048 (current-point (point))
3049 (virtual-end
3050 (and Info-scroll-prefer-subnodes
3051 (save-excursion
3052 (setq current-point (line-beginning-position))
3053 (goto-char (point-min))
3054 (search-forward "\n* Menu:" current-point t)))))
3055 (if (or virtual-end
3056 (pos-visible-in-window-p (point-min) nil t))
3057 (Info-last-preorder)
3058 (scroll-down))))
3060 (defun Info-mouse-scroll-down (e)
3061 "Scroll one screenful backward in Info, using the mouse.
3062 See `Info-scroll-down'."
3063 (interactive "e")
3064 (save-selected-window
3065 (if (eventp e)
3066 (select-window (posn-window (event-start e))))
3067 (Info-scroll-down)))
3069 (defun Info-next-reference-or-link (pat prop)
3070 "Move point to the next pattern-based cross-reference or property-based link.
3071 The next cross-reference is searched using the regexp PAT, and the next link
3072 is searched using the text property PROP. Move point to the closest found position
3073 of either a cross-reference found by `re-search-forward' or a link found by
3074 `next-single-char-property-change'. Return the new position of point, or nil."
3075 (let ((pxref (save-excursion (re-search-forward pat nil t)))
3076 (plink (next-single-char-property-change (point) prop)))
3077 (when (and (< plink (point-max)) (not (get-char-property plink prop)))
3078 (setq plink (next-single-char-property-change plink prop)))
3079 (if (< plink (point-max))
3080 (if (and pxref (<= pxref plink))
3081 (goto-char (or (match-beginning 1) (match-beginning 0)))
3082 (goto-char plink))
3083 (if pxref (goto-char (or (match-beginning 1) (match-beginning 0)))))))
3085 (defun Info-prev-reference-or-link (pat prop)
3086 "Move point to the previous pattern-based cross-reference or property-based link.
3087 The previous cross-reference is searched using the regexp PAT, and the previous link
3088 is searched using the text property PROP. Move point to the closest found position
3089 of either a cross-reference found by `re-search-backward' or a link found by
3090 `previous-single-char-property-change'. Return the new position of point, or nil."
3091 (let ((pxref (save-excursion (re-search-backward pat nil t)))
3092 (plink (previous-single-char-property-change (point) prop)))
3093 (when (and (> plink (point-min)) (not (get-char-property plink prop)))
3094 (setq plink (previous-single-char-property-change plink prop)))
3095 (if (> plink (point-min))
3096 (if (and pxref (>= pxref plink))
3097 (goto-char (or (match-beginning 1) (match-beginning 0)))
3098 (goto-char plink))
3099 (if pxref (goto-char (or (match-beginning 1) (match-beginning 0)))))))
3101 (defun Info-next-reference (&optional recur count)
3102 "Move cursor to the next cross-reference or menu item in the node.
3103 If COUNT is non-nil (interactively with a prefix arg), jump over
3104 COUNT cross-references."
3105 (interactive "i\np")
3106 (unless count
3107 (setq count 1))
3108 (if (< count 0)
3109 (Info-prev-reference recur (- count))
3110 (while (unless (zerop count) (setq count (1- count)))
3111 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3112 (old-pt (point))
3113 (case-fold-search t))
3114 (or (eobp) (forward-char 1))
3115 (or (Info-next-reference-or-link pat 'link)
3116 (progn
3117 (goto-char (point-min))
3118 (or (Info-next-reference-or-link pat 'link)
3119 (progn
3120 (goto-char old-pt)
3121 (user-error "No cross references in this node")))))
3122 (if (looking-at "\\* Menu:")
3123 (if recur
3124 (user-error "No cross references in this node")
3125 (Info-next-reference t))
3126 (if (looking-at "^\\* ")
3127 (forward-char 2)))))))
3129 (defun Info-prev-reference (&optional recur count)
3130 "Move cursor to the previous cross-reference or menu item in the node.
3131 If COUNT is non-nil (interactively with a prefix arg), jump over
3132 COUNT cross-references."
3133 (interactive "i\np")
3134 (unless count
3135 (setq count 1))
3136 (if (< count 0)
3137 (Info-next-reference recur (- count))
3138 (while (unless (zerop count) (setq count (1- count)))
3139 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3140 (old-pt (point))
3141 (case-fold-search t))
3142 (or (Info-prev-reference-or-link pat 'link)
3143 (progn
3144 (goto-char (point-max))
3145 (or (Info-prev-reference-or-link pat 'link)
3146 (progn
3147 (goto-char old-pt)
3148 (user-error "No cross references in this node")))))
3149 (if (looking-at "\\* Menu:")
3150 (if recur
3151 (user-error "No cross references in this node")
3152 (Info-prev-reference t))
3153 (if (looking-at "^\\* ")
3154 (forward-char 2)))))))
3156 (defun Info-index-nodes (&optional file)
3157 "Return a list of names of all index nodes in Info FILE.
3158 If FILE is omitted, it defaults to the current Info file.
3159 First look in a list of cached index node names. Then scan Info
3160 file and its subfiles for nodes with the index cookie. Then try
3161 to find index nodes starting from the first node in the top level
3162 menu whose name contains the word \"Index\", plus any immediately
3163 following nodes whose names also contain the word \"Index\"."
3164 (or file (setq file Info-current-file))
3165 (or (assoc file Info-index-nodes)
3166 ;; Skip virtual Info files
3167 (and (or (not (stringp file))
3168 (Info-virtual-file-p file))
3169 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
3170 (if (Info-file-supports-index-cookies file)
3171 ;; Find nodes with index cookie
3172 (let* ((default-directory (or (and (stringp file)
3173 (file-name-directory
3174 (setq file (Info-find-file file))))
3175 default-directory))
3176 Info-history Info-history-list Info-fontify-maximum-menu-size
3177 (main-file file) subfiles nodes)
3178 (condition-case nil
3179 (with-temp-buffer
3180 (while (or main-file subfiles)
3181 (erase-buffer)
3182 (info-insert-file-contents (or main-file (car subfiles)))
3183 (goto-char (point-min))
3184 (while (search-forward "\0\b[index\0\b]" nil 'move)
3185 (save-excursion
3186 (re-search-backward "^\^_")
3187 (search-forward "Node: ")
3188 (setq nodes (cons (Info-following-node-name) nodes))))
3189 (if main-file
3190 (save-excursion
3191 (goto-char (point-min))
3192 (if (search-forward "\n\^_\nIndirect:" nil t)
3193 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
3194 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
3195 (setq subfiles (cons (match-string-no-properties 1)
3196 subfiles)))))
3197 (setq subfiles (nreverse subfiles)
3198 main-file nil))
3199 (setq subfiles (cdr subfiles)))))
3200 (error nil))
3201 (if nodes
3202 (setq nodes (nreverse nodes)
3203 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
3204 nodes)
3205 ;; Else find nodes with the word "Index" in the node name
3206 (let ((case-fold-search t)
3207 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
3208 nodes node)
3209 (condition-case nil
3210 (with-temp-buffer
3211 (Info-mode)
3212 (Info-find-node file "Top")
3213 (when (and (search-forward "\n* menu:" nil t)
3214 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
3215 (goto-char (match-beginning 1))
3216 (setq nodes (list (Info-extract-menu-node-name)))
3217 (Info-goto-node (car nodes))
3218 (while (and (setq node (Info-extract-pointer "next" t))
3219 (string-match "\\<Index\\>" node))
3220 (push node nodes)
3221 (Info-goto-node node))))
3222 (error nil))
3223 (if nodes
3224 (setq nodes (nreverse nodes)
3225 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
3226 nodes))
3227 ;; If file has no index nodes, still add it to the cache
3228 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
3229 (cdr (assoc file Info-index-nodes)))
3231 (defun Info-index-node (&optional node file)
3232 "Return non-nil value if NODE is an index node.
3233 If NODE is nil, check the current Info node.
3234 If FILE is nil, check the current Info file."
3235 (or file (setq file Info-current-file))
3236 (if (and (or (and node (not (equal node Info-current-node)))
3237 (assoc file Info-index-nodes))
3238 (not Info-current-node-virtual))
3239 (member (or node Info-current-node) (Info-index-nodes file))
3240 ;; Don't search all index nodes if request is only for the current node
3241 ;; and file is not in the cache of index nodes
3242 (save-match-data
3243 (if (Info-file-supports-index-cookies file)
3244 (save-excursion
3245 (goto-char (+ (or (save-excursion
3246 (search-backward "\n\^_" nil t))
3247 (point-min)) 2))
3248 (search-forward "\0\b[index\0\b]"
3249 (or (save-excursion
3250 (search-forward "\n\^_" nil t))
3251 (point-max)) t))
3252 (string-match "\\<Index\\>" (or node Info-current-node ""))))))
3254 (defun Info-goto-index ()
3255 "Go to the first index node."
3256 (let ((node (car (Info-index-nodes))))
3257 (or node (error "No index"))
3258 (Info-goto-node node)))
3260 ;;;###autoload
3261 (defun Info-index (topic)
3262 "Look up a string TOPIC in the index for this manual and go to that entry.
3263 If there are no exact matches to the specified topic, this chooses
3264 the first match which is a case-insensitive substring of a topic.
3265 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3266 Give an empty topic name to go to the Index node itself."
3267 (interactive
3268 (list
3269 (let ((completion-ignore-case t)
3270 (Info-complete-menu-buffer (clone-buffer))
3271 (Info-complete-nodes (Info-index-nodes))
3272 (Info-history-list nil))
3273 (if (equal Info-current-file "dir")
3274 (error "The Info directory node has no index; use m to select a manual"))
3275 (unwind-protect
3276 (with-current-buffer Info-complete-menu-buffer
3277 (Info-goto-index)
3278 (completing-read "Index topic: " 'Info-complete-menu-item))
3279 (kill-buffer Info-complete-menu-buffer)))))
3280 (if (equal Info-current-file "dir")
3281 (error "The Info directory node has no index; use m to select a manual"))
3282 ;; Strip leading colon in topic; index format does not allow them.
3283 (if (and (stringp topic)
3284 (> (length topic) 0)
3285 (= (aref topic 0) ?:))
3286 (setq topic (substring topic 1)))
3287 (let ((orignode Info-current-node)
3288 (pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3289 (regexp-quote topic)))
3290 node (nodes (Info-index-nodes))
3291 (ohist-list Info-history-list)
3292 (case-fold-search t))
3293 (Info-goto-index)
3294 (or (equal topic "")
3295 (let ((matches nil)
3296 (exact nil)
3297 ;; We bind Info-history to nil for internal node-switches so
3298 ;; that we don't put junk in the history. In the first
3299 ;; Info-goto-index call, above, we do update the history
3300 ;; because that is what the user's previous node choice into it.
3301 (Info-history nil)
3302 found)
3303 (while
3304 (progn
3305 (goto-char (point-min))
3306 (while (re-search-forward pattern nil t)
3307 (let ((entry (match-string-no-properties 1))
3308 (nodename (match-string-no-properties 3))
3309 (line (string-to-number (concat "0" (match-string 4)))))
3310 (add-text-properties
3311 (- (match-beginning 2) (match-beginning 1))
3312 (- (match-end 2) (match-beginning 1))
3313 '(face info-index-match) entry)
3314 (push (list entry nodename Info-current-node line) matches)))
3315 (setq nodes (cdr nodes) node (car nodes)))
3316 (Info-goto-node node))
3317 (or matches
3318 (progn
3319 (Info-goto-node orignode)
3320 (user-error "No `%s' in index" topic)))
3321 ;; Here it is a feature that assoc is case-sensitive.
3322 (while (setq found (assoc topic matches))
3323 (setq exact (cons found exact)
3324 matches (delq found matches)))
3325 (setq Info-history-list ohist-list)
3326 (setq Info-index-alternatives (nconc exact (nreverse matches)))
3327 (Info-index-next 0)))))
3329 (defun Info-index-next (num)
3330 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3331 (interactive "p")
3332 (or Info-index-alternatives
3333 (user-error "No previous `i' command"))
3334 (while (< num 0)
3335 (setq num (+ num (length Info-index-alternatives))))
3336 (while (> num 0)
3337 (setq Info-index-alternatives
3338 (nconc (cdr Info-index-alternatives)
3339 (list (car Info-index-alternatives)))
3340 num (1- num)))
3341 (Info-goto-node (nth 1 (car Info-index-alternatives)))
3342 (if (> (nth 3 (car Info-index-alternatives)) 0)
3343 ;; Forward 2 lines less because `Info-find-node-2' initially
3344 ;; puts point to the 2nd line.
3345 (forward-line (- (nth 3 (car Info-index-alternatives)) 2))
3346 (forward-line 3) ; don't search in headers
3347 (let ((name (car (car Info-index-alternatives))))
3348 (Info-find-index-name name)))
3349 (message "Found `%s' in %s. %s"
3350 (car (car Info-index-alternatives))
3351 (nth 2 (car Info-index-alternatives))
3352 (if (cdr Info-index-alternatives)
3353 (format "(%s total; use `%s' for next)"
3354 (length Info-index-alternatives)
3355 (key-description (where-is-internal
3356 'Info-index-next overriding-local-map
3357 t)))
3358 "(Only match)")))
3360 (defun Info-find-index-name (name)
3361 "Move point to the place within the current node where NAME is defined."
3362 (let ((case-fold-search t))
3363 (if (or (re-search-forward (format
3364 "[a-zA-Z]+: %s\\( \\|$\\)"
3365 (regexp-quote name)) nil t)
3366 ;; Find a function definition with a return type.
3367 (re-search-forward (format
3368 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3369 (regexp-quote name)) nil t)
3370 (search-forward (format "`%s'" name) nil t)
3371 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
3372 (search-forward
3373 (format "`%s'" (substring name 0 (match-beginning 1)))
3374 nil t))
3375 (search-forward name nil t)
3376 ;; Try again without the " <1>" makeinfo can append
3377 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
3378 (Info-find-index-name (match-string 1 name))))
3379 (progn (beginning-of-line) t) ;; non-nil for recursive call
3380 (goto-char (point-min)))))
3382 (add-to-list 'Info-virtual-nodes
3383 '("\\`\\*Index.*\\*\\'"
3384 (find-node . Info-virtual-index-find-node)
3385 (slow . t)
3388 (defvar Info-virtual-index-nodes nil
3389 "Alist of cached matched index search nodes.
3390 Each element is ((FILENAME . TOPIC) MATCHES) where
3391 FILENAME is the file name of the manual,
3392 TOPIC is the search string given as an argument to `Info-virtual-index',
3393 MATCHES is a list of index matches found by `Info-index'.")
3395 (defun Info-virtual-index-find-node (filename nodename &optional _no-going-back)
3396 "Index-specific implementation of `Info-find-node-2'."
3397 ;; Generate Index-like menu of matches
3398 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename)
3399 ;; Generate Index-like menu of matches
3400 (let* ((topic (match-string 1 nodename))
3401 (matches (cdr (assoc (cons (or filename Info-current-file) topic)
3402 Info-virtual-index-nodes))))
3403 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3404 (or filename Info-current-file) nodename))
3405 (insert "Info Virtual Index\n")
3406 (insert "******************\n\n")
3407 (insert "Index entries that match `" topic "':\n\n")
3408 (insert "\0\b[index\0\b]\n")
3409 (if (null matches)
3410 (insert "No matches found.\n")
3411 (insert "* Menu:\n\n")
3412 (dolist (entry matches)
3413 (insert (format "* %-38s %s.%s\n"
3414 (format "%s [%s]:" (nth 0 entry) (nth 2 entry))
3415 (nth 1 entry)
3416 (if (nth 3 entry)
3417 (format " (line %s)" (nth 3 entry))
3418 ""))))))
3419 ;; Else, Generate a list of previous search results
3420 (let ((nodes (reverse Info-virtual-index-nodes)))
3421 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3422 (or filename Info-current-file) nodename))
3423 (insert "Info Virtual Index\n")
3424 (insert "******************\n\n")
3425 (insert "This is a list of search results produced by\n"
3426 "`Info-virtual-index' for the current manual.\n\n")
3427 (insert "* Menu:\n\n")
3428 (dolist (nodeinfo nodes)
3429 (when (equal (car (nth 0 nodeinfo)) (or filename Info-current-file))
3430 (insert
3431 (format "* %-20s %s.\n"
3432 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo)))
3433 (cdr (nth 0 nodeinfo)))))))))
3435 (defun Info-virtual-index (topic)
3436 "Show a node with all lines in the index containing a string TOPIC.
3437 Like `Info-index' but displays a node with index search results.
3438 Give an empty topic name to go to the node with links to previous
3439 search results."
3440 ;; `interactive' is a copy from `Info-index'
3441 (interactive
3442 (list
3443 (let ((completion-ignore-case t)
3444 (Info-complete-menu-buffer (clone-buffer))
3445 (Info-complete-nodes (Info-index-nodes))
3446 (Info-history-list nil))
3447 (if (equal Info-current-file "dir")
3448 (error "The Info directory node has no index; use m to select a manual"))
3449 (unwind-protect
3450 (with-current-buffer Info-complete-menu-buffer
3451 (Info-goto-index)
3452 (completing-read "Index topic: " 'Info-complete-menu-item))
3453 (kill-buffer Info-complete-menu-buffer)))))
3454 (if (equal topic "")
3455 (Info-find-node Info-current-file "*Index*")
3456 (unless (assoc (cons Info-current-file topic) Info-virtual-index-nodes)
3457 (let ((orignode Info-current-node)
3458 (ohist-list Info-history-list))
3459 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3460 (Info-index topic)
3461 (push (cons (cons Info-current-file topic) Info-index-alternatives)
3462 Info-virtual-index-nodes)
3463 ;; Clean up unnecessary side-effects of `Info-index'.
3464 (setq Info-history-list ohist-list)
3465 (Info-goto-node orignode)
3466 (message "")))
3467 (Info-find-node Info-current-file (format "*Index for `%s'*" topic))))
3469 (add-to-list 'Info-virtual-files
3470 '("\\`\\*Apropos\\*\\'"
3471 (toc-nodes . Info-apropos-toc-nodes)
3472 (find-file . Info-apropos-find-file)
3473 (find-node . Info-apropos-find-node)
3474 (slow . t)
3477 (defvar Info-apropos-file "*Apropos*"
3478 "Info file name of the virtual manual for matches of `info-apropos'.")
3480 (defvar Info-apropos-nodes nil
3481 "Alist of cached apropos matched nodes.
3482 Each element is (NODENAME STRING MATCHES) where
3483 NODENAME is the name of the node that holds the search result,
3484 STRING is the search string given as an argument to `info-apropos',
3485 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3487 (defun Info-apropos-toc-nodes (filename)
3488 "Apropos-specific implementation of `Info-toc-nodes'."
3489 (let ((nodes (mapcar 'car (reverse Info-apropos-nodes))))
3490 `(,filename
3491 ("Top" nil nil ,nodes)
3492 ,@(mapcar (lambda (node) `(,node "Top" nil nil)) nodes))))
3494 (defun Info-apropos-find-file (filename &optional _noerror)
3495 "Apropos-specific implementation of `Info-find-file'."
3496 filename)
3498 (defun Info-apropos-find-node (_filename nodename &optional _no-going-back)
3499 "Apropos-specific implementation of `Info-find-node-2'."
3500 (if (equal nodename "Top")
3501 ;; Generate Top menu
3502 (let ((nodes (reverse Info-apropos-nodes)))
3503 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3504 Info-apropos-file nodename))
3505 (insert "Apropos Index\n")
3506 (insert "*************\n\n")
3507 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3508 (insert "* Menu:\n\n")
3509 (dolist (nodeinfo nodes)
3510 (insert (format "* %-20s %s.\n"
3511 (format "%s::" (nth 0 nodeinfo))
3512 (nth 1 nodeinfo)))))
3513 ;; Else, Generate Index-like menu of matches
3514 (let* ((nodeinfo (assoc nodename Info-apropos-nodes))
3515 (matches (nth 2 nodeinfo)))
3516 (when matches
3517 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3518 Info-apropos-file nodename))
3519 (insert "Apropos Index\n")
3520 (insert "*************\n\n")
3521 (insert "Index entries that match `" (nth 1 nodeinfo) "':\n\n")
3522 (insert "\0\b[index\0\b]\n")
3523 (if (eq matches t)
3524 (insert "No matches found.\n")
3525 (insert "* Menu:\n\n")
3526 (dolist (entry matches)
3527 (insert (format "* %-38s (%s)%s.%s\n"
3528 (format "%s [%s]:" (nth 1 entry) (nth 0 entry))
3529 (nth 0 entry)
3530 (nth 2 entry)
3531 (if (nth 3 entry)
3532 (format " (line %s)" (nth 3 entry))
3533 "")))))))))
3535 (defun Info-apropos-matches (string)
3536 "Collect STRING matches from all known Info files on your system.
3537 Return a list of matches where each element is in the format
3538 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3539 (unless (string= string "")
3540 (let ((pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3541 (regexp-quote string)))
3542 (ohist Info-history)
3543 (ohist-list Info-history-list)
3544 (current-node Info-current-node)
3545 (current-file Info-current-file)
3546 manuals matches node nodes)
3547 (let ((Info-fontify-maximum-menu-size nil))
3548 (Info-directory)
3549 ;; current-node and current-file are nil when they invoke info-apropos
3550 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3551 ;; case, we use (DIR)Top instead, to avoid signaling an error after
3552 ;; the search is complete.
3553 (when (null current-node)
3554 (setq current-file Info-current-file)
3555 (setq current-node Info-current-node))
3556 (message "Searching indices...")
3557 (goto-char (point-min))
3558 (re-search-forward "\\* Menu: *\n" nil t)
3559 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
3560 ;; add-to-list makes sure we don't have duplicates in `manuals',
3561 ;; so that the following dolist loop runs faster.
3562 (add-to-list 'manuals (match-string 1)))
3563 (dolist (manual (nreverse manuals))
3564 (message "Searching %s" manual)
3565 (condition-case err
3566 (if (setq nodes (Info-index-nodes (Info-find-file manual)))
3567 (save-excursion
3568 (Info-find-node manual (car nodes))
3569 (while
3570 (progn
3571 (goto-char (point-min))
3572 (while (re-search-forward pattern nil t)
3573 (let ((entry (match-string-no-properties 1))
3574 (nodename (match-string-no-properties 3))
3575 (line (match-string-no-properties 4)))
3576 (add-text-properties
3577 (- (match-beginning 2) (match-beginning 1))
3578 (- (match-end 2) (match-beginning 1))
3579 '(face info-index-match) entry)
3580 (setq matches (cons (list manual entry nodename line)
3581 matches))))
3582 (setq nodes (cdr nodes) node (car nodes)))
3583 (Info-goto-node node))))
3584 (error
3585 (message "%s" (if (eq (car-safe err) 'error)
3586 (nth 1 err) err))
3587 (sit-for 1 t)))))
3588 (Info-find-node current-file current-node)
3589 (setq Info-history ohist
3590 Info-history-list ohist-list)
3591 (message "Searching indices...done")
3592 (or (nreverse matches) t))))
3594 ;;;###autoload
3595 (defun info-apropos (string)
3596 "Grovel indices of all known Info files on your system for STRING.
3597 Build a menu of the possible matches."
3598 (interactive "sIndex apropos: ")
3599 (if (equal string "")
3600 (Info-find-node Info-apropos-file "Top")
3601 (let* ((nodes Info-apropos-nodes) nodename)
3602 (while (and nodes (not (equal string (nth 1 (car nodes)))))
3603 (setq nodes (cdr nodes)))
3604 (if nodes
3605 (Info-find-node Info-apropos-file (car (car nodes)))
3606 (setq nodename (format "Index for `%s'" string))
3607 (push (list nodename string (Info-apropos-matches string))
3608 Info-apropos-nodes)
3609 (Info-find-node Info-apropos-file nodename)))))
3611 (add-to-list 'Info-virtual-files
3612 '("\\`\\*Finder.*\\*\\'"
3613 (find-file . Info-finder-find-file)
3614 (find-node . Info-finder-find-node)
3617 (defvar Info-finder-file "*Finder*"
3618 "Info file name of the virtual Info keyword finder manual.")
3620 (defun Info-finder-find-file (filename &optional _noerror)
3621 "Finder-specific implementation of `Info-find-file'."
3622 filename)
3624 (defvar finder-known-keywords)
3625 (declare-function find-library-name "find-func" (library))
3626 (declare-function finder-unknown-keywords "finder" ())
3627 (declare-function lm-commentary "lisp-mnt" (&optional file))
3628 (defvar finder-keywords-hash)
3629 (defvar package--builtins) ; finder requires package
3631 (defun Info-finder-find-node (_filename nodename &optional _no-going-back)
3632 "Finder-specific implementation of `Info-find-node-2'."
3633 (require 'finder)
3634 (cond
3635 ((equal nodename "Top")
3636 ;; Display Top menu with descriptions of the keywords
3637 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3638 Info-finder-file nodename))
3639 (insert "Finder Keywords\n")
3640 (insert "***************\n\n")
3641 (insert "* Menu:\n\n")
3642 (dolist (assoc (append '((all . "All package info")
3643 (unknown . "Unknown keywords"))
3644 finder-known-keywords))
3645 (let ((keyword (car assoc)))
3646 (insert (format "* %s %s.\n"
3647 (concat (symbol-name keyword) ": "
3648 "Keyword " (symbol-name keyword) ".")
3649 (cdr assoc))))))
3650 ((equal nodename "Keyword unknown")
3651 ;; Display unknown keywords
3652 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3653 Info-finder-file nodename))
3654 (insert "Finder Unknown Keywords\n")
3655 (insert "***********************\n\n")
3656 (insert "* Menu:\n\n")
3657 (mapc
3658 (lambda (assoc)
3659 (insert (format "* %-14s %s.\n"
3660 (concat (symbol-name (car assoc)) ": "
3661 "Keyword " (symbol-name (car assoc)) ".")
3662 (cdr assoc))))
3663 (finder-unknown-keywords)))
3664 ((equal nodename "Keyword all")
3665 ;; Display all package info.
3666 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3667 Info-finder-file nodename))
3668 (insert "Finder Package Info\n")
3669 (insert "*******************\n\n")
3670 (insert "* Menu:\n\n")
3671 (let (desc)
3672 (dolist (package package--builtins)
3673 (setq desc (cdr-safe package))
3674 (when (vectorp desc)
3675 (insert (format "* %-16s %s.\n"
3676 (concat (symbol-name (car package)) "::")
3677 (aref desc 2)))))))
3678 ((string-match "\\`Keyword " nodename)
3679 (setq nodename (substring nodename (match-end 0)))
3680 ;; Display packages that match the keyword
3681 ;; or the list of keywords separated by comma.
3682 (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
3683 Info-finder-file nodename))
3684 (insert "Finder Packages\n")
3685 (insert "***************\n\n")
3686 (insert
3687 "The following packages match the keyword `" nodename "':\n\n")
3688 (insert "* Menu:\n\n")
3689 (let ((keywords
3690 (mapcar 'intern (if (string-match-p "," nodename)
3691 (split-string nodename ",[ \t\n]*" t)
3692 (list nodename))))
3693 hits desc)
3694 (dolist (keyword keywords)
3695 (push (copy-tree (gethash keyword finder-keywords-hash)) hits))
3696 (setq hits (delete-dups (apply 'append hits)))
3697 (dolist (package hits)
3698 (setq desc (cdr-safe (assq package package--builtins)))
3699 (when (vectorp desc)
3700 (insert (format "* %-16s %s.\n"
3701 (concat (symbol-name package) "::")
3702 (aref desc 2)))))))
3704 ;; Display commentary section
3705 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3706 Info-finder-file nodename))
3707 (insert "Finder Commentary\n")
3708 (insert "*****************\n\n")
3709 (insert
3710 "Commentary section of the package `" nodename "':\n\n")
3711 (let ((str (lm-commentary (find-library-name nodename))))
3712 (if (null str)
3713 (insert "Can't find any Commentary section\n\n")
3714 (insert
3715 (with-temp-buffer
3716 (insert str)
3717 (goto-char (point-min))
3718 (delete-blank-lines)
3719 (goto-char (point-max))
3720 (delete-blank-lines)
3721 (goto-char (point-min))
3722 (while (re-search-forward "^;+ ?" nil t)
3723 (replace-match "" nil nil))
3724 (buffer-string))))))))
3726 ;;;###autoload
3727 (defun info-finder (&optional keywords)
3728 "Display descriptions of the keywords in the Finder virtual manual.
3729 In interactive use, a prefix argument directs this command to read
3730 a list of keywords separated by comma. After that, it displays a node
3731 with a list of packages that contain all specified keywords."
3732 (interactive
3733 (when current-prefix-arg
3734 (require 'finder)
3735 (list
3736 (completing-read-multiple
3737 "Keywords (separated by comma): "
3738 (mapcar 'symbol-name (mapcar 'car (append finder-known-keywords
3739 (finder-unknown-keywords))))
3740 nil t))))
3741 (require 'finder)
3742 (if keywords
3743 (Info-find-node Info-finder-file (mapconcat 'identity keywords ", "))
3744 (Info-find-node Info-finder-file "Top")))
3747 (defun Info-undefined ()
3748 "Make command be undefined in Info."
3749 (interactive)
3750 (ding))
3752 (defun Info-help ()
3753 "Enter the Info tutorial."
3754 (interactive)
3755 (delete-other-windows)
3756 (Info-find-node "info"
3757 (if (< (window-height) 23)
3758 "Help-Small-Screen"
3759 "Help")))
3761 (defun Info-summary ()
3762 "Display a brief summary of all Info commands."
3763 (interactive)
3764 (save-window-excursion
3765 (switch-to-buffer "*Help*")
3766 (setq buffer-read-only nil)
3767 (erase-buffer)
3768 (insert (documentation 'Info-mode))
3769 (help-mode)
3770 (goto-char (point-min))
3771 (let (ch flag)
3772 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
3773 (message (if flag "Type Space to see more"
3774 "Type Space to return to Info"))
3775 (if (not (eq ?\s (setq ch (read-event))))
3776 (progn (setq unread-command-events (list ch)) nil)
3777 flag))
3778 (scroll-up)))
3779 (bury-buffer "*Help*")))
3781 (defun Info-get-token (pos start all &optional errorstring)
3782 "Return the token around POS.
3783 POS must be somewhere inside the token.
3784 START is a regular expression which will match the
3785 beginning of the tokens delimited string.
3786 ALL is a regular expression with a single
3787 parenthesized subpattern which is the token to be
3788 returned. E.g. '{\(.*\)}' would return any string
3789 enclosed in braces around POS.
3790 ERRORSTRING optional fourth argument, controls action on no match:
3791 nil: return nil
3792 t: beep
3793 a string: signal an error, using that string."
3794 (let ((case-fold-search t))
3795 (save-excursion
3796 (goto-char pos)
3797 ;; First look for a match for START that goes across POS.
3798 (while (and (not (bobp)) (> (point) (- pos (length start)))
3799 (not (looking-at start)))
3800 (forward-char -1))
3801 ;; If we did not find one, search back for START
3802 ;; (this finds only matches that end at or before POS).
3803 (or (looking-at start)
3804 (progn
3805 (goto-char pos)
3806 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
3807 (let (found)
3808 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
3809 (not (setq found (and (<= (match-beginning 0) pos)
3810 (> (match-end 0) pos))))))
3811 (if (and found (<= (match-beginning 0) pos)
3812 (> (match-end 0) pos))
3813 (match-string-no-properties 1)
3814 (cond ((null errorstring)
3815 nil)
3816 ((eq errorstring t)
3817 (beep)
3818 nil)
3820 (error "No %s around position %d" errorstring pos))))))))
3822 (defun Info-mouse-follow-nearest-node (click)
3823 "\\<Info-mode-map>Follow a node reference near point.
3824 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3825 At end of the node's text, moves to the next node, or up if none."
3826 (interactive "e")
3827 (mouse-set-point click)
3828 (and (not (Info-follow-nearest-node))
3829 (save-excursion (forward-line 1) (eobp))
3830 (Info-next-preorder)))
3832 (defun Info-follow-nearest-node (&optional fork)
3833 "Follow a node reference near point.
3834 If point is on a reference, follow that reference. Otherwise,
3835 if point is in a menu item description, follow that menu item.
3837 If FORK is non-nil (interactively with a prefix arg), show the node in
3838 a new Info buffer.
3839 If FORK is a string, it is the name to use for the new buffer."
3840 (interactive "P")
3841 (or (Info-try-follow-nearest-node fork)
3842 (when (save-excursion
3843 (search-backward "\n* menu:" nil t))
3844 (save-excursion
3845 (beginning-of-line)
3846 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3847 (beginning-of-line 0))
3848 (when (looking-at "\\* +\\([^\t\n]*\\):")
3849 (Info-goto-node
3850 (Info-extract-menu-item (match-string-no-properties 1)) fork)
3851 t)))
3852 (and (eq this-command 'Info-mouse-follow-nearest-node)
3853 ;; Don't raise an error when mouse-1 is bound to this - it's
3854 ;; often used to simply select the window or frame.
3855 (eq 'mouse-1 (event-basic-type last-input-event)))
3856 (user-error "Point neither on reference nor in menu item description")))
3858 ;; Common subroutine.
3859 (defun Info-try-follow-nearest-node (&optional fork)
3860 "Follow a node reference near point. Return non-nil if successful.
3861 If FORK is non-nil, it is passed to `Info-goto-node'."
3862 (let (node)
3863 (cond
3864 ((setq node (Info-get-token (point) "[hf]t?tps?://"
3865 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3866 (browse-url node)
3867 (setq node t))
3868 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
3869 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3870 (Info-follow-reference node fork))
3871 ;; footnote
3872 ((setq node (Info-get-token (point) "(" "\\(([0-9]+)\\)"))
3873 (let ((old-point (point)) new-point)
3874 (save-excursion
3875 (goto-char (point-min))
3876 (when (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t)
3877 (setq new-point (if (< old-point (point))
3878 ;; Go to footnote reference
3879 (and (search-forward node nil t)
3880 ;; Put point at beginning of link
3881 (match-beginning 0))
3882 ;; Go to footnote definition
3883 (search-backward node nil t)))))
3884 (if new-point
3885 (progn
3886 (goto-char new-point)
3887 (setq node t))
3888 (setq node nil))))
3889 ;; menu item: node name
3890 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3891 (Info-goto-node node fork))
3892 ;; menu item: node name or index entry
3893 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3894 (beginning-of-line)
3895 (forward-char 2)
3896 (setq node (Info-extract-menu-node-name nil (Info-index-node)))
3897 (Info-goto-node node fork))
3898 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3899 (Info-goto-node node fork))
3900 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3901 (Info-goto-node node fork))
3902 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3903 (Info-goto-node "Top" fork))
3904 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3905 (Info-goto-node node fork)))
3906 node))
3908 (defun Info-mouse-follow-link (click)
3909 "Follow a link where you click."
3910 (interactive "@e")
3911 (let* ((position (event-start click))
3912 (posn-string (and position (posn-string position)))
3913 (link-args (if posn-string
3914 (get-text-property (cdr posn-string)
3915 'link-args
3916 (car posn-string))
3917 (get-char-property (posn-point position)
3918 'link-args))))
3919 (cond ((stringp link-args)
3920 (Info-goto-node link-args))
3921 ;; These special values of the `link-args' property are used
3922 ;; for navigation; see `Info-fontify-node'.
3923 ((eq link-args 'prev) (Info-prev))
3924 ((eq link-args 'next) (Info-next))
3925 ((eq link-args 'up) (Info-up)))))
3928 (defvar Info-mode-map
3929 (let ((map (make-keymap)))
3930 (suppress-keymap map)
3931 (define-key map "." 'beginning-of-buffer)
3932 (define-key map " " 'Info-scroll-up)
3933 (define-key map [?\S-\ ] 'Info-scroll-down)
3934 (define-key map "\C-m" 'Info-follow-nearest-node)
3935 (define-key map "\t" 'Info-next-reference)
3936 (define-key map "\e\t" 'Info-prev-reference)
3937 (define-key map [backtab] 'Info-prev-reference)
3938 (define-key map "1" 'Info-nth-menu-item)
3939 (define-key map "2" 'Info-nth-menu-item)
3940 (define-key map "3" 'Info-nth-menu-item)
3941 (define-key map "4" 'Info-nth-menu-item)
3942 (define-key map "5" 'Info-nth-menu-item)
3943 (define-key map "6" 'Info-nth-menu-item)
3944 (define-key map "7" 'Info-nth-menu-item)
3945 (define-key map "8" 'Info-nth-menu-item)
3946 (define-key map "9" 'Info-nth-menu-item)
3947 (define-key map "0" 'undefined)
3948 (define-key map "?" 'Info-summary)
3949 (define-key map "]" 'Info-forward-node)
3950 (define-key map "[" 'Info-backward-node)
3951 (define-key map "<" 'Info-top-node)
3952 (define-key map ">" 'Info-final-node)
3953 (define-key map "b" 'beginning-of-buffer)
3954 (put 'beginning-of-buffer :advertised-binding "b")
3955 (define-key map "d" 'Info-directory)
3956 (define-key map "e" 'end-of-buffer)
3957 (define-key map "f" 'Info-follow-reference)
3958 (define-key map "g" 'Info-goto-node)
3959 (define-key map "h" 'Info-help)
3960 (define-key map "i" 'Info-index)
3961 (define-key map "I" 'Info-virtual-index)
3962 (define-key map "l" 'Info-history-back)
3963 (define-key map "L" 'Info-history)
3964 (define-key map "m" 'Info-menu)
3965 (define-key map "n" 'Info-next)
3966 (define-key map "p" 'Info-prev)
3967 (define-key map "q" 'Info-exit)
3968 (define-key map "r" 'Info-history-forward)
3969 (define-key map "s" 'Info-search)
3970 (define-key map "S" 'Info-search-case-sensitively)
3971 (define-key map "\M-n" 'clone-buffer)
3972 (define-key map "t" 'Info-top-node)
3973 (define-key map "T" 'Info-toc)
3974 (define-key map "u" 'Info-up)
3975 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3976 (define-key map "w" 'Info-copy-current-node-name)
3977 (define-key map "c" 'Info-copy-current-node-name)
3978 ;; `^' for consistency with `dired-up-directory'.
3979 (define-key map "^" 'Info-up)
3980 (define-key map "," 'Info-index-next)
3981 (define-key map "\177" 'Info-scroll-down)
3982 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3983 (define-key map [follow-link] 'mouse-face)
3984 (define-key map [XF86Back] 'Info-history-back)
3985 (define-key map [XF86Forward] 'Info-history-forward)
3986 map)
3987 "Keymap containing Info commands.")
3990 (defun Info-check-pointer (item)
3991 "Non-nil if ITEM is present in this node."
3992 (condition-case nil
3993 (Info-extract-pointer item)
3994 (error nil)))
3996 (easy-menu-define
3997 Info-mode-menu Info-mode-map
3998 "Menu for Info files."
3999 '("Info"
4000 ["Up" Info-up :active (Info-check-pointer "up")
4001 :help "Go up in the Info tree"]
4002 ["Next" Info-next :active (Info-check-pointer "next")
4003 :help "Go to the next node"]
4004 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
4005 :help "Go to the previous node"]
4006 ["Backward" Info-backward-node
4007 :help "Go backward one node, considering all as a sequence"]
4008 ["Forward" Info-forward-node
4009 :help "Go forward one node, considering all as a sequence"]
4010 ["Beginning" beginning-of-buffer
4011 :help "Go to beginning of this node"]
4012 ["Top" Info-top-node
4013 :help "Go to top node of file"]
4014 ["Final Node" Info-final-node
4015 :help "Go to final node in this file"]
4016 ("Menu Item" ["You should never see this" report-emacs-bug t])
4017 ("Reference" ["You should never see this" report-emacs-bug t])
4018 ["Search..." Info-search
4019 :help "Search for regular expression in this Info file"]
4020 ["Search Next" Info-search-next
4021 :help "Search for another occurrence of regular expression"]
4022 ["Go to Node..." Info-goto-node
4023 :help "Go to a named node"]
4024 ["Back in history" Info-history-back :active Info-history
4025 :help "Go back in history to the last node you were at"]
4026 ["Forward in history" Info-history-forward :active Info-history-forward
4027 :help "Go forward in history"]
4028 ["History" Info-history :active Info-history-list
4029 :help "Go to menu of visited nodes"]
4030 ["Table of Contents" Info-toc
4031 :help "Go to table of contents"]
4032 ("Index"
4033 ["Lookup a String..." Info-index
4034 :help "Look for a string in the index items"]
4035 ["Next Matching Item" Info-index-next :active Info-index-alternatives
4036 :help "Look for another occurrence of previous item"]
4037 ["Lookup a string and display index of results..." Info-virtual-index
4038 :help "Look for a string in the index items and display node with results"]
4039 ["Lookup a string in all indices..." info-apropos
4040 :help "Look for a string in the indices of all manuals"])
4041 ["Copy Node Name" Info-copy-current-node-name
4042 :help "Copy the name of the current node into the kill ring"]
4043 ["Clone Info buffer" clone-buffer
4044 :help "Create a twin copy of the current Info buffer."]
4045 ["Exit" Info-exit :help "Stop reading Info"]))
4048 (defvar info-tool-bar-map
4049 (let ((map (make-sparse-keymap)))
4050 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
4051 :rtl "right-arrow"
4052 :label "Back"
4053 :vert-only t)
4054 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
4055 :rtl "left-arrow"
4056 :label "Forward"
4057 :vert-only t)
4058 (define-key-after map [separator-1] menu-bar-separator)
4059 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
4060 :rtl "next-node")
4061 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
4062 :rtl "prev-node")
4063 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
4064 :vert-only t)
4065 (define-key-after map [separator-2] menu-bar-separator)
4066 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
4067 :vert-only t)
4068 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
4069 (define-key-after map [separator-3] menu-bar-separator)
4070 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
4071 :label "Index")
4072 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
4073 :vert-only t)
4074 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
4075 :vert-only t)
4076 map))
4078 (defvar Info-menu-last-node nil)
4079 ;; Last node the menu was created for.
4080 ;; Value is a list, (FILE-NAME NODE-NAME).
4082 (defun Info-menu-update ()
4083 "Update the Info menu for the current node."
4084 (condition-case nil
4085 (if (or (not (derived-mode-p 'Info-mode))
4086 (equal (list Info-current-file Info-current-node)
4087 Info-menu-last-node))
4089 ;; Update menu menu.
4090 (let* ((Info-complete-menu-buffer (current-buffer))
4091 (items (nreverse (condition-case nil
4092 (Info-complete-menu-item "" nil t)
4093 (error nil))))
4094 entries current
4095 (number 0))
4096 (while (and items (< number 9))
4097 (setq current (car items)
4098 items (cdr items)
4099 number (1+ number))
4100 (setq entries (cons `[,current
4101 (Info-menu ,current)
4102 :keys ,(format "%d" number)]
4103 entries)))
4104 (if items
4105 (setq entries (cons ["Other..." Info-menu t] entries)))
4106 (or entries
4107 (setq entries (list ["No menu" nil nil] nil :active)))
4108 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
4109 ;; Update reference menu. Code stolen from `Info-follow-reference'.
4110 (let ((items nil)
4111 str i entries current
4112 (number 0)
4113 (case-fold-search t))
4114 (save-excursion
4115 (goto-char (point-min))
4116 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
4117 (setq str (match-string 1))
4118 (setq i 0)
4119 (while (setq i (string-match "[ \n\t]+" str i))
4120 (setq str (concat (substring str 0 i) " "
4121 (substring str (match-end 0))))
4122 (setq i (1+ i)))
4123 (setq items
4124 (cons str items))))
4125 (while (and items (< number 9))
4126 (setq current (car items)
4127 items (cdr items)
4128 number (1+ number))
4129 (setq entries (cons `[,current
4130 (Info-follow-reference ,current)
4132 entries)))
4133 (if items
4134 (setq entries (cons ["Other..." Info-follow-reference t]
4135 entries)))
4136 (or entries
4137 (setq entries (list ["No references" nil nil] nil :active)))
4138 (easy-menu-change '("Info") "Reference" (nreverse entries)))
4139 ;; Update last seen node.
4140 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
4141 ;; Try to avoid entering infinite beep mode in case of errors.
4142 (error (ding))))
4145 (defun Info-copy-current-node-name (&optional arg)
4146 "Put the name of the current Info node into the kill ring.
4147 The name of the Info file is prepended to the node name in parentheses.
4148 With a zero prefix arg, put the name inside a function call to `info'."
4149 (interactive "P")
4150 (unless Info-current-node
4151 (user-error "No current Info node"))
4152 (let ((node (if (stringp Info-current-file)
4153 (concat "(" (file-name-sans-extension
4154 (file-name-nondirectory Info-current-file))
4155 ") "
4156 Info-current-node))))
4157 (if (zerop (prefix-numeric-value arg))
4158 (setq node (concat "(info \"" node "\")")))
4159 (unless (stringp Info-current-file)
4160 (setq node (format "(Info-find-node '%S '%S)"
4161 Info-current-file Info-current-node)))
4162 (kill-new node)
4163 (message "%s" node)))
4166 ;; Info mode is suitable only for specially formatted data.
4167 (put 'Info-mode 'mode-class 'special)
4168 (put 'Info-mode 'no-clone-indirect t)
4170 (defvar tool-bar-map)
4171 (defvar bookmark-make-record-function)
4173 (defvar Info-mode-syntax-table
4174 (let ((st (copy-syntax-table text-mode-syntax-table)))
4175 ;; Use punctuation syntax for apostrophe because of
4176 ;; extensive use of quotes like `this' in Info manuals.
4177 (modify-syntax-entry ?' "." st)
4179 "Syntax table used in `Info-mode'.")
4181 ;; Autoload cookie needed by desktop.el
4182 ;;;###autoload
4183 (define-derived-mode Info-mode nil "Info"
4184 "Info mode provides commands for browsing through the Info documentation tree.
4185 Documentation in Info is divided into \"nodes\", each of which discusses
4186 one topic and contains references to other nodes which discuss related
4187 topics. Info has commands to follow the references and show you other nodes.
4189 \\<Info-mode-map>\
4190 \\[Info-help] Invoke the Info tutorial.
4191 \\[Info-exit] Quit Info: reselect previously selected buffer.
4193 Selecting other nodes:
4194 \\[Info-mouse-follow-nearest-node]
4195 Follow a node reference you click on.
4196 This works with menu items, cross references, and
4197 the \"next\", \"previous\" and \"up\", depending on where you click.
4198 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
4199 \\[Info-next] Move to the \"next\" node of this node.
4200 \\[Info-prev] Move to the \"previous\" node of this node.
4201 \\[Info-up] Move \"up\" from this node.
4202 \\[Info-menu] Pick menu item specified by name (or abbreviation).
4203 Picking a menu item causes another node to be selected.
4204 \\[Info-directory] Go to the Info directory node.
4205 \\[Info-top-node] Go to the Top node of this file.
4206 \\[Info-final-node] Go to the final node in this file.
4207 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
4208 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
4209 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
4210 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
4211 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
4212 \\[Info-history-back] Move back in history to the last node you were at.
4213 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
4214 \\[Info-history] Go to menu of visited nodes.
4215 \\[Info-toc] Go to table of contents of the current Info file.
4217 Moving within a node:
4218 \\[Info-scroll-up] Normally, scroll forward a full screen.
4219 Once you scroll far enough in a node that its menu appears on the
4220 screen but after point, the next scroll moves into its first
4221 subnode. When after all menu items (or if there is no menu),
4222 move up to the parent node.
4223 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
4224 already visible, try to go to the previous menu entry, or up
4225 if there is none.
4226 \\[beginning-of-buffer] Go to beginning of node.
4228 Advanced commands:
4229 \\[Info-search] Search through this Info file for specified regexp,
4230 and select the node in which the next occurrence is found.
4231 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
4232 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
4233 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
4234 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
4235 \\[Info-virtual-index] Look for a string and display the index node with results.
4236 \\[info-apropos] Look for a string in the indices of all manuals.
4237 \\[Info-goto-node] Move to node specified by name.
4238 You may include a filename as well, as (FILENAME)NODENAME.
4239 1 .. 9 Pick first ... ninth item in node's menu.
4240 Every third `*' is highlighted to help pick the right number.
4241 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
4242 \\[clone-buffer] Select a new cloned Info buffer in another window.
4243 \\[universal-argument] \\[info] Move to new Info file with completion.
4244 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
4245 :syntax-table Info-mode-syntax-table
4246 :abbrev-table text-mode-abbrev-table
4247 (setq tab-width 8)
4248 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
4249 (setq case-fold-search t)
4250 (setq buffer-read-only t)
4251 (make-local-variable 'Info-current-file)
4252 (make-local-variable 'Info-current-subfile)
4253 (make-local-variable 'Info-current-node)
4254 (set (make-local-variable 'Info-tag-table-marker) (make-marker))
4255 (set (make-local-variable 'Info-tag-table-buffer) nil)
4256 (make-local-variable 'Info-history)
4257 (make-local-variable 'Info-history-forward)
4258 (make-local-variable 'Info-index-alternatives)
4259 (if Info-use-header-line ; do not override global header lines
4260 (setq header-line-format
4261 '(:eval (get-text-property (point-min) 'header-line))))
4262 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
4263 ;; This is for the sake of the invisible text we use handling titles.
4264 (set (make-local-variable 'line-move-ignore-invisible) t)
4265 (set (make-local-variable 'desktop-save-buffer)
4266 'Info-desktop-buffer-misc-data)
4267 (set (make-local-variable 'widen-automatically) nil)
4268 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
4269 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
4270 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
4271 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
4272 (set (make-local-variable 'isearch-search-fun-function)
4273 'Info-isearch-search)
4274 (set (make-local-variable 'isearch-wrap-function)
4275 'Info-isearch-wrap)
4276 (set (make-local-variable 'isearch-push-state-function)
4277 'Info-isearch-push-state)
4278 (set (make-local-variable 'isearch-filter-predicate) #'Info-isearch-filter)
4279 (set (make-local-variable 'revert-buffer-function)
4280 'Info-revert-buffer-function)
4281 (Info-set-mode-line)
4282 (set (make-local-variable 'bookmark-make-record-function)
4283 'Info-bookmark-make-record))
4285 ;; When an Info buffer is killed, make sure the associated tags buffer
4286 ;; is killed too.
4287 (defun Info-kill-buffer ()
4288 (and (derived-mode-p 'Info-mode)
4289 Info-tag-table-buffer
4290 (kill-buffer Info-tag-table-buffer)))
4292 ;; Placed on `clone-buffer-hook'.
4293 (defun Info-clone-buffer ()
4294 (when (bufferp Info-tag-table-buffer)
4295 (setq Info-tag-table-buffer
4296 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4297 (let ((m Info-tag-table-marker))
4298 (when (markerp m)
4299 (setq Info-tag-table-marker
4300 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4301 (with-current-buffer Info-tag-table-buffer
4302 (copy-marker (marker-position m)))
4303 (make-marker))))))
4305 (define-obsolete-variable-alias 'Info-edit-map 'Info-edit-mode-map "24.1")
4306 (defvar Info-edit-mode-map (let ((map (make-sparse-keymap)))
4307 (set-keymap-parent map text-mode-map)
4308 (define-key map "\C-c\C-c" 'Info-cease-edit)
4309 map)
4310 "Local keymap used within `e' command of Info.")
4312 (make-obsolete-variable 'Info-edit-map
4313 "editing Info nodes by hand is not recommended."
4314 "24.4")
4316 ;; Info-edit mode is suitable only for specially formatted data.
4317 (put 'Info-edit-mode 'mode-class 'special)
4319 (define-derived-mode Info-edit-mode text-mode "Info Edit"
4320 "Major mode for editing the contents of an Info node.
4321 Like text mode with the addition of `Info-cease-edit'
4322 which returns to Info mode for browsing.
4323 \\{Info-edit-map}"
4324 (setq buffer-read-only nil)
4325 (force-mode-line-update)
4326 (buffer-enable-undo (current-buffer)))
4328 (make-obsolete 'Info-edit-mode
4329 "editing Info nodes by hand is not recommended." "24.4")
4331 (defun Info-edit ()
4332 "Edit the contents of this Info node."
4333 (interactive)
4334 (Info-edit-mode)
4335 (message "%s" (substitute-command-keys
4336 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
4338 (put 'Info-edit 'disabled "Editing Info nodes by hand is not recommended.
4339 This feature will be removed in future.")
4341 (make-obsolete 'Info-edit
4342 "editing Info nodes by hand is not recommended." "24.4")
4344 (defun Info-cease-edit ()
4345 "Finish editing Info node; switch back to Info proper."
4346 (interactive)
4347 ;; Do this first, so nothing has changed if user C-g's at query.
4348 (and (buffer-modified-p)
4349 (y-or-n-p "Save the file? ")
4350 (save-buffer))
4351 (Info-mode)
4352 (force-mode-line-update)
4353 (and (marker-position Info-tag-table-marker)
4354 (buffer-modified-p)
4355 (message "Tags may have changed. Use Info-tagify if necessary")))
4357 (make-obsolete 'Info-cease-edit
4358 "editing Info nodes by hand is not recommended." "24.4")
4360 (defvar Info-file-list-for-emacs
4361 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4362 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4363 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4364 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4365 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4366 ("copyright" . "autotype") ("executable" . "autotype")
4367 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4368 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4369 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4370 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4371 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4372 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4373 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4374 ("rfc2045" . "emacs-mime")
4375 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4376 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4377 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4378 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4379 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4380 ("mml" . "emacs-mime")
4381 "tramp" "dbus")
4382 "List of Info files that describe Emacs commands.
4383 An element can be a file name, or a list of the form (PREFIX . FILE)
4384 where PREFIX is a name prefix and FILE is the file to look in.
4385 If the element is just a file name, the file name also serves as the prefix.")
4387 (defun Info-find-emacs-command-nodes (command)
4388 "Return a list of locations documenting COMMAND.
4389 The `info-file' property of COMMAND says which Info manual to search.
4390 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4391 defines heuristics for which Info manual to try.
4392 The locations are of the format used in the variable `Info-history', i.e.
4393 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4394 in the first element of the returned list (which is treated specially in
4395 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4396 (let ((where '()) line-number
4397 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4398 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4399 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4400 (info-file "emacs")) ;default
4401 ;; Determine which Info file this command is documented in.
4402 (if (get command 'info-file)
4403 (setq info-file (get command 'info-file))
4404 ;; If it doesn't say explicitly, test its name against
4405 ;; various prefixes that we know.
4406 (let ((file-list Info-file-list-for-emacs))
4407 (while file-list
4408 (let* ((elt (car file-list))
4409 (name (if (consp elt)
4410 (car elt)
4411 elt))
4412 (file (if (consp elt) (cdr elt) elt))
4413 (case-fold-search nil)
4414 (regexp (concat "\\`" (regexp-quote name)
4415 "\\(\\'\\|-\\)")))
4416 (if (string-match regexp (symbol-name command))
4417 (setq info-file file file-list nil))
4418 (setq file-list (cdr file-list))))))
4419 (Info-find-node info-file "Top")
4420 ;; Bind Info-history to nil, to prevent the index nodes from
4421 ;; getting into the node history.
4422 (let ((Info-history nil)
4423 (Info-history-list nil)
4424 node (nodes (Info-index-nodes)))
4425 (Info-goto-node (car nodes))
4426 (while
4427 (progn
4428 (goto-char (point-min))
4429 (while (re-search-forward cmd-desc nil t)
4430 (setq where
4431 (cons (list Info-current-file
4432 (match-string-no-properties 2)
4434 where))
4435 (setq line-number (and (match-beginning 3)
4436 (string-to-number (match-string 3)))))
4437 (and (setq nodes (cdr nodes) node (car nodes))))
4438 (Info-goto-node node)))
4439 (if (and line-number where)
4440 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4441 (cdr where))
4442 where)))
4444 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4445 ;;;###autoload
4446 (defun Info-goto-emacs-command-node (command)
4447 "Go to the Info node in the Emacs manual for command COMMAND.
4448 The command is found by looking up in Emacs manual's indices
4449 or in another manual found via COMMAND's `info-file' property or
4450 the variable `Info-file-list-for-emacs'.
4451 COMMAND must be a symbol or string."
4452 (interactive "CFind documentation for command: ")
4453 ;; If command is given as a string, convert it to a symbol.
4454 (if (stringp command)
4455 (setq command (intern command)))
4456 (or (commandp command)
4457 (signal 'wrong-type-argument (list 'commandp command)))
4458 (let ((where (Info-find-emacs-command-nodes command)))
4459 (if where
4460 (let ((num-matches (length where)))
4461 ;; Get Info running, and pop to it in another window.
4462 (save-window-excursion
4463 (info))
4464 (or (derived-mode-p 'Info-mode) (pop-to-buffer "*info*"))
4465 ;; Bind Info-history to nil, to prevent the last Index node
4466 ;; visited by Info-find-emacs-command-nodes from being
4467 ;; pushed onto the history.
4468 (let ((Info-history nil) (Info-history-list nil)
4469 (line-number (nth 2 (car where))))
4470 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4471 (if (and (integerp line-number) (> line-number 0))
4472 (forward-line (1- line-number))))
4473 (if (> num-matches 1)
4474 (progn
4475 ;; (car where) will be pushed onto Info-history
4476 ;; when/if they go to another node. Put the other
4477 ;; nodes that were found on the history.
4478 (setq Info-history (nconc (cdr where) Info-history))
4479 (message "Found %d other entr%s. Use %s to see %s."
4480 (1- num-matches)
4481 (if (> num-matches 2) "ies" "y")
4482 (substitute-command-keys "\\[Info-history-back]")
4483 (if (> num-matches 2) "them" "it")))))
4484 (error "Couldn't find documentation for %s" command))))
4486 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4487 ;;;###autoload
4488 (defun Info-goto-emacs-key-command-node (key)
4489 "Go to the node in the Emacs manual which describes the command bound to KEY.
4490 KEY is a string.
4491 Interactively, if the binding is `execute-extended-command', a command is read.
4492 The command is found by looking up in Emacs manual's indices
4493 or in another manual found via COMMAND's `info-file' property or
4494 the variable `Info-file-list-for-emacs'."
4495 (interactive "kFind documentation for key: ")
4496 (let ((command (key-binding key)))
4497 (cond ((null command)
4498 (message "%s is undefined" (key-description key)))
4499 ((and (called-interactively-p 'interactive)
4500 (eq command 'execute-extended-command))
4501 (Info-goto-emacs-command-node
4502 (read-command "Find documentation for command: ")))
4504 (Info-goto-emacs-command-node command)))))
4506 (defvar Info-link-keymap
4507 (let ((keymap (make-sparse-keymap)))
4508 (define-key keymap [header-line down-mouse-1] 'mouse-drag-header-line)
4509 (define-key keymap [header-line mouse-1] 'mouse-select-window)
4510 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4511 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4512 (define-key keymap [follow-link] 'mouse-face)
4513 keymap)
4514 "Keymap to put on Info links.
4515 This is used for the \"Next\", \"Prev\", and \"Up\" links in the
4516 first line or header line, and for breadcrumb links.")
4518 (defun Info-breadcrumbs ()
4519 (let ((nodes (Info-toc-nodes Info-current-file))
4520 (node Info-current-node)
4521 (crumbs ())
4522 (depth Info-breadcrumbs-depth)
4523 line)
4525 ;; Get ancestors from the cached parent-children node info
4526 (while (and (not (equal "Top" node)) (> depth 0))
4527 (setq node (nth 1 (assoc node nodes)))
4528 (if node (push node crumbs))
4529 (setq depth (1- depth)))
4531 ;; Add bottom node.
4532 (when Info-use-header-line
4533 ;; Let it disappear if crumbs is nil.
4534 (nconc crumbs (list Info-current-node)))
4535 (when (or Info-use-header-line crumbs)
4536 ;; Add top node (and continuation if needed).
4537 (setq crumbs
4538 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4539 crumbs (cons nil crumbs))))
4540 ;; Eliminate duplicate.
4541 (forward-line 1)
4542 (dolist (node crumbs)
4543 (let ((text
4544 (if (not (equal node "Top")) node
4545 (format "(%s)Top"
4546 (if (stringp Info-current-file)
4547 (file-name-sans-extension
4548 (file-name-nondirectory Info-current-file))
4549 ;; Some legacy code can still use a symbol.
4550 Info-current-file)))))
4551 (setq line (concat
4552 line
4553 (if (null line) "" " > ")
4554 (cond
4555 ((null node) "...")
4556 ((equal node Info-current-node)
4557 ;; No point linking to ourselves.
4558 (propertize text 'font-lock-face 'info-header-node))
4560 (propertize text
4561 'mouse-face 'highlight
4562 'font-lock-face 'info-header-xref
4563 'help-echo "mouse-2: Go to node"
4564 'keymap Info-link-keymap
4565 'link-args text)))))))
4566 (setq line (concat line "\n")))
4567 ;; (font-lock-append-text-property 0 (length line)
4568 ;; 'font-lock-face 'header-line line)
4569 line))
4571 (defun Info-fontify-node ()
4572 "Fontify the node."
4573 (save-excursion
4574 (let* ((inhibit-read-only t)
4575 (case-fold-search t)
4576 paragraph-markers
4577 (not-fontified-p ; the node hasn't already been fontified
4578 (not (let ((where (next-single-property-change (point-min)
4579 'font-lock-face)))
4580 (and where (not (= where (point-max)))))))
4581 (fontify-visited-p ; visited nodes need to be re-fontified
4582 (and Info-fontify-visited-nodes
4583 ;; Don't take time to refontify visited nodes in huge nodes
4584 Info-fontify-maximum-menu-size
4585 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4586 rbeg rend)
4588 ;; Fontify header line
4589 (goto-char (point-min))
4590 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4591 (goto-char (match-end 0))
4592 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4593 (goto-char (match-end 0))
4594 (let* ((nbeg (match-beginning 2))
4595 (nend (match-end 2))
4596 (tbeg (match-beginning 1))
4597 (tag (match-string 1)))
4598 (if (string-equal (downcase tag) "node")
4599 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4600 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4601 (put-text-property tbeg nend 'mouse-face 'highlight)
4602 (put-text-property tbeg nend
4603 'help-echo
4604 (concat "mouse-2: Go to node "
4605 (buffer-substring nbeg nend)))
4606 ;; Set up the text property keymap. Depending on
4607 ;; `Info-use-header-line', it is either used in the
4608 ;; buffer, or copied to the header line. A symbol value
4609 ;; of the `link-args' property is handled specially by
4610 ;; `Info-mouse-follow-link'.
4611 (put-text-property tbeg nend 'keymap Info-link-keymap)
4612 (put-text-property tbeg nend 'link-args
4613 (intern (downcase tag))))))
4615 ;; (when (> Info-breadcrumbs-depth 0)
4616 ;; (insert (Info-breadcrumbs)))
4618 ;; Treat header line.
4619 (when Info-use-header-line
4620 (goto-char (point-min))
4621 (let* ((header-end (line-end-position))
4622 (header
4623 ;; If we find neither Next: nor Prev: link, show the entire
4624 ;; node header. Otherwise, don't show the File: and Node:
4625 ;; parts, to avoid wasting precious space on information that
4626 ;; is available in the mode line.
4627 (if (re-search-forward
4628 "\\(next\\|up\\|prev[ious]*\\): "
4629 header-end t)
4630 (progn
4631 (goto-char (match-beginning 1))
4632 (buffer-substring (point) header-end))
4633 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4634 header-end t)
4635 (concat "No next, prev or up links -- "
4636 (buffer-substring (point) header-end))
4637 (buffer-substring (point) header-end)))))
4638 (put-text-property (point-min) (1+ (point-min))
4639 'header-line
4640 (replace-regexp-in-string
4642 ;; Preserve text properties on duplicated `%'.
4643 (lambda (s) (concat s s)) header))
4644 ;; Hide the part of the first line
4645 ;; that is in the header, if it is just part.
4646 (cond
4647 ((> Info-breadcrumbs-depth 0)
4648 (let ((ov (make-overlay (point-min) (1+ header-end))))
4649 (overlay-put ov 'display (Info-breadcrumbs))
4650 (overlay-put ov 'evaporate t)))
4651 ((not (bobp))
4652 ;; Hide the punctuation at the end, too.
4653 (skip-chars-backward " \t,")
4654 (put-text-property (point) header-end 'invisible t)
4655 ;; Hide the suffix of the Info file name.
4656 (beginning-of-line)
4657 (if (re-search-forward
4658 (format "File: %s\\([^,\n\t]+\\),"
4659 (if (stringp Info-current-file)
4660 (file-name-sans-extension
4661 (file-name-nondirectory Info-current-file))
4662 Info-current-file))
4663 header-end t)
4664 (put-text-property (match-beginning 1) (match-end 1)
4665 'invisible t)))))))
4667 ;; Fontify titles
4668 (goto-char (point-min))
4669 (when (and font-lock-mode not-fontified-p)
4670 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4671 nil t)
4672 ;; Only consider it as an underlined title if the ASCII
4673 ;; underline has the same size as the text. A typical
4674 ;; counter example is when a continuation "..." is alone
4675 ;; on a line.
4676 (= (string-width (match-string 1))
4677 (string-width (match-string 2))))
4678 (let* ((c (preceding-char))
4679 (face
4680 (cond ((= c ?*) 'info-title-1)
4681 ((= c ?=) 'info-title-2)
4682 ((= c ?-) 'info-title-3)
4683 (t 'info-title-4))))
4684 (put-text-property (match-beginning 1) (match-end 1)
4685 'font-lock-face face))
4686 ;; This is a serious problem for trying to handle multiple
4687 ;; frame types at once. We want this text to be invisible
4688 ;; on frames that can display the font above.
4689 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4690 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4691 '(invisible t front-sticky nil rear-nonsticky t)))))
4693 ;; Fontify cross references
4694 (goto-char (point-min))
4695 (when (or not-fontified-p fontify-visited-p)
4696 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4697 (let ((start (match-beginning 0))
4698 (next (point))
4699 other-tag)
4700 (when not-fontified-p
4701 (when Info-hide-note-references
4702 (when (and (not (eq Info-hide-note-references 'hide))
4703 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4704 ;; *Note is often used where *note should have been
4705 (goto-char start)
4706 (skip-syntax-backward " ")
4707 (when (memq (char-before) '(?\( ?\[ ?\{))
4708 ;; Check whether the paren is preceded by
4709 ;; an end of sentence
4710 (skip-syntax-backward " ("))
4711 (setq other-tag
4712 (cond ((save-match-data (looking-back "\\<see"))
4714 ((save-match-data (looking-back "\\<in"))
4716 ((memq (char-before) '(nil ?\. ?! ??))
4717 "See ")
4718 ((save-match-data
4719 (save-excursion
4720 (search-forward "\n\n" start t)))
4721 "See ")
4722 (t "see "))))
4723 (goto-char next)
4724 (add-text-properties
4725 (match-beginning 1)
4726 (or (save-match-data
4727 ;; Don't hide \n after *Note
4728 (let ((start1 (match-beginning 1)))
4729 (if (string-match "\n" (match-string 1))
4730 (+ start1 (match-beginning 0)))))
4731 (match-end 1))
4732 (if other-tag
4733 `(display ,other-tag front-sticky nil rear-nonsticky t)
4734 '(invisible t front-sticky nil rear-nonsticky t))))
4735 (add-text-properties
4736 (match-beginning 2) (match-end 2)
4737 (list
4738 'help-echo (if (or (match-end 5)
4739 (not (equal (match-string 4) "")))
4740 (concat "mouse-2: go to " (or (match-string 5)
4741 (match-string 4)))
4742 "mouse-2: go to this node")
4743 'mouse-face 'highlight)))
4744 (when (or not-fontified-p fontify-visited-p)
4745 (setq rbeg (match-beginning 2)
4746 rend (match-end 2))
4747 (put-text-property
4748 rbeg rend
4749 'font-lock-face
4750 ;; Display visited nodes in a different face
4751 (if (and Info-fontify-visited-nodes
4752 (save-match-data
4753 (let* ((node (replace-regexp-in-string
4754 "^[ \t]+" ""
4755 (replace-regexp-in-string
4756 "[ \t\n]+" " "
4757 (or (match-string-no-properties 5)
4758 (and (not (equal (match-string 4) ""))
4759 (match-string-no-properties 4))
4760 (match-string-no-properties 2)))))
4761 (external-link-p
4762 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4763 (file (if external-link-p
4764 (file-name-nondirectory
4765 (match-string-no-properties 1 node))
4766 Info-current-file))
4767 (hl Info-history-list)
4768 res)
4769 (if external-link-p
4770 (setq node (if (equal (match-string 2 node) "")
4771 "Top"
4772 (match-string-no-properties 2 node))))
4773 (while hl
4774 (if (and (string-equal node (nth 1 (car hl)))
4775 (equal file
4776 (if (and external-link-p
4777 (stringp (caar hl)))
4778 (file-name-nondirectory
4779 (caar hl))
4780 (caar hl))))
4781 (setq res (car hl) hl nil)
4782 (setq hl (cdr hl))))
4783 res))) 'info-xref-visited 'info-xref))
4784 ;; For multiline ref, unfontify newline and surrounding whitespace
4785 (save-excursion
4786 (goto-char rbeg)
4787 (save-match-data
4788 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4789 (remove-text-properties (match-beginning 0)
4790 (match-end 0)
4791 '(font-lock-face t))))))
4792 (when not-fontified-p
4793 (when (memq Info-hide-note-references '(t hide))
4794 (add-text-properties (match-beginning 3) (match-end 3)
4795 '(invisible t front-sticky nil rear-nonsticky t))
4796 ;; Unhide the file name of the external reference in parens
4797 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4798 (remove-text-properties (match-beginning 6) (match-end 6)
4799 '(invisible t front-sticky nil rear-nonsticky t)))
4800 ;; Unhide newline because hidden newlines cause too long lines
4801 (save-match-data
4802 (let ((beg3 (match-beginning 3))
4803 (end3 (match-end 3)))
4804 (if (and (string-match "\n[ \t]*" (match-string 3))
4805 (not (save-match-data
4806 (save-excursion
4807 (goto-char (1+ end3))
4808 (looking-at "[.)]*$")))))
4809 (remove-text-properties (+ beg3 (match-beginning 0))
4810 (+ beg3 (match-end 0))
4811 '(invisible t front-sticky nil rear-nonsticky t))))))
4812 (when (and Info-refill-paragraphs Info-hide-note-references)
4813 (push (set-marker (make-marker) start)
4814 paragraph-markers))))))
4816 ;; Refill paragraphs (experimental feature)
4817 (when (and not-fontified-p
4818 Info-refill-paragraphs
4819 paragraph-markers)
4820 (let ((fill-nobreak-invisible t)
4821 (fill-individual-varying-indent nil)
4822 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4823 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4824 (adaptive-fill-mode nil))
4825 (goto-char (point-max))
4826 (dolist (m paragraph-markers)
4827 (when (< m (point))
4828 (goto-char m)
4829 (beginning-of-line)
4830 (let ((beg (point)))
4831 (when (zerop (forward-paragraph))
4832 (fill-individual-paragraphs beg (point) nil nil)
4833 (goto-char beg))))
4834 (set-marker m nil))))
4836 ;; Fontify menu items
4837 (goto-char (point-min))
4838 (when (and (or not-fontified-p fontify-visited-p)
4839 (search-forward "\n* Menu:" nil t)
4840 ;; Don't take time to annotate huge menus
4841 Info-fontify-maximum-menu-size
4842 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4843 (let ((n 0)
4844 cont)
4845 (while (re-search-forward
4846 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4847 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4848 nil t)
4849 (when (match-beginning 1)
4850 (when not-fontified-p
4851 (setq n (1+ n))
4852 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4853 (put-text-property (match-beginning 0)
4854 (1+ (match-beginning 0))
4855 'font-lock-face 'info-menu-star)))
4856 (when not-fontified-p
4857 (add-text-properties
4858 (match-beginning 1) (match-end 1)
4859 (list
4860 'help-echo (if (and (match-end 3)
4861 (not (equal (match-string 3) "")))
4862 (concat "mouse-2: go to " (match-string 3))
4863 "mouse-2: go to this node")
4864 'mouse-face 'highlight)))
4865 (when (or not-fontified-p fontify-visited-p)
4866 (put-text-property
4867 (match-beginning 1) (match-end 1)
4868 'font-lock-face
4869 ;; Display visited menu items in a different face
4870 (if (and Info-fontify-visited-nodes
4871 (save-match-data
4872 (let* ((node (if (equal (match-string 3) "")
4873 (match-string-no-properties 1)
4874 (match-string-no-properties 3)))
4875 (external-link-p
4876 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4877 (file (if external-link-p
4878 (file-name-nondirectory
4879 (match-string-no-properties 1 node))
4880 Info-current-file))
4881 (hl Info-history-list)
4882 res)
4883 (if external-link-p
4884 (setq node (if (equal (match-string 2 node) "")
4885 "Top"
4886 (match-string-no-properties 2 node))))
4887 (while hl
4888 (if (and (string-equal node (nth 1 (car hl)))
4889 (equal file
4890 (if (and external-link-p
4891 (stringp (caar hl)))
4892 (file-name-nondirectory
4893 (caar hl))
4894 (caar hl))))
4895 (setq res (car hl) hl nil)
4896 (setq hl (cdr hl))))
4897 res))) 'info-xref-visited 'info-xref)))
4898 (when (and not-fontified-p
4899 (memq Info-hide-note-references '(t hide))
4900 (not (Info-index-node)))
4901 (put-text-property (match-beginning 2) (1- (match-end 6))
4902 'invisible t)
4903 ;; Unhide the file name in parens
4904 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4905 (remove-text-properties (match-beginning 4) (match-end 4)
4906 '(invisible t)))
4907 ;; We need a stretchable space like :align-to but with
4908 ;; a minimum value.
4909 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4910 (if (>= 22 (- (match-end 1)
4911 (match-beginning 0)))
4912 '(space :align-to 24)
4913 '(space :width 2)))
4914 (setq cont (looking-at "."))
4915 (while (and (= (forward-line 1) 0)
4916 (looking-at "\\([ \t]+\\)[^*\n]"))
4917 (put-text-property (match-beginning 1) (1- (match-end 1))
4918 'invisible t)
4919 (put-text-property (1- (match-end 1)) (match-end 1)
4920 'display
4921 (if cont
4922 '(space :align-to 26)
4923 '(space :align-to 24)))
4924 (setq cont t)))))))
4926 ;; Fontify menu headers
4927 ;; Add the face `info-menu-header' to any header before a menu entry
4928 (goto-char (point-min))
4929 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4930 (put-text-property (match-beginning 0) (match-end 0)
4931 'font-lock-face 'info-menu-header)
4932 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4933 (put-text-property (match-beginning 1) (match-end 1)
4934 'font-lock-face 'info-menu-header)))
4936 ;; Hide index line numbers
4937 (goto-char (point-min))
4938 (when (and not-fontified-p (Info-index-node))
4939 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4940 (put-text-property (match-beginning 0) (match-end 0)
4941 'invisible t)))
4943 ;; Fontify http and ftp references
4944 (goto-char (point-min))
4945 (when not-fontified-p
4946 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4947 nil t)
4948 (add-text-properties (match-beginning 0) (match-end 0)
4949 '(font-lock-face info-xref
4950 mouse-face highlight
4951 help-echo "mouse-2: go to this URL"))))
4953 ;; Fontify footnotes
4954 (goto-char (point-min))
4955 (when (and not-fontified-p (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t))
4956 (let ((limit (point)))
4957 (goto-char (point-min))
4958 (while (re-search-forward "\\(([0-9]+)\\)" nil t)
4959 (add-text-properties (match-beginning 0) (match-end 0)
4960 `(font-lock-face info-xref
4961 link t
4962 mouse-face highlight
4963 help-echo
4964 ,(if (< (point) limit)
4965 "mouse-2: go to footnote definition"
4966 "mouse-2: go to footnote reference"))))))
4968 ;; Hide empty lines at the end of the node.
4969 (goto-char (point-max))
4970 (skip-chars-backward "\n")
4971 (when (< (point) (1- (point-max)))
4972 (put-text-property (point) (1- (point-max)) 'invisible t))
4974 (set-buffer-modified-p nil))))
4976 ;;; Speedbar support:
4977 ;; These functions permit speedbar to display the "tags" in the
4978 ;; current Info node.
4979 (eval-when-compile (require 'speedbar)) ; for speedbar-with-writable
4981 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
4982 (declare-function speedbar-center-buffer-smartly "speedbar" ())
4983 (declare-function speedbar-change-expand-button-char "speedbar" (char))
4984 (declare-function speedbar-change-initial-expansion-list "speedbar" (new-default))
4985 (declare-function speedbar-delete-subblock "speedbar" (indent))
4986 (declare-function speedbar-make-specialized-keymap "speedbar" ())
4987 (declare-function speedbar-make-tag-line "speedbar"
4988 (exp-button-type exp-button-char exp-button-function
4989 exp-button-data tag-button tag-button-function
4990 tag-button-data tag-button-face depth))
4992 (defvar Info-speedbar-key-map nil
4993 "Keymap used when in the Info display mode.")
4995 (defun Info-install-speedbar-variables ()
4996 "Install those variables used by speedbar to enhance Info."
4997 (if Info-speedbar-key-map
4999 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
5001 ;; Basic tree features
5002 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
5003 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
5004 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
5005 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
5008 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
5009 Info-speedbar-key-map
5010 Info-speedbar-hierarchy-buttons)))
5012 (defvar Info-speedbar-menu-items
5013 '(["Browse Node" speedbar-edit-line t]
5014 ["Expand Node" speedbar-expand-line
5015 (save-excursion (beginning-of-line)
5016 (looking-at "[0-9]+: *.\\+. "))]
5017 ["Contract Node" speedbar-contract-line
5018 (save-excursion (beginning-of-line)
5019 (looking-at "[0-9]+: *.-. "))]
5021 "Additional menu-items to add to speedbar frame.")
5023 ;; Make sure our special speedbar major mode is loaded
5024 (if (featurep 'speedbar)
5025 (Info-install-speedbar-variables)
5026 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
5028 ;;; Info hierarchy display method
5029 ;;;###autoload
5030 (defun Info-speedbar-browser ()
5031 "Initialize speedbar to display an Info node browser.
5032 This will add a speedbar major display mode."
5033 (interactive)
5034 (require 'speedbar)
5035 ;; Make sure that speedbar is active
5036 (speedbar-frame-mode 1)
5037 ;; Now, throw us into Info mode on speedbar.
5038 (speedbar-change-initial-expansion-list "Info")
5041 ;; speedbar loads dframe at runtime.
5042 (declare-function dframe-select-attached-frame "dframe" (&optional frame))
5043 (declare-function dframe-current-frame "dframe" (frame-var desired-major-mode))
5045 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
5046 "Display an Info directory hierarchy in speedbar.
5047 DIRECTORY is the current directory in the attached frame.
5048 DEPTH is the current indentation depth.
5049 NODE is an optional argument that is used to represent the
5050 specific node to expand."
5051 (if (and (not node)
5052 (save-excursion (goto-char (point-min))
5053 (let ((case-fold-search t))
5054 (looking-at "Info Nodes:"))))
5055 ;; Update our "current node" maybe?
5057 ;; We cannot use the generic list code, that depends on all leaves
5058 ;; being known at creation time.
5059 (if (not node)
5060 (speedbar-with-writable (insert "Info Nodes:\n")))
5061 (let ((completions nil))
5062 (speedbar-select-attached-frame)
5063 (save-window-excursion
5064 (setq completions
5065 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
5066 (select-frame (speedbar-current-frame))
5067 (if completions
5068 (speedbar-with-writable
5069 (dolist (completion completions)
5070 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
5071 (cdr completion)
5072 (car completion)
5073 'Info-speedbar-goto-node
5074 (cdr completion)
5075 'info-xref depth))
5077 nil))))
5079 (defun Info-speedbar-goto-node (_text node _indent)
5080 "When user clicks on TEXT, go to an info NODE.
5081 The INDENT level is ignored."
5082 (speedbar-select-attached-frame)
5083 (let* ((buff (or (get-buffer "*info*")
5084 (progn (info) (get-buffer "*info*"))))
5085 (bwin (get-buffer-window buff 0)))
5086 (if bwin
5087 (progn
5088 (select-window bwin)
5089 (raise-frame (window-frame bwin)))
5090 (if speedbar-power-click
5091 (switch-to-buffer-other-frame buff)
5092 (speedbar-select-attached-frame)
5093 (switch-to-buffer buff)))
5094 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
5095 (error "Invalid node %s" node)
5096 (Info-find-node (match-string 1 node) (match-string 2 node))
5097 ;; If we do a find-node, and we were in info mode, restore
5098 ;; the old default method. Once we are in info mode, it makes
5099 ;; sense to return to whatever method the user was using before.
5100 (if (string= speedbar-initial-expansion-list-name "Info")
5101 (speedbar-change-initial-expansion-list
5102 speedbar-previously-used-expansion-list-name)))))
5104 (defun Info-speedbar-expand-node (text token indent)
5105 "Expand the node the user clicked on.
5106 TEXT is the text of the button we clicked on, a + or - item.
5107 TOKEN is data related to this node (NAME . FILE).
5108 INDENT is the current indentation depth."
5109 (cond ((string-match "+" text) ;we have to expand this file
5110 (speedbar-change-expand-button-char ?-)
5111 (if (speedbar-with-writable
5112 (save-excursion
5113 (end-of-line) (forward-char 1)
5114 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
5115 (speedbar-change-expand-button-char ?-)
5116 (speedbar-change-expand-button-char ??)))
5117 ((string-match "-" text) ;we have to contract this node
5118 (speedbar-change-expand-button-char ?+)
5119 (speedbar-delete-subblock indent))
5120 (t (error "Ooops... not sure what to do")))
5121 (speedbar-center-buffer-smartly))
5123 (defun Info-speedbar-fetch-file-nodes (nodespec)
5124 "Fetch the subnodes from the info NODESPEC.
5125 NODESPEC is a string of the form: (file)node."
5126 ;; Set up a buffer we can use to fake-out Info.
5127 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
5128 (if (not (derived-mode-p 'Info-mode))
5129 (Info-mode))
5130 ;; Get the node into this buffer
5131 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
5132 (error "Invalid node specification %s" nodespec)
5133 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
5134 ;; Scan the created buffer
5135 (goto-char (point-min))
5136 (let ((completions nil)
5137 (case-fold-search t)
5138 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
5139 (match-string 1 nodespec))))
5140 ;; Always skip the first one...
5141 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5142 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5143 (let ((name (match-string 1)))
5144 (push (cons name
5145 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
5146 (match-string 1)
5147 (if (looking-at " *\\(([^)]+)\\)\\.")
5148 (concat (match-string 1) "Top")
5149 (concat "(" thisfile ")"
5150 (if (looking-at " \\([^.]+\\).")
5151 (match-string 1)
5152 name)))))
5153 completions)))
5154 (nreverse completions))))
5156 ;;; Info mode node listing
5157 ;; This is called by `speedbar-add-localized-speedbar-support'
5158 (defun Info-speedbar-buttons (_buffer)
5159 "Create a speedbar display to help navigation in an Info file.
5160 BUFFER is the buffer speedbar is requesting buttons for."
5161 (if (save-excursion (goto-char (point-min))
5162 (let ((case-fold-search t))
5163 (not (looking-at "Info Nodes:"))))
5164 (erase-buffer))
5165 (Info-speedbar-hierarchy-buttons nil 0))
5167 ;; FIXME: Really? Why here?
5168 (add-to-list 'debug-ignored-errors 'search-failed)
5170 ;;;; Desktop support
5172 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
5173 "Auxiliary information to be saved in desktop file."
5174 (list Info-current-file
5175 Info-current-node
5176 ;; Additional data as an association list.
5177 (delq nil (list
5178 (and Info-history
5179 (cons 'history Info-history))
5180 (and (Info-virtual-fun
5181 'slow Info-current-file Info-current-node)
5182 (cons 'slow t))))))
5184 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
5185 desktop-buffer-name
5186 desktop-buffer-misc)
5187 "Restore an Info buffer specified in a desktop file."
5188 (let* ((file (nth 0 desktop-buffer-misc))
5189 (node (nth 1 desktop-buffer-misc))
5190 (data (nth 2 desktop-buffer-misc))
5191 (hist (assq 'history data))
5192 (slow (assq 'slow data)))
5193 ;; Don't restore nodes slow to regenerate.
5194 (unless slow
5195 (when (and file node)
5196 (when desktop-buffer-name
5197 (set-buffer (get-buffer-create desktop-buffer-name))
5198 (Info-mode))
5199 (Info-find-node file node)
5200 (when hist
5201 (setq Info-history (cdr hist)))
5202 (current-buffer)))))
5204 (add-to-list 'desktop-buffer-mode-handlers
5205 '(Info-mode . Info-restore-desktop-buffer))
5207 ;;;; Bookmark support
5208 (declare-function bookmark-make-record-default
5209 "bookmark" (&optional no-file no-context posn))
5210 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
5211 (declare-function bookmark-default-handler "bookmark" (bmk))
5212 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
5214 (defun Info-bookmark-make-record ()
5215 "This implements the `bookmark-make-record-function' type (which see)
5216 for Info nodes."
5217 (let* ((file (and (stringp Info-current-file)
5218 (file-name-sans-extension
5219 (file-name-nondirectory Info-current-file))))
5220 (bookmark-name (if file
5221 (concat "(" file ") " Info-current-node)
5222 Info-current-node))
5223 (defaults (delq nil (list bookmark-name file Info-current-node))))
5224 `(,bookmark-name
5225 ,@(bookmark-make-record-default 'no-file)
5226 (filename . ,Info-current-file)
5227 (info-node . ,Info-current-node)
5228 (handler . Info-bookmark-jump)
5229 (defaults . ,defaults))))
5231 ;;;###autoload
5232 (defun Info-bookmark-jump (bmk)
5233 "This implements the `handler' function interface for the record
5234 type returned by `Info-bookmark-make-record', which see."
5235 (let* ((file (bookmark-prop-get bmk 'filename))
5236 (info-node (bookmark-prop-get bmk 'info-node))
5237 (buf (save-window-excursion ;FIXME: doesn't work with frames!
5238 (Info-find-node file info-node) (current-buffer))))
5239 ;; Use bookmark-default-handler to move to the appropriate location
5240 ;; within the node.
5241 (bookmark-default-handler
5242 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
5245 ;;;###autoload
5246 (defun info-display-manual (manual)
5247 "Display an Info buffer displaying MANUAL.
5248 If there is an existing Info buffer for MANUAL, display it.
5249 Otherwise, visit the manual in a new Info buffer."
5250 (interactive
5251 (list
5252 (progn
5253 (info-initialize)
5254 (completing-read "Manual name: "
5255 (info--manual-names)
5256 nil t))))
5257 (let ((blist (buffer-list))
5258 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
5259 (case-fold-search t)
5260 found)
5261 (dolist (buffer blist)
5262 (with-current-buffer buffer
5263 (when (and (eq major-mode 'Info-mode)
5264 (stringp Info-current-file)
5265 (string-match manual-re Info-current-file))
5266 (setq found buffer
5267 blist nil))))
5268 (if found
5269 (switch-to-buffer found)
5270 (info-initialize)
5271 (info (Info-find-file manual)
5272 (generate-new-buffer-name "*info*")))))
5274 (defun info--manual-names ()
5275 (let (names)
5276 (dolist (buffer (buffer-list))
5277 (with-current-buffer buffer
5278 (and (eq major-mode 'Info-mode)
5279 (stringp Info-current-file)
5280 (not (string= (substring (buffer-name) 0 1) " "))
5281 (push (file-name-sans-extension
5282 (file-name-nondirectory Info-current-file))
5283 names))))
5284 (delete-dups (append (nreverse names)
5285 (all-completions
5287 (apply-partially 'Info-read-node-name-2
5288 Info-directory-list
5289 (mapcar 'car Info-suffix-list)))))))
5291 (provide 'info)
5293 ;;; info.el ends here