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