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