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