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