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