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