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