]> code.delx.au - gnu-emacs/blob - lisp/info.el
(Info-default-dirs): New fun extracted from Info-initialize.
[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, 2001,
4 ;; 2002, 2003
5 ;; Free Software Foundation, Inc.
6
7 ;; Maintainer: FSF
8 ;; Keywords: help
9
10 ;; This file is part of GNU Emacs.
11
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
26
27 ;;; Commentary:
28
29 ;; Note that nowadays we expect info files to be made using makeinfo.
30 ;; In particular we make these assumptions:
31 ;; - a menu item MAY contain colons but not colon-space ": "
32 ;; - a menu item ending with ": " (but not ":: ") is an index entry
33 ;; - a node name MAY NOT contain a colon
34 ;; This distinction is to support indexing of computer programming
35 ;; language terms that may contain ":" but not ": ".
36
37 ;;; Code:
38
39 (eval-when-compile (require 'jka-compr))
40
41 (defgroup info nil
42 "Info subsystem"
43 :group 'help
44 :group 'docs)
45
46
47 (defvar Info-history nil
48 "List of info nodes user has visited.
49 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
50
51 (defcustom Info-enable-edit nil
52 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
53 This is convenient if you want to write info files by hand.
54 However, we recommend that you not do this.
55 It is better to write a Texinfo file and generate the Info file from that,
56 because that gives you a printed manual as well."
57 :type 'boolean
58 :group 'info)
59
60 (defvar Info-enable-active-nodes nil
61 "Non-nil allows Info to execute Lisp code associated with nodes.
62 The Lisp code is executed when the node is selected.")
63 (put 'Info-enable-active-nodes 'risky-local-variable t)
64
65 (defface info-node
66 '((((class color) (background light)) (:foreground "brown" :weight bold :slant italic))
67 (((class color) (background dark)) (:foreground "white" :weight bold :slant italic))
68 (t (:weight bold :slant italic)))
69 "Face for Info node names."
70 :group 'info)
71
72 (defface info-menu-5
73 '((((class color)) (:foreground "red1"))
74 (t (:underline t)))
75 "Face for every third `*' in an Info menu."
76 :group 'info)
77
78 (defface info-xref
79 '((((class color) (background light)) (:foreground "magenta4" :weight bold))
80 (((class color) (background dark)) (:foreground "cyan" :weight bold))
81 (t (:weight bold)))
82 "Face for Info cross-references."
83 :group 'info)
84
85 (defcustom Info-fontify-maximum-menu-size 100000
86 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
87 :type 'integer
88 :group 'info)
89
90 (defcustom Info-use-header-line t
91 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
92 A header-line does not scroll with the rest of the buffer."
93 :type 'boolean
94 :group 'info)
95
96 (defface info-header-xref
97 '((t (:inherit info-xref)))
98 "Face for Info cross-references in a node header."
99 :group 'info)
100
101 (defface info-header-node
102 '((t (:inherit info-node)))
103 "Face for Info nodes in a node header."
104 :group 'info)
105
106 (defvar Info-directory-list nil
107 "List of directories to search for Info documentation files.
108 If nil, meaning not yet initialized, Info uses the environment
109 variable INFOPATH to initialize it, or `Info-default-directory-list'
110 if there is no INFOPATH variable in the environment.
111
112 When `Info-directory-list' is initialized from the value of
113 `Info-default-directory-list', and Emacs is installed in one of the
114 standard directories, the directory of Info files that come with Emacs
115 is put last (so that local Info files override standard ones).
116
117 When `Info-directory-list' is initialized from the value of
118 `Info-default-directory-list', and Emacs is not installed in one
119 of the standard directories, the first element of the resulting
120 list is the directory where Emacs installs the Info files that
121 come with it. This is so that Emacs's own manual, which suits the
122 version of Emacs you are using, will always be found first. This
123 is useful when you install an experimental version of Emacs without
124 removing the standard installation.
125
126 If you want to override the order of directories in
127 `Info-default-directory-list', set INFOPATH in the environment.
128
129 If you run the Emacs executable from the `src' directory in the Emacs
130 source tree, and INFOPATH is not defined, the `info' directory in the
131 source tree is used as the first element of `Info-directory-list', in
132 place of the installation Info directory. This is useful when you run
133 a version of Emacs without installing it.")
134
135 (defcustom Info-additional-directory-list nil
136 "List of additional directories to search for Info documentation files.
137 These directories are searched after those in `Info-directory-list'."
138 :type '(repeat directory)
139 :group 'info)
140
141 (defcustom Info-scroll-prefer-subnodes t
142 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
143 If this is non-nil, and you scroll far enough in a node that its menu
144 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
145 moves to a subnode indicated by the following menu item. This means
146 that you visit a subnode before getting to the end of the menu.
147
148 Setting this option to nil results in behavior similar to the stand-alone
149 Info reader program, which visits the first subnode from the menu only
150 when you hit the end of the current node."
151 :type 'boolean
152 :group 'info)
153
154 (defcustom Info-hide-note-references t
155 "*If non-nil, hide the tag and section reference in *note and * menu items.
156 Also replaces the \"*note\" text with \"see\".
157 If value is non-nil but not t, the reference section is still shown."
158 :version "21.4"
159 :type '(choice (const :tag "No reformatting" nil)
160 (const :tag "Replace tag and hide reference" t)
161 (other :tag "Replace only tag" tag))
162 :group 'info)
163
164 (defcustom Info-mode-hook '(turn-on-font-lock)
165 "Hooks run when `info-mode' is called."
166 :type 'hook
167 :group 'info)
168
169 (defvar Info-current-file nil
170 "Info file that Info is now looking at, or nil.
171 This is the name that was specified in Info, not the actual file name.
172 It doesn't contain directory names or file name extensions added by Info.
173 Can also be t when using `Info-on-current-buffer'.")
174
175 (defvar Info-current-subfile nil
176 "Info subfile that is actually in the *info* buffer now.
177 nil if current info file is not split into subfiles.")
178
179 (defvar Info-current-node nil
180 "Name of node that Info is now looking at, or nil.")
181
182 (defvar Info-tag-table-marker nil
183 "Marker pointing at beginning of current Info file's tag table.
184 Marker points nowhere if file has no tag table.")
185
186 (defvar Info-tag-table-buffer nil
187 "Buffer used for indirect tag tables.")
188
189 (defvar Info-current-file-completions nil
190 "Cached completion list for current Info file.")
191
192 (defvar Info-index-alternatives nil
193 "List of possible matches for last `Info-index' command.")
194
195 (defvar Info-standalone nil
196 "Non-nil if Emacs was started solely as an Info browser.")
197 \f
198 (defvar Info-suffix-list
199 ;; The MS-DOS list should work both when long file names are
200 ;; supported (Windows 9X), and when only 8+3 file names are available.
201 (if (eq system-type 'ms-dos)
202 '( (".gz" . "gunzip")
203 (".z" . "gunzip")
204 (".bz2" . ("bzip2" "-dc"))
205 (".inz" . "gunzip")
206 (".igz" . "gunzip")
207 (".info.Z" . "gunzip")
208 (".info.gz" . "gunzip")
209 ("-info.Z" . "gunzip")
210 ("-info.gz" . "gunzip")
211 ("/index.gz". "gunzip")
212 ("/index.z" . "gunzip")
213 (".inf" . nil)
214 (".info" . nil)
215 ("-info" . nil)
216 ("/index" . nil)
217 ("" . nil))
218 '( (".info.Z". "uncompress")
219 (".info.Y". "unyabba")
220 (".info.gz". "gunzip")
221 (".info.z". "gunzip")
222 (".info.bz2" . ("bzip2" "-dc"))
223 (".info". nil)
224 ("-info.Z". "uncompress")
225 ("-info.Y". "unyabba")
226 ("-info.gz". "gunzip")
227 ("-info.bz2" . ("bzip2" "-dc"))
228 ("-info.z". "gunzip")
229 ("-info". nil)
230 ("/index.Z". "uncompress")
231 ("/index.Y". "unyabba")
232 ("/index.gz". "gunzip")
233 ("/index.z". "gunzip")
234 ("/index.bz2". ("bzip2" "-dc"))
235 ("/index". nil)
236 (".Z". "uncompress")
237 (".Y". "unyabba")
238 (".gz". "gunzip")
239 (".z". "gunzip")
240 (".bz2" . ("bzip2" "-dc"))
241 ("". nil)))
242 "List of file name suffixes and associated decoding commands.
243 Each entry should be (SUFFIX . STRING); the file is given to
244 the command as standard input.
245
246 STRING may be a list of strings. In that case, the first element is
247 the command name, and the rest are arguments to that command.
248
249 If STRING is nil, no decoding is done.
250 Because the SUFFIXes are tried in order, the empty string should
251 be last in the list.")
252
253 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
254 ;; First, on MS-DOS with no long file names support, delete some of
255 ;; the extension in FILENAME to make room.
256 (defun info-insert-file-contents-1 (filename suffix lfn)
257 (if lfn ; long file names are supported
258 (concat filename suffix)
259 (let* ((sans-exts (file-name-sans-extension filename))
260 ;; How long is the extension in FILENAME (not counting the dot).
261 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
262 ext-left)
263 ;; SUFFIX starts with a dot. If FILENAME already has one,
264 ;; get rid of the one in SUFFIX (unless suffix is empty).
265 (or (and (<= ext-len 0)
266 (not (eq (aref filename (1- (length filename))) ?.)))
267 (= (length suffix) 0)
268 (setq suffix (substring suffix 1)))
269 ;; How many chars of that extension should we keep?
270 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
271 ;; Get rid of the rest of the extension, and add SUFFIX.
272 (concat (substring filename 0 (- (length filename)
273 (- ext-len ext-left)))
274 suffix))))
275
276 (defun info-file-exists-p (filename)
277 (and (file-exists-p filename)
278 (not (file-directory-p filename))))
279
280 (defun info-insert-file-contents (filename &optional visit)
281 "Insert the contents of an info file in the current buffer.
282 Do the right thing if the file has been compressed or zipped."
283 (let* ((tail Info-suffix-list)
284 (lfn (if (fboundp 'msdos-long-file-names)
285 (msdos-long-file-names)
286 t))
287 (check-short (and (fboundp 'msdos-long-file-names)
288 lfn))
289 fullname decoder done)
290 (if (info-file-exists-p filename)
291 ;; FILENAME exists--see if that name contains a suffix.
292 ;; If so, set DECODE accordingly.
293 (progn
294 (while (and tail
295 (not (string-match
296 (concat (regexp-quote (car (car tail))) "$")
297 filename)))
298 (setq tail (cdr tail)))
299 (setq fullname filename
300 decoder (cdr (car tail))))
301 ;; Try adding suffixes to FILENAME and see if we can find something.
302 (while (and tail (not done))
303 (setq fullname (info-insert-file-contents-1 filename
304 (car (car tail)) lfn))
305 (if (info-file-exists-p fullname)
306 (setq done t
307 ;; If we found a file with a suffix, set DECODER
308 ;; according to the suffix.
309 decoder (cdr (car tail)))
310 ;; When the MS-DOS port runs on Windows, we need to check
311 ;; the short variant of a long file name as well.
312 (when check-short
313 (setq fullname (info-insert-file-contents-1 filename
314 (car (car tail)) nil))
315 (if (info-file-exists-p fullname)
316 (setq done t
317 decoder (cdr (car tail))))))
318 (setq tail (cdr tail)))
319 (or tail
320 (error "Can't find %s or any compressed version of it" filename)))
321 ;; check for conflict with jka-compr
322 (if (and (featurep 'jka-compr)
323 (jka-compr-installed-p)
324 (jka-compr-get-compression-info fullname))
325 (setq decoder nil))
326 (if decoder
327 (progn
328 (insert-file-contents-literally fullname visit)
329 (let ((buffer-read-only nil)
330 (coding-system-for-write 'no-conversion)
331 (default-directory (or (file-name-directory fullname)
332 default-directory)))
333 (or (consp decoder)
334 (setq decoder (list decoder)))
335 (apply 'call-process-region (point-min) (point-max)
336 (car decoder) t t nil (cdr decoder))))
337 (insert-file-contents fullname visit))))
338 \f
339 (defun Info-default-dirs ()
340 (let ((source (expand-file-name "info/" source-directory))
341 (sibling (if installation-directory
342 (expand-file-name "info/" installation-directory)
343 (if invocation-directory
344 (let ((infodir (expand-file-name
345 "../info/"
346 invocation-directory)))
347 (if (file-exists-p infodir)
348 infodir
349 (setq infodir (expand-file-name
350 "../../../info/"
351 invocation-directory))
352 (and (file-exists-p infodir)
353 infodir))))))
354 alternative)
355 (setq alternative
356 (if (and sibling (file-exists-p sibling))
357 ;; Uninstalled, Emacs builddir != srcdir.
358 sibling
359 ;; Uninstalled, builddir == srcdir
360 source))
361 (if (or (member alternative Info-default-directory-list)
362 ;; On DOS/NT, we use movable executables always,
363 ;; and we must always find the Info dir at run time.
364 (if (memq system-type '(ms-dos windows-nt))
365 nil
366 ;; Use invocation-directory for Info
367 ;; only if we used it for exec-directory also.
368 (not (string= exec-directory
369 (expand-file-name "lib-src/"
370 installation-directory))))
371 (not (file-exists-p alternative)))
372 Info-default-directory-list
373 ;; `alternative' contains the Info files that came with this
374 ;; version, so we should look there first. `Info-insert-dir'
375 ;; currently expects to find `alternative' first on the list.
376 (cons alternative
377 (reverse (cdr (reverse Info-default-directory-list)))))))
378
379 (defun info-initialize ()
380 "Initialize `Info-directory-list', if that hasn't been done yet."
381 (unless Info-directory-list
382 (let ((path (getenv "INFOPATH")))
383 (setq Info-directory-list
384 (prune-directory-list
385 (if path
386 (if (string-match ":\\'" path)
387 (append (split-string (substring path 0 -1)
388 (regexp-quote path-separator))
389 (Info-default-dirs))
390 (split-string path (regexp-quote path-separator)))
391 (Info-default-dirs)))))))
392
393 ;;;###autoload
394 (defun info-other-window (&optional file)
395 "Like `info' but show the Info buffer in another window."
396 (interactive (if current-prefix-arg
397 (list (read-file-name "Info file name: " nil nil t))))
398 (let (same-window-buffer-names)
399 (info file)))
400
401 ;;;###autoload (add-hook 'same-window-buffer-names "*info*")
402
403 ;;;###autoload
404 (defun info (&optional file)
405 "Enter Info, the documentation browser.
406 Optional argument FILE specifies the file to examine;
407 the default is the top-level directory of Info.
408 Called from a program, FILE may specify an Info node of the form
409 `(FILENAME)NODENAME'.
410
411 In interactive use, a prefix argument directs this command
412 to read a file name from the minibuffer.
413
414 The search path for Info files is in the variable `Info-directory-list'.
415 The top-level Info directory is made by combining all the files named `dir'
416 in all the directories in that path."
417 (interactive (if current-prefix-arg
418 (list (read-file-name "Info file name: " nil nil t))))
419 (if file
420 (progn
421 (pop-to-buffer "*info*")
422 ;; If argument already contains parentheses, don't add another set
423 ;; since the argument will then be parsed improperly. This also
424 ;; has the added benefit of allowing node names to be included
425 ;; following the parenthesized filename.
426 (if (and (stringp file) (string-match "(.*)" file))
427 (Info-goto-node file)
428 (Info-goto-node (concat "(" file ")"))))
429 (if (get-buffer "*info*")
430 (pop-to-buffer "*info*")
431 (Info-directory))))
432
433 ;;;###autoload
434 (defun info-emacs-manual ()
435 "Display the Emacs manual in Info mode."
436 (interactive)
437 (info "emacs"))
438
439 ;;;###autoload
440 (defun info-standalone ()
441 "Run Emacs as a standalone Info reader.
442 Usage: emacs -f info-standalone [filename]
443 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
444 (setq Info-standalone t)
445 (if (and command-line-args-left
446 (not (string-match "^-" (car command-line-args-left))))
447 (condition-case err
448 (progn
449 (info (car command-line-args-left))
450 (setq command-line-args-left (cdr command-line-args-left)))
451 (error (send-string-to-terminal
452 (format "%s\n" (if (eq (car-safe err) 'error)
453 (nth 1 err) err)))
454 (save-buffers-kill-emacs)))
455 (info)))
456 \f
457 ;; See if the accessible portion of the buffer begins with a node
458 ;; delimiter, and the node header line which follows matches REGEXP.
459 ;; Typically, this test will be followed by a loop that examines the
460 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
461 ;; to have the overhead of this special test inside the loop.
462
463 ;; This function changes match-data, but supposedly the caller might
464 ;; want to use the results of re-search-backward.
465
466 ;; The return value is the value of point at the beginning of matching
467 ;; REGEXP, if the function succeeds, nil otherwise.
468 (defun Info-node-at-bob-matching (regexp)
469 (and (bobp) ; are we at beginning of buffer?
470 (looking-at "\^_") ; does it begin with node delimiter?
471 (let (beg)
472 (forward-line 1)
473 (setq beg (point))
474 (forward-line 1) ; does the line after delimiter match REGEXP?
475 (re-search-backward regexp beg t))))
476
477 (defun Info-find-node (filename nodename &optional no-going-back)
478 "Go to an info node specified as separate FILENAME and NODENAME.
479 NO-GOING-BACK is non-nil if recovering from an error in this function;
480 it says do not attempt further (recursive) error recovery."
481 (info-initialize)
482 ;; Convert filename to lower case if not found as specified.
483 ;; Expand it.
484 (if (stringp filename)
485 (let (temp temp-downcase found)
486 (setq filename (substitute-in-file-name filename))
487 (if (string= (downcase filename) "dir")
488 (setq found t)
489 (let ((dirs (if (string-match "^\\./" filename)
490 ;; If specified name starts with `./'
491 ;; then just try current directory.
492 '("./")
493 (if (file-name-absolute-p filename)
494 ;; No point in searching for an
495 ;; absolute file name
496 '(nil)
497 (if Info-additional-directory-list
498 (append Info-directory-list
499 Info-additional-directory-list)
500 Info-directory-list)))))
501 ;; Search the directory list for file FILENAME.
502 (while (and dirs (not found))
503 (setq temp (expand-file-name filename (car dirs)))
504 (setq temp-downcase
505 (expand-file-name (downcase filename) (car dirs)))
506 ;; Try several variants of specified name.
507 (let ((suffix-list Info-suffix-list)
508 (lfn (if (fboundp 'msdos-long-file-names)
509 (msdos-long-file-names)
510 t)))
511 (while (and suffix-list (not found))
512 (cond ((info-file-exists-p
513 (info-insert-file-contents-1
514 temp (car (car suffix-list)) lfn))
515 (setq found temp))
516 ((info-file-exists-p
517 (info-insert-file-contents-1
518 temp-downcase (car (car suffix-list)) lfn))
519 (setq found temp-downcase))
520 ((and (fboundp 'msdos-long-file-names)
521 lfn
522 (info-file-exists-p
523 (info-insert-file-contents-1
524 temp (car (car suffix-list)) nil)))
525 (setq found temp)))
526 (setq suffix-list (cdr suffix-list))))
527 (setq dirs (cdr dirs)))))
528 (if found
529 (setq filename found)
530 (error "Info file %s does not exist" filename))))
531 ;; Record the node we are leaving.
532 (if (and Info-current-file (not no-going-back))
533 (setq Info-history
534 (cons (list Info-current-file Info-current-node (point))
535 Info-history)))
536 ;; Go into info buffer.
537 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
538 (Info-find-node-2 filename nodename no-going-back))
539
540 (defun Info-on-current-buffer (&optional nodename)
541 "Use the `Info-mode' to browse the current info buffer.
542 If a prefix arg is provided, it queries for the NODENAME which
543 else defaults to \"Top\"."
544 (interactive
545 (list (if current-prefix-arg
546 (completing-read "Node name: " (Info-build-node-completions)
547 nil t "Top"))))
548 (unless nodename (setq nodename "Top"))
549 (info-initialize)
550 (Info-mode)
551 (set (make-local-variable 'Info-current-file) t)
552 (Info-find-node-2 nil nodename))
553
554 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
555 ;; but at least it keeps this routine (which is only for the benefit of
556 ;; makeinfo-buffer) out of the way of normal operations.
557 ;;
558 (defun Info-revert-find-node (filename nodename)
559 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
560 When *info* is already displaying FILENAME and NODENAME, the window position
561 is preserved, if possible."
562 (pop-to-buffer "*info*")
563 (let ((old-filename Info-current-file)
564 (old-nodename Info-current-node)
565 (pcolumn (current-column))
566 (pline (count-lines (point-min) (line-beginning-position)))
567 (wline (count-lines (point-min) (window-start)))
568 (old-history Info-history)
569 (new-history (and Info-current-file
570 (list Info-current-file Info-current-node (point)))))
571 (kill-buffer (current-buffer))
572 (Info-find-node filename nodename)
573 (setq Info-history old-history)
574 (if (and (equal old-filename Info-current-file)
575 (equal old-nodename Info-current-node))
576 (progn
577 ;; note goto-line is no good, we want to measure from point-min
578 (beginning-of-buffer)
579 (forward-line wline)
580 (set-window-start (selected-window) (point))
581 (beginning-of-buffer)
582 (forward-line pline)
583 (move-to-column pcolumn))
584 ;; only add to the history when coming from a different file+node
585 (if new-history
586 (setq Info-history (cons new-history Info-history))))))
587
588 (defun Info-find-in-tag-table-1 (marker regexp case-fold)
589 "Find a node in a tag table.
590 MARKER specifies the buffer and position to start searching at.
591 REGEXP is a regular expression matching nodes or references. Its first
592 group should match `Node:' or `Ref:'.
593 CASE-FOLD t means search for a case-insensitive match.
594 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
595 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
596 where the match was found, and MODE is `major-mode' of the buffer in
597 which the match was found."
598 (let ((case-fold-search case-fold)
599 found-mode guesspos found-anchor)
600 (save-excursion
601 (set-buffer (marker-buffer marker))
602 (goto-char marker)
603
604 ;; Search tag table
605 (beginning-of-line)
606 (when (re-search-forward regexp nil t)
607 (list (string-equal "Ref:" (match-string 1))
608 (+ (point-min) (read (current-buffer)))
609 major-mode)))))
610
611 (defun Info-find-in-tag-table (marker regexp)
612 "Find a node in a tag table.
613 MARKER specifies the buffer and position to start searching at.
614 REGEXP is a regular expression matching nodes or references. Its first
615 group should match `Node:' or `Ref:'.
616 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
617 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
618 where the match was found, and MODE is `major-mode' of the buffer in
619 which the match was found.
620 This function tries to find a case-sensitive match first, then a
621 case-insensitive match is tried."
622 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
623 (when (null (car result))
624 (setq result (Info-find-in-tag-table-1 marker regexp t)))
625 result))
626
627 (defun Info-find-node-in-buffer-1 (regexp case-fold)
628 "Find a node or anchor in the current buffer.
629 REGEXP is a regular expression matching nodes or references. Its first
630 group should match `Node:' or `Ref:'.
631 CASE-FOLD t means search for a case-insensitive match.
632 Value is the position at which a match was found, or nil if not found."
633 (let ((case-fold-search case-fold)
634 found)
635 (save-excursion
636 (when (Info-node-at-bob-matching regexp)
637 (setq found (point)))
638 (while (and (not found)
639 (search-forward "\n\^_" nil t))
640 (forward-line 1)
641 (let ((beg (point)))
642 (forward-line 1)
643 (when (re-search-backward regexp beg t)
644 (beginning-of-line)
645 (setq found (point)))))
646 found)))
647
648 (defun Info-find-node-in-buffer (regexp)
649 "Find a node or anchor in the current buffer.
650 REGEXP is a regular expression matching nodes or references. Its first
651 group should match `Node:' or `Ref:'.
652 Value is the position at which a match was found, or nil if not found.
653 This function looks for a case-sensitive match first. If none is found,
654 a case-insensitive match is tried."
655 (or (Info-find-node-in-buffer-1 regexp nil)
656 (Info-find-node-in-buffer-1 regexp t)))
657
658 (defun Info-find-node-2 (filename nodename &optional no-going-back)
659 (buffer-disable-undo (current-buffer))
660 (or (eq major-mode 'Info-mode)
661 (Info-mode))
662 (widen)
663 (setq Info-current-node nil)
664 (unwind-protect
665 (let ((case-fold-search t)
666 anchorpos)
667 ;; Switch files if necessary
668 (or (null filename)
669 (equal Info-current-file filename)
670 (let ((buffer-read-only nil))
671 (setq Info-current-file nil
672 Info-current-subfile nil
673 Info-current-file-completions nil
674 buffer-file-name nil)
675 (erase-buffer)
676 (if (eq filename t)
677 (Info-insert-dir)
678 (info-insert-file-contents filename nil)
679 (setq default-directory (file-name-directory filename)))
680 (set-buffer-modified-p nil)
681 ;; See whether file has a tag table. Record the location if yes.
682 (goto-char (point-max))
683 (forward-line -8)
684 ;; Use string-equal, not equal, to ignore text props.
685 (if (not (or (string-equal nodename "*")
686 (not
687 (search-forward "\^_\nEnd tag table\n" nil t))))
688 (let (pos)
689 ;; We have a tag table. Find its beginning.
690 ;; Is this an indirect file?
691 (search-backward "\nTag table:\n")
692 (setq pos (point))
693 (if (save-excursion
694 (forward-line 2)
695 (looking-at "(Indirect)\n"))
696 ;; It is indirect. Copy it to another buffer
697 ;; and record that the tag table is in that buffer.
698 (let ((buf (current-buffer))
699 (tagbuf
700 (or Info-tag-table-buffer
701 (generate-new-buffer " *info tag table*"))))
702 (setq Info-tag-table-buffer tagbuf)
703 (save-excursion
704 (set-buffer tagbuf)
705 (buffer-disable-undo (current-buffer))
706 (setq case-fold-search t)
707 (erase-buffer)
708 (insert-buffer-substring buf))
709 (set-marker Info-tag-table-marker
710 (match-end 0) tagbuf))
711 (set-marker Info-tag-table-marker pos)))
712 (set-marker Info-tag-table-marker nil))
713 (setq Info-current-file
714 (if (eq filename t) "dir" filename))))
715 ;; Use string-equal, not equal, to ignore text props.
716 (if (string-equal nodename "*")
717 (progn (setq Info-current-node nodename)
718 (Info-set-mode-line))
719 ;; Possibilities:
720 ;;
721 ;; 1. Anchor found in tag table
722 ;; 2. Anchor *not* in tag table
723 ;;
724 ;; 3. Node found in tag table
725 ;; 4. Node *not* found in tag table, but found in file
726 ;; 5. Node *not* in tag table, and *not* in file
727 ;;
728 ;; *Or* the same, but in an indirect subfile.
729
730 ;; Search file for a suitable node.
731 (let ((guesspos (point-min))
732 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
733 (if (stringp nodename)
734 (regexp-quote nodename)
735 "")
736 "\\) *[,\t\n\177]"))
737 (nodepos nil))
738
739 (catch 'foo
740
741 ;; First, search a tag table, if any
742 (when (marker-position Info-tag-table-marker)
743 (let* ((m Info-tag-table-marker)
744 (found (Info-find-in-tag-table m regexp)))
745
746 (when found
747 ;; FOUND is (ANCHOR POS MODE).
748 (setq guesspos (nth 1 found))
749
750 ;; If this is an indirect file, determine which
751 ;; file really holds this node and read it in.
752 (unless (eq (nth 2 found) 'Info-mode)
753 ;; Note that the current buffer must be the
754 ;; *info* buffer on entry to
755 ;; Info-read-subfile. Thus the hackery above.
756 (setq guesspos (Info-read-subfile guesspos)))
757
758 ;; Handle anchor
759 (when (nth 0 found)
760 (goto-char (setq anchorpos guesspos))
761 (throw 'foo t)))))
762
763 ;; Else we may have a node, which we search for:
764 (goto-char (max (point-min)
765 (- (byte-to-position guesspos) 1000)))
766
767 ;; Now search from our advised position (or from beg of
768 ;; buffer) to find the actual node. First, check
769 ;; whether the node is right where we are, in case the
770 ;; buffer begins with a node.
771 (let ((pos (Info-find-node-in-buffer regexp)))
772 (when pos
773 (goto-char pos)
774 (throw 'foo t))
775 (error "No such anchor in tag table or node in tag table or file: %s"
776 nodename)))
777
778 (Info-select-node)
779 (goto-char (or anchorpos (point-min))))))
780 ;; If we did not finish finding the specified node,
781 ;; go back to the previous one.
782 (or Info-current-node no-going-back (null Info-history)
783 (let ((hist (car Info-history)))
784 (setq Info-history (cdr Info-history))
785 (Info-find-node (nth 0 hist) (nth 1 hist) t)
786 (goto-char (nth 2 hist))))))
787
788 ;; Cache the contents of the (virtual) dir file, once we have merged
789 ;; it for the first time, so we can save time subsequently.
790 (defvar Info-dir-contents nil)
791
792 ;; Cache for the directory we decided to use for the default-directory
793 ;; of the merged dir text.
794 (defvar Info-dir-contents-directory nil)
795
796 ;; Record the file attributes of all the files from which we
797 ;; constructed Info-dir-contents.
798 (defvar Info-dir-file-attributes nil)
799
800 (defvar Info-dir-file-name nil)
801
802 ;; Construct the Info directory node by merging the files named `dir'
803 ;; from various directories. Set the *info* buffer's
804 ;; default-directory to the first directory we actually get any text
805 ;; from.
806 (defun Info-insert-dir ()
807 (if (and Info-dir-contents Info-dir-file-attributes
808 ;; Verify that none of the files we used has changed
809 ;; since we used it.
810 (eval (cons 'and
811 (mapcar (lambda (elt)
812 (let ((curr (file-attributes
813 ;; Handle symlinks
814 (file-truename (car elt)))))
815
816 ;; Don't compare the access time.
817 (if curr (setcar (nthcdr 4 curr) 0))
818 (setcar (nthcdr 4 (cdr elt)) 0)
819 (equal (cdr elt) curr)))
820 Info-dir-file-attributes))))
821 (progn
822 (insert Info-dir-contents)
823 (goto-char (point-min)))
824 (let ((dirs (if Info-additional-directory-list
825 (append Info-directory-list
826 Info-additional-directory-list)
827 Info-directory-list))
828 (dir-file-attrs nil)
829 ;; Bind this in case the user sets it to nil.
830 (case-fold-search t)
831 ;; This is set non-nil if we find a problem in some input files.
832 problems
833 buffers buffer others nodes dirs-done)
834
835 ;; Search the directory list for the directory file.
836 (while dirs
837 (let ((truename (file-truename (expand-file-name (car dirs)))))
838 (or (member truename dirs-done)
839 (member (directory-file-name truename) dirs-done)
840 ;; Try several variants of specified name.
841 ;; Try upcasing, appending `.info', or both.
842 (let* (file
843 (attrs
844 (or
845 (progn (setq file (expand-file-name "dir" truename))
846 (file-attributes file))
847 (progn (setq file (expand-file-name "DIR" truename))
848 (file-attributes file))
849 (progn (setq file (expand-file-name "dir.info" truename))
850 (file-attributes file))
851 (progn (setq file (expand-file-name "DIR.INFO" truename))
852 (file-attributes file)))))
853 (setq dirs-done
854 (cons truename
855 (cons (directory-file-name truename)
856 dirs-done)))
857 (if attrs
858 (save-excursion
859 (or buffers
860 (message "Composing main Info directory..."))
861 (set-buffer (generate-new-buffer " info dir"))
862 (condition-case nil
863 (progn
864 (insert-file-contents file)
865 (set (make-local-variable 'Info-dir-file-name)
866 file)
867 (push (current-buffer) buffers)
868 (push (cons file attrs) dir-file-attrs))
869 (error (kill-buffer (current-buffer))))))))
870 (unless (cdr dirs)
871 (set (make-local-variable 'Info-dir-contents-directory)
872 (file-name-as-directory (car dirs))))
873 (setq dirs (cdr dirs))))
874
875 (or buffers
876 (error "Can't find the Info directory node"))
877
878 ;; Distinguish the dir file that comes with Emacs from all the
879 ;; others. Yes, that is really what this is supposed to do.
880 ;; The definition of `Info-directory-list' puts it first on that
881 ;; list and so last in `buffers' at this point.
882 (setq buffer (car (last buffers))
883 others (delq buffer buffers))
884
885 ;; Insert the entire original dir file as a start; note that we've
886 ;; already saved its default directory to use as the default
887 ;; directory for the whole concatenation.
888 (insert-buffer buffer)
889
890 ;; Look at each of the other buffers one by one.
891 (dolist (other others)
892 (let (this-buffer-nodes)
893 ;; In each, find all the menus.
894 (with-current-buffer other
895 (goto-char (point-min))
896 ;; Find each menu, and add an elt to NODES for it.
897 (while (re-search-forward "^\\* Menu:" nil t)
898 (while (and (zerop (forward-line 1)) (eolp)))
899 (let ((beg (point))
900 nodename end)
901 (re-search-backward "^\^_")
902 (search-forward "Node: ")
903 (setq nodename (Info-following-node-name))
904 (search-forward "\n\^_" nil 'move)
905 (beginning-of-line)
906 (setq end (point))
907 (push (list nodename other beg end) this-buffer-nodes)))
908 (if (assoc-ignore-case "top" this-buffer-nodes)
909 (setq nodes (nconc this-buffer-nodes nodes))
910 (setq problems t)
911 (message "No `top' node in %s" Info-dir-file-name)))))
912 ;; Add to the main menu a menu item for each other node.
913 (re-search-forward "^\\* Menu:")
914 (forward-line 1)
915 (let ((menu-items '("top"))
916 (end (save-excursion (search-forward "\^_" nil t) (point))))
917 (dolist (node nodes)
918 (let ((nodename (car node)))
919 (save-excursion
920 (or (member (downcase nodename) menu-items)
921 (re-search-forward (concat "^\\* +"
922 (regexp-quote nodename)
923 "::")
924 end t)
925 (progn
926 (insert "* " nodename "::" "\n")
927 (push nodename menu-items)))))))
928 ;; Now take each node of each of the other buffers
929 ;; and merge it into the main buffer.
930 (dolist (node nodes)
931 (let ((case-fold-search t)
932 (nodename (car node)))
933 (goto-char (point-min))
934 ;; Find the like-named node in the main buffer.
935 (if (re-search-forward (concat "^\^_.*\n.*Node: "
936 (regexp-quote nodename)
937 "[,\n\t]")
938 nil t)
939 (progn
940 (search-forward "\n\^_" nil 'move)
941 (beginning-of-line)
942 (insert "\n"))
943 ;; If none exists, add one.
944 (goto-char (point-max))
945 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
946 ;; Merge the text from the other buffer's menu
947 ;; into the menu in the like-named node in the main buffer.
948 (apply 'insert-buffer-substring (cdr node))))
949 (Info-dir-remove-duplicates)
950 ;; Kill all the buffers we just made.
951 (mapc 'kill-buffer buffers)
952 (goto-char (point-min))
953 (if problems
954 (message "Composing main Info directory...problems encountered, see `*Messages*'")
955 (message "Composing main Info directory...done"))
956 (set (make-local-variable 'Info-dir-contents) (buffer-string))
957 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
958 (setq default-directory Info-dir-contents-directory))
959
960 (defvar Info-streamline-headings
961 '(("Emacs" . "Emacs")
962 ("Programming" . "Programming")
963 ("Libraries" . "Libraries")
964 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
965 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
966
967 (defun Info-dir-remove-duplicates ()
968 (let (limit)
969 (goto-char (point-min))
970 ;; Remove duplicate headings in the same menu.
971 (while (search-forward "\n* Menu:" nil t)
972 (setq limit (save-excursion (search-forward "\n\1f" nil t)))
973 ;; Look for the next heading to unify.
974 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
975 (let ((name (match-string 1))
976 (start (match-beginning 0))
977 (entries nil) re)
978 ;; Check whether this heading should be streamlined.
979 (save-match-data
980 (dolist (x Info-streamline-headings)
981 (when (string-match (car x) name)
982 (setq name (cdr x))
983 (setq re (car x)))))
984 (if re (replace-match name t t nil 1))
985 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
986 (match-beginning 0)
987 (or limit (point-max))))
988 ;; Look for other headings of the same category and merge them.
989 (save-excursion
990 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
991 (when (if re (save-match-data (string-match re (match-string 1)))
992 (equal name (match-string 1)))
993 (forward-line 0)
994 ;; Delete redundant heading.
995 (delete-region (match-beginning 0) (point))
996 ;; Push the entries onto `text'.
997 (push
998 (delete-and-extract-region
999 (point)
1000 (if (re-search-forward "^[^* \n\t]" nil t)
1001 (match-beginning 0)
1002 (or limit (point-max)))) entries))))
1003 ;; Insert the entries just found.
1004 (while (= (line-beginning-position 0) (1- (point)))
1005 (backward-char))
1006 (dolist (entry (nreverse entries))
1007 (insert entry)
1008 (while (= (line-beginning-position 0) (1- (point)))
1009 (delete-region (1- (point)) (point))))
1010
1011 ;; Now remove duplicate entries under the same heading.
1012 (let ((seen nil)
1013 (limit (point)))
1014 (goto-char start)
1015 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1016 limit 'move)
1017 (let ((x (match-string 1)))
1018 (if (member-ignore-case x seen)
1019 (delete-region (match-beginning 0)
1020 (progn (re-search-forward "^[^ \t]" nil t)
1021 (match-beginning 0)))
1022 (push x seen))))))))))
1023
1024 ;; Note that on entry to this function the current-buffer must be the
1025 ;; *info* buffer; not the info tags buffer.
1026 (defun Info-read-subfile (nodepos)
1027 ;; NODEPOS is either a position (in the Info file as a whole,
1028 ;; not relative to a subfile) or the name of a subfile.
1029 (let (lastfilepos
1030 lastfilename)
1031 (if (numberp nodepos)
1032 (save-excursion
1033 (set-buffer (marker-buffer Info-tag-table-marker))
1034 (goto-char (point-min))
1035 (or (looking-at "\^_")
1036 (search-forward "\n\^_"))
1037 (forward-line 2)
1038 (catch 'foo
1039 (while (not (looking-at "\^_"))
1040 (if (not (eolp))
1041 (let ((beg (point))
1042 thisfilepos thisfilename)
1043 (search-forward ": ")
1044 (setq thisfilename (buffer-substring beg (- (point) 2)))
1045 (setq thisfilepos (+ (point-min) (read (current-buffer))))
1046 ;; read in version 19 stops at the end of number.
1047 ;; Advance to the next line.
1048 (forward-line 1)
1049 (if (> thisfilepos nodepos)
1050 (throw 'foo t))
1051 (setq lastfilename thisfilename)
1052 (setq lastfilepos thisfilepos))
1053 (forward-line 1)))))
1054 (setq lastfilename nodepos)
1055 (setq lastfilepos 0))
1056 ;; Assume previous buffer is in Info-mode.
1057 ;; (set-buffer (get-buffer "*info*"))
1058 (or (equal Info-current-subfile lastfilename)
1059 (let ((buffer-read-only nil))
1060 (setq buffer-file-name nil)
1061 (widen)
1062 (erase-buffer)
1063 (info-insert-file-contents lastfilename)
1064 (set-buffer-modified-p nil)
1065 (setq Info-current-subfile lastfilename)))
1066 ;; Widen in case we are in the same subfile as before.
1067 (widen)
1068 (goto-char (point-min))
1069 (if (looking-at "\^_")
1070 (forward-char 1)
1071 (search-forward "\n\^_"))
1072 (if (numberp nodepos)
1073 (+ (- nodepos lastfilepos) (point)))))
1074
1075 (defvar Info-header-line nil
1076 "If the info node header is hidden, the text of the header.")
1077 (put 'Info-header-line 'risky-local-variable t)
1078
1079 (defun Info-select-node ()
1080 "Select the info node that point is in.
1081 Bind this in case the user sets it to nil."
1082 (let ((case-fold-search t))
1083 (save-excursion
1084 ;; Find beginning of node.
1085 (if (search-backward "\n\^_" nil 'move)
1086 (forward-line 2)
1087 (if (looking-at "\^_")
1088 (forward-line 1)
1089 (signal 'search-failed (list "\n\^_"))))
1090 ;; Get nodename spelled as it is in the node.
1091 (re-search-forward "Node:[ \t]*")
1092 (setq Info-current-node
1093 (buffer-substring-no-properties (point)
1094 (progn
1095 (skip-chars-forward "^,\t\n")
1096 (point))))
1097 (Info-set-mode-line)
1098 ;; Find the end of it, and narrow.
1099 (beginning-of-line)
1100 (let (active-expression)
1101 ;; Narrow to the node contents
1102 (narrow-to-region (point)
1103 (if (re-search-forward "\n[\^_\f]" nil t)
1104 (prog1
1105 (1- (point))
1106 (if (looking-at "[\n\^_\f]*execute: ")
1107 (progn
1108 (goto-char (match-end 0))
1109 (setq active-expression
1110 (read (current-buffer))))))
1111 (point-max)))
1112 (if Info-enable-active-nodes (eval active-expression))
1113 (Info-fontify-node)
1114 (setq Info-header-line (get-text-property (point-min) 'header-line))
1115 (run-hooks 'Info-selection-hook)))))
1116
1117 (defun Info-set-mode-line ()
1118 (setq mode-line-buffer-identification
1119 (nconc (propertized-buffer-identification "%b")
1120 (list
1121 (concat " ("
1122 (file-name-nondirectory
1123 (if (stringp Info-current-file)
1124 Info-current-file
1125 (or buffer-file-name "")))
1126 ") "
1127 (or Info-current-node ""))))))
1128 \f
1129 ;; Go to an info node specified with a filename-and-nodename string
1130 ;; of the sort that is found in pointers in nodes.
1131
1132 (defun Info-goto-node (nodename &optional fork)
1133 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1134 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1135 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1136 its sub-files).
1137 Completion is available, but only for node names in the current Info file.
1138 If FORK is non-nil (interactively with a prefix arg), show the node in
1139 a new info buffer.
1140 If FORK is a string, it is the name to use for the new buffer."
1141 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
1142 (info-initialize)
1143 (if fork
1144 (set-buffer
1145 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
1146 (let (filename)
1147 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1148 nodename)
1149 (setq filename (if (= (match-beginning 1) (match-end 1))
1150 ""
1151 (substring nodename (match-beginning 2) (match-end 2)))
1152 nodename (substring nodename (match-beginning 3) (match-end 3)))
1153 (let ((trim (string-match "\\s *\\'" filename)))
1154 (if trim (setq filename (substring filename 0 trim))))
1155 (let ((trim (string-match "\\s *\\'" nodename)))
1156 (if trim (setq nodename (substring nodename 0 trim))))
1157 (if transient-mark-mode (deactivate-mark))
1158 (Info-find-node (if (equal filename "") nil filename)
1159 (if (equal nodename "") "Top" nodename))))
1160
1161 (defvar Info-read-node-completion-table)
1162
1163 ;; This function is used as the "completion table" while reading a node name.
1164 ;; It does completion using the alist in Info-read-node-completion-table
1165 ;; unless STRING starts with an open-paren.
1166 (defun Info-read-node-name-1 (string predicate code)
1167 (cond
1168 ;; First complete embedded file names.
1169 ((string-match "\\`([^)]*\\'" string)
1170 (let ((file (substring string 1)))
1171 (cond
1172 ((eq code nil)
1173 (let ((comp (try-completion file 'locate-file-completion
1174 (cons Info-directory-list
1175 (mapcar 'car Info-suffix-list)))))
1176 (cond
1177 ((eq comp t) (concat string ")"))
1178 (comp (concat "(" comp)))))
1179 ((eq code t) (all-completions file 'locate-file-completion
1180 (cons Info-directory-list
1181 (mapcar 'car Info-suffix-list))))
1182 (t nil))))
1183 ;; If a file name was given, then any node is fair game.
1184 ((string-match "\\`(" string)
1185 (cond
1186 ((eq code nil) string)
1187 ((eq code t) nil)
1188 (t t)))
1189 ;; Otherwise use Info-read-node-completion-table.
1190 ((eq code nil)
1191 (try-completion string Info-read-node-completion-table predicate))
1192 ((eq code t)
1193 (all-completions string Info-read-node-completion-table predicate))
1194 (t
1195 (test-completion string Info-read-node-completion-table predicate))))
1196
1197 (defun Info-read-node-name (prompt &optional default)
1198 (let* ((completion-ignore-case t)
1199 (Info-read-node-completion-table (Info-build-node-completions))
1200 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1201 (if (equal nodename "")
1202 (or default
1203 (Info-read-node-name prompt))
1204 nodename)))
1205
1206 (defun Info-build-node-completions ()
1207 (or Info-current-file-completions
1208 (let ((compl nil)
1209 ;; Bind this in case the user sets it to nil.
1210 (case-fold-search t)
1211 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1212 (save-excursion
1213 (save-restriction
1214 (if (marker-buffer Info-tag-table-marker)
1215 (let ((marker Info-tag-table-marker))
1216 (set-buffer (marker-buffer marker))
1217 (widen)
1218 (goto-char marker)
1219 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1220 (setq compl
1221 (cons (list (match-string-no-properties 2))
1222 compl))))
1223 (widen)
1224 (goto-char (point-min))
1225 ;; If the buffer begins with a node header, process that first.
1226 (if (Info-node-at-bob-matching node-regexp)
1227 (setq compl (list (match-string-no-properties 1))))
1228 ;; Now for the rest of the nodes.
1229 (while (search-forward "\n\^_" nil t)
1230 (forward-line 1)
1231 (let ((beg (point)))
1232 (forward-line 1)
1233 (if (re-search-backward node-regexp beg t)
1234 (setq compl
1235 (cons (list (match-string-no-properties 1))
1236 compl))))))))
1237 (setq compl (cons '("*") compl))
1238 (set (make-local-variable 'Info-current-file-completions) compl))))
1239 \f
1240 (defun Info-restore-point (hl)
1241 "If this node has been visited, restore the point value when we left."
1242 (while hl
1243 (if (and (equal (nth 0 (car hl)) Info-current-file)
1244 ;; Use string-equal, not equal, to ignore text props.
1245 (string-equal (nth 1 (car hl)) Info-current-node))
1246 (progn
1247 (goto-char (nth 2 (car hl)))
1248 (setq hl nil)) ;terminate the while at next iter
1249 (setq hl (cdr hl)))))
1250 \f
1251 (defvar Info-search-history nil
1252 "The history list for `Info-search'.")
1253
1254 (defun Info-search (regexp)
1255 "Search for REGEXP, starting from point, and select node it's found in."
1256 (interactive (list (read-string
1257 (if Info-search-history
1258 (format "Regexp search (default `%s'): "
1259 (car Info-search-history))
1260 "Regexp search: ")
1261 nil 'Info-search-history)))
1262 (when transient-mark-mode
1263 (deactivate-mark))
1264 (when (equal regexp "")
1265 (setq regexp (car Info-search-history)))
1266 (when regexp
1267 (let ((found ()) current
1268 (onode Info-current-node)
1269 (ofile Info-current-file)
1270 (opoint (point))
1271 (ostart (window-start))
1272 (osubfile Info-current-subfile))
1273 (save-excursion
1274 (save-restriction
1275 (widen)
1276 (if (null Info-current-subfile)
1277 (progn (re-search-forward regexp) (setq found (point)))
1278 (condition-case err
1279 (progn (re-search-forward regexp) (setq found (point)))
1280 (search-failed nil)))))
1281 (if (not found) ;can only happen in subfile case -- else would have erred
1282 (unwind-protect
1283 (let ((list ()))
1284 (save-excursion
1285 (set-buffer (marker-buffer Info-tag-table-marker))
1286 (goto-char (point-min))
1287 (search-forward "\n\^_\nIndirect:")
1288 (save-restriction
1289 (narrow-to-region (point)
1290 (progn (search-forward "\n\^_")
1291 (1- (point))))
1292 (goto-char (point-min))
1293 ;; Find the subfile we just searched.
1294 (search-forward (concat "\n" osubfile ": "))
1295 ;; Skip that one.
1296 (forward-line 1)
1297 ;; Make a list of all following subfiles.
1298 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1299 (while (not (eobp))
1300 (re-search-forward "\\(^.*\\): [0-9]+$")
1301 (goto-char (+ (match-end 1) 2))
1302 (setq list (cons (cons (+ (point-min)
1303 (read (current-buffer)))
1304 (match-string-no-properties 1))
1305 list))
1306 (goto-char (1+ (match-end 0))))
1307 ;; Put in forward order
1308 (setq list (nreverse list))))
1309 (while list
1310 (message "Searching subfile %s..." (cdr (car list)))
1311 (Info-read-subfile (car (car list)))
1312 (setq list (cdr list))
1313 (if (re-search-forward regexp nil t)
1314 (setq found (point) list ())))
1315 (if found
1316 (message "")
1317 (signal 'search-failed (list regexp))))
1318 (if (not found)
1319 (progn (Info-read-subfile osubfile)
1320 (goto-char opoint)
1321 (Info-select-node)
1322 (set-window-start (selected-window) ostart)))))
1323 (widen)
1324 (goto-char found)
1325 (Info-select-node)
1326 ;; Use string-equal, not equal, to ignore text props.
1327 (or (and (string-equal onode Info-current-node)
1328 (equal ofile Info-current-file))
1329 (setq Info-history (cons (list ofile onode opoint)
1330 Info-history))))))
1331 \f
1332 (defun Info-extract-pointer (name &optional errorname)
1333 "Extract the value of the node-pointer named NAME.
1334 If there is none, use ERRORNAME in the error message;
1335 if ERRORNAME is nil, just return nil.
1336 Bind this in case the user sets it to nil."
1337 (let ((case-fold-search t))
1338 (save-excursion
1339 (save-restriction
1340 (goto-char (point-min))
1341 (let ((bound (point)))
1342 (forward-line 1)
1343 (cond ((re-search-backward (concat name ":") bound t)
1344 (goto-char (match-end 0))
1345 (Info-following-node-name))
1346 ((not (eq errorname t))
1347 (error "Node has no %s"
1348 (capitalize (or errorname name))))))))))
1349
1350 (defun Info-following-node-name (&optional allowedchars)
1351 "Return the node name in the buffer following point.
1352 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1353 saying which chars may appear in the node name."
1354 (skip-chars-forward " \t")
1355 (buffer-substring-no-properties
1356 (point)
1357 (progn
1358 (while (looking-at (concat "[" (or allowedchars "^,\t\n") "]"))
1359 (skip-chars-forward (concat (or allowedchars "^,\t\n") "("))
1360 (if (looking-at "(")
1361 (skip-chars-forward "^)")))
1362 (skip-chars-backward " ")
1363 (point))))
1364
1365 (defun Info-next ()
1366 "Go to the next node of this node."
1367 (interactive)
1368 (Info-goto-node (Info-extract-pointer "next")))
1369
1370 (defun Info-prev ()
1371 "Go to the previous node of this node."
1372 (interactive)
1373 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1374
1375 (defun Info-up (&optional same-file)
1376 "Go to the superior node of this node.
1377 If SAME-FILE is non-nil, do not move to a different Info file."
1378 (interactive)
1379 (let ((node (Info-extract-pointer "up")))
1380 (and (or same-file (not (stringp Info-current-file)))
1381 (string-match "^(" node)
1382 (error "Up node is in another Info file"))
1383 (Info-goto-node node))
1384 (Info-restore-point Info-history))
1385
1386 (defun Info-last ()
1387 "Go back to the last node visited."
1388 (interactive)
1389 (or Info-history
1390 (error "This is the first Info node you looked at"))
1391 (let (filename nodename opoint)
1392 (setq filename (car (car Info-history)))
1393 (setq nodename (car (cdr (car Info-history))))
1394 (setq opoint (car (cdr (cdr (car Info-history)))))
1395 (setq Info-history (cdr Info-history))
1396 (Info-find-node filename nodename)
1397 (setq Info-history (cdr Info-history))
1398 (goto-char opoint)))
1399
1400 ;;;###autoload
1401 (defun Info-directory ()
1402 "Go to the Info directory node."
1403 (interactive)
1404 (Info-find-node "dir" "top"))
1405 \f
1406 (defun Info-follow-reference (footnotename)
1407 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1408 FOOTNOTENAME may be an abbreviation of the reference name."
1409 (interactive
1410 (let ((completion-ignore-case t)
1411 (case-fold-search t)
1412 completions default alt-default (start-point (point)) str i bol eol)
1413 (save-excursion
1414 ;; Store end and beginning of line.
1415 (end-of-line)
1416 (setq eol (point))
1417 (beginning-of-line)
1418 (setq bol (point))
1419
1420 (goto-char (point-min))
1421 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
1422 (setq str (buffer-substring-no-properties
1423 (match-beginning 1)
1424 (1- (point))))
1425 ;; See if this one should be the default.
1426 (and (null default)
1427 (<= (match-beginning 0) start-point)
1428 (<= start-point (point))
1429 (setq default t))
1430 ;; See if this one should be the alternate default.
1431 (and (null alt-default)
1432 (and (<= bol (match-beginning 0))
1433 (<= (point) eol))
1434 (setq alt-default t))
1435 (setq i 0)
1436 (while (setq i (string-match "[ \n\t]+" str i))
1437 (setq str (concat (substring str 0 i) " "
1438 (substring str (match-end 0))))
1439 (setq i (1+ i)))
1440 ;; Record as a completion and perhaps as default.
1441 (if (eq default t) (setq default str))
1442 (if (eq alt-default t) (setq alt-default str))
1443 ;; Don't add this string if it's a duplicate.
1444 ;; We use a loop instead of "(assoc str completions)" because
1445 ;; we want to do a case-insensitive compare.
1446 (let ((tail completions)
1447 (tem (downcase str)))
1448 (while (and tail
1449 (not (string-equal tem (downcase (car (car tail))))))
1450 (setq tail (cdr tail)))
1451 (or tail
1452 (setq completions
1453 (cons (cons str nil)
1454 completions))))))
1455 ;; If no good default was found, try an alternate.
1456 (or default
1457 (setq default alt-default))
1458 ;; If only one cross-reference found, then make it default.
1459 (if (eq (length completions) 1)
1460 (setq default (car (car completions))))
1461 (if completions
1462 (let ((input (completing-read (if default
1463 (concat
1464 "Follow reference named: (default "
1465 default ") ")
1466 "Follow reference named: ")
1467 completions nil t)))
1468 (list (if (equal input "")
1469 default input)))
1470 (error "No cross-references in this node"))))
1471
1472 (unless footnotename
1473 (error "No reference was specified"))
1474
1475 (let (target beg i (str (concat "\\*note " (regexp-quote footnotename)))
1476 (case-fold-search t))
1477 (while (setq i (string-match " " str i))
1478 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
1479 (setq i (+ i 6)))
1480 (save-excursion
1481 (goto-char (point-min))
1482 (or (re-search-forward str nil t)
1483 (error "No cross-reference named %s" footnotename))
1484 (goto-char (+ (match-beginning 0) 5))
1485 (setq target
1486 (Info-extract-menu-node-name "Bad format cross reference" t)))
1487 (while (setq i (string-match "[ \t\n]+" target i))
1488 (setq target (concat (substring target 0 i) " "
1489 (substring target (match-end 0))))
1490 (setq i (+ i 1)))
1491 (Info-goto-node target)))
1492
1493 (defun Info-extract-menu-node-name (&optional errmessage multi-line)
1494 (skip-chars-forward " \t\n")
1495 (let ((beg (point))
1496 str i)
1497 (while (not (looking-at ":*[,.;() \t\n]"))
1498 (skip-chars-forward "^:")
1499 (forward-char 1))
1500 (setq str
1501 (if (looking-at ":")
1502 (buffer-substring-no-properties beg (1- (point)))
1503 (skip-chars-forward " \t\n")
1504 (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
1505 (replace-regexp-in-string "[ \n]+" " " str)))
1506
1507 ;; No one calls this.
1508 ;;(defun Info-menu-item-sequence (list)
1509 ;; (while list
1510 ;; (Info-menu (car list))
1511 ;; (setq list (cdr list))))
1512
1513 (defvar Info-complete-menu-buffer)
1514 (defvar Info-complete-next-re nil)
1515 (defvar Info-complete-cache nil)
1516
1517 (defun Info-complete-menu-item (string predicate action)
1518 ;; This uses two dynamically bound variables:
1519 ;; - `Info-complete-menu-buffer' which contains the buffer in which
1520 ;; is the menu of items we're trying to complete.
1521 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
1522 ;; also look for menu items in subsequent nodes as long as those
1523 ;; nodes' names match `Info-complete-next-re'. This feature is currently
1524 ;; only used for completion in Info-index.
1525 (save-excursion
1526 (set-buffer Info-complete-menu-buffer)
1527 (let ((completion-ignore-case t)
1528 (case-fold-search t)
1529 (orignode Info-current-node)
1530 nextnode)
1531 (goto-char (point-min))
1532 (search-forward "\n* Menu:")
1533 (if (not (memq action '(nil t)))
1534 (re-search-forward
1535 (concat "\n\\* +" (regexp-quote string) ":") nil t)
1536 (let ((pattern (concat "\n\\* +\\("
1537 (regexp-quote string)
1538 "[^\t\n]*\\):"))
1539 completions)
1540 ;; Check the cache.
1541 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
1542 (equal (nth 1 Info-complete-cache) Info-current-node)
1543 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
1544 (let ((prev (nth 3 Info-complete-cache)))
1545 (eq t (compare-strings string 0 (length prev)
1546 prev 0 nil t))))
1547 ;; We can reuse the previous list.
1548 (setq completions (nth 4 Info-complete-cache))
1549 ;; The cache can't be used.
1550 (while
1551 (progn
1552 (while (re-search-forward pattern nil t)
1553 (push (match-string-no-properties 1)
1554 completions))
1555 ;; Check subsequent nodes if applicable.
1556 (and Info-complete-next-re
1557 (setq nextnode (Info-extract-pointer "next" t))
1558 (string-match Info-complete-next-re nextnode)))
1559 (Info-goto-node nextnode))
1560 ;; Go back to the start node (for the next completion).
1561 (unless (equal Info-current-node orignode)
1562 (Info-goto-node orignode))
1563 ;; Update the cache.
1564 (set (make-local-variable 'Info-complete-cache)
1565 (list Info-current-file Info-current-node
1566 Info-complete-next-re string completions)))
1567 (if action
1568 (all-completions string completions predicate)
1569 (try-completion string completions predicate)))))))
1570
1571
1572 (defun Info-menu (menu-item &optional fork)
1573 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
1574 The menu item should one of those listed in the current node's menu.
1575 Completion is allowed, and the default menu item is the one point is on.
1576 If FORK is non-nil (interactively with a prefix arg), show the node in
1577 a new info buffer. If FORK is a string, it is the name to use for the
1578 new buffer."
1579 (interactive
1580 (let ((completions '())
1581 ;; If point is within a menu item, use that item as the default
1582 (default nil)
1583 (p (point))
1584 beg
1585 (last nil)
1586 (case-fold-search t))
1587 (save-excursion
1588 (goto-char (point-min))
1589 (if (not (search-forward "\n* menu:" nil t))
1590 (error "No menu in this node"))
1591 (setq beg (point))
1592 (and (< (point) p)
1593 (save-excursion
1594 (goto-char p)
1595 (end-of-line)
1596 (if (re-search-backward "\n\\* +\\([^\t\n]*\\):" beg t)
1597 (setq default (match-string-no-properties 1))))))
1598 (let ((item nil))
1599 (while (null item)
1600 (setq item (let ((completion-ignore-case t)
1601 (Info-complete-menu-buffer (current-buffer)))
1602 (completing-read (if default
1603 (format "Menu item (default %s): "
1604 default)
1605 "Menu item: ")
1606 'Info-complete-menu-item nil t)))
1607 ;; we rely on the fact that completing-read accepts an input
1608 ;; of "" even when the require-match argument is true and ""
1609 ;; is not a valid possibility
1610 (if (string= item "")
1611 (if default
1612 (setq item default)
1613 ;; ask again
1614 (setq item nil))))
1615 (list item current-prefix-arg))))
1616 ;; there is a problem here in that if several menu items have the same
1617 ;; name you can only go to the node of the first with this command.
1618 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
1619
1620 (defun Info-extract-menu-item (menu-item)
1621 (setq menu-item (regexp-quote menu-item))
1622 (let ((case-fold-search t))
1623 (save-excursion
1624 (let ((case-fold-search t))
1625 (goto-char (point-min))
1626 (or (search-forward "\n* menu:" nil t)
1627 (error "No menu in this node"))
1628 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
1629 (re-search-forward (concat "\n\\* +" menu-item) nil t)
1630 (error "No such item in menu"))
1631 (beginning-of-line)
1632 (forward-char 2)
1633 (Info-extract-menu-node-name)))))
1634
1635 ;; If COUNT is nil, use the last item in the menu.
1636 (defun Info-extract-menu-counting (count)
1637 (let ((case-fold-search t))
1638 (save-excursion
1639 (let ((case-fold-search t))
1640 (goto-char (point-min))
1641 (or (search-forward "\n* menu:" nil t)
1642 (error "No menu in this node"))
1643 (if count
1644 (or (search-forward "\n* " nil t count)
1645 (error "Too few items in menu"))
1646 (while (search-forward "\n* " nil t)
1647 nil))
1648 (Info-extract-menu-node-name)))))
1649
1650 (defun Info-nth-menu-item ()
1651 "Go to the node of the Nth menu item.
1652 N is the digit argument used to invoke this command."
1653 (interactive)
1654 (Info-goto-node
1655 (Info-extract-menu-counting
1656 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
1657
1658 (defun Info-top-node ()
1659 "Go to the Top node of this file."
1660 (interactive)
1661 (Info-goto-node "Top"))
1662
1663 (defun Info-final-node ()
1664 "Go to the final node in this file."
1665 (interactive)
1666 (Info-goto-node "Top")
1667 (let ((Info-history nil)
1668 (case-fold-search t))
1669 ;; Go to the last node in the menu of Top.
1670 (Info-goto-node (Info-extract-menu-counting nil))
1671 ;; If the last node in the menu is not last in pointer structure,
1672 ;; move forward until we can't go any farther.
1673 (while (Info-forward-node t t) nil)
1674 ;; Then keep moving down to last subnode, unless we reach an index.
1675 (while (and (not (string-match "\\<index\\>" Info-current-node))
1676 (save-excursion (search-forward "\n* Menu:" nil t)))
1677 (Info-goto-node (Info-extract-menu-counting nil)))))
1678
1679 (defun Info-forward-node (&optional not-down no-error)
1680 "Go forward one node, considering all nodes as forming one sequence."
1681 (interactive)
1682 (goto-char (point-min))
1683 (forward-line 1)
1684 (let ((case-fold-search t))
1685 ;; three possibilities, in order of priority:
1686 ;; 1. next node is in a menu in this node (but not in an index)
1687 ;; 2. next node is next at same level
1688 ;; 3. next node is up and next
1689 (cond ((and (not not-down)
1690 (save-excursion (search-forward "\n* menu:" nil t))
1691 (not (string-match "\\<index\\>" Info-current-node)))
1692 (Info-goto-node (Info-extract-menu-counting 1))
1693 t)
1694 ((save-excursion (search-backward "next:" nil t))
1695 (Info-next)
1696 t)
1697 ((and (save-excursion (search-backward "up:" nil t))
1698 ;; Use string-equal, not equal, to ignore text props.
1699 (not (string-equal (downcase (Info-extract-pointer "up"))
1700 "top")))
1701 (let ((old-node Info-current-node))
1702 (Info-up)
1703 (let (Info-history success)
1704 (unwind-protect
1705 (setq success (Info-forward-node t no-error))
1706 (or success (Info-goto-node old-node))))))
1707 (no-error nil)
1708 (t (error "No pointer forward from this node")))))
1709
1710 (defun Info-backward-node ()
1711 "Go backward one node, considering all nodes as forming one sequence."
1712 (interactive)
1713 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
1714 (upnode (Info-extract-pointer "up" t))
1715 (case-fold-search t))
1716 (cond ((and upnode (string-match "(" upnode))
1717 (error "First node in file"))
1718 ((and upnode (or (null prevnode)
1719 ;; Use string-equal, not equal,
1720 ;; to ignore text properties.
1721 (string-equal (downcase prevnode)
1722 (downcase upnode))))
1723 (Info-up))
1724 (prevnode
1725 ;; If we move back at the same level,
1726 ;; go down to find the last subnode*.
1727 (Info-prev)
1728 (let (Info-history)
1729 (while (and (not (string-match "\\<index\\>" Info-current-node))
1730 (save-excursion (search-forward "\n* Menu:" nil t)))
1731 (Info-goto-node (Info-extract-menu-counting nil)))))
1732 (t
1733 (error "No pointer backward from this node")))))
1734
1735 (defun Info-exit ()
1736 "Exit Info by selecting some other buffer."
1737 (interactive)
1738 (if Info-standalone
1739 (save-buffers-kill-emacs)
1740 (quit-window)))
1741
1742 (defun Info-next-menu-item ()
1743 "Go to the node of the next menu item."
1744 (interactive)
1745 ;; Bind this in case the user sets it to nil.
1746 (let* ((case-fold-search t)
1747 (node
1748 (save-excursion
1749 (forward-line -1)
1750 (search-forward "\n* menu:" nil t)
1751 (and (search-forward "\n* " nil t)
1752 (Info-extract-menu-node-name)))))
1753 (if node (Info-goto-node node)
1754 (error "No more items in menu"))))
1755
1756 (defun Info-last-menu-item ()
1757 "Go to the node of the previous menu item."
1758 (interactive)
1759 (save-excursion
1760 (forward-line 1)
1761 ;; Bind this in case the user sets it to nil.
1762 (let* ((case-fold-search t)
1763 (beg (save-excursion
1764 (and (search-backward "\n* menu:" nil t)
1765 (point)))))
1766 (or (and beg (search-backward "\n* " beg t))
1767 (error "No previous items in menu")))
1768 (Info-goto-node (save-excursion
1769 (goto-char (match-end 0))
1770 (Info-extract-menu-node-name)))))
1771
1772 (defmacro Info-no-error (&rest body)
1773 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
1774
1775 (defun Info-next-preorder ()
1776 "Go to the next subnode or the next node, or go up a level."
1777 (interactive)
1778 (cond ((Info-no-error (Info-next-menu-item)))
1779 ((Info-no-error (Info-next)))
1780 ((Info-no-error (Info-up t))
1781 ;; Since we have already gone thru all the items in this menu,
1782 ;; go up to the end of this node.
1783 (goto-char (point-max))
1784 ;; Since logically we are done with the node with that menu,
1785 ;; move on from it.
1786 (Info-next-preorder))
1787 (t
1788 (error "No more nodes"))))
1789
1790 (defun Info-last-preorder ()
1791 "Go to the last node, popping up a level if there is none."
1792 (interactive)
1793 (cond ((Info-no-error
1794 (Info-last-menu-item)
1795 ;; If we go down a menu item, go to the end of the node
1796 ;; so we can scroll back through it.
1797 (goto-char (point-max)))
1798 ;; Keep going down, as long as there are nested menu nodes.
1799 (while (Info-no-error
1800 (Info-last-menu-item)
1801 ;; If we go down a menu item, go to the end of the node
1802 ;; so we can scroll back through it.
1803 (goto-char (point-max))))
1804 (recenter -1))
1805 ((and (Info-no-error (Info-extract-pointer "prev"))
1806 (not (equal (Info-extract-pointer "up")
1807 (Info-extract-pointer "prev"))))
1808 (Info-no-error (Info-prev))
1809 (goto-char (point-max))
1810 (while (Info-no-error
1811 (Info-last-menu-item)
1812 ;; If we go down a menu item, go to the end of the node
1813 ;; so we can scroll back through it.
1814 (goto-char (point-max))))
1815 (recenter -1))
1816 ((Info-no-error (Info-up t))
1817 (goto-char (point-min))
1818 (let ((case-fold-search t))
1819 (or (search-forward "\n* Menu:" nil t)
1820 (goto-char (point-max)))))
1821 (t (error "No previous nodes"))))
1822
1823 (defun Info-scroll-up ()
1824 "Scroll one screenful forward in Info, considering all nodes as one sequence.
1825 Once you scroll far enough in a node that its menu appears on the screen
1826 but after point, the next scroll moves into its first subnode, unless
1827 `Info-scroll-prefer-subnodes' is nil.
1828
1829 When you scroll past the end of a node, that goes to the next node if
1830 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
1831 if this node has no successor, it moves to the parent node's successor,
1832 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
1833 the menu of a node, it moves to subnode indicated by the following menu
1834 item. (That case won't normally result from this command, but can happen
1835 in other ways.)"
1836
1837 (interactive)
1838 (if (or (< (window-start) (point-min))
1839 (> (window-start) (point-max)))
1840 (set-window-start (selected-window) (point)))
1841 (let* ((case-fold-search t)
1842 (virtual-end (save-excursion
1843 (goto-char (point-min))
1844 (if (and Info-scroll-prefer-subnodes
1845 (search-forward "\n* Menu:" nil t))
1846 (point)
1847 (point-max)))))
1848 (if (or (< virtual-end (window-start))
1849 (pos-visible-in-window-p virtual-end))
1850 (cond
1851 (Info-scroll-prefer-subnodes (Info-next-preorder))
1852 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
1853 (t (Info-next-preorder)))
1854 (scroll-up))))
1855
1856 (defun Info-scroll-down ()
1857 "Scroll one screenful back in Info, considering all nodes as one sequence.
1858 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
1859 is non-nil, this goes to its last subnode. When you scroll past the
1860 beginning of a node, that goes to the previous node or back up to the
1861 parent node."
1862 (interactive)
1863 (if (or (< (window-start) (point-min))
1864 (> (window-start) (point-max)))
1865 (set-window-start (selected-window) (point)))
1866 (let* ((case-fold-search t)
1867 (current-point (point))
1868 (virtual-end
1869 (and Info-scroll-prefer-subnodes
1870 (save-excursion
1871 (beginning-of-line)
1872 (setq current-point (point))
1873 (goto-char (point-min))
1874 (search-forward "\n* Menu:"
1875 current-point
1876 t)))))
1877 (if (or virtual-end
1878 (pos-visible-in-window-p (point-min) nil t))
1879 (Info-last-preorder)
1880 (scroll-down))))
1881
1882 (defun Info-next-reference (&optional recur)
1883 "Move cursor to the next cross-reference or menu item in the node."
1884 (interactive)
1885 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1886 (old-pt (point))
1887 (case-fold-search t))
1888 (or (eobp) (forward-char 1))
1889 (or (re-search-forward pat nil t)
1890 (progn
1891 (goto-char (point-min))
1892 (or (re-search-forward pat nil t)
1893 (progn
1894 (goto-char old-pt)
1895 (error "No cross references in this node")))))
1896 (goto-char (match-beginning 0))
1897 (if (looking-at "\\* Menu:")
1898 (if recur
1899 (error "No cross references in this node")
1900 (Info-next-reference t)))))
1901
1902 (defun Info-prev-reference (&optional recur)
1903 "Move cursor to the previous cross-reference or menu item in the node."
1904 (interactive)
1905 (let ((pat "\\*note[ \n\t]*\\([^:]*\\):\\|^\\* .*:")
1906 (old-pt (point))
1907 (case-fold-search t))
1908 (or (re-search-backward pat nil t)
1909 (progn
1910 (goto-char (point-max))
1911 (or (re-search-backward pat nil t)
1912 (progn
1913 (goto-char old-pt)
1914 (error "No cross references in this node")))))
1915 (goto-char (match-beginning 0))
1916 (if (looking-at "\\* Menu:")
1917 (if recur
1918 (error "No cross references in this node")
1919 (Info-prev-reference t)))))
1920
1921 (defun Info-goto-index ()
1922 (Info-goto-node "Top")
1923 (or (search-forward "\n* menu:" nil t)
1924 (error "No index"))
1925 (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
1926 (error "No index"))
1927 (goto-char (match-beginning 1))
1928 ;; Protect Info-history so that the current node (Top) is not added to it.
1929 (let ((Info-history nil))
1930 (Info-goto-node (Info-extract-menu-node-name))))
1931
1932 (defun Info-index (topic)
1933 "Look up a string TOPIC in the index for this file.
1934 The index is defined as the first node in the top level menu whose
1935 name contains the word \"Index\", plus any immediately following
1936 nodes whose names also contain the word \"Index\".
1937 If there are no exact matches to the specified topic, this chooses
1938 the first match which is a case-insensitive substring of a topic.
1939 Use the `,' command to see the other matches.
1940 Give a blank topic name to go to the Index node itself."
1941 (interactive
1942 (list
1943 (let ((Info-complete-menu-buffer (clone-buffer))
1944 (Info-complete-next-re "\\<Index\\>"))
1945 (if (equal Info-current-file "dir")
1946 (error "The Info directory node has no index; use m to select a manual"))
1947 (unwind-protect
1948 (with-current-buffer Info-complete-menu-buffer
1949 (Info-goto-index)
1950 (completing-read "Index topic: " 'Info-complete-menu-item))
1951 (kill-buffer Info-complete-menu-buffer)))))
1952 (if (equal Info-current-file "dir")
1953 (error "The Info directory node has no index; use m to select a manual"))
1954 (let ((orignode Info-current-node)
1955 (rnode nil)
1956 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
1957 (regexp-quote topic)))
1958 node
1959 (case-fold-search t))
1960 (Info-goto-index)
1961 (or (equal topic "")
1962 (let ((matches nil)
1963 (exact nil)
1964 ;; We bind Info-history to nil for internal node-switches so
1965 ;; that we don't put junk in the history. In the first
1966 ;; Info-goto-index call, above, we do update the history
1967 ;; because that is what the user's previous node choice into it.
1968 (Info-history nil)
1969 found)
1970 (while
1971 (progn
1972 (goto-char (point-min))
1973 (while (re-search-forward pattern nil t)
1974 (push (list (match-string-no-properties 1)
1975 (match-string-no-properties 2)
1976 Info-current-node
1977 (string-to-number (concat "0"
1978 (match-string 3))))
1979 matches))
1980 (and (setq node (Info-extract-pointer "next" t))
1981 (string-match "\\<Index\\>" node)))
1982 (Info-goto-node node))
1983 (or matches
1984 (progn
1985 (Info-goto-node orignode)
1986 (error "No `%s' in index" topic)))
1987 ;; Here it is a feature that assoc is case-sensitive.
1988 (while (setq found (assoc topic matches))
1989 (setq exact (cons found exact)
1990 matches (delq found matches)))
1991 (setq Info-index-alternatives (nconc exact (nreverse matches)))
1992 (Info-index-next 0)))))
1993
1994 (defun Info-index-next (num)
1995 "Go to the next matching index item from the last `i' command."
1996 (interactive "p")
1997 (or Info-index-alternatives
1998 (error "No previous `i' command"))
1999 (while (< num 0)
2000 (setq num (+ num (length Info-index-alternatives))))
2001 (while (> num 0)
2002 (setq Info-index-alternatives
2003 (nconc (cdr Info-index-alternatives)
2004 (list (car Info-index-alternatives)))
2005 num (1- num)))
2006 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2007 (if (> (nth 3 (car Info-index-alternatives)) 0)
2008 (forward-line (nth 3 (car Info-index-alternatives)))
2009 (forward-line 3) ; don't search in headers
2010 (let ((name (car (car Info-index-alternatives))))
2011 (Info-find-index-name name)))
2012 (message "Found `%s' in %s. %s"
2013 (car (car Info-index-alternatives))
2014 (nth 2 (car Info-index-alternatives))
2015 (if (cdr Info-index-alternatives)
2016 "(`,' tries to find next)"
2017 "(Only match)")))
2018
2019 (defun Info-find-index-name (name)
2020 "Move point to the place within the current node where NAME is defined."
2021 (let ((case-fold-search t))
2022 (if (or (re-search-forward (format
2023 "[a-zA-Z]+: %s\\( \\|$\\)"
2024 (regexp-quote name)) nil t)
2025 ;; Find a function definition with a return type.
2026 (re-search-forward (format
2027 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2028 (regexp-quote name)) nil t)
2029 (search-forward (format "`%s'" name) nil t)
2030 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2031 (search-forward
2032 (format "`%s'" (substring name 0 (match-beginning 1)))
2033 nil t))
2034 (search-forward name nil t))
2035 (beginning-of-line)
2036 (goto-char (point-min)))))
2037
2038 (defun Info-undefined ()
2039 "Make command be undefined in Info."
2040 (interactive)
2041 (ding))
2042
2043 (defun Info-help ()
2044 "Enter the Info tutorial."
2045 (interactive)
2046 (delete-other-windows)
2047 (Info-find-node "info"
2048 (if (< (window-height) 23)
2049 "Help-Small-Screen"
2050 "Help")))
2051
2052 (defun Info-summary ()
2053 "Display a brief summary of all Info commands."
2054 (interactive)
2055 (save-window-excursion
2056 (switch-to-buffer "*Help*")
2057 (setq buffer-read-only nil)
2058 (erase-buffer)
2059 (insert (documentation 'Info-mode))
2060 (help-mode)
2061 (goto-char (point-min))
2062 (let (ch flag)
2063 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2064 (message (if flag "Type Space to see more"
2065 "Type Space to return to Info"))
2066 (if (not (eq ?\ (setq ch (read-event))))
2067 (progn (setq unread-command-events (list ch)) nil)
2068 flag))
2069 (scroll-up)))
2070 (bury-buffer "*Help*")))
2071 \f
2072 (defun Info-get-token (pos start all &optional errorstring)
2073 "Return the token around POS.
2074 POS must be somewhere inside the token
2075 START is a regular expression which will match the
2076 beginning of the tokens delimited string
2077 ALL is a regular expression with a single
2078 parenthesized subpattern which is the token to be
2079 returned. E.g. '{\(.*\)}' would return any string
2080 enclosed in braces around POS.
2081 ERRORSTRING optional fourth argument, controls action on no match
2082 nil: return nil
2083 t: beep
2084 a string: signal an error, using that string."
2085 (let ((case-fold-search t))
2086 (save-excursion
2087 (goto-char pos)
2088 ;; First look for a match for START that goes across POS.
2089 (while (and (not (bobp)) (> (point) (- pos (length start)))
2090 (not (looking-at start)))
2091 (forward-char -1))
2092 ;; If we did not find one, search back for START
2093 ;; (this finds only matches that end at or before POS).
2094 (or (looking-at start)
2095 (progn
2096 (goto-char pos)
2097 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
2098 (let (found)
2099 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2100 (not (setq found (and (<= (match-beginning 0) pos)
2101 (> (match-end 0) pos))))))
2102 (if (and found (<= (match-beginning 0) pos)
2103 (> (match-end 0) pos))
2104 (match-string-no-properties 1)
2105 (cond ((null errorstring)
2106 nil)
2107 ((eq errorstring t)
2108 (beep)
2109 nil)
2110 (t
2111 (error "No %s around position %d" errorstring pos))))))))
2112
2113 (defun Info-mouse-follow-nearest-node (click)
2114 "\\<Info-mode-map>Follow a node reference near point.
2115 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2116 At end of the node's text, moves to the next node, or up if none."
2117 (interactive "e")
2118 (mouse-set-point click)
2119 (and (not (Info-try-follow-nearest-node))
2120 (save-excursion (forward-line 1) (eobp))
2121 (Info-next-preorder)))
2122
2123 (defun Info-follow-nearest-node ()
2124 "Follow a node reference near point.
2125 If point is on a reference, follow that reference. Otherwise,
2126 if point is in a menu item description, follow that menu item."
2127 (interactive)
2128 (or (Info-try-follow-nearest-node)
2129 (when (save-excursion
2130 (search-backward "\n* menu:" nil t))
2131 (save-excursion
2132 (beginning-of-line)
2133 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2134 (beginning-of-line 0))
2135 (when (looking-at "\\* +\\([^\t\n]*\\):")
2136 (Info-goto-node
2137 (Info-extract-menu-item (match-string-no-properties 1)))
2138 t)))
2139 (error "Point neither on reference nor in menu item description")))
2140
2141 ;; Common subroutine.
2142 (defun Info-try-follow-nearest-node ()
2143 "Follow a node reference near point. Return non-nil if successful."
2144 (let (node)
2145 (cond
2146 ((setq node (Info-get-token (point) "\\*note[ \n]"
2147 "\\*note[ \n]\\([^:]*\\):"))
2148 (Info-follow-reference node))
2149 ;; menu item: node name
2150 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2151 (Info-goto-node node))
2152 ;; menu item: index entry
2153 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
2154 (beginning-of-line)
2155 (forward-char 2)
2156 (setq node (Info-extract-menu-node-name))
2157 (Info-goto-node node))
2158 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2159 (Info-goto-node node))
2160 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2161 (Info-goto-node node))
2162 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2163 (Info-goto-node "Top"))
2164 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2165 (Info-goto-node node)))
2166 node))
2167 \f
2168 (defvar Info-mode-map nil
2169 "Keymap containing Info commands.")
2170 (if Info-mode-map
2171 nil
2172 (setq Info-mode-map (make-keymap))
2173 (suppress-keymap Info-mode-map)
2174 (define-key Info-mode-map "." 'beginning-of-buffer)
2175 (define-key Info-mode-map " " 'Info-scroll-up)
2176 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
2177 (define-key Info-mode-map "\t" 'Info-next-reference)
2178 (define-key Info-mode-map "\e\t" 'Info-prev-reference)
2179 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2180 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2181 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2182 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2183 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2184 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2185 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2186 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2187 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2188 (define-key Info-mode-map "0" 'undefined)
2189 (define-key Info-mode-map "?" 'Info-summary)
2190 (define-key Info-mode-map "]" 'Info-forward-node)
2191 (define-key Info-mode-map "[" 'Info-backward-node)
2192 (define-key Info-mode-map "<" 'Info-top-node)
2193 (define-key Info-mode-map ">" 'Info-final-node)
2194 (define-key Info-mode-map "b" 'beginning-of-buffer)
2195 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
2196 (define-key Info-mode-map "d" 'Info-directory)
2197 (define-key Info-mode-map "e" 'Info-edit)
2198 (define-key Info-mode-map "f" 'Info-follow-reference)
2199 (define-key Info-mode-map "g" 'Info-goto-node)
2200 (define-key Info-mode-map "h" 'Info-help)
2201 (define-key Info-mode-map "i" 'Info-index)
2202 (define-key Info-mode-map "l" 'Info-last)
2203 (define-key Info-mode-map "m" 'Info-menu)
2204 (define-key Info-mode-map "n" 'Info-next)
2205 (define-key Info-mode-map "p" 'Info-prev)
2206 (define-key Info-mode-map "q" 'Info-exit)
2207 (define-key Info-mode-map "s" 'Info-search)
2208 ;; For consistency with Rmail.
2209 (define-key Info-mode-map "\M-s" 'Info-search)
2210 (define-key Info-mode-map "\M-n" 'clone-buffer)
2211 (define-key Info-mode-map "t" 'Info-top-node)
2212 (define-key Info-mode-map "u" 'Info-up)
2213 (define-key Info-mode-map "," 'Info-index-next)
2214 (define-key Info-mode-map "\177" 'Info-scroll-down)
2215 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
2216 )
2217
2218 (defun Info-check-pointer (item)
2219 "Non-nil if ITEM is present in this node."
2220 (condition-case nil
2221 (Info-extract-pointer item)
2222 (error nil)))
2223
2224 (easy-menu-define
2225 Info-mode-menu Info-mode-map
2226 "Menu for info files."
2227 '("Info"
2228 ["Up" Info-up :active (Info-check-pointer "up")
2229 :help "Go up in the Info tree"]
2230 ["Next" Info-next :active (Info-check-pointer "next")
2231 :help "Go to the next node"]
2232 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
2233 :help "Go to the previous node"]
2234 ["Backward" Info-backward-node
2235 :help "Go backward one node, considering all as a sequence"]
2236 ["Forward" Info-forward-node
2237 :help "Go forward one node, considering all as a sequence"]
2238 ["Beginning" beginning-of-buffer
2239 :help "Go to beginning of this node"]
2240 ["Top" Info-top-node
2241 :help "Go to top node of file"]
2242 ["Final Node" Info-final-node
2243 :help "Go to final node in this file"]
2244 ("Menu Item" ["You should never see this" report-emacs-bug t])
2245 ("Reference" ["You should never see this" report-emacs-bug t])
2246 ["Search..." Info-search
2247 :help "Search for regular expression in this Info file"]
2248 ["Go to Node..." Info-goto-node
2249 :help "Go to a named node"]
2250 ["Last" Info-last :active Info-history
2251 :help "Go to the last node you were at"]
2252 ("Index..."
2253 ["Lookup a String" Info-index
2254 :help "Look for a string in the index items"]
2255 ["Next Matching Item" Info-index-next
2256 :help "Look for another occurrence of previous item"])
2257 ["Edit" Info-edit :help "Edit contents of this node"
2258 :active Info-enable-edit]
2259 ["Copy Node Name" Info-copy-current-node-name
2260 :help "Copy the name of the current node into the kill ring"]
2261 ["Exit" Info-exit :help "Stop reading Info"]))
2262
2263
2264 (defvar info-tool-bar-map
2265 (if (display-graphic-p)
2266 (let ((map (make-sparse-keymap)))
2267 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
2268 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
2269 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
2270 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
2271 (tool-bar-local-item-from-menu 'Info-last "undo" map Info-mode-map)
2272 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
2273 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
2274 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
2275 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
2276 map)))
2277
2278 (defvar Info-menu-last-node nil)
2279 ;; Last node the menu was created for.
2280 ;; Value is a list, (FILE-NAME NODE-NAME).
2281
2282 (defun Info-menu-update ()
2283 "Update the Info menu for the current node."
2284 (condition-case nil
2285 (if (or (not (eq major-mode 'Info-mode))
2286 (equal (list Info-current-file Info-current-node)
2287 Info-menu-last-node))
2288 ()
2289 ;; Update menu menu.
2290 (let* ((Info-complete-menu-buffer (current-buffer))
2291 (items (nreverse (condition-case nil
2292 (Info-complete-menu-item "" nil t)
2293 (error nil))))
2294 entries current
2295 (number 0))
2296 (while (and items (< number 9))
2297 (setq current (car items)
2298 items (cdr items)
2299 number (1+ number))
2300 (setq entries (cons `[,current
2301 (Info-menu ,current)
2302 :keys ,(format "%d" number)]
2303 entries)))
2304 (if items
2305 (setq entries (cons ["Other..." Info-menu t] entries)))
2306 (or entries
2307 (setq entries (list ["No menu" nil nil] nil :active)))
2308 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
2309 ;; Update reference menu. Code stolen from `Info-follow-reference'.
2310 (let ((items nil)
2311 str i entries current
2312 (number 0)
2313 (case-fold-search t))
2314 (save-excursion
2315 (goto-char (point-min))
2316 (while (re-search-forward "\\*note[ \n\t]*\\([^:]*\\):" nil t)
2317 (setq str (buffer-substring
2318 (match-beginning 1)
2319 (1- (point))))
2320 (setq i 0)
2321 (while (setq i (string-match "[ \n\t]+" str i))
2322 (setq str (concat (substring str 0 i) " "
2323 (substring str (match-end 0))))
2324 (setq i (1+ i)))
2325 (setq items
2326 (cons str items))))
2327 (while (and items (< number 9))
2328 (setq current (car items)
2329 items (cdr items)
2330 number (1+ number))
2331 (setq entries (cons `[,current
2332 (Info-follow-reference ,current)
2333 t]
2334 entries)))
2335 (if items
2336 (setq entries (cons ["Other..." Info-follow-reference t]
2337 entries)))
2338 (or entries
2339 (setq entries (list ["No references" nil nil] nil :active)))
2340 (easy-menu-change '("Info") "Reference" (nreverse entries)))
2341 ;; Update last seen node.
2342 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
2343 ;; Try to avoid entering infinite beep mode in case of errors.
2344 (error (ding))))
2345
2346 \f
2347 (defun Info-copy-current-node-name ()
2348 "Put the name of the current info node into the kill ring.
2349 The name of the info file is prepended to the node name in parentheses."
2350 (interactive)
2351 (unless Info-current-node
2352 (error "No current info node"))
2353 (kill-new
2354 (concat "("
2355 (file-name-nondirectory
2356 (if (stringp Info-current-file)
2357 Info-current-file
2358 (or buffer-file-name "")))
2359 ")"
2360 Info-current-node)))
2361
2362 \f
2363 ;; Info mode is suitable only for specially formatted data.
2364 (put 'Info-mode 'mode-class 'special)
2365 (put 'Info-mode 'no-clone-indirect t)
2366
2367 (defun Info-mode ()
2368 "Info mode provides commands for browsing through the Info documentation tree.
2369 Documentation in Info is divided into \"nodes\", each of which discusses
2370 one topic and contains references to other nodes which discuss related
2371 topics. Info has commands to follow the references and show you other nodes.
2372
2373 \\<Info-mode-map>\
2374 \\[Info-help] Invoke the Info tutorial.
2375 \\[Info-exit] Quit Info: reselect previously selected buffer.
2376
2377 Selecting other nodes:
2378 \\[Info-mouse-follow-nearest-node]
2379 Follow a node reference you click on.
2380 This works with menu items, cross references, and
2381 the \"next\", \"previous\" and \"up\", depending on where you click.
2382 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
2383 \\[Info-next] Move to the \"next\" node of this node.
2384 \\[Info-prev] Move to the \"previous\" node of this node.
2385 \\[Info-up] Move \"up\" from this node.
2386 \\[Info-menu] Pick menu item specified by name (or abbreviation).
2387 Picking a menu item causes another node to be selected.
2388 \\[Info-directory] Go to the Info directory node.
2389 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
2390 \\[Info-last] Move to the last node you were at.
2391 \\[Info-index] Look up a topic in this file's Index and move to that node.
2392 \\[Info-index-next] (comma) Move to the next match from a previous `i' command.
2393 \\[Info-top-node] Go to the Top node of this file.
2394 \\[Info-final-node] Go to the final node in this file.
2395 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
2396 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
2397
2398 Moving within a node:
2399 \\[Info-scroll-up] Normally, scroll forward a full screen.
2400 Once you scroll far enough in a node that its menu appears on the
2401 screen but after point, the next scroll moves into its first
2402 subnode. When after all menu items (or if there is no menu),
2403 move up to the parent node.
2404 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
2405 already visible, try to go to the previous menu entry, or up
2406 if there is none.
2407 \\[beginning-of-buffer] Go to beginning of node.
2408
2409 Advanced commands:
2410 \\[Info-exit] Quit Info: reselect previously selected buffer.
2411 \\[Info-edit] Edit contents of selected node.
2412 1 Pick first item in node's menu.
2413 2, 3, 4, 5 Pick second ... fifth item in node's menu.
2414 \\[Info-goto-node] Move to node specified by name.
2415 You may include a filename as well, as (FILENAME)NODENAME.
2416 \\[universal-argument] \\[info] Move to new Info file with completion.
2417 \\[Info-search] Search through this Info file for specified regexp,
2418 and select the node in which the next occurrence is found.
2419 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
2420 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
2421 (kill-all-local-variables)
2422 (setq major-mode 'Info-mode)
2423 (setq mode-name "Info")
2424 (setq tab-width 8)
2425 (use-local-map Info-mode-map)
2426 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
2427 (set-syntax-table text-mode-syntax-table)
2428 (setq local-abbrev-table text-mode-abbrev-table)
2429 (setq case-fold-search t)
2430 (setq buffer-read-only t)
2431 (make-local-variable 'Info-current-file)
2432 (make-local-variable 'Info-current-subfile)
2433 (make-local-variable 'Info-current-node)
2434 (make-local-variable 'Info-tag-table-marker)
2435 (setq Info-tag-table-marker (make-marker))
2436 (make-local-variable 'Info-tag-table-buffer)
2437 (setq Info-tag-table-buffer nil)
2438 (make-local-variable 'Info-history)
2439 (make-local-variable 'Info-index-alternatives)
2440 (make-local-variable 'Info-header-line)
2441 (setq header-line-format (if Info-use-header-line 'Info-header-line))
2442 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
2443 ;; This is for the sake of the invisible text we use handling titles.
2444 (make-local-variable 'line-move-ignore-invisible)
2445 (setq line-move-ignore-invisible t)
2446 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
2447 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
2448 (Info-set-mode-line)
2449 (run-hooks 'Info-mode-hook))
2450
2451 (defun Info-clone-buffer-hook ()
2452 (when (bufferp Info-tag-table-buffer)
2453 (setq Info-tag-table-buffer
2454 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
2455 (let ((m Info-tag-table-marker))
2456 (when (markerp m)
2457 (setq Info-tag-table-marker
2458 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
2459 (with-current-buffer Info-tag-table-buffer
2460 (copy-marker (marker-position m)))
2461 (make-marker))))))
2462
2463 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
2464 (set-keymap-parent map text-mode-map)
2465 (define-key map "\C-c\C-c" 'Info-cease-edit)
2466 map)
2467 "Local keymap used within `e' command of Info.")
2468
2469 ;; Info-edit mode is suitable only for specially formatted data.
2470 (put 'Info-edit-mode 'mode-class 'special)
2471
2472 (defun Info-edit-mode ()
2473 "Major mode for editing the contents of an Info node.
2474 Like text mode with the addition of `Info-cease-edit'
2475 which returns to Info mode for browsing.
2476 \\{Info-edit-map}"
2477 (use-local-map Info-edit-map)
2478 (setq major-mode 'Info-edit-mode)
2479 (setq mode-name "Info Edit")
2480 (kill-local-variable 'mode-line-buffer-identification)
2481 (setq buffer-read-only nil)
2482 (force-mode-line-update)
2483 (buffer-enable-undo (current-buffer))
2484 (run-hooks 'Info-edit-mode-hook))
2485
2486 (defun Info-edit ()
2487 "Edit the contents of this Info node.
2488 Allowed only if variable `Info-enable-edit' is non-nil."
2489 (interactive)
2490 (or Info-enable-edit
2491 (error "Editing info nodes is not enabled"))
2492 (Info-edit-mode)
2493 (message "%s" (substitute-command-keys
2494 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
2495
2496 (defun Info-cease-edit ()
2497 "Finish editing Info node; switch back to Info proper."
2498 (interactive)
2499 ;; Do this first, so nothing has changed if user C-g's at query.
2500 (and (buffer-modified-p)
2501 (y-or-n-p "Save the file? ")
2502 (save-buffer))
2503 (use-local-map Info-mode-map)
2504 (setq major-mode 'Info-mode)
2505 (setq mode-name "Info")
2506 (Info-set-mode-line)
2507 (setq buffer-read-only t)
2508 (force-mode-line-update)
2509 (and (marker-position Info-tag-table-marker)
2510 (buffer-modified-p)
2511 (message "Tags may have changed. Use Info-tagify if necessary")))
2512 \f
2513 (defvar Info-file-list-for-emacs
2514 '("ediff" "eudc" "forms" "gnus" "info" ("mh" . "mh-e")
2515 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
2516 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
2517 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
2518 ("skeleton" . "autotype") ("auto-insert" . "autotype")
2519 ("copyright" . "autotype") ("executable" . "autotype")
2520 ("time-stamp" . "autotype") ("quickurl" . "autotype")
2521 ("tempo" . "autotype") ("hippie-expand" . "autotype")
2522 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
2523 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
2524 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
2525 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
2526 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
2527 ("rfc2045" . "emacs-mime")
2528 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
2529 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
2530 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
2531 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
2532 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
2533 ("mml" . "emacs-mime"))
2534 "List of Info files that describe Emacs commands.
2535 An element can be a file name, or a list of the form (PREFIX . FILE)
2536 where PREFIX is a name prefix and FILE is the file to look in.
2537 If the element is just a file name, the file name also serves as the prefix.")
2538
2539 (defun Info-find-emacs-command-nodes (command)
2540 "Return a list of locations documenting COMMAND.
2541 The `info-file' property of COMMAND says which Info manual to search.
2542 If COMMAND has no property, the variable `Info-file-list-for-emacs'
2543 defines heuristics for which Info manual to try.
2544 The locations are of the format used in `Info-history', i.e.
2545 \(FILENAME NODENAME BUFFERPOS\)."
2546 (let ((where '())
2547 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
2548 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\.$"))
2549 (info-file "emacs")) ;default
2550 ;; Determine which info file this command is documented in.
2551 (if (get command 'info-file)
2552 (setq info-file (get command 'info-file))
2553 ;; If it doesn't say explicitly, test its name against
2554 ;; various prefixes that we know.
2555 (let ((file-list Info-file-list-for-emacs))
2556 (while file-list
2557 (let* ((elt (car file-list))
2558 (name (if (consp elt)
2559 (car elt)
2560 elt))
2561 (file (if (consp elt) (cdr elt) elt))
2562 (regexp (concat "\\`" (regexp-quote name)
2563 "\\(\\'\\|-\\)")))
2564 (if (string-match regexp (symbol-name command))
2565 (setq info-file file file-list nil))
2566 (setq file-list (cdr file-list))))))
2567 (Info-find-node info-file "Top")
2568 (or (and (search-forward "\n* menu:" nil t)
2569 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2570 (error "Info file `%s' appears to lack an index" info-file))
2571 (goto-char (match-beginning 1))
2572 ;; Bind Info-history to nil, to prevent the index nodes from
2573 ;; getting into the node history.
2574 (let ((Info-history nil)
2575 (exact nil)
2576 node found)
2577 (Info-goto-node (Info-extract-menu-node-name))
2578 (while
2579 (progn
2580 (goto-char (point-min))
2581 (while (re-search-forward cmd-desc nil t)
2582 (setq where
2583 (cons (list Info-current-file
2584 (match-string-no-properties 2)
2585 0)
2586 where)))
2587 (and (setq node (Info-extract-pointer "next" t))
2588 (string-match "\\<Index\\>" node)))
2589 (Info-goto-node node)))
2590 where))
2591
2592 ;;;###autoload
2593 (defun Info-goto-emacs-command-node (command)
2594 "Go to the Info node in the Emacs manual for command COMMAND.
2595 The command is found by looking up in Emacs manual's indices
2596 or in another manual found via COMMAND's `info-file' property or
2597 the variable `Info-file-list-for-emacs'. COMMAND must be a symbol
2598 or string."
2599 (interactive "CFind documentation for command: ")
2600 ;; If command is given as a string, convert it to a symbol.
2601 (if (stringp command)
2602 (setq command (intern command)))
2603 (or (commandp command)
2604 (signal 'wrong-type-argument (list 'commandp command)))
2605 (let ((where (Info-find-emacs-command-nodes command)))
2606 (if where
2607 (let ((num-matches (length where)))
2608 ;; Get Info running, and pop to it in another window.
2609 (save-window-excursion
2610 (info))
2611 ;; FIXME It would be cool if this could use a buffer other
2612 ;; than *info*.
2613 (pop-to-buffer "*info*")
2614 ;; Bind Info-history to nil, to prevent the last Index node
2615 ;; visited by Info-find-emacs-command-nodes from being
2616 ;; pushed onto the history.
2617 (let ((Info-history nil))
2618 (Info-find-node (car (car where))
2619 (car (cdr (car where)))))
2620 (if (> num-matches 1)
2621 (progn
2622 ;; (car where) will be pushed onto Info-history
2623 ;; when/if they go to another node. Put the other
2624 ;; nodes that were found on the history.
2625 (setq Info-history (nconc (cdr where) Info-history))
2626 (message "Found %d other entr%s. Use %s to see %s."
2627 (1- num-matches)
2628 (if (> num-matches 2) "ies" "y")
2629 (substitute-command-keys "\\[Info-last]")
2630 (if (> num-matches 2) "them" "it")))))
2631 (error "Couldn't find documentation for %s" command))))
2632
2633 ;;;###autoload
2634 (defun Info-goto-emacs-key-command-node (key)
2635 "Go to the node in the Emacs manual which describes the command bound to KEY.
2636 KEY is a string.
2637 Interactively, if the binding is `execute-extended-command', a command is read.
2638 The command is found by looking up in Emacs manual's indices
2639 or in another manual found via COMMAND's `info-file' property or
2640 the variable `Info-file-list-for-emacs'."
2641 (interactive "kFind documentation for key: ")
2642 (let ((command (key-binding key)))
2643 (cond ((null command)
2644 (message "%s is undefined" (key-description key)))
2645 ((and (interactive-p)
2646 (eq command 'execute-extended-command))
2647 (Info-goto-emacs-command-node
2648 (read-command "Find documentation for command: ")))
2649 (t
2650 (Info-goto-emacs-command-node command)))))
2651 \f
2652 (defface Info-title-1-face
2653 '((((type tty pc) (class color)) (:foreground "yellow" :weight bold))
2654 (t (:height 1.2 :inherit Info-title-2-face)))
2655 "Face for Info titles at level 1."
2656 :group 'info)
2657
2658 (defface Info-title-2-face
2659 '((((type tty pc) (class color)) (:foreground "lightblue" :weight bold))
2660 (t (:height 1.2 :inherit Info-title-3-face)))
2661 "Face for Info titles at level 2."
2662 :group 'info)
2663
2664 (defface Info-title-3-face
2665 '((((type tty pc) (class color)) (:weight bold))
2666 (t (:height 1.2 :inherit Info-title-4-face)))
2667 "Face for Info titles at level 3."
2668 :group 'info)
2669
2670 (defface Info-title-4-face
2671 '((((type tty pc) (class color)) (:weight bold))
2672 (t (:weight bold :inherit variable-pitch)))
2673 "Face for Info titles at level 4."
2674 :group 'info)
2675
2676 (defface info-menu-header
2677 '((((type tty pc))
2678 :underline t
2679 :weight bold)
2680 (t
2681 :inherit variable-pitch
2682 :weight bold))
2683 "Face for headers in Info menus."
2684 :group 'info)
2685
2686 (defun Info-fontify-menu-headers ()
2687 "Add the face `info-menu-header' to any header before a menu entry."
2688 (save-excursion
2689 (goto-char (point-min))
2690 (when (re-search-forward "\\* Menu:" nil t)
2691 (put-text-property (match-beginning 0) (match-end 0)
2692 'font-lock-face 'info-menu-header)
2693 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
2694 (put-text-property (match-beginning 1) (match-end 1)
2695 'font-lock-face 'info-menu-header)))))
2696
2697 (defvar Info-next-link-keymap
2698 (let ((keymap (make-sparse-keymap)))
2699 (define-key keymap [header-line mouse-1] 'Info-next)
2700 (define-key keymap [header-line mouse-2] 'Info-next)
2701 (define-key keymap [header-line down-mouse-1] 'ignore)
2702 (define-key keymap [mouse-2] 'Info-next)
2703 keymap)
2704 "Keymap to put on the Next link in the text or the header line.")
2705
2706 (defvar Info-prev-link-keymap
2707 (let ((keymap (make-sparse-keymap)))
2708 (define-key keymap [header-line mouse-1] 'Info-prev)
2709 (define-key keymap [header-line mouse-2] 'Info-prev)
2710 (define-key keymap [header-line down-mouse-1] 'ignore)
2711 (define-key keymap [mouse-2] 'Info-prev)
2712 keymap)
2713 "Keymap to put on the Prev link in the text or the header line.")
2714
2715
2716 (defvar Info-up-link-keymap
2717 (let ((keymap (make-sparse-keymap)))
2718 (define-key keymap [header-line mouse-1] 'Info-up)
2719 (define-key keymap [header-line mouse-2] 'Info-up)
2720 (define-key keymap [header-line down-mouse-1] 'ignore)
2721 (define-key keymap [mouse-2] 'Info-up)
2722 keymap)
2723 "Keymap to put on the Up link in the text or the header line.")
2724
2725 (defun Info-fontify-node ()
2726 ;; Only fontify the node if it hasn't already been done.
2727 (unless (let ((where (next-property-change (point-min))))
2728 (and where (not (= where (point-max)))))
2729 (save-excursion
2730 (let ((inhibit-read-only t)
2731 (case-fold-search t)
2732 paragraph-markers)
2733 (goto-char (point-min))
2734 (when (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?")
2735 (goto-char (match-end 0))
2736 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
2737 (goto-char (match-end 0))
2738 (let* ((nbeg (match-beginning 2))
2739 (nend (match-end 2))
2740 (tbeg (match-beginning 1))
2741 (tag (buffer-substring tbeg (match-end 1))))
2742 (if (string-equal tag "Node")
2743 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
2744 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
2745 (put-text-property tbeg nend 'mouse-face 'highlight)
2746 (put-text-property tbeg nend
2747 'help-echo
2748 (concat "Go to node "
2749 (buffer-substring nbeg nend)))
2750 ;; Always set up the text property keymap.
2751 ;; It will either be used in the buffer
2752 ;; or copied in the header line.
2753 (put-text-property tbeg nend 'keymap
2754 (cond
2755 ((equal tag "Prev") Info-prev-link-keymap)
2756 ((equal tag "Next") Info-next-link-keymap)
2757 ((equal tag "Up") Info-up-link-keymap))))))
2758 (when Info-use-header-line
2759 (goto-char (point-min))
2760 (let ((header-end (save-excursion (end-of-line) (point)))
2761 header)
2762 ;; If we find neither Next: nor Prev: link, show the entire
2763 ;; node header. Otherwise, don't show the File: and Node:
2764 ;; parts, to avoid wasting precious space on information that
2765 ;; is available in the mode line.
2766 (if (re-search-forward
2767 "\\(next\\|up\\|prev[ious]*\\): "
2768 header-end t)
2769 (progn
2770 (goto-char (match-beginning 1))
2771 (setq header (buffer-substring (point) header-end)))
2772 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" nil t)
2773 (setq header
2774 (concat "No next, prev or up links -- "
2775 (buffer-substring (point) header-end)))
2776 (setq header (buffer-substring (point) header-end))))
2777
2778 (put-text-property (point-min) (1+ (point-min))
2779 'header-line header)
2780 ;; Hide the part of the first line
2781 ;; that is in the header, if it is just part.
2782 (unless (bobp)
2783 ;; Hide the punctuation at the end, too.
2784 (skip-chars-backward " \t,")
2785 (put-text-property (point) header-end 'invisible t)))))
2786 (goto-char (point-min))
2787 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
2788 nil t)
2789 (let* ((c (preceding-char))
2790 (face
2791 (cond ((= c ?*) 'Info-title-1-face)
2792 ((= c ?=) 'Info-title-2-face)
2793 ((= c ?-) 'Info-title-3-face)
2794 (t 'Info-title-4-face))))
2795 (put-text-property (match-beginning 1) (match-end 1)
2796 'font-lock-face face))
2797 ;; This is a serious problem for trying to handle multiple
2798 ;; frame types at once. We want this text to be invisible
2799 ;; on frames that can display the font above.
2800 (when (memq (framep (selected-frame)) '(x pc w32 mac))
2801 (add-text-properties (match-beginning 2) (1+ (match-end 2))
2802 '(invisible t))))
2803 (goto-char (point-min))
2804 (while (re-search-forward "\\(\\*Note[ \t]*\\)\n?[ \t]*\\([^:]*\\)\\(:[^.,:(]*\\(([^)]*)[^.,:]*\\)?[,:]?\n?\\)" nil t)
2805 (unless (= (char-after (1- (match-beginning 0))) ?\") ; hack
2806 (let ((start (match-beginning 0))
2807 (next (point))
2808 (hide-tag Info-hide-note-references)
2809 other-tag)
2810 (when hide-tag
2811 ;; *Note is often used where *note should have been
2812 (goto-char start)
2813 (skip-syntax-backward " ")
2814 (setq other-tag
2815 (cond
2816 ((or (<= (point) (point-min))
2817 (memq (char-after (1- (point))) '( ?\. ?! )))
2818 "See ")
2819 ((memq (char-after (1- (point))) '( ?\( ?\[ ?\{ ?\, ?\; ?\: ))
2820 "see ")
2821 (t nil)))
2822 (goto-char next))
2823 (if hide-tag
2824 (add-text-properties (match-beginning 1) (match-end 1)
2825 '(invisible t)))
2826 (add-text-properties (match-beginning 2) (match-end 2)
2827 '(font-lock-face info-xref
2828 mouse-face highlight
2829 help-echo "mouse-2: go to this node"))
2830 (when (eq Info-hide-note-references t)
2831 (add-text-properties (match-beginning 3) (match-end 3)
2832 '(invisible t)))
2833 (when other-tag
2834 (save-excursion
2835 (goto-char (match-beginning 1))
2836 (insert other-tag)))
2837 (when (or hide-tag (eq Info-hide-note-references t))
2838 (setq paragraph-markers (cons (set-marker (make-marker) start)
2839 paragraph-markers))))))
2840
2841 (let ((fill-nobreak-invisible t))
2842 (goto-char (point-max))
2843 (while paragraph-markers
2844 (let ((m (car paragraph-markers)))
2845 (setq paragraph-markers (cdr paragraph-markers))
2846 (when (< m (point))
2847 (goto-char m)
2848 (fill-paragraph nil)
2849 (backward-paragraph 1))
2850 (set-marker m nil))))
2851
2852 (goto-char (point-min))
2853 (if (and (search-forward "\n* Menu:" nil t)
2854 (not (string-match "\\<Index\\>" Info-current-node))
2855 ;; Don't take time to annotate huge menus
2856 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
2857 (let ((n 0)
2858 cont)
2859 (while (re-search-forward "^\\* +\\([^:\t\n]*\\)\\(:[^.,:(]*\\(([^)]*)[^.,:]*\\)?[,:.][ \t]*\\)" nil t)
2860 (setq n (1+ n))
2861 (if (zerop (% n 3)) ; visual aids to help with 1-9 keys
2862 (put-text-property (match-beginning 0)
2863 (1+ (match-beginning 0))
2864 'font-lock-face 'info-menu-5))
2865 (add-text-properties (match-beginning 1) (match-end 1)
2866 '(font-lock-face info-xref
2867 mouse-face highlight
2868 help-echo "mouse-2: go to this node"))
2869 (when (eq Info-hide-note-references t)
2870 (add-text-properties (match-beginning 2) (match-end 2)
2871 (list 'display
2872 (make-string (max 2 (- 22 (- (match-end 1) (match-beginning 1)))) ? )))
2873 (setq cont (looking-at "[ \t]*[^\n]")))
2874 (if (eq Info-hide-note-references t)
2875 (while (and (= (forward-line 1) 0)
2876 (looking-at "\\([ \t]+\\)[^*\n]"))
2877 (add-text-properties (match-beginning 1) (match-end 1)
2878 (list 'display (make-string (+ 22 (if cont 4 2)) ? )))
2879 (setq cont t))))))
2880
2881 (Info-fontify-menu-headers)
2882 (set-buffer-modified-p nil)))))
2883 \f
2884
2885 ;; When an Info buffer is killed, make sure the associated tags buffer
2886 ;; is killed too.
2887 (defun Info-kill-buffer ()
2888 (and (eq major-mode 'Info-mode)
2889 Info-tag-table-buffer
2890 (kill-buffer Info-tag-table-buffer)))
2891
2892 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
2893
2894 ;;; Speedbar support:
2895 ;; These functions permit speedbar to display the "tags" in the
2896 ;; current info node.
2897 (eval-when-compile (require 'speedbar))
2898
2899 (defvar Info-speedbar-key-map nil
2900 "Keymap used when in the info display mode.")
2901
2902 (defun Info-install-speedbar-variables ()
2903 "Install those variables used by speedbar to enhance Info."
2904 (if Info-speedbar-key-map
2905 nil
2906 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
2907
2908 ;; Basic tree features
2909 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
2910 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
2911 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
2912 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
2913 )
2914
2915 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
2916 Info-speedbar-key-map
2917 Info-speedbar-hierarchy-buttons)))
2918
2919 (defvar Info-speedbar-menu-items
2920 '(["Browse Node" speedbar-edit-line t]
2921 ["Expand Node" speedbar-expand-line
2922 (save-excursion (beginning-of-line)
2923 (looking-at "[0-9]+: *.\\+. "))]
2924 ["Contract Node" speedbar-contract-line
2925 (save-excursion (beginning-of-line)
2926 (looking-at "[0-9]+: *.-. "))]
2927 )
2928 "Additional menu-items to add to speedbar frame.")
2929
2930 ;; Make sure our special speedbar major mode is loaded
2931 (if (featurep 'speedbar)
2932 (Info-install-speedbar-variables)
2933 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
2934
2935 ;;; Info hierarchy display method
2936 ;;;###autoload
2937 (defun Info-speedbar-browser ()
2938 "Initialize speedbar to display an info node browser.
2939 This will add a speedbar major display mode."
2940 (interactive)
2941 (require 'speedbar)
2942 ;; Make sure that speedbar is active
2943 (speedbar-frame-mode 1)
2944 ;; Now, throw us into Info mode on speedbar.
2945 (speedbar-change-initial-expansion-list "Info")
2946 )
2947
2948 (eval-when-compile (defvar speedbar-attached-frame))
2949
2950 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
2951 "Display an Info directory hierarchy in speedbar.
2952 DIRECTORY is the current directory in the attached frame.
2953 DEPTH is the current indentation depth.
2954 NODE is an optional argument that is used to represent the
2955 specific node to expand."
2956 (if (and (not node)
2957 (save-excursion (goto-char (point-min))
2958 (let ((case-fold-search t))
2959 (looking-at "Info Nodes:"))))
2960 ;; Update our "current node" maybe?
2961 nil
2962 ;; We cannot use the generic list code, that depends on all leaves
2963 ;; being known at creation time.
2964 (if (not node)
2965 (speedbar-with-writable (insert "Info Nodes:\n")))
2966 (let ((completions nil)
2967 (cf (selected-frame)))
2968 (select-frame speedbar-attached-frame)
2969 (save-window-excursion
2970 (setq completions
2971 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
2972 (select-frame cf)
2973 (if completions
2974 (speedbar-with-writable
2975 (while completions
2976 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
2977 (cdr (car completions))
2978 (car (car completions))
2979 'Info-speedbar-goto-node
2980 (cdr (car completions))
2981 'info-xref depth)
2982 (setq completions (cdr completions)))
2983 t)
2984 nil))))
2985
2986 (defun Info-speedbar-goto-node (text node indent)
2987 "When user clicks on TEXT, go to an info NODE.
2988 The INDENT level is ignored."
2989 (select-frame speedbar-attached-frame)
2990 (let* ((buff (or (get-buffer "*info*")
2991 (progn (info) (get-buffer "*info*"))))
2992 (bwin (get-buffer-window buff 0)))
2993 (if bwin
2994 (progn
2995 (select-window bwin)
2996 (raise-frame (window-frame bwin)))
2997 (if speedbar-power-click
2998 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
2999 (select-frame speedbar-attached-frame)
3000 (switch-to-buffer buff)))
3001 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
3002 (file (match-string 1 node))
3003 (node (match-string 2 node)))
3004 (Info-find-node file node)
3005 ;; If we do a find-node, and we were in info mode, restore
3006 ;; the old default method. Once we are in info mode, it makes
3007 ;; sense to return to whatever method the user was using before.
3008 (if (string= speedbar-initial-expansion-list-name "Info")
3009 (speedbar-change-initial-expansion-list
3010 speedbar-previously-used-expansion-list-name)))))
3011
3012 (defun Info-speedbar-expand-node (text token indent)
3013 "Expand the node the user clicked on.
3014 TEXT is the text of the button we clicked on, a + or - item.
3015 TOKEN is data related to this node (NAME . FILE).
3016 INDENT is the current indentation depth."
3017 (cond ((string-match "+" text) ;we have to expand this file
3018 (speedbar-change-expand-button-char ?-)
3019 (if (speedbar-with-writable
3020 (save-excursion
3021 (end-of-line) (forward-char 1)
3022 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
3023 (speedbar-change-expand-button-char ?-)
3024 (speedbar-change-expand-button-char ??)))
3025 ((string-match "-" text) ;we have to contract this node
3026 (speedbar-change-expand-button-char ?+)
3027 (speedbar-delete-subblock indent))
3028 (t (error "Ooops... not sure what to do")))
3029 (speedbar-center-buffer-smartly))
3030
3031 (defun Info-speedbar-fetch-file-nodes (nodespec)
3032 "Fetch the subnodes from the info NODESPEC.
3033 NODESPEC is a string of the form: (file)node.
3034 Optional THISFILE represends the filename of"
3035 (save-excursion
3036 ;; Set up a buffer we can use to fake-out Info.
3037 (set-buffer (get-buffer-create "*info-browse-tmp*"))
3038 (if (not (equal major-mode 'Info-mode))
3039 (Info-mode))
3040 ;; Get the node into this buffer
3041 (let ((junk (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
3042 (file (match-string 1 nodespec))
3043 (node (match-string 2 nodespec)))
3044 (Info-find-node file node))
3045 ;; Scan the created buffer
3046 (goto-char (point-min))
3047 (let ((completions nil)
3048 (case-fold-search t)
3049 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
3050 (match-string 1 nodespec))))
3051 ;; Always skip the first one...
3052 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3053 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
3054 (let ((name (match-string 1)))
3055 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
3056 (setq name (cons name (match-string 1)))
3057 (if (looking-at " *\\(([^)]+)\\)\\.")
3058 (setq name (cons name (concat (match-string 1) "Top")))
3059 (if (looking-at " \\([^.]+\\).")
3060 (setq name
3061 (cons name (concat "(" thisfile ")" (match-string 1))))
3062 (setq name (cons name (concat "(" thisfile ")" name))))))
3063 (setq completions (cons name completions))))
3064 (nreverse completions))))
3065
3066 ;;; Info mode node listing
3067 (defun Info-speedbar-buttons (buffer)
3068 "Create a speedbar display to help navigation in an Info file.
3069 BUFFER is the buffer speedbar is requesting buttons for."
3070 (if (save-excursion (goto-char (point-min))
3071 (let ((case-fold-search t))
3072 (not (looking-at "Info Nodes:"))))
3073 (erase-buffer))
3074 (Info-speedbar-hierarchy-buttons nil 0)
3075 )
3076
3077 (dolist (mess '("^Node has no Previous$"
3078 "^No menu in this node$"
3079 "^Node has no Next$"
3080 "^No cross-references in this node^"
3081 search-failed
3082 "^No \".*\" in index$"))
3083 (add-to-list 'debug-ignored-errors mess))
3084
3085 (provide 'info)
3086
3087 ;;; info.el ends here