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