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