* variables.texi (File Local Variables): More hack-local-variables details.
[emacs.git] / lisp / info.el
blob796fd7e2256797ff9e81980f8ee9deb09a5e9942
1 ;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985-1986, 1992-2011 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: help
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; Note that nowadays we expect Info files to be made using makeinfo.
26 ;; In particular we make these assumptions:
27 ;; - a menu item MAY contain colons but not colon-space ": "
28 ;; - a menu item ending with ": " (but not ":: ") is an index entry
29 ;; - a node name MAY NOT contain a colon
30 ;; This distinction is to support indexing of computer programming
31 ;; language terms that may contain ":" but not ": ".
33 ;;; Code:
35 (eval-when-compile (require 'jka-compr) (require 'cl))
37 (defgroup info nil
38 "Info subsystem."
39 :group 'help
40 :group 'docs)
43 (defvar Info-history nil
44 "Stack of Info nodes user has visited.
45 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
47 (defvar Info-history-forward nil
48 "Stack of Info nodes user has visited with `Info-history-back' command.
49 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
51 (defvar Info-history-list nil
52 "List of all Info nodes user has visited.
53 Each element of the list is a list (FILENAME NODENAME).")
55 (defcustom Info-enable-edit nil
56 "Non-nil means the \\<Info-mode-map>\\[Info-edit] command in Info can edit the current node.
57 This is convenient if you want to write Info files by hand.
58 However, we recommend that you not do this.
59 It is better to write a Texinfo file and generate the Info file from that,
60 because that gives you a printed manual as well."
61 :type 'boolean
62 :group 'info)
64 (defvar Info-enable-active-nodes nil
65 "Non-nil allows Info to execute Lisp code associated with nodes.
66 The Lisp code is executed when the node is selected.")
67 (put 'Info-enable-active-nodes 'risky-local-variable t)
69 (defface info-node
70 '((((class color) (background light)) :foreground "brown" :weight bold :slant italic)
71 (((class color) (background dark)) :foreground "white" :weight bold :slant italic)
72 (t :weight bold :slant italic))
73 "Face for Info node names."
74 :group 'info)
76 (defface info-title-1
77 '((((type tty pc) (class color) (background light))
78 :foreground "green" :weight bold)
79 (((type tty pc) (class color) (background dark))
80 :foreground "yellow" :weight bold)
81 (t :height 1.2 :inherit info-title-2))
82 "Face for info titles at level 1."
83 :group 'info)
84 (define-obsolete-face-alias 'Info-title-1-face 'info-title-1 "22.1")
86 (defface info-title-2
87 '((((type tty pc) (class color)) :foreground "lightblue" :weight bold)
88 (t :height 1.2 :inherit info-title-3))
89 "Face for info titles at level 2."
90 :group 'info)
91 (define-obsolete-face-alias 'Info-title-2-face 'info-title-2 "22.1")
93 (defface info-title-3
94 '((((type tty pc) (class color)) :weight bold)
95 (t :height 1.2 :inherit info-title-4))
96 "Face for info titles at level 3."
97 :group 'info)
98 (define-obsolete-face-alias 'Info-title-3-face 'info-title-3 "22.1")
100 (defface info-title-4
101 '((((type tty pc) (class color)) :weight bold)
102 (t :weight bold :inherit variable-pitch))
103 "Face for info titles at level 4."
104 :group 'info)
105 (define-obsolete-face-alias 'Info-title-4-face 'info-title-4 "22.1")
107 (defface info-menu-header
108 '((((type tty pc))
109 :underline t
110 :weight bold)
112 :inherit variable-pitch
113 :weight bold))
114 "Face for headers in Info menus."
115 :group 'info)
117 (defface info-menu-star
118 '((((class color)) :foreground "red1")
119 (t :underline t))
120 "Face for every third `*' in an Info menu."
121 :group 'info)
122 (define-obsolete-face-alias 'info-menu-5 'info-menu-star "22.1")
124 (defface info-xref
125 '((t :inherit link))
126 "Face for unvisited Info cross-references."
127 :group 'info)
129 (defface info-xref-visited
130 '((t :inherit (link-visited info-xref)))
131 "Face for visited Info cross-references."
132 :version "22.1"
133 :group 'info)
135 (defcustom Info-fontify-visited-nodes t
136 "Non-nil to fontify references to visited nodes in `info-xref-visited' face."
137 :version "22.1"
138 :type 'boolean
139 :group 'info)
141 (defcustom Info-fontify-maximum-menu-size 100000
142 "Maximum size of menu to fontify if `font-lock-mode' is non-nil.
143 Set to nil to disable node fontification."
144 :type 'integer
145 :group 'info)
147 (defcustom Info-use-header-line t
148 "Non-nil means to put the beginning-of-node links in an Emacs header-line.
149 A header-line does not scroll with the rest of the buffer."
150 :type 'boolean
151 :group 'info)
153 (defface info-header-xref
154 '((t :inherit info-xref))
155 "Face for Info cross-references in a node header."
156 :group 'info)
158 (defface info-header-node
159 '((t :inherit info-node))
160 "Face for Info nodes in a node header."
161 :group 'info)
163 (defvar Info-directory-list nil
164 "List of directories to search for Info documentation files.
165 If nil, meaning not yet initialized, Info uses the environment
166 variable INFOPATH to initialize it, or `Info-default-directory-list'
167 if there is no INFOPATH variable in the environment, or the
168 concatenation of the two if INFOPATH ends with a `path-separator'.
170 When `Info-directory-list' is initialized from the value of
171 `Info-default-directory-list', and Emacs is installed in one of the
172 standard directories, the directory of Info files that come with Emacs
173 is put last (so that local Info files override standard ones).
175 When `Info-directory-list' is initialized from the value of
176 `Info-default-directory-list', and Emacs is not installed in one
177 of the standard directories, the first element of the resulting
178 list is the directory where Emacs installs the Info files that
179 come with it. This is so that Emacs's own manual, which suits the
180 version of Emacs you are using, will always be found first. This
181 is useful when you install an experimental version of Emacs without
182 removing the standard installation.
184 If you want to override the order of directories in
185 `Info-default-directory-list', set INFOPATH in the environment.
187 If you run the Emacs executable from the `src' directory in the Emacs
188 source tree, and INFOPATH is not defined, the `info' directory in the
189 source tree is used as the first element of `Info-directory-list', in
190 place of the installation Info directory. This is useful when you run
191 a version of Emacs without installing it.")
193 (defcustom Info-additional-directory-list nil
194 "List of additional directories to search for Info documentation files.
195 These directories are searched after those in `Info-directory-list'."
196 :type '(repeat directory)
197 :group 'info)
199 (defcustom Info-scroll-prefer-subnodes nil
200 "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
202 If this is non-nil, and you scroll far enough in a node that its menu
203 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
204 moves to a subnode indicated by the following menu item. This means
205 that you visit a subnode before getting to the end of the menu.
207 Setting this option to nil results in behavior similar to the stand-alone
208 Info reader program, which visits the first subnode from the menu only
209 when you hit the end of the current node."
210 :version "22.1"
211 :type 'boolean
212 :group 'info)
214 (defcustom Info-hide-note-references t
215 "If non-nil, hide the tag and section reference in *note and * menu items.
216 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
217 If value is non-nil but not t or `hide', the reference section is still shown.
218 `nil' completely disables this feature. If this is non-nil, you might
219 want to set `Info-refill-paragraphs'."
220 :version "22.1"
221 :type '(choice (const :tag "No hiding" nil)
222 (const :tag "Replace tag and hide reference" t)
223 (const :tag "Hide tag and reference" hide)
224 (other :tag "Only replace tag" tag))
225 :group 'info)
227 (defcustom Info-refill-paragraphs nil
228 "If non-nil, attempt to refill paragraphs with hidden references.
229 This refilling may accidentally remove explicit line breaks in the Info
230 file, so be prepared for a few surprises if you enable this feature.
231 This only has an effect if `Info-hide-note-references' is non-nil."
232 :version "22.1"
233 :type 'boolean
234 :group 'info)
236 (defcustom Info-breadcrumbs-depth 4
237 "Depth of breadcrumbs to display.
238 0 means do not display breadcrumbs."
239 :version "23.1"
240 :type 'integer
241 :group 'info)
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 `]+'."
249 :type 'regexp
250 :group 'info)
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
260 search direction.
262 Setting this option to nil restores the default isearch behavior
263 with wrapping around the current Info node."
264 :version "22.1"
265 :type 'boolean
266 :group 'info)
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."
277 :type 'hook
278 :group 'info)
280 (defcustom Info-selection-hook nil
281 "Hooks run when `Info-select-node' is called."
282 :type 'hook
283 :group 'info)
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
338 to override it.")
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 function to call instead
347 of calling the default corresponding function to override it.")
349 (defvar Info-current-node-virtual nil
350 "Non-nil if the current Info node is virtual.")
352 (defun Info-virtual-file-p (filename)
353 "Check if Info file FILENAME is virtual."
354 (Info-virtual-fun 'find-file filename nil))
356 (defun Info-virtual-fun (op filename nodename)
357 "Find a function that handles operations on virtual manuals.
358 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
359 FILENAME is a virtual Info file name, NODENAME is a virtual Info
360 node name. Return a function found either in `Info-virtual-files'
361 or `Info-virtual-nodes'."
362 (or (and (stringp filename) ; some legacy code can still use a symbol
363 (cdr-safe (assoc op (assoc-default filename
364 Info-virtual-files
365 'string-match))))
366 (and (stringp nodename) ; some legacy code can still use a symbol
367 (cdr-safe (assoc op (assoc-default nodename
368 Info-virtual-nodes
369 'string-match))))))
371 (defun Info-virtual-call (virtual-fun &rest args)
372 "Call a function that handles operations on virtual manuals."
373 (when (functionp virtual-fun)
374 (or (apply virtual-fun args) t)))
377 (defvar Info-suffix-list
378 ;; The MS-DOS list should work both when long file names are
379 ;; supported (Windows 9X), and when only 8+3 file names are available.
380 (if (eq system-type 'ms-dos)
381 '( (".gz" . "gunzip")
382 (".z" . "gunzip")
383 (".bz2" . ("bzip2" "-dc"))
384 (".inz" . "gunzip")
385 (".igz" . "gunzip")
386 (".info.Z" . "gunzip")
387 (".info.gz" . "gunzip")
388 ("-info.Z" . "gunzip")
389 ("-info.gz" . "gunzip")
390 ("/index.gz" . "gunzip")
391 ("/index.z" . "gunzip")
392 (".inf" . nil)
393 (".info" . nil)
394 ("-info" . nil)
395 ("/index" . nil)
396 ("" . nil))
397 '( (".info.Z" . "uncompress")
398 (".info.Y" . "unyabba")
399 (".info.gz" . "gunzip")
400 (".info.z" . "gunzip")
401 (".info.bz2" . ("bzip2" "-dc"))
402 (".info.xz" . "unxz")
403 (".info" . nil)
404 ("-info.Z" . "uncompress")
405 ("-info.Y" . "unyabba")
406 ("-info.gz" . "gunzip")
407 ("-info.bz2" . ("bzip2" "-dc"))
408 ("-info.z" . "gunzip")
409 ("-info.xz" . "unxz")
410 ("-info" . nil)
411 ("/index.Z" . "uncompress")
412 ("/index.Y" . "unyabba")
413 ("/index.gz" . "gunzip")
414 ("/index.z" . "gunzip")
415 ("/index.bz2" . ("bzip2" "-dc"))
416 ("/index.xz" . "unxz")
417 ("/index" . nil)
418 (".Z" . "uncompress")
419 (".Y" . "unyabba")
420 (".gz" . "gunzip")
421 (".z" . "gunzip")
422 (".bz2" . ("bzip2" "-dc"))
423 (".xz" . "unxz")
424 ("" . nil)))
425 "List of file name suffixes and associated decoding commands.
426 Each entry should be (SUFFIX . STRING); the file is given to
427 the command as standard input.
429 STRING may be a list of strings. In that case, the first element is
430 the command name, and the rest are arguments to that command.
432 If STRING is nil, no decoding is done.
433 Because the SUFFIXes are tried in order, the empty string should
434 be last in the list.")
436 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
437 ;; First, on MS-DOS with no long file names support, delete some of
438 ;; the extension in FILENAME to make room.
439 (defun info-insert-file-contents-1 (filename suffix lfn)
440 (if lfn ; long file names are supported
441 (concat filename suffix)
442 (let* ((sans-exts (file-name-sans-extension filename))
443 ;; How long is the extension in FILENAME (not counting the dot).
444 (ext-len (max 0 (- (length filename) (length sans-exts) 1)))
445 ext-left)
446 ;; SUFFIX starts with a dot. If FILENAME already has one,
447 ;; get rid of the one in SUFFIX (unless suffix is empty).
448 (or (and (<= ext-len 0)
449 (not (eq (aref filename (1- (length filename))) ?.)))
450 (= (length suffix) 0)
451 (setq suffix (substring suffix 1)))
452 ;; How many chars of that extension should we keep?
453 (setq ext-left (min ext-len (max 0 (- 3 (length suffix)))))
454 ;; Get rid of the rest of the extension, and add SUFFIX.
455 (concat (substring filename 0 (- (length filename)
456 (- ext-len ext-left)))
457 suffix))))
459 (defun info-file-exists-p (filename)
460 (and (file-exists-p filename)
461 (not (file-directory-p filename))))
463 (defun info-insert-file-contents (filename &optional visit)
464 "Insert the contents of an Info file in the current buffer.
465 Do the right thing if the file has been compressed or zipped."
466 (let* ((tail Info-suffix-list)
467 (lfn (if (fboundp 'msdos-long-file-names)
468 (msdos-long-file-names)
470 (check-short (and (fboundp 'msdos-long-file-names)
471 lfn))
472 fullname decoder done)
473 (if (info-file-exists-p filename)
474 ;; FILENAME exists--see if that name contains a suffix.
475 ;; If so, set DECODE accordingly.
476 (progn
477 (while (and tail
478 (not (string-match
479 (concat (regexp-quote (car (car tail))) "$")
480 filename)))
481 (setq tail (cdr tail)))
482 (setq fullname filename
483 decoder (cdr (car tail))))
484 ;; Try adding suffixes to FILENAME and see if we can find something.
485 (while (and tail (not done))
486 (setq fullname (info-insert-file-contents-1 filename
487 (car (car tail)) lfn))
488 (if (info-file-exists-p fullname)
489 (setq done t
490 ;; If we found a file with a suffix, set DECODER
491 ;; according to the suffix.
492 decoder (cdr (car tail)))
493 ;; When the MS-DOS port runs on Windows, we need to check
494 ;; the short variant of a long file name as well.
495 (when check-short
496 (setq fullname (info-insert-file-contents-1 filename
497 (car (car tail)) nil))
498 (if (info-file-exists-p fullname)
499 (setq done t
500 decoder (cdr (car tail))))))
501 (setq tail (cdr tail)))
502 (or tail
503 (error "Can't find %s or any compressed version of it" filename)))
504 ;; check for conflict with jka-compr
505 (if (and (jka-compr-installed-p)
506 (jka-compr-get-compression-info fullname))
507 (setq decoder nil))
508 (if decoder
509 (progn
510 (insert-file-contents-literally fullname visit)
511 (let ((inhibit-read-only t)
512 (coding-system-for-write 'no-conversion)
513 (inhibit-null-byte-detection t) ; Index nodes include null bytes
514 (default-directory (or (file-name-directory fullname)
515 default-directory)))
516 (or (consp decoder)
517 (setq decoder (list decoder)))
518 (apply 'call-process-region (point-min) (point-max)
519 (car decoder) t t nil (cdr decoder))))
520 (let ((inhibit-null-byte-detection t)) ; Index nodes include null bytes
521 (insert-file-contents fullname visit)))))
523 (defun Info-file-supports-index-cookies (&optional file)
524 "Return non-nil value if FILE supports Info index cookies.
525 Info index cookies were first introduced in 4.7, and all later
526 makeinfo versions output them in index nodes, so we can rely
527 solely on the makeinfo version. This function caches the information
528 in `Info-file-supports-index-cookies-list'."
529 (or file (setq file Info-current-file))
530 (or (assoc file Info-file-supports-index-cookies-list)
531 ;; Skip virtual Info files
532 (and (or (not (stringp file))
533 (Info-virtual-file-p file))
534 (setq Info-file-supports-index-cookies-list
535 (cons (cons file nil) Info-file-supports-index-cookies-list)))
536 (save-excursion
537 (let ((found nil))
538 (goto-char (point-min))
539 (condition-case ()
540 (if (and (re-search-forward
541 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
542 (line-beginning-position 3) t)
543 (not (version< (match-string 1) "4.7")))
544 (setq found t))
545 (error nil))
546 (setq Info-file-supports-index-cookies-list
547 (cons (cons file found) Info-file-supports-index-cookies-list)))))
548 (cdr (assoc file Info-file-supports-index-cookies-list)))
551 (defun Info-default-dirs ()
552 (let ((source (expand-file-name "info/" source-directory))
553 (sibling (if installation-directory
554 (expand-file-name "info/" installation-directory)
555 (if invocation-directory
556 (let ((infodir (expand-file-name
557 "../share/info/"
558 invocation-directory)))
559 (if (file-exists-p infodir)
560 infodir
561 (setq infodir (expand-file-name
562 "../../../share/info/"
563 invocation-directory))
564 (and (file-exists-p infodir)
565 infodir))))))
566 alternative)
567 (setq alternative
568 (if (and sibling (file-exists-p sibling))
569 ;; Uninstalled, Emacs builddir != srcdir.
570 sibling
571 ;; Uninstalled, builddir == srcdir
572 source))
573 (if (or (member alternative Info-default-directory-list)
574 ;; On DOS/NT, we use movable executables always,
575 ;; and we must always find the Info dir at run time.
576 (if (memq system-type '(ms-dos windows-nt))
578 ;; Use invocation-directory for Info
579 ;; only if we used it for exec-directory also.
580 (not (string= exec-directory
581 (expand-file-name "lib-src/"
582 installation-directory))))
583 (not (file-exists-p alternative)))
584 Info-default-directory-list
585 ;; `alternative' contains the Info files that came with this
586 ;; version, so we should look there first. `Info-insert-dir'
587 ;; currently expects to find `alternative' first on the list.
588 (cons alternative
589 ;; Don't drop the last part, it might contain non-Emacs stuff.
590 ;; (reverse (cdr (reverse
591 Info-default-directory-list)))) ;; )))
593 (defun info-initialize ()
594 "Initialize `Info-directory-list', if that hasn't been done yet."
595 (unless Info-directory-list
596 (let ((path (getenv "INFOPATH"))
597 (sep (regexp-quote path-separator)))
598 (setq Info-directory-list
599 (prune-directory-list
600 (if path
601 (if (string-match-p (concat sep "\\'") path)
602 (append (split-string (substring path 0 -1) sep)
603 (Info-default-dirs))
604 (split-string path sep))
605 (Info-default-dirs)))))))
607 ;;;###autoload
608 (defun info-other-window (&optional file-or-node)
609 "Like `info' but show the Info buffer in another window."
610 (interactive (if current-prefix-arg
611 (list (read-file-name "Info file name: " nil nil t))))
612 (let (same-window-buffer-names same-window-regexps)
613 (info file-or-node)))
615 ;;;###autoload (add-hook 'same-window-regexps (purecopy "\\*info\\*\\(\\|<[0-9]+>\\)"))
617 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
618 ;;;###autoload
619 (defun info (&optional file-or-node buffer)
620 "Enter Info, the documentation browser.
621 Optional argument FILE-OR-NODE specifies the file to examine;
622 the default is the top-level directory of Info.
623 Called from a program, FILE-OR-NODE may specify an Info node of the form
624 `(FILENAME)NODENAME'.
625 Optional argument BUFFER specifies the Info buffer name;
626 the default buffer name is *info*. If BUFFER exists,
627 just switch to BUFFER. Otherwise, create a new buffer
628 with the top-level Info directory.
630 In interactive use, a non-numeric prefix argument directs
631 this command to read a file name from the minibuffer.
632 A numeric prefix argument selects an Info buffer with the prefix number
633 appended to the Info buffer name.
635 The search path for Info files is in the variable `Info-directory-list'.
636 The top-level Info directory is made by combining all the files named `dir'
637 in all the directories in that path.
639 See a list of available Info commands in `Info-mode'."
640 (interactive (list
641 (if (and current-prefix-arg (not (numberp current-prefix-arg)))
642 (read-file-name "Info file name: " nil nil t))
643 (if (numberp current-prefix-arg)
644 (format "*info*<%s>" current-prefix-arg))))
645 (pop-to-buffer (or buffer "*info*"))
646 (if (and buffer (not (eq major-mode 'Info-mode)))
647 (Info-mode))
648 (if file-or-node
649 ;; If argument already contains parentheses, don't add another set
650 ;; since the argument will then be parsed improperly. This also
651 ;; has the added benefit of allowing node names to be included
652 ;; following the parenthesized filename.
653 (Info-goto-node
654 (if (and (stringp file-or-node) (string-match "(.*)" file-or-node))
655 file-or-node
656 (concat "(" file-or-node ")")))
657 (if (and (zerop (buffer-size))
658 (null Info-history))
659 ;; If we just created the Info buffer, go to the directory.
660 (Info-directory))))
662 ;;;###autoload
663 (defun info-emacs-manual ()
664 "Display the Emacs manual in Info mode."
665 (interactive)
666 (info "emacs"))
668 ;;;###autoload
669 (defun info-standalone ()
670 "Run Emacs as a standalone Info reader.
671 Usage: emacs -f info-standalone [filename]
672 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
673 (setq Info-standalone t)
674 (if (and command-line-args-left
675 (not (string-match "^-" (car command-line-args-left))))
676 (condition-case err
677 (progn
678 (info (car command-line-args-left))
679 (setq command-line-args-left (cdr command-line-args-left)))
680 (error (send-string-to-terminal
681 (format "%s\n" (if (eq (car-safe err) 'error)
682 (nth 1 err) err)))
683 (save-buffers-kill-emacs)))
684 (info)))
686 ;; See if the accessible portion of the buffer begins with a node
687 ;; delimiter, and the node header line which follows matches REGEXP.
688 ;; Typically, this test will be followed by a loop that examines the
689 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
690 ;; to have the overhead of this special test inside the loop.
692 ;; This function changes match-data, but supposedly the caller might
693 ;; want to use the results of re-search-backward.
695 ;; The return value is the value of point at the beginning of matching
696 ;; REGEXP, if the function succeeds, nil otherwise.
697 (defun Info-node-at-bob-matching (regexp)
698 (and (bobp) ; are we at beginning of buffer?
699 (looking-at "\^_") ; does it begin with node delimiter?
700 (let (beg)
701 (forward-line 1)
702 (setq beg (point))
703 (forward-line 1) ; does the line after delimiter match REGEXP?
704 (re-search-backward regexp beg t))))
706 (defun Info-find-file (filename &optional noerror)
707 "Return expanded FILENAME, or t if FILENAME is \"dir\".
708 Optional second argument NOERROR, if t, means if file is not found
709 just return nil (no error)."
710 ;; Convert filename to lower case if not found as specified.
711 ;; Expand it.
712 (cond
713 ((Info-virtual-call
714 (Info-virtual-fun 'find-file filename nil)
715 filename noerror))
716 ((stringp filename)
717 (let (temp temp-downcase found)
718 (setq filename (substitute-in-file-name filename))
719 (let ((dirs (if (string-match "^\\./" filename)
720 ;; If specified name starts with `./'
721 ;; then just try current directory.
722 '("./")
723 (if (file-name-absolute-p filename)
724 ;; No point in searching for an
725 ;; absolute file name
726 '(nil)
727 (if Info-additional-directory-list
728 (append Info-directory-list
729 Info-additional-directory-list)
730 Info-directory-list)))))
731 ;; Search the directory list for file FILENAME.
732 (while (and dirs (not found))
733 (setq temp (expand-file-name filename (car dirs)))
734 (setq temp-downcase
735 (expand-file-name (downcase filename) (car dirs)))
736 ;; Try several variants of specified name.
737 (let ((suffix-list Info-suffix-list)
738 (lfn (if (fboundp 'msdos-long-file-names)
739 (msdos-long-file-names)
740 t)))
741 (while (and suffix-list (not found))
742 (cond ((info-file-exists-p
743 (info-insert-file-contents-1
744 temp (car (car suffix-list)) lfn))
745 (setq found temp))
746 ((info-file-exists-p
747 (info-insert-file-contents-1
748 temp-downcase (car (car suffix-list)) lfn))
749 (setq found temp-downcase))
750 ((and (fboundp 'msdos-long-file-names)
752 (info-file-exists-p
753 (info-insert-file-contents-1
754 temp (car (car suffix-list)) nil)))
755 (setq found temp)))
756 (setq suffix-list (cdr suffix-list))))
757 (setq dirs (cdr dirs))))
758 (if found
759 (setq filename found)
760 (if noerror
761 (setq filename nil)
762 (error "Info file %s does not exist" filename)))
763 filename))))
765 (defun Info-find-node (filename nodename &optional no-going-back)
766 "Go to an Info node specified as separate FILENAME and NODENAME.
767 NO-GOING-BACK is non-nil if recovering from an error in this function;
768 it says do not attempt further (recursive) error recovery."
769 (info-initialize)
770 (setq filename (Info-find-file filename))
771 ;; Go into Info buffer.
772 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
773 ;; Record the node we are leaving, if we were in one.
774 (and (not no-going-back)
775 Info-current-file
776 (push (list Info-current-file Info-current-node (point))
777 Info-history))
778 (Info-find-node-2 filename nodename no-going-back))
780 ;;;###autoload
781 (defun Info-on-current-buffer (&optional nodename)
782 "Use Info mode to browse the current Info buffer.
783 With a prefix arg, this queries for the node name to visit first;
784 otherwise, that defaults to `Top'."
785 (interactive
786 (list (if current-prefix-arg
787 (completing-read "Node name: " (Info-build-node-completions)
788 nil t "Top"))))
789 (unless nodename (setq nodename "Top"))
790 (info-initialize)
791 (Info-mode)
792 (set (make-local-variable 'Info-current-file)
793 (or buffer-file-name
794 ;; If called on a non-file buffer, make a fake file name.
795 (concat default-directory (buffer-name))))
796 (Info-find-node-2 nil nodename))
798 ;; It's perhaps a bit nasty to kill the *info* buffer to force a re-read,
799 ;; but at least it keeps this routine (which is for makeinfo-buffer and
800 ;; Info-revert-buffer-function) out of the way of normal operations.
802 (defun Info-revert-find-node (filename nodename)
803 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
804 When *info* is already displaying FILENAME and NODENAME, the window position
805 is preserved, if possible."
806 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
807 (let ((old-filename Info-current-file)
808 (old-nodename Info-current-node)
809 (old-buffer-name (buffer-name))
810 (pcolumn (current-column))
811 (pline (count-lines (point-min) (line-beginning-position)))
812 (wline (count-lines (point-min) (window-start)))
813 (old-history-forward Info-history-forward)
814 (old-history Info-history)
815 (new-history (and Info-current-file
816 (list Info-current-file Info-current-node (point)))))
817 (kill-buffer (current-buffer))
818 (pop-to-buffer (or old-buffer-name "*info*"))
819 (Info-mode)
820 (Info-find-node filename nodename)
821 (setq Info-history-forward old-history-forward)
822 (setq Info-history old-history)
823 (if (and (equal old-filename Info-current-file)
824 (equal old-nodename Info-current-node))
825 (progn
826 ;; note goto-line is no good, we want to measure from point-min
827 (goto-char (point-min))
828 (forward-line wline)
829 (set-window-start (selected-window) (point))
830 (goto-char (point-min))
831 (forward-line pline)
832 (move-to-column pcolumn))
833 ;; only add to the history when coming from a different file+node
834 (if new-history
835 (setq Info-history (cons new-history Info-history))))))
837 (defun Info-revert-buffer-function (_ignore-auto noconfirm)
838 (when (or noconfirm (y-or-n-p "Revert info buffer? "))
839 (Info-revert-find-node Info-current-file Info-current-node)
840 (message "Reverted %s" Info-current-file)))
842 (defun Info-find-in-tag-table-1 (marker regexp case-fold)
843 "Find a node in a tag table.
844 MARKER specifies the buffer and position to start searching at.
845 REGEXP is a regular expression matching nodes or references. Its first
846 group should match `Node:' or `Ref:'.
847 CASE-FOLD t means search for a case-insensitive match.
848 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
849 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
850 where the match was found, and MODE is `major-mode' of the buffer in
851 which the match was found."
852 (let ((case-fold-search case-fold))
853 (with-current-buffer (marker-buffer marker)
854 (goto-char marker)
856 ;; Search tag table
857 (beginning-of-line)
858 (when (re-search-forward regexp nil t)
859 (list (string-equal "Ref:" (match-string 1))
860 (+ (point-min) (read (current-buffer)))
861 major-mode)))))
863 (defun Info-find-in-tag-table (marker regexp)
864 "Find a node in a tag table.
865 MARKER specifies the buffer and position to start searching at.
866 REGEXP is a regular expression matching nodes or references. Its first
867 group should match `Node:' or `Ref:'.
868 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
869 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
870 where the match was found, and MODE is `major-mode' of the buffer in
871 which the match was found.
872 This function tries to find a case-sensitive match first, then a
873 case-insensitive match is tried."
874 (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
875 (when (null (car result))
876 (setq result (Info-find-in-tag-table-1 marker regexp t)))
877 result))
879 (defun Info-find-node-in-buffer-1 (regexp case-fold)
880 "Find a node or anchor in the current buffer.
881 REGEXP is a regular expression matching nodes or references. Its first
882 group should match `Node:' or `Ref:'.
883 CASE-FOLD t means search for a case-insensitive match.
884 Value is the position at which a match was found, or nil if not found."
885 (let ((case-fold-search case-fold)
886 found)
887 (save-excursion
888 (if (Info-node-at-bob-matching regexp)
889 (setq found (point))
890 (while (and (not found)
891 (search-forward "\n\^_" nil t))
892 (forward-line 1)
893 (let ((beg (point)))
894 (forward-line 1)
895 (if (re-search-backward regexp beg t)
896 (setq found (line-beginning-position)))))))
897 found))
899 (defun Info-find-node-in-buffer (regexp)
900 "Find a node or anchor in the current buffer.
901 REGEXP is a regular expression matching nodes or references. Its first
902 group should match `Node:' or `Ref:'.
903 Value is the position at which a match was found, or nil if not found.
904 This function looks for a case-sensitive match first. If none is found,
905 a case-insensitive match is tried."
906 (or (Info-find-node-in-buffer-1 regexp nil)
907 (Info-find-node-in-buffer-1 regexp t)))
909 (defun Info-find-node-2 (filename nodename &optional no-going-back)
910 (buffer-disable-undo (current-buffer))
911 (or (eq major-mode 'Info-mode)
912 (Info-mode))
913 (widen)
914 (setq Info-current-node nil)
915 (unwind-protect
916 (let ((case-fold-search t)
917 (virtual-fun (Info-virtual-fun 'find-node
918 (or filename Info-current-file)
919 nodename))
920 anchorpos)
921 (cond
922 ((functionp virtual-fun)
923 (let ((filename (or filename Info-current-file)))
924 (setq buffer-read-only nil)
925 (setq Info-current-file filename
926 Info-current-subfile nil
927 Info-current-file-completions nil
928 buffer-file-name nil)
929 (erase-buffer)
930 (Info-virtual-call virtual-fun filename nodename no-going-back)
931 (set-marker Info-tag-table-marker nil)
932 (setq buffer-read-only t)
933 (set-buffer-modified-p nil)
934 (set (make-local-variable 'Info-current-node-virtual) t)))
935 ((not (and
936 ;; Reread a file when moving from a virtual node.
937 (not Info-current-node-virtual)
938 (or (null filename)
939 (equal Info-current-file filename))))
940 ;; Switch files if necessary
941 (let ((inhibit-read-only t))
942 (when Info-current-node-virtual
943 ;; When moving from a virtual node.
944 (set (make-local-variable 'Info-current-node-virtual) nil)
945 (if (null filename)
946 (setq filename Info-current-file)))
947 (setq Info-current-file nil
948 Info-current-subfile nil
949 Info-current-file-completions nil
950 buffer-file-name nil)
951 (erase-buffer)
952 (info-insert-file-contents filename nil)
953 (setq default-directory (file-name-directory filename))
954 (set-buffer-modified-p nil)
955 (set (make-local-variable 'Info-file-supports-index-cookies)
956 (Info-file-supports-index-cookies filename))
958 ;; See whether file has a tag table. Record the location if yes.
959 (goto-char (point-max))
960 (forward-line -8)
961 ;; Use string-equal, not equal, to ignore text props.
962 (if (not (or (string-equal nodename "*")
963 (not
964 (search-forward "\^_\nEnd tag table\n" nil t))))
965 (let (pos)
966 ;; We have a tag table. Find its beginning.
967 ;; Is this an indirect file?
968 (search-backward "\nTag table:\n")
969 (setq pos (point))
970 (if (save-excursion
971 (forward-line 2)
972 (looking-at "(Indirect)\n"))
973 ;; It is indirect. Copy it to another buffer
974 ;; and record that the tag table is in that buffer.
975 (let ((buf (current-buffer))
976 (tagbuf
977 (or Info-tag-table-buffer
978 (generate-new-buffer " *info tag table*"))))
979 (setq Info-tag-table-buffer tagbuf)
980 (with-current-buffer tagbuf
981 (buffer-disable-undo (current-buffer))
982 (setq case-fold-search t)
983 (erase-buffer)
984 (insert-buffer-substring buf))
985 (set-marker Info-tag-table-marker
986 (match-end 0) tagbuf))
987 (set-marker Info-tag-table-marker pos)))
988 (set-marker Info-tag-table-marker nil))
989 (setq Info-current-file filename)
992 ;; Use string-equal, not equal, to ignore text props.
993 (if (string-equal nodename "*")
994 (progn (setq Info-current-node nodename)
995 (Info-set-mode-line))
996 ;; Possibilities:
998 ;; 1. Anchor found in tag table
999 ;; 2. Anchor *not* in tag table
1001 ;; 3. Node found in tag table
1002 ;; 4. Node *not* found in tag table, but found in file
1003 ;; 5. Node *not* in tag table, and *not* in file
1005 ;; *Or* the same, but in an indirect subfile.
1007 ;; Search file for a suitable node.
1008 (let ((guesspos (point-min))
1009 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1010 (if (stringp nodename)
1011 (regexp-quote nodename)
1013 "\\) *[,\t\n\177]")))
1015 (catch 'foo
1017 ;; First, search a tag table, if any
1018 (when (marker-position Info-tag-table-marker)
1019 (let* ((m Info-tag-table-marker)
1020 (found (Info-find-in-tag-table m regexp)))
1022 (when found
1023 ;; FOUND is (ANCHOR POS MODE).
1024 (setq guesspos (nth 1 found))
1026 ;; If this is an indirect file, determine which
1027 ;; file really holds this node and read it in.
1028 (unless (eq (nth 2 found) 'Info-mode)
1029 ;; Note that the current buffer must be the
1030 ;; *info* buffer on entry to
1031 ;; Info-read-subfile. Thus the hackery above.
1032 (setq guesspos (Info-read-subfile guesspos)))
1034 ;; Handle anchor
1035 (when (nth 0 found)
1036 (goto-char (setq anchorpos guesspos))
1037 (throw 'foo t)))))
1039 ;; Else we may have a node, which we search for:
1040 (goto-char (max (point-min)
1041 (- (byte-to-position guesspos) 1000)))
1043 ;; Now search from our advised position (or from beg of
1044 ;; buffer) to find the actual node. First, check
1045 ;; whether the node is right where we are, in case the
1046 ;; buffer begins with a node.
1047 (let ((pos (Info-find-node-in-buffer regexp)))
1048 (when pos
1049 (goto-char pos)
1050 (throw 'foo t)))
1052 (when (string-match "\\([^.]+\\)\\." nodename)
1053 (let (Info-point-loc)
1054 (Info-find-node-2
1055 filename (match-string 1 nodename) no-going-back))
1056 (widen)
1057 (throw 'foo t))
1059 ;; No such anchor in tag table or node in tag table or file
1060 (error "No such node or anchor: %s" nodename))
1062 (Info-select-node)
1063 (goto-char (point-min))
1064 (forward-line 1) ; skip header line
1065 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1066 ;; (forward-line 1))
1068 (cond (anchorpos
1069 (let ((new-history (list Info-current-file
1070 (substring-no-properties nodename))))
1071 ;; Add anchors to the history too
1072 (setq Info-history-list
1073 (cons new-history
1074 (delete new-history Info-history-list))))
1075 (goto-char anchorpos))
1076 ((numberp Info-point-loc)
1077 (forward-line (- Info-point-loc 2))
1078 (setq Info-point-loc nil))
1079 ((stringp Info-point-loc)
1080 (Info-find-index-name Info-point-loc)
1081 (setq Info-point-loc nil))))))
1082 ;; If we did not finish finding the specified node,
1083 ;; go back to the previous one.
1084 (or Info-current-node no-going-back (null Info-history)
1085 (let ((hist (car Info-history)))
1086 (setq Info-history (cdr Info-history))
1087 (Info-find-node (nth 0 hist) (nth 1 hist) t)
1088 (goto-char (nth 2 hist))))))
1090 ;; Cache the contents of the (virtual) dir file, once we have merged
1091 ;; it for the first time, so we can save time subsequently.
1092 (defvar Info-dir-contents nil)
1094 ;; Cache for the directory we decided to use for the default-directory
1095 ;; of the merged dir text.
1096 (defvar Info-dir-contents-directory nil)
1098 ;; Record the file attributes of all the files from which we
1099 ;; constructed Info-dir-contents.
1100 (defvar Info-dir-file-attributes nil)
1102 (defvar Info-dir-file-name nil)
1104 ;; Construct the Info directory node by merging the files named `dir'
1105 ;; from various directories. Set the *info* buffer's
1106 ;; default-directory to the first directory we actually get any text
1107 ;; from.
1108 (defun Info-insert-dir ()
1109 (if (and Info-dir-contents Info-dir-file-attributes
1110 ;; Verify that none of the files we used has changed
1111 ;; since we used it.
1112 (eval (cons 'and
1113 (mapcar (lambda (elt)
1114 (let ((curr (file-attributes
1115 ;; Handle symlinks
1116 (file-truename (car elt)))))
1118 ;; Don't compare the access time.
1119 (if curr (setcar (nthcdr 4 curr) 0))
1120 (setcar (nthcdr 4 (cdr elt)) 0)
1121 (equal (cdr elt) curr)))
1122 Info-dir-file-attributes))))
1123 (progn
1124 (insert Info-dir-contents)
1125 (goto-char (point-min)))
1126 (let ((dirs (if Info-additional-directory-list
1127 (append Info-directory-list
1128 Info-additional-directory-list)
1129 Info-directory-list))
1130 (dir-file-attrs nil)
1131 ;; Bind this in case the user sets it to nil.
1132 (case-fold-search t)
1133 ;; This is set non-nil if we find a problem in some input files.
1134 problems
1135 buffers buffer others nodes dirs-done)
1137 ;; Search the directory list for the directory file.
1138 (while dirs
1139 (let ((truename (file-truename (expand-file-name (car dirs)))))
1140 (or (member truename dirs-done)
1141 (member (directory-file-name truename) dirs-done)
1142 ;; Try several variants of specified name.
1143 ;; Try upcasing, appending `.info', or both.
1144 (let* (file
1145 (attrs
1147 (progn (setq file (expand-file-name "dir" truename))
1148 (file-attributes file))
1149 (progn (setq file (expand-file-name "DIR" truename))
1150 (file-attributes file))
1151 (progn (setq file (expand-file-name "dir.info" truename))
1152 (file-attributes file))
1153 (progn (setq file (expand-file-name "DIR.INFO" truename))
1154 (file-attributes file)))))
1155 (setq dirs-done
1156 (cons truename
1157 (cons (directory-file-name truename)
1158 dirs-done)))
1159 (if attrs
1160 (with-current-buffer (generate-new-buffer " info dir")
1161 (or buffers
1162 (message "Composing main Info directory..."))
1163 (condition-case nil
1164 ;; Index nodes include null bytes. DIR
1165 ;; files should not have indices, but who
1166 ;; knows...
1167 (let ((inhibit-null-byte-detection t))
1168 (insert-file-contents file)
1169 (set (make-local-variable 'Info-dir-file-name)
1170 file)
1171 (push (current-buffer) buffers)
1172 (push (cons file attrs) dir-file-attrs))
1173 (error (kill-buffer (current-buffer))))))))
1174 (unless (cdr dirs)
1175 (set (make-local-variable 'Info-dir-contents-directory)
1176 (file-name-as-directory (car dirs))))
1177 (setq dirs (cdr dirs))))
1179 (or buffers
1180 (error "Can't find the Info directory node"))
1182 ;; Distinguish the dir file that comes with Emacs from all the
1183 ;; others. Yes, that is really what this is supposed to do.
1184 ;; The definition of `Info-directory-list' puts it first on that
1185 ;; list and so last in `buffers' at this point.
1186 (setq buffer (car (last buffers))
1187 others (delq buffer buffers))
1189 ;; Insert the entire original dir file as a start; note that we've
1190 ;; already saved its default directory to use as the default
1191 ;; directory for the whole concatenation.
1192 (save-excursion (insert-buffer-substring buffer))
1194 ;; Look at each of the other buffers one by one.
1195 (dolist (other others)
1196 (let (this-buffer-nodes)
1197 ;; In each, find all the menus.
1198 (with-current-buffer other
1199 (goto-char (point-min))
1200 ;; Find each menu, and add an elt to NODES for it.
1201 (while (re-search-forward "^\\* Menu:" nil t)
1202 (while (and (zerop (forward-line 1)) (eolp)))
1203 (let ((beg (point))
1204 nodename end)
1205 (re-search-backward "^\^_")
1206 (search-forward "Node: ")
1207 (setq nodename (Info-following-node-name))
1208 (search-forward "\n\^_" nil 'move)
1209 (beginning-of-line)
1210 (setq end (point))
1211 (push (list nodename other beg end) this-buffer-nodes)))
1212 (if (assoc-string "top" this-buffer-nodes t)
1213 (setq nodes (nconc this-buffer-nodes nodes))
1214 (setq problems t)
1215 (message "No `top' node in %s" Info-dir-file-name)))))
1216 ;; Add to the main menu a menu item for each other node.
1217 (re-search-forward "^\\* Menu:")
1218 (forward-line 1)
1219 (let ((menu-items '("top"))
1220 (end (save-excursion (search-forward "\^_" nil t) (point))))
1221 (dolist (node nodes)
1222 (let ((nodename (car node)))
1223 (save-excursion
1224 (or (member (downcase nodename) menu-items)
1225 (re-search-forward (concat "^\\* +"
1226 (regexp-quote nodename)
1227 "::")
1228 end t)
1229 (progn
1230 (insert "* " nodename "::" "\n")
1231 (push nodename menu-items)))))))
1232 ;; Now take each node of each of the other buffers
1233 ;; and merge it into the main buffer.
1234 (dolist (node nodes)
1235 (let ((case-fold-search t)
1236 (nodename (car node)))
1237 (goto-char (point-min))
1238 ;; Find the like-named node in the main buffer.
1239 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1240 (regexp-quote nodename)
1241 "[,\n\t]")
1242 nil t)
1243 (progn
1244 (search-forward "\n\^_" nil 'move)
1245 (beginning-of-line)
1246 (insert "\n"))
1247 ;; If none exists, add one.
1248 (goto-char (point-max))
1249 (insert "\^_\nFile: dir\tNode: " nodename "\n\n* Menu:\n\n"))
1250 ;; Merge the text from the other buffer's menu
1251 ;; into the menu in the like-named node in the main buffer.
1252 (apply 'insert-buffer-substring (cdr node))))
1253 (Info-dir-remove-duplicates)
1254 ;; Kill all the buffers we just made, including the special one excised.
1255 (mapc 'kill-buffer (cons buffer buffers))
1256 (goto-char (point-min))
1257 (if problems
1258 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1259 (message "Composing main Info directory...done"))
1260 (set (make-local-variable 'Info-dir-contents) (buffer-string))
1261 (set (make-local-variable 'Info-dir-file-attributes) dir-file-attrs)))
1262 (setq default-directory Info-dir-contents-directory))
1264 (defvar Info-streamline-headings
1265 '(("Emacs" . "Emacs")
1266 ("Programming" . "Programming")
1267 ("Libraries" . "Libraries")
1268 ("World Wide Web\\|Net Utilities" . "Net Utilities"))
1269 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1271 (defun Info-dir-remove-duplicates ()
1272 (let (limit)
1273 (goto-char (point-min))
1274 ;; Remove duplicate headings in the same menu.
1275 (while (search-forward "\n* Menu:" nil t)
1276 (setq limit (save-excursion (search-forward "\n\^_" nil t)))
1277 ;; Look for the next heading to unify.
1278 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1279 (let ((name (match-string 1))
1280 (start (match-beginning 0))
1281 (entries nil) re)
1282 ;; Check whether this heading should be streamlined.
1283 (save-match-data
1284 (dolist (x Info-streamline-headings)
1285 (when (string-match (car x) name)
1286 (setq name (cdr x))
1287 (setq re (car x)))))
1288 (if re (replace-match name t t nil 1))
1289 (goto-char (if (re-search-forward "^[^* \n\t]" limit t)
1290 (match-beginning 0)
1291 (or limit (point-max))))
1292 ;; Look for other headings of the same category and merge them.
1293 (save-excursion
1294 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t)
1295 (when (if re (save-match-data (string-match re (match-string 1)))
1296 (equal name (match-string 1)))
1297 (forward-line 0)
1298 ;; Delete redundant heading.
1299 (delete-region (match-beginning 0) (point))
1300 ;; Push the entries onto `text'.
1301 (push
1302 (delete-and-extract-region
1303 (point)
1304 (if (re-search-forward "^[^* \n\t]" nil t)
1305 (match-beginning 0)
1306 (or limit (point-max))))
1307 entries)
1308 (forward-line 0))))
1309 ;; Insert the entries just found.
1310 (while (= (line-beginning-position 0) (1- (point)))
1311 (backward-char))
1312 (dolist (entry (nreverse entries))
1313 (insert entry)
1314 (while (= (line-beginning-position 0) (1- (point)))
1315 (delete-region (1- (point)) (point))))
1317 ;; Now remove duplicate entries under the same heading.
1318 (let (seen)
1319 (save-restriction
1320 (narrow-to-region start (point))
1321 (goto-char (point-min))
1322 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil 'move)
1323 ;; Fold case straight away; `member-ignore-case' here wasteful.
1324 (let ((x (downcase (match-string 1))))
1325 (if (member x seen)
1326 (delete-region
1327 (match-beginning 0)
1328 (if (re-search-forward "^[^ \t]" nil 'move)
1329 (goto-char (match-beginning 0))
1330 (point-max)))
1331 (push x seen)))))))))))
1333 ;; Note that on entry to this function the current-buffer must be the
1334 ;; *info* buffer; not the info tags buffer.
1335 (defun Info-read-subfile (nodepos)
1336 ;; NODEPOS is either a position (in the Info file as a whole,
1337 ;; not relative to a subfile) or the name of a subfile.
1338 (let (lastfilepos
1339 lastfilename)
1340 (if (numberp nodepos)
1341 (with-current-buffer (marker-buffer Info-tag-table-marker)
1342 (goto-char (point-min))
1343 (or (looking-at "\^_")
1344 (search-forward "\n\^_"))
1345 (forward-line 2)
1346 (catch 'foo
1347 (while (not (looking-at "\^_"))
1348 (if (not (eolp))
1349 (let ((beg (point))
1350 thisfilepos thisfilename)
1351 (search-forward ": ")
1352 (setq thisfilename (buffer-substring beg (- (point) 2)))
1353 (setq thisfilepos (+ (point-min) (read (current-buffer))))
1354 ;; read in version 19 stops at the end of number.
1355 ;; Advance to the next line.
1356 (forward-line 1)
1357 (if (> thisfilepos nodepos)
1358 (throw 'foo t))
1359 (setq lastfilename thisfilename)
1360 (setq lastfilepos thisfilepos))
1361 (forward-line 1)))))
1362 (setq lastfilename nodepos)
1363 (setq lastfilepos 0))
1364 ;; Assume previous buffer is in Info-mode.
1365 ;; (set-buffer (get-buffer "*info*"))
1366 (or (equal Info-current-subfile lastfilename)
1367 (let ((inhibit-read-only t))
1368 (setq buffer-file-name nil)
1369 (widen)
1370 (erase-buffer)
1371 (info-insert-file-contents lastfilename)
1372 (set-buffer-modified-p nil)
1373 (setq Info-current-subfile lastfilename)))
1374 ;; Widen in case we are in the same subfile as before.
1375 (widen)
1376 (goto-char (point-min))
1377 (if (looking-at "\^_")
1378 (forward-char 1)
1379 (search-forward "\n\^_"))
1380 (if (numberp nodepos)
1381 (+ (- nodepos lastfilepos) (point)))))
1383 (defun Info-unescape-quotes (value)
1384 "Unescape double quotes and backslashes in VALUE."
1385 (let ((start 0)
1386 (unquote value))
1387 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start)
1388 (setq unquote (replace-match "" t t unquote 1))
1389 (setq start (- (match-end 0) 1)))
1390 unquote))
1392 ;; As of Texinfo 4.6, makeinfo writes constructs like
1393 ;; \0\h[image param=value ...\h\0]
1394 ;; into the Info file for handling images.
1395 (defun Info-split-parameter-string (parameter-string)
1396 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
1397 PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
1398 If VALUE contains whitespace or double quotes, it must be quoted
1399 in double quotes and any double quotes or backslashes must be
1400 escaped (\\\",\\\\)."
1401 (let ((start 0)
1402 (parameter-alist))
1403 (while (string-match
1404 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1405 parameter-string start)
1406 (setq start (match-end 0))
1407 (push (cons (match-string 1 parameter-string)
1408 (or (match-string 2 parameter-string)
1409 (Info-unescape-quotes
1410 (match-string 3 parameter-string))))
1411 parameter-alist))
1412 parameter-alist))
1414 (defun Info-display-images-node ()
1415 "Display images in current node."
1416 (save-excursion
1417 (let ((inhibit-read-only t)
1418 (case-fold-search t))
1419 (goto-char (point-min))
1420 (while (re-search-forward
1421 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1422 nil t)
1423 (let* ((start (match-beginning 1))
1424 (parameter-alist (Info-split-parameter-string (match-string 2)))
1425 (src (cdr (assoc-string "src" parameter-alist))))
1426 (if (display-images-p)
1427 (let* ((image-file (if src (if (file-name-absolute-p src) src
1428 (concat default-directory src))
1429 ""))
1430 (image (if (file-exists-p image-file)
1431 (create-image image-file)
1432 "[broken image]")))
1433 (if (not (get-text-property start 'display))
1434 (add-text-properties
1435 start (point) `(display ,image rear-nonsticky (display)))))
1436 ;; text-only display, show alternative text if provided, or
1437 ;; otherwise a clue that there's meant to be a picture
1438 (delete-region start (point))
1439 (insert (or (cdr (assoc-string "text" parameter-alist))
1440 (cdr (assoc-string "alt" parameter-alist))
1441 (and src
1442 (concat "[image:" src "]"))
1443 "[image]"))))))
1444 (set-buffer-modified-p nil)))
1446 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1447 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1448 ;; including one optional trailing newline.
1449 (defun Info-hide-cookies-node ()
1450 "Hide unrecognized cookies in current node."
1451 (save-excursion
1452 (let ((inhibit-read-only t)
1453 (case-fold-search t))
1454 (goto-char (point-min))
1455 (while (re-search-forward
1456 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1457 nil t)
1458 (let* ((start (match-beginning 1)))
1459 (if (and (not (get-text-property start 'invisible))
1460 (not (get-text-property start 'display)))
1461 (put-text-property start (point) 'invisible t)))))
1462 (set-buffer-modified-p nil)))
1464 (defun Info-select-node ()
1465 "Select the Info node that point is in."
1466 ;; Bind this in case the user sets it to nil.
1467 (let ((case-fold-search t))
1468 (save-excursion
1469 ;; Find beginning of node.
1470 (if (search-backward "\n\^_" nil 'move)
1471 (forward-line 2)
1472 (if (looking-at "\^_")
1473 (forward-line 1)
1474 (signal 'search-failed (list "\n\^_"))))
1475 ;; Get nodename spelled as it is in the node.
1476 (re-search-forward "Node:[ \t]*")
1477 (setq Info-current-node
1478 (buffer-substring-no-properties (point)
1479 (progn
1480 (skip-chars-forward "^,\t\n")
1481 (point))))
1482 (Info-set-mode-line)
1483 ;; Find the end of it, and narrow.
1484 (beginning-of-line)
1485 (let (active-expression)
1486 ;; Narrow to the node contents
1487 (narrow-to-region (point)
1488 (if (re-search-forward "\n[\^_\f]" nil t)
1489 (prog1
1490 (1- (point))
1491 (if (looking-at "[\n\^_\f]*execute: ")
1492 (progn
1493 (goto-char (match-end 0))
1494 (setq active-expression
1495 (read (current-buffer))))))
1496 (point-max)))
1497 (if Info-enable-active-nodes (eval active-expression))
1498 ;; Add a new unique history item to full history list
1499 (let ((new-history (list Info-current-file Info-current-node)))
1500 (setq Info-history-list
1501 (cons new-history (delete new-history Info-history-list)))
1502 (setq Info-history-forward nil))
1503 (if (not (eq Info-fontify-maximum-menu-size nil))
1504 (Info-fontify-node))
1505 (Info-display-images-node)
1506 (Info-hide-cookies-node)
1507 (run-hooks 'Info-selection-hook)))))
1509 (defvar Info-mode-line-node-keymap
1510 (let ((map (make-sparse-keymap)))
1511 (define-key map [mode-line mouse-1] 'Info-mouse-scroll-up)
1512 (define-key map [mode-line mouse-3] 'Info-mouse-scroll-down)
1513 map)
1514 "Keymap to put on the Info node name in the mode line.")
1516 (defun Info-set-mode-line ()
1517 (setq mode-line-buffer-identification
1518 (nconc (propertized-buffer-identification "%b")
1519 (list
1520 (concat
1521 " ("
1522 (if (stringp Info-current-file)
1523 (replace-regexp-in-string
1524 "%" "%%" (file-name-nondirectory Info-current-file))
1525 (format "*%S*" Info-current-file))
1526 ") "
1527 (if Info-current-node
1528 (propertize (replace-regexp-in-string
1529 "%" "%%" Info-current-node)
1530 'face 'mode-line-buffer-id
1531 'help-echo
1532 "mouse-1: scroll forward, mouse-3: scroll back"
1533 'mouse-face 'mode-line-highlight
1534 'local-map Info-mode-line-node-keymap)
1535 ""))))))
1537 ;; Go to an Info node specified with a filename-and-nodename string
1538 ;; of the sort that is found in pointers in nodes.
1540 ;; Don't autoload this function: the correct entry point for other packages
1541 ;; to use is `info'. --Stef
1542 ;; ;;;###autoload
1543 (defun Info-goto-node (nodename &optional fork)
1544 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1545 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1546 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1547 its sub-files).
1548 Completion is available, but only for node names in the current Info file.
1549 If FORK is non-nil (interactively with a prefix arg), show the node in
1550 a new Info buffer.
1551 If FORK is a string, it is the name to use for the new buffer."
1552 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg))
1553 (info-initialize)
1554 (if fork
1555 (set-buffer
1556 (clone-buffer (concat "*info-" (if (stringp fork) fork nodename) "*") t)))
1557 (let (filename)
1558 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1559 nodename)
1560 (setq filename (if (= (match-beginning 1) (match-end 1))
1562 (match-string 2 nodename))
1563 nodename (match-string 3 nodename))
1564 (let ((trim (string-match "\\s +\\'" filename)))
1565 (if trim (setq filename (substring filename 0 trim))))
1566 (let ((trim (string-match "\\s +\\'" nodename)))
1567 (if trim (setq nodename (substring nodename 0 trim))))
1568 (if transient-mark-mode (deactivate-mark))
1569 (Info-find-node (if (equal filename "") nil filename)
1570 (if (equal nodename "") "Top" nodename))))
1572 (defvar Info-read-node-completion-table)
1574 (defun Info-read-node-name-2 (dirs suffixes string pred action)
1575 "Virtual completion table for file names input in Info node names."
1576 (setq suffixes (remove "" suffixes))
1577 (when (file-name-absolute-p string)
1578 (setq dirs (list (file-name-directory string))))
1579 (let ((names nil)
1580 (suffix (concat (regexp-opt suffixes t) "\\'"))
1581 (string-dir (file-name-directory string)))
1582 (dolist (dir dirs)
1583 (unless dir
1584 (setq dir default-directory))
1585 (if string-dir (setq dir (expand-file-name string-dir dir)))
1586 (when (file-directory-p dir)
1587 (dolist (file (file-name-all-completions
1588 (file-name-nondirectory string) dir))
1589 ;; If the file name has no suffix or a standard suffix,
1590 ;; include it.
1591 (and (or (null (file-name-extension file))
1592 (string-match suffix file))
1593 ;; But exclude subfiles of split Info files.
1594 (not (string-match "-[0-9]+\\'" file))
1595 ;; And exclude backup files.
1596 (not (string-match "~\\'" file))
1597 (push (if string-dir (concat string-dir file) file) names))
1598 ;; If the file name ends in a standard suffix,
1599 ;; add the unsuffixed name as a completion option.
1600 (when (string-match suffix file)
1601 (setq file (substring file 0 (match-beginning 0)))
1602 (push (if string-dir (concat string-dir file) file) names)))))
1603 (complete-with-action action names string pred)))
1605 ;; This function is used as the "completion table" while reading a node name.
1606 ;; It does completion using the alist in Info-read-node-completion-table
1607 ;; unless STRING starts with an open-paren.
1608 (defun Info-read-node-name-1 (string predicate code)
1609 (cond
1610 ;; First complete embedded file names.
1611 ((string-match "\\`([^)]*\\'" string)
1612 (completion-table-with-context
1614 (apply-partially 'completion-table-with-terminator ")"
1615 (apply-partially 'Info-read-node-name-2
1616 Info-directory-list
1617 (mapcar 'car Info-suffix-list)))
1618 (substring string 1)
1619 predicate
1620 code))
1622 ;; If a file name was given, then any node is fair game.
1623 ((string-match "\\`(" string)
1624 (cond
1625 ((eq code nil) string)
1626 ((eq code t) nil)
1627 (t t)))
1628 ;; Otherwise use Info-read-node-completion-table.
1629 (t (complete-with-action
1630 code Info-read-node-completion-table string predicate))))
1632 ;; Arrange to highlight the proper letters in the completion list buffer.
1635 (defun Info-read-node-name (prompt)
1636 (let* ((completion-ignore-case t)
1637 (Info-read-node-completion-table (Info-build-node-completions))
1638 (nodename (completing-read prompt 'Info-read-node-name-1 nil t)))
1639 (if (equal nodename "")
1640 (Info-read-node-name prompt)
1641 nodename)))
1643 (defun Info-build-node-completions ()
1644 (or Info-current-file-completions
1645 (let ((compl nil)
1646 ;; Bind this in case the user sets it to nil.
1647 (case-fold-search t)
1648 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1649 (save-excursion
1650 (save-restriction
1651 (or Info-tag-table-marker
1652 (error "No Info tags found"))
1653 (if (marker-buffer Info-tag-table-marker)
1654 (let ((marker Info-tag-table-marker))
1655 (set-buffer (marker-buffer marker))
1656 (widen)
1657 (goto-char marker)
1658 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
1659 (setq compl
1660 (cons (list (match-string-no-properties 2))
1661 compl))))
1662 (widen)
1663 (goto-char (point-min))
1664 ;; If the buffer begins with a node header, process that first.
1665 (if (Info-node-at-bob-matching node-regexp)
1666 (setq compl (list (match-string-no-properties 1))))
1667 ;; Now for the rest of the nodes.
1668 (while (search-forward "\n\^_" nil t)
1669 (forward-line 1)
1670 (let ((beg (point)))
1671 (forward-line 1)
1672 (if (re-search-backward node-regexp beg t)
1673 (setq compl
1674 (cons (list (match-string-no-properties 1))
1675 compl))))))))
1676 (setq compl (cons '("*") compl))
1677 (set (make-local-variable 'Info-current-file-completions) compl))))
1679 (defun Info-restore-point (hl)
1680 "If this node has been visited, restore the point value when we left."
1681 (while hl
1682 (if (and (equal (nth 0 (car hl)) Info-current-file)
1683 ;; Use string-equal, not equal, to ignore text props.
1684 (string-equal (nth 1 (car hl)) Info-current-node))
1685 (progn
1686 (goto-char (nth 2 (car hl)))
1687 (setq hl nil)) ;terminate the while at next iter
1688 (setq hl (cdr hl)))))
1690 (defvar Info-search-history nil
1691 "The history list for `Info-search'.")
1693 (defvar Info-search-case-fold nil
1694 "The value of `case-fold-search' from previous `Info-search' command.")
1696 (defun Info-search (regexp &optional bound _noerror _count direction)
1697 "Search for REGEXP, starting from point, and select node it's found in.
1698 If DIRECTION is `backward', search in the reverse direction."
1699 (interactive (list (read-string
1700 (if Info-search-history
1701 (format "Regexp search%s (default %s): "
1702 (if case-fold-search "" " case-sensitively")
1703 (car Info-search-history))
1704 (format "Regexp search%s: "
1705 (if case-fold-search "" " case-sensitively")))
1706 nil 'Info-search-history)))
1707 (deactivate-mark)
1708 (when (equal regexp "")
1709 (setq regexp (car Info-search-history)))
1710 (when regexp
1711 (let (found beg-found give-up
1712 (backward (eq direction 'backward))
1713 (onode Info-current-node)
1714 (ofile Info-current-file)
1715 (opoint (point))
1716 (opoint-min (point-min))
1717 (opoint-max (point-max))
1718 (ostart (window-start))
1719 (osubfile Info-current-subfile))
1720 (setq Info-search-case-fold case-fold-search)
1721 (save-excursion
1722 (save-restriction
1723 (widen)
1724 (when backward
1725 ;; Hide Info file header for backward search
1726 (narrow-to-region (save-excursion
1727 (goto-char (point-min))
1728 (search-forward "\n\^_")
1729 (1- (point)))
1730 (point-max)))
1731 (while (and (not give-up)
1732 (or (null found)
1733 (not (funcall isearch-filter-predicate beg-found found))))
1734 (let ((search-spaces-regexp
1735 (if (or (not isearch-mode) isearch-regexp)
1736 Info-search-whitespace-regexp)))
1737 (if (if backward
1738 (re-search-backward regexp bound t)
1739 (re-search-forward regexp bound t))
1740 (setq found (point) beg-found (if backward (match-end 0)
1741 (match-beginning 0)))
1742 (setq give-up t))))))
1744 (when (and isearch-mode Info-isearch-search
1745 (not Info-isearch-initial-node)
1746 (not bound)
1747 (or give-up (and found (not (and (> found opoint-min)
1748 (< found opoint-max))))))
1749 (signal 'search-failed (list regexp "initial node")))
1751 ;; If no subfiles, give error now.
1752 (if give-up
1753 (if (null Info-current-subfile)
1754 (let ((search-spaces-regexp
1755 (if (or (not isearch-mode) isearch-regexp)
1756 Info-search-whitespace-regexp)))
1757 (if backward
1758 (re-search-backward regexp)
1759 (re-search-forward regexp)))
1760 (setq found nil)))
1762 (if (and bound (not found))
1763 (signal 'search-failed (list regexp)))
1765 (unless (or found bound)
1766 (unwind-protect
1767 ;; Try other subfiles.
1768 (let ((list ()))
1769 (with-current-buffer (marker-buffer Info-tag-table-marker)
1770 (goto-char (point-min))
1771 (search-forward "\n\^_\nIndirect:")
1772 (save-restriction
1773 (narrow-to-region (point)
1774 (progn (search-forward "\n\^_")
1775 (1- (point))))
1776 (goto-char (point-min))
1777 ;; Find the subfile we just searched.
1778 (search-forward (concat "\n" osubfile ": "))
1779 ;; Skip that one.
1780 (forward-line (if backward 0 1))
1781 (if backward (forward-char -1))
1782 ;; Make a list of all following subfiles.
1783 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1784 (while (not (if backward (bobp) (eobp)))
1785 (if backward
1786 (re-search-backward "\\(^.*\\): [0-9]+$")
1787 (re-search-forward "\\(^.*\\): [0-9]+$"))
1788 (goto-char (+ (match-end 1) 2))
1789 (setq list (cons (cons (+ (point-min)
1790 (read (current-buffer)))
1791 (match-string-no-properties 1))
1792 list))
1793 (goto-char (if backward
1794 (1- (match-beginning 0))
1795 (1+ (match-end 0)))))
1796 ;; Put in forward order
1797 (setq list (nreverse list))))
1798 (while list
1799 (message "Searching subfile %s..." (cdr (car list)))
1800 (Info-read-subfile (car (car list)))
1801 (when backward
1802 ;; Hide Info file header for backward search
1803 (narrow-to-region (save-excursion
1804 (goto-char (point-min))
1805 (search-forward "\n\^_")
1806 (1- (point)))
1807 (point-max))
1808 (goto-char (point-max)))
1809 (setq list (cdr list))
1810 (setq give-up nil found nil)
1811 (while (and (not give-up)
1812 (or (null found)
1813 (not (funcall isearch-filter-predicate beg-found found))))
1814 (let ((search-spaces-regexp
1815 (if (or (not isearch-mode) isearch-regexp)
1816 Info-search-whitespace-regexp)))
1817 (if (if backward
1818 (re-search-backward regexp nil t)
1819 (re-search-forward regexp nil t))
1820 (setq found (point) beg-found (if backward (match-end 0)
1821 (match-beginning 0)))
1822 (setq give-up t))))
1823 (if give-up
1824 (setq found nil))
1825 (if found
1826 (setq list nil)))
1827 (if found
1828 (message "")
1829 (signal 'search-failed (list regexp))))
1830 (if (not found)
1831 (progn (Info-read-subfile osubfile)
1832 (goto-char opoint)
1833 (Info-select-node)
1834 (set-window-start (selected-window) ostart)))))
1836 (if (and (string= osubfile Info-current-subfile)
1837 (> found opoint-min)
1838 (< found opoint-max))
1839 ;; Search landed in the same node
1840 (goto-char found)
1841 (widen)
1842 (goto-char found)
1843 (save-match-data (Info-select-node)))
1845 ;; Use string-equal, not equal, to ignore text props.
1846 (or (and (string-equal onode Info-current-node)
1847 (equal ofile Info-current-file))
1848 (and isearch-mode isearch-wrapped
1849 (eq opoint (if isearch-forward opoint-min opoint-max)))
1850 (setq Info-history (cons (list ofile onode opoint)
1851 Info-history))))))
1853 (defun Info-search-case-sensitively ()
1854 "Search for a regexp case-sensitively."
1855 (interactive)
1856 (let ((case-fold-search nil))
1857 (call-interactively 'Info-search)))
1859 (defun Info-search-next ()
1860 "Search for next regexp from a previous `Info-search' command."
1861 (interactive)
1862 (let ((case-fold-search Info-search-case-fold))
1863 (if Info-search-history
1864 (Info-search (car Info-search-history))
1865 (call-interactively 'Info-search))))
1867 (defun Info-search-backward (regexp &optional bound noerror count)
1868 "Search for REGEXP in the reverse direction."
1869 (interactive (list (read-string
1870 (if Info-search-history
1871 (format "Regexp search%s backward (default %s): "
1872 (if case-fold-search "" " case-sensitively")
1873 (car Info-search-history))
1874 (format "Regexp search%s backward: "
1875 (if case-fold-search "" " case-sensitively")))
1876 nil 'Info-search-history)))
1877 (Info-search regexp bound noerror count 'backward))
1879 (defun Info-isearch-search ()
1880 (if Info-isearch-search
1881 (lambda (string &optional bound noerror count)
1882 (if isearch-word
1883 (Info-search (concat "\\b" (replace-regexp-in-string
1884 "\\W+" "\\W+"
1885 (replace-regexp-in-string
1886 "^\\W+\\|\\W+$" "" string)
1887 nil t)
1888 ;; Lax version of word search
1889 (if (or isearch-nonincremental
1890 (eq (length string)
1891 (length (isearch-string-state
1892 (car isearch-cmds)))))
1893 "\\b"))
1894 bound noerror count
1895 (unless isearch-forward 'backward))
1896 (Info-search (if isearch-regexp string (regexp-quote string))
1897 bound noerror count
1898 (unless isearch-forward 'backward)))
1899 (point))
1900 (let ((isearch-search-fun-function nil))
1901 (isearch-search-fun))))
1903 (defun Info-isearch-wrap ()
1904 (if Info-isearch-search
1905 (if Info-isearch-initial-node
1906 (progn
1907 (if isearch-forward (Info-top-node) (Info-final-node))
1908 (goto-char (if isearch-forward (point-min) (point-max))))
1909 (setq Info-isearch-initial-node Info-current-node)
1910 (setq isearch-wrapped nil))
1911 (goto-char (if isearch-forward (point-min) (point-max)))))
1913 (defun Info-isearch-push-state ()
1914 `(lambda (cmd)
1915 (Info-isearch-pop-state cmd ',Info-current-file ',Info-current-node)))
1917 (defun Info-isearch-pop-state (_cmd file node)
1918 (or (and (equal Info-current-file file)
1919 (equal Info-current-node node))
1920 (progn (Info-find-node file node) (sit-for 0))))
1922 (defun Info-isearch-start ()
1923 (setq Info-isearch-initial-node
1924 ;; Don't stop at initial node for nonincremental search.
1925 ;; Otherwise this variable is set after first search failure.
1926 (and isearch-nonincremental Info-current-node))
1927 (setq Info-isearch-initial-history Info-history
1928 Info-isearch-initial-history-list Info-history-list)
1929 (add-hook 'isearch-mode-end-hook 'Info-isearch-end nil t))
1931 (defun Info-isearch-end ()
1932 ;; Remove intermediate nodes (visited while searching)
1933 ;; from the history. Add only the last node (where Isearch ended).
1934 (if (> (length Info-history)
1935 (length Info-isearch-initial-history))
1936 (setq Info-history
1937 (nthcdr (- (length Info-history)
1938 (length Info-isearch-initial-history)
1940 Info-history)))
1941 (if (> (length Info-history-list)
1942 (length Info-isearch-initial-history-list))
1943 (setq Info-history-list
1944 (cons (car Info-history-list)
1945 Info-isearch-initial-history-list)))
1946 (remove-hook 'isearch-mode-end-hook 'Info-isearch-end t))
1948 (defun Info-isearch-filter (beg-found found)
1949 "Test whether the current search hit is a visible useful text.
1950 Return non-nil if the text from BEG-FOUND to FOUND is visible
1951 and is not in the header line or a tag table."
1952 (save-match-data
1953 (let ((backward (< found beg-found)))
1954 (not
1956 (and (not (eq search-invisible t))
1957 (if backward
1958 (or (text-property-not-all found beg-found 'invisible nil)
1959 (text-property-not-all found beg-found 'display nil))
1960 (or (text-property-not-all beg-found found 'invisible nil)
1961 (text-property-not-all beg-found found 'display nil))))
1962 ;; Skip node header line
1963 (and (save-excursion (forward-line -1)
1964 (looking-at "\^_"))
1965 (forward-line (if backward -1 1)))
1966 ;; Skip Tag Table node
1967 (save-excursion
1968 (and (search-backward "\^_" nil t)
1969 (looking-at
1970 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
1973 (defun Info-extract-pointer (name &optional errorname)
1974 "Extract the value of the node-pointer named NAME.
1975 If there is none, use ERRORNAME in the error message;
1976 if ERRORNAME is nil, just return nil."
1977 ;; Bind this in case the user sets it to nil.
1978 (let ((case-fold-search t))
1979 (save-excursion
1980 (goto-char (point-min))
1981 (let ((bound (point)))
1982 (forward-line 1)
1983 (cond ((re-search-backward
1984 (concat name ":" (Info-following-node-name-re)) bound t)
1985 (match-string-no-properties 1))
1986 ((not (eq errorname t))
1987 (error "Node has no %s"
1988 (capitalize (or errorname name)))))))))
1990 (defun Info-following-node-name-re (&optional allowedchars)
1991 "Return a regexp matching a node name.
1992 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
1993 saying which chars may appear in the node name.
1994 Submatch 1 is the complete node name.
1995 Submatch 2 if non-nil is the parenthesized file name part of the node name.
1996 Submatch 3 is the local part of the node name.
1997 End of submatch 0, 1, and 3 are the same, so you can safely concat."
1998 (concat "[ \t]*" ;Skip leading space.
1999 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2000 "\\([" (or allowedchars "^,\t\n") "]*" ;Any number of allowed chars.
2001 "[" (or allowedchars "^,\t\n") " ]" ;The last char can't be a space.
2002 "\\|\\)\\)")) ;Allow empty node names.
2004 ;;; For compatibility; other files have used this name.
2005 (defun Info-following-node-name ()
2006 (and (looking-at (Info-following-node-name-re))
2007 (match-string-no-properties 1)))
2009 (defun Info-next ()
2010 "Go to the next node of this node."
2011 (interactive)
2012 ;; In case another window is currently selected
2013 (save-window-excursion
2014 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
2015 (Info-goto-node (Info-extract-pointer "next"))))
2017 (defun Info-prev ()
2018 "Go to the previous node of this node."
2019 (interactive)
2020 ;; In case another window is currently selected
2021 (save-window-excursion
2022 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
2023 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2025 (defun Info-up (&optional same-file)
2026 "Go to the superior node of this node.
2027 If SAME-FILE is non-nil, do not move to a different Info file."
2028 (interactive)
2029 ;; In case another window is currently selected
2030 (save-window-excursion
2031 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
2032 (let ((old-node Info-current-node)
2033 (old-file Info-current-file)
2034 (node (Info-extract-pointer "up")) p)
2035 (and same-file
2036 (string-match "^(" node)
2037 (error "Up node is in another Info file"))
2038 (Info-goto-node node)
2039 (setq p (point))
2040 (goto-char (point-min))
2041 (if (and (stringp old-file)
2042 (search-forward "\n* Menu:" nil t)
2043 (re-search-forward
2044 (if (string-equal old-node "Top")
2045 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file) ")")
2046 (concat "\n\\* +\\(" (regexp-quote old-node)
2047 ":\\|[^:]+: +" (regexp-quote old-node) "\\)"))
2048 nil t))
2049 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2050 (goto-char p)
2051 (Info-restore-point Info-history)))))
2053 (defun Info-history-back ()
2054 "Go back in the history to the last node visited."
2055 (interactive)
2056 (or Info-history
2057 (error "This is the first Info node you looked at"))
2058 (let ((history-forward
2059 (cons (list Info-current-file Info-current-node (point))
2060 Info-history-forward))
2061 filename nodename opoint)
2062 (setq filename (car (car Info-history)))
2063 (setq nodename (car (cdr (car Info-history))))
2064 (setq opoint (car (cdr (cdr (car Info-history)))))
2065 (setq Info-history (cdr Info-history))
2066 (Info-find-node filename nodename)
2067 (setq Info-history (cdr Info-history))
2068 (setq Info-history-forward history-forward)
2069 (goto-char opoint)))
2071 (defalias 'Info-last 'Info-history-back)
2073 (defun Info-history-forward ()
2074 "Go forward in the history of visited nodes."
2075 (interactive)
2076 (or Info-history-forward
2077 (error "This is the last Info node you looked at"))
2078 (let ((history-forward (cdr Info-history-forward))
2079 filename nodename opoint)
2080 (setq filename (car (car Info-history-forward)))
2081 (setq nodename (car (cdr (car Info-history-forward))))
2082 (setq opoint (car (cdr (cdr (car Info-history-forward)))))
2083 (Info-find-node filename nodename)
2084 (setq Info-history-forward history-forward)
2085 (goto-char opoint)))
2087 (add-to-list 'Info-virtual-files
2088 '("\\`dir\\'"
2089 (toc-nodes . Info-directory-toc-nodes)
2090 (find-file . Info-directory-find-file)
2091 (find-node . Info-directory-find-node)
2094 (defun Info-directory-toc-nodes (filename)
2095 "Directory-specific implementation of `Info-directory-toc-nodes'."
2096 `(,filename
2097 ("Top" nil nil nil)))
2099 (defun Info-directory-find-file (filename &optional _noerror)
2100 "Directory-specific implementation of `Info-find-file'."
2101 filename)
2103 (defun Info-directory-find-node (_filename _nodename &optional _no-going-back)
2104 "Directory-specific implementation of `Info-find-node-2'."
2105 (Info-insert-dir))
2107 ;;;###autoload
2108 (defun Info-directory ()
2109 "Go to the Info directory node."
2110 (interactive)
2111 (Info-find-node "dir" "top"))
2113 (add-to-list 'Info-virtual-files
2114 '("\\`\\*History\\*\\'"
2115 (toc-nodes . Info-history-toc-nodes)
2116 (find-file . Info-history-find-file)
2117 (find-node . Info-history-find-node)
2120 (defun Info-history-toc-nodes (filename)
2121 "History-specific implementation of `Info-history-toc-nodes'."
2122 `(,filename
2123 ("Top" nil nil nil)))
2125 (defun Info-history-find-file (filename &optional _noerror)
2126 "History-specific implementation of `Info-find-file'."
2127 filename)
2129 (defun Info-history-find-node (filename nodename &optional _no-going-back)
2130 "History-specific implementation of `Info-find-node-2'."
2131 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2132 (or filename Info-current-file) nodename))
2133 (insert "Recently Visited Nodes\n")
2134 (insert "**********************\n\n")
2135 (insert "* Menu:\n\n")
2136 (let ((hl (delete '("*History*" "Top") Info-history-list)))
2137 (while hl
2138 (let ((file (nth 0 (car hl)))
2139 (node (nth 1 (car hl))))
2140 (if (stringp file)
2141 (insert "* " node ": ("
2142 (propertize (or (file-name-directory file) "") 'invisible t)
2143 (file-name-nondirectory file)
2144 ")" node ".\n")))
2145 (setq hl (cdr hl)))))
2147 (defun Info-history ()
2148 "Go to a node with a menu of visited nodes."
2149 (interactive)
2150 (Info-find-node "*History*" "Top")
2151 (Info-next-reference)
2152 (Info-next-reference))
2154 (add-to-list 'Info-virtual-nodes
2155 '("\\`\\*TOC\\*\\'"
2156 (find-node . Info-toc-find-node)
2159 (defun Info-toc-find-node (filename nodename &optional _no-going-back)
2160 "Toc-specific implementation of `Info-find-node-2'."
2161 (let* ((curr-file (substring-no-properties (or filename Info-current-file)))
2162 (curr-node (substring-no-properties (or nodename Info-current-node)))
2163 (node-list (Info-toc-nodes curr-file)))
2164 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2165 curr-file curr-node))
2166 (insert "Table of Contents\n")
2167 (insert "*****************\n\n")
2168 (insert "*Note Top::\n")
2169 (Info-toc-insert
2170 (nth 3 (assoc "Top" node-list)) ; get Top nodes
2171 node-list 0 curr-file)
2172 (unless (bobp)
2173 (let ((Info-hide-note-references 'hide)
2174 (Info-fontify-visited-nodes nil))
2175 (setq Info-current-file filename Info-current-node "*TOC*")
2176 (goto-char (point-min))
2177 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t)
2178 (point-min))
2179 (point-max))
2180 (Info-fontify-node)
2181 (widen)))))
2183 (defun Info-toc ()
2184 "Go to a node with table of contents of the current Info file.
2185 Table of contents is created from the tree structure of menus."
2186 (interactive)
2187 (Info-find-node Info-current-file "*TOC*")
2188 (let ((prev-node (nth 1 (car Info-history))) p)
2189 (goto-char (point-min))
2190 (if (setq p (search-forward (concat "*Note " prev-node ":") nil t))
2191 (setq p (- p (length prev-node) 2)))
2192 (goto-char (or p (point-min)))))
2194 (defun Info-toc-insert (nodes node-list level curr-file)
2195 "Insert table of contents with references to nodes."
2196 (let ((section "Top"))
2197 (while nodes
2198 (let ((node (assoc (car nodes) node-list)))
2199 (unless (member (nth 2 node) (list nil section))
2200 (insert (setq section (nth 2 node)) "\n"))
2201 (insert (make-string level ?\t))
2202 (insert "*Note " (car nodes) ":: \n")
2203 (Info-toc-insert (nth 3 node) node-list (1+ level) curr-file)
2204 (setq nodes (cdr nodes))))))
2206 (defun Info-toc-build (file)
2207 "Build table of contents from menus of Info FILE and its subfiles."
2208 (with-temp-buffer
2209 (let* ((file (and (stringp file) (Info-find-file file)))
2210 (default-directory (or (and (stringp file)
2211 (file-name-directory file))
2212 default-directory))
2213 (main-file (and (stringp file) file))
2214 (sections '(("Top" "Top")))
2215 nodes subfiles)
2216 (while (or main-file subfiles)
2217 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2218 (erase-buffer)
2219 (info-insert-file-contents (or main-file (car subfiles)))
2220 (goto-char (point-min))
2221 (while (and (search-forward "\n\^_\nFile:" nil 'move)
2222 (search-forward "Node: " nil 'move))
2223 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2224 (bound (- (or (save-excursion (search-forward "\n\^_" nil t))
2225 (point-max)) 2))
2226 (upnode (and (re-search-forward
2227 (concat "Up:" (Info-following-node-name-re))
2228 bound t)
2229 (match-string-no-properties 1)))
2230 (section "Top")
2231 menu-items)
2232 (when (string-match "(" upnode) (setq upnode nil))
2233 (when (and (not (Info-index-node nodename file))
2234 (re-search-forward "^\\* Menu:" bound t))
2235 (forward-line 1)
2236 (beginning-of-line)
2237 (setq bound (or (and (equal nodename "Top")
2238 (save-excursion
2239 (re-search-forward
2240 "^[ \t-]*The Detailed Node Listing" nil t)))
2241 bound))
2242 (while (< (point) bound)
2243 (cond
2244 ;; Menu item line
2245 ((looking-at "^\\* +[^:]+:")
2246 (beginning-of-line)
2247 (forward-char 2)
2248 (let ((menu-node-name (substring-no-properties
2249 (Info-extract-menu-node-name))))
2250 (setq menu-items (cons menu-node-name menu-items))
2251 (if (equal nodename "Top")
2252 (setq sections
2253 (cons (list menu-node-name section) sections)))))
2254 ;; Other non-empty strings in the Top node are section names
2255 ((and (equal nodename "Top")
2256 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2257 (setq section (match-string-no-properties 1))))
2258 (forward-line 1)
2259 (beginning-of-line)))
2260 (setq nodes (cons (list nodename upnode
2261 (cadr (assoc nodename sections))
2262 (nreverse menu-items))
2263 nodes))
2264 (goto-char bound)))
2265 (if main-file
2266 (save-excursion
2267 (goto-char (point-min))
2268 (if (search-forward "\n\^_\nIndirect:" nil t)
2269 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2270 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2271 (setq subfiles (cons (match-string-no-properties 1)
2272 subfiles)))))
2273 (setq subfiles (nreverse subfiles)
2274 main-file nil))
2275 (setq subfiles (cdr subfiles))))
2276 (message "")
2277 (nreverse nodes))))
2279 (defvar Info-toc-nodes nil
2280 "Alist of cached parent-children node information in visited Info files.
2281 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
2282 where PARENT is the parent node extracted from the Up pointer,
2283 SECTION is the section name in the Top node where this node is placed,
2284 CHILDREN is a list of child nodes extracted from the node menu.")
2286 (defun Info-toc-nodes (filename)
2287 "Return a node list of Info FILENAME with parent-children information.
2288 This information is cached in the variable `Info-toc-nodes' with the help
2289 of the function `Info-toc-build'."
2290 (cond
2291 ((Info-virtual-call
2292 (Info-virtual-fun 'toc-nodes (or filename Info-current-file) nil)
2293 filename))
2295 (or filename (setq filename Info-current-file))
2296 (or (assoc filename Info-toc-nodes)
2297 ;; Skip virtual Info files
2298 (and (or (not (stringp filename))
2299 (Info-virtual-file-p filename))
2300 (push (cons filename nil) Info-toc-nodes))
2301 ;; Scan the entire manual and cache the result in Info-toc-nodes
2302 (let ((nodes (Info-toc-build filename)))
2303 (push (cons filename nodes) Info-toc-nodes)
2304 nodes)
2305 ;; If there is an error, still add nil to the cache
2306 (push (cons filename nil) Info-toc-nodes))
2307 (cdr (assoc filename Info-toc-nodes)))))
2310 (defun Info-follow-reference (footnotename &optional fork)
2311 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2312 FOOTNOTENAME may be an abbreviation of the reference name.
2313 If FORK is non-nil (interactively with a prefix arg), show the node in
2314 a new Info buffer. If FORK is a string, it is the name to use for the
2315 new buffer."
2316 (interactive
2317 (let ((completion-ignore-case t)
2318 (case-fold-search t)
2319 completions default alt-default (start-point (point)) str i bol eol)
2320 (save-excursion
2321 ;; Store end and beginning of line.
2322 (setq eol (line-end-position)
2323 bol (line-beginning-position))
2324 (goto-char (point-min))
2325 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
2326 (setq str (match-string-no-properties 1))
2327 ;; See if this one should be the default.
2328 (and (null default)
2329 (<= (match-beginning 0) start-point)
2330 (<= start-point (point))
2331 (setq default t))
2332 ;; See if this one should be the alternate default.
2333 (and (null alt-default)
2334 (and (<= bol (match-beginning 0))
2335 (<= (point) eol))
2336 (setq alt-default t))
2337 (setq i 0)
2338 (while (setq i (string-match "[ \n\t]+" str i))
2339 (setq str (concat (substring str 0 i) " "
2340 (substring str (match-end 0))))
2341 (setq i (1+ i)))
2342 ;; Record as a completion and perhaps as default.
2343 (if (eq default t) (setq default str))
2344 (if (eq alt-default t) (setq alt-default str))
2345 ;; Don't add this string if it's a duplicate.
2346 (or (assoc-string str completions t)
2347 (push str completions))))
2348 ;; If no good default was found, try an alternate.
2349 (or default
2350 (setq default alt-default))
2351 ;; If only one cross-reference found, then make it default.
2352 (if (eq (length completions) 1)
2353 (setq default (car completions)))
2354 (if completions
2355 (let ((input (completing-read (if default
2356 (concat
2357 "Follow reference named (default "
2358 default "): ")
2359 "Follow reference named: ")
2360 completions nil t)))
2361 (list (if (equal input "")
2362 default input) current-prefix-arg))
2363 (error "No cross-references in this node"))))
2365 (unless footnotename
2366 (error "No reference was specified"))
2368 (let (target i (str (concat "\\*note " (regexp-quote footnotename)))
2369 (case-fold-search t))
2370 (while (setq i (string-match " " str i))
2371 (setq str (concat (substring str 0 i) "[ \t\n]+" (substring str (1+ i))))
2372 (setq i (+ i 6)))
2373 (save-excursion
2374 ;; Move point to the beginning of reference if point is on reference
2375 (or (looking-at "\\*note[ \n\t]+")
2376 (and (looking-back "\\*note[ \n\t]+")
2377 (goto-char (match-beginning 0)))
2378 (if (and (save-excursion
2379 (goto-char (+ (point) 5)) ; skip a possible *note
2380 (re-search-backward "\\*note[ \n\t]+" nil t)
2381 (looking-at str))
2382 (<= (point) (match-end 0)))
2383 (goto-char (match-beginning 0))))
2384 ;; Go to the reference closest to point
2385 (let ((next-ref (save-excursion (and (re-search-forward str nil t)
2386 (+ (match-beginning 0) 5))))
2387 (prev-ref (save-excursion (and (re-search-backward str nil t)
2388 (+ (match-beginning 0) 5)))))
2389 (goto-char (cond ((and next-ref prev-ref)
2390 (if (< (abs (- next-ref (point)))
2391 (abs (- prev-ref (point))))
2392 next-ref prev-ref))
2393 ((or next-ref prev-ref))
2394 ((error "No cross-reference named %s" footnotename))))
2395 (setq target (Info-extract-menu-node-name t))))
2396 (while (setq i (string-match "[ \t\n]+" target i))
2397 (setq target (concat (substring target 0 i) " "
2398 (substring target (match-end 0))))
2399 (setq i (+ i 1)))
2400 (Info-goto-node target fork)))
2402 (defconst Info-menu-entry-name-re "\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2403 ;; We allow newline because this is also used in Info-follow-reference,
2404 ;; where the xref name might be wrapped over two lines.
2405 "Regexp that matches a menu entry name upto but not including the colon.
2406 Because of ambiguities, this should be concatenated with something like
2407 `:' and `Info-following-node-name-re'.")
2409 (defun Info-extract-menu-node-name (&optional multi-line index-node)
2410 (skip-chars-forward " \t\n")
2411 (when (looking-at (concat Info-menu-entry-name-re ":\\(:\\|"
2412 (Info-following-node-name-re
2413 (cond
2414 (index-node "^,\t\n")
2415 (multi-line "^.,\t")
2416 (t "^.,\t\n")))
2417 "\\)"
2418 (if index-node
2419 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2420 "")))
2421 (if index-node
2422 (setq Info-point-loc
2423 (if (match-beginning 5)
2424 (string-to-number (match-string 5))
2425 (buffer-substring-no-properties
2426 (match-beginning 0) (1- (match-beginning 1)))))
2427 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2428 ;;; (setq Info-point-loc
2429 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2431 (replace-regexp-in-string
2432 "[ \n]+" " "
2433 (or (match-string-no-properties 2)
2434 ;; If the node name is the menu entry name (using `entry::').
2435 (buffer-substring-no-properties
2436 (match-beginning 0) (1- (match-beginning 1)))))))
2438 ;; No one calls this.
2439 ;;(defun Info-menu-item-sequence (list)
2440 ;; (while list
2441 ;; (Info-menu (car list))
2442 ;; (setq list (cdr list))))
2444 (defvar Info-complete-menu-buffer)
2445 (defvar Info-complete-next-re nil)
2446 (defvar Info-complete-nodes nil)
2447 (defvar Info-complete-cache nil)
2449 (defconst Info-node-spec-re
2450 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2451 "Regexp to match the text after a : until the terminating `.'.")
2453 (defun Info-complete-menu-item (string predicate action)
2454 ;; This uses two dynamically bound variables:
2455 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2456 ;; is the menu of items we're trying to complete.
2457 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2458 ;; also look for menu items in subsequent nodes as long as those
2459 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2460 ;; not used.
2461 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2462 ;; also look for menu items in these nodes. This feature is currently
2463 ;; only used for completion in Info-index.
2465 ;; Note that `Info-complete-menu-buffer' could be current already,
2466 ;; so we want to save point.
2467 (with-current-buffer Info-complete-menu-buffer
2468 (save-excursion
2469 (let ((completion-ignore-case t)
2470 (case-fold-search t)
2471 (orignode Info-current-node)
2472 nextnode)
2473 (goto-char (point-min))
2474 (search-forward "\n* Menu:")
2475 (cond
2476 ((eq (car-safe action) 'boundaries) nil)
2477 ((eq action 'lambda)
2478 (re-search-forward
2479 (concat "\n\\* +" (regexp-quote string) ":") nil t))
2481 (let ((pattern (concat "\n\\* +\\("
2482 (regexp-quote string)
2483 Info-menu-entry-name-re "\\):"
2484 Info-node-spec-re))
2485 completions
2486 (complete-nodes Info-complete-nodes))
2487 ;; Check the cache.
2488 (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
2489 (equal (nth 1 Info-complete-cache) Info-current-node)
2490 (equal (nth 2 Info-complete-cache) Info-complete-next-re)
2491 (equal (nth 5 Info-complete-cache) Info-complete-nodes)
2492 (let ((prev (nth 3 Info-complete-cache)))
2493 (eq t (compare-strings string 0 (length prev)
2494 prev 0 nil t))))
2495 ;; We can reuse the previous list.
2496 (setq completions (nth 4 Info-complete-cache))
2497 ;; The cache can't be used.
2498 (while
2499 (progn
2500 (while (re-search-forward pattern nil t)
2501 (push (match-string-no-properties 1)
2502 completions))
2503 ;; Check subsequent nodes if applicable.
2504 (or (and Info-complete-next-re
2505 (setq nextnode (Info-extract-pointer "next" t))
2506 (string-match Info-complete-next-re nextnode))
2507 (and complete-nodes
2508 (setq complete-nodes (cdr complete-nodes)
2509 nextnode (car complete-nodes)))))
2510 (Info-goto-node nextnode))
2511 ;; Go back to the start node (for the next completion).
2512 (unless (equal Info-current-node orignode)
2513 (Info-goto-node orignode))
2514 ;; Update the cache.
2515 (set (make-local-variable 'Info-complete-cache)
2516 (list Info-current-file Info-current-node
2517 Info-complete-next-re string completions
2518 Info-complete-nodes)))
2519 (complete-with-action action completions string predicate))))))))
2522 (defun Info-menu (menu-item &optional fork)
2523 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2524 The menu item should one of those listed in the current node's menu.
2525 Completion is allowed, and the default menu item is the one point is on.
2526 If FORK is non-nil (interactively with a prefix arg), show the node in
2527 a new Info buffer. If FORK is a string, it is the name to use for the
2528 new buffer."
2529 (interactive
2530 (let (;; If point is within a menu item, use that item as the default
2531 (default nil)
2532 (p (point))
2534 (case-fold-search t))
2535 (save-excursion
2536 (goto-char (point-min))
2537 (if (not (search-forward "\n* menu:" nil t))
2538 (error "No menu in this node"))
2539 (setq beg (point))
2540 (and (< (point) p)
2541 (save-excursion
2542 (goto-char p)
2543 (end-of-line)
2544 (if (re-search-backward (concat "\n\\* +\\("
2545 Info-menu-entry-name-re
2546 "\\):") beg t)
2547 (setq default (match-string-no-properties 1))))))
2548 (let ((item nil))
2549 (while (null item)
2550 (setq item (let ((completion-ignore-case t)
2551 (Info-complete-menu-buffer (current-buffer)))
2552 (completing-read (if default
2553 (format "Menu item (default %s): "
2554 default)
2555 "Menu item: ")
2556 'Info-complete-menu-item nil t)))
2557 ;; we rely on the fact that completing-read accepts an input
2558 ;; of "" even when the require-match argument is true and ""
2559 ;; is not a valid possibility
2560 (if (string= item "")
2561 (if default
2562 (setq item default)
2563 ;; ask again
2564 (setq item nil))))
2565 (list item current-prefix-arg))))
2566 ;; there is a problem here in that if several menu items have the same
2567 ;; name you can only go to the node of the first with this command.
2568 (Info-goto-node (Info-extract-menu-item menu-item) (if fork menu-item)))
2570 (defun Info-extract-menu-item (menu-item)
2571 (setq menu-item (regexp-quote menu-item))
2572 (let ((case-fold-search t))
2573 (save-excursion
2574 (let ((case-fold-search t))
2575 (goto-char (point-min))
2576 (or (search-forward "\n* menu:" nil t)
2577 (error "No menu in this node"))
2578 (or (re-search-forward (concat "\n\\* +" menu-item ":") nil t)
2579 (re-search-forward (concat "\n\\* +" menu-item) nil t)
2580 (error "No such item in menu"))
2581 (beginning-of-line)
2582 (forward-char 2)
2583 (Info-extract-menu-node-name nil (Info-index-node))))))
2585 ;; If COUNT is nil, use the last item in the menu.
2586 (defun Info-extract-menu-counting (count &optional no-detail)
2587 (let ((case-fold-search t))
2588 (save-excursion
2589 (let ((case-fold-search t)
2590 (bound (when (and no-detail
2591 (re-search-forward
2592 "^[ \t-]*The Detailed Node Listing" nil t))
2593 (match-beginning 0))))
2594 (goto-char (point-min))
2595 (or (search-forward "\n* menu:" bound t)
2596 (error "No menu in this node"))
2597 (if count
2598 (or (search-forward "\n* " bound t count)
2599 (error "Too few items in menu"))
2600 (while (search-forward "\n* " bound t)
2601 nil))
2602 (Info-extract-menu-node-name nil (Info-index-node))))))
2604 (defun Info-nth-menu-item ()
2605 "Go to the node of the Nth menu item.
2606 N is the digit argument used to invoke this command."
2607 (interactive)
2608 (Info-goto-node
2609 (Info-extract-menu-counting
2610 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?0))))
2612 (defun Info-top-node ()
2613 "Go to the Top node of this file."
2614 (interactive)
2615 (Info-goto-node "Top"))
2617 (defun Info-final-node ()
2618 "Go to the final node in this file."
2619 (interactive)
2620 (Info-goto-node "Top")
2621 (let ((Info-history nil)
2622 (case-fold-search t))
2623 ;; Go to the last node in the menu of Top. But don't delve into
2624 ;; detailed node listings.
2625 (Info-goto-node (Info-extract-menu-counting nil t))
2626 ;; If the last node in the menu is not last in pointer structure,
2627 ;; move forward (but not down- or upward - see bug#1116) until we
2628 ;; can't go any farther.
2629 (while (Info-forward-node t t t) nil)
2630 ;; Then keep moving down to last subnode, unless we reach an index.
2631 (while (and (not (Info-index-node))
2632 (save-excursion (search-forward "\n* Menu:" nil t)))
2633 (Info-goto-node (Info-extract-menu-counting nil)))))
2635 (defun Info-forward-node (&optional not-down not-up no-error)
2636 "Go forward one node, considering all nodes as forming one sequence."
2637 (interactive)
2638 (goto-char (point-min))
2639 (forward-line 1)
2640 (let ((case-fold-search t))
2641 ;; three possibilities, in order of priority:
2642 ;; 1. next node is in a menu in this node (but not in an index)
2643 ;; 2. next node is next at same level
2644 ;; 3. next node is up and next
2645 (cond ((and (not not-down)
2646 (save-excursion (search-forward "\n* menu:" nil t))
2647 (not (Info-index-node)))
2648 (Info-goto-node (Info-extract-menu-counting 1))
2650 ((save-excursion (search-backward "next:" nil t))
2651 (Info-next)
2653 ((and (not not-up)
2654 (save-excursion (search-backward "up:" nil t))
2655 ;; Use string-equal, not equal, to ignore text props.
2656 (not (string-equal (downcase (Info-extract-pointer "up"))
2657 "top")))
2658 (let ((old-node Info-current-node))
2659 (Info-up)
2660 (let (Info-history success)
2661 (unwind-protect
2662 (setq success (Info-forward-node t nil no-error))
2663 (or success (Info-goto-node old-node))))))
2664 (no-error nil)
2665 (t (error "No pointer forward from this node")))))
2667 (defun Info-backward-node ()
2668 "Go backward one node, considering all nodes as forming one sequence."
2669 (interactive)
2670 (let ((prevnode (Info-extract-pointer "prev[ious]*" t))
2671 (upnode (Info-extract-pointer "up" t))
2672 (case-fold-search t))
2673 (cond ((and upnode (string-match "(" upnode))
2674 (error "First node in file"))
2675 ((and upnode (or (null prevnode)
2676 ;; Use string-equal, not equal,
2677 ;; to ignore text properties.
2678 (string-equal (downcase prevnode)
2679 (downcase upnode))))
2680 (Info-up))
2681 (prevnode
2682 ;; If we move back at the same level,
2683 ;; go down to find the last subnode*.
2684 (Info-prev)
2685 (let (Info-history)
2686 (while (and (not (Info-index-node))
2687 (save-excursion (search-forward "\n* Menu:" nil t)))
2688 (Info-goto-node (Info-extract-menu-counting nil)))))
2690 (error "No pointer backward from this node")))))
2692 (defun Info-exit ()
2693 "Exit Info by selecting some other buffer."
2694 (interactive)
2695 (if Info-standalone
2696 (save-buffers-kill-emacs)
2697 (quit-window)))
2699 (defun Info-next-menu-item ()
2700 "Go to the node of the next menu item."
2701 (interactive)
2702 ;; Bind this in case the user sets it to nil.
2703 (let* ((case-fold-search t)
2704 (node
2705 (save-excursion
2706 (forward-line -1)
2707 (search-forward "\n* menu:" nil t)
2708 (and (search-forward "\n* " nil t)
2709 (Info-extract-menu-node-name)))))
2710 (if node (Info-goto-node node)
2711 (error "No more items in menu"))))
2713 (defun Info-last-menu-item ()
2714 "Go to the node of the previous menu item."
2715 (interactive)
2716 (save-excursion
2717 (forward-line 1)
2718 ;; Bind this in case the user sets it to nil.
2719 (let* ((case-fold-search t)
2720 (beg (save-excursion
2721 (and (search-backward "\n* menu:" nil t)
2722 (point)))))
2723 (or (and beg (search-backward "\n* " beg t))
2724 (error "No previous items in menu")))
2725 (Info-goto-node (save-excursion
2726 (goto-char (match-end 0))
2727 (Info-extract-menu-node-name)))))
2729 (defmacro Info-no-error (&rest body)
2730 (list 'condition-case nil (cons 'progn (append body '(t))) '(error nil)))
2732 (defun Info-next-preorder ()
2733 "Go to the next subnode or the next node, or go up a level."
2734 (interactive)
2735 (cond ((Info-no-error (Info-next-menu-item)))
2736 ((Info-no-error (Info-next)))
2737 ((Info-no-error (Info-up t))
2738 ;; Since we have already gone thru all the items in this menu,
2739 ;; go up to the end of this node.
2740 (goto-char (point-max))
2741 ;; Since logically we are done with the node with that menu,
2742 ;; move on from it. But don't add intermediate nodes
2743 ;; to the history on recursive calls.
2744 (let (Info-history)
2745 (Info-next-preorder)))
2747 (error "No more nodes"))))
2749 (defun Info-last-preorder ()
2750 "Go to the last node, popping up a level if there is none."
2751 (interactive)
2752 (cond ((Info-no-error
2753 (Info-last-menu-item)
2754 ;; If we go down a menu item, go to the end of the node
2755 ;; so we can scroll back through it.
2756 (goto-char (point-max)))
2757 ;; Keep going down, as long as there are nested menu nodes.
2758 (while (Info-no-error
2759 (Info-last-menu-item)
2760 ;; If we go down a menu item, go to the end of the node
2761 ;; so we can scroll back through it.
2762 (goto-char (point-max))))
2763 (recenter -1))
2764 ((and (Info-no-error (Info-extract-pointer "prev"))
2765 (not (equal (Info-extract-pointer "up")
2766 (Info-extract-pointer "prev"))))
2767 (Info-no-error (Info-prev))
2768 (goto-char (point-max))
2769 (while (Info-no-error
2770 (Info-last-menu-item)
2771 ;; If we go down a menu item, go to the end of the node
2772 ;; so we can scroll back through it.
2773 (goto-char (point-max))))
2774 (recenter -1))
2775 ((Info-no-error (Info-up t))
2776 (goto-char (point-min))
2777 (let ((case-fold-search t))
2778 (or (search-forward "\n* Menu:" nil t)
2779 (goto-char (point-max)))))
2780 (t (error "No previous nodes"))))
2782 (defun Info-scroll-up ()
2783 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2784 Once you scroll far enough in a node that its menu appears on the screen
2785 but after point, the next scroll moves into its first subnode, unless
2786 `Info-scroll-prefer-subnodes' is nil.
2788 When you scroll past the end of a node, that goes to the next node if
2789 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
2790 if this node has no successor, it moves to the parent node's successor,
2791 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
2792 the menu of a node, it moves to subnode indicated by the following menu
2793 item. (That case won't normally result from this command, but can happen
2794 in other ways.)"
2796 (interactive)
2797 (if (or (< (window-start) (point-min))
2798 (> (window-start) (point-max)))
2799 (set-window-start (selected-window) (point)))
2800 (let* ((case-fold-search t)
2801 (virtual-end (save-excursion
2802 (goto-char (point-min))
2803 (if (and Info-scroll-prefer-subnodes
2804 (search-forward "\n* Menu:" nil t))
2805 (point)
2806 (point-max)))))
2807 (if (or (< virtual-end (window-start))
2808 (pos-visible-in-window-p virtual-end))
2809 (cond
2810 (Info-scroll-prefer-subnodes (Info-next-preorder))
2811 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
2812 (t (Info-next-preorder)))
2813 (scroll-up))))
2815 (defun Info-mouse-scroll-up (e)
2816 "Scroll one screenful forward in Info, using the mouse.
2817 See `Info-scroll-up'."
2818 (interactive "e")
2819 (save-selected-window
2820 (if (eventp e)
2821 (select-window (posn-window (event-start e))))
2822 (Info-scroll-up)))
2824 (defun Info-scroll-down ()
2825 "Scroll one screenful back in Info, considering all nodes as one sequence.
2826 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
2827 is non-nil, this goes to its last subnode. When you scroll past the
2828 beginning of a node, that goes to the previous node or back up to the
2829 parent node."
2830 (interactive)
2831 (if (or (< (window-start) (point-min))
2832 (> (window-start) (point-max)))
2833 (set-window-start (selected-window) (point)))
2834 (let* ((case-fold-search t)
2835 (current-point (point))
2836 (virtual-end
2837 (and Info-scroll-prefer-subnodes
2838 (save-excursion
2839 (setq current-point (line-beginning-position))
2840 (goto-char (point-min))
2841 (search-forward "\n* Menu:" current-point t)))))
2842 (if (or virtual-end
2843 (pos-visible-in-window-p (point-min) nil t))
2844 (Info-last-preorder)
2845 (scroll-down))))
2847 (defun Info-mouse-scroll-down (e)
2848 "Scroll one screenful backward in Info, using the mouse.
2849 See `Info-scroll-down'."
2850 (interactive "e")
2851 (save-selected-window
2852 (if (eventp e)
2853 (select-window (posn-window (event-start e))))
2854 (Info-scroll-down)))
2856 (defun Info-next-reference (&optional recur)
2857 "Move cursor to the next cross-reference or menu item in the node."
2858 (interactive)
2859 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2860 (old-pt (point))
2861 (case-fold-search t))
2862 (or (eobp) (forward-char 1))
2863 (or (re-search-forward pat nil t)
2864 (progn
2865 (goto-char (point-min))
2866 (or (re-search-forward pat nil t)
2867 (progn
2868 (goto-char old-pt)
2869 (error "No cross references in this node")))))
2870 (goto-char (or (match-beginning 1) (match-beginning 0)))
2871 (if (looking-at "\\* Menu:")
2872 (if recur
2873 (error "No cross references in this node")
2874 (Info-next-reference t))
2875 (if (looking-at "^\\* ")
2876 (forward-char 2)))))
2878 (defun Info-prev-reference (&optional recur)
2879 "Move cursor to the previous cross-reference or menu item in the node."
2880 (interactive)
2881 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
2882 (old-pt (point))
2883 (case-fold-search t))
2884 (or (re-search-backward pat nil t)
2885 (progn
2886 (goto-char (point-max))
2887 (or (re-search-backward pat nil t)
2888 (progn
2889 (goto-char old-pt)
2890 (error "No cross references in this node")))))
2891 (goto-char (or (match-beginning 1) (match-beginning 0)))
2892 (if (looking-at "\\* Menu:")
2893 (if recur
2894 (error "No cross references in this node")
2895 (Info-prev-reference t))
2896 (if (looking-at "^\\* ")
2897 (forward-char 2)))))
2899 (defvar Info-index-nodes nil
2900 "Alist of cached index node names of visited Info files.
2901 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
2903 (defun Info-index-nodes (&optional file)
2904 "Return a list of names of all index nodes in Info FILE.
2905 If FILE is omitted, it defaults to the current Info file.
2906 First look in a list of cached index node names. Then scan Info
2907 file and its subfiles for nodes with the index cookie. Then try
2908 to find index nodes starting from the first node in the top level
2909 menu whose name contains the word \"Index\", plus any immediately
2910 following nodes whose names also contain the word \"Index\"."
2911 (or file (setq file Info-current-file))
2912 (or (assoc file Info-index-nodes)
2913 ;; Skip virtual Info files
2914 (and (or (not (stringp file))
2915 (Info-virtual-file-p file))
2916 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
2917 (if (Info-file-supports-index-cookies file)
2918 ;; Find nodes with index cookie
2919 (let* ((default-directory (or (and (stringp file)
2920 (file-name-directory
2921 (setq file (Info-find-file file))))
2922 default-directory))
2923 Info-history Info-history-list Info-fontify-maximum-menu-size
2924 (main-file file) subfiles nodes)
2925 (condition-case nil
2926 (with-temp-buffer
2927 (while (or main-file subfiles)
2928 (erase-buffer)
2929 (info-insert-file-contents (or main-file (car subfiles)))
2930 (goto-char (point-min))
2931 (while (search-forward "\0\b[index\0\b]" nil 'move)
2932 (save-excursion
2933 (re-search-backward "^\^_")
2934 (search-forward "Node: ")
2935 (setq nodes (cons (Info-following-node-name) nodes))))
2936 (if main-file
2937 (save-excursion
2938 (goto-char (point-min))
2939 (if (search-forward "\n\^_\nIndirect:" nil t)
2940 (let ((bound (save-excursion (search-forward "\n\^_" nil t))))
2941 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t)
2942 (setq subfiles (cons (match-string-no-properties 1)
2943 subfiles)))))
2944 (setq subfiles (nreverse subfiles)
2945 main-file nil))
2946 (setq subfiles (cdr subfiles)))))
2947 (error nil))
2948 (if nodes
2949 (setq nodes (nreverse nodes)
2950 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2951 nodes)
2952 ;; Else find nodes with the word "Index" in the node name
2953 (let ((case-fold-search t)
2954 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
2955 nodes node)
2956 (condition-case nil
2957 (with-temp-buffer
2958 (Info-mode)
2959 (Info-find-node file "Top")
2960 (when (and (search-forward "\n* menu:" nil t)
2961 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
2962 (goto-char (match-beginning 1))
2963 (setq nodes (list (Info-extract-menu-node-name)))
2964 (Info-goto-node (car nodes))
2965 (while (and (setq node (Info-extract-pointer "next" t))
2966 (string-match "\\<Index\\>" node))
2967 (push node nodes)
2968 (Info-goto-node node))))
2969 (error nil))
2970 (if nodes
2971 (setq nodes (nreverse nodes)
2972 Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
2973 nodes))
2974 ;; If file has no index nodes, still add it to the cache
2975 (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
2976 (cdr (assoc file Info-index-nodes)))
2978 (defun Info-index-node (&optional node file)
2979 "Return non-nil value if NODE is an index node.
2980 If NODE is nil, check the current Info node.
2981 If FILE is nil, check the current Info file."
2982 (or file (setq file Info-current-file))
2983 (if (and (or (and node (not (equal node Info-current-node)))
2984 (assoc file Info-index-nodes))
2985 (not Info-current-node-virtual))
2986 (member (or node Info-current-node) (Info-index-nodes file))
2987 ;; Don't search all index nodes if request is only for the current node
2988 ;; and file is not in the cache of index nodes
2989 (save-match-data
2990 (if (Info-file-supports-index-cookies file)
2991 (save-excursion
2992 (goto-char (+ (or (save-excursion
2993 (search-backward "\n\^_" nil t))
2994 (point-min)) 2))
2995 (search-forward "\0\b[index\0\b]"
2996 (or (save-excursion
2997 (search-forward "\n\^_" nil t))
2998 (point-max)) t))
2999 (string-match "\\<Index\\>" (or node Info-current-node ""))))))
3001 (defun Info-goto-index ()
3002 "Go to the first index node."
3003 (let ((node (car (Info-index-nodes))))
3004 (or node (error "No index"))
3005 (Info-goto-node node)))
3007 ;;;###autoload
3008 (defun Info-index (topic)
3009 "Look up a string TOPIC in the index for this manual and go to that entry.
3010 If there are no exact matches to the specified topic, this chooses
3011 the first match which is a case-insensitive substring of a topic.
3012 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3013 Give an empty topic name to go to the Index node itself."
3014 (interactive
3015 (list
3016 (let ((completion-ignore-case t)
3017 (Info-complete-menu-buffer (clone-buffer))
3018 (Info-complete-nodes (Info-index-nodes))
3019 (Info-history-list nil))
3020 (if (equal Info-current-file "dir")
3021 (error "The Info directory node has no index; use m to select a manual"))
3022 (unwind-protect
3023 (with-current-buffer Info-complete-menu-buffer
3024 (Info-goto-index)
3025 (completing-read "Index topic: " 'Info-complete-menu-item))
3026 (kill-buffer Info-complete-menu-buffer)))))
3027 (if (equal Info-current-file "dir")
3028 (error "The Info directory node has no index; use m to select a manual"))
3029 ;; Strip leading colon in topic; index format does not allow them.
3030 (if (and (stringp topic)
3031 (> (length topic) 0)
3032 (= (aref topic 0) ?:))
3033 (setq topic (substring topic 1)))
3034 (let ((orignode Info-current-node)
3035 (pattern (format "\n\\* +\\([^\n]*%s[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3036 (regexp-quote topic)))
3037 node (nodes (Info-index-nodes))
3038 (ohist-list Info-history-list)
3039 (case-fold-search t))
3040 (Info-goto-index)
3041 (or (equal topic "")
3042 (let ((matches nil)
3043 (exact nil)
3044 ;; We bind Info-history to nil for internal node-switches so
3045 ;; that we don't put junk in the history. In the first
3046 ;; Info-goto-index call, above, we do update the history
3047 ;; because that is what the user's previous node choice into it.
3048 (Info-history nil)
3049 found)
3050 (while
3051 (progn
3052 (goto-char (point-min))
3053 (while (re-search-forward pattern nil t)
3054 (push (list (match-string-no-properties 1)
3055 (match-string-no-properties 2)
3056 Info-current-node
3057 (string-to-number (concat "0"
3058 (match-string 3))))
3059 matches))
3060 (setq nodes (cdr nodes) node (car nodes)))
3061 (Info-goto-node node))
3062 (or matches
3063 (progn
3064 (Info-goto-node orignode)
3065 (error "No `%s' in index" topic)))
3066 ;; Here it is a feature that assoc is case-sensitive.
3067 (while (setq found (assoc topic matches))
3068 (setq exact (cons found exact)
3069 matches (delq found matches)))
3070 (setq Info-history-list ohist-list)
3071 (setq Info-index-alternatives (nconc exact (nreverse matches)))
3072 (Info-index-next 0)))))
3074 (defun Info-index-next (num)
3075 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3076 (interactive "p")
3077 (or Info-index-alternatives
3078 (error "No previous `i' command"))
3079 (while (< num 0)
3080 (setq num (+ num (length Info-index-alternatives))))
3081 (while (> num 0)
3082 (setq Info-index-alternatives
3083 (nconc (cdr Info-index-alternatives)
3084 (list (car Info-index-alternatives)))
3085 num (1- num)))
3086 (Info-goto-node (nth 1 (car Info-index-alternatives)))
3087 (if (> (nth 3 (car Info-index-alternatives)) 0)
3088 ;; Forward 2 lines less because `Info-find-node-2' initially
3089 ;; puts point to the 2nd line.
3090 (forward-line (- (nth 3 (car Info-index-alternatives)) 2))
3091 (forward-line 3) ; don't search in headers
3092 (let ((name (car (car Info-index-alternatives))))
3093 (Info-find-index-name name)))
3094 (message "Found `%s' in %s. %s"
3095 (car (car Info-index-alternatives))
3096 (nth 2 (car Info-index-alternatives))
3097 (if (cdr Info-index-alternatives)
3098 (format "(%s total; use `%s' for next)"
3099 (length Info-index-alternatives)
3100 (key-description (where-is-internal
3101 'Info-index-next overriding-local-map
3102 t)))
3103 "(Only match)")))
3105 (defun Info-find-index-name (name)
3106 "Move point to the place within the current node where NAME is defined."
3107 (let ((case-fold-search t))
3108 (if (or (re-search-forward (format
3109 "[a-zA-Z]+: %s\\( \\|$\\)"
3110 (regexp-quote name)) nil t)
3111 ;; Find a function definition with a return type.
3112 (re-search-forward (format
3113 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3114 (regexp-quote name)) nil t)
3115 (search-forward (format "`%s'" name) nil t)
3116 (and (string-match "\\`.*\\( (.*)\\)\\'" name)
3117 (search-forward
3118 (format "`%s'" (substring name 0 (match-beginning 1)))
3119 nil t))
3120 (search-forward name nil t)
3121 ;; Try again without the " <1>" makeinfo can append
3122 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name)
3123 (Info-find-index-name (match-string 1 name))))
3124 (progn (beginning-of-line) t) ;; non-nil for recursive call
3125 (goto-char (point-min)))))
3127 (add-to-list 'Info-virtual-nodes
3128 '("\\`\\*Index.*\\*\\'"
3129 (find-node . Info-virtual-index-find-node)
3130 (slow . t)
3133 (defvar Info-virtual-index-nodes nil
3134 "Alist of cached matched index search nodes.
3135 Each element is ((FILENAME . TOPIC) MATCHES) where
3136 FILENAME is the file name of the manual,
3137 TOPIC is the search string given as an argument to `Info-virtual-index',
3138 MATCHES is a list of index matches found by `Info-index'.")
3140 (defun Info-virtual-index-find-node (filename nodename &optional _no-going-back)
3141 "Index-specific implementation of `Info-find-node-2'."
3142 ;; Generate Index-like menu of matches
3143 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename)
3144 ;; Generate Index-like menu of matches
3145 (let* ((topic (match-string 1 nodename))
3146 (matches (cdr (assoc (cons (or filename Info-current-file) topic)
3147 Info-virtual-index-nodes))))
3148 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3149 (or filename Info-current-file) nodename))
3150 (insert "Info Virtual Index\n")
3151 (insert "******************\n\n")
3152 (insert "Index entries that match `" topic "':\n\n")
3153 (insert "\0\b[index\0\b]\n")
3154 (if (null matches)
3155 (insert "No matches found.\n")
3156 (insert "* Menu:\n\n")
3157 (dolist (entry matches)
3158 (insert (format "* %-38s %s.%s\n"
3159 (format "%s [%s]:" (nth 0 entry) (nth 2 entry))
3160 (nth 1 entry)
3161 (if (nth 3 entry)
3162 (format " (line %s)" (nth 3 entry))
3163 ""))))))
3164 ;; Else, Generate a list of previous search results
3165 (let ((nodes (reverse Info-virtual-index-nodes)))
3166 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3167 (or filename Info-current-file) nodename))
3168 (insert "Info Virtual Index\n")
3169 (insert "******************\n\n")
3170 (insert "This is a list of search results produced by\n"
3171 "`Info-virtual-index' for the current manual.\n\n")
3172 (insert "* Menu:\n\n")
3173 (dolist (nodeinfo nodes)
3174 (when (equal (car (nth 0 nodeinfo)) (or filename Info-current-file))
3175 (insert
3176 (format "* %-20s %s.\n"
3177 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo)))
3178 (cdr (nth 0 nodeinfo)))))))))
3180 (defun Info-virtual-index (topic)
3181 "Show a node with all lines in the index containing a string TOPIC.
3182 Like `Info-index' but displays a node with index search results.
3183 Give an empty topic name to go to the node with links to previous
3184 search results."
3185 ;; `interactive' is a copy from `Info-index'
3186 (interactive
3187 (list
3188 (let ((completion-ignore-case t)
3189 (Info-complete-menu-buffer (clone-buffer))
3190 (Info-complete-nodes (Info-index-nodes))
3191 (Info-history-list nil))
3192 (if (equal Info-current-file "dir")
3193 (error "The Info directory node has no index; use m to select a manual"))
3194 (unwind-protect
3195 (with-current-buffer Info-complete-menu-buffer
3196 (Info-goto-index)
3197 (completing-read "Index topic: " 'Info-complete-menu-item))
3198 (kill-buffer Info-complete-menu-buffer)))))
3199 (if (equal topic "")
3200 (Info-find-node Info-current-file "*Index*")
3201 (unless (assoc (cons Info-current-file topic) Info-virtual-index-nodes)
3202 (let ((orignode Info-current-node)
3203 (ohist-list Info-history-list))
3204 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3205 (Info-index topic)
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)
3211 (message "")))
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)
3219 (slow . t)
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))))
3235 `(,filename
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'."
3241 filename)
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)))
3261 (when matches
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")
3268 (if (eq matches t)
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))
3274 (nth 0 entry)
3275 (nth 2 entry)
3276 (if (nth 3 entry)
3277 (format " (line %s)" (nth 3 entry))
3278 "")))))))))
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))
3294 (Info-directory)
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)
3311 (condition-case err
3312 (if (setq nodes (Info-index-nodes (Info-find-file manual)))
3313 (save-excursion
3314 (Info-find-node manual (car nodes))
3315 (while
3316 (progn
3317 (goto-char (point-min))
3318 (while (re-search-forward pattern nil t)
3319 (setq matches
3320 (cons (list manual
3321 (match-string-no-properties 1)
3322 (match-string-no-properties 2)
3323 (match-string-no-properties 3))
3324 matches)))
3325 (setq nodes (cdr nodes) node (car nodes)))
3326 (Info-goto-node node))))
3327 (error
3328 (message "%s" (if (eq (car-safe err) 'error)
3329 (nth 1 err) err))
3330 (sit-for 1 t)))))
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))))
3337 ;;;###autoload
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)))
3347 (if 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))
3351 Info-apropos-nodes)
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'."
3365 filename)
3367 (defvar finder-known-keywords)
3368 (declare-function find-library-name "find-func" (library))
3369 (declare-function finder-unknown-keywords "finder" ())
3370 (declare-function lm-commentary "lisp-mnt" (&optional file))
3371 (defvar finder-keywords-hash)
3372 (defvar package-alist) ; finder requires package
3374 (defun Info-finder-find-node (_filename nodename &optional _no-going-back)
3375 "Finder-specific implementation of `Info-find-node-2'."
3376 (require 'finder)
3377 (cond
3378 ((equal nodename "Top")
3379 ;; Display Top menu with descriptions of the keywords
3380 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3381 Info-finder-file nodename))
3382 (insert "Finder Keywords\n")
3383 (insert "***************\n\n")
3384 (insert "* Menu:\n\n")
3385 (dolist (assoc (append '((all . "All package info")
3386 (unknown . "unknown keywords"))
3387 finder-known-keywords))
3388 (let ((keyword (car assoc)))
3389 (insert (format "* %s %s.\n"
3390 (concat (symbol-name keyword) ": "
3391 "kw:" (symbol-name keyword) ".")
3392 (cdr assoc))))))
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")
3400 (mapc
3401 (lambda (assoc)
3402 (insert (format "* %-14s %s.\n"
3403 (concat (symbol-name (car assoc)) "::")
3404 (cdr 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 (dolist (package package-alist)
3413 (insert (format "%s - %s\n"
3414 (format "*Note %s::" (nth 0 package))
3415 (nth 1 package)))))
3416 ((string-match "\\`kw:" nodename)
3417 (setq nodename (substring nodename (match-end 0)))
3418 ;; Display packages that match the keyword
3419 ;; or the list of keywords separated by comma.
3420 (insert (format "\n\^_\nFile: %s, Node: kw:%s, Up: Top\n\n"
3421 Info-finder-file nodename))
3422 (insert "Finder Packages\n")
3423 (insert "***************\n\n")
3424 (insert
3425 "The following packages match the keyword `" nodename "':\n\n")
3426 (insert "* Menu:\n\n")
3427 (let ((keywords
3428 (mapcar 'intern (if (string-match-p "," nodename)
3429 (split-string nodename ",[ \t\n]*" t)
3430 (list nodename))))
3431 hits desc)
3432 (dolist (kw keywords)
3433 (push (copy-tree (gethash kw finder-keywords-hash)) hits))
3434 (setq hits (delete-dups (apply 'append hits)))
3435 (dolist (package hits)
3436 (setq desc (cdr-safe (assq package package-alist)))
3437 (when (vectorp desc)
3438 (insert (format "* %-16s %s.\n"
3439 (concat (symbol-name package) "::")
3440 (aref desc 2)))))))
3442 ;; Display commentary section
3443 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3444 Info-finder-file nodename))
3445 (insert "Finder Commentary\n")
3446 (insert "*****************\n\n")
3447 (insert
3448 "Commentary section of the package `" nodename "':\n\n")
3449 (let ((str (lm-commentary (find-library-name nodename))))
3450 (if (null str)
3451 (insert "Can't find any Commentary section\n\n")
3452 (insert
3453 (with-temp-buffer
3454 (insert str)
3455 (goto-char (point-min))
3456 (delete-blank-lines)
3457 (goto-char (point-max))
3458 (delete-blank-lines)
3459 (goto-char (point-min))
3460 (while (re-search-forward "^;+ ?" nil t)
3461 (replace-match "" nil nil))
3462 (buffer-string))))))))
3464 ;;;###autoload
3465 (defun info-finder (&optional keywords)
3466 "Display descriptions of the keywords in the Finder virtual manual.
3467 In interactive use, a prefix argument directs this command to read
3468 a list of keywords separated by comma. After that, it displays a node
3469 with a list of packages that contain all specified keywords."
3470 (interactive
3471 (when current-prefix-arg
3472 (require 'finder)
3473 (list
3474 (completing-read-multiple
3475 "Keywords (separated by comma): "
3476 (mapcar 'symbol-name (mapcar 'car (append finder-known-keywords
3477 (finder-unknown-keywords))))
3478 nil t))))
3479 (require 'finder)
3480 (if keywords
3481 (Info-find-node Info-finder-file (mapconcat 'identity keywords ", "))
3482 (Info-find-node Info-finder-file "Top")))
3485 (defun Info-undefined ()
3486 "Make command be undefined in Info."
3487 (interactive)
3488 (ding))
3490 (defun Info-help ()
3491 "Enter the Info tutorial."
3492 (interactive)
3493 (delete-other-windows)
3494 (Info-find-node "info"
3495 (if (< (window-height) 23)
3496 "Help-Small-Screen"
3497 "Help")))
3499 (defun Info-summary ()
3500 "Display a brief summary of all Info commands."
3501 (interactive)
3502 (save-window-excursion
3503 (switch-to-buffer "*Help*")
3504 (setq buffer-read-only nil)
3505 (erase-buffer)
3506 (insert (documentation 'Info-mode))
3507 (help-mode)
3508 (goto-char (point-min))
3509 (let (ch flag)
3510 (while (progn (setq flag (not (pos-visible-in-window-p (point-max))))
3511 (message (if flag "Type Space to see more"
3512 "Type Space to return to Info"))
3513 (if (not (eq ?\s (setq ch (read-event))))
3514 (progn (setq unread-command-events (list ch)) nil)
3515 flag))
3516 (scroll-up)))
3517 (bury-buffer "*Help*")))
3519 (defun Info-get-token (pos start all &optional errorstring)
3520 "Return the token around POS.
3521 POS must be somewhere inside the token.
3522 START is a regular expression which will match the
3523 beginning of the tokens delimited string.
3524 ALL is a regular expression with a single
3525 parenthesized subpattern which is the token to be
3526 returned. E.g. '{\(.*\)}' would return any string
3527 enclosed in braces around POS.
3528 ERRORSTRING optional fourth argument, controls action on no match:
3529 nil: return nil
3530 t: beep
3531 a string: signal an error, using that string."
3532 (let ((case-fold-search t))
3533 (save-excursion
3534 (goto-char pos)
3535 ;; First look for a match for START that goes across POS.
3536 (while (and (not (bobp)) (> (point) (- pos (length start)))
3537 (not (looking-at start)))
3538 (forward-char -1))
3539 ;; If we did not find one, search back for START
3540 ;; (this finds only matches that end at or before POS).
3541 (or (looking-at start)
3542 (progn
3543 (goto-char pos)
3544 (re-search-backward start (max (point-min) (- pos 200)) 'yes)))
3545 (let (found)
3546 (while (and (re-search-forward all (min (point-max) (+ pos 200)) 'yes)
3547 (not (setq found (and (<= (match-beginning 0) pos)
3548 (> (match-end 0) pos))))))
3549 (if (and found (<= (match-beginning 0) pos)
3550 (> (match-end 0) pos))
3551 (match-string-no-properties 1)
3552 (cond ((null errorstring)
3553 nil)
3554 ((eq errorstring t)
3555 (beep)
3556 nil)
3558 (error "No %s around position %d" errorstring pos))))))))
3560 (defun Info-mouse-follow-nearest-node (click)
3561 "\\<Info-mode-map>Follow a node reference near point.
3562 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3563 At end of the node's text, moves to the next node, or up if none."
3564 (interactive "e")
3565 (mouse-set-point click)
3566 (and (not (Info-follow-nearest-node))
3567 (save-excursion (forward-line 1) (eobp))
3568 (Info-next-preorder)))
3570 (defun Info-follow-nearest-node (&optional fork)
3571 "Follow a node reference near point.
3572 If point is on a reference, follow that reference. Otherwise,
3573 if point is in a menu item description, follow that menu item.
3575 If FORK is non-nil (interactively with a prefix arg), show the node in
3576 a new Info buffer.
3577 If FORK is a string, it is the name to use for the new buffer."
3578 (interactive "P")
3579 (or (Info-try-follow-nearest-node fork)
3580 (when (save-excursion
3581 (search-backward "\n* menu:" nil t))
3582 (save-excursion
3583 (beginning-of-line)
3584 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3585 (beginning-of-line 0))
3586 (when (looking-at "\\* +\\([^\t\n]*\\):")
3587 (Info-goto-node
3588 (Info-extract-menu-item (match-string-no-properties 1)) fork)
3589 t)))
3590 (and (eq this-command 'Info-mouse-follow-nearest-node)
3591 ;; Don't raise an error when mouse-1 is bound to this - it's
3592 ;; often used to simply select the window or frame.
3593 (eq 'mouse-1 (event-basic-type last-input-event)))
3594 (error "Point neither on reference nor in menu item description")))
3596 ;; Common subroutine.
3597 (defun Info-try-follow-nearest-node (&optional fork)
3598 "Follow a node reference near point. Return non-nil if successful.
3599 If FORK is non-nil, it is passed to `Info-goto-node'."
3600 (let (node)
3601 (cond
3602 ((setq node (Info-get-token (point) "[hf]t?tps?://"
3603 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3604 (browse-url node)
3605 (setq node t))
3606 ((setq node (Info-get-token (point) "\\*note[ \n\t]+"
3607 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3608 (Info-follow-reference node fork))
3609 ;; menu item: node name
3610 ((setq node (Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3611 (Info-goto-node node fork))
3612 ;; menu item: node name or index entry
3613 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3614 (beginning-of-line)
3615 (forward-char 2)
3616 (setq node (Info-extract-menu-node-name nil (Info-index-node)))
3617 (Info-goto-node node fork))
3618 ((setq node (Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3619 (Info-goto-node node fork))
3620 ((setq node (Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3621 (Info-goto-node node fork))
3622 ((setq node (Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3623 (Info-goto-node "Top" fork))
3624 ((setq node (Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3625 (Info-goto-node node fork)))
3626 node))
3628 (defun Info-mouse-follow-link (click)
3629 "Follow a link where you click."
3630 (interactive "e")
3631 (let* ((position (event-start click))
3632 (posn-string (and position (posn-string position)))
3633 (string (car-safe posn-string))
3634 (string-pos (cdr-safe posn-string))
3635 (link-args (and string string-pos
3636 (get-text-property string-pos 'link-args string))))
3637 (when link-args
3638 (Info-goto-node link-args))))
3641 (defvar Info-mode-map
3642 (let ((map (make-keymap)))
3643 (suppress-keymap map)
3644 (define-key map "." 'beginning-of-buffer)
3645 (define-key map " " 'Info-scroll-up)
3646 (define-key map "\C-m" 'Info-follow-nearest-node)
3647 (define-key map "\t" 'Info-next-reference)
3648 (define-key map "\e\t" 'Info-prev-reference)
3649 (define-key map [(shift tab)] 'Info-prev-reference)
3650 (define-key map [backtab] 'Info-prev-reference)
3651 (define-key map "1" 'Info-nth-menu-item)
3652 (define-key map "2" 'Info-nth-menu-item)
3653 (define-key map "3" 'Info-nth-menu-item)
3654 (define-key map "4" 'Info-nth-menu-item)
3655 (define-key map "5" 'Info-nth-menu-item)
3656 (define-key map "6" 'Info-nth-menu-item)
3657 (define-key map "7" 'Info-nth-menu-item)
3658 (define-key map "8" 'Info-nth-menu-item)
3659 (define-key map "9" 'Info-nth-menu-item)
3660 (define-key map "0" 'undefined)
3661 (define-key map "?" 'Info-summary)
3662 (define-key map "]" 'Info-forward-node)
3663 (define-key map "[" 'Info-backward-node)
3664 (define-key map "<" 'Info-top-node)
3665 (define-key map ">" 'Info-final-node)
3666 (define-key map "b" 'beginning-of-buffer)
3667 (define-key map "d" 'Info-directory)
3668 (define-key map "e" 'Info-edit)
3669 (define-key map "f" 'Info-follow-reference)
3670 (define-key map "g" 'Info-goto-node)
3671 (define-key map "h" 'Info-help)
3672 (define-key map "i" 'Info-index)
3673 (define-key map "I" 'Info-virtual-index)
3674 (define-key map "l" 'Info-history-back)
3675 (define-key map "L" 'Info-history)
3676 (define-key map "m" 'Info-menu)
3677 (define-key map "n" 'Info-next)
3678 (define-key map "p" 'Info-prev)
3679 (define-key map "q" 'Info-exit)
3680 (define-key map "r" 'Info-history-forward)
3681 (define-key map "s" 'Info-search)
3682 (define-key map "S" 'Info-search-case-sensitively)
3683 (define-key map "\M-n" 'clone-buffer)
3684 (define-key map "t" 'Info-top-node)
3685 (define-key map "T" 'Info-toc)
3686 (define-key map "u" 'Info-up)
3687 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3688 (define-key map "w" 'Info-copy-current-node-name)
3689 (define-key map "c" 'Info-copy-current-node-name)
3690 ;; `^' for consistency with `dired-up-directory'.
3691 (define-key map "^" 'Info-up)
3692 (define-key map "," 'Info-index-next)
3693 (define-key map "\177" 'Info-scroll-down)
3694 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3695 (define-key map [follow-link] 'mouse-face)
3696 map)
3697 "Keymap containing Info commands.")
3700 (defun Info-check-pointer (item)
3701 "Non-nil if ITEM is present in this node."
3702 (condition-case nil
3703 (Info-extract-pointer item)
3704 (error nil)))
3706 (easy-menu-define
3707 Info-mode-menu Info-mode-map
3708 "Menu for Info files."
3709 '("Info"
3710 ["Up" Info-up :active (Info-check-pointer "up")
3711 :help "Go up in the Info tree"]
3712 ["Next" Info-next :active (Info-check-pointer "next")
3713 :help "Go to the next node"]
3714 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
3715 :help "Go to the previous node"]
3716 ["Backward" Info-backward-node
3717 :help "Go backward one node, considering all as a sequence"]
3718 ["Forward" Info-forward-node
3719 :help "Go forward one node, considering all as a sequence"]
3720 ["Beginning" beginning-of-buffer
3721 :help "Go to beginning of this node"]
3722 ["Top" Info-top-node
3723 :help "Go to top node of file"]
3724 ["Final Node" Info-final-node
3725 :help "Go to final node in this file"]
3726 ("Menu Item" ["You should never see this" report-emacs-bug t])
3727 ("Reference" ["You should never see this" report-emacs-bug t])
3728 ["Search..." Info-search
3729 :help "Search for regular expression in this Info file"]
3730 ["Search Next" Info-search-next
3731 :help "Search for another occurrence of regular expression"]
3732 ["Go to Node..." Info-goto-node
3733 :help "Go to a named node"]
3734 ["Back in history" Info-history-back :active Info-history
3735 :help "Go back in history to the last node you were at"]
3736 ["Forward in history" Info-history-forward :active Info-history-forward
3737 :help "Go forward in history"]
3738 ["History" Info-history :active Info-history-list
3739 :help "Go to menu of visited nodes"]
3740 ["Table of Contents" Info-toc
3741 :help "Go to table of contents"]
3742 ("Index"
3743 ["Lookup a String..." Info-index
3744 :help "Look for a string in the index items"]
3745 ["Next Matching Item" Info-index-next :active Info-index-alternatives
3746 :help "Look for another occurrence of previous item"]
3747 ["Lookup a string and display index of results..." Info-virtual-index
3748 :help "Look for a string in the index items and display node with results"]
3749 ["Lookup a string in all indices..." info-apropos
3750 :help "Look for a string in the indices of all manuals"])
3751 ["Copy Node Name" Info-copy-current-node-name
3752 :help "Copy the name of the current node into the kill ring"]
3753 ["Clone Info buffer" clone-buffer
3754 :help "Create a twin copy of the current Info buffer."]
3755 ["Exit" Info-exit :help "Stop reading Info"]))
3758 (defvar info-tool-bar-map
3759 (let ((map (make-sparse-keymap)))
3760 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
3761 :rtl "right-arrow"
3762 :label "Back"
3763 :vert-only t)
3764 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
3765 :rtl "left-arrow"
3766 :label "Forward"
3767 :vert-only t)
3768 (define-key-after map [separator-1] menu-bar-separator)
3769 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
3770 :rtl "next-node")
3771 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
3772 :rtl "prev-node")
3773 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
3774 :vert-only t)
3775 (define-key-after map [separator-2] menu-bar-separator)
3776 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
3777 :vert-only t)
3778 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
3779 (define-key-after map [separator-3] menu-bar-separator)
3780 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
3781 :label "Index")
3782 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
3783 :vert-only t)
3784 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
3785 :vert-only t)
3786 map))
3788 (defvar Info-menu-last-node nil)
3789 ;; Last node the menu was created for.
3790 ;; Value is a list, (FILE-NAME NODE-NAME).
3792 (defun Info-menu-update ()
3793 "Update the Info menu for the current node."
3794 (condition-case nil
3795 (if (or (not (eq major-mode 'Info-mode))
3796 (equal (list Info-current-file Info-current-node)
3797 Info-menu-last-node))
3799 ;; Update menu menu.
3800 (let* ((Info-complete-menu-buffer (current-buffer))
3801 (items (nreverse (condition-case nil
3802 (Info-complete-menu-item "" nil t)
3803 (error nil))))
3804 entries current
3805 (number 0))
3806 (while (and items (< number 9))
3807 (setq current (car items)
3808 items (cdr items)
3809 number (1+ number))
3810 (setq entries (cons `[,current
3811 (Info-menu ,current)
3812 :keys ,(format "%d" number)]
3813 entries)))
3814 (if items
3815 (setq entries (cons ["Other..." Info-menu t] entries)))
3816 (or entries
3817 (setq entries (list ["No menu" nil nil] nil :active)))
3818 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
3819 ;; Update reference menu. Code stolen from `Info-follow-reference'.
3820 (let ((items nil)
3821 str i entries current
3822 (number 0)
3823 (case-fold-search t))
3824 (save-excursion
3825 (goto-char (point-min))
3826 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
3827 (setq str (match-string 1))
3828 (setq i 0)
3829 (while (setq i (string-match "[ \n\t]+" str i))
3830 (setq str (concat (substring str 0 i) " "
3831 (substring str (match-end 0))))
3832 (setq i (1+ i)))
3833 (setq items
3834 (cons str items))))
3835 (while (and items (< number 9))
3836 (setq current (car items)
3837 items (cdr items)
3838 number (1+ number))
3839 (setq entries (cons `[,current
3840 (Info-follow-reference ,current)
3842 entries)))
3843 (if items
3844 (setq entries (cons ["Other..." Info-follow-reference t]
3845 entries)))
3846 (or entries
3847 (setq entries (list ["No references" nil nil] nil :active)))
3848 (easy-menu-change '("Info") "Reference" (nreverse entries)))
3849 ;; Update last seen node.
3850 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
3851 ;; Try to avoid entering infinite beep mode in case of errors.
3852 (error (ding))))
3855 (defun Info-copy-current-node-name (&optional arg)
3856 "Put the name of the current Info node into the kill ring.
3857 The name of the Info file is prepended to the node name in parentheses.
3858 With a zero prefix arg, put the name inside a function call to `info'."
3859 (interactive "P")
3860 (unless Info-current-node
3861 (error "No current Info node"))
3862 (let ((node (if (stringp Info-current-file)
3863 (concat "(" (file-name-nondirectory Info-current-file) ") "
3864 Info-current-node))))
3865 (if (zerop (prefix-numeric-value arg))
3866 (setq node (concat "(info \"" node "\")")))
3867 (unless (stringp Info-current-file)
3868 (setq node (format "(Info-find-node '%S '%S)"
3869 Info-current-file Info-current-node)))
3870 (kill-new node)
3871 (message "%s" node)))
3874 ;; Info mode is suitable only for specially formatted data.
3875 (put 'Info-mode 'mode-class 'special)
3876 (put 'Info-mode 'no-clone-indirect t)
3878 (defvar tool-bar-map)
3879 (defvar bookmark-make-record-function)
3881 ;; Autoload cookie needed by desktop.el
3882 ;;;###autoload
3883 (define-derived-mode Info-mode nil "Info"
3884 "Info mode provides commands for browsing through the Info documentation tree.
3885 Documentation in Info is divided into \"nodes\", each of which discusses
3886 one topic and contains references to other nodes which discuss related
3887 topics. Info has commands to follow the references and show you other nodes.
3889 \\<Info-mode-map>\
3890 \\[Info-help] Invoke the Info tutorial.
3891 \\[Info-exit] Quit Info: reselect previously selected buffer.
3893 Selecting other nodes:
3894 \\[Info-mouse-follow-nearest-node]
3895 Follow a node reference you click on.
3896 This works with menu items, cross references, and
3897 the \"next\", \"previous\" and \"up\", depending on where you click.
3898 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
3899 \\[Info-next] Move to the \"next\" node of this node.
3900 \\[Info-prev] Move to the \"previous\" node of this node.
3901 \\[Info-up] Move \"up\" from this node.
3902 \\[Info-menu] Pick menu item specified by name (or abbreviation).
3903 Picking a menu item causes another node to be selected.
3904 \\[Info-directory] Go to the Info directory node.
3905 \\[Info-top-node] Go to the Top node of this file.
3906 \\[Info-final-node] Go to the final node in this file.
3907 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
3908 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
3909 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
3910 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
3911 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
3912 \\[Info-history-back] Move back in history to the last node you were at.
3913 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
3914 \\[Info-history] Go to menu of visited nodes.
3915 \\[Info-toc] Go to table of contents of the current Info file.
3917 Moving within a node:
3918 \\[Info-scroll-up] Normally, scroll forward a full screen.
3919 Once you scroll far enough in a node that its menu appears on the
3920 screen but after point, the next scroll moves into its first
3921 subnode. When after all menu items (or if there is no menu),
3922 move up to the parent node.
3923 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
3924 already visible, try to go to the previous menu entry, or up
3925 if there is none.
3926 \\[beginning-of-buffer] Go to beginning of node.
3928 Advanced commands:
3929 \\[Info-search] Search through this Info file for specified regexp,
3930 and select the node in which the next occurrence is found.
3931 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
3932 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
3933 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
3934 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
3935 \\[Info-virtual-index] Look for a string and display the index node with results.
3936 \\[info-apropos] Look for a string in the indices of all manuals.
3937 \\[Info-goto-node] Move to node specified by name.
3938 You may include a filename as well, as (FILENAME)NODENAME.
3939 1 .. 9 Pick first ... ninth item in node's menu.
3940 Every third `*' is highlighted to help pick the right number.
3941 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
3942 \\[clone-buffer] Select a new cloned Info buffer in another window.
3943 \\[universal-argument] \\[info] Move to new Info file with completion.
3944 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
3945 :syntax-table text-mode-syntax-table
3946 :abbrev-table text-mode-abbrev-table
3947 (setq tab-width 8)
3948 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
3949 (setq case-fold-search t)
3950 (setq buffer-read-only t)
3951 (make-local-variable 'Info-current-file)
3952 (make-local-variable 'Info-current-subfile)
3953 (make-local-variable 'Info-current-node)
3954 (set (make-local-variable 'Info-tag-table-marker) (make-marker))
3955 (set (make-local-variable 'Info-tag-table-buffer) nil)
3956 (make-local-variable 'Info-history)
3957 (make-local-variable 'Info-history-forward)
3958 (make-local-variable 'Info-index-alternatives)
3959 (if Info-use-header-line ; do not override global header lines
3960 (setq header-line-format
3961 '(:eval (get-text-property (point-min) 'header-line))))
3962 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
3963 ;; This is for the sake of the invisible text we use handling titles.
3964 (set (make-local-variable 'line-move-ignore-invisible) t)
3965 (set (make-local-variable 'desktop-save-buffer)
3966 'Info-desktop-buffer-misc-data)
3967 (set (make-local-variable 'widen-automatically) nil)
3968 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
3969 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
3970 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
3971 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
3972 (set (make-local-variable 'isearch-search-fun-function)
3973 'Info-isearch-search)
3974 (set (make-local-variable 'isearch-wrap-function)
3975 'Info-isearch-wrap)
3976 (set (make-local-variable 'isearch-push-state-function)
3977 'Info-isearch-push-state)
3978 (set (make-local-variable 'isearch-filter-predicate)
3979 'Info-isearch-filter)
3980 (set (make-local-variable 'search-whitespace-regexp)
3981 Info-search-whitespace-regexp)
3982 (set (make-local-variable 'revert-buffer-function)
3983 'Info-revert-buffer-function)
3984 (Info-set-mode-line)
3985 (set (make-local-variable 'bookmark-make-record-function)
3986 'Info-bookmark-make-record))
3988 ;; When an Info buffer is killed, make sure the associated tags buffer
3989 ;; is killed too.
3990 (defun Info-kill-buffer ()
3991 (and (eq major-mode 'Info-mode)
3992 Info-tag-table-buffer
3993 (kill-buffer Info-tag-table-buffer)))
3995 ;; Placed on `clone-buffer-hook'.
3996 (defun Info-clone-buffer ()
3997 (when (bufferp Info-tag-table-buffer)
3998 (setq Info-tag-table-buffer
3999 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4000 (let ((m Info-tag-table-marker))
4001 (when (markerp m)
4002 (setq Info-tag-table-marker
4003 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4004 (with-current-buffer Info-tag-table-buffer
4005 (copy-marker (marker-position m)))
4006 (make-marker))))))
4008 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
4009 (set-keymap-parent map text-mode-map)
4010 (define-key map "\C-c\C-c" 'Info-cease-edit)
4011 map)
4012 "Local keymap used within `e' command of Info.")
4014 ;; Info-edit mode is suitable only for specially formatted data.
4015 (put 'Info-edit-mode 'mode-class 'special)
4017 (defun Info-edit-mode ()
4018 "Major mode for editing the contents of an Info node.
4019 Like text mode with the addition of `Info-cease-edit'
4020 which returns to Info mode for browsing.
4021 \\{Info-edit-map}"
4022 (use-local-map Info-edit-map)
4023 (setq major-mode 'Info-edit-mode)
4024 (setq mode-name "Info Edit")
4025 (kill-local-variable 'mode-line-buffer-identification)
4026 (setq buffer-read-only nil)
4027 (force-mode-line-update)
4028 (buffer-enable-undo (current-buffer))
4029 (run-mode-hooks 'Info-edit-mode-hook))
4031 (defun Info-edit ()
4032 "Edit the contents of this Info node.
4033 Allowed only if variable `Info-enable-edit' is non-nil."
4034 (interactive)
4035 (or Info-enable-edit
4036 (error "Editing Info nodes is not enabled"))
4037 (Info-edit-mode)
4038 (message "%s" (substitute-command-keys
4039 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
4041 (defun Info-cease-edit ()
4042 "Finish editing Info node; switch back to Info proper."
4043 (interactive)
4044 ;; Do this first, so nothing has changed if user C-g's at query.
4045 (and (buffer-modified-p)
4046 (y-or-n-p "Save the file? ")
4047 (save-buffer))
4048 (use-local-map Info-mode-map)
4049 (setq major-mode 'Info-mode)
4050 (setq mode-name "Info")
4051 (Info-set-mode-line)
4052 (setq buffer-read-only t)
4053 (force-mode-line-update)
4054 (and (marker-position Info-tag-table-marker)
4055 (buffer-modified-p)
4056 (message "Tags may have changed. Use Info-tagify if necessary")))
4058 (defvar Info-file-list-for-emacs
4059 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4060 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4061 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4062 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4063 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4064 ("copyright" . "autotype") ("executable" . "autotype")
4065 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4066 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4067 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4068 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4069 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4070 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4071 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4072 ("rfc2045" . "emacs-mime")
4073 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4074 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4075 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4076 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4077 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4078 ("mml" . "emacs-mime"))
4079 "List of Info files that describe Emacs commands.
4080 An element can be a file name, or a list of the form (PREFIX . FILE)
4081 where PREFIX is a name prefix and FILE is the file to look in.
4082 If the element is just a file name, the file name also serves as the prefix.")
4084 (defun Info-find-emacs-command-nodes (command)
4085 "Return a list of locations documenting COMMAND.
4086 The `info-file' property of COMMAND says which Info manual to search.
4087 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4088 defines heuristics for which Info manual to try.
4089 The locations are of the format used in `Info-history', i.e.
4090 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4091 in the first element of the returned list (which is treated specially in
4092 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4093 (let ((where '()) line-number
4094 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4095 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4096 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4097 (info-file "emacs")) ;default
4098 ;; Determine which Info file this command is documented in.
4099 (if (get command 'info-file)
4100 (setq info-file (get command 'info-file))
4101 ;; If it doesn't say explicitly, test its name against
4102 ;; various prefixes that we know.
4103 (let ((file-list Info-file-list-for-emacs))
4104 (while file-list
4105 (let* ((elt (car file-list))
4106 (name (if (consp elt)
4107 (car elt)
4108 elt))
4109 (file (if (consp elt) (cdr elt) elt))
4110 (case-fold-search nil)
4111 (regexp (concat "\\`" (regexp-quote name)
4112 "\\(\\'\\|-\\)")))
4113 (if (string-match regexp (symbol-name command))
4114 (setq info-file file file-list nil))
4115 (setq file-list (cdr file-list))))))
4116 (Info-find-node info-file "Top")
4117 ;; Bind Info-history to nil, to prevent the index nodes from
4118 ;; getting into the node history.
4119 (let ((Info-history nil)
4120 (Info-history-list nil)
4121 node (nodes (Info-index-nodes)))
4122 (Info-goto-node (car nodes))
4123 (while
4124 (progn
4125 (goto-char (point-min))
4126 (while (re-search-forward cmd-desc nil t)
4127 (setq where
4128 (cons (list Info-current-file
4129 (match-string-no-properties 2)
4131 where))
4132 (setq line-number (and (match-beginning 3)
4133 (string-to-number (match-string 3)))))
4134 (and (setq nodes (cdr nodes) node (car nodes))))
4135 (Info-goto-node node)))
4136 (if (and line-number where)
4137 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4138 (cdr where))
4139 where)))
4141 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4142 ;;;###autoload
4143 (defun Info-goto-emacs-command-node (command)
4144 "Go to the Info node in the Emacs manual for command COMMAND.
4145 The command is found by looking up in Emacs manual's indices
4146 or in another manual found via COMMAND's `info-file' property or
4147 the variable `Info-file-list-for-emacs'.
4148 COMMAND must be a symbol or string."
4149 (interactive "CFind documentation for command: ")
4150 ;; If command is given as a string, convert it to a symbol.
4151 (if (stringp command)
4152 (setq command (intern command)))
4153 (or (commandp command)
4154 (signal 'wrong-type-argument (list 'commandp command)))
4155 (let ((where (Info-find-emacs-command-nodes command)))
4156 (if where
4157 (let ((num-matches (length where)))
4158 ;; Get Info running, and pop to it in another window.
4159 (save-window-excursion
4160 (info))
4161 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
4162 ;; Bind Info-history to nil, to prevent the last Index node
4163 ;; visited by Info-find-emacs-command-nodes from being
4164 ;; pushed onto the history.
4165 (let ((Info-history nil) (Info-history-list nil)
4166 (line-number (nth 2 (car where))))
4167 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4168 (if (and (integerp line-number) (> line-number 0))
4169 (forward-line (1- line-number))))
4170 (if (> num-matches 1)
4171 (progn
4172 ;; (car where) will be pushed onto Info-history
4173 ;; when/if they go to another node. Put the other
4174 ;; nodes that were found on the history.
4175 (setq Info-history (nconc (cdr where) Info-history))
4176 (message "Found %d other entr%s. Use %s to see %s."
4177 (1- num-matches)
4178 (if (> num-matches 2) "ies" "y")
4179 (substitute-command-keys "\\[Info-history-back]")
4180 (if (> num-matches 2) "them" "it")))))
4181 (error "Couldn't find documentation for %s" command))))
4183 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4184 ;;;###autoload
4185 (defun Info-goto-emacs-key-command-node (key)
4186 "Go to the node in the Emacs manual which describes the command bound to KEY.
4187 KEY is a string.
4188 Interactively, if the binding is `execute-extended-command', a command is read.
4189 The command is found by looking up in Emacs manual's indices
4190 or in another manual found via COMMAND's `info-file' property or
4191 the variable `Info-file-list-for-emacs'."
4192 (interactive "kFind documentation for key: ")
4193 (let ((command (key-binding key)))
4194 (cond ((null command)
4195 (message "%s is undefined" (key-description key)))
4196 ((and (called-interactively-p 'interactive)
4197 (eq command 'execute-extended-command))
4198 (Info-goto-emacs-command-node
4199 (read-command "Find documentation for command: ")))
4201 (Info-goto-emacs-command-node command)))))
4203 (defvar Info-next-link-keymap
4204 (let ((keymap (make-sparse-keymap)))
4205 (define-key keymap [header-line mouse-1] 'Info-next)
4206 (define-key keymap [header-line mouse-2] 'Info-next)
4207 (define-key keymap [header-line down-mouse-1] 'ignore)
4208 (define-key keymap [mouse-2] 'Info-next)
4209 (define-key keymap [follow-link] 'mouse-face)
4210 keymap)
4211 "Keymap to put on the Next link in the text or the header line.")
4213 (defvar Info-prev-link-keymap
4214 (let ((keymap (make-sparse-keymap)))
4215 (define-key keymap [header-line mouse-1] 'Info-prev)
4216 (define-key keymap [header-line mouse-2] 'Info-prev)
4217 (define-key keymap [header-line down-mouse-1] 'ignore)
4218 (define-key keymap [mouse-2] 'Info-prev)
4219 (define-key keymap [follow-link] 'mouse-face)
4220 keymap)
4221 "Keymap to put on the Prev link in the text or the header line.")
4223 (defvar Info-up-link-keymap
4224 (let ((keymap (make-sparse-keymap)))
4225 (define-key keymap [header-line mouse-1] 'Info-up)
4226 (define-key keymap [header-line mouse-2] 'Info-up)
4227 (define-key keymap [header-line down-mouse-1] 'ignore)
4228 (define-key keymap [mouse-2] 'Info-up)
4229 (define-key keymap [follow-link] 'mouse-face)
4230 keymap)
4231 "Keymap to put on the Up link in the text or the header line.")
4233 (defvar Info-link-keymap
4234 (let ((keymap (make-sparse-keymap)))
4235 (define-key keymap [header-line mouse-1] 'Info-mouse-follow-link)
4236 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4237 (define-key keymap [header-line down-mouse-1] 'ignore)
4238 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4239 (define-key keymap [follow-link] 'mouse-face)
4240 keymap)
4241 "Keymap to put on the link in the text or the header line.")
4243 (defun Info-breadcrumbs ()
4244 (let ((nodes (Info-toc-nodes Info-current-file))
4245 (node Info-current-node)
4246 (crumbs ())
4247 (depth Info-breadcrumbs-depth)
4248 line)
4250 ;; Get ancestors from the cached parent-children node info
4251 (while (and (not (equal "Top" node)) (> depth 0))
4252 (setq node (nth 1 (assoc node nodes)))
4253 (if node (push node crumbs))
4254 (setq depth (1- depth)))
4256 ;; Add bottom node.
4257 (when Info-use-header-line
4258 ;; Let it disappear if crumbs is nil.
4259 (nconc crumbs (list Info-current-node)))
4260 (when (or Info-use-header-line crumbs)
4261 ;; Add top node (and continuation if needed).
4262 (setq crumbs
4263 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4264 crumbs (cons nil crumbs))))
4265 ;; Eliminate duplicate.
4266 (forward-line 1)
4267 (dolist (node crumbs)
4268 (let ((text
4269 (if (not (equal node "Top")) node
4270 (format "(%s)Top"
4271 (if (stringp Info-current-file)
4272 (file-name-nondirectory Info-current-file)
4273 ;; Some legacy code can still use a symbol.
4274 Info-current-file)))))
4275 (setq line (concat
4276 line
4277 (if (null line) "" " > ")
4278 (cond
4279 ((null node) "...")
4280 ((equal node Info-current-node)
4281 ;; No point linking to ourselves.
4282 (propertize text 'font-lock-face 'info-header-node))
4284 (propertize text
4285 'mouse-face 'highlight
4286 'font-lock-face 'info-header-xref
4287 'help-echo "mouse-2: Go to node"
4288 'keymap Info-link-keymap
4289 'link-args text)))))))
4290 (setq line (concat line "\n")))
4291 ;; (font-lock-append-text-property 0 (length line)
4292 ;; 'font-lock-face 'header-line line)
4293 line))
4295 (defun Info-fontify-node ()
4296 "Fontify the node."
4297 (save-excursion
4298 (let* ((inhibit-read-only t)
4299 (case-fold-search t)
4300 paragraph-markers
4301 (not-fontified-p ; the node hasn't already been fontified
4302 (not (let ((where (next-single-property-change (point-min)
4303 'font-lock-face)))
4304 (and where (not (= where (point-max)))))))
4305 (fontify-visited-p ; visited nodes need to be re-fontified
4306 (and Info-fontify-visited-nodes
4307 ;; Don't take time to refontify visited nodes in huge nodes
4308 Info-fontify-maximum-menu-size
4309 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4310 rbeg rend)
4312 ;; Fontify header line
4313 (goto-char (point-min))
4314 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4315 (goto-char (match-end 0))
4316 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4317 (goto-char (match-end 0))
4318 (let* ((nbeg (match-beginning 2))
4319 (nend (match-end 2))
4320 (tbeg (match-beginning 1))
4321 (tag (match-string 1)))
4322 (if (string-equal (downcase tag) "node")
4323 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4324 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4325 (put-text-property tbeg nend 'mouse-face 'highlight)
4326 (put-text-property tbeg nend
4327 'help-echo
4328 (concat "mouse-2: Go to node "
4329 (buffer-substring nbeg nend)))
4330 ;; Always set up the text property keymap.
4331 ;; It will either be used in the buffer
4332 ;; or copied in the header line.
4333 (put-text-property
4334 tbeg nend 'keymap
4335 (cond
4336 ((string-equal (downcase tag) "prev") Info-prev-link-keymap)
4337 ((string-equal (downcase tag) "next") Info-next-link-keymap)
4338 ((string-equal (downcase tag) "up" ) Info-up-link-keymap))))))
4340 ;; (when (> Info-breadcrumbs-depth 0)
4341 ;; (insert (Info-breadcrumbs)))
4343 ;; Treat header line.
4344 (when Info-use-header-line
4345 (goto-char (point-min))
4346 (let* ((header-end (line-end-position))
4347 (header
4348 ;; If we find neither Next: nor Prev: link, show the entire
4349 ;; node header. Otherwise, don't show the File: and Node:
4350 ;; parts, to avoid wasting precious space on information that
4351 ;; is available in the mode line.
4352 (if (re-search-forward
4353 "\\(next\\|up\\|prev[ious]*\\): "
4354 header-end t)
4355 (progn
4356 (goto-char (match-beginning 1))
4357 (buffer-substring (point) header-end))
4358 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4359 header-end t)
4360 (concat "No next, prev or up links -- "
4361 (buffer-substring (point) header-end))
4362 (buffer-substring (point) header-end)))))
4363 (put-text-property (point-min) (1+ (point-min))
4364 'header-line
4365 (replace-regexp-in-string
4367 ;; Preserve text properties on duplicated `%'.
4368 (lambda (s) (concat s s)) header))
4369 ;; Hide the part of the first line
4370 ;; that is in the header, if it is just part.
4371 (cond
4372 ((> Info-breadcrumbs-depth 0)
4373 (let ((ov (make-overlay (point-min) (1+ header-end))))
4374 (overlay-put ov 'display (Info-breadcrumbs))
4375 (overlay-put ov 'evaporate t)))
4376 ((not (bobp))
4377 ;; Hide the punctuation at the end, too.
4378 (skip-chars-backward " \t,")
4379 (put-text-property (point) header-end 'invisible t))))))
4381 ;; Fontify titles
4382 (goto-char (point-min))
4383 (when (and font-lock-mode not-fontified-p)
4384 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4385 nil t)
4386 ;; Only consider it as an underlined title if the ASCII
4387 ;; underline has the same size as the text. A typical
4388 ;; counter example is when a continuation "..." is alone
4389 ;; on a line.
4390 (= (string-width (match-string 1))
4391 (string-width (match-string 2))))
4392 (let* ((c (preceding-char))
4393 (face
4394 (cond ((= c ?*) 'info-title-1)
4395 ((= c ?=) 'info-title-2)
4396 ((= c ?-) 'info-title-3)
4397 (t 'info-title-4))))
4398 (put-text-property (match-beginning 1) (match-end 1)
4399 'font-lock-face face))
4400 ;; This is a serious problem for trying to handle multiple
4401 ;; frame types at once. We want this text to be invisible
4402 ;; on frames that can display the font above.
4403 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4404 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4405 '(invisible t front-sticky nil rear-nonsticky t)))))
4407 ;; Fontify cross references
4408 (goto-char (point-min))
4409 (when (or not-fontified-p fontify-visited-p)
4410 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4411 (let ((start (match-beginning 0))
4412 (next (point))
4413 other-tag)
4414 (when not-fontified-p
4415 (when Info-hide-note-references
4416 (when (and (not (eq Info-hide-note-references 'hide))
4417 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4418 ;; *Note is often used where *note should have been
4419 (goto-char start)
4420 (skip-syntax-backward " ")
4421 (when (memq (char-before) '(?\( ?\[ ?\{))
4422 ;; Check whether the paren is preceded by
4423 ;; an end of sentence
4424 (skip-syntax-backward " ("))
4425 (setq other-tag
4426 (cond ((save-match-data (looking-back "\\<see"))
4428 ((save-match-data (looking-back "\\<in"))
4430 ((memq (char-before) '(nil ?\. ?! ??))
4431 "See ")
4432 ((save-match-data
4433 (save-excursion
4434 (search-forward "\n\n" start t)))
4435 "See ")
4436 (t "see "))))
4437 (goto-char next)
4438 (add-text-properties
4439 (match-beginning 1)
4440 (or (save-match-data
4441 ;; Don't hide \n after *Note
4442 (let ((start1 (match-beginning 1)))
4443 (if (string-match "\n" (match-string 1))
4444 (+ start1 (match-beginning 0)))))
4445 (match-end 1))
4446 (if other-tag
4447 `(display ,other-tag front-sticky nil rear-nonsticky t)
4448 '(invisible t front-sticky nil rear-nonsticky t))))
4449 (add-text-properties
4450 (match-beginning 2) (match-end 2)
4451 (list
4452 'help-echo (if (or (match-end 5)
4453 (not (equal (match-string 4) "")))
4454 (concat "mouse-2: go to " (or (match-string 5)
4455 (match-string 4)))
4456 "mouse-2: go to this node")
4457 'mouse-face 'highlight)))
4458 (when (or not-fontified-p fontify-visited-p)
4459 (setq rbeg (match-beginning 2)
4460 rend (match-end 2))
4461 (put-text-property
4462 rbeg rend
4463 'font-lock-face
4464 ;; Display visited nodes in a different face
4465 (if (and Info-fontify-visited-nodes
4466 (save-match-data
4467 (let* ((node (replace-regexp-in-string
4468 "^[ \t]+" ""
4469 (replace-regexp-in-string
4470 "[ \t\n]+" " "
4471 (or (match-string-no-properties 5)
4472 (and (not (equal (match-string 4) ""))
4473 (match-string-no-properties 4))
4474 (match-string-no-properties 2)))))
4475 (external-link-p
4476 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4477 (file (if external-link-p
4478 (file-name-nondirectory
4479 (match-string-no-properties 1 node))
4480 Info-current-file))
4481 (hl Info-history-list)
4482 res)
4483 (if external-link-p
4484 (setq node (if (equal (match-string 2 node) "")
4485 "Top"
4486 (match-string-no-properties 2 node))))
4487 (while hl
4488 (if (and (string-equal node (nth 1 (car hl)))
4489 (equal file
4490 (if (and external-link-p
4491 (stringp (caar hl)))
4492 (file-name-nondirectory
4493 (caar hl))
4494 (caar hl))))
4495 (setq res (car hl) hl nil)
4496 (setq hl (cdr hl))))
4497 res))) 'info-xref-visited 'info-xref))
4498 ;; For multiline ref, unfontify newline and surrounding whitespace
4499 (save-excursion
4500 (goto-char rbeg)
4501 (save-match-data
4502 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4503 (remove-text-properties (match-beginning 0)
4504 (match-end 0)
4505 '(font-lock-face t))))))
4506 (when not-fontified-p
4507 (when (memq Info-hide-note-references '(t hide))
4508 (add-text-properties (match-beginning 3) (match-end 3)
4509 '(invisible t front-sticky nil rear-nonsticky t))
4510 ;; Unhide the file name of the external reference in parens
4511 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4512 (remove-text-properties (match-beginning 6) (match-end 6)
4513 '(invisible t front-sticky nil rear-nonsticky t)))
4514 ;; Unhide newline because hidden newlines cause too long lines
4515 (save-match-data
4516 (let ((beg3 (match-beginning 3))
4517 (end3 (match-end 3)))
4518 (if (and (string-match "\n[ \t]*" (match-string 3))
4519 (not (save-match-data
4520 (save-excursion
4521 (goto-char (1+ end3))
4522 (looking-at "[.)]*$")))))
4523 (remove-text-properties (+ beg3 (match-beginning 0))
4524 (+ beg3 (match-end 0))
4525 '(invisible t front-sticky nil rear-nonsticky t))))))
4526 (when (and Info-refill-paragraphs Info-hide-note-references)
4527 (push (set-marker (make-marker) start)
4528 paragraph-markers))))))
4530 ;; Refill paragraphs (experimental feature)
4531 (when (and not-fontified-p
4532 Info-refill-paragraphs
4533 paragraph-markers)
4534 (let ((fill-nobreak-invisible t)
4535 (fill-individual-varying-indent nil)
4536 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4537 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4538 (adaptive-fill-mode nil))
4539 (goto-char (point-max))
4540 (dolist (m paragraph-markers)
4541 (when (< m (point))
4542 (goto-char m)
4543 (beginning-of-line)
4544 (let ((beg (point)))
4545 (when (zerop (forward-paragraph))
4546 (fill-individual-paragraphs beg (point) nil nil)
4547 (goto-char beg))))
4548 (set-marker m nil))))
4550 ;; Fontify menu items
4551 (goto-char (point-min))
4552 (when (and (or not-fontified-p fontify-visited-p)
4553 (search-forward "\n* Menu:" nil t)
4554 ;; Don't take time to annotate huge menus
4555 Info-fontify-maximum-menu-size
4556 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4557 (let ((n 0)
4558 cont)
4559 (while (re-search-forward
4560 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4561 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4562 nil t)
4563 (when (match-beginning 1)
4564 (when not-fontified-p
4565 (setq n (1+ n))
4566 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4567 (put-text-property (match-beginning 0)
4568 (1+ (match-beginning 0))
4569 'font-lock-face 'info-menu-star)))
4570 (when not-fontified-p
4571 (add-text-properties
4572 (match-beginning 1) (match-end 1)
4573 (list
4574 'help-echo (if (and (match-end 3)
4575 (not (equal (match-string 3) "")))
4576 (concat "mouse-2: go to " (match-string 3))
4577 "mouse-2: go to this node")
4578 'mouse-face 'highlight)))
4579 (when (or not-fontified-p fontify-visited-p)
4580 (put-text-property
4581 (match-beginning 1) (match-end 1)
4582 'font-lock-face
4583 ;; Display visited menu items in a different face
4584 (if (and Info-fontify-visited-nodes
4585 (save-match-data
4586 (let* ((node (if (equal (match-string 3) "")
4587 (match-string-no-properties 1)
4588 (match-string-no-properties 3)))
4589 (external-link-p
4590 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4591 (file (if external-link-p
4592 (file-name-nondirectory
4593 (match-string-no-properties 1 node))
4594 Info-current-file))
4595 (hl Info-history-list)
4596 res)
4597 (if external-link-p
4598 (setq node (if (equal (match-string 2 node) "")
4599 "Top"
4600 (match-string-no-properties 2 node))))
4601 (while hl
4602 (if (and (string-equal node (nth 1 (car hl)))
4603 (equal file
4604 (if (and external-link-p
4605 (stringp (caar hl)))
4606 (file-name-nondirectory
4607 (caar hl))
4608 (caar hl))))
4609 (setq res (car hl) hl nil)
4610 (setq hl (cdr hl))))
4611 res))) 'info-xref-visited 'info-xref)))
4612 (when (and not-fontified-p
4613 (memq Info-hide-note-references '(t hide))
4614 (not (Info-index-node)))
4615 (put-text-property (match-beginning 2) (1- (match-end 6))
4616 'invisible t)
4617 ;; Unhide the file name in parens
4618 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4619 (remove-text-properties (match-beginning 4) (match-end 4)
4620 '(invisible t)))
4621 ;; We need a stretchable space like :align-to but with
4622 ;; a minimum value.
4623 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4624 (if (>= 22 (- (match-end 1)
4625 (match-beginning 0)))
4626 '(space :align-to 24)
4627 '(space :width 2)))
4628 (setq cont (looking-at "."))
4629 (while (and (= (forward-line 1) 0)
4630 (looking-at "\\([ \t]+\\)[^*\n]"))
4631 (put-text-property (match-beginning 1) (1- (match-end 1))
4632 'invisible t)
4633 (put-text-property (1- (match-end 1)) (match-end 1)
4634 'display
4635 (if cont
4636 '(space :align-to 26)
4637 '(space :align-to 24)))
4638 (setq cont t)))))))
4640 ;; Fontify menu headers
4641 ;; Add the face `info-menu-header' to any header before a menu entry
4642 (goto-char (point-min))
4643 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4644 (put-text-property (match-beginning 0) (match-end 0)
4645 'font-lock-face 'info-menu-header)
4646 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4647 (put-text-property (match-beginning 1) (match-end 1)
4648 'font-lock-face 'info-menu-header)))
4650 ;; Hide index line numbers
4651 (goto-char (point-min))
4652 (when (and not-fontified-p (Info-index-node))
4653 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4654 (put-text-property (match-beginning 0) (match-end 0)
4655 'invisible t)))
4657 ;; Fontify http and ftp references
4658 (goto-char (point-min))
4659 (when not-fontified-p
4660 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4661 nil t)
4662 (add-text-properties (match-beginning 0) (match-end 0)
4663 '(font-lock-face info-xref
4664 mouse-face highlight
4665 help-echo "mouse-2: go to this URL"))))
4667 (set-buffer-modified-p nil))))
4669 ;;; Speedbar support:
4670 ;; These functions permit speedbar to display the "tags" in the
4671 ;; current Info node.
4672 (eval-when-compile (require 'speedbar))
4674 (defvar Info-speedbar-key-map nil
4675 "Keymap used when in the Info display mode.")
4677 (defun Info-install-speedbar-variables ()
4678 "Install those variables used by speedbar to enhance Info."
4679 (if Info-speedbar-key-map
4681 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
4683 ;; Basic tree features
4684 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
4685 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
4686 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
4687 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
4690 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
4691 Info-speedbar-key-map
4692 Info-speedbar-hierarchy-buttons)))
4694 (defvar Info-speedbar-menu-items
4695 '(["Browse Node" speedbar-edit-line t]
4696 ["Expand Node" speedbar-expand-line
4697 (save-excursion (beginning-of-line)
4698 (looking-at "[0-9]+: *.\\+. "))]
4699 ["Contract Node" speedbar-contract-line
4700 (save-excursion (beginning-of-line)
4701 (looking-at "[0-9]+: *.-. "))]
4703 "Additional menu-items to add to speedbar frame.")
4705 ;; Make sure our special speedbar major mode is loaded
4706 (if (featurep 'speedbar)
4707 (Info-install-speedbar-variables)
4708 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
4710 ;;; Info hierarchy display method
4711 ;;;###autoload
4712 (defun Info-speedbar-browser ()
4713 "Initialize speedbar to display an Info node browser.
4714 This will add a speedbar major display mode."
4715 (interactive)
4716 (require 'speedbar)
4717 ;; Make sure that speedbar is active
4718 (speedbar-frame-mode 1)
4719 ;; Now, throw us into Info mode on speedbar.
4720 (speedbar-change-initial-expansion-list "Info")
4723 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
4724 "Display an Info directory hierarchy in speedbar.
4725 DIRECTORY is the current directory in the attached frame.
4726 DEPTH is the current indentation depth.
4727 NODE is an optional argument that is used to represent the
4728 specific node to expand."
4729 (if (and (not node)
4730 (save-excursion (goto-char (point-min))
4731 (let ((case-fold-search t))
4732 (looking-at "Info Nodes:"))))
4733 ;; Update our "current node" maybe?
4735 ;; We cannot use the generic list code, that depends on all leaves
4736 ;; being known at creation time.
4737 (if (not node)
4738 (speedbar-with-writable (insert "Info Nodes:\n")))
4739 (let ((completions nil))
4740 (speedbar-select-attached-frame)
4741 (save-window-excursion
4742 (setq completions
4743 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
4744 (select-frame (speedbar-current-frame))
4745 (if completions
4746 (speedbar-with-writable
4747 (dolist (completion completions)
4748 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
4749 (cdr completion)
4750 (car completion)
4751 'Info-speedbar-goto-node
4752 (cdr completion)
4753 'info-xref depth))
4755 nil))))
4757 (defun Info-speedbar-goto-node (_text node _indent)
4758 "When user clicks on TEXT, go to an info NODE.
4759 The INDENT level is ignored."
4760 (speedbar-select-attached-frame)
4761 (let* ((buff (or (get-buffer "*info*")
4762 (progn (info) (get-buffer "*info*"))))
4763 (bwin (get-buffer-window buff 0)))
4764 (if bwin
4765 (progn
4766 (select-window bwin)
4767 (raise-frame (window-frame bwin)))
4768 (if speedbar-power-click
4769 (let ((pop-up-frames t)) (select-window (display-buffer buff)))
4770 (speedbar-select-attached-frame)
4771 (switch-to-buffer buff)))
4772 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
4773 (error "Invalid node %s" node)
4774 (Info-find-node (match-string 1 node) (match-string 2 node))
4775 ;; If we do a find-node, and we were in info mode, restore
4776 ;; the old default method. Once we are in info mode, it makes
4777 ;; sense to return to whatever method the user was using before.
4778 (if (string= speedbar-initial-expansion-list-name "Info")
4779 (speedbar-change-initial-expansion-list
4780 speedbar-previously-used-expansion-list-name)))))
4782 (defun Info-speedbar-expand-node (text token indent)
4783 "Expand the node the user clicked on.
4784 TEXT is the text of the button we clicked on, a + or - item.
4785 TOKEN is data related to this node (NAME . FILE).
4786 INDENT is the current indentation depth."
4787 (cond ((string-match "+" text) ;we have to expand this file
4788 (speedbar-change-expand-button-char ?-)
4789 (if (speedbar-with-writable
4790 (save-excursion
4791 (end-of-line) (forward-char 1)
4792 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
4793 (speedbar-change-expand-button-char ?-)
4794 (speedbar-change-expand-button-char ??)))
4795 ((string-match "-" text) ;we have to contract this node
4796 (speedbar-change-expand-button-char ?+)
4797 (speedbar-delete-subblock indent))
4798 (t (error "Ooops... not sure what to do")))
4799 (speedbar-center-buffer-smartly))
4801 (defun Info-speedbar-fetch-file-nodes (nodespec)
4802 "Fetch the subnodes from the info NODESPEC.
4803 NODESPEC is a string of the form: (file)node."
4804 ;; Set up a buffer we can use to fake-out Info.
4805 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
4806 (if (not (equal major-mode 'Info-mode))
4807 (Info-mode))
4808 ;; Get the node into this buffer
4809 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
4810 (error "Invalid node specification %s" nodespec)
4811 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
4812 ;; Scan the created buffer
4813 (goto-char (point-min))
4814 (let ((completions nil)
4815 (case-fold-search t)
4816 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
4817 (match-string 1 nodespec))))
4818 ;; Always skip the first one...
4819 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4820 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
4821 (let ((name (match-string 1)))
4822 (push (cons name
4823 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
4824 (match-string 1)
4825 (if (looking-at " *\\(([^)]+)\\)\\.")
4826 (concat (match-string 1) "Top")
4827 (concat "(" thisfile ")"
4828 (if (looking-at " \\([^.]+\\).")
4829 (match-string 1)
4830 name)))))
4831 completions)))
4832 (nreverse completions))))
4834 ;;; Info mode node listing
4835 ;; This is called by `speedbar-add-localized-speedbar-support'
4836 (defun Info-speedbar-buttons (_buffer)
4837 "Create a speedbar display to help navigation in an Info file.
4838 BUFFER is the buffer speedbar is requesting buttons for."
4839 (if (save-excursion (goto-char (point-min))
4840 (let ((case-fold-search t))
4841 (not (looking-at "Info Nodes:"))))
4842 (erase-buffer))
4843 (Info-speedbar-hierarchy-buttons nil 0))
4845 (dolist (mess '("^First node in file$"
4846 "^No `.*' in index$"
4847 "^No cross-reference named"
4848 "^No cross.references in this node$"
4849 "^No current Info node$"
4850 "^No menu in this node$"
4851 "^No more items in menu$"
4852 "^No more nodes$"
4853 "^No pointer \\(?:forward\\|backward\\) from this node$"
4854 "^No previous `i' command$"
4855 "^No previous items in menu$"
4856 "^No previous nodes$"
4857 "^No such item in menu$"
4858 "^No such node or anchor"
4859 "^Node has no"
4860 "^Point neither on reference nor in menu item description$"
4861 "^This is the \\(?:first\\|last\\) Info node you looked at$"
4862 search-failed))
4863 (add-to-list 'debug-ignored-errors mess))
4865 ;;;; Desktop support
4867 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
4868 "Auxiliary information to be saved in desktop file."
4869 (list Info-current-file
4870 Info-current-node
4871 ;; Additional data as an association list.
4872 (delq nil (list
4873 (and Info-history
4874 (cons 'history Info-history))
4875 (and (Info-virtual-fun
4876 'slow Info-current-file Info-current-node)
4877 (cons 'slow t))))))
4879 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
4880 desktop-buffer-name
4881 desktop-buffer-misc)
4882 "Restore an Info buffer specified in a desktop file."
4883 (let* ((file (nth 0 desktop-buffer-misc))
4884 (node (nth 1 desktop-buffer-misc))
4885 (data (nth 2 desktop-buffer-misc))
4886 (hist (assq 'history data))
4887 (slow (assq 'slow data)))
4888 ;; Don't restore nodes slow to regenerate.
4889 (unless slow
4890 (when (and file node)
4891 (when desktop-buffer-name
4892 (set-buffer (get-buffer-create desktop-buffer-name))
4893 (Info-mode))
4894 (Info-find-node file node)
4895 (when hist
4896 (setq Info-history (cdr hist)))
4897 (current-buffer)))))
4899 (add-to-list 'desktop-buffer-mode-handlers
4900 '(Info-mode . Info-restore-desktop-buffer))
4902 ;;;; Bookmark support
4903 (declare-function bookmark-make-record-default
4904 "bookmark" (&optional no-file no-context posn))
4905 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
4906 (declare-function bookmark-default-handler "bookmark" (bmk))
4907 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
4909 (defun Info-bookmark-make-record ()
4910 "This implements the `bookmark-make-record-function' type (which see)
4911 for Info nodes."
4912 `(,Info-current-node
4913 ,@(bookmark-make-record-default 'no-file)
4914 (filename . ,Info-current-file)
4915 (info-node . ,Info-current-node)
4916 (handler . Info-bookmark-jump)))
4918 ;;;###autoload
4919 (defun Info-bookmark-jump (bmk)
4920 "This implements the `handler' function interface for the record
4921 type returned by `Info-bookmark-make-record', which see."
4922 (let* ((file (bookmark-prop-get bmk 'filename))
4923 (info-node (bookmark-prop-get bmk 'info-node))
4924 (buf (save-window-excursion ;FIXME: doesn't work with frames!
4925 (Info-find-node file info-node) (current-buffer))))
4926 ;; Use bookmark-default-handler to move to the appropriate location
4927 ;; within the node.
4928 (bookmark-default-handler
4929 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
4932 ;;;###autoload
4933 (defun info-display-manual (manual)
4934 "Go to Info buffer that displays MANUAL, creating it if none already exists."
4935 (interactive "sManual name: ")
4936 (let ((blist (buffer-list))
4937 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
4938 (case-fold-search t)
4939 found)
4940 (dolist (buffer blist)
4941 (with-current-buffer buffer
4942 (when (and (eq major-mode 'Info-mode)
4943 (stringp Info-current-file)
4944 (string-match manual-re Info-current-file))
4945 (setq found buffer
4946 blist nil))))
4947 (if found
4948 (pop-to-buffer found)
4949 (info-initialize)
4950 (info (Info-find-file manual)))))
4952 (provide 'info)
4954 ;;; info.el ends here