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