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