]> code.delx.au - gnu-emacs/blob - lisp/info.el
(widget-button-click): Wrap with save-excursion
[gnu-emacs] / lisp / info.el
1 ;;; info.el --- info package for Emacs.
2
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 97, 98, 99 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 (eval-when-compile (require 'jka-compr))
33
34 (defgroup info nil
35 "Info subsystem"
36 :group 'help
37 :group 'docs)
38
39
40 (defvar Info-history nil
41 "List of info nodes user has visited.
42 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
43
44 (defcustom Info-enable-edit nil
45 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
46 This is convenient if you want to write info files by hand.
47 However, we recommend that you not do this.
48 It is better to write a Texinfo file and generate the Info file from that,
49 because that gives you a printed manual as well."
50 :type 'boolean
51 :group 'info)
52
53 (defvar Info-enable-active-nodes nil
54 "Non-nil allows Info to execute Lisp code associated with nodes.
55 The Lisp code is executed when the node is selected.")
56 (put 'Info-enable-active-nodes 'risky-local-variable t)
57
58 (defcustom Info-fontify t
59 "*Non-nil enables highlighting and fonts in Info nodes."
60 :type 'boolean
61 :group 'info)
62
63 (defface info-node
64 '((t (:bold t :italic t)))
65 "Face for Info node names."
66 :group 'info)
67
68 (defface info-menu-5
69 '((t (:underline t)))
70 "Face for the fifth and tenth `*' in an Info menu."
71 :group 'info)
72
73 (defface info-xref
74 '((t (:bold t)))
75 "Face for Info cross-references."
76 :group 'info)
77
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)
82
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.
90
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.")
95
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)
101
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'.")
107
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.")
111
112 (defvar Info-current-node nil
113 "Name of node that Info is now looking at, or nil.")
114
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.")
118
119 (defvar Info-tag-table-buffer nil
120 "Buffer used for indirect tag tables.")
121
122 (defvar Info-current-file-completions nil
123 "Cached completion list for current Info file.")
124
125 (defvar Info-index-alternatives nil
126 "List of possible matches for last Info-index command.")
127
128 (defvar Info-standalone nil
129 "Non-nil if Emacs was started solely as an Info browser.")
130 \f
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.")
180
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))))
203
204 (defun info-file-exists-p (filename)
205 (and (file-exists-p filename)
206 (not (file-directory-p filename))))
207
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))))
249 \f
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))
270 nil
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))))))))))
283
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)))
291
292 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
293
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'.
301
302 In interactive use, a prefix argument directs this command
303 to read a file name from the minibuffer.
304
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))))
323
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)))
341 \f
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.
347
348 ;; This function changes match-data, but supposedly the caller might
349 ;; want to use the results of re-search-backward.
350
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))))
361
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))
415
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))
428
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:
492 ;;
493 ;; 1. Anchor found in tag table
494 ;; 2. Anchor *not* in tag table
495 ;;
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
499 ;;
500 ;; *Or* the same, but in an indirect subfile.
501
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))
509
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.
520
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))
535
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)))))
548
549 ;; Handle anchor
550 (if found-anchor
551 (goto-char (setq anchorpos guesspos))
552
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))))))
617
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)
621
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)
625
626 ;; Record the file attributes of all the files from which we
627 ;; constructed Info-dir-contents.
628 (defvar Info-dir-file-attributes nil)
629
630 (defvar Info-dir-file-name nil)
631
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)))))
645
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)
660
661 (setq Info-dir-file-attributes nil)
662
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
672 (or
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))))
703
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))
712
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)
717
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))
797
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)))))
846
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)))))
882
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 "")))
891 "")
892 ")"
893 (or Info-current-node ""))))
894 \f
895 ;; Go to an info node specified with a filename-and-nodename string
896 ;; of the sort that is found in pointers in nodes.
897
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))
911 ""
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))))
921
922 (defvar Info-read-node-completion-table)
923
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
935 nil
936 (all-completions string Info-read-node-completion-table predicate)))
937 ((eq code 'lambda)
938 (if no-completion
939 t
940 (assoc string Info-read-node-completion-table))))))
941
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)))
950
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 (buffer-substring (match-beginning 1)
967 (match-end 1)))
968 compl))))
969 (widen)
970 (goto-char (point-min))
971 ;; If the buffer begins with a node header, process that first.
972 (if (Info-node-at-bob-matching node-regexp)
973 (setq compl (list (buffer-substring (match-beginning 1)
974 (match-end 1)))))
975 ;; Now for the rest of the nodes.
976 (while (search-forward "\n\^_" nil t)
977 (forward-line 1)
978 (let ((beg (point)))
979 (forward-line 1)
980 (if (re-search-backward node-regexp beg t)
981 (setq compl
982 (cons (list (buffer-substring (match-beginning 1)
983 (match-end 1)))
984 compl))))))))
985 (setq compl (cons '("*") compl))
986 (setq Info-current-file-completions compl))))
987 \f
988 (defun Info-restore-point (hl)
989 "If this node has been visited, restore the point value when we left."
990 (while hl
991 (if (and (equal (nth 0 (car hl)) Info-current-file)
992 ;; Use string-equal, not equal, to ignore text props.
993 (string-equal (nth 1 (car hl)) Info-current-node))
994 (progn
995 (goto-char (nth 2 (car hl)))
996 (setq hl nil)) ;terminate the while at next iter
997 (setq hl (cdr hl)))))
998 \f
999 (defvar Info-last-search nil
1000 "Default regexp for \\<Info-mode-map>\\[Info-search] command to search for.")
1001
1002 (defun Info-search (regexp)
1003 "Search for REGEXP, starting from point, and select node it's found in."
1004 (interactive "sSearch (regexp): ")
1005 (if transient-mark-mode (deactivate-mark))
1006 (if (equal regexp "")
1007 (setq regexp Info-last-search)
1008 (setq Info-last-search regexp))
1009 (when regexp
1010 (let ((found ()) current
1011 (onode Info-current-node)
1012 (ofile Info-current-file)
1013 (opoint (point))
1014 (ostart (window-start))
1015 (osubfile Info-current-subfile))
1016 (save-excursion
1017 (save-restriction
1018 (widen)
1019 (if (null Info-current-subfile)
1020 (progn (re-search-forward regexp) (setq found (point)))
1021 (condition-case err
1022 (progn (re-search-forward regexp) (setq found (point)))
1023 (search-failed nil)))))
1024 (if (not found) ;can only happen in subfile case -- else would have erred
1025 (unwind-protect
1026 (let ((list ()))
1027 (save-excursion
1028 (set-buffer (marker-buffer Info-tag-table-marker))
1029 (goto-char (point-min))
1030 (search-forward "\n\^_\nIndirect:")
1031 (save-restriction
1032 (narrow-to-region (point)
1033 (progn (search-forward "\n\^_")
1034 (1- (point))))
1035 (goto-char (point-min))
1036 (search-forward (concat "\n" osubfile ": "))
1037 (beginning-of-line)
1038 (while (not (eobp))
1039 (re-search-forward "\\(^.*\\): [0-9]+$")
1040 (goto-char (+ (match-end 1) 2))
1041 (setq list (cons (cons (read (current-buffer))
1042 (buffer-substring
1043 (match-beginning 1) (match-end 1)))
1044 list))
1045 (goto-char (1+ (match-end 0))))
1046 (setq list (nreverse list)
1047 current (car (car list))
1048 list (cdr list))))
1049 (while list
1050 (message "Searching subfile %s..." (cdr (car list)))
1051 (Info-read-subfile (car (car list)))
1052 (setq list (cdr list))
1053 ;;; (goto-char (point-min))
1054 (if (re-search-forward regexp nil t)
1055 (setq found (point) list ())))
1056 (if found
1057 (message "")
1058 (signal 'search-failed (list regexp))))
1059 (if (not found)
1060 (progn (Info-read-subfile osubfile)
1061 (goto-char opoint)
1062 (Info-select-node)
1063 (set-window-start (selected-window) ostart)))))
1064 (widen)
1065 (goto-char found)
1066 (Info-select-node)
1067 ;; Use string-equal, not equal, to ignore text props.
1068 (or (and (string-equal onode Info-current-node)
1069 (equal ofile Info-current-file))
1070 (setq Info-history (cons (list ofile onode opoint)
1071 Info-history))))))
1072 \f
1073 ;; Extract the value of the node-pointer named NAME.
1074 ;; If there is none, use ERRORNAME in the error message;
1075 ;; if ERRORNAME is nil, just return nil.
1076 (defun Info-extract-pointer (name &optional errorname)
1077 ;; Bind this in case the user sets it to nil.
1078 (let ((case-fold-search t))
1079 (save-excursion
1080 (goto-char (point-min))
1081 (forward-line 1)
1082 (if (re-search-backward (concat name ":") nil t)
1083 (progn
1084 (goto-char (match-end 0))
1085 (Info-following-node-name))
1086 (if (eq errorname t)
1087 nil
1088 (error "Node has no %s" (capitalize (or errorname name))))))))
1089
1090 ;; Return the node name in the buffer following point.
1091 ;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1092 ;; saying which chars may appear in the node name.
1093 (defun Info-following-node-name (&optional allowedchars)
1094 (skip-chars-forward " \t")
1095 (buffer-substring-no-properties
1096 (point)
1097 (progn
1098 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1099 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1100 (if (looking-at "(")
1101 (skip-chars-forward "^)")))
1102 (skip-chars-backward " ")
1103 (point))))
1104
1105 (defun Info-next ()
1106 "Go to the next node of this node."
1107 (interactive)
1108 (Info-goto-node (Info-extract-pointer "next")))
1109
1110 (defun Info-prev ()
1111 "Go to the previous node of this node."
1112 (interactive)
1113 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1114
1115 (defun Info-up (&optional same-file)
1116 "Go to the superior node of this node.
1117 If SAME-FILE is non-nil, do not move to a different Info file."
1118 (interactive)
1119 (let ((node (Info-extract-pointer "up")))
1120 (and (or same-file (not (stringp Info-current-file)))
1121 (string-match "^(" node)
1122 (error "Up node is in another Info file"))
1123 (Info-goto-node node))
1124 (Info-restore-point Info-history))
1125
1126 (defun Info-last ()
1127 "Go back to the last node visited."
1128 (interactive)
1129 (or Info-history
1130 (error "This is the first Info node you looked at"))
1131 (let (filename nodename opoint)
1132 (setq filename (car (car Info-history)))
1133 (setq nodename (car (cdr (car Info-history))))
1134 (setq opoint (car (cdr (cdr (car Info-history)))))
1135 (setq Info-history (cdr Info-history))
1136 (Info-find-node filename nodename)
1137 (setq Info-history (cdr Info-history))
1138 (goto-char opoint)))
1139
1140 (defun Info-directory ()
1141 "Go to the Info directory node."
1142 (interactive)
1143 (Info-find-node "dir" "top"))
1144 \f
1145 (defun Info-follow-reference (footnotename)
1146 "Follow cross reference named NAME to the node it refers to.
1147 NAME may be an abbreviation of the reference name."
1148 (interactive
1149 (let ((completion-ignore-case t)
1150 (case-fold-search t)
1151 completions default alt-default (start-point (point)) str i bol eol)
1152 (save-excursion
1153 ;; Store end and beginning of line.
1154 (end-of-line)
1155 (setq eol (point))
1156 (beginning-of-line)
1157 (setq bol (point))
1158
1159 (goto-char (point-min))
1160 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1161 (setq str (buffer-substring
1162 (match-beginning 1)
1163 (1- (point))))
1164 ;; See if this one should be the default.
1165 (and (null default)
1166 (<= (match-beginning 0) start-point)
1167 (<= start-point (point))
1168 (setq default t))
1169 ;; See if this one should be the alternate default.
1170 (and (null alt-default)
1171 (and (<= bol (match-beginning 0))
1172 (<= (point) eol))
1173 (setq alt-default t))
1174 (setq i 0)
1175 (while (setq i (string-match "[ \n\t]+" str i))
1176 (setq str (concat (substring str 0 i) " "
1177 (substring str (match-end 0))))
1178 (setq i (1+ i)))
1179 ;; Record as a completion and perhaps as default.
1180 (if (eq default t) (setq default str))
1181 (if (eq alt-default t) (setq alt-default str))
1182 ;; Don't add this string if it's a duplicate.
1183 ;; We use a loop instead of "(assoc str completions)" because
1184 ;; we want to do a case-insensitive compare.
1185 (let ((tail completions)
1186 (tem (downcase str)))
1187 (while (and tail
1188 (not (string-equal tem (downcase (car (car tail))))))
1189 (setq tail (cdr tail)))
1190 (or tail
1191 (setq completions
1192 (cons (cons str nil)
1193 completions))))))
1194 ;; If no good default was found, try an alternate.
1195 (or default
1196 (setq default alt-default))
1197 ;; If only one cross-reference found, then make it default.
1198 (if (eq (length completions) 1)
1199 (setq default (car (car completions))))
1200 (if completions
1201 (let ((input (completing-read (if default
1202 (concat "Follow reference named: ("
1203 default ") ")
1204 "Follow reference named: ")
1205 completions nil t)))
1206 (list (if (equal input "")
1207 default input)))
1208 (error "No cross-references in this node"))))
1209
1210 (unless footnotename
1211 (error "No reference was specified"))
1212
1213 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
1214 (case-fold-search t))
1215 (while (setq i (string-match " " str i))
1216 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1217 (setq i (+ i 6)))
1218 (save-excursion
1219 (goto-char (point-min))
1220 (or (re-search-forward str nil t)
1221 (error "No cross-reference named %s" footnotename))
1222 (goto-char (+ (match-beginning 0) 5))
1223 (setq target
1224 (Info-extract-menu-node-name "Bad format cross reference" t)))
1225 (while (setq i (string-match "[ \t\n]+" target i))
1226 (setq target (concat (substring target 0 i) " "
1227 (substring target (match-end 0))))
1228 (setq i (+ i 1)))
1229 (Info-goto-node target)))
1230
1231 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1232 (skip-chars-forward " \t\n")
1233 (let ((beg (point))
1234 str i)
1235 (skip-chars-forward "^:")
1236 (forward-char 1)
1237 (setq str
1238 (if (looking-at ":")
1239 (buffer-substring-no-properties beg (1- (point)))
1240 (skip-chars-forward " \t\n")
1241 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1242 (while (setq i (string-match "\n" str i))
1243 (aset str i ?\ ))
1244 ;; Collapse multiple spaces.
1245 (while (string-match " +" str)
1246 (setq str (replace-match " " t t str)))
1247 str))
1248
1249 ;; No one calls this.
1250 ;;(defun Info-menu-item-sequence (list)
1251 ;; (while list
1252 ;; (Info-menu (car list))
1253 ;; (setq list (cdr list))))
1254
1255 (defvar Info-complete-menu-buffer)
1256
1257 (defun Info-complete-menu-item (string predicate action)
1258 (let ((case-fold-search t))
1259 (cond ((eq action nil)
1260 (let (completions
1261 (pattern (concat "\n\\* +\\("
1262 (regexp-quote string)
1263 "[^:\t\n]*\\):")))
1264 (save-excursion
1265 (set-buffer Info-complete-menu-buffer)
1266 (goto-char (point-min))
1267 (search-forward "\n* Menu:")
1268 (while (re-search-forward pattern nil t)
1269 (setq completions (cons (cons (format "%s"
1270 (buffer-substring
1271 (match-beginning 1)
1272 (match-end 1)))
1273 (match-beginning 1))
1274 completions))))
1275 (try-completion string completions predicate)))
1276 ((eq action t)
1277 (let (completions
1278 (pattern (concat "\n\\* +\\("
1279 (regexp-quote string)
1280 "[^:\t\n]*\\):")))
1281 (save-excursion
1282 (set-buffer Info-complete-menu-buffer)
1283 (goto-char (point-min))
1284 (search-forward "\n* Menu:")
1285 (while (re-search-forward pattern nil t)
1286 (setq completions (cons (cons (format "%s"
1287 (buffer-substring
1288 (match-beginning 1)
1289 (match-end 1)))
1290 (match-beginning 1))
1291 completions))))
1292 (all-completions string completions predicate)))
1293 (t
1294 (save-excursion
1295 (set-buffer Info-complete-menu-buffer)
1296 (goto-char (point-min))
1297 (search-forward "\n* Menu:")
1298 (re-search-forward (concat "\n\\* +"
1299 (regexp-quote string)
1300 ":")
1301 nil t))))))
1302
1303
1304 (defun Info-menu (menu-item &optional fork)
1305 "Go to node for menu item named (or abbreviated) NAME.
1306 Completion is allowed, and the menu item point is on is the default."
1307 (interactive
1308 (let ((completions '())
1309 ;; If point is within a menu item, use that item as the default
1310 (default nil)
1311 (p (point))
1312 beg
1313 (last nil))
1314 (save-excursion
1315 (goto-char (point-min))
1316 (if (not (search-forward "\n* menu:" nil t))
1317 (error "No menu in this node"))
1318 (setq beg (point))
1319 (and (< (point) p)
1320 (save-excursion
1321 (goto-char p)
1322 (end-of-line)
1323 (if (re-search-backward "\n\\* +\\([^:\t\n]*\\):" beg t)
1324 (setq default (format "%s" (buffer-substring
1325 (match-beginning 1)
1326 (match-end 1))))))))
1327 (let ((item nil))
1328 (while (null item)
1329 (setq item (let ((completion-ignore-case t)
1330 (Info-complete-menu-buffer (current-buffer)))
1331 (completing-read (if default
1332 (format "Menu item (default %s): "
1333 default)
1334 "Menu item: ")
1335 'Info-complete-menu-item nil t)))
1336 ;; we rely on the fact that completing-read accepts an input
1337 ;; of "" even when the require-match argument is true and ""
1338 ;; is not a valid possibility
1339 (if (string= item "")
1340 (if default
1341 (setq item default)
1342 ;; ask again
1343 (setq item nil))))
1344 (list item current-prefix-arg))))
1345 ;; there is a problem here in that if several menu items have the same
1346 ;; name you can only go to the node of the first with this command.
1347 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
1348
1349 (defun Info-extract-menu-item (menu-item)
1350 (setq menu-item (regexp-quote menu-item))
1351 (let ((case-fold-search t))
1352 (save-excursion
1353 (goto-char (point-min))
1354 (or (search-forward "\n* menu:" nil t)
1355 (error "No menu in this node"))
1356 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1357 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1358 (error "No such item in menu"))
1359 (beginning-of-line)
1360 (forward-char 2)
1361 (Info-extract-menu-node-name))))
1362
1363 ;; If COUNT is nil, use the last item in the menu.
1364 (defun Info-extract-menu-counting (count)
1365 (let ((case-fold-search t))
1366 (save-excursion
1367 (goto-char (point-min))
1368 (or (search-forward "\n* menu:" nil t)
1369 (error "No menu in this node"))
1370 (if count
1371 (or (search-forward "\n* " nil t count)
1372 (error "Too few items in menu"))
1373 (while (search-forward "\n* " nil t)
1374 nil))
1375 (Info-extract-menu-node-name))))
1376
1377 (defun Info-nth-menu-item ()
1378 "Go to the node of the Nth menu item.
1379 N is the digit argument used to invoke this command."
1380 (interactive)
1381 (Info-goto-node
1382 (Info-extract-menu-counting
1383 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1384
1385 (defun Info-top-node ()
1386 "Go to the Top node of this file."
1387 (interactive)
1388 (Info-goto-node "Top"))
1389
1390 (defun Info-final-node ()
1391 "Go to the final node in this file."
1392 (interactive)
1393 (Info-goto-node "Top")
1394 (let (Info-history)
1395 ;; Go to the last node in the menu of Top.
1396 (Info-goto-node (Info-extract-menu-counting nil))
1397 ;; If the last node in the menu is not last in pointer structure,
1398 ;; move forward until we can't go any farther.
1399 (while (Info-forward-node t t) nil)
1400 ;; Then keep moving down to last subnode, unless we reach an index.
1401 (while (and (not (string-match "\\<index\\>" Info-current-node))
1402 (save-excursion (search-forward "\n* Menu:" nil t)))
1403 (Info-goto-node (Info-extract-menu-counting nil)))))
1404
1405 (defun Info-forward-node (&optional not-down no-error)
1406 "Go forward one node, considering all nodes as forming one sequence."
1407 (interactive)
1408 (goto-char (point-min))
1409 (forward-line 1)
1410 ;; three possibilities, in order of priority:
1411 ;; 1. next node is in a menu in this node (but not in an index)
1412 ;; 2. next node is next at same level
1413 ;; 3. next node is up and next
1414 (cond ((and (not not-down)
1415 (save-excursion (search-forward "\n* menu:" nil t))
1416 (not (string-match "\\<index\\>" Info-current-node)))
1417 (Info-goto-node (Info-extract-menu-counting 1))
1418 t)
1419 ((save-excursion (search-backward "next:" nil t))
1420 (Info-next)
1421 t)
1422 ((and (save-excursion (search-backward "up:" nil t))
1423 ;; Use string-equal, not equal, to ignore text props.
1424 (not (string-equal (downcase (Info-extract-pointer "up"))
1425 "top")))
1426 (let ((old-node Info-current-node))
1427 (Info-up)
1428 (let (Info-history success)
1429 (unwind-protect
1430 (setq success (Info-forward-node t no-error))
1431 (or success (Info-goto-node old-node))))))
1432 (no-error nil)
1433 (t (error "No pointer forward from this node"))))
1434
1435 (defun Info-backward-node ()
1436 "Go backward one node, considering all nodes as forming one sequence."
1437 (interactive)
1438 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1439 (upnode (Info-extract-pointer "up" t)))
1440 (cond ((and upnode (string-match "(" upnode))
1441 (error "First node in file"))
1442 ((and upnode (or (null prevnode)
1443 ;; Use string-equal, not equal,
1444 ;; to ignore text properties.
1445 (string-equal (downcase prevnode)
1446 (downcase upnode))))
1447 (Info-up))
1448 (prevnode
1449 ;; If we move back at the same level,
1450 ;; go down to find the last subnode*.
1451 (Info-prev)
1452 (let (Info-history)
1453 (while (and (not (string-match "\\<index\\>" Info-current-node))
1454 (save-excursion (search-forward "\n* Menu:" nil t)))
1455 (Info-goto-node (Info-extract-menu-counting nil)))))
1456 (t
1457 (error "No pointer backward from this node")))))
1458
1459 (defun Info-exit ()
1460 "Exit Info by selecting some other buffer."
1461 (interactive)
1462 (if Info-standalone
1463 (save-buffers-kill-emacs)
1464 (quit-window)))
1465
1466 (defun Info-next-menu-item ()
1467 (interactive)
1468 (let ((node
1469 (save-excursion
1470 (forward-line -1)
1471 (search-forward "\n* menu:" nil t)
1472 (and (search-forward "\n* " nil t)
1473 (Info-extract-menu-node-name)))))
1474 (if node (Info-goto-node node)
1475 (error "No more items in menu"))))
1476
1477 (defun Info-last-menu-item ()
1478 (interactive)
1479 (save-excursion
1480 (forward-line 1)
1481 (let ((beg (save-excursion
1482 (and (search-backward "\n* menu:" nil t)
1483 (point)))))
1484 (or (and beg (search-backward "\n* " beg t))
1485 (error "No previous items in menu")))
1486 (Info-goto-node (save-excursion
1487 (goto-char (match-end 0))
1488 (Info-extract-menu-node-name)))))
1489
1490 (defmacro Info-no-error (&rest body)
1491 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1492
1493 (defun Info-next-preorder ()
1494 "Go to the next subnode or the next node, or go up a level."
1495 (interactive)
1496 (cond ((Info-no-error (Info-next-menu-item)))
1497 ((Info-no-error (Info-next)))
1498 ((Info-no-error (Info-up t))
1499 ;; Since we have already gone thru all the items in this menu,
1500 ;; go up to the end of this node.
1501 (goto-char (point-max))
1502 ;; Since logically we are done with the node with that menu,
1503 ;; move on from it.
1504 (Info-next-preorder))
1505 (t
1506 (error "No more nodes"))))
1507
1508 (defun Info-last-preorder ()
1509 "Go to the last node, popping up a level if there is none."
1510 (interactive)
1511 (cond ((Info-no-error
1512 (Info-last-menu-item)
1513 ;; If we go down a menu item, go to the end of the node
1514 ;; so we can scroll back through it.
1515 (goto-char (point-max)))
1516 ;; Keep going down, as long as there are nested menu nodes.
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 ((and (not (equal (Info-extract-pointer "up")
1524 (Info-extract-pointer "prev"))))
1525 (Info-no-error (Info-prev))
1526 (goto-char (point-max))
1527 (while (Info-no-error
1528 (Info-last-menu-item)
1529 ;; If we go down a menu item, go to the end of the node
1530 ;; so we can scroll back through it.
1531 (goto-char (point-max))))
1532 (recenter -1))
1533 ((Info-no-error (Info-up t))
1534 (goto-char (point-min))
1535 (or (search-forward "\n* Menu:" nil t)
1536 (goto-char (point-max))))
1537 (t (error "No previous nodes"))))
1538
1539 (defun Info-scroll-up ()
1540 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1541 Once you scroll far enough in a node that its menu appears on the screen
1542 but after point, the next scroll moves into its first subnode.
1543
1544 When you scroll past the end of a node, that goes to the next node; if
1545 this node has no successor, it moves to the parent node's successor,
1546 and so on. If point is inside the menu of a node, it moves to
1547 subnode indicated by the following menu item. (That case won't
1548 normally result from this command, but can happen in other ways.)"
1549
1550 (interactive)
1551 (if (or (< (window-start) (point-min))
1552 (> (window-start) (point-max)))
1553 (set-window-start (selected-window) (point)))
1554 (let ((virtual-end (save-excursion
1555 (goto-char (point-min))
1556 (if (search-forward "\n* Menu:" nil t)
1557 (point)
1558 (point-max)))))
1559 (if (or (< virtual-end (window-start))
1560 (pos-visible-in-window-p virtual-end))
1561 (Info-next-preorder)
1562 (scroll-up))))
1563
1564 (defun Info-scroll-down ()
1565 "Scroll one screenful back in Info, considering all nodes as one sequence.
1566 Within the menu of a node, this goes to its last subnode.
1567 When you scroll past the beginning of a node, that goes to the
1568 previous node or back up to the parent node."
1569 (interactive)
1570 (if (or (< (window-start) (point-min))
1571 (> (window-start) (point-max)))
1572 (set-window-start (selected-window) (point)))
1573 (let* ((current-point (point))
1574 (virtual-end (save-excursion
1575 (beginning-of-line)
1576 (setq current-point (point))
1577 (goto-char (point-min))
1578 (search-forward "\n* Menu:"
1579 current-point
1580 t))))
1581 (if (or virtual-end (pos-visible-in-window-p (point-min)))
1582 (Info-last-preorder)
1583 (scroll-down))))
1584
1585 (defun Info-next-reference (&optional recur)
1586 "Move cursor to the next cross-reference or menu item in the node."
1587 (interactive)
1588 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1589 (old-pt (point))
1590 (case-fold-search t))
1591 (or (eobp) (forward-char 1))
1592 (or (re-search-forward pat nil t)
1593 (progn
1594 (goto-char (point-min))
1595 (or (re-search-forward pat nil t)
1596 (progn
1597 (goto-char old-pt)
1598 (error "No cross references in this node")))))
1599 (goto-char (match-beginning 0))
1600 (if (looking-at "\\* Menu:")
1601 (if recur
1602 (error "No cross references in this node")
1603 (Info-next-reference t)))))
1604
1605 (defun Info-prev-reference (&optional recur)
1606 "Move cursor to the previous cross-reference or menu item in the node."
1607 (interactive)
1608 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1609 (old-pt (point))
1610 (case-fold-search t))
1611 (or (re-search-backward pat nil t)
1612 (progn
1613 (goto-char (point-max))
1614 (or (re-search-backward pat nil t)
1615 (progn
1616 (goto-char old-pt)
1617 (error "No cross references in this node")))))
1618 (goto-char (match-beginning 0))
1619 (if (looking-at "\\* Menu:")
1620 (if recur
1621 (error "No cross references in this node")
1622 (Info-prev-reference t)))))
1623
1624 (defun Info-index (topic)
1625 "Look up a string in the index for this file.
1626 The index is defined as the first node in the top-level menu whose
1627 name contains the word \"Index\", plus any immediately following
1628 nodes whose names also contain the word \"Index\".
1629 If there are no exact matches to the specified topic, this chooses
1630 the first match which is a case-insensitive substring of a topic.
1631 Use the `,' command to see the other matches.
1632 Give a blank topic name to go to the Index node itself."
1633 (interactive "sIndex topic: ")
1634 (let ((orignode Info-current-node)
1635 (rnode nil)
1636 (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1637 (regexp-quote topic)))
1638 node
1639 (case-fold-search t))
1640 (Info-goto-node "Top")
1641 (or (search-forward "\n* menu:" nil t)
1642 (error "No index"))
1643 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1644 (error "No index"))
1645 (goto-char (match-beginning 1))
1646 ;; Here, and subsequently in this function,
1647 ;; we bind Info-history to nil for internal node-switches
1648 ;; so that we don't put junk in the history.
1649 ;; In the first Info-goto-node call, above, we do update the history
1650 ;; because that is what the user's previous node choice into it.
1651 (let ((Info-history nil))
1652 (Info-goto-node (Info-extract-menu-node-name)))
1653 (or (equal topic "")
1654 (let ((matches nil)
1655 (exact nil)
1656 (Info-history nil)
1657 found)
1658 (while
1659 (progn
1660 (goto-char (point-min))
1661 (while (re-search-forward pattern nil t)
1662 (setq matches
1663 (cons (list (buffer-substring (match-beginning 1)
1664 (match-end 1))
1665 (buffer-substring (match-beginning 2)
1666 (match-end 2))
1667 Info-current-node
1668 (string-to-int (concat "0"
1669 (buffer-substring
1670 (match-beginning 3)
1671 (match-end 3)))))
1672 matches)))
1673 (and (setq node (Info-extract-pointer "next" t))
1674 (string-match "\\<Index\\>" node)))
1675 (Info-goto-node node))
1676 (or matches
1677 (progn
1678 (Info-goto-node orignode)
1679 (error "No `%s' in index" topic)))
1680 ;; Here it is a feature that assoc is case-sensitive.
1681 (while (setq found (assoc topic matches))
1682 (setq exact (cons found exact)
1683 matches (delq found matches)))
1684 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1685 (Info-index-next 0)))))
1686
1687 (defun Info-index-next (num)
1688 "Go to the next matching index item from the last `i' command."
1689 (interactive "p")
1690 (or Info-index-alternatives
1691 (error "No previous `i' command"))
1692 (while (< num 0)
1693 (setq num (+ num (length Info-index-alternatives))))
1694 (while (> num 0)
1695 (setq Info-index-alternatives
1696 (nconc (cdr Info-index-alternatives)
1697 (list (car Info-index-alternatives)))
1698 num (1- num)))
1699 (Info-goto-node (nth 1 (car Info-index-alternatives)))
1700 (if (> (nth 3 (car Info-index-alternatives)) 0)
1701 (forward-line (nth 3 (car Info-index-alternatives)))
1702 (forward-line 3) ; don't search in headers
1703 (let ((name (car (car Info-index-alternatives))))
1704 (Info-find-index-name name)))
1705 (message "Found `%s' in %s. %s"
1706 (car (car Info-index-alternatives))
1707 (nth 2 (car Info-index-alternatives))
1708 (if (cdr Info-index-alternatives)
1709 "(Press `,' for more)"
1710 "(Only match)")))
1711
1712 (defun Info-find-index-name (name)
1713 "Move point to the place within the current node where NAME is defined."
1714 (let ((case-fold-search t))
1715 (if (or (re-search-forward (format
1716 "[a-zA-Z]+: %s\\( \\|$\\)"
1717 (regexp-quote name)) nil t)
1718 (search-forward (format "`%s'" name) nil t)
1719 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
1720 (search-forward
1721 (format "`%s'" (substring name 0 (match-beginning 1)))
1722 nil t))
1723 (search-forward name nil t))
1724 (beginning-of-line)
1725 (goto-char (point-min)))))
1726
1727 (defun Info-undefined ()
1728 "Make command be undefined in Info."
1729 (interactive)
1730 (ding))
1731
1732 (defun Info-help ()
1733 "Enter the Info tutorial."
1734 (interactive)
1735 (delete-other-windows)
1736 (Info-find-node "info"
1737 (if (< (window-height) 23)
1738 "Help-Small-Screen"
1739 "Help")))
1740
1741 (defun Info-summary ()
1742 "Display a brief summary of all Info commands."
1743 (interactive)
1744 (save-window-excursion
1745 (switch-to-buffer "*Help*")
1746 (setq buffer-read-only nil)
1747 (erase-buffer)
1748 (insert (documentation 'Info-mode))
1749 (help-mode)
1750 (goto-char (point-min))
1751 (let (ch flag)
1752 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
1753 (message (if flag "Type Space to see more"
1754 "Type Space to return to Info"))
1755 (if (not (eq ?\ (setq ch (read-event))))
1756 (progn (setq unread-command-events (list ch)) nil)
1757 flag))
1758 (scroll-up)))
1759 (bury-buffer "*Help*")))
1760 \f
1761 (defun Info-get-token (pos start all &optional errorstring)
1762 "Return the token around POS,
1763 POS must be somewhere inside the token
1764 START is a regular expression which will match the
1765 beginning of the tokens delimited string
1766 ALL is a regular expression with a single
1767 parenthesized subpattern which is the token to be
1768 returned. E.g. '{\(.*\)}' would return any string
1769 enclosed in braces around POS.
1770 SIG optional fourth argument, controls action on no match
1771 nil: return nil
1772 t: beep
1773 a string: signal an error, using that string."
1774 (let ((case-fold-search t))
1775 (save-excursion
1776 (goto-char pos)
1777 ;; First look for a match for START that goes across POS.
1778 (while (and (not (bobp)) (> (point) (- pos (length start)))
1779 (not (looking-at start)))
1780 (forward-char -1))
1781 ;; If we did not find one, search back for START
1782 ;; (this finds only matches that end at or before POS).
1783 (or (looking-at start)
1784 (progn
1785 (goto-char pos)
1786 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
1787 (let (found)
1788 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
1789 (not (setq found (and (<= (match-beginning 0) pos)
1790 (> (match-end 0) pos))))))
1791 (if (and found (<= (match-beginning 0) pos)
1792 (> (match-end 0) pos))
1793 (buffer-substring (match-beginning 1) (match-end 1))
1794 (cond ((null errorstring)
1795 nil)
1796 ((eq errorstring t)
1797 (beep)
1798 nil)
1799 (t
1800 (error "No %s around position %d" errorstring pos))))))))
1801
1802 (defun Info-mouse-follow-nearest-node (click)
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 you click.
1805 At end of the node's text, moves to the next node, or up if none."
1806 (interactive "e")
1807 (let* ((start (event-start click))
1808 (window (car start))
1809 (pos (car (cdr start))))
1810 (select-window window)
1811 (goto-char pos))
1812 (and (not (Info-try-follow-nearest-node))
1813 (save-excursion (forward-line 1) (eobp))
1814 (Info-next-preorder)))
1815
1816 (defun Info-follow-nearest-node ()
1817 "\\<Info-mode-map>Follow a node reference near point.
1818 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where point is.
1819 If no reference to follow, moves to the next node, or up if none."
1820 (interactive)
1821 (or (Info-try-follow-nearest-node)
1822 (Info-next-preorder)))
1823
1824 ;; Common subroutine.
1825 (defun Info-try-follow-nearest-node ()
1826 "Follow a node reference near point. Return non-nil if successful."
1827 (let (node)
1828 (cond
1829 ((setq node (Info-get-token (point) "\\*note[ \n]"
1830 "\\*note[ \n]\\([^:]*\\):"))
1831 (Info-follow-reference node))
1832 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
1833 (Info-goto-node node))
1834 ((Info-get-token (point) "\\* +" "\\* +\\([^:]*\\):")
1835 (beginning-of-line)
1836 (forward-char 2)
1837 (setq node (Info-extract-menu-node-name))
1838 (Info-goto-node node))
1839 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
1840 (Info-goto-node node))
1841 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
1842 (Info-goto-node node))
1843 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
1844 (Info-goto-node "Top"))
1845 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
1846 (Info-goto-node node)))
1847 node))
1848 \f
1849 (defvar Info-mode-map nil
1850 "Keymap containing Info commands.")
1851 (if Info-mode-map
1852 nil
1853 (setq Info-mode-map (make-keymap))
1854 (suppress-keymap Info-mode-map)
1855 (define-key Info-mode-map "." 'beginning-of-buffer)
1856 (define-key Info-mode-map " " 'Info-scroll-up)
1857 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
1858 (define-key Info-mode-map "\t" 'Info-next-reference)
1859 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
1860 (define-key Info-mode-map "1" 'Info-nth-menu-item)
1861 (define-key Info-mode-map "2" 'Info-nth-menu-item)
1862 (define-key Info-mode-map "3" 'Info-nth-menu-item)
1863 (define-key Info-mode-map "4" 'Info-nth-menu-item)
1864 (define-key Info-mode-map "5" 'Info-nth-menu-item)
1865 (define-key Info-mode-map "6" 'Info-nth-menu-item)
1866 (define-key Info-mode-map "7" 'Info-nth-menu-item)
1867 (define-key Info-mode-map "8" 'Info-nth-menu-item)
1868 (define-key Info-mode-map "9" 'Info-nth-menu-item)
1869 (define-key Info-mode-map "0" 'undefined)
1870 (define-key Info-mode-map "?" 'Info-summary)
1871 (define-key Info-mode-map "]" 'Info-forward-node)
1872 (define-key Info-mode-map "[" 'Info-backward-node)
1873 (define-key Info-mode-map "<" 'Info-top-node)
1874 (define-key Info-mode-map ">" 'Info-final-node)
1875 (define-key Info-mode-map "b" 'beginning-of-buffer)
1876 (define-key Info-mode-map "d" 'Info-directory)
1877 (define-key Info-mode-map "e" 'Info-edit)
1878 (define-key Info-mode-map "f" 'Info-follow-reference)
1879 (define-key Info-mode-map "g" 'Info-goto-node)
1880 (define-key Info-mode-map "h" 'Info-help)
1881 (define-key Info-mode-map "i" 'Info-index)
1882 (define-key Info-mode-map "l" 'Info-last)
1883 (define-key Info-mode-map "m" 'Info-menu)
1884 (define-key Info-mode-map "n" 'Info-next)
1885 (define-key Info-mode-map "p" 'Info-prev)
1886 (define-key Info-mode-map "q" 'Info-exit)
1887 (define-key Info-mode-map "s" 'Info-search)
1888 ;; For consistency with Rmail.
1889 (define-key Info-mode-map "\M-s" 'Info-search)
1890 (define-key Info-mode-map "\M-n" 'clone-buffer)
1891 (define-key Info-mode-map "t" 'Info-top-node)
1892 (define-key Info-mode-map "u" 'Info-up)
1893 (define-key Info-mode-map "," 'Info-index-next)
1894 (define-key Info-mode-map "\177" 'Info-scroll-down)
1895 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
1896 )
1897
1898 (defun Info-check-pointer (item)
1899 ;; Non-nil if ITEM is present in this node.
1900 (condition-case nil
1901 (Info-extract-pointer item)
1902 (error nil)))
1903
1904 (easy-menu-define Info-mode-menu Info-mode-map
1905 "Menu for info files."
1906 '("Info"
1907 ["Up" Info-up (Info-check-pointer "up")]
1908 ["Next" Info-next (Info-check-pointer "next")]
1909 ["Previous" Info-prev (Info-check-pointer "prev[ious]*")]
1910 ("Menu item" ["You should never see this" report-emacs-bug t])
1911 ("Reference" ["You should never see this" report-emacs-bug t])
1912 ["Search..." Info-search t]
1913 ["Goto node..." Info-goto-node t]
1914 ["Last" Info-last Info-history]
1915 ["Exit" Info-exit t]))
1916
1917 (defvar Info-menu-last-node nil)
1918 ;; Last node the menu was created for.
1919 ;; Value is a list, (FILE-NAME NODE-NAME).
1920
1921 (defun Info-menu-update ()
1922 ;; Update the Info menu for the current node.
1923 (condition-case nil
1924 (if (or (not (eq major-mode 'Info-mode))
1925 (equal (list Info-current-file Info-current-node)
1926 Info-menu-last-node))
1927 ()
1928 ;; Update menu menu.
1929 (let* ((Info-complete-menu-buffer (current-buffer))
1930 (items (nreverse (condition-case nil
1931 (Info-complete-menu-item
1932 "" (lambda (e) t) t)
1933 (error nil))))
1934 entries current
1935 (number 0))
1936 (while (and items (< number 9))
1937 (setq current (car items)
1938 items (cdr items)
1939 number (1+ number))
1940 (setq entries (cons `[,current
1941 (Info-menu ,current)
1942 :keys ,(format "%d" number)]
1943 entries)))
1944 (if items
1945 (setq entries (cons ["Other..." Info-menu t] entries)))
1946 (or entries
1947 (setq entries (list ["No menu" nil nil])))
1948 (easy-menu-change '("Info") "Menu item" (nreverse entries)))
1949 ;; Update reference menu. Code stolen from `Info-follow-reference'.
1950 (let ((items nil)
1951 str i entries current
1952 (number 0)
1953 (case-fold-search t))
1954 (save-excursion
1955 (goto-char (point-min))
1956 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1957 (setq str (buffer-substring
1958 (match-beginning 1)
1959 (1- (point))))
1960 (setq i 0)
1961 (while (setq i (string-match "[ \n\t]+" str i))
1962 (setq str (concat (substring str 0 i) " "
1963 (substring str (match-end 0))))
1964 (setq i (1+ i)))
1965 (setq items
1966 (cons str items))))
1967 (while (and items (< number 9))
1968 (setq current (car items)
1969 items (cdr items)
1970 number (1+ number))
1971 (setq entries (cons `[,current
1972 (Info-follow-reference ,current)
1973 t]
1974 entries)))
1975 (if items
1976 (setq entries (cons ["Other..." Info-follow-reference t]
1977 entries)))
1978 (or entries
1979 (setq entries (list ["No references" nil nil])))
1980 (easy-menu-change '("Info") "Reference" (nreverse entries)))
1981 ;; Update last seen node.
1982 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
1983 ;; Try to avoid entering infinite beep mode in case of errors.
1984 (error (ding))))
1985
1986 \f
1987 ;; Info mode is suitable only for specially formatted data.
1988 (put 'info-mode 'mode-class 'special)
1989
1990 (defun Info-mode ()
1991 "\\<Info-mode-map>
1992 Info mode provides commands for browsing through the Info documentation tree.
1993 Documentation in Info is divided into \"nodes\", each of which discusses
1994 one topic and contains references to other nodes which discuss related
1995 topics. Info has commands to follow the references and show you other nodes.
1996
1997 \\[Info-help] Invoke the Info tutorial.
1998 \\[Info-exit] Quit Info: reselect previously selected buffer.
1999
2000 Selecting other nodes:
2001 \\[Info-mouse-follow-nearest-node]
2002 Follow a node reference you click on.
2003 This works with menu items, cross references, and
2004 the \"next\", \"previous\" and \"up\", depending on where you click.
2005 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2006 \\[Info-next] Move to the \"next\" node of this node.
2007 \\[Info-prev] Move to the \"previous\" node of this node.
2008 \\[Info-up] Move \"up\" from this node.
2009 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2010 Picking a menu item causes another node to be selected.
2011 \\[Info-directory] Go to the Info directory node.
2012 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2013 \\[Info-last] Move to the last node you were at.
2014 \\[Info-index] Look up a topic in this file's Index and move to that node.
2015 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2016 \\[Info-top-node] Go to the Top node of this file.
2017 \\[Info-final-node] Go to the final node in this file.
2018 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2019 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2020
2021 Moving within a node:
2022 \\[Info-scroll-up] Normally, scroll forward a full screen.
2023 Once you scroll far enough in a node that its menu appears on the screen
2024 but after point, the next scroll moves into its first subnode.
2025 When after all menu items (or if their is no menu), move up to
2026 the parent node.
2027 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2028 already visible, try to go to the previous menu entry, or up if there is none.
2029 \\[beginning-of-buffer] Go to beginning of node.
2030
2031 Advanced commands:
2032 \\[Info-exit] Quit Info: reselect previously selected buffer.
2033 \\[Info-edit] Edit contents of selected node.
2034 1 Pick first item in node's menu.
2035 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2036 \\[Info-goto-node] Move to node specified by name.
2037 You may include a filename as well, as (FILENAME)NODENAME.
2038 \\[universal-argument] \\[info] Move to new Info file with completion.
2039 \\[Info-search] Search through this Info file for specified regexp,
2040 and select the node in which the next occurrence is found.
2041 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2042 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2043 (kill-all-local-variables)
2044 (setq major-mode 'Info-mode)
2045 (setq mode-name "Info")
2046 (setq tab-width 8)
2047 (use-local-map Info-mode-map)
2048 (make-local-hook 'activate-menubar-hook)
2049 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
2050 (set-syntax-table text-mode-syntax-table)
2051 (setq local-abbrev-table text-mode-abbrev-table)
2052 (setq case-fold-search t)
2053 (setq buffer-read-only t)
2054 (make-local-variable 'Info-current-file)
2055 (make-local-variable 'Info-current-subfile)
2056 (make-local-variable 'Info-current-node)
2057 (make-local-variable 'Info-tag-table-marker)
2058 (setq Info-tag-table-marker (make-marker))
2059 (make-local-variable 'Info-tag-table-buffer)
2060 (setq Info-tag-table-buffer nil)
2061 (make-local-variable 'Info-history)
2062 (make-local-variable 'Info-index-alternatives)
2063 ;; This is for the sake of the invisible text we use handling titles.
2064 (make-local-variable 'line-move-ignore-invisible)
2065 (setq line-move-ignore-invisible t)
2066 (add-hook (make-local-hook 'clone-buffer-hook) 'Info-clone-buffer-hook nil t)
2067 (Info-set-mode-line)
2068 (run-hooks 'Info-mode-hook))
2069
2070 (defun Info-clone-buffer-hook ()
2071 (when (bufferp Info-tag-table-buffer)
2072 (setq Info-tag-table-buffer
2073 (with-current-buffer Info-tag-table-buffer (clone-buffer)))
2074 (let ((m Info-tag-table-marker))
2075 (when (and (markerp m) (marker-position m))
2076 (setq Info-tag-table-marker
2077 (with-current-buffer Info-tag-table-buffer
2078 (copy-marker (marker-position m))))))))
2079
2080 (defvar Info-edit-map nil
2081 "Local keymap used within `e' command of Info.")
2082 (if Info-edit-map
2083 nil
2084 (setq Info-edit-map (nconc (make-sparse-keymap) text-mode-map))
2085 (define-key Info-edit-map "\C-c\C-c" 'Info-cease-edit))
2086
2087 ;; Info-edit mode is suitable only for specially formatted data.
2088 (put 'info-edit-mode 'mode-class 'special)
2089
2090 (defun Info-edit-mode ()
2091 "Major mode for editing the contents of an Info node.
2092 Like text mode with the addition of `Info-cease-edit'
2093 which returns to Info mode for browsing.
2094 \\{Info-edit-map}"
2095 (use-local-map Info-edit-map)
2096 (setq major-mode 'Info-edit-mode)
2097 (setq mode-name "Info Edit")
2098 (kill-local-variable 'mode-line-buffer-identification)
2099 (setq buffer-read-only nil)
2100 (force-mode-line-update)
2101 (buffer-enable-undo (current-buffer))
2102 (run-hooks 'Info-edit-mode-hook))
2103
2104 (defun Info-edit ()
2105 "Edit the contents of this Info node.
2106 Allowed only if variable `Info-enable-edit' is non-nil."
2107 (interactive)
2108 (or Info-enable-edit
2109 (error "Editing info nodes is not enabled"))
2110 (Info-edit-mode)
2111 (message "%s" (substitute-command-keys
2112 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2113
2114 (defun Info-cease-edit ()
2115 "Finish editing Info node; switch back to Info proper."
2116 (interactive)
2117 ;; Do this first, so nothing has changed if user C-g's at query.
2118 (and (buffer-modified-p)
2119 (y-or-n-p "Save the file? ")
2120 (save-buffer))
2121 (use-local-map Info-mode-map)
2122 (setq major-mode 'Info-mode)
2123 (setq mode-name "Info")
2124 (Info-set-mode-line)
2125 (setq buffer-read-only t)
2126 (force-mode-line-update)
2127 (and (marker-position Info-tag-table-marker)
2128 (buffer-modified-p)
2129 (message "Tags may have changed. Use Info-tagify if necessary")))
2130 \f
2131 (defvar Info-file-list-for-emacs
2132 '("ediff" "forms" "gnus" "info" ("mh" . "mh-e") "sc" "message"
2133 ("dired" . "dired-x") ("c" . "ccmode") "viper")
2134 "List of Info files that describe Emacs commands.
2135 An element can be a file name, or a list of the form (PREFIX . FILE)
2136 where PREFIX is a name prefix and FILE is the file to look in.
2137 If the element is just a file name, the file name also serves as the prefix.")
2138
2139 (defun Info-find-emacs-command-nodes (command)
2140 "Return a list of locations documenting COMMAND.
2141 The `info-file' property of COMMAND says which Info manual to search.
2142 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2143 defines heuristics for which Info manual to try.
2144 The locations are of the format used in Info-history, i.e.
2145 \(FILENAME NODENAME BUFFERPOS\)."
2146 (let ((where '())
2147 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
2148 ":\\s *\\(.*\\)\\.$"))
2149 (info-file "emacs")) ;default
2150 ;; Determine which info file this command is documented in.
2151 (if (get command 'info-file)
2152 (setq info-file (get command 'info-file))
2153 ;; If it doesn't say explicitly, test its name against
2154 ;; various prefixes that we know.
2155 (let ((file-list Info-file-list-for-emacs))
2156 (while file-list
2157 (let* ((elt (car file-list))
2158 (name (if (consp elt)
2159 (car elt)
2160 elt))
2161 (file (if (consp elt) (cdr elt) elt))
2162 (regexp (concat "\\`" (regexp-quote name)
2163 "\\(\\'\\|-\\)")))
2164 (if (string-match regexp (symbol-name command))
2165 (setq info-file file file-list nil))
2166 (setq file-list (cdr file-list))))))
2167 (save-excursion
2168 (condition-case nil
2169 (Info-find-node info-file "Command Index")
2170 ;; Some manuals may not have a separate Command Index node,
2171 ;; so try just Index instead.
2172 (error
2173 (Info-find-node info-file "Index")))
2174 ;; Take the index node off the Info history.
2175 (setq Info-history (cdr Info-history))
2176 (goto-char (point-max))
2177 (while (re-search-backward cmd-desc nil t)
2178 (setq where (cons (list Info-current-file
2179 (buffer-substring
2180 (match-beginning 1)
2181 (match-end 1))
2182 0)
2183 where)))
2184 where)))
2185
2186 ;;;###autoload
2187 (defun Info-goto-emacs-command-node (command)
2188 "Go to the Info node in the Emacs manual for command COMMAND.
2189 The command is found by looking up in Emacs manual's Command Index
2190 or in another manual found via COMMAND's `info-file' property or
2191 the variable `Info-file-list-for-emacs'."
2192 (interactive "CFind documentation for command: ")
2193 (or (commandp command)
2194 (signal 'wrong-type-argument (list 'commandp command)))
2195 (let ((where (Info-find-emacs-command-nodes command)))
2196 (if where
2197 (let ((num-matches (length where)))
2198 ;; Get Info running, and pop to it in another window.
2199 (save-window-excursion
2200 (info))
2201 ;; FIXME It would be cool if this could use a buffer other
2202 ;; than *info*.
2203 (pop-to-buffer "*info*")
2204 (Info-find-node (car (car where))
2205 (car (cdr (car where))))
2206 (if (> num-matches 1)
2207 (progn
2208 ;; Info-find-node already pushed (car where) onto
2209 ;; Info-history. Put the other nodes that were found on
2210 ;; the history.
2211 (setq Info-history (nconc (cdr where) Info-history))
2212 (message "Found %d other entr%s. Use %s to see %s."
2213 (1- num-matches)
2214 (if (> num-matches 2) "ies" "y")
2215 (substitute-command-keys "\\[Info-last]")
2216 (if (> num-matches 2) "them" "it")))))
2217 (error "Couldn't find documentation for %s" command))))
2218
2219 ;;;###autoload
2220 (defun Info-goto-emacs-key-command-node (key)
2221 "Go to the Info node in the Emacs manual the command bound to KEY, a string.
2222 Interactively, if the binding is execute-extended-command, a command is read.
2223 The command is found by looking up in Emacs manual's Command Index
2224 or in another manual found via COMMAND's `info-file' property or
2225 the variable `Info-file-list-for-emacs'."
2226 (interactive "kFind documentation for key:")
2227 (let ((command (key-binding key)))
2228 (cond ((null command)
2229 (message "%s is undefined" (key-description key)))
2230 ((and (interactive-p)
2231 (eq command 'execute-extended-command))
2232 (Info-goto-emacs-command-node
2233 (read-command "Find documentation for command: ")))
2234 (t
2235 (Info-goto-emacs-command-node command)))))
2236 \f
2237 (defcustom Info-title-face-alist
2238 '((?* bold underline)
2239 (?= bold-italic underline)
2240 (?- italic underline))
2241 "*Alist of face or list of faces to use for pseudo-underlined titles.
2242 The alist key is the character the title is underlined with (?*, ?= or ?-)."
2243 :type '(repeat (list character face face))
2244 :group 'info)
2245
2246 (defun Info-fontify-node ()
2247 (save-excursion
2248 (let ((buffer-read-only nil)
2249 (case-fold-search t))
2250 (goto-char (point-min))
2251 (when (looking-at "^File: [^,: \t]+,?[ \t]+")
2252 (goto-char (match-end 0))
2253 (while
2254 (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2255 (goto-char (match-end 0))
2256 (if (save-excursion
2257 (goto-char (match-beginning 1))
2258 (save-match-data (looking-at "Node:")))
2259 (put-text-property (match-beginning 2) (match-end 2)
2260 'face 'info-node)
2261 (put-text-property (match-beginning 2) (match-end 2)
2262 'face 'info-xref)
2263 (put-text-property (match-beginning 2) (match-end 2)
2264 'mouse-face 'highlight))))
2265 (goto-char (point-min))
2266 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\)$"
2267 nil t)
2268 (put-text-property (match-beginning 1) (match-end 1)
2269 'face
2270 (cdr (assq (preceding-char) Info-title-face-alist)))
2271 ;; This is a serious problem for trying to handle multiple
2272 ;; frame types at once. We want this text to be invisible
2273 ;; on frames that can display the font above.
2274 (if (memq (framep (selected-frame)) '(x pc w32))
2275 (put-text-property (match-end 1) (match-end 2)
2276 'invisible t)))
2277 (goto-char (point-min))
2278 (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
2279 (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
2280 nil
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 (goto-char (point-min))
2286 (if (and (search-forward "\n* Menu:" nil t)
2287 (not (string-match "\\<Index\\>" Info-current-node))
2288 ;; Don't take time to annotate huge menus
2289 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2290 (let ((n 0))
2291 (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
2292 (setq n (1+ n))
2293 (if (memq n '(5 9)) ; visual aids to help with 1-9 keys
2294 (put-text-property (match-beginning 0)
2295 (1+ (match-beginning 0))
2296 'face 'info-menu-5))
2297 (put-text-property (match-beginning 1) (match-end 1)
2298 'face 'info-xref)
2299 (put-text-property (match-beginning 1) (match-end 1)
2300 'mouse-face 'highlight))))
2301 (set-buffer-modified-p nil))))
2302 \f
2303
2304 ;; When an Info buffer is killed, make sure the associated tags buffer
2305 ;; is killed too.
2306 (defun Info-kill-buffer ()
2307 (and (eq major-mode 'Info-mode)
2308 Info-tag-table-buffer
2309 (kill-buffer Info-tag-table-buffer)))
2310
2311 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2312
2313 ;;; Speedbar support:
2314 ;; These functions permit speedbar to display the "tags" in the
2315 ;; current info node.
2316 (eval-when-compile (require 'speedbar))
2317
2318 (defvar Info-speedbar-key-map nil
2319 "Keymap used when in the info display mode.")
2320
2321 (defun Info-install-speedbar-variables ()
2322 "Install those variables used by speedbar to enhance Info."
2323 (if Info-speedbar-key-map
2324 nil
2325 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2326
2327 ;; Basic tree features
2328 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2329 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2330 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2331 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2332 )
2333
2334 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2335 Info-speedbar-key-map
2336 Info-speedbar-hierarchy-buttons)))
2337
2338 (defvar Info-speedbar-menu-items
2339 '(["Browse Node" speedbar-edit-line t]
2340 ["Expand Node" speedbar-expand-line
2341 (save-excursion (beginning-of-line)
2342 (looking-at "[0-9]+: *.\\+. "))]
2343 ["Contract Node" speedbar-contract-line
2344 (save-excursion (beginning-of-line)
2345 (looking-at "[0-9]+: *.-. "))]
2346 )
2347 "Additional menu-items to add to speedbar frame.")
2348
2349 ;; Make sure our special speedbar major mode is loaded
2350 (if (featurep 'speedbar)
2351 (Info-install-speedbar-variables)
2352 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2353
2354 ;;; Info hierarchy display method
2355 ;;;###autoload
2356 (defun Info-speedbar-browser ()
2357 "Initialize speedbar to display an info node browser.
2358 This will add a speedbar major display mode."
2359 (interactive)
2360 (require 'speedbar)
2361 ;; Make sure that speedbar is active
2362 (speedbar-frame-mode 1)
2363 ;; Now, throw us into Info mode on speedbar.
2364 (speedbar-change-initial-expansion-list "Info")
2365 )
2366
2367 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2368 "Display an Info directory hierarchy in speedbar.
2369 DIRECTORY is the current directory in the attached frame.
2370 DEPTH is the current indentation depth.
2371 NODE is an optional argument that is used to represent the
2372 specific node to expand."
2373 (if (and (not node)
2374 (save-excursion (goto-char (point-min))
2375 (let ((case-fold-search t))
2376 (looking-at "Info Nodes:"))))
2377 ;; Update our "current node" maybe?
2378 nil
2379 ;; We cannot use the generic list code, that depends on all leaves
2380 ;; being known at creation time.
2381 (if (not node)
2382 (speedbar-with-writable (insert "Info Nodes:\n")))
2383 (let ((completions nil)
2384 (cf (selected-frame)))
2385 (select-frame speedbar-attached-frame)
2386 (save-window-excursion
2387 (setq completions
2388 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
2389 (select-frame cf)
2390 (if completions
2391 (speedbar-with-writable
2392 (while completions
2393 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2394 (cdr (car completions))
2395 (car (car completions))
2396 'Info-speedbar-goto-node
2397 (cdr (car completions))
2398 'info-xref depth)
2399 (setq completions (cdr completions)))
2400 t)
2401 nil))))
2402
2403 (defun Info-speedbar-goto-node (text node indent)
2404 "When user clicks on TEXT, goto an info NODE.
2405 The INDENT level is ignored."
2406 (select-frame speedbar-attached-frame)
2407 (let* ((buff (or (get-buffer "*info*")
2408 (progn (info) (get-buffer "*info*"))))
2409 (bwin (get-buffer-window buff 0)))
2410 (if bwin
2411 (progn
2412 (select-window bwin)
2413 (raise-frame (window-frame bwin)))
2414 (if speedbar-power-click
2415 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2416 (select-frame speedbar-attached-frame)
2417 (switch-to-buffer buff)))
2418 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
2419 (file (match-string 1 node))
2420 (node (match-string 2 node)))
2421 (Info-find-node file node)
2422 ;; If we do a find-node, and we were in info mode, restore
2423 ;; the old default method. Once we are in info mode, it makes
2424 ;; sense to return to whatever method the user was using before.
2425 (if (string= speedbar-initial-expansion-list-name "Info")
2426 (speedbar-change-initial-expansion-list
2427 speedbar-previously-used-expansion-list-name)))))
2428
2429 (defun Info-speedbar-expand-node (text token indent)
2430 "Expand the node the user clicked on.
2431 TEXT is the text of the button we clicked on, a + or - item.
2432 TOKEN is data related to this node (NAME . FILE).
2433 INDENT is the current indentation depth."
2434 (cond ((string-match "+" text) ;we have to expand this file
2435 (speedbar-change-expand-button-char ?-)
2436 (if (speedbar-with-writable
2437 (save-excursion
2438 (end-of-line) (forward-char 1)
2439 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
2440 (speedbar-change-expand-button-char ?-)
2441 (speedbar-change-expand-button-char ??)))
2442 ((string-match "-" text) ;we have to contract this node
2443 (speedbar-change-expand-button-char ?+)
2444 (speedbar-delete-subblock indent))
2445 (t (error "Ooops... not sure what to do")))
2446 (speedbar-center-buffer-smartly))
2447
2448 (defun Info-speedbar-fetch-file-nodes (nodespec)
2449 "Fetch the subnodes from the info NODESPEC.
2450 NODESPEC is a string of the form: (file)node.
2451 Optional THISFILE represends the filename of"
2452 (save-excursion
2453 ;; Set up a buffer we can use to fake-out Info.
2454 (set-buffer (get-buffer-create "*info-browse-tmp*"))
2455 (if (not (equal major-mode 'Info-mode))
2456 (Info-mode))
2457 ;; Get the node into this buffer
2458 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
2459 (file (match-string 1 nodespec))
2460 (node (match-string 2 nodespec)))
2461 (Info-find-node file node))
2462 ;; Scan the created buffer
2463 (goto-char (point-min))
2464 (let ((completions nil)
2465 (case-fold-search t)
2466 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
2467 (match-string 1 nodespec))))
2468 ;; Always skip the first one...
2469 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2470 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
2471 (let ((name (match-string 1)))
2472 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
2473 (setq name (cons name (match-string 1)))
2474 (if (looking-at " *\\(([^)]+)\\)\\.")
2475 (setq name (cons name (concat (match-string 1) "Top")))
2476 (if (looking-at " \\([^.]+\\).")
2477 (setq name
2478 (cons name (concat "(" thisfile ")" (match-string 1))))
2479 (setq name (cons name (concat "(" thisfile ")" name))))))
2480 (setq completions (cons name completions))))
2481 (nreverse completions))))
2482
2483 ;;; Info mode node listing
2484 (defun Info-speedbar-buttons (buffer)
2485 "Create a speedbar display to help navigation in an Info file.
2486 BUFFER is the buffer speedbar is requesting buttons for."
2487 (if (save-excursion (goto-char (point-min))
2488 (let ((case-fold-search t))
2489 (not (looking-at "Info Nodes:"))))
2490 (erase-buffer))
2491 (Info-speedbar-hierarchy-buttons nil 0)
2492 )
2493
2494 (provide 'info)
2495
2496 ;;; info.el ends here