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