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