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