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