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