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