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