(cwarn) <defgroup>: Add :version, :link.
[emacs.git] / lisp / info.el
blobeb71449e6c4a699119c995d6027185d14591f27f
1 ;;; info.el --- info package for Emacs.
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99, 2000 Free Software
4 ;; Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: help
9 ;; This file is part of GNU Emacs.
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.
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.
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.
26 ;;; Commentary:
28 ;; Note that nowadays we expect info files to be made using makeinfo.
30 ;;; Code:
32 (eval-when-compile (require 'jka-compr))
34 (defgroup info nil
35 "Info subsystem"
36 :group 'help
37 :group 'docs)
40 (defvar Info-history nil
41 "List of info nodes user has visited.
42 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
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)
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)
58 (defcustom Info-fontify t
59 "*Non-nil enables highlighting and fonts in Info nodes."
60 :type 'boolean
61 :group 'info)
63 (defface info-node
64 '((((class color)) (:foreground "brown" :bold t :italic t))
65 (t (:bold t :italic t)))
66 "Face for Info node names."
67 :group 'info)
69 (defface info-menu-5
70 '((((class color)) (:foreground "red1"))
71 (t (:underline t)))
72 "Face for the fifth and tenth `*' in an Info menu."
73 :group 'info)
75 (defface info-xref
76 '((((class color)) (:foreground "magenta4" :bold t))
77 (t (:bold t)))
78 "Face for Info cross-references."
79 :group 'info)
81 (defcustom Info-fontify-maximum-menu-size 100000
82 "*Maximum size of menu to fontify if `Info-fontify' is non-nil."
83 :type 'integer
84 :group 'info)
86 (defvar Info-directory-list nil
87 "List of directories to search for Info documentation files.
88 nil means not yet initialized. In this case, Info uses the environment
89 variable INFOPATH to initialize it, or `Info-default-directory-list'
90 if there is no INFOPATH variable in the environment.
91 The last element of `Info-default-directory-list' is the directory
92 where Emacs installs the Info files that come with it.
94 If you run the Emacs executable from the `src' directory in the Emacs
95 source tree, the `info' directory in the source tree is used as the last
96 element, in place of the installation Info directory. This is useful
97 when you run a version of Emacs without installing it.")
99 (defcustom Info-additional-directory-list nil
100 "List of additional directories to search for Info documentation files.
101 These directories are not searched for merging the `dir' file."
102 :type '(repeat directory)
103 :group 'info)
105 (defvar Info-current-file nil
106 "Info file that Info is now looking at, or nil.
107 This is the name that was specified in Info, not the actual file name.
108 It doesn't contain directory names or file name extensions added by Info.
109 Can also be t when using `Info-on-current-buffer'.")
111 (defvar Info-current-subfile nil
112 "Info subfile that is actually in the *info* buffer now.
113 nil if current info file is not split into subfiles.")
115 (defvar Info-current-node nil
116 "Name of node that Info is now looking at, or nil.")
118 (defvar Info-tag-table-marker nil
119 "Marker pointing at beginning of current Info file's tag table.
120 Marker points nowhere if file has no tag table.")
122 (defvar Info-tag-table-buffer nil
123 "Buffer used for indirect tag tables.")
125 (defvar Info-current-file-completions nil
126 "Cached completion list for current Info file.")
128 (defvar Info-index-alternatives nil
129 "List of possible matches for last `Info-index' command.")
131 (defvar Info-standalone nil
132 "Non-nil if Emacs was started solely as an Info browser.")
134 (defvar Info-suffix-list
135 ;; The MS-DOS list should work both when long file names are
136 ;; supported (Windows 9X), and when only 8+3 file names are available.
137 (if (eq system-type 'ms-dos)
138 '( (".gz" . "gunzip")
139 (".z" . "gunzip")
140 (".bz2" . "bzip2 -dc")
141 (".inz" . "gunzip")
142 (".igz" . "gunzip")
143 (".info.Z" . "gunzip")
144 (".info.gz" . "gunzip")
145 ("-info.Z" . "gunzip")
146 ("-info.gz" . "gunzip")
147 ("/index.gz". "gunzip")
148 ("/index.z" . "gunzip")
149 (".inf" . nil)
150 (".info" . nil)
151 ("-info" . nil)
152 ("/index" . nil)
153 ("" . nil))
154 '( (".info.Z". "uncompress")
155 (".info.Y". "unyabba")
156 (".info.gz". "gunzip")
157 (".info.z". "gunzip")
158 (".info.bz2" . "bzip2 -dc")
159 (".info". nil)
160 ("-info.Z". "uncompress")
161 ("-info.Y". "unyabba")
162 ("-info.gz". "gunzip")
163 ("-info.bz2" . "bzip2 -dc")
164 ("-info.z". "gunzip")
165 ("-info". nil)
166 ("/index.Z". "uncompress")
167 ("/index.Y". "unyabba")
168 ("/index.gz". "gunzip")
169 ("/index.z". "gunzip")
170 ("/index.bz2". "bzip2 -dc")
171 ("/index". nil)
172 (".Z". "uncompress")
173 (".Y". "unyabba")
174 (".gz". "gunzip")
175 (".z". "gunzip")
176 (".bz2" . "bzip2 -dc")
177 ("". nil)))
178 "List of file name suffixes and associated decoding commands.
179 Each entry should be (SUFFIX . STRING); the file is given to
180 the command as standard input. If STRING is nil, no decoding is done.
181 Because the SUFFIXes are tried in order, the empty string should
182 be last in the list.")
184 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
185 ;; First, on ms-dos, delete some of the extension in FILENAME
186 ;; to make room.
187 (defun info-insert-file-contents-1 (filename suffix)
188 (if (not (eq system-type 'ms-dos))
189 (concat filename suffix)
190 (let* ((sans-exts (file-name-sans-extension filename))
191 ;; How long is the extension in FILENAME (not counting the dot).
192 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
193 ext-left)
194 ;; SUFFIX starts with a dot. If FILENAME already has one,
195 ;; get rid of the one in SUFFIX (unless suffix is empty).
196 (or (and (<= ext-len 0)
197 (not (eq (aref filename (1- (length filename))) ?.)))
198 (= (length suffix) 0)
199 (setq suffix (substring suffix 1)))
200 ;; How many chars of that extension should we keep?
201 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
202 ;; Get rid of the rest of the extension, and add SUFFIX.
203 (concat (substring filename 0 (- (length filename)
204 (- ext-len ext-left)))
205 suffix))))
207 (defun info-file-exists-p (filename)
208 (and (file-exists-p filename)
209 (not (file-directory-p filename))))
211 (defun info-insert-file-contents (filename &optional visit)
212 "Insert the contents of an info file in the current buffer.
213 Do the right thing if the file has been compressed or zipped."
214 (let ((tail Info-suffix-list)
215 fullname decoder)
216 (if (file-exists-p filename)
217 ;; FILENAME exists--see if that name contains a suffix.
218 ;; If so, set DECODE accordingly.
219 (progn
220 (while (and tail
221 (not (string-match
222 (concat (regexp-quote (car (car tail))) "$")
223 filename)))
224 (setq tail (cdr tail)))
225 (setq fullname filename
226 decoder (cdr (car tail))))
227 ;; Try adding suffixes to FILENAME and see if we can find something.
228 (while (and tail
229 (not (info-file-exists-p (info-insert-file-contents-1
230 filename (car (car tail))))))
231 (setq tail (cdr tail)))
232 ;; If we found a file with a suffix, set DECODER according to the suffix
233 ;; and set FULLNAME to the file's actual name.
234 (setq fullname (info-insert-file-contents-1 filename (car (car tail)))
235 decoder (cdr (car tail)))
236 (or tail
237 (error "Can't find %s or any compressed version of it" filename)))
238 ;; check for conflict with jka-compr
239 (if (and (featurep 'jka-compr)
240 (jka-compr-installed-p)
241 (jka-compr-get-compression-info fullname))
242 (setq decoder nil))
243 (if decoder
244 (progn
245 (insert-file-contents-literally fullname visit)
246 (let ((buffer-read-only nil)
247 (coding-system-for-write 'no-conversion)
248 (default-directory (or (file-name-directory fullname)
249 default-directory)))
250 (call-process-region (point-min) (point-max) decoder t t)))
251 (insert-file-contents fullname visit))))
253 (defun info-initialize ()
254 "Initialize `Info-directory-list', if that hasn't been done yet."
255 (unless Info-directory-list
256 (let ((path (getenv "INFOPATH"))
257 (source (expand-file-name "info/" source-directory))
258 (sibling (if installation-directory
259 (expand-file-name "info/" installation-directory)))
260 alternative)
261 (setq Info-directory-list
262 (prune-directory-list
263 (if path
264 (split-string path (regexp-quote path-separator))
265 (if (and sibling (file-exists-p sibling))
266 ;; Uninstalled, Emacs builddir != srcdir.
267 (setq alternative sibling)
268 ;; Uninstalled, builddir == srcdir
269 (setq alternative source))
270 (if (or (member alternative Info-default-directory-list)
271 ;; On DOS/NT, we use movable executables always,
272 ;; and we must always find the Info dir at run time.
273 (if (memq system-type '(ms-dos windows-nt))
275 ;; Use invocation-directory for Info
276 ;; only if we used it for exec-directory also.
277 (not (string= exec-directory
278 (expand-file-name "lib-src/"
279 installation-directory))))
280 (not (file-exists-p alternative)))
281 Info-default-directory-list
282 ;; `alternative' contains the Info files that came with this
283 ;; version, so we should look there first. `Info-insert-dir'
284 ;; currently expects to find `alternative' first on the list.
285 (cons alternative
286 (reverse (cdr (reverse Info-default-directory-list)))))))))))
288 ;;;###autoload
289 (defun info-other-window (&optional file)
290 "Like `info' but show the Info buffer in another window."
291 (interactive (if current-prefix-arg
292 (list (read-file-name "Info file name: " nil nil t))))
293 (let (same-window-buffer-names)
294 (info file)))
296 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
298 ;;;###autoload
299 (defun info (&optional file)
300 "Enter Info, the documentation browser.
301 Optional argument FILE specifies the file to examine;
302 the default is the top-level directory of Info.
303 Called from a program, FILE may specify an Info node of the form
304 `(FILENAME)NODENAME'.
306 In interactive use, a prefix argument directs this command
307 to read a file name from the minibuffer.
309 The search path for Info files is in the variable `Info-directory-list'.
310 The top-level Info directory is made by combining all the files named `dir'
311 in all the directories in that path."
312 (interactive (if current-prefix-arg
313 (list (read-file-name "Info file name: " nil nil t))))
314 (if file
315 (progn
316 (pop-to-buffer "*info*")
317 ;; If argument already contains parentheses, don't add another set
318 ;; since the argument will then be parsed improperly. This also
319 ;; has the added benefit of allowing node names to be included
320 ;; following the parenthesized filename.
321 (if (and (stringp file) (string-match "(.*)" file))
322 (Info-goto-node file)
323 (Info-goto-node (concat "(" file ")"))))
324 (if (get-buffer "*info*")
325 (pop-to-buffer "*info*")
326 (Info-directory))))
328 ;;;###autoload
329 (defun info-standalone ()
330 "Run Emacs as a standalone Info reader.
331 Usage: emacs -f info-standalone [filename]
332 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
333 (setq Info-standalone t)
334 (if (and command-line-args-left
335 (not (string-match "^-" (car command-line-args-left))))
336 (condition-case err
337 (progn
338 (info (car command-line-args-left))
339 (setq command-line-args-left (cdr command-line-args-left)))
340 (error (send-string-to-terminal
341 (format "%s\n" (if (eq (car-safe err) 'error)
342 (nth 1 err) err)))
343 (save-buffers-kill-emacs)))
344 (info)))
346 ;; See if the the accessible portion of the buffer begins with a node
347 ;; delimiter, and the node header line which follows matches REGEXP.
348 ;; Typically, this test will be followed by a loop that examines the
349 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
350 ;; to have the overhead of this special test inside the loop.
352 ;; This function changes match-data, but supposedly the caller might
353 ;; want to use the results of re-search-backward.
355 ;; The return value is the value of point at the beginning of matching
356 ;; REGERXP, if the function succeeds, nil otherwise.
357 (defun Info-node-at-bob-matching (regexp)
358 (and (bobp) ; are we at beginning of buffer?
359 (looking-at "\^_") ; does it begin with node delimiter?
360 (let (beg)
361 (forward-line 1)
362 (setq beg (point))
363 (forward-line 1) ; does the line after delimiter match REGEXP?
364 (re-search-backward regexp beg t))))
366 (defun Info-find-node (filename nodename &optional no-going-back)
367 "Go to an info node specified as separate FILENAME and NODENAME.
368 NO-GOING-BACK is non-nil if recovering from an error in this function;
369 it says do not attempt further (recursive) error recovery."
370 (info-initialize)
371 ;; Convert filename to lower case if not found as specified.
372 ;; Expand it.
373 (if (stringp filename)
374 (let (temp temp-downcase found)
375 (setq filename (substitute-in-file-name filename))
376 (if (string= (downcase filename) "dir")
377 (setq found t)
378 (let ((dirs (if (string-match "^\\./" filename)
379 ;; If specified name starts with `./'
380 ;; then just try current directory.
381 '("./")
382 (if (file-name-absolute-p filename)
383 ;; No point in searching for an
384 ;; absolute file name
385 '(nil)
386 (if Info-additional-directory-list
387 (append Info-directory-list
388 Info-additional-directory-list)
389 Info-directory-list)))))
390 ;; Search the directory list for file FILENAME.
391 (while (and dirs (not found))
392 (setq temp (expand-file-name filename (car dirs)))
393 (setq temp-downcase
394 (expand-file-name (downcase filename) (car dirs)))
395 ;; Try several variants of specified name.
396 (let ((suffix-list Info-suffix-list))
397 (while (and suffix-list (not found))
398 (cond ((info-file-exists-p
399 (info-insert-file-contents-1
400 temp (car (car suffix-list))))
401 (setq found temp))
402 ((info-file-exists-p
403 (info-insert-file-contents-1
404 temp-downcase (car (car suffix-list))))
405 (setq found temp-downcase)))
406 (setq suffix-list (cdr suffix-list))))
407 (setq dirs (cdr dirs)))))
408 (if found
409 (setq filename found)
410 (error "Info file %s does not exist" filename))))
411 ;; Record the node we are leaving.
412 (if (and Info-current-file (not no-going-back))
413 (setq Info-history
414 (cons (list Info-current-file Info-current-node (point))
415 Info-history)))
416 ;; Go into info buffer.
417 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
418 (Info-find-node-2 filename nodename no-going-back))
420 (defun Info-on-current-buffer (&optional nodename)
421 "Use the `Info-mode' to browse the current info buffer.
422 If a prefix arg is provided, it queries for the NODENAME which
423 else defaults to `Top'."
424 (interactive
425 (list (if current-prefix-arg
426 (completing-read "Node name: " (Info-build-node-completions)
427 nil t "Top")
428 "Top")))
429 (info-initialize)
430 (Info-mode)
431 (set (make-local-variable 'Info-current-file) t)
432 (Info-find-node-2 nil nodename))
434 (defun Info-find-in-tag-table-1 (marker regexp case-fold)
435 "Find a node in a tag table.
436 MARKER specifies the buffer and position to start searching at.
437 REGEXP is a regular expression matching nodes or references. Its first
438 group should match `Node:' or `Ref:'.
439 CASE-FOLD t means search for a case-insensitive match.
440 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
441 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
442 where the match was found, and MODE is `major-mode' of the buffer in
443 which the match was found."
444 (let ((case-fold-search case-fold)
445 found-mode guesspos found-anchor)
446 (save-excursion
447 (set-buffer (marker-buffer marker))
448 (goto-char marker)
450 ;; Search tag table
451 (beginning-of-line)
452 (when (re-search-forward regexp nil t)
453 (list (string-equal "Ref:" (match-string 1))
454 (1+ (read (current-buffer)))
455 major-mode)))))
457 (defun Info-find-in-tag-table (marker regexp)
458 "Find a node in a tag table.
459 MARKER specifies the buffer and position to start searching at.
460 REGEXP is a regular expression matching nodes or references. Its first
461 group should match `Node:' or `Ref:'.
462 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
463 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
464 where the match was found, and MODE is `major-mode' of the buffer in
465 which the match was found.
466 This function tries to find a case-sensitive match first, then a
467 case-insensitive match is tried."
468 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
469 (when (null (car result))
470 (setq result (Info-find-in-tag-table-1 marker regexp t)))
471 result))
473 (defun Info-find-node-in-buffer-1 (regexp case-fold)
474 "Find a node or anchor in the current buffer.
475 REGEXP is a regular expression matching nodes or references. Its first
476 group should match `Node:' or `Ref:'.
477 CASE-FOLD t means search for a case-insensitive match.
478 Value is the position at which a match was found, or nil if not found."
479 (let ((case-fold-search case-fold)
480 found)
481 (save-excursion
482 (when (Info-node-at-bob-matching regexp)
483 (setq found (point)))
484 (while (and (not found)
485 (search-forward "\n\^_" nil t))
486 (forward-line 1)
487 (let ((beg (point)))
488 (forward-line 1)
489 (when (re-search-backward regexp beg t)
490 (beginning-of-line)
491 (setq found (point)))))
492 found)))
494 (defun Info-find-node-in-buffer (regexp)
495 "Find a node or anchor in the current buffer.
496 REGEXP is a regular expression matching nodes or references. Its first
497 group should match `Node:' or `Ref:'.
498 Value is the position at which a match was found, or nil if not found.
499 This function looks for a case-sensitive match first. If none is found,
500 a case-insensitive match is tried."
501 (or (Info-find-node-in-buffer-1 regexp nil)
502 (Info-find-node-in-buffer-1 regexp t)))
504 (defun Info-find-node-2 (filename nodename &optional no-going-back)
505 (buffer-disable-undo (current-buffer))
506 (or (eq major-mode 'Info-mode)
507 (Info-mode))
508 (widen)
509 (setq Info-current-node nil)
510 (unwind-protect
511 (let ((case-fold-search t)
512 anchorpos)
513 ;; Switch files if necessary
514 (or (null filename)
515 (equal Info-current-file filename)
516 (let ((buffer-read-only nil))
517 (setq Info-current-file nil
518 Info-current-subfile nil
519 Info-current-file-completions nil
520 buffer-file-name nil)
521 (erase-buffer)
522 (if (eq filename t)
523 (Info-insert-dir)
524 (info-insert-file-contents filename t)
525 (setq default-directory (file-name-directory filename)))
526 (set-buffer-modified-p nil)
527 ;; See whether file has a tag table. Record the location if yes.
528 (goto-char (point-max))
529 (forward-line -8)
530 ;; Use string-equal, not equal, to ignore text props.
531 (if (not (or (string-equal nodename "*")
532 (not
533 (search-forward "\^_\nEnd tag table\n" nil t))))
534 (let (pos)
535 ;; We have a tag table. Find its beginning.
536 ;; Is this an indirect file?
537 (search-backward "\nTag table:\n")
538 (setq pos (point))
539 (if (save-excursion
540 (forward-line 2)
541 (looking-at "(Indirect)\n"))
542 ;; It is indirect. Copy it to another buffer
543 ;; and record that the tag table is in that buffer.
544 (let ((buf (current-buffer))
545 (tagbuf
546 (or Info-tag-table-buffer
547 (generate-new-buffer " *info tag table*"))))
548 (setq Info-tag-table-buffer tagbuf)
549 (save-excursion
550 (set-buffer tagbuf)
551 (buffer-disable-undo (current-buffer))
552 (setq case-fold-search t)
553 (erase-buffer)
554 (insert-buffer-substring buf))
555 (set-marker Info-tag-table-marker
556 (match-end 0) tagbuf))
557 (set-marker Info-tag-table-marker pos)))
558 (set-marker Info-tag-table-marker nil))
559 (setq Info-current-file
560 (if (eq filename t) "dir" filename))))
561 ;; Use string-equal, not equal, to ignore text props.
562 (if (string-equal nodename "*")
563 (progn (setq Info-current-node nodename)
564 (Info-set-mode-line))
565 ;; Possibilities:
567 ;; 1. Anchor found in tag table
568 ;; 2. Anchor *not* in tag table
570 ;; 3. Node found in tag table
571 ;; 4. Node *not* found in tag table, but found in file
572 ;; 5. Node *not* in tag table, and *not* in file
574 ;; *Or* the same, but in an indirect subfile.
576 ;; Search file for a suitable node.
577 (let ((guesspos (point-min))
578 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
579 (if (stringp nodename)
580 (regexp-quote nodename)
582 "\\) *[,\t\n\177]"))
583 (nodepos nil))
585 (catch 'foo
587 ;; First, search a tag table, if any
588 (when (marker-position Info-tag-table-marker)
589 (let* ((m Info-tag-table-marker)
590 (found (Info-find-in-tag-table m regexp)))
592 (when found
593 ;; FOUND is (ANCHOR POS MODE).
594 (setq guesspos (nth 1 found))
596 ;; If this is an indirect file, determine which
597 ;; file really holds this node and read it in.
598 (unless (eq (nth 2 found) 'Info-mode)
599 ;; Note that the current buffer must be the
600 ;; *info* buffer on entry to
601 ;; Info-read-subfile. Thus the hackery above.
602 (setq guesspos (Info-read-subfile guesspos)))
604 ;; Handle anchor
605 (when (nth 0 found)
606 (goto-char (setq anchorpos guesspos))
607 (throw 'foo t)))))
609 ;; Else we may have a node, which we search for:
610 (goto-char (max (point-min)
611 (- (byte-to-position guesspos) 1000)))
613 ;; Now search from our advised position (or from beg of
614 ;; buffer) to find the actual node. First, check
615 ;; whether the node is right where we are, in case the
616 ;; buffer begins with a node.
617 (let ((pos (Info-find-node-in-buffer regexp)))
618 (when pos
619 (goto-char pos)
620 (throw 'foo t))
621 (error "No such anchor in tag table or node in tag table or file: %s"
622 nodename)))
624 (Info-select-node)
625 (goto-char (or anchorpos (point-min))))))
626 ;; If we did not finish finding the specified node,
627 ;; go back to the previous one.
628 (or Info-current-node no-going-back (null Info-history)
629 (let ((hist (car Info-history)))
630 (setq Info-history (cdr Info-history))
631 (Info-find-node (nth 0 hist) (nth 1 hist) t)
632 (goto-char (nth 2 hist))))))
634 ;; Cache the contents of the (virtual) dir file, once we have merged
635 ;; it for the first time, so we can save time subsequently.
636 (defvar Info-dir-contents nil)
638 ;; Cache for the directory we decided to use for the default-directory
639 ;; of the merged dir text.
640 (defvar Info-dir-contents-directory nil)
642 ;; Record the file attributes of all the files from which we
643 ;; constructed Info-dir-contents.
644 (defvar Info-dir-file-attributes nil)
646 (defvar Info-dir-file-name nil)
648 ;; Construct the Info directory node by merging the files named `dir'
649 ;; from various directories. Set the *info* buffer's
650 ;; default-directory to the first directory we actually get any text
651 ;; from.
652 (defun Info-insert-dir ()
653 (if (and Info-dir-contents Info-dir-file-attributes
654 ;; Verify that none of the files we used has changed
655 ;; since we used it.
656 (eval (cons 'and
657 (mapcar (lambda (elt)
658 (let ((curr (file-attributes
659 ;; Handle symlinks
660 (file-truename (car elt)))))
662 ;; Don't compare the access time.
663 (if curr (setcar (nthcdr 4 curr) 0))
664 (setcar (nthcdr 4 (cdr elt)) 0)
665 (equal (cdr elt) curr)))
666 Info-dir-file-attributes))))
667 (progn
668 (insert Info-dir-contents)
669 (goto-char (point-min)))
670 (let ((dirs (if Info-additional-directory-list
671 (append Info-directory-list
672 Info-additional-directory-list)
673 Info-directory-list))
674 ;; Bind this in case the user sets it to nil.
675 (case-fold-search t)
676 ;; This is set non-nil if we find a problem in some input files.
677 problems
678 buffers buffer others nodes dirs-done)
680 (setq Info-dir-file-attributes nil)
682 ;; Search the directory list for the directory file.
683 (while dirs
684 (let ((truename (file-truename (expand-file-name (car dirs)))))
685 (or (member truename dirs-done)
686 (member (directory-file-name truename) dirs-done)
687 ;; Try several variants of specified name.
688 ;; Try upcasing, appending `.info', or both.
689 (let* (file
690 (attrs
692 (progn (setq file (expand-file-name "dir" truename))
693 (file-attributes file))
694 (progn (setq file (expand-file-name "DIR" truename))
695 (file-attributes file))
696 (progn (setq file (expand-file-name "dir.info" truename))
697 (file-attributes file))
698 (progn (setq file (expand-file-name "DIR.INFO" truename))
699 (file-attributes file)))))
700 (setq dirs-done
701 (cons truename
702 (cons (directory-file-name truename)
703 dirs-done)))
704 (if attrs
705 (save-excursion
706 (or buffers
707 (message "Composing main Info directory..."))
708 (set-buffer (generate-new-buffer " info dir"))
709 (condition-case nil
710 (progn
711 (insert-file-contents file)
712 (make-local-variable 'Info-dir-file-name)
713 (setq Info-dir-file-name file)
714 (setq buffers (cons (current-buffer) buffers)
715 Info-dir-file-attributes
716 (cons (cons file attrs)
717 Info-dir-file-attributes)))
718 (error (kill-buffer (current-buffer))))))))
719 (or (cdr dirs) (setq Info-dir-contents-directory
720 (file-name-as-directory (car dirs))))
721 (setq dirs (cdr dirs))))
723 (or buffers
724 (error "Can't find the Info directory node"))
725 ;; Distinguish the dir file that comes with Emacs from all the
726 ;; others. Yes, that is really what this is supposed to do.
727 ;; The definition of `Info-directory-list' puts it first on that
728 ;; list and so last in `buffers' at this point.
729 (setq buffer (car (last buffers))
730 others (delq buffer buffers))
732 ;; Insert the entire original dir file as a start; note that we've
733 ;; already saved its default directory to use as the default
734 ;; directory for the whole concatenation.
735 (insert-buffer buffer)
737 ;; Look at each of the other buffers one by one.
738 (while others
739 (let ((other (car others))
740 ;; Bind this in case the user sets it to nil.
741 (case-fold-search t)
742 this-buffer-nodes)
743 ;; In each, find all the menus.
744 (save-excursion
745 (set-buffer other)
746 (goto-char (point-min))
747 ;; Find each menu, and add an elt to NODES for it.
748 (while (re-search-forward "^\\* Menu:" nil t)
749 (let (beg nodename end)
750 (forward-line 1)
751 (setq beg (point))
752 (or (search-backward "\n\^_" nil 'move)
753 (looking-at "\^_")
754 (signal 'search-failed (list "\n\^_")))
755 (search-forward "Node: ")
756 (setq nodename (Info-following-node-name))
757 (search-forward "\n\^_" nil 'move)
758 (beginning-of-line)
759 (setq end (point))
760 (setq this-buffer-nodes
761 (cons (list nodename other beg end)
762 this-buffer-nodes))))
763 (if (assoc-ignore-case "top" this-buffer-nodes)
764 (setq nodes (nconc this-buffer-nodes nodes))
765 (setq problems t)
766 (message "No `top' node in %s" Info-dir-file-name))))
767 (setq others (cdr others)))
768 ;; Add to the main menu a menu item for each other node.
769 (let ((case-fold-search t)
770 (re-search-forward "^\\* Menu:")))
771 (forward-line 1)
772 (let ((menu-items '("top"))
773 (nodes nodes)
774 (case-fold-search t)
775 (end (save-excursion (search-forward "\^_" nil t) (point))))
776 (while nodes
777 (let ((nodename (car (car nodes))))
778 (save-excursion
779 (or (member (downcase nodename) menu-items)
780 (re-search-forward (concat "^\\* +"
781 (regexp-quote nodename)
782 "::")
783 end t)
784 (progn
785 (insert "* " nodename "::" "\n")
786 (setq menu-items (cons nodename menu-items))))))
787 (setq nodes (cdr nodes))))
788 ;; Now take each node of each of the other buffers
789 ;; and merge it into the main buffer.
790 (while nodes
791 (let ((case-fold-search t)
792 (nodename (car (car nodes))))
793 (goto-char (point-min))
794 ;; Find the like-named node in the main buffer.
795 (if (re-search-forward (concat "^\^_.*\n.*Node: "
796 (regexp-quote nodename)
797 "[,\n\t]")
798 nil t)
799 (progn
800 (search-forward "\n\^_" nil 'move)
801 (beginning-of-line)
802 (insert "\n"))
803 ;; If none exists, add one.
804 (goto-char (point-max))
805 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
806 ;; Merge the text from the other buffer's menu
807 ;; into the menu in the like-named node in the main buffer.
808 (apply 'insert-buffer-substring (cdr (car nodes))))
809 (setq nodes (cdr nodes)))
810 ;; Kill all the buffers we just made.
811 (while buffers
812 (kill-buffer (car buffers))
813 (setq buffers (cdr buffers)))
814 (goto-char (point-min))
815 (if problems
816 (message "Composing main Info directory...problems encountered, see `*Messages*'")
817 (message "Composing main Info directory...done")))
818 (setq Info-dir-contents (buffer-string)))
819 (setq default-directory Info-dir-contents-directory))
821 ;; Note that on entry to this function the current-buffer must be the
822 ;; *info* buffer; not the info tags buffer.
823 (defun Info-read-subfile (nodepos)
824 ;; NODEPOS is either a position (in the Info file as a whole,
825 ;; not relative to a subfile) or the name of a subfile.
826 (let (lastfilepos
827 lastfilename)
828 (if (numberp nodepos)
829 (save-excursion
830 (set-buffer (marker-buffer Info-tag-table-marker))
831 (goto-char (point-min))
832 (or (looking-at "\^_")
833 (search-forward "\n\^_"))
834 (forward-line 2)
835 (catch 'foo
836 (while (not (looking-at "\^_"))
837 (if (not (eolp))
838 (let ((beg (point))
839 thisfilepos thisfilename)
840 (search-forward ": ")
841 (setq thisfilename (buffer-substring beg (- (point) 2)))
842 (setq thisfilepos (read (current-buffer)))
843 ;; read in version 19 stops at the end of number.
844 ;; Advance to the next line.
845 (forward-line 1)
846 (if (> thisfilepos nodepos)
847 (throw 'foo t))
848 (setq lastfilename thisfilename)
849 (setq lastfilepos thisfilepos))
850 (forward-line 1)))))
851 (setq lastfilename nodepos)
852 (setq lastfilepos 0))
853 ;; Assume previous buffer is in Info-mode.
854 ;; (set-buffer (get-buffer "*info*"))
855 (or (equal Info-current-subfile lastfilename)
856 (let ((buffer-read-only nil))
857 (setq buffer-file-name nil)
858 (widen)
859 (erase-buffer)
860 (info-insert-file-contents lastfilename)
861 (set-buffer-modified-p nil)
862 (setq Info-current-subfile lastfilename)))
863 (goto-char (point-min))
864 (if (looking-at "\^_")
865 (forward-char 1)
866 (search-forward "\n\^_"))
867 (if (numberp nodepos)
868 (+ (- nodepos lastfilepos) (point)))))
870 (defun Info-select-node ()
871 "Select the info node that point is in.
872 Bind this in case the user sets it to nil."
873 (let ((case-fold-search t))
874 (save-excursion
875 ;; Find beginning of node.
876 (if (search-backward "\n\^_" nil 'move)
877 (forward-line 2)
878 (if (looking-at "\^_")
879 (forward-line 1)
880 (signal 'search-failed (list "\n\^_"))))
881 ;; Get nodename spelled as it is in the node.
882 (re-search-forward "Node:[ \t]*")
883 (setq Info-current-node
884 (buffer-substring-no-properties (point)
885 (progn
886 (skip-chars-forward "^,\t\n")
887 (point))))
888 (Info-set-mode-line)
889 ;; Find the end of it, and narrow.
890 (beginning-of-line)
891 (let (active-expression)
892 (narrow-to-region (point)
893 (if (re-search-forward "\n[\^_\f]" nil t)
894 (prog1
895 (1- (point))
896 (if (looking-at "[\n\^_\f]*execute: ")
897 (progn
898 (goto-char (match-end 0))
899 (setq active-expression
900 (read (current-buffer))))))
901 (point-max)))
902 (if Info-enable-active-nodes (eval active-expression))
903 (if Info-fontify (Info-fontify-node))
904 (run-hooks 'Info-selection-hook)))))
906 (defun Info-set-mode-line ()
907 (setq mode-line-buffer-identification
908 (concat
909 " *Info* ("
910 (file-name-nondirectory (if (stringp Info-current-file)
911 Info-current-file
912 (or buffer-file-name "")))
913 ") "
914 (or Info-current-node ""))))
916 ;; Go to an info node specified with a filename-and-nodename string
917 ;; of the sort that is found in pointers in nodes.
919 (defun Info-goto-node (nodename &optional fork)
920 "Go to info node named NAME. Give just NODENAME or (FILENAME)NODENAME.
921 If FORK is non-nil, show the node in a new info buffer.
922 If FORK is a string, it is the name to use for the new buffer."
923 (interactive (list (Info-read-node-name "Goto node: ") current-prefix-arg))
924 (info-initialize)
925 (if fork
926 (set-buffer
927 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
928 (let (filename)
929 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
930 nodename)
931 (setq filename (if (= (match-beginning 1) (match-end 1))
933 (substring nodename (match-beginning 2) (match-end 2)))
934 nodename (substring nodename (match-beginning 3) (match-end 3)))
935 (let ((trim (string-match "\\s *\\'" filename)))
936 (if trim (setq filename (substring filename 0 trim))))
937 (let ((trim (string-match "\\s *\\'" nodename)))
938 (if trim (setq nodename (substring nodename 0 trim))))
939 (if transient-mark-mode (deactivate-mark))
940 (Info-find-node (if (equal filename "") nil filename)
941 (if (equal nodename "") "Top" nodename))))
943 (defvar Info-read-node-completion-table)
945 ;; This function is used as the "completion table" while reading a node name.
946 ;; It does completion using the alist in Info-read-node-completion-table
947 ;; unless STRING starts with an open-paren.
948 (defun Info-read-node-name-1 (string predicate code)
949 (let ((no-completion (and (> (length string) 0) (eq (aref string 0) ?\())))
950 (cond ((eq code nil)
951 (if no-completion
952 string
953 (try-completion string Info-read-node-completion-table predicate)))
954 ((eq code t)
955 (if no-completion
957 (all-completions string Info-read-node-completion-table predicate)))
958 ((eq code 'lambda)
959 (if no-completion
961 (assoc string Info-read-node-completion-table))))))
963 (defun Info-read-node-name (prompt &optional default)
964 (let* ((completion-ignore-case t)
965 (Info-read-node-completion-table (Info-build-node-completions))
966 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
967 (if (equal nodename "")
968 (or default
969 (Info-read-node-name prompt))
970 nodename)))
972 (defun Info-build-node-completions ()
973 (or Info-current-file-completions
974 (let ((compl nil)
975 ;; Bind this in case the user sets it to nil.
976 (case-fold-search t)
977 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
978 (save-excursion
979 (save-restriction
980 (if (marker-buffer Info-tag-table-marker)
981 (let ((marker Info-tag-table-marker))
982 (set-buffer (marker-buffer marker))
983 (widen)
984 (goto-char marker)
985 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
986 (setq compl
987 (cons (list (match-string-no-properties 2))
988 compl))))
989 (widen)
990 (goto-char (point-min))
991 ;; If the buffer begins with a node header, process that first.
992 (if (Info-node-at-bob-matching node-regexp)
993 (setq compl (list (match-string-no-properties 1))))
994 ;; Now for the rest of the nodes.
995 (while (search-forward "\n\^_" nil t)
996 (forward-line 1)
997 (let ((beg (point)))
998 (forward-line 1)
999 (if (re-search-backward node-regexp beg t)
1000 (setq compl
1001 (cons (list (match-string-no-properties 1))
1002 compl))))))))
1003 (setq compl (cons '("*") compl))
1004 (setq Info-current-file-completions compl))))
1006 (defun Info-restore-point (hl)
1007 "If this node has been visited, restore the point value when we left."
1008 (while hl
1009 (if (and (equal (nth 0 (car hl)) Info-current-file)
1010 ;; Use string-equal, not equal, to ignore text props.
1011 (string-equal (nth 1 (car hl)) Info-current-node))
1012 (progn
1013 (goto-char (nth 2 (car hl)))
1014 (setq hl nil)) ;terminate the while at next iter
1015 (setq hl (cdr hl)))))
1017 (defvar Info-search-history nil
1018 "The history list for `Info-search'.")
1020 (defun Info-search (regexp)
1021 "Search for REGEXP, starting from point, and select node it's found in."
1022 (interactive (list (read-string "Regexp search: "
1023 nil 'Info-search-history)))
1024 (when transient-mark-mode
1025 (deactivate-mark))
1026 (when (equal regexp "")
1027 (setq regexp (car Info-search-history)))
1028 (when regexp
1029 (let ((found ()) current
1030 (onode Info-current-node)
1031 (ofile Info-current-file)
1032 (opoint (point))
1033 (ostart (window-start))
1034 (osubfile Info-current-subfile))
1035 (save-excursion
1036 (save-restriction
1037 (widen)
1038 (if (null Info-current-subfile)
1039 (progn (re-search-forward regexp) (setq found (point)))
1040 (condition-case err
1041 (progn (re-search-forward regexp) (setq found (point)))
1042 (search-failed nil)))))
1043 (if (not found) ;can only happen in subfile case -- else would have erred
1044 (unwind-protect
1045 (let ((list ()))
1046 (save-excursion
1047 (set-buffer (marker-buffer Info-tag-table-marker))
1048 (goto-char (point-min))
1049 (search-forward "\n\^_\nIndirect:")
1050 (save-restriction
1051 (narrow-to-region (point)
1052 (progn (search-forward "\n\^_")
1053 (1- (point))))
1054 (goto-char (point-min))
1055 (search-forward (concat "\n" osubfile ": "))
1056 (beginning-of-line)
1057 (while (not (eobp))
1058 (re-search-forward "\\(^.*\\): [0-9]+$")
1059 (goto-char (+ (match-end 1) 2))
1060 (setq list (cons (cons (read (current-buffer))
1061 (match-string-no-properties 1))
1062 list))
1063 (goto-char (1+ (match-end 0))))
1064 (setq list (nreverse list)
1065 current (car (car list))
1066 list (cdr list))))
1067 (while list
1068 (message "Searching subfile %s..." (cdr (car list)))
1069 (Info-read-subfile (car (car list)))
1070 (setq list (cdr list))
1071 ;;; (goto-char (point-min))
1072 (if (re-search-forward regexp nil t)
1073 (setq found (point) list ())))
1074 (if found
1075 (message "")
1076 (signal 'search-failed (list regexp))))
1077 (if (not found)
1078 (progn (Info-read-subfile osubfile)
1079 (goto-char opoint)
1080 (Info-select-node)
1081 (set-window-start (selected-window) ostart)))))
1082 (widen)
1083 (goto-char found)
1084 (Info-select-node)
1085 ;; Use string-equal, not equal, to ignore text props.
1086 (or (and (string-equal onode Info-current-node)
1087 (equal ofile Info-current-file))
1088 (setq Info-history (cons (list ofile onode opoint)
1089 Info-history))))))
1091 (defun Info-extract-pointer (name &optional errorname)
1092 "Extract the value of the node-pointer named NAME.
1093 If there is none, use ERRORNAME in the error message;
1094 if ERRORNAME is nil, just return nil.
1095 Bind this in case the user sets it to nil."
1096 (let ((case-fold-search t))
1097 (save-excursion
1098 (goto-char (point-min))
1099 (forward-line 1)
1100 (if (re-search-backward (concat name ":") nil t)
1101 (progn
1102 (goto-char (match-end 0))
1103 (Info-following-node-name))
1104 (if (eq errorname t)
1106 (error "Node has no %s" (capitalize (or errorname name))))))))
1108 (defun Info-following-node-name (&optional allowedchars)
1109 "Return the node name in the buffer following point.
1110 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1111 saying which chars may appear in the node name."
1112 (skip-chars-forward " \t")
1113 (buffer-substring-no-properties
1114 (point)
1115 (progn
1116 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1117 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1118 (if (looking-at "(")
1119 (skip-chars-forward "^)")))
1120 (skip-chars-backward " ")
1121 (point))))
1123 (defun Info-next ()
1124 "Go to the next node of this node."
1125 (interactive)
1126 (Info-goto-node (Info-extract-pointer "next")))
1128 (defun Info-prev ()
1129 "Go to the previous node of this node."
1130 (interactive)
1131 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1133 (defun Info-up (&optional same-file)
1134 "Go to the superior node of this node.
1135 If SAME-FILE is non-nil, do not move to a different Info file."
1136 (interactive)
1137 (let ((node (Info-extract-pointer "up")))
1138 (and (or same-file (not (stringp Info-current-file)))
1139 (string-match "^(" node)
1140 (error "Up node is in another Info file"))
1141 (Info-goto-node node))
1142 (Info-restore-point Info-history))
1144 (defun Info-last ()
1145 "Go back to the last node visited."
1146 (interactive)
1147 (or Info-history
1148 (error "This is the first Info node you looked at"))
1149 (let (filename nodename opoint)
1150 (setq filename (car (car Info-history)))
1151 (setq nodename (car (cdr (car Info-history))))
1152 (setq opoint (car (cdr (cdr (car Info-history)))))
1153 (setq Info-history (cdr Info-history))
1154 (Info-find-node filename nodename)
1155 (setq Info-history (cdr Info-history))
1156 (goto-char opoint)))
1158 ;;;###autoload
1159 (defun Info-directory ()
1160 "Go to the Info directory node."
1161 (interactive)
1162 (Info-find-node "dir" "top"))
1164 (defun Info-follow-reference (footnotename)
1165 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1166 FOOTNOTENAME may be an abbreviation of the reference name."
1167 (interactive
1168 (let ((completion-ignore-case t)
1169 (case-fold-search t)
1170 completions default alt-default (start-point (point)) str i bol eol)
1171 (save-excursion
1172 ;; Store end and beginning of line.
1173 (end-of-line)
1174 (setq eol (point))
1175 (beginning-of-line)
1176 (setq bol (point))
1178 (goto-char (point-min))
1179 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1180 (setq str (buffer-substring-no-properties
1181 (match-beginning 1)
1182 (1- (point))))
1183 ;; See if this one should be the default.
1184 (and (null default)
1185 (<= (match-beginning 0) start-point)
1186 (<= start-point (point))
1187 (setq default t))
1188 ;; See if this one should be the alternate default.
1189 (and (null alt-default)
1190 (and (<= bol (match-beginning 0))
1191 (<= (point) eol))
1192 (setq alt-default t))
1193 (setq i 0)
1194 (while (setq i (string-match "[ \n\t]+" str i))
1195 (setq str (concat (substring str 0 i) " "
1196 (substring str (match-end 0))))
1197 (setq i (1+ i)))
1198 ;; Record as a completion and perhaps as default.
1199 (if (eq default t) (setq default str))
1200 (if (eq alt-default t) (setq alt-default str))
1201 ;; Don't add this string if it's a duplicate.
1202 ;; We use a loop instead of "(assoc str completions)" because
1203 ;; we want to do a case-insensitive compare.
1204 (let ((tail completions)
1205 (tem (downcase str)))
1206 (while (and tail
1207 (not (string-equal tem (downcase (car (car tail))))))
1208 (setq tail (cdr tail)))
1209 (or tail
1210 (setq completions
1211 (cons (cons str nil)
1212 completions))))))
1213 ;; If no good default was found, try an alternate.
1214 (or default
1215 (setq default alt-default))
1216 ;; If only one cross-reference found, then make it default.
1217 (if (eq (length completions) 1)
1218 (setq default (car (car completions))))
1219 (if completions
1220 (let ((input (completing-read (if default
1221 (concat "Follow reference named: ("
1222 default ") ")
1223 "Follow reference named: ")
1224 completions nil t)))
1225 (list (if (equal input "")
1226 default input)))
1227 (error "No cross-references in this node"))))
1229 (unless footnotename
1230 (error "No reference was specified"))
1232 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
1233 (case-fold-search t))
1234 (while (setq i (string-match " " str i))
1235 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1236 (setq i (+ i 6)))
1237 (save-excursion
1238 (goto-char (point-min))
1239 (or (re-search-forward str nil t)
1240 (error "No cross-reference named %s" footnotename))
1241 (goto-char (+ (match-beginning 0) 5))
1242 (setq target
1243 (Info-extract-menu-node-name "Bad format cross reference" t)))
1244 (while (setq i (string-match "[ \t\n]+" target i))
1245 (setq target (concat (substring target 0 i) " "
1246 (substring target (match-end 0))))
1247 (setq i (+ i 1)))
1248 (Info-goto-node target)))
1250 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1251 (skip-chars-forward " \t\n")
1252 (let ((beg (point))
1253 str i)
1254 (skip-chars-forward "^:")
1255 (forward-char 1)
1256 (setq str
1257 (if (looking-at ":")
1258 (buffer-substring-no-properties beg (1- (point)))
1259 (skip-chars-forward " \t\n")
1260 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1261 (while (setq i (string-match "\n" str i))
1262 (aset str i ?\ ))
1263 ;; Collapse multiple spaces.
1264 (while (string-match " +" str)
1265 (setq str (replace-match " " t t str)))
1266 str))
1268 ;; No one calls this.
1269 ;;(defun Info-menu-item-sequence (list)
1270 ;; (while list
1271 ;; (Info-menu (car list))
1272 ;; (setq list (cdr list))))
1274 (defvar Info-complete-menu-buffer)
1276 (defun Info-complete-menu-item (string predicate action)
1277 (let ((completion-ignore-case t)
1278 (case-fold-search t))
1279 (cond ((eq action nil)
1280 (let (completions
1281 (pattern (concat "\n\\* +\\("
1282 (regexp-quote string)
1283 "[^:\t\n]*\\):")))
1284 (save-excursion
1285 (set-buffer Info-complete-menu-buffer)
1286 (goto-char (point-min))
1287 (search-forward "\n* Menu:")
1288 (while (re-search-forward pattern nil t)
1289 (setq completions
1290 (cons (cons (match-string-no-properties 1)
1291 (match-beginning 1))
1292 completions))))
1293 (try-completion string completions predicate)))
1294 ((eq action t)
1295 (let (completions
1296 (pattern (concat "\n\\* +\\("
1297 (regexp-quote string)
1298 "[^:\t\n]*\\):")))
1299 (save-excursion
1300 (set-buffer Info-complete-menu-buffer)
1301 (goto-char (point-min))
1302 (search-forward "\n* Menu:")
1303 (while (re-search-forward pattern nil t)
1304 (setq completions (cons (cons
1305 (match-string-no-properties 1)
1306 (match-beginning 1))
1307 completions))))
1308 (all-completions string completions predicate)))
1310 (save-excursion
1311 (set-buffer Info-complete-menu-buffer)
1312 (goto-char (point-min))
1313 (search-forward "\n* Menu:")
1314 (re-search-forward (concat "\n\\* +"
1315 (regexp-quote string)
1316 ":")
1317 nil t))))))
1320 (defun Info-menu (menu-item &optional fork)
1321 "Go to node for menu item named (or abbreviated) NAME.
1322 Completion is allowed, and the menu item point is on is the default."
1323 (interactive
1324 (let ((completions '())
1325 ;; If point is within a menu item, use that item as the default
1326 (default nil)
1327 (p (point))
1329 (last nil)
1330 (case-fold-search t))
1331 (save-excursion
1332 (goto-char (point-min))
1333 (if (not (search-forward "\n* menu:" nil t))
1334 (error "No menu in this node"))
1335 (setq beg (point))
1336 (and (< (point) p)
1337 (save-excursion
1338 (goto-char p)
1339 (end-of-line)
1340 (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
1341 (setq default (match-string-no-properties 1))))))
1342 (let ((item nil))
1343 (while (null item)
1344 (setq item (let ((completion-ignore-case t)
1345 (Info-complete-menu-buffer (current-buffer)))
1346 (completing-read (if default
1347 (format "Menu item (default %s): "
1348 default)
1349 "Menu item: ")
1350 'Info-complete-menu-item nil t)))
1351 ;; we rely on the fact that completing-read accepts an input
1352 ;; of "" even when the require-match argument is true and ""
1353 ;; is not a valid possibility
1354 (if (string= item "")
1355 (if default
1356 (setq item default)
1357 ;; ask again
1358 (setq item nil))))
1359 (list item current-prefix-arg))))
1360 ;; there is a problem here in that if several menu items have the same
1361 ;; name you can only go to the node of the first with this command.
1362 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
1364 (defun Info-extract-menu-item (menu-item)
1365 (setq menu-item (regexp-quote menu-item))
1366 (let ((case-fold-search t))
1367 (save-excursion
1368 (let ((case-fold-search t))
1369 (goto-char (point-min))
1370 (or (search-forward "\n* menu:" nil t)
1371 (error "No menu in this node"))
1372 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1373 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1374 (error "No such item in menu"))
1375 (beginning-of-line)
1376 (forward-char 2)
1377 (Info-extract-menu-node-name)))))
1379 ;; If COUNT is nil, use the last item in the menu.
1380 (defun Info-extract-menu-counting (count)
1381 (let ((case-fold-search t))
1382 (save-excursion
1383 (let ((case-fold-search t))
1384 (goto-char (point-min))
1385 (or (search-forward "\n* menu:" nil t)
1386 (error "No menu in this node"))
1387 (if count
1388 (or (search-forward "\n* " nil t count)
1389 (error "Too few items in menu"))
1390 (while (search-forward "\n* " nil t)
1391 nil))
1392 (Info-extract-menu-node-name)))))
1394 (defun Info-nth-menu-item ()
1395 "Go to the node of the Nth menu item.
1396 N is the digit argument used to invoke this command."
1397 (interactive)
1398 (Info-goto-node
1399 (Info-extract-menu-counting
1400 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1402 (defun Info-top-node ()
1403 "Go to the Top node of this file."
1404 (interactive)
1405 (Info-goto-node "Top"))
1407 (defun Info-final-node ()
1408 "Go to the final node in this file."
1409 (interactive)
1410 (Info-goto-node "Top")
1411 (let ((Info-history nil)
1412 (case-fold-search t))
1413 ;; Go to the last node in the menu of Top.
1414 (Info-goto-node (Info-extract-menu-counting nil))
1415 ;; If the last node in the menu is not last in pointer structure,
1416 ;; move forward until we can't go any farther.
1417 (while (Info-forward-node t t) nil)
1418 ;; Then keep moving down to last subnode, unless we reach an index.
1419 (while (and (not (string-match "\\<index\\>" Info-current-node))
1420 (save-excursion (search-forward "\n* Menu:" nil t)))
1421 (Info-goto-node (Info-extract-menu-counting nil)))))
1423 (defun Info-forward-node (&optional not-down no-error)
1424 "Go forward one node, considering all nodes as forming one sequence."
1425 (interactive)
1426 (goto-char (point-min))
1427 (forward-line 1)
1428 (let ((case-fold-search t))
1429 ;; three possibilities, in order of priority:
1430 ;; 1. next node is in a menu in this node (but not in an index)
1431 ;; 2. next node is next at same level
1432 ;; 3. next node is up and next
1433 (cond ((and (not not-down)
1434 (save-excursion (search-forward "\n* menu:" nil t))
1435 (not (string-match "\\<index\\>" Info-current-node)))
1436 (Info-goto-node (Info-extract-menu-counting 1))
1438 ((save-excursion (search-backward "next:" nil t))
1439 (Info-next)
1441 ((and (save-excursion (search-backward "up:" nil t))
1442 ;; Use string-equal, not equal, to ignore text props.
1443 (not (string-equal (downcase (Info-extract-pointer "up"))
1444 "top")))
1445 (let ((old-node Info-current-node))
1446 (Info-up)
1447 (let (Info-history success)
1448 (unwind-protect
1449 (setq success (Info-forward-node t no-error))
1450 (or success (Info-goto-node old-node))))))
1451 (no-error nil)
1452 (t (error "No pointer forward from this node")))))
1454 (defun Info-backward-node ()
1455 "Go backward one node, considering all nodes as forming one sequence."
1456 (interactive)
1457 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1458 (upnode (Info-extract-pointer "up" t))
1459 (case-fold-search t))
1460 (cond ((and upnode (string-match "(" upnode))
1461 (error "First node in file"))
1462 ((and upnode (or (null prevnode)
1463 ;; Use string-equal, not equal,
1464 ;; to ignore text properties.
1465 (string-equal (downcase prevnode)
1466 (downcase upnode))))
1467 (Info-up))
1468 (prevnode
1469 ;; If we move back at the same level,
1470 ;; go down to find the last subnode*.
1471 (Info-prev)
1472 (let (Info-history)
1473 (while (and (not (string-match "\\<index\\>" Info-current-node))
1474 (save-excursion (search-forward "\n* Menu:" nil t)))
1475 (Info-goto-node (Info-extract-menu-counting nil)))))
1477 (error "No pointer backward from this node")))))
1479 (defun Info-exit ()
1480 "Exit Info by selecting some other buffer."
1481 (interactive)
1482 (if Info-standalone
1483 (save-buffers-kill-emacs)
1484 (quit-window)))
1486 (defun Info-next-menu-item ()
1487 (interactive)
1488 ;; Bind this in case the user sets it to nil.
1489 (let* ((case-fold-search t)
1490 (node
1491 (save-excursion
1492 (forward-line -1)
1493 (search-forward "\n* menu:" nil t)
1494 (and (search-forward "\n* " nil t)
1495 (Info-extract-menu-node-name)))))
1496 (if node (Info-goto-node node)
1497 (error "No more items in menu"))))
1499 (defun Info-last-menu-item ()
1500 (interactive)
1501 (save-excursion
1502 (forward-line 1)
1503 ;; Bind this in case the user sets it to nil.
1504 (let* ((case-fold-search t)
1505 (beg (save-excursion
1506 (and (search-backward "\n* menu:" nil t)
1507 (point)))))
1508 (or (and beg (search-backward "\n* " beg t))
1509 (error "No previous items in menu")))
1510 (Info-goto-node (save-excursion
1511 (goto-char (match-end 0))
1512 (Info-extract-menu-node-name)))))
1514 (defmacro Info-no-error (&rest body)
1515 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1517 (defun Info-next-preorder ()
1518 "Go to the next subnode or the next node, or go up a level."
1519 (interactive)
1520 (cond ((Info-no-error (Info-next-menu-item)))
1521 ((Info-no-error (Info-next)))
1522 ((Info-no-error (Info-up t))
1523 ;; Since we have already gone thru all the items in this menu,
1524 ;; go up to the end of this node.
1525 (goto-char (point-max))
1526 ;; Since logically we are done with the node with that menu,
1527 ;; move on from it.
1528 (Info-next-preorder))
1530 (error "No more nodes"))))
1532 (defun Info-last-preorder ()
1533 "Go to the last node, popping up a level if there is none."
1534 (interactive)
1535 (cond ((Info-no-error
1536 (Info-last-menu-item)
1537 ;; If we go down a menu item, go to the end of the node
1538 ;; so we can scroll back through it.
1539 (goto-char (point-max)))
1540 ;; Keep going down, as long as there are nested menu nodes.
1541 (while (Info-no-error
1542 (Info-last-menu-item)
1543 ;; If we go down a menu item, go to the end of the node
1544 ;; so we can scroll back through it.
1545 (goto-char (point-max))))
1546 (recenter -1))
1547 ((and (not (equal (Info-extract-pointer "up")
1548 (Info-extract-pointer "prev"))))
1549 (Info-no-error (Info-prev))
1550 (goto-char (point-max))
1551 (while (Info-no-error
1552 (Info-last-menu-item)
1553 ;; If we go down a menu item, go to the end of the node
1554 ;; so we can scroll back through it.
1555 (goto-char (point-max))))
1556 (recenter -1))
1557 ((Info-no-error (Info-up t))
1558 (goto-char (point-min))
1559 (let ((case-fold-search t))
1560 (or (search-forward "\n* Menu:" nil t)
1561 (goto-char (point-max)))))
1562 (t (error "No previous nodes"))))
1564 (defun Info-scroll-up ()
1565 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1566 Once you scroll far enough in a node that its menu appears on the screen
1567 but after point, the next scroll moves into its first subnode.
1569 When you scroll past the end of a node, that goes to the next node; if
1570 this node has no successor, it moves to the parent node's successor,
1571 and so on. If point is inside the menu of a node, it moves to
1572 subnode indicated by the following menu item. (That case won't
1573 normally result from this command, but can happen in other ways.)"
1575 (interactive)
1576 (if (or (< (window-start) (point-min))
1577 (> (window-start) (point-max)))
1578 (set-window-start (selected-window) (point)))
1579 (let* ((case-fold-search t)
1580 (virtual-end (save-excursion
1581 (goto-char (point-min))
1582 (if (search-forward "\n* Menu:" nil t)
1583 (point)
1584 (point-max)))))
1585 (if (or (< virtual-end (window-start))
1586 (pos-visible-in-window-p virtual-end))
1587 (Info-next-preorder)
1588 (scroll-up))))
1590 (defun Info-scroll-down ()
1591 "Scroll one screenful back in Info, considering all nodes as one sequence.
1592 Within the menu of a node, this goes to its last subnode.
1593 When you scroll past the beginning of a node, that goes to the
1594 previous node or back up to the parent node."
1595 (interactive)
1596 (if (or (< (window-start) (point-min))
1597 (> (window-start) (point-max)))
1598 (set-window-start (selected-window) (point)))
1599 (let* ((case-fold-search t)
1600 (current-point (point))
1601 (virtual-end (save-excursion
1602 (beginning-of-line)
1603 (setq current-point (point))
1604 (goto-char (point-min))
1605 (search-forward "\n* Menu:"
1606 current-point
1607 t))))
1608 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1609 (Info-last-preorder)
1610 (scroll-down))))
1612 (defun Info-next-reference (&optional recur)
1613 "Move cursor to the next cross-reference or menu item in the node."
1614 (interactive)
1615 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1616 (old-pt (point))
1617 (case-fold-search t))
1618 (or (eobp) (forward-char 1))
1619 (or (re-search-forward pat nil t)
1620 (progn
1621 (goto-char (point-min))
1622 (or (re-search-forward pat nil t)
1623 (progn
1624 (goto-char old-pt)
1625 (error "No cross references in this node")))))
1626 (goto-char (match-beginning 0))
1627 (if (looking-at "\\* Menu:")
1628 (if recur
1629 (error "No cross references in this node")
1630 (Info-next-reference t)))))
1632 (defun Info-prev-reference (&optional recur)
1633 "Move cursor to the previous cross-reference or menu item in the node."
1634 (interactive)
1635 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1636 (old-pt (point))
1637 (case-fold-search t))
1638 (or (re-search-backward pat nil t)
1639 (progn
1640 (goto-char (point-max))
1641 (or (re-search-backward pat nil t)
1642 (progn
1643 (goto-char old-pt)
1644 (error "No cross references in this node")))))
1645 (goto-char (match-beginning 0))
1646 (if (looking-at "\\* Menu:")
1647 (if recur
1648 (error "No cross references in this node")
1649 (Info-prev-reference t)))))
1651 (defun Info-index (topic)
1652 "Look up a string TOPIC in the index for this file.
1653 The index is defined as the first node in the top-level menu whose
1654 name contains the word \"Index\", plus any immediately following
1655 nodes whose names also contain the word \"Index\".
1656 If there are no exact matches to the specified topic, this chooses
1657 the first match which is a case-insensitive substring of a topic.
1658 Use the `,' command to see the other matches.
1659 Give a blank topic name to go to the Index node itself."
1660 (interactive "sIndex topic: ")
1661 (let ((orignode Info-current-node)
1662 (rnode nil)
1663 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1664 (regexp-quote topic)))
1665 node
1666 (case-fold-search t))
1667 (Info-goto-node "Top")
1668 (or (search-forward "\n* menu:" nil t)
1669 (error "No index"))
1670 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1671 (error "No index"))
1672 (goto-char (match-beginning 1))
1673 ;; Here, and subsequently in this function,
1674 ;; we bind Info-history to nil for internal node-switches
1675 ;; so that we don't put junk in the history.
1676 ;; In the first Info-goto-node call, above, we do update the history
1677 ;; because that is what the user's previous node choice into it.
1678 (let ((Info-history nil))
1679 (Info-goto-node (Info-extract-menu-node-name)))
1680 (or (equal topic "")
1681 (let ((matches nil)
1682 (exact nil)
1683 (Info-history nil)
1684 found)
1685 (while
1686 (progn
1687 (goto-char (point-min))
1688 (while (re-search-forward pattern nil t)
1689 (setq matches
1690 (cons (list (match-string-no-properties 1)
1691 (match-string-no-properties 2)
1692 Info-current-node
1693 (string-to-int (concat "0"
1694 (match-string 3))))
1695 matches)))
1696 (and (setq node (Info-extract-pointer "next" t))
1697 (string-match "\\<Index\\>" node)))
1698 (Info-goto-node node))
1699 (or matches
1700 (progn
1701 (Info-goto-node orignode)
1702 (error "No `%s' in index" topic)))
1703 ;; Here it is a feature that assoc is case-sensitive.
1704 (while (setq found (assoc topic matches))
1705 (setq exact (cons found exact)
1706 matches (delq found matches)))
1707 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1708 (Info-index-next 0)))))
1710 (defun Info-index-next (num)
1711 "Go to the next matching index item from the last `i' command."
1712 (interactive "p")
1713 (or Info-index-alternatives
1714 (error "No previous `i' command"))
1715 (while (< num 0)
1716 (setq num (+ num (length Info-index-alternatives))))
1717 (while (> num 0)
1718 (setq Info-index-alternatives
1719 (nconc (cdr Info-index-alternatives)
1720 (list (car Info-index-alternatives)))
1721 num (1- num)))
1722 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1723 (if (> (nth 3 (car Info-index-alternatives)) 0)
1724 (forward-line (nth 3 (car Info-index-alternatives)))
1725 (forward-line 3) ; don't search in headers
1726 (let ((name (car (car Info-index-alternatives))))
1727 (Info-find-index-name name)))
1728 (message "Found `%s' in %s. %s"
1729 (car (car Info-index-alternatives))
1730 (nth 2 (car Info-index-alternatives))
1731 (if (cdr Info-index-alternatives)
1732 "(Press `,' for more)"
1733 "(Only match)")))
1735 (defun Info-find-index-name (name)
1736 "Move point to the place within the current node where NAME is defined."
1737 (let ((case-fold-search t))
1738 (if (or (re-search-forward (format
1739 "[a-zA-Z]+: %s\\( \\|$\\)"
1740 (regexp-quote name)) nil t)
1741 (search-forward (format "`%s'" name) nil t)
1742 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1743 (search-forward
1744 (format "`%s'" (substring name 0 (match-beginning 1)))
1745 nil t))
1746 (search-forward name nil t))
1747 (beginning-of-line)
1748 (goto-char (point-min)))))
1750 (defun Info-undefined ()
1751 "Make command be undefined in Info."
1752 (interactive)
1753 (ding))
1755 (defun Info-help ()
1756 "Enter the Info tutorial."
1757 (interactive)
1758 (delete-other-windows)
1759 (Info-find-node "info"
1760 (if (< (window-height) 23)
1761 "Help-Small-Screen"
1762 "Help")))
1764 (defun Info-summary ()
1765 "Display a brief summary of all Info commands."
1766 (interactive)
1767 (save-window-excursion
1768 (switch-to-buffer "*Help*")
1769 (setq buffer-read-only nil)
1770 (erase-buffer)
1771 (insert (documentation 'Info-mode))
1772 (help-mode)
1773 (goto-char (point-min))
1774 (let (ch flag)
1775 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1776 (message (if flag "Type Space to see more"
1777 "Type Space to return to Info"))
1778 (if (not (eq ?\ (setq ch (read-event))))
1779 (progn (setq unread-command-events (list ch)) nil)
1780 flag))
1781 (scroll-up)))
1782 (bury-buffer "*Help*")))
1784 (defun Info-get-token (pos start all &optional errorstring)
1785 "Return the token around POS.
1786 POS must be somewhere inside the token
1787 START is a regular expression which will match the
1788 beginning of the tokens delimited string
1789 ALL is a regular expression with a single
1790 parenthesized subpattern which is the token to be
1791 returned. E.g. '{\(.*\)}' would return any string
1792 enclosed in braces around POS.
1793 ERRORSTRING optional fourth argument, controls action on no match
1794 nil: return nil
1795 t: beep
1796 a string: signal an error, using that string."
1797 (let ((case-fold-search t))
1798 (save-excursion
1799 (goto-char pos)
1800 ;; First look for a match for START that goes across POS.
1801 (while (and (not (bobp)) (> (point) (- pos (length start)))
1802 (not (looking-at start)))
1803 (forward-char -1))
1804 ;; If we did not find one, search back for START
1805 ;; (this finds only matches that end at or before POS).
1806 (or (looking-at start)
1807 (progn
1808 (goto-char pos)
1809 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
1810 (let (found)
1811 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1812 (not (setq found (and (<= (match-beginning 0) pos)
1813 (> (match-end 0) pos))))))
1814 (if (and found (<= (match-beginning 0) pos)
1815 (> (match-end 0) pos))
1816 (match-string-no-properties 1)
1817 (cond ((null errorstring)
1818 nil)
1819 ((eq errorstring t)
1820 (beep)
1821 nil)
1823 (error "No %s around position %d" errorstring pos))))))))
1825 (defun Info-mouse-follow-nearest-node (click)
1826 "\\<Info-mode-map>Follow a node reference near point.
1827 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
1828 At end of the node's text, moves to the next node, or up if none."
1829 (interactive "e")
1830 (let* ((start (event-start click))
1831 (window (car start))
1832 (pos (car (cdr start))))
1833 (select-window window)
1834 (goto-char pos))
1835 (and (not (Info-try-follow-nearest-node))
1836 (save-excursion (forward-line 1) (eobp))
1837 (Info-next-preorder)))
1839 (defun Info-follow-nearest-node ()
1840 "\\<Info-mode-map>Follow a node reference near point.
1841 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1842 If no reference to follow, moves to the next node, or up if none."
1843 (interactive)
1844 (or (Info-try-follow-nearest-node)
1845 (Info-next-preorder)))
1847 ;; Common subroutine.
1848 (defun Info-try-follow-nearest-node ()
1849 "Follow a node reference near point. Return non-nil if successful."
1850 (let (node)
1851 (cond
1852 ((setq node (Info-get-token (point) "\\*note[ \n]"
1853 "\\*note[ \n]\\([^:]*\\):"))
1854 (Info-follow-reference node))
1855 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1856 (Info-goto-node node))
1857 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
1858 (beginning-of-line)
1859 (forward-char 2)
1860 (setq node (Info-extract-menu-node-name))
1861 (Info-goto-node node))
1862 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1863 (Info-goto-node node))
1864 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1865 (Info-goto-node node))
1866 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1867 (Info-goto-node "Top"))
1868 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1869 (Info-goto-node node)))
1870 node))
1872 (defvar Info-mode-map nil
1873 "Keymap containing Info commands.")
1874 (if Info-mode-map
1876 (setq Info-mode-map (make-keymap))
1877 (suppress-keymap Info-mode-map)
1878 (define-key Info-mode-map "." 'beginning-of-buffer)
1879 (define-key Info-mode-map " " 'Info-scroll-up)
1880 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1881 (define-key Info-mode-map "\t" 'Info-next-reference)
1882 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1883 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1884 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1885 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1886 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1887 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1888 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1889 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1890 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1891 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1892 (define-key Info-mode-map "0" 'undefined)
1893 (define-key Info-mode-map "?" 'Info-summary)
1894 (define-key Info-mode-map "]" 'Info-forward-node)
1895 (define-key Info-mode-map "[" 'Info-backward-node)
1896 (define-key Info-mode-map "<" 'Info-top-node)
1897 (define-key Info-mode-map ">" 'Info-final-node)
1898 (define-key Info-mode-map "b" 'beginning-of-buffer)
1899 (define-key Info-mode-map "d" 'Info-directory)
1900 (define-key Info-mode-map "e" 'Info-edit)
1901 (define-key Info-mode-map "f" 'Info-follow-reference)
1902 (define-key Info-mode-map "g" 'Info-goto-node)
1903 (define-key Info-mode-map "h" 'Info-help)
1904 (define-key Info-mode-map "i" 'Info-index)
1905 (define-key Info-mode-map "l" 'Info-last)
1906 (define-key Info-mode-map "m" 'Info-menu)
1907 (define-key Info-mode-map "n" 'Info-next)
1908 (define-key Info-mode-map "p" 'Info-prev)
1909 (define-key Info-mode-map "q" 'Info-exit)
1910 (define-key Info-mode-map "s" 'Info-search)
1911 ;; For consistency with Rmail.
1912 (define-key Info-mode-map "\M-s" 'Info-search)
1913 (define-key Info-mode-map "\M-n" 'clone-buffer)
1914 (define-key Info-mode-map "t" 'Info-top-node)
1915 (define-key Info-mode-map "u" 'Info-up)
1916 (define-key Info-mode-map "," 'Info-index-next)
1917 (define-key Info-mode-map "\177" 'Info-scroll-down)
1918 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1921 (defun Info-check-pointer (item)
1922 "Non-nil if ITEM is present in this node."
1923 (condition-case nil
1924 (Info-extract-pointer item)
1925 (error nil)))
1927 (easy-menu-define
1928 Info-mode-menu Info-mode-map
1929 "Menu for info files."
1930 '("Info"
1931 ["Up" Info-up :active (Info-check-pointer "up")
1932 :help "Go up in the Info tree"]
1933 ["Next" Info-next :active (Info-check-pointer "next")
1934 :help "Go to the next node"]
1935 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
1936 :help "Go to the previous node"]
1937 ["Backward" Info-backward-node
1938 :help "Go backward one node, considering all as a sequence"]
1939 ["Forward" Info-forward-node
1940 :help "Go forward one node, considering all as a sequence"]
1941 ["Top" Info-top-node
1942 :help "Go to top node of file"]
1943 ["Final Node" Info-final-node
1944 :help "Go to final node in this file"]
1945 ("Menu Item" ["You should never see this" report-emacs-bug t])
1946 ("Reference" ["You should never see this" report-emacs-bug t])
1947 ["Search..." Info-search
1948 :help "Search for regular expression in this Info file"]
1949 ["Goto Node..." Info-goto-node
1950 :help "Go to a named node"]
1951 ["Last" Info-last Info-history
1952 :help "Go to the last node you were at"]
1953 ("Index..."
1954 ["Lookup a String" Info-index
1955 :help "Look for a string in the index items"]
1956 ["Next Matching Item" Info-index-next
1957 :help "Look for another occurrence of previous item"])
1958 ["Exit" Info-exit t]))
1960 (defvar Info-menu-last-node nil)
1961 ;; Last node the menu was created for.
1962 ;; Value is a list, (FILE-NAME NODE-NAME).
1964 (defun Info-menu-update ()
1965 "Update the Info menu for the current node."
1966 (condition-case nil
1967 (if (or (not (eq major-mode 'Info-mode))
1968 (equal (list Info-current-file Info-current-node)
1969 Info-menu-last-node))
1971 ;; Update menu menu.
1972 (let* ((Info-complete-menu-buffer (current-buffer))
1973 (items (nreverse (condition-case nil
1974 (Info-complete-menu-item
1975 "" (lambda (e) t) t)
1976 (error nil))))
1977 entries current
1978 (number 0))
1979 (while (and items (< number 9))
1980 (setq current (car items)
1981 items (cdr items)
1982 number (1+ number))
1983 (setq entries (cons `[,current
1984 (Info-menu ,current)
1985 :keys ,(format "%d" number)]
1986 entries)))
1987 (if items
1988 (setq entries (cons ["Other..." Info-menu t] entries)))
1989 (or entries
1990 (setq entries (list ["No menu" nil nil])))
1991 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
1992 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1993 (let ((items nil)
1994 str i entries current
1995 (number 0)
1996 (case-fold-search t))
1997 (save-excursion
1998 (goto-char (point-min))
1999 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
2000 (setq str (buffer-substring
2001 (match-beginning 1)
2002 (1- (point))))
2003 (setq i 0)
2004 (while (setq i (string-match "[ \n\t]+" str i))
2005 (setq str (concat (substring str 0 i) " "
2006 (substring str (match-end 0))))
2007 (setq i (1+ i)))
2008 (setq items
2009 (cons str items))))
2010 (while (and items (< number 9))
2011 (setq current (car items)
2012 items (cdr items)
2013 number (1+ number))
2014 (setq entries (cons `[,current
2015 (Info-follow-reference ,current)
2017 entries)))
2018 (if items
2019 (setq entries (cons ["Other..." Info-follow-reference t]
2020 entries)))
2021 (or entries
2022 (setq entries (list ["No references" nil nil])))
2023 (easy-menu-change '("Info") "Reference" (nreverse entries)))
2024 ;; Update last seen node.
2025 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
2026 ;; Try to avoid entering infinite beep mode in case of errors.
2027 (error (ding))))
2030 ;; Info mode is suitable only for specially formatted data.
2031 (put 'info-mode 'mode-class 'special)
2033 (defun Info-mode ()
2034 "Info mode provides commands for browsing through the Info documentation tree.
2035 Documentation in Info is divided into \"nodes\", each of which discusses
2036 one topic and contains references to other nodes which discuss related
2037 topics. Info has commands to follow the references and show you other nodes.
2039 \\<Info-mode-map>\
2040 \\[Info-help] Invoke the Info tutorial.
2041 \\[Info-exit] Quit Info: reselect previously selected buffer.
2043 Selecting other nodes:
2044 \\[Info-mouse-follow-nearest-node]
2045 Follow a node reference you click on.
2046 This works with menu items, cross references, and
2047 the \"next\", \"previous\" and \"up\", depending on where you click.
2048 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2049 \\[Info-next] Move to the \"next\" node of this node.
2050 \\[Info-prev] Move to the \"previous\" node of this node.
2051 \\[Info-up] Move \"up\" from this node.
2052 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2053 Picking a menu item causes another node to be selected.
2054 \\[Info-directory] Go to the Info directory node.
2055 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2056 \\[Info-last] Move to the last node you were at.
2057 \\[Info-index] Look up a topic in this file's Index and move to that node.
2058 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2059 \\[Info-top-node] Go to the Top node of this file.
2060 \\[Info-final-node] Go to the final node in this file.
2061 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2062 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2064 Moving within a node:
2065 \\[Info-scroll-up] Normally, scroll forward a full screen.
2066 Once you scroll far enough in a node that its menu appears on the screen
2067 but after point, the next scroll moves into its first subnode.
2068 When after all menu items (or if their is no menu), move up to
2069 the parent node.
2070 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2071 already visible, try to go to the previous menu entry, or up if there is none.
2072 \\[beginning-of-buffer] Go to beginning of node.
2074 Advanced commands:
2075 \\[Info-exit] Quit Info: reselect previously selected buffer.
2076 \\[Info-edit] Edit contents of selected node.
2077 1 Pick first item in node's menu.
2078 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2079 \\[Info-goto-node] Move to node specified by name.
2080 You may include a filename as well, as (FILENAME)NODENAME.
2081 \\[universal-argument] \\[info] Move to new Info file with completion.
2082 \\[Info-search] Search through this Info file for specified regexp,
2083 and select the node in which the next occurrence is found.
2084 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2085 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2086 (kill-all-local-variables)
2087 (setq major-mode 'Info-mode)
2088 (setq mode-name "Info")
2089 (setq tab-width 8)
2090 (use-local-map Info-mode-map)
2091 (make-local-hook 'activate-menubar-hook)
2092 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
2093 (set-syntax-table text-mode-syntax-table)
2094 (setq local-abbrev-table text-mode-abbrev-table)
2095 (setq case-fold-search t)
2096 (setq buffer-read-only t)
2097 (make-local-variable 'Info-current-file)
2098 (make-local-variable 'Info-current-subfile)
2099 (make-local-variable 'Info-current-node)
2100 (make-local-variable 'Info-tag-table-marker)
2101 (setq Info-tag-table-marker (make-marker))
2102 (make-local-variable 'Info-tag-table-buffer)
2103 (setq Info-tag-table-buffer nil)
2104 (make-local-variable 'Info-history)
2105 (make-local-variable 'Info-index-alternatives)
2106 ;; This is for the sake of the invisible text we use handling titles.
2107 (make-local-variable 'line-move-ignore-invisible)
2108 (setq line-move-ignore-invisible t)
2109 (add-hook (make-local-hook 'clone-buffer-hook) 'Info-clone-buffer-hook nil t)
2110 (Info-set-mode-line)
2111 (run-hooks 'Info-mode-hook))
2113 (defun Info-clone-buffer-hook ()
2114 (when (bufferp Info-tag-table-buffer)
2115 (setq Info-tag-table-buffer
2116 (with-current-buffer Info-tag-table-buffer (clone-buffer)))
2117 (let ((m Info-tag-table-marker))
2118 (when (and (markerp m) (marker-position m))
2119 (setq Info-tag-table-marker
2120 (with-current-buffer Info-tag-table-buffer
2121 (copy-marker (marker-position m))))))))
2123 (defvar Info-edit-map nil
2124 "Local keymap used within `e' command of Info.")
2125 (if Info-edit-map
2127 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
2128 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
2130 ;; Info-edit mode is suitable only for specially formatted data.
2131 (put 'info-edit-mode 'mode-class 'special)
2133 (defun Info-edit-mode ()
2134 "Major mode for editing the contents of an Info node.
2135 Like text mode with the addition of `Info-cease-edit'
2136 which returns to Info mode for browsing.
2137 \\{Info-edit-map}"
2138 (use-local-map Info-edit-map)
2139 (setq major-mode 'Info-edit-mode)
2140 (setq mode-name "Info Edit")
2141 (kill-local-variable 'mode-line-buffer-identification)
2142 (setq buffer-read-only nil)
2143 (force-mode-line-update)
2144 (buffer-enable-undo (current-buffer))
2145 (run-hooks 'Info-edit-mode-hook))
2147 (defun Info-edit ()
2148 "Edit the contents of this Info node.
2149 Allowed only if variable `Info-enable-edit' is non-nil."
2150 (interactive)
2151 (or Info-enable-edit
2152 (error "Editing info nodes is not enabled"))
2153 (Info-edit-mode)
2154 (message "%s" (substitute-command-keys
2155 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2157 (defun Info-cease-edit ()
2158 "Finish editing Info node; switch back to Info proper."
2159 (interactive)
2160 ;; Do this first, so nothing has changed if user C-g's at query.
2161 (and (buffer-modified-p)
2162 (y-or-n-p "Save the file? ")
2163 (save-buffer))
2164 (use-local-map Info-mode-map)
2165 (setq major-mode 'Info-mode)
2166 (setq mode-name "Info")
2167 (Info-set-mode-line)
2168 (setq buffer-read-only t)
2169 (force-mode-line-update)
2170 (and (marker-position Info-tag-table-marker)
2171 (buffer-modified-p)
2172 (message "Tags may have changed. Use Info-tagify if necessary")))
2174 (defvar Info-file-list-for-emacs
2175 '("ediff" "forms" "gnus" ("mh" . "mh-e") "sc" "message"
2176 ("dired" . "dired-x") ("c" . "ccmode") "viper" "vip"
2177 ("skeleton" . "autotype") ("auto-insert" . "autotype")
2178 ("copyright" . "autotype") ("executable" . "autotype")
2179 ("time-stamp" . "autotype") ("quickurl" . "autotype")
2180 ("tempo" . "autotype") ("hippie-expand" . "autotype")
2181 ("cvs" . "pcl-cvs")
2182 "ebrowse" "cl" "idlwave" "reftex" "widget" "woman")
2183 "List of Info files that describe Emacs commands.
2184 An element can be a file name, or a list of the form (PREFIX . FILE)
2185 where PREFIX is a name prefix and FILE is the file to look in.
2186 If the element is just a file name, the file name also serves as the prefix.")
2188 (defun Info-find-emacs-command-nodes (command)
2189 "Return a list of locations documenting COMMAND.
2190 The `info-file' property of COMMAND says which Info manual to search.
2191 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2192 defines heuristics for which Info manual to try.
2193 The locations are of the format used in `Info-history', i.e.
2194 \(FILENAME NODENAME BUFFERPOS\)."
2195 (let ((where '())
2196 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
2197 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
2198 (info-file "emacs")) ;default
2199 ;; Determine which info file this command is documented in.
2200 (if (get command 'info-file)
2201 (setq info-file (get command 'info-file))
2202 ;; If it doesn't say explicitly, test its name against
2203 ;; various prefixes that we know.
2204 (let ((file-list Info-file-list-for-emacs))
2205 (while file-list
2206 (let* ((elt (car file-list))
2207 (name (if (consp elt)
2208 (car elt)
2209 elt))
2210 (file (if (consp elt) (cdr elt) elt))
2211 (regexp (concat "\\`" (regexp-quote name)
2212 "\\(\\'\\|-\\)")))
2213 (if (string-match regexp (symbol-name command))
2214 (setq info-file file file-list nil))
2215 (setq file-list (cdr file-list))))))
2216 (Info-find-node info-file "Top")
2217 (or (and (search-forward "\n* menu:" nil t)
2218 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2219 (error "Info file `%s' appears to lack an index" info-file))
2220 (goto-char (match-beginning 1))
2221 ;; Bind Info-history to nil, to prevent the index nodes from
2222 ;; getting into the node history.
2223 (let ((Info-history nil)
2224 (exact nil)
2225 node found)
2226 (Info-goto-node (Info-extract-menu-node-name))
2227 (while
2228 (progn
2229 (goto-char (point-min))
2230 (while (re-search-forward cmd-desc nil t)
2231 (setq where
2232 (cons (list Info-current-file
2233 (match-string-no-properties 2)
2235 where)))
2236 (and (setq node (Info-extract-pointer "next" t))
2237 (string-match "\\<Index\\>" node)))
2238 (Info-goto-node node)))
2239 where))
2241 ;;;###autoload
2242 (defun Info-goto-emacs-command-node (command)
2243 "Go to the Info node in the Emacs manual for command COMMAND.
2244 The command is found by looking up in Emacs manual's Command Index
2245 or in another manual found via COMMAND's `info-file' property or
2246 the variable `Info-file-list-for-emacs'."
2247 (interactive "CFind documentation for command: ")
2248 (or (commandp command)
2249 (signal 'wrong-type-argument (list 'commandp command)))
2250 (let ((where (Info-find-emacs-command-nodes command)))
2251 (if where
2252 (let ((num-matches (length where)))
2253 ;; Get Info running, and pop to it in another window.
2254 (save-window-excursion
2255 (info))
2256 ;; FIXME It would be cool if this could use a buffer other
2257 ;; than *info*.
2258 (pop-to-buffer "*info*")
2259 ;; Bind Info-history to nil, to prevent the last Index node
2260 ;; visited by Info-find-emacs-command-nodes from being
2261 ;; pushed onto the history.
2262 (let ((Info-history nil))
2263 (Info-find-node (car (car where))
2264 (car (cdr (car where)))))
2265 (if (> num-matches 1)
2266 (progn
2267 ;; (car where) will be pushed onto Info-history
2268 ;; when/if they go to another node. Put the other
2269 ;; nodes that were found on the history.
2270 (setq Info-history (nconc (cdr where) Info-history))
2271 (message "Found %d other entr%s. Use %s to see %s."
2272 (1- num-matches)
2273 (if (> num-matches 2) "ies" "y")
2274 (substitute-command-keys "\\[Info-last]")
2275 (if (> num-matches 2) "them" "it")))))
2276 (error "Couldn't find documentation for %s" command))))
2278 ;;;###autoload
2279 (defun Info-goto-emacs-key-command-node (key)
2280 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2281 Interactively, if the binding is `execute-extended-command', a command is read.
2282 The command is found by looking up in Emacs manual's Command Index
2283 or in another manual found via COMMAND's `info-file' property or
2284 the variable `Info-file-list-for-emacs'."
2285 (interactive "kFind documentation for key: ")
2286 (let ((command (key-binding key)))
2287 (cond ((null command)
2288 (message "%s is undefined" (key-description key)))
2289 ((and (interactive-p)
2290 (eq command 'execute-extended-command))
2291 (Info-goto-emacs-command-node
2292 (read-command "Find documentation for command: ")))
2294 (Info-goto-emacs-command-node command)))))
2296 (defface Info-title-1-face
2297 '((t (:family "helv" :height 240 :weight bold)))
2298 "Face for Info titles at level 1."
2299 :group 'info)
2301 (defface Info-title-2-face
2302 '((t (:family "helv" :height 180 :weight bold)))
2303 "Face for Info titles at level 2."
2304 :group 'info)
2306 (defface Info-title-3-face
2307 '((t (:family "helv" :height 160 :weight bold)))
2308 "Face for Info titles at level 3."
2309 :group 'info)
2311 (defun Info-fontify-node ()
2312 (save-excursion
2313 (let ((buffer-read-only nil)
2314 (case-fold-search t))
2315 (goto-char (point-min))
2316 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2317 (goto-char (match-end 0))
2318 (while
2319 (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2320 (goto-char (match-end 0))
2321 (if (save-excursion
2322 (goto-char (match-beginning 1))
2323 (save-match-data (looking-at "Node:")))
2324 (put-text-property (match-beginning 2) (match-end 2)
2325 'face 'info-node)
2326 (put-text-property (match-beginning 2) (match-end 2)
2327 'face 'info-xref)
2328 (put-text-property (match-beginning 2) (match-end 2)
2329 'mouse-face 'highlight))))
2330 (goto-char (point-min))
2331 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2332 nil t)
2333 (let ((c (preceding-char))
2334 face)
2335 (cond ((= c ?*) (setq face 'Info-title-1-face))
2336 ((= c ?=) (setq face 'Info-title-2-face))
2337 (t (setq face 'Info-title-3-face)))
2338 (put-text-property (match-beginning 1) (match-end 1)
2339 'face face))
2340 ;; This is a serious problem for trying to handle multiple
2341 ;; frame types at once. We want this text to be invisible
2342 ;; on frames that can display the font above.
2343 (if (memq (framep (selected-frame)) '(x pc w32))
2344 (add-text-properties (match-end 1) (match-end 2)
2345 '(invisible t intangible t))))
2346 (goto-char (point-min))
2347 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
2348 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2350 (put-text-property (match-beginning 1) (match-end 1)
2351 'face 'info-xref)
2352 (put-text-property (match-beginning 1) (match-end 1)
2353 'mouse-face 'highlight)))
2354 (goto-char (point-min))
2355 (if (and (search-forward "\n* Menu:" nil t)
2356 (not (string-match "\\<Index\\>" Info-current-node))
2357 ;; Don't take time to annotate huge menus
2358 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2359 (let ((n 0))
2360 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
2361 (setq n (1+ n))
2362 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
2363 (put-text-property (match-beginning 0)
2364 (1+ (match-beginning 0))
2365 'face 'info-menu-5))
2366 (put-text-property (match-beginning 1) (match-end 1)
2367 'face 'info-xref)
2368 (put-text-property (match-beginning 1) (match-end 1)
2369 'mouse-face 'highlight))))
2370 (set-buffer-modified-p nil))))
2373 ;; When an Info buffer is killed, make sure the associated tags buffer
2374 ;; is killed too.
2375 (defun Info-kill-buffer ()
2376 (and (eq major-mode 'Info-mode)
2377 Info-tag-table-buffer
2378 (kill-buffer Info-tag-table-buffer)))
2380 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2382 ;;; Speedbar support:
2383 ;; These functions permit speedbar to display the "tags" in the
2384 ;; current info node.
2385 (eval-when-compile (require 'speedbar))
2387 (defvar Info-speedbar-key-map nil
2388 "Keymap used when in the info display mode.")
2390 (defun Info-install-speedbar-variables ()
2391 "Install those variables used by speedbar to enhance Info."
2392 (if Info-speedbar-key-map
2394 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2396 ;; Basic tree features
2397 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2398 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2399 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2400 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2403 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2404 Info-speedbar-key-map
2405 Info-speedbar-hierarchy-buttons)))
2407 (defvar Info-speedbar-menu-items
2408 '(["Browse Node" speedbar-edit-line t]
2409 ["Expand Node" speedbar-expand-line
2410 (save-excursion (beginning-of-line)
2411 (looking-at "[0-9]+: *.\\+. "))]
2412 ["Contract Node" speedbar-contract-line
2413 (save-excursion (beginning-of-line)
2414 (looking-at "[0-9]+: *.-. "))]
2416 "Additional menu-items to add to speedbar frame.")
2418 ;; Make sure our special speedbar major mode is loaded
2419 (if (featurep 'speedbar)
2420 (Info-install-speedbar-variables)
2421 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2423 ;;; Info hierarchy display method
2424 ;;;###autoload
2425 (defun Info-speedbar-browser ()
2426 "Initialize speedbar to display an info node browser.
2427 This will add a speedbar major display mode."
2428 (interactive)
2429 (require 'speedbar)
2430 ;; Make sure that speedbar is active
2431 (speedbar-frame-mode 1)
2432 ;; Now, throw us into Info mode on speedbar.
2433 (speedbar-change-initial-expansion-list "Info")
2436 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2437 "Display an Info directory hierarchy in speedbar.
2438 DIRECTORY is the current directory in the attached frame.
2439 DEPTH is the current indentation depth.
2440 NODE is an optional argument that is used to represent the
2441 specific node to expand."
2442 (if (and (not node)
2443 (save-excursion (goto-char (point-min))
2444 (let ((case-fold-search t))
2445 (looking-at "Info Nodes:"))))
2446 ;; Update our "current node" maybe?
2448 ;; We cannot use the generic list code, that depends on all leaves
2449 ;; being known at creation time.
2450 (if (not node)
2451 (speedbar-with-writable (insert "Info Nodes:\n")))
2452 (let ((completions nil)
2453 (cf (selected-frame)))
2454 (select-frame speedbar-attached-frame)
2455 (save-window-excursion
2456 (setq completions
2457 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
2458 (select-frame cf)
2459 (if completions
2460 (speedbar-with-writable
2461 (while completions
2462 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2463 (cdr (car completions))
2464 (car (car completions))
2465 'Info-speedbar-goto-node
2466 (cdr (car completions))
2467 'info-xref depth)
2468 (setq completions (cdr completions)))
2470 nil))))
2472 (defun Info-speedbar-goto-node (text node indent)
2473 "When user clicks on TEXT, goto an info NODE.
2474 The INDENT level is ignored."
2475 (select-frame speedbar-attached-frame)
2476 (let* ((buff (or (get-buffer "*info*")
2477 (progn (info) (get-buffer "*info*"))))
2478 (bwin (get-buffer-window buff 0)))
2479 (if bwin
2480 (progn
2481 (select-window bwin)
2482 (raise-frame (window-frame bwin)))
2483 (if speedbar-power-click
2484 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2485 (select-frame speedbar-attached-frame)
2486 (switch-to-buffer buff)))
2487 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
2488 (file (match-string 1 node))
2489 (node (match-string 2 node)))
2490 (Info-find-node file node)
2491 ;; If we do a find-node, and we were in info mode, restore
2492 ;; the old default method. Once we are in info mode, it makes
2493 ;; sense to return to whatever method the user was using before.
2494 (if (string= speedbar-initial-expansion-list-name "Info")
2495 (speedbar-change-initial-expansion-list
2496 speedbar-previously-used-expansion-list-name)))))
2498 (defun Info-speedbar-expand-node (text token indent)
2499 "Expand the node the user clicked on.
2500 TEXT is the text of the button we clicked on, a + or - item.
2501 TOKEN is data related to this node (NAME . FILE).
2502 INDENT is the current indentation depth."
2503 (cond ((string-match "+" text) ;we have to expand this file
2504 (speedbar-change-expand-button-char ?-)
2505 (if (speedbar-with-writable
2506 (save-excursion
2507 (end-of-line) (forward-char 1)
2508 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
2509 (speedbar-change-expand-button-char ?-)
2510 (speedbar-change-expand-button-char ??)))
2511 ((string-match "-" text) ;we have to contract this node
2512 (speedbar-change-expand-button-char ?+)
2513 (speedbar-delete-subblock indent))
2514 (t (error "Ooops... not sure what to do")))
2515 (speedbar-center-buffer-smartly))
2517 (defun Info-speedbar-fetch-file-nodes (nodespec)
2518 "Fetch the subnodes from the info NODESPEC.
2519 NODESPEC is a string of the form: (file)node.
2520 Optional THISFILE represends the filename of"
2521 (save-excursion
2522 ;; Set up a buffer we can use to fake-out Info.
2523 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2524 (if (not (equal major-mode 'Info-mode))
2525 (Info-mode))
2526 ;; Get the node into this buffer
2527 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
2528 (file (match-string 1 nodespec))
2529 (node (match-string 2 nodespec)))
2530 (Info-find-node file node))
2531 ;; Scan the created buffer
2532 (goto-char (point-min))
2533 (let ((completions nil)
2534 (case-fold-search t)
2535 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
2536 (match-string 1 nodespec))))
2537 ;; Always skip the first one...
2538 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2539 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2540 (let ((name (match-string 1)))
2541 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2542 (setq name (cons name (match-string 1)))
2543 (if (looking-at " *\\(([^)]+)\\)\\.")
2544 (setq name (cons name (concat (match-string 1) "Top")))
2545 (if (looking-at " \\([^.]+\\).")
2546 (setq name
2547 (cons name (concat "(" thisfile ")" (match-string 1))))
2548 (setq name (cons name (concat "(" thisfile ")" name))))))
2549 (setq completions (cons name completions))))
2550 (nreverse completions))))
2552 ;;; Info mode node listing
2553 (defun Info-speedbar-buttons (buffer)
2554 "Create a speedbar display to help navigation in an Info file.
2555 BUFFER is the buffer speedbar is requesting buttons for."
2556 (if (save-excursion (goto-char (point-min))
2557 (let ((case-fold-search t))
2558 (not (looking-at "Info Nodes:"))))
2559 (erase-buffer))
2560 (Info-speedbar-hierarchy-buttons nil 0)
2563 (dolist (mess '("^Node has no Previous$"
2564 "^No menu in this node$"
2565 "^Node has no Next$"
2566 "^No cross-references in this node^"
2567 search-failed
2568 "^No \".*\" in index$"))
2569 (add-to-list 'debug-ignored-errors mess))
2571 (provide 'info)
2573 ;;; info.el ends here