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