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