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