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