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