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