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