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