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