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