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