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