1 ;;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985,86,92,93,94,95,96,97,98,99,2000,01,02,03,2004
4 ;; Free Software Foundation, Inc.
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)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
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 ": ".
38 (eval-when-compile (require 'jka-compr))
46 (defvar Info-history nil
47 "Stack of info nodes user has visited.
48 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
50 (defvar Info-history-forward nil
51 "Stack of info nodes user has visited with `Info-history-back' command.
52 Each element of list is a list (FILENAME NODENAME BUFFERPOS).")
54 (defvar Info-history-list nil
55 "List of all info nodes user has visited.
56 Each element of list is a list (FILENAME NODENAME).")
58 (defcustom Info-enable-edit nil
59 "*Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
60 This is convenient if you want to write info files by hand.
61 However, we recommend that you not do this.
62 It is better to write a Texinfo file and generate the Info file from that,
63 because that gives you a printed manual as well."
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)
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."
80 '((((class color)) :foreground "red1")
82 "Face for every third `*' in an Info menu."
86 '((((class color) (background light)) :foreground "blue" :underline t)
87 (((class color) (background dark)) :foreground "cyan" :underline t)
89 "Face for Info cross-references."
92 (defface info-xref-visited
93 '((default :inherit info-xref)
94 (((class color) (background light)) :foreground "magenta4")
95 (((class color) (background dark)) :foreground "magenta3")) ;"violet"?
96 "Face for visited Info cross-references."
99 (defcustom Info-fontify-visited-nodes t
100 "*Non-nil means to fontify visited nodes in a different face."
105 (defcustom Info-fontify-maximum-menu-size 100000
106 "*Maximum size of menu to fontify if `font-lock-mode' is non-nil."
110 (defcustom Info-use-header-line t
111 "*Non-nil means to put the beginning-of-node links in an Emacs header-line.
112 A header-line does not scroll with the rest of the buffer."
116 (defface info-header-xref
117 '((t :inherit info-xref))
118 "Face for Info cross-references in a node header."
121 (defface info-header-node
122 '((t :inherit info-node))
123 "Face for Info nodes in a node header."
126 (defvar Info-directory-list nil
127 "List of directories to search for Info documentation files.
128 If nil, meaning not yet initialized, Info uses the environment
129 variable INFOPATH to initialize it, or `Info-default-directory-list'
130 if there is no INFOPATH variable in the environment, or the
131 concatenation of the two if INFOPATH ends with a colon.
133 When `Info-directory-list' is initialized from the value of
134 `Info-default-directory-list', and Emacs is installed in one of the
135 standard directories, the directory of Info files that come with Emacs
136 is put last (so that local Info files override standard ones).
138 When `Info-directory-list' is initialized from the value of
139 `Info-default-directory-list', and Emacs is not installed in one
140 of the standard directories, the first element of the resulting
141 list is the directory where Emacs installs the Info files that
142 come with it. This is so that Emacs's own manual, which suits the
143 version of Emacs you are using, will always be found first. This
144 is useful when you install an experimental version of Emacs without
145 removing the standard installation.
147 If you want to override the order of directories in
148 `Info-default-directory-list', set INFOPATH in the environment.
150 If you run the Emacs executable from the `src' directory in the Emacs
151 source tree, and INFOPATH is not defined, the `info' directory in the
152 source tree is used as the first element of `Info-directory-list', in
153 place of the installation Info directory. This is useful when you run
154 a version of Emacs without installing it.")
156 (defcustom Info-additional-directory-list nil
157 "List of additional directories to search for Info documentation files.
158 These directories are searched after those in `Info-directory-list'."
159 :type '(repeat directory)
162 (defcustom Info-scroll-prefer-subnodes nil
163 "*If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
164 If this is non-nil, and you scroll far enough in a node that its menu
165 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
166 moves to a subnode indicated by the following menu item. This means
167 that you visit a subnode before getting to the end of the menu.
169 Setting this option to nil results in behavior similar to the stand-alone
170 Info reader program, which visits the first subnode from the menu only
171 when you hit the end of the current node."
176 (defcustom Info-hide-note-references t
177 "*If non-nil, hide the tag and section reference in *note and * menu items.
178 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
179 If value is non-nil but not t or `hide', the reference section is still shown."
181 :type '(choice (const :tag "No hiding" nil)
182 (const :tag "Replace tag and hide reference" t)
183 (const :tag "Hide tag and reference" hide)
184 (other :tag "Only replace tag" tag))
187 (defcustom Info-refill-paragraphs nil
188 "*If non-nil, attempt to refill paragraphs with hidden references.
189 This refilling may accidentally remove explicit line breaks in the info
190 file, so be prepared for a few surprises if you enable this feature."
195 (defcustom Info-search-whitespace-regexp "\\s-+"
196 "*If non-nil, regular expression to match a sequence of whitespace chars.
197 This applies to Info search for regular expressions.
198 You might want to use something like \"[ \\t\\r\\n]+\" instead.
199 In the Customization buffer, that is `[' followed by a space,
200 a tab, a carriage return (control-M), a newline, and `]+'."
204 (defcustom Info-isearch-search t
205 "*If non-nil, isearch invoked in Info mode uses `Info-search' function.
206 This allows isearch to search through multiple nodes.
207 When isearch fails, it wraps and restarts the search from the
208 top/final node depending on search direction."
213 (defcustom Info-mode-hook
214 ;; Try to obey obsolete Info-fontify settings.
215 (unless (and (boundp 'Info-fontify) (null Info-fontify))
216 '(turn-on-font-lock))
217 "Hooks run when `Info-mode' is called."
221 (defcustom Info-selection-hook nil
222 "Hooks run when `Info-select-node' is called."
226 (defvar Info-edit-mode-hook nil
227 "Hooks run when `Info-edit-mode' is called.")
229 (defvar Info-current-file nil
230 "Info file that Info is now looking at, or nil.
231 This is the name that was specified in Info, not the actual file name.
232 It doesn't contain directory names or file name extensions added by Info.
233 Can also be t when using `Info-on-current-buffer'.")
235 (defvar Info-current-subfile nil
236 "Info subfile that is actually in the *info* buffer now.
237 nil if current info file is not split into subfiles.")
239 (defvar Info-current-node nil
240 "Name of node that Info is now looking at, or nil.")
242 (defvar Info-tag-table-marker nil
243 "Marker pointing at beginning of current Info file's tag table.
244 Marker points nowhere if file has no tag table.")
246 (defvar Info-tag-table-buffer nil
247 "Buffer used for indirect tag tables.")
249 (defvar Info-current-file-completions nil
250 "Cached completion list for current Info file.")
252 (defvar Info-index-alternatives nil
253 "List of possible matches for last `Info-index' command.")
255 (defvar Info-point-loc nil
256 "Point location within a selected node.
257 If string, the point is moved to the proper occurrence of the
258 name of the followed cross reference within a selected node.
259 If number, the point is moved to the corresponding line.")
261 (defvar Info-standalone nil
262 "Non-nil if Emacs was started solely as an Info browser.")
264 (defvar Info-suffix-list
265 ;; The MS-DOS list should work both when long file names are
266 ;; supported (Windows 9X), and when only 8+3 file names are available.
267 (if (eq system-type 'ms-dos)
268 '( (".gz" . "gunzip")
270 (".bz2" . ("bzip2" "-dc"))
273 (".info.Z" . "gunzip")
274 (".info.gz" . "gunzip")
275 ("-info.Z" . "gunzip")
276 ("-info.gz" . "gunzip")
277 ("/index.gz". "gunzip")
278 ("/index.z" . "gunzip")
284 '( (".info.Z". "uncompress")
285 (".info.Y". "unyabba")
286 (".info.gz". "gunzip")
287 (".info.z". "gunzip")
288 (".info.bz2" . ("bzip2" "-dc"))
290 ("-info.Z". "uncompress")
291 ("-info.Y". "unyabba")
292 ("-info.gz". "gunzip")
293 ("-info.bz2" . ("bzip2" "-dc"))
294 ("-info.z". "gunzip")
296 ("/index.Z". "uncompress")
297 ("/index.Y". "unyabba")
298 ("/index.gz". "gunzip")
299 ("/index.z". "gunzip")
300 ("/index.bz2". ("bzip2" "-dc"))
306 (".bz2" . ("bzip2" "-dc"))
308 "List of file name suffixes and associated decoding commands.
309 Each entry should be (SUFFIX . STRING); the file is given to
310 the command as standard input.
312 STRING may be a list of strings. In that case, the first element is
313 the command name, and the rest are arguments to that command.
315 If STRING is nil, no decoding is done.
316 Because the SUFFIXes are tried in order, the empty string should
317 be last in the list.")
319 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
320 ;; First, on MS-DOS with no long file names support, delete some of
321 ;; the extension in FILENAME to make room.
322 (defun info-insert-file-contents-1 (filename suffix lfn)
323 (if lfn ; long file names are supported
324 (concat filename suffix)
325 (let* ((sans-exts (file-name-sans-extension filename))
326 ;; How long is the extension in FILENAME (not counting the dot).
327 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
329 ;; SUFFIX starts with a dot. If FILENAME already has one,
330 ;; get rid of the one in SUFFIX (unless suffix is empty).
331 (or (and (<= ext-len 0)
332 (not (eq (aref filename (1- (length filename))) ?.)))
333 (= (length suffix) 0)
334 (setq suffix (substring suffix 1)))
335 ;; How many chars of that extension should we keep?
336 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
337 ;; Get rid of the rest of the extension, and add SUFFIX.
338 (concat (substring filename 0 (- (length filename)
339 (- ext-len ext-left)))
342 (defun info-file-exists-p (filename)
343 (and (file-exists-p filename)
344 (not (file-directory-p filename))))
346 (defun info-insert-file-contents (filename &optional visit)
347 "Insert the contents of an info file in the current buffer.
348 Do the right thing if the file has been compressed or zipped."
349 (let* ((tail Info-suffix-list)
350 (lfn (if (fboundp 'msdos-long-file-names)
351 (msdos-long-file-names)
353 (check-short (and (fboundp 'msdos-long-file-names)
355 fullname decoder done)
356 (if (info-file-exists-p filename)
357 ;; FILENAME exists--see if that name contains a suffix.
358 ;; If so, set DECODE accordingly.
362 (concat (regexp-quote (car (car tail))) "$")
364 (setq tail (cdr tail)))
365 (setq fullname filename
366 decoder (cdr (car tail))))
367 ;; Try adding suffixes to FILENAME and see if we can find something.
368 (while (and tail (not done))
369 (setq fullname (info-insert-file-contents-1 filename
370 (car (car tail)) lfn))
371 (if (info-file-exists-p fullname)
373 ;; If we found a file with a suffix, set DECODER
374 ;; according to the suffix.
375 decoder (cdr (car tail)))
376 ;; When the MS-DOS port runs on Windows, we need to check
377 ;; the short variant of a long file name as well.
379 (setq fullname (info-insert-file-contents-1 filename
380 (car (car tail)) nil))
381 (if (info-file-exists-p fullname)
383 decoder (cdr (car tail))))))
384 (setq tail (cdr tail)))
386 (error "Can't find %s or any compressed version of it" filename)))
387 ;; check for conflict with jka-compr
388 (if (and (featurep 'jka-compr)
389 (jka-compr-installed-p)
390 (jka-compr-get-compression-info fullname))
394 (insert-file-contents-literally fullname visit)
395 (let ((buffer-read-only nil)
396 (coding-system-for-write 'no-conversion)
397 (default-directory (or (file-name-directory fullname)
400 (setq decoder (list decoder)))
401 (apply 'call-process-region (point-min) (point-max)
402 (car decoder) t t nil (cdr decoder))))
403 (insert-file-contents fullname visit))))
405 (defun Info-default-dirs ()
406 (let ((source (expand-file-name "info/" source-directory))
407 (sibling (if installation-directory
408 (expand-file-name "info/" installation-directory)
409 (if invocation-directory
410 (let ((infodir (expand-file-name
412 invocation-directory)))
413 (if (file-exists-p infodir)
415 (setq infodir (expand-file-name
417 invocation-directory))
418 (and (file-exists-p infodir)
422 (if (and sibling (file-exists-p sibling))
423 ;; Uninstalled, Emacs builddir != srcdir.
425 ;; Uninstalled, builddir == srcdir
427 (if (or (member alternative Info-default-directory-list)
428 ;; On DOS/NT, we use movable executables always,
429 ;; and we must always find the Info dir at run time.
430 (if (memq system-type '(ms-dos windows-nt))
432 ;; Use invocation-directory for Info
433 ;; only if we used it for exec-directory also.
434 (not (string= exec-directory
435 (expand-file-name "lib-src/"
436 installation-directory))))
437 (not (file-exists-p alternative)))
438 Info-default-directory-list
439 ;; `alternative' contains the Info files that came with this
440 ;; version, so we should look there first. `Info-insert-dir'
441 ;; currently expects to find `alternative' first on the list.
443 ;; Don't drop the last part, it might contain non-Emacs stuff.
444 ;; (reverse (cdr (reverse
445 Info-default-directory-list)))) ;; )))
447 (defun info-initialize ()
448 "Initialize `Info-directory-list', if that hasn't been done yet."
449 (unless Info-directory-list
450 (let ((path (getenv "INFOPATH")))
451 (setq Info-directory-list
452 (prune-directory-list
454 (if (string-match ":\\'" path)
455 (append (split-string (substring path 0 -1)
456 (regexp-quote path-separator))
458 (split-string path (regexp-quote path-separator)))
459 (Info-default-dirs)))))))
462 (defun info-other-window (&optional file)
463 "Like `info' but show the Info buffer in another window."
464 (interactive (if current-prefix-arg
465 (list (read-file-name "Info file name: " nil nil t))))
466 (let (same-window-buffer-names same-window-regexps)
469 ;;;###autoload (add-hook 'same-window-regexps "\\*info\\*\\(\\|<[0-9]+>\\)")
471 ;;;###autoload (put 'info 'info-file "emacs")
473 (defun info (&optional file buffer)
474 "Enter Info, the documentation browser.
475 Optional argument FILE specifies the file to examine;
476 the default is the top-level directory of Info.
477 Called from a program, FILE may specify an Info node of the form
478 `(FILENAME)NODENAME'.
479 Optional argument BUFFER specifies the Info buffer name;
480 the default buffer name is *info*. If BUFFER exists,
481 just switch to BUFFER. Otherwise, create a new buffer
482 with the top-level Info directory.
484 In interactive use, a non-numeric prefix argument directs
485 this command to read a file name from the minibuffer.
486 A numeric prefix argument selects an Info buffer with the prefix number
487 appended to the Info buffer name.
489 The search path for Info files is in the variable `Info-directory-list'.
490 The top-level Info directory is made by combining all the files named `dir'
491 in all the directories in that path."
493 (if (and current-prefix-arg (not (numberp current-prefix-arg)))
494 (read-file-name "Info file name: " nil nil t))
495 (if (numberp current-prefix-arg)
496 (format "*info*<%s>" current-prefix-arg))))
497 (pop-to-buffer (or buffer "*info*"))
498 (if (and buffer (not (eq major-mode 'Info-mode)))
501 ;; If argument already contains parentheses, don't add another set
502 ;; since the argument will then be parsed improperly. This also
503 ;; has the added benefit of allowing node names to be included
504 ;; following the parenthesized filename.
505 (if (and (stringp file) (string-match "(.*)" file))
506 (Info-goto-node file)
507 (Info-goto-node (concat "(" file ")")))
508 (if (zerop (buffer-size))
512 (defun info-emacs-manual ()
513 "Display the Emacs manual in Info mode."
518 (defun info-standalone ()
519 "Run Emacs as a standalone Info reader.
520 Usage: emacs -f info-standalone [filename]
521 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
522 (setq Info-standalone t)
523 (if (and command-line-args-left
524 (not (string-match "^-" (car command-line-args-left))))
527 (info (car command-line-args-left))
528 (setq command-line-args-left (cdr command-line-args-left)))
529 (error (send-string-to-terminal
530 (format "%s\n" (if (eq (car-safe err) 'error)
532 (save-buffers-kill-emacs)))
535 ;; See if the accessible portion of the buffer begins with a node
536 ;; delimiter, and the node header line which follows matches REGEXP.
537 ;; Typically, this test will be followed by a loop that examines the
538 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
539 ;; to have the overhead of this special test inside the loop.
541 ;; This function changes match-data, but supposedly the caller might
542 ;; want to use the results of re-search-backward.
544 ;; The return value is the value of point at the beginning of matching
545 ;; REGEXP, if the function succeeds, nil otherwise.
546 (defun Info-node-at-bob-matching (regexp)
547 (and (bobp) ; are we at beginning of buffer?
548 (looking-at "\^_") ; does it begin with node delimiter?
552 (forward-line 1) ; does the line after delimiter match REGEXP?
553 (re-search-backward regexp beg t))))
555 (defun Info-find-file (filename &optional noerror)
556 "Return expanded FILENAME, or t, if FILENAME is \"dir\".
557 Optional second argument NOERROR, if t, means if file is not found
558 just return nil (no error)."
559 ;; Convert filename to lower case if not found as specified.
561 (if (stringp filename)
562 (let (temp temp-downcase found)
563 (setq filename (substitute-in-file-name filename))
565 ((string= (downcase filename) "dir")
567 ((string= filename "apropos")
568 (setq found 'apropos))
569 ((string= filename "history")
570 (setq found 'history))
571 ((string= filename "toc")
574 (let ((dirs (if (string-match "^\\./" filename)
575 ;; If specified name starts with `./'
576 ;; then just try current directory.
578 (if (file-name-absolute-p filename)
579 ;; No point in searching for an
580 ;; absolute file name
582 (if Info-additional-directory-list
583 (append Info-directory-list
584 Info-additional-directory-list)
585 Info-directory-list)))))
586 ;; Search the directory list for file FILENAME.
587 (while (and dirs (not found))
588 (setq temp (expand-file-name filename (car dirs)))
590 (expand-file-name (downcase filename) (car dirs)))
591 ;; Try several variants of specified name.
592 (let ((suffix-list Info-suffix-list)
593 (lfn (if (fboundp 'msdos-long-file-names)
594 (msdos-long-file-names)
596 (while (and suffix-list (not found))
597 (cond ((info-file-exists-p
598 (info-insert-file-contents-1
599 temp (car (car suffix-list)) lfn))
602 (info-insert-file-contents-1
603 temp-downcase (car (car suffix-list)) lfn))
604 (setq found temp-downcase))
605 ((and (fboundp 'msdos-long-file-names)
608 (info-insert-file-contents-1
609 temp (car (car suffix-list)) nil)))
611 (setq suffix-list (cdr suffix-list))))
612 (setq dirs (cdr dirs))))))
614 (setq filename found)
617 (error "Info file %s does not exist" filename)))
620 (defun Info-find-node (filename nodename &optional no-going-back)
621 "Go to an info node specified as separate FILENAME and NODENAME.
622 NO-GOING-BACK is non-nil if recovering from an error in this function;
623 it says do not attempt further (recursive) error recovery."
625 (setq filename (Info-find-file filename))
626 ;; Record the node we are leaving.
627 (if (and Info-current-file (not no-going-back))
629 (cons (list Info-current-file Info-current-node (point))
631 ;; Go into info buffer.
632 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
633 (Info-find-node-2 filename nodename no-going-back))
635 (defun Info-on-current-buffer (&optional nodename)
636 "Use the `Info-mode' to browse the current info buffer.
637 If a prefix arg is provided, it queries for the NODENAME which
638 else defaults to \"Top\"."
640 (list (if current-prefix-arg
641 (completing-read "Node name: " (Info-build-node-completions)
643 (unless nodename (setq nodename "Top"))
646 (set (make-local-variable 'Info-current-file) t)
647 (Info-find-node-2 nil nodename))
649 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
650 ;; but at least it keeps this routine (which is only for the benefit of
651 ;; makeinfo-buffer) out of the way of normal operations.
653 (defun Info-revert-find-node (filename nodename)
654 "Go to an info node FILENAME and NODENAME, re-reading disk contents.
655 When *info* is already displaying FILENAME and NODENAME, the window position
656 is preserved, if possible."
657 (pop-to-buffer "*info*")
658 (let ((old-filename Info-current-file)
659 (old-nodename Info-current-node)
660 (pcolumn (current-column))
661 (pline (count-lines (point-min) (line-beginning-position)))
662 (wline (count-lines (point-min) (window-start)))
663 (old-history Info-history)
664 (new-history (and Info-current-file
665 (list Info-current-file Info-current-node (point)))))
666 (kill-buffer (current-buffer))
667 (Info-find-node filename nodename)
668 (setq Info-history old-history)
669 (if (and (equal old-filename Info-current-file)
670 (equal old-nodename Info-current-node))
672 ;; note goto-line is no good, we want to measure from point-min
673 (goto-char (point-min))
675 (set-window-start (selected-window) (point))
676 (goto-char (point-min))
678 (move-to-column pcolumn))
679 ;; only add to the history when coming from a different file+node
681 (setq Info-history (cons new-history Info-history))))))
683 (defun Info-find-in-tag-table-1 (marker regexp case-fold)
684 "Find a node in a tag table.
685 MARKER specifies the buffer and position to start searching at.
686 REGEXP is a regular expression matching nodes or references. Its first
687 group should match `Node:' or `Ref:'.
688 CASE-FOLD t means search for a case-insensitive match.
689 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
690 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
691 where the match was found, and MODE is `major-mode' of the buffer in
692 which the match was found."
693 (let ((case-fold-search case-fold))
695 (set-buffer (marker-buffer marker))
700 (when (re-search-forward regexp nil t)
701 (list (string-equal "Ref:" (match-string 1))
702 (+ (point-min) (read (current-buffer)))
705 (defun Info-find-in-tag-table (marker regexp)
706 "Find a node in a tag table.
707 MARKER specifies the buffer and position to start searching at.
708 REGEXP is a regular expression matching nodes or references. Its first
709 group should match `Node:' or `Ref:'.
710 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
711 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
712 where the match was found, and MODE is `major-mode' of the buffer in
713 which the match was found.
714 This function tries to find a case-sensitive match first, then a
715 case-insensitive match is tried."
716 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
717 (when (null (car result))
718 (setq result (Info-find-in-tag-table-1 marker regexp t)))
721 (defun Info-find-node-in-buffer-1 (regexp case-fold)
722 "Find a node or anchor in the current buffer.
723 REGEXP is a regular expression matching nodes or references. Its first
724 group should match `Node:' or `Ref:'.
725 CASE-FOLD t means search for a case-insensitive match.
726 Value is the position at which a match was found, or nil if not found."
727 (let ((case-fold-search case-fold)
730 (when (Info-node-at-bob-matching regexp)
731 (setq found (point)))
732 (while (and (not found)
733 (search-forward "\n\^_" nil t))
737 (when (re-search-backward regexp beg t)
739 (setq found (point)))))
742 (defun Info-find-node-in-buffer (regexp)
743 "Find a node or anchor in the current buffer.
744 REGEXP is a regular expression matching nodes or references. Its first
745 group should match `Node:' or `Ref:'.
746 Value is the position at which a match was found, or nil if not found.
747 This function looks for a case-sensitive match first. If none is found,
748 a case-insensitive match is tried."
749 (or (Info-find-node-in-buffer-1 regexp nil)
750 (Info-find-node-in-buffer-1 regexp t)))
752 (defun Info-find-node-2 (filename nodename &optional no-going-back)
753 (buffer-disable-undo (current-buffer))
754 (or (eq major-mode 'Info-mode)
757 (setq Info-current-node nil)
759 (let ((case-fold-search t)
761 ;; Switch files if necessary
763 (equal Info-current-file filename)
764 (let ((buffer-read-only nil))
765 (setq Info-current-file nil
766 Info-current-subfile nil
767 Info-current-file-completions nil
768 buffer-file-name nil)
773 ((eq filename 'apropos)
774 (insert-buffer-substring " *info-apropos*"))
775 ((eq filename 'history)
776 (insert-buffer-substring " *info-history*"))
778 (insert-buffer-substring " *info-toc*"))
780 (info-insert-file-contents filename nil)
781 (setq default-directory (file-name-directory filename))))
782 (set-buffer-modified-p nil)
783 ;; See whether file has a tag table. Record the location if yes.
784 (goto-char (point-max))
786 ;; Use string-equal, not equal, to ignore text props.
787 (if (not (or (string-equal nodename "*")
789 (search-forward "\^_\nEnd tag table\n" nil t))))
791 ;; We have a tag table. Find its beginning.
792 ;; Is this an indirect file?
793 (search-backward "\nTag table:\n")
797 (looking-at "(Indirect)\n"))
798 ;; It is indirect. Copy it to another buffer
799 ;; and record that the tag table is in that buffer.
800 (let ((buf (current-buffer))
802 (or Info-tag-table-buffer
803 (generate-new-buffer " *info tag table*"))))
804 (setq Info-tag-table-buffer tagbuf)
807 (buffer-disable-undo (current-buffer))
808 (setq case-fold-search t)
810 (insert-buffer-substring buf))
811 (set-marker Info-tag-table-marker
812 (match-end 0) tagbuf))
813 (set-marker Info-tag-table-marker pos)))
814 (set-marker Info-tag-table-marker nil))
815 (setq Info-current-file
817 ((eq filename t) "dir")
818 ((eq filename 'apropos) "apropos")
819 ((eq filename 'history) "history")
820 ((eq filename 'toc) "toc")
823 ;; Use string-equal, not equal, to ignore text props.
824 (if (string-equal nodename "*")
825 (progn (setq Info-current-node nodename)
826 (Info-set-mode-line))
829 ;; 1. Anchor found in tag table
830 ;; 2. Anchor *not* in tag table
832 ;; 3. Node found in tag table
833 ;; 4. Node *not* found in tag table, but found in file
834 ;; 5. Node *not* in tag table, and *not* in file
836 ;; *Or* the same, but in an indirect subfile.
838 ;; Search file for a suitable node.
839 (let ((guesspos (point-min))
840 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
841 (if (stringp nodename)
842 (regexp-quote nodename)
844 "\\) *[,\t\n\177]")))
848 ;; First, search a tag table, if any
849 (when (marker-position Info-tag-table-marker)
850 (let* ((m Info-tag-table-marker)
851 (found (Info-find-in-tag-table m regexp)))
854 ;; FOUND is (ANCHOR POS MODE).
855 (setq guesspos (nth 1 found))
857 ;; If this is an indirect file, determine which
858 ;; file really holds this node and read it in.
859 (unless (eq (nth 2 found) 'Info-mode)
860 ;; Note that the current buffer must be the
861 ;; *info* buffer on entry to
862 ;; Info-read-subfile. Thus the hackery above.
863 (setq guesspos (Info-read-subfile guesspos)))
867 (goto-char (setq anchorpos guesspos))
870 ;; Else we may have a node, which we search for:
871 (goto-char (max (point-min)
872 (- (byte-to-position guesspos) 1000)))
874 ;; Now search from our advised position (or from beg of
875 ;; buffer) to find the actual node. First, check
876 ;; whether the node is right where we are, in case the
877 ;; buffer begins with a node.
878 (let ((pos (Info-find-node-in-buffer regexp)))
883 (when (string-match "\\([^.]+\\)\\." nodename)
884 (let (Info-point-loc)
886 filename (match-string 1 nodename) no-going-back))
890 ;; No such anchor in tag table or node in tag table or file
891 (error "No such node or anchor: %s" nodename))
894 (goto-char (point-min))
896 (let ((new-history (list Info-current-file
897 (substring-no-properties nodename))))
898 ;; Add anchors to the history too
899 (setq Info-history-list
901 (delete new-history Info-history-list))))
902 (goto-char anchorpos))
903 ((numberp Info-point-loc)
904 (forward-line (1- Info-point-loc))
905 (setq Info-point-loc nil))
906 ((stringp Info-point-loc)
907 (Info-find-index-name Info-point-loc)
908 (setq Info-point-loc nil))))))
909 ;; If we did not finish finding the specified node,
910 ;; go back to the previous one.
911 (or Info-current-node no-going-back (null Info-history)
912 (let ((hist (car Info-history)))
913 (setq Info-history (cdr Info-history))
914 (Info-find-node (nth 0 hist) (nth 1 hist) t)
915 (goto-char (nth 2 hist))))))
917 ;; Cache the contents of the (virtual) dir file, once we have merged
918 ;; it for the first time, so we can save time subsequently.
919 (defvar Info-dir-contents nil)
921 ;; Cache for the directory we decided to use for the default-directory
922 ;; of the merged dir text.
923 (defvar Info-dir-contents-directory nil)
925 ;; Record the file attributes of all the files from which we
926 ;; constructed Info-dir-contents.
927 (defvar Info-dir-file-attributes nil)
929 (defvar Info-dir-file-name nil)
931 ;; Construct the Info directory node by merging the files named `dir'
932 ;; from various directories. Set the *info* buffer's
933 ;; default-directory to the first directory we actually get any text
935 (defun Info-insert-dir ()
936 (if (and Info-dir-contents Info-dir-file-attributes
937 ;; Verify that none of the files we used has changed
940 (mapcar (lambda (elt)
941 (let ((curr (file-attributes
943 (file-truename (car elt)))))
945 ;; Don't compare the access time.
946 (if curr (setcar (nthcdr 4 curr) 0))
947 (setcar (nthcdr 4 (cdr elt)) 0)
948 (equal (cdr elt) curr)))
949 Info-dir-file-attributes))))
951 (insert Info-dir-contents)
952 (goto-char (point-min)))
953 (let ((dirs (if Info-additional-directory-list
954 (append Info-directory-list
955 Info-additional-directory-list)
956 Info-directory-list))
958 ;; Bind this in case the user sets it to nil.
960 ;; This is set non-nil if we find a problem in some input files.
962 buffers buffer others nodes dirs-done)
964 ;; Search the directory list for the directory file.
966 (let ((truename (file-truename (expand-file-name (car dirs)))))
967 (or (member truename dirs-done)
968 (member (directory-file-name truename) dirs-done)
969 ;; Try several variants of specified name.
970 ;; Try upcasing, appending `.info', or both.
974 (progn (setq file (expand-file-name "dir" truename))
975 (file-attributes file))
976 (progn (setq file (expand-file-name "DIR" truename))
977 (file-attributes file))
978 (progn (setq file (expand-file-name "dir.info" truename))
979 (file-attributes file))
980 (progn (setq file (expand-file-name "DIR.INFO" truename))
981 (file-attributes file)))))
984 (cons (directory-file-name truename)
989 (message "Composing main Info directory..."))
990 (set-buffer (generate-new-buffer " info dir"))
993 (insert-file-contents file)
994 (set (make-local-variable 'Info-dir-file-name)
996 (push (current-buffer) buffers)
997 (push (cons file attrs) dir-file-attrs))
998 (error (kill-buffer (current-buffer))))))))
1000 (set (make-local-variable 'Info-dir-contents-directory)
1001 (file-name-as-directory (car dirs))))
1002 (setq dirs (cdr dirs))))
1005 (error "Can't find the Info directory node"))
1007 ;; Distinguish the dir file that comes with Emacs from all the
1008 ;; others. Yes, that is really what this is supposed to do.
1009 ;; The definition of `Info-directory-list' puts it first on that
1010 ;; list and so last in `buffers' at this point.
1011 (setq buffer (car (last buffers))
1012 others (delq buffer buffers))
1014 ;; Insert the entire original dir file as a start; note that we've
1015 ;; already saved its default directory to use as the default
1016 ;; directory for the whole concatenation.
1017 (insert-buffer buffer)
1019 ;; Look at each of the other buffers one by one.
1020 (dolist (other others)
1021 (let (this-buffer-nodes)
1022 ;; In each, find all the menus.
1023 (with-current-buffer other
1024 (goto-char (point-min))
1025 ;; Find each menu, and add an elt to NODES for it.
1026 (while (re-search-forward "^\\* Menu:" nil t)
1027 (while (and (zerop (forward-line 1)) (eolp)))
1030 (re-search-backward "^\^_")
1031 (search-forward "Node: ")
1032 (setq nodename (Info-following-node-name))
1033 (search-forward "\n\^_" nil 'move)
1036 (push (list nodename other beg end) this-buffer-nodes)))
1037 (if (assoc-string "top" this-buffer-nodes t)
1038 (setq nodes (nconc this-buffer-nodes nodes))
1040 (message "No `top' node in %s" Info-dir-file-name)))))
1041 ;; Add to the main menu a menu item for each other node.
1042 (re-search-forward "^\\* Menu:")
1044 (let ((menu-items '("top"))
1045 (end (save-excursion (search-forward "\^_" nil t) (point))))
1046 (dolist (node nodes)
1047 (let ((nodename (car node)))
1049 (or (member (downcase nodename) menu-items)
1050 (re-search-forward (concat "^\\* +"
1051 (regexp-quote nodename)
1055 (insert "* " nodename "::" "\n")
1056 (push nodename menu-items)))))))
1057 ;; Now take each node of each of the other buffers
1058 ;; and merge it into the main buffer.
1059 (dolist (node nodes)
1060 (let ((case-fold-search t)
1061 (nodename (car node)))
1062 (goto-char (point-min))
1063 ;; Find the like-named node in the main buffer.
1064 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1065 (regexp-quote nodename)
1069 (search-forward "\n\^_" nil 'move)
1072 ;; If none exists, add one.
1073 (goto-char (point-max))
1074 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
1075 ;; Merge the text from the other buffer's menu
1076 ;; into the menu in the like-named node in the main buffer.
1077 (apply 'insert-buffer-substring (cdr node))))
1078 (Info-dir-remove-duplicates)
1079 ;; Kill all the buffers we just made, including the special one excised.
1080 (mapc 'kill-buffer (cons buffer buffers))
1081 (goto-char (point-min))
1083 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1084 (message "Composing main Info directory...done"))
1085 (set (make-local-variable 'Info-dir-contents) (buffer-string))
1086 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
1087 (setq default-directory Info-dir-contents-directory))
1089 (defvar Info-streamline-headings
1090 '(("Emacs" . "Emacs")
1091 ("Programming" . "Programming")
1092 ("Libraries" . "Libraries")
1093 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
1094 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1096 (defun Info-dir-remove-duplicates ()
1098 (goto-char (point-min))
1099 ;; Remove duplicate headings in the same menu.
1100 (while (search-forward "\n* Menu:" nil t)
1101 (setq limit (save-excursion (search-forward "\n\^_" nil t)))
1102 ;; Look for the next heading to unify.
1103 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1104 (let ((name (match-string 1))
1105 (start (match-beginning 0))
1107 ;; Check whether this heading should be streamlined.
1109 (dolist (x Info-streamline-headings)
1110 (when (string-match (car x) name)
1112 (setq re (car x)))))
1113 (if re (replace-match name t t nil 1))
1114 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
1116 (or limit (point-max))))
1117 ;; Look for other headings of the same category and merge them.
1119 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1120 (when (if re (save-match-data (string-match re (match-string 1)))
1121 (equal name (match-string 1)))
1123 ;; Delete redundant heading.
1124 (delete-region (match-beginning 0) (point))
1125 ;; Push the entries onto `text'.
1127 (delete-and-extract-region
1129 (if (re-search-forward "^[^* \n\t]" nil t)
1131 (or limit (point-max)))) entries))))
1132 ;; Insert the entries just found.
1133 (while (= (line-beginning-position 0) (1- (point)))
1135 (dolist (entry (nreverse entries))
1137 (while (= (line-beginning-position 0) (1- (point)))
1138 (delete-region (1- (point)) (point))))
1140 ;; Now remove duplicate entries under the same heading.
1144 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)"
1146 (let ((x (match-string 1)))
1147 (if (member-ignore-case x seen)
1148 (delete-region (match-beginning 0)
1149 (progn (re-search-forward "^[^ \t]" nil t)
1150 (match-beginning 0)))
1151 (push x seen))))))))))
1153 ;; Note that on entry to this function the current-buffer must be the
1154 ;; *info* buffer; not the info tags buffer.
1155 (defun Info-read-subfile (nodepos)
1156 ;; NODEPOS is either a position (in the Info file as a whole,
1157 ;; not relative to a subfile) or the name of a subfile.
1160 (if (numberp nodepos)
1162 (set-buffer (marker-buffer Info-tag-table-marker))
1163 (goto-char (point-min))
1164 (or (looking-at "\^_")
1165 (search-forward "\n\^_"))
1168 (while (not (looking-at "\^_"))
1171 thisfilepos thisfilename)
1172 (search-forward ": ")
1173 (setq thisfilename (buffer-substring beg (- (point) 2)))
1174 (setq thisfilepos (+ (point-min) (read (current-buffer))))
1175 ;; read in version 19 stops at the end of number.
1176 ;; Advance to the next line.
1178 (if (> thisfilepos nodepos)
1180 (setq lastfilename thisfilename)
1181 (setq lastfilepos thisfilepos))
1182 (forward-line 1)))))
1183 (setq lastfilename nodepos)
1184 (setq lastfilepos 0))
1185 ;; Assume previous buffer is in Info-mode.
1186 ;; (set-buffer (get-buffer "*info*"))
1187 (or (equal Info-current-subfile lastfilename)
1188 (let ((buffer-read-only nil))
1189 (setq buffer-file-name nil)
1192 (info-insert-file-contents lastfilename)
1193 (set-buffer-modified-p nil)
1194 (setq Info-current-subfile lastfilename)))
1195 ;; Widen in case we are in the same subfile as before.
1197 (goto-char (point-min))
1198 (if (looking-at "\^_")
1200 (search-forward "\n\^_"))
1201 (if (numberp nodepos)
1202 (+ (- nodepos lastfilepos) (point)))))
1204 (defun Info-unescape-quotes (value)
1205 "Unescape double quotes and backslashes in VALUE."
1208 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start)
1209 (setq unquote (replace-match "" t t unquote 1))
1210 (setq start (- (match-end 0) 1)))
1213 ;; As of Texinfo 4.6, makeinfo writes constructs like
1214 ;; \0\h[image param=value ...\h\0]
1215 ;; into the Info file for handling images.
1216 (defun Info-split-parameter-string (parameter-string)
1217 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1218 whitespace separated list of KEY=VALUE pairs. If VALUE contains
1219 whitespace or double quotes, it must be quoted in double quotes and
1220 any double quotes or backslashes must be escaped (\\\",\\\\)."
1223 (while (string-match
1224 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1225 parameter-string start)
1226 (setq start (match-end 0))
1227 (push (cons (match-string 1 parameter-string)
1228 (or (match-string 2 parameter-string)
1229 (Info-unescape-quotes
1230 (match-string 3 parameter-string))))
1234 (defun Info-display-images-node ()
1235 "Display images in current node."
1237 (let ((inhibit-read-only t)
1238 (case-fold-search t))
1239 (goto-char (point-min))
1240 (while (re-search-forward
1241 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1243 (let* ((start (match-beginning 1))
1244 (parameter-alist (Info-split-parameter-string (match-string 2)))
1245 (src (cdr (assoc-string "src" parameter-alist)))
1246 (image-file (if src (if (file-name-absolute-p src) src
1247 (concat default-directory src))
1249 (image (if (file-exists-p image-file)
1250 (create-image image-file)
1252 (if (not (get-text-property start 'display))
1253 (add-text-properties
1254 start (point) `(display ,image rear-nonsticky (display)))))))
1255 (set-buffer-modified-p nil)))
1257 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1258 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1259 ;; including one optional trailing newline.
1260 (defun Info-hide-cookies-node ()
1261 "Hide unrecognised cookies in current node."
1263 (let ((inhibit-read-only t)
1264 (case-fold-search t))
1265 (goto-char (point-min))
1266 (while (re-search-forward
1267 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1269 (let* ((start (match-beginning 1)))
1270 (if (not (get-text-property start 'invisible))
1271 (put-text-property start (point) 'invisible t)))))
1272 (set-buffer-modified-p nil)))
1274 (defun Info-select-node ()
1275 "Select the info node that point is in."
1276 ;; Bind this in case the user sets it to nil.
1277 (let ((case-fold-search t))
1279 ;; Find beginning of node.
1280 (if (search-backward "\n\^_" nil 'move)
1282 (if (looking-at "\^_")
1284 (signal 'search-failed (list "\n\^_"))))
1285 ;; Get nodename spelled as it is in the node.
1286 (re-search-forward "Node:[ \t]*")
1287 (setq Info-current-node
1288 (buffer-substring-no-properties (point)
1290 (skip-chars-forward "^,\t\n")
1292 (Info-set-mode-line)
1293 ;; Find the end of it, and narrow.
1295 (let (active-expression)
1296 ;; Narrow to the node contents
1297 (narrow-to-region (point)
1298 (if (re-search-forward "\n[\^_\f]" nil t)
1301 (if (looking-at "[\n\^_\f]*execute: ")
1303 (goto-char (match-end 0))
1304 (setq active-expression
1305 (read (current-buffer))))))
1307 (if Info-enable-active-nodes (eval active-expression))
1308 ;; Add a new unique history item to full history list
1309 (let ((new-history (list Info-current-file Info-current-node)))
1310 (setq Info-history-list
1311 (cons new-history (delete new-history Info-history-list)))
1312 (setq Info-history-forward nil))
1313 (if (not (eq Info-fontify-maximum-menu-size nil))
1314 (Info-fontify-node))
1315 (Info-display-images-node)
1316 (Info-hide-cookies-node)
1317 (run-hooks 'Info-selection-hook)))))
1319 (defun Info-set-mode-line ()
1320 (setq mode-line-buffer-identification
1321 (nconc (propertized-buffer-identification "%b")
1324 (file-name-nondirectory
1325 (if (stringp Info-current-file)
1327 (or buffer-file-name "")))
1329 (or Info-current-node ""))))))
1331 ;; Go to an info node specified with a filename-and-nodename string
1332 ;; of the sort that is found in pointers in nodes.
1335 (defun Info-goto-node (nodename &optional fork)
1336 "Go to info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1337 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1338 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1340 Completion is available, but only for node names in the current Info file.
1341 If FORK is non-nil (interactively with a prefix arg), show the node in
1343 If FORK is a string, it is the name to use for the new buffer."
1344 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
1348 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
1350 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1352 (setq filename (if (= (match-beginning 1) (match-end 1))
1354 (match-string 2 nodename))
1355 nodename (match-string 3 nodename))
1356 (let ((trim (string-match "\\s +\\'" filename)))
1357 (if trim (setq filename (substring filename 0 trim))))
1358 (let ((trim (string-match "\\s +\\'" nodename)))
1359 (if trim (setq nodename (substring nodename 0 trim))))
1360 (if transient-mark-mode (deactivate-mark))
1361 (Info-find-node (if (equal filename "") nil filename)
1362 (if (equal nodename "") "Top" nodename))))
1364 (defvar Info-read-node-completion-table)
1366 ;; This function is used as the "completion table" while reading a node name.
1367 ;; It does completion using the alist in Info-read-node-completion-table
1368 ;; unless STRING starts with an open-paren.
1369 (defun Info-read-node-name-1 (string predicate code)
1371 ;; First complete embedded file names.
1372 ((string-match "\\`([^)]*\\'" string)
1373 (let ((file (substring string 1)))
1376 (let ((comp (try-completion file 'locate-file-completion
1377 (cons Info-directory-list
1378 (mapcar 'car Info-suffix-list)))))
1380 ((eq comp t) (concat string ")"))
1381 (comp (concat "(" comp)))))
1382 ((eq code t) (all-completions file 'locate-file-completion
1383 (cons Info-directory-list
1384 (mapcar 'car Info-suffix-list))))
1386 ;; If a file name was given, then any node is fair game.
1387 ((string-match "\\`(" string)
1389 ((eq code nil) string)
1392 ;; Otherwise use Info-read-node-completion-table.
1394 (try-completion string Info-read-node-completion-table predicate))
1396 (all-completions string Info-read-node-completion-table predicate))
1398 (test-completion string Info-read-node-completion-table predicate))))
1400 (defun Info-read-node-name (prompt &optional default)
1401 (let* ((completion-ignore-case t)
1402 (Info-read-node-completion-table (Info-build-node-completions))
1403 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1404 (if (equal nodename "")
1406 (Info-read-node-name prompt))
1409 (defun Info-build-node-completions ()
1410 (or Info-current-file-completions
1412 ;; Bind this in case the user sets it to nil.
1413 (case-fold-search t)
1414 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1417 (if (marker-buffer Info-tag-table-marker)
1418 (let ((marker Info-tag-table-marker))
1419 (set-buffer (marker-buffer marker))
1422 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1424 (cons (list (match-string-no-properties 2))
1427 (goto-char (point-min))
1428 ;; If the buffer begins with a node header, process that first.
1429 (if (Info-node-at-bob-matching node-regexp)
1430 (setq compl (list (match-string-no-properties 1))))
1431 ;; Now for the rest of the nodes.
1432 (while (search-forward "\n\^_" nil t)
1434 (let ((beg (point)))
1436 (if (re-search-backward node-regexp beg t)
1438 (cons (list (match-string-no-properties 1))
1440 (setq compl (cons '("*") compl))
1441 (set (make-local-variable 'Info-current-file-completions) compl))))
1443 (defun Info-restore-point (hl)
1444 "If this node has been visited, restore the point value when we left."
1446 (if (and (equal (nth 0 (car hl)) Info-current-file)
1447 ;; Use string-equal, not equal, to ignore text props.
1448 (string-equal (nth 1 (car hl)) Info-current-node))
1450 (goto-char (nth 2 (car hl)))
1451 (setq hl nil)) ;terminate the while at next iter
1452 (setq hl (cdr hl)))))
1454 (defvar Info-search-history nil
1455 "The history list for `Info-search'.")
1457 (defvar Info-search-case-fold nil
1458 "The value of `case-fold-search' from previous `Info-search' command.")
1460 (defun Info-search (regexp &optional bound noerror count direction)
1461 "Search for REGEXP, starting from point, and select node it's found in.
1462 If DIRECTION is `backward', search in the reverse direction."
1463 (interactive (list (read-string
1464 (if Info-search-history
1465 (format "Regexp search%s (default `%s'): "
1466 (if case-fold-search "" " case-sensitively")
1467 (car Info-search-history))
1468 (format "Regexp search%s: "
1469 (if case-fold-search "" " case-sensitively")))
1470 nil 'Info-search-history)))
1471 (when transient-mark-mode
1473 (when (equal regexp "")
1474 (setq regexp (car Info-search-history)))
1476 (let (found beg-found give-up
1477 (backward (eq direction 'backward))
1478 (onode Info-current-node)
1479 (ofile Info-current-file)
1481 (opoint-min (point-min))
1482 (opoint-max (point-max))
1483 (ostart (window-start))
1484 (osubfile Info-current-subfile))
1485 (setq Info-search-case-fold case-fold-search)
1490 ;; Hide Info file header for backward search
1491 (narrow-to-region (save-excursion
1492 (goto-char (point-min))
1493 (search-forward "\n\^_")
1496 (while (and (not give-up)
1500 (isearch-range-invisible found beg-found)
1501 (isearch-range-invisible beg-found found))
1502 ;; Skip node header line
1503 (and (save-excursion (forward-line -1)
1505 (forward-line (if backward -1 1)))
1506 ;; Skip Tag Table node
1508 (and (search-backward "\^_" nil t)
1509 (looking-at "\^_\nTag Table"))))))
1510 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1512 (re-search-backward regexp bound t)
1513 (re-search-forward regexp bound t))
1514 (setq found (point) beg-found (if backward (match-end 0)
1515 (match-beginning 0)))
1516 (setq give-up t))))))
1517 ;; If no subfiles, give error now.
1519 (if (null Info-current-subfile)
1520 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1522 (re-search-backward regexp)
1523 (re-search-forward regexp)))
1526 (unless (or found bound)
1528 ;; Try other subfiles.
1531 (set-buffer (marker-buffer Info-tag-table-marker))
1532 (goto-char (point-min))
1533 (search-forward "\n\^_\nIndirect:")
1535 (narrow-to-region (point)
1536 (progn (search-forward "\n\^_")
1538 (goto-char (point-min))
1539 ;; Find the subfile we just searched.
1540 (search-forward (concat "\n" osubfile ": "))
1542 (forward-line (if backward 0 1))
1543 (if backward (forward-char -1))
1544 ;; Make a list of all following subfiles.
1545 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1546 (while (not (if backward (bobp) (eobp)))
1548 (re-search-backward "\\(^.*\\): [0-9]+$")
1549 (re-search-forward "\\(^.*\\): [0-9]+$"))
1550 (goto-char (+ (match-end 1) 2))
1551 (setq list (cons (cons (+ (point-min)
1552 (read (current-buffer)))
1553 (match-string-no-properties 1))
1555 (goto-char (if backward
1556 (1- (match-beginning 0))
1557 (1+ (match-end 0)))))
1558 ;; Put in forward order
1559 (setq list (nreverse list))))
1561 (message "Searching subfile %s..." (cdr (car list)))
1562 (Info-read-subfile (car (car list)))
1564 ;; Hide Info file header for backward search
1565 (narrow-to-region (save-excursion
1566 (goto-char (point-min))
1567 (search-forward "\n\^_")
1570 (goto-char (point-max)))
1571 (setq list (cdr list))
1572 (setq give-up nil found nil)
1573 (while (and (not give-up)
1577 (isearch-range-invisible found beg-found)
1578 (isearch-range-invisible beg-found found))
1579 ;; Skip node header line
1580 (and (save-excursion (forward-line -1)
1582 (forward-line (if backward -1 1)))
1583 ;; Skip Tag Table node
1585 (and (search-backward "\^_" nil t)
1586 (looking-at "\^_\nTag Table"))))))
1587 (let ((search-spaces-regexp Info-search-whitespace-regexp))
1589 (re-search-backward regexp nil t)
1590 (re-search-forward regexp nil t))
1591 (setq found (point) beg-found (if backward (match-end 0)
1592 (match-beginning 0)))
1600 (signal 'search-failed (list regexp))))
1602 (progn (Info-read-subfile osubfile)
1605 (set-window-start (selected-window) ostart)))))
1607 (if (and (string= osubfile Info-current-subfile)
1608 (> found opoint-min)
1609 (< found opoint-max))
1610 ;; Search landed in the same node
1614 (save-match-data (Info-select-node)))
1616 ;; Use string-equal, not equal, to ignore text props.
1617 (or (and (string-equal onode Info-current-node)
1618 (equal ofile Info-current-file))
1619 (and isearch-mode isearch-wrapped
1620 (eq opoint (if isearch-forward opoint-min opoint-max)))
1621 (setq Info-history (cons (list ofile onode opoint)
1624 (defun Info-search-case-sensitively ()
1625 "Search for a regexp case-sensitively."
1627 (let ((case-fold-search nil))
1628 (call-interactively 'Info-search)))
1630 (defun Info-search-next ()
1631 "Search for next regexp from a previous `Info-search' command."
1633 (let ((case-fold-search Info-search-case-fold))
1634 (if Info-search-history
1635 (Info-search (car Info-search-history))
1636 (call-interactively 'Info-search))))
1638 (defun Info-search-backward (regexp &optional bound noerror count)
1639 "Search for REGEXP in the reverse direction."
1640 (interactive (list (read-string
1641 (if Info-search-history
1642 (format "Regexp search%s backward (default `%s'): "
1643 (if case-fold-search "" " case-sensitively")
1644 (car Info-search-history))
1645 (format "Regexp search%s backward: "
1646 (if case-fold-search "" " case-sensitively")))
1647 nil 'Info-search-history)))
1648 (Info-search regexp bound noerror count 'backward))
1650 (defun Info-isearch-search ()
1651 (if Info-isearch-search
1652 (lambda (string &optional bound noerror count)
1655 (Info-search (concat "\\b" (replace-regexp-in-string
1657 (replace-regexp-in-string
1658 "^\\W+\\|\\W+$" "" string)) "\\b")
1660 (unless isearch-forward 'backward))
1661 (Info-search (if isearch-regexp string (regexp-quote string))
1663 (unless isearch-forward 'backward))
1666 (let ((isearch-search-fun-function nil))
1667 (isearch-search-fun))))
1669 (defun Info-isearch-wrap ()
1670 (when Info-isearch-search
1671 (if isearch-forward (Info-top-node) (Info-final-node))
1672 (goto-char (if isearch-forward (point-min) (point-max)))))
1674 (defun Info-isearch-push-state ()
1676 (Info-isearch-pop-state cmd ,Info-current-file ,Info-current-node)))
1678 (defun Info-isearch-pop-state (cmd file node)
1679 (or (and (string= Info-current-file file)
1680 (string= Info-current-node node))
1681 (progn (Info-find-node file node) (sit-for 0))))
1684 (defun Info-extract-pointer (name &optional errorname)
1685 "Extract the value of the node-pointer named NAME.
1686 If there is none, use ERRORNAME in the error message;
1687 if ERRORNAME is nil, just return nil."
1688 ;; Bind this in case the user sets it to nil.
1689 (let ((case-fold-search t))
1691 (goto-char (point-min))
1692 (let ((bound (point)))
1694 (cond ((re-search-backward
1695 (concat name ":" (Info-following-node-name-re)) bound t)
1697 ((not (eq errorname t))
1698 (error "Node has no %s"
1699 (capitalize (or errorname name)))))))))
1701 (defun Info-following-node-name-re (&optional allowedchars)
1702 "Return a regexp matching a node name.
1703 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1704 saying which chars may appear in the node name.
1705 Submatch 1 is the complete node name.
1706 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1707 Submatch 3 is the local part of the node name.
1708 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1709 (concat "[ \t]*" ;Skip leading space.
1710 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1711 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
1712 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
1713 "\\|\\)\\)")) ;Allow empty node names.
1715 ;;; For compatibility; other files have used this name.
1716 (defun Info-following-node-name ()
1717 (and (looking-at (Info-following-node-name-re))
1721 "Go to the next node of this node."
1723 (Info-goto-node (Info-extract-pointer "next")))
1726 "Go to the previous node of this node."
1728 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous")))
1730 (defun Info-up (&optional same-file)
1731 "Go to the superior node of this node.
1732 If SAME-FILE is non-nil, do not move to a different Info file."
1734 (let ((old-node Info-current-node)
1735 (old-file Info-current-file)
1736 (node (Info-extract-pointer "up")) p)
1737 (and (or same-file (not (stringp Info-current-file)))
1738 (string-match "^(" node)
1739 (error "Up node is in another Info file"))
1740 (Info-goto-node node)
1742 (goto-char (point-min))
1743 (if (and (search-forward "\n* Menu:" nil t)
1745 (if (string-equal old-node "Top")
1746 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
1747 (concat "\n\\* +\\(" (regexp-quote old-node)
1748 ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
1752 (Info-restore-point Info-history))))
1754 (defun Info-history-back ()
1755 "Go back in the history to the last node visited."
1758 (error "This is the first Info node you looked at"))
1759 (let ((history-forward
1760 (cons (list Info-current-file Info-current-node (point))
1761 Info-history-forward))
1762 filename nodename opoint)
1763 (setq filename (car (car Info-history)))
1764 (setq nodename (car (cdr (car Info-history))))
1765 (setq opoint (car (cdr (cdr (car Info-history)))))
1766 (setq Info-history (cdr Info-history))
1767 (Info-find-node filename nodename)
1768 (setq Info-history (cdr Info-history))
1769 (setq Info-history-forward history-forward)
1770 (goto-char opoint)))
1772 (defalias 'Info-last 'Info-history-back)
1774 (defun Info-history-forward ()
1775 "Go forward in the history of visited nodes."
1777 (or Info-history-forward
1778 (error "This is the last Info node you looked at"))
1779 (let ((history-forward (cdr Info-history-forward))
1780 filename nodename opoint)
1781 (setq filename (car (car Info-history-forward)))
1782 (setq nodename (car (cdr (car Info-history-forward))))
1783 (setq opoint (car (cdr (cdr (car Info-history-forward)))))
1784 (Info-find-node filename nodename)
1785 (setq Info-history-forward history-forward)
1786 (goto-char opoint)))
1789 (defun Info-directory ()
1790 "Go to the Info directory node."
1792 (Info-find-node "dir" "top"))
1794 (defun Info-history ()
1795 "Go to a node with a menu of visited nodes."
1797 (let ((curr-file Info-current-file)
1798 (curr-node Info-current-node)
1800 (with-current-buffer (get-buffer-create " *info-history*")
1801 (let ((inhibit-read-only t))
1803 (goto-char (point-min))
1804 (insert "\n\^_\nFile: history, Node: Top, Up: (dir)\n\n")
1805 (insert "Recently Visited Nodes\n**********************\n\n")
1806 (insert "* Menu:\n\n")
1807 (let ((hl (delete '("history" "Top") Info-history-list)))
1809 (let ((file (nth 0 (car hl)))
1810 (node (nth 1 (car hl))))
1811 (if (and (string-equal file curr-file)
1812 (string-equal node curr-node))
1814 (insert "* " node ": (" (file-name-nondirectory file)
1816 (setq hl (cdr hl))))))
1817 (Info-find-node "history" "Top")
1818 (goto-char (or p (point-min)))))
1821 "Go to a node with table of contents of the current Info file.
1822 Table of contents is created from the tree structure of menus."
1824 (let ((curr-file (substring-no-properties Info-current-file))
1825 (curr-node (substring-no-properties Info-current-node))
1827 (with-current-buffer (get-buffer-create " *info-toc*")
1828 (let ((inhibit-read-only t)
1829 (node-list (Info-build-toc curr-file)))
1831 (goto-char (point-min))
1832 (insert "\n\^_\nFile: toc, Node: Top, Up: (dir)\n\n")
1833 (insert "Table of Contents\n*****************\n\n")
1834 (insert "*Note Top: (" curr-file ")Top.\n")
1836 (nth 2 (assoc "Top" node-list)) ; get Top nodes
1837 node-list 0 curr-file))
1839 (let ((Info-hide-note-references 'hide)
1840 (Info-fontify-visited-nodes nil))
1842 (setq Info-current-file "toc" Info-current-node "Top")
1843 (goto-char (point-min))
1844 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t)
1849 (goto-char (point-min))
1850 (if (setq p (search-forward (concat "*Note " curr-node ":") nil t))
1851 (setq p (- p (length curr-node) 2))))
1852 (Info-find-node "toc" "Top")
1853 (goto-char (or p (point-min)))))
1855 (defun Info-insert-toc (nodes node-list level curr-file)
1856 "Insert table of contents with references to nodes."
1857 (let ((section "Top"))
1859 (let ((node (assoc (car nodes) node-list)))
1860 (unless (member (nth 1 node) (list nil section))
1861 (insert (setq section (nth 1 node)) "\n"))
1862 (insert (make-string level ?\t))
1863 (insert "*Note " (car nodes) ": (" curr-file ")" (car nodes) ".\n")
1864 (Info-insert-toc (nth 2 node) node-list (1+ level) curr-file)
1865 (setq nodes (cdr nodes))))))
1867 (defun Info-build-toc (file)
1868 "Build table of contents from menus of Info FILE and its subfiles."
1870 (let* ((file (and (stringp file) (Info-find-file file)))
1871 (default-directory (or (and (stringp file)
1872 (file-name-directory file))
1874 (main-file (and (stringp file) file))
1875 (sections '(("Top" "Top")))
1877 (while (or main-file subfiles)
1878 (or main-file (message "Searching subfile %s..." (car subfiles)))
1880 (info-insert-file-contents (or main-file (car subfiles)))
1881 (goto-char (point-min))
1882 (while (and (search-forward "\n\^_\nFile:" nil 'move)
1883 (search-forward "Node: " nil 'move))
1884 (let ((nodename (substring-no-properties (Info-following-node-name)))
1885 (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
1889 (when (and (not (Info-index-node nodename file))
1890 (re-search-forward "^\\* Menu:" bound t))
1893 (setq bound (or (and (equal nodename "Top")
1896 "^[ \t-]*The Detailed Node Listing" nil t)))
1898 (while (< (point) bound)
1901 ((looking-at "^\\* +[^:]+:")
1904 (let ((menu-node-name (substring-no-properties
1905 (Info-extract-menu-node-name))))
1906 (setq menu-items (cons menu-node-name menu-items))
1907 (if (equal nodename "Top")
1909 (cons (list menu-node-name section) sections)))))
1910 ;; Other non-empty strings in the Top node are section names
1911 ((and (equal nodename "Top")
1912 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
1913 (setq section (match-string-no-properties 1))))
1915 (beginning-of-line)))
1916 (setq nodes (cons (list nodename
1917 (cadr (assoc nodename sections))
1918 (nreverse menu-items))
1923 (goto-char (point-min))
1924 (if (search-forward "\n\^_\nIndirect:" nil t)
1925 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
1926 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
1927 (setq subfiles (cons (match-string-no-properties 1)
1929 (setq subfiles (nreverse subfiles)
1931 (setq subfiles (cdr subfiles))))
1935 (defun Info-follow-reference (footnotename &optional fork)
1936 "Follow cross reference named FOOTNOTENAME to the node it refers to.
1937 FOOTNOTENAME may be an abbreviation of the reference name.
1938 If FORK is non-nil (interactively with a prefix arg), show the node in
1939 a new info buffer. If FORK is a string, it is the name to use for the
1942 (let ((completion-ignore-case t)
1943 (case-fold-search t)
1944 completions default alt-default (start-point (point)) str i bol eol)
1946 ;; Store end and beginning of line.
1952 (goto-char (point-min))
1953 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
1954 (setq str (match-string-no-properties 1))
1955 ;; See if this one should be the default.
1957 (<= (match-beginning 0) start-point)
1958 (<= start-point (point))
1960 ;; See if this one should be the alternate default.
1961 (and (null alt-default)
1962 (and (<= bol (match-beginning 0))
1964 (setq alt-default t))
1966 (while (setq i (string-match "[ \n\t]+" str i))
1967 (setq str (concat (substring str 0 i) " "
1968 (substring str (match-end 0))))
1970 ;; Record as a completion and perhaps as default.
1971 (if (eq default t) (setq default str))
1972 (if (eq alt-default t) (setq alt-default str))
1973 ;; Don't add this string if it's a duplicate.
1974 (or (assoc-string str completions t)
1975 (push str completions))))
1976 ;; If no good default was found, try an alternate.
1978 (setq default alt-default))
1979 ;; If only one cross-reference found, then make it default.
1980 (if (eq (length completions) 1)
1981 (setq default (car completions)))
1983 (let ((input (completing-read (if default
1985 "Follow reference named: (default "
1987 "Follow reference named: ")
1988 completions nil t)))
1989 (list (if (equal input "")
1990 default input) current-prefix-arg))
1991 (error "No cross-references in this node"))))
1993 (unless footnotename
1994 (error "No reference was specified"))
1996 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
1997 (case-fold-search t))
1998 (while (setq i (string-match " " str i))
1999 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
2002 ;; Move point to the beginning of reference if point is on reference
2003 (or (looking-at "\\*note[ \n\t]+")
2004 (and (looking-back "\\*note[ \n\t]+")
2005 (goto-char (match-beginning 0)))
2006 (if (and (save-excursion
2007 (goto-char (+ (point) 5)) ; skip a possible *note
2008 (re-search-backward "\\*note[ \n\t]+" nil t)
2010 (<= (point) (match-end 0)))
2011 (goto-char (match-beginning 0))))
2012 ;; Go to the reference closest to point
2013 (let ((next-ref (save-excursion (and (re-search-forward str nil t)
2014 (+ (match-beginning 0) 5))))
2015 (prev-ref (save-excursion (and (re-search-backward str nil t)
2016 (+ (match-beginning 0) 5)))))
2017 (goto-char (cond ((and next-ref prev-ref)
2018 (if (< (abs (- next-ref (point)))
2019 (abs (- prev-ref (point))))
2021 ((or next-ref prev-ref))
2022 ((error "No cross-reference named %s" footnotename))))
2023 (setq target (Info-extract-menu-node-name t))))
2024 (while (setq i (string-match "[ \t\n]+" target i))
2025 (setq target (concat (substring target 0 i) " "
2026 (substring target (match-end 0))))
2028 (Info-goto-node target fork)))
2030 (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2031 ;; We allow newline because this is also used in Info-follow-reference,
2032 ;; where the xref name might be wrapped over two lines.
2033 "Regexp that matches a menu entry name upto but not including the colon.
2034 Because of ambiguities, this should be concatenated with something like
2035 `:' and `Info-following-node-name-re'.")
2037 (defun Info-extract-menu-node-name (&optional multi-line index-node)
2038 (skip-chars-forward " \t\n")
2039 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
2040 (Info-following-node-name-re
2042 (index-node "^,\t\n")
2043 (multi-line "^.,\t")
2047 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2050 (setq Info-point-loc
2051 (if (match-beginning 5)
2052 (string-to-number (match-string 5))
2053 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))
2054 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2055 ;;; (setq Info-point-loc
2056 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2058 (replace-regexp-in-string
2060 (or (match-string 2)
2061 ;; If the node name is the menu entry name (using `entry::').
2062 (buffer-substring (match-beginning 0) (1- (match-beginning 1)))))))
2064 ;; No one calls this.
2065 ;;(defun Info-menu-item-sequence (list)
2067 ;; (Info-menu (car list))
2068 ;; (setq list (cdr list))))
2070 (defvar Info-complete-menu-buffer)
2071 (defvar Info-complete-next-re nil)
2072 (defvar Info-complete-nodes nil)
2073 (defvar Info-complete-cache nil)
2075 (defconst Info-node-spec-re
2076 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2077 "Regexp to match the text after a : until the terminating `.'.")
2079 (defun Info-complete-menu-item (string predicate action)
2080 ;; This uses two dynamically bound variables:
2081 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2082 ;; is the menu of items we're trying to complete.
2083 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2084 ;; also look for menu items in subsequent nodes as long as those
2085 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2087 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2088 ;; also look for menu items in these nodes. This feature is currently
2089 ;; only used for completion in Info-index.
2091 ;; Note that `Info-complete-menu-buffer' could be current already,
2092 ;; so we want to save point.
2094 (set-buffer Info-complete-menu-buffer)
2095 (let ((completion-ignore-case t)
2096 (case-fold-search t)
2097 (orignode Info-current-node)
2099 (goto-char (point-min))
2100 (search-forward "\n* Menu:")
2101 (if (not (memq action '(nil t)))
2103 (concat "\n\\* +" (regexp-quote string) ":") nil t)
2104 (let ((pattern (concat "\n\\* +\\("
2105 (regexp-quote string)
2106 Info-menu-entry-name-re "\\):" Info-node-spec-re))
2109 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
2110 (equal (nth 1 Info-complete-cache) Info-current-node)
2111 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
2112 (equal (nth 5 Info-complete-cache) Info-complete-nodes)
2113 (let ((prev (nth 3 Info-complete-cache)))
2114 (eq t (compare-strings string 0 (length prev)
2116 ;; We can reuse the previous list.
2117 (setq completions (nth 4 Info-complete-cache))
2118 ;; The cache can't be used.
2121 (while (re-search-forward pattern nil t)
2122 (push (match-string-no-properties 1)
2124 ;; Check subsequent nodes if applicable.
2125 (or (and Info-complete-next-re
2126 (setq nextnode (Info-extract-pointer "next" t))
2127 (string-match Info-complete-next-re nextnode))
2128 (and Info-complete-nodes
2129 (setq Info-complete-nodes (cdr Info-complete-nodes)
2130 nextnode (car Info-complete-nodes)))))
2131 (Info-goto-node nextnode))
2132 ;; Go back to the start node (for the next completion).
2133 (unless (equal Info-current-node orignode)
2134 (Info-goto-node orignode))
2135 ;; Update the cache.
2136 (set (make-local-variable 'Info-complete-cache)
2137 (list Info-current-file Info-current-node
2138 Info-complete-next-re string completions
2139 Info-complete-nodes)))
2141 (all-completions string completions predicate)
2142 (try-completion string completions predicate)))))))
2145 (defun Info-menu (menu-item &optional fork)
2146 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2147 The menu item should one of those listed in the current node's menu.
2148 Completion is allowed, and the default menu item is the one point is on.
2149 If FORK is non-nil (interactively with a prefix arg), show the node in
2150 a new info buffer. If FORK is a string, it is the name to use for the
2153 (let ((completions '())
2154 ;; If point is within a menu item, use that item as the default
2159 (case-fold-search t))
2161 (goto-char (point-min))
2162 (if (not (search-forward "\n* menu:" nil t))
2163 (error "No menu in this node"))
2169 (if (re-search-backward (concat "\n\\* +\\("
2170 Info-menu-entry-name-re
2172 (setq default (match-string-no-properties 1))))))
2175 (setq item (let ((completion-ignore-case t)
2176 (Info-complete-menu-buffer (current-buffer)))
2177 (completing-read (if default
2178 (format "Menu item (default %s): "
2181 'Info-complete-menu-item nil t)))
2182 ;; we rely on the fact that completing-read accepts an input
2183 ;; of "" even when the require-match argument is true and ""
2184 ;; is not a valid possibility
2185 (if (string= item "")
2190 (list item current-prefix-arg))))
2191 ;; there is a problem here in that if several menu items have the same
2192 ;; name you can only go to the node of the first with this command.
2193 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
2195 (defun Info-extract-menu-item (menu-item)
2196 (setq menu-item (regexp-quote menu-item))
2197 (let ((case-fold-search t))
2199 (let ((case-fold-search t))
2200 (goto-char (point-min))
2201 (or (search-forward "\n* menu:" nil t)
2202 (error "No menu in this node"))
2203 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
2204 (re-search-forward (concat "\n\\* +" menu-item) nil t)
2205 (error "No such item in menu"))
2208 (Info-extract-menu-node-name nil (Info-index-node))))))
2210 ;; If COUNT is nil, use the last item in the menu.
2211 (defun Info-extract-menu-counting (count)
2212 (let ((case-fold-search t))
2214 (let ((case-fold-search t))
2215 (goto-char (point-min))
2216 (or (search-forward "\n* menu:" nil t)
2217 (error "No menu in this node"))
2219 (or (search-forward "\n* " nil t count)
2220 (error "Too few items in menu"))
2221 (while (search-forward "\n* " nil t)
2223 (Info-extract-menu-node-name nil (Info-index-node))))))
2225 (defun Info-nth-menu-item ()
2226 "Go to the node of the Nth menu item.
2227 N is the digit argument used to invoke this command."
2230 (Info-extract-menu-counting
2231 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
2233 (defun Info-top-node ()
2234 "Go to the Top node of this file."
2236 (Info-goto-node "Top"))
2238 (defun Info-final-node ()
2239 "Go to the final node in this file."
2241 (Info-goto-node "Top")
2242 (let ((Info-history nil)
2243 (case-fold-search t))
2244 ;; Go to the last node in the menu of Top.
2245 (Info-goto-node (Info-extract-menu-counting nil))
2246 ;; If the last node in the menu is not last in pointer structure,
2247 ;; move forward until we can't go any farther.
2248 (while (Info-forward-node t t) nil)
2249 ;; Then keep moving down to last subnode, unless we reach an index.
2250 (while (and (not (Info-index-node))
2251 (save-excursion (search-forward "\n* Menu:" nil t)))
2252 (Info-goto-node (Info-extract-menu-counting nil)))))
2254 (defun Info-forward-node (&optional not-down no-error)
2255 "Go forward one node, considering all nodes as forming one sequence."
2257 (goto-char (point-min))
2259 (let ((case-fold-search t))
2260 ;; three possibilities, in order of priority:
2261 ;; 1. next node is in a menu in this node (but not in an index)
2262 ;; 2. next node is next at same level
2263 ;; 3. next node is up and next
2264 (cond ((and (not not-down)
2265 (save-excursion (search-forward "\n* menu:" nil t))
2266 (not (Info-index-node)))
2267 (Info-goto-node (Info-extract-menu-counting 1))
2269 ((save-excursion (search-backward "next:" nil t))
2272 ((and (save-excursion (search-backward "up:" nil t))
2273 ;; Use string-equal, not equal, to ignore text props.
2274 (not (string-equal (downcase (Info-extract-pointer "up"))
2276 (let ((old-node Info-current-node))
2278 (let (Info-history success)
2280 (setq success (Info-forward-node t no-error))
2281 (or success (Info-goto-node old-node))))))
2283 (t (error "No pointer forward from this node")))))
2285 (defun Info-backward-node ()
2286 "Go backward one node, considering all nodes as forming one sequence."
2288 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
2289 (upnode (Info-extract-pointer "up" t))
2290 (case-fold-search t))
2291 (cond ((and upnode (string-match "(" upnode))
2292 (error "First node in file"))
2293 ((and upnode (or (null prevnode)
2294 ;; Use string-equal, not equal,
2295 ;; to ignore text properties.
2296 (string-equal (downcase prevnode)
2297 (downcase upnode))))
2300 ;; If we move back at the same level,
2301 ;; go down to find the last subnode*.
2304 (while (and (not (Info-index-node))
2305 (save-excursion (search-forward "\n* Menu:" nil t)))
2306 (Info-goto-node (Info-extract-menu-counting nil)))))
2308 (error "No pointer backward from this node")))))
2311 "Exit Info by selecting some other buffer."
2314 (save-buffers-kill-emacs)
2317 (defun Info-next-menu-item ()
2318 "Go to the node of the next menu item."
2320 ;; Bind this in case the user sets it to nil.
2321 (let* ((case-fold-search t)
2325 (search-forward "\n* menu:" nil t)
2326 (and (search-forward "\n* " nil t)
2327 (Info-extract-menu-node-name)))))
2328 (if node (Info-goto-node node)
2329 (error "No more items in menu"))))
2331 (defun Info-last-menu-item ()
2332 "Go to the node of the previous menu item."
2336 ;; Bind this in case the user sets it to nil.
2337 (let* ((case-fold-search t)
2338 (beg (save-excursion
2339 (and (search-backward "\n* menu:" nil t)
2341 (or (and beg (search-backward "\n* " beg t))
2342 (error "No previous items in menu")))
2343 (Info-goto-node (save-excursion
2344 (goto-char (match-end 0))
2345 (Info-extract-menu-node-name)))))
2347 (defmacro Info-no-error (&rest body)
2348 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
2350 (defun Info-next-preorder ()
2351 "Go to the next subnode or the next node, or go up a level."
2353 (cond ((Info-no-error (Info-next-menu-item)))
2354 ((Info-no-error (Info-next)))
2355 ((Info-no-error (Info-up t))
2356 ;; Since we have already gone thru all the items in this menu,
2357 ;; go up to the end of this node.
2358 (goto-char (point-max))
2359 ;; Since logically we are done with the node with that menu,
2361 (Info-next-preorder))
2363 (error "No more nodes"))))
2365 (defun Info-last-preorder ()
2366 "Go to the last node, popping up a level if there is none."
2368 (cond ((Info-no-error
2369 (Info-last-menu-item)
2370 ;; If we go down a menu item, go to the end of the node
2371 ;; so we can scroll back through it.
2372 (goto-char (point-max)))
2373 ;; Keep going down, as long as there are nested menu nodes.
2374 (while (Info-no-error
2375 (Info-last-menu-item)
2376 ;; If we go down a menu item, go to the end of the node
2377 ;; so we can scroll back through it.
2378 (goto-char (point-max))))
2380 ((and (Info-no-error (Info-extract-pointer "prev"))
2381 (not (equal (Info-extract-pointer "up")
2382 (Info-extract-pointer "prev"))))
2383 (Info-no-error (Info-prev))
2384 (goto-char (point-max))
2385 (while (Info-no-error
2386 (Info-last-menu-item)
2387 ;; If we go down a menu item, go to the end of the node
2388 ;; so we can scroll back through it.
2389 (goto-char (point-max))))
2391 ((Info-no-error (Info-up t))
2392 (goto-char (point-min))
2393 (let ((case-fold-search t))
2394 (or (search-forward "\n* Menu:" nil t)
2395 (goto-char (point-max)))))
2396 (t (error "No previous nodes"))))
2398 (defun Info-scroll-up ()
2399 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2400 Once you scroll far enough in a node that its menu appears on the screen
2401 but after point, the next scroll moves into its first subnode, unless
2402 `Info-scroll-prefer-subnodes' is nil.
2404 When you scroll past the end of a node, that goes to the next node if
2405 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2406 if this node has no successor, it moves to the parent node's successor,
2407 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2408 the menu of a node, it moves to subnode indicated by the following menu
2409 item. (That case won't normally result from this command, but can happen
2413 (if (or (< (window-start) (point-min))
2414 (> (window-start) (point-max)))
2415 (set-window-start (selected-window) (point)))
2416 (let* ((case-fold-search t)
2417 (virtual-end (save-excursion
2418 (goto-char (point-min))
2419 (if (and Info-scroll-prefer-subnodes
2420 (search-forward "\n* Menu:" nil t))
2423 (if (or (< virtual-end (window-start))
2424 (pos-visible-in-window-p virtual-end))
2426 (Info-scroll-prefer-subnodes (Info-next-preorder))
2427 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2428 (t (Info-next-preorder)))
2431 (defun Info-scroll-down ()
2432 "Scroll one screenful back in Info, considering all nodes as one sequence.
2433 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2434 is non-nil, this goes to its last subnode. When you scroll past the
2435 beginning of a node, that goes to the previous node or back up to the
2438 (if (or (< (window-start) (point-min))
2439 (> (window-start) (point-max)))
2440 (set-window-start (selected-window) (point)))
2441 (let* ((case-fold-search t)
2442 (current-point (point))
2444 (and Info-scroll-prefer-subnodes
2447 (setq current-point (point))
2448 (goto-char (point-min))
2449 (search-forward "\n* Menu:"
2453 (pos-visible-in-window-p (point-min) nil t))
2454 (Info-last-preorder)
2457 (defun Info-next-reference (&optional recur)
2458 "Move cursor to the next cross-reference or menu item in the node."
2460 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2462 (case-fold-search t))
2463 (or (eobp) (forward-char 1))
2464 (or (re-search-forward pat nil t)
2466 (goto-char (point-min))
2467 (or (re-search-forward pat nil t)
2470 (error "No cross references in this node")))))
2471 (goto-char (or (match-beginning 1) (match-beginning 0)))
2472 (if (looking-at "\\* Menu:")
2474 (error "No cross references in this node")
2475 (Info-next-reference t)))))
2477 (defun Info-prev-reference (&optional recur)
2478 "Move cursor to the previous cross-reference or menu item in the node."
2480 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tp://")
2482 (case-fold-search t))
2483 (or (re-search-backward pat nil t)
2485 (goto-char (point-max))
2486 (or (re-search-backward pat nil t)
2489 (error "No cross references in this node")))))
2490 (goto-char (or (match-beginning 1) (match-beginning 0)))
2491 (if (looking-at "\\* Menu:")
2493 (error "No cross references in this node")
2494 (Info-prev-reference t)))))
2496 (defvar Info-index-nodes nil
2497 "Alist of cached index node names of visited Info files.
2498 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2500 (defun Info-index-nodes (&optional file)
2501 "Return a list of names of all index nodes in Info FILE.
2502 If FILE is omitted, it defaults to the current Info file.
2503 First look in a list of cached index node names. Then scan Info
2504 file and its subfiles for nodes with the index cookie. Then try
2505 to find index nodes starting from the first node in the top level
2506 menu whose name contains the word \"Index\", plus any immediately
2507 following nodes whose names also contain the word \"Index\"."
2508 (or file (setq file Info-current-file))
2509 (or (assoc file Info-index-nodes)
2510 ;; Skip virtual Info files
2511 (and (member file '("dir" "history" "toc" "apropos"))
2512 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
2513 (not (stringp file))
2514 ;; Find nodes with index cookie
2515 (let* ((default-directory (or (and (stringp file)
2516 (file-name-directory
2517 (setq file (Info-find-file file))))
2519 Info-history Info-history-list Info-fontify-maximum-menu-size
2520 (main-file file) subfiles nodes node)
2523 (while (or main-file subfiles)
2525 (info-insert-file-contents (or main-file (car subfiles)))
2526 (goto-char (point-min))
2527 (while (search-forward "\0\b[index\0\b]" nil 'move)
2529 (re-search-backward "^\^_")
2530 (search-forward "Node: ")
2531 (setq nodes (cons (Info-following-node-name) nodes))))
2534 (goto-char (point-min))
2535 (if (search-forward "\n\^_\nIndirect:" nil t)
2536 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2537 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2538 (setq subfiles (cons (match-string-no-properties 1)
2540 (setq subfiles (nreverse subfiles)
2542 (setq subfiles (cdr subfiles)))))
2545 (setq nodes (nreverse nodes)
2546 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2548 ;; Find nodes with the word "Index" in the node name
2549 (let ((case-fold-search t)
2550 Info-history Info-history-list Info-fontify-maximum-menu-size
2555 (Info-find-node file "Top")
2556 (when (and (search-forward "\n* menu:" nil t)
2557 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2558 (goto-char (match-beginning 1))
2559 (setq nodes (list (Info-extract-menu-node-name)))
2560 (Info-goto-node (car nodes))
2561 (while (and (setq node (Info-extract-pointer "next" t))
2562 (string-match "\\<Index\\>" node))
2563 (setq nodes (cons node nodes))
2564 (Info-goto-node node))))
2567 (setq nodes (nreverse nodes)
2568 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2570 ;; If file has no index nodes, still add it to the cache
2571 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
2572 (cdr (assoc file Info-index-nodes)))
2574 (defun Info-index-node (&optional node file)
2575 "Return non-nil value if NODE is an index node.
2576 If NODE is nil, check the current Info node.
2577 If FILE is nil, check the current Info file."
2578 (if (or (and node (not (equal node Info-current-node)))
2579 (assoc (or file Info-current-file) Info-index-nodes))
2580 (member (or node Info-current-node) (Info-index-nodes file))
2581 ;; Don't search all index nodes if request is only for the current node
2582 ;; and file is not in the cache of index nodes
2585 (string-match "\\<Index\\>" (or node Info-current-node "")))
2587 (goto-char (+ (or (save-excursion
2588 (search-backward "\n\^_" nil t))
2590 (search-forward "\0\b[index\0\b]"
2592 (search-forward "\n\^_" nil t))
2595 (defun Info-goto-index ()
2596 "Go to the first index node."
2597 (let ((node (car (Info-index-nodes))))
2598 (or node (error "No index"))
2599 (Info-goto-node node)))
2602 (defun Info-index (topic)
2603 "Look up a string TOPIC in the index for this file.
2604 If there are no exact matches to the specified topic, this chooses
2605 the first match which is a case-insensitive substring of a topic.
2606 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
2607 Give a blank topic name to go to the Index node itself."
2610 (let ((Info-complete-menu-buffer (clone-buffer))
2611 (Info-complete-nodes (Info-index-nodes))
2612 (Info-history-list nil))
2613 (if (equal Info-current-file "dir")
2614 (error "The Info directory node has no index; use m to select a manual"))
2616 (with-current-buffer Info-complete-menu-buffer
2618 (completing-read "Index topic: " 'Info-complete-menu-item))
2619 (kill-buffer Info-complete-menu-buffer)))))
2620 (if (equal Info-current-file "dir")
2621 (error "The Info directory node has no index; use m to select a manual"))
2622 (let ((orignode Info-current-node)
2623 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
2624 (regexp-quote topic)))
2625 node (nodes (Info-index-nodes))
2626 (ohist-list Info-history-list)
2627 (case-fold-search t))
2629 (or (equal topic "")
2632 ;; We bind Info-history to nil for internal node-switches so
2633 ;; that we don't put junk in the history. In the first
2634 ;; Info-goto-index call, above, we do update the history
2635 ;; because that is what the user's previous node choice into it.
2640 (goto-char (point-min))
2641 (while (re-search-forward pattern nil t)
2642 (push (list (match-string-no-properties 1)
2643 (match-string-no-properties 2)
2645 (string-to-number (concat "0"
2648 (setq nodes (cdr nodes) node (car nodes)))
2649 (Info-goto-node node))
2652 (Info-goto-node orignode)
2653 (error "No `%s' in index" topic)))
2654 ;; Here it is a feature that assoc is case-sensitive.
2655 (while (setq found (assoc topic matches))
2656 (setq exact (cons found exact)
2657 matches (delq found matches)))
2658 (setq Info-history-list ohist-list)
2659 (setq Info-index-alternatives (nconc exact (nreverse matches)))
2660 (Info-index-next 0)))))
2662 (defun Info-index-next (num)
2663 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
2665 (or Info-index-alternatives
2666 (error "No previous `i' command"))
2668 (setq num (+ num (length Info-index-alternatives))))
2670 (setq Info-index-alternatives
2671 (nconc (cdr Info-index-alternatives)
2672 (list (car Info-index-alternatives)))
2674 (Info-goto-node (nth 1 (car Info-index-alternatives)))
2675 (if (> (nth 3 (car Info-index-alternatives)) 0)
2676 (forward-line (1- (nth 3 (car Info-index-alternatives))))
2677 (forward-line 3) ; don't search in headers
2678 (let ((name (car (car Info-index-alternatives))))
2679 (Info-find-index-name name)))
2680 (message "Found `%s' in %s. %s"
2681 (car (car Info-index-alternatives))
2682 (nth 2 (car Info-index-alternatives))
2683 (if (cdr Info-index-alternatives)
2684 "(`,' tries to find next)"
2687 (defun Info-find-index-name (name)
2688 "Move point to the place within the current node where NAME is defined."
2689 (let ((case-fold-search t))
2690 (if (or (re-search-forward (format
2691 "[a-zA-Z]+: %s\\( \\|$\\)"
2692 (regexp-quote name)) nil t)
2693 ;; Find a function definition with a return type.
2694 (re-search-forward (format
2695 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
2696 (regexp-quote name)) nil t)
2697 (search-forward (format "`%s'" name) nil t)
2698 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
2700 (format "`%s'" (substring name 0 (match-beginning 1)))
2702 (search-forward name nil t)
2703 ;; Try again without the " <1>" makeinfo can append
2704 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
2705 (Info-find-index-name (match-string 1 name))))
2706 (progn (beginning-of-line) t) ;; non-nil for recursive call
2707 (goto-char (point-min)))))
2710 (defun info-apropos (string)
2711 "Grovel indices of all known Info files on your system for STRING.
2712 Build a menu of the possible matches."
2713 (interactive "sIndex apropos: ")
2714 (unless (string= string "")
2715 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
2716 (regexp-quote string)))
2717 (ohist Info-history)
2718 (ohist-list Info-history-list)
2719 (current-node Info-current-node)
2720 (current-file Info-current-file)
2721 manuals matches node nodes)
2722 (let ((Info-fontify-maximum-menu-size nil))
2724 (message "Searching indices...")
2725 (goto-char (point-min))
2726 (re-search-forward "\\* Menu: *\n" nil t)
2727 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t)
2728 (add-to-list 'manuals (match-string 1)))
2729 (dolist (manual manuals)
2730 (message "Searching %s" manual)
2731 (if (setq nodes (Info-index-nodes (Info-find-file manual)))
2734 (Info-find-node manual (car nodes))
2737 (goto-char (point-min))
2738 (while (re-search-forward pattern nil t)
2739 (add-to-list 'matches
2741 (match-string-no-properties 1)
2742 (match-string-no-properties 2)
2743 (match-string-no-properties 3))))
2744 (setq nodes (cdr nodes) node (car nodes)))
2745 (Info-goto-node node)))
2747 (Info-goto-node (concat "(" current-file ")" current-node))
2748 (setq Info-history ohist
2749 Info-history-list ohist-list)
2750 (message "Searching indices...done")
2752 (message "No matches found")
2753 (with-current-buffer (get-buffer-create " *info-apropos*")
2755 (insert "\n\^_\nFile: apropos, Node: Index, Up: (dir)\n")
2756 (insert "* Menu: \nNodes whose indices contain \"" string "\"\n\n")
2757 (dolist (entry matches)
2759 (format "* %-38s (%s)%s.%s\n"
2760 (concat (nth 1 entry) " [" (nth 0 entry) "]:")
2764 (concat " (line " (nth 3 entry) ")")
2766 (Info-find-node "apropos" "Index")
2767 (setq Info-complete-cache nil)))))
2769 (defun Info-undefined ()
2770 "Make command be undefined in Info."
2775 "Enter the Info tutorial."
2777 (delete-other-windows)
2778 (Info-find-node "info"
2779 (if (< (window-height) 23)
2783 (defun Info-summary ()
2784 "Display a brief summary of all Info commands."
2786 (save-window-excursion
2787 (switch-to-buffer "*Help*")
2788 (setq buffer-read-only nil)
2790 (insert (documentation 'Info-mode))
2792 (goto-char (point-min))
2794 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
2795 (message (if flag "Type Space to see more"
2796 "Type Space to return to Info"))
2797 (if (not (eq ?\ (setq ch (read-event))))
2798 (progn (setq unread-command-events (list ch)) nil)
2801 (bury-buffer "*Help*")))
2803 (defun Info-get-token (pos start all &optional errorstring)
2804 "Return the token around POS.
2805 POS must be somewhere inside the token
2806 START is a regular expression which will match the
2807 beginning of the tokens delimited string
2808 ALL is a regular expression with a single
2809 parenthesized subpattern which is the token to be
2810 returned. E.g. '{\(.*\)}' would return any string
2811 enclosed in braces around POS.
2812 ERRORSTRING optional fourth argument, controls action on no match
2815 a string: signal an error, using that string."
2816 (let ((case-fold-search t))
2819 ;; First look for a match for START that goes across POS.
2820 (while (and (not (bobp)) (> (point) (- pos (length start)))
2821 (not (looking-at start)))
2823 ;; If we did not find one, search back for START
2824 ;; (this finds only matches that end at or before POS).
2825 (or (looking-at start)
2828 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
2830 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
2831 (not (setq found (and (<= (match-beginning 0) pos)
2832 (> (match-end 0) pos))))))
2833 (if (and found (<= (match-beginning 0) pos)
2834 (> (match-end 0) pos))
2835 (match-string-no-properties 1)
2836 (cond ((null errorstring)
2842 (error "No %s around position %d" errorstring pos))))))))
2844 (defun Info-mouse-follow-nearest-node (click)
2845 "\\<Info-mode-map>Follow a node reference near point.
2846 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
2847 At end of the node's text, moves to the next node, or up if none."
2849 (mouse-set-point click)
2850 (and (not (Info-try-follow-nearest-node))
2851 (save-excursion (forward-line 1) (eobp))
2852 (Info-next-preorder)))
2854 (defun Info-follow-nearest-node (&optional fork)
2855 "Follow a node reference near point.
2856 If point is on a reference, follow that reference. Otherwise,
2857 if point is in a menu item description, follow that menu item."
2859 (or (Info-try-follow-nearest-node fork)
2860 (when (save-excursion
2861 (search-backward "\n* menu:" nil t))
2864 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
2865 (beginning-of-line 0))
2866 (when (looking-at "\\* +\\([^\t\n]*\\):")
2868 (Info-extract-menu-item (match-string-no-properties 1)) fork)
2870 (error "Point neither on reference nor in menu item description")))
2872 ;; Common subroutine.
2873 (defun Info-try-follow-nearest-node (&optional fork)
2874 "Follow a node reference near point. Return non-nil if successful."
2877 ((Info-get-token (point) "[hf]t?tp://" "[hf]t?tp://\\([^ \t\n\"`({<>})']+\\)")
2879 (browse-url (browse-url-url-at-point)))
2880 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
2881 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
2882 (Info-follow-reference node fork))
2883 ;; menu item: node name
2884 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
2885 (Info-goto-node node fork))
2886 ;; menu item: node name or index entry
2887 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
2890 (setq node (Info-extract-menu-node-name nil (Info-index-node)))
2891 (Info-goto-node node fork))
2892 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
2893 (Info-goto-node node fork))
2894 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
2895 (Info-goto-node node fork))
2896 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
2897 (Info-goto-node "Top" fork))
2898 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
2899 (Info-goto-node node fork)))
2902 (defvar Info-mode-map nil
2903 "Keymap containing Info commands.")
2906 (setq Info-mode-map (make-keymap))
2907 (suppress-keymap Info-mode-map)
2908 (define-key Info-mode-map "." 'beginning-of-buffer)
2909 (define-key Info-mode-map " " 'Info-scroll-up)
2910 (define-key Info-mode-map "\C-m" 'Info-follow-nearest-node)
2911 (define-key Info-mode-map "\t" 'Info-next-reference)
2912 (define-key Info-mode-map [(shift tab)] 'Info-prev-reference)
2913 (define-key Info-mode-map [backtab] 'Info-prev-reference)
2914 (define-key Info-mode-map "1" 'Info-nth-menu-item)
2915 (define-key Info-mode-map "2" 'Info-nth-menu-item)
2916 (define-key Info-mode-map "3" 'Info-nth-menu-item)
2917 (define-key Info-mode-map "4" 'Info-nth-menu-item)
2918 (define-key Info-mode-map "5" 'Info-nth-menu-item)
2919 (define-key Info-mode-map "6" 'Info-nth-menu-item)
2920 (define-key Info-mode-map "7" 'Info-nth-menu-item)
2921 (define-key Info-mode-map "8" 'Info-nth-menu-item)
2922 (define-key Info-mode-map "9" 'Info-nth-menu-item)
2923 (define-key Info-mode-map "0" 'undefined)
2924 (define-key Info-mode-map "?" 'Info-summary)
2925 (define-key Info-mode-map "]" 'Info-forward-node)
2926 (define-key Info-mode-map "[" 'Info-backward-node)
2927 (define-key Info-mode-map "<" 'Info-top-node)
2928 (define-key Info-mode-map ">" 'Info-final-node)
2929 (define-key Info-mode-map "b" 'beginning-of-buffer)
2930 (define-key Info-mode-map "c" 'Info-copy-current-node-name)
2931 (define-key Info-mode-map "d" 'Info-directory)
2932 (define-key Info-mode-map "e" 'Info-edit)
2933 (define-key Info-mode-map "f" 'Info-follow-reference)
2934 (define-key Info-mode-map "g" 'Info-goto-node)
2935 (define-key Info-mode-map "h" 'Info-help)
2936 (define-key Info-mode-map "i" 'Info-index)
2937 (define-key Info-mode-map "l" 'Info-history-back)
2938 (define-key Info-mode-map "L" 'Info-history)
2939 (define-key Info-mode-map "m" 'Info-menu)
2940 (define-key Info-mode-map "n" 'Info-next)
2941 (define-key Info-mode-map "p" 'Info-prev)
2942 (define-key Info-mode-map "q" 'Info-exit)
2943 (define-key Info-mode-map "r" 'Info-history-forward)
2944 (define-key Info-mode-map "s" 'Info-search)
2945 (define-key Info-mode-map "S" 'Info-search-case-sensitively)
2946 ;; For consistency with Rmail.
2947 (define-key Info-mode-map "\M-s" 'Info-search)
2948 (define-key Info-mode-map "\M-n" 'clone-buffer)
2949 (define-key Info-mode-map "t" 'Info-top-node)
2950 (define-key Info-mode-map "T" 'Info-toc)
2951 (define-key Info-mode-map "u" 'Info-up)
2952 ;; For consistency with dired-copy-filename-as-kill.
2953 (define-key Info-mode-map "w" 'Info-copy-current-node-name)
2954 (define-key Info-mode-map "," 'Info-index-next)
2955 (define-key Info-mode-map "\177" 'Info-scroll-down)
2956 (define-key Info-mode-map [mouse-2] 'Info-mouse-follow-nearest-node)
2957 (define-key Info-mode-map [follow-link] 'mouse-face)
2960 (defun Info-check-pointer (item)
2961 "Non-nil if ITEM is present in this node."
2963 (Info-extract-pointer item)
2967 Info-mode-menu Info-mode-map
2968 "Menu for info files."
2970 ["Up" Info-up :active (Info-check-pointer "up")
2971 :help "Go up in the Info tree"]
2972 ["Next" Info-next :active (Info-check-pointer "next")
2973 :help "Go to the next node"]
2974 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
2975 :help "Go to the previous node"]
2976 ["Backward" Info-backward-node
2977 :help "Go backward one node, considering all as a sequence"]
2978 ["Forward" Info-forward-node
2979 :help "Go forward one node, considering all as a sequence"]
2980 ["Beginning" beginning-of-buffer
2981 :help "Go to beginning of this node"]
2982 ["Top" Info-top-node
2983 :help "Go to top node of file"]
2984 ["Final Node" Info-final-node
2985 :help "Go to final node in this file"]
2986 ("Menu Item" ["You should never see this" report-emacs-bug t])
2987 ("Reference" ["You should never see this" report-emacs-bug t])
2988 ["Search..." Info-search
2989 :help "Search for regular expression in this Info file"]
2990 ["Search Case-Sensitively..." Info-search-case-sensitively
2991 :help "Search for regular expression case sensitively"]
2992 ["Search Next" Info-search-next
2993 :help "Search for another occurrence of regular expression"]
2994 ["Go to Node..." Info-goto-node
2995 :help "Go to a named node"]
2996 ["Back in history" Info-history-back :active Info-history
2997 :help "Go back in history to the last node you were at"]
2998 ["Forward in history" Info-history-forward :active Info-history-forward
2999 :help "Go forward in history"]
3000 ["History" Info-history :active Info-history-list
3001 :help "Go to menu of visited nodes"]
3002 ["Table of Contents" Info-toc
3003 :help "Go to table of contents"]
3005 ["Lookup a String" Info-index
3006 :help "Look for a string in the index items"]
3007 ["Next Matching Item" Info-index-next
3008 :help "Look for another occurrence of previous item"]
3009 ["Lookup a string in all indices" info-apropos
3010 :help "Look for a string in the indices of all manuals"])
3011 ["Edit" Info-edit :help "Edit contents of this node"
3012 :active Info-enable-edit]
3013 ["Copy Node Name" Info-copy-current-node-name
3014 :help "Copy the name of the current node into the kill ring"]
3015 ["Clone Info buffer" clone-buffer
3016 :help "Create a twin copy of the current Info buffer."]
3017 ["Exit" Info-exit :help "Stop reading Info"]))
3020 (defvar info-tool-bar-map
3021 (if (display-graphic-p)
3022 (let ((map (make-sparse-keymap)))
3023 (tool-bar-local-item-from-menu 'Info-exit "close" map Info-mode-map)
3024 (tool-bar-local-item-from-menu 'Info-prev "left_arrow" map Info-mode-map)
3025 (tool-bar-local-item-from-menu 'Info-next "right_arrow" map Info-mode-map)
3026 (tool-bar-local-item-from-menu 'Info-up "up_arrow" map Info-mode-map)
3027 (tool-bar-local-item-from-menu 'Info-history-back "back_arrow" map Info-mode-map)
3028 (tool-bar-local-item-from-menu 'Info-history-forward "fwd_arrow" map Info-mode-map)
3029 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
3030 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map)
3031 (tool-bar-local-item-from-menu 'Info-goto-node "jump_to" map Info-mode-map)
3032 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
3035 (defvar Info-menu-last-node nil)
3036 ;; Last node the menu was created for.
3037 ;; Value is a list, (FILE-NAME NODE-NAME).
3039 (defun Info-menu-update ()
3040 "Update the Info menu for the current node."
3042 (if (or (not (eq major-mode 'Info-mode))
3043 (equal (list Info-current-file Info-current-node)
3044 Info-menu-last-node))
3046 ;; Update menu menu.
3047 (let* ((Info-complete-menu-buffer (current-buffer))
3048 (items (nreverse (condition-case nil
3049 (Info-complete-menu-item "" nil t)
3053 (while (and items (< number 9))
3054 (setq current (car items)
3057 (setq entries (cons `[,current
3058 (Info-menu ,current)
3059 :keys ,(format "%d" number)]
3062 (setq entries (cons ["Other..." Info-menu t] entries)))
3064 (setq entries (list ["No menu" nil nil] nil :active)))
3065 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3066 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3068 str i entries current
3070 (case-fold-search t))
3072 (goto-char (point-min))
3073 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3074 (setq str (match-string 1))
3076 (while (setq i (string-match "[ \n\t]+" str i))
3077 (setq str (concat (substring str 0 i) " "
3078 (substring str (match-end 0))))
3082 (while (and items (< number 9))
3083 (setq current (car items)
3086 (setq entries (cons `[,current
3087 (Info-follow-reference ,current)
3091 (setq entries (cons ["Other..." Info-follow-reference t]
3094 (setq entries (list ["No references" nil nil] nil :active)))
3095 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3096 ;; Update last seen node.
3097 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3098 ;; Try to avoid entering infinite beep mode in case of errors.
3102 (defun Info-copy-current-node-name (&optional arg)
3103 "Put the name of the current info node into the kill ring.
3104 The name of the info file is prepended to the node name in parentheses.
3105 With a zero prefix arg, put the name inside a function call to `info'."
3107 (unless Info-current-node
3108 (error "No current info node"))
3109 (let ((node (concat "(" (file-name-nondirectory
3110 (or (and (stringp Info-current-file)
3114 ")" Info-current-node)))
3115 (if (zerop (prefix-numeric-value arg))
3116 (setq node (concat "(info \"" node "\")")))
3118 (message "%s" node)))
3121 ;; Info mode is suitable only for specially formatted data.
3122 (put 'Info-mode 'mode-class 'special)
3123 (put 'Info-mode 'no-clone-indirect t)
3126 "Info mode provides commands for browsing through the Info documentation tree.
3127 Documentation in Info is divided into \"nodes\", each of which discusses
3128 one topic and contains references to other nodes which discuss related
3129 topics. Info has commands to follow the references and show you other nodes.
3132 \\[Info-help] Invoke the Info tutorial.
3133 \\[Info-exit] Quit Info: reselect previously selected buffer.
3135 Selecting other nodes:
3136 \\[Info-mouse-follow-nearest-node]
3137 Follow a node reference you click on.
3138 This works with menu items, cross references, and
3139 the \"next\", \"previous\" and \"up\", depending on where you click.
3140 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3141 \\[Info-next] Move to the \"next\" node of this node.
3142 \\[Info-prev] Move to the \"previous\" node of this node.
3143 \\[Info-up] Move \"up\" from this node.
3144 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3145 Picking a menu item causes another node to be selected.
3146 \\[Info-directory] Go to the Info directory node.
3147 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3148 \\[Info-history-back] Move back in history to the last node you were at.
3149 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3150 \\[Info-history] Go to menu of visited nodes.
3151 \\[Info-toc] Go to table of contents of the current Info file.
3152 \\[Info-top-node] Go to the Top node of this file.
3153 \\[Info-final-node] Go to the final node in this file.
3154 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3155 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3156 \\[Info-index] Look up a topic in this file's Index and move to that node.
3157 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3158 \\[info-apropos] Look for a string in the indices of all manuals.
3160 Moving within a node:
3161 \\[Info-scroll-up] Normally, scroll forward a full screen.
3162 Once you scroll far enough in a node that its menu appears on the
3163 screen but after point, the next scroll moves into its first
3164 subnode. When after all menu items (or if there is no menu),
3165 move up to the parent node.
3166 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3167 already visible, try to go to the previous menu entry, or up
3169 \\[beginning-of-buffer] Go to beginning of node.
3172 \\[Info-copy-current-node-name] Put name of current info node in the kill ring.
3173 \\[clone-buffer] Select a new cloned Info buffer in another window.
3174 \\[Info-edit] Edit contents of selected node.
3175 1 .. 9 Pick first ... ninth item in node's menu.
3176 Every third `*' is highlighted to help pick the right number.
3177 \\[Info-goto-node] Move to node specified by name.
3178 You may include a filename as well, as (FILENAME)NODENAME.
3179 \\[universal-argument] \\[info] Move to new Info file with completion.
3180 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>.
3181 \\[Info-search] Search through this Info file for specified regexp,
3182 and select the node in which the next occurrence is found.
3183 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3184 \\[Info-search-next] Search for another occurrence of regexp
3185 from a previous \\<Info-mode-map>\\[Info-search] command.
3186 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3187 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item."
3188 (kill-all-local-variables)
3189 (setq major-mode 'Info-mode)
3190 (setq mode-name "Info")
3192 (use-local-map Info-mode-map)
3193 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3194 (set-syntax-table text-mode-syntax-table)
3195 (setq local-abbrev-table text-mode-abbrev-table)
3196 (setq case-fold-search t)
3197 (setq buffer-read-only t)
3198 (make-local-variable 'Info-current-file)
3199 (make-local-variable 'Info-current-subfile)
3200 (make-local-variable 'Info-current-node)
3201 (make-local-variable 'Info-tag-table-marker)
3202 (setq Info-tag-table-marker (make-marker))
3203 (make-local-variable 'Info-tag-table-buffer)
3204 (setq Info-tag-table-buffer nil)
3205 (make-local-variable 'Info-history)
3206 (make-local-variable 'Info-history-forward)
3207 (make-local-variable 'Info-index-alternatives)
3208 (setq header-line-format
3209 (if Info-use-header-line
3210 '(:eval (get-text-property (point-min) 'header-line))
3211 nil)) ; so the header line isn't displayed
3212 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
3213 ;; This is for the sake of the invisible text we use handling titles.
3214 (make-local-variable 'line-move-ignore-invisible)
3215 (setq line-move-ignore-invisible t)
3216 (make-local-variable 'desktop-save-buffer)
3217 (setq desktop-save-buffer 'Info-desktop-buffer-misc-data)
3218 (add-hook 'clone-buffer-hook 'Info-clone-buffer-hook nil t)
3219 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
3220 (set (make-local-variable 'isearch-search-fun-function)
3221 'Info-isearch-search)
3222 (set (make-local-variable 'isearch-wrap-function)
3224 (set (make-local-variable 'isearch-push-state-function)
3225 'Info-isearch-push-state)
3226 (set (make-local-variable 'search-whitespace-regexp)
3227 Info-search-whitespace-regexp)
3228 (Info-set-mode-line)
3229 (run-hooks 'Info-mode-hook))
3231 (defun Info-clone-buffer-hook ()
3232 (when (bufferp Info-tag-table-buffer)
3233 (setq Info-tag-table-buffer
3234 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
3235 (let ((m Info-tag-table-marker))
3237 (setq Info-tag-table-marker
3238 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
3239 (with-current-buffer Info-tag-table-buffer
3240 (copy-marker (marker-position m)))
3243 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
3244 (set-keymap-parent map text-mode-map)
3245 (define-key map "\C-c\C-c" 'Info-cease-edit)
3247 "Local keymap used within `e' command of Info.")
3249 ;; Info-edit mode is suitable only for specially formatted data.
3250 (put 'Info-edit-mode 'mode-class 'special)
3252 (defun Info-edit-mode ()
3253 "Major mode for editing the contents of an Info node.
3254 Like text mode with the addition of `Info-cease-edit'
3255 which returns to Info mode for browsing.
3257 (use-local-map Info-edit-map)
3258 (setq major-mode 'Info-edit-mode)
3259 (setq mode-name "Info Edit")
3260 (kill-local-variable 'mode-line-buffer-identification)
3261 (setq buffer-read-only nil)
3262 (force-mode-line-update)
3263 (buffer-enable-undo (current-buffer))
3264 (run-hooks 'Info-edit-mode-hook))
3267 "Edit the contents of this Info node.
3268 Allowed only if variable `Info-enable-edit' is non-nil."
3270 (or Info-enable-edit
3271 (error "Editing info nodes is not enabled"))
3273 (message "%s" (substitute-command-keys
3274 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
3276 (defun Info-cease-edit ()
3277 "Finish editing Info node; switch back to Info proper."
3279 ;; Do this first, so nothing has changed if user C-g's at query.
3280 (and (buffer-modified-p)
3281 (y-or-n-p "Save the file? ")
3283 (use-local-map Info-mode-map)
3284 (setq major-mode 'Info-mode)
3285 (setq mode-name "Info")
3286 (Info-set-mode-line)
3287 (setq buffer-read-only t)
3288 (force-mode-line-update)
3289 (and (marker-position Info-tag-table-marker)
3291 (message "Tags may have changed. Use Info-tagify if necessary")))
3293 (defvar Info-file-list-for-emacs
3294 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
3295 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
3296 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
3297 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
3298 ("skeleton" . "autotype") ("auto-insert" . "autotype")
3299 ("copyright" . "autotype") ("executable" . "autotype")
3300 ("time-stamp" . "autotype") ("quickurl" . "autotype")
3301 ("tempo" . "autotype") ("hippie-expand" . "autotype")
3302 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
3303 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
3304 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
3305 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
3306 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
3307 ("rfc2045" . "emacs-mime")
3308 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
3309 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
3310 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
3311 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
3312 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
3313 ("mml" . "emacs-mime"))
3314 "List of Info files that describe Emacs commands.
3315 An element can be a file name, or a list of the form (PREFIX . FILE)
3316 where PREFIX is a name prefix and FILE is the file to look in.
3317 If the element is just a file name, the file name also serves as the prefix.")
3319 (defun Info-find-emacs-command-nodes (command)
3320 "Return a list of locations documenting COMMAND.
3321 The `info-file' property of COMMAND says which Info manual to search.
3322 If COMMAND has no property, the variable `Info-file-list-for-emacs'
3323 defines heuristics for which Info manual to try.
3324 The locations are of the format used in `Info-history', i.e.
3325 \(FILENAME NODENAME BUFFERPOS\), where BUFFERPOS is the line number
3326 in the first element of the returned list (which is treated specially in
3327 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
3328 (let ((where '()) line-number
3329 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
3330 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
3331 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
3332 (info-file "emacs")) ;default
3333 ;; Determine which info file this command is documented in.
3334 (if (get command 'info-file)
3335 (setq info-file (get command 'info-file))
3336 ;; If it doesn't say explicitly, test its name against
3337 ;; various prefixes that we know.
3338 (let ((file-list Info-file-list-for-emacs))
3340 (let* ((elt (car file-list))
3341 (name (if (consp elt)
3344 (file (if (consp elt) (cdr elt) elt))
3345 (case-fold-search nil)
3346 (regexp (concat "\\`" (regexp-quote name)
3348 (if (string-match regexp (symbol-name command))
3349 (setq info-file file file-list nil))
3350 (setq file-list (cdr file-list))))))
3351 (Info-find-node info-file "Top")
3352 (or (and (search-forward "\n* menu:" nil t)
3353 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
3354 (error "Info file `%s' appears to lack an index" info-file))
3355 (goto-char (match-beginning 1))
3356 ;; Bind Info-history to nil, to prevent the index nodes from
3357 ;; getting into the node history.
3358 (let ((Info-history nil)
3359 (Info-history-list nil)
3360 node (nodes (Info-index-nodes)))
3361 (Info-goto-node (car nodes))
3364 (goto-char (point-min))
3365 (while (re-search-forward cmd-desc nil t)
3367 (cons (list Info-current-file
3368 (match-string-no-properties 2)
3371 (setq line-number (and (match-beginning 3)
3372 (string-to-number (match-string 3)))))
3373 (and (setq nodes (cdr nodes) node (car nodes))))
3374 (Info-goto-node node)))
3375 (if (and line-number where)
3376 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
3380 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file "emacs")
3382 (defun Info-goto-emacs-command-node (command)
3383 "Go to the Info node in the Emacs manual for command COMMAND.
3384 The command is found by looking up in Emacs manual's indices
3385 or in another manual found via COMMAND's `info-file' property or
3386 the variable `Info-file-list-for-emacs'.
3387 COMMAND must be a symbol or string."
3388 (interactive "CFind documentation for command: ")
3389 ;; If command is given as a string, convert it to a symbol.
3390 (if (stringp command)
3391 (setq command (intern command)))
3392 (or (commandp command)
3393 (signal 'wrong-type-argument (list 'commandp command)))
3394 (let ((where (Info-find-emacs-command-nodes command)))
3396 (let ((num-matches (length where)))
3397 ;; Get Info running, and pop to it in another window.
3398 (save-window-excursion
3400 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
3401 ;; Bind Info-history to nil, to prevent the last Index node
3402 ;; visited by Info-find-emacs-command-nodes from being
3403 ;; pushed onto the history.
3404 (let ((Info-history nil) (Info-history-list nil)
3405 (line-number (nth 2 (car where))))
3406 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
3407 (if (and (integerp line-number) (> line-number 0))
3408 (forward-line (1- line-number))))
3409 (if (> num-matches 1)
3411 ;; (car where) will be pushed onto Info-history
3412 ;; when/if they go to another node. Put the other
3413 ;; nodes that were found on the history.
3414 (setq Info-history (nconc (cdr where) Info-history))
3415 (message "Found %d other entr%s. Use %s to see %s."
3417 (if (> num-matches 2) "ies" "y")
3418 (substitute-command-keys "\\[Info-history-back]")
3419 (if (> num-matches 2) "them" "it")))))
3420 (error "Couldn't find documentation for %s" command))))
3422 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file "emacs")
3424 (defun Info-goto-emacs-key-command-node (key)
3425 "Go to the node in the Emacs manual which describes the command bound to KEY.
3427 Interactively, if the binding is `execute-extended-command', a command is read.
3428 The command is found by looking up in Emacs manual's indices
3429 or in another manual found via COMMAND's `info-file' property or
3430 the variable `Info-file-list-for-emacs'."
3431 (interactive "kFind documentation for key: ")
3432 (let ((command (key-binding key)))
3433 (cond ((null command)
3434 (message "%s is undefined" (key-description key)))
3435 ((and (interactive-p)
3436 (eq command 'execute-extended-command))
3437 (Info-goto-emacs-command-node
3438 (read-command "Find documentation for command: ")))
3440 (Info-goto-emacs-command-node command)))))
3442 (defface Info-title-1-face
3443 '((((type tty pc) (class color)) :foreground "yellow" :weight bold)
3444 (t :height 1.2 :inherit Info-title-2-face))
3445 "Face for Info titles at level 1."
3448 (defface Info-title-2-face
3449 '((((type tty pc) (class color)) :foreground "lightblue" :weight bold)
3450 (t :height 1.2 :inherit Info-title-3-face))
3451 "Face for Info titles at level 2."
3454 (defface Info-title-3-face
3455 '((((type tty pc) (class color)) :weight bold)
3456 (t :height 1.2 :inherit Info-title-4-face))
3457 "Face for Info titles at level 3."
3460 (defface Info-title-4-face
3461 '((((type tty pc) (class color)) :weight bold)
3462 (t :weight bold :inherit variable-pitch))
3463 "Face for Info titles at level 4."
3466 (defface info-menu-header
3471 :inherit variable-pitch
3473 "Face for headers in Info menus."
3476 (defun Info-escape-percent (string)
3477 "Double all occurrences of `%' in STRING.
3479 Return a new string with all `%' characters replaced by `%%'.
3480 Preserve text properties."
3482 (end (length string))
3485 (while (and (< start end) (string-match "%" string start))
3486 (setq mb (match-beginning 0)
3488 m (substring string mb me)
3491 (cons (substring string start mb)
3494 (push (substring string start end) matches)
3495 (apply #'concat (nreverse matches)))))
3497 (defvar Info-next-link-keymap
3498 (let ((keymap (make-sparse-keymap)))
3499 (define-key keymap [header-line mouse-1] 'Info-next)
3500 (define-key keymap [header-line mouse-2] 'Info-next)
3501 (define-key keymap [header-line down-mouse-1] 'ignore)
3502 (define-key keymap [mouse-2] 'Info-next)
3503 (define-key keymap [follow-link] 'mouse-face)
3505 "Keymap to put on the Next link in the text or the header line.")
3507 (defvar Info-prev-link-keymap
3508 (let ((keymap (make-sparse-keymap)))
3509 (define-key keymap [header-line mouse-1] 'Info-prev)
3510 (define-key keymap [header-line mouse-2] 'Info-prev)
3511 (define-key keymap [header-line down-mouse-1] 'ignore)
3512 (define-key keymap [mouse-2] 'Info-prev)
3513 (define-key keymap [follow-link] 'mouse-face)
3515 "Keymap to put on the Prev link in the text or the header line.")
3518 (defvar Info-up-link-keymap
3519 (let ((keymap (make-sparse-keymap)))
3520 (define-key keymap [header-line mouse-1] 'Info-up)
3521 (define-key keymap [header-line mouse-2] 'Info-up)
3522 (define-key keymap [header-line down-mouse-1] 'ignore)
3523 (define-key keymap [mouse-2] 'Info-up)
3524 (define-key keymap [follow-link] 'mouse-face)
3526 "Keymap to put on the Up link in the text or the header line.")
3528 (defun Info-fontify-node ()
3531 (let* ((inhibit-read-only t)
3532 (case-fold-search t)
3534 (not-fontified-p ; the node hasn't already been fontified
3535 (not (let ((where (next-property-change (point-min))))
3536 (and where (not (= where (point-max)))))))
3537 (fontify-visited-p ; visited nodes need to be re-fontified
3538 (and Info-fontify-visited-nodes
3539 ;; Don't take time to refontify visited nodes in huge nodes
3540 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
3543 ;; Fontify header line
3544 (goto-char (point-min))
3545 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
3546 (goto-char (match-end 0))
3547 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
3548 (goto-char (match-end 0))
3549 (let* ((nbeg (match-beginning 2))
3550 (nend (match-end 2))
3551 (tbeg (match-beginning 1))
3552 (tag (match-string 1)))
3553 (if (string-equal tag "Node")
3554 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
3555 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
3556 (put-text-property tbeg nend 'mouse-face 'highlight)
3557 (put-text-property tbeg nend
3559 (concat "mouse-2: Go to node "
3560 (buffer-substring nbeg nend)))
3561 ;; Always set up the text property keymap.
3562 ;; It will either be used in the buffer
3563 ;; or copied in the header line.
3564 (put-text-property tbeg nend 'keymap
3566 ((equal tag "Prev") Info-prev-link-keymap)
3567 ((equal tag "Next") Info-next-link-keymap)
3568 ((equal tag "Up") Info-up-link-keymap))))))
3569 (when Info-use-header-line
3570 (goto-char (point-min))
3571 (let ((header-end (line-end-position))
3573 ;; If we find neither Next: nor Prev: link, show the entire
3574 ;; node header. Otherwise, don't show the File: and Node:
3575 ;; parts, to avoid wasting precious space on information that
3576 ;; is available in the mode line.
3577 (if (re-search-forward
3578 "\\(next\\|up\\|prev[ious]*\\): "
3581 (goto-char (match-beginning 1))
3582 (setq header (buffer-substring (point) header-end)))
3583 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*" header-end t)
3585 (concat "No next, prev or up links -- "
3586 (buffer-substring (point) header-end)))
3587 (setq header (buffer-substring (point) header-end))))
3588 (put-text-property (point-min) (1+ (point-min))
3589 'header-line (Info-escape-percent header))
3590 ;; Hide the part of the first line
3591 ;; that is in the header, if it is just part.
3593 ;; Hide the punctuation at the end, too.
3594 (skip-chars-backward " \t,")
3595 (put-text-property (point) header-end 'invisible t)))))
3598 (goto-char (point-min))
3599 (when not-fontified-p
3600 (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
3602 (let* ((c (preceding-char))
3604 (cond ((= c ?*) 'Info-title-1-face)
3605 ((= c ?=) 'Info-title-2-face)
3606 ((= c ?-) 'Info-title-3-face)
3607 (t 'Info-title-4-face))))
3608 (put-text-property (match-beginning 1) (match-end 1)
3609 'font-lock-face face))
3610 ;; This is a serious problem for trying to handle multiple
3611 ;; frame types at once. We want this text to be invisible
3612 ;; on frames that can display the font above.
3613 (when (memq (framep (selected-frame)) '(x pc w32 mac))
3614 (add-text-properties (1- (match-beginning 2)) (match-end 2)
3615 '(invisible t front-sticky nil rear-nonsticky t)))))
3617 ;; Fontify cross references
3618 (goto-char (point-min))
3619 (when (or not-fontified-p fontify-visited-p)
3620 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
3621 (let ((start (match-beginning 0))
3624 (when not-fontified-p
3625 (when Info-hide-note-references
3626 (when (not (eq Info-hide-note-references 'hide))
3627 ;; *Note is often used where *note should have been
3629 (skip-syntax-backward " ")
3631 (cond ((memq (char-before) '(nil ?\. ?! ??))
3633 ((memq (char-before) '(?\, ?\; ?\: ?-))
3635 ((memq (char-before) '(?\( ?\[ ?\{))
3636 ;; Check whether the paren is preceded by
3637 ;; an end of sentence
3638 (skip-syntax-backward " (")
3639 (if (memq (char-before) '(nil ?\. ?! ??))
3642 ((save-match-data (looking-at "\n\n"))
3645 (add-text-properties
3647 (or (save-match-data
3648 ;; Don't hide \n after *Note
3649 (let ((start1 (match-beginning 1)))
3650 (if (string-match "\n" (match-string 1))
3651 (+ start1 (match-beginning 0)))))
3654 `(display ,other-tag front-sticky nil rear-nonsticky t)
3655 '(invisible t front-sticky nil rear-nonsticky t))))
3656 (add-text-properties
3657 (match-beginning 2) (match-end 2)
3659 'help-echo (if (or (match-end 5)
3660 (not (equal (match-string 4) "")))
3661 (concat "mouse-2: go to " (or (match-string 5)
3663 "mouse-2: go to this node")
3664 'mouse-face 'highlight)))
3665 (when (or not-fontified-p fontify-visited-p)
3666 (setq rbeg (match-beginning 2)
3671 ;; Display visited nodes in a different face
3672 (if (and Info-fontify-visited-nodes
3674 (let* ((node (replace-regexp-in-string
3676 (replace-regexp-in-string
3678 (or (match-string 5)
3679 (and (not (equal (match-string 4) ""))
3681 (match-string 2)))))
3682 (file (file-name-nondirectory
3684 (hl Info-history-list)
3686 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3687 (setq file (file-name-nondirectory
3688 (match-string 1 node))
3689 node (if (equal (match-string 2 node) "")
3691 (match-string 2 node))))
3693 (if (and (string-equal node (nth 1 (car hl)))
3695 (file-name-nondirectory
3697 (setq res (car hl) hl nil)
3698 (setq hl (cdr hl))))
3699 res))) 'info-xref-visited 'info-xref))
3700 ;; For multiline ref, unfontify newline and surrounding whitespace
3704 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
3705 (remove-text-properties (match-beginning 0)
3707 '(font-lock-face t))))))
3708 (when not-fontified-p
3709 (when (memq Info-hide-note-references '(t hide))
3710 (add-text-properties (match-beginning 3) (match-end 3)
3711 '(invisible t front-sticky nil rear-nonsticky t))
3712 ;; Unhide the file name of the external reference in parens
3713 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
3714 (remove-text-properties (match-beginning 6) (match-end 6)
3715 '(invisible t front-sticky nil rear-nonsticky t)))
3716 ;; Unhide newline because hidden newlines cause too long lines
3718 (let ((beg3 (match-beginning 3))
3719 (end3 (match-end 3)))
3720 (if (and (string-match "\n[ \t]*" (match-string 3))
3721 (not (save-match-data
3723 (goto-char (1+ end3))
3724 (looking-at "[.)]*$")))))
3725 (remove-text-properties (+ beg3 (match-beginning 0))
3726 (+ beg3 (match-end 0))
3727 '(invisible t front-sticky nil rear-nonsticky t))))))
3728 (when (and Info-refill-paragraphs Info-hide-note-references)
3729 (push (set-marker (make-marker) start)
3730 paragraph-markers))))))
3732 ;; Refill paragraphs (experimental feature)
3733 (when (and not-fontified-p
3734 Info-refill-paragraphs
3736 (let ((fill-nobreak-invisible t)
3737 (fill-individual-varying-indent nil)
3738 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
3739 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
3740 (adaptive-fill-mode nil))
3741 (goto-char (point-max))
3742 (while paragraph-markers
3743 (let ((m (car paragraph-markers)))
3744 (setq paragraph-markers (cdr paragraph-markers))
3748 (let ((beg (point)))
3749 (when (zerop (forward-paragraph))
3750 (fill-individual-paragraphs beg (point) nil nil)
3752 (set-marker m nil)))))
3754 ;; Fontify menu items
3755 (goto-char (point-min))
3756 (when (and (or not-fontified-p fontify-visited-p)
3757 (search-forward "\n* Menu:" nil t)
3758 (not (Info-index-node))
3759 ;; Don't take time to annotate huge menus
3760 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
3763 (while (re-search-forward
3764 (concat "^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
3765 Info-node-spec-re "\\([ \t]*\\)\\)")
3767 (when not-fontified-p
3769 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
3770 (put-text-property (match-beginning 0)
3771 (1+ (match-beginning 0))
3772 'font-lock-face 'info-menu-5)))
3773 (when not-fontified-p
3774 (add-text-properties
3775 (match-beginning 1) (match-end 1)
3777 'help-echo (if (match-end 3)
3778 (concat "mouse-2: go to " (match-string 3))
3779 "mouse-2: go to this node")
3780 'mouse-face 'highlight)))
3781 (when (or not-fontified-p fontify-visited-p)
3782 (add-text-properties
3783 (match-beginning 1) (match-end 1)
3786 ;; Display visited menu items in a different face
3787 (if (and Info-fontify-visited-nodes
3789 (let ((node (if (equal (match-string 3) "")
3792 (file (file-name-nondirectory Info-current-file))
3793 (hl Info-history-list)
3795 (if (string-match "(\\([^)]+\\))\\([^)]*\\)" node)
3796 (setq file (file-name-nondirectory
3797 (match-string 1 node))
3798 node (if (equal (match-string 2 node) "")
3800 (match-string 2 node))))
3802 (if (and (string-equal node (nth 1 (car hl)))
3804 (file-name-nondirectory
3806 (setq res (car hl) hl nil)
3807 (setq hl (cdr hl))))
3808 res))) 'info-xref-visited 'info-xref))))
3809 (when (and not-fontified-p (memq Info-hide-note-references '(t hide)))
3810 (put-text-property (match-beginning 2) (1- (match-end 6))
3812 ;; Unhide the file name in parens
3813 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
3814 (remove-text-properties (match-beginning 4) (match-end 4)
3816 ;; We need a stretchable space like :align-to but with
3818 (put-text-property (1- (match-end 6)) (match-end 6) 'display
3819 (if (>= 22 (- (match-end 1)
3820 (match-beginning 0)))
3821 '(space :align-to 24)
3823 (setq cont (looking-at "."))
3824 (while (and (= (forward-line 1) 0)
3825 (looking-at "\\([ \t]+\\)[^*\n]"))
3826 (put-text-property (match-beginning 1) (1- (match-end 1))
3828 (put-text-property (1- (match-end 1)) (match-end 1)
3831 '(space :align-to 26)
3832 '(space :align-to 24)))
3835 ;; Fontify menu headers
3836 ;; Add the face `info-menu-header' to any header before a menu entry
3837 (goto-char (point-min))
3838 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
3839 (put-text-property (match-beginning 0) (match-end 0)
3840 'font-lock-face 'info-menu-header)
3841 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
3842 (put-text-property (match-beginning 1) (match-end 1)
3843 'font-lock-face 'info-menu-header)))
3845 ;; Hide index line numbers
3846 (goto-char (point-min))
3847 (when (and not-fontified-p (Info-index-node))
3848 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
3849 (put-text-property (match-beginning 0) (match-end 0)
3852 ;; Fontify http and ftp references
3853 (goto-char (point-min))
3854 (when not-fontified-p
3855 (while (re-search-forward "[hf]t?tp://[^ \t\n\"`({<>})']+" nil t)
3856 (add-text-properties (match-beginning 0) (match-end 0)
3857 '(font-lock-face info-xref
3858 mouse-face highlight
3859 help-echo "mouse-2: go to this URL"))))
3861 (set-buffer-modified-p nil))))
3864 ;; When an Info buffer is killed, make sure the associated tags buffer
3866 (defun Info-kill-buffer ()
3867 (and (eq major-mode 'Info-mode)
3868 Info-tag-table-buffer
3869 (kill-buffer Info-tag-table-buffer)))
3871 (add-hook 'kill-buffer-hook 'Info-kill-buffer)
3873 ;;; Speedbar support:
3874 ;; These functions permit speedbar to display the "tags" in the
3875 ;; current info node.
3876 (eval-when-compile (require 'speedbar))
3878 (defvar Info-speedbar-key-map nil
3879 "Keymap used when in the info display mode.")
3881 (defun Info-install-speedbar-variables ()
3882 "Install those variables used by speedbar to enhance Info."
3883 (if Info-speedbar-key-map
3885 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
3887 ;; Basic tree features
3888 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
3889 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
3890 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
3891 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
3894 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
3895 Info-speedbar-key-map
3896 Info-speedbar-hierarchy-buttons)))
3898 (defvar Info-speedbar-menu-items
3899 '(["Browse Node" speedbar-edit-line t]
3900 ["Expand Node" speedbar-expand-line
3901 (save-excursion (beginning-of-line)
3902 (looking-at "[0-9]+: *.\\+. "))]
3903 ["Contract Node" speedbar-contract-line
3904 (save-excursion (beginning-of-line)
3905 (looking-at "[0-9]+: *.-. "))]
3907 "Additional menu-items to add to speedbar frame.")
3909 ;; Make sure our special speedbar major mode is loaded
3910 (if (featurep 'speedbar)
3911 (Info-install-speedbar-variables)
3912 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
3914 ;;; Info hierarchy display method
3916 (defun Info-speedbar-browser ()
3917 "Initialize speedbar to display an info node browser.
3918 This will add a speedbar major display mode."
3921 ;; Make sure that speedbar is active
3922 (speedbar-frame-mode 1)
3923 ;; Now, throw us into Info mode on speedbar.
3924 (speedbar-change-initial-expansion-list "Info")
3927 (eval-when-compile (defvar speedbar-attached-frame))
3929 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
3930 "Display an Info directory hierarchy in speedbar.
3931 DIRECTORY is the current directory in the attached frame.
3932 DEPTH is the current indentation depth.
3933 NODE is an optional argument that is used to represent the
3934 specific node to expand."
3936 (save-excursion (goto-char (point-min))
3937 (let ((case-fold-search t))
3938 (looking-at "Info Nodes:"))))
3939 ;; Update our "current node" maybe?
3941 ;; We cannot use the generic list code, that depends on all leaves
3942 ;; being known at creation time.
3944 (speedbar-with-writable (insert "Info Nodes:\n")))
3945 (let ((completions nil)
3946 (cf (selected-frame)))
3947 (select-frame speedbar-attached-frame)
3948 (save-window-excursion
3950 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
3953 (speedbar-with-writable
3954 (dolist (completion completions)
3955 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
3958 'Info-speedbar-goto-node
3964 (defun Info-speedbar-goto-node (text node indent)
3965 "When user clicks on TEXT, go to an info NODE.
3966 The INDENT level is ignored."
3967 (select-frame speedbar-attached-frame)
3968 (let* ((buff (or (get-buffer "*info*")
3969 (progn (info) (get-buffer "*info*"))))
3970 (bwin (get-buffer-window buff 0)))
3973 (select-window bwin)
3974 (raise-frame (window-frame bwin)))
3975 (if speedbar-power-click
3976 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
3977 (select-frame speedbar-attached-frame)
3978 (switch-to-buffer buff)))
3979 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
3980 (error "Invalid node %s" node)
3981 (Info-find-node (match-string 1 node) (match-string 2 node))
3982 ;; If we do a find-node, and we were in info mode, restore
3983 ;; the old default method. Once we are in info mode, it makes
3984 ;; sense to return to whatever method the user was using before.
3985 (if (string= speedbar-initial-expansion-list-name "Info")
3986 (speedbar-change-initial-expansion-list
3987 speedbar-previously-used-expansion-list-name)))))
3989 (defun Info-speedbar-expand-node (text token indent)
3990 "Expand the node the user clicked on.
3991 TEXT is the text of the button we clicked on, a + or - item.
3992 TOKEN is data related to this node (NAME . FILE).
3993 INDENT is the current indentation depth."
3994 (cond ((string-match "+" text) ;we have to expand this file
3995 (speedbar-change-expand-button-char ?-)
3996 (if (speedbar-with-writable
3998 (end-of-line) (forward-char 1)
3999 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4000 (speedbar-change-expand-button-char ?-)
4001 (speedbar-change-expand-button-char ??)))
4002 ((string-match "-" text) ;we have to contract this node
4003 (speedbar-change-expand-button-char ?+)
4004 (speedbar-delete-subblock indent))
4005 (t (error "Ooops... not sure what to do")))
4006 (speedbar-center-buffer-smartly))
4008 (defun Info-speedbar-fetch-file-nodes (nodespec)
4009 "Fetch the subnodes from the info NODESPEC.
4010 NODESPEC is a string of the form: (file)node.
4011 Optional THISFILE represends the filename of"
4013 ;; Set up a buffer we can use to fake-out Info.
4014 (set-buffer (get-buffer-create "*info-browse-tmp*"))
4015 (if (not (equal major-mode 'Info-mode))
4017 ;; Get the node into this buffer
4018 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4019 (error "Invalid node specification %s" nodespec)
4020 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4021 ;; Scan the created buffer
4022 (goto-char (point-min))
4023 (let ((completions nil)
4024 (case-fold-search t)
4025 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4026 (match-string 1 nodespec))))
4027 ;; Always skip the first one...
4028 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4029 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4030 (let ((name (match-string 1)))
4032 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4034 (if (looking-at " *\\(([^)]+)\\)\\.")
4035 (concat (match-string 1) "Top")
4036 (concat "(" thisfile ")"
4037 (if (looking-at " \\([^.]+\\).")
4041 (nreverse completions))))
4043 ;;; Info mode node listing
4044 ;; FIXME: Seems not to be used. -stef
4045 (defun Info-speedbar-buttons (buffer)
4046 "Create a speedbar display to help navigation in an Info file.
4047 BUFFER is the buffer speedbar is requesting buttons for."
4048 (if (save-excursion (goto-char (point-min))
4049 (let ((case-fold-search t))
4050 (not (looking-at "Info Nodes:"))))
4052 (Info-speedbar-hierarchy-buttons nil 0)
4055 (dolist (mess '("^Node has no Previous$"
4056 "^No menu in this node$"
4057 "^Node has no Next$"
4058 "^No cross-references in this node^"
4060 "^No \".*\" in index$"))
4061 (add-to-list 'debug-ignored-errors mess))
4063 ;;;; Desktop support
4065 (defun Info-desktop-buffer-misc-data (desktop-dirname)
4066 "Auxiliary information to be saved in desktop file."
4067 (if (not (member Info-current-file '("apropos" "history" "toc")))
4068 (list Info-current-file Info-current-node)))
4071 (defun Info-restore-desktop-buffer (desktop-buffer-file-name
4073 desktop-buffer-misc)
4074 "Restore an info buffer specified in a desktop file."
4075 (let ((first (nth 0 desktop-buffer-misc))
4076 (second (nth 1 desktop-buffer-misc)))
4077 (when (and first second)
4078 (when desktop-buffer-name
4079 (set-buffer (get-buffer-create desktop-buffer-name))
4081 (Info-find-node first second)
4086 ;;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
4087 ;;; info.el ends here