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