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