1 ;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 ;; Free Software Foundation, Inc.
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; Note that nowadays we expect Info files to be made using makeinfo.
28 ;; In particular we make these assumptions:
29 ;; - a menu item MAY contain colons but not colon-space ": "
30 ;; - a menu item ending with ": " (but not ":: ") is an index entry
31 ;; - a node name MAY NOT contain a colon
32 ;; This distinction is to support indexing of computer programming
33 ;; language terms that may contain ":" but not ": ".
37 (eval-when-compile (require 'jka-compr
) (require 'cl
))
45 (defvar Info-history nil
46 "Stack of Info nodes user has visited.
47 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
49 (defvar Info-history-forward nil
50 "Stack of Info nodes user has visited with `Info-history-back' command.
51 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
53 (defvar Info-history-list nil
54 "List of all Info nodes user has visited.
55 Each element of the list is a list (FILENAME NODENAME).")
57 (defcustom Info-enable-edit nil
58 "Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
59 This is convenient if you want to write Info files by hand.
60 However, we recommend that you not do this.
61 It is better to write a Texinfo file and generate the Info file from that,
62 because that gives you a printed manual as well."
66 (defvar Info-enable-active-nodes nil
67 "Non-nil allows Info to execute Lisp code associated with nodes.
68 The Lisp code is executed when the node is selected.")
69 (put 'Info-enable-active-nodes
'risky-local-variable t
)
72 '((((class color
) (background light
)) :foreground
"brown" :weight bold
:slant italic
)
73 (((class color
) (background dark
)) :foreground
"white" :weight bold
:slant italic
)
74 (t :weight bold
:slant italic
))
75 "Face for Info node names."
79 '((((type tty pc
) (class color
) (background light
))
80 :foreground
"green" :weight bold
)
81 (((type tty pc
) (class color
) (background dark
))
82 :foreground
"yellow" :weight bold
)
83 (t :height
1.2 :inherit info-title-2
))
84 "Face for info titles at level 1."
86 (define-obsolete-face-alias 'Info-title-1-face
'info-title-1
"22.1")
89 '((((type tty pc
) (class color
)) :foreground
"lightblue" :weight bold
)
90 (t :height
1.2 :inherit info-title-3
))
91 "Face for info titles at level 2."
93 (define-obsolete-face-alias 'Info-title-2-face
'info-title-2
"22.1")
96 '((((type tty pc
) (class color
)) :weight bold
)
97 (t :height
1.2 :inherit info-title-4
))
98 "Face for info titles at level 3."
100 (define-obsolete-face-alias 'Info-title-3-face
'info-title-3
"22.1")
102 (defface info-title-4
103 '((((type tty pc
) (class color
)) :weight bold
)
104 (t :weight bold
:inherit variable-pitch
))
105 "Face for info titles at level 4."
107 (define-obsolete-face-alias 'Info-title-4-face
'info-title-4
"22.1")
109 (defface info-menu-header
114 :inherit variable-pitch
116 "Face for headers in Info menus."
119 (defface info-menu-star
120 '((((class color
)) :foreground
"red1")
122 "Face for every third `*' in an Info menu."
124 (define-obsolete-face-alias 'info-menu-5
'info-menu-star
"22.1")
128 "Face for unvisited Info cross-references."
131 (defface info-xref-visited
132 '((t :inherit
(link-visited info-xref
)))
133 "Face for visited Info cross-references."
137 (defcustom Info-fontify-visited-nodes t
138 "Non-nil to fontify references to visited nodes in `info-xref-visited' face."
143 (defcustom Info-fontify-maximum-menu-size
100000
144 "Maximum size of menu to fontify if `font-lock-mode' is non-nil.
145 Set to nil to disable node fontification."
149 (defcustom Info-use-header-line t
150 "Non-nil means to put the beginning-of-node links in an Emacs header-line.
151 A header-line does not scroll with the rest of the buffer."
155 (defface info-header-xref
156 '((t :inherit info-xref
))
157 "Face for Info cross-references in a node header."
160 (defface info-header-node
161 '((t :inherit info-node
))
162 "Face for Info nodes in a node header."
165 (defvar Info-directory-list nil
166 "List of directories to search for Info documentation files.
167 If nil, meaning not yet initialized, Info uses the environment
168 variable INFOPATH to initialize it, or `Info-default-directory-list'
169 if there is no INFOPATH variable in the environment, or the
170 concatenation of the two if INFOPATH ends with a colon.
172 When `Info-directory-list' is initialized from the value of
173 `Info-default-directory-list', and Emacs is installed in one of the
174 standard directories, the directory of Info files that come with Emacs
175 is put last (so that local Info files override standard ones).
177 When `Info-directory-list' is initialized from the value of
178 `Info-default-directory-list', and Emacs is not installed in one
179 of the standard directories, the first element of the resulting
180 list is the directory where Emacs installs the Info files that
181 come with it. This is so that Emacs's own manual, which suits the
182 version of Emacs you are using, will always be found first. This
183 is useful when you install an experimental version of Emacs without
184 removing the standard installation.
186 If you want to override the order of directories in
187 `Info-default-directory-list', set INFOPATH in the environment.
189 If you run the Emacs executable from the `src' directory in the Emacs
190 source tree, and INFOPATH is not defined, the `info' directory in the
191 source tree is used as the first element of `Info-directory-list', in
192 place of the installation Info directory. This is useful when you run
193 a version of Emacs without installing it.")
195 (defcustom Info-additional-directory-list nil
196 "List of additional directories to search for Info documentation files.
197 These directories are searched after those in `Info-directory-list'."
198 :type
'(repeat directory
)
201 (defcustom Info-scroll-prefer-subnodes nil
202 "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
204 If this is non-nil, and you scroll far enough in a node that its menu
205 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
206 moves to a subnode indicated by the following menu item. This means
207 that you visit a subnode before getting to the end of the menu.
209 Setting this option to nil results in behavior similar to the stand-alone
210 Info reader program, which visits the first subnode from the menu only
211 when you hit the end of the current node."
216 (defcustom Info-hide-note-references t
217 "If non-nil, hide the tag and section reference in *note and * menu items.
218 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
219 If value is non-nil but not t or `hide', the reference section is still shown.
220 `nil' completely disables this feature. If this is non-nil, you might
221 want to set `Info-refill-paragraphs'."
223 :type
'(choice (const :tag
"No hiding" nil
)
224 (const :tag
"Replace tag and hide reference" t
)
225 (const :tag
"Hide tag and reference" hide
)
226 (other :tag
"Only replace tag" tag
))
229 (defcustom Info-refill-paragraphs nil
230 "If non-nil, attempt to refill paragraphs with hidden references.
231 This refilling may accidentally remove explicit line breaks in the Info
232 file, so be prepared for a few surprises if you enable this feature.
233 This only has an effect if `Info-hide-note-references' is non-nil."
238 (defcustom Info-breadcrumbs-depth
4
239 "Depth of breadcrumbs to display.
240 0 means do not display breadcrumbs."
243 (defcustom Info-search-whitespace-regexp
"\\s-+"
244 "If non-nil, regular expression to match a sequence of whitespace chars.
245 This applies to Info search for regular expressions.
246 You might want to use something like \"[ \\t\\r\\n]+\" instead.
247 In the Customization buffer, that is `[' followed by a space,
248 a tab, a carriage return (control-M), a newline, and `]+'."
252 (defcustom Info-isearch-search t
253 "If non-nil, isearch in Info searches through multiple nodes.
254 Before leaving the initial Info node, where isearch was started,
255 it fails once with the error message [initial node], and with
256 subsequent C-s/C-r continues through other nodes without failing
257 with this error message in other nodes. When isearch fails for
258 the rest of the manual, it wraps aroung the whole manual and
259 restarts the search from the top/final node depending on
262 Setting this option to nil restores the default isearch behavior
263 with wrapping around the current Info node."
268 (defvar Info-isearch-initial-node nil
)
269 (defvar Info-isearch-initial-history nil
)
270 (defvar Info-isearch-initial-history-list nil
)
272 (defcustom Info-mode-hook
273 ;; Try to obey obsolete Info-fontify settings.
274 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
275 '(turn-on-font-lock))
276 "Hooks run when `Info-mode' is called."
280 (defcustom Info-selection-hook nil
281 "Hooks run when `Info-select-node' is called."
285 (defvar Info-edit-mode-hook nil
286 "Hooks run when `Info-edit-mode' is called.")
288 (defvar Info-current-file nil
289 "Info file that Info is now looking at, or nil.
290 This is the name that was specified in Info, not the actual file name.
291 It doesn't contain directory names or file name extensions added by Info.")
293 (defvar Info-current-subfile nil
294 "Info subfile that is actually in the *info* buffer now.
295 It is nil if current Info file is not split into subfiles.")
297 (defvar Info-current-node nil
298 "Name of node that Info is now looking at, or nil.")
300 (defvar Info-tag-table-marker nil
301 "Marker pointing at beginning of current Info file's tag table.
302 Marker points nowhere if file has no tag table.")
304 (defvar Info-tag-table-buffer nil
305 "Buffer used for indirect tag tables.")
307 (defvar Info-current-file-completions nil
308 "Cached completion list for current Info file.")
310 (defvar Info-file-supports-index-cookies nil
311 "Non-nil if current Info file supports index cookies.")
313 (defvar Info-file-supports-index-cookies-list nil
314 "List of Info files with information about index cookies support.
315 Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
316 where SUPPORTS-INDEX-COOKIES can be either t or nil.")
318 (defvar Info-index-alternatives nil
319 "List of possible matches for last `Info-index' command.")
321 (defvar Info-point-loc nil
322 "Point location within a selected node.
323 If string, the point is moved to the proper occurrence of the
324 name of the followed cross reference within a selected node.
325 If number, the point is moved to the corresponding line.")
327 (defvar Info-standalone nil
328 "Non-nil if Emacs was started solely as an Info browser.")
330 (defvar Info-virtual-files nil
331 "List of definitions of virtual Info files.
332 Each element of the list has the format (FILENAME (OPERATION . HANDLER) ...)
333 where FILENAME is a regexp that matches a class of virtual Info file names.
334 It should be carefully chosen to not cause file name clashes with
335 existing file names. OPERATION is one of the following operation
336 symbols `find-file', `find-node', `toc-nodes' that define what HANDLER
337 function to call instead of calling the default corresponding function
340 (defvar Info-virtual-nodes nil
341 "List of definitions of virtual Info nodes.
342 Each element of the list has the format (NODENAME (OPERATION . HANDLER) ...)
343 where NODENAME is a regexp that matches a class of virtual Info node names.
344 It should be carefully chosen to not cause node name clashes with
345 existing node names. OPERATION is one of the following operation
346 symbols `find-node' that define what HANDLER
347 function to call instead of calling the default corresponding function
350 (defvar Info-current-node-virtual nil
351 "Non-nil if the current Info node is virtual.")
353 (defun Info-virtual-file-p (filename)
354 "Check if Info file FILENAME is virtual."
355 (Info-virtual-fun 'find-file filename nil
))
357 (defun Info-virtual-fun (op filename nodename
)
358 "Find a function that handles operations on virtual manuals.
359 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
360 FILENAME is a virtual Info file name, NODENAME is a virtual Info
361 node name. Return a function found either in `Info-virtual-files'
362 or `Info-virtual-nodes'."
363 (or (and (stringp filename
) ; some legacy code can still use a symbol
364 (cdr-safe (assoc op
(assoc-default filename
367 (and (stringp nodename
) ; some legacy code can still use a symbol
368 (cdr-safe (assoc op
(assoc-default nodename
372 (defun Info-virtual-call (virtual-fun &rest args
)
373 "Call a function that handles operations on virtual manuals."
374 (when (functionp virtual-fun
)
375 (or (apply virtual-fun args
) t
)))
378 (defvar Info-suffix-list
379 ;; The MS-DOS list should work both when long file names are
380 ;; supported (Windows 9X), and when only 8+3 file names are available.
381 (if (eq system-type
'ms-dos
)
382 '( (".gz" .
"gunzip")
384 (".bz2" .
("bzip2" "-dc"))
387 (".info.Z" .
"gunzip")
388 (".info.gz" .
"gunzip")
389 ("-info.Z" .
"gunzip")
390 ("-info.gz" .
"gunzip")
391 ("/index.gz".
"gunzip")
392 ("/index.z" .
"gunzip")
398 '( (".info.Z".
"uncompress")
399 (".info.Y".
"unyabba")
400 (".info.gz".
"gunzip")
401 (".info.z".
"gunzip")
402 (".info.bz2" .
("bzip2" "-dc"))
404 ("-info.Z".
"uncompress")
405 ("-info.Y".
"unyabba")
406 ("-info.gz".
"gunzip")
407 ("-info.bz2" .
("bzip2" "-dc"))
408 ("-info.z".
"gunzip")
410 ("/index.Z".
"uncompress")
411 ("/index.Y".
"unyabba")
412 ("/index.gz".
"gunzip")
413 ("/index.z".
"gunzip")
414 ("/index.bz2".
("bzip2" "-dc"))
420 (".bz2" .
("bzip2" "-dc"))
422 "List of file name suffixes and associated decoding commands.
423 Each entry should be (SUFFIX . STRING); the file is given to
424 the command as standard input.
426 STRING may be a list of strings. In that case, the first element is
427 the command name, and the rest are arguments to that command.
429 If STRING is nil, no decoding is done.
430 Because the SUFFIXes are tried in order, the empty string should
431 be last in the list.")
433 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
434 ;; First, on MS-DOS with no long file names support, delete some of
435 ;; the extension in FILENAME to make room.
436 (defun info-insert-file-contents-1 (filename suffix lfn
)
437 (if lfn
; long file names are supported
438 (concat filename suffix
)
439 (let* ((sans-exts (file-name-sans-extension filename
))
440 ;; How long is the extension in FILENAME (not counting the dot).
441 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
443 ;; SUFFIX starts with a dot. If FILENAME already has one,
444 ;; get rid of the one in SUFFIX (unless suffix is empty).
445 (or (and (<= ext-len
0)
446 (not (eq (aref filename
(1- (length filename
))) ?.
)))
447 (= (length suffix
) 0)
448 (setq suffix
(substring suffix
1)))
449 ;; How many chars of that extension should we keep?
450 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
451 ;; Get rid of the rest of the extension, and add SUFFIX.
452 (concat (substring filename
0 (- (length filename
)
453 (- ext-len ext-left
)))
456 (defun info-file-exists-p (filename)
457 (and (file-exists-p filename
)
458 (not (file-directory-p filename
))))
460 (defun info-insert-file-contents (filename &optional visit
)
461 "Insert the contents of an Info file in the current buffer.
462 Do the right thing if the file has been compressed or zipped."
463 (let* ((tail Info-suffix-list
)
464 (lfn (if (fboundp 'msdos-long-file-names
)
465 (msdos-long-file-names)
467 (check-short (and (fboundp 'msdos-long-file-names
)
469 fullname decoder done
)
470 (if (info-file-exists-p filename
)
471 ;; FILENAME exists--see if that name contains a suffix.
472 ;; If so, set DECODE accordingly.
476 (concat (regexp-quote (car (car tail
))) "$")
478 (setq tail
(cdr tail
)))
479 (setq fullname filename
480 decoder
(cdr (car tail
))))
481 ;; Try adding suffixes to FILENAME and see if we can find something.
482 (while (and tail
(not done
))
483 (setq fullname
(info-insert-file-contents-1 filename
484 (car (car tail
)) lfn
))
485 (if (info-file-exists-p fullname
)
487 ;; If we found a file with a suffix, set DECODER
488 ;; according to the suffix.
489 decoder
(cdr (car tail
)))
490 ;; When the MS-DOS port runs on Windows, we need to check
491 ;; the short variant of a long file name as well.
493 (setq fullname
(info-insert-file-contents-1 filename
494 (car (car tail
)) nil
))
495 (if (info-file-exists-p fullname
)
497 decoder
(cdr (car tail
))))))
498 (setq tail
(cdr tail
)))
500 (error "Can't find %s or any compressed version of it" filename
)))
501 ;; check for conflict with jka-compr
502 (if (and (jka-compr-installed-p)
503 (jka-compr-get-compression-info fullname
))
507 (insert-file-contents-literally fullname visit
)
508 (let ((inhibit-read-only t
)
509 (coding-system-for-write 'no-conversion
)
510 (inhibit-null-byte-detection t
) ; Index nodes include null bytes
511 (default-directory (or (file-name-directory fullname
)
514 (setq decoder
(list decoder
)))
515 (apply 'call-process-region
(point-min) (point-max)
516 (car decoder
) t t nil
(cdr decoder
))))
517 (let ((inhibit-null-byte-detection t
)) ; Index nodes include null bytes
518 (insert-file-contents fullname visit
)))))
520 (defun Info-file-supports-index-cookies (&optional file
)
521 "Return non-nil value if FILE supports Info index cookies.
522 Info index cookies were first introduced in 4.7, and all later
523 makeinfo versions output them in index nodes, so we can rely
524 solely on the makeinfo version. This function caches the information
525 in `Info-file-supports-index-cookies-list'."
526 (or file
(setq file Info-current-file
))
527 (or (assoc file Info-file-supports-index-cookies-list
)
528 ;; Skip virtual Info files
529 (and (or (not (stringp file
))
530 (Info-virtual-file-p file
))
531 (setq Info-file-supports-index-cookies-list
532 (cons (cons file nil
) Info-file-supports-index-cookies-list
)))
535 (goto-char (point-min))
537 (if (and (re-search-forward
538 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
539 (line-beginning-position 3) t
)
540 (not (version< (match-string 1) "4.7")))
543 (setq Info-file-supports-index-cookies-list
544 (cons (cons file found
) Info-file-supports-index-cookies-list
)))))
545 (cdr (assoc file Info-file-supports-index-cookies-list
)))
548 (defun Info-default-dirs ()
549 (let ((source (expand-file-name "info/" source-directory
))
550 (sibling (if installation-directory
551 (expand-file-name "info/" installation-directory
)
552 (if invocation-directory
553 (let ((infodir (expand-file-name
555 invocation-directory
)))
556 (if (file-exists-p infodir
)
558 (setq infodir
(expand-file-name
559 "../../../share/info/"
560 invocation-directory
))
561 (and (file-exists-p infodir
)
565 (if (and sibling
(file-exists-p sibling
))
566 ;; Uninstalled, Emacs builddir != srcdir.
568 ;; Uninstalled, builddir == srcdir
570 (if (or (member alternative Info-default-directory-list
)
571 ;; On DOS/NT, we use movable executables always,
572 ;; and we must always find the Info dir at run time.
573 (if (memq system-type
'(ms-dos windows-nt
))
575 ;; Use invocation-directory for Info
576 ;; only if we used it for exec-directory also.
577 (not (string= exec-directory
578 (expand-file-name "lib-src/"
579 installation-directory
))))
580 (not (file-exists-p alternative
)))
581 Info-default-directory-list
582 ;; `alternative' contains the Info files that came with this
583 ;; version, so we should look there first. `Info-insert-dir'
584 ;; currently expects to find `alternative' first on the list.
586 ;; Don't drop the last part, it might contain non-Emacs stuff.
587 ;; (reverse (cdr (reverse
588 Info-default-directory-list
)))) ;; )))
590 (defun info-initialize ()
591 "Initialize `Info-directory-list', if that hasn't been done yet."
592 (unless Info-directory-list
593 (let ((path (getenv "INFOPATH")))
594 (setq Info-directory-list
595 (prune-directory-list
597 (if (string-match ":\\'" path
)
598 (append (split-string (substring path
0 -
1)
599 (regexp-quote path-separator
))
601 (split-string path
(regexp-quote path-separator
)))
602 (Info-default-dirs)))))))
605 (defun info-other-window (&optional file-or-node
)
606 "Like `info' but show the Info buffer in another window."
607 (interactive (if current-prefix-arg
608 (list (read-file-name "Info file name: " nil nil t
))))
609 (let (same-window-buffer-names same-window-regexps
)
610 (info file-or-node
)))
612 ;;;###autoload (add-hook 'same-window-regexps (purecopy "\\*info\\*\\(\\|<[0-9]+>\\)"))
614 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
616 (defun info (&optional file-or-node buffer
)
617 "Enter Info, the documentation browser.
618 Optional argument FILE-OR-NODE specifies the file to examine;
619 the default is the top-level directory of Info.
620 Called from a program, FILE-OR-NODE may specify an Info node of the form
621 `(FILENAME)NODENAME'.
622 Optional argument BUFFER specifies the Info buffer name;
623 the default buffer name is *info*. If BUFFER exists,
624 just switch to BUFFER. Otherwise, create a new buffer
625 with the top-level Info directory.
627 In interactive use, a non-numeric prefix argument directs
628 this command to read a file name from the minibuffer.
629 A numeric prefix argument selects an Info buffer with the prefix number
630 appended to the Info buffer name.
632 The search path for Info files is in the variable `Info-directory-list'.
633 The top-level Info directory is made by combining all the files named `dir'
634 in all the directories in that path.
636 See a list of available Info commands in `Info-mode'."
638 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
639 (read-file-name "Info file name: " nil nil t
))
640 (if (numberp current-prefix-arg
)
641 (format "*info*<%s>" current-prefix-arg
))))
642 (pop-to-buffer (or buffer
"*info*"))
643 (if (and buffer
(not (eq major-mode
'Info-mode
)))
646 ;; If argument already contains parentheses, don't add another set
647 ;; since the argument will then be parsed improperly. This also
648 ;; has the added benefit of allowing node names to be included
649 ;; following the parenthesized filename.
651 (if (and (stringp file-or-node
) (string-match "(.*)" file-or-node
))
653 (concat "(" file-or-node
")")))
654 (if (and (zerop (buffer-size))
656 ;; If we just created the Info buffer, go to the directory.
660 (defun info-emacs-manual ()
661 "Display the Emacs manual in Info mode."
666 (defun info-standalone ()
667 "Run Emacs as a standalone Info reader.
668 Usage: emacs -f info-standalone [filename]
669 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
670 (setq Info-standalone t
)
671 (if (and command-line-args-left
672 (not (string-match "^-" (car command-line-args-left
))))
675 (info (car command-line-args-left
))
676 (setq command-line-args-left
(cdr command-line-args-left
)))
677 (error (send-string-to-terminal
678 (format "%s\n" (if (eq (car-safe err
) 'error
)
680 (save-buffers-kill-emacs)))
683 ;; See if the accessible portion of the buffer begins with a node
684 ;; delimiter, and the node header line which follows matches REGEXP.
685 ;; Typically, this test will be followed by a loop that examines the
686 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
687 ;; to have the overhead of this special test inside the loop.
689 ;; This function changes match-data, but supposedly the caller might
690 ;; want to use the results of re-search-backward.
692 ;; The return value is the value of point at the beginning of matching
693 ;; REGEXP, if the function succeeds, nil otherwise.
694 (defun Info-node-at-bob-matching (regexp)
695 (and (bobp) ; are we at beginning of buffer?
696 (looking-at "\^_") ; does it begin with node delimiter?
700 (forward-line 1) ; does the line after delimiter match REGEXP?
701 (re-search-backward regexp beg t
))))
703 (defun Info-find-file (filename &optional noerror
)
704 "Return expanded FILENAME, or t, if FILENAME is \"dir\".
705 Optional second argument NOERROR, if t, means if file is not found
706 just return nil (no error)."
707 ;; Convert filename to lower case if not found as specified.
711 (Info-virtual-fun 'find-file filename nil
)
714 (let (temp temp-downcase found
)
715 (setq filename
(substitute-in-file-name filename
))
716 (let ((dirs (if (string-match "^\\./" filename
)
717 ;; If specified name starts with `./'
718 ;; then just try current directory.
720 (if (file-name-absolute-p filename
)
721 ;; No point in searching for an
722 ;; absolute file name
724 (if Info-additional-directory-list
725 (append Info-directory-list
726 Info-additional-directory-list
)
727 Info-directory-list
)))))
728 ;; Search the directory list for file FILENAME.
729 (while (and dirs
(not found
))
730 (setq temp
(expand-file-name filename
(car dirs
)))
732 (expand-file-name (downcase filename
) (car dirs
)))
733 ;; Try several variants of specified name.
734 (let ((suffix-list Info-suffix-list
)
735 (lfn (if (fboundp 'msdos-long-file-names
)
736 (msdos-long-file-names)
738 (while (and suffix-list
(not found
))
739 (cond ((info-file-exists-p
740 (info-insert-file-contents-1
741 temp
(car (car suffix-list
)) lfn
))
744 (info-insert-file-contents-1
745 temp-downcase
(car (car suffix-list
)) lfn
))
746 (setq found temp-downcase
))
747 ((and (fboundp 'msdos-long-file-names
)
750 (info-insert-file-contents-1
751 temp
(car (car suffix-list
)) nil
)))
753 (setq suffix-list
(cdr suffix-list
))))
754 (setq dirs
(cdr dirs
))))
756 (setq filename found
)
759 (error "Info file %s does not exist" filename
)))
762 (defun Info-find-node (filename nodename
&optional no-going-back
)
763 "Go to an Info node specified as separate FILENAME and NODENAME.
764 NO-GOING-BACK is non-nil if recovering from an error in this function;
765 it says do not attempt further (recursive) error recovery."
767 (setq filename
(Info-find-file filename
))
768 ;; Go into Info buffer.
769 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
770 ;; Record the node we are leaving, if we were in one.
771 (and (not no-going-back
)
773 (push (list Info-current-file Info-current-node
(point))
775 (Info-find-node-2 filename nodename no-going-back
))
778 (defun Info-on-current-buffer (&optional nodename
)
779 "Use Info mode to browse the current Info buffer.
780 With a prefix arg, this queries for the node name to visit first;
781 otherwise, that defaults to `Top'."
783 (list (if current-prefix-arg
784 (completing-read "Node name: " (Info-build-node-completions)
786 (unless nodename
(setq nodename
"Top"))
789 (set (make-local-variable 'Info-current-file
)
791 ;; If called on a non-file buffer, make a fake file name.
792 (concat default-directory
(buffer-name))))
793 (Info-find-node-2 nil nodename
))
795 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
796 ;; but at least it keeps this routine (which is for makeinfo-buffer and
797 ;; Info-revert-buffer-function) out of the way of normal operations.
799 (defun Info-revert-find-node (filename nodename
)
800 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
801 When *info* is already displaying FILENAME and NODENAME, the window position
802 is preserved, if possible."
803 (pop-to-buffer "*info*")
804 (let ((old-filename Info-current-file
)
805 (old-nodename Info-current-node
)
806 (pcolumn (current-column))
807 (pline (count-lines (point-min) (line-beginning-position)))
808 (wline (count-lines (point-min) (window-start)))
809 (old-history Info-history
)
810 (new-history (and Info-current-file
811 (list Info-current-file Info-current-node
(point)))))
812 (kill-buffer (current-buffer))
813 (Info-find-node filename nodename
)
814 (setq Info-history old-history
)
815 (if (and (equal old-filename Info-current-file
)
816 (equal old-nodename Info-current-node
))
818 ;; note goto-line is no good, we want to measure from point-min
819 (goto-char (point-min))
821 (set-window-start (selected-window) (point))
822 (goto-char (point-min))
824 (move-to-column pcolumn
))
825 ;; only add to the history when coming from a different file+node
827 (setq Info-history
(cons new-history Info-history
))))))
829 (defun Info-revert-buffer-function (ignore-auto noconfirm
)
830 (when (or noconfirm
(y-or-n-p "Revert info buffer? "))
831 (Info-revert-find-node Info-current-file Info-current-node
)
832 (message "Reverted %s" Info-current-file
)))
834 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
835 "Find a node in a tag table.
836 MARKER specifies the buffer and position to start searching at.
837 REGEXP is a regular expression matching nodes or references. Its first
838 group should match `Node:' or `Ref:'.
839 CASE-FOLD t means search for a case-insensitive match.
840 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
841 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
842 where the match was found, and MODE is `major-mode' of the buffer in
843 which the match was found."
844 (let ((case-fold-search case-fold
))
845 (with-current-buffer (marker-buffer marker
)
850 (when (re-search-forward regexp nil t
)
851 (list (string-equal "Ref:" (match-string 1))
852 (+ (point-min) (read (current-buffer)))
855 (defun Info-find-in-tag-table (marker regexp
)
856 "Find a node in a tag table.
857 MARKER specifies the buffer and position to start searching at.
858 REGEXP is a regular expression matching nodes or references. Its first
859 group should match `Node:' or `Ref:'.
860 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
861 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
862 where the match was found, and MODE is `major-mode' of the buffer in
863 which the match was found.
864 This function tries to find a case-sensitive match first, then a
865 case-insensitive match is tried."
866 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
867 (when (null (car result
))
868 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
871 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
872 "Find a node or anchor in the current buffer.
873 REGEXP is a regular expression matching nodes or references. Its first
874 group should match `Node:' or `Ref:'.
875 CASE-FOLD t means search for a case-insensitive match.
876 Value is the position at which a match was found, or nil if not found."
877 (let ((case-fold-search case-fold
)
880 (when (Info-node-at-bob-matching regexp
)
881 (setq found
(point)))
882 (while (and (not found
)
883 (search-forward "\n\^_" nil t
))
887 (when (re-search-backward regexp beg t
)
889 (setq found
(point)))))
892 (defun Info-find-node-in-buffer (regexp)
893 "Find a node or anchor in the current buffer.
894 REGEXP is a regular expression matching nodes or references. Its first
895 group should match `Node:' or `Ref:'.
896 Value is the position at which a match was found, or nil if not found.
897 This function looks for a case-sensitive match first. If none is found,
898 a case-insensitive match is tried."
899 (or (Info-find-node-in-buffer-1 regexp nil
)
900 (Info-find-node-in-buffer-1 regexp t
)))
902 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
903 (buffer-disable-undo (current-buffer))
904 (or (eq major-mode
'Info-mode
)
907 (setq Info-current-node nil
)
909 (let ((case-fold-search t
)
910 (virtual-fun (Info-virtual-fun 'find-node
911 (or filename Info-current-file
)
915 ((functionp virtual-fun
)
916 (let ((filename (or filename Info-current-file
)))
917 (setq buffer-read-only nil
)
918 (setq Info-current-file filename
919 Info-current-subfile nil
920 Info-current-file-completions nil
921 buffer-file-name nil
)
923 (Info-virtual-call virtual-fun filename nodename no-going-back
)
924 (set-marker Info-tag-table-marker nil
)
925 (setq buffer-read-only t
)
926 (set-buffer-modified-p nil
)
927 (set (make-local-variable 'Info-current-node-virtual
) t
)))
929 ;; Reread a file when moving from a virtual node.
930 (not Info-current-node-virtual
)
932 (equal Info-current-file filename
))))
933 ;; Switch files if necessary
934 (let ((inhibit-read-only t
))
935 (when Info-current-node-virtual
936 ;; When moving from a virtual node.
937 (set (make-local-variable 'Info-current-node-virtual
) nil
)
939 (setq filename Info-current-file
)))
940 (setq Info-current-file nil
941 Info-current-subfile nil
942 Info-current-file-completions nil
943 buffer-file-name nil
)
945 (info-insert-file-contents filename nil
)
946 (setq default-directory
(file-name-directory filename
))
947 (set-buffer-modified-p nil
)
948 (set (make-local-variable 'Info-file-supports-index-cookies
)
949 (Info-file-supports-index-cookies filename
))
951 ;; See whether file has a tag table. Record the location if yes.
952 (goto-char (point-max))
954 ;; Use string-equal, not equal, to ignore text props.
955 (if (not (or (string-equal nodename
"*")
957 (search-forward "\^_\nEnd tag table\n" nil t
))))
959 ;; We have a tag table. Find its beginning.
960 ;; Is this an indirect file?
961 (search-backward "\nTag table:\n")
965 (looking-at "(Indirect)\n"))
966 ;; It is indirect. Copy it to another buffer
967 ;; and record that the tag table is in that buffer.
968 (let ((buf (current-buffer))
970 (or Info-tag-table-buffer
971 (generate-new-buffer " *info tag table*"))))
972 (setq Info-tag-table-buffer tagbuf
)
973 (with-current-buffer tagbuf
974 (buffer-disable-undo (current-buffer))
975 (setq case-fold-search t
)
977 (insert-buffer-substring buf
))
978 (set-marker Info-tag-table-marker
979 (match-end 0) tagbuf
))
980 (set-marker Info-tag-table-marker pos
)))
981 (set-marker Info-tag-table-marker nil
))
982 (setq Info-current-file filename
)
985 ;; Use string-equal, not equal, to ignore text props.
986 (if (string-equal nodename
"*")
987 (progn (setq Info-current-node nodename
)
988 (Info-set-mode-line))
991 ;; 1. Anchor found in tag table
992 ;; 2. Anchor *not* in tag table
994 ;; 3. Node found in tag table
995 ;; 4. Node *not* found in tag table, but found in file
996 ;; 5. Node *not* in tag table, and *not* in file
998 ;; *Or* the same, but in an indirect subfile.
1000 ;; Search file for a suitable node.
1001 (let ((guesspos (point-min))
1002 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1003 (if (stringp nodename
)
1004 (regexp-quote nodename
)
1006 "\\) *[,\t\n\177]")))
1010 ;; First, search a tag table, if any
1011 (when (marker-position Info-tag-table-marker
)
1012 (let* ((m Info-tag-table-marker
)
1013 (found (Info-find-in-tag-table m regexp
)))
1016 ;; FOUND is (ANCHOR POS MODE).
1017 (setq guesspos
(nth 1 found
))
1019 ;; If this is an indirect file, determine which
1020 ;; file really holds this node and read it in.
1021 (unless (eq (nth 2 found
) 'Info-mode
)
1022 ;; Note that the current buffer must be the
1023 ;; *info* buffer on entry to
1024 ;; Info-read-subfile. Thus the hackery above.
1025 (setq guesspos
(Info-read-subfile guesspos
)))
1029 (goto-char (setq anchorpos guesspos
))
1032 ;; Else we may have a node, which we search for:
1033 (goto-char (max (point-min)
1034 (- (byte-to-position guesspos
) 1000)))
1036 ;; Now search from our advised position (or from beg of
1037 ;; buffer) to find the actual node. First, check
1038 ;; whether the node is right where we are, in case the
1039 ;; buffer begins with a node.
1040 (let ((pos (Info-find-node-in-buffer regexp
)))
1045 (when (string-match "\\([^.]+\\)\\." nodename
)
1046 (let (Info-point-loc)
1048 filename
(match-string 1 nodename
) no-going-back
))
1052 ;; No such anchor in tag table or node in tag table or file
1053 (error "No such node or anchor: %s" nodename
))
1056 (goto-char (point-min))
1057 (forward-line 1) ; skip header line
1058 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1059 ;; (forward-line 1))
1062 (let ((new-history (list Info-current-file
1063 (substring-no-properties nodename
))))
1064 ;; Add anchors to the history too
1065 (setq Info-history-list
1067 (delete new-history Info-history-list
))))
1068 (goto-char anchorpos
))
1069 ((numberp Info-point-loc
)
1070 (forward-line (- Info-point-loc
2))
1071 (setq Info-point-loc nil
))
1072 ((stringp Info-point-loc
)
1073 (Info-find-index-name Info-point-loc
)
1074 (setq Info-point-loc nil
))))))
1075 ;; If we did not finish finding the specified node,
1076 ;; go back to the previous one.
1077 (or Info-current-node no-going-back
(null Info-history
)
1078 (let ((hist (car Info-history
)))
1079 (setq Info-history
(cdr Info-history
))
1080 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
1081 (goto-char (nth 2 hist
))))))
1083 ;; Cache the contents of the (virtual) dir file, once we have merged
1084 ;; it for the first time, so we can save time subsequently.
1085 (defvar Info-dir-contents nil
)
1087 ;; Cache for the directory we decided to use for the default-directory
1088 ;; of the merged dir text.
1089 (defvar Info-dir-contents-directory nil
)
1091 ;; Record the file attributes of all the files from which we
1092 ;; constructed Info-dir-contents.
1093 (defvar Info-dir-file-attributes nil
)
1095 (defvar Info-dir-file-name nil
)
1097 ;; Construct the Info directory node by merging the files named `dir'
1098 ;; from various directories. Set the *info* buffer's
1099 ;; default-directory to the first directory we actually get any text
1101 (defun Info-insert-dir ()
1102 (if (and Info-dir-contents Info-dir-file-attributes
1103 ;; Verify that none of the files we used has changed
1104 ;; since we used it.
1106 (mapcar (lambda (elt)
1107 (let ((curr (file-attributes
1109 (file-truename (car elt
)))))
1111 ;; Don't compare the access time.
1112 (if curr
(setcar (nthcdr 4 curr
) 0))
1113 (setcar (nthcdr 4 (cdr elt
)) 0)
1114 (equal (cdr elt
) curr
)))
1115 Info-dir-file-attributes
))))
1117 (insert Info-dir-contents
)
1118 (goto-char (point-min)))
1119 (let ((dirs (if Info-additional-directory-list
1120 (append Info-directory-list
1121 Info-additional-directory-list
)
1122 Info-directory-list
))
1123 (dir-file-attrs nil
)
1124 ;; Bind this in case the user sets it to nil.
1125 (case-fold-search t
)
1126 ;; This is set non-nil if we find a problem in some input files.
1128 buffers buffer others nodes dirs-done
)
1130 ;; Search the directory list for the directory file.
1132 (let ((truename (file-truename (expand-file-name (car dirs
)))))
1133 (or (member truename dirs-done
)
1134 (member (directory-file-name truename
) dirs-done
)
1135 ;; Try several variants of specified name.
1136 ;; Try upcasing, appending `.info', or both.
1140 (progn (setq file
(expand-file-name "dir" truename
))
1141 (file-attributes file
))
1142 (progn (setq file
(expand-file-name "DIR" truename
))
1143 (file-attributes file
))
1144 (progn (setq file
(expand-file-name "dir.info" truename
))
1145 (file-attributes file
))
1146 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
1147 (file-attributes file
)))))
1150 (cons (directory-file-name truename
)
1153 (with-current-buffer (generate-new-buffer " info dir")
1155 (message "Composing main Info directory..."))
1157 ;; Index nodes include null bytes. DIR
1158 ;; files should not have indices, but who
1160 (let ((inhibit-null-byte-detection t
))
1161 (insert-file-contents file
)
1162 (set (make-local-variable 'Info-dir-file-name
)
1164 (push (current-buffer) buffers
)
1165 (push (cons file attrs
) dir-file-attrs
))
1166 (error (kill-buffer (current-buffer))))))))
1168 (set (make-local-variable 'Info-dir-contents-directory
)
1169 (file-name-as-directory (car dirs
))))
1170 (setq dirs
(cdr dirs
))))
1173 (error "Can't find the Info directory node"))
1175 ;; Distinguish the dir file that comes with Emacs from all the
1176 ;; others. Yes, that is really what this is supposed to do.
1177 ;; The definition of `Info-directory-list' puts it first on that
1178 ;; list and so last in `buffers' at this point.
1179 (setq buffer
(car (last buffers
))
1180 others
(delq buffer buffers
))
1182 ;; Insert the entire original dir file as a start; note that we've
1183 ;; already saved its default directory to use as the default
1184 ;; directory for the whole concatenation.
1185 (save-excursion (insert-buffer-substring buffer
))
1187 ;; Look at each of the other buffers one by one.
1188 (dolist (other others
)
1189 (let (this-buffer-nodes)
1190 ;; In each, find all the menus.
1191 (with-current-buffer other
1192 (goto-char (point-min))
1193 ;; Find each menu, and add an elt to NODES for it.
1194 (while (re-search-forward "^\\* Menu:" nil t
)
1195 (while (and (zerop (forward-line 1)) (eolp)))
1198 (re-search-backward "^\^_")
1199 (search-forward "Node: ")
1200 (setq nodename
(Info-following-node-name))
1201 (search-forward "\n\^_" nil
'move
)
1204 (push (list nodename other beg end
) this-buffer-nodes
)))
1205 (if (assoc-string "top" this-buffer-nodes t
)
1206 (setq nodes
(nconc this-buffer-nodes nodes
))
1208 (message "No `top' node in %s" Info-dir-file-name
)))))
1209 ;; Add to the main menu a menu item for each other node.
1210 (re-search-forward "^\\* Menu:")
1212 (let ((menu-items '("top"))
1213 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1214 (dolist (node nodes
)
1215 (let ((nodename (car node
)))
1217 (or (member (downcase nodename
) menu-items
)
1218 (re-search-forward (concat "^\\* +"
1219 (regexp-quote nodename
)
1223 (insert "* " nodename
"::" "\n")
1224 (push nodename menu-items
)))))))
1225 ;; Now take each node of each of the other buffers
1226 ;; and merge it into the main buffer.
1227 (dolist (node nodes
)
1228 (let ((case-fold-search t
)
1229 (nodename (car node
)))
1230 (goto-char (point-min))
1231 ;; Find the like-named node in the main buffer.
1232 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1233 (regexp-quote nodename
)
1237 (search-forward "\n\^_" nil
'move
)
1240 ;; If none exists, add one.
1241 (goto-char (point-max))
1242 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1243 ;; Merge the text from the other buffer's menu
1244 ;; into the menu in the like-named node in the main buffer.
1245 (apply 'insert-buffer-substring
(cdr node
))))
1246 (Info-dir-remove-duplicates)
1247 ;; Kill all the buffers we just made, including the special one excised.
1248 (mapc 'kill-buffer
(cons buffer buffers
))
1249 (goto-char (point-min))
1251 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1252 (message "Composing main Info directory...done"))
1253 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
1254 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
1255 (setq default-directory Info-dir-contents-directory
))
1257 (defvar Info-streamline-headings
1258 '(("Emacs" .
"Emacs")
1259 ("Programming" .
"Programming")
1260 ("Libraries" .
"Libraries")
1261 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1262 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1264 (defun Info-dir-remove-duplicates ()
1266 (goto-char (point-min))
1267 ;; Remove duplicate headings in the same menu.
1268 (while (search-forward "\n* Menu:" nil t
)
1269 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1270 ;; Look for the next heading to unify.
1271 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1272 (let ((name (match-string 1))
1273 (start (match-beginning 0))
1275 ;; Check whether this heading should be streamlined.
1277 (dolist (x Info-streamline-headings
)
1278 (when (string-match (car x
) name
)
1280 (setq re
(car x
)))))
1281 (if re
(replace-match name t t nil
1))
1282 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1284 (or limit
(point-max))))
1285 ;; Look for other headings of the same category and merge them.
1287 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1288 (when (if re
(save-match-data (string-match re
(match-string 1)))
1289 (equal name
(match-string 1)))
1291 ;; Delete redundant heading.
1292 (delete-region (match-beginning 0) (point))
1293 ;; Push the entries onto `text'.
1295 (delete-and-extract-region
1297 (if (re-search-forward "^[^* \n\t]" nil t
)
1299 (or limit
(point-max))))
1302 ;; Insert the entries just found.
1303 (while (= (line-beginning-position 0) (1- (point)))
1305 (dolist (entry (nreverse entries
))
1307 (while (= (line-beginning-position 0) (1- (point)))
1308 (delete-region (1- (point)) (point))))
1310 ;; Now remove duplicate entries under the same heading.
1313 (narrow-to-region start
(point))
1314 (goto-char (point-min))
1315 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil
'move
)
1316 ;; Fold case straight away; `member-ignore-case' here wasteful.
1317 (let ((x (downcase (match-string 1))))
1321 (if (re-search-forward "^[^ \t]" nil
'move
)
1322 (goto-char (match-beginning 0))
1324 (push x seen
)))))))))))
1326 ;; Note that on entry to this function the current-buffer must be the
1327 ;; *info* buffer; not the info tags buffer.
1328 (defun Info-read-subfile (nodepos)
1329 ;; NODEPOS is either a position (in the Info file as a whole,
1330 ;; not relative to a subfile) or the name of a subfile.
1333 (if (numberp nodepos
)
1334 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1335 (goto-char (point-min))
1336 (or (looking-at "\^_")
1337 (search-forward "\n\^_"))
1340 (while (not (looking-at "\^_"))
1343 thisfilepos thisfilename
)
1344 (search-forward ": ")
1345 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1346 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1347 ;; read in version 19 stops at the end of number.
1348 ;; Advance to the next line.
1350 (if (> thisfilepos nodepos
)
1352 (setq lastfilename thisfilename
)
1353 (setq lastfilepos thisfilepos
))
1354 (forward-line 1)))))
1355 (setq lastfilename nodepos
)
1356 (setq lastfilepos
0))
1357 ;; Assume previous buffer is in Info-mode.
1358 ;; (set-buffer (get-buffer "*info*"))
1359 (or (equal Info-current-subfile lastfilename
)
1360 (let ((inhibit-read-only t
))
1361 (setq buffer-file-name nil
)
1364 (info-insert-file-contents lastfilename
)
1365 (set-buffer-modified-p nil
)
1366 (setq Info-current-subfile lastfilename
)))
1367 ;; Widen in case we are in the same subfile as before.
1369 (goto-char (point-min))
1370 (if (looking-at "\^_")
1372 (search-forward "\n\^_"))
1373 (if (numberp nodepos
)
1374 (+ (- nodepos lastfilepos
) (point)))))
1376 (defun Info-unescape-quotes (value)
1377 "Unescape double quotes and backslashes in VALUE."
1380 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1381 (setq unquote
(replace-match "" t t unquote
1))
1382 (setq start
(- (match-end 0) 1)))
1385 ;; As of Texinfo 4.6, makeinfo writes constructs like
1386 ;; \0\h[image param=value ...\h\0]
1387 ;; into the Info file for handling images.
1388 (defun Info-split-parameter-string (parameter-string)
1389 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING; a
1390 whitespace separated list of KEY=VALUE pairs. If VALUE contains
1391 whitespace or double quotes, it must be quoted in double quotes and
1392 any double quotes or backslashes must be escaped (\\\",\\\\)."
1395 (while (string-match
1396 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1397 parameter-string start
)
1398 (setq start
(match-end 0))
1399 (push (cons (match-string 1 parameter-string
)
1400 (or (match-string 2 parameter-string
)
1401 (Info-unescape-quotes
1402 (match-string 3 parameter-string
))))
1406 (defun Info-display-images-node ()
1407 "Display images in current node."
1409 (let ((inhibit-read-only t
)
1410 (case-fold-search t
))
1411 (goto-char (point-min))
1412 (while (re-search-forward
1413 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1415 (let* ((start (match-beginning 1))
1416 (parameter-alist (Info-split-parameter-string (match-string 2)))
1417 (src (cdr (assoc-string "src" parameter-alist
))))
1418 (if (display-images-p)
1419 (let* ((image-file (if src
(if (file-name-absolute-p src
) src
1420 (concat default-directory src
))
1422 (image (if (file-exists-p image-file
)
1423 (create-image image-file
)
1425 (if (not (get-text-property start
'display
))
1426 (add-text-properties
1427 start
(point) `(display ,image rear-nonsticky
(display)))))
1428 ;; text-only display, show alternative text if provided, or
1429 ;; otherwise a clue that there's meant to be a picture
1430 (delete-region start
(point))
1431 (insert (or (cdr (assoc-string "text" parameter-alist
))
1432 (cdr (assoc-string "alt" parameter-alist
))
1434 (concat "[image:" src
"]"))
1436 (set-buffer-modified-p nil
)))
1438 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1439 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1440 ;; including one optional trailing newline.
1441 (defun Info-hide-cookies-node ()
1442 "Hide unrecognized cookies in current node."
1444 (let ((inhibit-read-only t
)
1445 (case-fold-search t
))
1446 (goto-char (point-min))
1447 (while (re-search-forward
1448 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1450 (let* ((start (match-beginning 1)))
1451 (if (and (not (get-text-property start
'invisible
))
1452 (not (get-text-property start
'display
)))
1453 (put-text-property start
(point) 'invisible t
)))))
1454 (set-buffer-modified-p nil
)))
1456 (defun Info-select-node ()
1457 "Select the Info node that point is in."
1458 ;; Bind this in case the user sets it to nil.
1459 (let ((case-fold-search t
))
1461 ;; Find beginning of node.
1462 (if (search-backward "\n\^_" nil
'move
)
1464 (if (looking-at "\^_")
1466 (signal 'search-failed
(list "\n\^_"))))
1467 ;; Get nodename spelled as it is in the node.
1468 (re-search-forward "Node:[ \t]*")
1469 (setq Info-current-node
1470 (buffer-substring-no-properties (point)
1472 (skip-chars-forward "^,\t\n")
1474 (Info-set-mode-line)
1475 ;; Find the end of it, and narrow.
1477 (let (active-expression)
1478 ;; Narrow to the node contents
1479 (narrow-to-region (point)
1480 (if (re-search-forward "\n[\^_\f]" nil t
)
1483 (if (looking-at "[\n\^_\f]*execute: ")
1485 (goto-char (match-end 0))
1486 (setq active-expression
1487 (read (current-buffer))))))
1489 (if Info-enable-active-nodes
(eval active-expression
))
1490 ;; Add a new unique history item to full history list
1491 (let ((new-history (list Info-current-file Info-current-node
)))
1492 (setq Info-history-list
1493 (cons new-history
(delete new-history Info-history-list
)))
1494 (setq Info-history-forward nil
))
1495 (if (not (eq Info-fontify-maximum-menu-size nil
))
1496 (Info-fontify-node))
1497 (Info-display-images-node)
1498 (Info-hide-cookies-node)
1499 (run-hooks 'Info-selection-hook
)))))
1501 (defvar Info-mode-line-node-keymap
1502 (let ((map (make-sparse-keymap)))
1503 (define-key map
[mode-line mouse-1
] 'Info-mouse-scroll-up
)
1504 (define-key map
[mode-line mouse-3
] 'Info-mouse-scroll-down
)
1506 "Keymap to put on the Info node name in the mode line.")
1508 (defun Info-set-mode-line ()
1509 (setq mode-line-buffer-identification
1510 (nconc (propertized-buffer-identification "%b")
1514 (if (stringp Info-current-file
)
1515 (replace-regexp-in-string
1516 "%" "%%" (file-name-nondirectory Info-current-file
))
1517 (format "*%S*" Info-current-file
))
1519 (if Info-current-node
1520 (propertize (replace-regexp-in-string
1521 "%" "%%" Info-current-node
)
1522 'face
'mode-line-buffer-id
1524 "mouse-1: scroll forward, mouse-3: scroll back"
1525 'mouse-face
'mode-line-highlight
1526 'local-map Info-mode-line-node-keymap
)
1529 ;; Go to an Info node specified with a filename-and-nodename string
1530 ;; of the sort that is found in pointers in nodes.
1532 ;; Don't autoload this function: the correct entry point for other packages
1533 ;; to use is `info'. --Stef
1535 (defun Info-goto-node (nodename &optional fork
)
1536 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1537 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1538 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1540 Completion is available, but only for node names in the current Info file.
1541 If FORK is non-nil (interactively with a prefix arg), show the node in
1543 If FORK is a string, it is the name to use for the new buffer."
1544 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1548 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1550 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1552 (setq filename
(if (= (match-beginning 1) (match-end 1))
1554 (match-string 2 nodename
))
1555 nodename
(match-string 3 nodename
))
1556 (let ((trim (string-match "\\s +\\'" filename
)))
1557 (if trim
(setq filename
(substring filename
0 trim
))))
1558 (let ((trim (string-match "\\s +\\'" nodename
)))
1559 (if trim
(setq nodename
(substring nodename
0 trim
))))
1560 (if transient-mark-mode
(deactivate-mark))
1561 (Info-find-node (if (equal filename
"") nil filename
)
1562 (if (equal nodename
"") "Top" nodename
))))
1564 (defvar Info-read-node-completion-table
)
1566 (defun Info-read-node-name-2 (dirs suffixes string pred action
)
1567 "Virtual completion table for file names input in Info node names.
1568 PATH-AND-SUFFIXES is a pair of lists, (DIRECTORIES . SUFFIXES)."
1569 (setq suffixes
(remove "" suffixes
))
1570 (when (file-name-absolute-p string
)
1571 (setq dirs
(list (file-name-directory string
))))
1573 (suffix (concat (regexp-opt suffixes t
) "\\'"))
1574 (string-dir (file-name-directory string
)))
1577 (setq dir default-directory
))
1578 (if string-dir
(setq dir
(expand-file-name string-dir dir
)))
1579 (when (file-directory-p dir
)
1580 (dolist (file (file-name-all-completions
1581 (file-name-nondirectory string
) dir
))
1582 ;; If the file name has no suffix or a standard suffix,
1584 (and (or (null (file-name-extension file
))
1585 (string-match suffix file
))
1586 ;; But exclude subfiles of split Info files.
1587 (not (string-match "-[0-9]+\\'" file
))
1588 ;; And exclude backup files.
1589 (not (string-match "~\\'" file
))
1590 (push (if string-dir
(concat string-dir file
) file
) names
))
1591 ;; If the file name ends in a standard suffix,
1592 ;; add the unsuffixed name as a completion option.
1593 (when (string-match suffix file
)
1594 (setq file
(substring file
0 (match-beginning 0)))
1595 (push (if string-dir
(concat string-dir file
) file
) names
)))))
1596 (complete-with-action action names string pred
)))
1598 ;; This function is used as the "completion table" while reading a node name.
1599 ;; It does completion using the alist in Info-read-node-completion-table
1600 ;; unless STRING starts with an open-paren.
1601 (defun Info-read-node-name-1 (string predicate code
)
1603 ;; First complete embedded file names.
1604 ((string-match "\\`([^)]*\\'" string
)
1605 (completion-table-with-context
1607 (apply-partially 'completion-table-with-terminator
")"
1608 (apply-partially 'Info-read-node-name-2
1610 (mapcar 'car Info-suffix-list
)))
1611 (substring string
1)
1615 ;; If a file name was given, then any node is fair game.
1616 ((string-match "\\`(" string
)
1618 ((eq code nil
) string
)
1621 ;; Otherwise use Info-read-node-completion-table.
1622 (t (complete-with-action
1623 code Info-read-node-completion-table string predicate
))))
1625 ;; Arrange to highlight the proper letters in the completion list buffer.
1628 (defun Info-read-node-name (prompt)
1629 (let* ((completion-ignore-case t
)
1630 (Info-read-node-completion-table (Info-build-node-completions))
1631 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1632 (if (equal nodename
"")
1633 (Info-read-node-name prompt
)
1636 (defun Info-build-node-completions ()
1637 (or Info-current-file-completions
1639 ;; Bind this in case the user sets it to nil.
1640 (case-fold-search t
)
1641 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1644 (or Info-tag-table-marker
1645 (error "No Info tags found"))
1646 (if (marker-buffer Info-tag-table-marker
)
1647 (let ((marker Info-tag-table-marker
))
1648 (set-buffer (marker-buffer marker
))
1651 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1653 (cons (list (match-string-no-properties 2))
1656 (goto-char (point-min))
1657 ;; If the buffer begins with a node header, process that first.
1658 (if (Info-node-at-bob-matching node-regexp
)
1659 (setq compl
(list (match-string-no-properties 1))))
1660 ;; Now for the rest of the nodes.
1661 (while (search-forward "\n\^_" nil t
)
1663 (let ((beg (point)))
1665 (if (re-search-backward node-regexp beg t
)
1667 (cons (list (match-string-no-properties 1))
1669 (setq compl
(cons '("*") compl
))
1670 (set (make-local-variable 'Info-current-file-completions
) compl
))))
1672 (defun Info-restore-point (hl)
1673 "If this node has been visited, restore the point value when we left."
1675 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1676 ;; Use string-equal, not equal, to ignore text props.
1677 (string-equal (nth 1 (car hl
)) Info-current-node
))
1679 (goto-char (nth 2 (car hl
)))
1680 (setq hl nil
)) ;terminate the while at next iter
1681 (setq hl
(cdr hl
)))))
1683 (defvar Info-search-history nil
1684 "The history list for `Info-search'.")
1686 (defvar Info-search-case-fold nil
1687 "The value of `case-fold-search' from previous `Info-search' command.")
1689 (defun Info-search (regexp &optional bound noerror count direction
)
1690 "Search for REGEXP, starting from point, and select node it's found in.
1691 If DIRECTION is `backward', search in the reverse direction."
1692 (interactive (list (read-string
1693 (if Info-search-history
1694 (format "Regexp search%s (default %s): "
1695 (if case-fold-search
"" " case-sensitively")
1696 (car Info-search-history
))
1697 (format "Regexp search%s: "
1698 (if case-fold-search
"" " case-sensitively")))
1699 nil
'Info-search-history
)))
1701 (when (equal regexp
"")
1702 (setq regexp
(car Info-search-history
)))
1704 (let (found beg-found give-up
1705 (backward (eq direction
'backward
))
1706 (onode Info-current-node
)
1707 (ofile Info-current-file
)
1709 (opoint-min (point-min))
1710 (opoint-max (point-max))
1711 (ostart (window-start))
1712 (osubfile Info-current-subfile
))
1713 (setq Info-search-case-fold case-fold-search
)
1718 ;; Hide Info file header for backward search
1719 (narrow-to-region (save-excursion
1720 (goto-char (point-min))
1721 (search-forward "\n\^_")
1724 (while (and (not give-up
)
1726 (not (funcall isearch-filter-predicate beg-found found
))))
1727 (let ((search-spaces-regexp
1728 (if (or (not isearch-mode
) isearch-regexp
)
1729 Info-search-whitespace-regexp
)))
1731 (re-search-backward regexp bound t
)
1732 (re-search-forward regexp bound t
))
1733 (setq found
(point) beg-found
(if backward
(match-end 0)
1734 (match-beginning 0)))
1735 (setq give-up t
))))))
1737 (when (and isearch-mode Info-isearch-search
1738 (not Info-isearch-initial-node
)
1740 (or give-up
(and found
(not (and (> found opoint-min
)
1741 (< found opoint-max
))))))
1742 (signal 'search-failed
(list regexp
"initial node")))
1744 ;; If no subfiles, give error now.
1746 (if (null Info-current-subfile
)
1747 (let ((search-spaces-regexp
1748 (if (or (not isearch-mode
) isearch-regexp
)
1749 Info-search-whitespace-regexp
)))
1751 (re-search-backward regexp
)
1752 (re-search-forward regexp
)))
1755 (if (and bound
(not found
))
1756 (signal 'search-failed
(list regexp
)))
1758 (unless (or found bound
)
1760 ;; Try other subfiles.
1762 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1763 (goto-char (point-min))
1764 (search-forward "\n\^_\nIndirect:")
1766 (narrow-to-region (point)
1767 (progn (search-forward "\n\^_")
1769 (goto-char (point-min))
1770 ;; Find the subfile we just searched.
1771 (search-forward (concat "\n" osubfile
": "))
1773 (forward-line (if backward
0 1))
1774 (if backward
(forward-char -
1))
1775 ;; Make a list of all following subfiles.
1776 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1777 (while (not (if backward
(bobp) (eobp)))
1779 (re-search-backward "\\(^.*\\): [0-9]+$")
1780 (re-search-forward "\\(^.*\\): [0-9]+$"))
1781 (goto-char (+ (match-end 1) 2))
1782 (setq list
(cons (cons (+ (point-min)
1783 (read (current-buffer)))
1784 (match-string-no-properties 1))
1786 (goto-char (if backward
1787 (1- (match-beginning 0))
1788 (1+ (match-end 0)))))
1789 ;; Put in forward order
1790 (setq list
(nreverse list
))))
1792 (message "Searching subfile %s..." (cdr (car list
)))
1793 (Info-read-subfile (car (car list
)))
1795 ;; Hide Info file header for backward search
1796 (narrow-to-region (save-excursion
1797 (goto-char (point-min))
1798 (search-forward "\n\^_")
1801 (goto-char (point-max)))
1802 (setq list
(cdr list
))
1803 (setq give-up nil found nil
)
1804 (while (and (not give-up
)
1806 (not (funcall isearch-filter-predicate beg-found found
))))
1807 (let ((search-spaces-regexp
1808 (if (or (not isearch-mode
) isearch-regexp
)
1809 Info-search-whitespace-regexp
)))
1811 (re-search-backward regexp nil t
)
1812 (re-search-forward regexp nil t
))
1813 (setq found
(point) beg-found
(if backward
(match-end 0)
1814 (match-beginning 0)))
1822 (signal 'search-failed
(list regexp
))))
1824 (progn (Info-read-subfile osubfile
)
1827 (set-window-start (selected-window) ostart
)))))
1829 (if (and (string= osubfile Info-current-subfile
)
1830 (> found opoint-min
)
1831 (< found opoint-max
))
1832 ;; Search landed in the same node
1836 (save-match-data (Info-select-node)))
1838 ;; Use string-equal, not equal, to ignore text props.
1839 (or (and (string-equal onode Info-current-node
)
1840 (equal ofile Info-current-file
))
1841 (and isearch-mode isearch-wrapped
1842 (eq opoint
(if isearch-forward opoint-min opoint-max
)))
1843 (setq Info-history
(cons (list ofile onode opoint
)
1846 (defun Info-search-case-sensitively ()
1847 "Search for a regexp case-sensitively."
1849 (let ((case-fold-search nil
))
1850 (call-interactively 'Info-search
)))
1852 (defun Info-search-next ()
1853 "Search for next regexp from a previous `Info-search' command."
1855 (let ((case-fold-search Info-search-case-fold
))
1856 (if Info-search-history
1857 (Info-search (car Info-search-history
))
1858 (call-interactively 'Info-search
))))
1860 (defun Info-search-backward (regexp &optional bound noerror count
)
1861 "Search for REGEXP in the reverse direction."
1862 (interactive (list (read-string
1863 (if Info-search-history
1864 (format "Regexp search%s backward (default %s): "
1865 (if case-fold-search
"" " case-sensitively")
1866 (car Info-search-history
))
1867 (format "Regexp search%s backward: "
1868 (if case-fold-search
"" " case-sensitively")))
1869 nil
'Info-search-history
)))
1870 (Info-search regexp bound noerror count
'backward
))
1872 (defun Info-isearch-search ()
1873 (if Info-isearch-search
1874 (lambda (string &optional bound noerror count
)
1876 (Info-search (concat "\\b" (replace-regexp-in-string
1878 (replace-regexp-in-string
1879 "^\\W+\\|\\W+$" "" string
)
1881 ;; Lax version of word search
1882 (if (or isearch-nonincremental
1884 (length (isearch-string-state
1885 (car isearch-cmds
)))))
1888 (unless isearch-forward
'backward
))
1889 (Info-search (if isearch-regexp string
(regexp-quote string
))
1891 (unless isearch-forward
'backward
)))
1893 (let ((isearch-search-fun-function nil
))
1894 (isearch-search-fun))))
1896 (defun Info-isearch-wrap ()
1897 (if Info-isearch-search
1898 (if Info-isearch-initial-node
1900 (if isearch-forward
(Info-top-node) (Info-final-node))
1901 (goto-char (if isearch-forward
(point-min) (point-max))))
1902 (setq Info-isearch-initial-node Info-current-node
)
1903 (setq isearch-wrapped nil
))
1904 (goto-char (if isearch-forward
(point-min) (point-max)))))
1906 (defun Info-isearch-push-state ()
1908 (Info-isearch-pop-state cmd
',Info-current-file
',Info-current-node
)))
1910 (defun Info-isearch-pop-state (cmd file node
)
1911 (or (and (equal Info-current-file file
)
1912 (equal Info-current-node node
))
1913 (progn (Info-find-node file node
) (sit-for 0))))
1915 (defun Info-isearch-start ()
1916 (setq Info-isearch-initial-node
1917 ;; Don't stop at initial node for nonincremental search.
1918 ;; Otherwise this variable is set after first search failure.
1919 (and isearch-nonincremental Info-current-node
))
1920 (setq Info-isearch-initial-history Info-history
1921 Info-isearch-initial-history-list Info-history-list
)
1922 (add-hook 'isearch-mode-end-hook
'Info-isearch-end nil t
))
1924 (defun Info-isearch-end ()
1925 ;; Remove intermediate nodes (visited while searching)
1926 ;; from the history. Add only the last node (where Isearch ended).
1927 (if (> (length Info-history
)
1928 (length Info-isearch-initial-history
))
1930 (nthcdr (- (length Info-history
)
1931 (length Info-isearch-initial-history
)
1934 (if (> (length Info-history-list
)
1935 (length Info-isearch-initial-history-list
))
1936 (setq Info-history-list
1937 (cons (car Info-history-list
)
1938 Info-isearch-initial-history-list
)))
1939 (remove-hook 'isearch-mode-end-hook
'Info-isearch-end t
))
1941 (defun Info-isearch-filter (beg-found found
)
1942 "Test whether the current search hit is a visible useful text.
1943 Return non-nil if the text from BEG-FOUND to FOUND is visible
1944 and is not in the header line or a tag table."
1946 (let ((backward (< found beg-found
)))
1949 (and (not (eq search-invisible t
))
1951 (or (text-property-not-all found beg-found
'invisible nil
)
1952 (text-property-not-all found beg-found
'display nil
))
1953 (or (text-property-not-all beg-found found
'invisible nil
)
1954 (text-property-not-all beg-found found
'display nil
))))
1955 ;; Skip node header line
1956 (and (save-excursion (forward-line -
1)
1958 (forward-line (if backward -
1 1)))
1959 ;; Skip Tag Table node
1961 (and (search-backward "\^_" nil t
)
1963 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
1966 (defun Info-extract-pointer (name &optional errorname
)
1967 "Extract the value of the node-pointer named NAME.
1968 If there is none, use ERRORNAME in the error message;
1969 if ERRORNAME is nil, just return nil."
1970 ;; Bind this in case the user sets it to nil.
1971 (let ((case-fold-search t
))
1973 (goto-char (point-min))
1974 (let ((bound (point)))
1976 (cond ((re-search-backward
1977 (concat name
":" (Info-following-node-name-re)) bound t
)
1978 (match-string-no-properties 1))
1979 ((not (eq errorname t
))
1980 (error "Node has no %s"
1981 (capitalize (or errorname name
)))))))))
1983 (defun Info-following-node-name-re (&optional allowedchars
)
1984 "Return a regexp matching a node name.
1985 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1986 saying which chars may appear in the node name.
1987 Submatch 1 is the complete node name.
1988 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1989 Submatch 3 is the local part of the node name.
1990 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1991 (concat "[ \t]*" ;Skip leading space.
1992 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
1993 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
1994 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
1995 "\\|\\)\\)")) ;Allow empty node names.
1997 ;;; For compatibility; other files have used this name.
1998 (defun Info-following-node-name ()
1999 (and (looking-at (Info-following-node-name-re))
2000 (match-string-no-properties 1)))
2003 "Go to the next node of this node."
2005 ;; In case another window is currently selected
2006 (save-window-excursion
2007 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
2008 (Info-goto-node (Info-extract-pointer "next"))))
2011 "Go to the previous node of this node."
2013 ;; In case another window is currently selected
2014 (save-window-excursion
2015 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
2016 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2018 (defun Info-up (&optional same-file
)
2019 "Go to the superior node of this node.
2020 If SAME-FILE is non-nil, do not move to a different Info file."
2022 ;; In case another window is currently selected
2023 (save-window-excursion
2024 (or (eq major-mode
'Info-mode
) (pop-to-buffer "*info*"))
2025 (let ((old-node Info-current-node
)
2026 (old-file Info-current-file
)
2027 (node (Info-extract-pointer "up")) p
)
2029 (string-match "^(" node
)
2030 (error "Up node is in another Info file"))
2031 (Info-goto-node node
)
2033 (goto-char (point-min))
2034 (if (and (stringp old-file
)
2035 (search-forward "\n* Menu:" nil t
)
2037 (if (string-equal old-node
"Top")
2038 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
2039 (concat "\n\\* +\\(" (regexp-quote old-node
)
2040 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
2042 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2044 (Info-restore-point Info-history
)))))
2046 (defun Info-history-back ()
2047 "Go back in the history to the last node visited."
2050 (error "This is the first Info node you looked at"))
2051 (let ((history-forward
2052 (cons (list Info-current-file Info-current-node
(point))
2053 Info-history-forward
))
2054 filename nodename opoint
)
2055 (setq filename
(car (car Info-history
)))
2056 (setq nodename
(car (cdr (car Info-history
))))
2057 (setq opoint
(car (cdr (cdr (car Info-history
)))))
2058 (setq Info-history
(cdr Info-history
))
2059 (Info-find-node filename nodename
)
2060 (setq Info-history
(cdr Info-history
))
2061 (setq Info-history-forward history-forward
)
2062 (goto-char opoint
)))
2064 (defalias 'Info-last
'Info-history-back
)
2066 (defun Info-history-forward ()
2067 "Go forward in the history of visited nodes."
2069 (or Info-history-forward
2070 (error "This is the last Info node you looked at"))
2071 (let ((history-forward (cdr Info-history-forward
))
2072 filename nodename opoint
)
2073 (setq filename
(car (car Info-history-forward
)))
2074 (setq nodename
(car (cdr (car Info-history-forward
))))
2075 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
2076 (Info-find-node filename nodename
)
2077 (setq Info-history-forward history-forward
)
2078 (goto-char opoint
)))
2080 (add-to-list 'Info-virtual-files
2082 (toc-nodes . Info-directory-toc-nodes
)
2083 (find-file . Info-directory-find-file
)
2084 (find-node . Info-directory-find-node
)
2087 (defun Info-directory-toc-nodes (filename)
2088 "Directory-specific implementation of Info-directory-toc-nodes."
2090 ("Top" nil nil nil
)))
2092 (defun Info-directory-find-file (filename &optional noerror
)
2093 "Directory-specific implementation of Info-find-file."
2096 (defun Info-directory-find-node (filename nodename
&optional no-going-back
)
2097 "Directory-specific implementation of Info-find-node-2."
2101 (defun Info-directory ()
2102 "Go to the Info directory node."
2104 (Info-find-node "dir" "top"))
2106 (add-to-list 'Info-virtual-files
2107 '("\\`\\*History\\*\\'"
2108 (toc-nodes . Info-history-toc-nodes
)
2109 (find-file . Info-history-find-file
)
2110 (find-node . Info-history-find-node
)
2113 (defun Info-history-toc-nodes (filename)
2114 "History-specific implementation of Info-history-toc-nodes."
2116 ("Top" nil nil nil
)))
2118 (defun Info-history-find-file (filename &optional noerror
)
2119 "History-specific implementation of Info-find-file."
2122 (defun Info-history-find-node (filename nodename
&optional no-going-back
)
2123 "History-specific implementation of Info-find-node-2."
2124 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2125 (or filename Info-current-file
) nodename
))
2126 (insert "Recently Visited Nodes\n")
2127 (insert "**********************\n\n")
2128 (insert "* Menu:\n\n")
2129 (let ((hl (delete '("*History*" "Top") Info-history-list
)))
2131 (let ((file (nth 0 (car hl
)))
2132 (node (nth 1 (car hl
))))
2134 (insert "* " node
": ("
2135 (propertize (or (file-name-directory file
) "") 'invisible t
)
2136 (file-name-nondirectory file
)
2138 (setq hl
(cdr hl
)))))
2140 (defun Info-history ()
2141 "Go to a node with a menu of visited nodes."
2143 (Info-find-node "*History*" "Top")
2144 (Info-next-reference)
2145 (Info-next-reference))
2147 (add-to-list 'Info-virtual-nodes
2149 (find-node . Info-toc-find-node
)
2152 (defun Info-toc-find-node (filename nodename
&optional no-going-back
)
2153 "Toc-specific implementation of Info-find-node-2."
2154 (let* ((curr-file (substring-no-properties (or filename Info-current-file
)))
2155 (curr-node (substring-no-properties (or nodename Info-current-node
)))
2156 (node-list (Info-toc-nodes curr-file
)))
2157 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2158 curr-file curr-node
))
2159 (insert "Table of Contents\n")
2160 (insert "*****************\n\n")
2161 (insert "*Note Top::\n")
2163 (nth 3 (assoc "Top" node-list
)) ; get Top nodes
2164 node-list
0 curr-file
)
2166 (let ((Info-hide-note-references 'hide
)
2167 (Info-fontify-visited-nodes nil
))
2168 (setq Info-current-file filename Info-current-node
"*TOC*")
2169 (goto-char (point-min))
2170 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
2177 "Go to a node with table of contents of the current Info file.
2178 Table of contents is created from the tree structure of menus."
2180 (Info-find-node Info-current-file
"*TOC*")
2181 (let ((prev-node (nth 1 (car Info-history
))) p
)
2182 (goto-char (point-min))
2183 (if (setq p
(search-forward (concat "*Note " prev-node
":") nil t
))
2184 (setq p
(- p
(length prev-node
) 2)))
2185 (goto-char (or p
(point-min)))))
2187 (defun Info-toc-insert (nodes node-list level curr-file
)
2188 "Insert table of contents with references to nodes."
2189 (let ((section "Top"))
2191 (let ((node (assoc (car nodes
) node-list
)))
2192 (unless (member (nth 2 node
) (list nil section
))
2193 (insert (setq section
(nth 2 node
)) "\n"))
2194 (insert (make-string level ?
\t))
2195 (insert "*Note " (car nodes
) ":: \n")
2196 (Info-toc-insert (nth 3 node
) node-list
(1+ level
) curr-file
)
2197 (setq nodes
(cdr nodes
))))))
2199 (defun Info-toc-build (file)
2200 "Build table of contents from menus of Info FILE and its subfiles."
2202 (let* ((file (and (stringp file
) (Info-find-file file
)))
2203 (default-directory (or (and (stringp file
)
2204 (file-name-directory file
))
2206 (main-file (and (stringp file
) file
))
2207 (sections '(("Top" "Top")))
2209 (while (or main-file subfiles
)
2210 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2212 (info-insert-file-contents (or main-file
(car subfiles
)))
2213 (goto-char (point-min))
2214 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
2215 (search-forward "Node: " nil
'move
))
2216 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2217 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
2219 (upnode (and (re-search-forward
2220 (concat "Up:" (Info-following-node-name-re))
2222 (match-string-no-properties 1)))
2225 (when (string-match "(" upnode
) (setq upnode nil
))
2226 (when (and (not (Info-index-node nodename file
))
2227 (re-search-forward "^\\* Menu:" bound t
))
2230 (setq bound
(or (and (equal nodename
"Top")
2233 "^[ \t-]*The Detailed Node Listing" nil t
)))
2235 (while (< (point) bound
)
2238 ((looking-at "^\\* +[^:]+:")
2241 (let ((menu-node-name (substring-no-properties
2242 (Info-extract-menu-node-name))))
2243 (setq menu-items
(cons menu-node-name menu-items
))
2244 (if (equal nodename
"Top")
2246 (cons (list menu-node-name section
) sections
)))))
2247 ;; Other non-empty strings in the Top node are section names
2248 ((and (equal nodename
"Top")
2249 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2250 (setq section
(match-string-no-properties 1))))
2252 (beginning-of-line)))
2253 (setq nodes
(cons (list nodename upnode
2254 (cadr (assoc nodename sections
))
2255 (nreverse menu-items
))
2260 (goto-char (point-min))
2261 (if (search-forward "\n\^_\nIndirect:" nil t
)
2262 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2263 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2264 (setq subfiles
(cons (match-string-no-properties 1)
2266 (setq subfiles
(nreverse subfiles
)
2268 (setq subfiles
(cdr subfiles
))))
2272 (defvar Info-toc-nodes nil
2273 "Alist of cached parent-children node information in visited Info files.
2274 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
2275 where PARENT is the parent node extracted from the Up pointer,
2276 SECTION is the section name in the Top node where this node is placed,
2277 CHILDREN is a list of child nodes extracted from the node menu.")
2279 (defun Info-toc-nodes (filename)
2280 "Return a node list of Info FILENAME with parent-children information.
2281 This information is cached in the variable `Info-toc-nodes' with the help
2282 of the function `Info-toc-build'."
2285 (Info-virtual-fun 'toc-nodes
(or filename Info-current-file
) nil
)
2288 (or filename
(setq filename Info-current-file
))
2289 (or (assoc filename Info-toc-nodes
)
2290 ;; Skip virtual Info files
2291 (and (or (not (stringp filename
))
2292 (Info-virtual-file-p filename
))
2293 (push (cons filename nil
) Info-toc-nodes
))
2294 ;; Scan the entire manual and cache the result in Info-toc-nodes
2295 (let ((nodes (Info-toc-build filename
)))
2296 (push (cons filename nodes
) Info-toc-nodes
)
2298 ;; If there is an error, still add nil to the cache
2299 (push (cons filename nil
) Info-toc-nodes
))
2300 (cdr (assoc filename Info-toc-nodes
)))))
2303 (defun Info-follow-reference (footnotename &optional fork
)
2304 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2305 FOOTNOTENAME may be an abbreviation of the reference name.
2306 If FORK is non-nil (interactively with a prefix arg), show the node in
2307 a new Info buffer. If FORK is a string, it is the name to use for the
2310 (let ((completion-ignore-case t
)
2311 (case-fold-search t
)
2312 completions default alt-default
(start-point (point)) str i bol eol
)
2314 ;; Store end and beginning of line.
2320 (goto-char (point-min))
2321 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
2322 (setq str
(match-string-no-properties 1))
2323 ;; See if this one should be the default.
2325 (<= (match-beginning 0) start-point
)
2326 (<= start-point
(point))
2328 ;; See if this one should be the alternate default.
2329 (and (null alt-default
)
2330 (and (<= bol
(match-beginning 0))
2332 (setq alt-default t
))
2334 (while (setq i
(string-match "[ \n\t]+" str i
))
2335 (setq str
(concat (substring str
0 i
) " "
2336 (substring str
(match-end 0))))
2338 ;; Record as a completion and perhaps as default.
2339 (if (eq default t
) (setq default str
))
2340 (if (eq alt-default t
) (setq alt-default str
))
2341 ;; Don't add this string if it's a duplicate.
2342 (or (assoc-string str completions t
)
2343 (push str completions
))))
2344 ;; If no good default was found, try an alternate.
2346 (setq default alt-default
))
2347 ;; If only one cross-reference found, then make it default.
2348 (if (eq (length completions
) 1)
2349 (setq default
(car completions
)))
2351 (let ((input (completing-read (if default
2353 "Follow reference named (default "
2355 "Follow reference named: ")
2356 completions nil t
)))
2357 (list (if (equal input
"")
2358 default input
) current-prefix-arg
))
2359 (error "No cross-references in this node"))))
2361 (unless footnotename
2362 (error "No reference was specified"))
2364 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
2365 (case-fold-search t
))
2366 (while (setq i
(string-match " " str i
))
2367 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
2370 ;; Move point to the beginning of reference if point is on reference
2371 (or (looking-at "\\*note[ \n\t]+")
2372 (and (looking-back "\\*note[ \n\t]+")
2373 (goto-char (match-beginning 0)))
2374 (if (and (save-excursion
2375 (goto-char (+ (point) 5)) ; skip a possible *note
2376 (re-search-backward "\\*note[ \n\t]+" nil t
)
2378 (<= (point) (match-end 0)))
2379 (goto-char (match-beginning 0))))
2380 ;; Go to the reference closest to point
2381 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2382 (+ (match-beginning 0) 5))))
2383 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2384 (+ (match-beginning 0) 5)))))
2385 (goto-char (cond ((and next-ref prev-ref
)
2386 (if (< (abs (- next-ref
(point)))
2387 (abs (- prev-ref
(point))))
2389 ((or next-ref prev-ref
))
2390 ((error "No cross-reference named %s" footnotename
))))
2391 (setq target
(Info-extract-menu-node-name t
))))
2392 (while (setq i
(string-match "[ \t\n]+" target i
))
2393 (setq target
(concat (substring target
0 i
) " "
2394 (substring target
(match-end 0))))
2396 (Info-goto-node target fork
)))
2398 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2399 ;; We allow newline because this is also used in Info-follow-reference,
2400 ;; where the xref name might be wrapped over two lines.
2401 "Regexp that matches a menu entry name upto but not including the colon.
2402 Because of ambiguities, this should be concatenated with something like
2403 `:' and `Info-following-node-name-re'.")
2405 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2406 (skip-chars-forward " \t\n")
2407 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2408 (Info-following-node-name-re
2410 (index-node "^,\t\n")
2411 (multi-line "^.,\t")
2415 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2418 (setq Info-point-loc
2419 (if (match-beginning 5)
2420 (string-to-number (match-string 5))
2421 (buffer-substring-no-properties
2422 (match-beginning 0) (1- (match-beginning 1)))))
2423 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2424 ;;; (setq Info-point-loc
2425 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2427 (replace-regexp-in-string
2429 (or (match-string-no-properties 2)
2430 ;; If the node name is the menu entry name (using `entry::').
2431 (buffer-substring-no-properties
2432 (match-beginning 0) (1- (match-beginning 1)))))))
2434 ;; No one calls this.
2435 ;;(defun Info-menu-item-sequence (list)
2437 ;; (Info-menu (car list))
2438 ;; (setq list (cdr list))))
2440 (defvar Info-complete-menu-buffer
)
2441 (defvar Info-complete-next-re nil
)
2442 (defvar Info-complete-nodes nil
)
2443 (defvar Info-complete-cache nil
)
2445 (defconst Info-node-spec-re
2446 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2447 "Regexp to match the text after a : until the terminating `.'.")
2449 (defun Info-complete-menu-item (string predicate action
)
2450 ;; This uses two dynamically bound variables:
2451 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2452 ;; is the menu of items we're trying to complete.
2453 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2454 ;; also look for menu items in subsequent nodes as long as those
2455 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2457 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2458 ;; also look for menu items in these nodes. This feature is currently
2459 ;; only used for completion in Info-index.
2461 ;; Note that `Info-complete-menu-buffer' could be current already,
2462 ;; so we want to save point.
2463 (with-current-buffer Info-complete-menu-buffer
2465 (let ((completion-ignore-case t
)
2466 (case-fold-search t
)
2467 (orignode Info-current-node
)
2469 (goto-char (point-min))
2470 (search-forward "\n* Menu:")
2472 ((eq (car-safe action
) 'boundaries
) nil
)
2473 ((eq action
'lambda
)
2475 (concat "\n\\* +" (regexp-quote string
) ":") nil t
))
2477 (let ((pattern (concat "\n\\* +\\("
2478 (regexp-quote string
)
2479 Info-menu-entry-name-re
"\\):"
2482 (complete-nodes Info-complete-nodes
))
2484 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2485 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2486 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2487 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2488 (let ((prev (nth 3 Info-complete-cache
)))
2489 (eq t
(compare-strings string
0 (length prev
)
2491 ;; We can reuse the previous list.
2492 (setq completions
(nth 4 Info-complete-cache
))
2493 ;; The cache can't be used.
2496 (while (re-search-forward pattern nil t
)
2497 (push (match-string-no-properties 1)
2499 ;; Check subsequent nodes if applicable.
2500 (or (and Info-complete-next-re
2501 (setq nextnode
(Info-extract-pointer "next" t
))
2502 (string-match Info-complete-next-re nextnode
))
2504 (setq complete-nodes
(cdr complete-nodes
)
2505 nextnode
(car complete-nodes
)))))
2506 (Info-goto-node nextnode
))
2507 ;; Go back to the start node (for the next completion).
2508 (unless (equal Info-current-node orignode
)
2509 (Info-goto-node orignode
))
2510 ;; Update the cache.
2511 (set (make-local-variable 'Info-complete-cache
)
2512 (list Info-current-file Info-current-node
2513 Info-complete-next-re string completions
2514 Info-complete-nodes
)))
2515 (complete-with-action action completions string predicate
))))))))
2518 (defun Info-menu (menu-item &optional fork
)
2519 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2520 The menu item should one of those listed in the current node's menu.
2521 Completion is allowed, and the default menu item is the one point is on.
2522 If FORK is non-nil (interactively with a prefix arg), show the node in
2523 a new Info buffer. If FORK is a string, it is the name to use for the
2526 (let (;; If point is within a menu item, use that item as the default
2530 (case-fold-search t
))
2532 (goto-char (point-min))
2533 (if (not (search-forward "\n* menu:" nil t
))
2534 (error "No menu in this node"))
2540 (if (re-search-backward (concat "\n\\* +\\("
2541 Info-menu-entry-name-re
2543 (setq default
(match-string-no-properties 1))))))
2546 (setq item
(let ((completion-ignore-case t
)
2547 (Info-complete-menu-buffer (current-buffer)))
2548 (completing-read (if default
2549 (format "Menu item (default %s): "
2552 'Info-complete-menu-item nil t
)))
2553 ;; we rely on the fact that completing-read accepts an input
2554 ;; of "" even when the require-match argument is true and ""
2555 ;; is not a valid possibility
2556 (if (string= item
"")
2561 (list item current-prefix-arg
))))
2562 ;; there is a problem here in that if several menu items have the same
2563 ;; name you can only go to the node of the first with this command.
2564 (Info-goto-node (Info-extract-menu-item menu-item
) (if fork menu-item
)))
2566 (defun Info-extract-menu-item (menu-item)
2567 (setq menu-item
(regexp-quote menu-item
))
2568 (let ((case-fold-search t
))
2570 (let ((case-fold-search t
))
2571 (goto-char (point-min))
2572 (or (search-forward "\n* menu:" nil t
)
2573 (error "No menu in this node"))
2574 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2575 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2576 (error "No such item in menu"))
2579 (Info-extract-menu-node-name nil
(Info-index-node))))))
2581 ;; If COUNT is nil, use the last item in the menu.
2582 (defun Info-extract-menu-counting (count &optional no-detail
)
2583 (let ((case-fold-search t
))
2585 (let ((case-fold-search t
)
2586 (bound (when (and no-detail
2588 "^[ \t-]*The Detailed Node Listing" nil t
))
2589 (match-beginning 0))))
2590 (goto-char (point-min))
2591 (or (search-forward "\n* menu:" bound t
)
2592 (error "No menu in this node"))
2594 (or (search-forward "\n* " bound t count
)
2595 (error "Too few items in menu"))
2596 (while (search-forward "\n* " bound t
)
2598 (Info-extract-menu-node-name nil
(Info-index-node))))))
2600 (defun Info-nth-menu-item ()
2601 "Go to the node of the Nth menu item.
2602 N is the digit argument used to invoke this command."
2605 (Info-extract-menu-counting
2606 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2608 (defun Info-top-node ()
2609 "Go to the Top node of this file."
2611 (Info-goto-node "Top"))
2613 (defun Info-final-node ()
2614 "Go to the final node in this file."
2616 (Info-goto-node "Top")
2617 (let ((Info-history nil
)
2618 (case-fold-search t
))
2619 ;; Go to the last node in the menu of Top. But don't delve into
2620 ;; detailed node listings.
2621 (Info-goto-node (Info-extract-menu-counting nil t
))
2622 ;; If the last node in the menu is not last in pointer structure,
2623 ;; move forward (but not down- or upward - see bug#1116) until we
2624 ;; can't go any farther.
2625 (while (Info-forward-node t t t
) nil
)
2626 ;; Then keep moving down to last subnode, unless we reach an index.
2627 (while (and (not (Info-index-node))
2628 (save-excursion (search-forward "\n* Menu:" nil t
)))
2629 (Info-goto-node (Info-extract-menu-counting nil
)))))
2631 (defun Info-forward-node (&optional not-down not-up no-error
)
2632 "Go forward one node, considering all nodes as forming one sequence."
2634 (goto-char (point-min))
2636 (let ((case-fold-search t
))
2637 ;; three possibilities, in order of priority:
2638 ;; 1. next node is in a menu in this node (but not in an index)
2639 ;; 2. next node is next at same level
2640 ;; 3. next node is up and next
2641 (cond ((and (not not-down
)
2642 (save-excursion (search-forward "\n* menu:" nil t
))
2643 (not (Info-index-node)))
2644 (Info-goto-node (Info-extract-menu-counting 1))
2646 ((save-excursion (search-backward "next:" nil t
))
2650 (save-excursion (search-backward "up:" nil t
))
2651 ;; Use string-equal, not equal, to ignore text props.
2652 (not (string-equal (downcase (Info-extract-pointer "up"))
2654 (let ((old-node Info-current-node
))
2656 (let (Info-history success
)
2658 (setq success
(Info-forward-node t nil no-error
))
2659 (or success
(Info-goto-node old-node
))))))
2661 (t (error "No pointer forward from this node")))))
2663 (defun Info-backward-node ()
2664 "Go backward one node, considering all nodes as forming one sequence."
2666 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2667 (upnode (Info-extract-pointer "up" t
))
2668 (case-fold-search t
))
2669 (cond ((and upnode
(string-match "(" upnode
))
2670 (error "First node in file"))
2671 ((and upnode
(or (null prevnode
)
2672 ;; Use string-equal, not equal,
2673 ;; to ignore text properties.
2674 (string-equal (downcase prevnode
)
2675 (downcase upnode
))))
2678 ;; If we move back at the same level,
2679 ;; go down to find the last subnode*.
2682 (while (and (not (Info-index-node))
2683 (save-excursion (search-forward "\n* Menu:" nil t
)))
2684 (Info-goto-node (Info-extract-menu-counting nil
)))))
2686 (error "No pointer backward from this node")))))
2689 "Exit Info by selecting some other buffer."
2692 (save-buffers-kill-emacs)
2695 (defun Info-next-menu-item ()
2696 "Go to the node of the next menu item."
2698 ;; Bind this in case the user sets it to nil.
2699 (let* ((case-fold-search t
)
2703 (search-forward "\n* menu:" nil t
)
2704 (and (search-forward "\n* " nil t
)
2705 (Info-extract-menu-node-name)))))
2706 (if node
(Info-goto-node node
)
2707 (error "No more items in menu"))))
2709 (defun Info-last-menu-item ()
2710 "Go to the node of the previous menu item."
2714 ;; Bind this in case the user sets it to nil.
2715 (let* ((case-fold-search t
)
2716 (beg (save-excursion
2717 (and (search-backward "\n* menu:" nil t
)
2719 (or (and beg
(search-backward "\n* " beg t
))
2720 (error "No previous items in menu")))
2721 (Info-goto-node (save-excursion
2722 (goto-char (match-end 0))
2723 (Info-extract-menu-node-name)))))
2725 (defmacro Info-no-error
(&rest body
)
2726 (list 'condition-case nil
(cons 'progn
(append body
'(t))) '(error nil
)))
2728 (defun Info-next-preorder ()
2729 "Go to the next subnode or the next node, or go up a level."
2731 (cond ((Info-no-error (Info-next-menu-item)))
2732 ((Info-no-error (Info-next)))
2733 ((Info-no-error (Info-up t
))
2734 ;; Since we have already gone thru all the items in this menu,
2735 ;; go up to the end of this node.
2736 (goto-char (point-max))
2737 ;; Since logically we are done with the node with that menu,
2738 ;; move on from it. But don't add intermediate nodes
2739 ;; to the history on recursive calls.
2741 (Info-next-preorder)))
2743 (error "No more nodes"))))
2745 (defun Info-last-preorder ()
2746 "Go to the last node, popping up a level if there is none."
2748 (cond ((Info-no-error
2749 (Info-last-menu-item)
2750 ;; If we go down a menu item, go to the end of the node
2751 ;; so we can scroll back through it.
2752 (goto-char (point-max)))
2753 ;; Keep going down, as long as there are nested menu nodes.
2754 (while (Info-no-error
2755 (Info-last-menu-item)
2756 ;; If we go down a menu item, go to the end of the node
2757 ;; so we can scroll back through it.
2758 (goto-char (point-max))))
2760 ((and (Info-no-error (Info-extract-pointer "prev"))
2761 (not (equal (Info-extract-pointer "up")
2762 (Info-extract-pointer "prev"))))
2763 (Info-no-error (Info-prev))
2764 (goto-char (point-max))
2765 (while (Info-no-error
2766 (Info-last-menu-item)
2767 ;; If we go down a menu item, go to the end of the node
2768 ;; so we can scroll back through it.
2769 (goto-char (point-max))))
2771 ((Info-no-error (Info-up t
))
2772 (goto-char (point-min))
2773 (let ((case-fold-search t
))
2774 (or (search-forward "\n* Menu:" nil t
)
2775 (goto-char (point-max)))))
2776 (t (error "No previous nodes"))))
2778 (defun Info-scroll-up ()
2779 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2780 Once you scroll far enough in a node that its menu appears on the screen
2781 but after point, the next scroll moves into its first subnode, unless
2782 `Info-scroll-prefer-subnodes' is nil.
2784 When you scroll past the end of a node, that goes to the next node if
2785 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2786 if this node has no successor, it moves to the parent node's successor,
2787 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2788 the menu of a node, it moves to subnode indicated by the following menu
2789 item. (That case won't normally result from this command, but can happen
2793 (if (or (< (window-start) (point-min))
2794 (> (window-start) (point-max)))
2795 (set-window-start (selected-window) (point)))
2796 (let* ((case-fold-search t
)
2797 (virtual-end (save-excursion
2798 (goto-char (point-min))
2799 (if (and Info-scroll-prefer-subnodes
2800 (search-forward "\n* Menu:" nil t
))
2803 (if (or (< virtual-end
(window-start))
2804 (pos-visible-in-window-p virtual-end
))
2806 (Info-scroll-prefer-subnodes (Info-next-preorder))
2807 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2808 (t (Info-next-preorder)))
2811 (defun Info-mouse-scroll-up (e)
2812 "Scroll one screenful forward in Info, using the mouse.
2813 See `Info-scroll-up'."
2815 (save-selected-window
2817 (select-window (posn-window (event-start e
))))
2820 (defun Info-scroll-down ()
2821 "Scroll one screenful back in Info, considering all nodes as one sequence.
2822 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2823 is non-nil, this goes to its last subnode. When you scroll past the
2824 beginning of a node, that goes to the previous node or back up to the
2827 (if (or (< (window-start) (point-min))
2828 (> (window-start) (point-max)))
2829 (set-window-start (selected-window) (point)))
2830 (let* ((case-fold-search t
)
2831 (current-point (point))
2833 (and Info-scroll-prefer-subnodes
2836 (setq current-point
(point))
2837 (goto-char (point-min))
2838 (search-forward "\n* Menu:"
2842 (pos-visible-in-window-p (point-min) nil t
))
2843 (Info-last-preorder)
2846 (defun Info-mouse-scroll-down (e)
2847 "Scroll one screenful backward in Info, using the mouse.
2848 See `Info-scroll-down'."
2850 (save-selected-window
2852 (select-window (posn-window (event-start e
))))
2853 (Info-scroll-down)))
2855 (defun Info-next-reference (&optional recur
)
2856 "Move cursor to the next cross-reference or menu item in the node."
2858 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2860 (case-fold-search t
))
2861 (or (eobp) (forward-char 1))
2862 (or (re-search-forward pat nil t
)
2864 (goto-char (point-min))
2865 (or (re-search-forward pat nil t
)
2868 (error "No cross references in this node")))))
2869 (goto-char (or (match-beginning 1) (match-beginning 0)))
2870 (if (looking-at "\\* Menu:")
2872 (error "No cross references in this node")
2873 (Info-next-reference t
))
2874 (if (looking-at "^\\* ")
2875 (forward-char 2)))))
2877 (defun Info-prev-reference (&optional recur
)
2878 "Move cursor to the previous cross-reference or menu item in the node."
2880 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2882 (case-fold-search t
))
2883 (or (re-search-backward pat nil t
)
2885 (goto-char (point-max))
2886 (or (re-search-backward pat nil t
)
2889 (error "No cross references in this node")))))
2890 (goto-char (or (match-beginning 1) (match-beginning 0)))
2891 (if (looking-at "\\* Menu:")
2893 (error "No cross references in this node")
2894 (Info-prev-reference t
))
2895 (if (looking-at "^\\* ")
2896 (forward-char 2)))))
2898 (defvar Info-index-nodes nil
2899 "Alist of cached index node names of visited Info files.
2900 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2902 (defun Info-index-nodes (&optional file
)
2903 "Return a list of names of all index nodes in Info FILE.
2904 If FILE is omitted, it defaults to the current Info file.
2905 First look in a list of cached index node names. Then scan Info
2906 file and its subfiles for nodes with the index cookie. Then try
2907 to find index nodes starting from the first node in the top level
2908 menu whose name contains the word \"Index\", plus any immediately
2909 following nodes whose names also contain the word \"Index\"."
2910 (or file
(setq file Info-current-file
))
2911 (or (assoc file Info-index-nodes
)
2912 ;; Skip virtual Info files
2913 (and (or (not (stringp file
))
2914 (Info-virtual-file-p file
))
2915 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2916 (if (Info-file-supports-index-cookies file
)
2917 ;; Find nodes with index cookie
2918 (let* ((default-directory (or (and (stringp file
)
2919 (file-name-directory
2920 (setq file
(Info-find-file file
))))
2922 Info-history Info-history-list Info-fontify-maximum-menu-size
2923 (main-file file
) subfiles nodes
)
2926 (while (or main-file subfiles
)
2928 (info-insert-file-contents (or main-file
(car subfiles
)))
2929 (goto-char (point-min))
2930 (while (search-forward "\0\b[index\0\b]" nil
'move
)
2932 (re-search-backward "^\^_")
2933 (search-forward "Node: ")
2934 (setq nodes
(cons (Info-following-node-name) nodes
))))
2937 (goto-char (point-min))
2938 (if (search-forward "\n\^_\nIndirect:" nil t
)
2939 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2940 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2941 (setq subfiles
(cons (match-string-no-properties 1)
2943 (setq subfiles
(nreverse subfiles
)
2945 (setq subfiles
(cdr subfiles
)))))
2948 (setq nodes
(nreverse nodes
)
2949 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2951 ;; Else find nodes with the word "Index" in the node name
2952 (let ((case-fold-search t
)
2953 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
2958 (Info-find-node file
"Top")
2959 (when (and (search-forward "\n* menu:" nil t
)
2960 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
2961 (goto-char (match-beginning 1))
2962 (setq nodes
(list (Info-extract-menu-node-name)))
2963 (Info-goto-node (car nodes
))
2964 (while (and (setq node
(Info-extract-pointer "next" t
))
2965 (string-match "\\<Index\\>" node
))
2967 (Info-goto-node node
))))
2970 (setq nodes
(nreverse nodes
)
2971 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
2973 ;; If file has no index nodes, still add it to the cache
2974 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
2975 (cdr (assoc file Info-index-nodes
)))
2977 (defun Info-index-node (&optional node file
)
2978 "Return non-nil value if NODE is an index node.
2979 If NODE is nil, check the current Info node.
2980 If FILE is nil, check the current Info file."
2981 (or file
(setq file Info-current-file
))
2982 (if (and (or (and node
(not (equal node Info-current-node
)))
2983 (assoc file Info-index-nodes
))
2984 (not Info-current-node-virtual
))
2985 (member (or node Info-current-node
) (Info-index-nodes file
))
2986 ;; Don't search all index nodes if request is only for the current node
2987 ;; and file is not in the cache of index nodes
2989 (if (Info-file-supports-index-cookies file
)
2991 (goto-char (+ (or (save-excursion
2992 (search-backward "\n\^_" nil t
))
2994 (search-forward "\0\b[index\0\b]"
2996 (search-forward "\n\^_" nil t
))
2998 (string-match "\\<Index\\>" (or node Info-current-node
""))))))
3000 (defun Info-goto-index ()
3001 "Go to the first index node."
3002 (let ((node (car (Info-index-nodes))))
3003 (or node
(error "No index"))
3004 (Info-goto-node node
)))
3007 (defun Info-index (topic)
3008 "Look up a string TOPIC in the index for this manual and go to that entry.
3009 If there are no exact matches to the specified topic, this chooses
3010 the first match which is a case-insensitive substring of a topic.
3011 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3012 Give an empty topic name to go to the Index node itself."
3015 (let ((completion-ignore-case t
)
3016 (Info-complete-menu-buffer (clone-buffer))
3017 (Info-complete-nodes (Info-index-nodes))
3018 (Info-history-list nil
))
3019 (if (equal Info-current-file
"dir")
3020 (error "The Info directory node has no index; use m to select a manual"))
3022 (with-current-buffer Info-complete-menu-buffer
3024 (completing-read "Index topic: " 'Info-complete-menu-item
))
3025 (kill-buffer Info-complete-menu-buffer
)))))
3026 (if (equal Info-current-file
"dir")
3027 (error "The Info directory node has no index; use m to select a manual"))
3028 ;; Strip leading colon in topic; index format does not allow them.
3029 (if (and (stringp topic
)
3030 (> (length topic
) 0)
3031 (= (aref topic
0) ?
:))
3032 (setq topic
(substring topic
1)))
3033 (let ((orignode Info-current-node
)
3034 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3035 (regexp-quote topic
)))
3036 node
(nodes (Info-index-nodes))
3037 (ohist-list Info-history-list
)
3038 (case-fold-search t
))
3040 (or (equal topic
"")
3043 ;; We bind Info-history to nil for internal node-switches so
3044 ;; that we don't put junk in the history. In the first
3045 ;; Info-goto-index call, above, we do update the history
3046 ;; because that is what the user's previous node choice into it.
3051 (goto-char (point-min))
3052 (while (re-search-forward pattern nil t
)
3053 (push (list (match-string-no-properties 1)
3054 (match-string-no-properties 2)
3056 (string-to-number (concat "0"
3059 (setq nodes
(cdr nodes
) node
(car nodes
)))
3060 (Info-goto-node node
))
3063 (Info-goto-node orignode
)
3064 (error "No `%s' in index" topic
)))
3065 ;; Here it is a feature that assoc is case-sensitive.
3066 (while (setq found
(assoc topic matches
))
3067 (setq exact
(cons found exact
)
3068 matches
(delq found matches
)))
3069 (setq Info-history-list ohist-list
)
3070 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
3071 (Info-index-next 0)))))
3073 (defun Info-index-next (num)
3074 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3076 (or Info-index-alternatives
3077 (error "No previous `i' command"))
3079 (setq num
(+ num
(length Info-index-alternatives
))))
3081 (setq Info-index-alternatives
3082 (nconc (cdr Info-index-alternatives
)
3083 (list (car Info-index-alternatives
)))
3085 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
3086 (if (> (nth 3 (car Info-index-alternatives
)) 0)
3087 ;; Forward 2 lines less because `Info-find-node-2' initially
3088 ;; puts point to the 2nd line.
3089 (forward-line (- (nth 3 (car Info-index-alternatives
)) 2))
3090 (forward-line 3) ; don't search in headers
3091 (let ((name (car (car Info-index-alternatives
))))
3092 (Info-find-index-name name
)))
3093 (message "Found `%s' in %s. %s"
3094 (car (car Info-index-alternatives
))
3095 (nth 2 (car Info-index-alternatives
))
3096 (if (cdr Info-index-alternatives
)
3097 (format "(%s total; use `%s' for next)"
3098 (length Info-index-alternatives
)
3099 (key-description (where-is-internal
3100 'Info-index-next overriding-local-map
3104 (defun Info-find-index-name (name)
3105 "Move point to the place within the current node where NAME is defined."
3106 (let ((case-fold-search t
))
3107 (if (or (re-search-forward (format
3108 "[a-zA-Z]+: %s\\( \\|$\\)"
3109 (regexp-quote name
)) nil t
)
3110 ;; Find a function definition with a return type.
3111 (re-search-forward (format
3112 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3113 (regexp-quote name
)) nil t
)
3114 (search-forward (format "`%s'" name
) nil t
)
3115 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
3117 (format "`%s'" (substring name
0 (match-beginning 1)))
3119 (search-forward name nil t
)
3120 ;; Try again without the " <1>" makeinfo can append
3121 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
3122 (Info-find-index-name (match-string 1 name
))))
3123 (progn (beginning-of-line) t
) ;; non-nil for recursive call
3124 (goto-char (point-min)))))
3126 (add-to-list 'Info-virtual-nodes
3127 '("\\`\\*Index.*\\*\\'"
3128 (find-node . Info-virtual-index-find-node
)
3132 (defvar Info-virtual-index-nodes nil
3133 "Alist of cached matched index search nodes.
3134 Each element is ((FILENAME . TOPIC) MATCHES) where
3135 FILENAME is the file name of the manual,
3136 TOPIC is the search string given as an argument to `Info-virtual-index',
3137 MATCHES is a list of index matches found by `Info-index'.")
3139 (defun Info-virtual-index-find-node (filename nodename
&optional no-going-back
)
3140 "Index-specific implementation of Info-find-node-2."
3141 ;; Generate Index-like menu of matches
3142 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename
)
3143 ;; Generate Index-like menu of matches
3144 (let* ((topic (match-string 1 nodename
))
3145 (matches (cdr (assoc (cons (or filename Info-current-file
) topic
)
3146 Info-virtual-index-nodes
))))
3147 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3148 (or filename Info-current-file
) nodename
))
3149 (insert "Info Virtual Index\n")
3150 (insert "******************\n\n")
3151 (insert "Index entries that match `" topic
"':\n\n")
3152 (insert "\0\b[index\0\b]\n")
3154 (insert "No matches found.\n")
3155 (insert "* Menu:\n\n")
3156 (dolist (entry matches
)
3157 (insert (format "* %-38s %s.%s\n"
3158 (format "%s [%s]:" (nth 0 entry
) (nth 2 entry
))
3161 (format " (line %s)" (nth 3 entry
))
3163 ;; Else, Generate a list of previous search results
3164 (let ((nodes (reverse Info-virtual-index-nodes
)))
3165 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3166 (or filename Info-current-file
) nodename
))
3167 (insert "Info Virtual Index\n")
3168 (insert "******************\n\n")
3169 (insert "This is a list of search results produced by\n"
3170 "`Info-virtual-index' for the current manual.\n\n")
3171 (insert "* Menu:\n\n")
3172 (dolist (nodeinfo nodes
)
3173 (when (equal (car (nth 0 nodeinfo
)) (or filename Info-current-file
))
3175 (format "* %-20s %s.\n"
3176 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo
)))
3177 (cdr (nth 0 nodeinfo
)))))))))
3179 (defun Info-virtual-index (topic)
3180 "Show a node with all lines in the index containing a string TOPIC.
3181 Like `Info-index' but displays a node with index search results.
3182 Give an empty topic name to go to the node with links to previous
3184 ;; `interactive' is a copy from `Info-index'
3187 (let ((completion-ignore-case t
)
3188 (Info-complete-menu-buffer (clone-buffer))
3189 (Info-complete-nodes (Info-index-nodes))
3190 (Info-history-list nil
))
3191 (if (equal Info-current-file
"dir")
3192 (error "The Info directory node has no index; use m to select a manual"))
3194 (with-current-buffer Info-complete-menu-buffer
3196 (completing-read "Index topic: " 'Info-complete-menu-item
))
3197 (kill-buffer Info-complete-menu-buffer
)))))
3198 (if (equal topic
"")
3199 (Info-find-node Info-current-file
"*Index*")
3200 (unless (assoc (cons Info-current-file topic
) Info-virtual-index-nodes
)
3201 (let ((orignode Info-current-node
)
3202 (ohist-list Info-history-list
)
3204 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3206 (push (cons (cons Info-current-file topic
) Info-index-alternatives
)
3207 Info-virtual-index-nodes
)
3208 ;; Clean up unneccessary side-effects of `Info-index'.
3209 (setq Info-history-list ohist-list
)
3210 (Info-goto-node orignode
)
3212 (Info-find-node Info-current-file
(format "*Index for `%s'*" topic
))))
3214 (add-to-list 'Info-virtual-files
3215 '("\\`\\*Apropos\\*\\'"
3216 (toc-nodes . Info-apropos-toc-nodes
)
3217 (find-file . Info-apropos-find-file
)
3218 (find-node . Info-apropos-find-node
)
3222 (defvar Info-apropos-file
"*Apropos*"
3223 "Info file name of the virtual manual for matches of `info-apropos'.")
3225 (defvar Info-apropos-nodes nil
3226 "Alist of cached apropos matched nodes.
3227 Each element is (NODENAME STRING MATCHES) where
3228 NODENAME is the name of the node that holds the search result,
3229 STRING is the search string given as an argument to `info-apropos',
3230 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3232 (defun Info-apropos-toc-nodes (filename)
3233 "Apropos-specific implementation of Info-apropos-toc-nodes."
3234 (let ((nodes (mapcar 'car
(reverse Info-apropos-nodes
))))
3236 ("Top" nil nil
,nodes
)
3237 ,@(mapcar (lambda (node) `(,node
"Top" nil nil
)) nodes
))))
3239 (defun Info-apropos-find-file (filename &optional noerror
)
3240 "Apropos-specific implementation of Info-find-file."
3243 (defun Info-apropos-find-node (filename nodename
&optional no-going-back
)
3244 "Apropos-specific implementation of Info-find-node-2."
3245 (if (equal nodename
"Top")
3246 ;; Generate Top menu
3247 (let ((nodes (reverse Info-apropos-nodes
)))
3248 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3249 Info-apropos-file nodename
))
3250 (insert "Apropos Index\n")
3251 (insert "*************\n\n")
3252 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3253 (insert "* Menu:\n\n")
3254 (dolist (nodeinfo nodes
)
3255 (insert (format "* %-20s %s.\n"
3256 (format "%s::" (nth 0 nodeinfo
))
3257 (nth 1 nodeinfo
)))))
3258 ;; Else, Generate Index-like menu of matches
3259 (let* ((nodeinfo (assoc nodename Info-apropos-nodes
))
3260 (matches (nth 2 nodeinfo
)))
3262 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3263 Info-apropos-file nodename
))
3264 (insert "Apropos Index\n")
3265 (insert "*************\n\n")
3266 (insert "Index entries that match `" (nth 1 nodeinfo
) "':\n\n")
3267 (insert "\0\b[index\0\b]\n")
3269 (insert "No matches found.\n")
3270 (insert "* Menu:\n\n")
3271 (dolist (entry matches
)
3272 (insert (format "* %-38s (%s)%s.%s\n"
3273 (format "%s [%s]:" (nth 1 entry
) (nth 0 entry
))
3277 (format " (line %s)" (nth 3 entry
))
3280 (defun Info-apropos-matches (string)
3281 "Collect STRING matches from all known Info files on your system.
3282 Return a list of matches where each element is in the format
3283 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3284 (interactive "sIndex apropos: ")
3285 (unless (string= string
"")
3286 (let ((pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3287 (regexp-quote string
)))
3288 (ohist Info-history
)
3289 (ohist-list Info-history-list
)
3290 (current-node Info-current-node
)
3291 (current-file Info-current-file
)
3292 manuals matches node nodes
)
3293 (let ((Info-fontify-maximum-menu-size nil
))
3295 ;; current-node and current-file are nil when they invoke info-apropos
3296 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3297 ;; case, we use (DIR)Top instead, to avoid signalling an error after
3298 ;; the search is complete.
3299 (when (null current-node
)
3300 (setq current-file Info-current-file
)
3301 (setq current-node Info-current-node
))
3302 (message "Searching indices...")
3303 (goto-char (point-min))
3304 (re-search-forward "\\* Menu: *\n" nil t
)
3305 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
3306 ;; add-to-list makes sure we don't have duplicates in `manuals',
3307 ;; so that the following dolist loop runs faster.
3308 (add-to-list 'manuals
(match-string 1)))
3309 (dolist (manual (nreverse manuals
))
3310 (message "Searching %s" manual
)
3312 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
3314 (Info-find-node manual
(car nodes
))
3317 (goto-char (point-min))
3318 (while (re-search-forward pattern nil t
)
3321 (match-string-no-properties 1)
3322 (match-string-no-properties 2)
3323 (match-string-no-properties 3))
3325 (setq nodes
(cdr nodes
) node
(car nodes
)))
3326 (Info-goto-node node
))))
3328 (message "%s" (if (eq (car-safe err
) 'error
)
3331 (Info-find-node current-file current-node
)
3332 (setq Info-history ohist
3333 Info-history-list ohist-list
)
3334 (message "Searching indices...done")
3335 (or (nreverse matches
) t
))))
3338 (defun info-apropos (string)
3339 "Grovel indices of all known Info files on your system for STRING.
3340 Build a menu of the possible matches."
3341 (interactive "sIndex apropos: ")
3342 (if (equal string
"")
3343 (Info-find-node Info-apropos-file
"Top")
3344 (let* ((nodes Info-apropos-nodes
) nodename
)
3345 (while (and nodes
(not (equal string
(nth 1 (car nodes
)))))
3346 (setq nodes
(cdr nodes
)))
3348 (Info-find-node Info-apropos-file
(car (car nodes
)))
3349 (setq nodename
(format "Index for `%s'" string
))
3350 (push (list nodename string
(Info-apropos-matches string
))
3352 (Info-find-node Info-apropos-file nodename
)))))
3354 (add-to-list 'Info-virtual-files
3355 '("\\`\\*Finder.*\\*\\'"
3356 (find-file . Info-finder-find-file
)
3357 (find-node . Info-finder-find-node
)
3360 (defvar Info-finder-file
"*Finder*"
3361 "Info file name of the virtual Info keyword finder manual.")
3363 (defun Info-finder-find-file (filename &optional noerror
)
3364 "Finder-specific implementation of Info-find-file."
3367 (defvar finder-known-keywords
)
3368 (defvar finder-package-info
)
3369 (declare-function find-library-name
"find-func" (library))
3370 (declare-function finder-unknown-keywords
"finder" ())
3371 (declare-function lm-commentary
"lisp-mnt" (&optional file
))
3373 (defun Info-finder-find-node (filename nodename
&optional no-going-back
)
3374 "Finder-specific implementation of Info-find-node-2."
3377 ((equal nodename
"Top")
3378 ;; Display Top menu with descriptions of the keywords
3379 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3380 Info-finder-file nodename
))
3381 (insert "Finder Keywords\n")
3382 (insert "***************\n\n")
3383 (insert "* Menu:\n\n")
3386 (let ((keyword (car assoc
)))
3387 (insert (format "* %-14s %s.\n"
3388 (concat (symbol-name keyword
) "::")
3390 (append '((all .
"All package info")
3391 (unknown .
"unknown keywords"))
3392 finder-known-keywords
)))
3393 ((equal nodename
"unknown")
3394 ;; Display unknown keywords
3395 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3396 Info-finder-file nodename
))
3397 (insert "Finder Unknown Keywords\n")
3398 (insert "***********************\n\n")
3399 (insert "* Menu:\n\n")
3402 (insert (format "* %-14s %s.\n"
3403 (concat (symbol-name (car assoc
)) "::")
3405 (finder-unknown-keywords)))
3406 ((equal nodename
"all")
3407 ;; Display all package info.
3408 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3409 Info-finder-file nodename
))
3410 (insert "Finder Package Info\n")
3411 (insert "*******************\n\n")
3412 (mapc (lambda (package)
3413 (insert (format "%s - %s\n"
3414 (format "*Note %s::" (nth 0 package
))
3416 (insert "Keywords: "
3417 (mapconcat (lambda (keyword)
3418 (format "*Note %s::" (symbol-name keyword
)))
3419 (nth 2 package
) ", ")
3421 finder-package-info
))
3422 ((string-match-p "\\.el\\'" nodename
)
3423 ;; Display commentary section
3424 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3425 Info-finder-file nodename
))
3426 (insert "Finder Commentary\n")
3427 (insert "*****************\n\n")
3429 "Commentary section of the package `" nodename
"':\n\n")
3430 (let ((str (lm-commentary (find-library-name nodename
))))
3432 (insert "Can't find any Commentary section\n\n")
3436 (goto-char (point-min))
3437 (delete-blank-lines)
3438 (goto-char (point-max))
3439 (delete-blank-lines)
3440 (goto-char (point-min))
3441 (while (re-search-forward "^;+ ?" nil t
)
3442 (replace-match "" nil nil
))
3443 (buffer-string))))))
3445 ;; Display packages that match the keyword
3446 ;; or the list of keywords separated by comma.
3447 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3448 Info-finder-file nodename
))
3449 (insert "Finder Packages\n")
3450 (insert "***************\n\n")
3452 "The following packages match the keyword `" nodename
"':\n\n")
3453 (insert "* Menu:\n\n")
3455 (mapcar 'intern
(if (string-match-p "," nodename
)
3456 (split-string nodename
",[ \t\n]*" t
)
3460 (unless (memq nil
(mapcar (lambda (k) (memq k
(nth 2 package
)))
3462 (insert (format "* %-16s %s.\n"
3463 (concat (nth 0 package
) "::")
3465 finder-package-info
)))))
3468 (defun info-finder (&optional keywords
)
3469 "Display descriptions of the keywords in the Finder virtual manual.
3470 In interactive use, a prefix argument directs this command to read
3471 a list of keywords separated by comma. After that, it displays a node
3472 with a list packages that contain all specified keywords."
3474 (when current-prefix-arg
3477 (completing-read-multiple
3478 "Keywords (separated by comma): "
3479 (mapcar 'symbol-name
(mapcar 'car
(append finder-known-keywords
3480 (finder-unknown-keywords))))
3484 (Info-find-node Info-finder-file
(mapconcat 'identity keywords
", "))
3485 (Info-find-node Info-finder-file
"Top")))
3488 (defun Info-undefined ()
3489 "Make command be undefined in Info."
3494 "Enter the Info tutorial."
3496 (delete-other-windows)
3497 (Info-find-node "info"
3498 (if (< (window-height) 23)
3502 (defun Info-summary ()
3503 "Display a brief summary of all Info commands."
3505 (save-window-excursion
3506 (switch-to-buffer "*Help*")
3507 (setq buffer-read-only nil
)
3509 (insert (documentation 'Info-mode
))
3511 (goto-char (point-min))
3513 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
3514 (message (if flag
"Type Space to see more"
3515 "Type Space to return to Info"))
3516 (if (not (eq ?\s
(setq ch
(read-event))))
3517 (progn (setq unread-command-events
(list ch
)) nil
)
3520 (bury-buffer "*Help*")))
3522 (defun Info-get-token (pos start all
&optional errorstring
)
3523 "Return the token around POS.
3524 POS must be somewhere inside the token
3525 START is a regular expression which will match the
3526 beginning of the tokens delimited string
3527 ALL is a regular expression with a single
3528 parenthesized subpattern which is the token to be
3529 returned. E.g. '{\(.*\)}' would return any string
3530 enclosed in braces around POS.
3531 ERRORSTRING optional fourth argument, controls action on no match
3534 a string: signal an error, using that string."
3535 (let ((case-fold-search t
))
3538 ;; First look for a match for START that goes across POS.
3539 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
3540 (not (looking-at start
)))
3542 ;; If we did not find one, search back for START
3543 ;; (this finds only matches that end at or before POS).
3544 (or (looking-at start
)
3547 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
3549 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
3550 (not (setq found
(and (<= (match-beginning 0) pos
)
3551 (> (match-end 0) pos
))))))
3552 (if (and found
(<= (match-beginning 0) pos
)
3553 (> (match-end 0) pos
))
3554 (match-string-no-properties 1)
3555 (cond ((null errorstring
)
3561 (error "No %s around position %d" errorstring pos
))))))))
3563 (defun Info-mouse-follow-nearest-node (click)
3564 "\\<Info-mode-map>Follow a node reference near point.
3565 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3566 At end of the node's text, moves to the next node, or up if none."
3568 (mouse-set-point click
)
3569 (and (not (Info-follow-nearest-node))
3570 (save-excursion (forward-line 1) (eobp))
3571 (Info-next-preorder)))
3573 (defun Info-follow-nearest-node (&optional fork
)
3574 "Follow a node reference near point.
3575 If point is on a reference, follow that reference. Otherwise,
3576 if point is in a menu item description, follow that menu item.
3578 If FORK is non-nil (interactively with a prefix arg), show the node in
3580 If FORK is a string, it is the name to use for the new buffer."
3582 (or (Info-try-follow-nearest-node fork
)
3583 (when (save-excursion
3584 (search-backward "\n* menu:" nil t
))
3587 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3588 (beginning-of-line 0))
3589 (when (looking-at "\\* +\\([^\t\n]*\\):")
3591 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
3593 (and (eq this-command
'Info-mouse-follow-nearest-node
)
3594 ;; Don't raise an error when mouse-1 is bound to this - it's
3595 ;; often used to simply select the window or frame.
3596 (eq 'mouse-1
(event-basic-type last-input-event
)))
3597 (error "Point neither on reference nor in menu item description")))
3599 ;; Common subroutine.
3600 (defun Info-try-follow-nearest-node (&optional fork
)
3601 "Follow a node reference near point. Return non-nil if successful.
3602 If FORK is non-nil, it is passed to `Info-goto-node'."
3605 ((setq node
(Info-get-token (point) "[hf]t?tps?://"
3606 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3609 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
3610 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3611 (Info-follow-reference node fork
))
3612 ;; menu item: node name
3613 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3614 (Info-goto-node node fork
))
3615 ;; menu item: node name or index entry
3616 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3619 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
3620 (Info-goto-node node fork
))
3621 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3622 (Info-goto-node node fork
))
3623 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3624 (Info-goto-node node fork
))
3625 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3626 (Info-goto-node "Top" fork
))
3627 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3628 (Info-goto-node node fork
)))
3631 (defun Info-mouse-follow-link (click)
3632 "Follow a link where you click."
3634 (let* ((position (event-start click
))
3635 (posn-string (and position
(posn-string position
)))
3636 (string (car-safe posn-string
))
3637 (string-pos (cdr-safe posn-string
))
3638 (link-args (and string string-pos
3639 (get-text-property string-pos
'link-args string
))))
3641 (Info-goto-node link-args
))))
3644 (defvar Info-mode-map
3645 (let ((map (make-keymap)))
3646 (suppress-keymap map
)
3647 (define-key map
"." 'beginning-of-buffer
)
3648 (define-key map
" " 'Info-scroll-up
)
3649 (define-key map
"\C-m" 'Info-follow-nearest-node
)
3650 (define-key map
"\t" 'Info-next-reference
)
3651 (define-key map
"\e\t" 'Info-prev-reference
)
3652 (define-key map
[(shift tab
)] 'Info-prev-reference
)
3653 (define-key map
[backtab] 'Info-prev-reference)
3654 (define-key map "1" 'Info-nth-menu-item)
3655 (define-key map "2" 'Info-nth-menu-item)
3656 (define-key map "3" 'Info-nth-menu-item)
3657 (define-key map "4" 'Info-nth-menu-item)
3658 (define-key map "5" 'Info-nth-menu-item)
3659 (define-key map "6" 'Info-nth-menu-item)
3660 (define-key map "7" 'Info-nth-menu-item)
3661 (define-key map "8" 'Info-nth-menu-item)
3662 (define-key map "9" 'Info-nth-menu-item)
3663 (define-key map "0" 'undefined)
3664 (define-key map "?" 'Info-summary)
3665 (define-key map "]" 'Info-forward-node)
3666 (define-key map "[" 'Info-backward-node)
3667 (define-key map "<" 'Info-top-node)
3668 (define-key map ">" 'Info-final-node)
3669 (define-key map "b" 'beginning-of-buffer)
3670 (define-key map "d" 'Info-directory)
3671 (define-key map "e" 'Info-edit)
3672 (define-key map "f" 'Info-follow-reference)
3673 (define-key map "g" 'Info-goto-node)
3674 (define-key map "h" 'Info-help)
3675 (define-key map "i" 'Info-index)
3676 (define-key map "I" 'Info-virtual-index)
3677 (define-key map "l" 'Info-history-back)
3678 (define-key map "L" 'Info-history)
3679 (define-key map "m" 'Info-menu)
3680 (define-key map "n" 'Info-next)
3681 (define-key map "p" 'Info-prev)
3682 (define-key map "q" 'Info-exit)
3683 (define-key map "r" 'Info-history-forward)
3684 (define-key map "s" 'Info-search)
3685 (define-key map "S" 'Info-search-case-sensitively)
3686 (define-key map "\M-n" 'clone-buffer)
3687 (define-key map "t" 'Info-top-node)
3688 (define-key map "T" 'Info-toc)
3689 (define-key map "u" 'Info-up)
3690 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3691 (define-key map "w" 'Info-copy-current-node-name)
3692 (define-key map "c" 'Info-copy-current-node-name)
3693 ;; `^' for consistency with `dired-up-directory'.
3694 (define-key map "^" 'Info-up)
3695 (define-key map "," 'Info-index-next)
3696 (define-key map "\177" 'Info-scroll-down)
3697 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3698 (define-key map [follow-link] 'mouse-face)
3700 "Keymap containing Info commands.")
3703 (defun Info-check-pointer (item)
3704 "Non-nil if ITEM is present in this node."
3706 (Info-extract-pointer item)
3710 Info-mode-menu Info-mode-map
3711 "Menu for Info files."
3713 ["Up" Info-up :active (Info-check-pointer "up")
3714 :help "Go up in the Info tree"]
3715 ["Next" Info-next :active (Info-check-pointer "next")
3716 :help "Go to the next node"]
3717 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3718 :help "Go to the previous node"]
3719 ["Backward" Info-backward-node
3720 :help "Go backward one node, considering all as a sequence"]
3721 ["Forward" Info-forward-node
3722 :help "Go forward one node, considering all as a sequence"]
3723 ["Beginning" beginning-of-buffer
3724 :help "Go to beginning of this node"]
3725 ["Top" Info-top-node
3726 :help "Go to top node of file"]
3727 ["Final Node" Info-final-node
3728 :help "Go to final node in this file"]
3729 ("Menu Item" ["You should never see this" report-emacs-bug t])
3730 ("Reference" ["You should never see this" report-emacs-bug t])
3731 ["Search..." Info-search
3732 :help "Search for regular expression in this Info file"]
3733 ["Search Next" Info-search-next
3734 :help "Search for another occurrence of regular expression"]
3735 ["Go to Node..." Info-goto-node
3736 :help "Go to a named node"]
3737 ["Back in history" Info-history-back :active Info-history
3738 :help "Go back in history to the last node you were at"]
3739 ["Forward in history" Info-history-forward :active Info-history-forward
3740 :help "Go forward in history"]
3741 ["History" Info-history :active Info-history-list
3742 :help "Go to menu of visited nodes"]
3743 ["Table of Contents" Info-toc
3744 :help "Go to table of contents"]
3746 ["Lookup a String..." Info-index
3747 :help "Look for a string in the index items"]
3748 ["Next Matching Item" Info-index-next :active Info-index-alternatives
3749 :help "Look for another occurrence of previous item"]
3750 ["Lookup a string and display index of results..." Info-virtual-index
3751 :help "Look for a string in the index items and display node with results"]
3752 ["Lookup a string in all indices..." info-apropos
3753 :help "Look for a string in the indices of all manuals"])
3754 ["Copy Node Name" Info-copy-current-node-name
3755 :help "Copy the name of the current node into the kill ring"]
3756 ["Clone Info buffer" clone-buffer
3757 :help "Create a twin copy of the current Info buffer."]
3758 ["Exit" Info-exit :help "Stop reading Info"]))
3761 (defvar info-tool-bar-map
3762 (let ((map (make-sparse-keymap)))
3763 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
3766 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
3769 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
3771 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
3773 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map)
3774 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map)
3775 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
3776 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
3777 :label "Index Search")
3778 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map)
3779 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map)
3782 (defvar Info-menu-last-node nil)
3783 ;; Last node the menu was created for.
3784 ;; Value is a list, (FILE-NAME NODE-NAME).
3786 (defun Info-menu-update ()
3787 "Update the Info menu for the current node."
3789 (if (or (not (eq major-mode 'Info-mode))
3790 (equal (list Info-current-file Info-current-node)
3791 Info-menu-last-node))
3793 ;; Update menu menu.
3794 (let* ((Info-complete-menu-buffer (current-buffer))
3795 (items (nreverse (condition-case nil
3796 (Info-complete-menu-item "" nil t)
3800 (while (and items (< number 9))
3801 (setq current (car items)
3804 (setq entries (cons `[,current
3805 (Info-menu ,current)
3806 :keys ,(format "%d" number)]
3809 (setq entries (cons ["Other..." Info-menu t] entries)))
3811 (setq entries (list ["No menu" nil nil] nil :active)))
3812 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3813 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3815 str i entries current
3817 (case-fold-search t))
3819 (goto-char (point-min))
3820 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3821 (setq str (match-string 1))
3823 (while (setq i (string-match "[ \n\t]+" str i))
3824 (setq str (concat (substring str 0 i) " "
3825 (substring str (match-end 0))))
3829 (while (and items (< number 9))
3830 (setq current (car items)
3833 (setq entries (cons `[,current
3834 (Info-follow-reference ,current)
3838 (setq entries (cons ["Other..." Info-follow-reference t]
3841 (setq entries (list ["No references" nil nil] nil :active)))
3842 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3843 ;; Update last seen node.
3844 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3845 ;; Try to avoid entering infinite beep mode in case of errors.
3849 (defun Info-copy-current-node-name (&optional arg)
3850 "Put the name of the current Info node into the kill ring.
3851 The name of the Info file is prepended to the node name in parentheses.
3852 With a zero prefix arg, put the name inside a function call to `info'."
3854 (unless Info-current-node
3855 (error "No current Info node"))
3856 (let ((node (if (stringp Info-current-file)
3857 (concat "(" (file-name-nondirectory Info-current-file) ") "
3858 Info-current-node))))
3859 (if (zerop (prefix-numeric-value arg))
3860 (setq node (concat "(info \"" node "\")")))
3861 (unless (stringp Info-current-file)
3862 (setq node (format "(Info-find-node '%S '%S)"
3863 Info-current-file Info-current-node)))
3865 (message "%s" node)))
3868 ;; Info mode is suitable only for specially formatted data.
3869 (put 'Info-mode 'mode-class 'special)
3870 (put 'Info-mode 'no-clone-indirect t)
3872 (defvar tool-bar-map)
3873 (defvar bookmark-make-record-function)
3875 ;; Autoload cookie needed by desktop.el
3877 (define-derived-mode Info-mode nil "Info"
3878 "Info mode provides commands for browsing through the Info documentation tree.
3879 Documentation in Info is divided into \"nodes\", each of which discusses
3880 one topic and contains references to other nodes which discuss related
3881 topics. Info has commands to follow the references and show you other nodes.
3884 \\[Info-help] Invoke the Info tutorial.
3885 \\[Info-exit] Quit Info: reselect previously selected buffer.
3887 Selecting other nodes:
3888 \\[Info-mouse-follow-nearest-node]
3889 Follow a node reference you click on.
3890 This works with menu items, cross references, and
3891 the \"next\", \"previous\" and \"up\", depending on where you click.
3892 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3893 \\[Info-next] Move to the \"next\" node of this node.
3894 \\[Info-prev] Move to the \"previous\" node of this node.
3895 \\[Info-up] Move \"up\" from this node.
3896 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3897 Picking a menu item causes another node to be selected.
3898 \\[Info-directory] Go to the Info directory node.
3899 \\[Info-top-node] Go to the Top node of this file.
3900 \\[Info-final-node] Go to the final node in this file.
3901 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3902 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3903 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3904 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
3905 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3906 \\[Info-history-back] Move back in history to the last node you were at.
3907 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3908 \\[Info-history] Go to menu of visited nodes.
3909 \\[Info-toc] Go to table of contents of the current Info file.
3911 Moving within a node:
3912 \\[Info-scroll-up] Normally, scroll forward a full screen.
3913 Once you scroll far enough in a node that its menu appears on the
3914 screen but after point, the next scroll moves into its first
3915 subnode. When after all menu items (or if there is no menu),
3916 move up to the parent node.
3917 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3918 already visible, try to go to the previous menu entry, or up
3920 \\[beginning-of-buffer] Go to beginning of node.
3923 \\[Info-search] Search through this Info file for specified regexp,
3924 and select the node in which the next occurrence is found.
3925 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3926 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
3927 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
3928 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3929 \\[Info-virtual-index] Look for a string and display the index node with results.
3930 \\[info-apropos] Look for a string in the indices of all manuals.
3931 \\[Info-goto-node] Move to node specified by name.
3932 You may include a filename as well, as (FILENAME)NODENAME.
3933 1 .. 9 Pick first ... ninth item in node's menu.
3934 Every third `*' is highlighted to help pick the right number.
3935 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
3936 \\[clone-buffer] Select a new cloned Info buffer in another window.
3937 \\[universal-argument] \\[info] Move to new Info file with completion.
3938 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
3939 :syntax-table text-mode-syntax-table
3940 :abbrev-table text-mode-abbrev-table
3942 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3943 (setq case-fold-search t)
3944 (setq buffer-read-only t)
3945 (make-local-variable 'Info-current-file)
3946 (make-local-variable 'Info-current-subfile)
3947 (make-local-variable 'Info-current-node)
3948 (set (make-local-variable 'Info-tag-table-marker) (make-marker))
3949 (set (make-local-variable 'Info-tag-table-buffer) nil)
3950 (make-local-variable 'Info-history)
3951 (make-local-variable 'Info-history-forward)
3952 (make-local-variable 'Info-index-alternatives)
3953 (if Info-use-header-line ; do not override global header lines
3954 (setq header-line-format
3955 '(:eval (get-text-property (point-min) 'header-line))))
3956 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
3957 ;; This is for the sake of the invisible text we use handling titles.
3958 (set (make-local-variable 'line-move-ignore-invisible) t)
3959 (set (make-local-variable 'desktop-save-buffer)
3960 'Info-desktop-buffer-misc-data)
3961 (set (make-local-variable 'widen-automatically) nil)
3962 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
3963 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
3964 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
3965 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
3966 (set (make-local-variable 'isearch-search-fun-function)
3967 'Info-isearch-search)
3968 (set (make-local-variable 'isearch-wrap-function)
3970 (set (make-local-variable 'isearch-push-state-function)
3971 'Info-isearch-push-state)
3972 (set (make-local-variable 'isearch-filter-predicate)
3973 'Info-isearch-filter)
3974 (set (make-local-variable 'search-whitespace-regexp)
3975 Info-search-whitespace-regexp)
3976 (set (make-local-variable 'revert-buffer-function)
3977 'Info-revert-buffer-function)
3978 (Info-set-mode-line)
3979 (set (make-local-variable 'bookmark-make-record-function)
3980 'Info-bookmark-make-record))
3982 ;; When an Info buffer is killed, make sure the associated tags buffer
3984 (defun Info-kill-buffer ()
3985 (and (eq major-mode 'Info-mode)
3986 Info-tag-table-buffer
3987 (kill-buffer Info-tag-table-buffer)))
3989 ;; Placed on `clone-buffer-hook'.
3990 (defun Info-clone-buffer ()
3991 (when (bufferp Info-tag-table-buffer)
3992 (setq Info-tag-table-buffer
3993 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
3994 (let ((m Info-tag-table-marker))
3996 (setq Info-tag-table-marker
3997 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
3998 (with-current-buffer Info-tag-table-buffer
3999 (copy-marker (marker-position m)))
4002 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
4003 (set-keymap-parent map text-mode-map)
4004 (define-key map "\C-c\C-c" 'Info-cease-edit)
4006 "Local keymap used within `e' command of Info.")
4008 ;; Info-edit mode is suitable only for specially formatted data.
4009 (put 'Info-edit-mode 'mode-class 'special)
4011 (defun Info-edit-mode ()
4012 "Major mode for editing the contents of an Info node.
4013 Like text mode with the addition of `Info-cease-edit'
4014 which returns to Info mode for browsing.
4016 (use-local-map Info-edit-map)
4017 (setq major-mode 'Info-edit-mode)
4018 (setq mode-name "Info Edit")
4019 (kill-local-variable 'mode-line-buffer-identification)
4020 (setq buffer-read-only nil)
4021 (force-mode-line-update)
4022 (buffer-enable-undo (current-buffer))
4023 (run-mode-hooks 'Info-edit-mode-hook))
4026 "Edit the contents of this Info node.
4027 Allowed only if variable `Info-enable-edit' is non-nil."
4029 (or Info-enable-edit
4030 (error "Editing Info nodes is not enabled"))
4032 (message "%s" (substitute-command-keys
4033 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
4035 (defun Info-cease-edit ()
4036 "Finish editing Info node; switch back to Info proper."
4038 ;; Do this first, so nothing has changed if user C-g's at query.
4039 (and (buffer-modified-p)
4040 (y-or-n-p "Save the file? ")
4042 (use-local-map Info-mode-map)
4043 (setq major-mode 'Info-mode)
4044 (setq mode-name "Info")
4045 (Info-set-mode-line)
4046 (setq buffer-read-only t)
4047 (force-mode-line-update)
4048 (and (marker-position Info-tag-table-marker)
4050 (message "Tags may have changed. Use Info-tagify if necessary")))
4052 (defvar Info-file-list-for-emacs
4053 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4054 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4055 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4056 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4057 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4058 ("copyright" . "autotype") ("executable" . "autotype")
4059 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4060 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4061 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4062 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4063 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4064 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4065 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4066 ("rfc2045" . "emacs-mime")
4067 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4068 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4069 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4070 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4071 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4072 ("mml" . "emacs-mime"))
4073 "List of Info files that describe Emacs commands.
4074 An element can be a file name, or a list of the form (PREFIX . FILE)
4075 where PREFIX is a name prefix and FILE is the file to look in.
4076 If the element is just a file name, the file name also serves as the prefix.")
4078 (defun Info-find-emacs-command-nodes (command)
4079 "Return a list of locations documenting COMMAND.
4080 The `info-file' property of COMMAND says which Info manual to search.
4081 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4082 defines heuristics for which Info manual to try.
4083 The locations are of the format used in `Info-history', i.e.
4084 \(FILENAME NODENAME BUFFERPOS\), where BUFFERPOS is the line number
4085 in the first element of the returned list (which is treated specially in
4086 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4087 (let ((where '()) line-number
4088 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4089 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4090 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4091 (info-file "emacs")) ;default
4092 ;; Determine which Info file this command is documented in.
4093 (if (get command 'info-file)
4094 (setq info-file (get command 'info-file))
4095 ;; If it doesn't say explicitly, test its name against
4096 ;; various prefixes that we know.
4097 (let ((file-list Info-file-list-for-emacs))
4099 (let* ((elt (car file-list))
4100 (name (if (consp elt)
4103 (file (if (consp elt) (cdr elt) elt))
4104 (case-fold-search nil)
4105 (regexp (concat "\\`" (regexp-quote name)
4107 (if (string-match regexp (symbol-name command))
4108 (setq info-file file file-list nil))
4109 (setq file-list (cdr file-list))))))
4110 (Info-find-node info-file "Top")
4111 ;; Bind Info-history to nil, to prevent the index nodes from
4112 ;; getting into the node history.
4113 (let ((Info-history nil)
4114 (Info-history-list nil)
4115 node (nodes (Info-index-nodes)))
4116 (Info-goto-node (car nodes))
4119 (goto-char (point-min))
4120 (while (re-search-forward cmd-desc nil t)
4122 (cons (list Info-current-file
4123 (match-string-no-properties 2)
4126 (setq line-number (and (match-beginning 3)
4127 (string-to-number (match-string 3)))))
4128 (and (setq nodes (cdr nodes) node (car nodes))))
4129 (Info-goto-node node)))
4130 (if (and line-number where)
4131 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4135 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4137 (defun Info-goto-emacs-command-node (command)
4138 "Go to the Info node in the Emacs manual for command COMMAND.
4139 The command is found by looking up in Emacs manual's indices
4140 or in another manual found via COMMAND's `info-file' property or
4141 the variable `Info-file-list-for-emacs'.
4142 COMMAND must be a symbol or string."
4143 (interactive "CFind documentation for command: ")
4144 ;; If command is given as a string, convert it to a symbol.
4145 (if (stringp command)
4146 (setq command (intern command)))
4147 (or (commandp command)
4148 (signal 'wrong-type-argument (list 'commandp command)))
4149 (let ((where (Info-find-emacs-command-nodes command)))
4151 (let ((num-matches (length where)))
4152 ;; Get Info running, and pop to it in another window.
4153 (save-window-excursion
4155 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
4156 ;; Bind Info-history to nil, to prevent the last Index node
4157 ;; visited by Info-find-emacs-command-nodes from being
4158 ;; pushed onto the history.
4159 (let ((Info-history nil) (Info-history-list nil)
4160 (line-number (nth 2 (car where))))
4161 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4162 (if (and (integerp line-number) (> line-number 0))
4163 (forward-line (1- line-number))))
4164 (if (> num-matches 1)
4166 ;; (car where) will be pushed onto Info-history
4167 ;; when/if they go to another node. Put the other
4168 ;; nodes that were found on the history.
4169 (setq Info-history (nconc (cdr where) Info-history))
4170 (message "Found %d other entr%s. Use %s to see %s."
4172 (if (> num-matches 2) "ies" "y")
4173 (substitute-command-keys "\\[Info-history-back]")
4174 (if (> num-matches 2) "them" "it")))))
4175 (error "Couldn't find documentation for %s" command))))
4177 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4179 (defun Info-goto-emacs-key-command-node (key)
4180 "Go to the node in the Emacs manual which describes the command bound to KEY.
4182 Interactively, if the binding is `execute-extended-command', a command is read.
4183 The command is found by looking up in Emacs manual's indices
4184 or in another manual found via COMMAND's `info-file' property or
4185 the variable `Info-file-list-for-emacs'."
4186 (interactive "kFind documentation for key: ")
4187 (let ((command (key-binding key)))
4188 (cond ((null command)
4189 (message "%s is undefined" (key-description key)))
4190 ((and (called-interactively-p 'interactive)
4191 (eq command 'execute-extended-command))
4192 (Info-goto-emacs-command-node
4193 (read-command "Find documentation for command: ")))
4195 (Info-goto-emacs-command-node command)))))
4197 (defvar Info-next-link-keymap
4198 (let ((keymap (make-sparse-keymap)))
4199 (define-key keymap [header-line mouse-1] 'Info-next)
4200 (define-key keymap [header-line mouse-2] 'Info-next)
4201 (define-key keymap [header-line down-mouse-1] 'ignore)
4202 (define-key keymap [mouse-2] 'Info-next)
4203 (define-key keymap [follow-link] 'mouse-face)
4205 "Keymap to put on the Next link in the text or the header line.")
4207 (defvar Info-prev-link-keymap
4208 (let ((keymap (make-sparse-keymap)))
4209 (define-key keymap [header-line mouse-1] 'Info-prev)
4210 (define-key keymap [header-line mouse-2] 'Info-prev)
4211 (define-key keymap [header-line down-mouse-1] 'ignore)
4212 (define-key keymap [mouse-2] 'Info-prev)
4213 (define-key keymap [follow-link] 'mouse-face)
4215 "Keymap to put on the Prev link in the text or the header line.")
4217 (defvar Info-up-link-keymap
4218 (let ((keymap (make-sparse-keymap)))
4219 (define-key keymap [header-line mouse-1] 'Info-up)
4220 (define-key keymap [header-line mouse-2] 'Info-up)
4221 (define-key keymap [header-line down-mouse-1] 'ignore)
4222 (define-key keymap [mouse-2] 'Info-up)
4223 (define-key keymap [follow-link] 'mouse-face)
4225 "Keymap to put on the Up link in the text or the header line.")
4227 (defvar Info-link-keymap
4228 (let ((keymap (make-sparse-keymap)))
4229 (define-key keymap [header-line mouse-1] 'Info-mouse-follow-link)
4230 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4231 (define-key keymap [header-line down-mouse-1] 'ignore)
4232 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4233 (define-key keymap [follow-link] 'mouse-face)
4235 "Keymap to put on the link in the text or the header line.")
4237 (defun Info-breadcrumbs ()
4238 (let ((nodes (Info-toc-nodes Info-current-file))
4239 (node Info-current-node)
4241 (depth Info-breadcrumbs-depth)
4244 ;; Get ancestors from the cached parent-children node info
4245 (while (and (not (equal "Top" node)) (> depth 0))
4246 (setq node (nth 1 (assoc node nodes)))
4247 (if node (push node crumbs))
4248 (setq depth (1- depth)))
4251 (when Info-use-header-line
4252 ;; Let it disappear if crumbs is nil.
4253 (nconc crumbs (list Info-current-node)))
4254 (when (or Info-use-header-line crumbs)
4255 ;; Add top node (and continuation if needed).
4257 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4258 crumbs (cons nil crumbs))))
4259 ;; Eliminate duplicate.
4261 (dolist (node crumbs)
4263 (if (not (equal node "Top")) node
4265 (if (stringp Info-current-file)
4266 (file-name-nondirectory Info-current-file)
4267 ;; Some legacy code can still use a symbol.
4268 Info-current-file)))))
4271 (if (null line) "" " > ")
4274 ((equal node Info-current-node)
4275 ;; No point linking to ourselves.
4276 (propertize text 'font-lock-face 'info-header-node))
4279 'mouse-face 'highlight
4280 'font-lock-face 'info-header-xref
4281 'help-echo "mouse-2: Go to node"
4282 'keymap Info-link-keymap
4283 'link-args text)))))))
4284 (setq line (concat line "\n")))
4285 ;; (font-lock-append-text-property 0 (length line)
4286 ;; 'font-lock-face 'header-line line)
4289 (defun Info-fontify-node ()
4292 (let* ((inhibit-read-only t)
4293 (case-fold-search t)
4295 (not-fontified-p ; the node hasn't already been fontified
4296 (not (let ((where (next-single-property-change (point-min)
4298 (and where (not (= where (point-max)))))))
4299 (fontify-visited-p ; visited nodes need to be re-fontified
4300 (and Info-fontify-visited-nodes
4301 ;; Don't take time to refontify visited nodes in huge nodes
4302 Info-fontify-maximum-menu-size
4303 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4306 ;; Fontify header line
4307 (goto-char (point-min))
4308 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4309 (goto-char (match-end 0))
4310 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4311 (goto-char (match-end 0))
4312 (let* ((nbeg (match-beginning 2))
4313 (nend (match-end 2))
4314 (tbeg (match-beginning 1))
4315 (tag (match-string 1)))
4316 (if (string-equal (downcase tag) "node")
4317 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4318 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4319 (put-text-property tbeg nend 'mouse-face 'highlight)
4320 (put-text-property tbeg nend
4322 (concat "mouse-2: Go to node "
4323 (buffer-substring nbeg nend)))
4324 ;; Always set up the text property keymap.
4325 ;; It will either be used in the buffer
4326 ;; or copied in the header line.
4330 ((string-equal (downcase tag) "prev") Info-prev-link-keymap)
4331 ((string-equal (downcase tag) "next") Info-next-link-keymap)
4332 ((string-equal (downcase tag) "up" ) Info-up-link-keymap))))))
4334 ;; (when (> Info-breadcrumbs-depth 0)
4335 ;; (insert (Info-breadcrumbs)))
4337 ;; Treat header line.
4338 (when Info-use-header-line
4339 (goto-char (point-min))
4340 (let* ((header-end (line-end-position))
4342 ;; If we find neither Next: nor Prev: link, show the entire
4343 ;; node header. Otherwise, don't show the File: and Node:
4344 ;; parts, to avoid wasting precious space on information that
4345 ;; is available in the mode line.
4346 (if (re-search-forward
4347 "\\(next\\|up\\|prev[ious]*\\): "
4350 (goto-char (match-beginning 1))
4351 (buffer-substring (point) header-end))
4352 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4354 (concat "No next, prev or up links -- "
4355 (buffer-substring (point) header-end))
4356 (buffer-substring (point) header-end)))))
4357 (put-text-property (point-min) (1+ (point-min))
4359 (replace-regexp-in-string
4361 ;; Preserve text properties on duplicated `%'.
4362 (lambda (s) (concat s s)) header))
4363 ;; Hide the part of the first line
4364 ;; that is in the header, if it is just part.
4366 ((> Info-breadcrumbs-depth 0)
4367 (let ((ov (make-overlay (point-min) (1+ header-end))))
4368 (overlay-put ov 'display (Info-breadcrumbs))
4369 (overlay-put ov 'evaporate t)))
4371 ;; Hide the punctuation at the end, too.
4372 (skip-chars-backward " \t,")
4373 (put-text-property (point) header-end 'invisible t))))))
4376 (goto-char (point-min))
4377 (when (and font-lock-mode not-fontified-p)
4378 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4380 ;; Only consider it as an underlined title if the ASCII
4381 ;; underline has the same size as the text. A typical
4382 ;; counter example is when a continuation "..." is alone
4384 (= (string-width (match-string 1))
4385 (string-width (match-string 2))))
4386 (let* ((c (preceding-char))
4388 (cond ((= c ?*) 'info-title-1)
4389 ((= c ?=) 'info-title-2)
4390 ((= c ?-) 'info-title-3)
4391 (t 'info-title-4))))
4392 (put-text-property (match-beginning 1) (match-end 1)
4393 'font-lock-face face))
4394 ;; This is a serious problem for trying to handle multiple
4395 ;; frame types at once. We want this text to be invisible
4396 ;; on frames that can display the font above.
4397 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4398 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4399 '(invisible t front-sticky nil rear-nonsticky t)))))
4401 ;; Fontify cross references
4402 (goto-char (point-min))
4403 (when (or not-fontified-p fontify-visited-p)
4404 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4405 (let ((start (match-beginning 0))
4408 (when not-fontified-p
4409 (when Info-hide-note-references
4410 (when (and (not (eq Info-hide-note-references 'hide))
4411 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4412 ;; *Note is often used where *note should have been
4414 (skip-syntax-backward " ")
4415 (when (memq (char-before) '(?\( ?\[ ?\{))
4416 ;; Check whether the paren is preceded by
4417 ;; an end of sentence
4418 (skip-syntax-backward " ("))
4420 (cond ((save-match-data (looking-back "\\<see"))
4422 ((save-match-data (looking-back "\\<in"))
4424 ((memq (char-before) '(nil ?\. ?! ??))
4428 (search-forward "\n\n" start t)))
4432 (add-text-properties
4434 (or (save-match-data
4435 ;; Don't hide \n after *Note
4436 (let ((start1 (match-beginning 1)))
4437 (if (string-match "\n" (match-string 1))
4438 (+ start1 (match-beginning 0)))))
4441 `(display ,other-tag front-sticky nil rear-nonsticky t)
4442 '(invisible t front-sticky nil rear-nonsticky t))))
4443 (add-text-properties
4444 (match-beginning 2) (match-end 2)
4446 'help-echo (if (or (match-end 5)
4447 (not (equal (match-string 4) "")))
4448 (concat "mouse-2: go to " (or (match-string 5)
4450 "mouse-2: go to this node")
4451 'mouse-face 'highlight)))
4452 (when (or not-fontified-p fontify-visited-p)
4453 (setq rbeg (match-beginning 2)
4458 ;; Display visited nodes in a different face
4459 (if (and Info-fontify-visited-nodes
4461 (let* ((node (replace-regexp-in-string
4463 (replace-regexp-in-string
4465 (or (match-string-no-properties 5)
4466 (and (not (equal (match-string 4) ""))
4467 (match-string-no-properties 4))
4468 (match-string-no-properties 2)))))
4470 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4471 (file (if external-link-p
4472 (file-name-nondirectory
4473 (match-string-no-properties 1 node))
4475 (hl Info-history-list)
4478 (setq node (if (equal (match-string 2 node) "")
4480 (match-string-no-properties 2 node))))
4482 (if (and (string-equal node (nth 1 (car hl)))
4484 (if (and external-link-p
4485 (stringp (caar hl)))
4486 (file-name-nondirectory
4489 (setq res (car hl) hl nil)
4490 (setq hl (cdr hl))))
4491 res))) 'info-xref-visited 'info-xref))
4492 ;; For multiline ref, unfontify newline and surrounding whitespace
4496 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4497 (remove-text-properties (match-beginning 0)
4499 '(font-lock-face t))))))
4500 (when not-fontified-p
4501 (when (memq Info-hide-note-references '(t hide))
4502 (add-text-properties (match-beginning 3) (match-end 3)
4503 '(invisible t front-sticky nil rear-nonsticky t))
4504 ;; Unhide the file name of the external reference in parens
4505 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4506 (remove-text-properties (match-beginning 6) (match-end 6)
4507 '(invisible t front-sticky nil rear-nonsticky t)))
4508 ;; Unhide newline because hidden newlines cause too long lines
4510 (let ((beg3 (match-beginning 3))
4511 (end3 (match-end 3)))
4512 (if (and (string-match "\n[ \t]*" (match-string 3))
4513 (not (save-match-data
4515 (goto-char (1+ end3))
4516 (looking-at "[.)]*$")))))
4517 (remove-text-properties (+ beg3 (match-beginning 0))
4518 (+ beg3 (match-end 0))
4519 '(invisible t front-sticky nil rear-nonsticky t))))))
4520 (when (and Info-refill-paragraphs Info-hide-note-references)
4521 (push (set-marker (make-marker) start)
4522 paragraph-markers))))))
4524 ;; Refill paragraphs (experimental feature)
4525 (when (and not-fontified-p
4526 Info-refill-paragraphs
4528 (let ((fill-nobreak-invisible t)
4529 (fill-individual-varying-indent nil)
4530 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4531 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4532 (adaptive-fill-mode nil))
4533 (goto-char (point-max))
4534 (dolist (m paragraph-markers)
4538 (let ((beg (point)))
4539 (when (zerop (forward-paragraph))
4540 (fill-individual-paragraphs beg (point) nil nil)
4542 (set-marker m nil))))
4544 ;; Fontify menu items
4545 (goto-char (point-min))
4546 (when (and (or not-fontified-p fontify-visited-p)
4547 (search-forward "\n* Menu:" nil t)
4548 ;; Don't take time to annotate huge menus
4549 Info-fontify-maximum-menu-size
4550 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4553 (while (re-search-forward
4554 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4555 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4557 (when (match-beginning 1)
4558 (when not-fontified-p
4560 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4561 (put-text-property (match-beginning 0)
4562 (1+ (match-beginning 0))
4563 'font-lock-face 'info-menu-star)))
4564 (when not-fontified-p
4565 (add-text-properties
4566 (match-beginning 1) (match-end 1)
4568 'help-echo (if (and (match-end 3)
4569 (not (equal (match-string 3) "")))
4570 (concat "mouse-2: go to " (match-string 3))
4571 "mouse-2: go to this node")
4572 'mouse-face 'highlight)))
4573 (when (or not-fontified-p fontify-visited-p)
4575 (match-beginning 1) (match-end 1)
4577 ;; Display visited menu items in a different face
4578 (if (and Info-fontify-visited-nodes
4580 (let* ((node (if (equal (match-string 3) "")
4581 (match-string-no-properties 1)
4582 (match-string-no-properties 3)))
4584 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4585 (file (if external-link-p
4586 (file-name-nondirectory
4587 (match-string-no-properties 1 node))
4589 (hl Info-history-list)
4592 (setq node (if (equal (match-string 2 node) "")
4594 (match-string-no-properties 2 node))))
4596 (if (and (string-equal node (nth 1 (car hl)))
4598 (if (and external-link-p
4599 (stringp (caar hl)))
4600 (file-name-nondirectory
4603 (setq res (car hl) hl nil)
4604 (setq hl (cdr hl))))
4605 res))) 'info-xref-visited 'info-xref)))
4606 (when (and not-fontified-p
4607 (memq Info-hide-note-references '(t hide))
4608 (not (Info-index-node)))
4609 (put-text-property (match-beginning 2) (1- (match-end 6))
4611 ;; Unhide the file name in parens
4612 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4613 (remove-text-properties (match-beginning 4) (match-end 4)
4615 ;; We need a stretchable space like :align-to but with
4617 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4618 (if (>= 22 (- (match-end 1)
4619 (match-beginning 0)))
4620 '(space :align-to 24)
4622 (setq cont (looking-at "."))
4623 (while (and (= (forward-line 1) 0)
4624 (looking-at "\\([ \t]+\\)[^*\n]"))
4625 (put-text-property (match-beginning 1) (1- (match-end 1))
4627 (put-text-property (1- (match-end 1)) (match-end 1)
4630 '(space :align-to 26)
4631 '(space :align-to 24)))
4634 ;; Fontify menu headers
4635 ;; Add the face `info-menu-header' to any header before a menu entry
4636 (goto-char (point-min))
4637 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4638 (put-text-property (match-beginning 0) (match-end 0)
4639 'font-lock-face 'info-menu-header)
4640 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4641 (put-text-property (match-beginning 1) (match-end 1)
4642 'font-lock-face 'info-menu-header)))
4644 ;; Hide index line numbers
4645 (goto-char (point-min))
4646 (when (and not-fontified-p (Info-index-node))
4647 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4648 (put-text-property (match-beginning 0) (match-end 0)
4651 ;; Fontify http and ftp references
4652 (goto-char (point-min))
4653 (when not-fontified-p
4654 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4656 (add-text-properties (match-beginning 0) (match-end 0)
4657 '(font-lock-face info-xref
4658 mouse-face highlight
4659 help-echo "mouse-2: go to this URL"))))
4661 (set-buffer-modified-p nil))))
4663 ;;; Speedbar support:
4664 ;; These functions permit speedbar to display the "tags" in the
4665 ;; current Info node.
4666 (eval-when-compile (require 'speedbar))
4668 (defvar Info-speedbar-key-map nil
4669 "Keymap used when in the info display mode.")
4671 (defun Info-install-speedbar-variables ()
4672 "Install those variables used by speedbar to enhance Info."
4673 (if Info-speedbar-key-map
4675 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
4677 ;; Basic tree features
4678 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
4679 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
4680 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
4681 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
4684 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
4685 Info-speedbar-key-map
4686 Info-speedbar-hierarchy-buttons)))
4688 (defvar Info-speedbar-menu-items
4689 '(["Browse Node" speedbar-edit-line t]
4690 ["Expand Node" speedbar-expand-line
4691 (save-excursion (beginning-of-line)
4692 (looking-at "[0-9]+: *.\\+. "))]
4693 ["Contract Node" speedbar-contract-line
4694 (save-excursion (beginning-of-line)
4695 (looking-at "[0-9]+: *.-. "))]
4697 "Additional menu-items to add to speedbar frame.")
4699 ;; Make sure our special speedbar major mode is loaded
4700 (if (featurep 'speedbar)
4701 (Info-install-speedbar-variables)
4702 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4704 ;;; Info hierarchy display method
4706 (defun Info-speedbar-browser ()
4707 "Initialize speedbar to display an Info node browser.
4708 This will add a speedbar major display mode."
4711 ;; Make sure that speedbar is active
4712 (speedbar-frame-mode 1)
4713 ;; Now, throw us into Info mode on speedbar.
4714 (speedbar-change-initial-expansion-list "Info")
4717 (defun Info-speedbar-hierarchy-buttons (directory depth &optional node)
4718 "Display an Info directory hierarchy in speedbar.
4719 DIRECTORY is the current directory in the attached frame.
4720 DEPTH is the current indentation depth.
4721 NODE is an optional argument that is used to represent the
4722 specific node to expand."
4724 (save-excursion (goto-char (point-min))
4725 (let ((case-fold-search t))
4726 (looking-at "Info Nodes:"))))
4727 ;; Update our "current node" maybe?
4729 ;; We cannot use the generic list code, that depends on all leaves
4730 ;; being known at creation time.
4732 (speedbar-with-writable (insert "Info Nodes:\n")))
4733 (let ((completions nil))
4734 (speedbar-select-attached-frame)
4735 (save-window-excursion
4737 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
4738 (select-frame (speedbar-current-frame))
4740 (speedbar-with-writable
4741 (dolist (completion completions)
4742 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
4745 'Info-speedbar-goto-node
4751 (defun Info-speedbar-goto-node (text node indent)
4752 "When user clicks on TEXT, go to an info NODE.
4753 The INDENT level is ignored."
4754 (speedbar-select-attached-frame)
4755 (let* ((buff (or (get-buffer "*info*")
4756 (progn (info) (get-buffer "*info*"))))
4757 (bwin (get-buffer-window buff 0)))
4760 (select-window bwin)
4761 (raise-frame (window-frame bwin)))
4762 (if speedbar-power-click
4763 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
4764 (speedbar-select-attached-frame)
4765 (switch-to-buffer buff)))
4766 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4767 (error "Invalid node %s" node)
4768 (Info-find-node (match-string 1 node) (match-string 2 node))
4769 ;; If we do a find-node, and we were in info mode, restore
4770 ;; the old default method. Once we are in info mode, it makes
4771 ;; sense to return to whatever method the user was using before.
4772 (if (string= speedbar-initial-expansion-list-name "Info")
4773 (speedbar-change-initial-expansion-list
4774 speedbar-previously-used-expansion-list-name)))))
4776 (defun Info-speedbar-expand-node (text token indent)
4777 "Expand the node the user clicked on.
4778 TEXT is the text of the button we clicked on, a + or - item.
4779 TOKEN is data related to this node (NAME . FILE).
4780 INDENT is the current indentation depth."
4781 (cond ((string-match "+" text) ;we have to expand this file
4782 (speedbar-change-expand-button-char ?-)
4783 (if (speedbar-with-writable
4785 (end-of-line) (forward-char 1)
4786 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4787 (speedbar-change-expand-button-char ?-)
4788 (speedbar-change-expand-button-char ??)))
4789 ((string-match "-" text) ;we have to contract this node
4790 (speedbar-change-expand-button-char ?+)
4791 (speedbar-delete-subblock indent))
4792 (t (error "Ooops... not sure what to do")))
4793 (speedbar-center-buffer-smartly))
4795 (defun Info-speedbar-fetch-file-nodes (nodespec)
4796 "Fetch the subnodes from the info NODESPEC.
4797 NODESPEC is a string of the form: (file)node."
4798 ;; Set up a buffer we can use to fake-out Info.
4799 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
4800 (if (not (equal major-mode 'Info-mode))
4802 ;; Get the node into this buffer
4803 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4804 (error "Invalid node specification %s" nodespec)
4805 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4806 ;; Scan the created buffer
4807 (goto-char (point-min))
4808 (let ((completions nil)
4809 (case-fold-search t)
4810 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4811 (match-string 1 nodespec))))
4812 ;; Always skip the first one...
4813 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4814 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4815 (let ((name (match-string 1)))
4817 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4819 (if (looking-at " *\\(([^)]+)\\)\\.")
4820 (concat (match-string 1) "Top")
4821 (concat "(" thisfile ")"
4822 (if (looking-at " \\([^.]+\\).")
4826 (nreverse completions))))
4828 ;;; Info mode node listing
4829 ;; This is called by `speedbar-add-localized-speedbar-support'
4830 (defun Info-speedbar-buttons (buffer)
4831 "Create a speedbar display to help navigation in an Info file.
4832 BUFFER is the buffer speedbar is requesting buttons for."
4833 (if (save-excursion (goto-char (point-min))
4834 (let ((case-fold-search t))
4835 (not (looking-at "Info Nodes:"))))
4837 (Info-speedbar-hierarchy-buttons nil 0))
4839 (dolist (mess '("^First node in file$"
4840 "^No `.*' in index$"
4841 "^No cross-reference named"
4842 "^No cross.references in this node$"
4843 "^No current Info node$"
4844 "^No menu in this node$"
4845 "^No more items in menu$"
4847 "^No pointer \\(?:forward\\|backward\\) from this node$"
4848 "^No previous `i' command$"
4849 "^No previous items in menu$"
4850 "^No previous nodes$"
4851 "^No such item in menu$"
4852 "^No such node or anchor"
4854 "^Point neither on reference nor in menu item description$"
4855 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4857 (add-to-list 'debug-ignored-errors mess))
4859 ;;;; Desktop support
4861 (defun Info-desktop-buffer-misc-data (desktop-dirname)
4862 "Auxiliary information to be saved in desktop file."
4863 (list Info-current-file
4865 ;; Additional data as an association list.
4868 (cons 'history Info-history))
4869 (and (Info-virtual-fun
4870 'slow Info-current-file Info-current-node)
4873 (defun Info-restore-desktop-buffer (desktop-buffer-file-name
4875 desktop-buffer-misc)
4876 "Restore an Info buffer specified in a desktop file."
4877 (let* ((file (nth 0 desktop-buffer-misc))
4878 (node (nth 1 desktop-buffer-misc))
4879 (data (nth 2 desktop-buffer-misc))
4880 (hist (assq 'history data))
4881 (slow (assq 'slow data)))
4882 ;; Don't restore nodes slow to regenerate.
4884 (when (and file node)
4885 (when desktop-buffer-name
4886 (set-buffer (get-buffer-create desktop-buffer-name))
4888 (Info-find-node file node)
4890 (setq Info-history (cdr hist)))
4891 (current-buffer)))))
4893 (add-to-list 'desktop-buffer-mode-handlers
4894 '(Info-mode . Info-restore-desktop-buffer))
4896 ;;;; Bookmark support
4897 (declare-function bookmark-make-record-default "bookmark" (&optional pos-only))
4898 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
4899 (declare-function bookmark-default-handler "bookmark" (bmk))
4900 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
4902 (defun Info-bookmark-make-record ()
4903 "This implements the `bookmark-make-record-function' type (which see)
4905 `(,Info-current-node
4906 ,@(bookmark-make-record-default 'point-only)
4907 (filename . ,Info-current-file)
4908 (info-node . ,Info-current-node)
4909 (handler . Info-bookmark-jump)))
4912 (defun Info-bookmark-jump (bmk)
4913 "This implements the `handler' function interface for the record
4914 type returned by `Info-bookmark-make-record', which see."
4915 (let* ((file (bookmark-prop-get bmk 'filename))
4916 (info-node (bookmark-prop-get bmk 'info-node))
4917 (buf (save-window-excursion ;FIXME: doesn't work with frames!
4918 (Info-find-node file info-node) (current-buffer))))
4919 ;; Use bookmark-default-handler to move to the appropriate location
4921 (bookmark-default-handler
4922 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
4926 ;; arch-tag: f2480fe2-2139-40c1-a49b-6314991164ac
4927 ;;; info.el ends here