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