1 ;; info.el --- info package for Emacs
3 ;; Copyright (C) 1985-1986, 1992-2013 Free Software Foundation, Inc.
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/>.
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 ": ".
41 (defvar Info-history nil
42 "Stack of Info nodes user has visited.
43 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
45 (defvar Info-history-forward nil
46 "Stack of Info nodes user has visited with `Info-history-back' command.
47 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
49 (defvar Info-history-list nil
50 "List of all Info nodes user has visited.
51 Each element of the list is a list (FILENAME NODENAME).")
53 (defcustom Info-history-skip-intermediate-nodes t
54 "Non-nil means don't record intermediate Info nodes to the history.
55 Intermediate Info nodes are nodes visited by Info internally in the process of
56 searching the node to display. Intermediate nodes are not presented
62 (defvar Info-enable-active-nodes nil
63 "Non-nil allows Info to execute Lisp code associated with nodes.
64 The Lisp code is executed when the node is selected.")
65 (put 'Info-enable-active-nodes
'risky-local-variable t
)
68 '((((class color
) (background light
)) :foreground
"brown" :weight bold
:slant italic
)
69 (((class color
) (background dark
)) :foreground
"white" :weight bold
:slant italic
)
70 (t :weight bold
:slant italic
))
71 "Face for Info node names."
75 '((((type tty pc
) (class color
) (background light
))
76 :foreground
"green" :weight bold
)
77 (((type tty pc
) (class color
) (background dark
))
78 :foreground
"yellow" :weight bold
)
79 (t :height
1.2 :inherit info-title-2
))
80 "Face for info titles at level 1."
82 (define-obsolete-face-alias 'Info-title-1-face
'info-title-1
"22.1")
85 '((((type tty pc
) (class color
)) :foreground
"lightblue" :weight bold
)
86 (t :height
1.2 :inherit info-title-3
))
87 "Face for info titles at level 2."
89 (define-obsolete-face-alias 'Info-title-2-face
'info-title-2
"22.1")
92 '((((type tty pc
) (class color
)) :weight bold
)
93 (t :height
1.2 :inherit info-title-4
))
94 "Face for info titles at level 3."
96 (define-obsolete-face-alias 'Info-title-3-face
'info-title-3
"22.1")
99 '((((type tty pc
) (class color
)) :weight bold
)
100 (t :weight bold
:inherit variable-pitch
))
101 "Face for info titles at level 4."
103 (define-obsolete-face-alias 'Info-title-4-face
'info-title-4
"22.1")
105 (defface info-menu-header
110 :inherit variable-pitch
112 "Face for headers in Info menus."
115 (defface info-menu-star
116 '((((class color
)) :foreground
"red1")
118 "Face for every third `*' in an Info menu."
120 (define-obsolete-face-alias 'info-menu-5
'info-menu-star
"22.1")
124 "Face for unvisited Info cross-references."
127 (defface info-xref-visited
128 '((t :inherit
(link-visited info-xref
)))
129 "Face for visited Info cross-references."
133 (defcustom Info-fontify-visited-nodes t
134 "Non-nil to fontify references to visited nodes in `info-xref-visited' face."
139 (defcustom Info-fontify-maximum-menu-size
100000
140 "Maximum size of menu to fontify if `font-lock-mode' is non-nil.
141 Set to nil to disable node fontification."
145 (defcustom Info-use-header-line t
146 "Non-nil means to put the beginning-of-node links in an Emacs header-line.
147 A header-line does not scroll with the rest of the buffer."
151 (defface info-header-xref
152 '((t :inherit info-xref
))
153 "Face for Info cross-references in a node header."
156 (defface info-header-node
157 '((t :inherit info-node
))
158 "Face for Info nodes in a node header."
161 (defface info-index-match
162 '((t :inherit match
))
163 "Face used to highlight matches in an index entry."
167 ;; This is a defcustom largely so that we can get the benefit
168 ;; of custom-initialize-delay. Perhaps it would work to make it a
169 ;; defvar and explicitly give it a standard-value property, and
170 ;; call custom-initialize-delay on it.
171 ;; The progn forces the autoloader to include the whole thing, not
172 ;; just an abbreviated version.
175 (defcustom Info-default-directory-list
177 (file-name-as-directory
178 ;; Self-contained NS build with info/ in the app-bundle.
179 (or (and (featurep 'ns
)
180 (let ((dir (expand-file-name "../info" data-directory
)))
181 (if (file-directory-p dir
) dir
)))
182 configure-info-directory
)))
184 ;; Directory trees in which to look for info subdirectories
185 (prune-directory-list '("/usr/local/" "/usr/" "/opt/" "/")))
187 ;; Subdirectories in each directory tree that may contain info
188 ;; directories. Most of these are rather outdated.
189 ;; It ought to be fine to stop checking the "emacs" ones now,
190 ;; since this is Emacs and we have not installed info files
191 ;; into such directories for a looong time...
192 '("share/" "" "gnu/" "gnu/lib/" "gnu/lib/emacs/"
193 "emacs/" "lib/" "lib/emacs/"))
196 (mapcar (lambda (pfx)
198 (mapcar (lambda (sfx)
199 (concat pfx sfx
"info/"))
201 (prune-directory-list dirs
)))
203 ;; If $(prefix)/share/info is not one of the standard info
204 ;; directories, they are probably installing an experimental
205 ;; version of Emacs, so make sure that experimental version's Info
206 ;; files override the ones in standard directories.
208 (if (member config-dir standard-info-dirs
)
209 ;; FIXME? What is the point of adding it again at the end
210 ;; when it is already present earlier in the list?
211 (nconc standard-info-dirs
(list config-dir
))
212 (cons config-dir standard-info-dirs
))))
213 (if (not (eq system-type
'windows-nt
))
215 ;; Include the info directory near where Emacs executable was installed.
216 (let* ((instdir (file-name-directory invocation-directory
))
217 (dir1 (expand-file-name "../info/" instdir
))
218 (dir2 (expand-file-name "../../../info/" instdir
)))
219 (cond ((file-exists-p dir1
) (append dirs
(list dir1
)))
220 ((file-exists-p dir2
) (append dirs
(list dir2
)))
223 "Default list of directories to search for Info documentation files.
224 They are searched in the order they are given in the list.
225 Therefore, the directory of Info files that come with Emacs
226 normally should come last (so that local files override standard ones),
227 unless Emacs is installed into a non-standard directory. In the latter
228 case, the directory of Info files that come with Emacs should be
231 Once Info is started, the list of directories to search
232 comes from the variable `Info-directory-list'.
233 This variable `Info-default-directory-list' is used as the default
234 for initializing `Info-directory-list' when Info is started, unless
235 the environment variable INFOPATH is set.
237 Although this is a customizable variable, that is mainly for technical
238 reasons. Normally, you should either set INFOPATH or customize
239 `Info-additional-directory-list', rather than changing this variable."
240 :initialize
'custom-initialize-delay
241 :type
'(repeat directory
)
244 (defvar Info-directory-list nil
245 "List of directories to search for Info documentation files.
246 If nil, meaning not yet initialized, Info uses the environment
247 variable INFOPATH to initialize it, or `Info-default-directory-list'
248 if there is no INFOPATH variable in the environment, or the
249 concatenation of the two if INFOPATH ends with a `path-separator'.
251 When `Info-directory-list' is initialized from the value of
252 `Info-default-directory-list', and Emacs is installed in one of the
253 standard directories, the directory of Info files that come with Emacs
254 is put last (so that local Info files override standard ones).
256 When `Info-directory-list' is initialized from the value of
257 `Info-default-directory-list', and Emacs is not installed in one
258 of the standard directories, the first element of the resulting
259 list is the directory where Emacs installs the Info files that
260 come with it. This is so that Emacs's own manual, which suits the
261 version of Emacs you are using, will always be found first. This
262 is useful when you install an experimental version of Emacs without
263 removing the standard installation.
265 If you want to override the order of directories in
266 `Info-default-directory-list', set INFOPATH in the environment.
268 If you run the Emacs executable from the `src' directory in the Emacs
269 source tree, and INFOPATH is not defined, the `info' directory in the
270 source tree is used as the first element of `Info-directory-list', in
271 place of the installation Info directory. This is useful when you run
272 a version of Emacs without installing it.")
274 (defcustom Info-additional-directory-list nil
275 "List of additional directories to search for Info documentation files.
276 These directories are searched after those in `Info-directory-list'."
277 :type
'(repeat directory
)
280 (defcustom Info-scroll-prefer-subnodes nil
281 "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
283 If this is non-nil, and you scroll far enough in a node that its menu
284 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
285 moves to a subnode indicated by the following menu item. This means
286 that you visit a subnode before getting to the end of the menu.
288 Setting this option to nil results in behavior similar to the stand-alone
289 Info reader program, which visits the first subnode from the menu only
290 when you hit the end of the current node."
295 (defcustom Info-hide-note-references t
296 "If non-nil, hide the tag and section reference in *note and * menu items.
297 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
298 If value is non-nil but not t or `hide', the reference section is still shown.
299 `nil' completely disables this feature. If this is non-nil, you might
300 want to set `Info-refill-paragraphs'."
302 :type
'(choice (const :tag
"No hiding" nil
)
303 (const :tag
"Replace tag and hide reference" t
)
304 (const :tag
"Hide tag and reference" hide
)
305 (other :tag
"Only replace tag" tag
))
306 :set
(lambda (sym val
)
308 (dolist (buffer (buffer-list))
309 (with-current-buffer buffer
310 (when (eq major-mode
'Info-mode
)
311 (revert-buffer t t
)))))
314 (defcustom Info-refill-paragraphs nil
315 "If non-nil, attempt to refill paragraphs with hidden references.
316 This refilling may accidentally remove explicit line breaks in the Info
317 file, so be prepared for a few surprises if you enable this feature.
318 This only has an effect if `Info-hide-note-references' is non-nil."
323 (defcustom Info-breadcrumbs-depth
4
324 "Depth of breadcrumbs to display.
325 0 means do not display breadcrumbs."
330 (defcustom Info-search-whitespace-regexp
"\\s-+"
331 "If non-nil, regular expression to match a sequence of whitespace chars.
332 This applies to Info search for regular expressions.
333 You might want to use something like \"[ \\t\\r\\n]+\" instead.
334 In the Customization buffer, that is `[' followed by a space,
335 a tab, a carriage return (control-M), a newline, and `]+'."
339 (defcustom Info-isearch-search t
340 "If non-nil, isearch in Info searches through multiple nodes.
341 Before leaving the initial Info node, where isearch was started,
342 it fails once with the error message [end of node], and with
343 subsequent C-s/C-r continues through other nodes without failing
344 with this error message in other nodes. When isearch fails for
345 the rest of the manual, it displays the error message [end of manual],
346 wraps around the whole manual and restarts the search from the top/final
347 node depending on search direction.
349 Setting this option to nil restores the default isearch behavior
350 with wrapping around the current Info node."
355 (defvar Info-isearch-initial-node nil
)
356 (defvar Info-isearch-initial-history nil
)
357 (defvar Info-isearch-initial-history-list nil
)
359 (defcustom Info-mode-hook
360 ;; Try to obey obsolete Info-fontify settings.
361 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
362 '(turn-on-font-lock))
363 "Hooks run when `Info-mode' is called."
367 (defcustom Info-selection-hook nil
368 "Hooks run when `Info-select-node' is called."
372 (defvar Info-edit-mode-hook nil
373 "Hooks run when `Info-edit-mode' is called.")
375 (make-obsolete-variable 'Info-edit-mode-hook
376 "editing Info nodes by hand is not recommended." "24.4")
378 (defvar Info-current-file nil
379 "Info file that Info is now looking at, or nil.
380 This is the name that was specified in Info, not the actual file name.
381 It doesn't contain directory names or file name extensions added by Info.")
383 (defvar Info-current-subfile nil
384 "Info subfile that is actually in the *info* buffer now.
385 It is nil if current Info file is not split into subfiles.")
387 (defvar Info-current-node nil
388 "Name of node that Info is now looking at, or nil.")
390 (defvar Info-tag-table-marker nil
391 "Marker pointing at beginning of current Info file's tag table.
392 Marker points nowhere if file has no tag table.")
394 (defvar Info-tag-table-buffer nil
395 "Buffer used for indirect tag tables.")
397 (defvar Info-current-file-completions nil
398 "Cached completion list for current Info file.")
400 (defvar Info-file-completions nil
401 "Cached completion alist of visited Info files.
402 Each element of the alist is (FILE . COMPLETIONS)")
404 (defvar Info-file-supports-index-cookies nil
405 "Non-nil if current Info file supports index cookies.")
407 (defvar Info-file-supports-index-cookies-list nil
408 "List of Info files with information about index cookies support.
409 Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
410 where SUPPORTS-INDEX-COOKIES can be either t or nil.")
412 (defvar Info-index-alternatives nil
413 "List of possible matches for last `Info-index' command.")
415 (defvar Info-point-loc nil
416 "Point location within a selected node.
417 If string, the point is moved to the proper occurrence of the
418 name of the followed cross reference within a selected node.
419 If number, the point is moved to the corresponding line.")
421 (defvar Info-standalone nil
422 "Non-nil if Emacs was started solely as an Info browser.")
424 (defvar Info-file-attributes nil
425 "Alist of file attributes of visited Info files.
426 Each element is a list (FILE-NAME FILE-ATTRIBUTES...).")
428 (defvar Info-toc-nodes nil
429 "Alist of cached parent-children node information in visited Info files.
430 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
431 where PARENT is the parent node extracted from the Up pointer,
432 SECTION is the section name in the Top node where this node is placed,
433 CHILDREN is a list of child nodes extracted from the node menu.")
435 (defvar Info-index-nodes nil
436 "Alist of cached index node names of visited Info files.
437 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
439 (defvar Info-virtual-files nil
440 "List of definitions of virtual Info files.
441 Each element of the list has the format (FILENAME (OPERATION . HANDLER) ...)
442 where FILENAME is a regexp that matches a class of virtual Info file names.
443 It should be carefully chosen to not cause file name clashes with
444 existing file names. OPERATION is one of the following operation
445 symbols `find-file', `find-node', `toc-nodes' that define what HANDLER
446 function to call instead of calling the default corresponding function
449 (defvar Info-virtual-nodes nil
450 "List of definitions of virtual Info nodes.
451 Each element of the list has the format (NODENAME (OPERATION . HANDLER) ...)
452 where NODENAME is a regexp that matches a class of virtual Info node names.
453 It should be carefully chosen to not cause node name clashes with
454 existing node names. OPERATION is one of the following operation
455 symbols `find-node' that define what HANDLER function to call instead
456 of calling the default corresponding function to override it.")
458 (defvar Info-current-node-virtual nil
459 "Non-nil if the current Info node is virtual.")
461 (defun Info-virtual-file-p (filename)
462 "Check if Info file FILENAME is virtual."
463 (Info-virtual-fun 'find-file filename nil
))
465 (defun Info-virtual-fun (op filename nodename
)
466 "Find a function that handles operations on virtual manuals.
467 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
468 FILENAME is a virtual Info file name, NODENAME is a virtual Info
469 node name. Return a function found either in `Info-virtual-files'
470 or `Info-virtual-nodes'."
471 (or (and (stringp filename
) ; some legacy code can still use a symbol
472 (cdr-safe (assoc op
(assoc-default filename
475 (and (stringp nodename
) ; some legacy code can still use a symbol
476 (cdr-safe (assoc op
(assoc-default nodename
480 (defun Info-virtual-call (virtual-fun &rest args
)
481 "Call a function that handles operations on virtual manuals."
482 (when (functionp virtual-fun
)
483 (or (apply virtual-fun args
) t
)))
486 (defvar Info-suffix-list
487 ;; The MS-DOS list should work both when long file names are
488 ;; supported (Windows 9X), and when only 8+3 file names are available.
489 (if (eq system-type
'ms-dos
)
490 '( (".gz" .
"gunzip")
492 (".bz2" .
("bzip2" "-dc"))
495 (".info.Z" .
"gunzip")
496 (".info.gz" .
"gunzip")
497 ("-info.Z" .
"gunzip")
498 ("-info.gz" .
"gunzip")
499 ("/index.gz" .
"gunzip")
500 ("/index.z" .
"gunzip")
506 '( (".info.Z" .
"uncompress")
507 (".info.Y" .
"unyabba")
508 (".info.gz" .
"gunzip")
509 (".info.z" .
"gunzip")
510 (".info.bz2" .
("bzip2" "-dc"))
511 (".info.xz" .
"unxz")
513 ("-info.Z" .
"uncompress")
514 ("-info.Y" .
"unyabba")
515 ("-info.gz" .
"gunzip")
516 ("-info.bz2" .
("bzip2" "-dc"))
517 ("-info.z" .
"gunzip")
518 ("-info.xz" .
"unxz")
520 ("/index.Z" .
"uncompress")
521 ("/index.Y" .
"unyabba")
522 ("/index.gz" .
"gunzip")
523 ("/index.z" .
"gunzip")
524 ("/index.bz2" .
("bzip2" "-dc"))
525 ("/index.xz" .
"unxz")
527 (".Z" .
"uncompress")
531 (".bz2" .
("bzip2" "-dc"))
534 "List of file name suffixes and associated decoding commands.
535 Each entry should be (SUFFIX . STRING); the file is given to
536 the command as standard input.
538 STRING may be a list of strings. In that case, the first element is
539 the command name, and the rest are arguments to that command.
541 If STRING is nil, no decoding is done.
542 Because the SUFFIXes are tried in order, the empty string should
543 be last in the list.")
545 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
546 ;; First, on MS-DOS with no long file names support, delete some of
547 ;; the extension in FILENAME to make room.
548 (defun info-insert-file-contents-1 (filename suffix lfn
)
549 (if lfn
; long file names are supported
550 (concat filename suffix
)
551 (let* ((sans-exts (file-name-sans-extension filename
))
552 ;; How long is the extension in FILENAME (not counting the dot).
553 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
555 ;; SUFFIX starts with a dot. If FILENAME already has one,
556 ;; get rid of the one in SUFFIX (unless suffix is empty).
557 (or (and (<= ext-len
0)
558 (not (eq (aref filename
(1- (length filename
))) ?.
)))
559 (= (length suffix
) 0)
560 (setq suffix
(substring suffix
1)))
561 ;; How many chars of that extension should we keep?
562 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
563 ;; Get rid of the rest of the extension, and add SUFFIX.
564 (concat (substring filename
0 (- (length filename
)
565 (- ext-len ext-left
)))
568 (defun info-file-exists-p (filename)
569 (and (file-exists-p filename
)
570 (not (file-directory-p filename
))))
572 (defun info-insert-file-contents (filename &optional visit
)
573 "Insert the contents of an Info file in the current buffer.
574 Do the right thing if the file has been compressed or zipped."
575 (let* ((tail Info-suffix-list
)
576 (jka-compr-verbose nil
)
577 (lfn (if (fboundp 'msdos-long-file-names
)
578 (msdos-long-file-names)
580 (check-short (and (fboundp 'msdos-long-file-names
)
582 fullname decoder done
)
583 (if (info-file-exists-p filename
)
584 ;; FILENAME exists--see if that name contains a suffix.
585 ;; If so, set DECODE accordingly.
589 (concat (regexp-quote (car (car tail
))) "$")
591 (setq tail
(cdr tail
)))
592 (setq fullname filename
593 decoder
(cdr (car tail
))))
594 ;; Try adding suffixes to FILENAME and see if we can find something.
595 (while (and tail
(not done
))
596 (setq fullname
(info-insert-file-contents-1 filename
597 (car (car tail
)) lfn
))
598 (if (info-file-exists-p fullname
)
600 ;; If we found a file with a suffix, set DECODER
601 ;; according to the suffix.
602 decoder
(cdr (car tail
)))
603 ;; When the MS-DOS port runs on Windows, we need to check
604 ;; the short variant of a long file name as well.
606 (setq fullname
(info-insert-file-contents-1 filename
607 (car (car tail
)) nil
))
608 (if (info-file-exists-p fullname
)
610 decoder
(cdr (car tail
))))))
611 (setq tail
(cdr tail
)))
613 (error "Can't find %s or any compressed version of it" filename
)))
614 ;; check for conflict with jka-compr
615 (if (and (jka-compr-installed-p)
616 (jka-compr-get-compression-info fullname
))
620 (insert-file-contents-literally fullname visit
)
621 (let ((inhibit-read-only t
)
622 (coding-system-for-write 'no-conversion
)
623 (inhibit-null-byte-detection t
) ; Index nodes include null bytes
624 (default-directory (or (file-name-directory fullname
)
627 (setq decoder
(list decoder
)))
628 (apply 'call-process-region
(point-min) (point-max)
629 (car decoder
) t t nil
(cdr decoder
))))
630 (let ((inhibit-null-byte-detection t
)) ; Index nodes include null bytes
631 (insert-file-contents fullname visit
)))
633 ;; Clear the caches of modified Info files.
634 (let* ((attribs-old (cdr (assoc fullname Info-file-attributes
)))
635 (modtime-old (and attribs-old
(nth 5 attribs-old
)))
636 (attribs-new (and (stringp fullname
) (file-attributes fullname
)))
637 (modtime-new (and attribs-new
(nth 5 attribs-new
))))
638 (when (and modtime-old modtime-new
639 (> (float-time modtime-new
) (float-time modtime-old
)))
640 (setq Info-index-nodes
(remove (assoc (or Info-current-file filename
)
643 (setq Info-toc-nodes
(remove (assoc (or Info-current-file filename
)
646 ;; Add new modtime to `Info-file-attributes'.
647 (setq Info-file-attributes
648 (cons (cons fullname attribs-new
)
649 (remove (assoc fullname Info-file-attributes
)
650 Info-file-attributes
))))))
652 (defun Info-file-supports-index-cookies (&optional file
)
653 "Return non-nil value if FILE supports Info index cookies.
654 Info index cookies were first introduced in 4.7, and all later
655 makeinfo versions output them in index nodes, so we can rely
656 solely on the makeinfo version. This function caches the information
657 in `Info-file-supports-index-cookies-list'."
658 (or file
(setq file Info-current-file
))
659 (or (assoc file Info-file-supports-index-cookies-list
)
660 ;; Skip virtual Info files
661 (and (or (not (stringp file
))
662 (Info-virtual-file-p file
))
663 (setq Info-file-supports-index-cookies-list
664 (cons (cons file nil
) Info-file-supports-index-cookies-list
)))
667 (goto-char (point-min))
669 (if (and (re-search-forward
670 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
671 (line-beginning-position 4) t
)
672 (not (version< (match-string 1) "4.7")))
675 (setq Info-file-supports-index-cookies-list
676 (cons (cons file found
) Info-file-supports-index-cookies-list
)))))
677 (cdr (assoc file Info-file-supports-index-cookies-list
)))
680 (defun Info-default-dirs ()
681 (let ((source (expand-file-name "info/" source-directory
))
682 (sibling (if installation-directory
683 (expand-file-name "info/" installation-directory
)
684 (if invocation-directory
685 (let ((infodir (expand-file-name
687 invocation-directory
)))
688 (if (file-exists-p infodir
)
690 (setq infodir
(expand-file-name
691 "../../../share/info/"
692 invocation-directory
))
693 (and (file-exists-p infodir
)
697 (if (and sibling
(file-exists-p sibling
))
698 ;; Uninstalled, Emacs builddir != srcdir.
700 ;; Uninstalled, builddir == srcdir
702 (if (or (member alternative Info-default-directory-list
)
703 ;; On DOS/NT, we use movable executables always,
704 ;; and we must always find the Info dir at run time.
705 (if (memq system-type
'(ms-dos windows-nt
))
707 ;; Use invocation-directory for Info
708 ;; only if we used it for exec-directory also.
709 (not (string= exec-directory
710 (expand-file-name "lib-src/"
711 installation-directory
))))
712 (not (file-exists-p alternative
)))
713 Info-default-directory-list
714 ;; `alternative' contains the Info files that came with this
715 ;; version, so we should look there first. `Info-insert-dir'
716 ;; currently expects to find `alternative' first on the list.
718 ;; Don't drop the last part, it might contain non-Emacs stuff.
719 ;; (reverse (cdr (reverse
720 Info-default-directory-list
)))) ;; )))
722 (defun info-initialize ()
723 "Initialize `Info-directory-list', if that hasn't been done yet."
724 (unless Info-directory-list
725 (let ((path (getenv "INFOPATH"))
726 (sep (regexp-quote path-separator
)))
727 (setq Info-directory-list
728 (prune-directory-list
730 (if (string-match-p (concat sep
"\\'") path
)
731 (append (split-string (substring path
0 -
1) sep
)
733 (split-string path sep
))
734 (Info-default-dirs))))
735 ;; For a self-contained (ie relocatable) NS build, AFAICS we
736 ;; always want the included info directory to be at the head of
737 ;; the search path, unless it's already in INFOPATH somewhere.
738 ;; It's at the head of Info-default-directory-list,
739 ;; but there's no way to get it at the head of Info-directory-list
740 ;; except by doing it here.
743 (let ((dir (expand-file-name "../info" data-directory
)))
744 (and (file-directory-p dir
)
745 (not (member dir
(split-string path
":" t
)))
746 (push dir Info-directory-list
)))))))
749 (defun info-other-window (&optional file-or-node buffer
)
750 "Like `info' but show the Info buffer in another window."
752 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
753 (read-file-name "Info file name: " nil nil t
))
754 (if (numberp current-prefix-arg
)
755 (format "*info*<%s>" current-prefix-arg
))))
756 (info-setup file-or-node
757 (switch-to-buffer-other-window (or buffer
"*info*"))))
759 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
761 (defun info (&optional file-or-node buffer
)
762 "Enter Info, the documentation browser.
763 Optional argument FILE-OR-NODE specifies the file to examine;
764 the default is the top-level directory of Info.
765 Called from a program, FILE-OR-NODE may specify an Info node of the form
766 \"(FILENAME)NODENAME\".
767 Optional argument BUFFER specifies the Info buffer name;
768 the default buffer name is *info*. If BUFFER exists,
769 just switch to BUFFER. Otherwise, create a new buffer
770 with the top-level Info directory.
772 In interactive use, a non-numeric prefix argument directs
773 this command to read a file name from the minibuffer.
775 A numeric prefix argument N selects an Info buffer named
778 The search path for Info files is in the variable `Info-directory-list'.
779 The top-level Info directory is made by combining all the files named `dir'
780 in all the directories in that path.
782 See a list of available Info commands in `Info-mode'."
784 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
785 (read-file-name "Info file name: " nil nil t
))
786 (if (numberp current-prefix-arg
)
787 (format "*info*<%s>" current-prefix-arg
))))
788 (info-setup file-or-node
789 (pop-to-buffer-same-window (or buffer
"*info*"))))
791 (defun info-setup (file-or-node buffer
)
792 "Display Info node FILE-OR-NODE in BUFFER."
793 (if (and buffer
(not (eq major-mode
'Info-mode
)))
796 ;; If argument already contains parentheses, don't add another set
797 ;; since the argument will then be parsed improperly. This also
798 ;; has the added benefit of allowing node names to be included
799 ;; following the parenthesized filename.
801 (if (and (stringp file-or-node
) (string-match "(.*)" file-or-node
))
803 (concat "(" file-or-node
")")))
804 (if (and (zerop (buffer-size))
806 ;; If we just created the Info buffer, go to the directory.
810 (defun info-emacs-manual ()
811 "Display the Emacs manual in Info mode."
816 (defun info-emacs-bug ()
817 "Display the \"Reporting Bugs\" section of the Emacs manual in Info mode."
819 (info "(emacs)Bugs"))
822 (defun info-standalone ()
823 "Run Emacs as a standalone Info reader.
824 Usage: emacs -f info-standalone [filename]
825 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
826 (setq Info-standalone t
)
827 (if (and command-line-args-left
828 (not (string-match "^-" (car command-line-args-left
))))
831 (info (car command-line-args-left
))
832 (setq command-line-args-left
(cdr command-line-args-left
)))
833 (error (send-string-to-terminal
834 (format "%s\n" (if (eq (car-safe err
) 'error
)
836 (save-buffers-kill-emacs)))
839 ;; See if the accessible portion of the buffer begins with a node
840 ;; delimiter, and the node header line which follows matches REGEXP.
841 ;; Typically, this test will be followed by a loop that examines the
842 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
843 ;; to have the overhead of this special test inside the loop.
845 ;; This function changes match-data, but supposedly the caller might
846 ;; want to use the results of re-search-backward.
848 ;; The return value is the value of point at the beginning of matching
849 ;; REGEXP, if the function succeeds, nil otherwise.
850 (defun Info-node-at-bob-matching (regexp)
851 (and (bobp) ; are we at beginning of buffer?
852 (looking-at "\^_") ; does it begin with node delimiter?
856 (forward-line 1) ; does the line after delimiter match REGEXP?
857 (re-search-backward regexp beg t
))))
859 (defun Info-find-file (filename &optional noerror
)
860 "Return expanded FILENAME, or t if FILENAME is \"dir\".
861 Optional second argument NOERROR, if t, means if file is not found
862 just return nil (no error)."
863 ;; Convert filename to lower case if not found as specified.
867 (Info-virtual-fun 'find-file filename nil
)
870 (let (temp temp-downcase found
)
871 (setq filename
(substitute-in-file-name filename
))
872 (let ((dirs (if (string-match "^\\./" filename
)
873 ;; If specified name starts with `./'
874 ;; then just try current directory.
876 (if (file-name-absolute-p filename
)
877 ;; No point in searching for an
878 ;; absolute file name
880 (if Info-additional-directory-list
881 (append Info-directory-list
882 Info-additional-directory-list
)
883 Info-directory-list
)))))
884 ;; Fall back on the installation directory if we can't find
885 ;; the info node anywhere else.
886 (when installation-directory
887 (setq dirs
(append dirs
(list (expand-file-name
888 "info" installation-directory
)))))
889 ;; Search the directory list for file FILENAME.
890 (while (and dirs
(not found
))
891 (setq temp
(expand-file-name filename
(car dirs
)))
893 (expand-file-name (downcase filename
) (car dirs
)))
894 ;; Try several variants of specified name.
895 (let ((suffix-list Info-suffix-list
)
896 (lfn (if (fboundp 'msdos-long-file-names
)
897 (msdos-long-file-names)
899 (while (and suffix-list
(not found
))
900 (cond ((info-file-exists-p
901 (info-insert-file-contents-1
902 temp
(car (car suffix-list
)) lfn
))
905 (info-insert-file-contents-1
906 temp-downcase
(car (car suffix-list
)) lfn
))
907 (setq found temp-downcase
))
908 ((and (fboundp 'msdos-long-file-names
)
911 (info-insert-file-contents-1
912 temp
(car (car suffix-list
)) nil
)))
914 (setq suffix-list
(cdr suffix-list
))))
915 (setq dirs
(cdr dirs
))))
917 (setq filename found
)
920 (error "Info file %s does not exist" filename
)))
923 (defun Info-find-node (filename nodename
&optional no-going-back
)
924 "Go to an Info node specified as separate FILENAME and NODENAME.
925 NO-GOING-BACK is non-nil if recovering from an error in this function;
926 it says do not attempt further (recursive) error recovery."
928 (setq filename
(Info-find-file filename
))
929 ;; Go into Info buffer.
930 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
931 ;; Record the node we are leaving, if we were in one.
932 (and (not no-going-back
)
934 (push (list Info-current-file Info-current-node
(point))
936 (Info-find-node-2 filename nodename no-going-back
))
939 (defun Info-on-current-buffer (&optional nodename
)
940 "Use Info mode to browse the current Info buffer.
941 With a prefix arg, this queries for the node name to visit first;
942 otherwise, that defaults to `Top'."
944 (list (if current-prefix-arg
945 (completing-read "Node name: " (Info-build-node-completions)
947 (unless nodename
(setq nodename
"Top"))
950 (set (make-local-variable 'Info-current-file
)
952 ;; If called on a non-file buffer, make a fake file name.
953 (concat default-directory
(buffer-name))))
954 (Info-find-node-2 nil nodename
))
956 (defun Info-revert-find-node (filename nodename
)
957 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
958 When *info* is already displaying FILENAME and NODENAME, the window position
959 is preserved, if possible."
960 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
961 (let ((old-filename Info-current-file
)
962 (old-nodename Info-current-node
)
963 (window-selected (eq (selected-window) (get-buffer-window)))
964 (pcolumn (current-column))
965 (pline (count-lines (point-min) (line-beginning-position)))
966 (wline (count-lines (point-min) (window-start)))
967 (new-history (and Info-current-file
968 (list Info-current-file Info-current-node
(point)))))
969 ;; When `Info-current-file' is nil, `Info-find-node-2' rereads the file.
970 (setq Info-current-file nil
)
971 (Info-find-node filename nodename
)
972 (if (and (equal old-filename Info-current-file
)
973 (equal old-nodename Info-current-node
))
975 ;; note goto-line is no good, we want to measure from point-min
976 (when window-selected
977 (goto-char (point-min))
979 (set-window-start (selected-window) (point)))
980 (goto-char (point-min))
982 (move-to-column pcolumn
))
983 ;; only add to the history when coming from a different file+node
985 (setq Info-history
(cons new-history Info-history
))))))
987 (defun Info-revert-buffer-function (_ignore-auto noconfirm
)
988 (when (or noconfirm
(y-or-n-p "Revert info buffer? "))
989 (Info-revert-find-node Info-current-file Info-current-node
)
990 (message "Reverted %s" Info-current-file
)))
992 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
993 "Find a node in a tag table.
994 MARKER specifies the buffer and position to start searching at.
995 REGEXP is a regular expression matching nodes or references. Its first
996 group should match `Node:' or `Ref:'.
997 CASE-FOLD t means search for a case-insensitive match.
998 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
999 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
1000 where the match was found, and MODE is `major-mode' of the buffer in
1001 which the match was found."
1002 (let ((case-fold-search case-fold
))
1003 (with-current-buffer (marker-buffer marker
)
1008 (when (re-search-forward regexp nil t
)
1009 (list (string-equal "Ref:" (match-string 1))
1010 (+ (point-min) (read (current-buffer)))
1013 (defun Info-find-in-tag-table (marker regexp
)
1014 "Find a node in a tag table.
1015 MARKER specifies the buffer and position to start searching at.
1016 REGEXP is a regular expression matching nodes or references. Its first
1017 group should match `Node:' or `Ref:'.
1018 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1019 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
1020 where the match was found, and MODE is `major-mode' of the buffer in
1021 which the match was found.
1022 This function tries to find a case-sensitive match first, then a
1023 case-insensitive match is tried."
1024 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
1025 (when (null (car result
))
1026 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
1029 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
1030 "Find a node or anchor in the current buffer.
1031 REGEXP is a regular expression matching nodes or references. Its first
1032 group should match `Node:' or `Ref:'.
1033 CASE-FOLD t means search for a case-insensitive match.
1034 Value is the position at which a match was found, or nil if not found."
1035 (let ((case-fold-search case-fold
)
1038 (if (Info-node-at-bob-matching regexp
)
1039 (setq found
(point))
1040 (while (and (not found
)
1041 (search-forward "\n\^_" nil t
))
1043 (let ((beg (point)))
1045 (if (re-search-backward regexp beg t
)
1046 (setq found
(line-beginning-position)))))))
1049 (defun Info-find-node-in-buffer (regexp)
1050 "Find a node or anchor in the current buffer.
1051 REGEXP is a regular expression matching nodes or references. Its first
1052 group should match `Node:' or `Ref:'.
1053 Value is the position at which a match was found, or nil if not found.
1054 This function looks for a case-sensitive match first. If none is found,
1055 a case-insensitive match is tried."
1056 (or (Info-find-node-in-buffer-1 regexp nil
)
1057 (Info-find-node-in-buffer-1 regexp t
)))
1059 (defun Info-find-node-2 (filename nodename
&optional no-going-back
)
1060 (buffer-disable-undo (current-buffer))
1061 (or (eq major-mode
'Info-mode
)
1064 (setq Info-current-node nil
)
1066 (let ((case-fold-search t
)
1067 (virtual-fun (Info-virtual-fun 'find-node
1068 (or filename Info-current-file
)
1072 ((functionp virtual-fun
)
1073 (let ((filename (or filename Info-current-file
)))
1074 (setq buffer-read-only nil
)
1075 (setq Info-current-file filename
1076 Info-current-subfile nil
1077 Info-current-file-completions nil
1078 buffer-file-name nil
)
1080 (Info-virtual-call virtual-fun filename nodename no-going-back
)
1081 (set-marker Info-tag-table-marker nil
)
1082 (setq buffer-read-only t
)
1083 (set-buffer-modified-p nil
)
1084 (set (make-local-variable 'Info-current-node-virtual
) t
)))
1086 ;; Reread a file when moving from a virtual node.
1087 (not Info-current-node-virtual
)
1089 (equal Info-current-file filename
))))
1090 ;; Switch files if necessary
1091 (let ((inhibit-read-only t
))
1092 (when Info-current-node-virtual
1093 ;; When moving from a virtual node.
1094 (set (make-local-variable 'Info-current-node-virtual
) nil
)
1096 (setq filename Info-current-file
)))
1097 (setq Info-current-file nil
1098 Info-current-subfile nil
1099 Info-current-file-completions nil
1100 buffer-file-name nil
)
1102 (info-insert-file-contents filename nil
)
1103 (setq default-directory
(file-name-directory filename
))
1104 (set-buffer-modified-p nil
)
1105 (set (make-local-variable 'Info-file-supports-index-cookies
)
1106 (Info-file-supports-index-cookies filename
))
1108 ;; See whether file has a tag table. Record the location if yes.
1109 (goto-char (point-max))
1111 ;; Use string-equal, not equal, to ignore text props.
1112 (if (not (or (string-equal nodename
"*")
1114 (search-forward "\^_\nEnd tag table\n" nil t
))))
1116 ;; We have a tag table. Find its beginning.
1117 ;; Is this an indirect file?
1118 (search-backward "\nTag table:\n")
1122 (looking-at "(Indirect)\n"))
1123 ;; It is indirect. Copy it to another buffer
1124 ;; and record that the tag table is in that buffer.
1125 (let ((buf (current-buffer))
1127 (or Info-tag-table-buffer
1128 (generate-new-buffer " *info tag table*"))))
1129 (setq Info-tag-table-buffer tagbuf
)
1130 (with-current-buffer tagbuf
1131 (buffer-disable-undo (current-buffer))
1132 (setq case-fold-search t
)
1134 (insert-buffer-substring buf
))
1135 (set-marker Info-tag-table-marker
1136 (match-end 0) tagbuf
))
1137 (set-marker Info-tag-table-marker pos
)))
1138 (set-marker Info-tag-table-marker nil
))
1139 (setq Info-current-file filename
)
1142 ;; Use string-equal, not equal, to ignore text props.
1143 (if (string-equal nodename
"*")
1144 (progn (setq Info-current-node nodename
)
1145 (Info-set-mode-line))
1148 ;; 1. Anchor found in tag table
1149 ;; 2. Anchor *not* in tag table
1151 ;; 3. Node found in tag table
1152 ;; 4. Node *not* found in tag table, but found in file
1153 ;; 5. Node *not* in tag table, and *not* in file
1155 ;; *Or* the same, but in an indirect subfile.
1157 ;; Search file for a suitable node.
1158 (let ((guesspos (point-min))
1159 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1160 (if (stringp nodename
)
1161 (regexp-quote nodename
)
1163 "\\) *[,\t\n\177]")))
1167 ;; First, search a tag table, if any
1168 (when (marker-position Info-tag-table-marker
)
1169 (let* ((m Info-tag-table-marker
)
1170 (found (Info-find-in-tag-table m regexp
)))
1173 ;; FOUND is (ANCHOR POS MODE).
1174 (setq guesspos
(nth 1 found
))
1176 ;; If this is an indirect file, determine which
1177 ;; file really holds this node and read it in.
1178 (unless (eq (nth 2 found
) 'Info-mode
)
1179 ;; Note that the current buffer must be the
1180 ;; *info* buffer on entry to
1181 ;; Info-read-subfile. Thus the hackery above.
1182 (setq guesspos
(Info-read-subfile guesspos
)))
1186 (goto-char (setq anchorpos guesspos
))
1189 ;; Else we may have a node, which we search for:
1190 (goto-char (max (point-min)
1191 (- (byte-to-position guesspos
) 1000)))
1193 ;; Now search from our advised position (or from beg of
1194 ;; buffer) to find the actual node. First, check
1195 ;; whether the node is right where we are, in case the
1196 ;; buffer begins with a node.
1197 (let ((pos (Info-find-node-in-buffer regexp
)))
1202 (when (string-match "\\([^.]+\\)\\." nodename
)
1203 (let (Info-point-loc)
1205 filename
(match-string 1 nodename
) no-going-back
))
1209 ;; No such anchor in tag table or node in tag table or file
1210 (user-error "No such node or anchor: %s" nodename
))
1213 (goto-char (point-min))
1214 (forward-line 1) ; skip header line
1215 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1216 ;; (forward-line 1))
1219 (let ((new-history (list Info-current-file
1220 (substring-no-properties nodename
))))
1221 ;; Add anchors to the history too
1222 (setq Info-history-list
1224 (remove new-history Info-history-list
))))
1225 (goto-char anchorpos
))
1226 ((numberp Info-point-loc
)
1227 (forward-line (- Info-point-loc
2))
1228 (setq Info-point-loc nil
))
1229 ((stringp Info-point-loc
)
1230 (Info-find-index-name Info-point-loc
)
1231 (setq Info-point-loc nil
))))))
1232 ;; If we did not finish finding the specified node,
1233 ;; go back to the previous one.
1234 (or Info-current-node no-going-back
(null Info-history
)
1235 (let ((hist (car Info-history
)))
1236 (setq Info-history
(cdr Info-history
))
1237 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
1238 (goto-char (nth 2 hist
))))))
1240 ;; Cache the contents of the (virtual) dir file, once we have merged
1241 ;; it for the first time, so we can save time subsequently.
1242 (defvar Info-dir-contents nil
)
1244 ;; Cache for the directory we decided to use for the default-directory
1245 ;; of the merged dir text.
1246 (defvar Info-dir-contents-directory nil
)
1248 ;; Record the file attributes of all the files from which we
1249 ;; constructed Info-dir-contents.
1250 (defvar Info-dir-file-attributes nil
)
1252 (defvar Info-dir-file-name nil
)
1254 ;; Construct the Info directory node by merging the files named `dir'
1255 ;; from various directories. Set the *info* buffer's
1256 ;; default-directory to the first directory we actually get any text
1258 (defun Info-insert-dir ()
1259 (if (and Info-dir-contents Info-dir-file-attributes
1260 ;; Verify that none of the files we used has changed
1261 ;; since we used it.
1263 (mapcar (lambda (elt)
1264 (let ((curr (file-attributes
1266 (file-truename (car elt
)))))
1268 ;; Don't compare the access time.
1269 (if curr
(setcar (nthcdr 4 curr
) 0))
1270 (setcar (nthcdr 4 (cdr elt
)) 0)
1271 (equal (cdr elt
) curr
)))
1272 Info-dir-file-attributes
))))
1274 (insert Info-dir-contents
)
1275 (goto-char (point-min)))
1276 (let ((dirs (if Info-additional-directory-list
1277 (append Info-directory-list
1278 Info-additional-directory-list
)
1279 Info-directory-list
))
1280 (dir-file-attrs nil
)
1281 ;; Bind this in case the user sets it to nil.
1282 (case-fold-search t
)
1283 ;; This is set non-nil if we find a problem in some input files.
1285 buffers buffer others nodes dirs-done
)
1287 ;; Search the directory list for the directory file.
1289 (let ((truename (file-truename (expand-file-name (car dirs
)))))
1290 (or (member truename dirs-done
)
1291 (member (directory-file-name truename
) dirs-done
)
1292 ;; Try several variants of specified name.
1293 ;; Try upcasing, appending `.info', or both.
1297 (progn (setq file
(expand-file-name "dir" truename
))
1298 (file-attributes file
))
1299 (progn (setq file
(expand-file-name "DIR" truename
))
1300 (file-attributes file
))
1301 (progn (setq file
(expand-file-name "dir.info" truename
))
1302 (file-attributes file
))
1303 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
1304 (file-attributes file
))
1305 ;; Shouldn't really happen, but sometimes does,
1306 ;; eg on Debian systems with buggy packages;
1307 ;; so may as well try it.
1308 ;; http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00005.html
1309 (progn (setq file
(expand-file-name "dir.gz" truename
))
1310 (file-attributes file
)))))
1313 (cons (directory-file-name truename
)
1316 (with-current-buffer (generate-new-buffer " info dir")
1318 (message "Composing main Info directory..."))
1320 ;; Index nodes include null bytes. DIR
1321 ;; files should not have indices, but who
1323 (let ((inhibit-null-byte-detection t
))
1324 (insert-file-contents file
)
1325 (set (make-local-variable 'Info-dir-file-name
)
1327 (push (current-buffer) buffers
)
1328 (push (cons file attrs
) dir-file-attrs
))
1329 (error (kill-buffer (current-buffer))))))))
1331 (set (make-local-variable 'Info-dir-contents-directory
)
1332 (file-name-as-directory (car dirs
))))
1333 (setq dirs
(cdr dirs
))))
1336 (error "Can't find the Info directory node"))
1338 ;; Distinguish the dir file that comes with Emacs from all the
1339 ;; others. Yes, that is really what this is supposed to do.
1340 ;; The definition of `Info-directory-list' puts it first on that
1341 ;; list and so last in `buffers' at this point.
1342 (setq buffer
(car (last buffers
))
1343 others
(delq buffer buffers
))
1345 ;; Insert the entire original dir file as a start; note that we've
1346 ;; already saved its default directory to use as the default
1347 ;; directory for the whole concatenation.
1348 (save-excursion (insert-buffer-substring buffer
))
1350 ;; Look at each of the other buffers one by one.
1351 (dolist (other others
)
1352 (let (this-buffer-nodes)
1353 ;; In each, find all the menus.
1354 (with-current-buffer other
1355 (goto-char (point-min))
1356 ;; Find each menu, and add an elt to NODES for it.
1357 (while (re-search-forward "^\\* Menu:" nil t
)
1358 (while (and (zerop (forward-line 1)) (eolp)))
1361 (re-search-backward "^\^_")
1362 (search-forward "Node: ")
1363 (setq nodename
(Info-following-node-name))
1364 (search-forward "\n\^_" nil
'move
)
1367 (push (list nodename other beg end
) this-buffer-nodes
)))
1368 (if (assoc-string "top" this-buffer-nodes t
)
1369 (setq nodes
(nconc this-buffer-nodes nodes
))
1371 (message "No `top' node in %s" Info-dir-file-name
)))))
1372 ;; Add to the main menu a menu item for each other node.
1373 (re-search-forward "^\\* Menu:")
1375 (let ((menu-items '("top"))
1376 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1377 (dolist (node nodes
)
1378 (let ((nodename (car node
)))
1380 (or (member (downcase nodename
) menu-items
)
1381 (re-search-forward (concat "^\\* +"
1382 (regexp-quote nodename
)
1386 (insert "* " nodename
"::" "\n")
1387 (push nodename menu-items
)))))))
1388 ;; Now take each node of each of the other buffers
1389 ;; and merge it into the main buffer.
1390 (dolist (node nodes
)
1391 (let ((case-fold-search t
)
1392 (nodename (car node
)))
1393 (goto-char (point-min))
1394 ;; Find the like-named node in the main buffer.
1395 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1396 (regexp-quote nodename
)
1400 (search-forward "\n\^_" nil
'move
)
1403 ;; If none exists, add one.
1404 (goto-char (point-max))
1405 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1406 ;; Merge the text from the other buffer's menu
1407 ;; into the menu in the like-named node in the main buffer.
1408 (apply 'insert-buffer-substring
(cdr node
))))
1409 (Info-dir-remove-duplicates)
1410 ;; Kill all the buffers we just made, including the special one excised.
1411 (mapc 'kill-buffer
(cons buffer buffers
))
1412 (goto-char (point-min))
1414 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1415 (message "Composing main Info directory...done"))
1416 (set (make-local-variable 'Info-dir-contents
) (buffer-string))
1417 (set (make-local-variable 'Info-dir-file-attributes
) dir-file-attrs
)))
1418 (setq default-directory Info-dir-contents-directory
))
1420 (defvar Info-streamline-headings
1421 '(("Emacs" .
"Emacs")
1422 ("Programming" .
"Programming")
1423 ("Libraries" .
"Libraries")
1424 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1425 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1427 (defun Info-dir-remove-duplicates ()
1429 (goto-char (point-min))
1430 ;; Remove duplicate headings in the same menu.
1431 (while (search-forward "\n* Menu:" nil t
)
1432 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1433 ;; Look for the next heading to unify.
1434 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1435 (let ((name (match-string 1))
1436 (start (match-beginning 0))
1438 ;; Check whether this heading should be streamlined.
1440 (dolist (x Info-streamline-headings
)
1441 (when (string-match (car x
) name
)
1443 (setq re
(car x
)))))
1444 (if re
(replace-match name t t nil
1))
1445 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1447 (or limit
(point-max))))
1448 ;; Look for other headings of the same category and merge them.
1450 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1451 (when (if re
(save-match-data (string-match re
(match-string 1)))
1452 (equal name
(match-string 1)))
1454 ;; Delete redundant heading.
1455 (delete-region (match-beginning 0) (point))
1456 ;; Push the entries onto `text'.
1458 (delete-and-extract-region
1460 (if (re-search-forward "^[^* \n\t]" nil t
)
1462 (or limit
(point-max))))
1465 ;; Insert the entries just found.
1466 (while (= (line-beginning-position 0) (1- (point)))
1468 (dolist (entry (nreverse entries
))
1470 (while (= (line-beginning-position 0) (1- (point)))
1471 (delete-region (1- (point)) (point))))
1473 ;; Now remove duplicate entries under the same heading.
1476 (narrow-to-region start
(point))
1477 (goto-char (point-min))
1478 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil
'move
)
1479 ;; Fold case straight away; `member-ignore-case' here wasteful.
1480 (let ((x (downcase (match-string 1))))
1484 (if (re-search-forward "^[^ \t]" nil
'move
)
1485 (goto-char (match-beginning 0))
1487 (push x seen
)))))))))))
1489 ;; Note that on entry to this function the current-buffer must be the
1490 ;; *info* buffer; not the info tags buffer.
1491 (defun Info-read-subfile (nodepos)
1492 ;; NODEPOS is either a position (in the Info file as a whole,
1493 ;; not relative to a subfile) or the name of a subfile.
1496 (if (numberp nodepos
)
1497 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1498 (goto-char (point-min))
1499 (or (looking-at "\^_")
1500 (search-forward "\n\^_"))
1503 (while (not (looking-at "\^_"))
1506 thisfilepos thisfilename
)
1507 (search-forward ": ")
1508 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1509 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1510 ;; read in version 19 stops at the end of number.
1511 ;; Advance to the next line.
1513 (if (> thisfilepos nodepos
)
1515 (setq lastfilename thisfilename
)
1516 (setq lastfilepos thisfilepos
))
1517 (forward-line 1)))))
1518 (setq lastfilename nodepos
)
1519 (setq lastfilepos
0))
1520 ;; Assume previous buffer is in Info-mode.
1521 ;; (set-buffer (get-buffer "*info*"))
1522 (or (equal Info-current-subfile lastfilename
)
1523 (let ((inhibit-read-only t
))
1524 (setq buffer-file-name nil
)
1527 (info-insert-file-contents lastfilename
)
1528 (set-buffer-modified-p nil
)
1529 (setq Info-current-subfile lastfilename
)))
1530 ;; Widen in case we are in the same subfile as before.
1532 (goto-char (point-min))
1533 (if (looking-at "\^_")
1535 (search-forward "\n\^_"))
1536 (if (numberp nodepos
)
1537 (+ (- nodepos lastfilepos
) (point)))))
1539 (defun Info-unescape-quotes (value)
1540 "Unescape double quotes and backslashes in VALUE."
1543 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1544 (setq unquote
(replace-match "" t t unquote
1))
1545 (setq start
(- (match-end 0) 1)))
1548 ;; As of Texinfo 4.6, makeinfo writes constructs like
1549 ;; \0\h[image param=value ...\h\0]
1550 ;; into the Info file for handling images.
1551 (defun Info-split-parameter-string (parameter-string)
1552 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
1553 PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
1554 If VALUE contains whitespace or double quotes, it must be quoted
1555 in double quotes and any double quotes or backslashes must be
1556 escaped (\\\",\\\\)."
1559 (while (string-match
1560 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1561 parameter-string start
)
1562 (setq start
(match-end 0))
1563 (push (cons (match-string 1 parameter-string
)
1564 (or (match-string 2 parameter-string
)
1565 (Info-unescape-quotes
1566 (match-string 3 parameter-string
))))
1570 (defun Info-display-images-node ()
1571 "Display images in current node."
1573 (let ((inhibit-read-only t
)
1574 (case-fold-search t
))
1575 (goto-char (point-min))
1576 (while (re-search-forward
1577 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1579 (let* ((start (match-beginning 1))
1580 (parameter-alist (Info-split-parameter-string (match-string 2)))
1581 (src (cdr (assoc-string "src" parameter-alist
))))
1582 (if (display-images-p)
1583 (let* ((image-file (if src
(if (file-name-absolute-p src
) src
1584 (concat default-directory src
))
1586 (image (if (file-exists-p image-file
)
1587 (create-image image-file
)
1589 (if (not (get-text-property start
'display
))
1590 (add-text-properties
1591 start
(point) `(display ,image rear-nonsticky
(display)))))
1592 ;; text-only display, show alternative text if provided, or
1593 ;; otherwise a clue that there's meant to be a picture
1594 (delete-region start
(point))
1595 (insert (or (cdr (assoc-string "text" parameter-alist
))
1596 (cdr (assoc-string "alt" parameter-alist
))
1598 (concat "[image:" src
"]"))
1600 (set-buffer-modified-p nil
)))
1602 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1603 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1604 ;; including one optional trailing newline.
1605 (defun Info-hide-cookies-node ()
1606 "Hide unrecognized cookies in current node."
1608 (let ((inhibit-read-only t
)
1609 (case-fold-search t
))
1610 (goto-char (point-min))
1611 (while (re-search-forward
1612 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1614 (let* ((start (match-beginning 1)))
1615 (if (and (not (get-text-property start
'invisible
))
1616 (not (get-text-property start
'display
)))
1617 (put-text-property start
(point) 'invisible t
)))))
1618 (set-buffer-modified-p nil
)))
1620 (defun Info-select-node ()
1621 "Select the Info node that point is in."
1622 ;; Bind this in case the user sets it to nil.
1623 (let ((case-fold-search t
))
1625 ;; Find beginning of node.
1626 (if (search-backward "\n\^_" nil
'move
)
1628 (if (looking-at "\^_")
1630 (signal 'search-failed
(list "\n\^_"))))
1631 ;; Get nodename spelled as it is in the node.
1632 (re-search-forward "Node:[ \t]*")
1633 (setq Info-current-node
1634 (buffer-substring-no-properties (point)
1636 (skip-chars-forward "^,\t\n")
1638 (Info-set-mode-line)
1639 ;; Find the end of it, and narrow.
1641 (let (active-expression)
1642 ;; Narrow to the node contents
1643 (narrow-to-region (point)
1644 (if (re-search-forward "\n[\^_\f]" nil t
)
1647 (if (looking-at "[\n\^_\f]*execute: ")
1649 (goto-char (match-end 0))
1650 (setq active-expression
1651 (read (current-buffer))))))
1653 (if Info-enable-active-nodes
(eval active-expression
))
1654 ;; Add a new unique history item to full history list
1655 (let ((new-history (list Info-current-file Info-current-node
)))
1656 (setq Info-history-list
1657 (cons new-history
(remove new-history Info-history-list
)))
1658 (setq Info-history-forward nil
))
1659 (if (not (eq Info-fontify-maximum-menu-size nil
))
1660 (Info-fontify-node))
1661 (Info-display-images-node)
1662 (Info-hide-cookies-node)
1663 (run-hooks 'Info-selection-hook
)))))
1665 (defvar Info-mode-line-node-keymap
1666 (let ((map (make-sparse-keymap)))
1667 (define-key map
[mode-line mouse-1
] 'Info-mouse-scroll-up
)
1668 (define-key map
[mode-line mouse-3
] 'Info-mouse-scroll-down
)
1670 "Keymap to put on the Info node name in the mode line.")
1672 (defun Info-set-mode-line ()
1673 (setq mode-line-buffer-identification
1674 (nconc (propertized-buffer-identification "%b")
1678 (if (stringp Info-current-file
)
1679 (replace-regexp-in-string
1681 (file-name-sans-extension
1682 (file-name-nondirectory Info-current-file
)))
1683 (format "*%S*" Info-current-file
))
1685 (if Info-current-node
1686 (propertize (replace-regexp-in-string
1687 "%" "%%" Info-current-node
)
1688 'face
'mode-line-buffer-id
1690 "mouse-1: scroll forward, mouse-3: scroll back"
1691 'mouse-face
'mode-line-highlight
1692 'local-map Info-mode-line-node-keymap
)
1695 ;; Go to an Info node specified with a filename-and-nodename string
1696 ;; of the sort that is found in pointers in nodes.
1698 ;; Don't autoload this function: the correct entry point for other packages
1699 ;; to use is `info'. --Stef
1701 (defun Info-goto-node (nodename &optional fork
)
1702 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1703 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1704 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1706 Completion is available for node names in the current Info file as well as
1707 in the Info file FILENAME after the closing parenthesis in (FILENAME).
1708 Empty NODENAME in (FILENAME) defaults to the Top node.
1709 If FORK is non-nil (interactively with a prefix arg), show the node in
1711 If FORK is a string, it is the name to use for the new buffer."
1712 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1716 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1718 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1720 (setq filename
(if (= (match-beginning 1) (match-end 1))
1722 (match-string 2 nodename
))
1723 nodename
(match-string 3 nodename
))
1724 (let ((trim (string-match "\\s +\\'" filename
)))
1725 (if trim
(setq filename
(substring filename
0 trim
))))
1726 (let ((trim (string-match "\\s +\\'" nodename
)))
1727 (if trim
(setq nodename
(substring nodename
0 trim
))))
1728 (if transient-mark-mode
(deactivate-mark))
1729 (Info-find-node (if (equal filename
"") nil filename
)
1730 (if (equal nodename
"") "Top" nodename
))))
1732 (defvar Info-read-node-completion-table
)
1734 (defun Info-read-node-name-2 (dirs suffixes string pred action
)
1735 "Internal function used to complete Info node names.
1736 Return a completion table for Info files---the FILENAME part of a
1737 node named \"(FILENAME)NODENAME\". DIRS is a list of Info
1738 directories to search if FILENAME is not absolute; SUFFIXES is a
1739 list of valid filename suffixes for Info files. See
1740 `try-completion' for a description of the remaining arguments."
1741 (setq suffixes
(remove "" suffixes
))
1742 (when (file-name-absolute-p string
)
1743 (setq dirs
(list (file-name-directory string
))))
1745 (names-sans-suffix nil
)
1746 (suffix (concat (regexp-opt suffixes t
) "\\'"))
1747 (string-dir (file-name-directory string
)))
1750 (setq dir default-directory
))
1751 (if string-dir
(setq dir
(expand-file-name string-dir dir
)))
1752 (when (file-directory-p dir
)
1753 (dolist (file (file-name-all-completions
1754 (file-name-nondirectory string
) dir
))
1755 ;; If the file name has no suffix or a standard suffix,
1757 (and (or (null (file-name-extension file
))
1758 (string-match suffix file
))
1759 ;; But exclude subfiles of split Info files.
1760 (not (string-match "-[0-9]+\\'" file
))
1761 ;; And exclude backup files.
1762 (not (string-match "~\\'" file
))
1763 (push (if string-dir
(concat string-dir file
) file
) names
))
1764 ;; If the file name ends in a standard suffix,
1765 ;; add the unsuffixed name as a completion option.
1766 (when (string-match suffix file
)
1767 (setq file
(substring file
0 (match-beginning 0)))
1768 (push (if string-dir
(concat string-dir file
) file
)
1769 names-sans-suffix
)))))
1770 ;; If there is just one file, don't duplicate it with suffixes,
1771 ;; so `Info-read-node-name-1' will be able to complete a single
1772 ;; candidate and to add the terminating ")".
1773 (if (and (= (length names
) 1) (= (length names-sans-suffix
) 1))
1774 (setq names names-sans-suffix
)
1775 (setq names
(append names-sans-suffix names
)))
1776 (complete-with-action action names string pred
)))
1778 (defun Info-read-node-name-1 (string predicate code
)
1779 "Internal function used by `Info-read-node-name'.
1780 See `completing-read' for a description of arguments and usage."
1782 ;; First complete embedded file names.
1783 ((string-match "\\`([^)]*\\'" string
)
1784 (completion-table-with-context
1786 (apply-partially 'completion-table-with-terminator
")"
1787 (apply-partially 'Info-read-node-name-2
1789 (mapcar 'car Info-suffix-list
)))
1790 (substring string
1)
1793 ;; If a file name was given, complete nodes in the file.
1794 ((string-match "\\`(\\([^)]+\\))" string
)
1795 (let ((file0 (match-string 0 string
))
1796 (file1 (match-string 1 string
))
1797 (nodename (substring string
(match-end 0))))
1798 (if (and (equal nodename
"") (eq code
'lambda
))
1799 ;; Empty node name is permitted that means "Top".
1801 (completion-table-with-context
1804 (lambda (string pred action
)
1805 (complete-with-action
1807 (Info-build-node-completions (Info-find-file file1
))
1809 nodename predicate code
))))
1810 ;; Otherwise use Info-read-node-completion-table.
1811 (t (complete-with-action
1812 code Info-read-node-completion-table string predicate
))))
1814 ;; Arrange to highlight the proper letters in the completion list buffer.
1815 (defun Info-read-node-name (prompt)
1816 "Read an Info node name with completion, prompting with PROMPT.
1817 A node name can have the form \"NODENAME\", referring to a node
1818 in the current Info file, or \"(FILENAME)NODENAME\", referring to
1819 a node in FILENAME. \"(FILENAME)\" is a short format to go to
1820 the Top node in FILENAME."
1821 (let* ((completion-ignore-case t
)
1822 (Info-read-node-completion-table (Info-build-node-completions))
1823 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1824 (if (equal nodename
"")
1825 (Info-read-node-name prompt
)
1828 (defun Info-build-node-completions (&optional filename
)
1830 (or (cdr (assoc filename Info-file-completions
))
1833 (Info-goto-node (format "(%s)Top" filename
))
1834 (Info-build-node-completions-1)
1835 (push (cons filename Info-current-file-completions
) Info-file-completions
)
1836 Info-current-file-completions
))
1837 (or Info-current-file-completions
1838 (Info-build-node-completions-1))))
1840 (defun Info-build-node-completions-1 ()
1842 ;; Bind this in case the user sets it to nil.
1843 (case-fold-search t
)
1844 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1847 (or Info-tag-table-marker
1848 (error "No Info tags found"))
1849 (if (marker-buffer Info-tag-table-marker
)
1850 (let ((marker Info-tag-table-marker
))
1851 (set-buffer (marker-buffer marker
))
1854 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1856 (cons (list (match-string-no-properties 2))
1859 (goto-char (point-min))
1860 ;; If the buffer begins with a node header, process that first.
1861 (if (Info-node-at-bob-matching node-regexp
)
1862 (setq compl
(list (match-string-no-properties 1))))
1863 ;; Now for the rest of the nodes.
1864 (while (search-forward "\n\^_" nil t
)
1866 (let ((beg (point)))
1868 (if (re-search-backward node-regexp beg t
)
1870 (cons (list (match-string-no-properties 1))
1872 (setq compl
(cons '("*") (nreverse compl
)))
1873 (set (make-local-variable 'Info-current-file-completions
) compl
)
1877 (defun Info-restore-point (hl)
1878 "If this node has been visited, restore the point value when we left."
1880 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1881 ;; Use string-equal, not equal, to ignore text props.
1882 (string-equal (nth 1 (car hl
)) Info-current-node
))
1884 (goto-char (nth 2 (car hl
)))
1885 (setq hl nil
)) ;terminate the while at next iter
1886 (setq hl
(cdr hl
)))))
1888 (defvar Info-search-history nil
1889 "The history list for `Info-search'.")
1891 (defvar Info-search-case-fold nil
1892 "The value of `case-fold-search' from previous `Info-search' command.")
1894 (defun Info-search (regexp &optional bound _noerror _count direction
)
1895 "Search for REGEXP, starting from point, and select node it's found in.
1896 If DIRECTION is `backward', search in the reverse direction."
1897 (interactive (list (read-string
1898 (if Info-search-history
1899 (format "Regexp search%s (default %s): "
1900 (if case-fold-search
"" " case-sensitively")
1901 (car Info-search-history
))
1902 (format "Regexp search%s: "
1903 (if case-fold-search
"" " case-sensitively")))
1904 nil
'Info-search-history
)))
1906 (when (equal regexp
"")
1907 (setq regexp
(car Info-search-history
)))
1909 (let (found beg-found give-up
1910 (backward (eq direction
'backward
))
1911 (onode Info-current-node
)
1912 (ofile Info-current-file
)
1914 (opoint-min (point-min))
1915 (opoint-max (point-max))
1916 (ostart (window-start))
1917 (osubfile Info-current-subfile
))
1918 (setq Info-search-case-fold case-fold-search
)
1923 ;; Hide Info file header for backward search
1924 (narrow-to-region (save-excursion
1925 (goto-char (point-min))
1926 (search-forward "\n\^_")
1929 (while (and (not give-up
)
1931 (not (funcall isearch-filter-predicate beg-found found
))))
1932 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1934 (re-search-backward regexp bound t
)
1935 (re-search-forward regexp bound t
))
1936 (setq found
(point) beg-found
(if backward
(match-end 0)
1937 (match-beginning 0)))
1938 (setq give-up t
))))))
1940 (when (and isearch-mode Info-isearch-search
1941 (not Info-isearch-initial-node
)
1943 (or give-up
(and found
(not (and (> found opoint-min
)
1944 (< found opoint-max
))))))
1945 (signal 'search-failed
(list regexp
"end of node")))
1947 ;; If no subfiles, give error now.
1949 (if (null Info-current-subfile
)
1951 (signal 'search-failed
(list regexp
"end of manual"))
1952 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1954 (re-search-backward regexp
)
1955 (re-search-forward regexp
))))
1958 (if (and bound
(not found
))
1959 (signal 'search-failed
(list regexp
)))
1961 (unless (or found bound
)
1963 ;; Try other subfiles.
1965 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1966 (goto-char (point-min))
1967 (search-forward "\n\^_\nIndirect:")
1969 (narrow-to-region (point)
1970 (progn (search-forward "\n\^_")
1972 (goto-char (point-min))
1973 ;; Find the subfile we just searched.
1974 (search-forward (concat "\n" osubfile
": "))
1976 (forward-line (if backward
0 1))
1977 (if backward
(forward-char -
1))
1978 ;; Make a list of all following subfiles.
1979 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
1980 (while (not (if backward
(bobp) (eobp)))
1982 (re-search-backward "\\(^.*\\): [0-9]+$")
1983 (re-search-forward "\\(^.*\\): [0-9]+$"))
1984 (goto-char (+ (match-end 1) 2))
1985 (setq list
(cons (cons (+ (point-min)
1986 (read (current-buffer)))
1987 (match-string-no-properties 1))
1989 (goto-char (if backward
1990 (1- (match-beginning 0))
1991 (1+ (match-end 0)))))
1992 ;; Put in forward order
1993 (setq list
(nreverse list
))))
1995 (message "Searching subfile %s..." (cdr (car list
)))
1996 (Info-read-subfile (car (car list
)))
1998 ;; Hide Info file header for backward search
1999 (narrow-to-region (save-excursion
2000 (goto-char (point-min))
2001 (search-forward "\n\^_")
2004 (goto-char (point-max)))
2005 (setq list
(cdr list
))
2006 (setq give-up nil found nil
)
2007 (while (and (not give-up
)
2009 (not (funcall isearch-filter-predicate beg-found found
))))
2010 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
2012 (re-search-backward regexp nil t
)
2013 (re-search-forward regexp nil t
))
2014 (setq found
(point) beg-found
(if backward
(match-end 0)
2015 (match-beginning 0)))
2023 (signal 'search-failed
(if isearch-mode
2024 (list regexp
"end of manual")
2027 (progn (Info-read-subfile osubfile
)
2030 (set-window-start (selected-window) ostart
)))))
2032 (if (and (string= osubfile Info-current-subfile
)
2033 (> found opoint-min
)
2034 (< found opoint-max
))
2035 ;; Search landed in the same node
2039 (save-match-data (Info-select-node)))
2041 ;; Use string-equal, not equal, to ignore text props.
2042 (or (and (string-equal onode Info-current-node
)
2043 (equal ofile Info-current-file
))
2044 (and isearch-mode isearch-wrapped
2045 (eq opoint
(if isearch-forward opoint-min opoint-max
)))
2046 (setq Info-history
(cons (list ofile onode opoint
)
2049 (defun Info-search-case-sensitively ()
2050 "Search for a regexp case-sensitively."
2052 (let ((case-fold-search nil
))
2053 (call-interactively 'Info-search
)))
2055 (defun Info-search-next ()
2056 "Search for next regexp from a previous `Info-search' command."
2058 (let ((case-fold-search Info-search-case-fold
))
2059 (if Info-search-history
2060 (Info-search (car Info-search-history
))
2061 (call-interactively 'Info-search
))))
2063 (defun Info-search-backward (regexp &optional bound noerror count
)
2064 "Search for REGEXP in the reverse direction."
2065 (interactive (list (read-string
2066 (if Info-search-history
2067 (format "Regexp search%s backward (default %s): "
2068 (if case-fold-search
"" " case-sensitively")
2069 (car Info-search-history
))
2070 (format "Regexp search%s backward: "
2071 (if case-fold-search
"" " case-sensitively")))
2072 nil
'Info-search-history
)))
2073 (Info-search regexp bound noerror count
'backward
))
2075 (defun Info-isearch-search ()
2076 (if Info-isearch-search
2077 (lambda (string &optional bound noerror count
)
2078 (let ((Info-search-whitespace-regexp
2079 (if (if isearch-regexp
2080 isearch-regexp-lax-whitespace
2081 isearch-lax-whitespace
)
2082 search-whitespace-regexp
)))
2086 ;; Lax version of word search
2087 (let ((lax (not (or isearch-nonincremental
2089 (length (isearch--state-string
2090 (car isearch-cmds
))))))))
2091 (if (functionp isearch-word
)
2092 (funcall isearch-word string lax
)
2093 (word-search-regexp string lax
))))
2094 (isearch-regexp string
)
2095 (t (regexp-quote string
)))
2097 (unless isearch-forward
'backward
)))
2099 (isearch-search-fun-default)))
2101 (defun Info-isearch-wrap ()
2102 (if Info-isearch-search
2103 (if Info-isearch-initial-node
2105 (if isearch-forward
(Info-top-node) (Info-final-node))
2106 (goto-char (if isearch-forward
(point-min) (point-max))))
2107 (setq Info-isearch-initial-node Info-current-node
)
2108 (setq isearch-wrapped nil
))
2109 (goto-char (if isearch-forward
(point-min) (point-max)))))
2111 (defun Info-isearch-push-state ()
2113 (Info-isearch-pop-state cmd
',Info-current-file
',Info-current-node
)))
2115 (defun Info-isearch-pop-state (_cmd file node
)
2116 (or (and (equal Info-current-file file
)
2117 (equal Info-current-node node
))
2118 (progn (Info-find-node file node
) (sit-for 0))))
2120 (defun Info-isearch-start ()
2121 (setq Info-isearch-initial-node
2122 ;; Don't stop at initial node for nonincremental search.
2123 ;; Otherwise this variable is set after first search failure.
2124 (and isearch-nonincremental Info-current-node
))
2125 (setq Info-isearch-initial-history Info-history
2126 Info-isearch-initial-history-list Info-history-list
)
2127 (add-hook 'isearch-mode-end-hook
'Info-isearch-end nil t
))
2129 (defun Info-isearch-end ()
2130 ;; Remove intermediate nodes (visited while searching)
2131 ;; from the history. Add only the last node (where Isearch ended).
2132 (if (> (length Info-history
)
2133 (length Info-isearch-initial-history
))
2135 (nthcdr (- (length Info-history
)
2136 (length Info-isearch-initial-history
)
2139 (if (> (length Info-history-list
)
2140 (length Info-isearch-initial-history-list
))
2141 (setq Info-history-list
2142 (cons (car Info-history-list
)
2143 Info-isearch-initial-history-list
)))
2144 (remove-hook 'isearch-mode-end-hook
'Info-isearch-end t
))
2146 (defun Info-isearch-filter (beg-found found
)
2147 "Test whether the current search hit is a visible useful text.
2148 Return non-nil if the text from BEG-FOUND to FOUND is visible
2149 and is not in the header line or a tag table."
2151 (let ((backward (< found beg-found
)))
2154 (and (not search-invisible
)
2156 (or (text-property-not-all found beg-found
'invisible nil
)
2157 (text-property-not-all found beg-found
'display nil
))
2158 (or (text-property-not-all beg-found found
'invisible nil
)
2159 (text-property-not-all beg-found found
'display nil
))))
2160 ;; Skip node header line
2161 (and (save-excursion (forward-line -
1)
2163 (forward-line (if backward -
1 1)))
2164 ;; Skip Tag Table node
2166 (and (search-backward "\^_" nil t
)
2168 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
2171 (defun Info-extract-pointer (name &optional errorname
)
2172 "Extract the value of the node-pointer named NAME.
2173 If there is none, use ERRORNAME in the error message;
2174 if ERRORNAME is nil, just return nil."
2175 ;; Bind this in case the user sets it to nil.
2176 (let ((case-fold-search t
))
2178 (goto-char (point-min))
2179 (let ((bound (point)))
2181 (cond ((re-search-backward
2182 (concat name
":" (Info-following-node-name-re)) bound t
)
2183 (match-string-no-properties 1))
2184 ((not (eq errorname t
))
2185 (user-error "Node has no %s"
2186 (capitalize (or errorname name
)))))))))
2188 (defun Info-following-node-name-re (&optional allowedchars
)
2189 "Return a regexp matching a node name.
2190 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
2191 saying which chars may appear in the node name.
2192 Submatch 1 is the complete node name.
2193 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2194 Submatch 3 is the local part of the node name.
2195 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2196 (concat "[ \t\n]*" ;Skip leading space.
2197 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2198 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
2199 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
2200 "\\|\\)\\)")) ;Allow empty node names.
2202 ;;; For compatibility; other files have used this name.
2203 (defun Info-following-node-name ()
2204 (and (looking-at (Info-following-node-name-re))
2205 (match-string-no-properties 1)))
2208 "Go to the next node of this node."
2210 ;; In case another window is currently selected
2211 (save-window-excursion
2212 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
2213 (Info-goto-node (Info-extract-pointer "next"))))
2216 "Go to the previous node of this node."
2218 ;; In case another window is currently selected
2219 (save-window-excursion
2220 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
2221 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2223 (defun Info-up (&optional same-file
)
2224 "Go to the superior node of this node.
2225 If SAME-FILE is non-nil, do not move to a different Info file."
2227 ;; In case another window is currently selected
2228 (save-window-excursion
2229 (or (eq major-mode
'Info-mode
) (switch-to-buffer "*info*"))
2230 (let ((old-node Info-current-node
)
2231 (old-file Info-current-file
)
2232 (node (Info-extract-pointer "up")) p
)
2234 (string-match "^(" node
)
2235 (error "Up node is in another Info file"))
2236 (Info-goto-node node
)
2238 (goto-char (point-min))
2239 (if (and (stringp old-file
)
2240 (search-forward "\n* Menu:" nil t
)
2242 (if (string-equal old-node
"Top")
2243 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
2244 (concat "\n\\* +\\(" (regexp-quote old-node
)
2245 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
2247 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2249 (Info-restore-point Info-history
)))))
2251 (defun Info-history-back ()
2252 "Go back in the history to the last node visited."
2255 (user-error "This is the first Info node you looked at"))
2256 (let ((history-forward
2257 (cons (list Info-current-file Info-current-node
(point))
2258 Info-history-forward
))
2259 filename nodename opoint
)
2260 (setq filename
(car (car Info-history
)))
2261 (setq nodename
(car (cdr (car Info-history
))))
2262 (setq opoint
(car (cdr (cdr (car Info-history
)))))
2263 (setq Info-history
(cdr Info-history
))
2264 (Info-find-node filename nodename
)
2265 (setq Info-history
(cdr Info-history
))
2266 (setq Info-history-forward history-forward
)
2267 (goto-char opoint
)))
2269 (defalias 'Info-last
'Info-history-back
)
2271 (defun Info-history-forward ()
2272 "Go forward in the history of visited nodes."
2274 (or Info-history-forward
2275 (user-error "This is the last Info node you looked at"))
2276 (let ((history-forward (cdr Info-history-forward
))
2277 filename nodename opoint
)
2278 (setq filename
(car (car Info-history-forward
)))
2279 (setq nodename
(car (cdr (car Info-history-forward
))))
2280 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
2281 (Info-find-node filename nodename
)
2282 (setq Info-history-forward history-forward
)
2283 (goto-char opoint
)))
2285 (add-to-list 'Info-virtual-files
2287 (toc-nodes . Info-directory-toc-nodes
)
2288 (find-file . Info-directory-find-file
)
2289 (find-node . Info-directory-find-node
)
2292 (defun Info-directory-toc-nodes (filename)
2293 "Directory-specific implementation of `Info-toc-nodes'."
2295 ("Top" nil nil nil
)))
2297 (defun Info-directory-find-file (filename &optional _noerror
)
2298 "Directory-specific implementation of `Info-find-file'."
2301 (defun Info-directory-find-node (_filename _nodename
&optional _no-going-back
)
2302 "Directory-specific implementation of `Info-find-node-2'."
2306 (defun Info-directory ()
2307 "Go to the Info directory node."
2309 (Info-find-node "dir" "top"))
2311 (add-to-list 'Info-virtual-files
2312 '("\\`\\*History\\*\\'"
2313 (toc-nodes . Info-history-toc-nodes
)
2314 (find-file . Info-history-find-file
)
2315 (find-node . Info-history-find-node
)
2318 (defun Info-history-toc-nodes (filename)
2319 "History-specific implementation of `Info-toc-nodes'."
2321 ("Top" nil nil nil
)))
2323 (defun Info-history-find-file (filename &optional _noerror
)
2324 "History-specific implementation of `Info-find-file'."
2327 (defun Info-history-find-node (filename nodename
&optional _no-going-back
)
2328 "History-specific implementation of `Info-find-node-2'."
2329 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2330 (or filename Info-current-file
) nodename
))
2331 (insert "Recently Visited Nodes\n")
2332 (insert "**********************\n\n")
2333 (insert "* Menu:\n\n")
2334 (let ((hl (remove '("*History*" "Top") Info-history-list
)))
2336 (let ((file (nth 0 (car hl
)))
2337 (node (nth 1 (car hl
))))
2339 (insert "* " node
": ("
2340 (propertize (or (file-name-directory file
) "") 'invisible t
)
2341 (file-name-nondirectory file
)
2343 (setq hl
(cdr hl
)))))
2345 (defun Info-history ()
2346 "Go to a node with a menu of visited nodes."
2348 (Info-find-node "*History*" "Top")
2349 (Info-next-reference)
2350 (Info-next-reference))
2352 (add-to-list 'Info-virtual-nodes
2354 (find-node . Info-toc-find-node
)
2357 (defun Info-toc-find-node (filename nodename
&optional _no-going-back
)
2358 "Toc-specific implementation of `Info-find-node-2'."
2359 (let* ((curr-file (substring-no-properties (or filename Info-current-file
)))
2360 (curr-node (substring-no-properties (or nodename Info-current-node
)))
2361 (node-list (Info-toc-nodes curr-file
)))
2362 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2363 curr-file curr-node
))
2364 (insert "Table of Contents\n")
2365 (insert "*****************\n\n")
2366 (insert "*Note Top::\n")
2368 (nth 3 (assoc "Top" node-list
)) ; get Top nodes
2369 node-list
0 curr-file
)
2371 (let ((Info-hide-note-references 'hide
)
2372 (Info-fontify-visited-nodes nil
))
2373 (setq Info-current-file filename Info-current-node
"*TOC*")
2374 (goto-char (point-min))
2375 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
2382 "Go to a node with table of contents of the current Info file.
2383 Table of contents is created from the tree structure of menus."
2385 (Info-find-node Info-current-file
"*TOC*")
2386 (let ((prev-node (nth 1 (car Info-history
))) p
)
2387 (goto-char (point-min))
2388 (if (setq p
(search-forward (concat "*Note " prev-node
":") nil t
))
2389 (setq p
(- p
(length prev-node
) 2)))
2390 (goto-char (or p
(point-min)))))
2392 (defun Info-toc-insert (nodes node-list level curr-file
)
2393 "Insert table of contents with references to nodes."
2394 (let ((section "Top"))
2396 (let ((node (assoc (car nodes
) node-list
)))
2397 (unless (member (nth 2 node
) (list nil section
))
2398 (insert (setq section
(nth 2 node
)) "\n"))
2399 (insert (make-string level ?
\t))
2400 (insert "*Note " (car nodes
) ":: \n")
2401 (Info-toc-insert (nth 3 node
) node-list
(1+ level
) curr-file
)
2402 (setq nodes
(cdr nodes
))))))
2404 (defun Info-toc-build (file)
2405 "Build table of contents from menus of Info FILE and its subfiles."
2407 (let* ((file (and (stringp file
) (Info-find-file file
)))
2408 (default-directory (or (and (stringp file
)
2409 (file-name-directory file
))
2411 (main-file (and (stringp file
) file
))
2412 (sections '(("Top" "Top")))
2414 (while (or main-file subfiles
)
2415 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2417 (info-insert-file-contents (or main-file
(car subfiles
)))
2418 (goto-char (point-min))
2419 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
2420 (search-forward "Node: " nil
'move
))
2421 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2422 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
2424 (upnode (and (re-search-forward
2425 (concat "Up:" (Info-following-node-name-re))
2427 (match-string-no-properties 1)))
2430 (when (and upnode
(string-match "(" upnode
)) (setq upnode nil
))
2431 (when (and (not (Info-index-node nodename file
))
2432 (re-search-forward "^\\* Menu:" bound t
))
2435 (setq bound
(or (and (equal nodename
"Top")
2438 "^[ \t-]*The Detailed Node Listing" nil t
)))
2440 (while (< (point) bound
)
2443 ((looking-at "^\\* +[^:]+:")
2446 (let ((menu-node-name (substring-no-properties
2447 (Info-extract-menu-node-name))))
2448 (setq menu-items
(cons menu-node-name menu-items
))
2449 (if (equal nodename
"Top")
2451 (cons (list menu-node-name section
) sections
)))))
2452 ;; Other non-empty strings in the Top node are section names
2453 ((and (equal nodename
"Top")
2454 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2455 (setq section
(match-string-no-properties 1))))
2457 (beginning-of-line)))
2458 (setq nodes
(cons (list nodename upnode
2459 (cadr (assoc nodename sections
))
2460 (nreverse menu-items
))
2465 (goto-char (point-min))
2466 (if (search-forward "\n\^_\nIndirect:" nil t
)
2467 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2468 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2469 (setq subfiles
(cons (match-string-no-properties 1)
2471 (setq subfiles
(nreverse subfiles
)
2473 (setq subfiles
(cdr subfiles
))))
2477 (defun Info-toc-nodes (filename)
2478 "Return a node list of Info FILENAME with parent-children information.
2479 This information is cached in the variable `Info-toc-nodes' with the help
2480 of the function `Info-toc-build'."
2483 (Info-virtual-fun 'toc-nodes
(or filename Info-current-file
) nil
)
2486 (or filename
(setq filename Info-current-file
))
2487 (or (assoc filename Info-toc-nodes
)
2488 ;; Skip virtual Info files
2489 (and (or (not (stringp filename
))
2490 (Info-virtual-file-p filename
))
2491 (push (cons filename nil
) Info-toc-nodes
))
2492 ;; Scan the entire manual and cache the result in Info-toc-nodes
2493 (let ((nodes (Info-toc-build filename
)))
2494 (push (cons filename nodes
) Info-toc-nodes
)
2496 ;; If there is an error, still add nil to the cache
2497 (push (cons filename nil
) Info-toc-nodes
))
2498 (cdr (assoc filename Info-toc-nodes
)))))
2501 (defun Info-follow-reference (footnotename &optional fork
)
2502 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2503 FOOTNOTENAME may be an abbreviation of the reference name.
2504 If FORK is non-nil (interactively with a prefix arg), show the node in
2505 a new Info buffer. If FORK is a string, it is the name to use for the
2508 (let ((completion-ignore-case t
)
2509 (case-fold-search t
)
2510 completions default alt-default
(start-point (point)) str i bol eol
)
2512 ;; Store end and beginning of line.
2513 (setq eol
(line-end-position)
2514 bol
(line-beginning-position))
2515 (goto-char (point-min))
2516 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
2517 (setq str
(match-string-no-properties 1))
2518 ;; See if this one should be the default.
2520 (<= (match-beginning 0) start-point
)
2521 (<= start-point
(point))
2523 ;; See if this one should be the alternate default.
2524 (and (null alt-default
)
2525 (and (<= bol
(match-beginning 0))
2527 (setq alt-default t
))
2529 (while (setq i
(string-match "[ \n\t]+" str i
))
2530 (setq str
(concat (substring str
0 i
) " "
2531 (substring str
(match-end 0))))
2533 ;; Record as a completion and perhaps as default.
2534 (if (eq default t
) (setq default str
))
2535 (if (eq alt-default t
) (setq alt-default str
))
2536 ;; Don't add this string if it's a duplicate.
2537 (or (assoc-string str completions t
)
2538 (push str completions
))))
2539 ;; If no good default was found, try an alternate.
2541 (setq default alt-default
))
2542 ;; If only one cross-reference found, then make it default.
2543 (if (eq (length completions
) 1)
2544 (setq default
(car completions
)))
2546 (let ((input (completing-read (if default
2548 "Follow reference named (default "
2550 "Follow reference named: ")
2551 completions nil t
)))
2552 (list (if (equal input
"")
2553 default input
) current-prefix-arg
))
2554 (user-error "No cross-references in this node"))))
2556 (unless footnotename
2557 (error "No reference was specified"))
2559 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
2560 (case-fold-search t
))
2561 (while (setq i
(string-match " " str i
))
2562 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
2565 ;; Move point to the beginning of reference if point is on reference
2566 (or (looking-at "\\*note[ \n\t]+")
2567 (and (looking-back "\\*note[ \n\t]+")
2568 (goto-char (match-beginning 0)))
2569 (if (and (save-excursion
2570 (goto-char (+ (point) 5)) ; skip a possible *note
2571 (re-search-backward "\\*note[ \n\t]+" nil t
)
2573 (<= (point) (match-end 0)))
2574 (goto-char (match-beginning 0))))
2575 ;; Go to the reference closest to point
2576 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2577 (+ (match-beginning 0) 5))))
2578 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2579 (+ (match-beginning 0) 5)))))
2580 (goto-char (cond ((and next-ref prev-ref
)
2581 (if (< (abs (- next-ref
(point)))
2582 (abs (- prev-ref
(point))))
2584 ((or next-ref prev-ref
))
2585 ((user-error "No cross-reference named %s"
2587 (setq target
(Info-extract-menu-node-name t
))))
2588 (while (setq i
(string-match "[ \t\n]+" target i
))
2589 (setq target
(concat (substring target
0 i
) " "
2590 (substring target
(match-end 0))))
2592 (Info-goto-node target fork
)))
2594 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2595 ;; We allow newline because this is also used in Info-follow-reference,
2596 ;; where the xref name might be wrapped over two lines.
2597 "Regexp that matches a menu entry name upto but not including the colon.
2598 Because of ambiguities, this should be concatenated with something like
2599 `:' and `Info-following-node-name-re'.")
2601 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2602 (skip-chars-forward " \t\n")
2603 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2604 (Info-following-node-name-re
2606 (index-node "^,\t\n")
2607 (multi-line "^.,\t")
2611 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2614 (setq Info-point-loc
2615 (if (match-beginning 5)
2616 (string-to-number (match-string 5))
2617 (buffer-substring-no-properties
2618 (match-beginning 0) (1- (match-beginning 1)))))
2619 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2620 ;;; (setq Info-point-loc
2621 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2623 (replace-regexp-in-string
2625 (or (and (not (equal (match-string-no-properties 2) ""))
2626 (match-string-no-properties 2))
2627 ;; If the node name is the menu entry name (using `entry::').
2628 (buffer-substring-no-properties
2629 (match-beginning 0) (1- (match-beginning 1)))))))
2631 ;; No one calls this.
2632 ;;(defun Info-menu-item-sequence (list)
2634 ;; (Info-menu (car list))
2635 ;; (setq list (cdr list))))
2637 (defvar Info-complete-menu-buffer
)
2638 (defvar Info-complete-next-re nil
)
2639 (defvar Info-complete-nodes nil
)
2640 (defvar Info-complete-cache nil
)
2642 (defconst Info-node-spec-re
2643 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2644 "Regexp to match the text after a : until the terminating `.'.")
2646 (defun Info-complete-menu-item (string predicate action
)
2647 ;; This uses two dynamically bound variables:
2648 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2649 ;; is the menu of items we're trying to complete.
2650 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2651 ;; also look for menu items in subsequent nodes as long as those
2652 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2654 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2655 ;; also look for menu items in these nodes. This feature is currently
2656 ;; only used for completion in Info-index.
2658 ;; Note that `Info-complete-menu-buffer' could be current already,
2659 ;; so we want to save point.
2660 (with-current-buffer Info-complete-menu-buffer
2662 (let ((completion-ignore-case t
)
2663 (case-fold-search t
)
2664 (orignode Info-current-node
)
2666 (goto-char (point-min))
2667 (search-forward "\n* Menu:")
2669 ((eq (car-safe action
) 'boundaries
) nil
)
2670 ((eq action
'lambda
)
2672 (concat "\n\\* +" (regexp-quote string
) ":") nil t
))
2674 (let ((pattern (concat "\n\\* +\\("
2675 (regexp-quote string
)
2676 Info-menu-entry-name-re
"\\):"
2679 (complete-nodes Info-complete-nodes
))
2681 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2682 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2683 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2684 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2685 (let ((prev (nth 3 Info-complete-cache
)))
2686 (eq t
(compare-strings string
0 (length prev
)
2688 ;; We can reuse the previous list.
2689 (setq completions
(nth 4 Info-complete-cache
))
2690 ;; The cache can't be used.
2693 (while (re-search-forward pattern nil t
)
2694 (push (match-string-no-properties 1)
2696 (setq completions
(delete-dups completions
))
2697 ;; Check subsequent nodes if applicable.
2698 (or (and Info-complete-next-re
2699 (setq nextnode
(Info-extract-pointer "next" t
))
2700 (string-match Info-complete-next-re nextnode
))
2702 (setq complete-nodes
(cdr complete-nodes
)
2703 nextnode
(car complete-nodes
)))))
2704 (Info-goto-node nextnode
))
2705 ;; Go back to the start node (for the next completion).
2706 (unless (equal Info-current-node orignode
)
2707 (Info-goto-node orignode
))
2708 ;; Update the cache.
2709 (set (make-local-variable 'Info-complete-cache
)
2710 (list Info-current-file Info-current-node
2711 Info-complete-next-re string completions
2712 Info-complete-nodes
)))
2713 (complete-with-action action completions string predicate
))))))))
2716 (defun Info-menu (menu-item &optional fork
)
2717 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2718 The menu item should one of those listed in the current node's menu.
2719 Completion is allowed, and the default menu item is the one point is on.
2720 If FORK is non-nil (interactively with a prefix arg), show the node in
2721 a new Info buffer. If FORK is a string, it is the name to use for the
2724 (let (;; If point is within a menu item, use that item as the default
2728 (case-fold-search t
))
2730 (goto-char (point-min))
2731 (if (not (search-forward "\n* menu:" nil t
))
2732 (user-error "No menu in this node"))
2738 (if (re-search-backward (concat "\n\\* +\\("
2739 Info-menu-entry-name-re
2741 (setq default
(match-string-no-properties 1))))))
2744 (setq item
(let ((completion-ignore-case t
)
2745 (Info-complete-menu-buffer (current-buffer)))
2746 (completing-read (if default
2747 (format "Menu item (default %s): "
2750 'Info-complete-menu-item nil t
)))
2751 ;; we rely on the fact that completing-read accepts an input
2752 ;; of "" even when the require-match argument is true and ""
2753 ;; is not a valid possibility
2754 (if (string= item
"")
2759 (list item current-prefix-arg
))))
2760 ;; there is a problem here in that if several menu items have the same
2761 ;; name you can only go to the node of the first with this command.
2762 (Info-goto-node (Info-extract-menu-item menu-item
)
2764 (if (stringp fork
) fork menu-item
))))
2766 (defun Info-extract-menu-item (menu-item)
2767 (setq menu-item
(regexp-quote menu-item
))
2768 (let ((case-fold-search t
))
2770 (let ((case-fold-search t
))
2771 (goto-char (point-min))
2772 (or (search-forward "\n* menu:" nil t
)
2773 (user-error "No menu in this node"))
2774 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2775 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2776 (user-error "No such item in menu"))
2779 (Info-extract-menu-node-name nil
(Info-index-node))))))
2781 ;; If COUNT is nil, use the last item in the menu.
2782 (defun Info-extract-menu-counting (count &optional no-detail
)
2783 (let ((case-fold-search t
))
2785 (let ((case-fold-search t
)
2786 (bound (when (and no-detail
2788 "^[ \t-]*The Detailed Node Listing" nil t
))
2789 (match-beginning 0))))
2790 (goto-char (point-min))
2791 (or (search-forward "\n* menu:" bound t
)
2792 (user-error "No menu in this node"))
2794 (or (search-forward "\n* " bound t count
)
2795 (error "Too few items in menu"))
2796 (while (search-forward "\n* " bound t
)
2798 (Info-extract-menu-node-name nil
(Info-index-node))))))
2800 (defun Info-nth-menu-item ()
2801 "Go to the node of the Nth menu item.
2802 N is the digit argument used to invoke this command."
2805 (Info-extract-menu-counting
2806 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2808 (defun Info-top-node ()
2809 "Go to the Top node of this file."
2811 (Info-goto-node "Top"))
2813 (defun Info-final-node ()
2814 "Go to the final node in this file."
2816 (Info-goto-node "Top")
2817 (let ((Info-history nil
)
2818 (case-fold-search t
))
2819 ;; Go to the last node in the menu of Top. But don't delve into
2820 ;; detailed node listings.
2821 (Info-goto-node (Info-extract-menu-counting nil t
))
2822 ;; If the last node in the menu is not last in pointer structure,
2823 ;; move forward (but not down- or upward - see bug#1116) until we
2824 ;; can't go any farther.
2825 (while (Info-forward-node t t t
) nil
)
2826 ;; Then keep moving down to last subnode, unless we reach an index.
2827 (while (and (not (Info-index-node))
2828 (save-excursion (search-forward "\n* Menu:" nil t
)))
2829 (Info-goto-node (Info-extract-menu-counting nil
)))))
2831 (defun Info-forward-node (&optional not-down not-up no-error
)
2832 "Go forward one node, considering all nodes as forming one sequence."
2834 (goto-char (point-min))
2836 (let ((case-fold-search t
))
2837 ;; three possibilities, in order of priority:
2838 ;; 1. next node is in a menu in this node (but not in an index)
2839 ;; 2. next node is next at same level
2840 ;; 3. next node is up and next
2841 (cond ((and (not not-down
)
2842 (save-excursion (search-forward "\n* menu:" nil t
))
2843 (not (Info-index-node)))
2844 (Info-goto-node (Info-extract-menu-counting 1))
2846 ((save-excursion (search-backward "next:" nil t
))
2850 (save-excursion (search-backward "up:" nil t
))
2851 ;; Use string-equal, not equal, to ignore text props.
2852 (not (string-equal (downcase (Info-extract-pointer "up"))
2854 (let ((old-node Info-current-node
))
2856 (let ((old-history Info-history
)
2859 (setq success
(Info-forward-node t nil no-error
))
2860 (or success
(Info-goto-node old-node
)))
2861 (if Info-history-skip-intermediate-nodes
2862 (setq Info-history old-history
)))))
2864 (t (user-error "No pointer forward from this node")))))
2866 (defun Info-backward-node ()
2867 "Go backward one node, considering all nodes as forming one sequence."
2869 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2870 (upnode (Info-extract-pointer "up" t
))
2871 (case-fold-search t
))
2872 (cond ((and upnode
(string-match "(" upnode
))
2873 (user-error "First node in file"))
2874 ((and upnode
(or (null prevnode
)
2875 ;; Use string-equal, not equal,
2876 ;; to ignore text properties.
2877 (string-equal (downcase prevnode
)
2878 (downcase upnode
))))
2881 ;; If we move back at the same level,
2882 ;; go down to find the last subnode*.
2884 (let ((old-history Info-history
))
2885 (while (and (not (Info-index-node))
2886 (save-excursion (search-forward "\n* Menu:" nil t
)))
2887 (Info-goto-node (Info-extract-menu-counting nil
)))
2888 (if Info-history-skip-intermediate-nodes
2889 (setq Info-history old-history
))))
2891 (user-error "No pointer backward from this node")))))
2894 "Exit Info by selecting some other buffer."
2897 (save-buffers-kill-emacs)
2900 (defun Info-next-menu-item ()
2901 "Go to the node of the next menu item."
2903 ;; Bind this in case the user sets it to nil.
2904 (let* ((case-fold-search t
)
2908 (search-forward "\n* menu:" nil t
)
2909 (and (search-forward "\n* " nil t
)
2910 (Info-extract-menu-node-name)))))
2911 (if node
(Info-goto-node node
)
2912 (user-error "No more items in menu"))))
2914 (defun Info-last-menu-item ()
2915 "Go to the node of the previous menu item."
2919 ;; Bind this in case the user sets it to nil.
2920 (let* ((case-fold-search t
)
2921 (beg (save-excursion
2922 (and (search-backward "\n* menu:" nil t
)
2924 (or (and beg
(search-backward "\n* " beg t
))
2925 (user-error "No previous items in menu")))
2926 (Info-goto-node (save-excursion
2927 (goto-char (match-end 0))
2928 (Info-extract-menu-node-name)))))
2930 (defmacro Info-no-error
(&rest body
)
2931 `(condition-case nil
(progn ,@body t
) (error nil
)))
2933 (defun Info-next-preorder ()
2934 "Go to the next subnode or the next node, or go up a level."
2936 (cond ((Info-no-error (Info-next-menu-item)))
2937 ((Info-no-error (Info-next)))
2938 ((Info-no-error (Info-up t
))
2939 ;; Since we have already gone thru all the items in this menu,
2940 ;; go up to the end of this node.
2941 (goto-char (point-max))
2942 ;; Since logically we are done with the node with that menu,
2943 ;; move on from it. But don't add intermediate nodes
2944 ;; to the history on recursive calls.
2945 (let ((old-history Info-history
))
2946 (Info-next-preorder)
2947 (if Info-history-skip-intermediate-nodes
2948 (setq Info-history old-history
))))
2950 (user-error "No more nodes"))))
2952 (defun Info-last-preorder ()
2953 "Go to the last node, popping up a level if there is none."
2955 (cond ((and Info-scroll-prefer-subnodes
2957 (Info-last-menu-item)
2958 ;; If we go down a menu item, go to the end of the node
2959 ;; so we can scroll back through it.
2960 (goto-char (point-max))))
2961 ;; Keep going down, as long as there are nested menu nodes.
2962 (let ((old-history Info-history
))
2963 (while (Info-no-error
2964 (Info-last-menu-item)
2965 ;; If we go down a menu item, go to the end of the node
2966 ;; so we can scroll back through it.
2967 (goto-char (point-max))))
2968 (if Info-history-skip-intermediate-nodes
2969 (setq Info-history old-history
)))
2971 ((and (Info-no-error (Info-extract-pointer "prev"))
2972 (not (equal (Info-extract-pointer "up")
2973 (Info-extract-pointer "prev"))))
2974 (Info-no-error (Info-prev))
2975 (goto-char (point-max))
2976 (let ((old-history Info-history
))
2977 (while (Info-no-error
2978 (Info-last-menu-item)
2979 ;; If we go down a menu item, go to the end of the node
2980 ;; so we can scroll back through it.
2981 (goto-char (point-max))))
2982 (if Info-history-skip-intermediate-nodes
2983 (setq Info-history old-history
)))
2985 ((Info-no-error (Info-up t
))
2986 (goto-char (point-min))
2987 (let ((case-fold-search t
))
2988 (or (search-forward "\n* Menu:" nil t
)
2989 (goto-char (point-max)))))
2990 (t (user-error "No previous nodes"))))
2992 (defun Info-scroll-up ()
2993 "Scroll one screenful forward in Info, considering all nodes as one sequence.
2994 Once you scroll far enough in a node that its menu appears on the screen
2995 but after point, the next scroll moves into its first subnode, unless
2996 `Info-scroll-prefer-subnodes' is nil.
2998 When you scroll past the end of a node, that goes to the next node if
2999 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
3000 if this node has no successor, it moves to the parent node's successor,
3001 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
3002 the menu of a node, it moves to subnode indicated by the following menu
3003 item. (That case won't normally result from this command, but can happen
3007 (if (or (< (window-start) (point-min))
3008 (> (window-start) (point-max)))
3009 (set-window-start (selected-window) (point)))
3010 (let* ((case-fold-search t
)
3011 (virtual-end (save-excursion
3012 (goto-char (point-min))
3013 (if (and Info-scroll-prefer-subnodes
3014 (search-forward "\n* Menu:" nil t
))
3017 (if (or (< virtual-end
(window-start))
3018 (pos-visible-in-window-p virtual-end
))
3020 (Info-scroll-prefer-subnodes (Info-next-preorder))
3021 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
3022 (t (Info-next-preorder)))
3025 (defun Info-mouse-scroll-up (e)
3026 "Scroll one screenful forward in Info, using the mouse.
3027 See `Info-scroll-up'."
3029 (save-selected-window
3031 (select-window (posn-window (event-start e
))))
3034 (defun Info-scroll-down ()
3035 "Scroll one screenful back in Info, considering all nodes as one sequence.
3036 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
3037 is non-nil, this goes to its last subnode. When you scroll past the
3038 beginning of a node, that goes to the previous node or back up to the
3041 (if (or (< (window-start) (point-min))
3042 (> (window-start) (point-max)))
3043 (set-window-start (selected-window) (point)))
3044 (let* ((case-fold-search t
)
3045 (current-point (point))
3047 (and Info-scroll-prefer-subnodes
3049 (setq current-point
(line-beginning-position))
3050 (goto-char (point-min))
3051 (search-forward "\n* Menu:" current-point t
)))))
3053 (pos-visible-in-window-p (point-min) nil t
))
3054 (Info-last-preorder)
3057 (defun Info-mouse-scroll-down (e)
3058 "Scroll one screenful backward in Info, using the mouse.
3059 See `Info-scroll-down'."
3061 (save-selected-window
3063 (select-window (posn-window (event-start e
))))
3064 (Info-scroll-down)))
3066 (defun Info-next-reference-or-link (pat prop
)
3067 "Move point to the next pattern-based cross-reference or property-based link.
3068 The next cross-reference is searched using the regexp PAT, and the next link
3069 is searched using the text property PROP. Move point to the closest found position
3070 of either a cross-reference found by `re-search-forward' or a link found by
3071 `next-single-char-property-change'. Return the new position of point, or nil."
3072 (let ((pxref (save-excursion (re-search-forward pat nil t
)))
3073 (plink (next-single-char-property-change (point) prop
)))
3074 (when (and (< plink
(point-max)) (not (get-char-property plink prop
)))
3075 (setq plink
(next-single-char-property-change plink prop
)))
3076 (if (< plink
(point-max))
3077 (if (and pxref
(<= pxref plink
))
3078 (goto-char (or (match-beginning 1) (match-beginning 0)))
3080 (if pxref
(goto-char (or (match-beginning 1) (match-beginning 0)))))))
3082 (defun Info-prev-reference-or-link (pat prop
)
3083 "Move point to the previous pattern-based cross-reference or property-based link.
3084 The previous cross-reference is searched using the regexp PAT, and the previous link
3085 is searched using the text property PROP. Move point to the closest found position
3086 of either a cross-reference found by `re-search-backward' or a link found by
3087 `previous-single-char-property-change'. Return the new position of point, or nil."
3088 (let ((pxref (save-excursion (re-search-backward pat nil t
)))
3089 (plink (previous-single-char-property-change (point) prop
)))
3090 (when (and (> plink
(point-min)) (not (get-char-property plink prop
)))
3091 (setq plink
(previous-single-char-property-change plink prop
)))
3092 (if (> plink
(point-min))
3093 (if (and pxref
(>= pxref plink
))
3094 (goto-char (or (match-beginning 1) (match-beginning 0)))
3096 (if pxref
(goto-char (or (match-beginning 1) (match-beginning 0)))))))
3098 (defun Info-next-reference (&optional recur count
)
3099 "Move cursor to the next cross-reference or menu item in the node.
3100 If COUNT is non-nil (interactively with a prefix arg), jump over
3101 COUNT cross-references."
3102 (interactive "i\np")
3106 (Info-prev-reference recur
(- count
))
3107 (while (unless (zerop count
) (setq count
(1- count
)))
3108 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3110 (case-fold-search t
))
3111 (or (eobp) (forward-char 1))
3112 (or (Info-next-reference-or-link pat
'link
)
3114 (goto-char (point-min))
3115 (or (Info-next-reference-or-link pat
'link
)
3118 (user-error "No cross references in this node")))))
3119 (if (looking-at "\\* Menu:")
3121 (user-error "No cross references in this node")
3122 (Info-next-reference t
))
3123 (if (looking-at "^\\* ")
3124 (forward-char 2)))))))
3126 (defun Info-prev-reference (&optional recur count
)
3127 "Move cursor to the previous cross-reference or menu item in the node.
3128 If COUNT is non-nil (interactively with a prefix arg), jump over
3129 COUNT cross-references."
3130 (interactive "i\np")
3134 (Info-next-reference recur
(- count
))
3135 (while (unless (zerop count
) (setq count
(1- count
)))
3136 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3138 (case-fold-search t
))
3139 (or (Info-prev-reference-or-link pat
'link
)
3141 (goto-char (point-max))
3142 (or (Info-prev-reference-or-link pat
'link
)
3145 (user-error "No cross references in this node")))))
3146 (if (looking-at "\\* Menu:")
3148 (user-error "No cross references in this node")
3149 (Info-prev-reference t
))
3150 (if (looking-at "^\\* ")
3151 (forward-char 2)))))))
3153 (defun Info-index-nodes (&optional file
)
3154 "Return a list of names of all index nodes in Info FILE.
3155 If FILE is omitted, it defaults to the current Info file.
3156 First look in a list of cached index node names. Then scan Info
3157 file and its subfiles for nodes with the index cookie. Then try
3158 to find index nodes starting from the first node in the top level
3159 menu whose name contains the word \"Index\", plus any immediately
3160 following nodes whose names also contain the word \"Index\"."
3161 (or file
(setq file Info-current-file
))
3162 (or (assoc file Info-index-nodes
)
3163 ;; Skip virtual Info files
3164 (and (or (not (stringp file
))
3165 (Info-virtual-file-p file
))
3166 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
3167 (if (Info-file-supports-index-cookies file
)
3168 ;; Find nodes with index cookie
3169 (let* ((default-directory (or (and (stringp file
)
3170 (file-name-directory
3171 (setq file
(Info-find-file file
))))
3173 Info-history Info-history-list Info-fontify-maximum-menu-size
3174 (main-file file
) subfiles nodes
)
3177 (while (or main-file subfiles
)
3179 (info-insert-file-contents (or main-file
(car subfiles
)))
3180 (goto-char (point-min))
3181 (while (search-forward "\0\b[index\0\b]" nil
'move
)
3183 (re-search-backward "^\^_")
3184 (search-forward "Node: ")
3185 (setq nodes
(cons (Info-following-node-name) nodes
))))
3188 (goto-char (point-min))
3189 (if (search-forward "\n\^_\nIndirect:" nil t
)
3190 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
3191 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
3192 (setq subfiles
(cons (match-string-no-properties 1)
3194 (setq subfiles
(nreverse subfiles
)
3196 (setq subfiles
(cdr subfiles
)))))
3199 (setq nodes
(nreverse nodes
)
3200 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
3202 ;; Else find nodes with the word "Index" in the node name
3203 (let ((case-fold-search t
)
3204 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
3209 (Info-find-node file
"Top")
3210 (when (and (search-forward "\n* menu:" nil t
)
3211 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
3212 (goto-char (match-beginning 1))
3213 (setq nodes
(list (Info-extract-menu-node-name)))
3214 (Info-goto-node (car nodes
))
3215 (while (and (setq node
(Info-extract-pointer "next" t
))
3216 (string-match "\\<Index\\>" node
))
3218 (Info-goto-node node
))))
3221 (setq nodes
(nreverse nodes
)
3222 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
3224 ;; If file has no index nodes, still add it to the cache
3225 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
3226 (cdr (assoc file Info-index-nodes
)))
3228 (defun Info-index-node (&optional node file
)
3229 "Return non-nil value if NODE is an index node.
3230 If NODE is nil, check the current Info node.
3231 If FILE is nil, check the current Info file."
3232 (or file
(setq file Info-current-file
))
3233 (if (and (or (and node
(not (equal node Info-current-node
)))
3234 (assoc file Info-index-nodes
))
3235 (not Info-current-node-virtual
))
3236 (member (or node Info-current-node
) (Info-index-nodes file
))
3237 ;; Don't search all index nodes if request is only for the current node
3238 ;; and file is not in the cache of index nodes
3240 (if (Info-file-supports-index-cookies file
)
3242 (goto-char (+ (or (save-excursion
3243 (search-backward "\n\^_" nil t
))
3245 (search-forward "\0\b[index\0\b]"
3247 (search-forward "\n\^_" nil t
))
3249 (string-match "\\<Index\\>" (or node Info-current-node
""))))))
3251 (defun Info-goto-index ()
3252 "Go to the first index node."
3253 (let ((node (car (Info-index-nodes))))
3254 (or node
(error "No index"))
3255 (Info-goto-node node
)))
3258 (defun Info-index (topic)
3259 "Look up a string TOPIC in the index for this manual and go to that entry.
3260 If there are no exact matches to the specified topic, this chooses
3261 the first match which is a case-insensitive substring of a topic.
3262 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3263 Give an empty topic name to go to the Index node itself."
3266 (let ((completion-ignore-case t
)
3267 (Info-complete-menu-buffer (clone-buffer))
3268 (Info-complete-nodes (Info-index-nodes))
3269 (Info-history-list nil
))
3270 (if (equal Info-current-file
"dir")
3271 (error "The Info directory node has no index; use m to select a manual"))
3273 (with-current-buffer Info-complete-menu-buffer
3275 (completing-read "Index topic: " 'Info-complete-menu-item
))
3276 (kill-buffer Info-complete-menu-buffer
)))))
3277 (if (equal Info-current-file
"dir")
3278 (error "The Info directory node has no index; use m to select a manual"))
3279 ;; Strip leading colon in topic; index format does not allow them.
3280 (if (and (stringp topic
)
3281 (> (length topic
) 0)
3282 (= (aref topic
0) ?
:))
3283 (setq topic
(substring topic
1)))
3284 (let ((orignode Info-current-node
)
3285 (pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3286 (regexp-quote topic
)))
3287 node
(nodes (Info-index-nodes))
3288 (ohist-list Info-history-list
)
3289 (case-fold-search t
))
3291 (or (equal topic
"")
3294 ;; We bind Info-history to nil for internal node-switches so
3295 ;; that we don't put junk in the history. In the first
3296 ;; Info-goto-index call, above, we do update the history
3297 ;; because that is what the user's previous node choice into it.
3302 (goto-char (point-min))
3303 (while (re-search-forward pattern nil t
)
3304 (let ((entry (match-string-no-properties 1))
3305 (nodename (match-string-no-properties 3))
3306 (line (string-to-number (concat "0" (match-string 4)))))
3307 (add-text-properties
3308 (- (match-beginning 2) (match-beginning 1))
3309 (- (match-end 2) (match-beginning 1))
3310 '(face info-index-match
) entry
)
3311 (push (list entry nodename Info-current-node line
) matches
)))
3312 (setq nodes
(cdr nodes
) node
(car nodes
)))
3313 (Info-goto-node node
))
3316 (Info-goto-node orignode
)
3317 (user-error "No `%s' in index" topic
)))
3318 ;; Here it is a feature that assoc is case-sensitive.
3319 (while (setq found
(assoc topic matches
))
3320 (setq exact
(cons found exact
)
3321 matches
(delq found matches
)))
3322 (setq Info-history-list ohist-list
)
3323 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
3324 (Info-index-next 0)))))
3326 (defun Info-index-next (num)
3327 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3329 (or Info-index-alternatives
3330 (user-error "No previous `i' command"))
3332 (setq num
(+ num
(length Info-index-alternatives
))))
3334 (setq Info-index-alternatives
3335 (nconc (cdr Info-index-alternatives
)
3336 (list (car Info-index-alternatives
)))
3338 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
3339 (if (> (nth 3 (car Info-index-alternatives
)) 0)
3340 ;; Forward 2 lines less because `Info-find-node-2' initially
3341 ;; puts point to the 2nd line.
3342 (forward-line (- (nth 3 (car Info-index-alternatives
)) 2))
3343 (forward-line 3) ; don't search in headers
3344 (let ((name (car (car Info-index-alternatives
))))
3345 (Info-find-index-name name
)))
3346 (message "Found `%s' in %s. %s"
3347 (car (car Info-index-alternatives
))
3348 (nth 2 (car Info-index-alternatives
))
3349 (if (cdr Info-index-alternatives
)
3350 (format "(%s total; use `%s' for next)"
3351 (length Info-index-alternatives
)
3352 (key-description (where-is-internal
3353 'Info-index-next overriding-local-map
3357 (defun Info-find-index-name (name)
3358 "Move point to the place within the current node where NAME is defined."
3359 (let ((case-fold-search t
))
3360 (if (or (re-search-forward (format
3361 "[a-zA-Z]+: %s\\( \\|$\\)"
3362 (regexp-quote name
)) nil t
)
3363 ;; Find a function definition with a return type.
3364 (re-search-forward (format
3365 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3366 (regexp-quote name
)) nil t
)
3367 (search-forward (format "`%s'" name
) nil t
)
3368 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
3370 (format "`%s'" (substring name
0 (match-beginning 1)))
3372 (search-forward name nil t
)
3373 ;; Try again without the " <1>" makeinfo can append
3374 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
3375 (Info-find-index-name (match-string 1 name
))))
3376 (progn (beginning-of-line) t
) ;; non-nil for recursive call
3377 (goto-char (point-min)))))
3379 (add-to-list 'Info-virtual-nodes
3380 '("\\`\\*Index.*\\*\\'"
3381 (find-node . Info-virtual-index-find-node
)
3385 (defvar Info-virtual-index-nodes nil
3386 "Alist of cached matched index search nodes.
3387 Each element is ((FILENAME . TOPIC) MATCHES) where
3388 FILENAME is the file name of the manual,
3389 TOPIC is the search string given as an argument to `Info-virtual-index',
3390 MATCHES is a list of index matches found by `Info-index'.")
3392 (defun Info-virtual-index-find-node (filename nodename
&optional _no-going-back
)
3393 "Index-specific implementation of `Info-find-node-2'."
3394 ;; Generate Index-like menu of matches
3395 (if (string-match "^\\*Index for `\\(.+\\)'\\*$" nodename
)
3396 ;; Generate Index-like menu of matches
3397 (let* ((topic (match-string 1 nodename
))
3398 (matches (cdr (assoc (cons (or filename Info-current-file
) topic
)
3399 Info-virtual-index-nodes
))))
3400 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3401 (or filename Info-current-file
) nodename
))
3402 (insert "Info Virtual Index\n")
3403 (insert "******************\n\n")
3404 (insert "Index entries that match `" topic
"':\n\n")
3405 (insert "\0\b[index\0\b]\n")
3407 (insert "No matches found.\n")
3408 (insert "* Menu:\n\n")
3409 (dolist (entry matches
)
3410 (insert (format "* %-38s %s.%s\n"
3411 (format "%s [%s]:" (nth 0 entry
) (nth 2 entry
))
3414 (format " (line %s)" (nth 3 entry
))
3416 ;; Else, Generate a list of previous search results
3417 (let ((nodes (reverse Info-virtual-index-nodes
)))
3418 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3419 (or filename Info-current-file
) nodename
))
3420 (insert "Info Virtual Index\n")
3421 (insert "******************\n\n")
3422 (insert "This is a list of search results produced by\n"
3423 "`Info-virtual-index' for the current manual.\n\n")
3424 (insert "* Menu:\n\n")
3425 (dolist (nodeinfo nodes
)
3426 (when (equal (car (nth 0 nodeinfo
)) (or filename Info-current-file
))
3428 (format "* %-20s %s.\n"
3429 (format "*Index for `%s'*::" (cdr (nth 0 nodeinfo
)))
3430 (cdr (nth 0 nodeinfo
)))))))))
3432 (defun Info-virtual-index (topic)
3433 "Show a node with all lines in the index containing a string TOPIC.
3434 Like `Info-index' but displays a node with index search results.
3435 Give an empty topic name to go to the node with links to previous
3437 ;; `interactive' is a copy from `Info-index'
3440 (let ((completion-ignore-case t
)
3441 (Info-complete-menu-buffer (clone-buffer))
3442 (Info-complete-nodes (Info-index-nodes))
3443 (Info-history-list nil
))
3444 (if (equal Info-current-file
"dir")
3445 (error "The Info directory node has no index; use m to select a manual"))
3447 (with-current-buffer Info-complete-menu-buffer
3449 (completing-read "Index topic: " 'Info-complete-menu-item
))
3450 (kill-buffer Info-complete-menu-buffer
)))))
3451 (if (equal topic
"")
3452 (Info-find-node Info-current-file
"*Index*")
3453 (unless (assoc (cons Info-current-file topic
) Info-virtual-index-nodes
)
3454 (let ((orignode Info-current-node
)
3455 (ohist-list Info-history-list
))
3456 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3458 (push (cons (cons Info-current-file topic
) Info-index-alternatives
)
3459 Info-virtual-index-nodes
)
3460 ;; Clean up unnecessary side-effects of `Info-index'.
3461 (setq Info-history-list ohist-list
)
3462 (Info-goto-node orignode
)
3464 (Info-find-node Info-current-file
(format "*Index for `%s'*" topic
))))
3466 (add-to-list 'Info-virtual-files
3467 '("\\`\\*Apropos\\*\\'"
3468 (toc-nodes . Info-apropos-toc-nodes
)
3469 (find-file . Info-apropos-find-file
)
3470 (find-node . Info-apropos-find-node
)
3474 (defvar Info-apropos-file
"*Apropos*"
3475 "Info file name of the virtual manual for matches of `info-apropos'.")
3477 (defvar Info-apropos-nodes nil
3478 "Alist of cached apropos matched nodes.
3479 Each element is (NODENAME STRING MATCHES) where
3480 NODENAME is the name of the node that holds the search result,
3481 STRING is the search string given as an argument to `info-apropos',
3482 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3484 (defun Info-apropos-toc-nodes (filename)
3485 "Apropos-specific implementation of `Info-toc-nodes'."
3486 (let ((nodes (mapcar 'car
(reverse Info-apropos-nodes
))))
3488 ("Top" nil nil
,nodes
)
3489 ,@(mapcar (lambda (node) `(,node
"Top" nil nil
)) nodes
))))
3491 (defun Info-apropos-find-file (filename &optional _noerror
)
3492 "Apropos-specific implementation of `Info-find-file'."
3495 (defun Info-apropos-find-node (_filename nodename
&optional _no-going-back
)
3496 "Apropos-specific implementation of `Info-find-node-2'."
3497 (if (equal nodename
"Top")
3498 ;; Generate Top menu
3499 (let ((nodes (reverse Info-apropos-nodes
)))
3500 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3501 Info-apropos-file nodename
))
3502 (insert "Apropos Index\n")
3503 (insert "*************\n\n")
3504 (insert "This is a list of search results produced by `info-apropos'.\n\n")
3505 (insert "* Menu:\n\n")
3506 (dolist (nodeinfo nodes
)
3507 (insert (format "* %-20s %s.\n"
3508 (format "%s::" (nth 0 nodeinfo
))
3509 (nth 1 nodeinfo
)))))
3510 ;; Else, Generate Index-like menu of matches
3511 (let* ((nodeinfo (assoc nodename Info-apropos-nodes
))
3512 (matches (nth 2 nodeinfo
)))
3514 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3515 Info-apropos-file nodename
))
3516 (insert "Apropos Index\n")
3517 (insert "*************\n\n")
3518 (insert "Index entries that match `" (nth 1 nodeinfo
) "':\n\n")
3519 (insert "\0\b[index\0\b]\n")
3521 (insert "No matches found.\n")
3522 (insert "* Menu:\n\n")
3523 (dolist (entry matches
)
3524 (insert (format "* %-38s (%s)%s.%s\n"
3525 (format "%s [%s]:" (nth 1 entry
) (nth 0 entry
))
3529 (format " (line %s)" (nth 3 entry
))
3532 (defun Info-apropos-matches (string)
3533 "Collect STRING matches from all known Info files on your system.
3534 Return a list of matches where each element is in the format
3535 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3536 (unless (string= string
"")
3537 (let ((pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3538 (regexp-quote string
)))
3539 (ohist Info-history
)
3540 (ohist-list Info-history-list
)
3541 (current-node Info-current-node
)
3542 (current-file Info-current-file
)
3543 manuals matches node nodes
)
3544 (let ((Info-fontify-maximum-menu-size nil
))
3546 ;; current-node and current-file are nil when they invoke info-apropos
3547 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3548 ;; case, we use (DIR)Top instead, to avoid signaling an error after
3549 ;; the search is complete.
3550 (when (null current-node
)
3551 (setq current-file Info-current-file
)
3552 (setq current-node Info-current-node
))
3553 (message "Searching indices...")
3554 (goto-char (point-min))
3555 (re-search-forward "\\* Menu: *\n" nil t
)
3556 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
3557 ;; add-to-list makes sure we don't have duplicates in `manuals',
3558 ;; so that the following dolist loop runs faster.
3559 (add-to-list 'manuals
(match-string 1)))
3560 (dolist (manual (nreverse manuals
))
3561 (message "Searching %s" manual
)
3563 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
3565 (Info-find-node manual
(car nodes
))
3568 (goto-char (point-min))
3569 (while (re-search-forward pattern nil t
)
3570 (let ((entry (match-string-no-properties 1))
3571 (nodename (match-string-no-properties 3))
3572 (line (match-string-no-properties 4)))
3573 (add-text-properties
3574 (- (match-beginning 2) (match-beginning 1))
3575 (- (match-end 2) (match-beginning 1))
3576 '(face info-index-match
) entry
)
3577 (setq matches
(cons (list manual entry nodename line
)
3579 (setq nodes
(cdr nodes
) node
(car nodes
)))
3580 (Info-goto-node node
))))
3582 (message "%s" (if (eq (car-safe err
) 'error
)
3585 (Info-find-node current-file current-node
)
3586 (setq Info-history ohist
3587 Info-history-list ohist-list
)
3588 (message "Searching indices...done")
3589 (or (nreverse matches
) t
))))
3592 (defun info-apropos (string)
3593 "Grovel indices of all known Info files on your system for STRING.
3594 Build a menu of the possible matches."
3595 (interactive "sIndex apropos: ")
3596 (if (equal string
"")
3597 (Info-find-node Info-apropos-file
"Top")
3598 (let* ((nodes Info-apropos-nodes
) nodename
)
3599 (while (and nodes
(not (equal string
(nth 1 (car nodes
)))))
3600 (setq nodes
(cdr nodes
)))
3602 (Info-find-node Info-apropos-file
(car (car nodes
)))
3603 (setq nodename
(format "Index for `%s'" string
))
3604 (push (list nodename string
(Info-apropos-matches string
))
3606 (Info-find-node Info-apropos-file nodename
)))))
3608 (add-to-list 'Info-virtual-files
3609 '("\\`\\*Finder.*\\*\\'"
3610 (find-file . Info-finder-find-file
)
3611 (find-node . Info-finder-find-node
)
3614 (defvar Info-finder-file
"*Finder*"
3615 "Info file name of the virtual Info keyword finder manual.")
3617 (defun Info-finder-find-file (filename &optional _noerror
)
3618 "Finder-specific implementation of `Info-find-file'."
3621 (defvar finder-known-keywords
)
3622 (declare-function find-library-name
"find-func" (library))
3623 (declare-function finder-unknown-keywords
"finder" ())
3624 (declare-function lm-commentary
"lisp-mnt" (&optional file
))
3625 (defvar finder-keywords-hash
)
3626 (defvar package--builtins
) ; finder requires package
3628 (defun Info-finder-find-node (_filename nodename
&optional _no-going-back
)
3629 "Finder-specific implementation of `Info-find-node-2'."
3632 ((equal nodename
"Top")
3633 ;; Display Top menu with descriptions of the keywords
3634 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3635 Info-finder-file nodename
))
3636 (insert "Finder Keywords\n")
3637 (insert "***************\n\n")
3638 (insert "* Menu:\n\n")
3639 (dolist (assoc (append '((all .
"All package info")
3640 (unknown .
"Unknown keywords"))
3641 finder-known-keywords
))
3642 (let ((keyword (car assoc
)))
3643 (insert (format "* %s %s.\n"
3644 (concat (symbol-name keyword
) ": "
3645 "Keyword " (symbol-name keyword
) ".")
3647 ((equal nodename
"Keyword unknown")
3648 ;; Display unknown keywords
3649 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3650 Info-finder-file nodename
))
3651 (insert "Finder Unknown Keywords\n")
3652 (insert "***********************\n\n")
3653 (insert "* Menu:\n\n")
3656 (insert (format "* %-14s %s.\n"
3657 (concat (symbol-name (car assoc
)) ": "
3658 "Keyword " (symbol-name (car assoc
)) ".")
3660 (finder-unknown-keywords)))
3661 ((equal nodename
"Keyword all")
3662 ;; Display all package info.
3663 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3664 Info-finder-file nodename
))
3665 (insert "Finder Package Info\n")
3666 (insert "*******************\n\n")
3667 (insert "* Menu:\n\n")
3669 (dolist (package package--builtins
)
3670 (setq desc
(cdr-safe package
))
3671 (when (vectorp desc
)
3672 (insert (format "* %-16s %s.\n"
3673 (concat (symbol-name (car package
)) "::")
3675 ((string-match "\\`Keyword " nodename
)
3676 (setq nodename
(substring nodename
(match-end 0)))
3677 ;; Display packages that match the keyword
3678 ;; or the list of keywords separated by comma.
3679 (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
3680 Info-finder-file nodename
))
3681 (insert "Finder Packages\n")
3682 (insert "***************\n\n")
3684 "The following packages match the keyword `" nodename
"':\n\n")
3685 (insert "* Menu:\n\n")
3687 (mapcar 'intern
(if (string-match-p "," nodename
)
3688 (split-string nodename
",[ \t\n]*" t
)
3691 (dolist (keyword keywords
)
3692 (push (copy-tree (gethash keyword finder-keywords-hash
)) hits
))
3693 (setq hits
(delete-dups (apply 'append hits
)))
3694 (dolist (package hits
)
3695 (setq desc
(cdr-safe (assq package package--builtins
)))
3696 (when (vectorp desc
)
3697 (insert (format "* %-16s %s.\n"
3698 (concat (symbol-name package
) "::")
3701 ;; Display commentary section
3702 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3703 Info-finder-file nodename
))
3704 (insert "Finder Commentary\n")
3705 (insert "*****************\n\n")
3707 "Commentary section of the package `" nodename
"':\n\n")
3708 (let ((str (lm-commentary (find-library-name nodename
))))
3710 (insert "Can't find any Commentary section\n\n")
3714 (goto-char (point-min))
3715 (delete-blank-lines)
3716 (goto-char (point-max))
3717 (delete-blank-lines)
3718 (goto-char (point-min))
3719 (while (re-search-forward "^;+ ?" nil t
)
3720 (replace-match "" nil nil
))
3721 (buffer-string))))))))
3724 (defun info-finder (&optional keywords
)
3725 "Display descriptions of the keywords in the Finder virtual manual.
3726 In interactive use, a prefix argument directs this command to read
3727 a list of keywords separated by comma. After that, it displays a node
3728 with a list of packages that contain all specified keywords."
3730 (when current-prefix-arg
3733 (completing-read-multiple
3734 "Keywords (separated by comma): "
3735 (mapcar 'symbol-name
(mapcar 'car
(append finder-known-keywords
3736 (finder-unknown-keywords))))
3740 (Info-find-node Info-finder-file
(mapconcat 'identity keywords
", "))
3741 (Info-find-node Info-finder-file
"Top")))
3744 (defun Info-undefined ()
3745 "Make command be undefined in Info."
3750 "Enter the Info tutorial."
3752 (delete-other-windows)
3753 (Info-find-node "info"
3754 (if (< (window-height) 23)
3758 (defun Info-summary ()
3759 "Display a brief summary of all Info commands."
3761 (save-window-excursion
3762 (switch-to-buffer "*Help*")
3763 (setq buffer-read-only nil
)
3765 (insert (documentation 'Info-mode
))
3767 (goto-char (point-min))
3769 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
3770 (message (if flag
"Type Space to see more"
3771 "Type Space to return to Info"))
3772 (if (not (eq ?\s
(setq ch
(read-event))))
3773 (progn (setq unread-command-events
(list ch
)) nil
)
3776 (bury-buffer "*Help*")))
3778 (defun Info-get-token (pos start all
&optional errorstring
)
3779 "Return the token around POS.
3780 POS must be somewhere inside the token.
3781 START is a regular expression which will match the
3782 beginning of the tokens delimited string.
3783 ALL is a regular expression with a single
3784 parenthesized subpattern which is the token to be
3785 returned. E.g. '{\(.*\)}' would return any string
3786 enclosed in braces around POS.
3787 ERRORSTRING optional fourth argument, controls action on no match:
3790 a string: signal an error, using that string."
3791 (let ((case-fold-search t
))
3794 ;; First look for a match for START that goes across POS.
3795 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
3796 (not (looking-at start
)))
3798 ;; If we did not find one, search back for START
3799 ;; (this finds only matches that end at or before POS).
3800 (or (looking-at start
)
3803 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
3805 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
3806 (not (setq found
(and (<= (match-beginning 0) pos
)
3807 (> (match-end 0) pos
))))))
3808 (if (and found
(<= (match-beginning 0) pos
)
3809 (> (match-end 0) pos
))
3810 (match-string-no-properties 1)
3811 (cond ((null errorstring
)
3817 (error "No %s around position %d" errorstring pos
))))))))
3819 (defun Info-mouse-follow-nearest-node (click)
3820 "\\<Info-mode-map>Follow a node reference near point.
3821 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3822 At end of the node's text, moves to the next node, or up if none."
3824 (mouse-set-point click
)
3825 (and (not (Info-follow-nearest-node))
3826 (save-excursion (forward-line 1) (eobp))
3827 (Info-next-preorder)))
3829 (defun Info-follow-nearest-node (&optional fork
)
3830 "Follow a node reference near point.
3831 If point is on a reference, follow that reference. Otherwise,
3832 if point is in a menu item description, follow that menu item.
3834 If FORK is non-nil (interactively with a prefix arg), show the node in
3836 If FORK is a string, it is the name to use for the new buffer."
3838 (or (Info-try-follow-nearest-node fork
)
3839 (when (save-excursion
3840 (search-backward "\n* menu:" nil t
))
3843 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3844 (beginning-of-line 0))
3845 (when (looking-at "\\* +\\([^\t\n]*\\):")
3847 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
3849 (and (eq this-command
'Info-mouse-follow-nearest-node
)
3850 ;; Don't raise an error when mouse-1 is bound to this - it's
3851 ;; often used to simply select the window or frame.
3852 (eq 'mouse-1
(event-basic-type last-input-event
)))
3853 (user-error "Point neither on reference nor in menu item description")))
3855 ;; Common subroutine.
3856 (defun Info-try-follow-nearest-node (&optional fork
)
3857 "Follow a node reference near point. Return non-nil if successful.
3858 If FORK is non-nil, it is passed to `Info-goto-node'."
3861 ((setq node
(Info-get-token (point) "[hf]t?tps?://"
3862 "\\([hf]t?tps?://[^ \t\n\"`({<>})']+\\)"))
3865 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
3866 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3867 (Info-follow-reference node fork
))
3868 ;; menu item: node name
3869 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3870 (Info-goto-node node fork
))
3871 ;; menu item: node name or index entry
3872 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3875 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
3876 (Info-goto-node node fork
))
3877 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3878 (Info-goto-node node fork
))
3879 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3880 (Info-goto-node node fork
))
3881 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3882 (Info-goto-node "Top" fork
))
3883 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3884 (Info-goto-node node fork
))
3886 ((setq node
(Info-get-token (point) "(" "\\(([0-9]+)\\)"))
3887 (let ((old-point (point)) new-point
)
3889 (goto-char (point-min))
3890 (when (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t
)
3891 (setq new-point
(if (< old-point
(point))
3892 ;; Go to footnote reference
3893 (and (search-forward node nil t
)
3894 ;; Put point at beginning of link
3895 (match-beginning 0))
3896 ;; Go to footnote definition
3897 (search-backward node nil t
)))))
3900 (goto-char new-point
)
3905 (defun Info-mouse-follow-link (click)
3906 "Follow a link where you click."
3908 (let* ((position (event-start click
))
3909 (posn-string (and position
(posn-string position
)))
3910 (link-args (if posn-string
3911 (get-text-property (cdr posn-string
)
3914 (get-char-property (posn-point position
)
3916 (cond ((stringp link-args
)
3917 (Info-goto-node link-args
))
3918 ;; These special values of the `link-args' property are used
3919 ;; for navigation; see `Info-fontify-node'.
3920 ((eq link-args
'prev
) (Info-prev))
3921 ((eq link-args
'next
) (Info-next))
3922 ((eq link-args
'up
) (Info-up)))))
3925 (defvar Info-mode-map
3926 (let ((map (make-keymap)))
3927 (suppress-keymap map
)
3928 (define-key map
"." 'beginning-of-buffer
)
3929 (define-key map
" " 'Info-scroll-up
)
3930 (define-key map
[?\S-\
] 'Info-scroll-down
)
3931 (define-key map
"\C-m" 'Info-follow-nearest-node
)
3932 (define-key map
"\t" 'Info-next-reference
)
3933 (define-key map
"\e\t" 'Info-prev-reference
)
3934 (define-key map
[backtab] 'Info-prev-reference)
3935 (define-key map "1" 'Info-nth-menu-item)
3936 (define-key map "2" 'Info-nth-menu-item)
3937 (define-key map "3" 'Info-nth-menu-item)
3938 (define-key map "4" 'Info-nth-menu-item)
3939 (define-key map "5" 'Info-nth-menu-item)
3940 (define-key map "6" 'Info-nth-menu-item)
3941 (define-key map "7" 'Info-nth-menu-item)
3942 (define-key map "8" 'Info-nth-menu-item)
3943 (define-key map "9" 'Info-nth-menu-item)
3944 (define-key map "0" 'undefined)
3945 (define-key map "?" 'Info-summary)
3946 (define-key map "]" 'Info-forward-node)
3947 (define-key map "[" 'Info-backward-node)
3948 (define-key map "<" 'Info-top-node)
3949 (define-key map ">" 'Info-final-node)
3950 (define-key map "b" 'beginning-of-buffer)
3951 (put 'beginning-of-buffer :advertised-binding "b")
3952 (define-key map "d" 'Info-directory)
3953 (define-key map "e" 'end-of-buffer)
3954 (define-key map "f" 'Info-follow-reference)
3955 (define-key map "g" 'Info-goto-node)
3956 (define-key map "h" 'Info-help)
3957 (define-key map "i" 'Info-index)
3958 (define-key map "I" 'Info-virtual-index)
3959 (define-key map "l" 'Info-history-back)
3960 (define-key map "L" 'Info-history)
3961 (define-key map "m" 'Info-menu)
3962 (define-key map "n" 'Info-next)
3963 (define-key map "p" 'Info-prev)
3964 (define-key map "q" 'Info-exit)
3965 (define-key map "r" 'Info-history-forward)
3966 (define-key map "s" 'Info-search)
3967 (define-key map "S" 'Info-search-case-sensitively)
3968 (define-key map "\M-n" 'clone-buffer)
3969 (define-key map "t" 'Info-top-node)
3970 (define-key map "T" 'Info-toc)
3971 (define-key map "u" 'Info-up)
3972 ;; `w' for consistency with `dired-copy-filename-as-kill'.
3973 (define-key map "w" 'Info-copy-current-node-name)
3974 (define-key map "c" 'Info-copy-current-node-name)
3975 ;; `^' for consistency with `dired-up-directory'.
3976 (define-key map "^" 'Info-up)
3977 (define-key map "," 'Info-index-next)
3978 (define-key map "\177" 'Info-scroll-down)
3979 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
3980 (define-key map [follow-link] 'mouse-face)
3981 (define-key map [XF86Back] 'Info-history-back)
3982 (define-key map [XF86Forward] 'Info-history-forward)
3984 "Keymap containing Info commands.")
3987 (defun Info-check-pointer (item)
3988 "Non-nil if ITEM is present in this node."
3990 (Info-extract-pointer item)
3994 Info-mode-menu Info-mode-map
3995 "Menu for Info files."
3997 ["Up" Info-up :active (Info-check-pointer "up")
3998 :help "Go up in the Info tree"]
3999 ["Next" Info-next :active (Info-check-pointer "next")
4000 :help "Go to the next node"]
4001 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
4002 :help "Go to the previous node"]
4003 ["Backward" Info-backward-node
4004 :help "Go backward one node, considering all as a sequence"]
4005 ["Forward" Info-forward-node
4006 :help "Go forward one node, considering all as a sequence"]
4007 ["Beginning" beginning-of-buffer
4008 :help "Go to beginning of this node"]
4009 ["Top" Info-top-node
4010 :help "Go to top node of file"]
4011 ["Final Node" Info-final-node
4012 :help "Go to final node in this file"]
4013 ("Menu Item" ["You should never see this" report-emacs-bug t])
4014 ("Reference" ["You should never see this" report-emacs-bug t])
4015 ["Search..." Info-search
4016 :help "Search for regular expression in this Info file"]
4017 ["Search Next" Info-search-next
4018 :help "Search for another occurrence of regular expression"]
4019 ["Go to Node..." Info-goto-node
4020 :help "Go to a named node"]
4021 ["Back in history" Info-history-back :active Info-history
4022 :help "Go back in history to the last node you were at"]
4023 ["Forward in history" Info-history-forward :active Info-history-forward
4024 :help "Go forward in history"]
4025 ["History" Info-history :active Info-history-list
4026 :help "Go to menu of visited nodes"]
4027 ["Table of Contents" Info-toc
4028 :help "Go to table of contents"]
4030 ["Lookup a String..." Info-index
4031 :help "Look for a string in the index items"]
4032 ["Next Matching Item" Info-index-next :active Info-index-alternatives
4033 :help "Look for another occurrence of previous item"]
4034 ["Lookup a string and display index of results..." Info-virtual-index
4035 :help "Look for a string in the index items and display node with results"]
4036 ["Lookup a string in all indices..." info-apropos
4037 :help "Look for a string in the indices of all manuals"])
4038 ["Copy Node Name" Info-copy-current-node-name
4039 :help "Copy the name of the current node into the kill ring"]
4040 ["Clone Info buffer" clone-buffer
4041 :help "Create a twin copy of the current Info buffer."]
4042 ["Exit" Info-exit :help "Stop reading Info"]))
4045 (defvar info-tool-bar-map
4046 (let ((map (make-sparse-keymap)))
4047 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
4051 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
4055 (define-key-after map [separator-1] menu-bar-separator)
4056 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
4058 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
4060 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
4062 (define-key-after map [separator-2] menu-bar-separator)
4063 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
4065 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
4066 (define-key-after map [separator-3] menu-bar-separator)
4067 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
4069 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
4071 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
4075 (defvar Info-menu-last-node nil)
4076 ;; Last node the menu was created for.
4077 ;; Value is a list, (FILE-NAME NODE-NAME).
4079 (defun Info-menu-update ()
4080 "Update the Info menu for the current node."
4082 (if (or (not (eq major-mode 'Info-mode))
4083 (equal (list Info-current-file Info-current-node)
4084 Info-menu-last-node))
4086 ;; Update menu menu.
4087 (let* ((Info-complete-menu-buffer (current-buffer))
4088 (items (nreverse (condition-case nil
4089 (Info-complete-menu-item "" nil t)
4093 (while (and items (< number 9))
4094 (setq current (car items)
4097 (setq entries (cons `[,current
4098 (Info-menu ,current)
4099 :keys ,(format "%d" number)]
4102 (setq entries (cons ["Other..." Info-menu t] entries)))
4104 (setq entries (list ["No menu" nil nil] nil :active)))
4105 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
4106 ;; Update reference menu. Code stolen from `Info-follow-reference'.
4108 str i entries current
4110 (case-fold-search t))
4112 (goto-char (point-min))
4113 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
4114 (setq str (match-string 1))
4116 (while (setq i (string-match "[ \n\t]+" str i))
4117 (setq str (concat (substring str 0 i) " "
4118 (substring str (match-end 0))))
4122 (while (and items (< number 9))
4123 (setq current (car items)
4126 (setq entries (cons `[,current
4127 (Info-follow-reference ,current)
4131 (setq entries (cons ["Other..." Info-follow-reference t]
4134 (setq entries (list ["No references" nil nil] nil :active)))
4135 (easy-menu-change '("Info") "Reference" (nreverse entries)))
4136 ;; Update last seen node.
4137 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
4138 ;; Try to avoid entering infinite beep mode in case of errors.
4142 (defun Info-copy-current-node-name (&optional arg)
4143 "Put the name of the current Info node into the kill ring.
4144 The name of the Info file is prepended to the node name in parentheses.
4145 With a zero prefix arg, put the name inside a function call to `info'."
4147 (unless Info-current-node
4148 (user-error "No current Info node"))
4149 (let ((node (if (stringp Info-current-file)
4150 (concat "(" (file-name-sans-extension
4151 (file-name-nondirectory Info-current-file))
4153 Info-current-node))))
4154 (if (zerop (prefix-numeric-value arg))
4155 (setq node (concat "(info \"" node "\")")))
4156 (unless (stringp Info-current-file)
4157 (setq node (format "(Info-find-node '%S '%S)"
4158 Info-current-file Info-current-node)))
4160 (message "%s" node)))
4163 ;; Info mode is suitable only for specially formatted data.
4164 (put 'Info-mode 'mode-class 'special)
4165 (put 'Info-mode 'no-clone-indirect t)
4167 (defvar tool-bar-map)
4168 (defvar bookmark-make-record-function)
4170 (defvar Info-mode-syntax-table
4171 (let ((st (copy-syntax-table text-mode-syntax-table)))
4172 ;; Use punctuation syntax for apostrophe because of
4173 ;; extensive use of quotes like `this' in Info manuals.
4174 (modify-syntax-entry ?' "." st)
4176 "Syntax table used in `Info-mode'.")
4178 ;; Autoload cookie needed by desktop.el
4180 (define-derived-mode Info-mode nil "Info"
4181 "Info mode provides commands for browsing through the Info documentation tree.
4182 Documentation in Info is divided into \"nodes\", each of which discusses
4183 one topic and contains references to other nodes which discuss related
4184 topics. Info has commands to follow the references and show you other nodes.
4187 \\[Info-help] Invoke the Info tutorial.
4188 \\[Info-exit] Quit Info: reselect previously selected buffer.
4190 Selecting other nodes:
4191 \\[Info-mouse-follow-nearest-node]
4192 Follow a node reference you click on.
4193 This works with menu items, cross references, and
4194 the \"next\", \"previous\" and \"up\", depending on where you click.
4195 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
4196 \\[Info-next] Move to the \"next\" node of this node.
4197 \\[Info-prev] Move to the \"previous\" node of this node.
4198 \\[Info-up] Move \"up\" from this node.
4199 \\[Info-menu] Pick menu item specified by name (or abbreviation).
4200 Picking a menu item causes another node to be selected.
4201 \\[Info-directory] Go to the Info directory node.
4202 \\[Info-top-node] Go to the Top node of this file.
4203 \\[Info-final-node] Go to the final node in this file.
4204 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
4205 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
4206 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
4207 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
4208 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
4209 \\[Info-history-back] Move back in history to the last node you were at.
4210 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
4211 \\[Info-history] Go to menu of visited nodes.
4212 \\[Info-toc] Go to table of contents of the current Info file.
4214 Moving within a node:
4215 \\[Info-scroll-up] Normally, scroll forward a full screen.
4216 Once you scroll far enough in a node that its menu appears on the
4217 screen but after point, the next scroll moves into its first
4218 subnode. When after all menu items (or if there is no menu),
4219 move up to the parent node.
4220 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
4221 already visible, try to go to the previous menu entry, or up
4223 \\[beginning-of-buffer] Go to beginning of node.
4226 \\[Info-search] Search through this Info file for specified regexp,
4227 and select the node in which the next occurrence is found.
4228 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
4229 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
4230 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
4231 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
4232 \\[Info-virtual-index] Look for a string and display the index node with results.
4233 \\[info-apropos] Look for a string in the indices of all manuals.
4234 \\[Info-goto-node] Move to node specified by name.
4235 You may include a filename as well, as (FILENAME)NODENAME.
4236 1 .. 9 Pick first ... ninth item in node's menu.
4237 Every third `*' is highlighted to help pick the right number.
4238 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
4239 \\[clone-buffer] Select a new cloned Info buffer in another window.
4240 \\[universal-argument] \\[info] Move to new Info file with completion.
4241 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
4242 :syntax-table Info-mode-syntax-table
4243 :abbrev-table text-mode-abbrev-table
4245 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
4246 (setq case-fold-search t)
4247 (setq buffer-read-only t)
4248 (make-local-variable 'Info-current-file)
4249 (make-local-variable 'Info-current-subfile)
4250 (make-local-variable 'Info-current-node)
4251 (set (make-local-variable 'Info-tag-table-marker) (make-marker))
4252 (set (make-local-variable 'Info-tag-table-buffer) nil)
4253 (make-local-variable 'Info-history)
4254 (make-local-variable 'Info-history-forward)
4255 (make-local-variable 'Info-index-alternatives)
4256 (if Info-use-header-line ; do not override global header lines
4257 (setq header-line-format
4258 '(:eval (get-text-property (point-min) 'header-line))))
4259 (set (make-local-variable 'tool-bar-map) info-tool-bar-map)
4260 ;; This is for the sake of the invisible text we use handling titles.
4261 (set (make-local-variable 'line-move-ignore-invisible) t)
4262 (set (make-local-variable 'desktop-save-buffer)
4263 'Info-desktop-buffer-misc-data)
4264 (set (make-local-variable 'widen-automatically) nil)
4265 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
4266 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
4267 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
4268 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
4269 (set (make-local-variable 'isearch-search-fun-function)
4270 'Info-isearch-search)
4271 (set (make-local-variable 'isearch-wrap-function)
4273 (set (make-local-variable 'isearch-push-state-function)
4274 'Info-isearch-push-state)
4275 (set (make-local-variable 'isearch-filter-predicate)
4276 'Info-isearch-filter)
4277 (set (make-local-variable 'revert-buffer-function)
4278 'Info-revert-buffer-function)
4279 (Info-set-mode-line)
4280 (set (make-local-variable 'bookmark-make-record-function)
4281 'Info-bookmark-make-record))
4283 ;; When an Info buffer is killed, make sure the associated tags buffer
4285 (defun Info-kill-buffer ()
4286 (and (eq major-mode 'Info-mode)
4287 Info-tag-table-buffer
4288 (kill-buffer Info-tag-table-buffer)))
4290 ;; Placed on `clone-buffer-hook'.
4291 (defun Info-clone-buffer ()
4292 (when (bufferp Info-tag-table-buffer)
4293 (setq Info-tag-table-buffer
4294 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4295 (let ((m Info-tag-table-marker))
4297 (setq Info-tag-table-marker
4298 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4299 (with-current-buffer Info-tag-table-buffer
4300 (copy-marker (marker-position m)))
4303 (defvar Info-edit-map (let ((map (make-sparse-keymap)))
4304 (set-keymap-parent map text-mode-map)
4305 (define-key map "\C-c\C-c" 'Info-cease-edit)
4307 "Local keymap used within `e' command of Info.")
4309 (make-obsolete-variable 'Info-edit-map
4310 "editing Info nodes by hand is not recommended."
4313 ;; Info-edit mode is suitable only for specially formatted data.
4314 (put 'Info-edit-mode 'mode-class 'special)
4316 (defun Info-edit-mode ()
4317 "Major mode for editing the contents of an Info node.
4318 Like text mode with the addition of `Info-cease-edit'
4319 which returns to Info mode for browsing.
4321 (use-local-map Info-edit-map)
4322 (setq major-mode 'Info-edit-mode)
4323 (setq mode-name "Info Edit")
4324 (kill-local-variable 'mode-line-buffer-identification)
4325 (setq buffer-read-only nil)
4326 (force-mode-line-update)
4327 (buffer-enable-undo (current-buffer))
4328 (run-mode-hooks 'Info-edit-mode-hook))
4330 (make-obsolete 'Info-edit-mode
4331 "editing Info nodes by hand is not recommended." "24.4")
4334 "Edit the contents of this Info node."
4337 (message "%s" (substitute-command-keys
4338 "Editing: Type \\<Info-edit-map>\\[Info-cease-edit] to return to info")))
4340 (put 'Info-edit 'disabled "Editing Info nodes by hand is not recommended.
4341 This feature will be removed in future.")
4343 (make-obsolete 'Info-edit
4344 "editing Info nodes by hand is not recommended." "24.4")
4346 (defun Info-cease-edit ()
4347 "Finish editing Info node; switch back to Info proper."
4349 ;; Do this first, so nothing has changed if user C-g's at query.
4350 (and (buffer-modified-p)
4351 (y-or-n-p "Save the file? ")
4353 (use-local-map Info-mode-map)
4354 (setq major-mode 'Info-mode)
4355 (setq mode-name "Info")
4356 (Info-set-mode-line)
4357 (setq buffer-read-only t)
4358 (force-mode-line-update)
4359 (and (marker-position Info-tag-table-marker)
4361 (message "Tags may have changed. Use Info-tagify if necessary")))
4363 (make-obsolete 'Info-cease-edit
4364 "editing Info nodes by hand is not recommended." "24.4")
4366 (defvar Info-file-list-for-emacs
4367 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4368 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4369 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4370 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4371 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4372 ("copyright" . "autotype") ("executable" . "autotype")
4373 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4374 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4375 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4376 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4377 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4378 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4379 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4380 ("rfc2045" . "emacs-mime")
4381 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4382 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4383 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4384 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4385 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4386 ("mml" . "emacs-mime")
4388 "List of Info files that describe Emacs commands.
4389 An element can be a file name, or a list of the form (PREFIX . FILE)
4390 where PREFIX is a name prefix and FILE is the file to look in.
4391 If the element is just a file name, the file name also serves as the prefix.")
4393 (defun Info-find-emacs-command-nodes (command)
4394 "Return a list of locations documenting COMMAND.
4395 The `info-file' property of COMMAND says which Info manual to search.
4396 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4397 defines heuristics for which Info manual to try.
4398 The locations are of the format used in the variable `Info-history', i.e.
4399 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4400 in the first element of the returned list (which is treated specially in
4401 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4402 (let ((where '()) line-number
4403 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4404 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4405 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4406 (info-file "emacs")) ;default
4407 ;; Determine which Info file this command is documented in.
4408 (if (get command 'info-file)
4409 (setq info-file (get command 'info-file))
4410 ;; If it doesn't say explicitly, test its name against
4411 ;; various prefixes that we know.
4412 (let ((file-list Info-file-list-for-emacs))
4414 (let* ((elt (car file-list))
4415 (name (if (consp elt)
4418 (file (if (consp elt) (cdr elt) elt))
4419 (case-fold-search nil)
4420 (regexp (concat "\\`" (regexp-quote name)
4422 (if (string-match regexp (symbol-name command))
4423 (setq info-file file file-list nil))
4424 (setq file-list (cdr file-list))))))
4425 (Info-find-node info-file "Top")
4426 ;; Bind Info-history to nil, to prevent the index nodes from
4427 ;; getting into the node history.
4428 (let ((Info-history nil)
4429 (Info-history-list nil)
4430 node (nodes (Info-index-nodes)))
4431 (Info-goto-node (car nodes))
4434 (goto-char (point-min))
4435 (while (re-search-forward cmd-desc nil t)
4437 (cons (list Info-current-file
4438 (match-string-no-properties 2)
4441 (setq line-number (and (match-beginning 3)
4442 (string-to-number (match-string 3)))))
4443 (and (setq nodes (cdr nodes) node (car nodes))))
4444 (Info-goto-node node)))
4445 (if (and line-number where)
4446 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4450 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4452 (defun Info-goto-emacs-command-node (command)
4453 "Go to the Info node in the Emacs manual for command COMMAND.
4454 The command is found by looking up in Emacs manual's indices
4455 or in another manual found via COMMAND's `info-file' property or
4456 the variable `Info-file-list-for-emacs'.
4457 COMMAND must be a symbol or string."
4458 (interactive "CFind documentation for command: ")
4459 ;; If command is given as a string, convert it to a symbol.
4460 (if (stringp command)
4461 (setq command (intern command)))
4462 (or (commandp command)
4463 (signal 'wrong-type-argument (list 'commandp command)))
4464 (let ((where (Info-find-emacs-command-nodes command)))
4466 (let ((num-matches (length where)))
4467 ;; Get Info running, and pop to it in another window.
4468 (save-window-excursion
4470 (or (eq major-mode 'Info-mode) (pop-to-buffer "*info*"))
4471 ;; Bind Info-history to nil, to prevent the last Index node
4472 ;; visited by Info-find-emacs-command-nodes from being
4473 ;; pushed onto the history.
4474 (let ((Info-history nil) (Info-history-list nil)
4475 (line-number (nth 2 (car where))))
4476 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4477 (if (and (integerp line-number) (> line-number 0))
4478 (forward-line (1- line-number))))
4479 (if (> num-matches 1)
4481 ;; (car where) will be pushed onto Info-history
4482 ;; when/if they go to another node. Put the other
4483 ;; nodes that were found on the history.
4484 (setq Info-history (nconc (cdr where) Info-history))
4485 (message "Found %d other entr%s. Use %s to see %s."
4487 (if (> num-matches 2) "ies" "y")
4488 (substitute-command-keys "\\[Info-history-back]")
4489 (if (> num-matches 2) "them" "it")))))
4490 (error "Couldn't find documentation for %s" command))))
4492 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4494 (defun Info-goto-emacs-key-command-node (key)
4495 "Go to the node in the Emacs manual which describes the command bound to KEY.
4497 Interactively, if the binding is `execute-extended-command', a command is read.
4498 The command is found by looking up in Emacs manual's indices
4499 or in another manual found via COMMAND's `info-file' property or
4500 the variable `Info-file-list-for-emacs'."
4501 (interactive "kFind documentation for key: ")
4502 (let ((command (key-binding key)))
4503 (cond ((null command)
4504 (message "%s is undefined" (key-description key)))
4505 ((and (called-interactively-p 'interactive)
4506 (eq command 'execute-extended-command))
4507 (Info-goto-emacs-command-node
4508 (read-command "Find documentation for command: ")))
4510 (Info-goto-emacs-command-node command)))))
4512 (defvar Info-link-keymap
4513 (let ((keymap (make-sparse-keymap)))
4514 (define-key keymap [header-line down-mouse-1] 'mouse-drag-header-line)
4515 (define-key keymap [header-line mouse-1] 'mouse-select-window)
4516 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4517 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4518 (define-key keymap [follow-link] 'mouse-face)
4520 "Keymap to put on Info links.
4521 This is used for the \"Next\", \"Prev\", and \"Up\" links in the
4522 first line or header line, and for breadcrumb links.")
4524 (defun Info-breadcrumbs ()
4525 (let ((nodes (Info-toc-nodes Info-current-file))
4526 (node Info-current-node)
4528 (depth Info-breadcrumbs-depth)
4531 ;; Get ancestors from the cached parent-children node info
4532 (while (and (not (equal "Top" node)) (> depth 0))
4533 (setq node (nth 1 (assoc node nodes)))
4534 (if node (push node crumbs))
4535 (setq depth (1- depth)))
4538 (when Info-use-header-line
4539 ;; Let it disappear if crumbs is nil.
4540 (nconc crumbs (list Info-current-node)))
4541 (when (or Info-use-header-line crumbs)
4542 ;; Add top node (and continuation if needed).
4544 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4545 crumbs (cons nil crumbs))))
4546 ;; Eliminate duplicate.
4548 (dolist (node crumbs)
4550 (if (not (equal node "Top")) node
4552 (if (stringp Info-current-file)
4553 (file-name-sans-extension
4554 (file-name-nondirectory Info-current-file))
4555 ;; Some legacy code can still use a symbol.
4556 Info-current-file)))))
4559 (if (null line) "" " > ")
4562 ((equal node Info-current-node)
4563 ;; No point linking to ourselves.
4564 (propertize text 'font-lock-face 'info-header-node))
4567 'mouse-face 'highlight
4568 'font-lock-face 'info-header-xref
4569 'help-echo "mouse-2: Go to node"
4570 'keymap Info-link-keymap
4571 'link-args text)))))))
4572 (setq line (concat line "\n")))
4573 ;; (font-lock-append-text-property 0 (length line)
4574 ;; 'font-lock-face 'header-line line)
4577 (defun Info-fontify-node ()
4580 (let* ((inhibit-read-only t)
4581 (case-fold-search t)
4583 (not-fontified-p ; the node hasn't already been fontified
4584 (not (let ((where (next-single-property-change (point-min)
4586 (and where (not (= where (point-max)))))))
4587 (fontify-visited-p ; visited nodes need to be re-fontified
4588 (and Info-fontify-visited-nodes
4589 ;; Don't take time to refontify visited nodes in huge nodes
4590 Info-fontify-maximum-menu-size
4591 (< (- (point-max) (point-min)) Info-fontify-maximum-menu-size)))
4594 ;; Fontify header line
4595 (goto-char (point-min))
4596 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4597 (goto-char (match-end 0))
4598 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4599 (goto-char (match-end 0))
4600 (let* ((nbeg (match-beginning 2))
4601 (nend (match-end 2))
4602 (tbeg (match-beginning 1))
4603 (tag (match-string 1)))
4604 (if (string-equal (downcase tag) "node")
4605 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4606 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4607 (put-text-property tbeg nend 'mouse-face 'highlight)
4608 (put-text-property tbeg nend
4610 (concat "mouse-2: Go to node "
4611 (buffer-substring nbeg nend)))
4612 ;; Set up the text property keymap. Depending on
4613 ;; `Info-use-header-line', it is either used in the
4614 ;; buffer, or copied to the header line. A symbol value
4615 ;; of the `link-args' property is handled specially by
4616 ;; `Info-mouse-follow-link'.
4617 (put-text-property tbeg nend 'keymap Info-link-keymap)
4618 (put-text-property tbeg nend 'link-args
4619 (intern (downcase tag))))))
4621 ;; (when (> Info-breadcrumbs-depth 0)
4622 ;; (insert (Info-breadcrumbs)))
4624 ;; Treat header line.
4625 (when Info-use-header-line
4626 (goto-char (point-min))
4627 (let* ((header-end (line-end-position))
4629 ;; If we find neither Next: nor Prev: link, show the entire
4630 ;; node header. Otherwise, don't show the File: and Node:
4631 ;; parts, to avoid wasting precious space on information that
4632 ;; is available in the mode line.
4633 (if (re-search-forward
4634 "\\(next\\|up\\|prev[ious]*\\): "
4637 (goto-char (match-beginning 1))
4638 (buffer-substring (point) header-end))
4639 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4641 (concat "No next, prev or up links -- "
4642 (buffer-substring (point) header-end))
4643 (buffer-substring (point) header-end)))))
4644 (put-text-property (point-min) (1+ (point-min))
4646 (replace-regexp-in-string
4648 ;; Preserve text properties on duplicated `%'.
4649 (lambda (s) (concat s s)) header))
4650 ;; Hide the part of the first line
4651 ;; that is in the header, if it is just part.
4653 ((> Info-breadcrumbs-depth 0)
4654 (let ((ov (make-overlay (point-min) (1+ header-end))))
4655 (overlay-put ov 'display (Info-breadcrumbs))
4656 (overlay-put ov 'evaporate t)))
4658 ;; Hide the punctuation at the end, too.
4659 (skip-chars-backward " \t,")
4660 (put-text-property (point) header-end 'invisible t)
4661 ;; Hide the suffix of the Info file name.
4663 (if (re-search-forward
4664 (format "File: %s\\([^,\n\t]+\\),"
4665 (if (stringp Info-current-file)
4666 (file-name-sans-extension
4667 (file-name-nondirectory Info-current-file))
4670 (put-text-property (match-beginning 1) (match-end 1)
4674 (goto-char (point-min))
4675 (when (and font-lock-mode not-fontified-p)
4676 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4678 ;; Only consider it as an underlined title if the ASCII
4679 ;; underline has the same size as the text. A typical
4680 ;; counter example is when a continuation "..." is alone
4682 (= (string-width (match-string 1))
4683 (string-width (match-string 2))))
4684 (let* ((c (preceding-char))
4686 (cond ((= c ?*) 'info-title-1)
4687 ((= c ?=) 'info-title-2)
4688 ((= c ?-) 'info-title-3)
4689 (t 'info-title-4))))
4690 (put-text-property (match-beginning 1) (match-end 1)
4691 'font-lock-face face))
4692 ;; This is a serious problem for trying to handle multiple
4693 ;; frame types at once. We want this text to be invisible
4694 ;; on frames that can display the font above.
4695 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4696 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4697 '(invisible t front-sticky nil rear-nonsticky t)))))
4699 ;; Fontify cross references
4700 (goto-char (point-min))
4701 (when (or not-fontified-p fontify-visited-p)
4702 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4703 (let ((start (match-beginning 0))
4706 (when not-fontified-p
4707 (when Info-hide-note-references
4708 (when (and (not (eq Info-hide-note-references 'hide))
4709 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4710 ;; *Note is often used where *note should have been
4712 (skip-syntax-backward " ")
4713 (when (memq (char-before) '(?\( ?\[ ?\{))
4714 ;; Check whether the paren is preceded by
4715 ;; an end of sentence
4716 (skip-syntax-backward " ("))
4718 (cond ((save-match-data (looking-back "\\<see"))
4720 ((save-match-data (looking-back "\\<in"))
4722 ((memq (char-before) '(nil ?\. ?! ??))
4726 (search-forward "\n\n" start t)))
4730 (add-text-properties
4732 (or (save-match-data
4733 ;; Don't hide \n after *Note
4734 (let ((start1 (match-beginning 1)))
4735 (if (string-match "\n" (match-string 1))
4736 (+ start1 (match-beginning 0)))))
4739 `(display ,other-tag front-sticky nil rear-nonsticky t)
4740 '(invisible t front-sticky nil rear-nonsticky t))))
4741 (add-text-properties
4742 (match-beginning 2) (match-end 2)
4744 'help-echo (if (or (match-end 5)
4745 (not (equal (match-string 4) "")))
4746 (concat "mouse-2: go to " (or (match-string 5)
4748 "mouse-2: go to this node")
4749 'mouse-face 'highlight)))
4750 (when (or not-fontified-p fontify-visited-p)
4751 (setq rbeg (match-beginning 2)
4756 ;; Display visited nodes in a different face
4757 (if (and Info-fontify-visited-nodes
4759 (let* ((node (replace-regexp-in-string
4761 (replace-regexp-in-string
4763 (or (match-string-no-properties 5)
4764 (and (not (equal (match-string 4) ""))
4765 (match-string-no-properties 4))
4766 (match-string-no-properties 2)))))
4768 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4769 (file (if external-link-p
4770 (file-name-nondirectory
4771 (match-string-no-properties 1 node))
4773 (hl Info-history-list)
4776 (setq node (if (equal (match-string 2 node) "")
4778 (match-string-no-properties 2 node))))
4780 (if (and (string-equal node (nth 1 (car hl)))
4782 (if (and external-link-p
4783 (stringp (caar hl)))
4784 (file-name-nondirectory
4787 (setq res (car hl) hl nil)
4788 (setq hl (cdr hl))))
4789 res))) 'info-xref-visited 'info-xref))
4790 ;; For multiline ref, unfontify newline and surrounding whitespace
4794 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4795 (remove-text-properties (match-beginning 0)
4797 '(font-lock-face t))))))
4798 (when not-fontified-p
4799 (when (memq Info-hide-note-references '(t hide))
4800 (add-text-properties (match-beginning 3) (match-end 3)
4801 '(invisible t front-sticky nil rear-nonsticky t))
4802 ;; Unhide the file name of the external reference in parens
4803 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4804 (remove-text-properties (match-beginning 6) (match-end 6)
4805 '(invisible t front-sticky nil rear-nonsticky t)))
4806 ;; Unhide newline because hidden newlines cause too long lines
4808 (let ((beg3 (match-beginning 3))
4809 (end3 (match-end 3)))
4810 (if (and (string-match "\n[ \t]*" (match-string 3))
4811 (not (save-match-data
4813 (goto-char (1+ end3))
4814 (looking-at "[.)]*$")))))
4815 (remove-text-properties (+ beg3 (match-beginning 0))
4816 (+ beg3 (match-end 0))
4817 '(invisible t front-sticky nil rear-nonsticky t))))))
4818 (when (and Info-refill-paragraphs Info-hide-note-references)
4819 (push (set-marker (make-marker) start)
4820 paragraph-markers))))))
4822 ;; Refill paragraphs (experimental feature)
4823 (when (and not-fontified-p
4824 Info-refill-paragraphs
4826 (let ((fill-nobreak-invisible t)
4827 (fill-individual-varying-indent nil)
4828 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4829 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4830 (adaptive-fill-mode nil))
4831 (goto-char (point-max))
4832 (dolist (m paragraph-markers)
4836 (let ((beg (point)))
4837 (when (zerop (forward-paragraph))
4838 (fill-individual-paragraphs beg (point) nil nil)
4840 (set-marker m nil))))
4842 ;; Fontify menu items
4843 (goto-char (point-min))
4844 (when (and (or not-fontified-p fontify-visited-p)
4845 (search-forward "\n* Menu:" nil t)
4846 ;; Don't take time to annotate huge menus
4847 Info-fontify-maximum-menu-size
4848 (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
4851 (while (re-search-forward
4852 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4853 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4855 (when (match-beginning 1)
4856 (when not-fontified-p
4858 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4859 (put-text-property (match-beginning 0)
4860 (1+ (match-beginning 0))
4861 'font-lock-face 'info-menu-star)))
4862 (when not-fontified-p
4863 (add-text-properties
4864 (match-beginning 1) (match-end 1)
4866 'help-echo (if (and (match-end 3)
4867 (not (equal (match-string 3) "")))
4868 (concat "mouse-2: go to " (match-string 3))
4869 "mouse-2: go to this node")
4870 'mouse-face 'highlight)))
4871 (when (or not-fontified-p fontify-visited-p)
4873 (match-beginning 1) (match-end 1)
4875 ;; Display visited menu items in a different face
4876 (if (and Info-fontify-visited-nodes
4878 (let* ((node (if (equal (match-string 3) "")
4879 (match-string-no-properties 1)
4880 (match-string-no-properties 3)))
4882 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4883 (file (if external-link-p
4884 (file-name-nondirectory
4885 (match-string-no-properties 1 node))
4887 (hl Info-history-list)
4890 (setq node (if (equal (match-string 2 node) "")
4892 (match-string-no-properties 2 node))))
4894 (if (and (string-equal node (nth 1 (car hl)))
4896 (if (and external-link-p
4897 (stringp (caar hl)))
4898 (file-name-nondirectory
4901 (setq res (car hl) hl nil)
4902 (setq hl (cdr hl))))
4903 res))) 'info-xref-visited 'info-xref)))
4904 (when (and not-fontified-p
4905 (memq Info-hide-note-references '(t hide))
4906 (not (Info-index-node)))
4907 (put-text-property (match-beginning 2) (1- (match-end 6))
4909 ;; Unhide the file name in parens
4910 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4911 (remove-text-properties (match-beginning 4) (match-end 4)
4913 ;; We need a stretchable space like :align-to but with
4915 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4916 (if (>= 22 (- (match-end 1)
4917 (match-beginning 0)))
4918 '(space :align-to 24)
4920 (setq cont (looking-at "."))
4921 (while (and (= (forward-line 1) 0)
4922 (looking-at "\\([ \t]+\\)[^*\n]"))
4923 (put-text-property (match-beginning 1) (1- (match-end 1))
4925 (put-text-property (1- (match-end 1)) (match-end 1)
4928 '(space :align-to 26)
4929 '(space :align-to 24)))
4932 ;; Fontify menu headers
4933 ;; Add the face `info-menu-header' to any header before a menu entry
4934 (goto-char (point-min))
4935 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4936 (put-text-property (match-beginning 0) (match-end 0)
4937 'font-lock-face 'info-menu-header)
4938 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4939 (put-text-property (match-beginning 1) (match-end 1)
4940 'font-lock-face 'info-menu-header)))
4942 ;; Hide index line numbers
4943 (goto-char (point-min))
4944 (when (and not-fontified-p (Info-index-node))
4945 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4946 (put-text-property (match-beginning 0) (match-end 0)
4949 ;; Fontify http and ftp references
4950 (goto-char (point-min))
4951 (when not-fontified-p
4952 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`({<>})']+"
4954 (add-text-properties (match-beginning 0) (match-end 0)
4955 '(font-lock-face info-xref
4956 mouse-face highlight
4957 help-echo "mouse-2: go to this URL"))))
4959 ;; Fontify footnotes
4960 (goto-char (point-min))
4961 (when (and not-fontified-p (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t))
4962 (let ((limit (point)))
4963 (goto-char (point-min))
4964 (while (re-search-forward "\\(([0-9]+)\\)" nil t)
4965 (add-text-properties (match-beginning 0) (match-end 0)
4966 `(font-lock-face info-xref
4968 mouse-face highlight
4970 ,(if (< (point) limit)
4971 "mouse-2: go to footnote definition"
4972 "mouse-2: go to footnote reference"))))))
4974 ;; Hide empty lines at the end of the node.
4975 (goto-char (point-max))
4976 (skip-chars-backward "\n")
4977 (when (< (point) (1- (point-max)))
4978 (put-text-property (point) (1- (point-max)) 'invisible t))
4980 (set-buffer-modified-p nil))))
4982 ;;; Speedbar support:
4983 ;; These functions permit speedbar to display the "tags" in the
4984 ;; current Info node.
4985 (eval-when-compile (require 'speedbar))
4987 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
4988 (declare-function speedbar-center-buffer-smartly "speedbar" ())
4989 (declare-function speedbar-change-expand-button-char "speedbar" (char))
4990 (declare-function speedbar-change-initial-expansion-list "speedbar" (new-default))
4991 (declare-function speedbar-delete-subblock "speedbar" (indent))
4992 (declare-function speedbar-make-specialized-keymap "speedbar" ())
4993 (declare-function speedbar-make-tag-line "speedbar"
4994 (exp-button-type exp-button-char exp-button-function
4995 exp-button-data tag-button tag-button-function
4996 tag-button-data tag-button-face depth))
4998 (defvar Info-speedbar-key-map nil
4999 "Keymap used when in the Info display mode.")
5001 (defun Info-install-speedbar-variables ()
5002 "Install those variables used by speedbar to enhance Info."
5003 (if Info-speedbar-key-map
5005 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
5007 ;; Basic tree features
5008 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
5009 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
5010 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
5011 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
5014 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
5015 Info-speedbar-key-map
5016 Info-speedbar-hierarchy-buttons)))
5018 (defvar Info-speedbar-menu-items
5019 '(["Browse Node" speedbar-edit-line t]
5020 ["Expand Node" speedbar-expand-line
5021 (save-excursion (beginning-of-line)
5022 (looking-at "[0-9]+: *.\\+. "))]
5023 ["Contract Node" speedbar-contract-line
5024 (save-excursion (beginning-of-line)
5025 (looking-at "[0-9]+: *.-. "))]
5027 "Additional menu-items to add to speedbar frame.")
5029 ;; Make sure our special speedbar major mode is loaded
5030 (if (featurep 'speedbar)
5031 (Info-install-speedbar-variables)
5032 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
5034 ;;; Info hierarchy display method
5036 (defun Info-speedbar-browser ()
5037 "Initialize speedbar to display an Info node browser.
5038 This will add a speedbar major display mode."
5041 ;; Make sure that speedbar is active
5042 (speedbar-frame-mode 1)
5043 ;; Now, throw us into Info mode on speedbar.
5044 (speedbar-change-initial-expansion-list "Info")
5047 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
5048 "Display an Info directory hierarchy in speedbar.
5049 DIRECTORY is the current directory in the attached frame.
5050 DEPTH is the current indentation depth.
5051 NODE is an optional argument that is used to represent the
5052 specific node to expand."
5054 (save-excursion (goto-char (point-min))
5055 (let ((case-fold-search t))
5056 (looking-at "Info Nodes:"))))
5057 ;; Update our "current node" maybe?
5059 ;; We cannot use the generic list code, that depends on all leaves
5060 ;; being known at creation time.
5062 (speedbar-with-writable (insert "Info Nodes:\n")))
5063 (let ((completions nil))
5064 (speedbar-select-attached-frame)
5065 (save-window-excursion
5067 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
5068 (select-frame (speedbar-current-frame))
5070 (speedbar-with-writable
5071 (dolist (completion completions)
5072 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
5075 'Info-speedbar-goto-node
5081 (defun Info-speedbar-goto-node (_text node _indent)
5082 "When user clicks on TEXT, go to an info NODE.
5083 The INDENT level is ignored."
5084 (speedbar-select-attached-frame)
5085 (let* ((buff (or (get-buffer "*info*")
5086 (progn (info) (get-buffer "*info*"))))
5087 (bwin (get-buffer-window buff 0)))
5090 (select-window bwin)
5091 (raise-frame (window-frame bwin)))
5092 (if speedbar-power-click
5093 (switch-to-buffer-other-frame buff)
5094 (speedbar-select-attached-frame)
5095 (switch-to-buffer buff)))
5096 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
5097 (error "Invalid node %s" node)
5098 (Info-find-node (match-string 1 node) (match-string 2 node))
5099 ;; If we do a find-node, and we were in info mode, restore
5100 ;; the old default method. Once we are in info mode, it makes
5101 ;; sense to return to whatever method the user was using before.
5102 (if (string= speedbar-initial-expansion-list-name "Info")
5103 (speedbar-change-initial-expansion-list
5104 speedbar-previously-used-expansion-list-name)))))
5106 (defun Info-speedbar-expand-node (text token indent)
5107 "Expand the node the user clicked on.
5108 TEXT is the text of the button we clicked on, a + or - item.
5109 TOKEN is data related to this node (NAME . FILE).
5110 INDENT is the current indentation depth."
5111 (cond ((string-match "+" text) ;we have to expand this file
5112 (speedbar-change-expand-button-char ?-)
5113 (if (speedbar-with-writable
5115 (end-of-line) (forward-char 1)
5116 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
5117 (speedbar-change-expand-button-char ?-)
5118 (speedbar-change-expand-button-char ??)))
5119 ((string-match "-" text) ;we have to contract this node
5120 (speedbar-change-expand-button-char ?+)
5121 (speedbar-delete-subblock indent))
5122 (t (error "Ooops... not sure what to do")))
5123 (speedbar-center-buffer-smartly))
5125 (defun Info-speedbar-fetch-file-nodes (nodespec)
5126 "Fetch the subnodes from the info NODESPEC.
5127 NODESPEC is a string of the form: (file)node."
5128 ;; Set up a buffer we can use to fake-out Info.
5129 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
5130 (if (not (equal major-mode 'Info-mode))
5132 ;; Get the node into this buffer
5133 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
5134 (error "Invalid node specification %s" nodespec)
5135 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
5136 ;; Scan the created buffer
5137 (goto-char (point-min))
5138 (let ((completions nil)
5139 (case-fold-search t)
5140 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
5141 (match-string 1 nodespec))))
5142 ;; Always skip the first one...
5143 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5144 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5145 (let ((name (match-string 1)))
5147 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
5149 (if (looking-at " *\\(([^)]+)\\)\\.")
5150 (concat (match-string 1) "Top")
5151 (concat "(" thisfile ")"
5152 (if (looking-at " \\([^.]+\\).")
5156 (nreverse completions))))
5158 ;;; Info mode node listing
5159 ;; This is called by `speedbar-add-localized-speedbar-support'
5160 (defun Info-speedbar-buttons (_buffer)
5161 "Create a speedbar display to help navigation in an Info file.
5162 BUFFER is the buffer speedbar is requesting buttons for."
5163 (if (save-excursion (goto-char (point-min))
5164 (let ((case-fold-search t))
5165 (not (looking-at "Info Nodes:"))))
5167 (Info-speedbar-hierarchy-buttons nil 0))
5169 ;; FIXME: Really? Why here?
5170 (add-to-list 'debug-ignored-errors 'search-failed)
5172 ;;;; Desktop support
5174 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
5175 "Auxiliary information to be saved in desktop file."
5176 (list Info-current-file
5178 ;; Additional data as an association list.
5181 (cons 'history Info-history))
5182 (and (Info-virtual-fun
5183 'slow Info-current-file Info-current-node)
5186 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
5188 desktop-buffer-misc)
5189 "Restore an Info buffer specified in a desktop file."
5190 (let* ((file (nth 0 desktop-buffer-misc))
5191 (node (nth 1 desktop-buffer-misc))
5192 (data (nth 2 desktop-buffer-misc))
5193 (hist (assq 'history data))
5194 (slow (assq 'slow data)))
5195 ;; Don't restore nodes slow to regenerate.
5197 (when (and file node)
5198 (when desktop-buffer-name
5199 (set-buffer (get-buffer-create desktop-buffer-name))
5201 (Info-find-node file node)
5203 (setq Info-history (cdr hist)))
5204 (current-buffer)))))
5206 (add-to-list 'desktop-buffer-mode-handlers
5207 '(Info-mode . Info-restore-desktop-buffer))
5209 ;;;; Bookmark support
5210 (declare-function bookmark-make-record-default
5211 "bookmark" (&optional no-file no-context posn))
5212 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
5213 (declare-function bookmark-default-handler "bookmark" (bmk))
5214 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
5216 (defun Info-bookmark-make-record ()
5217 "This implements the `bookmark-make-record-function' type (which see)
5219 (let* ((file (and (stringp Info-current-file)
5220 (file-name-sans-extension
5221 (file-name-nondirectory Info-current-file))))
5222 (bookmark-name (if file
5223 (concat "(" file ") " Info-current-node)
5225 (defaults (delq nil (list bookmark-name file Info-current-node))))
5227 ,@(bookmark-make-record-default 'no-file)
5228 (filename . ,Info-current-file)
5229 (info-node . ,Info-current-node)
5230 (handler . Info-bookmark-jump)
5231 (defaults . ,defaults))))
5234 (defun Info-bookmark-jump (bmk)
5235 "This implements the `handler' function interface for the record
5236 type returned by `Info-bookmark-make-record', which see."
5237 (let* ((file (bookmark-prop-get bmk 'filename))
5238 (info-node (bookmark-prop-get bmk 'info-node))
5239 (buf (save-window-excursion ;FIXME: doesn't work with frames!
5240 (Info-find-node file info-node) (current-buffer))))
5241 ;; Use bookmark-default-handler to move to the appropriate location
5243 (bookmark-default-handler
5244 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
5248 (defun info-display-manual (manual)
5249 "Display an Info buffer displaying MANUAL.
5250 If there is an existing Info buffer for MANUAL, display it.
5251 Otherwise, visit the manual in a new Info buffer."
5256 (completing-read "Manual name: "
5257 (info--manual-names)
5259 (let ((blist (buffer-list))
5260 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
5261 (case-fold-search t)
5263 (dolist (buffer blist)
5264 (with-current-buffer buffer
5265 (when (and (eq major-mode 'Info-mode)
5266 (stringp Info-current-file)
5267 (string-match manual-re Info-current-file))
5271 (switch-to-buffer found)
5273 (info (Info-find-file manual)
5274 (generate-new-buffer-name "*info*")))))
5276 (defun info--manual-names ()
5278 (dolist (buffer (buffer-list))
5279 (with-current-buffer buffer
5280 (and (eq major-mode 'Info-mode)
5281 (stringp Info-current-file)
5282 (not (string= (substring (buffer-name) 0 1) " "))
5283 (push (file-name-sans-extension
5284 (file-name-nondirectory Info-current-file))
5286 (delete-dups (append (nreverse names)
5289 (apply-partially 'Info-read-node-name-2
5291 (mapcar 'car Info-suffix-list)))))))
5295 ;;; info.el ends here