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