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