]> code.delx.au - gnu-emacs/blob - lisp/info.el
2005-09-24 Emilio C. Lopes <eclig@gmx.net>
[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 (save-excursion (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)
1776 nil t)
1777 "\\b")
1778 bound noerror count
1779 (unless isearch-forward 'backward))
1780 (Info-search (if isearch-regexp string (regexp-quote string))
1781 bound noerror count
1782 (unless isearch-forward 'backward))
1783 (point)))
1784 (let ((isearch-search-fun-function nil))
1785 (isearch-search-fun))))
1786
1787 (defun Info-isearch-wrap ()
1788 (if Info-isearch-search
1789 (if Info-isearch-initial-node
1790 (progn
1791 (if isearch-forward (Info-top-node) (Info-final-node))
1792 (goto-char (if isearch-forward (point-min) (point-max))))
1793 (setq Info-isearch-initial-node Info-current-node)
1794 (setq isearch-wrapped nil))
1795 (goto-char (if isearch-forward (point-min) (point-max)))))
1796
1797 (defun Info-isearch-push-state ()
1798 `(lambda (cmd)
1799 (Info-isearch-pop-state cmd ,Info-current-file ,Info-current-node)))
1800
1801 (defun Info-isearch-pop-state (cmd file node)
1802 (or (and (string= Info-current-file file)
1803 (string= Info-current-node node))
1804 (progn (Info-find-node file node) (sit-for 0))))
1805
1806 (defun Info-isearch-start ()
1807 (setq Info-isearch-initial-node nil))
1808 \f
1809 (defun Info-extract-pointer (name &optional errorname)
1810 "Extract the value of the node-pointer named NAME.
1811 If there is none, use ERRORNAME in the error message;
1812 if ERRORNAME is nil, just return nil."
1813 ;; Bind this in case the user sets it to nil.
1814 (let ((case-fold-search t))
1815 (save-excursion
1816 (goto-char (point-min))
1817 (let ((bound (point)))
1818 (forward-line 1)
1819 (cond ((re-search-backward
1820 (concat name ":" (Info-following-node-name-re)) bound t)
1821 (match-string 1))
1822 ((not (eq errorname t))
1823 (error "Node has no %s"
1824 (capitalize (or errorname name)))))))))
1825
1826 (defun Info-following-node-name-re (&optional allowedchars)
1827 "Return a regexp matching a node name.
1828 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1829 saying which chars may appear in the node name.
1830 Submatch 1 is the complete node name.
1831 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1832 Submatch 3 is the local part of the node name.
1833 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1834 (concat "[ \t]*" ;Skip leading space.
1835 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1836 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
1837 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
1838 "\\|\\)\\)")) ;Allow empty node names.
1839
1840 ;;; For compatibility; other files have used this name.
1841 (defun Info-following-node-name ()
1842 (and (looking-at (Info-following-node-name-re))
1843 (match-string 1)))
1844
1845 (defun Info-next ()
1846 "Go to the next node of this node."
1847 (interactive)
1848 (Info-goto-node (Info-extract-pointer "next")))
1849
1850 (defun Info-prev ()
1851 "Go to the previous node of this node."
1852 (interactive)
1853 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1854
1855 (defun Info-up (&optional same-file)
1856 "Go to the superior node of this node.
1857 If SAME-FILE is non-nil, do not move to a different Info file."
1858 (interactive)
1859 (let ((old-node Info-current-node)
1860 (old-file Info-current-file)
1861 (node (Info-extract-pointer "up")) p)
1862 (and (or same-file (not (stringp Info-current-file)))
1863 (string-match "^(" node)
1864 (error "Up node is in another Info file"))
1865 (Info-goto-node node)
1866 (setq p (point))
1867 (goto-char (point-min))
1868 (if (and (search-forward "\n* Menu:" nil t)
1869 (re-search-forward
1870 (if (string-equal old-node "Top")
1871 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
1872 (concat "\n\\* +\\(" (regexp-quote old-node)
1873 ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
1874 nil t))
1875 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
1876 (goto-char p)
1877 (Info-restore-point Info-history))))
1878
1879 (defun Info-history-back ()
1880 "Go back in the history to the last node visited."
1881 (interactive)
1882 (or Info-history
1883 (error "This is the first Info node you looked at"))
1884 (let ((history-forward
1885 (cons (list Info-current-file Info-current-node (point))
1886 Info-history-forward))
1887 filename nodename opoint)
1888 (setq filename (car (car Info-history)))
1889 (setq nodename (car (cdr (car Info-history))))
1890 (setq opoint (car (cdr (cdr (car Info-history)))))
1891 (setq Info-history (cdr Info-history))
1892 (Info-find-node filename nodename)
1893 (setq Info-history (cdr Info-history))
1894 (setq Info-history-forward history-forward)
1895 (goto-char opoint)))
1896
1897 (defalias 'Info-last 'Info-history-back)
1898
1899 (defun Info-history-forward ()
1900 "Go forward in the history of visited nodes."
1901 (interactive)
1902 (or Info-history-forward
1903 (error "This is the last Info node you looked at"))
1904 (let ((history-forward (cdr Info-history-forward))
1905 filename nodename opoint)
1906 (setq filename (car (car Info-history-forward)))
1907 (setq nodename (car (cdr (car Info-history-forward))))
1908 (setq opoint (car (cdr (cdr (car Info-history-forward)))))
1909 (Info-find-node filename nodename)
1910 (setq Info-history-forward history-forward)
1911 (goto-char opoint)))
1912
1913 ;;;###autoload
1914 (defun Info-directory ()
1915 "Go to the Info directory node."
1916 (interactive)
1917 (Info-find-node "dir" "top"))
1918 \f
1919 (defun Info-history ()
1920 "Go to a node with a menu of visited nodes."
1921 (interactive)
1922 (let ((curr-file Info-current-file)
1923 (curr-node Info-current-node)
1924 p)
1925 (with-current-buffer (get-buffer-create " *info-history*")
1926 (let ((inhibit-read-only t))
1927 (erase-buffer)
1928 (goto-char (point-min))
1929 (insert "\n\^_\nFile: history, Node: Top, Up: (dir)\n\n")
1930 (insert "Recently Visited Nodes\n**********************\n\n")
1931 (insert "* Menu:\n\n")
1932 (let ((hl (delete '("history" "Top") Info-history-list)))
1933 (while hl
1934 (let ((file (nth 0 (car hl)))
1935 (node (nth 1 (car hl))))
1936 (if (and (string-equal file curr-file)
1937 (string-equal node curr-node))
1938 (setq p (point)))
1939 (insert "* " node ": (" (file-name-nondirectory file)
1940 ")" node ".\n"))
1941 (setq hl (cdr hl))))))
1942 (Info-find-node "history" "Top")
1943 (goto-char (or p (point-min)))))
1944
1945 (defun Info-toc ()
1946 "Go to a node with table of contents of the current Info file.
1947 Table of contents is created from the tree structure of menus."
1948 (interactive)
1949 (let ((curr-file (substring-no-properties Info-current-file))
1950 (curr-node (substring-no-properties Info-current-node))
1951 p)
1952 (with-current-buffer (get-buffer-create " *info-toc*")
1953 (let ((inhibit-read-only t)
1954 (node-list (Info-build-toc curr-file)))
1955 (erase-buffer)
1956 (goto-char (point-min))
1957 (insert "\n\^_\nFile: toc, Node: Top, Up: (dir)\n\n")
1958 (insert "Table of Contents\n*****************\n\n")
1959 (insert "*Note Top: (" curr-file ")Top.\n")
1960 (Info-insert-toc
1961 (nth 2 (assoc "Top" node-list)) ; get Top nodes
1962 node-list 0 curr-file))
1963 (if (not (bobp))
1964 (let ((Info-hide-note-references 'hide)
1965 (Info-fontify-visited-nodes nil))
1966 (Info-mode)
1967 (setq Info-current-file "toc" Info-current-node "Top")
1968 (goto-char (point-min))
1969 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t)
1970 (point-min))
1971 (point-max))
1972 (Info-fontify-node)
1973 (widen)))
1974 (goto-char (point-min))
1975 (if (setq p (search-forward (concat "*Note " curr-node ":") nil t))
1976 (setq p (- p (length curr-node) 2))))
1977 (Info-find-node "toc" "Top")
1978 (goto-char (or p (point-min)))))
1979
1980 (defun Info-insert-toc (nodes node-list level curr-file)
1981 "Insert table of contents with references to nodes."
1982 (let ((section "Top"))
1983 (while nodes
1984 (let ((node (assoc (car nodes) node-list)))
1985 (unless (member (nth 1 node) (list nil section))
1986 (insert (setq section (nth 1 node)) "\n"))
1987 (insert (make-string level ?\t))
1988 (insert "*Note " (car nodes) ": (" curr-file ")" (car nodes) ".\n")
1989 (Info-insert-toc (nth 2 node) node-list (1+ level) curr-file)
1990 (setq nodes (cdr nodes))))))
1991
1992 (defun Info-build-toc (file)
1993 "Build table of contents from menus of Info FILE and its subfiles."
1994 (with-temp-buffer
1995 (let* ((file (and (stringp file) (Info-find-file file)))
1996 (default-directory (or (and (stringp file)
1997 (file-name-directory file))
1998 default-directory))
1999 (main-file (and (stringp file) file))
2000 (sections '(("Top" "Top")))
2001 nodes subfiles)
2002 (while (or main-file subfiles)
2003 (or main-file (message "Searching subfile %s..." (car subfiles)))
2004 (erase-buffer)
2005 (info-insert-file-contents (or main-file (car subfiles)))
2006 (goto-char (point-min))
2007 (while (and (search-forward "\n\^_\nFile:" nil 'move)
2008 (search-forward "Node: " nil 'move))
2009 (let ((nodename (substring-no-properties (Info-following-node-name)))
2010 (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
2011 (point-max)) 2))
2012 (section "Top")
2013 menu-items)
2014 (when (and (not (Info-index-node nodename file))
2015 (re-search-forward "^\\* Menu:" bound t))
2016 (forward-line 1)
2017 (beginning-of-line)
2018 (setq bound (or (and (equal nodename "Top")
2019 (save-excursion
2020 (re-search-forward
2021 "^[ \t-]*The Detailed Node Listing" nil t)))
2022 bound))
2023 (while (< (point) bound)
2024 (cond
2025 ;; Menu item line
2026 ((looking-at "^\\* +[^:]+:")
2027 (beginning-of-line)
2028 (forward-char 2)
2029 (let ((menu-node-name (substring-no-properties
2030 (Info-extract-menu-node-name))))
2031 (setq menu-items (cons menu-node-name menu-items))
2032 (if (equal nodename "Top")
2033 (setq sections
2034 (cons (list menu-node-name section) sections)))))
2035 ;; Other non-empty strings in the Top node are section names
2036 ((and (equal nodename "Top")
2037 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2038 (setq section (match-string-no-properties 1))))
2039 (forward-line 1)
2040 (beginning-of-line)))
2041 (setq nodes (cons (list nodename
2042 (cadr (assoc nodename sections))
2043 (nreverse menu-items))
2044 nodes))
2045 (goto-char bound)))
2046 (if main-file
2047 (save-excursion
2048 (goto-char (point-min))
2049 (if (search-forward "\n\^_\nIndirect:" nil t)
2050 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2051 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2052 (setq subfiles (cons (match-string-no-properties 1)
2053 subfiles)))))
2054 (setq subfiles (nreverse subfiles)
2055 main-file nil))
2056 (setq subfiles (cdr subfiles))))
2057 (message "")
2058 (nreverse nodes))))
2059 \f
2060 (defun Info-follow-reference (footnotename &optional fork)
2061 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2062 FOOTNOTENAME may be an abbreviation of the reference name.
2063 If FORK is non-nil (interactively with a prefix arg), show the node in
2064 a new Info buffer. If FORK is a string, it is the name to use for the
2065 new buffer."
2066 (interactive
2067 (let ((completion-ignore-case t)
2068 (case-fold-search t)
2069 completions default alt-default (start-point (point)) str i bol eol)
2070 (save-excursion
2071 ;; Store end and beginning of line.
2072 (end-of-line)
2073 (setq eol (point))
2074 (beginning-of-line)
2075 (setq bol (point))
2076
2077 (goto-char (point-min))
2078 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
2079 (setq str (match-string-no-properties 1))
2080 ;; See if this one should be the default.
2081 (and (null default)
2082 (<= (match-beginning 0) start-point)
2083 (<= start-point (point))
2084 (setq default t))
2085 ;; See if this one should be the alternate default.
2086 (and (null alt-default)
2087 (and (<= bol (match-beginning 0))
2088 (<= (point) eol))
2089 (setq alt-default t))
2090 (setq i 0)
2091 (while (setq i (string-match "[ \n\t]+" str i))
2092 (setq str (concat (substring str 0 i) " "
2093 (substring str (match-end 0))))
2094 (setq i (1+ i)))
2095 ;; Record as a completion and perhaps as default.
2096 (if (eq default t) (setq default str))
2097 (if (eq alt-default t) (setq alt-default str))
2098 ;; Don't add this string if it's a duplicate.
2099 (or (assoc-string str completions t)
2100 (push str completions))))
2101 ;; If no good default was found, try an alternate.
2102 (or default
2103 (setq default alt-default))
2104 ;; If only one cross-reference found, then make it default.
2105 (if (eq (length completions) 1)
2106 (setq default (car completions)))
2107 (if completions
2108 (let ((input (completing-read (if default
2109 (concat
2110 "Follow reference named (default "
2111 default "): ")
2112 "Follow reference named: ")
2113 completions nil t)))
2114 (list (if (equal input "")
2115 default input) current-prefix-arg))
2116 (error "No cross-references in this node"))))
2117
2118 (unless footnotename
2119 (error "No reference was specified"))
2120
2121 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
2122 (case-fold-search t))
2123 (while (setq i (string-match " " str i))
2124 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
2125 (setq i (+ i 6)))
2126 (save-excursion
2127 ;; Move point to the beginning of reference if point is on reference
2128 (or (looking-at "\\*note[ \n\t]+")
2129 (and (looking-back "\\*note[ \n\t]+")
2130 (goto-char (match-beginning 0)))
2131 (if (and (save-excursion
2132 (goto-char (+ (point) 5)) ; skip a possible *note
2133 (re-search-backward "\\*note[ \n\t]+" nil t)
2134 (looking-at str))
2135 (<= (point) (match-end 0)))
2136 (goto-char (match-beginning 0))))
2137 ;; Go to the reference closest to point
2138 (let ((next-ref (save-excursion (and (re-search-forward str nil t)
2139 (+ (match-beginning 0) 5))))
2140 (prev-ref (save-excursion (and (re-search-backward str nil t)
2141 (+ (match-beginning 0) 5)))))
2142 (goto-char (cond ((and next-ref prev-ref)
2143 (if (< (abs (- next-ref (point)))
2144 (abs (- prev-ref (point))))
2145 next-ref prev-ref))
2146 ((or next-ref prev-ref))
2147 ((error "No cross-reference named %s" footnotename))))
2148 (setq target (Info-extract-menu-node-name t))))
2149 (while (setq i (string-match "[ \t\n]+" target i))
2150 (setq target (concat (substring target 0 i) " "
2151 (substring target (match-end 0))))
2152 (setq i (+ i 1)))
2153 (Info-goto-node target fork)))
2154
2155 (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2156 ;; We allow newline because this is also used in Info-follow-reference,
2157 ;; where the xref name might be wrapped over two lines.
2158 "Regexp that matches a menu entry name upto but not including the colon.
2159 Because of ambiguities, this should be concatenated with something like
2160 `:' and `Info-following-node-name-re'.")
2161
2162 (defun Info-extract-menu-node-name (&optional multi-line index-node)
2163 (skip-chars-forward " \t\n")
2164 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
2165 (Info-following-node-name-re
2166 (cond
2167 (index-node "^,\t\n")
2168 (multi-line "^.,\t")
2169 (t "^.,\t\n")))
2170 "\\)"
2171 (if index-node
2172 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2173 "")))
2174 (if index-node
2175 (setq Info-point-loc
2176 (if (match-beginning 5)
2177 (string-to-number (match-string 5))
2178 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))
2179 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2180 ;;; (setq Info-point-loc
2181 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2182 )
2183 (replace-regexp-in-string
2184 "[ \n]+" " "
2185 (or (match-string 2)
2186 ;; If the node name is the menu entry name (using `entry::').
2187 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))))
2188
2189 ;; No one calls this.
2190 ;;(defun Info-menu-item-sequence (list)
2191 ;; (while list
2192 ;; (Info-menu (car list))
2193 ;; (setq list (cdr list))))
2194
2195 (defvar Info-complete-menu-buffer)
2196 (defvar Info-complete-next-re nil)
2197 (defvar Info-complete-nodes nil)
2198 (defvar Info-complete-cache nil)
2199
2200 (defconst Info-node-spec-re
2201 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2202 "Regexp to match the text after a : until the terminating `.'.")
2203
2204 (defun Info-complete-menu-item (string predicate action)
2205 ;; This uses two dynamically bound variables:
2206 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2207 ;; is the menu of items we're trying to complete.
2208 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2209 ;; also look for menu items in subsequent nodes as long as those
2210 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2211 ;; not used.
2212 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2213 ;; also look for menu items in these nodes. This feature is currently
2214 ;; only used for completion in Info-index.
2215
2216 ;; Note that `Info-complete-menu-buffer' could be current already,
2217 ;; so we want to save point.
2218 (save-excursion
2219 (set-buffer Info-complete-menu-buffer)
2220 (let ((completion-ignore-case t)
2221 (case-fold-search t)
2222 (orignode Info-current-node)
2223 nextnode)
2224 (goto-char (point-min))
2225 (search-forward "\n* Menu:")
2226 (if (not (memq action '(nil t)))
2227 (re-search-forward
2228 (concat "\n\\* +" (regexp-quote string) ":") nil t)
2229 (let ((pattern (concat "\n\\* +\\("
2230 (regexp-quote string)
2231 Info-menu-entry-name-re "\\):" Info-node-spec-re))
2232 completions)
2233 ;; Check the cache.
2234 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
2235 (equal (nth 1 Info-complete-cache) Info-current-node)
2236 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
2237 (equal (nth 5 Info-complete-cache) Info-complete-nodes)
2238 (let ((prev (nth 3 Info-complete-cache)))
2239 (eq t (compare-strings string 0 (length prev)
2240 prev 0 nil t))))
2241 ;; We can reuse the previous list.
2242 (setq completions (nth 4 Info-complete-cache))
2243 ;; The cache can't be used.
2244 (while
2245 (progn
2246 (while (re-search-forward pattern nil t)
2247 (push (match-string-no-properties 1)
2248 completions))
2249 ;; Check subsequent nodes if applicable.
2250 (or (and Info-complete-next-re
2251 (setq nextnode (Info-extract-pointer "next" t))
2252 (string-match Info-complete-next-re nextnode))
2253 (and Info-complete-nodes
2254 (setq Info-complete-nodes (cdr Info-complete-nodes)
2255 nextnode (car Info-complete-nodes)))))
2256 (Info-goto-node nextnode))
2257 ;; Go back to the start node (for the next completion).
2258 (unless (equal Info-current-node orignode)
2259 (Info-goto-node orignode))
2260 ;; Update the cache.
2261 (set (make-local-variable 'Info-complete-cache)
2262 (list Info-current-file Info-current-node
2263 Info-complete-next-re string completions
2264 Info-complete-nodes)))
2265 (if action
2266 (all-completions string completions predicate)
2267 (try-completion string completions predicate)))))))
2268
2269
2270 (defun Info-menu (menu-item &optional fork)
2271 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2272 The menu item should one of those listed in the current node's menu.
2273 Completion is allowed, and the default menu item is the one point is on.
2274 If FORK is non-nil (interactively with a prefix arg), show the node in
2275 a new Info buffer. If FORK is a string, it is the name to use for the
2276 new buffer."
2277 (interactive
2278 (let ((completions '())
2279 ;; If point is within a menu item, use that item as the default
2280 (default nil)
2281 (p (point))
2282 beg
2283 (last nil)
2284 (case-fold-search t))
2285 (save-excursion
2286 (goto-char (point-min))
2287 (if (not (search-forward "\n* menu:" nil t))
2288 (error "No menu in this node"))
2289 (setq beg (point))
2290 (and (< (point) p)
2291 (save-excursion
2292 (goto-char p)
2293 (end-of-line)
2294 (if (re-search-backward (concat "\n\\* +\\("
2295 Info-menu-entry-name-re
2296 "\\):") beg t)
2297 (setq default (match-string-no-properties 1))))))
2298 (let ((item nil))
2299 (while (null item)
2300 (setq item (let ((completion-ignore-case t)
2301 (Info-complete-menu-buffer (current-buffer)))
2302 (completing-read (if default
2303 (format "Menu item (default %s): "
2304 default)
2305 "Menu item: ")
2306 'Info-complete-menu-item nil t)))
2307 ;; we rely on the fact that completing-read accepts an input
2308 ;; of "" even when the require-match argument is true and ""
2309 ;; is not a valid possibility
2310 (if (string= item "")
2311 (if default
2312 (setq item default)
2313 ;; ask again
2314 (setq item nil))))
2315 (list item current-prefix-arg))))
2316 ;; there is a problem here in that if several menu items have the same
2317 ;; name you can only go to the node of the first with this command.
2318 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
2319
2320 (defun Info-extract-menu-item (menu-item)
2321 (setq menu-item (regexp-quote menu-item))
2322 (let ((case-fold-search t))
2323 (save-excursion
2324 (let ((case-fold-search t))
2325 (goto-char (point-min))
2326 (or (search-forward "\n* menu:" nil t)
2327 (error "No menu in this node"))
2328 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
2329 (re-search-forward (concat "\n\\* +" menu-item) nil t)
2330 (error "No such item in menu"))
2331 (beginning-of-line)
2332 (forward-char 2)
2333 (Info-extract-menu-node-name nil (Info-index-node))))))
2334
2335 ;; If COUNT is nil, use the last item in the menu.
2336 (defun Info-extract-menu-counting (count)
2337 (let ((case-fold-search t))
2338 (save-excursion
2339 (let ((case-fold-search t))
2340 (goto-char (point-min))
2341 (or (search-forward "\n* menu:" nil t)
2342 (error "No menu in this node"))
2343 (if count
2344 (or (search-forward "\n* " nil t count)
2345 (error "Too few items in menu"))
2346 (while (search-forward "\n* " nil t)
2347 nil))
2348 (Info-extract-menu-node-name nil (Info-index-node))))))
2349
2350 (defun Info-nth-menu-item ()
2351 "Go to the node of the Nth menu item.
2352 N is the digit argument used to invoke this command."
2353 (interactive)
2354 (Info-goto-node
2355 (Info-extract-menu-counting
2356 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
2357
2358 (defun Info-top-node ()
2359 "Go to the Top node of this file."
2360 (interactive)
2361 (Info-goto-node "Top"))
2362
2363 (defun Info-final-node ()
2364 "Go to the final node in this file."
2365 (interactive)
2366 (Info-goto-node "Top")
2367 (let ((Info-history nil)
2368 (case-fold-search t))
2369 ;; Go to the last node in the menu of Top.
2370 (Info-goto-node (Info-extract-menu-counting nil))
2371 ;; If the last node in the menu is not last in pointer structure,
2372 ;; move forward until we can't go any farther.
2373 (while (Info-forward-node t t) nil)
2374 ;; Then keep moving down to last subnode, unless we reach an index.
2375 (while (and (not (Info-index-node))
2376 (save-excursion (search-forward "\n* Menu:" nil t)))
2377 (Info-goto-node (Info-extract-menu-counting nil)))))
2378
2379 (defun Info-forward-node (&optional not-down no-error)
2380 "Go forward one node, considering all nodes as forming one sequence."
2381 (interactive)
2382 (goto-char (point-min))
2383 (forward-line 1)
2384 (let ((case-fold-search t))
2385 ;; three possibilities, in order of priority:
2386 ;; 1. next node is in a menu in this node (but not in an index)
2387 ;; 2. next node is next at same level
2388 ;; 3. next node is up and next
2389 (cond ((and (not not-down)
2390 (save-excursion (search-forward "\n* menu:" nil t))
2391 (not (Info-index-node)))
2392 (Info-goto-node (Info-extract-menu-counting 1))
2393 t)
2394 ((save-excursion (search-backward "next:" nil t))
2395 (Info-next)
2396 t)
2397 ((and (save-excursion (search-backward "up:" nil t))
2398 ;; Use string-equal, not equal, to ignore text props.
2399 (not (string-equal (downcase (Info-extract-pointer "up"))
2400 "top")))
2401 (let ((old-node Info-current-node))
2402 (Info-up)
2403 (let (Info-history success)
2404 (unwind-protect
2405 (setq success (Info-forward-node t no-error))
2406 (or success (Info-goto-node old-node))))))
2407 (no-error nil)
2408 (t (error "No pointer forward from this node")))))
2409
2410 (defun Info-backward-node ()
2411 "Go backward one node, considering all nodes as forming one sequence."
2412 (interactive)
2413 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
2414 (upnode (Info-extract-pointer "up" t))
2415 (case-fold-search t))
2416 (cond ((and upnode (string-match "(" upnode))
2417 (error "First node in file"))
2418 ((and upnode (or (null prevnode)
2419 ;; Use string-equal, not equal,
2420 ;; to ignore text properties.
2421 (string-equal (downcase prevnode)
2422 (downcase upnode))))
2423 (Info-up))
2424 (prevnode
2425 ;; If we move back at the same level,
2426 ;; go down to find the last subnode*.
2427 (Info-prev)
2428 (let (Info-history)
2429 (while (and (not (Info-index-node))
2430 (save-excursion (search-forward "\n* Menu:" nil t)))
2431 (Info-goto-node (Info-extract-menu-counting nil)))))
2432 (t
2433 (error "No pointer backward from this node")))))
2434
2435 (defun Info-exit ()
2436 "Exit Info by selecting some other buffer."
2437 (interactive)
2438 (if Info-standalone
2439 (save-buffers-kill-emacs)
2440 (quit-window)))
2441
2442 (defun Info-next-menu-item ()
2443 "Go to the node of the next menu item."
2444 (interactive)
2445 ;; Bind this in case the user sets it to nil.
2446 (let* ((case-fold-search t)
2447 (node
2448 (save-excursion
2449 (forward-line -1)
2450 (search-forward "\n* menu:" nil t)
2451 (and (search-forward "\n* " nil t)
2452 (Info-extract-menu-node-name)))))
2453 (if node (Info-goto-node node)
2454 (error "No more items in menu"))))
2455
2456 (defun Info-last-menu-item ()
2457 "Go to the node of the previous menu item."
2458 (interactive)
2459 (save-excursion
2460 (forward-line 1)
2461 ;; Bind this in case the user sets it to nil.
2462 (let* ((case-fold-search t)
2463 (beg (save-excursion
2464 (and (search-backward "\n* menu:" nil t)
2465 (point)))))
2466 (or (and beg (search-backward "\n* " beg t))
2467 (error "No previous items in menu")))
2468 (Info-goto-node (save-excursion
2469 (goto-char (match-end 0))
2470 (Info-extract-menu-node-name)))))
2471
2472 (defmacro Info-no-error (&rest body)
2473 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
2474
2475 (defun Info-next-preorder ()
2476 "Go to the next subnode or the next node, or go up a level."
2477 (interactive)
2478 (cond ((Info-no-error (Info-next-menu-item)))
2479 ((Info-no-error (Info-next)))
2480 ((Info-no-error (Info-up t))
2481 ;; Since we have already gone thru all the items in this menu,
2482 ;; go up to the end of this node.
2483 (goto-char (point-max))
2484 ;; Since logically we are done with the node with that menu,
2485 ;; move on from it.
2486 (Info-next-preorder))
2487 (t
2488 (error "No more nodes"))))
2489
2490 (defun Info-last-preorder ()
2491 "Go to the last node, popping up a level if there is none."
2492 (interactive)
2493 (cond ((Info-no-error
2494 (Info-last-menu-item)
2495 ;; If we go down a menu item, go to the end of the node
2496 ;; so we can scroll back through it.
2497 (goto-char (point-max)))
2498 ;; Keep going down, as long as there are nested menu nodes.
2499 (while (Info-no-error
2500 (Info-last-menu-item)
2501 ;; If we go down a menu item, go to the end of the node
2502 ;; so we can scroll back through it.
2503 (goto-char (point-max))))
2504 (recenter -1))
2505 ((and (Info-no-error (Info-extract-pointer "prev"))
2506 (not (equal (Info-extract-pointer "up")
2507 (Info-extract-pointer "prev"))))
2508 (Info-no-error (Info-prev))
2509 (goto-char (point-max))
2510 (while (Info-no-error
2511 (Info-last-menu-item)
2512 ;; If we go down a menu item, go to the end of the node
2513 ;; so we can scroll back through it.
2514 (goto-char (point-max))))
2515 (recenter -1))
2516 ((Info-no-error (Info-up t))
2517 (goto-char (point-min))
2518 (let ((case-fold-search t))
2519 (or (search-forward "\n* Menu:" nil t)
2520 (goto-char (point-max)))))
2521 (t (error "No previous nodes"))))
2522
2523 (defun Info-scroll-up ()
2524 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2525 Once you scroll far enough in a node that its menu appears on the screen
2526 but after point, the next scroll moves into its first subnode, unless
2527 `Info-scroll-prefer-subnodes' is nil.
2528
2529 When you scroll past the end of a node, that goes to the next node if
2530 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2531 if this node has no successor, it moves to the parent node's successor,
2532 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2533 the menu of a node, it moves to subnode indicated by the following menu
2534 item. (That case won't normally result from this command, but can happen
2535 in other ways.)"
2536
2537 (interactive)
2538 (if (or (< (window-start) (point-min))
2539 (> (window-start) (point-max)))
2540 (set-window-start (selected-window) (point)))
2541 (let* ((case-fold-search t)
2542 (virtual-end (save-excursion
2543 (goto-char (point-min))
2544 (if (and Info-scroll-prefer-subnodes
2545 (search-forward "\n* Menu:" nil t))
2546 (point)
2547 (point-max)))))
2548 (if (or (< virtual-end (window-start))
2549 (pos-visible-in-window-p virtual-end))
2550 (cond
2551 (Info-scroll-prefer-subnodes (Info-next-preorder))
2552 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2553 (t (Info-next-preorder)))
2554 (scroll-up))))
2555
2556 (defun Info-scroll-down ()
2557 "Scroll one screenful back in Info, considering all nodes as one sequence.
2558 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2559 is non-nil, this goes to its last subnode. When you scroll past the
2560 beginning of a node, that goes to the previous node or back up to the
2561 parent node."
2562 (interactive)
2563 (if (or (< (window-start) (point-min))
2564 (> (window-start) (point-max)))
2565 (set-window-start (selected-window) (point)))
2566 (let* ((case-fold-search t)
2567 (current-point (point))
2568 (virtual-end
2569 (and Info-scroll-prefer-subnodes
2570 (save-excursion
2571 (beginning-of-line)
2572 (setq current-point (point))
2573 (goto-char (point-min))
2574 (search-forward "\n* Menu:"
2575 current-point
2576 t)))))
2577 (if (or virtual-end
2578 (pos-visible-in-window-p (point-min) nil t))
2579 (Info-last-preorder)
2580 (scroll-down))))
2581
2582 (defun Info-next-reference (&optional recur)
2583 "Move cursor to the next cross-reference or menu item in the node."
2584 (interactive)
2585 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2586 (old-pt (point))
2587 (case-fold-search t))
2588 (or (eobp) (forward-char 1))
2589 (or (re-search-forward pat nil t)
2590 (progn
2591 (goto-char (point-min))
2592 (or (re-search-forward pat nil t)
2593 (progn
2594 (goto-char old-pt)
2595 (error "No cross references in this node")))))
2596 (goto-char (or (match-beginning 1) (match-beginning 0)))
2597 (if (looking-at "\\* Menu:")
2598 (if recur
2599 (error "No cross references in this node")
2600 (Info-next-reference t))
2601 (if (looking-at "^\\* ")
2602 (forward-char 2)))))
2603
2604 (defun Info-prev-reference (&optional recur)
2605 "Move cursor to the previous cross-reference or menu item in the node."
2606 (interactive)
2607 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2608 (old-pt (point))
2609 (case-fold-search t))
2610 (or (re-search-backward pat nil t)
2611 (progn
2612 (goto-char (point-max))
2613 (or (re-search-backward pat nil t)
2614 (progn
2615 (goto-char old-pt)
2616 (error "No cross references in this node")))))
2617 (goto-char (or (match-beginning 1) (match-beginning 0)))
2618 (if (looking-at "\\* Menu:")
2619 (if recur
2620 (error "No cross references in this node")
2621 (Info-prev-reference t))
2622 (if (looking-at "^\\* ")
2623 (forward-char 2)))))
2624 \f
2625 (defvar Info-index-nodes nil
2626 "Alist of cached index node names of visited Info files.
2627 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2628
2629 (defun Info-index-nodes (&optional file)
2630 "Return a list of names of all index nodes in Info FILE.
2631 If FILE is omitted, it defaults to the current Info file.
2632 First look in a list of cached index node names. Then scan Info
2633 file and its subfiles for nodes with the index cookie. Then try
2634 to find index nodes starting from the first node in the top level
2635 menu whose name contains the word \"Index\", plus any immediately
2636 following nodes whose names also contain the word \"Index\"."
2637 (or file (setq file Info-current-file))
2638 (or (assoc file Info-index-nodes)
2639 ;; Skip virtual Info files
2640 (and (member file '("dir" "history" "toc" "apropos"))
2641 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
2642 (not (stringp file))
2643 ;; Find nodes with index cookie
2644 (let* ((default-directory (or (and (stringp file)
2645 (file-name-directory
2646 (setq file (Info-find-file file))))
2647 default-directory))
2648 Info-history Info-history-list Info-fontify-maximum-menu-size
2649 (main-file file) subfiles nodes node)
2650 (condition-case nil
2651 (with-temp-buffer
2652 (while (or main-file subfiles)
2653 (erase-buffer)
2654 (info-insert-file-contents (or main-file (car subfiles)))
2655 (goto-char (point-min))
2656 (while (search-forward "\0\b[index\0\b]" nil 'move)
2657 (save-excursion
2658 (re-search-backward "^\^_")
2659 (search-forward "Node: ")
2660 (setq nodes (cons (Info-following-node-name) nodes))))
2661 (if main-file
2662 (save-excursion
2663 (goto-char (point-min))
2664 (if (search-forward "\n\^_\nIndirect:" nil t)
2665 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2666 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2667 (setq subfiles (cons (match-string-no-properties 1)
2668 subfiles)))))
2669 (setq subfiles (nreverse subfiles)
2670 main-file nil))
2671 (setq subfiles (cdr subfiles)))))
2672 (error nil))
2673 (if nodes
2674 (setq nodes (nreverse nodes)
2675 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2676 nodes)
2677 ;; Find nodes with the word "Index" in the node name
2678 (let ((case-fold-search t)
2679 Info-history Info-history-list Info-fontify-maximum-menu-size
2680 nodes node)
2681 (condition-case nil
2682 (with-temp-buffer
2683 (Info-mode)
2684 (Info-find-node file "Top")
2685 (when (and (search-forward "\n* menu:" nil t)
2686 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2687 (goto-char (match-beginning 1))
2688 (setq nodes (list (Info-extract-menu-node-name)))
2689 (Info-goto-node (car nodes))
2690 (while (and (setq node (Info-extract-pointer "next" t))
2691 (string-match "\\<Index\\>" node))
2692 (setq nodes (cons node nodes))
2693 (Info-goto-node node))))
2694 (error nil))
2695 (if nodes
2696 (setq nodes (nreverse nodes)
2697 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2698 nodes)
2699 ;; If file has no index nodes, still add it to the cache
2700 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
2701 (cdr (assoc file Info-index-nodes)))
2702
2703 (defun Info-index-node (&optional node file)
2704 "Return non-nil value if NODE is an index node.
2705 If NODE is nil, check the current Info node.
2706 If FILE is nil, check the current Info file."
2707 (if (or (and node (not (equal node Info-current-node)))
2708 (assoc (or file Info-current-file) Info-index-nodes))
2709 (member (or node Info-current-node) (Info-index-nodes file))
2710 ;; Don't search all index nodes if request is only for the current node
2711 ;; and file is not in the cache of index nodes
2712 (or
2713 (save-match-data
2714 (string-match "\\<Index\\>" (or node Info-current-node "")))
2715 (save-excursion
2716 (goto-char (+ (or (save-excursion
2717 (search-backward "\n\^_" nil t))
2718 (point-min)) 2))
2719 (search-forward "\0\b[index\0\b]"
2720 (or (save-excursion
2721 (search-forward "\n\^_" nil t))
2722 (point-max)) t)))))
2723
2724 (defun Info-goto-index ()
2725 "Go to the first index node."
2726 (let ((node (car (Info-index-nodes))))
2727 (or node (error "No index"))
2728 (Info-goto-node node)))
2729
2730 ;;;###autoload
2731 (defun Info-index (topic)
2732 "Look up a string TOPIC in the index for this file.
2733 If there are no exact matches to the specified topic, this chooses
2734 the first match which is a case-insensitive substring of a topic.
2735 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
2736 Give a blank topic name to go to the Index node itself."
2737 (interactive
2738 (list
2739 (let ((Info-complete-menu-buffer (clone-buffer))
2740 (Info-complete-nodes (Info-index-nodes))
2741 (Info-history-list nil))
2742 (if (equal Info-current-file "dir")
2743 (error "The Info directory node has no index; use m to select a manual"))
2744 (unwind-protect
2745 (with-current-buffer Info-complete-menu-buffer
2746 (Info-goto-index)
2747 (completing-read "Index topic: " 'Info-complete-menu-item))
2748 (kill-buffer Info-complete-menu-buffer)))))
2749 (if (equal Info-current-file "dir")
2750 (error "The Info directory node has no index; use m to select a manual"))
2751 (let ((orignode Info-current-node)
2752 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
2753 (regexp-quote topic)))
2754 node (nodes (Info-index-nodes))
2755 (ohist-list Info-history-list)
2756 (case-fold-search t))
2757 (Info-goto-index)
2758 (or (equal topic "")
2759 (let ((matches nil)
2760 (exact nil)
2761 ;; We bind Info-history to nil for internal node-switches so
2762 ;; that we don't put junk in the history. In the first
2763 ;; Info-goto-index call, above, we do update the history
2764 ;; because that is what the user's previous node choice into it.
2765 (Info-history nil)
2766 found)
2767 (while
2768 (progn
2769 (goto-char (point-min))
2770 (while (re-search-forward pattern nil t)
2771 (push (list (match-string-no-properties 1)
2772 (match-string-no-properties 2)
2773 Info-current-node
2774 (string-to-number (concat "0"
2775 (match-string 3))))
2776 matches))
2777 (setq nodes (cdr nodes) node (car nodes)))
2778 (Info-goto-node node))
2779 (or matches
2780 (progn
2781 (Info-goto-node orignode)
2782 (error "No `%s' in index" topic)))
2783 ;; Here it is a feature that assoc is case-sensitive.
2784 (while (setq found (assoc topic matches))
2785 (setq exact (cons found exact)
2786 matches (delq found matches)))
2787 (setq Info-history-list ohist-list)
2788 (setq Info-index-alternatives (nconc exact (nreverse matches)))
2789 (Info-index-next 0)))))
2790
2791 (defun Info-index-next (num)
2792 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
2793 (interactive "p")
2794 (or Info-index-alternatives
2795 (error "No previous `i' command"))
2796 (while (< num 0)
2797 (setq num (+ num (length Info-index-alternatives))))
2798 (while (> num 0)
2799 (setq Info-index-alternatives
2800 (nconc (cdr Info-index-alternatives)
2801 (list (car Info-index-alternatives)))
2802 num (1- num)))
2803 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2804 (if (> (nth 3 (car Info-index-alternatives)) 0)
2805 (forward-line (1- (nth 3 (car Info-index-alternatives))))
2806 (forward-line 3) ; don't search in headers
2807 (let ((name (car (car Info-index-alternatives))))
2808 (Info-find-index-name name)))
2809 (message "Found `%s' in %s. %s"
2810 (car (car Info-index-alternatives))
2811 (nth 2 (car Info-index-alternatives))
2812 (if (cdr Info-index-alternatives)
2813 "(`,' tries to find next)"
2814 "(Only match)")))
2815
2816 (defun Info-find-index-name (name)
2817 "Move point to the place within the current node where NAME is defined."
2818 (let ((case-fold-search t))
2819 (if (or (re-search-forward (format
2820 "[a-zA-Z]+: %s\\( \\|$\\)"
2821 (regexp-quote name)) nil t)
2822 ;; Find a function definition with a return type.
2823 (re-search-forward (format
2824 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2825 (regexp-quote name)) nil t)
2826 (search-forward (format "`%s'" name) nil t)
2827 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2828 (search-forward
2829 (format "`%s'" (substring name 0 (match-beginning 1)))
2830 nil t))
2831 (search-forward name nil t)
2832 ;; Try again without the " <1>" makeinfo can append
2833 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
2834 (Info-find-index-name (match-string 1 name))))
2835 (progn (beginning-of-line) t) ;; non-nil for recursive call
2836 (goto-char (point-min)))))
2837
2838 ;;;###autoload
2839 (defun info-apropos (string)
2840 "Grovel indices of all known Info files on your system for STRING.
2841 Build a menu of the possible matches."
2842 (interactive "sIndex apropos: ")
2843 (unless (string= string "")
2844 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
2845 (regexp-quote string)))
2846 (ohist Info-history)
2847 (ohist-list Info-history-list)
2848 (current-node Info-current-node)
2849 (current-file Info-current-file)
2850 manuals matches node nodes)
2851 (let ((Info-fontify-maximum-menu-size nil))
2852 (Info-directory)
2853 (message "Searching indices...")
2854 (goto-char (point-min))
2855 (re-search-forward "\\* Menu: *\n" nil t)
2856 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
2857 (setq manuals (cons (match-string 1) manuals)))
2858 (dolist (manual (nreverse manuals))
2859 (message "Searching %s" manual)
2860 (condition-case err
2861 (if (setq nodes (Info-index-nodes (Info-find-file manual)))
2862 (save-excursion
2863 (Info-find-node manual (car nodes))
2864 (while
2865 (progn
2866 (goto-char (point-min))
2867 (while (re-search-forward pattern nil t)
2868 (setq matches
2869 (cons (list manual
2870 (match-string-no-properties 1)
2871 (match-string-no-properties 2)
2872 (match-string-no-properties 3))
2873 matches)))
2874 (setq nodes (cdr nodes) node (car nodes)))
2875 (Info-goto-node node))))
2876 (error
2877 (message "%s" (if (eq (car-safe err) 'error)
2878 (nth 1 err) err))
2879 (sit-for 1 t)))))
2880 (Info-goto-node (concat "(" current-file ")" current-node))
2881 (setq Info-history ohist
2882 Info-history-list ohist-list)
2883 (message "Searching indices...done")
2884 (if (null matches)
2885 (message "No matches found")
2886 (with-current-buffer (get-buffer-create " *info-apropos*")
2887 (erase-buffer)
2888 (insert "\n\^_\nFile: apropos, Node: Index, Up: (dir)\n")
2889 (insert "* Menu: \nNodes whose indices contain `" string "':\n\n")
2890 (dolist (entry (nreverse matches))
2891 (insert
2892 (format "* %-38s (%s)%s.%s\n"
2893 (concat (nth 1 entry) " [" (nth 0 entry) "]:")
2894 (nth 0 entry)
2895 (nth 2 entry)
2896 (if (nth 3 entry)
2897 (concat " (line " (nth 3 entry) ")")
2898 "")))))
2899 (Info-find-node "apropos" "Index")
2900 (setq Info-complete-cache nil)))))
2901
2902 (defun Info-undefined ()
2903 "Make command be undefined in Info."
2904 (interactive)
2905 (ding))
2906
2907 (defun Info-help ()
2908 "Enter the Info tutorial."
2909 (interactive)
2910 (delete-other-windows)
2911 (Info-find-node "info"
2912 (if (< (window-height) 23)
2913 "Help-Small-Screen"
2914 "Help")))
2915
2916 (defun Info-summary ()
2917 "Display a brief summary of all Info commands."
2918 (interactive)
2919 (save-window-excursion
2920 (switch-to-buffer "*Help*")
2921 (setq buffer-read-only nil)
2922 (erase-buffer)
2923 (insert (documentation 'Info-mode))
2924 (help-mode)
2925 (goto-char (point-min))
2926 (let (ch flag)
2927 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2928 (message (if flag "Type Space to see more"
2929 "Type Space to return to Info"))
2930 (if (not (eq ?\s (setq ch (read-event))))
2931 (progn (setq unread-command-events (list ch)) nil)
2932 flag))
2933 (scroll-up)))
2934 (bury-buffer "*Help*")))
2935 \f
2936 (defun Info-get-token (pos start all &optional errorstring)
2937 "Return the token around POS.
2938 POS must be somewhere inside the token
2939 START is a regular expression which will match the
2940 beginning of the tokens delimited string
2941 ALL is a regular expression with a single
2942 parenthesized subpattern which is the token to be
2943 returned. E.g. '{\(.*\)}' would return any string
2944 enclosed in braces around POS.
2945 ERRORSTRING optional fourth argument, controls action on no match
2946 nil: return nil
2947 t: beep
2948 a string: signal an error, using that string."
2949 (let ((case-fold-search t))
2950 (save-excursion
2951 (goto-char pos)
2952 ;; First look for a match for START that goes across POS.
2953 (while (and (not (bobp)) (> (point) (- pos (length start)))
2954 (not (looking-at start)))
2955 (forward-char -1))
2956 ;; If we did not find one, search back for START
2957 ;; (this finds only matches that end at or before POS).
2958 (or (looking-at start)
2959 (progn
2960 (goto-char pos)
2961 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
2962 (let (found)
2963 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2964 (not (setq found (and (<= (match-beginning 0) pos)
2965 (> (match-end 0) pos))))))
2966 (if (and found (<= (match-beginning 0) pos)
2967 (> (match-end 0) pos))
2968 (match-string-no-properties 1)
2969 (cond ((null errorstring)
2970 nil)
2971 ((eq errorstring t)
2972 (beep)
2973 nil)
2974 (t
2975 (error "No %s around position %d" errorstring pos))))))))
2976
2977 (defun Info-mouse-follow-nearest-node (click)
2978 "\\<Info-mode-map>Follow a node reference near point.
2979 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2980 At end of the node's text, moves to the next node, or up if none."
2981 (interactive "e")
2982 (mouse-set-point click)
2983 (and (not (Info-try-follow-nearest-node))
2984 (save-excursion (forward-line 1) (eobp))
2985 (Info-next-preorder)))
2986
2987 (defun Info-follow-nearest-node (&optional fork)
2988 "Follow a node reference near point.
2989 If point is on a reference, follow that reference. Otherwise,
2990 if point is in a menu item description, follow that menu item."
2991 (interactive "P")
2992 (or (Info-try-follow-nearest-node fork)
2993 (when (save-excursion
2994 (search-backward "\n* menu:" nil t))
2995 (save-excursion
2996 (beginning-of-line)
2997 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2998 (beginning-of-line 0))
2999 (when (looking-at "\\* +\\([^\t\n]*\\):")
3000 (Info-goto-node
3001 (Info-extract-menu-item (match-string-no-properties 1)) fork)
3002 t)))
3003 (error "Point neither on reference nor in menu item description")))
3004
3005 ;; Common subroutine.
3006 (defun Info-try-follow-nearest-node (&optional fork)
3007 "Follow a node reference near point. Return non-nil if successful."
3008 (let (node)
3009 (cond
3010 ((Info-get-token (point) "[hf]t?tp://" "[hf]t?tp://\\([^ \t\n\"`({<>})']+\\)")
3011 (setq node t)
3012 (browse-url (browse-url-url-at-point)))
3013 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
3014 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3015 (Info-follow-reference node fork))
3016 ;; menu item: node name
3017 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3018 (Info-goto-node node fork))
3019 ;; menu item: node name or index entry
3020 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3021 (beginning-of-line)
3022 (forward-char 2)
3023 (setq node (Info-extract-menu-node-name nil (Info-index-node)))
3024 (Info-goto-node node fork))
3025 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3026 (Info-goto-node node fork))
3027 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3028 (Info-goto-node node fork))
3029 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3030 (Info-goto-node "Top" fork))
3031 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3032 (Info-goto-node node fork)))
3033 node))
3034 \f
3035 (defvar Info-mode-map nil
3036 "Keymap containing Info commands.")
3037 (if Info-mode-map
3038 nil
3039 (setq Info-mode-map (make-keymap))
3040 (suppress-keymap Info-mode-map)
3041 (define-key Info-mode-map "." 'beginning-of-buffer)
3042 (define-key Info-mode-map " " 'Info-scroll-up)
3043 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
3044 (define-key Info-mode-map "\t" 'Info-next-reference)
3045 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
3046 (define-key Info-mode-map [backtab] 'Info-prev-reference)
3047 (define-key Info-mode-map "1" 'Info-nth-menu-item)
3048 (define-key Info-mode-map "2" 'Info-nth-menu-item)
3049 (define-key Info-mode-map "3" 'Info-nth-menu-item)
3050 (define-key Info-mode-map "4" 'Info-nth-menu-item)
3051 (define-key Info-mode-map "5" 'Info-nth-menu-item)
3052 (define-key Info-mode-map "6" 'Info-nth-menu-item)
3053 (define-key Info-mode-map "7" 'Info-nth-menu-item)
3054 (define-key Info-mode-map "8" 'Info-nth-menu-item)
3055 (define-key Info-mode-map "9" 'Info-nth-menu-item)
3056 (define-key Info-mode-map "0" 'undefined)
3057 (define-key Info-mode-map "?" 'Info-summary)
3058 (define-key Info-mode-map "]" 'Info-forward-node)
3059 (define-key Info-mode-map "[" 'Info-backward-node)
3060 (define-key Info-mode-map "<" 'Info-top-node)
3061 (define-key Info-mode-map ">" 'Info-final-node)
3062 (define-key Info-mode-map "b" 'beginning-of-buffer)
3063 (define-key Info-mode-map "d" 'Info-directory)
3064 (define-key Info-mode-map "e" 'Info-edit)
3065 (define-key Info-mode-map "f" 'Info-follow-reference)
3066 (define-key Info-mode-map "g" 'Info-goto-node)
3067 (define-key Info-mode-map "h" 'Info-help)
3068 (define-key Info-mode-map "i" 'Info-index)
3069 (define-key Info-mode-map "l" 'Info-history-back)
3070 (define-key Info-mode-map "L" 'Info-history)
3071 (define-key Info-mode-map "m" 'Info-menu)
3072 (define-key Info-mode-map "n" 'Info-next)
3073 (define-key Info-mode-map "p" 'Info-prev)
3074 (define-key Info-mode-map "q" 'Info-exit)
3075 (define-key Info-mode-map "r" 'Info-history-forward)
3076 (define-key Info-mode-map "s" 'Info-search)
3077 (define-key Info-mode-map "S" 'Info-search-case-sensitively)
3078 ;; For consistency with Rmail.
3079 (define-key Info-mode-map "\M-s" 'Info-search)
3080 (define-key Info-mode-map "\M-n" 'clone-buffer)
3081 (define-key Info-mode-map "t" 'Info-top-node)
3082 (define-key Info-mode-map "T" 'Info-toc)
3083 (define-key Info-mode-map "u" 'Info-up)
3084 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3085 (define-key Info-mode-map "w" 'Info-copy-current-node-name)
3086 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
3087 ;; `^' for consistency with `dired-up-directory'.
3088 (define-key Info-mode-map "^" 'Info-up)
3089 (define-key Info-mode-map "," 'Info-index-next)
3090 (define-key Info-mode-map "\177" 'Info-scroll-down)
3091 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
3092 (define-key Info-mode-map [follow-link] 'mouse-face)
3093 )
3094
3095 (defun Info-check-pointer (item)
3096 "Non-nil if ITEM is present in this node."
3097 (condition-case nil
3098 (Info-extract-pointer item)
3099 (error nil)))
3100
3101 (easy-menu-define
3102 Info-mode-menu Info-mode-map
3103 "Menu for Info files."
3104 '("Info"
3105 ["Up" Info-up :active (Info-check-pointer "up")
3106 :help "Go up in the Info tree"]
3107 ["Next" Info-next :active (Info-check-pointer "next")
3108 :help "Go to the next node"]
3109 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3110 :help "Go to the previous node"]
3111 ["Backward" Info-backward-node
3112 :help "Go backward one node, considering all as a sequence"]
3113 ["Forward" Info-forward-node
3114 :help "Go forward one node, considering all as a sequence"]
3115 ["Beginning" beginning-of-buffer
3116 :help "Go to beginning of this node"]
3117 ["Top" Info-top-node
3118 :help "Go to top node of file"]
3119 ["Final Node" Info-final-node
3120 :help "Go to final node in this file"]
3121 ("Menu Item" ["You should never see this" report-emacs-bug t])
3122 ("Reference" ["You should never see this" report-emacs-bug t])
3123 ["Search..." Info-search
3124 :help "Search for regular expression in this Info file"]
3125 ["Search Next" Info-search-next
3126 :help "Search for another occurrence of regular expression"]
3127 ["Go to Node..." Info-goto-node
3128 :help "Go to a named node"]
3129 ["Back in history" Info-history-back :active Info-history
3130 :help "Go back in history to the last node you were at"]
3131 ["Forward in history" Info-history-forward :active Info-history-forward
3132 :help "Go forward in history"]
3133 ["History" Info-history :active Info-history-list
3134 :help "Go to menu of visited nodes"]
3135 ["Table of Contents" Info-toc
3136 :help "Go to table of contents"]
3137 ("Index"
3138 ["Lookup a String..." Info-index
3139 :help "Look for a string in the index items"]
3140 ["Next Matching Item" Info-index-next :active Info-index-alternatives
3141 :help "Look for another occurrence of previous item"]
3142 ["Lookup a string in all indices..." info-apropos
3143 :help "Look for a string in the indices of all manuals"])
3144 ["Edit" Info-edit :help "Edit contents of this node"
3145 :active Info-enable-edit]
3146 ["Copy Node Name" Info-copy-current-node-name
3147 :help "Copy the name of the current node into the kill ring"]
3148 ["Clone Info buffer" clone-buffer
3149 :help "Create a twin copy of the current Info buffer."]
3150 ["Exit" Info-exit :help "Stop reading Info"]))
3151
3152
3153 (defvar info-tool-bar-map
3154 (if (display-graphic-p)
3155 (let ((map (make-sparse-keymap)))
3156 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
3157 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
3158 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
3159 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
3160 (tool-bar-local-item-from-menu 'Info-history-back "back_arrow" map Info-mode-map)
3161 (tool-bar-local-item-from-menu 'Info-history-forward "fwd_arrow" map Info-mode-map)
3162 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
3163 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
3164 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
3165 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
3166 map)))
3167
3168 (defvar Info-menu-last-node nil)
3169 ;; Last node the menu was created for.
3170 ;; Value is a list, (FILE-NAME NODE-NAME).
3171
3172 (defun Info-menu-update ()
3173 "Update the Info menu for the current node."
3174 (condition-case nil
3175 (if (or (not (eq major-mode 'Info-mode))
3176 (equal (list Info-current-file Info-current-node)
3177 Info-menu-last-node))
3178 ()
3179 ;; Update menu menu.
3180 (let* ((Info-complete-menu-buffer (current-buffer))
3181 (items (nreverse (condition-case nil
3182 (Info-complete-menu-item "" nil t)
3183 (error nil))))
3184 entries current
3185 (number 0))
3186 (while (and items (< number 9))
3187 (setq current (car items)
3188 items (cdr items)
3189 number (1+ number))
3190 (setq entries (cons `[,current
3191 (Info-menu ,current)
3192 :keys ,(format "%d" number)]
3193 entries)))
3194 (if items
3195 (setq entries (cons ["Other..." Info-menu t] entries)))
3196 (or entries
3197 (setq entries (list ["No menu" nil nil] nil :active)))
3198 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3199 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3200 (let ((items nil)
3201 str i entries current
3202 (number 0)
3203 (case-fold-search t))
3204 (save-excursion
3205 (goto-char (point-min))
3206 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3207 (setq str (match-string 1))
3208 (setq i 0)
3209 (while (setq i (string-match "[ \n\t]+" str i))
3210 (setq str (concat (substring str 0 i) " "
3211 (substring str (match-end 0))))
3212 (setq i (1+ i)))
3213 (setq items
3214 (cons str items))))
3215 (while (and items (< number 9))
3216 (setq current (car items)
3217 items (cdr items)
3218 number (1+ number))
3219 (setq entries (cons `[,current
3220 (Info-follow-reference ,current)
3221 t]
3222 entries)))
3223 (if items
3224 (setq entries (cons ["Other..." Info-follow-reference t]
3225 entries)))
3226 (or entries
3227 (setq entries (list ["No references" nil nil] nil :active)))
3228 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3229 ;; Update last seen node.
3230 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3231 ;; Try to avoid entering infinite beep mode in case of errors.
3232 (error (ding))))
3233
3234 \f
3235 (defun Info-copy-current-node-name (&optional arg)
3236 "Put the name of the current Info node into the kill ring.
3237 The name of the Info file is prepended to the node name in parentheses.
3238 With a zero prefix arg, put the name inside a function call to `info'."
3239 (interactive "P")
3240 (unless Info-current-node
3241 (error "No current Info node"))
3242 (let ((node (concat "(" (file-name-nondirectory
3243 (or (and (stringp Info-current-file)
3244 Info-current-file)
3245 buffer-file-name
3246 ""))
3247 ")" Info-current-node)))
3248 (if (zerop (prefix-numeric-value arg))
3249 (setq node (concat "(info \"" node "\")")))
3250 (kill-new node)
3251 (message "%s" node)))
3252
3253 \f
3254 ;; Info mode is suitable only for specially formatted data.
3255 (put 'Info-mode 'mode-class 'special)
3256 (put 'Info-mode 'no-clone-indirect t)
3257
3258 (defvar tool-bar-map)
3259
3260 ;; Autoload cookie needed by desktop.el
3261 ;;;###autoload
3262 (defun Info-mode ()
3263 "Info mode provides commands for browsing through the Info documentation tree.
3264 Documentation in Info is divided into \"nodes\", each of which discusses
3265 one topic and contains references to other nodes which discuss related
3266 topics. Info has commands to follow the references and show you other nodes.
3267
3268 \\<Info-mode-map>\
3269 \\[Info-help] Invoke the Info tutorial.
3270 \\[Info-exit] Quit Info: reselect previously selected buffer.
3271
3272 Selecting other nodes:
3273 \\[Info-mouse-follow-nearest-node]
3274 Follow a node reference you click on.
3275 This works with menu items, cross references, and
3276 the \"next\", \"previous\" and \"up\", depending on where you click.
3277 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3278 \\[Info-next] Move to the \"next\" node of this node.
3279 \\[Info-prev] Move to the \"previous\" node of this node.
3280 \\[Info-up] Move \"up\" from this node.
3281 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3282 Picking a menu item causes another node to be selected.
3283 \\[Info-directory] Go to the Info directory node.
3284 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3285 \\[Info-history-back] Move back in history to the last node you were at.
3286 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3287 \\[Info-history] Go to menu of visited nodes.
3288 \\[Info-toc] Go to table of contents of the current Info file.
3289 \\[Info-top-node] Go to the Top node of this file.
3290 \\[Info-final-node] Go to the final node in this file.
3291 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3292 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3293 \\[Info-index] Look up a topic in this file's Index and move to that node.
3294 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3295 \\[info-apropos] Look for a string in the indices of all manuals.
3296
3297 Moving within a node:
3298 \\[Info-scroll-up] Normally, scroll forward a full screen.
3299 Once you scroll far enough in a node that its menu appears on the
3300 screen but after point, the next scroll moves into its first
3301 subnode. When after all menu items (or if there is no menu),
3302 move up to the parent node.
3303 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3304 already visible, try to go to the previous menu entry, or up
3305 if there is none.
3306 \\[beginning-of-buffer] Go to beginning of node.
3307
3308 Advanced commands:
3309 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
3310 \\[clone-buffer] Select a new cloned Info buffer in another window.
3311 \\[Info-edit] Edit contents of selected node.
3312 1 .. 9 Pick first ... ninth item in node's menu.
3313 Every third `*' is highlighted to help pick the right number.
3314 \\[Info-goto-node] Move to node specified by name.
3315 You may include a filename as well, as (FILENAME)NODENAME.
3316 \\[universal-argument] \\[info] Move to new Info file with completion.
3317 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>.
3318 \\[Info-search] Search through this Info file for specified regexp,
3319 and select the node in which the next occurrence is found.
3320 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3321 \\[Info-search-next] Search for another occurrence of regexp
3322 from a previous \\<Info-mode-map>\\[Info-search] command.
3323 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3324 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
3325 (kill-all-local-variables)
3326 (setq major-mode 'Info-mode)
3327 (setq mode-name "Info")
3328 (setq tab-width 8)
3329 (use-local-map Info-mode-map)
3330 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3331 (set-syntax-table text-mode-syntax-table)
3332 (setq local-abbrev-table text-mode-abbrev-table)
3333 (setq case-fold-search t)
3334 (setq buffer-read-only t)
3335 (make-local-variable 'Info-current-file)
3336 (make-local-variable 'Info-current-subfile)
3337 (make-local-variable 'Info-current-node)
3338 (make-local-variable 'Info-tag-table-marker)
3339 (setq Info-tag-table-marker (make-marker))
3340 (make-local-variable 'Info-tag-table-buffer)
3341 (setq Info-tag-table-buffer nil)
3342 (make-local-variable 'Info-history)
3343 (make-local-variable 'Info-history-forward)
3344 (make-local-variable 'Info-index-alternatives)
3345 (setq header-line-format
3346 (if Info-use-header-line
3347 '(:eval (get-text-property (point-min) 'header-line))
3348 nil)) ; so the header line isn't displayed
3349 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
3350 ;; This is for the sake of the invisible text we use handling titles.
3351 (make-local-variable 'line-move-ignore-invisible)
3352 (setq line-move-ignore-invisible t)
3353 (make-local-variable 'desktop-save-buffer)
3354 (make-local-variable 'widen-automatically)
3355 (setq widen-automatically nil)
3356 (setq desktop-save-buffer 'Info-desktop-buffer-misc-data)
3357 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
3358 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
3359 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
3360 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
3361 (set (make-local-variable 'isearch-search-fun-function)
3362 'Info-isearch-search)
3363 (set (make-local-variable 'isearch-wrap-function)
3364 'Info-isearch-wrap)
3365 (set (make-local-variable 'isearch-push-state-function)
3366 'Info-isearch-push-state)
3367 (set (make-local-variable 'search-whitespace-regexp)
3368 Info-search-whitespace-regexp)
3369 (Info-set-mode-line)
3370 (run-mode-hooks 'Info-mode-hook))
3371
3372 ;; When an Info buffer is killed, make sure the associated tags buffer
3373 ;; is killed too.
3374 (defun Info-kill-buffer ()
3375 (and (eq major-mode 'Info-mode)
3376 Info-tag-table-buffer
3377 (kill-buffer Info-tag-table-buffer)))
3378
3379 (defun Info-clone-buffer-hook ()
3380 (when (bufferp Info-tag-table-buffer)
3381 (setq Info-tag-table-buffer
3382 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
3383 (let ((m Info-tag-table-marker))
3384 (when (markerp m)
3385 (setq Info-tag-table-marker
3386 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
3387 (with-current-buffer Info-tag-table-buffer
3388 (copy-marker (marker-position m)))
3389 (make-marker))))))
3390
3391 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
3392 (set-keymap-parent map text-mode-map)
3393 (define-key map "\C-c\C-c" 'Info-cease-edit)
3394 map)
3395 "Local keymap used within `e' command of Info.")
3396
3397 ;; Info-edit mode is suitable only for specially formatted data.
3398 (put 'Info-edit-mode 'mode-class 'special)
3399
3400 (defun Info-edit-mode ()
3401 "Major mode for editing the contents of an Info node.
3402 Like text mode with the addition of `Info-cease-edit'
3403 which returns to Info mode for browsing.
3404 \\{Info-edit-map}"
3405 (use-local-map Info-edit-map)
3406 (setq major-mode 'Info-edit-mode)
3407 (setq mode-name "Info Edit")
3408 (kill-local-variable 'mode-line-buffer-identification)
3409 (setq buffer-read-only nil)
3410 (force-mode-line-update)
3411 (buffer-enable-undo (current-buffer))
3412 (run-mode-hooks 'Info-edit-mode-hook))
3413
3414 (defun Info-edit ()
3415 "Edit the contents of this Info node.
3416 Allowed only if variable `Info-enable-edit' is non-nil."
3417 (interactive)
3418 (or Info-enable-edit
3419 (error "Editing Info nodes is not enabled"))
3420 (Info-edit-mode)
3421 (message "%s" (substitute-command-keys
3422 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
3423
3424 (defun Info-cease-edit ()
3425 "Finish editing Info node; switch back to Info proper."
3426 (interactive)
3427 ;; Do this first, so nothing has changed if user C-g's at query.
3428 (and (buffer-modified-p)
3429 (y-or-n-p "Save the file? ")
3430 (save-buffer))
3431 (use-local-map Info-mode-map)
3432 (setq major-mode 'Info-mode)
3433 (setq mode-name "Info")
3434 (Info-set-mode-line)
3435 (setq buffer-read-only t)
3436 (force-mode-line-update)
3437 (and (marker-position Info-tag-table-marker)
3438 (buffer-modified-p)
3439 (message "Tags may have changed. Use Info-tagify if necessary")))
3440 \f
3441 (defvar Info-file-list-for-emacs
3442 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
3443 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
3444 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
3445 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
3446 ("skeleton" . "autotype") ("auto-insert" . "autotype")
3447 ("copyright" . "autotype") ("executable" . "autotype")
3448 ("time-stamp" . "autotype") ("quickurl" . "autotype")
3449 ("tempo" . "autotype") ("hippie-expand" . "autotype")
3450 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
3451 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
3452 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
3453 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
3454 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
3455 ("rfc2045" . "emacs-mime")
3456 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
3457 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
3458 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
3459 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
3460 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
3461 ("mml" . "emacs-mime"))
3462 "List of Info files that describe Emacs commands.
3463 An element can be a file name, or a list of the form (PREFIX . FILE)
3464 where PREFIX is a name prefix and FILE is the file to look in.
3465 If the element is just a file name, the file name also serves as the prefix.")
3466
3467 (defun Info-find-emacs-command-nodes (command)
3468 "Return a list of locations documenting COMMAND.
3469 The `info-file' property of COMMAND says which Info manual to search.
3470 If COMMAND has no property, the variable `Info-file-list-for-emacs'
3471 defines heuristics for which Info manual to try.
3472 The locations are of the format used in `Info-history', i.e.
3473 \(FILENAME NODENAME BUFFERPOS\), where BUFFERPOS is the line number
3474 in the first element of the returned list (which is treated specially in
3475 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
3476 (let ((where '()) line-number
3477 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
3478 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
3479 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
3480 (info-file "emacs")) ;default
3481 ;; Determine which Info file this command is documented in.
3482 (if (get command 'info-file)
3483 (setq info-file (get command 'info-file))
3484 ;; If it doesn't say explicitly, test its name against
3485 ;; various prefixes that we know.
3486 (let ((file-list Info-file-list-for-emacs))
3487 (while file-list
3488 (let* ((elt (car file-list))
3489 (name (if (consp elt)
3490 (car elt)
3491 elt))
3492 (file (if (consp elt) (cdr elt) elt))
3493 (case-fold-search nil)
3494 (regexp (concat "\\`" (regexp-quote name)
3495 "\\(\\'\\|-\\)")))
3496 (if (string-match regexp (symbol-name command))
3497 (setq info-file file file-list nil))
3498 (setq file-list (cdr file-list))))))
3499 (Info-find-node info-file "Top")
3500 (or (and (search-forward "\n* menu:" nil t)
3501 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
3502 (error "Info file `%s' appears to lack an index" info-file))
3503 (goto-char (match-beginning 1))
3504 ;; Bind Info-history to nil, to prevent the index nodes from
3505 ;; getting into the node history.
3506 (let ((Info-history nil)
3507 (Info-history-list nil)
3508 node (nodes (Info-index-nodes)))
3509 (Info-goto-node (car nodes))
3510 (while
3511 (progn
3512 (goto-char (point-min))
3513 (while (re-search-forward cmd-desc nil t)
3514 (setq where
3515 (cons (list Info-current-file
3516 (match-string-no-properties 2)
3517 0)
3518 where))
3519 (setq line-number (and (match-beginning 3)
3520 (string-to-number (match-string 3)))))
3521 (and (setq nodes (cdr nodes) node (car nodes))))
3522 (Info-goto-node node)))
3523 (if (and line-number where)
3524 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
3525 (cdr where))
3526 where)))
3527
3528 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file "emacs")
3529 ;;;###autoload
3530 (defun Info-goto-emacs-command-node (command)
3531 "Go to the Info node in the Emacs manual for command COMMAND.
3532 The command is found by looking up in Emacs manual's indices
3533 or in another manual found via COMMAND's `info-file' property or
3534 the variable `Info-file-list-for-emacs'.
3535 COMMAND must be a symbol or string."
3536 (interactive "CFind documentation for command: ")
3537 ;; If command is given as a string, convert it to a symbol.
3538 (if (stringp command)
3539 (setq command (intern command)))
3540 (or (commandp command)
3541 (signal 'wrong-type-argument (list 'commandp command)))
3542 (let ((where (Info-find-emacs-command-nodes command)))
3543 (if where
3544 (let ((num-matches (length where)))
3545 ;; Get Info running, and pop to it in another window.
3546 (save-window-excursion
3547 (info))
3548 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
3549 ;; Bind Info-history to nil, to prevent the last Index node
3550 ;; visited by Info-find-emacs-command-nodes from being
3551 ;; pushed onto the history.
3552 (let ((Info-history nil) (Info-history-list nil)
3553 (line-number (nth 2 (car where))))
3554 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
3555 (if (and (integerp line-number) (> line-number 0))
3556 (forward-line (1- line-number))))
3557 (if (> num-matches 1)
3558 (progn
3559 ;; (car where) will be pushed onto Info-history
3560 ;; when/if they go to another node. Put the other
3561 ;; nodes that were found on the history.
3562 (setq Info-history (nconc (cdr where) Info-history))
3563 (message "Found %d other entr%s. Use %s to see %s."
3564 (1- num-matches)
3565 (if (> num-matches 2) "ies" "y")
3566 (substitute-command-keys "\\[Info-history-back]")
3567 (if (> num-matches 2) "them" "it")))))
3568 (error "Couldn't find documentation for %s" command))))
3569
3570 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file "emacs")
3571 ;;;###autoload
3572 (defun Info-goto-emacs-key-command-node (key)
3573 "Go to the node in the Emacs manual which describes the command bound to KEY.
3574 KEY is a string.
3575 Interactively, if the binding is `execute-extended-command', a command is read.
3576 The command is found by looking up in Emacs manual's indices
3577 or in another manual found via COMMAND's `info-file' property or
3578 the variable `Info-file-list-for-emacs'."
3579 (interactive "kFind documentation for key: ")
3580 (let ((command (key-binding key)))
3581 (cond ((null command)
3582 (message "%s is undefined" (key-description key)))
3583 ((and (interactive-p)
3584 (eq command 'execute-extended-command))
3585 (Info-goto-emacs-command-node
3586 (read-command "Find documentation for command: ")))
3587 (t
3588 (Info-goto-emacs-command-node command)))))
3589 \f
3590 (defvar Info-next-link-keymap
3591 (let ((keymap (make-sparse-keymap)))
3592 (define-key keymap [header-line mouse-1] 'Info-next)
3593 (define-key keymap [header-line mouse-2] 'Info-next)
3594 (define-key keymap [header-line down-mouse-1] 'ignore)
3595 (define-key keymap [mouse-2] 'Info-next)
3596 (define-key keymap [follow-link] 'mouse-face)
3597 keymap)
3598 "Keymap to put on the Next link in the text or the header line.")
3599
3600 (defvar Info-prev-link-keymap
3601 (let ((keymap (make-sparse-keymap)))
3602 (define-key keymap [header-line mouse-1] 'Info-prev)
3603 (define-key keymap [header-line mouse-2] 'Info-prev)
3604 (define-key keymap [header-line down-mouse-1] 'ignore)
3605 (define-key keymap [mouse-2] 'Info-prev)
3606 (define-key keymap [follow-link] 'mouse-face)
3607 keymap)
3608 "Keymap to put on the Prev link in the text or the header line.")
3609
3610 (defvar Info-up-link-keymap
3611 (let ((keymap (make-sparse-keymap)))
3612 (define-key keymap [header-line mouse-1] 'Info-up)
3613 (define-key keymap [header-line mouse-2] 'Info-up)
3614 (define-key keymap [header-line down-mouse-1] 'ignore)
3615 (define-key keymap [mouse-2] 'Info-up)
3616 (define-key keymap [follow-link] 'mouse-face)
3617 keymap)
3618 "Keymap to put on the Up link in the text or the header line.")
3619
3620 (defun Info-fontify-node ()
3621 "Fontify the node."
3622 (save-excursion
3623 (let* ((inhibit-read-only t)
3624 (case-fold-search t)
3625 paragraph-markers
3626 (not-fontified-p ; the node hasn't already been fontified
3627 (not (let ((where (next-property-change (point-min))))
3628 (and where (not (= where (point-max)))))))
3629 (fontify-visited-p ; visited nodes need to be re-fontified
3630 (and Info-fontify-visited-nodes
3631 ;; Don't take time to refontify visited nodes in huge nodes
3632 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
3633 rbeg rend)
3634
3635 ;; Fontify header line
3636 (goto-char (point-min))
3637 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
3638 (goto-char (match-end 0))
3639 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
3640 (goto-char (match-end 0))
3641 (let* ((nbeg (match-beginning 2))
3642 (nend (match-end 2))
3643 (tbeg (match-beginning 1))
3644 (tag (match-string 1)))
3645 (if (string-equal tag "Node")
3646 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
3647 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
3648 (put-text-property tbeg nend 'mouse-face 'highlight)
3649 (put-text-property tbeg nend
3650 'help-echo
3651 (concat "mouse-2: Go to node "
3652 (buffer-substring nbeg nend)))
3653 ;; Always set up the text property keymap.
3654 ;; It will either be used in the buffer
3655 ;; or copied in the header line.
3656 (put-text-property tbeg nend 'keymap
3657 (cond
3658 ((equal tag "Prev") Info-prev-link-keymap)
3659 ((equal tag "Next") Info-next-link-keymap)
3660 ((equal tag "Up") Info-up-link-keymap))))))
3661 (when Info-use-header-line
3662 (goto-char (point-min))
3663 (let ((header-end (line-end-position))
3664 header)
3665 ;; If we find neither Next: nor Prev: link, show the entire
3666 ;; node header. Otherwise, don't show the File: and Node:
3667 ;; parts, to avoid wasting precious space on information that
3668 ;; is available in the mode line.
3669 (if (re-search-forward
3670 "\\(next\\|up\\|prev[ious]*\\): "
3671 header-end t)
3672 (progn
3673 (goto-char (match-beginning 1))
3674 (setq header (buffer-substring (point) header-end)))
3675 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" header-end t)
3676 (setq header
3677 (concat "No next, prev or up links -- "
3678 (buffer-substring (point) header-end)))
3679 (setq header (buffer-substring (point) header-end))))
3680 (put-text-property (point-min) (1+ (point-min))
3681 'header-line
3682 (replace-regexp-in-string
3683 "%"
3684 ;; Preserve text properties on duplicated `%'.
3685 (lambda (s) (concat s s)) header))
3686 ;; Hide the part of the first line
3687 ;; that is in the header, if it is just part.
3688 (unless (bobp)
3689 ;; Hide the punctuation at the end, too.
3690 (skip-chars-backward " \t,")
3691 (put-text-property (point) header-end 'invisible t)))))
3692
3693 ;; Fontify titles
3694 (goto-char (point-min))
3695 (when not-fontified-p
3696 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
3697 nil t)
3698 (let* ((c (preceding-char))
3699 (face
3700 (cond ((= c ?*) 'info-title-1)
3701 ((= c ?=) 'info-title-2)
3702 ((= c ?-) 'info-title-3)
3703 (t 'info-title-4))))
3704 (put-text-property (match-beginning 1) (match-end 1)
3705 'font-lock-face face))
3706 ;; This is a serious problem for trying to handle multiple
3707 ;; frame types at once. We want this text to be invisible
3708 ;; on frames that can display the font above.
3709 (when (memq (framep (selected-frame)) '(x pc w32 mac))
3710 (add-text-properties (1- (match-beginning 2)) (match-end 2)
3711 '(invisible t front-sticky nil rear-nonsticky t)))))
3712
3713 ;; Fontify cross references
3714 (goto-char (point-min))
3715 (when (or not-fontified-p fontify-visited-p)
3716 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
3717 (let ((start (match-beginning 0))
3718 (next (point))
3719 other-tag)
3720 (when not-fontified-p
3721 (when Info-hide-note-references
3722 (when (not (eq Info-hide-note-references 'hide))
3723 ;; *Note is often used where *note should have been
3724 (goto-char start)
3725 (skip-syntax-backward " ")
3726 (setq other-tag
3727 (cond ((memq (char-before) '(nil ?\. ?! ??))
3728 "See ")
3729 ((memq (char-before) '(?\, ?\; ?\: ?-))
3730 "see ")
3731 ((memq (char-before) '(?\( ?\[ ?\{))
3732 ;; Check whether the paren is preceded by
3733 ;; an end of sentence
3734 (skip-syntax-backward " (")
3735 (if (memq (char-before) '(nil ?\. ?! ??))
3736 "See "
3737 "see "))
3738 ((save-match-data (looking-at "\n\n"))
3739 "See "))))
3740 (goto-char next)
3741 (add-text-properties
3742 (match-beginning 1)
3743 (or (save-match-data
3744 ;; Don't hide \n after *Note
3745 (let ((start1 (match-beginning 1)))
3746 (if (string-match "\n" (match-string 1))
3747 (+ start1 (match-beginning 0)))))
3748 (match-end 1))
3749 (if other-tag
3750 `(display ,other-tag front-sticky nil rear-nonsticky t)
3751 '(invisible t front-sticky nil rear-nonsticky t))))
3752 (add-text-properties
3753 (match-beginning 2) (match-end 2)
3754 (list
3755 'help-echo (if (or (match-end 5)
3756 (not (equal (match-string 4) "")))
3757 (concat "mouse-2: go to " (or (match-string 5)
3758 (match-string 4)))
3759 "mouse-2: go to this node")
3760 'mouse-face 'highlight)))
3761 (when (or not-fontified-p fontify-visited-p)
3762 (setq rbeg (match-beginning 2)
3763 rend (match-end 2))
3764 (put-text-property
3765 rbeg rend
3766 'font-lock-face
3767 ;; Display visited nodes in a different face
3768 (if (and Info-fontify-visited-nodes
3769 (save-match-data
3770 (let* ((node (replace-regexp-in-string
3771 "^[ \t]+" ""
3772 (replace-regexp-in-string
3773 "[ \t\n]+" " "
3774 (or (match-string 5)
3775 (and (not (equal (match-string 4) ""))
3776 (match-string 4))
3777 (match-string 2)))))
3778 (file (file-name-nondirectory
3779 Info-current-file))
3780 (hl Info-history-list)
3781 res)
3782 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3783 (setq file (file-name-nondirectory
3784 (match-string 1 node))
3785 node (if (equal (match-string 2 node) "")
3786 "Top"
3787 (match-string 2 node))))
3788 (while hl
3789 (if (and (string-equal node (nth 1 (car hl)))
3790 (string-equal file
3791 (file-name-nondirectory
3792 (nth 0 (car hl)))))
3793 (setq res (car hl) hl nil)
3794 (setq hl (cdr hl))))
3795 res))) 'info-xref-visited 'info-xref))
3796 ;; For multiline ref, unfontify newline and surrounding whitespace
3797 (save-excursion
3798 (goto-char rbeg)
3799 (save-match-data
3800 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
3801 (remove-text-properties (match-beginning 0)
3802 (match-end 0)
3803 '(font-lock-face t))))))
3804 (when not-fontified-p
3805 (when (memq Info-hide-note-references '(t hide))
3806 (add-text-properties (match-beginning 3) (match-end 3)
3807 '(invisible t front-sticky nil rear-nonsticky t))
3808 ;; Unhide the file name of the external reference in parens
3809 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
3810 (remove-text-properties (match-beginning 6) (match-end 6)
3811 '(invisible t front-sticky nil rear-nonsticky t)))
3812 ;; Unhide newline because hidden newlines cause too long lines
3813 (save-match-data
3814 (let ((beg3 (match-beginning 3))
3815 (end3 (match-end 3)))
3816 (if (and (string-match "\n[ \t]*" (match-string 3))
3817 (not (save-match-data
3818 (save-excursion
3819 (goto-char (1+ end3))
3820 (looking-at "[.)]*$")))))
3821 (remove-text-properties (+ beg3 (match-beginning 0))
3822 (+ beg3 (match-end 0))
3823 '(invisible t front-sticky nil rear-nonsticky t))))))
3824 (when (and Info-refill-paragraphs Info-hide-note-references)
3825 (push (set-marker (make-marker) start)
3826 paragraph-markers))))))
3827
3828 ;; Refill paragraphs (experimental feature)
3829 (when (and not-fontified-p
3830 Info-refill-paragraphs
3831 paragraph-markers)
3832 (let ((fill-nobreak-invisible t)
3833 (fill-individual-varying-indent nil)
3834 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
3835 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
3836 (adaptive-fill-mode nil))
3837 (goto-char (point-max))
3838 (while paragraph-markers
3839 (let ((m (car paragraph-markers)))
3840 (setq paragraph-markers (cdr paragraph-markers))
3841 (when (< m (point))
3842 (goto-char m)
3843 (beginning-of-line)
3844 (let ((beg (point)))
3845 (when (zerop (forward-paragraph))
3846 (fill-individual-paragraphs beg (point) nil nil)
3847 (goto-char beg))))
3848 (set-marker m nil)))))
3849
3850 ;; Fontify menu items
3851 (goto-char (point-min))
3852 (when (and (or not-fontified-p fontify-visited-p)
3853 (search-forward "\n* Menu:" nil t)
3854 (not (Info-index-node))
3855 ;; Don't take time to annotate huge menus
3856 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
3857 (let ((n 0)
3858 cont)
3859 (while (re-search-forward
3860 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
3861 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
3862 nil t)
3863 (when (match-beginning 1)
3864 (when not-fontified-p
3865 (setq n (1+ n))
3866 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
3867 (put-text-property (match-beginning 0)
3868 (1+ (match-beginning 0))
3869 'font-lock-face 'info-menu-star)))
3870 (when not-fontified-p
3871 (add-text-properties
3872 (match-beginning 1) (match-end 1)
3873 (list
3874 'help-echo (if (and (match-end 3)
3875 (not (equal (match-string 3) "")))
3876 (concat "mouse-2: go to " (match-string 3))
3877 "mouse-2: go to this node")
3878 'mouse-face 'highlight)))
3879 (when (or not-fontified-p fontify-visited-p)
3880 (add-text-properties
3881 (match-beginning 1) (match-end 1)
3882 (list
3883 'font-lock-face
3884 ;; Display visited menu items in a different face
3885 (if (and Info-fontify-visited-nodes
3886 (save-match-data
3887 (let ((node (if (equal (match-string 3) "")
3888 (match-string 1)
3889 (match-string 3)))
3890 (file (file-name-nondirectory Info-current-file))
3891 (hl Info-history-list)
3892 res)
3893 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3894 (setq file (file-name-nondirectory
3895 (match-string 1 node))
3896 node (if (equal (match-string 2 node) "")
3897 "Top"
3898 (match-string 2 node))))
3899 (while hl
3900 (if (and (string-equal node (nth 1 (car hl)))
3901 (string-equal file
3902 (file-name-nondirectory
3903 (nth 0 (car hl)))))
3904 (setq res (car hl) hl nil)
3905 (setq hl (cdr hl))))
3906 res))) 'info-xref-visited 'info-xref))))
3907 (when (and not-fontified-p (memq Info-hide-note-references '(t hide)))
3908 (put-text-property (match-beginning 2) (1- (match-end 6))
3909 'invisible t)
3910 ;; Unhide the file name in parens
3911 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
3912 (remove-text-properties (match-beginning 4) (match-end 4)
3913 '(invisible t)))
3914 ;; We need a stretchable space like :align-to but with
3915 ;; a minimum value.
3916 (put-text-property (1- (match-end 6)) (match-end 6) 'display
3917 (if (>= 22 (- (match-end 1)
3918 (match-beginning 0)))
3919 '(space :align-to 24)
3920 '(space :width 2)))
3921 (setq cont (looking-at "."))
3922 (while (and (= (forward-line 1) 0)
3923 (looking-at "\\([ \t]+\\)[^*\n]"))
3924 (put-text-property (match-beginning 1) (1- (match-end 1))
3925 'invisible t)
3926 (put-text-property (1- (match-end 1)) (match-end 1)
3927 'display
3928 (if cont
3929 '(space :align-to 26)
3930 '(space :align-to 24)))
3931 (setq cont t)))))))
3932
3933 ;; Fontify menu headers
3934 ;; Add the face `info-menu-header' to any header before a menu entry
3935 (goto-char (point-min))
3936 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
3937 (put-text-property (match-beginning 0) (match-end 0)
3938 'font-lock-face 'info-menu-header)
3939 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
3940 (put-text-property (match-beginning 1) (match-end 1)
3941 'font-lock-face 'info-menu-header)))
3942
3943 ;; Hide index line numbers
3944 (goto-char (point-min))
3945 (when (and not-fontified-p (Info-index-node))
3946 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
3947 (put-text-property (match-beginning 0) (match-end 0)
3948 'invisible t)))
3949
3950 ;; Fontify http and ftp references
3951 (goto-char (point-min))
3952 (when not-fontified-p
3953 (while (re-search-forward "[hf]t?tp://[^ \t\n\"`({<>})']+" nil t)
3954 (add-text-properties (match-beginning 0) (match-end 0)
3955 '(font-lock-face info-xref
3956 mouse-face highlight
3957 help-echo "mouse-2: go to this URL"))))
3958
3959 (set-buffer-modified-p nil))))
3960 \f
3961 ;;; Speedbar support:
3962 ;; These functions permit speedbar to display the "tags" in the
3963 ;; current Info node.
3964 (eval-when-compile (require 'speedbar))
3965
3966 (defvar Info-speedbar-key-map nil
3967 "Keymap used when in the info display mode.")
3968
3969 (defun Info-install-speedbar-variables ()
3970 "Install those variables used by speedbar to enhance Info."
3971 (if Info-speedbar-key-map
3972 nil
3973 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
3974
3975 ;; Basic tree features
3976 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
3977 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
3978 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
3979 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
3980 )
3981
3982 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
3983 Info-speedbar-key-map
3984 Info-speedbar-hierarchy-buttons)))
3985
3986 (defvar Info-speedbar-menu-items
3987 '(["Browse Node" speedbar-edit-line t]
3988 ["Expand Node" speedbar-expand-line
3989 (save-excursion (beginning-of-line)
3990 (looking-at "[0-9]+: *.\\+. "))]
3991 ["Contract Node" speedbar-contract-line
3992 (save-excursion (beginning-of-line)
3993 (looking-at "[0-9]+: *.-. "))]
3994 )
3995 "Additional menu-items to add to speedbar frame.")
3996
3997 ;; Make sure our special speedbar major mode is loaded
3998 (if (featurep 'speedbar)
3999 (Info-install-speedbar-variables)
4000 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4001
4002 ;;; Info hierarchy display method
4003 ;;;###autoload
4004 (defun Info-speedbar-browser ()
4005 "Initialize speedbar to display an Info node browser.
4006 This will add a speedbar major display mode."
4007 (interactive)
4008 (require 'speedbar)
4009 ;; Make sure that speedbar is active
4010 (speedbar-frame-mode 1)
4011 ;; Now, throw us into Info mode on speedbar.
4012 (speedbar-change-initial-expansion-list "Info")
4013 )
4014
4015 (eval-when-compile (defvar speedbar-attached-frame))
4016
4017 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
4018 "Display an Info directory hierarchy in speedbar.
4019 DIRECTORY is the current directory in the attached frame.
4020 DEPTH is the current indentation depth.
4021 NODE is an optional argument that is used to represent the
4022 specific node to expand."
4023 (if (and (not node)
4024 (save-excursion (goto-char (point-min))
4025 (let ((case-fold-search t))
4026 (looking-at "Info Nodes:"))))
4027 ;; Update our "current node" maybe?
4028 nil
4029 ;; We cannot use the generic list code, that depends on all leaves
4030 ;; being known at creation time.
4031 (if (not node)
4032 (speedbar-with-writable (insert "Info Nodes:\n")))
4033 (let ((completions nil)
4034 (cf (selected-frame)))
4035 (select-frame speedbar-attached-frame)
4036 (save-window-excursion
4037 (setq completions
4038 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
4039 (select-frame cf)
4040 (if completions
4041 (speedbar-with-writable
4042 (dolist (completion completions)
4043 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
4044 (cdr completion)
4045 (car completion)
4046 'Info-speedbar-goto-node
4047 (cdr completion)
4048 'info-xref depth))
4049 t)
4050 nil))))
4051
4052 (defun Info-speedbar-goto-node (text node indent)
4053 "When user clicks on TEXT, go to an info NODE.
4054 The INDENT level is ignored."
4055 (select-frame speedbar-attached-frame)
4056 (let* ((buff (or (get-buffer "*info*")
4057 (progn (info) (get-buffer "*info*"))))
4058 (bwin (get-buffer-window buff 0)))
4059 (if bwin
4060 (progn
4061 (select-window bwin)
4062 (raise-frame (window-frame bwin)))
4063 (if speedbar-power-click
4064 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
4065 (select-frame speedbar-attached-frame)
4066 (switch-to-buffer buff)))
4067 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4068 (error "Invalid node %s" node)
4069 (Info-find-node (match-string 1 node) (match-string 2 node))
4070 ;; If we do a find-node, and we were in info mode, restore
4071 ;; the old default method. Once we are in info mode, it makes
4072 ;; sense to return to whatever method the user was using before.
4073 (if (string= speedbar-initial-expansion-list-name "Info")
4074 (speedbar-change-initial-expansion-list
4075 speedbar-previously-used-expansion-list-name)))))
4076
4077 (defun Info-speedbar-expand-node (text token indent)
4078 "Expand the node the user clicked on.
4079 TEXT is the text of the button we clicked on, a + or - item.
4080 TOKEN is data related to this node (NAME . FILE).
4081 INDENT is the current indentation depth."
4082 (cond ((string-match "+" text) ;we have to expand this file
4083 (speedbar-change-expand-button-char ?-)
4084 (if (speedbar-with-writable
4085 (save-excursion
4086 (end-of-line) (forward-char 1)
4087 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4088 (speedbar-change-expand-button-char ?-)
4089 (speedbar-change-expand-button-char ??)))
4090 ((string-match "-" text) ;we have to contract this node
4091 (speedbar-change-expand-button-char ?+)
4092 (speedbar-delete-subblock indent))
4093 (t (error "Ooops... not sure what to do")))
4094 (speedbar-center-buffer-smartly))
4095
4096 (defun Info-speedbar-fetch-file-nodes (nodespec)
4097 "Fetch the subnodes from the info NODESPEC.
4098 NODESPEC is a string of the form: (file)node."
4099 (save-excursion
4100 ;; Set up a buffer we can use to fake-out Info.
4101 (set-buffer (get-buffer-create "*info-browse-tmp*"))
4102 (if (not (equal major-mode 'Info-mode))
4103 (Info-mode))
4104 ;; Get the node into this buffer
4105 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4106 (error "Invalid node specification %s" nodespec)
4107 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4108 ;; Scan the created buffer
4109 (goto-char (point-min))
4110 (let ((completions nil)
4111 (case-fold-search t)
4112 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4113 (match-string 1 nodespec))))
4114 ;; Always skip the first one...
4115 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4116 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4117 (let ((name (match-string 1)))
4118 (push (cons name
4119 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4120 (match-string 1)
4121 (if (looking-at " *\\(([^)]+)\\)\\.")
4122 (concat (match-string 1) "Top")
4123 (concat "(" thisfile ")"
4124 (if (looking-at " \\([^.]+\\).")
4125 (match-string 1)
4126 name)))))
4127 completions)))
4128 (nreverse completions))))
4129
4130 ;;; Info mode node listing
4131 ;; FIXME: Seems not to be used. -stef
4132 (defun Info-speedbar-buttons (buffer)
4133 "Create a speedbar display to help navigation in an Info file.
4134 BUFFER is the buffer speedbar is requesting buttons for."
4135 (if (save-excursion (goto-char (point-min))
4136 (let ((case-fold-search t))
4137 (not (looking-at "Info Nodes:"))))
4138 (erase-buffer))
4139 (Info-speedbar-hierarchy-buttons nil 0)
4140 )
4141
4142 (dolist (mess '("^First node in file$"
4143 "^No `.*' in index$"
4144 "^No cross-reference named"
4145 "^No cross.references in this node$"
4146 "^No current Info node$"
4147 "^No menu in this node$"
4148 "^No more items in menu$"
4149 "^No more nodes$"
4150 "^No pointer \\(?:forward\\|backward\\) from this node$"
4151 "^No previous `i' command$"
4152 "^No previous items in menu$"
4153 "^No previous nodes$"
4154 "^No such item in menu$"
4155 "^No such node or anchor"
4156 "^Node has no"
4157 "^Point neither on reference nor in menu item description$"
4158 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4159 search-failed))
4160 (add-to-list 'debug-ignored-errors mess))
4161
4162 ;;;; Desktop support
4163
4164 (defun Info-desktop-buffer-misc-data (desktop-dirname)
4165 "Auxiliary information to be saved in desktop file."
4166 (if (not (member Info-current-file '("apropos" "history" "toc")))
4167 (list Info-current-file Info-current-node)))
4168
4169 (defun Info-restore-desktop-buffer (desktop-buffer-file-name
4170 desktop-buffer-name
4171 desktop-buffer-misc)
4172 "Restore an Info buffer specified in a desktop file."
4173 (let ((first (nth 0 desktop-buffer-misc))
4174 (second (nth 1 desktop-buffer-misc)))
4175 (when (and first second)
4176 (when desktop-buffer-name
4177 (set-buffer (get-buffer-create desktop-buffer-name))
4178 (Info-mode))
4179 (Info-find-node first second)
4180 (current-buffer))))
4181
4182 (add-to-list 'desktop-buffer-mode-handlers
4183 '(Info-mode . Info-restore-desktop-buffer))
4184
4185 (provide 'info)
4186
4187 ;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
4188 ;;; info.el ends here