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