Spelling fixes.
[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 (let ((search-spaces-regexp
1773 (if (or (not isearch-mode) isearch-regexp)
1774 Info-search-whitespace-regexp)))
1775 (if backward
1776 (re-search-backward regexp)
1777 (re-search-forward regexp)))
1778 (setq found nil)))
1779
1780 (if (and bound (not found))
1781 (signal 'search-failed (list regexp)))
1782
1783 (unless (or found bound)
1784 (unwind-protect
1785 ;; Try other subfiles.
1786 (let ((list ()))
1787 (with-current-buffer (marker-buffer Info-tag-table-marker)
1788 (goto-char (point-min))
1789 (search-forward "\n\^_\nIndirect:")
1790 (save-restriction
1791 (narrow-to-region (point)
1792 (progn (search-forward "\n\^_")
1793 (1- (point))))
1794 (goto-char (point-min))
1795 ;; Find the subfile we just searched.
1796 (search-forward (concat "\n" osubfile ": "))
1797 ;; Skip that one.
1798 (forward-line (if backward 0 1))
1799 (if backward (forward-char -1))
1800 ;; Make a list of all following subfiles.
1801 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1802 (while (not (if backward (bobp) (eobp)))
1803 (if backward
1804 (re-search-backward "\\(^.*\\): [0-9]+$")
1805 (re-search-forward "\\(^.*\\): [0-9]+$"))
1806 (goto-char (+ (match-end 1) 2))
1807 (setq list (cons (cons (+ (point-min)
1808 (read (current-buffer)))
1809 (match-string-no-properties 1))
1810 list))
1811 (goto-char (if backward
1812 (1- (match-beginning 0))
1813 (1+ (match-end 0)))))
1814 ;; Put in forward order
1815 (setq list (nreverse list))))
1816 (while list
1817 (message "Searching subfile %s..." (cdr (car list)))
1818 (Info-read-subfile (car (car list)))
1819 (when backward
1820 ;; Hide Info file header for backward search
1821 (narrow-to-region (save-excursion
1822 (goto-char (point-min))
1823 (search-forward "\n\^_")
1824 (1- (point)))
1825 (point-max))
1826 (goto-char (point-max)))
1827 (setq list (cdr list))
1828 (setq give-up nil found nil)
1829 (while (and (not give-up)
1830 (or (null found)
1831 (not (funcall isearch-filter-predicate beg-found found))))
1832 (let ((search-spaces-regexp
1833 (if (or (not isearch-mode) isearch-regexp)
1834 Info-search-whitespace-regexp)))
1835 (if (if backward
1836 (re-search-backward regexp nil t)
1837 (re-search-forward regexp nil t))
1838 (setq found (point) beg-found (if backward (match-end 0)
1839 (match-beginning 0)))
1840 (setq give-up t))))
1841 (if give-up
1842 (setq found nil))
1843 (if found
1844 (setq list nil)))
1845 (if found
1846 (message "")
1847 (signal 'search-failed (if isearch-mode
1848 (list regexp "end of the manual")
1849 (list regexp)))))
1850 (if (not found)
1851 (progn (Info-read-subfile osubfile)
1852 (goto-char opoint)
1853 (Info-select-node)
1854 (set-window-start (selected-window) ostart)))))
1855
1856 (if (and (string= osubfile Info-current-subfile)
1857 (> found opoint-min)
1858 (< found opoint-max))
1859 ;; Search landed in the same node
1860 (goto-char found)
1861 (widen)
1862 (goto-char found)
1863 (save-match-data (Info-select-node)))
1864
1865 ;; Use string-equal, not equal, to ignore text props.
1866 (or (and (string-equal onode Info-current-node)
1867 (equal ofile Info-current-file))
1868 (and isearch-mode isearch-wrapped
1869 (eq opoint (if isearch-forward opoint-min opoint-max)))
1870 (setq Info-history (cons (list ofile onode opoint)
1871 Info-history))))))
1872
1873 (defun Info-search-case-sensitively ()
1874 "Search for a regexp case-sensitively."
1875 (interactive)
1876 (let ((case-fold-search nil))
1877 (call-interactively 'Info-search)))
1878
1879 (defun Info-search-next ()
1880 "Search for next regexp from a previous `Info-search' command."
1881 (interactive)
1882 (let ((case-fold-search Info-search-case-fold))
1883 (if Info-search-history
1884 (Info-search (car Info-search-history))
1885 (call-interactively 'Info-search))))
1886
1887 (defun Info-search-backward (regexp &optional bound noerror count)
1888 "Search for REGEXP in the reverse direction."
1889 (interactive (list (read-string
1890 (if Info-search-history
1891 (format "Regexp search%s backward (default %s): "
1892 (if case-fold-search "" " case-sensitively")
1893 (car Info-search-history))
1894 (format "Regexp search%s backward: "
1895 (if case-fold-search "" " case-sensitively")))
1896 nil 'Info-search-history)))
1897 (Info-search regexp bound noerror count 'backward))
1898
1899 (defun Info-isearch-search ()
1900 (if Info-isearch-search
1901 (lambda (string &optional bound noerror count)
1902 (if isearch-word
1903 (Info-search (concat "\\b" (replace-regexp-in-string
1904 "\\W+" "\\W+"
1905 (replace-regexp-in-string
1906 "^\\W+\\|\\W+$" "" string)
1907 nil t)
1908 ;; Lax version of word search
1909 (if (or isearch-nonincremental
1910 (eq (length string)
1911 (length (isearch-string-state
1912 (car isearch-cmds)))))
1913 "\\b"))
1914 bound noerror count
1915 (unless isearch-forward 'backward))
1916 (Info-search (if isearch-regexp string (regexp-quote string))
1917 bound noerror count
1918 (unless isearch-forward 'backward)))
1919 (point))
1920 (let ((isearch-search-fun-function nil))
1921 (isearch-search-fun))))
1922
1923 (defun Info-isearch-wrap ()
1924 (if Info-isearch-search
1925 (if Info-isearch-initial-node
1926 (progn
1927 (if isearch-forward (Info-top-node) (Info-final-node))
1928 (goto-char (if isearch-forward (point-min) (point-max))))
1929 (setq Info-isearch-initial-node Info-current-node)
1930 (setq isearch-wrapped nil))
1931 (goto-char (if isearch-forward (point-min) (point-max)))))
1932
1933 (defun Info-isearch-push-state ()
1934 `(lambda (cmd)
1935 (Info-isearch-pop-state cmd ',Info-current-file ',Info-current-node)))
1936
1937 (defun Info-isearch-pop-state (_cmd file node)
1938 (or (and (equal Info-current-file file)
1939 (equal Info-current-node node))
1940 (progn (Info-find-node file node) (sit-for 0))))
1941
1942 (defun Info-isearch-start ()
1943 (setq Info-isearch-initial-node
1944 ;; Don't stop at initial node for nonincremental search.
1945 ;; Otherwise this variable is set after first search failure.
1946 (and isearch-nonincremental Info-current-node))
1947 (setq Info-isearch-initial-history Info-history
1948 Info-isearch-initial-history-list Info-history-list)
1949 (add-hook 'isearch-mode-end-hook 'Info-isearch-end nil t))
1950
1951 (defun Info-isearch-end ()
1952 ;; Remove intermediate nodes (visited while searching)
1953 ;; from the history. Add only the last node (where Isearch ended).
1954 (if (> (length Info-history)
1955 (length Info-isearch-initial-history))
1956 (setq Info-history
1957 (nthcdr (- (length Info-history)
1958 (length Info-isearch-initial-history)
1959 1)
1960 Info-history)))
1961 (if (> (length Info-history-list)
1962 (length Info-isearch-initial-history-list))
1963 (setq Info-history-list
1964 (cons (car Info-history-list)
1965 Info-isearch-initial-history-list)))
1966 (remove-hook 'isearch-mode-end-hook 'Info-isearch-end t))
1967
1968 (defun Info-isearch-filter (beg-found found)
1969 "Test whether the current search hit is a visible useful text.
1970 Return non-nil if the text from BEG-FOUND to FOUND is visible
1971 and is not in the header line or a tag table."
1972 (save-match-data
1973 (let ((backward (< found beg-found)))
1974 (not
1975 (or
1976 (and (not (eq search-invisible t))
1977 (if backward
1978 (or (text-property-not-all found beg-found 'invisible nil)
1979 (text-property-not-all found beg-found 'display nil))
1980 (or (text-property-not-all beg-found found 'invisible nil)
1981 (text-property-not-all beg-found found 'display nil))))
1982 ;; Skip node header line
1983 (and (save-excursion (forward-line -1)
1984 (looking-at "\^_"))
1985 (forward-line (if backward -1 1)))
1986 ;; Skip Tag Table node
1987 (save-excursion
1988 (and (search-backward "\^_" nil t)
1989 (looking-at
1990 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
1991
1992 \f
1993 (defun Info-extract-pointer (name &optional errorname)
1994 "Extract the value of the node-pointer named NAME.
1995 If there is none, use ERRORNAME in the error message;
1996 if ERRORNAME is nil, just return nil."
1997 ;; Bind this in case the user sets it to nil.
1998 (let ((case-fold-search t))
1999 (save-excursion
2000 (goto-char (point-min))
2001 (let ((bound (point)))
2002 (forward-line 1)
2003 (cond ((re-search-backward
2004 (concat name ":" (Info-following-node-name-re)) bound t)
2005 (match-string-no-properties 1))
2006 ((not (eq errorname t))
2007 (error "Node has no %s"
2008 (capitalize (or errorname name)))))))))
2009
2010 (defun Info-following-node-name-re (&optional allowedchars)
2011 "Return a regexp matching a node name.
2012 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
2013 saying which chars may appear in the node name.
2014 Submatch 1 is the complete node name.
2015 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2016 Submatch 3 is the local part of the node name.
2017 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2018 (concat "[ \t\n]*" ;Skip leading space.
2019 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2020 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
2021 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
2022 "\\|\\)\\)")) ;Allow empty node names.
2023
2024 ;;; For compatibility; other files have used this name.
2025 (defun Info-following-node-name ()
2026 (and (looking-at (Info-following-node-name-re))
2027 (match-string-no-properties 1)))
2028
2029 (defun Info-next ()
2030 "Go to the next node of this node."
2031 (interactive)
2032 ;; In case another window is currently selected
2033 (save-window-excursion
2034 (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
2035 (Info-goto-node (Info-extract-pointer "next"))))
2036
2037 (defun Info-prev ()
2038 "Go to the previous node of this node."
2039 (interactive)
2040 ;; In case another window is currently selected
2041 (save-window-excursion
2042 (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
2043 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2044
2045 (defun Info-up (&optional same-file)
2046 "Go to the superior node of this node.
2047 If SAME-FILE is non-nil, do not move to a different Info file."
2048 (interactive)
2049 ;; In case another window is currently selected
2050 (save-window-excursion
2051 (or (eq major-mode 'Info-mode) (switch-to-buffer "*info*"))
2052 (let ((old-node Info-current-node)
2053 (old-file Info-current-file)
2054 (node (Info-extract-pointer "up")) p)
2055 (and same-file
2056 (string-match "^(" node)
2057 (error "Up node is in another Info file"))
2058 (Info-goto-node node)
2059 (setq p (point))
2060 (goto-char (point-min))
2061 (if (and (stringp old-file)
2062 (search-forward "\n* Menu:" nil t)
2063 (re-search-forward
2064 (if (string-equal old-node "Top")
2065 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
2066 (concat "\n\\* +\\(" (regexp-quote old-node)
2067 ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
2068 nil t))
2069 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2070 (goto-char p)
2071 (Info-restore-point Info-history)))))
2072
2073 (defun Info-history-back ()
2074 "Go back in the history to the last node visited."
2075 (interactive)
2076 (or Info-history
2077 (error "This is the first Info node you looked at"))
2078 (let ((history-forward
2079 (cons (list Info-current-file Info-current-node (point))
2080 Info-history-forward))
2081 filename nodename opoint)
2082 (setq filename (car (car Info-history)))
2083 (setq nodename (car (cdr (car Info-history))))
2084 (setq opoint (car (cdr (cdr (car Info-history)))))
2085 (setq Info-history (cdr Info-history))
2086 (Info-find-node filename nodename)
2087 (setq Info-history (cdr Info-history))
2088 (setq Info-history-forward history-forward)
2089 (goto-char opoint)))
2090
2091 (defalias 'Info-last 'Info-history-back)
2092
2093 (defun Info-history-forward ()
2094 "Go forward in the history of visited nodes."
2095 (interactive)
2096 (or Info-history-forward
2097 (error "This is the last Info node you looked at"))
2098 (let ((history-forward (cdr Info-history-forward))
2099 filename nodename opoint)
2100 (setq filename (car (car Info-history-forward)))
2101 (setq nodename (car (cdr (car Info-history-forward))))
2102 (setq opoint (car (cdr (cdr (car Info-history-forward)))))
2103 (Info-find-node filename nodename)
2104 (setq Info-history-forward history-forward)
2105 (goto-char opoint)))
2106 \f
2107 (add-to-list 'Info-virtual-files
2108 '("\\`dir\\'"
2109 (toc-nodes . Info-directory-toc-nodes)
2110 (find-file . Info-directory-find-file)
2111 (find-node . Info-directory-find-node)
2112 ))
2113
2114 (defun Info-directory-toc-nodes (filename)
2115 "Directory-specific implementation of `Info-toc-nodes'."
2116 `(,filename
2117 ("Top" nil nil nil)))
2118
2119 (defun Info-directory-find-file (filename &optional _noerror)
2120 "Directory-specific implementation of `Info-find-file'."
2121 filename)
2122
2123 (defun Info-directory-find-node (_filename _nodename &optional _no-going-back)
2124 "Directory-specific implementation of `Info-find-node-2'."
2125 (Info-insert-dir))
2126
2127 ;;;###autoload
2128 (defun Info-directory ()
2129 "Go to the Info directory node."
2130 (interactive)
2131 (Info-find-node "dir" "top"))
2132 \f
2133 (add-to-list 'Info-virtual-files
2134 '("\\`\\*History\\*\\'"
2135 (toc-nodes . Info-history-toc-nodes)
2136 (find-file . Info-history-find-file)
2137 (find-node . Info-history-find-node)
2138 ))
2139
2140 (defun Info-history-toc-nodes (filename)
2141 "History-specific implementation of `Info-toc-nodes'."
2142 `(,filename
2143 ("Top" nil nil nil)))
2144
2145 (defun Info-history-find-file (filename &optional _noerror)
2146 "History-specific implementation of `Info-find-file'."
2147 filename)
2148
2149 (defun Info-history-find-node (filename nodename &optional _no-going-back)
2150 "History-specific implementation of `Info-find-node-2'."
2151 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2152 (or filename Info-current-file) nodename))
2153 (insert "Recently Visited Nodes\n")
2154 (insert "**********************\n\n")
2155 (insert "* Menu:\n\n")
2156 (let ((hl (remove '("*History*" "Top") Info-history-list)))
2157 (while hl
2158 (let ((file (nth 0 (car hl)))
2159 (node (nth 1 (car hl))))
2160 (if (stringp file)
2161 (insert "* " node ": ("
2162 (propertize (or (file-name-directory file) "") 'invisible t)
2163 (file-name-nondirectory file)
2164 ")" node ".\n")))
2165 (setq hl (cdr hl)))))
2166
2167 (defun Info-history ()
2168 "Go to a node with a menu of visited nodes."
2169 (interactive)
2170 (Info-find-node "*History*" "Top")
2171 (Info-next-reference)
2172 (Info-next-reference))
2173 \f
2174 (add-to-list 'Info-virtual-nodes
2175 '("\\`\\*TOC\\*\\'"
2176 (find-node . Info-toc-find-node)
2177 ))
2178
2179 (defun Info-toc-find-node (filename nodename &optional _no-going-back)
2180 "Toc-specific implementation of `Info-find-node-2'."
2181 (let* ((curr-file (substring-no-properties (or filename Info-current-file)))
2182 (curr-node (substring-no-properties (or nodename Info-current-node)))
2183 (node-list (Info-toc-nodes curr-file)))
2184 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2185 curr-file curr-node))
2186 (insert "Table of Contents\n")
2187 (insert "*****************\n\n")
2188 (insert "*Note Top::\n")
2189 (Info-toc-insert
2190 (nth 3 (assoc "Top" node-list)) ; get Top nodes
2191 node-list 0 curr-file)
2192 (unless (bobp)
2193 (let ((Info-hide-note-references 'hide)
2194 (Info-fontify-visited-nodes nil))
2195 (setq Info-current-file filename Info-current-node "*TOC*")
2196 (goto-char (point-min))
2197 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t)
2198 (point-min))
2199 (point-max))
2200 (Info-fontify-node)
2201 (widen)))))
2202
2203 (defun Info-toc ()
2204 "Go to a node with table of contents of the current Info file.
2205 Table of contents is created from the tree structure of menus."
2206 (interactive)
2207 (Info-find-node Info-current-file "*TOC*")
2208 (let ((prev-node (nth 1 (car Info-history))) p)
2209 (goto-char (point-min))
2210 (if (setq p (search-forward (concat "*Note " prev-node ":") nil t))
2211 (setq p (- p (length prev-node) 2)))
2212 (goto-char (or p (point-min)))))
2213
2214 (defun Info-toc-insert (nodes node-list level curr-file)
2215 "Insert table of contents with references to nodes."
2216 (let ((section "Top"))
2217 (while nodes
2218 (let ((node (assoc (car nodes) node-list)))
2219 (unless (member (nth 2 node) (list nil section))
2220 (insert (setq section (nth 2 node)) "\n"))
2221 (insert (make-string level ?\t))
2222 (insert "*Note " (car nodes) ":: \n")
2223 (Info-toc-insert (nth 3 node) node-list (1+ level) curr-file)
2224 (setq nodes (cdr nodes))))))
2225
2226 (defun Info-toc-build (file)
2227 "Build table of contents from menus of Info FILE and its subfiles."
2228 (with-temp-buffer
2229 (let* ((file (and (stringp file) (Info-find-file file)))
2230 (default-directory (or (and (stringp file)
2231 (file-name-directory file))
2232 default-directory))
2233 (main-file (and (stringp file) file))
2234 (sections '(("Top" "Top")))
2235 nodes subfiles)
2236 (while (or main-file subfiles)
2237 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2238 (erase-buffer)
2239 (info-insert-file-contents (or main-file (car subfiles)))
2240 (goto-char (point-min))
2241 (while (and (search-forward "\n\^_\nFile:" nil 'move)
2242 (search-forward "Node: " nil 'move))
2243 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2244 (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
2245 (point-max)) 2))
2246 (upnode (and (re-search-forward
2247 (concat "Up:" (Info-following-node-name-re))
2248 bound t)
2249 (match-string-no-properties 1)))
2250 (section "Top")
2251 menu-items)
2252 (when (string-match "(" upnode) (setq upnode nil))
2253 (when (and (not (Info-index-node nodename file))
2254 (re-search-forward "^\\* Menu:" bound t))
2255 (forward-line 1)
2256 (beginning-of-line)
2257 (setq bound (or (and (equal nodename "Top")
2258 (save-excursion
2259 (re-search-forward
2260 "^[ \t-]*The Detailed Node Listing" nil t)))
2261 bound))
2262 (while (< (point) bound)
2263 (cond
2264 ;; Menu item line
2265 ((looking-at "^\\* +[^:]+:")
2266 (beginning-of-line)
2267 (forward-char 2)
2268 (let ((menu-node-name (substring-no-properties
2269 (Info-extract-menu-node-name))))
2270 (setq menu-items (cons menu-node-name menu-items))
2271 (if (equal nodename "Top")
2272 (setq sections
2273 (cons (list menu-node-name section) sections)))))
2274 ;; Other non-empty strings in the Top node are section names
2275 ((and (equal nodename "Top")
2276 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2277 (setq section (match-string-no-properties 1))))
2278 (forward-line 1)
2279 (beginning-of-line)))
2280 (setq nodes (cons (list nodename upnode
2281 (cadr (assoc nodename sections))
2282 (nreverse menu-items))
2283 nodes))
2284 (goto-char bound)))
2285 (if main-file
2286 (save-excursion
2287 (goto-char (point-min))
2288 (if (search-forward "\n\^_\nIndirect:" nil t)
2289 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2290 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2291 (setq subfiles (cons (match-string-no-properties 1)
2292 subfiles)))))
2293 (setq subfiles (nreverse subfiles)
2294 main-file nil))
2295 (setq subfiles (cdr subfiles))))
2296 (message "")
2297 (nreverse nodes))))
2298
2299 (defvar Info-toc-nodes nil
2300 "Alist of cached parent-children node information in visited Info files.
2301 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
2302 where PARENT is the parent node extracted from the Up pointer,
2303 SECTION is the section name in the Top node where this node is placed,
2304 CHILDREN is a list of child nodes extracted from the node menu.")
2305
2306 (defun Info-toc-nodes (filename)
2307 "Return a node list of Info FILENAME with parent-children information.
2308 This information is cached in the variable `Info-toc-nodes' with the help
2309 of the function `Info-toc-build'."
2310 (cond
2311 ((Info-virtual-call
2312 (Info-virtual-fun 'toc-nodes (or filename Info-current-file) nil)
2313 filename))
2314 (t
2315 (or filename (setq filename Info-current-file))
2316 (or (assoc filename Info-toc-nodes)
2317 ;; Skip virtual Info files
2318 (and (or (not (stringp filename))
2319 (Info-virtual-file-p filename))
2320 (push (cons filename nil) Info-toc-nodes))
2321 ;; Scan the entire manual and cache the result in Info-toc-nodes
2322 (let ((nodes (Info-toc-build filename)))
2323 (push (cons filename nodes) Info-toc-nodes)
2324 nodes)
2325 ;; If there is an error, still add nil to the cache
2326 (push (cons filename nil) Info-toc-nodes))
2327 (cdr (assoc filename Info-toc-nodes)))))
2328
2329 \f
2330 (defun Info-follow-reference (footnotename &optional fork)
2331 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2332 FOOTNOTENAME may be an abbreviation of the reference name.
2333 If FORK is non-nil (interactively with a prefix arg), show the node in
2334 a new Info buffer. If FORK is a string, it is the name to use for the
2335 new buffer."
2336 (interactive
2337 (let ((completion-ignore-case t)
2338 (case-fold-search t)
2339 completions default alt-default (start-point (point)) str i bol eol)
2340 (save-excursion
2341 ;; Store end and beginning of line.
2342 (setq eol (line-end-position)
2343 bol (line-beginning-position))
2344 (goto-char (point-min))
2345 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
2346 (setq str (match-string-no-properties 1))
2347 ;; See if this one should be the default.
2348 (and (null default)
2349 (<= (match-beginning 0) start-point)
2350 (<= start-point (point))
2351 (setq default t))
2352 ;; See if this one should be the alternate default.
2353 (and (null alt-default)
2354 (and (<= bol (match-beginning 0))
2355 (<= (point) eol))
2356 (setq alt-default t))
2357 (setq i 0)
2358 (while (setq i (string-match "[ \n\t]+" str i))
2359 (setq str (concat (substring str 0 i) " "
2360 (substring str (match-end 0))))
2361 (setq i (1+ i)))
2362 ;; Record as a completion and perhaps as default.
2363 (if (eq default t) (setq default str))
2364 (if (eq alt-default t) (setq alt-default str))
2365 ;; Don't add this string if it's a duplicate.
2366 (or (assoc-string str completions t)
2367 (push str completions))))
2368 ;; If no good default was found, try an alternate.
2369 (or default
2370 (setq default alt-default))
2371 ;; If only one cross-reference found, then make it default.
2372 (if (eq (length completions) 1)
2373 (setq default (car completions)))
2374 (if completions
2375 (let ((input (completing-read (if default
2376 (concat
2377 "Follow reference named (default "
2378 default "): ")
2379 "Follow reference named: ")
2380 completions nil t)))
2381 (list (if (equal input "")
2382 default input) current-prefix-arg))
2383 (error "No cross-references in this node"))))
2384
2385 (unless footnotename
2386 (error "No reference was specified"))
2387
2388 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
2389 (case-fold-search t))
2390 (while (setq i (string-match " " str i))
2391 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
2392 (setq i (+ i 6)))
2393 (save-excursion
2394 ;; Move point to the beginning of reference if point is on reference
2395 (or (looking-at "\\*note[ \n\t]+")
2396 (and (looking-back "\\*note[ \n\t]+")
2397 (goto-char (match-beginning 0)))
2398 (if (and (save-excursion
2399 (goto-char (+ (point) 5)) ; skip a possible *note
2400 (re-search-backward "\\*note[ \n\t]+" nil t)
2401 (looking-at str))
2402 (<= (point) (match-end 0)))
2403 (goto-char (match-beginning 0))))
2404 ;; Go to the reference closest to point
2405 (let ((next-ref (save-excursion (and (re-search-forward str nil t)
2406 (+ (match-beginning 0) 5))))
2407 (prev-ref (save-excursion (and (re-search-backward str nil t)
2408 (+ (match-beginning 0) 5)))))
2409 (goto-char (cond ((and next-ref prev-ref)
2410 (if (< (abs (- next-ref (point)))
2411 (abs (- prev-ref (point))))
2412 next-ref prev-ref))
2413 ((or next-ref prev-ref))
2414 ((error "No cross-reference named %s" footnotename))))
2415 (setq target (Info-extract-menu-node-name t))))
2416 (while (setq i (string-match "[ \t\n]+" target i))
2417 (setq target (concat (substring target 0 i) " "
2418 (substring target (match-end 0))))
2419 (setq i (+ i 1)))
2420 (Info-goto-node target fork)))
2421
2422 (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2423 ;; We allow newline because this is also used in Info-follow-reference,
2424 ;; where the xref name might be wrapped over two lines.
2425 "Regexp that matches a menu entry name upto but not including the colon.
2426 Because of ambiguities, this should be concatenated with something like
2427 `:' and `Info-following-node-name-re'.")
2428
2429 (defun Info-extract-menu-node-name (&optional multi-line index-node)
2430 (skip-chars-forward " \t\n")
2431 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
2432 (Info-following-node-name-re
2433 (cond
2434 (index-node "^,\t\n")
2435 (multi-line "^.,\t")
2436 (t "^.,\t\n")))
2437 "\\)"
2438 (if index-node
2439 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2440 "")))
2441 (if index-node
2442 (setq Info-point-loc
2443 (if (match-beginning 5)
2444 (string-to-number (match-string 5))
2445 (buffer-substring-no-properties
2446 (match-beginning 0) (1- (match-beginning 1)))))
2447 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2448 ;;; (setq Info-point-loc
2449 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2450 )
2451 (replace-regexp-in-string
2452 "[ \n]+" " "
2453 (or (and (not (equal (match-string-no-properties 2) ""))
2454 (match-string-no-properties 2))
2455 ;; If the node name is the menu entry name (using `entry::').
2456 (buffer-substring-no-properties
2457 (match-beginning 0) (1- (match-beginning 1)))))))
2458
2459 ;; No one calls this.
2460 ;;(defun Info-menu-item-sequence (list)
2461 ;; (while list
2462 ;; (Info-menu (car list))
2463 ;; (setq list (cdr list))))
2464
2465 (defvar Info-complete-menu-buffer)
2466 (defvar Info-complete-next-re nil)
2467 (defvar Info-complete-nodes nil)
2468 (defvar Info-complete-cache nil)
2469
2470 (defconst Info-node-spec-re
2471 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2472 "Regexp to match the text after a : until the terminating `.'.")
2473
2474 (defun Info-complete-menu-item (string predicate action)
2475 ;; This uses two dynamically bound variables:
2476 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2477 ;; is the menu of items we're trying to complete.
2478 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2479 ;; also look for menu items in subsequent nodes as long as those
2480 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2481 ;; not used.
2482 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2483 ;; also look for menu items in these nodes. This feature is currently
2484 ;; only used for completion in Info-index.
2485
2486 ;; Note that `Info-complete-menu-buffer' could be current already,
2487 ;; so we want to save point.
2488 (with-current-buffer Info-complete-menu-buffer
2489 (save-excursion
2490 (let ((completion-ignore-case t)
2491 (case-fold-search t)
2492 (orignode Info-current-node)
2493 nextnode)
2494 (goto-char (point-min))
2495 (search-forward "\n* Menu:")
2496 (cond
2497 ((eq (car-safe action) 'boundaries) nil)
2498 ((eq action 'lambda)
2499 (re-search-forward
2500 (concat "\n\\* +" (regexp-quote string) ":") nil t))
2501 (t
2502 (let ((pattern (concat "\n\\* +\\("
2503 (regexp-quote string)
2504 Info-menu-entry-name-re "\\):"
2505 Info-node-spec-re))
2506 completions
2507 (complete-nodes Info-complete-nodes))
2508 ;; Check the cache.
2509 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
2510 (equal (nth 1 Info-complete-cache) Info-current-node)
2511 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
2512 (equal (nth 5 Info-complete-cache) Info-complete-nodes)
2513 (let ((prev (nth 3 Info-complete-cache)))
2514 (eq t (compare-strings string 0 (length prev)
2515 prev 0 nil t))))
2516 ;; We can reuse the previous list.
2517 (setq completions (nth 4 Info-complete-cache))
2518 ;; The cache can't be used.
2519 (while
2520 (progn
2521 (while (re-search-forward pattern nil t)
2522 (push (match-string-no-properties 1)
2523 completions))
2524 ;; Check subsequent nodes if applicable.
2525 (or (and Info-complete-next-re
2526 (setq nextnode (Info-extract-pointer "next" t))
2527 (string-match Info-complete-next-re nextnode))
2528 (and complete-nodes
2529 (setq complete-nodes (cdr complete-nodes)
2530 nextnode (car complete-nodes)))))
2531 (Info-goto-node nextnode))
2532 ;; Go back to the start node (for the next completion).
2533 (unless (equal Info-current-node orignode)
2534 (Info-goto-node orignode))
2535 ;; Update the cache.
2536 (set (make-local-variable 'Info-complete-cache)
2537 (list Info-current-file Info-current-node
2538 Info-complete-next-re string completions
2539 Info-complete-nodes)))
2540 (complete-with-action action completions string predicate))))))))
2541
2542
2543 (defun Info-menu (menu-item &optional fork)
2544 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2545 The menu item should one of those listed in the current node's menu.
2546 Completion is allowed, and the default menu item is the one point is on.
2547 If FORK is non-nil (interactively with a prefix arg), show the node in
2548 a new Info buffer. If FORK is a string, it is the name to use for the
2549 new buffer."
2550 (interactive
2551 (let (;; If point is within a menu item, use that item as the default
2552 (default nil)
2553 (p (point))
2554 beg
2555 (case-fold-search t))
2556 (save-excursion
2557 (goto-char (point-min))
2558 (if (not (search-forward "\n* menu:" nil t))
2559 (error "No menu in this node"))
2560 (setq beg (point))
2561 (and (< (point) p)
2562 (save-excursion
2563 (goto-char p)
2564 (end-of-line)
2565 (if (re-search-backward (concat "\n\\* +\\("
2566 Info-menu-entry-name-re
2567 "\\):") beg t)
2568 (setq default (match-string-no-properties 1))))))
2569 (let ((item nil))
2570 (while (null item)
2571 (setq item (let ((completion-ignore-case t)
2572 (Info-complete-menu-buffer (current-buffer)))
2573 (completing-read (if default
2574 (format "Menu item (default %s): "
2575 default)
2576 "Menu item: ")
2577 'Info-complete-menu-item nil t)))
2578 ;; we rely on the fact that completing-read accepts an input
2579 ;; of "" even when the require-match argument is true and ""
2580 ;; is not a valid possibility
2581 (if (string= item "")
2582 (if default
2583 (setq item default)
2584 ;; ask again
2585 (setq item nil))))
2586 (list item current-prefix-arg))))
2587 ;; there is a problem here in that if several menu items have the same
2588 ;; name you can only go to the node of the first with this command.
2589 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
2590
2591 (defun Info-extract-menu-item (menu-item)
2592 (setq menu-item (regexp-quote menu-item))
2593 (let ((case-fold-search t))
2594 (save-excursion
2595 (let ((case-fold-search t))
2596 (goto-char (point-min))
2597 (or (search-forward "\n* menu:" nil t)
2598 (error "No menu in this node"))
2599 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
2600 (re-search-forward (concat "\n\\* +" menu-item) nil t)
2601 (error "No such item in menu"))
2602 (beginning-of-line)
2603 (forward-char 2)
2604 (Info-extract-menu-node-name nil (Info-index-node))))))
2605
2606 ;; If COUNT is nil, use the last item in the menu.
2607 (defun Info-extract-menu-counting (count &optional no-detail)
2608 (let ((case-fold-search t))
2609 (save-excursion
2610 (let ((case-fold-search t)
2611 (bound (when (and no-detail
2612 (re-search-forward
2613 "^[ \t-]*The Detailed Node Listing" nil t))
2614 (match-beginning 0))))
2615 (goto-char (point-min))
2616 (or (search-forward "\n* menu:" bound t)
2617 (error "No menu in this node"))
2618 (if count
2619 (or (search-forward "\n* " bound t count)
2620 (error "Too few items in menu"))
2621 (while (search-forward "\n* " bound t)
2622 nil))
2623 (Info-extract-menu-node-name nil (Info-index-node))))))
2624
2625 (defun Info-nth-menu-item ()
2626 "Go to the node of the Nth menu item.
2627 N is the digit argument used to invoke this command."
2628 (interactive)
2629 (Info-goto-node
2630 (Info-extract-menu-counting
2631 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
2632
2633 (defun Info-top-node ()
2634 "Go to the Top node of this file."
2635 (interactive)
2636 (Info-goto-node "Top"))
2637
2638 (defun Info-final-node ()
2639 "Go to the final node in this file."
2640 (interactive)
2641 (Info-goto-node "Top")
2642 (let ((Info-history nil)
2643 (case-fold-search t))
2644 ;; Go to the last node in the menu of Top. But don't delve into
2645 ;; detailed node listings.
2646 (Info-goto-node (Info-extract-menu-counting nil t))
2647 ;; If the last node in the menu is not last in pointer structure,
2648 ;; move forward (but not down- or upward - see bug#1116) until we
2649 ;; can't go any farther.
2650 (while (Info-forward-node t t t) nil)
2651 ;; Then keep moving down to last subnode, unless we reach an index.
2652 (while (and (not (Info-index-node))
2653 (save-excursion (search-forward "\n* Menu:" nil t)))
2654 (Info-goto-node (Info-extract-menu-counting nil)))))
2655
2656 (defun Info-forward-node (&optional not-down not-up no-error)
2657 "Go forward one node, considering all nodes as forming one sequence."
2658 (interactive)
2659 (goto-char (point-min))
2660 (forward-line 1)
2661 (let ((case-fold-search t))
2662 ;; three possibilities, in order of priority:
2663 ;; 1. next node is in a menu in this node (but not in an index)
2664 ;; 2. next node is next at same level
2665 ;; 3. next node is up and next
2666 (cond ((and (not not-down)
2667 (save-excursion (search-forward "\n* menu:" nil t))
2668 (not (Info-index-node)))
2669 (Info-goto-node (Info-extract-menu-counting 1))
2670 t)
2671 ((save-excursion (search-backward "next:" nil t))
2672 (Info-next)
2673 t)
2674 ((and (not not-up)
2675 (save-excursion (search-backward "up:" nil t))
2676 ;; Use string-equal, not equal, to ignore text props.
2677 (not (string-equal (downcase (Info-extract-pointer "up"))
2678 "top")))
2679 (let ((old-node Info-current-node))
2680 (Info-up)
2681 (let ((old-history Info-history)
2682 success)
2683 (unwind-protect
2684 (setq success (Info-forward-node t nil no-error))
2685 (or success (Info-goto-node old-node)))
2686 (if Info-history-skip-intermediate-nodes
2687 (setq Info-history old-history)))))
2688 (no-error nil)
2689 (t (error "No pointer forward from this node")))))
2690
2691 (defun Info-backward-node ()
2692 "Go backward one node, considering all nodes as forming one sequence."
2693 (interactive)
2694 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
2695 (upnode (Info-extract-pointer "up" t))
2696 (case-fold-search t))
2697 (cond ((and upnode (string-match "(" upnode))
2698 (error "First node in file"))
2699 ((and upnode (or (null prevnode)
2700 ;; Use string-equal, not equal,
2701 ;; to ignore text properties.
2702 (string-equal (downcase prevnode)
2703 (downcase upnode))))
2704 (Info-up))
2705 (prevnode
2706 ;; If we move back at the same level,
2707 ;; go down to find the last subnode*.
2708 (Info-prev)
2709 (let ((old-history Info-history))
2710 (while (and (not (Info-index-node))
2711 (save-excursion (search-forward "\n* Menu:" nil t)))
2712 (Info-goto-node (Info-extract-menu-counting nil)))
2713 (if Info-history-skip-intermediate-nodes
2714 (setq Info-history old-history))))
2715 (t
2716 (error "No pointer backward from this node")))))
2717
2718 (defun Info-exit ()
2719 "Exit Info by selecting some other buffer."
2720 (interactive)
2721 (if Info-standalone
2722 (save-buffers-kill-emacs)
2723 (quit-window)))
2724
2725 (defun Info-next-menu-item ()
2726 "Go to the node of the next menu item."
2727 (interactive)
2728 ;; Bind this in case the user sets it to nil.
2729 (let* ((case-fold-search t)
2730 (node
2731 (save-excursion
2732 (forward-line -1)
2733 (search-forward "\n* menu:" nil t)
2734 (and (search-forward "\n* " nil t)
2735 (Info-extract-menu-node-name)))))
2736 (if node (Info-goto-node node)
2737 (error "No more items in menu"))))
2738
2739 (defun Info-last-menu-item ()
2740 "Go to the node of the previous menu item."
2741 (interactive)
2742 (save-excursion
2743 (forward-line 1)
2744 ;; Bind this in case the user sets it to nil.
2745 (let* ((case-fold-search t)
2746 (beg (save-excursion
2747 (and (search-backward "\n* menu:" nil t)
2748 (point)))))
2749 (or (and beg (search-backward "\n* " beg t))
2750 (error "No previous items in menu")))
2751 (Info-goto-node (save-excursion
2752 (goto-char (match-end 0))
2753 (Info-extract-menu-node-name)))))
2754
2755 (defmacro Info-no-error (&rest body)
2756 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
2757
2758 (defun Info-next-preorder ()
2759 "Go to the next subnode or the next node, or go up a level."
2760 (interactive)
2761 (cond ((Info-no-error (Info-next-menu-item)))
2762 ((Info-no-error (Info-next)))
2763 ((Info-no-error (Info-up t))
2764 ;; Since we have already gone thru all the items in this menu,
2765 ;; go up to the end of this node.
2766 (goto-char (point-max))
2767 ;; Since logically we are done with the node with that menu,
2768 ;; move on from it. But don't add intermediate nodes
2769 ;; to the history on recursive calls.
2770 (let ((old-history Info-history))
2771 (Info-next-preorder)
2772 (if Info-history-skip-intermediate-nodes
2773 (setq Info-history old-history))))
2774 (t
2775 (error "No more nodes"))))
2776
2777 (defun Info-last-preorder ()
2778 "Go to the last node, popping up a level if there is none."
2779 (interactive)
2780 (cond ((and Info-scroll-prefer-subnodes
2781 (Info-no-error
2782 (Info-last-menu-item)
2783 ;; If we go down a menu item, go to the end of the node
2784 ;; so we can scroll back through it.
2785 (goto-char (point-max))))
2786 ;; Keep going down, as long as there are nested menu nodes.
2787 (let ((old-history Info-history))
2788 (while (Info-no-error
2789 (Info-last-menu-item)
2790 ;; If we go down a menu item, go to the end of the node
2791 ;; so we can scroll back through it.
2792 (goto-char (point-max))))
2793 (if Info-history-skip-intermediate-nodes
2794 (setq Info-history old-history)))
2795 (recenter -1))
2796 ((and (Info-no-error (Info-extract-pointer "prev"))
2797 (not (equal (Info-extract-pointer "up")
2798 (Info-extract-pointer "prev"))))
2799 (Info-no-error (Info-prev))
2800 (goto-char (point-max))
2801 (let ((old-history Info-history))
2802 (while (Info-no-error
2803 (Info-last-menu-item)
2804 ;; If we go down a menu item, go to the end of the node
2805 ;; so we can scroll back through it.
2806 (goto-char (point-max))))
2807 (if Info-history-skip-intermediate-nodes
2808 (setq Info-history old-history)))
2809 (recenter -1))
2810 ((Info-no-error (Info-up t))
2811 (goto-char (point-min))
2812 (let ((case-fold-search t))
2813 (or (search-forward "\n* Menu:" nil t)
2814 (goto-char (point-max)))))
2815 (t (error "No previous nodes"))))
2816
2817 (defun Info-scroll-up ()
2818 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2819 Once you scroll far enough in a node that its menu appears on the screen
2820 but after point, the next scroll moves into its first subnode, unless
2821 `Info-scroll-prefer-subnodes' is nil.
2822
2823 When you scroll past the end of a node, that goes to the next node if
2824 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2825 if this node has no successor, it moves to the parent node's successor,
2826 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2827 the menu of a node, it moves to subnode indicated by the following menu
2828 item. (That case won't normally result from this command, but can happen
2829 in other ways.)"
2830
2831 (interactive)
2832 (if (or (< (window-start) (point-min))
2833 (> (window-start) (point-max)))
2834 (set-window-start (selected-window) (point)))
2835 (let* ((case-fold-search t)
2836 (virtual-end (save-excursion
2837 (goto-char (point-min))
2838 (if (and Info-scroll-prefer-subnodes
2839 (search-forward "\n* Menu:" nil t))
2840 (point)
2841 (point-max)))))
2842 (if (or (< virtual-end (window-start))
2843 (pos-visible-in-window-p virtual-end))
2844 (cond
2845 (Info-scroll-prefer-subnodes (Info-next-preorder))
2846 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2847 (t (Info-next-preorder)))
2848 (scroll-up))))
2849
2850 (defun Info-mouse-scroll-up (e)
2851 "Scroll one screenful forward in Info, using the mouse.
2852 See `Info-scroll-up'."
2853 (interactive "e")
2854 (save-selected-window
2855 (if (eventp e)
2856 (select-window (posn-window (event-start e))))
2857 (Info-scroll-up)))
2858
2859 (defun Info-scroll-down ()
2860 "Scroll one screenful back in Info, considering all nodes as one sequence.
2861 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2862 is non-nil, this goes to its last subnode. When you scroll past the
2863 beginning of a node, that goes to the previous node or back up to the
2864 parent node."
2865 (interactive)
2866 (if (or (< (window-start) (point-min))
2867 (> (window-start) (point-max)))
2868 (set-window-start (selected-window) (point)))
2869 (let* ((case-fold-search t)
2870 (current-point (point))
2871 (virtual-end
2872 (and Info-scroll-prefer-subnodes
2873 (save-excursion
2874 (setq current-point (line-beginning-position))
2875 (goto-char (point-min))
2876 (search-forward "\n* Menu:" current-point t)))))
2877 (if (or virtual-end
2878 (pos-visible-in-window-p (point-min) nil t))
2879 (Info-last-preorder)
2880 (scroll-down))))
2881
2882 (defun Info-mouse-scroll-down (e)
2883 "Scroll one screenful backward in Info, using the mouse.
2884 See `Info-scroll-down'."
2885 (interactive "e")
2886 (save-selected-window
2887 (if (eventp e)
2888 (select-window (posn-window (event-start e))))
2889 (Info-scroll-down)))
2890
2891 (defun Info-next-reference (&optional recur)
2892 "Move cursor to the next cross-reference or menu item in the node."
2893 (interactive)
2894 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2895 (old-pt (point))
2896 (case-fold-search t))
2897 (or (eobp) (forward-char 1))
2898 (or (re-search-forward pat nil t)
2899 (progn
2900 (goto-char (point-min))
2901 (or (re-search-forward pat nil t)
2902 (progn
2903 (goto-char old-pt)
2904 (error "No cross references in this node")))))
2905 (goto-char (or (match-beginning 1) (match-beginning 0)))
2906 (if (looking-at "\\* Menu:")
2907 (if recur
2908 (error "No cross references in this node")
2909 (Info-next-reference t))
2910 (if (looking-at "^\\* ")
2911 (forward-char 2)))))
2912
2913 (defun Info-prev-reference (&optional recur)
2914 "Move cursor to the previous cross-reference or menu item in the node."
2915 (interactive)
2916 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2917 (old-pt (point))
2918 (case-fold-search t))
2919 (or (re-search-backward pat nil t)
2920 (progn
2921 (goto-char (point-max))
2922 (or (re-search-backward pat nil t)
2923 (progn
2924 (goto-char old-pt)
2925 (error "No cross references in this node")))))
2926 (goto-char (or (match-beginning 1) (match-beginning 0)))
2927 (if (looking-at "\\* Menu:")
2928 (if recur
2929 (error "No cross references in this node")
2930 (Info-prev-reference t))
2931 (if (looking-at "^\\* ")
2932 (forward-char 2)))))
2933 \f
2934 (defvar Info-index-nodes nil
2935 "Alist of cached index node names of visited Info files.
2936 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2937
2938 (defun Info-index-nodes (&optional file)
2939 "Return a list of names of all index nodes in Info FILE.
2940 If FILE is omitted, it defaults to the current Info file.
2941 First look in a list of cached index node names. Then scan Info
2942 file and its subfiles for nodes with the index cookie. Then try
2943 to find index nodes starting from the first node in the top level
2944 menu whose name contains the word \"Index\", plus any immediately
2945 following nodes whose names also contain the word \"Index\"."
2946 (or file (setq file Info-current-file))
2947 (or (assoc file Info-index-nodes)
2948 ;; Skip virtual Info files
2949 (and (or (not (stringp file))
2950 (Info-virtual-file-p file))
2951 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
2952 (if (Info-file-supports-index-cookies file)
2953 ;; Find nodes with index cookie
2954 (let* ((default-directory (or (and (stringp file)
2955 (file-name-directory
2956 (setq file (Info-find-file file))))
2957 default-directory))
2958 Info-history Info-history-list Info-fontify-maximum-menu-size
2959 (main-file file) subfiles nodes)
2960 (condition-case nil
2961 (with-temp-buffer
2962 (while (or main-file subfiles)
2963 (erase-buffer)
2964 (info-insert-file-contents (or main-file (car subfiles)))
2965 (goto-char (point-min))
2966 (while (search-forward "\0\b[index\0\b]" nil 'move)
2967 (save-excursion
2968 (re-search-backward "^\^_")
2969 (search-forward "Node: ")
2970 (setq nodes (cons (Info-following-node-name) nodes))))
2971 (if main-file
2972 (save-excursion
2973 (goto-char (point-min))
2974 (if (search-forward "\n\^_\nIndirect:" nil t)
2975 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2976 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2977 (setq subfiles (cons (match-string-no-properties 1)
2978 subfiles)))))
2979 (setq subfiles (nreverse subfiles)
2980 main-file nil))
2981 (setq subfiles (cdr subfiles)))))
2982 (error nil))
2983 (if nodes
2984 (setq nodes (nreverse nodes)
2985 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2986 nodes)
2987 ;; Else find nodes with the word "Index" in the node name
2988 (let ((case-fold-search t)
2989 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
2990 nodes node)
2991 (condition-case nil
2992 (with-temp-buffer
2993 (Info-mode)
2994 (Info-find-node file "Top")
2995 (when (and (search-forward "\n* menu:" nil t)
2996 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2997 (goto-char (match-beginning 1))
2998 (setq nodes (list (Info-extract-menu-node-name)))
2999 (Info-goto-node (car nodes))
3000 (while (and (setq node (Info-extract-pointer "next" t))
3001 (string-match "\\<Index\\>" node))
3002 (push node nodes)
3003 (Info-goto-node node))))
3004 (error nil))
3005 (if nodes
3006 (setq nodes (nreverse nodes)
3007 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
3008 nodes))
3009 ;; If file has no index nodes, still add it to the cache
3010 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
3011 (cdr (assoc file Info-index-nodes)))
3012
3013 (defun Info-index-node (&optional node file)
3014 "Return non-nil value if NODE is an index node.
3015 If NODE is nil, check the current Info node.
3016 If FILE is nil, check the current Info file."
3017 (or file (setq file Info-current-file))
3018 (if (and (or (and node (not (equal node Info-current-node)))
3019 (assoc file Info-index-nodes))
3020 (not Info-current-node-virtual))
3021 (member (or node Info-current-node) (Info-index-nodes file))
3022 ;; Don't search all index nodes if request is only for the current node
3023 ;; and file is not in the cache of index nodes
3024 (save-match-data
3025 (if (Info-file-supports-index-cookies file)
3026 (save-excursion
3027 (goto-char (+ (or (save-excursion
3028 (search-backward "\n\^_" nil t))
3029 (point-min)) 2))
3030 (search-forward "\0\b[index\0\b]"
3031 (or (save-excursion
3032 (search-forward "\n\^_" nil t))
3033 (point-max)) t))
3034 (string-match "\\<Index\\>" (or node Info-current-node ""))))))
3035
3036 (defun Info-goto-index ()
3037 "Go to the first index node."
3038 (let ((node (car (Info-index-nodes))))
3039 (or node (error "No index"))
3040 (Info-goto-node node)))
3041
3042 ;;;###autoload
3043 (defun Info-index (topic)
3044 "Look up a string TOPIC in the index for this manual and go to that entry.
3045 If there are no exact matches to the specified topic, this chooses
3046 the first match which is a case-insensitive substring of a topic.
3047 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3048 Give an empty topic name to go to the Index node itself."
3049 (interactive
3050 (list
3051 (let ((completion-ignore-case t)
3052 (Info-complete-menu-buffer (clone-buffer))
3053 (Info-complete-nodes (Info-index-nodes))
3054 (Info-history-list nil))
3055 (if (equal Info-current-file "dir")
3056 (error "The Info directory node has no index; use m to select a manual"))
3057 (unwind-protect
3058 (with-current-buffer Info-complete-menu-buffer
3059 (Info-goto-index)
3060 (completing-read "Index topic: " 'Info-complete-menu-item))
3061 (kill-buffer Info-complete-menu-buffer)))))
3062 (if (equal Info-current-file "dir")
3063 (error "The Info directory node has no index; use m to select a manual"))
3064 ;; Strip leading colon in topic; index format does not allow them.
3065 (if (and (stringp topic)
3066 (> (length topic) 0)
3067 (= (aref topic 0) ?:))
3068 (setq topic (substring topic 1)))
3069 (let ((orignode Info-current-node)
3070 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3071 (regexp-quote topic)))
3072 node (nodes (Info-index-nodes))
3073 (ohist-list Info-history-list)
3074 (case-fold-search t))
3075 (Info-goto-index)
3076 (or (equal topic "")
3077 (let ((matches nil)
3078 (exact nil)
3079 ;; We bind Info-history to nil for internal node-switches so
3080 ;; that we don't put junk in the history. In the first
3081 ;; Info-goto-index call, above, we do update the history
3082 ;; because that is what the user's previous node choice into it.
3083 (Info-history nil)
3084 found)
3085 (while
3086 (progn
3087 (goto-char (point-min))
3088 (while (re-search-forward pattern nil t)
3089 (push (list (match-string-no-properties 1)
3090 (match-string-no-properties 2)
3091 Info-current-node
3092 (string-to-number (concat "0"
3093 (match-string 3))))
3094 matches))
3095 (setq nodes (cdr nodes) node (car nodes)))
3096 (Info-goto-node node))
3097 (or matches
3098 (progn
3099 (Info-goto-node orignode)
3100 (error "No `%s' in index" topic)))
3101 ;; Here it is a feature that assoc is case-sensitive.
3102 (while (setq found (assoc topic matches))
3103 (setq exact (cons found exact)
3104 matches (delq found matches)))
3105 (setq Info-history-list ohist-list)
3106 (setq Info-index-alternatives (nconc exact (nreverse matches)))
3107 (Info-index-next 0)))))
3108
3109 (defun Info-index-next (num)
3110 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3111 (interactive "p")
3112 (or Info-index-alternatives
3113 (error "No previous `i' command"))
3114 (while (< num 0)
3115 (setq num (+ num (length Info-index-alternatives))))
3116 (while (> num 0)
3117 (setq Info-index-alternatives
3118 (nconc (cdr Info-index-alternatives)
3119 (list (car Info-index-alternatives)))
3120 num (1- num)))
3121 (Info-goto-node (nth 1 (car Info-index-alternatives)))
3122 (if (> (nth 3 (car Info-index-alternatives)) 0)
3123 ;; Forward 2 lines less because `Info-find-node-2' initially
3124 ;; puts point to the 2nd line.
3125 (forward-line (- (nth 3 (car Info-index-alternatives)) 2))
3126 (forward-line 3) ; don't search in headers
3127 (let ((name (car (car Info-index-alternatives))))
3128 (Info-find-index-name name)))
3129 (message "Found `%s' in %s. %s"
3130 (car (car Info-index-alternatives))
3131 (nth 2 (car Info-index-alternatives))
3132 (if (cdr Info-index-alternatives)
3133 (format "(%s total; use `%s' for next)"
3134 (length Info-index-alternatives)
3135 (key-description (where-is-internal
3136 'Info-index-next overriding-local-map
3137 t)))
3138 "(Only match)")))
3139
3140 (defun Info-find-index-name (name)
3141 "Move point to the place within the current node where NAME is defined."
3142 (let ((case-fold-search t))
3143 (if (or (re-search-forward (format
3144 "[a-zA-Z]+: %s\\( \\|$\\)"
3145 (regexp-quote name)) nil t)
3146 ;; Find a function definition with a return type.
3147 (re-search-forward (format
3148 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3149 (regexp-quote name)) nil t)
3150 (search-forward (format "`%s'" name) nil t)
3151 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
3152 (search-forward
3153 (format "`%s'" (substring name 0 (match-beginning 1)))
3154 nil t))
3155 (search-forward name nil t)
3156 ;; Try again without the " <1>" makeinfo can append
3157 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
3158 (Info-find-index-name (match-string 1 name))))
3159 (progn (beginning-of-line) t) ;; non-nil for recursive call
3160 (goto-char (point-min)))))
3161 \f
3162 (add-to-list 'Info-virtual-nodes
3163 '("\\`\\*Index.*\\*\\'"
3164 (find-node . Info-virtual-index-find-node)
3165 (slow . t)
3166 ))
3167
3168 (defvar Info-virtual-index-nodes nil
3169 "Alist of cached matched index search nodes.
3170 Each element is ((FILENAME . TOPIC) MATCHES) where
3171 FILENAME is the file name of the manual,
3172 TOPIC is the search string given as an argument to `Info-virtual-index',
3173 MATCHES is a list of index matches found by `Info-index'.")
3174
3175 (defun Info-virtual-index-find-node (filename nodename &optional _no-going-back)
3176 "Index-specific implementation of `Info-find-node-2'."
3177 ;; Generate Index-like menu of matches
3178 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename)
3179 ;; Generate Index-like menu of matches
3180 (let* ((topic (match-string 1 nodename))
3181 (matches (cdr (assoc (cons (or filename Info-current-file) topic)
3182 Info-virtual-index-nodes))))
3183 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3184 (or filename Info-current-file) nodename))
3185 (insert "Info Virtual Index\n")
3186 (insert "******************\n\n")
3187 (insert "Index entries that match `" topic "':\n\n")
3188 (insert "\0\b[index\0\b]\n")
3189 (if (null matches)
3190 (insert "No matches found.\n")
3191 (insert "* Menu:\n\n")
3192 (dolist (entry matches)
3193 (insert (format "* %-38s %s.%s\n"
3194 (format "%s [%s]:" (nth 0 entry) (nth 2 entry))
3195 (nth 1 entry)
3196 (if (nth 3 entry)
3197 (format " (line %s)" (nth 3 entry))
3198 ""))))))
3199 ;; Else, Generate a list of previous search results
3200 (let ((nodes (reverse Info-virtual-index-nodes)))
3201 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3202 (or filename Info-current-file) nodename))
3203 (insert "Info Virtual Index\n")
3204 (insert "******************\n\n")
3205 (insert "This is a list of search results produced by\n"
3206 "`Info-virtual-index' for the current manual.\n\n")
3207 (insert "* Menu:\n\n")
3208 (dolist (nodeinfo nodes)
3209 (when (equal (car (nth 0 nodeinfo)) (or filename Info-current-file))
3210 (insert
3211 (format "* %-20s %s.\n"
3212 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo)))
3213 (cdr (nth 0 nodeinfo)))))))))
3214
3215 (defun Info-virtual-index (topic)
3216 "Show a node with all lines in the index containing a string TOPIC.
3217 Like `Info-index' but displays a node with index search results.
3218 Give an empty topic name to go to the node with links to previous
3219 search results."
3220 ;; `interactive' is a copy from `Info-index'
3221 (interactive
3222 (list
3223 (let ((completion-ignore-case t)
3224 (Info-complete-menu-buffer (clone-buffer))
3225 (Info-complete-nodes (Info-index-nodes))
3226 (Info-history-list nil))
3227 (if (equal Info-current-file "dir")
3228 (error "The Info directory node has no index; use m to select a manual"))
3229 (unwind-protect
3230 (with-current-buffer Info-complete-menu-buffer
3231 (Info-goto-index)
3232 (completing-read "Index topic: " 'Info-complete-menu-item))
3233 (kill-buffer Info-complete-menu-buffer)))))
3234 (if (equal topic "")
3235 (Info-find-node Info-current-file "*Index*")
3236 (unless (assoc (cons Info-current-file topic) Info-virtual-index-nodes)
3237 (let ((orignode Info-current-node)
3238 (ohist-list Info-history-list))
3239 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3240 (Info-index topic)
3241 (push (cons (cons Info-current-file topic) Info-index-alternatives)
3242 Info-virtual-index-nodes)
3243 ;; Clean up unnecessary side-effects of `Info-index'.
3244 (setq Info-history-list ohist-list)
3245 (Info-goto-node orignode)
3246 (message "")))
3247 (Info-find-node Info-current-file (format "*Index for `%s'*" topic))))
3248 \f
3249 (add-to-list 'Info-virtual-files
3250 '("\\`\\*Apropos\\*\\'"
3251 (toc-nodes . Info-apropos-toc-nodes)
3252 (find-file . Info-apropos-find-file)
3253 (find-node . Info-apropos-find-node)
3254 (slow . t)
3255 ))
3256
3257 (defvar Info-apropos-file "*Apropos*"
3258 "Info file name of the virtual manual for matches of `info-apropos'.")
3259
3260 (defvar Info-apropos-nodes nil
3261 "Alist of cached apropos matched nodes.
3262 Each element is (NODENAME STRING MATCHES) where
3263 NODENAME is the name of the node that holds the search result,
3264 STRING is the search string given as an argument to `info-apropos',
3265 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3266
3267 (defun Info-apropos-toc-nodes (filename)
3268 "Apropos-specific implementation of `Info-toc-nodes'."
3269 (let ((nodes (mapcar 'car (reverse Info-apropos-nodes))))
3270 `(,filename
3271 ("Top" nil nil ,nodes)
3272 ,@(mapcar (lambda (node) `(,node "Top" nil nil)) nodes))))
3273
3274 (defun Info-apropos-find-file (filename &optional _noerror)
3275 "Apropos-specific implementation of `Info-find-file'."
3276 filename)
3277
3278 (defun Info-apropos-find-node (_filename nodename &optional _no-going-back)
3279 "Apropos-specific implementation of `Info-find-node-2'."
3280 (if (equal nodename "Top")
3281 ;; Generate Top menu
3282 (let ((nodes (reverse Info-apropos-nodes)))
3283 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3284 Info-apropos-file nodename))
3285 (insert "Apropos Index\n")
3286 (insert "*************\n\n")
3287 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3288 (insert "* Menu:\n\n")
3289 (dolist (nodeinfo nodes)
3290 (insert (format "* %-20s %s.\n"
3291 (format "%s::" (nth 0 nodeinfo))
3292 (nth 1 nodeinfo)))))
3293 ;; Else, Generate Index-like menu of matches
3294 (let* ((nodeinfo (assoc nodename Info-apropos-nodes))
3295 (matches (nth 2 nodeinfo)))
3296 (when matches
3297 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3298 Info-apropos-file nodename))
3299 (insert "Apropos Index\n")
3300 (insert "*************\n\n")
3301 (insert "Index entries that match `" (nth 1 nodeinfo) "':\n\n")
3302 (insert "\0\b[index\0\b]\n")
3303 (if (eq matches t)
3304 (insert "No matches found.\n")
3305 (insert "* Menu:\n\n")
3306 (dolist (entry matches)
3307 (insert (format "* %-38s (%s)%s.%s\n"
3308 (format "%s [%s]:" (nth 1 entry) (nth 0 entry))
3309 (nth 0 entry)
3310 (nth 2 entry)
3311 (if (nth 3 entry)
3312 (format " (line %s)" (nth 3 entry))
3313 "")))))))))
3314
3315 (defun Info-apropos-matches (string)
3316 "Collect STRING matches from all known Info files on your system.
3317 Return a list of matches where each element is in the format
3318 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3319 (unless (string= string "")
3320 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3321 (regexp-quote string)))
3322 (ohist Info-history)
3323 (ohist-list Info-history-list)
3324 (current-node Info-current-node)
3325 (current-file Info-current-file)
3326 manuals matches node nodes)
3327 (let ((Info-fontify-maximum-menu-size nil))
3328 (Info-directory)
3329 ;; current-node and current-file are nil when they invoke info-apropos
3330 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3331 ;; case, we use (DIR)Top instead, to avoid signaling an error after
3332 ;; the search is complete.
3333 (when (null current-node)
3334 (setq current-file Info-current-file)
3335 (setq current-node Info-current-node))
3336 (message "Searching indices...")
3337 (goto-char (point-min))
3338 (re-search-forward "\\* Menu: *\n" nil t)
3339 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
3340 ;; add-to-list makes sure we don't have duplicates in `manuals',
3341 ;; so that the following dolist loop runs faster.
3342 (add-to-list 'manuals (match-string 1)))
3343 (dolist (manual (nreverse manuals))
3344 (message "Searching %s" manual)
3345 (condition-case err
3346 (if (setq nodes (Info-index-nodes (Info-find-file manual)))
3347 (save-excursion
3348 (Info-find-node manual (car nodes))
3349 (while
3350 (progn
3351 (goto-char (point-min))
3352 (while (re-search-forward pattern nil t)
3353 (setq matches
3354 (cons (list manual
3355 (match-string-no-properties 1)
3356 (match-string-no-properties 2)
3357 (match-string-no-properties 3))
3358 matches)))
3359 (setq nodes (cdr nodes) node (car nodes)))
3360 (Info-goto-node node))))
3361 (error
3362 (message "%s" (if (eq (car-safe err) 'error)
3363 (nth 1 err) err))
3364 (sit-for 1 t)))))
3365 (Info-find-node current-file current-node)
3366 (setq Info-history ohist
3367 Info-history-list ohist-list)
3368 (message "Searching indices...done")
3369 (or (nreverse matches) t))))
3370
3371 ;;;###autoload
3372 (defun info-apropos (string)
3373 "Grovel indices of all known Info files on your system for STRING.
3374 Build a menu of the possible matches."
3375 (interactive "sIndex apropos: ")
3376 (if (equal string "")
3377 (Info-find-node Info-apropos-file "Top")
3378 (let* ((nodes Info-apropos-nodes) nodename)
3379 (while (and nodes (not (equal string (nth 1 (car nodes)))))
3380 (setq nodes (cdr nodes)))
3381 (if nodes
3382 (Info-find-node Info-apropos-file (car (car nodes)))
3383 (setq nodename (format "Index for `%s'" string))
3384 (push (list nodename string (Info-apropos-matches string))
3385 Info-apropos-nodes)
3386 (Info-find-node Info-apropos-file nodename)))))
3387 \f
3388 (add-to-list 'Info-virtual-files
3389 '("\\`\\*Finder.*\\*\\'"
3390 (find-file . Info-finder-find-file)
3391 (find-node . Info-finder-find-node)
3392 ))
3393
3394 (defvar Info-finder-file "*Finder*"
3395 "Info file name of the virtual Info keyword finder manual.")
3396
3397 (defun Info-finder-find-file (filename &optional _noerror)
3398 "Finder-specific implementation of `Info-find-file'."
3399 filename)
3400
3401 (defvar finder-known-keywords)
3402 (declare-function find-library-name "find-func" (library))
3403 (declare-function finder-unknown-keywords "finder" ())
3404 (declare-function lm-commentary "lisp-mnt" (&optional file))
3405 (defvar finder-keywords-hash)
3406 (defvar package--builtins) ; finder requires package
3407
3408 (defun Info-finder-find-node (_filename nodename &optional _no-going-back)
3409 "Finder-specific implementation of `Info-find-node-2'."
3410 (require 'finder)
3411 (cond
3412 ((equal nodename "Top")
3413 ;; Display Top menu with descriptions of the keywords
3414 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3415 Info-finder-file nodename))
3416 (insert "Finder Keywords\n")
3417 (insert "***************\n\n")
3418 (insert "* Menu:\n\n")
3419 (dolist (assoc (append '((all . "All package info")
3420 (unknown . "Unknown keywords"))
3421 finder-known-keywords))
3422 (let ((keyword (car assoc)))
3423 (insert (format "* %s %s.\n"
3424 (concat (symbol-name keyword) ": "
3425 "Keyword " (symbol-name keyword) ".")
3426 (cdr assoc))))))
3427 ((equal nodename "Keyword unknown")
3428 ;; Display unknown keywords
3429 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3430 Info-finder-file nodename))
3431 (insert "Finder Unknown Keywords\n")
3432 (insert "***********************\n\n")
3433 (insert "* Menu:\n\n")
3434 (mapc
3435 (lambda (assoc)
3436 (insert (format "* %-14s %s.\n"
3437 (concat (symbol-name (car assoc)) ": "
3438 "Keyword " (symbol-name (car assoc)) ".")
3439 (cdr assoc))))
3440 (finder-unknown-keywords)))
3441 ((equal nodename "Keyword all")
3442 ;; Display all package info.
3443 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3444 Info-finder-file nodename))
3445 (insert "Finder Package Info\n")
3446 (insert "*******************\n\n")
3447 (insert "* Menu:\n\n")
3448 (let (desc)
3449 (dolist (package package--builtins)
3450 (setq desc (cdr-safe package))
3451 (when (vectorp desc)
3452 (insert (format "* %-16s %s.\n"
3453 (concat (symbol-name (car package)) "::")
3454 (aref desc 2)))))))
3455 ((string-match "\\`Keyword " nodename)
3456 (setq nodename (substring nodename (match-end 0)))
3457 ;; Display packages that match the keyword
3458 ;; or the list of keywords separated by comma.
3459 (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
3460 Info-finder-file nodename))
3461 (insert "Finder Packages\n")
3462 (insert "***************\n\n")
3463 (insert
3464 "The following packages match the keyword `" nodename "':\n\n")
3465 (insert "* Menu:\n\n")
3466 (let ((keywords
3467 (mapcar 'intern (if (string-match-p "," nodename)
3468 (split-string nodename ",[ \t\n]*" t)
3469 (list nodename))))
3470 hits desc)
3471 (dolist (keyword keywords)
3472 (push (copy-tree (gethash keyword finder-keywords-hash)) hits))
3473 (setq hits (delete-dups (apply 'append hits)))
3474 (dolist (package hits)
3475 (setq desc (cdr-safe (assq package package--builtins)))
3476 (when (vectorp desc)
3477 (insert (format "* %-16s %s.\n"
3478 (concat (symbol-name package) "::")
3479 (aref desc 2)))))))
3480 (t
3481 ;; Display commentary section
3482 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3483 Info-finder-file nodename))
3484 (insert "Finder Commentary\n")
3485 (insert "*****************\n\n")
3486 (insert
3487 "Commentary section of the package `" nodename "':\n\n")
3488 (let ((str (lm-commentary (find-library-name nodename))))
3489 (if (null str)
3490 (insert "Can't find any Commentary section\n\n")
3491 (insert
3492 (with-temp-buffer
3493 (insert str)
3494 (goto-char (point-min))
3495 (delete-blank-lines)
3496 (goto-char (point-max))
3497 (delete-blank-lines)
3498 (goto-char (point-min))
3499 (while (re-search-forward "^;+ ?" nil t)
3500 (replace-match "" nil nil))
3501 (buffer-string))))))))
3502
3503 ;;;###autoload
3504 (defun info-finder (&optional keywords)
3505 "Display descriptions of the keywords in the Finder virtual manual.
3506 In interactive use, a prefix argument directs this command to read
3507 a list of keywords separated by comma. After that, it displays a node
3508 with a list of packages that contain all specified keywords."
3509 (interactive
3510 (when current-prefix-arg
3511 (require 'finder)
3512 (list
3513 (completing-read-multiple
3514 "Keywords (separated by comma): "
3515 (mapcar 'symbol-name (mapcar 'car (append finder-known-keywords
3516 (finder-unknown-keywords))))
3517 nil t))))
3518 (require 'finder)
3519 (if keywords
3520 (Info-find-node Info-finder-file (mapconcat 'identity keywords ", "))
3521 (Info-find-node Info-finder-file "Top")))
3522
3523 \f
3524 (defun Info-undefined ()
3525 "Make command be undefined in Info."
3526 (interactive)
3527 (ding))
3528
3529 (defun Info-help ()
3530 "Enter the Info tutorial."
3531 (interactive)
3532 (delete-other-windows)
3533 (Info-find-node "info"
3534 (if (< (window-height) 23)
3535 "Help-Small-Screen"
3536 "Help")))
3537
3538 (defun Info-summary ()
3539 "Display a brief summary of all Info commands."
3540 (interactive)
3541 (save-window-excursion
3542 (switch-to-buffer "*Help*")
3543 (setq buffer-read-only nil)
3544 (erase-buffer)
3545 (insert (documentation 'Info-mode))
3546 (help-mode)
3547 (goto-char (point-min))
3548 (let (ch flag)
3549 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
3550 (message (if flag "Type Space to see more"
3551 "Type Space to return to Info"))
3552 (if (not (eq ?\s (setq ch (read-event))))
3553 (progn (setq unread-command-events (list ch)) nil)
3554 flag))
3555 (scroll-up)))
3556 (bury-buffer "*Help*")))
3557 \f
3558 (defun Info-get-token (pos start all &optional errorstring)
3559 "Return the token around POS.
3560 POS must be somewhere inside the token.
3561 START is a regular expression which will match the
3562 beginning of the tokens delimited string.
3563 ALL is a regular expression with a single
3564 parenthesized subpattern which is the token to be
3565 returned. E.g. '{\(.*\)}' would return any string
3566 enclosed in braces around POS.
3567 ERRORSTRING optional fourth argument, controls action on no match:
3568 nil: return nil
3569 t: beep
3570 a string: signal an error, using that string."
3571 (let ((case-fold-search t))
3572 (save-excursion
3573 (goto-char pos)
3574 ;; First look for a match for START that goes across POS.
3575 (while (and (not (bobp)) (> (point) (- pos (length start)))
3576 (not (looking-at start)))
3577 (forward-char -1))
3578 ;; If we did not find one, search back for START
3579 ;; (this finds only matches that end at or before POS).
3580 (or (looking-at start)
3581 (progn
3582 (goto-char pos)
3583 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
3584 (let (found)
3585 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
3586 (not (setq found (and (<= (match-beginning 0) pos)
3587 (> (match-end 0) pos))))))
3588 (if (and found (<= (match-beginning 0) pos)
3589 (> (match-end 0) pos))
3590 (match-string-no-properties 1)
3591 (cond ((null errorstring)
3592 nil)
3593 ((eq errorstring t)
3594 (beep)
3595 nil)
3596 (t
3597 (error "No %s around position %d" errorstring pos))))))))
3598
3599 (defun Info-mouse-follow-nearest-node (click)
3600 "\\<Info-mode-map>Follow a node reference near point.
3601 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3602 At end of the node's text, moves to the next node, or up if none."
3603 (interactive "e")
3604 (mouse-set-point click)
3605 (and (not (Info-follow-nearest-node))
3606 (save-excursion (forward-line 1) (eobp))
3607 (Info-next-preorder)))
3608
3609 (defun Info-follow-nearest-node (&optional fork)
3610 "Follow a node reference near point.
3611 If point is on a reference, follow that reference. Otherwise,
3612 if point is in a menu item description, follow that menu item.
3613
3614 If FORK is non-nil (interactively with a prefix arg), show the node in
3615 a new Info buffer.
3616 If FORK is a string, it is the name to use for the new buffer."
3617 (interactive "P")
3618 (or (Info-try-follow-nearest-node fork)
3619 (when (save-excursion
3620 (search-backward "\n* menu:" nil t))
3621 (save-excursion
3622 (beginning-of-line)
3623 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3624 (beginning-of-line 0))
3625 (when (looking-at "\\* +\\([^\t\n]*\\):")
3626 (Info-goto-node
3627 (Info-extract-menu-item (match-string-no-properties 1)) fork)
3628 t)))
3629 (and (eq this-command 'Info-mouse-follow-nearest-node)
3630 ;; Don't raise an error when mouse-1 is bound to this - it's
3631 ;; often used to simply select the window or frame.
3632 (eq 'mouse-1 (event-basic-type last-input-event)))
3633 (error "Point neither on reference nor in menu item description")))
3634
3635 ;; Common subroutine.
3636 (defun Info-try-follow-nearest-node (&optional fork)
3637 "Follow a node reference near point. Return non-nil if successful.
3638 If FORK is non-nil, it is passed to `Info-goto-node'."
3639 (let (node)
3640 (cond
3641 ((setq node (Info-get-token (point) "[hf]t?tps?://"
3642 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3643 (browse-url node)
3644 (setq node t))
3645 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
3646 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3647 (Info-follow-reference node fork))
3648 ;; menu item: node name
3649 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3650 (Info-goto-node node fork))
3651 ;; menu item: node name or index entry
3652 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3653 (beginning-of-line)
3654 (forward-char 2)
3655 (setq node (Info-extract-menu-node-name nil (Info-index-node)))
3656 (Info-goto-node node fork))
3657 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3658 (Info-goto-node node fork))
3659 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3660 (Info-goto-node node fork))
3661 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3662 (Info-goto-node "Top" fork))
3663 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3664 (Info-goto-node node fork)))
3665 node))
3666
3667 (defun Info-mouse-follow-link (click)
3668 "Follow a link where you click."
3669 (interactive "e")
3670 (let* ((position (event-start click))
3671 (posn-string (and position (posn-string position)))
3672 (string (car-safe posn-string))
3673 (string-pos (cdr-safe posn-string))
3674 (link-args (and string string-pos
3675 (get-text-property string-pos 'link-args string))))
3676 (when link-args
3677 (Info-goto-node link-args))))
3678
3679 \f
3680 (defvar Info-mode-map
3681 (let ((map (make-keymap)))
3682 (suppress-keymap map)
3683 (define-key map "." 'beginning-of-buffer)
3684 (define-key map " " 'Info-scroll-up)
3685 (define-key map "\C-m" 'Info-follow-nearest-node)
3686 (define-key map "\t" 'Info-next-reference)
3687 (define-key map "\e\t" 'Info-prev-reference)
3688 (define-key map [backtab] 'Info-prev-reference)
3689 (define-key map "1" 'Info-nth-menu-item)
3690 (define-key map "2" 'Info-nth-menu-item)
3691 (define-key map "3" 'Info-nth-menu-item)
3692 (define-key map "4" 'Info-nth-menu-item)
3693 (define-key map "5" 'Info-nth-menu-item)
3694 (define-key map "6" 'Info-nth-menu-item)
3695 (define-key map "7" 'Info-nth-menu-item)
3696 (define-key map "8" 'Info-nth-menu-item)
3697 (define-key map "9" 'Info-nth-menu-item)
3698 (define-key map "0" 'undefined)
3699 (define-key map "?" 'Info-summary)
3700 (define-key map "]" 'Info-forward-node)
3701 (define-key map "[" 'Info-backward-node)
3702 (define-key map "<" 'Info-top-node)
3703 (define-key map ">" 'Info-final-node)
3704 (define-key map "b" 'beginning-of-buffer)
3705 (put 'beginning-of-buffer :advertised-binding "b")
3706 (define-key map "d" 'Info-directory)
3707 (define-key map "e" 'Info-edit)
3708 (define-key map "f" 'Info-follow-reference)
3709 (define-key map "g" 'Info-goto-node)
3710 (define-key map "h" 'Info-help)
3711 (define-key map "i" 'Info-index)
3712 (define-key map "I" 'Info-virtual-index)
3713 (define-key map "l" 'Info-history-back)
3714 (define-key map "L" 'Info-history)
3715 (define-key map "m" 'Info-menu)
3716 (define-key map "n" 'Info-next)
3717 (define-key map "p" 'Info-prev)
3718 (define-key map "q" 'Info-exit)
3719 (define-key map "r" 'Info-history-forward)
3720 (define-key map "s" 'Info-search)
3721 (define-key map "S" 'Info-search-case-sensitively)
3722 (define-key map "\M-n" 'clone-buffer)
3723 (define-key map "t" 'Info-top-node)
3724 (define-key map "T" 'Info-toc)
3725 (define-key map "u" 'Info-up)
3726 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3727 (define-key map "w" 'Info-copy-current-node-name)
3728 (define-key map "c" 'Info-copy-current-node-name)
3729 ;; `^' for consistency with `dired-up-directory'.
3730 (define-key map "^" 'Info-up)
3731 (define-key map "," 'Info-index-next)
3732 (define-key map "\177" 'Info-scroll-down)
3733 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3734 (define-key map [follow-link] 'mouse-face)
3735 map)
3736 "Keymap containing Info commands.")
3737
3738
3739 (defun Info-check-pointer (item)
3740 "Non-nil if ITEM is present in this node."
3741 (condition-case nil
3742 (Info-extract-pointer item)
3743 (error nil)))
3744
3745 (easy-menu-define
3746 Info-mode-menu Info-mode-map
3747 "Menu for Info files."
3748 '("Info"
3749 ["Up" Info-up :active (Info-check-pointer "up")
3750 :help "Go up in the Info tree"]
3751 ["Next" Info-next :active (Info-check-pointer "next")
3752 :help "Go to the next node"]
3753 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3754 :help "Go to the previous node"]
3755 ["Backward" Info-backward-node
3756 :help "Go backward one node, considering all as a sequence"]
3757 ["Forward" Info-forward-node
3758 :help "Go forward one node, considering all as a sequence"]
3759 ["Beginning" beginning-of-buffer
3760 :help "Go to beginning of this node"]
3761 ["Top" Info-top-node
3762 :help "Go to top node of file"]
3763 ["Final Node" Info-final-node
3764 :help "Go to final node in this file"]
3765 ("Menu Item" ["You should never see this" report-emacs-bug t])
3766 ("Reference" ["You should never see this" report-emacs-bug t])
3767 ["Search..." Info-search
3768 :help "Search for regular expression in this Info file"]
3769 ["Search Next" Info-search-next
3770 :help "Search for another occurrence of regular expression"]
3771 ["Go to Node..." Info-goto-node
3772 :help "Go to a named node"]
3773 ["Back in history" Info-history-back :active Info-history
3774 :help "Go back in history to the last node you were at"]
3775 ["Forward in history" Info-history-forward :active Info-history-forward
3776 :help "Go forward in history"]
3777 ["History" Info-history :active Info-history-list
3778 :help "Go to menu of visited nodes"]
3779 ["Table of Contents" Info-toc
3780 :help "Go to table of contents"]
3781 ("Index"
3782 ["Lookup a String..." Info-index
3783 :help "Look for a string in the index items"]
3784 ["Next Matching Item" Info-index-next :active Info-index-alternatives
3785 :help "Look for another occurrence of previous item"]
3786 ["Lookup a string and display index of results..." Info-virtual-index
3787 :help "Look for a string in the index items and display node with results"]
3788 ["Lookup a string in all indices..." info-apropos
3789 :help "Look for a string in the indices of all manuals"])
3790 ["Copy Node Name" Info-copy-current-node-name
3791 :help "Copy the name of the current node into the kill ring"]
3792 ["Clone Info buffer" clone-buffer
3793 :help "Create a twin copy of the current Info buffer."]
3794 ["Exit" Info-exit :help "Stop reading Info"]))
3795
3796
3797 (defvar info-tool-bar-map
3798 (let ((map (make-sparse-keymap)))
3799 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
3800 :rtl "right-arrow"
3801 :label "Back"
3802 :vert-only t)
3803 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
3804 :rtl "left-arrow"
3805 :label "Forward"
3806 :vert-only t)
3807 (define-key-after map [separator-1] menu-bar-separator)
3808 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
3809 :rtl "next-node")
3810 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
3811 :rtl "prev-node")
3812 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
3813 :vert-only t)
3814 (define-key-after map [separator-2] menu-bar-separator)
3815 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
3816 :vert-only t)
3817 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
3818 (define-key-after map [separator-3] menu-bar-separator)
3819 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
3820 :label "Index")
3821 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
3822 :vert-only t)
3823 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
3824 :vert-only t)
3825 map))
3826
3827 (defvar Info-menu-last-node nil)
3828 ;; Last node the menu was created for.
3829 ;; Value is a list, (FILE-NAME NODE-NAME).
3830
3831 (defun Info-menu-update ()
3832 "Update the Info menu for the current node."
3833 (condition-case nil
3834 (if (or (not (eq major-mode 'Info-mode))
3835 (equal (list Info-current-file Info-current-node)
3836 Info-menu-last-node))
3837 ()
3838 ;; Update menu menu.
3839 (let* ((Info-complete-menu-buffer (current-buffer))
3840 (items (nreverse (condition-case nil
3841 (Info-complete-menu-item "" nil t)
3842 (error nil))))
3843 entries current
3844 (number 0))
3845 (while (and items (< number 9))
3846 (setq current (car items)
3847 items (cdr items)
3848 number (1+ number))
3849 (setq entries (cons `[,current
3850 (Info-menu ,current)
3851 :keys ,(format "%d" number)]
3852 entries)))
3853 (if items
3854 (setq entries (cons ["Other..." Info-menu t] entries)))
3855 (or entries
3856 (setq entries (list ["No menu" nil nil] nil :active)))
3857 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3858 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3859 (let ((items nil)
3860 str i entries current
3861 (number 0)
3862 (case-fold-search t))
3863 (save-excursion
3864 (goto-char (point-min))
3865 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3866 (setq str (match-string 1))
3867 (setq i 0)
3868 (while (setq i (string-match "[ \n\t]+" str i))
3869 (setq str (concat (substring str 0 i) " "
3870 (substring str (match-end 0))))
3871 (setq i (1+ i)))
3872 (setq items
3873 (cons str items))))
3874 (while (and items (< number 9))
3875 (setq current (car items)
3876 items (cdr items)
3877 number (1+ number))
3878 (setq entries (cons `[,current
3879 (Info-follow-reference ,current)
3880 t]
3881 entries)))
3882 (if items
3883 (setq entries (cons ["Other..." Info-follow-reference t]
3884 entries)))
3885 (or entries
3886 (setq entries (list ["No references" nil nil] nil :active)))
3887 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3888 ;; Update last seen node.
3889 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3890 ;; Try to avoid entering infinite beep mode in case of errors.
3891 (error (ding))))
3892
3893 \f
3894 (defun Info-copy-current-node-name (&optional arg)
3895 "Put the name of the current Info node into the kill ring.
3896 The name of the Info file is prepended to the node name in parentheses.
3897 With a zero prefix arg, put the name inside a function call to `info'."
3898 (interactive "P")
3899 (unless Info-current-node
3900 (error "No current Info node"))
3901 (let ((node (if (stringp Info-current-file)
3902 (concat "(" (file-name-nondirectory Info-current-file) ") "
3903 Info-current-node))))
3904 (if (zerop (prefix-numeric-value arg))
3905 (setq node (concat "(info \"" node "\")")))
3906 (unless (stringp Info-current-file)
3907 (setq node (format "(Info-find-node '%S '%S)"
3908 Info-current-file Info-current-node)))
3909 (kill-new node)
3910 (message "%s" node)))
3911
3912 \f
3913 ;; Info mode is suitable only for specially formatted data.
3914 (put 'Info-mode 'mode-class 'special)
3915 (put 'Info-mode 'no-clone-indirect t)
3916
3917 (defvar tool-bar-map)
3918 (defvar bookmark-make-record-function)
3919
3920 (defvar Info-mode-syntax-table
3921 (let ((st (copy-syntax-table text-mode-syntax-table)))
3922 ;; Use punctuation syntax for apostrophe because of
3923 ;; extensive use of quotes like `this' in Info manuals.
3924 (modify-syntax-entry ?' "." st)
3925 st)
3926 "Syntax table used in `Info-mode'.")
3927
3928 ;; Autoload cookie needed by desktop.el
3929 ;;;###autoload
3930 (define-derived-mode Info-mode nil "Info"
3931 "Info mode provides commands for browsing through the Info documentation tree.
3932 Documentation in Info is divided into \"nodes\", each of which discusses
3933 one topic and contains references to other nodes which discuss related
3934 topics. Info has commands to follow the references and show you other nodes.
3935
3936 \\<Info-mode-map>\
3937 \\[Info-help] Invoke the Info tutorial.
3938 \\[Info-exit] Quit Info: reselect previously selected buffer.
3939
3940 Selecting other nodes:
3941 \\[Info-mouse-follow-nearest-node]
3942 Follow a node reference you click on.
3943 This works with menu items, cross references, and
3944 the \"next\", \"previous\" and \"up\", depending on where you click.
3945 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3946 \\[Info-next] Move to the \"next\" node of this node.
3947 \\[Info-prev] Move to the \"previous\" node of this node.
3948 \\[Info-up] Move \"up\" from this node.
3949 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3950 Picking a menu item causes another node to be selected.
3951 \\[Info-directory] Go to the Info directory node.
3952 \\[Info-top-node] Go to the Top node of this file.
3953 \\[Info-final-node] Go to the final node in this file.
3954 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3955 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3956 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3957 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
3958 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3959 \\[Info-history-back] Move back in history to the last node you were at.
3960 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3961 \\[Info-history] Go to menu of visited nodes.
3962 \\[Info-toc] Go to table of contents of the current Info file.
3963
3964 Moving within a node:
3965 \\[Info-scroll-up] Normally, scroll forward a full screen.
3966 Once you scroll far enough in a node that its menu appears on the
3967 screen but after point, the next scroll moves into its first
3968 subnode. When after all menu items (or if there is no menu),
3969 move up to the parent node.
3970 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3971 already visible, try to go to the previous menu entry, or up
3972 if there is none.
3973 \\[beginning-of-buffer] Go to beginning of node.
3974
3975 Advanced commands:
3976 \\[Info-search] Search through this Info file for specified regexp,
3977 and select the node in which the next occurrence is found.
3978 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3979 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
3980 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
3981 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3982 \\[Info-virtual-index] Look for a string and display the index node with results.
3983 \\[info-apropos] Look for a string in the indices of all manuals.
3984 \\[Info-goto-node] Move to node specified by name.
3985 You may include a filename as well, as (FILENAME)NODENAME.
3986 1 .. 9 Pick first ... ninth item in node's menu.
3987 Every third `*' is highlighted to help pick the right number.
3988 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
3989 \\[clone-buffer] Select a new cloned Info buffer in another window.
3990 \\[universal-argument] \\[info] Move to new Info file with completion.
3991 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
3992 :syntax-table Info-mode-syntax-table
3993 :abbrev-table text-mode-abbrev-table
3994 (setq tab-width 8)
3995 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3996 (setq case-fold-search t)
3997 (setq buffer-read-only t)
3998 (make-local-variable 'Info-current-file)
3999 (make-local-variable 'Info-current-subfile)
4000 (make-local-variable 'Info-current-node)
4001 (set (make-local-variable 'Info-tag-table-marker) (make-marker))
4002 (set (make-local-variable 'Info-tag-table-buffer) nil)
4003 (make-local-variable 'Info-history)
4004 (make-local-variable 'Info-history-forward)
4005 (make-local-variable 'Info-index-alternatives)
4006 (if Info-use-header-line ; do not override global header lines
4007 (setq header-line-format
4008 '(:eval (get-text-property (point-min) 'header-line))))
4009 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
4010 ;; This is for the sake of the invisible text we use handling titles.
4011 (set (make-local-variable 'line-move-ignore-invisible) t)
4012 (set (make-local-variable 'desktop-save-buffer)
4013 'Info-desktop-buffer-misc-data)
4014 (set (make-local-variable 'widen-automatically) nil)
4015 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
4016 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
4017 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
4018 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
4019 (set (make-local-variable 'isearch-search-fun-function)
4020 'Info-isearch-search)
4021 (set (make-local-variable 'isearch-wrap-function)
4022 'Info-isearch-wrap)
4023 (set (make-local-variable 'isearch-push-state-function)
4024 'Info-isearch-push-state)
4025 (set (make-local-variable 'isearch-filter-predicate)
4026 'Info-isearch-filter)
4027 (set (make-local-variable 'search-whitespace-regexp)
4028 Info-search-whitespace-regexp)
4029 (set (make-local-variable 'revert-buffer-function)
4030 'Info-revert-buffer-function)
4031 (Info-set-mode-line)
4032 (set (make-local-variable 'bookmark-make-record-function)
4033 'Info-bookmark-make-record))
4034
4035 ;; When an Info buffer is killed, make sure the associated tags buffer
4036 ;; is killed too.
4037 (defun Info-kill-buffer ()
4038 (and (eq major-mode 'Info-mode)
4039 Info-tag-table-buffer
4040 (kill-buffer Info-tag-table-buffer)))
4041
4042 ;; Placed on `clone-buffer-hook'.
4043 (defun Info-clone-buffer ()
4044 (when (bufferp Info-tag-table-buffer)
4045 (setq Info-tag-table-buffer
4046 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4047 (let ((m Info-tag-table-marker))
4048 (when (markerp m)
4049 (setq Info-tag-table-marker
4050 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4051 (with-current-buffer Info-tag-table-buffer
4052 (copy-marker (marker-position m)))
4053 (make-marker))))))
4054
4055 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
4056 (set-keymap-parent map text-mode-map)
4057 (define-key map "\C-c\C-c" 'Info-cease-edit)
4058 map)
4059 "Local keymap used within `e' command of Info.")
4060
4061 ;; Info-edit mode is suitable only for specially formatted data.
4062 (put 'Info-edit-mode 'mode-class 'special)
4063
4064 (defun Info-edit-mode ()
4065 "Major mode for editing the contents of an Info node.
4066 Like text mode with the addition of `Info-cease-edit'
4067 which returns to Info mode for browsing.
4068 \\{Info-edit-map}"
4069 (use-local-map Info-edit-map)
4070 (setq major-mode 'Info-edit-mode)
4071 (setq mode-name "Info Edit")
4072 (kill-local-variable 'mode-line-buffer-identification)
4073 (setq buffer-read-only nil)
4074 (force-mode-line-update)
4075 (buffer-enable-undo (current-buffer))
4076 (run-mode-hooks 'Info-edit-mode-hook))
4077
4078 (defun Info-edit ()
4079 "Edit the contents of this Info node.
4080 Allowed only if variable `Info-enable-edit' is non-nil."
4081 (interactive)
4082 (or Info-enable-edit
4083 (error "Editing Info nodes is not enabled"))
4084 (Info-edit-mode)
4085 (message "%s" (substitute-command-keys
4086 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
4087
4088 (defun Info-cease-edit ()
4089 "Finish editing Info node; switch back to Info proper."
4090 (interactive)
4091 ;; Do this first, so nothing has changed if user C-g's at query.
4092 (and (buffer-modified-p)
4093 (y-or-n-p "Save the file? ")
4094 (save-buffer))
4095 (use-local-map Info-mode-map)
4096 (setq major-mode 'Info-mode)
4097 (setq mode-name "Info")
4098 (Info-set-mode-line)
4099 (setq buffer-read-only t)
4100 (force-mode-line-update)
4101 (and (marker-position Info-tag-table-marker)
4102 (buffer-modified-p)
4103 (message "Tags may have changed. Use Info-tagify if necessary")))
4104 \f
4105 (defvar Info-file-list-for-emacs
4106 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4107 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4108 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4109 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4110 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4111 ("copyright" . "autotype") ("executable" . "autotype")
4112 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4113 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4114 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4115 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4116 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4117 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4118 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4119 ("rfc2045" . "emacs-mime")
4120 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4121 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4122 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4123 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4124 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4125 ("mml" . "emacs-mime"))
4126 "List of Info files that describe Emacs commands.
4127 An element can be a file name, or a list of the form (PREFIX . FILE)
4128 where PREFIX is a name prefix and FILE is the file to look in.
4129 If the element is just a file name, the file name also serves as the prefix.")
4130
4131 (defun Info-find-emacs-command-nodes (command)
4132 "Return a list of locations documenting COMMAND.
4133 The `info-file' property of COMMAND says which Info manual to search.
4134 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4135 defines heuristics for which Info manual to try.
4136 The locations are of the format used in `Info-history', i.e.
4137 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4138 in the first element of the returned list (which is treated specially in
4139 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4140 (let ((where '()) line-number
4141 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4142 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4143 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4144 (info-file "emacs")) ;default
4145 ;; Determine which Info file this command is documented in.
4146 (if (get command 'info-file)
4147 (setq info-file (get command 'info-file))
4148 ;; If it doesn't say explicitly, test its name against
4149 ;; various prefixes that we know.
4150 (let ((file-list Info-file-list-for-emacs))
4151 (while file-list
4152 (let* ((elt (car file-list))
4153 (name (if (consp elt)
4154 (car elt)
4155 elt))
4156 (file (if (consp elt) (cdr elt) elt))
4157 (case-fold-search nil)
4158 (regexp (concat "\\`" (regexp-quote name)
4159 "\\(\\'\\|-\\)")))
4160 (if (string-match regexp (symbol-name command))
4161 (setq info-file file file-list nil))
4162 (setq file-list (cdr file-list))))))
4163 (Info-find-node info-file "Top")
4164 ;; Bind Info-history to nil, to prevent the index nodes from
4165 ;; getting into the node history.
4166 (let ((Info-history nil)
4167 (Info-history-list nil)
4168 node (nodes (Info-index-nodes)))
4169 (Info-goto-node (car nodes))
4170 (while
4171 (progn
4172 (goto-char (point-min))
4173 (while (re-search-forward cmd-desc nil t)
4174 (setq where
4175 (cons (list Info-current-file
4176 (match-string-no-properties 2)
4177 0)
4178 where))
4179 (setq line-number (and (match-beginning 3)
4180 (string-to-number (match-string 3)))))
4181 (and (setq nodes (cdr nodes) node (car nodes))))
4182 (Info-goto-node node)))
4183 (if (and line-number where)
4184 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4185 (cdr where))
4186 where)))
4187
4188 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4189 ;;;###autoload
4190 (defun Info-goto-emacs-command-node (command)
4191 "Go to the Info node in the Emacs manual for command COMMAND.
4192 The command is found by looking up in Emacs manual's indices
4193 or in another manual found via COMMAND's `info-file' property or
4194 the variable `Info-file-list-for-emacs'.
4195 COMMAND must be a symbol or string."
4196 (interactive "CFind documentation for command: ")
4197 ;; If command is given as a string, convert it to a symbol.
4198 (if (stringp command)
4199 (setq command (intern command)))
4200 (or (commandp command)
4201 (signal 'wrong-type-argument (list 'commandp command)))
4202 (let ((where (Info-find-emacs-command-nodes command)))
4203 (if where
4204 (let ((num-matches (length where)))
4205 ;; Get Info running, and pop to it in another window.
4206 (save-window-excursion
4207 (info))
4208 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
4209 ;; Bind Info-history to nil, to prevent the last Index node
4210 ;; visited by Info-find-emacs-command-nodes from being
4211 ;; pushed onto the history.
4212 (let ((Info-history nil) (Info-history-list nil)
4213 (line-number (nth 2 (car where))))
4214 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4215 (if (and (integerp line-number) (> line-number 0))
4216 (forward-line (1- line-number))))
4217 (if (> num-matches 1)
4218 (progn
4219 ;; (car where) will be pushed onto Info-history
4220 ;; when/if they go to another node. Put the other
4221 ;; nodes that were found on the history.
4222 (setq Info-history (nconc (cdr where) Info-history))
4223 (message "Found %d other entr%s. Use %s to see %s."
4224 (1- num-matches)
4225 (if (> num-matches 2) "ies" "y")
4226 (substitute-command-keys "\\[Info-history-back]")
4227 (if (> num-matches 2) "them" "it")))))
4228 (error "Couldn't find documentation for %s" command))))
4229
4230 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4231 ;;;###autoload
4232 (defun Info-goto-emacs-key-command-node (key)
4233 "Go to the node in the Emacs manual which describes the command bound to KEY.
4234 KEY is a string.
4235 Interactively, if the binding is `execute-extended-command', a command is read.
4236 The command is found by looking up in Emacs manual's indices
4237 or in another manual found via COMMAND's `info-file' property or
4238 the variable `Info-file-list-for-emacs'."
4239 (interactive "kFind documentation for key: ")
4240 (let ((command (key-binding key)))
4241 (cond ((null command)
4242 (message "%s is undefined" (key-description key)))
4243 ((and (called-interactively-p 'interactive)
4244 (eq command 'execute-extended-command))
4245 (Info-goto-emacs-command-node
4246 (read-command "Find documentation for command: ")))
4247 (t
4248 (Info-goto-emacs-command-node command)))))
4249 \f
4250 (defvar Info-next-link-keymap
4251 (let ((keymap (make-sparse-keymap)))
4252 (define-key keymap [header-line mouse-1] 'Info-next)
4253 (define-key keymap [header-line mouse-2] 'Info-next)
4254 (define-key keymap [header-line down-mouse-1] 'ignore)
4255 (define-key keymap [mouse-2] 'Info-next)
4256 (define-key keymap [follow-link] 'mouse-face)
4257 keymap)
4258 "Keymap to put on the Next link in the text or the header line.")
4259
4260 (defvar Info-prev-link-keymap
4261 (let ((keymap (make-sparse-keymap)))
4262 (define-key keymap [header-line mouse-1] 'Info-prev)
4263 (define-key keymap [header-line mouse-2] 'Info-prev)
4264 (define-key keymap [header-line down-mouse-1] 'ignore)
4265 (define-key keymap [mouse-2] 'Info-prev)
4266 (define-key keymap [follow-link] 'mouse-face)
4267 keymap)
4268 "Keymap to put on the Prev link in the text or the header line.")
4269
4270 (defvar Info-up-link-keymap
4271 (let ((keymap (make-sparse-keymap)))
4272 (define-key keymap [header-line mouse-1] 'Info-up)
4273 (define-key keymap [header-line mouse-2] 'Info-up)
4274 (define-key keymap [header-line down-mouse-1] 'ignore)
4275 (define-key keymap [mouse-2] 'Info-up)
4276 (define-key keymap [follow-link] 'mouse-face)
4277 keymap)
4278 "Keymap to put on the Up link in the text or the header line.")
4279
4280 (defvar Info-link-keymap
4281 (let ((keymap (make-sparse-keymap)))
4282 (define-key keymap [header-line mouse-1] 'Info-mouse-follow-link)
4283 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4284 (define-key keymap [header-line down-mouse-1] 'ignore)
4285 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4286 (define-key keymap [follow-link] 'mouse-face)
4287 keymap)
4288 "Keymap to put on the link in the text or the header line.")
4289
4290 (defun Info-breadcrumbs ()
4291 (let ((nodes (Info-toc-nodes Info-current-file))
4292 (node Info-current-node)
4293 (crumbs ())
4294 (depth Info-breadcrumbs-depth)
4295 line)
4296
4297 ;; Get ancestors from the cached parent-children node info
4298 (while (and (not (equal "Top" node)) (> depth 0))
4299 (setq node (nth 1 (assoc node nodes)))
4300 (if node (push node crumbs))
4301 (setq depth (1- depth)))
4302
4303 ;; Add bottom node.
4304 (when Info-use-header-line
4305 ;; Let it disappear if crumbs is nil.
4306 (nconc crumbs (list Info-current-node)))
4307 (when (or Info-use-header-line crumbs)
4308 ;; Add top node (and continuation if needed).
4309 (setq crumbs
4310 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4311 crumbs (cons nil crumbs))))
4312 ;; Eliminate duplicate.
4313 (forward-line 1)
4314 (dolist (node crumbs)
4315 (let ((text
4316 (if (not (equal node "Top")) node
4317 (format "(%s)Top"
4318 (if (stringp Info-current-file)
4319 (file-name-nondirectory Info-current-file)
4320 ;; Some legacy code can still use a symbol.
4321 Info-current-file)))))
4322 (setq line (concat
4323 line
4324 (if (null line) "" " > ")
4325 (cond
4326 ((null node) "...")
4327 ((equal node Info-current-node)
4328 ;; No point linking to ourselves.
4329 (propertize text 'font-lock-face 'info-header-node))
4330 (t
4331 (propertize text
4332 'mouse-face 'highlight
4333 'font-lock-face 'info-header-xref
4334 'help-echo "mouse-2: Go to node"
4335 'keymap Info-link-keymap
4336 'link-args text)))))))
4337 (setq line (concat line "\n")))
4338 ;; (font-lock-append-text-property 0 (length line)
4339 ;; 'font-lock-face 'header-line line)
4340 line))
4341
4342 (defun Info-fontify-node ()
4343 "Fontify the node."
4344 (save-excursion
4345 (let* ((inhibit-read-only t)
4346 (case-fold-search t)
4347 paragraph-markers
4348 (not-fontified-p ; the node hasn't already been fontified
4349 (not (let ((where (next-single-property-change (point-min)
4350 'font-lock-face)))
4351 (and where (not (= where (point-max)))))))
4352 (fontify-visited-p ; visited nodes need to be re-fontified
4353 (and Info-fontify-visited-nodes
4354 ;; Don't take time to refontify visited nodes in huge nodes
4355 Info-fontify-maximum-menu-size
4356 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4357 rbeg rend)
4358
4359 ;; Fontify header line
4360 (goto-char (point-min))
4361 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4362 (goto-char (match-end 0))
4363 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4364 (goto-char (match-end 0))
4365 (let* ((nbeg (match-beginning 2))
4366 (nend (match-end 2))
4367 (tbeg (match-beginning 1))
4368 (tag (match-string 1)))
4369 (if (string-equal (downcase tag) "node")
4370 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4371 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4372 (put-text-property tbeg nend 'mouse-face 'highlight)
4373 (put-text-property tbeg nend
4374 'help-echo
4375 (concat "mouse-2: Go to node "
4376 (buffer-substring nbeg nend)))
4377 ;; Always set up the text property keymap.
4378 ;; It will either be used in the buffer
4379 ;; or copied in the header line.
4380 (put-text-property
4381 tbeg nend 'keymap
4382 (cond
4383 ((string-equal (downcase tag) "prev") Info-prev-link-keymap)
4384 ((string-equal (downcase tag) "next") Info-next-link-keymap)
4385 ((string-equal (downcase tag) "up" ) Info-up-link-keymap))))))
4386
4387 ;; (when (> Info-breadcrumbs-depth 0)
4388 ;; (insert (Info-breadcrumbs)))
4389
4390 ;; Treat header line.
4391 (when Info-use-header-line
4392 (goto-char (point-min))
4393 (let* ((header-end (line-end-position))
4394 (header
4395 ;; If we find neither Next: nor Prev: link, show the entire
4396 ;; node header. Otherwise, don't show the File: and Node:
4397 ;; parts, to avoid wasting precious space on information that
4398 ;; is available in the mode line.
4399 (if (re-search-forward
4400 "\\(next\\|up\\|prev[ious]*\\): "
4401 header-end t)
4402 (progn
4403 (goto-char (match-beginning 1))
4404 (buffer-substring (point) header-end))
4405 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4406 header-end t)
4407 (concat "No next, prev or up links -- "
4408 (buffer-substring (point) header-end))
4409 (buffer-substring (point) header-end)))))
4410 (put-text-property (point-min) (1+ (point-min))
4411 'header-line
4412 (replace-regexp-in-string
4413 "%"
4414 ;; Preserve text properties on duplicated `%'.
4415 (lambda (s) (concat s s)) header))
4416 ;; Hide the part of the first line
4417 ;; that is in the header, if it is just part.
4418 (cond
4419 ((> Info-breadcrumbs-depth 0)
4420 (let ((ov (make-overlay (point-min) (1+ header-end))))
4421 (overlay-put ov 'display (Info-breadcrumbs))
4422 (overlay-put ov 'evaporate t)))
4423 ((not (bobp))
4424 ;; Hide the punctuation at the end, too.
4425 (skip-chars-backward " \t,")
4426 (put-text-property (point) header-end 'invisible t))))))
4427
4428 ;; Fontify titles
4429 (goto-char (point-min))
4430 (when (and font-lock-mode not-fontified-p)
4431 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4432 nil t)
4433 ;; Only consider it as an underlined title if the ASCII
4434 ;; underline has the same size as the text. A typical
4435 ;; counter example is when a continuation "..." is alone
4436 ;; on a line.
4437 (= (string-width (match-string 1))
4438 (string-width (match-string 2))))
4439 (let* ((c (preceding-char))
4440 (face
4441 (cond ((= c ?*) 'info-title-1)
4442 ((= c ?=) 'info-title-2)
4443 ((= c ?-) 'info-title-3)
4444 (t 'info-title-4))))
4445 (put-text-property (match-beginning 1) (match-end 1)
4446 'font-lock-face face))
4447 ;; This is a serious problem for trying to handle multiple
4448 ;; frame types at once. We want this text to be invisible
4449 ;; on frames that can display the font above.
4450 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4451 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4452 '(invisible t front-sticky nil rear-nonsticky t)))))
4453
4454 ;; Fontify cross references
4455 (goto-char (point-min))
4456 (when (or not-fontified-p fontify-visited-p)
4457 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4458 (let ((start (match-beginning 0))
4459 (next (point))
4460 other-tag)
4461 (when not-fontified-p
4462 (when Info-hide-note-references
4463 (when (and (not (eq Info-hide-note-references 'hide))
4464 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4465 ;; *Note is often used where *note should have been
4466 (goto-char start)
4467 (skip-syntax-backward " ")
4468 (when (memq (char-before) '(?\( ?\[ ?\{))
4469 ;; Check whether the paren is preceded by
4470 ;; an end of sentence
4471 (skip-syntax-backward " ("))
4472 (setq other-tag
4473 (cond ((save-match-data (looking-back "\\<see"))
4474 "")
4475 ((save-match-data (looking-back "\\<in"))
4476 "")
4477 ((memq (char-before) '(nil ?\. ?! ??))
4478 "See ")
4479 ((save-match-data
4480 (save-excursion
4481 (search-forward "\n\n" start t)))
4482 "See ")
4483 (t "see "))))
4484 (goto-char next)
4485 (add-text-properties
4486 (match-beginning 1)
4487 (or (save-match-data
4488 ;; Don't hide \n after *Note
4489 (let ((start1 (match-beginning 1)))
4490 (if (string-match "\n" (match-string 1))
4491 (+ start1 (match-beginning 0)))))
4492 (match-end 1))
4493 (if other-tag
4494 `(display ,other-tag front-sticky nil rear-nonsticky t)
4495 '(invisible t front-sticky nil rear-nonsticky t))))
4496 (add-text-properties
4497 (match-beginning 2) (match-end 2)
4498 (list
4499 'help-echo (if (or (match-end 5)
4500 (not (equal (match-string 4) "")))
4501 (concat "mouse-2: go to " (or (match-string 5)
4502 (match-string 4)))
4503 "mouse-2: go to this node")
4504 'mouse-face 'highlight)))
4505 (when (or not-fontified-p fontify-visited-p)
4506 (setq rbeg (match-beginning 2)
4507 rend (match-end 2))
4508 (put-text-property
4509 rbeg rend
4510 'font-lock-face
4511 ;; Display visited nodes in a different face
4512 (if (and Info-fontify-visited-nodes
4513 (save-match-data
4514 (let* ((node (replace-regexp-in-string
4515 "^[ \t]+" ""
4516 (replace-regexp-in-string
4517 "[ \t\n]+" " "
4518 (or (match-string-no-properties 5)
4519 (and (not (equal (match-string 4) ""))
4520 (match-string-no-properties 4))
4521 (match-string-no-properties 2)))))
4522 (external-link-p
4523 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4524 (file (if external-link-p
4525 (file-name-nondirectory
4526 (match-string-no-properties 1 node))
4527 Info-current-file))
4528 (hl Info-history-list)
4529 res)
4530 (if external-link-p
4531 (setq node (if (equal (match-string 2 node) "")
4532 "Top"
4533 (match-string-no-properties 2 node))))
4534 (while hl
4535 (if (and (string-equal node (nth 1 (car hl)))
4536 (equal file
4537 (if (and external-link-p
4538 (stringp (caar hl)))
4539 (file-name-nondirectory
4540 (caar hl))
4541 (caar hl))))
4542 (setq res (car hl) hl nil)
4543 (setq hl (cdr hl))))
4544 res))) 'info-xref-visited 'info-xref))
4545 ;; For multiline ref, unfontify newline and surrounding whitespace
4546 (save-excursion
4547 (goto-char rbeg)
4548 (save-match-data
4549 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4550 (remove-text-properties (match-beginning 0)
4551 (match-end 0)
4552 '(font-lock-face t))))))
4553 (when not-fontified-p
4554 (when (memq Info-hide-note-references '(t hide))
4555 (add-text-properties (match-beginning 3) (match-end 3)
4556 '(invisible t front-sticky nil rear-nonsticky t))
4557 ;; Unhide the file name of the external reference in parens
4558 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4559 (remove-text-properties (match-beginning 6) (match-end 6)
4560 '(invisible t front-sticky nil rear-nonsticky t)))
4561 ;; Unhide newline because hidden newlines cause too long lines
4562 (save-match-data
4563 (let ((beg3 (match-beginning 3))
4564 (end3 (match-end 3)))
4565 (if (and (string-match "\n[ \t]*" (match-string 3))
4566 (not (save-match-data
4567 (save-excursion
4568 (goto-char (1+ end3))
4569 (looking-at "[.)]*$")))))
4570 (remove-text-properties (+ beg3 (match-beginning 0))
4571 (+ beg3 (match-end 0))
4572 '(invisible t front-sticky nil rear-nonsticky t))))))
4573 (when (and Info-refill-paragraphs Info-hide-note-references)
4574 (push (set-marker (make-marker) start)
4575 paragraph-markers))))))
4576
4577 ;; Refill paragraphs (experimental feature)
4578 (when (and not-fontified-p
4579 Info-refill-paragraphs
4580 paragraph-markers)
4581 (let ((fill-nobreak-invisible t)
4582 (fill-individual-varying-indent nil)
4583 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4584 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4585 (adaptive-fill-mode nil))
4586 (goto-char (point-max))
4587 (dolist (m paragraph-markers)
4588 (when (< m (point))
4589 (goto-char m)
4590 (beginning-of-line)
4591 (let ((beg (point)))
4592 (when (zerop (forward-paragraph))
4593 (fill-individual-paragraphs beg (point) nil nil)
4594 (goto-char beg))))
4595 (set-marker m nil))))
4596
4597 ;; Fontify menu items
4598 (goto-char (point-min))
4599 (when (and (or not-fontified-p fontify-visited-p)
4600 (search-forward "\n* Menu:" nil t)
4601 ;; Don't take time to annotate huge menus
4602 Info-fontify-maximum-menu-size
4603 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4604 (let ((n 0)
4605 cont)
4606 (while (re-search-forward
4607 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4608 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4609 nil t)
4610 (when (match-beginning 1)
4611 (when not-fontified-p
4612 (setq n (1+ n))
4613 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4614 (put-text-property (match-beginning 0)
4615 (1+ (match-beginning 0))
4616 'font-lock-face 'info-menu-star)))
4617 (when not-fontified-p
4618 (add-text-properties
4619 (match-beginning 1) (match-end 1)
4620 (list
4621 'help-echo (if (and (match-end 3)
4622 (not (equal (match-string 3) "")))
4623 (concat "mouse-2: go to " (match-string 3))
4624 "mouse-2: go to this node")
4625 'mouse-face 'highlight)))
4626 (when (or not-fontified-p fontify-visited-p)
4627 (put-text-property
4628 (match-beginning 1) (match-end 1)
4629 'font-lock-face
4630 ;; Display visited menu items in a different face
4631 (if (and Info-fontify-visited-nodes
4632 (save-match-data
4633 (let* ((node (if (equal (match-string 3) "")
4634 (match-string-no-properties 1)
4635 (match-string-no-properties 3)))
4636 (external-link-p
4637 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4638 (file (if external-link-p
4639 (file-name-nondirectory
4640 (match-string-no-properties 1 node))
4641 Info-current-file))
4642 (hl Info-history-list)
4643 res)
4644 (if external-link-p
4645 (setq node (if (equal (match-string 2 node) "")
4646 "Top"
4647 (match-string-no-properties 2 node))))
4648 (while hl
4649 (if (and (string-equal node (nth 1 (car hl)))
4650 (equal file
4651 (if (and external-link-p
4652 (stringp (caar hl)))
4653 (file-name-nondirectory
4654 (caar hl))
4655 (caar hl))))
4656 (setq res (car hl) hl nil)
4657 (setq hl (cdr hl))))
4658 res))) 'info-xref-visited 'info-xref)))
4659 (when (and not-fontified-p
4660 (memq Info-hide-note-references '(t hide))
4661 (not (Info-index-node)))
4662 (put-text-property (match-beginning 2) (1- (match-end 6))
4663 'invisible t)
4664 ;; Unhide the file name in parens
4665 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4666 (remove-text-properties (match-beginning 4) (match-end 4)
4667 '(invisible t)))
4668 ;; We need a stretchable space like :align-to but with
4669 ;; a minimum value.
4670 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4671 (if (>= 22 (- (match-end 1)
4672 (match-beginning 0)))
4673 '(space :align-to 24)
4674 '(space :width 2)))
4675 (setq cont (looking-at "."))
4676 (while (and (= (forward-line 1) 0)
4677 (looking-at "\\([ \t]+\\)[^*\n]"))
4678 (put-text-property (match-beginning 1) (1- (match-end 1))
4679 'invisible t)
4680 (put-text-property (1- (match-end 1)) (match-end 1)
4681 'display
4682 (if cont
4683 '(space :align-to 26)
4684 '(space :align-to 24)))
4685 (setq cont t)))))))
4686
4687 ;; Fontify menu headers
4688 ;; Add the face `info-menu-header' to any header before a menu entry
4689 (goto-char (point-min))
4690 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4691 (put-text-property (match-beginning 0) (match-end 0)
4692 'font-lock-face 'info-menu-header)
4693 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4694 (put-text-property (match-beginning 1) (match-end 1)
4695 'font-lock-face 'info-menu-header)))
4696
4697 ;; Hide index line numbers
4698 (goto-char (point-min))
4699 (when (and not-fontified-p (Info-index-node))
4700 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4701 (put-text-property (match-beginning 0) (match-end 0)
4702 'invisible t)))
4703
4704 ;; Fontify http and ftp references
4705 (goto-char (point-min))
4706 (when not-fontified-p
4707 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4708 nil t)
4709 (add-text-properties (match-beginning 0) (match-end 0)
4710 '(font-lock-face info-xref
4711 mouse-face highlight
4712 help-echo "mouse-2: go to this URL"))))
4713
4714 (set-buffer-modified-p nil))))
4715 \f
4716 ;;; Speedbar support:
4717 ;; These functions permit speedbar to display the "tags" in the
4718 ;; current Info node.
4719 (eval-when-compile (require 'speedbar))
4720
4721 (defvar Info-speedbar-key-map nil
4722 "Keymap used when in the Info display mode.")
4723
4724 (defun Info-install-speedbar-variables ()
4725 "Install those variables used by speedbar to enhance Info."
4726 (if Info-speedbar-key-map
4727 nil
4728 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
4729
4730 ;; Basic tree features
4731 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
4732 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
4733 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
4734 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
4735 )
4736
4737 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
4738 Info-speedbar-key-map
4739 Info-speedbar-hierarchy-buttons)))
4740
4741 (defvar Info-speedbar-menu-items
4742 '(["Browse Node" speedbar-edit-line t]
4743 ["Expand Node" speedbar-expand-line
4744 (save-excursion (beginning-of-line)
4745 (looking-at "[0-9]+: *.\\+. "))]
4746 ["Contract Node" speedbar-contract-line
4747 (save-excursion (beginning-of-line)
4748 (looking-at "[0-9]+: *.-. "))]
4749 )
4750 "Additional menu-items to add to speedbar frame.")
4751
4752 ;; Make sure our special speedbar major mode is loaded
4753 (if (featurep 'speedbar)
4754 (Info-install-speedbar-variables)
4755 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4756
4757 ;;; Info hierarchy display method
4758 ;;;###autoload
4759 (defun Info-speedbar-browser ()
4760 "Initialize speedbar to display an Info node browser.
4761 This will add a speedbar major display mode."
4762 (interactive)
4763 (require 'speedbar)
4764 ;; Make sure that speedbar is active
4765 (speedbar-frame-mode 1)
4766 ;; Now, throw us into Info mode on speedbar.
4767 (speedbar-change-initial-expansion-list "Info")
4768 )
4769
4770 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
4771 "Display an Info directory hierarchy in speedbar.
4772 DIRECTORY is the current directory in the attached frame.
4773 DEPTH is the current indentation depth.
4774 NODE is an optional argument that is used to represent the
4775 specific node to expand."
4776 (if (and (not node)
4777 (save-excursion (goto-char (point-min))
4778 (let ((case-fold-search t))
4779 (looking-at "Info Nodes:"))))
4780 ;; Update our "current node" maybe?
4781 nil
4782 ;; We cannot use the generic list code, that depends on all leaves
4783 ;; being known at creation time.
4784 (if (not node)
4785 (speedbar-with-writable (insert "Info Nodes:\n")))
4786 (let ((completions nil))
4787 (speedbar-select-attached-frame)
4788 (save-window-excursion
4789 (setq completions
4790 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
4791 (select-frame (speedbar-current-frame))
4792 (if completions
4793 (speedbar-with-writable
4794 (dolist (completion completions)
4795 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
4796 (cdr completion)
4797 (car completion)
4798 'Info-speedbar-goto-node
4799 (cdr completion)
4800 'info-xref depth))
4801 t)
4802 nil))))
4803
4804 (defun Info-speedbar-goto-node (_text node _indent)
4805 "When user clicks on TEXT, go to an info NODE.
4806 The INDENT level is ignored."
4807 (speedbar-select-attached-frame)
4808 (let* ((buff (or (get-buffer "*info*")
4809 (progn (info) (get-buffer "*info*"))))
4810 (bwin (get-buffer-window buff 0)))
4811 (if bwin
4812 (progn
4813 (select-window bwin)
4814 (raise-frame (window-frame bwin)))
4815 (if speedbar-power-click
4816 (switch-to-buffer-other-frame buff)
4817 (speedbar-select-attached-frame)
4818 (switch-to-buffer buff)))
4819 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4820 (error "Invalid node %s" node)
4821 (Info-find-node (match-string 1 node) (match-string 2 node))
4822 ;; If we do a find-node, and we were in info mode, restore
4823 ;; the old default method. Once we are in info mode, it makes
4824 ;; sense to return to whatever method the user was using before.
4825 (if (string= speedbar-initial-expansion-list-name "Info")
4826 (speedbar-change-initial-expansion-list
4827 speedbar-previously-used-expansion-list-name)))))
4828
4829 (defun Info-speedbar-expand-node (text token indent)
4830 "Expand the node the user clicked on.
4831 TEXT is the text of the button we clicked on, a + or - item.
4832 TOKEN is data related to this node (NAME . FILE).
4833 INDENT is the current indentation depth."
4834 (cond ((string-match "+" text) ;we have to expand this file
4835 (speedbar-change-expand-button-char ?-)
4836 (if (speedbar-with-writable
4837 (save-excursion
4838 (end-of-line) (forward-char 1)
4839 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4840 (speedbar-change-expand-button-char ?-)
4841 (speedbar-change-expand-button-char ??)))
4842 ((string-match "-" text) ;we have to contract this node
4843 (speedbar-change-expand-button-char ?+)
4844 (speedbar-delete-subblock indent))
4845 (t (error "Ooops... not sure what to do")))
4846 (speedbar-center-buffer-smartly))
4847
4848 (defun Info-speedbar-fetch-file-nodes (nodespec)
4849 "Fetch the subnodes from the info NODESPEC.
4850 NODESPEC is a string of the form: (file)node."
4851 ;; Set up a buffer we can use to fake-out Info.
4852 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
4853 (if (not (equal major-mode 'Info-mode))
4854 (Info-mode))
4855 ;; Get the node into this buffer
4856 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4857 (error "Invalid node specification %s" nodespec)
4858 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4859 ;; Scan the created buffer
4860 (goto-char (point-min))
4861 (let ((completions nil)
4862 (case-fold-search t)
4863 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4864 (match-string 1 nodespec))))
4865 ;; Always skip the first one...
4866 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4867 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4868 (let ((name (match-string 1)))
4869 (push (cons name
4870 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4871 (match-string 1)
4872 (if (looking-at " *\\(([^)]+)\\)\\.")
4873 (concat (match-string 1) "Top")
4874 (concat "(" thisfile ")"
4875 (if (looking-at " \\([^.]+\\).")
4876 (match-string 1)
4877 name)))))
4878 completions)))
4879 (nreverse completions))))
4880
4881 ;;; Info mode node listing
4882 ;; This is called by `speedbar-add-localized-speedbar-support'
4883 (defun Info-speedbar-buttons (_buffer)
4884 "Create a speedbar display to help navigation in an Info file.
4885 BUFFER is the buffer speedbar is requesting buttons for."
4886 (if (save-excursion (goto-char (point-min))
4887 (let ((case-fold-search t))
4888 (not (looking-at "Info Nodes:"))))
4889 (erase-buffer))
4890 (Info-speedbar-hierarchy-buttons nil 0))
4891
4892 (dolist (mess '("^First node in file$"
4893 "^No `.*' in index$"
4894 "^No cross-reference named"
4895 "^No cross.references in this node$"
4896 "^No current Info node$"
4897 "^No menu in this node$"
4898 "^No more items in menu$"
4899 "^No more nodes$"
4900 "^No pointer \\(?:forward\\|backward\\) from this node$"
4901 "^No previous `i' command$"
4902 "^No previous items in menu$"
4903 "^No previous nodes$"
4904 "^No such item in menu$"
4905 "^No such node or anchor"
4906 "^Node has no"
4907 "^Point neither on reference nor in menu item description$"
4908 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4909 search-failed))
4910 (add-to-list 'debug-ignored-errors mess))
4911
4912 ;;;; Desktop support
4913
4914 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
4915 "Auxiliary information to be saved in desktop file."
4916 (list Info-current-file
4917 Info-current-node
4918 ;; Additional data as an association list.
4919 (delq nil (list
4920 (and Info-history
4921 (cons 'history Info-history))
4922 (and (Info-virtual-fun
4923 'slow Info-current-file Info-current-node)
4924 (cons 'slow t))))))
4925
4926 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
4927 desktop-buffer-name
4928 desktop-buffer-misc)
4929 "Restore an Info buffer specified in a desktop file."
4930 (let* ((file (nth 0 desktop-buffer-misc))
4931 (node (nth 1 desktop-buffer-misc))
4932 (data (nth 2 desktop-buffer-misc))
4933 (hist (assq 'history data))
4934 (slow (assq 'slow data)))
4935 ;; Don't restore nodes slow to regenerate.
4936 (unless slow
4937 (when (and file node)
4938 (when desktop-buffer-name
4939 (set-buffer (get-buffer-create desktop-buffer-name))
4940 (Info-mode))
4941 (Info-find-node file node)
4942 (when hist
4943 (setq Info-history (cdr hist)))
4944 (current-buffer)))))
4945
4946 (add-to-list 'desktop-buffer-mode-handlers
4947 '(Info-mode . Info-restore-desktop-buffer))
4948
4949 ;;;; Bookmark support
4950 (declare-function bookmark-make-record-default
4951 "bookmark" (&optional no-file no-context posn))
4952 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
4953 (declare-function bookmark-default-handler "bookmark" (bmk))
4954 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
4955
4956 (defun Info-bookmark-make-record ()
4957 "This implements the `bookmark-make-record-function' type (which see)
4958 for Info nodes."
4959 `(,Info-current-node
4960 ,@(bookmark-make-record-default 'no-file)
4961 (filename . ,Info-current-file)
4962 (info-node . ,Info-current-node)
4963 (handler . Info-bookmark-jump)))
4964
4965 ;;;###autoload
4966 (defun Info-bookmark-jump (bmk)
4967 "This implements the `handler' function interface for the record
4968 type returned by `Info-bookmark-make-record', which see."
4969 (let* ((file (bookmark-prop-get bmk 'filename))
4970 (info-node (bookmark-prop-get bmk 'info-node))
4971 (buf (save-window-excursion ;FIXME: doesn't work with frames!
4972 (Info-find-node file info-node) (current-buffer))))
4973 ;; Use bookmark-default-handler to move to the appropriate location
4974 ;; within the node.
4975 (bookmark-default-handler
4976 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
4977
4978 \f
4979 ;;;###autoload
4980 (defun info-display-manual (manual)
4981 "Go to Info buffer that displays MANUAL, creating it if none already exists."
4982 (interactive "sManual name: ")
4983 (let ((blist (buffer-list))
4984 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
4985 (case-fold-search t)
4986 found)
4987 (dolist (buffer blist)
4988 (with-current-buffer buffer
4989 (when (and (eq major-mode 'Info-mode)
4990 (stringp Info-current-file)
4991 (string-match manual-re Info-current-file))
4992 (setq found buffer
4993 blist nil))))
4994 (if found
4995 (switch-to-buffer found)
4996 (info-initialize)
4997 (info (Info-find-file manual)))))
4998
4999 (provide 'info)
5000
5001 ;;; info.el ends here