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