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