]> code.delx.au - gnu-emacs/blob - lisp/info.el
Add new maintainer (deego).
[gnu-emacs] / lisp / info.el
1 ;;; info.el --- info package for Emacs
2
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002
4 ;; 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 2, 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., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Note that nowadays we expect info files to be made using makeinfo.
29
30 ;;; Code:
31
32 (eval-when-compile (require 'jka-compr))
33
34 (defgroup info nil
35 "Info subsystem"
36 :group 'help
37 :group 'docs)
38
39
40 (defvar Info-history nil
41 "List of info nodes user has visited.
42 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
43
44 (defcustom Info-enable-edit nil
45 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
46 This is convenient if you want to write info files by hand.
47 However, we recommend that you not do this.
48 It is better to write a Texinfo file and generate the Info file from that,
49 because that gives you a printed manual as well."
50 :type 'boolean
51 :group 'info)
52
53 (defvar Info-enable-active-nodes nil
54 "Non-nil allows Info to execute Lisp code associated with nodes.
55 The Lisp code is executed when the node is selected.")
56 (put 'Info-enable-active-nodes 'risky-local-variable t)
57
58 (defface info-node
59 '((((class color) (background light)) (:foreground "brown" :weight bold :slant italic))
60 (((class color) (background dark)) (:foreground "white" :weight bold :slant italic))
61 (t (:weight bold :slant italic)))
62 "Face for Info node names."
63 :group 'info)
64
65 (defface info-menu-5
66 '((((class color)) (:foreground "red1"))
67 (t (:underline t)))
68 "Face for every third `*' in an Info menu."
69 :group 'info)
70
71 (defface info-xref
72 '((((class color) (background light)) (:foreground "magenta4" :weight bold))
73 (((class color) (background dark)) (:foreground "cyan" :weight bold))
74 (t (:weight bold)))
75 "Face for Info cross-references."
76 :group 'info)
77
78 (defcustom Info-fontify-maximum-menu-size 100000
79 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
80 :type 'integer
81 :group 'info)
82
83 (defcustom Info-use-header-line t
84 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
85 A header-line does not scroll with the rest of the buffer."
86 :type 'boolean
87 :group 'info)
88
89 (defface info-header-xref
90 '((t (:inherit info-xref)))
91 "Face for Info cross-references in a node header."
92 :group 'info)
93
94 (defface info-header-node
95 '((t (:inherit info-node)))
96 "Face for Info nodes in a node header."
97 :group 'info)
98
99 (defvar Info-directory-list nil
100 "List of directories to search for Info documentation files.
101 If nil, meaning not yet initialized, Info uses the environment
102 variable INFOPATH to initialize it, or `Info-default-directory-list'
103 if there is no INFOPATH variable in the environment.
104
105 When `Info-directory-list' is initialized from the value of
106 `Info-default-directory-list', and Emacs is installed in one of the
107 standard directories, the directory of Info files that come with Emacs
108 is put last (so that local Info files override standard ones).
109
110 When `Info-directory-list' is initialized from the value of
111 `Info-default-directory-list', and Emacs is not installed in one
112 of the standard directories, the first element of the resulting
113 list is the directory where Emacs installs the Info files that
114 come with it. This is so that Emacs's own manual, which suits the
115 version of Emacs you are using, will always be found first. This
116 is useful when you install an experimental version of Emacs without
117 removing the standard installation.
118
119 If you want to override the order of directories in
120 `Info-default-directory-list', set INFOPATH in the environment.
121
122 If you run the Emacs executable from the `src' directory in the Emacs
123 source tree, and INFOPATH is not defined, the `info' directory in the
124 source tree is used as the first element of `Info-directory-list', in
125 place of the installation Info directory. This is useful when you run
126 a version of Emacs without installing it.")
127
128 (defcustom Info-additional-directory-list nil
129 "List of additional directories to search for Info documentation files.
130 These directories are searched after those in `Info-directory-list'."
131 :type '(repeat directory)
132 :group 'info)
133
134 (defcustom Info-scroll-prefer-subnodes t
135 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
136 If this is non-nil, and you scroll far enough in a node that its menu
137 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
138 moves to a subnode indicated by the following menu item. This means
139 that you visit a subnode before getting to the end of the menu.
140
141 Setting this option to nil results in behavior similar to the stand-alone
142 Info reader program, which visits the first subnode from the menu only
143 when you hit the end of the current node."
144 :type 'boolean
145 :group 'info)
146
147 (defcustom Info-hide-note-references t
148 "*If non-nil, hide the tag and section reference in *note and * menu items.
149 Also replaces the \"*note\" text with \"see\".
150 If value is a number, the reference section is still shown."
151 :version "21.4"
152 :type '(choice (const :tag "Replace tag and hide reference" t)
153 (const :tag "Replace only tag" tag)
154 (const :tag "No reformatting" nil))
155 :group 'info)
156
157 (defcustom Info-mode-hook '(turn-on-font-lock)
158 "Hooks run when `info-mode' is called."
159 :type 'hook
160 :group 'info)
161
162 (defvar Info-current-file nil
163 "Info file that Info is now looking at, or nil.
164 This is the name that was specified in Info, not the actual file name.
165 It doesn't contain directory names or file name extensions added by Info.
166 Can also be t when using `Info-on-current-buffer'.")
167
168 (defvar Info-current-subfile nil
169 "Info subfile that is actually in the *info* buffer now.
170 nil if current info file is not split into subfiles.")
171
172 (defvar Info-current-node nil
173 "Name of node that Info is now looking at, or nil.")
174
175 (defvar Info-tag-table-marker nil
176 "Marker pointing at beginning of current Info file's tag table.
177 Marker points nowhere if file has no tag table.")
178
179 (defvar Info-tag-table-buffer nil
180 "Buffer used for indirect tag tables.")
181
182 (defvar Info-current-file-completions nil
183 "Cached completion list for current Info file.")
184
185 (defvar Info-index-alternatives nil
186 "List of possible matches for last `Info-index' command.")
187
188 (defvar Info-standalone nil
189 "Non-nil if Emacs was started solely as an Info browser.")
190 \f
191 (defvar Info-suffix-list
192 ;; The MS-DOS list should work both when long file names are
193 ;; supported (Windows 9X), and when only 8+3 file names are available.
194 (if (eq system-type 'ms-dos)
195 '( (".gz" . "gunzip")
196 (".z" . "gunzip")
197 (".bz2" . ("bzip2" "-dc"))
198 (".inz" . "gunzip")
199 (".igz" . "gunzip")
200 (".info.Z" . "gunzip")
201 (".info.gz" . "gunzip")
202 ("-info.Z" . "gunzip")
203 ("-info.gz" . "gunzip")
204 ("/index.gz". "gunzip")
205 ("/index.z" . "gunzip")
206 (".inf" . nil)
207 (".info" . nil)
208 ("-info" . nil)
209 ("/index" . nil)
210 ("" . nil))
211 '( (".info.Z". "uncompress")
212 (".info.Y". "unyabba")
213 (".info.gz". "gunzip")
214 (".info.z". "gunzip")
215 (".info.bz2" . ("bzip2" "-dc"))
216 (".info". nil)
217 ("-info.Z". "uncompress")
218 ("-info.Y". "unyabba")
219 ("-info.gz". "gunzip")
220 ("-info.bz2" . ("bzip2" "-dc"))
221 ("-info.z". "gunzip")
222 ("-info". nil)
223 ("/index.Z". "uncompress")
224 ("/index.Y". "unyabba")
225 ("/index.gz". "gunzip")
226 ("/index.z". "gunzip")
227 ("/index.bz2". ("bzip2" "-dc"))
228 ("/index". nil)
229 (".Z". "uncompress")
230 (".Y". "unyabba")
231 (".gz". "gunzip")
232 (".z". "gunzip")
233 (".bz2" . ("bzip2" "-dc"))
234 ("". nil)))
235 "List of file name suffixes and associated decoding commands.
236 Each entry should be (SUFFIX . STRING); the file is given to
237 the command as standard input.
238
239 STRING may be a list of strings. In that case, the first element is
240 the command name, and the rest are arguments to that command.
241
242 If STRING is nil, no decoding is done.
243 Because the SUFFIXes are tried in order, the empty string should
244 be last in the list.")
245
246 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
247 ;; First, on MS-DOS with no long file names support, delete some of
248 ;; the extension in FILENAME to make room.
249 (defun info-insert-file-contents-1 (filename suffix lfn)
250 (if lfn ; long file names are supported
251 (concat filename suffix)
252 (let* ((sans-exts (file-name-sans-extension filename))
253 ;; How long is the extension in FILENAME (not counting the dot).
254 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
255 ext-left)
256 ;; SUFFIX starts with a dot. If FILENAME already has one,
257 ;; get rid of the one in SUFFIX (unless suffix is empty).
258 (or (and (<= ext-len 0)
259 (not (eq (aref filename (1- (length filename))) ?.)))
260 (= (length suffix) 0)
261 (setq suffix (substring suffix 1)))
262 ;; How many chars of that extension should we keep?
263 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
264 ;; Get rid of the rest of the extension, and add SUFFIX.
265 (concat (substring filename 0 (- (length filename)
266 (- ext-len ext-left)))
267 suffix))))
268
269 (defun info-file-exists-p (filename)
270 (and (file-exists-p filename)
271 (not (file-directory-p filename))))
272
273 (defun info-insert-file-contents (filename &optional visit)
274 "Insert the contents of an info file in the current buffer.
275 Do the right thing if the file has been compressed or zipped."
276 (let* ((tail Info-suffix-list)
277 (lfn (or (not (fboundp 'msdos-long-file-names))
278 (msdos-long-file-names)))
279 (check-short (and (fboundp 'msdos-long-file-names)
280 lfn))
281 fullname decoder done)
282 (if (info-file-exists-p filename)
283 ;; FILENAME exists--see if that name contains a suffix.
284 ;; If so, set DECODE accordingly.
285 (progn
286 (while (and tail
287 (not (string-match
288 (concat (regexp-quote (car (car tail))) "$")
289 filename)))
290 (setq tail (cdr tail)))
291 (setq fullname filename
292 decoder (cdr (car tail))))
293 ;; Try adding suffixes to FILENAME and see if we can find something.
294 (while (and tail (not done))
295 (setq fullname (info-insert-file-contents-1 filename
296 (car (car tail)) lfn))
297 (if (info-file-exists-p fullname)
298 (setq done t
299 ;; If we found a file with a suffix, set DECODER
300 ;; according to the suffix.
301 decoder (cdr (car tail)))
302 ;; When the MS-DOS port runs on Windows, we need to check
303 ;; the short variant of a long file name as well.
304 (when check-short
305 (setq fullname (info-insert-file-contents-1 filename
306 (car (car tail)) nil))
307 (if (info-file-exists-p fullname)
308 (setq done t
309 decoder (cdr (car tail))))))
310 (setq tail (cdr tail)))
311 (or tail
312 (error "Can't find %s or any compressed version of it" filename)))
313 ;; check for conflict with jka-compr
314 (if (and (featurep 'jka-compr)
315 (jka-compr-installed-p)
316 (jka-compr-get-compression-info fullname))
317 (setq decoder nil))
318 (if decoder
319 (progn
320 (insert-file-contents-literally fullname visit)
321 (let ((buffer-read-only nil)
322 (coding-system-for-write 'no-conversion)
323 (default-directory (or (file-name-directory fullname)
324 default-directory)))
325 (or (consp decoder)
326 (setq decoder (list decoder)))
327 (apply 'call-process-region (point-min) (point-max)
328 (car decoder) t t nil (cdr decoder))))
329 (insert-file-contents fullname visit))))
330 \f
331 (defun info-initialize ()
332 "Initialize `Info-directory-list', if that hasn't been done yet."
333 (unless Info-directory-list
334 (let ((path (getenv "INFOPATH"))
335 (source (expand-file-name "info/" source-directory))
336 (sibling (if installation-directory
337 (expand-file-name "info/" installation-directory)
338 (if invocation-directory
339 (let ((infodir (expand-file-name
340 "../info/"
341 invocation-directory)))
342 (if (file-exists-p infodir)
343 infodir
344 (setq infodir (expand-file-name
345 "../../../info/"
346 invocation-directory))
347 (and (file-exists-p infodir)
348 infodir))))))
349 alternative)
350 (setq Info-directory-list
351 (prune-directory-list
352 (if path
353 (split-string path (regexp-quote path-separator))
354 (if (and sibling (file-exists-p sibling))
355 ;; Uninstalled, Emacs builddir != srcdir.
356 (setq alternative sibling)
357 ;; Uninstalled, builddir == srcdir
358 (setq alternative source))
359 (if (or (member alternative Info-default-directory-list)
360 ;; On DOS/NT, we use movable executables always,
361 ;; and we must always find the Info dir at run time.
362 (if (memq system-type '(ms-dos windows-nt))
363 nil
364 ;; Use invocation-directory for Info
365 ;; only if we used it for exec-directory also.
366 (not (string= exec-directory
367 (expand-file-name "lib-src/"
368 installation-directory))))
369 (not (file-exists-p alternative)))
370 Info-default-directory-list
371 ;; `alternative' contains the Info files that came with this
372 ;; version, so we should look there first. `Info-insert-dir'
373 ;; currently expects to find `alternative' first on the list.
374 (cons alternative
375 (reverse (cdr (reverse Info-default-directory-list)))))))))))
376
377 ;;;###autoload
378 (defun info-other-window (&optional file)
379 "Like `info' but show the Info buffer in another window."
380 (interactive (if current-prefix-arg
381 (list (read-file-name "Info file name: " nil nil t))))
382 (let (same-window-buffer-names)
383 (info file)))
384
385 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
386
387 ;;;###autoload
388 (defun info (&optional file)
389 "Enter Info, the documentation browser.
390 Optional argument FILE specifies the file to examine;
391 the default is the top-level directory of Info.
392 Called from a program, FILE may specify an Info node of the form
393 `(FILENAME)NODENAME'.
394
395 In interactive use, a prefix argument directs this command
396 to read a file name from the minibuffer.
397
398 The search path for Info files is in the variable `Info-directory-list'.
399 The top-level Info directory is made by combining all the files named `dir'
400 in all the directories in that path."
401 (interactive (if current-prefix-arg
402 (list (read-file-name "Info file name: " nil nil t))))
403 (if file
404 (progn
405 (pop-to-buffer "*info*")
406 ;; If argument already contains parentheses, don't add another set
407 ;; since the argument will then be parsed improperly. This also
408 ;; has the added benefit of allowing node names to be included
409 ;; following the parenthesized filename.
410 (if (and (stringp file) (string-match "(.*)" file))
411 (Info-goto-node file)
412 (Info-goto-node (concat "(" file ")"))))
413 (if (get-buffer "*info*")
414 (pop-to-buffer "*info*")
415 (Info-directory))))
416
417 ;;;###autoload
418 (defun info-emacs-manual ()
419 "Display the Emacs manual in Info mode."
420 (interactive)
421 (info "emacs"))
422
423 ;;;###autoload
424 (defun info-standalone ()
425 "Run Emacs as a standalone Info reader.
426 Usage: emacs -f info-standalone [filename]
427 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
428 (setq Info-standalone t)
429 (if (and command-line-args-left
430 (not (string-match "^-" (car command-line-args-left))))
431 (condition-case err
432 (progn
433 (info (car command-line-args-left))
434 (setq command-line-args-left (cdr command-line-args-left)))
435 (error (send-string-to-terminal
436 (format "%s\n" (if (eq (car-safe err) 'error)
437 (nth 1 err) err)))
438 (save-buffers-kill-emacs)))
439 (info)))
440 \f
441 ;; See if the accessible portion of the buffer begins with a node
442 ;; delimiter, and the node header line which follows matches REGEXP.
443 ;; Typically, this test will be followed by a loop that examines the
444 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
445 ;; to have the overhead of this special test inside the loop.
446
447 ;; This function changes match-data, but supposedly the caller might
448 ;; want to use the results of re-search-backward.
449
450 ;; The return value is the value of point at the beginning of matching
451 ;; REGEXP, if the function succeeds, nil otherwise.
452 (defun Info-node-at-bob-matching (regexp)
453 (and (bobp) ; are we at beginning of buffer?
454 (looking-at "\^_") ; does it begin with node delimiter?
455 (let (beg)
456 (forward-line 1)
457 (setq beg (point))
458 (forward-line 1) ; does the line after delimiter match REGEXP?
459 (re-search-backward regexp beg t))))
460
461 (defun Info-find-node (filename nodename &optional no-going-back)
462 "Go to an info node specified as separate FILENAME and NODENAME.
463 NO-GOING-BACK is non-nil if recovering from an error in this function;
464 it says do not attempt further (recursive) error recovery."
465 (info-initialize)
466 ;; Convert filename to lower case if not found as specified.
467 ;; Expand it.
468 (if (stringp filename)
469 (let (temp temp-downcase found)
470 (setq filename (substitute-in-file-name filename))
471 (if (string= (downcase filename) "dir")
472 (setq found t)
473 (let ((dirs (if (string-match "^\\./" filename)
474 ;; If specified name starts with `./'
475 ;; then just try current directory.
476 '("./")
477 (if (file-name-absolute-p filename)
478 ;; No point in searching for an
479 ;; absolute file name
480 '(nil)
481 (if Info-additional-directory-list
482 (append Info-directory-list
483 Info-additional-directory-list)
484 Info-directory-list)))))
485 ;; Search the directory list for file FILENAME.
486 (while (and dirs (not found))
487 (setq temp (expand-file-name filename (car dirs)))
488 (setq temp-downcase
489 (expand-file-name (downcase filename) (car dirs)))
490 ;; Try several variants of specified name.
491 (let ((suffix-list Info-suffix-list)
492 (lfn (or (not (fboundp 'msdos-long-file-names))
493 (msdos-long-file-names))))
494 (while (and suffix-list (not found))
495 (cond ((info-file-exists-p
496 (info-insert-file-contents-1
497 temp (car (car suffix-list)) lfn))
498 (setq found temp))
499 ((info-file-exists-p
500 (info-insert-file-contents-1
501 temp-downcase (car (car suffix-list)) lfn))
502 (setq found temp-downcase))
503 ((and (fboundp 'msdos-long-file-names)
504 lfn
505 (info-file-exists-p
506 (info-insert-file-contents-1
507 temp (car (car suffix-list)) nil)))
508 (setq found temp)))
509 (setq suffix-list (cdr suffix-list))))
510 (setq dirs (cdr dirs)))))
511 (if found
512 (setq filename found)
513 (error "Info file %s does not exist" filename))))
514 ;; Record the node we are leaving.
515 (if (and Info-current-file (not no-going-back))
516 (setq Info-history
517 (cons (list Info-current-file Info-current-node (point))
518 Info-history)))
519 ;; Go into info buffer.
520 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
521 (Info-find-node-2 filename nodename no-going-back))
522
523 (defun Info-on-current-buffer (&optional nodename)
524 "Use the `Info-mode' to browse the current info buffer.
525 If a prefix arg is provided, it queries for the NODENAME which
526 else defaults to \"Top\"."
527 (interactive
528 (list (if current-prefix-arg
529 (completing-read "Node name: " (Info-build-node-completions)
530 nil t "Top"))))
531 (unless nodename (setq nodename "Top"))
532 (info-initialize)
533 (Info-mode)
534 (set (make-local-variable 'Info-current-file) t)
535 (Info-find-node-2 nil nodename))
536
537 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
538 ;; but at least it keeps this routine (which is only for the benefit of
539 ;; makeinfo-buffer) out of the way of normal operations.
540 ;;
541 (defun Info-revert-find-node (filename nodename)
542 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
543 When *info* is already displaying FILENAME and NODENAME, the window position
544 is preserved, if possible."
545 (pop-to-buffer "*info*")
546 (let ((old-filename Info-current-file)
547 (old-nodename Info-current-node)
548 (pcolumn (current-column))
549 (pline (count-lines (point-min) (line-beginning-position)))
550 (wline (count-lines (point-min) (window-start)))
551 (old-history Info-history)
552 (new-history (and Info-current-file
553 (list Info-current-file Info-current-node (point)))))
554 (kill-buffer (current-buffer))
555 (Info-find-node filename nodename)
556 (setq Info-history old-history)
557 (if (and (equal old-filename Info-current-file)
558 (equal old-nodename Info-current-node))
559 (progn
560 ;; note goto-line is no good, we want to measure from point-min
561 (beginning-of-buffer)
562 (forward-line wline)
563 (set-window-start (selected-window) (point))
564 (beginning-of-buffer)
565 (forward-line pline)
566 (move-to-column pcolumn))
567 ;; only add to the history when coming from a different file+node
568 (if new-history
569 (setq Info-history (cons new-history Info-history))))))
570
571 (defun Info-find-in-tag-table-1 (marker regexp case-fold)
572 "Find a node in a tag table.
573 MARKER specifies the buffer and position to start searching at.
574 REGEXP is a regular expression matching nodes or references. Its first
575 group should match `Node:' or `Ref:'.
576 CASE-FOLD t means search for a case-insensitive match.
577 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
578 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
579 where the match was found, and MODE is `major-mode' of the buffer in
580 which the match was found."
581 (let ((case-fold-search case-fold)
582 found-mode guesspos found-anchor)
583 (save-excursion
584 (set-buffer (marker-buffer marker))
585 (goto-char marker)
586
587 ;; Search tag table
588 (beginning-of-line)
589 (when (re-search-forward regexp nil t)
590 (list (string-equal "Ref:" (match-string 1))
591 (+ (point-min) (read (current-buffer)))
592 major-mode)))))
593
594 (defun Info-find-in-tag-table (marker regexp)
595 "Find a node in a tag table.
596 MARKER specifies the buffer and position to start searching at.
597 REGEXP is a regular expression matching nodes or references. Its first
598 group should match `Node:' or `Ref:'.
599 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
600 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
601 where the match was found, and MODE is `major-mode' of the buffer in
602 which the match was found.
603 This function tries to find a case-sensitive match first, then a
604 case-insensitive match is tried."
605 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
606 (when (null (car result))
607 (setq result (Info-find-in-tag-table-1 marker regexp t)))
608 result))
609
610 (defun Info-find-node-in-buffer-1 (regexp case-fold)
611 "Find a node or anchor in the current buffer.
612 REGEXP is a regular expression matching nodes or references. Its first
613 group should match `Node:' or `Ref:'.
614 CASE-FOLD t means search for a case-insensitive match.
615 Value is the position at which a match was found, or nil if not found."
616 (let ((case-fold-search case-fold)
617 found)
618 (save-excursion
619 (when (Info-node-at-bob-matching regexp)
620 (setq found (point)))
621 (while (and (not found)
622 (search-forward "\n\^_" nil t))
623 (forward-line 1)
624 (let ((beg (point)))
625 (forward-line 1)
626 (when (re-search-backward regexp beg t)
627 (beginning-of-line)
628 (setq found (point)))))
629 found)))
630
631 (defun Info-find-node-in-buffer (regexp)
632 "Find a node or anchor in the current buffer.
633 REGEXP is a regular expression matching nodes or references. Its first
634 group should match `Node:' or `Ref:'.
635 Value is the position at which a match was found, or nil if not found.
636 This function looks for a case-sensitive match first. If none is found,
637 a case-insensitive match is tried."
638 (or (Info-find-node-in-buffer-1 regexp nil)
639 (Info-find-node-in-buffer-1 regexp t)))
640
641 (defun Info-find-node-2 (filename nodename &optional no-going-back)
642 (buffer-disable-undo (current-buffer))
643 (or (eq major-mode 'Info-mode)
644 (Info-mode))
645 (widen)
646 (setq Info-current-node nil)
647 (unwind-protect
648 (let ((case-fold-search t)
649 anchorpos)
650 ;; Switch files if necessary
651 (or (null filename)
652 (equal Info-current-file filename)
653 (let ((buffer-read-only nil))
654 (setq Info-current-file nil
655 Info-current-subfile nil
656 Info-current-file-completions nil
657 buffer-file-name nil)
658 (erase-buffer)
659 (if (eq filename t)
660 (Info-insert-dir)
661 (info-insert-file-contents filename nil)
662 (setq default-directory (file-name-directory filename)))
663 (set-buffer-modified-p nil)
664 ;; See whether file has a tag table. Record the location if yes.
665 (goto-char (point-max))
666 (forward-line -8)
667 ;; Use string-equal, not equal, to ignore text props.
668 (if (not (or (string-equal nodename "*")
669 (not
670 (search-forward "\^_\nEnd tag table\n" nil t))))
671 (let (pos)
672 ;; We have a tag table. Find its beginning.
673 ;; Is this an indirect file?
674 (search-backward "\nTag table:\n")
675 (setq pos (point))
676 (if (save-excursion
677 (forward-line 2)
678 (looking-at "(Indirect)\n"))
679 ;; It is indirect. Copy it to another buffer
680 ;; and record that the tag table is in that buffer.
681 (let ((buf (current-buffer))
682 (tagbuf
683 (or Info-tag-table-buffer
684 (generate-new-buffer " *info tag table*"))))
685 (setq Info-tag-table-buffer tagbuf)
686 (save-excursion
687 (set-buffer tagbuf)
688 (buffer-disable-undo (current-buffer))
689 (setq case-fold-search t)
690 (erase-buffer)
691 (insert-buffer-substring buf))
692 (set-marker Info-tag-table-marker
693 (match-end 0) tagbuf))
694 (set-marker Info-tag-table-marker pos)))
695 (set-marker Info-tag-table-marker nil))
696 (setq Info-current-file
697 (if (eq filename t) "dir" filename))))
698 ;; Use string-equal, not equal, to ignore text props.
699 (if (string-equal nodename "*")
700 (progn (setq Info-current-node nodename)
701 (Info-set-mode-line))
702 ;; Possibilities:
703 ;;
704 ;; 1. Anchor found in tag table
705 ;; 2. Anchor *not* in tag table
706 ;;
707 ;; 3. Node found in tag table
708 ;; 4. Node *not* found in tag table, but found in file
709 ;; 5. Node *not* in tag table, and *not* in file
710 ;;
711 ;; *Or* the same, but in an indirect subfile.
712
713 ;; Search file for a suitable node.
714 (let ((guesspos (point-min))
715 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
716 (if (stringp nodename)
717 (regexp-quote nodename)
718 "")
719 "\\) *[,\t\n\177]"))
720 (nodepos nil))
721
722 (catch 'foo
723
724 ;; First, search a tag table, if any
725 (when (marker-position Info-tag-table-marker)
726 (let* ((m Info-tag-table-marker)
727 (found (Info-find-in-tag-table m regexp)))
728
729 (when found
730 ;; FOUND is (ANCHOR POS MODE).
731 (setq guesspos (nth 1 found))
732
733 ;; If this is an indirect file, determine which
734 ;; file really holds this node and read it in.
735 (unless (eq (nth 2 found) 'Info-mode)
736 ;; Note that the current buffer must be the
737 ;; *info* buffer on entry to
738 ;; Info-read-subfile. Thus the hackery above.
739 (setq guesspos (Info-read-subfile guesspos)))
740
741 ;; Handle anchor
742 (when (nth 0 found)
743 (goto-char (setq anchorpos guesspos))
744 (throw 'foo t)))))
745
746 ;; Else we may have a node, which we search for:
747 (goto-char (max (point-min)
748 (- (byte-to-position guesspos) 1000)))
749
750 ;; Now search from our advised position (or from beg of
751 ;; buffer) to find the actual node. First, check
752 ;; whether the node is right where we are, in case the
753 ;; buffer begins with a node.
754 (let ((pos (Info-find-node-in-buffer regexp)))
755 (when pos
756 (goto-char pos)
757 (throw 'foo t))
758 (error "No such anchor in tag table or node in tag table or file: %s"
759 nodename)))
760
761 (Info-select-node)
762 (goto-char (or anchorpos (point-min))))))
763 ;; If we did not finish finding the specified node,
764 ;; go back to the previous one.
765 (or Info-current-node no-going-back (null Info-history)
766 (let ((hist (car Info-history)))
767 (setq Info-history (cdr Info-history))
768 (Info-find-node (nth 0 hist) (nth 1 hist) t)
769 (goto-char (nth 2 hist))))))
770
771 ;; Cache the contents of the (virtual) dir file, once we have merged
772 ;; it for the first time, so we can save time subsequently.
773 (defvar Info-dir-contents nil)
774
775 ;; Cache for the directory we decided to use for the default-directory
776 ;; of the merged dir text.
777 (defvar Info-dir-contents-directory nil)
778
779 ;; Record the file attributes of all the files from which we
780 ;; constructed Info-dir-contents.
781 (defvar Info-dir-file-attributes nil)
782
783 (defvar Info-dir-file-name nil)
784
785 ;; Construct the Info directory node by merging the files named `dir'
786 ;; from various directories. Set the *info* buffer's
787 ;; default-directory to the first directory we actually get any text
788 ;; from.
789 (defun Info-insert-dir ()
790 (if (and Info-dir-contents Info-dir-file-attributes
791 ;; Verify that none of the files we used has changed
792 ;; since we used it.
793 (eval (cons 'and
794 (mapcar (lambda (elt)
795 (let ((curr (file-attributes
796 ;; Handle symlinks
797 (file-truename (car elt)))))
798
799 ;; Don't compare the access time.
800 (if curr (setcar (nthcdr 4 curr) 0))
801 (setcar (nthcdr 4 (cdr elt)) 0)
802 (equal (cdr elt) curr)))
803 Info-dir-file-attributes))))
804 (progn
805 (insert Info-dir-contents)
806 (goto-char (point-min)))
807 (let ((dirs (if Info-additional-directory-list
808 (append Info-directory-list
809 Info-additional-directory-list)
810 Info-directory-list))
811 (dir-file-attrs nil)
812 ;; Bind this in case the user sets it to nil.
813 (case-fold-search t)
814 ;; This is set non-nil if we find a problem in some input files.
815 problems
816 buffers buffer others nodes dirs-done)
817
818 ;; Search the directory list for the directory file.
819 (while dirs
820 (let ((truename (file-truename (expand-file-name (car dirs)))))
821 (or (member truename dirs-done)
822 (member (directory-file-name truename) dirs-done)
823 ;; Try several variants of specified name.
824 ;; Try upcasing, appending `.info', or both.
825 (let* (file
826 (attrs
827 (or
828 (progn (setq file (expand-file-name "dir" truename))
829 (file-attributes file))
830 (progn (setq file (expand-file-name "DIR" truename))
831 (file-attributes file))
832 (progn (setq file (expand-file-name "dir.info" truename))
833 (file-attributes file))
834 (progn (setq file (expand-file-name "DIR.INFO" truename))
835 (file-attributes file)))))
836 (setq dirs-done
837 (cons truename
838 (cons (directory-file-name truename)
839 dirs-done)))
840 (if attrs
841 (save-excursion
842 (or buffers
843 (message "Composing main Info directory..."))
844 (set-buffer (generate-new-buffer " info dir"))
845 (condition-case nil
846 (progn
847 (insert-file-contents file)
848 (set (make-local-variable 'Info-dir-file-name)
849 file)
850 (push (current-buffer) buffers)
851 (push (cons file attrs) dir-file-attrs))
852 (error (kill-buffer (current-buffer))))))))
853 (unless (cdr dirs)
854 (set (make-local-variable 'Info-dir-contents-directory)
855 (file-name-as-directory (car dirs))))
856 (setq dirs (cdr dirs))))
857
858 (or buffers
859 (error "Can't find the Info directory node"))
860
861 ;; Distinguish the dir file that comes with Emacs from all the
862 ;; others. Yes, that is really what this is supposed to do.
863 ;; The definition of `Info-directory-list' puts it first on that
864 ;; list and so last in `buffers' at this point.
865 (setq buffer (car (last buffers))
866 others (delq buffer buffers))
867
868 ;; Insert the entire original dir file as a start; note that we've
869 ;; already saved its default directory to use as the default
870 ;; directory for the whole concatenation.
871 (insert-buffer buffer)
872
873 ;; Look at each of the other buffers one by one.
874 (dolist (other others)
875 (let (this-buffer-nodes)
876 ;; In each, find all the menus.
877 (with-current-buffer other
878 (goto-char (point-min))
879 ;; Find each menu, and add an elt to NODES for it.
880 (while (re-search-forward "^\\* Menu:" nil t)
881 (while (and (zerop (forward-line 1)) (eolp)))
882 (let ((beg (point))
883 nodename end)
884 (re-search-backward "^\^_")
885 (search-forward "Node: ")
886 (setq nodename (Info-following-node-name))
887 (search-forward "\n\^_" nil 'move)
888 (beginning-of-line)
889 (setq end (point))
890 (push (list nodename other beg end) this-buffer-nodes)))
891 (if (assoc-ignore-case "top" this-buffer-nodes)
892 (setq nodes (nconc this-buffer-nodes nodes))
893 (setq problems t)
894 (message "No `top' node in %s" Info-dir-file-name)))))
895 ;; Add to the main menu a menu item for each other node.
896 (re-search-forward "^\\* Menu:")
897 (forward-line 1)
898 (let ((menu-items '("top"))
899 (end (save-excursion (search-forward "\^_" nil t) (point))))
900 (dolist (node nodes)
901 (let ((nodename (car node)))
902 (save-excursion
903 (or (member (downcase nodename) menu-items)
904 (re-search-forward (concat "^\\* +"
905 (regexp-quote nodename)
906 "::")
907 end t)
908 (progn
909 (insert "* " nodename "::" "\n")
910 (push nodename menu-items)))))))
911 ;; Now take each node of each of the other buffers
912 ;; and merge it into the main buffer.
913 (dolist (node nodes)
914 (let ((case-fold-search t)
915 (nodename (car node)))
916 (goto-char (point-min))
917 ;; Find the like-named node in the main buffer.
918 (if (re-search-forward (concat "^\^_.*\n.*Node: "
919 (regexp-quote nodename)
920 "[,\n\t]")
921 nil t)
922 (progn
923 (search-forward "\n\^_" nil 'move)
924 (beginning-of-line)
925 (insert "\n"))
926 ;; If none exists, add one.
927 (goto-char (point-max))
928 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
929 ;; Merge the text from the other buffer's menu
930 ;; into the menu in the like-named node in the main buffer.
931 (apply 'insert-buffer-substring (cdr node))))
932 (Info-dir-remove-duplicates)
933 ;; Kill all the buffers we just made.
934 (mapc 'kill-buffer buffers)
935 (goto-char (point-min))
936 (if problems
937 (message "Composing main Info directory...problems encountered, see `*Messages*'")
938 (message "Composing main Info directory...done"))
939 (set (make-local-variable 'Info-dir-contents) (buffer-string))
940 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
941 (setq default-directory Info-dir-contents-directory))
942
943 (defvar Info-streamline-headings
944 '(("Emacs" . "Emacs")
945 ("Programming" . "Programming")
946 ("Libraries" . "Libraries")
947 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
948 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
949
950 (defun Info-dir-remove-duplicates ()
951 (let (limit)
952 (goto-char (point-min))
953 ;; Remove duplicate headings in the same menu.
954 (while (search-forward "\n* Menu:" nil t)
955 (setq limit (save-excursion (search-forward "\n\1f" nil t)))
956 ;; Look for the next heading to unify.
957 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
958 (let ((name (match-string 1))
959 (start (match-beginning 0))
960 (entries nil) re)
961 ;; Check whether this heading should be streamlined.
962 (save-match-data
963 (dolist (x Info-streamline-headings)
964 (when (string-match (car x) name)
965 (setq name (cdr x))
966 (setq re (car x)))))
967 (if re (replace-match name t t nil 1))
968 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
969 (match-beginning 0)
970 (or limit (point-max))))
971 ;; Look for other headings of the same category and merge them.
972 (save-excursion
973 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
974 (when (if re (save-match-data (string-match re (match-string 1)))
975 (equal name (match-string 1)))
976 (forward-line 0)
977 ;; Delete redundant heading.
978 (delete-region (match-beginning 0) (point))
979 ;; Push the entries onto `text'.
980 (push
981 (delete-and-extract-region
982 (point)
983 (if (re-search-forward "^[^* \n\t]" nil t)
984 (match-beginning 0)
985 (or limit (point-max)))) entries))))
986 ;; Insert the entries just found.
987 (while (= (line-beginning-position 0) (1- (point)))
988 (backward-char))
989 (dolist (entry (nreverse entries))
990 (insert entry)
991 (while (= (line-beginning-position 0) (1- (point)))
992 (delete-region (1- (point)) (point))))
993
994 ;; Now remove duplicate entries under the same heading.
995 (let ((seen nil)
996 (limit (point)))
997 (goto-char start)
998 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
999 limit 'move)
1000 (let ((x (match-string 1)))
1001 (if (member-ignore-case x seen)
1002 (delete-region (match-beginning 0)
1003 (progn (re-search-forward "^[^ \t]" nil t)
1004 (match-beginning 0)))
1005 (push x seen))))))))))
1006
1007 ;; Note that on entry to this function the current-buffer must be the
1008 ;; *info* buffer; not the info tags buffer.
1009 (defun Info-read-subfile (nodepos)
1010 ;; NODEPOS is either a position (in the Info file as a whole,
1011 ;; not relative to a subfile) or the name of a subfile.
1012 (let (lastfilepos
1013 lastfilename)
1014 (if (numberp nodepos)
1015 (save-excursion
1016 (set-buffer (marker-buffer Info-tag-table-marker))
1017 (goto-char (point-min))
1018 (or (looking-at "\^_")
1019 (search-forward "\n\^_"))
1020 (forward-line 2)
1021 (catch 'foo
1022 (while (not (looking-at "\^_"))
1023 (if (not (eolp))
1024 (let ((beg (point))
1025 thisfilepos thisfilename)
1026 (search-forward ": ")
1027 (setq thisfilename (buffer-substring beg (- (point) 2)))
1028 (setq thisfilepos (+ (point-min) (read (current-buffer))))
1029 ;; read in version 19 stops at the end of number.
1030 ;; Advance to the next line.
1031 (forward-line 1)
1032 (if (> thisfilepos nodepos)
1033 (throw 'foo t))
1034 (setq lastfilename thisfilename)
1035 (setq lastfilepos thisfilepos))
1036 (forward-line 1)))))
1037 (setq lastfilename nodepos)
1038 (setq lastfilepos 0))
1039 ;; Assume previous buffer is in Info-mode.
1040 ;; (set-buffer (get-buffer "*info*"))
1041 (or (equal Info-current-subfile lastfilename)
1042 (let ((buffer-read-only nil))
1043 (setq buffer-file-name nil)
1044 (widen)
1045 (erase-buffer)
1046 (info-insert-file-contents lastfilename)
1047 (set-buffer-modified-p nil)
1048 (setq Info-current-subfile lastfilename)))
1049 ;; Widen in case we are in the same subfile as before.
1050 (widen)
1051 (goto-char (point-min))
1052 (if (looking-at "\^_")
1053 (forward-char 1)
1054 (search-forward "\n\^_"))
1055 (if (numberp nodepos)
1056 (+ (- nodepos lastfilepos) (point)))))
1057
1058 (defvar Info-header-line nil
1059 "If the info node header is hidden, the text of the header.")
1060 (put 'Info-header-line 'risky-local-variable t)
1061
1062 (defun Info-select-node ()
1063 "Select the info node that point is in.
1064 Bind this in case the user sets it to nil."
1065 (let ((case-fold-search t))
1066 (save-excursion
1067 ;; Find beginning of node.
1068 (if (search-backward "\n\^_" nil 'move)
1069 (forward-line 2)
1070 (if (looking-at "\^_")
1071 (forward-line 1)
1072 (signal 'search-failed (list "\n\^_"))))
1073 ;; Get nodename spelled as it is in the node.
1074 (re-search-forward "Node:[ \t]*")
1075 (setq Info-current-node
1076 (buffer-substring-no-properties (point)
1077 (progn
1078 (skip-chars-forward "^,\t\n")
1079 (point))))
1080 (Info-set-mode-line)
1081 ;; Find the end of it, and narrow.
1082 (beginning-of-line)
1083 (let (active-expression)
1084 ;; Narrow to the node contents
1085 (narrow-to-region (point)
1086 (if (re-search-forward "\n[\^_\f]" nil t)
1087 (prog1
1088 (1- (point))
1089 (if (looking-at "[\n\^_\f]*execute: ")
1090 (progn
1091 (goto-char (match-end 0))
1092 (setq active-expression
1093 (read (current-buffer))))))
1094 (point-max)))
1095 (if Info-enable-active-nodes (eval active-expression))
1096 (Info-fontify-node)
1097 (setq Info-header-line (get-text-property (point-min) 'header-line))
1098 (run-hooks 'Info-selection-hook)))))
1099
1100 (defun Info-set-mode-line ()
1101 (setq mode-line-buffer-identification
1102 (nconc (propertized-buffer-identification "%b")
1103 (list
1104 (concat " ("
1105 (file-name-nondirectory
1106 (if (stringp Info-current-file)
1107 Info-current-file
1108 (or buffer-file-name "")))
1109 ") "
1110 (or Info-current-node ""))))))
1111 \f
1112 ;; Go to an info node specified with a filename-and-nodename string
1113 ;; of the sort that is found in pointers in nodes.
1114
1115 (defun Info-goto-node (nodename &optional fork)
1116 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1117 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1118 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1119 its sub-files).
1120 Completion is available, but only for node names in the current Info file.
1121 If FORK is non-nil (interactively with a prefix arg), show the node in
1122 a new info buffer.
1123 If FORK is a string, it is the name to use for the new buffer."
1124 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
1125 (info-initialize)
1126 (if fork
1127 (set-buffer
1128 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
1129 (let (filename)
1130 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1131 nodename)
1132 (setq filename (if (= (match-beginning 1) (match-end 1))
1133 ""
1134 (substring nodename (match-beginning 2) (match-end 2)))
1135 nodename (substring nodename (match-beginning 3) (match-end 3)))
1136 (let ((trim (string-match "\\s *\\'" filename)))
1137 (if trim (setq filename (substring filename 0 trim))))
1138 (let ((trim (string-match "\\s *\\'" nodename)))
1139 (if trim (setq nodename (substring nodename 0 trim))))
1140 (if transient-mark-mode (deactivate-mark))
1141 (Info-find-node (if (equal filename "") nil filename)
1142 (if (equal nodename "") "Top" nodename))))
1143
1144 (defvar Info-read-node-completion-table)
1145
1146 ;; This function is used as the "completion table" while reading a node name.
1147 ;; It does completion using the alist in Info-read-node-completion-table
1148 ;; unless STRING starts with an open-paren.
1149 (defun Info-read-node-name-1 (string predicate code)
1150 (cond
1151 ;; First complete embedded file names.
1152 ((string-match "\\`([^)]*\\'" string)
1153 (let ((file (substring string 1)))
1154 (cond
1155 ((eq code nil)
1156 (let ((comp (try-completion file 'locate-file-completion
1157 (cons Info-directory-list
1158 (mapcar 'car Info-suffix-list)))))
1159 (cond
1160 ((eq comp t) (concat string ")"))
1161 (comp (concat "(" comp)))))
1162 ((eq code t) (all-completions file 'locate-file-completion
1163 (cons Info-directory-list
1164 (mapcar 'car Info-suffix-list))))
1165 (t nil))))
1166 ;; If a file name was given, then any node is fair game.
1167 ((string-match "\\`(" string)
1168 (cond
1169 ((eq code nil) string)
1170 ((eq code t) nil)
1171 (t t)))
1172 ;; Otherwise use Info-read-node-completion-table.
1173 ((eq code nil)
1174 (try-completion string Info-read-node-completion-table predicate))
1175 ((eq code t)
1176 (all-completions string Info-read-node-completion-table predicate))
1177 (t
1178 (test-completion string Info-read-node-completion-table predicate))))
1179
1180 (defun Info-read-node-name (prompt &optional default)
1181 (let* ((completion-ignore-case t)
1182 (Info-read-node-completion-table (Info-build-node-completions))
1183 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1184 (if (equal nodename "")
1185 (or default
1186 (Info-read-node-name prompt))
1187 nodename)))
1188
1189 (defun Info-build-node-completions ()
1190 (or Info-current-file-completions
1191 (let ((compl nil)
1192 ;; Bind this in case the user sets it to nil.
1193 (case-fold-search t)
1194 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1195 (save-excursion
1196 (save-restriction
1197 (if (marker-buffer Info-tag-table-marker)
1198 (let ((marker Info-tag-table-marker))
1199 (set-buffer (marker-buffer marker))
1200 (widen)
1201 (goto-char marker)
1202 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1203 (setq compl
1204 (cons (list (match-string-no-properties 2))
1205 compl))))
1206 (widen)
1207 (goto-char (point-min))
1208 ;; If the buffer begins with a node header, process that first.
1209 (if (Info-node-at-bob-matching node-regexp)
1210 (setq compl (list (match-string-no-properties 1))))
1211 ;; Now for the rest of the nodes.
1212 (while (search-forward "\n\^_" nil t)
1213 (forward-line 1)
1214 (let ((beg (point)))
1215 (forward-line 1)
1216 (if (re-search-backward node-regexp beg t)
1217 (setq compl
1218 (cons (list (match-string-no-properties 1))
1219 compl))))))))
1220 (setq compl (cons '("*") compl))
1221 (set (make-local-variable 'Info-current-file-completions) compl))))
1222 \f
1223 (defun Info-restore-point (hl)
1224 "If this node has been visited, restore the point value when we left."
1225 (while hl
1226 (if (and (equal (nth 0 (car hl)) Info-current-file)
1227 ;; Use string-equal, not equal, to ignore text props.
1228 (string-equal (nth 1 (car hl)) Info-current-node))
1229 (progn
1230 (goto-char (nth 2 (car hl)))
1231 (setq hl nil)) ;terminate the while at next iter
1232 (setq hl (cdr hl)))))
1233 \f
1234 (defvar Info-search-history nil
1235 "The history list for `Info-search'.")
1236
1237 (defun Info-search (regexp)
1238 "Search for REGEXP, starting from point, and select node it's found in."
1239 (interactive (list (read-string
1240 (if Info-search-history
1241 (format "Regexp search (default `%s'): "
1242 (car Info-search-history))
1243 "Regexp search: ")
1244 nil 'Info-search-history)))
1245 (when transient-mark-mode
1246 (deactivate-mark))
1247 (when (equal regexp "")
1248 (setq regexp (car Info-search-history)))
1249 (when regexp
1250 (let ((found ()) current
1251 (onode Info-current-node)
1252 (ofile Info-current-file)
1253 (opoint (point))
1254 (ostart (window-start))
1255 (osubfile Info-current-subfile))
1256 (save-excursion
1257 (save-restriction
1258 (widen)
1259 (if (null Info-current-subfile)
1260 (progn (re-search-forward regexp) (setq found (point)))
1261 (condition-case err
1262 (progn (re-search-forward regexp) (setq found (point)))
1263 (search-failed nil)))))
1264 (if (not found) ;can only happen in subfile case -- else would have erred
1265 (unwind-protect
1266 (let ((list ()))
1267 (save-excursion
1268 (set-buffer (marker-buffer Info-tag-table-marker))
1269 (goto-char (point-min))
1270 (search-forward "\n\^_\nIndirect:")
1271 (save-restriction
1272 (narrow-to-region (point)
1273 (progn (search-forward "\n\^_")
1274 (1- (point))))
1275 (goto-char (point-min))
1276 ;; Find the subfile we just searched.
1277 (search-forward (concat "\n" osubfile ": "))
1278 ;; Skip that one.
1279 (forward-line 1)
1280 ;; Make a list of all following subfiles.
1281 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1282 (while (not (eobp))
1283 (re-search-forward "\\(^.*\\): [0-9]+$")
1284 (goto-char (+ (match-end 1) 2))
1285 (setq list (cons (cons (+ (point-min)
1286 (read (current-buffer)))
1287 (match-string-no-properties 1))
1288 list))
1289 (goto-char (1+ (match-end 0))))
1290 ;; Put in forward order
1291 (setq list (nreverse list))))
1292 (while list
1293 (message "Searching subfile %s..." (cdr (car list)))
1294 (Info-read-subfile (car (car list)))
1295 (setq list (cdr list))
1296 (if (re-search-forward regexp nil t)
1297 (setq found (point) list ())))
1298 (if found
1299 (message "")
1300 (signal 'search-failed (list regexp))))
1301 (if (not found)
1302 (progn (Info-read-subfile osubfile)
1303 (goto-char opoint)
1304 (Info-select-node)
1305 (set-window-start (selected-window) ostart)))))
1306 (widen)
1307 (goto-char found)
1308 (Info-select-node)
1309 ;; Use string-equal, not equal, to ignore text props.
1310 (or (and (string-equal onode Info-current-node)
1311 (equal ofile Info-current-file))
1312 (setq Info-history (cons (list ofile onode opoint)
1313 Info-history))))))
1314 \f
1315 (defun Info-extract-pointer (name &optional errorname)
1316 "Extract the value of the node-pointer named NAME.
1317 If there is none, use ERRORNAME in the error message;
1318 if ERRORNAME is nil, just return nil.
1319 Bind this in case the user sets it to nil."
1320 (let ((case-fold-search t))
1321 (save-excursion
1322 (save-restriction
1323 (goto-char (point-min))
1324 (let ((bound (point)))
1325 (forward-line 1)
1326 (cond ((re-search-backward (concat name ":") bound t)
1327 (goto-char (match-end 0))
1328 (Info-following-node-name))
1329 ((not (eq errorname t))
1330 (error "Node has no %s"
1331 (capitalize (or errorname name))))))))))
1332
1333 (defun Info-following-node-name (&optional allowedchars)
1334 "Return the node name in the buffer following point.
1335 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1336 saying which chars may appear in the node name."
1337 (skip-chars-forward " \t")
1338 (buffer-substring-no-properties
1339 (point)
1340 (progn
1341 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1342 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1343 (if (looking-at "(")
1344 (skip-chars-forward "^)")))
1345 (skip-chars-backward " ")
1346 (point))))
1347
1348 (defun Info-next ()
1349 "Go to the next node of this node."
1350 (interactive)
1351 (Info-goto-node (Info-extract-pointer "next")))
1352
1353 (defun Info-prev ()
1354 "Go to the previous node of this node."
1355 (interactive)
1356 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1357
1358 (defun Info-up (&optional same-file)
1359 "Go to the superior node of this node.
1360 If SAME-FILE is non-nil, do not move to a different Info file."
1361 (interactive)
1362 (let ((node (Info-extract-pointer "up")))
1363 (and (or same-file (not (stringp Info-current-file)))
1364 (string-match "^(" node)
1365 (error "Up node is in another Info file"))
1366 (Info-goto-node node))
1367 (Info-restore-point Info-history))
1368
1369 (defun Info-last ()
1370 "Go back to the last node visited."
1371 (interactive)
1372 (or Info-history
1373 (error "This is the first Info node you looked at"))
1374 (let (filename nodename opoint)
1375 (setq filename (car (car Info-history)))
1376 (setq nodename (car (cdr (car Info-history))))
1377 (setq opoint (car (cdr (cdr (car Info-history)))))
1378 (setq Info-history (cdr Info-history))
1379 (Info-find-node filename nodename)
1380 (setq Info-history (cdr Info-history))
1381 (goto-char opoint)))
1382
1383 ;;;###autoload
1384 (defun Info-directory ()
1385 "Go to the Info directory node."
1386 (interactive)
1387 (Info-find-node "dir" "top"))
1388 \f
1389 (defun Info-follow-reference (footnotename)
1390 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1391 FOOTNOTENAME may be an abbreviation of the reference name."
1392 (interactive
1393 (let ((completion-ignore-case t)
1394 (case-fold-search t)
1395 completions default alt-default (start-point (point)) str i bol eol)
1396 (save-excursion
1397 ;; Store end and beginning of line.
1398 (end-of-line)
1399 (setq eol (point))
1400 (beginning-of-line)
1401 (setq bol (point))
1402
1403 (goto-char (point-min))
1404 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1405 (setq str (buffer-substring-no-properties
1406 (match-beginning 1)
1407 (1- (point))))
1408 ;; See if this one should be the default.
1409 (and (null default)
1410 (<= (match-beginning 0) start-point)
1411 (<= start-point (point))
1412 (setq default t))
1413 ;; See if this one should be the alternate default.
1414 (and (null alt-default)
1415 (and (<= bol (match-beginning 0))
1416 (<= (point) eol))
1417 (setq alt-default t))
1418 (setq i 0)
1419 (while (setq i (string-match "[ \n\t]+" str i))
1420 (setq str (concat (substring str 0 i) " "
1421 (substring str (match-end 0))))
1422 (setq i (1+ i)))
1423 ;; Record as a completion and perhaps as default.
1424 (if (eq default t) (setq default str))
1425 (if (eq alt-default t) (setq alt-default str))
1426 ;; Don't add this string if it's a duplicate.
1427 ;; We use a loop instead of "(assoc str completions)" because
1428 ;; we want to do a case-insensitive compare.
1429 (let ((tail completions)
1430 (tem (downcase str)))
1431 (while (and tail
1432 (not (string-equal tem (downcase (car (car tail))))))
1433 (setq tail (cdr tail)))
1434 (or tail
1435 (setq completions
1436 (cons (cons str nil)
1437 completions))))))
1438 ;; If no good default was found, try an alternate.
1439 (or default
1440 (setq default alt-default))
1441 ;; If only one cross-reference found, then make it default.
1442 (if (eq (length completions) 1)
1443 (setq default (car (car completions))))
1444 (if completions
1445 (let ((input (completing-read (if default
1446 (concat
1447 "Follow reference named: (default "
1448 default ") ")
1449 "Follow reference named: ")
1450 completions nil t)))
1451 (list (if (equal input "")
1452 default input)))
1453 (error "No cross-references in this node"))))
1454
1455 (unless footnotename
1456 (error "No reference was specified"))
1457
1458 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
1459 (case-fold-search t))
1460 (while (setq i (string-match " " str i))
1461 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1462 (setq i (+ i 6)))
1463 (save-excursion
1464 (goto-char (point-min))
1465 (or (re-search-forward str nil t)
1466 (error "No cross-reference named %s" footnotename))
1467 (goto-char (+ (match-beginning 0) 5))
1468 (setq target
1469 (Info-extract-menu-node-name "Bad format cross reference" t)))
1470 (while (setq i (string-match "[ \t\n]+" target i))
1471 (setq target (concat (substring target 0 i) " "
1472 (substring target (match-end 0))))
1473 (setq i (+ i 1)))
1474 (Info-goto-node target)))
1475
1476 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1477 (skip-chars-forward " \t\n")
1478 (let ((beg (point))
1479 str i)
1480 (skip-chars-forward "^:")
1481 (forward-char 1)
1482 (setq str
1483 (if (looking-at ":")
1484 (buffer-substring-no-properties beg (1- (point)))
1485 (skip-chars-forward " \t\n")
1486 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1487 (replace-regexp-in-string "[ \n]+" " " str)))
1488
1489 ;; No one calls this.
1490 ;;(defun Info-menu-item-sequence (list)
1491 ;; (while list
1492 ;; (Info-menu (car list))
1493 ;; (setq list (cdr list))))
1494
1495 (defvar Info-complete-menu-buffer)
1496 (defvar Info-complete-next-re nil)
1497 (defvar Info-complete-cache nil)
1498
1499 (defun Info-complete-menu-item (string predicate action)
1500 ;; This uses two dynamically bound variables:
1501 ;; - `Info-complete-menu-buffer' which contains the buffer in which
1502 ;; is the menu of items we're trying to complete.
1503 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
1504 ;; also look for menu items in subsequent nodes as long as those
1505 ;; nodes' names match `Info-complete-next-re'. This feature is currently
1506 ;; only used for completion in Info-index.
1507 (save-excursion
1508 (set-buffer Info-complete-menu-buffer)
1509 (let ((completion-ignore-case t)
1510 (case-fold-search t)
1511 (orignode Info-current-node)
1512 nextnode)
1513 (goto-char (point-min))
1514 (search-forward "\n* Menu:")
1515 (if (not (memq action '(nil t)))
1516 (re-search-forward
1517 (concat "\n\\* +" (regexp-quote string) ":") nil t)
1518 (let ((pattern (concat "\n\\* +\\("
1519 (regexp-quote string)
1520 "[^:\t\n]*\\):"))
1521 completions)
1522 ;; Check the cache.
1523 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
1524 (equal (nth 1 Info-complete-cache) Info-current-node)
1525 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
1526 (let ((prev (nth 3 Info-complete-cache)))
1527 (eq t (compare-strings string 0 (length prev)
1528 prev 0 nil t))))
1529 ;; We can reuse the previous list.
1530 (setq completions (nth 4 Info-complete-cache))
1531 ;; The cache can't be used.
1532 (while
1533 (progn
1534 (while (re-search-forward pattern nil t)
1535 (push (match-string-no-properties 1)
1536 completions))
1537 ;; Check subsequent nodes if applicable.
1538 (and Info-complete-next-re
1539 (setq nextnode (Info-extract-pointer "next" t))
1540 (string-match Info-complete-next-re nextnode)))
1541 (Info-goto-node nextnode))
1542 ;; Go back to the start node (for the next completion).
1543 (unless (equal Info-current-node orignode)
1544 (Info-goto-node orignode))
1545 ;; Update the cache.
1546 (set (make-local-variable 'Info-complete-cache)
1547 (list Info-current-file Info-current-node
1548 Info-complete-next-re string completions)))
1549 (if action
1550 (all-completions string completions predicate)
1551 (try-completion string completions predicate)))))))
1552
1553
1554 (defun Info-menu (menu-item &optional fork)
1555 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
1556 The menu item should one of those listed in the current node's menu.
1557 Completion is allowed, and the default menu item is the one point is on.
1558 If FORK is non-nil (interactively with a prefix arg), show the node in
1559 a new info buffer. If FORK is a string, it is the name to use for the
1560 new buffer."
1561 (interactive
1562 (let ((completions '())
1563 ;; If point is within a menu item, use that item as the default
1564 (default nil)
1565 (p (point))
1566 beg
1567 (last nil)
1568 (case-fold-search t))
1569 (save-excursion
1570 (goto-char (point-min))
1571 (if (not (search-forward "\n* menu:" nil t))
1572 (error "No menu in this node"))
1573 (setq beg (point))
1574 (and (< (point) p)
1575 (save-excursion
1576 (goto-char p)
1577 (end-of-line)
1578 (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
1579 (setq default (match-string-no-properties 1))))))
1580 (let ((item nil))
1581 (while (null item)
1582 (setq item (let ((completion-ignore-case t)
1583 (Info-complete-menu-buffer (current-buffer)))
1584 (completing-read (if default
1585 (format "Menu item (default %s): "
1586 default)
1587 "Menu item: ")
1588 'Info-complete-menu-item nil t)))
1589 ;; we rely on the fact that completing-read accepts an input
1590 ;; of "" even when the require-match argument is true and ""
1591 ;; is not a valid possibility
1592 (if (string= item "")
1593 (if default
1594 (setq item default)
1595 ;; ask again
1596 (setq item nil))))
1597 (list item current-prefix-arg))))
1598 ;; there is a problem here in that if several menu items have the same
1599 ;; name you can only go to the node of the first with this command.
1600 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
1601
1602 (defun Info-extract-menu-item (menu-item)
1603 (setq menu-item (regexp-quote menu-item))
1604 (let ((case-fold-search t))
1605 (save-excursion
1606 (let ((case-fold-search t))
1607 (goto-char (point-min))
1608 (or (search-forward "\n* menu:" nil t)
1609 (error "No menu in this node"))
1610 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1611 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1612 (error "No such item in menu"))
1613 (beginning-of-line)
1614 (forward-char 2)
1615 (Info-extract-menu-node-name)))))
1616
1617 ;; If COUNT is nil, use the last item in the menu.
1618 (defun Info-extract-menu-counting (count)
1619 (let ((case-fold-search t))
1620 (save-excursion
1621 (let ((case-fold-search t))
1622 (goto-char (point-min))
1623 (or (search-forward "\n* menu:" nil t)
1624 (error "No menu in this node"))
1625 (if count
1626 (or (search-forward "\n* " nil t count)
1627 (error "Too few items in menu"))
1628 (while (search-forward "\n* " nil t)
1629 nil))
1630 (Info-extract-menu-node-name)))))
1631
1632 (defun Info-nth-menu-item ()
1633 "Go to the node of the Nth menu item.
1634 N is the digit argument used to invoke this command."
1635 (interactive)
1636 (Info-goto-node
1637 (Info-extract-menu-counting
1638 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1639
1640 (defun Info-top-node ()
1641 "Go to the Top node of this file."
1642 (interactive)
1643 (Info-goto-node "Top"))
1644
1645 (defun Info-final-node ()
1646 "Go to the final node in this file."
1647 (interactive)
1648 (Info-goto-node "Top")
1649 (let ((Info-history nil)
1650 (case-fold-search t))
1651 ;; Go to the last node in the menu of Top.
1652 (Info-goto-node (Info-extract-menu-counting nil))
1653 ;; If the last node in the menu is not last in pointer structure,
1654 ;; move forward until we can't go any farther.
1655 (while (Info-forward-node t t) nil)
1656 ;; Then keep moving down to last subnode, unless we reach an index.
1657 (while (and (not (string-match "\\<index\\>" Info-current-node))
1658 (save-excursion (search-forward "\n* Menu:" nil t)))
1659 (Info-goto-node (Info-extract-menu-counting nil)))))
1660
1661 (defun Info-forward-node (&optional not-down no-error)
1662 "Go forward one node, considering all nodes as forming one sequence."
1663 (interactive)
1664 (goto-char (point-min))
1665 (forward-line 1)
1666 (let ((case-fold-search t))
1667 ;; three possibilities, in order of priority:
1668 ;; 1. next node is in a menu in this node (but not in an index)
1669 ;; 2. next node is next at same level
1670 ;; 3. next node is up and next
1671 (cond ((and (not not-down)
1672 (save-excursion (search-forward "\n* menu:" nil t))
1673 (not (string-match "\\<index\\>" Info-current-node)))
1674 (Info-goto-node (Info-extract-menu-counting 1))
1675 t)
1676 ((save-excursion (search-backward "next:" nil t))
1677 (Info-next)
1678 t)
1679 ((and (save-excursion (search-backward "up:" nil t))
1680 ;; Use string-equal, not equal, to ignore text props.
1681 (not (string-equal (downcase (Info-extract-pointer "up"))
1682 "top")))
1683 (let ((old-node Info-current-node))
1684 (Info-up)
1685 (let (Info-history success)
1686 (unwind-protect
1687 (setq success (Info-forward-node t no-error))
1688 (or success (Info-goto-node old-node))))))
1689 (no-error nil)
1690 (t (error "No pointer forward from this node")))))
1691
1692 (defun Info-backward-node ()
1693 "Go backward one node, considering all nodes as forming one sequence."
1694 (interactive)
1695 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1696 (upnode (Info-extract-pointer "up" t))
1697 (case-fold-search t))
1698 (cond ((and upnode (string-match "(" upnode))
1699 (error "First node in file"))
1700 ((and upnode (or (null prevnode)
1701 ;; Use string-equal, not equal,
1702 ;; to ignore text properties.
1703 (string-equal (downcase prevnode)
1704 (downcase upnode))))
1705 (Info-up))
1706 (prevnode
1707 ;; If we move back at the same level,
1708 ;; go down to find the last subnode*.
1709 (Info-prev)
1710 (let (Info-history)
1711 (while (and (not (string-match "\\<index\\>" Info-current-node))
1712 (save-excursion (search-forward "\n* Menu:" nil t)))
1713 (Info-goto-node (Info-extract-menu-counting nil)))))
1714 (t
1715 (error "No pointer backward from this node")))))
1716
1717 (defun Info-exit ()
1718 "Exit Info by selecting some other buffer."
1719 (interactive)
1720 (if Info-standalone
1721 (save-buffers-kill-emacs)
1722 (quit-window)))
1723
1724 (defun Info-next-menu-item ()
1725 "Go to the node of the next menu item."
1726 (interactive)
1727 ;; Bind this in case the user sets it to nil.
1728 (let* ((case-fold-search t)
1729 (node
1730 (save-excursion
1731 (forward-line -1)
1732 (search-forward "\n* menu:" nil t)
1733 (and (search-forward "\n* " nil t)
1734 (Info-extract-menu-node-name)))))
1735 (if node (Info-goto-node node)
1736 (error "No more items in menu"))))
1737
1738 (defun Info-last-menu-item ()
1739 "Go to the node of the previous menu item."
1740 (interactive)
1741 (save-excursion
1742 (forward-line 1)
1743 ;; Bind this in case the user sets it to nil.
1744 (let* ((case-fold-search t)
1745 (beg (save-excursion
1746 (and (search-backward "\n* menu:" nil t)
1747 (point)))))
1748 (or (and beg (search-backward "\n* " beg t))
1749 (error "No previous items in menu")))
1750 (Info-goto-node (save-excursion
1751 (goto-char (match-end 0))
1752 (Info-extract-menu-node-name)))))
1753
1754 (defmacro Info-no-error (&rest body)
1755 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1756
1757 (defun Info-next-preorder ()
1758 "Go to the next subnode or the next node, or go up a level."
1759 (interactive)
1760 (cond ((Info-no-error (Info-next-menu-item)))
1761 ((Info-no-error (Info-next)))
1762 ((Info-no-error (Info-up t))
1763 ;; Since we have already gone thru all the items in this menu,
1764 ;; go up to the end of this node.
1765 (goto-char (point-max))
1766 ;; Since logically we are done with the node with that menu,
1767 ;; move on from it.
1768 (Info-next-preorder))
1769 (t
1770 (error "No more nodes"))))
1771
1772 (defun Info-last-preorder ()
1773 "Go to the last node, popping up a level if there is none."
1774 (interactive)
1775 (cond ((Info-no-error
1776 (Info-last-menu-item)
1777 ;; If we go down a menu item, go to the end of the node
1778 ;; so we can scroll back through it.
1779 (goto-char (point-max)))
1780 ;; Keep going down, as long as there are nested menu nodes.
1781 (while (Info-no-error
1782 (Info-last-menu-item)
1783 ;; If we go down a menu item, go to the end of the node
1784 ;; so we can scroll back through it.
1785 (goto-char (point-max))))
1786 (recenter -1))
1787 ((and (Info-no-error (Info-extract-pointer "prev"))
1788 (not (equal (Info-extract-pointer "up")
1789 (Info-extract-pointer "prev"))))
1790 (Info-no-error (Info-prev))
1791 (goto-char (point-max))
1792 (while (Info-no-error
1793 (Info-last-menu-item)
1794 ;; If we go down a menu item, go to the end of the node
1795 ;; so we can scroll back through it.
1796 (goto-char (point-max))))
1797 (recenter -1))
1798 ((Info-no-error (Info-up t))
1799 (goto-char (point-min))
1800 (let ((case-fold-search t))
1801 (or (search-forward "\n* Menu:" nil t)
1802 (goto-char (point-max)))))
1803 (t (error "No previous nodes"))))
1804
1805 (defun Info-scroll-up ()
1806 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1807 Once you scroll far enough in a node that its menu appears on the screen
1808 but after point, the next scroll moves into its first subnode, unless
1809 `Info-scroll-prefer-subnodes' is nil.
1810
1811 When you scroll past the end of a node, that goes to the next node if
1812 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
1813 if this node has no successor, it moves to the parent node's successor,
1814 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
1815 the menu of a node, it moves to subnode indicated by the following menu
1816 item. (That case won't normally result from this command, but can happen
1817 in other ways.)"
1818
1819 (interactive)
1820 (if (or (< (window-start) (point-min))
1821 (> (window-start) (point-max)))
1822 (set-window-start (selected-window) (point)))
1823 (let* ((case-fold-search t)
1824 (virtual-end (save-excursion
1825 (goto-char (point-min))
1826 (if (and Info-scroll-prefer-subnodes
1827 (search-forward "\n* Menu:" nil t))
1828 (point)
1829 (point-max)))))
1830 (if (or (< virtual-end (window-start))
1831 (pos-visible-in-window-p virtual-end))
1832 (cond
1833 (Info-scroll-prefer-subnodes (Info-next-preorder))
1834 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
1835 (t (Info-next-preorder)))
1836 (scroll-up))))
1837
1838 (defun Info-scroll-down ()
1839 "Scroll one screenful back in Info, considering all nodes as one sequence.
1840 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
1841 is non-nil, this goes to its last subnode. When you scroll past the
1842 beginning of a node, that goes to the previous node or back up to the
1843 parent node."
1844 (interactive)
1845 (if (or (< (window-start) (point-min))
1846 (> (window-start) (point-max)))
1847 (set-window-start (selected-window) (point)))
1848 (let* ((case-fold-search t)
1849 (current-point (point))
1850 (virtual-end
1851 (and Info-scroll-prefer-subnodes
1852 (save-excursion
1853 (beginning-of-line)
1854 (setq current-point (point))
1855 (goto-char (point-min))
1856 (search-forward "\n* Menu:"
1857 current-point
1858 t)))))
1859 (if (or virtual-end
1860 (pos-visible-in-window-p (point-min) nil t))
1861 (Info-last-preorder)
1862 (scroll-down))))
1863
1864 (defun Info-next-reference (&optional recur)
1865 "Move cursor to the next cross-reference or menu item in the node."
1866 (interactive)
1867 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1868 (old-pt (point))
1869 (case-fold-search t))
1870 (or (eobp) (forward-char 1))
1871 (or (re-search-forward pat nil t)
1872 (progn
1873 (goto-char (point-min))
1874 (or (re-search-forward pat nil t)
1875 (progn
1876 (goto-char old-pt)
1877 (error "No cross references in this node")))))
1878 (goto-char (match-beginning 0))
1879 (if (looking-at "\\* Menu:")
1880 (if recur
1881 (error "No cross references in this node")
1882 (Info-next-reference t)))))
1883
1884 (defun Info-prev-reference (&optional recur)
1885 "Move cursor to the previous cross-reference or menu item in the node."
1886 (interactive)
1887 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1888 (old-pt (point))
1889 (case-fold-search t))
1890 (or (re-search-backward pat nil t)
1891 (progn
1892 (goto-char (point-max))
1893 (or (re-search-backward pat nil t)
1894 (progn
1895 (goto-char old-pt)
1896 (error "No cross references in this node")))))
1897 (goto-char (match-beginning 0))
1898 (if (looking-at "\\* Menu:")
1899 (if recur
1900 (error "No cross references in this node")
1901 (Info-prev-reference t)))))
1902
1903 (defun Info-goto-index ()
1904 (Info-goto-node "Top")
1905 (or (search-forward "\n* menu:" nil t)
1906 (error "No index"))
1907 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1908 (error "No index"))
1909 (goto-char (match-beginning 1))
1910 ;; Protect Info-history so that the current node (Top) is not added to it.
1911 (let ((Info-history nil))
1912 (Info-goto-node (Info-extract-menu-node-name))))
1913
1914 (defun Info-index (topic)
1915 "Look up a string TOPIC in the index for this file.
1916 The index is defined as the first node in the top level menu whose
1917 name contains the word \"Index\", plus any immediately following
1918 nodes whose names also contain the word \"Index\".
1919 If there are no exact matches to the specified topic, this chooses
1920 the first match which is a case-insensitive substring of a topic.
1921 Use the `,' command to see the other matches.
1922 Give a blank topic name to go to the Index node itself."
1923 (interactive
1924 (list
1925 (let ((Info-complete-menu-buffer (clone-buffer))
1926 (Info-complete-next-re "\\<Index\\>"))
1927 (if (equal Info-current-file "dir")
1928 (error "The Info directory node has no index; use m to select a manual"))
1929 (unwind-protect
1930 (with-current-buffer Info-complete-menu-buffer
1931 (Info-goto-index)
1932 (completing-read "Index topic: " 'Info-complete-menu-item))
1933 (kill-buffer Info-complete-menu-buffer)))))
1934 (if (equal Info-current-file "dir")
1935 (error "The Info directory node has no index; use m to select a manual"))
1936 (let ((orignode Info-current-node)
1937 (rnode nil)
1938 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1939 (regexp-quote topic)))
1940 node
1941 (case-fold-search t))
1942 (Info-goto-index)
1943 (or (equal topic "")
1944 (let ((matches nil)
1945 (exact nil)
1946 ;; We bind Info-history to nil for internal node-switches so
1947 ;; that we don't put junk in the history. In the first
1948 ;; Info-goto-index call, above, we do update the history
1949 ;; because that is what the user's previous node choice into it.
1950 (Info-history nil)
1951 found)
1952 (while
1953 (progn
1954 (goto-char (point-min))
1955 (while (re-search-forward pattern nil t)
1956 (push (list (match-string-no-properties 1)
1957 (match-string-no-properties 2)
1958 Info-current-node
1959 (string-to-number (concat "0"
1960 (match-string 3))))
1961 matches))
1962 (and (setq node (Info-extract-pointer "next" t))
1963 (string-match "\\<Index\\>" node)))
1964 (Info-goto-node node))
1965 (or matches
1966 (progn
1967 (Info-goto-node orignode)
1968 (error "No `%s' in index" topic)))
1969 ;; Here it is a feature that assoc is case-sensitive.
1970 (while (setq found (assoc topic matches))
1971 (setq exact (cons found exact)
1972 matches (delq found matches)))
1973 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1974 (Info-index-next 0)))))
1975
1976 (defun Info-index-next (num)
1977 "Go to the next matching index item from the last `i' command."
1978 (interactive "p")
1979 (or Info-index-alternatives
1980 (error "No previous `i' command"))
1981 (while (< num 0)
1982 (setq num (+ num (length Info-index-alternatives))))
1983 (while (> num 0)
1984 (setq Info-index-alternatives
1985 (nconc (cdr Info-index-alternatives)
1986 (list (car Info-index-alternatives)))
1987 num (1- num)))
1988 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1989 (if (> (nth 3 (car Info-index-alternatives)) 0)
1990 (forward-line (nth 3 (car Info-index-alternatives)))
1991 (forward-line 3) ; don't search in headers
1992 (let ((name (car (car Info-index-alternatives))))
1993 (Info-find-index-name name)))
1994 (message "Found `%s' in %s. %s"
1995 (car (car Info-index-alternatives))
1996 (nth 2 (car Info-index-alternatives))
1997 (if (cdr Info-index-alternatives)
1998 "(Press `,' for more)"
1999 "(Only match)")))
2000
2001 (defun Info-find-index-name (name)
2002 "Move point to the place within the current node where NAME is defined."
2003 (let ((case-fold-search t))
2004 (if (or (re-search-forward (format
2005 "[a-zA-Z]+: %s\\( \\|$\\)"
2006 (regexp-quote name)) nil t)
2007 ;; Find a function definition with a return type.
2008 (re-search-forward (format
2009 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2010 (regexp-quote name)) nil t)
2011 (search-forward (format "`%s'" name) nil t)
2012 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2013 (search-forward
2014 (format "`%s'" (substring name 0 (match-beginning 1)))
2015 nil t))
2016 (search-forward name nil t))
2017 (beginning-of-line)
2018 (goto-char (point-min)))))
2019
2020 (defun Info-undefined ()
2021 "Make command be undefined in Info."
2022 (interactive)
2023 (ding))
2024
2025 (defun Info-help ()
2026 "Enter the Info tutorial."
2027 (interactive)
2028 (delete-other-windows)
2029 (Info-find-node "info"
2030 (if (< (window-height) 23)
2031 "Help-Small-Screen"
2032 "Help")))
2033
2034 (defun Info-summary ()
2035 "Display a brief summary of all Info commands."
2036 (interactive)
2037 (save-window-excursion
2038 (switch-to-buffer "*Help*")
2039 (setq buffer-read-only nil)
2040 (erase-buffer)
2041 (insert (documentation 'Info-mode))
2042 (help-mode)
2043 (goto-char (point-min))
2044 (let (ch flag)
2045 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2046 (message (if flag "Type Space to see more"
2047 "Type Space to return to Info"))
2048 (if (not (eq ?\ (setq ch (read-event))))
2049 (progn (setq unread-command-events (list ch)) nil)
2050 flag))
2051 (scroll-up)))
2052 (bury-buffer "*Help*")))
2053 \f
2054 (defun Info-get-token (pos start all &optional errorstring)
2055 "Return the token around POS.
2056 POS must be somewhere inside the token
2057 START is a regular expression which will match the
2058 beginning of the tokens delimited string
2059 ALL is a regular expression with a single
2060 parenthesized subpattern which is the token to be
2061 returned. E.g. '{\(.*\)}' would return any string
2062 enclosed in braces around POS.
2063 ERRORSTRING optional fourth argument, controls action on no match
2064 nil: return nil
2065 t: beep
2066 a string: signal an error, using that string."
2067 (let ((case-fold-search t))
2068 (save-excursion
2069 (goto-char pos)
2070 ;; First look for a match for START that goes across POS.
2071 (while (and (not (bobp)) (> (point) (- pos (length start)))
2072 (not (looking-at start)))
2073 (forward-char -1))
2074 ;; If we did not find one, search back for START
2075 ;; (this finds only matches that end at or before POS).
2076 (or (looking-at start)
2077 (progn
2078 (goto-char pos)
2079 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
2080 (let (found)
2081 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2082 (not (setq found (and (<= (match-beginning 0) pos)
2083 (> (match-end 0) pos))))))
2084 (if (and found (<= (match-beginning 0) pos)
2085 (> (match-end 0) pos))
2086 (match-string-no-properties 1)
2087 (cond ((null errorstring)
2088 nil)
2089 ((eq errorstring t)
2090 (beep)
2091 nil)
2092 (t
2093 (error "No %s around position %d" errorstring pos))))))))
2094
2095 (defun Info-mouse-follow-nearest-node (click)
2096 "\\<Info-mode-map>Follow a node reference near point.
2097 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2098 At end of the node's text, moves to the next node, or up if none."
2099 (interactive "e")
2100 (mouse-set-point click)
2101 (and (not (Info-try-follow-nearest-node))
2102 (save-excursion (forward-line 1) (eobp))
2103 (Info-next-preorder)))
2104
2105 (defun Info-follow-nearest-node ()
2106 "\\<Info-mode-map>Follow a node reference near point.
2107 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
2108 If no reference to follow, moves to the next node, or up if none."
2109 (interactive)
2110 (or (Info-try-follow-nearest-node)
2111 (Info-next-preorder)))
2112
2113 ;; Common subroutine.
2114 (defun Info-try-follow-nearest-node ()
2115 "Follow a node reference near point. Return non-nil if successful."
2116 (let (node)
2117 (cond
2118 ((setq node (Info-get-token (point) "\\*note[ \n]"
2119 "\\*note[ \n]\\([^:]*\\):"))
2120 (Info-follow-reference node))
2121 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2122 (Info-goto-node node))
2123 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
2124 (beginning-of-line)
2125 (forward-char 2)
2126 (setq node (Info-extract-menu-node-name))
2127 (Info-goto-node node))
2128 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2129 (Info-goto-node node))
2130 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2131 (Info-goto-node node))
2132 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2133 (Info-goto-node "Top"))
2134 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2135 (Info-goto-node node)))
2136 node))
2137 \f
2138 (defvar Info-mode-map nil
2139 "Keymap containing Info commands.")
2140 (if Info-mode-map
2141 nil
2142 (setq Info-mode-map (make-keymap))
2143 (suppress-keymap Info-mode-map)
2144 (define-key Info-mode-map "." 'beginning-of-buffer)
2145 (define-key Info-mode-map " " 'Info-scroll-up)
2146 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
2147 (define-key Info-mode-map "\t" 'Info-next-reference)
2148 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
2149 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2150 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2151 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2152 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2153 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2154 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2155 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2156 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2157 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2158 (define-key Info-mode-map "0" 'undefined)
2159 (define-key Info-mode-map "?" 'Info-summary)
2160 (define-key Info-mode-map "]" 'Info-forward-node)
2161 (define-key Info-mode-map "[" 'Info-backward-node)
2162 (define-key Info-mode-map "<" 'Info-top-node)
2163 (define-key Info-mode-map ">" 'Info-final-node)
2164 (define-key Info-mode-map "b" 'beginning-of-buffer)
2165 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
2166 (define-key Info-mode-map "d" 'Info-directory)
2167 (define-key Info-mode-map "e" 'Info-edit)
2168 (define-key Info-mode-map "f" 'Info-follow-reference)
2169 (define-key Info-mode-map "g" 'Info-goto-node)
2170 (define-key Info-mode-map "h" 'Info-help)
2171 (define-key Info-mode-map "i" 'Info-index)
2172 (define-key Info-mode-map "l" 'Info-last)
2173 (define-key Info-mode-map "m" 'Info-menu)
2174 (define-key Info-mode-map "n" 'Info-next)
2175 (define-key Info-mode-map "p" 'Info-prev)
2176 (define-key Info-mode-map "q" 'Info-exit)
2177 (define-key Info-mode-map "s" 'Info-search)
2178 ;; For consistency with Rmail.
2179 (define-key Info-mode-map "\M-s" 'Info-search)
2180 (define-key Info-mode-map "\M-n" 'clone-buffer)
2181 (define-key Info-mode-map "t" 'Info-top-node)
2182 (define-key Info-mode-map "u" 'Info-up)
2183 (define-key Info-mode-map "," 'Info-index-next)
2184 (define-key Info-mode-map "\177" 'Info-scroll-down)
2185 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
2186 )
2187
2188 (defun Info-check-pointer (item)
2189 "Non-nil if ITEM is present in this node."
2190 (condition-case nil
2191 (Info-extract-pointer item)
2192 (error nil)))
2193
2194 (easy-menu-define
2195 Info-mode-menu Info-mode-map
2196 "Menu for info files."
2197 '("Info"
2198 ["Up" Info-up :active (Info-check-pointer "up")
2199 :help "Go up in the Info tree"]
2200 ["Next" Info-next :active (Info-check-pointer "next")
2201 :help "Go to the next node"]
2202 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
2203 :help "Go to the previous node"]
2204 ["Backward" Info-backward-node
2205 :help "Go backward one node, considering all as a sequence"]
2206 ["Forward" Info-forward-node
2207 :help "Go forward one node, considering all as a sequence"]
2208 ["Beginning" beginning-of-buffer
2209 :help "Go to beginning of this node"]
2210 ["Top" Info-top-node
2211 :help "Go to top node of file"]
2212 ["Final Node" Info-final-node
2213 :help "Go to final node in this file"]
2214 ("Menu Item" ["You should never see this" report-emacs-bug t])
2215 ("Reference" ["You should never see this" report-emacs-bug t])
2216 ["Search..." Info-search
2217 :help "Search for regular expression in this Info file"]
2218 ["Go to Node..." Info-goto-node
2219 :help "Go to a named node"]
2220 ["Last" Info-last :active Info-history
2221 :help "Go to the last node you were at"]
2222 ("Index..."
2223 ["Lookup a String" Info-index
2224 :help "Look for a string in the index items"]
2225 ["Next Matching Item" Info-index-next
2226 :help "Look for another occurrence of previous item"])
2227 ["Edit" Info-edit :help "Edit contents of this node"
2228 :active Info-enable-edit]
2229 ["Copy Node Name" Info-copy-current-node-name
2230 :help "Copy the name of the current node into the kill ring"]
2231 ["Exit" Info-exit :help "Stop reading Info"]))
2232
2233
2234 (defvar info-tool-bar-map
2235 (if (display-graphic-p)
2236 (let ((map (make-sparse-keymap)))
2237 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
2238 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
2239 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
2240 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
2241 (tool-bar-local-item-from-menu 'Info-last "undo" map Info-mode-map)
2242 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
2243 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
2244 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
2245 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
2246 map)))
2247
2248 (defvar Info-menu-last-node nil)
2249 ;; Last node the menu was created for.
2250 ;; Value is a list, (FILE-NAME NODE-NAME).
2251
2252 (defun Info-menu-update ()
2253 "Update the Info menu for the current node."
2254 (condition-case nil
2255 (if (or (not (eq major-mode 'Info-mode))
2256 (equal (list Info-current-file Info-current-node)
2257 Info-menu-last-node))
2258 ()
2259 ;; Update menu menu.
2260 (let* ((Info-complete-menu-buffer (current-buffer))
2261 (items (nreverse (condition-case nil
2262 (Info-complete-menu-item "" nil t)
2263 (error nil))))
2264 entries current
2265 (number 0))
2266 (while (and items (< number 9))
2267 (setq current (car items)
2268 items (cdr items)
2269 number (1+ number))
2270 (setq entries (cons `[,current
2271 (Info-menu ,current)
2272 :keys ,(format "%d" number)]
2273 entries)))
2274 (if items
2275 (setq entries (cons ["Other..." Info-menu t] entries)))
2276 (or entries
2277 (setq entries (list ["No menu" nil nil] nil :active)))
2278 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
2279 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2280 (let ((items nil)
2281 str i entries current
2282 (number 0)
2283 (case-fold-search t))
2284 (save-excursion
2285 (goto-char (point-min))
2286 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
2287 (setq str (buffer-substring
2288 (match-beginning 1)
2289 (1- (point))))
2290 (setq i 0)
2291 (while (setq i (string-match "[ \n\t]+" str i))
2292 (setq str (concat (substring str 0 i) " "
2293 (substring str (match-end 0))))
2294 (setq i (1+ i)))
2295 (setq items
2296 (cons str items))))
2297 (while (and items (< number 9))
2298 (setq current (car items)
2299 items (cdr items)
2300 number (1+ number))
2301 (setq entries (cons `[,current
2302 (Info-follow-reference ,current)
2303 t]
2304 entries)))
2305 (if items
2306 (setq entries (cons ["Other..." Info-follow-reference t]
2307 entries)))
2308 (or entries
2309 (setq entries (list ["No references" nil nil] nil :active)))
2310 (easy-menu-change '("Info") "Reference" (nreverse entries)))
2311 ;; Update last seen node.
2312 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
2313 ;; Try to avoid entering infinite beep mode in case of errors.
2314 (error (ding))))
2315
2316 \f
2317 (defun Info-copy-current-node-name ()
2318 "Put the name of the current info node into the kill ring.
2319 The name of the info file is prepended to the node name in parentheses."
2320 (interactive)
2321 (unless Info-current-node
2322 (error "No current info node"))
2323 (kill-new
2324 (concat "("
2325 (file-name-nondirectory
2326 (if (stringp Info-current-file)
2327 Info-current-file
2328 (or buffer-file-name "")))
2329 ")"
2330 Info-current-node)))
2331
2332 \f
2333 ;; Info mode is suitable only for specially formatted data.
2334 (put 'Info-mode 'mode-class 'special)
2335 (put 'Info-mode 'no-clone-indirect t)
2336
2337 (defun Info-mode ()
2338 "Info mode provides commands for browsing through the Info documentation tree.
2339 Documentation in Info is divided into \"nodes\", each of which discusses
2340 one topic and contains references to other nodes which discuss related
2341 topics. Info has commands to follow the references and show you other nodes.
2342
2343 \\<Info-mode-map>\
2344 \\[Info-help] Invoke the Info tutorial.
2345 \\[Info-exit] Quit Info: reselect previously selected buffer.
2346
2347 Selecting other nodes:
2348 \\[Info-mouse-follow-nearest-node]
2349 Follow a node reference you click on.
2350 This works with menu items, cross references, and
2351 the \"next\", \"previous\" and \"up\", depending on where you click.
2352 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2353 \\[Info-next] Move to the \"next\" node of this node.
2354 \\[Info-prev] Move to the \"previous\" node of this node.
2355 \\[Info-up] Move \"up\" from this node.
2356 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2357 Picking a menu item causes another node to be selected.
2358 \\[Info-directory] Go to the Info directory node.
2359 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2360 \\[Info-last] Move to the last node you were at.
2361 \\[Info-index] Look up a topic in this file's Index and move to that node.
2362 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2363 \\[Info-top-node] Go to the Top node of this file.
2364 \\[Info-final-node] Go to the final node in this file.
2365 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2366 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2367
2368 Moving within a node:
2369 \\[Info-scroll-up] Normally, scroll forward a full screen.
2370 Once you scroll far enough in a node that its menu appears on the
2371 screen but after point, the next scroll moves into its first
2372 subnode. When after all menu items (or if there is no menu),
2373 move up to the parent node.
2374 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2375 already visible, try to go to the previous menu entry, or up
2376 if there is none.
2377 \\[beginning-of-buffer] Go to beginning of node.
2378
2379 Advanced commands:
2380 \\[Info-exit] Quit Info: reselect previously selected buffer.
2381 \\[Info-edit] Edit contents of selected node.
2382 1 Pick first item in node's menu.
2383 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2384 \\[Info-goto-node] Move to node specified by name.
2385 You may include a filename as well, as (FILENAME)NODENAME.
2386 \\[universal-argument] \\[info] Move to new Info file with completion.
2387 \\[Info-search] Search through this Info file for specified regexp,
2388 and select the node in which the next occurrence is found.
2389 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2390 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2391 (kill-all-local-variables)
2392 (setq major-mode 'Info-mode)
2393 (setq mode-name "Info")
2394 (setq tab-width 8)
2395 (use-local-map Info-mode-map)
2396 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
2397 (set-syntax-table text-mode-syntax-table)
2398 (setq local-abbrev-table text-mode-abbrev-table)
2399 (setq case-fold-search t)
2400 (setq buffer-read-only t)
2401 (make-local-variable 'Info-current-file)
2402 (make-local-variable 'Info-current-subfile)
2403 (make-local-variable 'Info-current-node)
2404 (make-local-variable 'Info-tag-table-marker)
2405 (setq Info-tag-table-marker (make-marker))
2406 (make-local-variable 'Info-tag-table-buffer)
2407 (setq Info-tag-table-buffer nil)
2408 (make-local-variable 'Info-history)
2409 (make-local-variable 'Info-index-alternatives)
2410 (make-local-variable 'Info-header-line)
2411 (setq header-line-format (if Info-use-header-line 'Info-header-line))
2412 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
2413 ;; This is for the sake of the invisible text we use handling titles.
2414 (make-local-variable 'line-move-ignore-invisible)
2415 (setq line-move-ignore-invisible t)
2416 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
2417 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
2418 (Info-set-mode-line)
2419 (run-hooks 'Info-mode-hook))
2420
2421 (defun Info-clone-buffer-hook ()
2422 (when (bufferp Info-tag-table-buffer)
2423 (setq Info-tag-table-buffer
2424 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
2425 (let ((m Info-tag-table-marker))
2426 (when (markerp m)
2427 (setq Info-tag-table-marker
2428 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
2429 (with-current-buffer Info-tag-table-buffer
2430 (copy-marker (marker-position m)))
2431 (make-marker))))))
2432
2433 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
2434 (set-keymap-parent map text-mode-map)
2435 (define-key map "\C-c\C-c" 'Info-cease-edit)
2436 map)
2437 "Local keymap used within `e' command of Info.")
2438
2439 ;; Info-edit mode is suitable only for specially formatted data.
2440 (put 'Info-edit-mode 'mode-class 'special)
2441
2442 (defun Info-edit-mode ()
2443 "Major mode for editing the contents of an Info node.
2444 Like text mode with the addition of `Info-cease-edit'
2445 which returns to Info mode for browsing.
2446 \\{Info-edit-map}"
2447 (use-local-map Info-edit-map)
2448 (setq major-mode 'Info-edit-mode)
2449 (setq mode-name "Info Edit")
2450 (kill-local-variable 'mode-line-buffer-identification)
2451 (setq buffer-read-only nil)
2452 (force-mode-line-update)
2453 (buffer-enable-undo (current-buffer))
2454 (run-hooks 'Info-edit-mode-hook))
2455
2456 (defun Info-edit ()
2457 "Edit the contents of this Info node.
2458 Allowed only if variable `Info-enable-edit' is non-nil."
2459 (interactive)
2460 (or Info-enable-edit
2461 (error "Editing info nodes is not enabled"))
2462 (Info-edit-mode)
2463 (message "%s" (substitute-command-keys
2464 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2465
2466 (defun Info-cease-edit ()
2467 "Finish editing Info node; switch back to Info proper."
2468 (interactive)
2469 ;; Do this first, so nothing has changed if user C-g's at query.
2470 (and (buffer-modified-p)
2471 (y-or-n-p "Save the file? ")
2472 (save-buffer))
2473 (use-local-map Info-mode-map)
2474 (setq major-mode 'Info-mode)
2475 (setq mode-name "Info")
2476 (Info-set-mode-line)
2477 (setq buffer-read-only t)
2478 (force-mode-line-update)
2479 (and (marker-position Info-tag-table-marker)
2480 (buffer-modified-p)
2481 (message "Tags may have changed. Use Info-tagify if necessary")))
2482 \f
2483 (defvar Info-file-list-for-emacs
2484 '("ediff" "eudc" "forms" "gnus" "info" ("mh" . "mh-e")
2485 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
2486 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
2487 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
2488 ("skeleton" . "autotype") ("auto-insert" . "autotype")
2489 ("copyright" . "autotype") ("executable" . "autotype")
2490 ("time-stamp" . "autotype") ("quickurl" . "autotype")
2491 ("tempo" . "autotype") ("hippie-expand" . "autotype")
2492 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
2493 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
2494 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
2495 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
2496 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
2497 ("rfc2045" . "emacs-mime")
2498 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
2499 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
2500 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
2501 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
2502 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
2503 ("mml" . "emacs-mime"))
2504 "List of Info files that describe Emacs commands.
2505 An element can be a file name, or a list of the form (PREFIX . FILE)
2506 where PREFIX is a name prefix and FILE is the file to look in.
2507 If the element is just a file name, the file name also serves as the prefix.")
2508
2509 (defun Info-find-emacs-command-nodes (command)
2510 "Return a list of locations documenting COMMAND.
2511 The `info-file' property of COMMAND says which Info manual to search.
2512 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2513 defines heuristics for which Info manual to try.
2514 The locations are of the format used in `Info-history', i.e.
2515 \(FILENAME NODENAME BUFFERPOS\)."
2516 (let ((where '())
2517 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
2518 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
2519 (info-file "emacs")) ;default
2520 ;; Determine which info file this command is documented in.
2521 (if (get command 'info-file)
2522 (setq info-file (get command 'info-file))
2523 ;; If it doesn't say explicitly, test its name against
2524 ;; various prefixes that we know.
2525 (let ((file-list Info-file-list-for-emacs))
2526 (while file-list
2527 (let* ((elt (car file-list))
2528 (name (if (consp elt)
2529 (car elt)
2530 elt))
2531 (file (if (consp elt) (cdr elt) elt))
2532 (regexp (concat "\\`" (regexp-quote name)
2533 "\\(\\'\\|-\\)")))
2534 (if (string-match regexp (symbol-name command))
2535 (setq info-file file file-list nil))
2536 (setq file-list (cdr file-list))))))
2537 (Info-find-node info-file "Top")
2538 (or (and (search-forward "\n* menu:" nil t)
2539 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2540 (error "Info file `%s' appears to lack an index" info-file))
2541 (goto-char (match-beginning 1))
2542 ;; Bind Info-history to nil, to prevent the index nodes from
2543 ;; getting into the node history.
2544 (let ((Info-history nil)
2545 (exact nil)
2546 node found)
2547 (Info-goto-node (Info-extract-menu-node-name))
2548 (while
2549 (progn
2550 (goto-char (point-min))
2551 (while (re-search-forward cmd-desc nil t)
2552 (setq where
2553 (cons (list Info-current-file
2554 (match-string-no-properties 2)
2555 0)
2556 where)))
2557 (and (setq node (Info-extract-pointer "next" t))
2558 (string-match "\\<Index\\>" node)))
2559 (Info-goto-node node)))
2560 where))
2561
2562 ;;;###autoload
2563 (defun Info-goto-emacs-command-node (command)
2564 "Go to the Info node in the Emacs manual for command COMMAND.
2565 The command is found by looking up in Emacs manual's indices
2566 or in another manual found via COMMAND's `info-file' property or
2567 the variable `Info-file-list-for-emacs'."
2568 (interactive "CFind documentation for command: ")
2569 (or (commandp command)
2570 (signal 'wrong-type-argument (list 'commandp command)))
2571 (let ((where (Info-find-emacs-command-nodes command)))
2572 (if where
2573 (let ((num-matches (length where)))
2574 ;; Get Info running, and pop to it in another window.
2575 (save-window-excursion
2576 (info))
2577 ;; FIXME It would be cool if this could use a buffer other
2578 ;; than *info*.
2579 (pop-to-buffer "*info*")
2580 ;; Bind Info-history to nil, to prevent the last Index node
2581 ;; visited by Info-find-emacs-command-nodes from being
2582 ;; pushed onto the history.
2583 (let ((Info-history nil))
2584 (Info-find-node (car (car where))
2585 (car (cdr (car where)))))
2586 (if (> num-matches 1)
2587 (progn
2588 ;; (car where) will be pushed onto Info-history
2589 ;; when/if they go to another node. Put the other
2590 ;; nodes that were found on the history.
2591 (setq Info-history (nconc (cdr where) Info-history))
2592 (message "Found %d other entr%s. Use %s to see %s."
2593 (1- num-matches)
2594 (if (> num-matches 2) "ies" "y")
2595 (substitute-command-keys "\\[Info-last]")
2596 (if (> num-matches 2) "them" "it")))))
2597 (error "Couldn't find documentation for %s" command))))
2598
2599 ;;;###autoload
2600 (defun Info-goto-emacs-key-command-node (key)
2601 "Go to the node in the Emacs manual which describes the command bound to KEY.
2602 KEY is a string.
2603 Interactively, if the binding is `execute-extended-command', a command is read.
2604 The command is found by looking up in Emacs manual's indices
2605 or in another manual found via COMMAND's `info-file' property or
2606 the variable `Info-file-list-for-emacs'."
2607 (interactive "kFind documentation for key: ")
2608 (let ((command (key-binding key)))
2609 (cond ((null command)
2610 (message "%s is undefined" (key-description key)))
2611 ((and (interactive-p)
2612 (eq command 'execute-extended-command))
2613 (Info-goto-emacs-command-node
2614 (read-command "Find documentation for command: ")))
2615 (t
2616 (Info-goto-emacs-command-node command)))))
2617 \f
2618 (defface Info-title-1-face
2619 '((((type tty pc) (class color)) (:foreground "yellow" :weight bold))
2620 (t (:height 1.2 :inherit Info-title-2-face)))
2621 "Face for Info titles at level 1."
2622 :group 'info)
2623
2624 (defface Info-title-2-face
2625 '((((type tty pc) (class color)) (:foreground "lightblue" :weight bold))
2626 (t (:height 1.2 :inherit Info-title-3-face)))
2627 "Face for Info titles at level 2."
2628 :group 'info)
2629
2630 (defface Info-title-3-face
2631 '((((type tty pc) (class color)) (:weight bold))
2632 (t (:height 1.2 :inherit Info-title-4-face)))
2633 "Face for Info titles at level 3."
2634 :group 'info)
2635
2636 (defface Info-title-4-face
2637 '((((type tty pc) (class color)) (:weight bold))
2638 (t (:weight bold :inherit variable-pitch)))
2639 "Face for Info titles at level 4."
2640 :group 'info)
2641
2642 (defface info-menu-header
2643 '((((type tty pc))
2644 :underline t
2645 :weight bold)
2646 (t
2647 :inherit variable-pitch
2648 :weight bold))
2649 "Face for headers in Info menus."
2650 :group 'info)
2651
2652 (defun Info-fontify-menu-headers ()
2653 "Add the face `info-menu-header' to any header before a menu entry."
2654 (save-excursion
2655 (goto-char (point-min))
2656 (when (re-search-forward "\\* Menu:" nil t)
2657 (put-text-property (match-beginning 0) (match-end 0)
2658 'font-lock-face 'info-menu-header)
2659 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
2660 (put-text-property (match-beginning 1) (match-end 1)
2661 'font-lock-face 'info-menu-header)))))
2662
2663 (defvar Info-next-link-keymap
2664 (let ((keymap (make-sparse-keymap)))
2665 (define-key keymap [header-line mouse-1] 'Info-next)
2666 (define-key keymap [header-line mouse-2] 'Info-next)
2667 (define-key keymap [header-line down-mouse-1] 'ignore)
2668 (define-key keymap [mouse-2] 'Info-next)
2669 keymap)
2670 "Keymap to put on the Next link in the text or the header line.")
2671
2672 (defvar Info-prev-link-keymap
2673 (let ((keymap (make-sparse-keymap)))
2674 (define-key keymap [header-line mouse-1] 'Info-prev)
2675 (define-key keymap [header-line mouse-2] 'Info-prev)
2676 (define-key keymap [header-line down-mouse-1] 'ignore)
2677 (define-key keymap [mouse-2] 'Info-prev)
2678 keymap)
2679 "Keymap to put on the Prev link in the text or the header line.")
2680
2681
2682 (defvar Info-up-link-keymap
2683 (let ((keymap (make-sparse-keymap)))
2684 (define-key keymap [header-line mouse-1] 'Info-up)
2685 (define-key keymap [header-line mouse-2] 'Info-up)
2686 (define-key keymap [header-line down-mouse-1] 'ignore)
2687 (define-key keymap [mouse-2] 'Info-up)
2688 keymap)
2689 "Keymap to put on the Up link in the text or the header line.")
2690
2691 (defun Info-fontify-node ()
2692 ;; Only fontify the node if it hasn't already been done.
2693 (unless (next-property-change (point-min))
2694 (save-excursion
2695 (let ((inhibit-read-only t)
2696 (case-fold-search t)
2697 paragraph-markers)
2698 (goto-char (point-min))
2699 (when (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?")
2700 (goto-char (match-end 0))
2701 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2702 (goto-char (match-end 0))
2703 (let* ((nbeg (match-beginning 2))
2704 (nend (match-end 2))
2705 (tbeg (match-beginning 1))
2706 (tag (buffer-substring tbeg (match-end 1))))
2707 (if (string-equal tag "Node")
2708 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
2709 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
2710 (put-text-property tbeg nend 'mouse-face 'highlight)
2711 (put-text-property tbeg nend
2712 'help-echo
2713 (concat "Go to node "
2714 (buffer-substring nbeg nend)))
2715 ;; Always set up the text property keymap.
2716 ;; It will either be used in the buffer
2717 ;; or copied in the header line.
2718 (put-text-property tbeg nend 'keymap
2719 (cond
2720 ((equal tag "Prev") Info-prev-link-keymap)
2721 ((equal tag "Next") Info-next-link-keymap)
2722 ((equal tag "Up") Info-up-link-keymap))))))
2723 (when Info-use-header-line
2724 (goto-char (point-min))
2725 (let ((header-end (save-excursion (end-of-line) (point)))
2726 header)
2727 ;; If we find neither Next: nor Prev: link, show the entire
2728 ;; node header. Otherwise, don't show the File: and Node:
2729 ;; parts, to avoid wasting precious space on information that
2730 ;; is available in the mode line.
2731 (if (re-search-forward
2732 "\\(next\\|up\\|prev[ious]*\\): "
2733 header-end t)
2734 (progn
2735 (goto-char (match-beginning 1))
2736 (setq header (buffer-substring (point) header-end)))
2737 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" nil t)
2738 (setq header
2739 (concat "No next, prev or up links -- "
2740 (buffer-substring (point) header-end)))
2741 (setq header (buffer-substring (point) header-end))))
2742
2743 (put-text-property (point-min) (1+ (point-min))
2744 'header-line header)
2745 ;; Hide the part of the first line
2746 ;; that is in the header, if it is just part.
2747 (unless (bobp)
2748 ;; Hide the punctuation at the end, too.
2749 (skip-chars-backward " \t,")
2750 (put-text-property (point) header-end 'invisible t)))))
2751 (goto-char (point-min))
2752 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
2753 nil t)
2754 (let* ((c (preceding-char))
2755 (face
2756 (cond ((= c ?*) 'Info-title-1-face)
2757 ((= c ?=) 'Info-title-2-face)
2758 ((= c ?-) 'Info-title-3-face)
2759 (t 'Info-title-4-face))))
2760 (put-text-property (match-beginning 1) (match-end 1)
2761 'font-lock-face face))
2762 ;; This is a serious problem for trying to handle multiple
2763 ;; frame types at once. We want this text to be invisible
2764 ;; on frames that can display the font above.
2765 (when (memq (framep (selected-frame)) '(x pc w32 mac))
2766 (add-text-properties (match-beginning 2) (1+ (match-end 2))
2767 '(invisible t))))
2768 (goto-char (point-min))
2769 (while (re-search-forward "\\(\\*Note[ \n\t]*\\)\\([^:]*\\)\\(:[^.,:(]*\\(([^)]*)[^.,:]*\\)?[,:]?\n?\\)" nil t)
2770 (unless (= (char-after (1- (match-beginning 0))) ?\") ; hack
2771 (let ((start (match-beginning 0))
2772 (next (point))
2773 (hide-tag Info-hide-note-references)
2774 other-tag)
2775 (when hide-tag
2776 ;; *Note is often used where *note should have been
2777 (goto-char start)
2778 (skip-syntax-backward " ")
2779 (setq other-tag
2780 (cond
2781 ((or (<= (point) (point-min))
2782 (memq (char-after (1- (point))) '( ?\. ?! )))
2783 "See ")
2784 ((memq (char-after (1- (point))) '( ?\( ?\[ ?\{ ?\, ?\; ?\: ))
2785 "see ")
2786 (t nil)))
2787 (goto-char next))
2788 (if hide-tag
2789 (add-text-properties (match-beginning 1) (match-end 1)
2790 '(invisible t)))
2791 (add-text-properties (match-beginning 2) (match-end 2)
2792 '(font-lock-face info-xref
2793 mouse-face highlight
2794 help-echo "mouse-2: go to this node"))
2795 (when (eq Info-hide-note-references t)
2796 (add-text-properties (match-beginning 3) (match-end 3)
2797 '(invisible t)))
2798 (when other-tag
2799 (goto-char (match-beginning 1))
2800 (insert other-tag))
2801 (when (or hide-tag (eq Info-hide-note-references t))
2802 (setq paragraph-markers (cons (set-marker (make-marker) start)
2803 paragraph-markers))))))
2804
2805 (let ((fill-nobreak-invisible t))
2806 (goto-char (point-max))
2807 (while paragraph-markers
2808 (let ((m (car paragraph-markers)))
2809 (setq paragraph-markers (cdr paragraph-markers))
2810 (when (< m (point))
2811 (goto-char m)
2812 (fill-paragraph nil)
2813 (backward-paragraph 1))
2814 (set-marker m nil))))
2815
2816 (goto-char (point-min))
2817 (if (and (search-forward "\n* Menu:" nil t)
2818 (not (string-match "\\<Index\\>" Info-current-node))
2819 ;; Don't take time to annotate huge menus
2820 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2821 (let ((n 0)
2822 cont)
2823 (while (re-search-forward "^\\* +\\([^:\t\n]*\\)\\(:[^.,:(]*\\(([^)]*)[^.,:]*\\)?[,:.][ \t]*\\)" nil t)
2824 (setq n (1+ n))
2825 (if (zerop (% n 3)) ; visual aids to help with 1-9 keys
2826 (put-text-property (match-beginning 0)
2827 (1+ (match-beginning 0))
2828 'font-lock-face 'info-menu-5))
2829 (add-text-properties (match-beginning 1) (match-end 1)
2830 '(font-lock-face info-xref
2831 mouse-face highlight
2832 help-echo "mouse-2: go to this node"))
2833 (when (eq Info-hide-note-references t)
2834 (add-text-properties (match-beginning 2) (match-end 2)
2835 (list 'display
2836 (make-string (max 2 (- 22 (- (match-end 1) (match-beginning 1)))) ? )))
2837 (setq cont (looking-at "[ \t]*[^\n]")))
2838 (if (eq Info-hide-note-references t)
2839 (while (and (= (forward-line 1) 0)
2840 (looking-at "\\([ \t]+\\)[^*\n]"))
2841 (add-text-properties (match-beginning 1) (match-end 1)
2842 (list 'display (make-string (+ 22 (if cont 4 2)) ? )))
2843 (setq cont t))))))
2844
2845 (Info-fontify-menu-headers)
2846 (set-buffer-modified-p nil)))))
2847 \f
2848
2849 ;; When an Info buffer is killed, make sure the associated tags buffer
2850 ;; is killed too.
2851 (defun Info-kill-buffer ()
2852 (and (eq major-mode 'Info-mode)
2853 Info-tag-table-buffer
2854 (kill-buffer Info-tag-table-buffer)))
2855
2856 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2857
2858 ;;; Speedbar support:
2859 ;; These functions permit speedbar to display the "tags" in the
2860 ;; current info node.
2861 (eval-when-compile (require 'speedbar))
2862
2863 (defvar Info-speedbar-key-map nil
2864 "Keymap used when in the info display mode.")
2865
2866 (defun Info-install-speedbar-variables ()
2867 "Install those variables used by speedbar to enhance Info."
2868 (if Info-speedbar-key-map
2869 nil
2870 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2871
2872 ;; Basic tree features
2873 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2874 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2875 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2876 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2877 )
2878
2879 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2880 Info-speedbar-key-map
2881 Info-speedbar-hierarchy-buttons)))
2882
2883 (defvar Info-speedbar-menu-items
2884 '(["Browse Node" speedbar-edit-line t]
2885 ["Expand Node" speedbar-expand-line
2886 (save-excursion (beginning-of-line)
2887 (looking-at "[0-9]+: *.\\+. "))]
2888 ["Contract Node" speedbar-contract-line
2889 (save-excursion (beginning-of-line)
2890 (looking-at "[0-9]+: *.-. "))]
2891 )
2892 "Additional menu-items to add to speedbar frame.")
2893
2894 ;; Make sure our special speedbar major mode is loaded
2895 (if (featurep 'speedbar)
2896 (Info-install-speedbar-variables)
2897 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2898
2899 ;;; Info hierarchy display method
2900 ;;;###autoload
2901 (defun Info-speedbar-browser ()
2902 "Initialize speedbar to display an info node browser.
2903 This will add a speedbar major display mode."
2904 (interactive)
2905 (require 'speedbar)
2906 ;; Make sure that speedbar is active
2907 (speedbar-frame-mode 1)
2908 ;; Now, throw us into Info mode on speedbar.
2909 (speedbar-change-initial-expansion-list "Info")
2910 )
2911
2912 (eval-when-compile (defvar speedbar-attached-frame))
2913
2914 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2915 "Display an Info directory hierarchy in speedbar.
2916 DIRECTORY is the current directory in the attached frame.
2917 DEPTH is the current indentation depth.
2918 NODE is an optional argument that is used to represent the
2919 specific node to expand."
2920 (if (and (not node)
2921 (save-excursion (goto-char (point-min))
2922 (let ((case-fold-search t))
2923 (looking-at "Info Nodes:"))))
2924 ;; Update our "current node" maybe?
2925 nil
2926 ;; We cannot use the generic list code, that depends on all leaves
2927 ;; being known at creation time.
2928 (if (not node)
2929 (speedbar-with-writable (insert "Info Nodes:\n")))
2930 (let ((completions nil)
2931 (cf (selected-frame)))
2932 (select-frame speedbar-attached-frame)
2933 (save-window-excursion
2934 (setq completions
2935 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
2936 (select-frame cf)
2937 (if completions
2938 (speedbar-with-writable
2939 (while completions
2940 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2941 (cdr (car completions))
2942 (car (car completions))
2943 'Info-speedbar-goto-node
2944 (cdr (car completions))
2945 'info-xref depth)
2946 (setq completions (cdr completions)))
2947 t)
2948 nil))))
2949
2950 (defun Info-speedbar-goto-node (text node indent)
2951 "When user clicks on TEXT, go to an info NODE.
2952 The INDENT level is ignored."
2953 (select-frame speedbar-attached-frame)
2954 (let* ((buff (or (get-buffer "*info*")
2955 (progn (info) (get-buffer "*info*"))))
2956 (bwin (get-buffer-window buff 0)))
2957 (if bwin
2958 (progn
2959 (select-window bwin)
2960 (raise-frame (window-frame bwin)))
2961 (if speedbar-power-click
2962 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2963 (select-frame speedbar-attached-frame)
2964 (switch-to-buffer buff)))
2965 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
2966 (file (match-string 1 node))
2967 (node (match-string 2 node)))
2968 (Info-find-node file node)
2969 ;; If we do a find-node, and we were in info mode, restore
2970 ;; the old default method. Once we are in info mode, it makes
2971 ;; sense to return to whatever method the user was using before.
2972 (if (string= speedbar-initial-expansion-list-name "Info")
2973 (speedbar-change-initial-expansion-list
2974 speedbar-previously-used-expansion-list-name)))))
2975
2976 (defun Info-speedbar-expand-node (text token indent)
2977 "Expand the node the user clicked on.
2978 TEXT is the text of the button we clicked on, a + or - item.
2979 TOKEN is data related to this node (NAME . FILE).
2980 INDENT is the current indentation depth."
2981 (cond ((string-match "+" text) ;we have to expand this file
2982 (speedbar-change-expand-button-char ?-)
2983 (if (speedbar-with-writable
2984 (save-excursion
2985 (end-of-line) (forward-char 1)
2986 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
2987 (speedbar-change-expand-button-char ?-)
2988 (speedbar-change-expand-button-char ??)))
2989 ((string-match "-" text) ;we have to contract this node
2990 (speedbar-change-expand-button-char ?+)
2991 (speedbar-delete-subblock indent))
2992 (t (error "Ooops... not sure what to do")))
2993 (speedbar-center-buffer-smartly))
2994
2995 (defun Info-speedbar-fetch-file-nodes (nodespec)
2996 "Fetch the subnodes from the info NODESPEC.
2997 NODESPEC is a string of the form: (file)node.
2998 Optional THISFILE represends the filename of"
2999 (save-excursion
3000 ;; Set up a buffer we can use to fake-out Info.
3001 (set-buffer (get-buffer-create "*info-browse-tmp*"))
3002 (if (not (equal major-mode 'Info-mode))
3003 (Info-mode))
3004 ;; Get the node into this buffer
3005 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
3006 (file (match-string 1 nodespec))
3007 (node (match-string 2 nodespec)))
3008 (Info-find-node file node))
3009 ;; Scan the created buffer
3010 (goto-char (point-min))
3011 (let ((completions nil)
3012 (case-fold-search t)
3013 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
3014 (match-string 1 nodespec))))
3015 ;; Always skip the first one...
3016 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3017 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3018 (let ((name (match-string 1)))
3019 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
3020 (setq name (cons name (match-string 1)))
3021 (if (looking-at " *\\(([^)]+)\\)\\.")
3022 (setq name (cons name (concat (match-string 1) "Top")))
3023 (if (looking-at " \\([^.]+\\).")
3024 (setq name
3025 (cons name (concat "(" thisfile ")" (match-string 1))))
3026 (setq name (cons name (concat "(" thisfile ")" name))))))
3027 (setq completions (cons name completions))))
3028 (nreverse completions))))
3029
3030 ;;; Info mode node listing
3031 (defun Info-speedbar-buttons (buffer)
3032 "Create a speedbar display to help navigation in an Info file.
3033 BUFFER is the buffer speedbar is requesting buttons for."
3034 (if (save-excursion (goto-char (point-min))
3035 (let ((case-fold-search t))
3036 (not (looking-at "Info Nodes:"))))
3037 (erase-buffer))
3038 (Info-speedbar-hierarchy-buttons nil 0)
3039 )
3040
3041 (dolist (mess '("^Node has no Previous$"
3042 "^No menu in this node$"
3043 "^Node has no Next$"
3044 "^No cross-references in this node^"
3045 search-failed
3046 "^No \".*\" in index$"))
3047 (add-to-list 'debug-ignored-errors mess))
3048
3049 (provide 'info)
3050
3051 ;;; info.el ends here