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