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