1 ;; info.el --- Info package for Emacs -*- lexical-binding:t -*-
3 ;; Copyright (C) 1985-1986, 1992-2015 Free Software Foundation, Inc.
5 ;; Maintainer: emacs-devel@gnu.org
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 ": ".
35 (eval-when-compile (require 'cl-lib
))
43 (defvar-local Info-history nil
44 "Stack of Info nodes user has visited.
45 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
47 (defvar-local Info-history-forward nil
48 "Stack of Info nodes user has visited with `Info-history-back' command.
49 Each element of the stack is a list (FILENAME NODENAME BUFFERPOS).")
51 (defvar Info-history-list nil
52 "List of all Info nodes user has visited.
53 Each element of the list is a list (FILENAME NODENAME).")
55 (defcustom Info-history-skip-intermediate-nodes t
56 "Non-nil means don't record intermediate Info nodes to the history.
57 Intermediate Info nodes are nodes visited by Info internally in the process of
58 searching the node to display. Intermediate nodes are not presented
64 (defvar Info-enable-active-nodes nil
65 "Non-nil allows Info to execute Lisp code associated with nodes.
66 The Lisp code is executed when the node is selected.")
67 (put 'Info-enable-active-nodes
'risky-local-variable t
)
70 '((((class color
) (background light
)) :foreground
"brown" :weight bold
:slant italic
)
71 (((class color
) (background dark
)) :foreground
"white" :weight bold
:slant italic
)
72 (t :weight bold
:slant italic
))
73 "Face for Info node names."
77 '((((type tty pc
) (class color
) (background light
))
78 :foreground
"green" :weight bold
)
79 (((type tty pc
) (class color
) (background dark
))
80 :foreground
"yellow" :weight bold
)
81 (t :height
1.2 :inherit info-title-2
))
82 "Face for info titles at level 1."
84 (define-obsolete-face-alias 'Info-title-1-face
'info-title-1
"22.1")
87 '((((type tty pc
) (class color
)) :foreground
"lightblue" :weight bold
)
88 (t :height
1.2 :inherit info-title-3
))
89 "Face for info titles at level 2."
91 (define-obsolete-face-alias 'Info-title-2-face
'info-title-2
"22.1")
94 '((((type tty pc
) (class color
)) :weight bold
)
95 (t :height
1.2 :inherit info-title-4
))
96 "Face for info titles at level 3."
98 (define-obsolete-face-alias 'Info-title-3-face
'info-title-3
"22.1")
100 (defface info-title-4
101 '((((type tty pc
) (class color
)) :weight bold
)
102 (t :weight bold
:inherit variable-pitch
))
103 "Face for info titles at level 4."
105 (define-obsolete-face-alias 'Info-title-4-face
'info-title-4
"22.1")
107 (defface info-menu-header
112 :inherit variable-pitch
114 "Face for headers in Info menus."
117 (defface info-menu-star
118 '((((class color
)) :foreground
"red1")
120 "Face for every third `*' in an Info menu."
122 (define-obsolete-face-alias 'info-menu-5
'info-menu-star
"22.1")
126 "Face for unvisited Info cross-references."
129 (defface info-xref-visited
130 '((t :inherit
(link-visited info-xref
)))
131 "Face for visited Info cross-references."
135 (defcustom Info-fontify-visited-nodes t
136 "Non-nil to fontify references to visited nodes in `info-xref-visited' face."
141 ;; It's unfortunate that nil means no fontification, as opposed to no limit,
142 ;; since that differs from font-lock-maximum-size.
143 (defcustom Info-fontify-maximum-menu-size
400000
144 "Maximum size of menu to fontify if `font-lock-mode' is non-nil.
145 Set to nil to disable node fontification; set to t for no limit."
146 :type
'(choice (const :tag
"No fontification" nil
)
147 (const :tag
"No size limit" t
)
148 (integer :tag
"Up to this many characters"))
149 :version
"25.1" ; 100k -> 400k
152 (defcustom Info-use-header-line t
153 "Non-nil means to put the beginning-of-node links in an Emacs header-line.
154 A header-line does not scroll with the rest of the buffer."
158 (defface info-header-xref
159 '((t :inherit info-xref
))
160 "Face for Info cross-references in a node header."
163 (defface info-header-node
164 '((t :inherit info-node
))
165 "Face for Info nodes in a node header."
168 (defface info-index-match
169 '((t :inherit match
))
170 "Face used to highlight matches in an index entry."
174 ;; This is a defcustom largely so that we can get the benefit
175 ;; of custom-initialize-delay. Perhaps it would work to make it a
176 ;; defvar and explicitly give it a standard-value property, and
177 ;; call custom-initialize-delay on it.
178 ;; The progn forces the autoloader to include the whole thing, not
179 ;; just an abbreviated version.
182 (defcustom Info-default-directory-list
184 (file-name-as-directory
185 ;; Self-contained NS build with info/ in the app-bundle.
186 (or (and (featurep 'ns
)
187 (let ((dir (expand-file-name "../info" data-directory
)))
188 (if (file-directory-p dir
) dir
)))
189 configure-info-directory
)))
191 ;; Directory trees in which to look for info subdirectories
192 (prune-directory-list '("/usr/local/" "/usr/" "/opt/" "/")))
194 ;; Subdirectories in each directory tree that may contain info
195 ;; directories. Most of these are rather outdated.
196 ;; It ought to be fine to stop checking the "emacs" ones now,
197 ;; since this is Emacs and we have not installed info files
198 ;; into such directories for a looong time...
199 '("share/" "" "gnu/" "gnu/lib/" "gnu/lib/emacs/"
200 "emacs/" "lib/" "lib/emacs/"))
203 (mapcar (lambda (pfx)
205 (mapcar (lambda (sfx)
206 (concat pfx sfx
"info/"))
208 (prune-directory-list dirs
)))
210 ;; If $(prefix)/share/info is not one of the standard info
211 ;; directories, they are probably installing an experimental
212 ;; version of Emacs, so make sure that experimental version's Info
213 ;; files override the ones in standard directories.
215 (if (member config-dir standard-info-dirs
)
216 ;; FIXME? What is the point of adding it again at the end
217 ;; when it is already present earlier in the list?
218 (nconc standard-info-dirs
(list config-dir
))
219 (cons config-dir standard-info-dirs
))))
220 (if (not (eq system-type
'windows-nt
))
222 ;; Include the info directory near where Emacs executable was installed.
223 (let* ((instdir (file-name-directory invocation-directory
))
224 (dir1 (expand-file-name "../info/" instdir
))
225 (dir2 (expand-file-name "../../../info/" instdir
)))
226 (cond ((file-exists-p dir1
) (append dirs
(list dir1
)))
227 ((file-exists-p dir2
) (append dirs
(list dir2
)))
230 "Default list of directories to search for Info documentation files.
231 They are searched in the order they are given in the list.
232 Therefore, the directory of Info files that come with Emacs
233 normally should come last (so that local files override standard ones),
234 unless Emacs is installed into a non-standard directory. In the latter
235 case, the directory of Info files that come with Emacs should be
238 Once Info is started, the list of directories to search
239 comes from the variable `Info-directory-list'.
240 This variable `Info-default-directory-list' is used as the default
241 for initializing `Info-directory-list' when Info is started, unless
242 the environment variable INFOPATH is set.
244 Although this is a customizable variable, that is mainly for technical
245 reasons. Normally, you should either set INFOPATH or customize
246 `Info-additional-directory-list', rather than changing this variable."
247 :initialize
'custom-initialize-delay
248 :type
'(repeat directory
)
251 (defvar Info-directory-list nil
252 "List of directories to search for Info documentation files.
253 If nil, meaning not yet initialized, Info uses the environment
254 variable INFOPATH to initialize it, or `Info-default-directory-list'
255 if there is no INFOPATH variable in the environment, or the
256 concatenation of the two if INFOPATH ends with a `path-separator'.
258 When `Info-directory-list' is initialized from the value of
259 `Info-default-directory-list', and Emacs is installed in one of the
260 standard directories, the directory of Info files that come with Emacs
261 is put last (so that local Info files override standard ones).
263 When `Info-directory-list' is initialized from the value of
264 `Info-default-directory-list', and Emacs is not installed in one
265 of the standard directories, the first element of the resulting
266 list is the directory where Emacs installs the Info files that
267 come with it. This is so that Emacs's own manual, which suits the
268 version of Emacs you are using, will always be found first. This
269 is useful when you install an experimental version of Emacs without
270 removing the standard installation.
272 If you want to override the order of directories in
273 `Info-default-directory-list', set INFOPATH in the environment.
275 If you run the Emacs executable from the `src' directory in the Emacs
276 source tree, and INFOPATH is not defined, the `info' directory in the
277 source tree is used as the first element of `Info-directory-list', in
278 place of the installation Info directory. This is useful when you run
279 a version of Emacs without installing it.")
281 (defcustom Info-additional-directory-list nil
282 "List of additional directories to search for Info documentation files.
283 These directories are searched after those in `Info-directory-list'."
284 :type
'(repeat directory
)
287 (defcustom Info-scroll-prefer-subnodes nil
288 "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
290 If this is non-nil, and you scroll far enough in a node that its menu
291 appears on the screen, the next \\<Info-mode-map>\\[Info-scroll-up]
292 moves to a subnode indicated by the following menu item. This means
293 that you visit a subnode before getting to the end of the menu.
295 Setting this option to nil results in behavior similar to the stand-alone
296 Info reader program, which visits the first subnode from the menu only
297 when you hit the end of the current node."
302 (defcustom Info-hide-note-references t
303 "If non-nil, hide the tag and section reference in *note and * menu items.
304 If value is non-nil but not `hide', also replaces the \"*note\" with \"see\".
305 If value is non-nil but not t or `hide', the reference section is still shown.
306 nil completely disables this feature. If this is non-nil, you might
307 want to set `Info-refill-paragraphs'."
309 :type
'(choice (const :tag
"No hiding" nil
)
310 (const :tag
"Replace tag and hide reference" t
)
311 (const :tag
"Hide tag and reference" hide
)
312 (other :tag
"Only replace tag" tag
))
313 :set
(lambda (sym val
)
315 (dolist (buffer (buffer-list))
316 (with-current-buffer buffer
317 (when (eq major-mode
'Info-mode
)
318 (revert-buffer t t
)))))
321 (defcustom Info-refill-paragraphs nil
322 "If non-nil, attempt to refill paragraphs with hidden references.
323 This refilling may accidentally remove explicit line breaks in the Info
324 file, so be prepared for a few surprises if you enable this feature.
325 This only has an effect if `Info-hide-note-references' is non-nil."
330 (defcustom Info-breadcrumbs-depth
4
331 "Depth of breadcrumbs to display.
332 0 means do not display breadcrumbs."
337 (defcustom Info-search-whitespace-regexp
"\\s-+"
338 "If non-nil, regular expression to match a sequence of whitespace chars.
339 This applies to Info search for regular expressions.
340 You might want to use something like \"[ \\t\\r\\n]+\" instead.
341 In the Customization buffer, that is `[' followed by a space,
342 a tab, a carriage return (control-M), a newline, and `]+'."
346 (defcustom Info-isearch-search t
347 "If non-nil, isearch in Info searches through multiple nodes.
348 Before leaving the initial Info node, where isearch was started,
349 it fails once with the error message [end of node], and with
350 subsequent C-s/C-r continues through other nodes without failing
351 with this error message in other nodes. When isearch fails for
352 the rest of the manual, it displays the error message [end of manual],
353 wraps around the whole manual and restarts the search from the top/final
354 node depending on search direction.
356 Setting this option to nil restores the default isearch behavior
357 with wrapping around the current Info node."
362 (defvar Info-isearch-initial-node nil
)
363 (defvar Info-isearch-initial-history nil
)
364 (defvar Info-isearch-initial-history-list nil
)
366 (defcustom Info-mode-hook
367 ;; Try to obey obsolete Info-fontify settings.
368 (unless (and (boundp 'Info-fontify
) (null Info-fontify
))
369 '(turn-on-font-lock))
370 "Hooks run when `Info-mode' is called."
374 (defcustom Info-selection-hook nil
375 "Hooks run when `Info-select-node' is called."
379 (defvar Info-edit-mode-hook nil
380 "Hooks run when `Info-edit-mode' is called.")
382 (make-obsolete-variable 'Info-edit-mode-hook
383 "editing Info nodes by hand is not recommended." "24.4")
385 (defvar-local Info-current-file nil
386 "Info file that Info is now looking at, or nil.
387 This is the name that was specified in Info, not the actual file name.
388 It doesn't contain directory names or file name extensions added by Info.")
390 (defvar-local Info-current-subfile nil
391 "Info subfile that is actually in the *info* buffer now.
392 It is nil if current Info file is not split into subfiles.")
394 (defvar-local Info-current-node nil
395 "Name of node that Info is now looking at, or nil.")
397 (defvar-local Info-tag-table-marker nil
398 "Marker pointing at beginning of current Info file's tag table.
399 Marker points nowhere if file has no tag table.")
401 (defvar-local Info-tag-table-buffer nil
402 "Buffer used for indirect tag tables.")
404 (defvar-local Info-current-file-completions nil
405 "Cached completion list for current Info file.")
407 (defvar Info-file-completions nil
408 "Cached completion alist of visited Info files.
409 Each element of the alist is (FILE . COMPLETIONS)")
411 (defvar-local Info-file-supports-index-cookies nil
412 "Non-nil if current Info file supports index cookies.")
414 (defvar Info-file-supports-index-cookies-list nil
415 "List of Info files with information about index cookies support.
416 Each element of the list is a list (FILENAME SUPPORTS-INDEX-COOKIES)
417 where SUPPORTS-INDEX-COOKIES can be either t or nil.")
419 (defvar-local Info-index-alternatives nil
420 "List of possible matches for last `Info-index' command.")
422 (defvar Info-point-loc nil
423 "Point location within a selected node.
424 If string, the point is moved to the proper occurrence of the
425 name of the followed cross reference within a selected node.
426 If number, the point is moved to the corresponding line.")
428 (defvar Info-standalone nil
429 "Non-nil if Emacs was started solely as an Info browser.")
431 (defvar Info-file-attributes nil
432 "Alist of file attributes of visited Info files.
433 Each element is a list (FILE-NAME FILE-ATTRIBUTES...).")
435 (defvar Info-toc-nodes nil
436 "Alist of cached parent-children node information in visited Info files.
437 Each element is (FILE (NODE-NAME PARENT SECTION CHILDREN) ...)
438 where PARENT is the parent node extracted from the Up pointer,
439 SECTION is the section name in the Top node where this node is placed,
440 CHILDREN is a list of child nodes extracted from the node menu.")
442 (defvar Info-index-nodes nil
443 "Alist of cached index node names of visited Info files.
444 Each element has the form (INFO-FILE INDEX-NODE-NAMES-LIST).")
446 (defvar Info-virtual-files nil
447 "List of definitions of virtual Info files.
448 Each element of the list has the format (FILENAME (OPERATION . HANDLER) ...)
449 where FILENAME is a regexp that matches a class of virtual Info file names.
450 It should be carefully chosen to not cause file name clashes with
451 existing file names. OPERATION is one of the following operation
452 symbols `find-file', `find-node', `toc-nodes' that define what HANDLER
453 function to call instead of calling the default corresponding function
456 (defvar Info-virtual-nodes nil
457 "List of definitions of virtual Info nodes.
458 Each element of the list has the format (NODENAME (OPERATION . HANDLER) ...)
459 where NODENAME is a regexp that matches a class of virtual Info node names.
460 It should be carefully chosen to not cause node name clashes with
461 existing node names. OPERATION is one of the following operation
462 symbols `find-node' that define what HANDLER function to call instead
463 of calling the default corresponding function to override it.")
465 (defvar-local Info-current-node-virtual nil
466 "Non-nil if the current Info node is virtual.")
468 (defun Info-virtual-file-p (filename)
469 "Check if Info file FILENAME is virtual."
470 (Info-virtual-fun 'find-file filename nil
))
472 (defun Info-virtual-fun (op filename nodename
)
473 "Find a function that handles operations on virtual manuals.
474 OP is an operation symbol (`find-file', `find-node' or `toc-nodes'),
475 FILENAME is a virtual Info file name, NODENAME is a virtual Info
476 node name. Return a function found either in `Info-virtual-files'
477 or `Info-virtual-nodes'."
478 (or (and (stringp filename
) ; some legacy code can still use a symbol
479 (cdr-safe (assoc op
(assoc-default filename
482 (and (stringp nodename
) ; some legacy code can still use a symbol
483 (cdr-safe (assoc op
(assoc-default nodename
487 (defun Info-virtual-call (virtual-fun &rest args
)
488 "Call a function that handles operations on virtual manuals."
489 (when (functionp virtual-fun
)
490 (or (apply virtual-fun args
) t
)))
493 (defvar Info-suffix-list
494 ;; The MS-DOS list should work both when long file names are
495 ;; supported (Windows 9X), and when only 8+3 file names are available.
496 (if (eq system-type
'ms-dos
)
497 '( (".gz" .
"gunzip")
499 (".bz2" .
("bzip2" "-dc"))
502 (".info.Z" .
"gunzip")
503 (".info.gz" .
"gunzip")
504 ("-info.Z" .
"gunzip")
505 ("-info.gz" .
"gunzip")
506 ("/index.gz" .
"gunzip")
507 ("/index.z" .
"gunzip")
513 '( (".info.Z" .
"uncompress")
514 (".info.Y" .
"unyabba")
515 (".info.gz" .
"gunzip")
516 (".info.z" .
"gunzip")
517 (".info.bz2" .
("bzip2" "-dc"))
518 (".info.xz" .
"unxz")
520 ("-info.Z" .
"uncompress")
521 ("-info.Y" .
"unyabba")
522 ("-info.gz" .
"gunzip")
523 ("-info.bz2" .
("bzip2" "-dc"))
524 ("-info.z" .
"gunzip")
525 ("-info.xz" .
"unxz")
527 ("/index.Z" .
"uncompress")
528 ("/index.Y" .
"unyabba")
529 ("/index.gz" .
"gunzip")
530 ("/index.z" .
"gunzip")
531 ("/index.bz2" .
("bzip2" "-dc"))
532 ("/index.xz" .
"unxz")
534 (".Z" .
"uncompress")
538 (".bz2" .
("bzip2" "-dc"))
541 "List of file name suffixes and associated decoding commands.
542 Each entry should be (SUFFIX . STRING); the file is given to
543 the command as standard input.
545 STRING may be a list of strings. In that case, the first element is
546 the command name, and the rest are arguments to that command.
548 If STRING is nil, no decoding is done.
549 Because the SUFFIXes are tried in order, the empty string should
550 be last in the list.")
552 ;; Concatenate SUFFIX onto FILENAME. SUFFIX should start with a dot.
553 ;; First, on MS-DOS with no long file names support, delete some of
554 ;; the extension in FILENAME to make room.
555 (defun info-insert-file-contents-1 (filename suffix lfn
)
556 (if lfn
; long file names are supported
557 (concat filename suffix
)
558 (let* ((sans-exts (file-name-sans-extension filename
))
559 ;; How long is the extension in FILENAME (not counting the dot).
560 (ext-len (max 0 (- (length filename
) (length sans-exts
) 1)))
562 ;; SUFFIX starts with a dot. If FILENAME already has one,
563 ;; get rid of the one in SUFFIX (unless suffix is empty).
564 (or (and (<= ext-len
0)
565 (not (eq (aref filename
(1- (length filename
))) ?.
)))
566 (= (length suffix
) 0)
567 (setq suffix
(substring suffix
1)))
568 ;; How many chars of that extension should we keep?
569 (setq ext-left
(min ext-len
(max 0 (- 3 (length suffix
)))))
570 ;; Get rid of the rest of the extension, and add SUFFIX.
571 (concat (substring filename
0 (- (length filename
)
572 (- ext-len ext-left
)))
575 (defun info-file-exists-p (filename)
576 (and (file-exists-p filename
)
577 (not (file-directory-p filename
))))
579 (defun info-insert-file-contents (filename &optional visit
)
580 "Insert the contents of an Info file in the current buffer.
581 Do the right thing if the file has been compressed or zipped."
582 (let* ((tail Info-suffix-list
)
583 (jka-compr-verbose nil
)
584 (lfn (if (fboundp 'msdos-long-file-names
)
585 (msdos-long-file-names)
587 (check-short (and (fboundp 'msdos-long-file-names
)
589 fullname decoder done
)
590 (if (info-file-exists-p filename
)
591 ;; FILENAME exists--see if that name contains a suffix.
592 ;; If so, set DECODE accordingly.
596 (concat (regexp-quote (car (car tail
))) "$")
598 (setq tail
(cdr tail
)))
599 (setq fullname filename
600 decoder
(cdr (car tail
))))
601 ;; Try adding suffixes to FILENAME and see if we can find something.
602 (while (and tail
(not done
))
603 (setq fullname
(info-insert-file-contents-1 filename
604 (car (car tail
)) lfn
))
605 (if (info-file-exists-p fullname
)
607 ;; If we found a file with a suffix, set DECODER
608 ;; according to the suffix.
609 decoder
(cdr (car tail
)))
610 ;; When the MS-DOS port runs on Windows, we need to check
611 ;; the short variant of a long file name as well.
613 (setq fullname
(info-insert-file-contents-1 filename
614 (car (car tail
)) nil
))
615 (if (info-file-exists-p fullname
)
617 decoder
(cdr (car tail
))))))
618 (setq tail
(cdr tail
)))
620 (error "Can't find %s or any compressed version of it" filename
)))
621 ;; check for conflict with jka-compr
622 (if (and (jka-compr-installed-p)
623 (jka-compr-get-compression-info fullname
))
627 (insert-file-contents-literally fullname visit
)
628 (let ((inhibit-read-only t
)
629 (coding-system-for-write 'no-conversion
)
630 (inhibit-null-byte-detection t
) ; Index nodes include null bytes
631 (default-directory (or (file-name-directory fullname
)
634 (setq decoder
(list decoder
)))
635 (apply #'call-process-region
(point-min) (point-max)
636 (car decoder
) t t nil
(cdr decoder
))))
637 (let ((inhibit-null-byte-detection t
)) ; Index nodes include null bytes
638 (insert-file-contents fullname visit
)))
640 ;; Clear the caches of modified Info files.
641 (let* ((attribs-old (cdr (assoc fullname Info-file-attributes
)))
642 (modtime-old (and attribs-old
(nth 5 attribs-old
)))
643 (attribs-new (and (stringp fullname
) (file-attributes fullname
)))
644 (modtime-new (and attribs-new
(nth 5 attribs-new
))))
645 (when (and modtime-old modtime-new
646 (> (float-time modtime-new
) (float-time modtime-old
)))
647 (setq Info-index-nodes
(remove (assoc (or Info-current-file filename
)
650 (setq Info-toc-nodes
(remove (assoc (or Info-current-file filename
)
653 ;; Add new modtime to `Info-file-attributes'.
654 (setq Info-file-attributes
655 (cons (cons fullname attribs-new
)
656 (remove (assoc fullname Info-file-attributes
)
657 Info-file-attributes
))))))
659 (defun Info-file-supports-index-cookies (&optional file
)
660 "Return non-nil value if FILE supports Info index cookies.
661 Info index cookies were first introduced in 4.7, and all later
662 makeinfo versions output them in index nodes, so we can rely
663 solely on the makeinfo version. This function caches the information
664 in `Info-file-supports-index-cookies-list'."
665 (or file
(setq file Info-current-file
))
666 (or (assoc file Info-file-supports-index-cookies-list
)
667 ;; Skip virtual Info files
668 (and (or (not (stringp file
))
669 (Info-virtual-file-p file
))
670 (setq Info-file-supports-index-cookies-list
671 (cons (cons file nil
) Info-file-supports-index-cookies-list
)))
674 (goto-char (point-min))
676 (if (and (re-search-forward
677 "makeinfo[ \n]version[ \n]\\([0-9]+.[0-9]+\\)"
678 (line-beginning-position 4) t
)
679 (not (version< (match-string 1) "4.7")))
682 (setq Info-file-supports-index-cookies-list
683 (cons (cons file found
) Info-file-supports-index-cookies-list
)))))
684 (cdr (assoc file Info-file-supports-index-cookies-list
)))
687 (defun Info-default-dirs ()
688 (let ((source (expand-file-name "info/" source-directory
))
689 (sibling (if installation-directory
690 (expand-file-name "info/" installation-directory
)
691 (if invocation-directory
692 (let ((infodir (expand-file-name
694 invocation-directory
)))
695 (if (file-exists-p infodir
)
697 (setq infodir
(expand-file-name
698 "../../../share/info/"
699 invocation-directory
))
700 (and (file-exists-p infodir
)
704 (if (and sibling
(file-exists-p sibling
))
705 ;; Uninstalled, Emacs builddir != srcdir.
707 ;; Uninstalled, builddir == srcdir
709 (if (or (member alternative Info-default-directory-list
)
710 ;; On DOS/NT, we use movable executables always,
711 ;; and we must always find the Info dir at run time.
712 (if (memq system-type
'(ms-dos windows-nt
))
714 ;; Use invocation-directory for Info
715 ;; only if we used it for exec-directory also.
716 (not (string= exec-directory
717 (expand-file-name "lib-src/"
718 installation-directory
))))
719 (not (file-exists-p alternative
)))
720 Info-default-directory-list
721 ;; `alternative' contains the Info files that came with this
722 ;; version, so we should look there first. `Info-insert-dir'
723 ;; currently expects to find `alternative' first on the list.
725 ;; Don't drop the last part, it might contain non-Emacs stuff.
726 ;; (reverse (cdr (reverse
727 Info-default-directory-list
)))) ;; )))
729 (defun info-initialize ()
730 "Initialize `Info-directory-list', if that hasn't been done yet."
731 (unless Info-directory-list
732 (let ((path (getenv "INFOPATH"))
733 (sep (regexp-quote path-separator
)))
734 (setq Info-directory-list
735 (prune-directory-list
737 (if (string-match-p (concat sep
"\\'") path
)
738 (append (split-string (substring path
0 -
1) sep
)
740 (split-string path sep
))
741 (Info-default-dirs))))
742 ;; For a self-contained (ie relocatable) NS build, AFAICS we
743 ;; always want the included info directory to be at the head of
744 ;; the search path, unless it's already in INFOPATH somewhere.
745 ;; It's at the head of Info-default-directory-list,
746 ;; but there's no way to get it at the head of Info-directory-list
747 ;; except by doing it here.
750 (let ((dir (expand-file-name "../info" data-directory
)))
751 (and (file-directory-p dir
)
752 (not (member dir
(split-string path
":" t
)))
753 (push dir Info-directory-list
)))))))
756 (defun info-other-window (&optional file-or-node buffer
)
757 "Like `info' but show the Info buffer in another window."
759 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
760 (read-file-name "Info file name: " nil nil t
))
761 (if (numberp current-prefix-arg
)
762 (format "*info*<%s>" current-prefix-arg
))))
763 (info-setup file-or-node
764 (switch-to-buffer-other-window (or buffer
"*info*"))))
766 ;;;###autoload (put 'info 'info-file (purecopy "emacs"))
768 (defun info (&optional file-or-node buffer
)
769 "Enter Info, the documentation browser.
770 Optional argument FILE-OR-NODE specifies the file to examine;
771 the default is the top-level directory of Info.
772 Called from a program, FILE-OR-NODE may specify an Info node of the form
773 \"(FILENAME)NODENAME\".
774 Optional argument BUFFER specifies the Info buffer name;
775 the default buffer name is *info*. If BUFFER exists,
776 just switch to BUFFER. Otherwise, create a new buffer
777 with the top-level Info directory.
779 In interactive use, a non-numeric prefix argument directs
780 this command to read a file name from the minibuffer.
782 A numeric prefix argument of N selects an Info buffer named \"*info*<N>\".
784 The search path for Info files is in the variable `Info-directory-list'.
785 The top-level Info directory is made by combining all the files named `dir'
786 in all the directories in that path.
788 See a list of available Info commands in `Info-mode'."
790 (if (and current-prefix-arg
(not (numberp current-prefix-arg
)))
791 (read-file-name "Info file name: " nil nil t
))
792 (if (numberp current-prefix-arg
)
793 (format "*info*<%s>" current-prefix-arg
))))
794 (info-setup file-or-node
795 (pop-to-buffer-same-window (or buffer
"*info*"))))
797 (defun info-setup (file-or-node buffer
)
798 "Display Info node FILE-OR-NODE in BUFFER."
799 (if (and buffer
(not (derived-mode-p 'Info-mode
)))
802 ;; If argument already contains parentheses, don't add another set
803 ;; since the argument will then be parsed improperly. This also
804 ;; has the added benefit of allowing node names to be included
805 ;; following the parenthesized filename.
807 (if (and (stringp file-or-node
) (string-match "(.*)" file-or-node
))
809 (concat "(" file-or-node
")")))
810 (if (and (zerop (buffer-size))
812 ;; If we just created the Info buffer, go to the directory.
816 (defun info-emacs-manual ()
817 "Display the Emacs manual in Info mode."
822 (defun info-emacs-bug ()
823 "Display the \"Reporting Bugs\" section of the Emacs manual in Info mode."
825 (info "(emacs)Bugs"))
828 (defun info-standalone ()
829 "Run Emacs as a standalone Info reader.
830 Usage: emacs -f info-standalone [filename]
831 In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
832 (setq Info-standalone t
)
833 (if (and command-line-args-left
834 (not (string-match "^-" (car command-line-args-left
))))
837 (info (car command-line-args-left
))
838 (setq command-line-args-left
(cdr command-line-args-left
)))
839 (error (send-string-to-terminal
840 (format "%s\n" (if (eq (car-safe err
) 'error
)
842 (save-buffers-kill-emacs)))
845 ;; See if the accessible portion of the buffer begins with a node
846 ;; delimiter, and the node header line which follows matches REGEXP.
847 ;; Typically, this test will be followed by a loop that examines the
848 ;; rest of the buffer with (search-forward "\n\^_"), and it's a pity
849 ;; to have the overhead of this special test inside the loop.
851 ;; This function changes match-data, but supposedly the caller might
852 ;; want to use the results of re-search-backward.
854 ;; The return value is the value of point at the beginning of matching
855 ;; REGEXP, if the function succeeds, nil otherwise.
856 (defun Info-node-at-bob-matching (regexp)
857 (and (bobp) ; are we at beginning of buffer?
858 (looking-at "\^_") ; does it begin with node delimiter?
862 (forward-line 1) ; does the line after delimiter match REGEXP?
863 (re-search-backward regexp beg t
))))
865 (defun Info-find-file (filename &optional noerror
)
866 "Return expanded FILENAME, or t if FILENAME is \"dir\".
867 Optional second argument NOERROR, if t, means if file is not found
868 just return nil (no error)."
869 ;; Convert filename to lower case if not found as specified.
873 (Info-virtual-fun 'find-file filename nil
)
876 (let (temp temp-downcase found
)
877 (setq filename
(substitute-in-file-name filename
))
878 (let ((dirs (if (string-match "^\\./" filename
)
879 ;; If specified name starts with `./'
880 ;; then just try current directory.
882 (if (file-name-absolute-p filename
)
883 ;; No point in searching for an
884 ;; absolute file name
886 (if Info-additional-directory-list
887 (append Info-directory-list
888 Info-additional-directory-list
)
889 Info-directory-list
)))))
890 ;; Fall back on the installation directory if we can't find
891 ;; the info node anywhere else.
892 (when installation-directory
893 (setq dirs
(append dirs
(list (expand-file-name
894 "info" installation-directory
)))))
895 ;; Search the directory list for file FILENAME.
896 (while (and dirs
(not found
))
897 (setq temp
(expand-file-name filename
(car dirs
)))
899 (expand-file-name (downcase filename
) (car dirs
)))
900 ;; Try several variants of specified name.
901 (let ((suffix-list Info-suffix-list
)
902 (lfn (if (fboundp 'msdos-long-file-names
)
903 (msdos-long-file-names)
905 (while (and suffix-list
(not found
))
906 (cond ((info-file-exists-p
907 (info-insert-file-contents-1
908 temp
(car (car suffix-list
)) lfn
))
911 (info-insert-file-contents-1
912 temp-downcase
(car (car suffix-list
)) lfn
))
913 (setq found temp-downcase
))
914 ((and (fboundp 'msdos-long-file-names
)
917 (info-insert-file-contents-1
918 temp
(car (car suffix-list
)) nil
)))
920 (setq suffix-list
(cdr suffix-list
))))
921 (setq dirs
(cdr dirs
))))
923 (setq filename found
)
926 ;; If there is no previous Info file, go to the directory.
927 (unless Info-current-file
929 (user-error "Info file %s does not exist" filename
)))
932 (defun Info-find-node (filename nodename
&optional no-going-back strict-case
)
933 "Go to an Info node specified as separate FILENAME and NODENAME.
934 NO-GOING-BACK is non-nil if recovering from an error in this function;
935 it says do not attempt further (recursive) error recovery.
937 This function first looks for a case-sensitive match for NODENAME;
938 if none is found it then tries a case-insensitive match (unless
939 STRICT-CASE is non-nil)."
941 (setq filename
(Info-find-file filename
))
942 ;; Go into Info buffer.
943 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
944 ;; Record the node we are leaving, if we were in one.
945 (and (not no-going-back
)
947 (push (list Info-current-file Info-current-node
(point))
949 (Info-find-node-2 filename nodename no-going-back strict-case
))
952 (defun Info-on-current-buffer (&optional nodename
)
953 "Use Info mode to browse the current Info buffer.
954 With a prefix arg, this queries for the node name to visit first;
955 otherwise, that defaults to `Top'."
957 (list (if current-prefix-arg
958 (completing-read "Node name: " (Info-build-node-completions)
960 (unless nodename
(setq nodename
"Top"))
963 (setq Info-current-file
965 ;; If called on a non-file buffer, make a fake file name.
966 (concat default-directory
(buffer-name))))
967 (Info-find-node-2 nil nodename
))
969 (defun Info-revert-find-node (filename nodename
)
970 "Go to an Info node FILENAME and NODENAME, re-reading disk contents.
971 When *info* is already displaying FILENAME and NODENAME, the window position
972 is preserved, if possible."
973 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
974 (let ((old-filename Info-current-file
)
975 (old-nodename Info-current-node
)
976 (window-selected (eq (selected-window) (get-buffer-window)))
977 (pcolumn (current-column))
978 (pline (count-lines (point-min) (line-beginning-position)))
979 (wline (count-lines (point-min) (window-start)))
980 (new-history (and Info-current-file
981 (list Info-current-file Info-current-node
(point)))))
982 ;; When `Info-current-file' is nil, `Info-find-node-2' rereads the file.
983 (setq Info-current-file nil
)
984 (Info-find-node filename nodename
)
985 (if (and (equal old-filename Info-current-file
)
986 (equal old-nodename Info-current-node
))
988 ;; note goto-line is no good, we want to measure from point-min
989 (when window-selected
990 (goto-char (point-min))
992 (set-window-start (selected-window) (point)))
993 (goto-char (point-min))
995 (move-to-column pcolumn
))
996 ;; only add to the history when coming from a different file+node
998 (setq Info-history
(cons new-history Info-history
))))))
1000 (defun Info-revert-buffer-function (_ignore-auto noconfirm
)
1001 (when (or noconfirm
(y-or-n-p "Revert info buffer? "))
1002 (Info-revert-find-node Info-current-file Info-current-node
)
1003 (message "Reverted %s" Info-current-file
)))
1005 (defun Info-find-in-tag-table-1 (marker regexp case-fold
)
1006 "Find a node in a tag table.
1007 MARKER specifies the buffer and position to start searching at.
1008 REGEXP is a regular expression matching nodes or references. Its first
1009 group should match `Node:' or `Ref:'.
1010 CASE-FOLD t means search for a case-insensitive match.
1011 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1012 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
1013 where the match was found, and MODE is `major-mode' of the buffer in
1014 which the match was found."
1015 (let ((case-fold-search case-fold
))
1016 (with-current-buffer (marker-buffer marker
)
1021 (when (re-search-forward regexp nil t
)
1022 (list (string-equal "Ref:" (match-string 1))
1023 (+ (point-min) (read (current-buffer)))
1026 (defun Info-find-in-tag-table (marker regexp
&optional strict-case
)
1027 "Find a node in a tag table.
1028 MARKER specifies the buffer and position to start searching at.
1029 REGEXP is a regular expression matching nodes or references. Its first
1030 group should match `Node:' or `Ref:'.
1031 If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
1032 FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
1033 where the match was found, and MODE is `major-mode' of the buffer in
1034 which the match was found.
1035 This function tries to find a case-sensitive match first, then a
1036 case-insensitive match is tried (unless optional argument STRICT-CASE
1038 (let ((result (Info-find-in-tag-table-1 marker regexp nil
)))
1039 (or strict-case
(car result
)
1040 (setq result
(Info-find-in-tag-table-1 marker regexp t
)))
1043 (defun Info-find-node-in-buffer-1 (regexp case-fold
)
1044 "Find a node or anchor in the current buffer.
1045 REGEXP is a regular expression matching nodes or references. Its first
1046 group should match `Node:' or `Ref:'.
1047 CASE-FOLD t means search for a case-insensitive match.
1048 Value is the position at which a match was found, or nil if not found."
1049 (let ((case-fold-search case-fold
)
1052 (if (Info-node-at-bob-matching regexp
)
1053 (setq found
(point))
1054 (while (and (not found
)
1055 (search-forward "\n\^_" nil t
))
1057 (let ((beg (point)))
1059 (if (re-search-backward regexp beg t
)
1060 (setq found
(line-beginning-position)))))))
1063 (defun Info-find-node-in-buffer (regexp &optional strict-case
)
1064 "Find a node or anchor in the current buffer.
1065 REGEXP is a regular expression matching nodes or references. Its first
1066 group should match `Node:' or `Ref:'.
1067 Value is the position at which a match was found, or nil if not found.
1068 This function looks for a case-sensitive match first. If none is found,
1069 a case-insensitive match is tried (unless optional argument STRICT-CASE
1071 (or (Info-find-node-in-buffer-1 regexp nil
)
1072 (and (not strict-case
)
1073 (Info-find-node-in-buffer-1 regexp t
))))
1075 (defun Info-find-node-2 (filename nodename
&optional no-going-back strict-case
)
1076 (buffer-disable-undo (current-buffer))
1077 (or (derived-mode-p 'Info-mode
)
1080 (setq Info-current-node nil
)
1082 (let ((case-fold-search t
)
1083 (virtual-fun (Info-virtual-fun 'find-node
1084 (or filename Info-current-file
)
1088 ((functionp virtual-fun
)
1089 (let ((filename (or filename Info-current-file
)))
1090 (setq buffer-read-only nil
)
1091 (setq Info-current-file filename
1092 Info-current-subfile nil
1093 Info-current-file-completions nil
1094 buffer-file-name nil
)
1096 (Info-virtual-call virtual-fun filename nodename no-going-back
)
1097 (set-marker Info-tag-table-marker nil
)
1098 (setq buffer-read-only t
)
1099 (set-buffer-modified-p nil
)
1100 (setq Info-current-node-virtual t
)))
1102 ;; Reread a file when moving from a virtual node.
1103 (not Info-current-node-virtual
)
1105 (equal Info-current-file filename
))))
1106 ;; Switch files if necessary
1107 (let ((inhibit-read-only t
))
1108 (when Info-current-node-virtual
1109 ;; When moving from a virtual node.
1110 (setq Info-current-node-virtual nil
)
1112 (setq filename Info-current-file
)))
1113 (setq Info-current-file nil
1114 Info-current-subfile nil
1115 Info-current-file-completions nil
1116 buffer-file-name nil
)
1118 (info-insert-file-contents filename nil
)
1119 (setq default-directory
(file-name-directory filename
))
1120 (set-buffer-modified-p nil
)
1121 (setq Info-file-supports-index-cookies
1122 (Info-file-supports-index-cookies filename
))
1124 ;; See whether file has a tag table. Record the location if yes.
1125 (goto-char (point-max))
1127 ;; Use string-equal, not equal, to ignore text props.
1128 (if (not (or (string-equal nodename
"*")
1130 (search-forward "\^_\nEnd tag table\n" nil t
))))
1132 ;; We have a tag table. Find its beginning.
1133 ;; Is this an indirect file?
1134 (search-backward "\nTag table:\n")
1138 (looking-at "(Indirect)\n"))
1139 ;; It is indirect. Copy it to another buffer
1140 ;; and record that the tag table is in that buffer.
1141 (let ((buf (current-buffer))
1143 (or Info-tag-table-buffer
1144 (generate-new-buffer " *info tag table*"))))
1145 (setq Info-tag-table-buffer tagbuf
)
1146 (with-current-buffer tagbuf
1147 (buffer-disable-undo (current-buffer))
1148 (setq case-fold-search t
)
1150 (insert-buffer-substring buf
))
1151 (set-marker Info-tag-table-marker
1152 (match-end 0) tagbuf
))
1153 (set-marker Info-tag-table-marker pos
)))
1154 (set-marker Info-tag-table-marker nil
))
1155 (setq Info-current-file filename
)
1158 ;; Use string-equal, not equal, to ignore text props.
1159 (if (string-equal nodename
"*")
1160 (progn (setq Info-current-node nodename
)
1161 (Info-set-mode-line))
1164 ;; 1. Anchor found in tag table
1165 ;; 2. Anchor *not* in tag table
1167 ;; 3. Node found in tag table
1168 ;; 4. Node *not* found in tag table, but found in file
1169 ;; 5. Node *not* in tag table, and *not* in file
1171 ;; *Or* the same, but in an indirect subfile.
1173 ;; Search file for a suitable node.
1174 (let ((guesspos (point-min))
1175 (regexp (concat "\\(Node:\\|Ref:\\) *\\("
1176 (if (stringp nodename
)
1177 (regexp-quote nodename
)
1179 "\\) *[,\t\n\177]")))
1183 ;; First, search a tag table, if any
1184 (when (marker-position Info-tag-table-marker
)
1185 (let* ((m Info-tag-table-marker
)
1186 (found (Info-find-in-tag-table m regexp strict-case
)))
1189 ;; FOUND is (ANCHOR POS MODE).
1190 (setq guesspos
(nth 1 found
))
1192 ;; If this is an indirect file, determine which
1193 ;; file really holds this node and read it in.
1194 (unless (eq (nth 2 found
) 'Info-mode
)
1195 ;; Note that the current buffer must be the
1196 ;; *info* buffer on entry to
1197 ;; Info-read-subfile. Thus the hackery above.
1198 (setq guesspos
(Info-read-subfile guesspos
)))
1202 (goto-char (setq anchorpos guesspos
))
1205 ;; Else we may have a node, which we search for:
1206 (goto-char (max (point-min)
1207 (- (byte-to-position guesspos
) 1000)))
1209 ;; Now search from our advised position (or from beg of
1210 ;; buffer) to find the actual node. First, check
1211 ;; whether the node is right where we are, in case the
1212 ;; buffer begins with a node.
1213 (let ((pos (Info-find-node-in-buffer regexp strict-case
)))
1218 (when (string-match "\\([^.]+\\)\\." nodename
)
1219 (let (Info-point-loc)
1221 filename
(match-string 1 nodename
) no-going-back
))
1225 ;; No such anchor in tag table or node in tag table or file
1226 (user-error "No such node or anchor: %s" nodename
))
1229 (goto-char (point-min))
1230 (forward-line 1) ; skip header line
1231 ;; (when (> Info-breadcrumbs-depth 0) ; skip breadcrumbs line
1232 ;; (forward-line 1))
1235 (let ((new-history (list Info-current-file
1236 (substring-no-properties nodename
))))
1237 ;; Add anchors to the history too
1238 (setq Info-history-list
1240 (remove new-history Info-history-list
))))
1241 (goto-char anchorpos
))
1242 ((numberp Info-point-loc
)
1243 (forward-line (- Info-point-loc
2))
1244 (setq Info-point-loc nil
))
1245 ((stringp Info-point-loc
)
1246 (Info-find-index-name Info-point-loc
)
1247 (setq Info-point-loc nil
))))))
1248 ;; If we did not finish finding the specified node,
1249 ;; go back to the previous one or to the Top node.
1250 (unless (or Info-current-node no-going-back
)
1252 (let ((hist (car Info-history
)))
1253 (setq Info-history
(cdr Info-history
))
1254 (Info-find-node (nth 0 hist
) (nth 1 hist
) t
)
1255 (goto-char (nth 2 hist
)))
1256 (Info-find-node Info-current-file
"Top" t
)))))
1258 ;; Cache the contents of the (virtual) dir file, once we have merged
1259 ;; it for the first time, so we can save time subsequently.
1260 (defvar-local Info-dir-contents nil
)
1262 ;; Cache for the directory we decided to use for the default-directory
1263 ;; of the merged dir text.
1264 (defvar-local Info-dir-contents-directory nil
)
1266 ;; Record the file attributes of all the files from which we
1267 ;; constructed Info-dir-contents.
1268 (defvar-local Info-dir-file-attributes nil
)
1270 (defvar-local Info-dir-file-name nil
)
1272 ;; Construct the Info directory node by merging the files named `dir'
1273 ;; from various directories. Set the *info* buffer's
1274 ;; default-directory to the first directory we actually get any text
1276 (defun Info-insert-dir ()
1277 (if (and Info-dir-contents Info-dir-file-attributes
1278 ;; Verify that none of the files we used has changed
1279 ;; since we used it.
1281 (mapcar (lambda (elt)
1282 (let ((curr (file-attributes
1284 (file-truename (car elt
)))))
1286 ;; Don't compare the access time.
1287 (if curr
(setcar (nthcdr 4 curr
) 0))
1288 (setcar (nthcdr 4 (cdr elt
)) 0)
1289 (equal (cdr elt
) curr
)))
1290 Info-dir-file-attributes
))))
1292 (insert Info-dir-contents
)
1293 (goto-char (point-min)))
1294 (let ((dirs (if Info-additional-directory-list
1295 (append Info-directory-list
1296 Info-additional-directory-list
)
1297 Info-directory-list
))
1298 (dir-file-attrs nil
)
1299 ;; Bind this in case the user sets it to nil.
1300 (case-fold-search t
)
1301 ;; This is set non-nil if we find a problem in some input files.
1303 buffers buffer others nodes dirs-done
)
1305 ;; Search the directory list for the directory file.
1307 (let ((truename (file-truename (expand-file-name (car dirs
)))))
1308 (or (member truename dirs-done
)
1309 (member (directory-file-name truename
) dirs-done
)
1310 ;; Try several variants of specified name.
1311 ;; Try upcasing, appending `.info', or both.
1315 (progn (setq file
(expand-file-name "dir" truename
))
1316 (file-attributes file
))
1317 (progn (setq file
(expand-file-name "DIR" truename
))
1318 (file-attributes file
))
1319 (progn (setq file
(expand-file-name "dir.info" truename
))
1320 (file-attributes file
))
1321 (progn (setq file
(expand-file-name "DIR.INFO" truename
))
1322 (file-attributes file
))
1323 ;; Shouldn't really happen, but sometimes does,
1324 ;; eg on Debian systems with buggy packages;
1325 ;; so may as well try it.
1326 ;; http://lists.gnu.org/archive/html/emacs-devel/2012-03/msg00005.html
1327 (progn (setq file
(expand-file-name "dir.gz" truename
))
1328 (file-attributes file
)))))
1331 (cons (directory-file-name truename
)
1334 (with-current-buffer (generate-new-buffer " info dir")
1336 (message "Composing main Info directory..."))
1338 ;; Index nodes include null bytes. DIR
1339 ;; files should not have indices, but who
1341 (let ((inhibit-null-byte-detection t
))
1342 (insert-file-contents file
)
1343 (setq Info-dir-file-name file
)
1344 (push (current-buffer) buffers
)
1345 (push (cons file attrs
) dir-file-attrs
))
1346 (error (kill-buffer (current-buffer))))))))
1348 (setq Info-dir-contents-directory
1349 (file-name-as-directory (car dirs
))))
1350 (setq dirs
(cdr dirs
))))
1353 (error "Can't find the Info directory node"))
1355 ;; Distinguish the dir file that comes with Emacs from all the
1356 ;; others. Yes, that is really what this is supposed to do.
1357 ;; The definition of `Info-directory-list' puts it first on that
1358 ;; list and so last in `buffers' at this point.
1359 (setq buffer
(car (last buffers
))
1360 others
(delq buffer buffers
))
1362 ;; Insert the entire original dir file as a start; note that we've
1363 ;; already saved its default directory to use as the default
1364 ;; directory for the whole concatenation.
1365 (save-excursion (insert-buffer-substring buffer
))
1367 ;; Look at each of the other buffers one by one.
1368 (dolist (other others
)
1369 (let (this-buffer-nodes)
1370 ;; In each, find all the menus.
1371 (with-current-buffer other
1372 (goto-char (point-min))
1373 ;; Find each menu, and add an elt to NODES for it.
1374 (while (re-search-forward "^\\* Menu:" nil t
)
1375 (while (and (zerop (forward-line 1)) (eolp)))
1378 (re-search-backward "^\^_")
1379 (search-forward "Node: ")
1380 (setq nodename
(Info-following-node-name))
1381 (search-forward "\n\^_" nil
'move
)
1384 (push (list nodename other beg end
) this-buffer-nodes
)))
1385 (if (assoc-string "top" this-buffer-nodes t
)
1386 (setq nodes
(nconc this-buffer-nodes nodes
))
1388 (message "No `top' node in %s" Info-dir-file-name
)))))
1389 ;; Add to the main menu a menu item for each other node.
1390 (re-search-forward "^\\* Menu:")
1392 (let ((menu-items '("top"))
1393 (end (save-excursion (search-forward "\^_" nil t
) (point))))
1394 (dolist (node nodes
)
1395 (let ((nodename (car node
)))
1397 (or (member (downcase nodename
) menu-items
)
1398 (re-search-forward (concat "^\\* +"
1399 (regexp-quote nodename
)
1403 (insert "* " nodename
"::" "\n")
1404 (push nodename menu-items
)))))))
1405 ;; Now take each node of each of the other buffers
1406 ;; and merge it into the main buffer.
1407 (dolist (node nodes
)
1408 (let ((case-fold-search t
)
1409 (nodename (car node
)))
1410 (goto-char (point-min))
1411 ;; Find the like-named node in the main buffer.
1412 (if (re-search-forward (concat "^\^_.*\n.*Node: "
1413 (regexp-quote nodename
)
1417 (search-forward "\n\^_" nil
'move
)
1420 ;; If none exists, add one.
1421 (goto-char (point-max))
1422 (insert "\^_\nFile: dir\tNode: " nodename
"\n\n* Menu:\n\n"))
1423 ;; Merge the text from the other buffer's menu
1424 ;; into the menu in the like-named node in the main buffer.
1425 (apply #'insert-buffer-substring
(cdr node
))))
1426 (Info-dir-remove-duplicates)
1427 ;; Kill all the buffers we just made, including the special one excised.
1428 (mapc #'kill-buffer
(cons buffer buffers
))
1429 (goto-char (point-min))
1431 (message "Composing main Info directory...problems encountered, see `*Messages*'")
1432 (message "Composing main Info directory...done"))
1433 (setq Info-dir-contents
(buffer-string))
1434 (setq Info-dir-file-attributes dir-file-attrs
)))
1435 (setq default-directory Info-dir-contents-directory
))
1437 (defvar Info-streamline-headings
1438 '(("Emacs" .
"Emacs")
1439 ("Programming" .
"Programming")
1440 ("Libraries" .
"Libraries")
1441 ("World Wide Web\\|Net Utilities" .
"Net Utilities"))
1442 "List of elements (RE . NAME) to merge headings matching RE to NAME.")
1444 (defun Info-dir-remove-duplicates ()
1446 (goto-char (point-min))
1447 ;; Remove duplicate headings in the same menu.
1448 (while (search-forward "\n* Menu:" nil t
)
1449 (setq limit
(save-excursion (search-forward "\n\^_" nil t
)))
1450 ;; Look for the next heading to unify.
1451 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1452 (let ((name (match-string 1))
1453 (start (match-beginning 0))
1455 ;; Check whether this heading should be streamlined.
1457 (dolist (x Info-streamline-headings
)
1458 (when (string-match (car x
) name
)
1460 (setq re
(car x
)))))
1461 (if re
(replace-match name t t nil
1))
1462 (goto-char (if (re-search-forward "^[^* \n\t]" limit t
)
1464 (or limit
(point-max))))
1465 ;; Look for other headings of the same category and merge them.
1467 (while (re-search-forward "^\\(\\w.*\\)\n\\*" limit t
)
1468 (when (if re
(save-match-data (string-match re
(match-string 1)))
1469 (equal name
(match-string 1)))
1471 ;; Delete redundant heading.
1472 (delete-region (match-beginning 0) (point))
1473 ;; Push the entries onto `text'.
1475 (delete-and-extract-region
1477 (if (re-search-forward "^[^* \n\t]" nil t
)
1479 (or limit
(point-max))))
1482 ;; Insert the entries just found.
1483 (while (= (line-beginning-position 0) (1- (point)))
1485 (dolist (entry (nreverse entries
))
1487 (while (= (line-beginning-position 0) (1- (point)))
1488 (delete-region (1- (point)) (point))))
1490 ;; Now remove duplicate entries under the same heading.
1493 (narrow-to-region start
(point))
1494 (goto-char (point-min))
1495 (while (re-search-forward "^* \\([^:\n]+:\\(:\\|[^.\n]+\\).\\)" nil
'move
)
1496 ;; Fold case straight away; `member-ignore-case' here wasteful.
1497 (let ((x (downcase (match-string 1))))
1501 (if (re-search-forward "^[^ \t]" nil
'move
)
1502 (goto-char (match-beginning 0))
1504 (push x seen
)))))))))))
1506 ;; Note that on entry to this function the current-buffer must be the
1507 ;; *info* buffer; not the info tags buffer.
1508 (defun Info-read-subfile (nodepos)
1509 ;; NODEPOS is either a position (in the Info file as a whole,
1510 ;; not relative to a subfile) or the name of a subfile.
1513 (if (numberp nodepos
)
1514 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1515 (goto-char (point-min))
1516 (or (looking-at "\^_")
1517 (search-forward "\n\^_"))
1520 (while (not (looking-at "\^_"))
1523 thisfilepos thisfilename
)
1524 (search-forward ": ")
1525 (setq thisfilename
(buffer-substring beg
(- (point) 2)))
1526 (setq thisfilepos
(+ (point-min) (read (current-buffer))))
1527 ;; read in version 19 stops at the end of number.
1528 ;; Advance to the next line.
1530 (if (> thisfilepos nodepos
)
1532 (setq lastfilename thisfilename
)
1533 (setq lastfilepos thisfilepos
))
1534 (forward-line 1)))))
1535 (setq lastfilename nodepos
)
1536 (setq lastfilepos
0))
1537 ;; Assume previous buffer is in Info-mode.
1538 ;; (set-buffer (get-buffer "*info*"))
1539 (or (equal Info-current-subfile lastfilename
)
1540 (let ((inhibit-read-only t
))
1541 (setq buffer-file-name nil
)
1544 (info-insert-file-contents lastfilename
)
1545 (set-buffer-modified-p nil
)
1546 (setq Info-current-subfile lastfilename
)))
1547 ;; Widen in case we are in the same subfile as before.
1549 (goto-char (point-min))
1550 ;; Skip the summary segment for `Info-search'.
1551 (if (looking-at "\^_")
1553 (search-forward "\n\^_"))
1554 ;; Don't add the length of the skipped summary segment to
1555 ;; the value returned to `Info-find-node-2'. (Bug#14125)
1556 (if (numberp nodepos
)
1557 (+ (- nodepos lastfilepos
) (point-min)))))
1559 (defun Info-unescape-quotes (value)
1560 "Unescape double quotes and backslashes in VALUE."
1563 (while (string-match "[^\\\"]*\\(\\\\\\)[\\\\\"]" unquote start
)
1564 (setq unquote
(replace-match "" t t unquote
1))
1565 (setq start
(- (match-end 0) 1)))
1568 ;; As of Texinfo 4.6, makeinfo writes constructs like
1569 ;; \0\h[image param=value ...\h\0]
1570 ;; into the Info file for handling images.
1571 (defun Info-split-parameter-string (parameter-string)
1572 "Return alist of (\"KEY\" . \"VALUE\") from PARAMETER-STRING.
1573 PARAMETER-STRING is a whitespace separated list of KEY=VALUE pairs.
1574 If VALUE contains whitespace or double quotes, it must be quoted
1575 in double quotes and any double quotes or backslashes must be
1576 escaped (\\\",\\\\)."
1579 (while (string-match
1580 "\\s *\\([^=]+\\)=\\(?:\\([^\\s \"]+\\)\\|\\(?:\"\\(\\(?:[^\\\"]\\|\\\\[\\\\\"]\\)*\\)\"\\)\\)"
1581 parameter-string start
)
1582 (setq start
(match-end 0))
1583 (push (cons (match-string 1 parameter-string
)
1584 (or (match-string 2 parameter-string
)
1585 (Info-unescape-quotes
1586 (match-string 3 parameter-string
))))
1590 (defun Info-display-images-node ()
1591 "Display images in current node."
1593 (let ((inhibit-read-only t
)
1594 (case-fold-search t
))
1595 (goto-char (point-min))
1596 (while (re-search-forward
1597 "\\(\0\b[[]image\\(\\(?:[^\b]\\|[^\0]+\b\\)*\\)\0\b[]]\\)"
1599 (let* ((start (match-beginning 1))
1600 (parameter-alist (Info-split-parameter-string (match-string 2)))
1601 (src (cdr (assoc-string "src" parameter-alist
))))
1602 (if (display-images-p)
1603 (let* ((image-file (if src
(if (file-name-absolute-p src
) src
1604 (concat default-directory src
))
1606 (image (if (file-exists-p image-file
)
1607 (create-image image-file
)
1608 (or (cdr (assoc-string "text" parameter-alist
))
1609 (and src
(concat "[broken image:" src
"]"))
1610 "[broken image]"))))
1611 (if (not (get-text-property start
'display
))
1612 (add-text-properties
1614 `(display ,image rear-nonsticky
(display)
1615 help-echo
,(cdr (assoc-string "alt" parameter-alist
))))))
1616 ;; text-only display, show alternative text if provided, or
1617 ;; otherwise a clue that there's meant to be a picture
1618 (delete-region start
(point))
1619 (insert (or (cdr (assoc-string "text" parameter-alist
))
1620 (cdr (assoc-string "alt" parameter-alist
))
1621 (and src
(concat "[image:" src
"]"))
1623 (set-buffer-modified-p nil
)))
1625 ;; Texinfo 4.7 adds cookies of the form ^@^H[NAME CONTENTS ^@^H].
1626 ;; Hide any construct of the general form ^@[^@-^_][ ... ^@[^@-^_]],
1627 ;; including one optional trailing newline.
1628 (defun Info-hide-cookies-node ()
1629 "Hide unrecognized cookies in current node."
1631 (let ((inhibit-read-only t
)
1632 (case-fold-search t
))
1633 (goto-char (point-min))
1634 (while (re-search-forward
1635 "\\(\0[\0-\37][[][^\0]*\0[\0-\37][]]\n?\\)"
1637 (let* ((start (match-beginning 1)))
1638 (if (and (not (get-text-property start
'invisible
))
1639 (not (get-text-property start
'display
)))
1640 (put-text-property start
(point) 'invisible t
)))))
1641 (set-buffer-modified-p nil
)))
1643 (defun Info-select-node ()
1644 "Select the Info node that point is in."
1645 ;; Bind this in case the user sets it to nil.
1646 (let ((case-fold-search t
))
1648 ;; Find beginning of node.
1649 (if (search-backward "\n\^_" nil
'move
)
1651 (if (looking-at "\^_")
1653 (signal 'search-failed
(list "\n\^_"))))
1654 ;; Get nodename spelled as it is in the node.
1655 (re-search-forward "Node:[ \t]*")
1656 (setq Info-current-node
1657 (buffer-substring-no-properties (point)
1659 (skip-chars-forward "^,\t\n")
1661 (Info-set-mode-line)
1662 ;; Find the end of it, and narrow.
1664 (let (active-expression)
1665 ;; Narrow to the node contents
1666 (narrow-to-region (point)
1667 (if (re-search-forward "\n[\^_\f]" nil t
)
1670 (if (looking-at "[\n\^_\f]*execute: ")
1672 (goto-char (match-end 0))
1673 (setq active-expression
1674 (read (current-buffer))))))
1676 (if Info-enable-active-nodes
(eval active-expression
))
1677 ;; Add a new unique history item to full history list
1678 (let ((new-history (list Info-current-file Info-current-node
)))
1679 (setq Info-history-list
1680 (cons new-history
(remove new-history Info-history-list
)))
1681 (setq Info-history-forward nil
))
1682 (if (not (eq Info-fontify-maximum-menu-size nil
))
1683 (Info-fontify-node))
1684 (Info-display-images-node)
1685 (Info-hide-cookies-node)
1686 (run-hooks 'Info-selection-hook
)))))
1688 (defvar Info-mode-line-node-keymap
1689 (let ((map (make-sparse-keymap)))
1690 (define-key map
[mode-line mouse-1
] 'Info-mouse-scroll-up
)
1691 (define-key map
[mode-line mouse-3
] 'Info-mouse-scroll-down
)
1693 "Keymap to put on the Info node name in the mode line.")
1695 (defun Info-set-mode-line ()
1696 (setq mode-line-buffer-identification
1697 (nconc (propertized-buffer-identification "%b")
1701 (if (stringp Info-current-file
)
1702 (replace-regexp-in-string
1704 (file-name-sans-extension
1705 (file-name-nondirectory Info-current-file
)))
1706 (format "*%S*" Info-current-file
))
1708 (if Info-current-node
1709 (propertize (replace-regexp-in-string
1710 "%" "%%" Info-current-node
)
1711 'face
'mode-line-buffer-id
1713 "mouse-1: scroll forward, mouse-3: scroll back"
1714 'mouse-face
'mode-line-highlight
1715 'local-map Info-mode-line-node-keymap
)
1718 ;; Go to an Info node specified with a filename-and-nodename string
1719 ;; of the sort that is found in pointers in nodes.
1721 ;; Don't autoload this function: the correct entry point for other packages
1722 ;; to use is `info'. --Stef
1724 (defun Info-goto-node (nodename &optional fork strict-case
)
1725 "Go to Info node named NODENAME. Give just NODENAME or (FILENAME)NODENAME.
1726 If NODENAME is of the form (FILENAME)NODENAME, the node is in the Info file
1727 FILENAME; otherwise, NODENAME should be in the current Info file (or one of
1729 Completion is available for node names in the current Info file as well as
1730 in the Info file FILENAME after the closing parenthesis in (FILENAME).
1731 Empty NODENAME in (FILENAME) defaults to the Top node.
1732 If FORK is non-nil (interactively with a prefix arg), show the node in
1734 If FORK is a string, it is the name to use for the new buffer.
1736 This function first looks for a case-sensitive match for the node part
1737 of NODENAME; if none is found it then tries a case-insensitive match
1738 \(unless STRICT-CASE is non-nil)."
1739 (interactive (list (Info-read-node-name "Go to node: ") current-prefix-arg
))
1743 (clone-buffer (concat "*info-" (if (stringp fork
) fork nodename
) "*") t
)))
1745 (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)"
1747 (setq filename
(if (= (match-beginning 1) (match-end 1))
1749 (match-string 2 nodename
))
1750 nodename
(match-string 3 nodename
))
1751 (let ((trim (string-match "\\s +\\'" filename
)))
1752 (if trim
(setq filename
(substring filename
0 trim
))))
1753 (let ((trim (string-match "\\s +\\'" nodename
)))
1754 (if trim
(setq nodename
(substring nodename
0 trim
))))
1755 (if transient-mark-mode
(deactivate-mark))
1756 (Info-find-node (if (equal filename
"") nil filename
)
1757 (if (equal nodename
"") "Top" nodename
) nil strict-case
)))
1759 (defvar Info-read-node-completion-table
)
1761 (defun Info-read-node-name-2 (dirs suffixes string pred action
)
1762 "Internal function used to complete Info node names.
1763 Return a completion table for Info files---the FILENAME part of a
1764 node named \"(FILENAME)NODENAME\". DIRS is a list of Info
1765 directories to search if FILENAME is not absolute; SUFFIXES is a
1766 list of valid filename suffixes for Info files. See
1767 `try-completion' for a description of the remaining arguments."
1768 (setq suffixes
(remove "" suffixes
))
1769 (when (file-name-absolute-p string
)
1770 (setq dirs
(list (file-name-directory string
))))
1772 (names-sans-suffix nil
)
1773 (suffix (concat (regexp-opt suffixes t
) "\\'"))
1774 (string-dir (file-name-directory string
)))
1777 (setq dir default-directory
))
1778 (if string-dir
(setq dir
(expand-file-name string-dir dir
)))
1779 (when (file-directory-p dir
)
1780 (dolist (file (file-name-all-completions
1781 (file-name-nondirectory string
) dir
))
1782 ;; If the file name has no suffix or a standard suffix,
1784 (and (or (null (file-name-extension file
))
1785 (string-match suffix file
))
1786 ;; But exclude subfiles of split Info files.
1787 (not (string-match "-[0-9]+\\'" file
))
1788 ;; And exclude backup files.
1789 (not (string-match "~\\'" file
))
1790 (push (if string-dir
(concat string-dir file
) file
) names
))
1791 ;; If the file name ends in a standard suffix,
1792 ;; add the unsuffixed name as a completion option.
1793 (when (string-match suffix file
)
1794 (setq file
(substring file
0 (match-beginning 0)))
1795 (push (if string-dir
(concat string-dir file
) file
)
1796 names-sans-suffix
)))))
1797 ;; If there is just one file, don't duplicate it with suffixes,
1798 ;; so `Info-read-node-name-1' will be able to complete a single
1799 ;; candidate and to add the terminating ")".
1800 (if (and (= (length names
) 1) (= (length names-sans-suffix
) 1))
1801 (setq names names-sans-suffix
)
1802 (setq names
(append names-sans-suffix names
)))
1803 (complete-with-action action names string pred
)))
1805 (defun Info-read-node-name-1 (string predicate code
)
1806 "Internal function used by `Info-read-node-name'.
1807 See `completing-read' for a description of arguments and usage."
1809 ;; First complete embedded file names.
1810 ((string-match "\\`([^)]*\\'" string
)
1811 (completion-table-with-context
1813 (apply-partially #'completion-table-with-terminator
")"
1814 (apply-partially #'Info-read-node-name-2
1816 (mapcar #'car Info-suffix-list
)))
1817 (substring string
1)
1820 ;; If a file name was given, complete nodes in the file.
1821 ((string-match "\\`(\\([^)]+\\))" string
)
1822 (let ((file0 (match-string 0 string
))
1823 (file1 (match-string 1 string
))
1824 (nodename (substring string
(match-end 0))))
1825 (if (and (equal nodename
"") (eq code
'lambda
))
1826 ;; Empty node name is permitted that means "Top".
1828 (completion-table-with-context
1830 (lambda (string pred action
)
1831 (complete-with-action
1833 (Info-build-node-completions (Info-find-file file1
))
1835 nodename predicate code
))))
1836 ;; Otherwise use Info-read-node-completion-table.
1837 (t (complete-with-action
1838 code Info-read-node-completion-table string predicate
))))
1840 ;; Arrange to highlight the proper letters in the completion list buffer.
1841 (defun Info-read-node-name (prompt)
1842 "Read an Info node name with completion, prompting with PROMPT.
1843 A node name can have the form \"NODENAME\", referring to a node
1844 in the current Info file, or \"(FILENAME)NODENAME\", referring to
1845 a node in FILENAME. \"(FILENAME)\" is a short format to go to
1846 the Top node in FILENAME."
1847 (let* ((completion-ignore-case t
)
1848 (Info-read-node-completion-table (Info-build-node-completions))
1849 (nodename (completing-read prompt
'Info-read-node-name-1 nil t
)))
1850 (if (equal nodename
"")
1851 (Info-read-node-name prompt
)
1854 (defun Info-build-node-completions (&optional filename
)
1856 (or (cdr (assoc filename Info-file-completions
))
1859 (Info-goto-node (format "(%s)Top" filename
))
1860 (Info-build-node-completions-1)
1861 (push (cons filename Info-current-file-completions
) Info-file-completions
)
1862 Info-current-file-completions
))
1863 (or Info-current-file-completions
1864 (Info-build-node-completions-1))))
1866 (defun Info-build-node-completions-1 ()
1868 ;; Bind this in case the user sets it to nil.
1869 (case-fold-search t
)
1870 (node-regexp "Node: *\\([^,\n]*\\) *[,\n\t]"))
1873 (or Info-tag-table-marker
1874 (error "No Info tags found"))
1875 (if (marker-buffer Info-tag-table-marker
)
1876 (let ((marker Info-tag-table-marker
))
1877 (set-buffer (marker-buffer marker
))
1880 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t
)
1882 (cons (list (match-string-no-properties 2))
1885 (goto-char (point-min))
1886 ;; If the buffer begins with a node header, process that first.
1887 (if (Info-node-at-bob-matching node-regexp
)
1888 (setq compl
(list (match-string-no-properties 1))))
1889 ;; Now for the rest of the nodes.
1890 (while (search-forward "\n\^_" nil t
)
1892 (let ((beg (point)))
1894 (if (re-search-backward node-regexp beg t
)
1896 (cons (list (match-string-no-properties 1))
1898 (setq compl
(cons '("*") (nreverse compl
)))
1899 (setq Info-current-file-completions compl
)
1903 (defun Info-restore-point (hl)
1904 "If this node has been visited, restore the point value when we left."
1906 (if (and (equal (nth 0 (car hl
)) Info-current-file
)
1907 ;; Use string-equal, not equal, to ignore text props.
1908 (string-equal (nth 1 (car hl
)) Info-current-node
))
1910 (goto-char (nth 2 (car hl
)))
1911 (setq hl nil
)) ;terminate the while at next iter
1912 (setq hl
(cdr hl
)))))
1914 (defvar Info-search-history nil
1915 "The history list for `Info-search'.")
1917 (defvar Info-search-case-fold nil
1918 "The value of `case-fold-search' from previous `Info-search' command.")
1920 (defun Info--search-loop (regexp bound backward
)
1922 ;; Hide Info file header for backward search.
1923 (narrow-to-region (save-excursion
1924 (goto-char (point-min))
1925 (search-forward "\n\^_")
1931 (while (not (or give-up
1933 (funcall isearch-filter-predicate
1935 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1937 (if backward
#'re-search-backward
#'re-search-forward
)
1939 (setq found
(point) beg-found
(if backward
(match-end 0)
1940 (match-beginning 0)))
1941 (setq give-up t found nil
))))
1944 (defun Info-search (regexp &optional bound _noerror _count direction
)
1945 "Search for REGEXP, starting from point, and select node it's found in.
1946 If DIRECTION is `backward', search in the reverse direction."
1947 (interactive (list (read-string
1948 (if Info-search-history
1949 (format "Regexp search%s (default %s): "
1950 (if case-fold-search
"" " case-sensitively")
1951 (car Info-search-history
))
1952 (format "Regexp search%s: "
1953 (if case-fold-search
"" " case-sensitively")))
1954 nil
'Info-search-history
)))
1956 (when (equal regexp
"")
1957 (setq regexp
(car Info-search-history
)))
1959 (setq Info-search-case-fold case-fold-search
)
1960 (let* ((backward (eq direction
'backward
))
1961 (onode Info-current-node
)
1962 (ofile Info-current-file
)
1964 (opoint-min (point-min))
1965 (opoint-max (point-max))
1966 (ostart (window-start))
1967 (osubfile Info-current-subfile
)
1972 (Info--search-loop regexp bound backward
)))))
1974 (unless (or (not isearch-mode
) (not Info-isearch-search
)
1975 Info-isearch-initial-node
1977 (and found
(> found opoint-min
) (< found opoint-max
)))
1978 (signal 'search-failed
(list regexp
"end of node")))
1980 ;; If no subfiles, give error now.
1981 (unless (or found Info-current-subfile
)
1983 (signal 'search-failed
(list regexp
"end of manual"))
1984 (let ((search-spaces-regexp Info-search-whitespace-regexp
))
1986 (re-search-backward regexp
)
1987 (re-search-forward regexp
)))))
1989 (if (and bound
(not found
))
1990 (signal 'search-failed
(list regexp
)))
1992 (unless (or found bound
)
1994 ;; Try other subfiles.
1996 (with-current-buffer (marker-buffer Info-tag-table-marker
)
1997 (goto-char (point-min))
1998 (search-forward "\n\^_\nIndirect:")
2000 (narrow-to-region (point)
2001 (progn (search-forward "\n\^_")
2003 (goto-char (point-min))
2004 ;; Find the subfile we just searched.
2005 (search-forward (concat "\n" osubfile
": "))
2007 (forward-line (if backward
0 1))
2008 (if backward
(forward-char -
1))
2009 ;; Make a list of all following subfiles.
2010 ;; Each elt has the form (VIRT-POSITION . SUBFILENAME).
2011 (while (not (if backward
(bobp) (eobp)))
2013 (re-search-backward "\\(^.*\\): [0-9]+$")
2014 (re-search-forward "\\(^.*\\): [0-9]+$"))
2015 (goto-char (+ (match-end 1) 2))
2016 (setq list
(cons (cons (+ (point-min)
2017 (read (current-buffer)))
2018 (match-string-no-properties 1))
2020 (goto-char (if backward
2021 (1- (match-beginning 0))
2022 (1+ (match-end 0)))))
2023 ;; Put in forward order
2024 (setq list
(nreverse list
))))
2026 (message "Searching subfile %s..." (cdr (car list
)))
2027 (Info-read-subfile (car (car list
)))
2028 (when backward
(goto-char (point-max)))
2029 (setq list
(cdr list
))
2030 (setq found
(Info--search-loop regexp nil backward
))
2035 (signal 'search-failed
(if isearch-mode
2036 (list regexp
"end of manual")
2039 (progn (Info-read-subfile osubfile
)
2042 (set-window-start (selected-window) ostart
)))))
2044 (if (and (string= osubfile Info-current-subfile
)
2045 (> found opoint-min
)
2046 (< found opoint-max
))
2047 ;; Search landed in the same node
2051 (save-match-data (Info-select-node)))
2053 ;; Use string-equal, not equal, to ignore text props.
2054 (or (and (string-equal onode Info-current-node
)
2055 (equal ofile Info-current-file
))
2056 (and isearch-mode isearch-wrapped
2057 (eq opoint
(if isearch-forward opoint-min opoint-max
)))
2058 (setq Info-history
(cons (list ofile onode opoint
)
2061 (defun Info-search-case-sensitively ()
2062 "Search for a regexp case-sensitively."
2064 (let ((case-fold-search nil
))
2065 (call-interactively 'Info-search
)))
2067 (defun Info-search-next ()
2068 "Search for next regexp from a previous `Info-search' command."
2070 (let ((case-fold-search Info-search-case-fold
))
2071 (if Info-search-history
2072 (Info-search (car Info-search-history
))
2073 (call-interactively 'Info-search
))))
2075 (defun Info-search-backward (regexp &optional bound noerror count
)
2076 "Search for REGEXP in the reverse direction."
2077 (interactive (list (read-string
2078 (if Info-search-history
2079 (format "Regexp search%s backward (default %s): "
2080 (if case-fold-search
"" " case-sensitively")
2081 (car Info-search-history
))
2082 (format "Regexp search%s backward: "
2083 (if case-fold-search
"" " case-sensitively")))
2084 nil
'Info-search-history
)))
2085 (Info-search regexp bound noerror count
'backward
))
2087 (defun Info-isearch-search ()
2088 (if Info-isearch-search
2089 (lambda (string &optional bound noerror count
)
2090 (let ((Info-search-whitespace-regexp
2091 (if (if isearch-regexp
2092 isearch-regexp-lax-whitespace
2093 isearch-lax-whitespace
)
2094 search-whitespace-regexp
)))
2098 ;; Lax version of word search
2099 (let ((lax (not (or isearch-nonincremental
2101 (length (isearch--state-string
2102 (car isearch-cmds
))))))))
2103 (if (functionp isearch-word
)
2104 (funcall isearch-word string lax
)
2105 (word-search-regexp string lax
))))
2106 (isearch-regexp string
)
2107 (t (regexp-quote string
)))
2109 (unless isearch-forward
'backward
)))
2111 (isearch-search-fun-default)))
2113 (defun Info-isearch-wrap ()
2114 (if Info-isearch-search
2115 (if Info-isearch-initial-node
2117 (if isearch-forward
(Info-top-node) (Info-final-node))
2118 (goto-char (if isearch-forward
(point-min) (point-max))))
2119 (setq Info-isearch-initial-node Info-current-node
)
2120 (setq isearch-wrapped nil
))
2121 (goto-char (if isearch-forward
(point-min) (point-max)))))
2123 (defun Info-isearch-push-state ()
2125 (Info-isearch-pop-state cmd
',Info-current-file
',Info-current-node
)))
2127 (defun Info-isearch-pop-state (_cmd file node
)
2128 (or (and (equal Info-current-file file
)
2129 (equal Info-current-node node
))
2130 (progn (Info-find-node file node
) (sit-for 0))))
2132 (defun Info-isearch-start ()
2133 (setq Info-isearch-initial-node
2134 ;; Don't stop at initial node for nonincremental search.
2135 ;; Otherwise this variable is set after first search failure.
2136 (and isearch-nonincremental Info-current-node
))
2137 (setq Info-isearch-initial-history Info-history
2138 Info-isearch-initial-history-list Info-history-list
)
2139 (add-hook 'isearch-mode-end-hook
'Info-isearch-end nil t
))
2141 (defun Info-isearch-end ()
2142 ;; Remove intermediate nodes (visited while searching)
2143 ;; from the history. Add only the last node (where Isearch ended).
2144 (if (> (length Info-history
)
2145 (length Info-isearch-initial-history
))
2147 (nthcdr (- (length Info-history
)
2148 (length Info-isearch-initial-history
)
2151 (if (> (length Info-history-list
)
2152 (length Info-isearch-initial-history-list
))
2153 (setq Info-history-list
2154 (cons (car Info-history-list
)
2155 Info-isearch-initial-history-list
)))
2156 (remove-hook 'isearch-mode-end-hook
'Info-isearch-end t
))
2158 (defun Info-isearch-filter (beg-found found
)
2159 "Test whether the current search hit is a visible useful text.
2160 Return non-nil if the text from BEG-FOUND to FOUND is visible
2161 and is not in the header line or a tag table."
2163 (let ((backward (< found beg-found
)))
2166 (and (not search-invisible
)
2168 (or (text-property-not-all found beg-found
'invisible nil
)
2169 (text-property-not-all found beg-found
'display nil
))
2170 (or (text-property-not-all beg-found found
'invisible nil
)
2171 (text-property-not-all beg-found found
'display nil
))))
2172 ;; Skip node header line
2173 (and (save-excursion (forward-line -
1)
2175 (forward-line (if backward -
1 1)))
2176 ;; Skip Tag Table node
2178 (and (search-backward "\^_" nil t
)
2180 "\^_\n\\(Tag Table\\|Local Variables\\)"))))))))
2183 (defun Info-extract-pointer (name &optional errorname
)
2184 "Extract the value of the node-pointer named NAME.
2185 If there is none, use ERRORNAME in the error message;
2186 if ERRORNAME is nil, just return nil."
2187 ;; Bind this in case the user sets it to nil.
2188 (let ((case-fold-search t
))
2190 (goto-char (point-min))
2191 (let ((bound (point)))
2193 (cond ((re-search-backward
2194 (concat name
":" (Info-following-node-name-re)) bound t
)
2195 (match-string-no-properties 1))
2196 ((not (eq errorname t
))
2197 (user-error "Node has no %s"
2198 (capitalize (or errorname name
)))))))))
2200 (defun Info-following-node-name-re (&optional allowedchars
)
2201 "Return a regexp matching a node name.
2202 ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
2203 saying which chars may appear in the node name.
2204 Submatch 1 is the complete node name.
2205 Submatch 2 if non-nil is the parenthesized file name part of the node name.
2206 Submatch 3 is the local part of the node name.
2207 End of submatch 0, 1, and 3 are the same, so you can safely concat."
2208 (concat "[ \t\n]*" ;Skip leading space.
2209 "\\(\\(([^)]+)\\)?" ;Node name can start with a file name.
2210 "\\([" (or allowedchars
"^,\t\n") "]*" ;Any number of allowed chars.
2211 "[" (or allowedchars
"^,\t\n") " ]" ;The last char can't be a space.
2212 "\\|\\)\\)")) ;Allow empty node names.
2214 ;; For compatibility; other files have used this name.
2215 (defun Info-following-node-name ()
2216 (and (looking-at (Info-following-node-name-re))
2217 (match-string-no-properties 1)))
2220 "Go to the next node of this node."
2222 ;; In case another window is currently selected
2223 (save-window-excursion
2224 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
2225 (Info-goto-node (Info-extract-pointer "next"))))
2228 "Go to the previous node of this node."
2230 ;; In case another window is currently selected
2231 (save-window-excursion
2232 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
2233 (Info-goto-node (Info-extract-pointer "prev[ious]*" "previous"))))
2235 (defun Info-up (&optional same-file
)
2236 "Go to the superior node of this node.
2237 If SAME-FILE is non-nil, do not move to a different Info file."
2239 ;; In case another window is currently selected
2240 (save-window-excursion
2241 (or (derived-mode-p 'Info-mode
) (switch-to-buffer "*info*"))
2242 (let ((old-node Info-current-node
)
2243 (old-file Info-current-file
)
2244 (node (Info-extract-pointer "up")) p
)
2246 (string-match "^(" node
)
2247 (error "Up node is in another Info file"))
2248 (Info-goto-node node
)
2250 (goto-char (point-min))
2251 (if (and (stringp old-file
)
2252 (search-forward "\n* Menu:" nil t
)
2254 (if (string-equal old-node
"Top")
2255 (concat "\n\\*[^:]+: +(" (file-name-nondirectory old-file
) ")")
2256 (concat "\n\\* +\\(" (regexp-quote old-node
)
2257 ":\\|[^:]+: +" (regexp-quote old-node
) "\\)"))
2259 (progn (beginning-of-line) (if (looking-at "^\\* ") (forward-char 2)))
2261 (Info-restore-point Info-history
)))))
2263 (defun Info-history-back ()
2264 "Go back in the history to the last node visited."
2267 (user-error "This is the first Info node you looked at"))
2268 (let ((history-forward
2269 (cons (list Info-current-file Info-current-node
(point))
2270 Info-history-forward
))
2271 filename nodename opoint
)
2272 (setq filename
(car (car Info-history
)))
2273 (setq nodename
(car (cdr (car Info-history
))))
2274 (setq opoint
(car (cdr (cdr (car Info-history
)))))
2275 (setq Info-history
(cdr Info-history
))
2276 (Info-find-node filename nodename
)
2277 (setq Info-history
(cdr Info-history
))
2278 (setq Info-history-forward history-forward
)
2279 (goto-char opoint
)))
2281 (defalias 'Info-last
'Info-history-back
)
2283 (defun Info-history-forward ()
2284 "Go forward in the history of visited nodes."
2286 (or Info-history-forward
2287 (user-error "This is the last Info node you looked at"))
2288 (let ((history-forward (cdr Info-history-forward
))
2289 filename nodename opoint
)
2290 (setq filename
(car (car Info-history-forward
)))
2291 (setq nodename
(car (cdr (car Info-history-forward
))))
2292 (setq opoint
(car (cdr (cdr (car Info-history-forward
)))))
2293 (Info-find-node filename nodename
)
2294 (setq Info-history-forward history-forward
)
2295 (goto-char opoint
)))
2297 (add-to-list 'Info-virtual-files
2299 (toc-nodes . Info-directory-toc-nodes
)
2300 (find-file . Info-directory-find-file
)
2301 (find-node . Info-directory-find-node
)
2304 (defun Info-directory-toc-nodes (filename)
2305 "Directory-specific implementation of `Info-toc-nodes'."
2307 ("Top" nil nil nil
)))
2309 (defun Info-directory-find-file (filename &optional _noerror
)
2310 "Directory-specific implementation of `Info-find-file'."
2313 (defun Info-directory-find-node (_filename _nodename
&optional _no-going-back
)
2314 "Directory-specific implementation of `Info-find-node-2'."
2318 (defun Info-directory ()
2319 "Go to the Info directory node."
2321 (Info-find-node "dir" "top"))
2323 (add-to-list 'Info-virtual-files
2324 '("\\`\\*History\\*\\'"
2325 (toc-nodes . Info-history-toc-nodes
)
2326 (find-file . Info-history-find-file
)
2327 (find-node . Info-history-find-node
)
2330 (defun Info-history-toc-nodes (filename)
2331 "History-specific implementation of `Info-toc-nodes'."
2333 ("Top" nil nil nil
)))
2335 (defun Info-history-find-file (filename &optional _noerror
)
2336 "History-specific implementation of `Info-find-file'."
2339 (defun Info-history-find-node (filename nodename
&optional _no-going-back
)
2340 "History-specific implementation of `Info-find-node-2'."
2341 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
2342 (or filename Info-current-file
) nodename
))
2343 (insert "Recently Visited Nodes\n")
2344 (insert "**********************\n\n")
2345 (insert "* Menu:\n\n")
2346 (let ((hl (remove '("*History*" "Top") Info-history-list
)))
2348 (let ((file (nth 0 (car hl
)))
2349 (node (nth 1 (car hl
))))
2351 (insert "* " node
": ("
2352 (propertize (or (file-name-directory file
) "") 'invisible t
)
2353 (file-name-nondirectory file
)
2355 (setq hl
(cdr hl
)))))
2357 (defun Info-history ()
2358 "Go to a node with a menu of visited nodes."
2360 (Info-find-node "*History*" "Top")
2361 (Info-next-reference)
2362 (Info-next-reference))
2364 (add-to-list 'Info-virtual-nodes
2366 (find-node . Info-toc-find-node
)
2369 (defun Info-toc-find-node (filename nodename
&optional _no-going-back
)
2370 "Toc-specific implementation of `Info-find-node-2'."
2371 (let* ((curr-file (substring-no-properties (or filename Info-current-file
)))
2372 (curr-node (substring-no-properties (or nodename Info-current-node
)))
2373 (node-list (Info-toc-nodes curr-file
)))
2374 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
2375 curr-file curr-node
))
2376 (insert "Table of Contents\n")
2377 (insert "*****************\n\n")
2378 (insert "*Note Top::\n")
2380 (nth 3 (assoc "Top" node-list
)) ; get Top nodes
2381 node-list
0 curr-file
)
2383 (let ((Info-hide-note-references 'hide
)
2384 (Info-fontify-visited-nodes nil
))
2385 (setq Info-current-file filename Info-current-node
"*TOC*")
2386 (goto-char (point-min))
2387 (narrow-to-region (or (re-search-forward "\n[\^_\f]\n" nil t
)
2394 "Go to a node with table of contents of the current Info file.
2395 Table of contents is created from the tree structure of menus."
2397 (Info-find-node Info-current-file
"*TOC*")
2398 (let ((prev-node (nth 1 (car Info-history
))) p
)
2399 (goto-char (point-min))
2400 (if (setq p
(search-forward (concat "*Note " prev-node
":") nil t
))
2401 (setq p
(- p
(length prev-node
) 2)))
2402 (goto-char (or p
(point-min)))))
2404 (defun Info-toc-insert (nodes node-list level curr-file
)
2405 "Insert table of contents with references to nodes."
2406 (let ((section "Top"))
2408 (let ((node (assoc (car nodes
) node-list
)))
2409 (unless (member (nth 2 node
) (list nil section
))
2410 (insert (setq section
(nth 2 node
)) "\n"))
2411 (insert (make-string level ?
\t))
2412 (insert "*Note " (car nodes
) ":: \n")
2413 (Info-toc-insert (nth 3 node
) node-list
(1+ level
) curr-file
)
2414 (setq nodes
(cdr nodes
))))))
2416 (defun Info-toc-build (file)
2417 "Build table of contents from menus of Info FILE and its subfiles."
2419 (let* ((file (and (stringp file
) (Info-find-file file
)))
2420 (default-directory (or (and (stringp file
)
2421 (file-name-directory file
))
2423 (main-file (and (stringp file
) file
))
2424 (sections '(("Top" "Top")))
2426 (while (or main-file subfiles
)
2427 ;; (or main-file (message "Searching subfile %s..." (car subfiles)))
2429 (info-insert-file-contents (or main-file
(car subfiles
)))
2430 (goto-char (point-min))
2431 (while (and (search-forward "\n\^_\nFile:" nil
'move
)
2432 (search-forward "Node: " nil
'move
))
2433 (let* ((nodename (substring-no-properties (Info-following-node-name)))
2434 (bound (- (or (save-excursion (search-forward "\n\^_" nil t
))
2436 (upnode (and (re-search-forward
2437 (concat "Up:" (Info-following-node-name-re))
2439 (match-string-no-properties 1)))
2442 (when (and upnode
(string-match "(" upnode
)) (setq upnode nil
))
2443 (when (and (not (Info-index-node nodename file
))
2444 (re-search-forward "^\\* Menu:" bound t
))
2447 (setq bound
(or (and (equal nodename
"Top")
2450 "^[ \t-]*The Detailed Node Listing" nil t
)))
2452 (while (< (point) bound
)
2455 ((looking-at "^\\* +[^:]+:")
2458 (let ((menu-node-name (substring-no-properties
2459 (Info-extract-menu-node-name))))
2460 (setq menu-items
(cons menu-node-name menu-items
))
2461 (if (equal nodename
"Top")
2463 (cons (list menu-node-name section
) sections
)))))
2464 ;; Other non-empty strings in the Top node are section names
2465 ((and (equal nodename
"Top")
2466 (looking-at "^\\([^ \t\n*=.-][^:\n]*\\)"))
2467 (setq section
(match-string-no-properties 1))))
2469 (beginning-of-line)))
2470 (setq nodes
(cons (list nodename upnode
2471 (cadr (assoc nodename sections
))
2472 (nreverse menu-items
))
2477 (goto-char (point-min))
2478 (if (search-forward "\n\^_\nIndirect:" nil t
)
2479 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
2480 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
2481 (setq subfiles
(cons (match-string-no-properties 1)
2483 (setq subfiles
(nreverse subfiles
)
2485 (setq subfiles
(cdr subfiles
))))
2489 (defun Info-toc-nodes (filename)
2490 "Return a node list of Info FILENAME with parent-children information.
2491 This information is cached in the variable `Info-toc-nodes' with the help
2492 of the function `Info-toc-build'."
2495 (Info-virtual-fun 'toc-nodes
(or filename Info-current-file
) nil
)
2498 (or filename
(setq filename Info-current-file
))
2499 (or (assoc filename Info-toc-nodes
)
2500 ;; Skip virtual Info files
2501 (and (or (not (stringp filename
))
2502 (Info-virtual-file-p filename
))
2503 (push (cons filename nil
) Info-toc-nodes
))
2504 ;; Scan the entire manual and cache the result in Info-toc-nodes
2505 (let ((nodes (Info-toc-build filename
)))
2506 (push (cons filename nodes
) Info-toc-nodes
)
2508 ;; If there is an error, still add nil to the cache
2509 (push (cons filename nil
) Info-toc-nodes
))
2510 (cdr (assoc filename Info-toc-nodes
)))))
2513 (defun Info-follow-reference (footnotename &optional fork
)
2514 "Follow cross reference named FOOTNOTENAME to the node it refers to.
2515 FOOTNOTENAME may be an abbreviation of the reference name.
2516 If FORK is non-nil (interactively with a prefix arg), show the node in
2517 a new Info buffer. If FORK is a string, it is the name to use for the
2520 (let ((completion-ignore-case t
)
2521 (case-fold-search t
)
2522 completions default alt-default
(start-point (point)) str i bol eol
)
2524 ;; Store end and beginning of line.
2525 (setq eol
(line-end-position)
2526 bol
(line-beginning-position))
2527 (goto-char (point-min))
2528 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t
)
2529 (setq str
(match-string-no-properties 1))
2530 ;; See if this one should be the default.
2532 (<= (match-beginning 0) start-point
)
2533 (<= start-point
(point))
2535 ;; See if this one should be the alternate default.
2536 (and (null alt-default
)
2537 (and (<= bol
(match-beginning 0))
2539 (setq alt-default t
))
2541 (while (setq i
(string-match "[ \n\t]+" str i
))
2542 (setq str
(concat (substring str
0 i
) " "
2543 (substring str
(match-end 0))))
2545 ;; Record as a completion and perhaps as default.
2546 (if (eq default t
) (setq default str
))
2547 (if (eq alt-default t
) (setq alt-default str
))
2548 ;; Don't add this string if it's a duplicate.
2549 (or (assoc-string str completions t
)
2550 (push str completions
))))
2551 ;; If no good default was found, try an alternate.
2553 (setq default alt-default
))
2554 ;; If only one cross-reference found, then make it default.
2555 (if (eq (length completions
) 1)
2556 (setq default
(car completions
)))
2558 (let ((input (completing-read (if default
2560 "Follow reference named (default "
2562 "Follow reference named: ")
2563 completions nil t
)))
2564 (list (if (equal input
"")
2565 default input
) current-prefix-arg
))
2566 (user-error "No cross-references in this node"))))
2568 (unless footnotename
2569 (error "No reference was specified"))
2571 (let (target i
(str (concat "\\*note " (regexp-quote footnotename
)))
2572 (case-fold-search t
))
2573 (while (setq i
(string-match " " str i
))
2574 (setq str
(concat (substring str
0 i
) "[ \t\n]+" (substring str
(1+ i
))))
2577 ;; Move point to the beginning of reference if point is on reference
2578 (or (looking-at "\\*note[ \n\t]+")
2579 (and (looking-back "\\*note[ \n\t]+"
2580 (save-excursion (skip-chars-backward " \n\t")
2581 (line-beginning-position)))
2582 (goto-char (match-beginning 0)))
2583 (if (and (save-excursion
2584 (goto-char (+ (point) 5)) ; skip a possible *note
2585 (re-search-backward "\\*note[ \n\t]+" nil t
)
2587 (<= (point) (match-end 0)))
2588 (goto-char (match-beginning 0))))
2589 ;; Go to the reference closest to point
2590 (let ((next-ref (save-excursion (and (re-search-forward str nil t
)
2591 (+ (match-beginning 0) 5))))
2592 (prev-ref (save-excursion (and (re-search-backward str nil t
)
2593 (+ (match-beginning 0) 5)))))
2594 (goto-char (cond ((and next-ref prev-ref
)
2595 (if (< (abs (- next-ref
(point)))
2596 (abs (- prev-ref
(point))))
2598 ((or next-ref prev-ref
))
2599 ((user-error "No cross-reference named %s"
2601 (setq target
(Info-extract-menu-node-name t
))))
2602 (while (setq i
(string-match "[ \t\n]+" target i
))
2603 (setq target
(concat (substring target
0 i
) " "
2604 (substring target
(match-end 0))))
2606 (Info-goto-node target fork
)))
2608 (defconst Info-menu-entry-name-re
"\\(?:[^:]\\|:[^:,.;() \t\n]\\)*"
2609 ;; We allow newline because this is also used in Info-follow-reference,
2610 ;; where the xref name might be wrapped over two lines.
2611 "Regexp that matches a menu entry name upto but not including the colon.
2612 Because of ambiguities, this should be concatenated with something like
2613 `:' and `Info-following-node-name-re'.")
2615 (defun Info-extract-menu-node-name (&optional multi-line index-node
)
2616 (skip-chars-forward " \t\n")
2617 (when (looking-at (concat Info-menu-entry-name-re
":\\(:\\|"
2618 (Info-following-node-name-re
2620 (index-node "^,\t\n")
2621 (multi-line "^.,\t")
2625 "\\.\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"
2628 (setq Info-point-loc
2629 (if (match-beginning 5)
2630 (string-to-number (match-string 5))
2631 (buffer-substring-no-properties
2632 (match-beginning 0) (1- (match-beginning 1)))))
2633 ;;; Uncomment next line to use names of cross-references in non-index nodes:
2634 ;;; (setq Info-point-loc
2635 ;;; (buffer-substring (match-beginning 0) (1- (match-beginning 1))))
2637 (replace-regexp-in-string
2639 (or (and (not (equal (match-string-no-properties 2) ""))
2640 (match-string-no-properties 2))
2641 ;; If the node name is the menu entry name (using `entry::').
2642 (buffer-substring-no-properties
2643 (match-beginning 0) (1- (match-beginning 1)))))))
2645 ;; No one calls this.
2646 ;;(defun Info-menu-item-sequence (list)
2648 ;; (Info-menu (car list))
2649 ;; (setq list (cdr list))))
2651 (defvar Info-complete-menu-buffer
)
2652 (defvar Info-complete-next-re nil
)
2653 (defvar Info-complete-nodes nil
)
2654 (defvar-local Info-complete-cache nil
)
2656 (defconst Info-node-spec-re
2657 (concat (Info-following-node-name-re "^.,:") "[,:.]")
2658 "Regexp to match the text after a : until the terminating `.'.")
2660 (defun Info-complete-menu-item (string predicate action
)
2661 ;; This uses two dynamically bound variables:
2662 ;; - `Info-complete-menu-buffer' which contains the buffer in which
2663 ;; is the menu of items we're trying to complete.
2664 ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
2665 ;; also look for menu items in subsequent nodes as long as those
2666 ;; nodes' names match `Info-complete-next-re'. This feature is currently
2668 ;; - `Info-complete-nodes' which, if non-nil, indicates that we should
2669 ;; also look for menu items in these nodes. This feature is currently
2670 ;; only used for completion in Info-index.
2672 ;; Note that `Info-complete-menu-buffer' could be current already,
2673 ;; so we want to save point.
2674 (with-current-buffer Info-complete-menu-buffer
2676 (let ((completion-ignore-case t
)
2677 (case-fold-search t
)
2678 (orignode Info-current-node
)
2680 (goto-char (point-min))
2681 (search-forward "\n* Menu:")
2683 ((eq (car-safe action
) 'boundaries
) nil
)
2684 ((eq action
'lambda
)
2686 (concat "\n\\* +" (regexp-quote string
) ":") nil t
))
2688 (let ((pattern (concat "\n\\* +\\("
2689 (regexp-quote string
)
2690 Info-menu-entry-name-re
"\\):"
2693 (complete-nodes Info-complete-nodes
))
2695 (if (and (equal (nth 0 Info-complete-cache
) Info-current-file
)
2696 (equal (nth 1 Info-complete-cache
) Info-current-node
)
2697 (equal (nth 2 Info-complete-cache
) Info-complete-next-re
)
2698 (equal (nth 5 Info-complete-cache
) Info-complete-nodes
)
2699 (string-prefix-p (nth 3 Info-complete-cache
) string
) t
)
2700 ;; We can reuse the previous list.
2701 (setq completions
(nth 4 Info-complete-cache
))
2702 ;; The cache can't be used.
2705 (while (re-search-forward pattern nil t
)
2706 (push (match-string-no-properties 1)
2708 (setq completions
(delete-dups completions
))
2709 ;; Check subsequent nodes if applicable.
2710 (or (and Info-complete-next-re
2711 (setq nextnode
(Info-extract-pointer "next" t
))
2712 (string-match Info-complete-next-re nextnode
))
2714 (setq complete-nodes
(cdr complete-nodes
)
2715 nextnode
(car complete-nodes
)))))
2716 (Info-goto-node nextnode
))
2717 ;; Go back to the start node (for the next completion).
2718 (unless (equal Info-current-node orignode
)
2719 (Info-goto-node orignode
))
2720 ;; Update the cache.
2721 (setq Info-complete-cache
2722 (list Info-current-file Info-current-node
2723 Info-complete-next-re string completions
2724 Info-complete-nodes
)))
2725 (complete-with-action action completions string predicate
))))))))
2728 (defun Info-menu (menu-item &optional fork
)
2729 "Go to the node pointed to by the menu item named (or abbreviated) MENU-ITEM.
2730 The menu item should one of those listed in the current node's menu.
2731 Completion is allowed, and the default menu item is the one point is on.
2732 If FORK is non-nil (interactively with a prefix arg), show the node in
2733 a new Info buffer. If FORK is a string, it is the name to use for the
2736 (let (;; If point is within a menu item, use that item as the default
2740 (case-fold-search t
))
2742 (goto-char (point-min))
2743 (if (not (search-forward "\n* menu:" nil t
))
2744 (user-error "No menu in this node"))
2750 (if (re-search-backward (concat "\n\\* +\\("
2751 Info-menu-entry-name-re
2754 (setq default
(match-string-no-properties 1))))))
2757 (setq item
(let ((completion-ignore-case t
)
2758 (Info-complete-menu-buffer (current-buffer)))
2759 (completing-read (if default
2760 (format "Menu item (default %s): "
2763 #'Info-complete-menu-item nil t nil nil
2765 ;; we rely on the fact that completing-read accepts an input
2766 ;; of "" even when the require-match argument is true and ""
2767 ;; is not a valid possibility
2768 (if (string= item
"")
2773 (list item current-prefix-arg
))))
2774 ;; there is a problem here in that if several menu items have the same
2775 ;; name you can only go to the node of the first with this command.
2776 (Info-goto-node (Info-extract-menu-item menu-item
)
2778 (if (stringp fork
) fork menu-item
))))
2780 (defun Info-extract-menu-item (menu-item)
2781 (setq menu-item
(regexp-quote menu-item
))
2782 (let ((case-fold-search t
))
2784 (let ((case-fold-search t
))
2785 (goto-char (point-min))
2786 (or (search-forward "\n* menu:" nil t
)
2787 (user-error "No menu in this node"))
2788 (or (re-search-forward (concat "\n\\* +" menu-item
":") nil t
)
2789 (re-search-forward (concat "\n\\* +" menu-item
) nil t
)
2790 (user-error "No such item in menu"))
2793 (Info-extract-menu-node-name nil
(Info-index-node))))))
2795 ;; If COUNT is nil, use the last item in the menu.
2796 (defun Info-extract-menu-counting (count &optional no-detail
)
2797 (let ((case-fold-search t
))
2799 (let ((case-fold-search t
)
2800 (bound (when (and no-detail
2802 "^[ \t-]*The Detailed Node Listing" nil t
))
2803 (match-beginning 0))))
2804 (goto-char (point-min))
2805 (or (search-forward "\n* menu:" bound t
)
2806 (user-error "No menu in this node"))
2808 (or (search-forward "\n* " bound t count
)
2809 (error "Too few items in menu"))
2810 (while (search-forward "\n* " bound t
)
2812 (Info-extract-menu-node-name nil
(Info-index-node))))))
2814 (defun Info-nth-menu-item ()
2815 "Go to the node of the Nth menu item.
2816 N is the digit argument used to invoke this command."
2819 (Info-extract-menu-counting
2820 (- (aref (this-command-keys) (1- (length (this-command-keys)))) ?
0))))
2822 (defun Info-top-node ()
2823 "Go to the Top node of this file."
2825 (Info-goto-node "Top"))
2827 (defun Info-final-node ()
2828 "Go to the final node in this file."
2830 (Info-goto-node "Top")
2831 (let ((Info-history nil
)
2832 (case-fold-search t
))
2833 ;; Go to the last node in the menu of Top. But don't delve into
2834 ;; detailed node listings.
2835 (Info-goto-node (Info-extract-menu-counting nil t
))
2836 ;; If the last node in the menu is not last in pointer structure,
2837 ;; move forward (but not down- or upward - see bug#1116) until we
2838 ;; can't go any farther.
2839 (while (Info-forward-node t t t
) nil
)
2840 ;; Then keep moving down to last subnode, unless we reach an index.
2841 (while (and (not (Info-index-node))
2842 (save-excursion (search-forward "\n* Menu:" nil t
)))
2843 (Info-goto-node (Info-extract-menu-counting nil
)))))
2845 (defun Info-forward-node (&optional not-down not-up no-error
)
2846 "Go forward one node, considering all nodes as forming one sequence."
2848 (goto-char (point-min))
2850 (let ((case-fold-search t
))
2851 ;; three possibilities, in order of priority:
2852 ;; 1. next node is in a menu in this node (but not in an index)
2853 ;; 2. next node is next at same level
2854 ;; 3. next node is up and next
2855 (cond ((and (not not-down
)
2856 (save-excursion (search-forward "\n* menu:" nil t
))
2857 (not (Info-index-node)))
2858 (Info-goto-node (Info-extract-menu-counting 1))
2860 ((save-excursion (search-backward "next:" nil t
))
2864 (save-excursion (search-backward "up:" nil t
))
2865 ;; Use string-equal, not equal, to ignore text props.
2866 (not (string-equal (downcase (Info-extract-pointer "up"))
2868 (let ((old-node Info-current-node
))
2870 (let ((old-history Info-history
)
2873 (setq success
(Info-forward-node t nil no-error
))
2874 (or success
(Info-goto-node old-node
)))
2875 (if Info-history-skip-intermediate-nodes
2876 (setq Info-history old-history
)))))
2878 (t (user-error "No pointer forward from this node")))))
2880 (defun Info-backward-node ()
2881 "Go backward one node, considering all nodes as forming one sequence."
2883 (let ((prevnode (Info-extract-pointer "prev[ious]*" t
))
2884 (upnode (Info-extract-pointer "up" t
))
2885 (case-fold-search t
))
2886 (cond ((and upnode
(string-match "(" upnode
))
2887 (user-error "First node in file"))
2888 ((and upnode
(or (null prevnode
)
2889 ;; Use string-equal, not equal,
2890 ;; to ignore text properties.
2891 (string-equal (downcase prevnode
)
2892 (downcase upnode
))))
2895 ;; If we move back at the same level,
2896 ;; go down to find the last subnode*.
2898 (let ((old-history Info-history
))
2899 (while (and (not (Info-index-node))
2900 (save-excursion (search-forward "\n* Menu:" nil t
)))
2901 (Info-goto-node (Info-extract-menu-counting nil
)))
2902 (if Info-history-skip-intermediate-nodes
2903 (setq Info-history old-history
))))
2905 (user-error "No pointer backward from this node")))))
2908 "Exit Info by selecting some other buffer."
2911 (save-buffers-kill-emacs)
2914 (defun Info-next-menu-item ()
2915 "Go to the node of the next menu item."
2917 ;; Bind this in case the user sets it to nil.
2918 (let* ((case-fold-search t
)
2922 (search-forward "\n* menu:" nil t
)
2923 (and (search-forward "\n* " nil t
)
2924 (Info-extract-menu-node-name)))))
2925 (if node
(Info-goto-node node
)
2926 (user-error "No more items in menu"))))
2928 (defun Info-last-menu-item ()
2929 "Go to the node of the previous menu item."
2933 ;; Bind this in case the user sets it to nil.
2934 (let* ((case-fold-search t
)
2935 (beg (save-excursion
2936 (and (search-backward "\n* menu:" nil t
)
2938 (or (and beg
(search-backward "\n* " beg t
))
2939 (user-error "No previous items in menu")))
2940 (Info-goto-node (save-excursion
2941 (goto-char (match-end 0))
2942 (Info-extract-menu-node-name)))))
2944 (defmacro Info-no-error
(&rest body
)
2945 `(condition-case nil
(progn ,@body t
) (error nil
)))
2947 (defun Info-next-preorder ()
2948 "Go to the next subnode or the next node, or go up a level."
2950 (cond ((Info-no-error (Info-next-menu-item)))
2951 ((Info-no-error (Info-next)))
2952 ((Info-no-error (Info-up t
))
2953 ;; Since we have already gone thru all the items in this menu,
2954 ;; go up to the end of this node.
2955 (goto-char (point-max))
2956 ;; Since logically we are done with the node with that menu,
2957 ;; move on from it. But don't add intermediate nodes
2958 ;; to the history on recursive calls.
2959 (let ((old-history Info-history
))
2960 (Info-next-preorder)
2961 (if Info-history-skip-intermediate-nodes
2962 (setq Info-history old-history
))))
2964 (user-error "No more nodes"))))
2966 (defun Info-last-preorder ()
2967 "Go to the last node, popping up a level if there is none."
2969 (cond ((and Info-scroll-prefer-subnodes
2971 (Info-last-menu-item)
2972 ;; If we go down a menu item, go to the end of the node
2973 ;; so we can scroll back through it.
2974 (goto-char (point-max))))
2975 ;; Keep going down, as long as there are nested menu nodes.
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 ((and (Info-no-error (Info-extract-pointer "prev"))
2986 (not (equal (Info-extract-pointer "up")
2987 (Info-extract-pointer "prev"))))
2988 (Info-no-error (Info-prev))
2989 (goto-char (point-max))
2990 (let ((old-history Info-history
))
2991 (while (Info-no-error
2992 (Info-last-menu-item)
2993 ;; If we go down a menu item, go to the end of the node
2994 ;; so we can scroll back through it.
2995 (goto-char (point-max))))
2996 (if Info-history-skip-intermediate-nodes
2997 (setq Info-history old-history
)))
2999 ((Info-no-error (Info-up t
))
3000 (goto-char (point-min))
3001 (let ((case-fold-search t
))
3002 (or (search-forward "\n* Menu:" nil t
)
3003 (goto-char (point-max)))))
3004 (t (user-error "No previous nodes"))))
3006 (defun Info-scroll-up ()
3007 "Scroll one screenful forward in Info, considering all nodes as one sequence.
3008 Once you scroll far enough in a node that its menu appears on the screen
3009 but after point, the next scroll moves into its first subnode, unless
3010 `Info-scroll-prefer-subnodes' is nil.
3012 When you scroll past the end of a node, that goes to the next node if
3013 `Info-scroll-prefer-subnodes' is non-nil and to the first subnode otherwise;
3014 if this node has no successor, it moves to the parent node's successor,
3015 and so on. If `Info-scroll-prefer-subnodes' is non-nil and point is inside
3016 the menu of a node, it moves to subnode indicated by the following menu
3017 item. (That case won't normally result from this command, but can happen
3021 (if (or (< (window-start) (point-min))
3022 (> (window-start) (point-max)))
3023 (set-window-start (selected-window) (point)))
3024 (let* ((case-fold-search t
)
3025 (virtual-end (save-excursion
3026 (goto-char (point-min))
3027 (if (and Info-scroll-prefer-subnodes
3028 (search-forward "\n* Menu:" nil t
))
3031 (if (or (< virtual-end
(window-start))
3032 (pos-visible-in-window-p virtual-end
))
3034 (Info-scroll-prefer-subnodes (Info-next-preorder))
3035 ((Info-no-error (Info-goto-node (Info-extract-menu-counting 1))))
3036 (t (Info-next-preorder)))
3039 (defun Info-mouse-scroll-up (e)
3040 "Scroll one screenful forward in Info, using the mouse.
3041 See `Info-scroll-up'."
3043 (save-selected-window
3045 (select-window (posn-window (event-start e
))))
3048 (defun Info-scroll-down ()
3049 "Scroll one screenful back in Info, considering all nodes as one sequence.
3050 If point is within the menu of a node, and `Info-scroll-prefer-subnodes'
3051 is non-nil, this goes to its last subnode. When you scroll past the
3052 beginning of a node, that goes to the previous node or back up to the
3055 (if (or (< (window-start) (point-min))
3056 (> (window-start) (point-max)))
3057 (set-window-start (selected-window) (point)))
3058 (let* ((case-fold-search t
)
3059 (current-point (point))
3061 (and Info-scroll-prefer-subnodes
3063 (setq current-point
(line-beginning-position))
3064 (goto-char (point-min))
3065 (search-forward "\n* Menu:" current-point t
)))))
3067 (pos-visible-in-window-p (point-min) nil t
))
3068 (Info-last-preorder)
3071 (defun Info-mouse-scroll-down (e)
3072 "Scroll one screenful backward in Info, using the mouse.
3073 See `Info-scroll-down'."
3075 (save-selected-window
3077 (select-window (posn-window (event-start e
))))
3078 (Info-scroll-down)))
3080 (defun Info-next-reference-or-link (pat prop
)
3081 "Move point to the next pattern-based cross-reference or property-based link.
3082 The next cross-reference is searched using the regexp PAT, and the next link
3083 is searched using the text property PROP. Move point to the closest found position
3084 of either a cross-reference found by `re-search-forward' or a link found by
3085 `next-single-char-property-change'. Return the new position of point, or nil."
3086 (let ((pxref (save-excursion (re-search-forward pat nil t
)))
3087 (plink (next-single-char-property-change (point) prop
)))
3088 (when (and (< plink
(point-max)) (not (get-char-property plink prop
)))
3089 (setq plink
(next-single-char-property-change plink prop
)))
3090 (if (< plink
(point-max))
3091 (if (and pxref
(<= pxref plink
))
3092 (goto-char (or (match-beginning 1) (match-beginning 0)))
3094 (if pxref
(goto-char (or (match-beginning 1) (match-beginning 0)))))))
3096 (defun Info-prev-reference-or-link (pat prop
)
3097 "Move point to the previous pattern-based cross-reference or property-based link.
3098 The previous cross-reference is searched using the regexp PAT, and the previous link
3099 is searched using the text property PROP. Move point to the closest found position
3100 of either a cross-reference found by `re-search-backward' or a link found by
3101 `previous-single-char-property-change'. Return the new position of point, or nil."
3102 (let ((pxref (save-excursion (re-search-backward pat nil t
)))
3103 (plink (previous-single-char-property-change (point) prop
)))
3104 (when (and (> plink
(point-min)) (not (get-char-property plink prop
)))
3105 (setq plink
(previous-single-char-property-change plink prop
)))
3106 (if (> plink
(point-min))
3107 (if (and pxref
(>= pxref plink
))
3108 (goto-char (or (match-beginning 1) (match-beginning 0)))
3110 (if pxref
(goto-char (or (match-beginning 1) (match-beginning 0)))))))
3112 (defun Info-next-reference (&optional recur count
)
3113 "Move cursor to the next cross-reference or menu item in the node.
3114 If COUNT is non-nil (interactively with a prefix arg), jump over
3115 COUNT cross-references."
3116 (interactive "i\np")
3120 (Info-prev-reference recur
(- count
))
3121 (while (unless (zerop count
) (setq count
(1- count
)))
3122 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3124 (case-fold-search t
))
3125 (or (eobp) (forward-char 1))
3126 (or (Info-next-reference-or-link pat
'link
)
3128 (goto-char (point-min))
3129 (or (Info-next-reference-or-link pat
'link
)
3132 (user-error "No cross references in this node")))))
3133 (if (looking-at "\\* Menu:")
3135 (user-error "No cross references in this node")
3136 (Info-next-reference t
))
3137 (if (looking-at "^\\* ")
3138 (forward-char 2)))))))
3140 (defun Info-prev-reference (&optional recur count
)
3141 "Move cursor to the previous cross-reference or menu item in the node.
3142 If COUNT is non-nil (interactively with a prefix arg), jump over
3143 COUNT cross-references."
3144 (interactive "i\np")
3148 (Info-next-reference recur
(- count
))
3149 (while (unless (zerop count
) (setq count
(1- count
)))
3150 (let ((pat "\\*note[ \n\t]+\\([^:]+\\):\\|^\\* .*:\\|[hf]t?tps?://")
3152 (case-fold-search t
))
3153 (or (Info-prev-reference-or-link pat
'link
)
3155 (goto-char (point-max))
3156 (or (Info-prev-reference-or-link pat
'link
)
3159 (user-error "No cross references in this node")))))
3160 (if (looking-at "\\* Menu:")
3162 (user-error "No cross references in this node")
3163 (Info-prev-reference t
))
3164 (if (looking-at "^\\* ")
3165 (forward-char 2)))))))
3167 (defun Info-index-nodes (&optional file
)
3168 "Return a list of names of all index nodes in Info FILE.
3169 If FILE is omitted, it defaults to the current Info file.
3170 First look in a list of cached index node names. Then scan Info
3171 file and its subfiles for nodes with the index cookie. Then try
3172 to find index nodes starting from the first node in the top level
3173 menu whose name contains the word \"Index\", plus any immediately
3174 following nodes whose names also contain the word \"Index\"."
3175 (or file
(setq file Info-current-file
))
3176 (or (assoc file Info-index-nodes
)
3177 ;; Skip virtual Info files
3178 (and (or (not (stringp file
))
3179 (Info-virtual-file-p file
))
3180 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
3181 (if (Info-file-supports-index-cookies file
)
3182 ;; Find nodes with index cookie
3183 (let* ((default-directory (or (and (stringp file
)
3184 (file-name-directory
3185 (setq file
(Info-find-file file
))))
3187 Info-history Info-history-list Info-fontify-maximum-menu-size
3188 (main-file file
) subfiles nodes
)
3191 (while (or main-file subfiles
)
3193 (info-insert-file-contents (or main-file
(car subfiles
)))
3194 (goto-char (point-min))
3195 (while (search-forward "\0\b[index\0\b]" nil
'move
)
3197 (re-search-backward "^\^_")
3198 (search-forward "Node: ")
3199 (setq nodes
(cons (Info-following-node-name) nodes
))))
3202 (goto-char (point-min))
3203 (if (search-forward "\n\^_\nIndirect:" nil t
)
3204 (let ((bound (save-excursion (search-forward "\n\^_" nil t
))))
3205 (while (re-search-forward "^\\(.*\\): [0-9]+$" bound t
)
3206 (setq subfiles
(cons (match-string-no-properties 1)
3208 (setq subfiles
(nreverse subfiles
)
3210 (setq subfiles
(cdr subfiles
)))))
3213 (setq nodes
(nreverse nodes
)
3214 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
3216 ;; Else find nodes with the word "Index" in the node name
3217 (let ((case-fold-search t
)
3218 Info-history Info-history-list Info-fontify-maximum-menu-size Info-point-loc
3223 (Info-find-node file
"Top")
3224 (when (and (search-forward "\n* menu:" nil t
)
3225 (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t
))
3226 (goto-char (match-beginning 1))
3227 (setq nodes
(list (Info-extract-menu-node-name)))
3228 (Info-goto-node (car nodes
))
3229 (while (and (setq node
(Info-extract-pointer "next" t
))
3230 (string-match "\\<Index\\>" node
))
3232 (Info-goto-node node
))))
3235 (setq nodes
(nreverse nodes
)
3236 Info-index-nodes
(cons (cons file nodes
) Info-index-nodes
)))
3238 ;; If file has no index nodes, still add it to the cache
3239 (setq Info-index-nodes
(cons (cons file nil
) Info-index-nodes
)))
3240 (cdr (assoc file Info-index-nodes
)))
3242 (defun Info-index-node (&optional node file
)
3243 "Return non-nil value if NODE is an index node.
3244 If NODE is nil, check the current Info node.
3245 If FILE is nil, check the current Info file."
3246 (or file
(setq file Info-current-file
))
3247 (if (and (or (and node
(not (equal node Info-current-node
)))
3248 (assoc file Info-index-nodes
))
3249 (not Info-current-node-virtual
))
3250 (member (or node Info-current-node
) (Info-index-nodes file
))
3251 ;; Don't search all index nodes if request is only for the current node
3252 ;; and file is not in the cache of index nodes
3254 (if (Info-file-supports-index-cookies file
)
3256 (goto-char (+ (or (save-excursion
3257 (search-backward "\n\^_" nil t
))
3259 (search-forward "\0\b[index\0\b]"
3261 (search-forward "\n\^_" nil t
))
3263 (string-match "\\<Index\\>" (or node Info-current-node
""))))))
3265 (defun Info-goto-index ()
3266 "Go to the first index node."
3267 (let ((node (car (Info-index-nodes))))
3268 (or node
(error "No index"))
3269 (Info-goto-node node
)))
3272 (defun Info-index (topic)
3273 "Look up a string TOPIC in the index for this manual and go to that entry.
3274 If there are no exact matches to the specified topic, this chooses
3275 the first match which is a case-insensitive substring of a topic.
3276 Use the \\<Info-mode-map>\\[Info-index-next] command to see the other matches.
3277 Give an empty topic name to go to the Index node itself."
3280 (let ((completion-ignore-case t
)
3281 (Info-complete-menu-buffer (clone-buffer))
3282 (Info-complete-nodes (Info-index-nodes))
3283 (Info-history-list nil
))
3284 (if (equal Info-current-file
"dir")
3285 (error "The Info directory node has no index; use m to select a manual"))
3287 (with-current-buffer Info-complete-menu-buffer
3289 (completing-read "Index topic: " 'Info-complete-menu-item
))
3290 (kill-buffer Info-complete-menu-buffer
)))))
3291 (if (equal Info-current-file
"dir")
3292 (error "The Info directory node has no index; use m to select a manual"))
3293 ;; Strip leading colon in topic; index format does not allow them.
3294 (if (and (stringp topic
)
3295 (> (length topic
) 0)
3296 (= (aref topic
0) ?
:))
3297 (setq topic
(substring topic
1)))
3298 (let ((orignode Info-current-node
)
3299 (pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]*\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3300 (regexp-quote topic
)))
3301 node
(nodes (Info-index-nodes))
3302 (ohist-list Info-history-list
)
3303 (case-fold-search t
))
3305 (or (equal topic
"")
3308 ;; We bind Info-history to nil for internal node-switches so
3309 ;; that we don't put junk in the history. In the first
3310 ;; Info-goto-index call, above, we do update the history
3311 ;; because that is what the user's previous node choice into it.
3316 (goto-char (point-min))
3317 (while (re-search-forward pattern nil t
)
3318 (let ((entry (match-string-no-properties 1))
3319 (nodename (match-string-no-properties 3))
3320 (line (string-to-number (concat "0" (match-string 4)))))
3321 (add-text-properties
3322 (- (match-beginning 2) (match-beginning 1))
3323 (- (match-end 2) (match-beginning 1))
3324 '(face info-index-match
) entry
)
3325 (push (list entry nodename Info-current-node line
) matches
)))
3326 (setq nodes
(cdr nodes
) node
(car nodes
)))
3327 (Info-goto-node node
))
3330 (Info-goto-node orignode
)
3331 (user-error "No `%s' in index" topic
)))
3332 ;; Here it is a feature that assoc is case-sensitive.
3333 (while (setq found
(assoc topic matches
))
3334 (setq exact
(cons found exact
)
3335 matches
(delq found matches
)))
3336 (setq Info-history-list ohist-list
)
3337 (setq Info-index-alternatives
(nconc exact
(nreverse matches
)))
3338 (Info-index-next 0)))))
3340 (defun Info-index-next (num)
3341 "Go to the next matching index item from the last \\<Info-mode-map>\\[Info-index] command."
3343 (or Info-index-alternatives
3344 (user-error "No previous `i' command"))
3346 (setq num
(+ num
(length Info-index-alternatives
))))
3348 (setq Info-index-alternatives
3349 (nconc (cdr Info-index-alternatives
)
3350 (list (car Info-index-alternatives
)))
3352 (Info-goto-node (nth 1 (car Info-index-alternatives
)))
3353 (if (> (nth 3 (car Info-index-alternatives
)) 0)
3354 ;; Forward 2 lines less because `Info-find-node-2' initially
3355 ;; puts point to the 2nd line.
3356 (forward-line (- (nth 3 (car Info-index-alternatives
)) 2))
3357 (forward-line 3) ; don't search in headers
3358 (let ((name (car (car Info-index-alternatives
))))
3359 (Info-find-index-name name
)))
3360 (message "Found `%s' in %s. %s"
3361 (car (car Info-index-alternatives
))
3362 (nth 2 (car Info-index-alternatives
))
3363 (if (cdr Info-index-alternatives
)
3364 (format "(%s total; use `%s' for next)"
3365 (length Info-index-alternatives
)
3366 (key-description (where-is-internal
3367 'Info-index-next overriding-local-map
3371 (defun Info-find-index-name (name)
3372 "Move point to the place within the current node where NAME is defined."
3373 (let ((case-fold-search t
))
3374 (if (or (re-search-forward (format
3375 "[a-zA-Z]+: %s\\( \\|$\\)"
3376 (regexp-quote name
)) nil t
)
3377 ;; Find a function definition with a return type.
3378 (re-search-forward (format
3379 "[a-zA-Z]+: [a-zA-Z0-9_ *&]+ %s\\( \\|$\\)"
3380 (regexp-quote name
)) nil t
)
3381 (search-forward (format "['`‘]%s['’]" name
) nil t
)
3382 (and (string-match "\\`.*\\( (.*)\\)\\'" name
)
3384 (format "['`‘]%s['’]" (substring name
0 (match-beginning 1)))
3386 (search-forward name nil t
)
3387 ;; Try again without the " <1>" makeinfo can append
3388 (and (string-match "\\`\\(.*\\) <[0-9]+>\\'" name
)
3389 (Info-find-index-name (match-string 1 name
))))
3390 (progn (beginning-of-line) t
) ;; non-nil for recursive call
3391 (goto-char (point-min)))))
3393 (add-to-list 'Info-virtual-nodes
3394 '("\\`\\*Index.*\\*\\'"
3395 (find-node . Info-virtual-index-find-node
)
3399 (defvar Info-virtual-index-nodes nil
3400 "Alist of cached matched index search nodes.
3401 Each element is ((FILENAME . TOPIC) MATCHES) where
3402 FILENAME is the file name of the manual,
3403 TOPIC is the search string given as an argument to `Info-virtual-index',
3404 MATCHES is a list of index matches found by `Info-index'.")
3406 (defun Info-virtual-index-find-node (filename nodename
&optional _no-going-back
)
3407 "Index-specific implementation of `Info-find-node-2'."
3408 ;; Generate Index-like menu of matches
3409 (if (string-match "^\\*Index for ‘\\(.+\\)’\\*$" nodename
)
3410 ;; Generate Index-like menu of matches
3411 (let* ((topic (match-string 1 nodename
))
3412 (matches (cdr (assoc (cons (or filename Info-current-file
) topic
)
3413 Info-virtual-index-nodes
))))
3414 (insert (format "\n\^_\nFile: %s, Node: %s, Up: *Index*\n\n"
3415 (or filename Info-current-file
) nodename
))
3416 (insert "Info Virtual Index\n")
3417 (insert "******************\n\n")
3418 (insert "Index entries that match ‘" topic
"’:\n\n")
3419 (insert "\0\b[index\0\b]\n")
3421 (insert "No matches found.\n")
3422 (insert "* Menu:\n\n")
3423 (dolist (entry matches
)
3424 (insert (format "* %-38s %s.%s\n"
3425 (format "%s [%s]:" (nth 0 entry
) (nth 2 entry
))
3428 (format " (line %s)" (nth 3 entry
))
3430 ;; Else, Generate a list of previous search results
3431 (let ((nodes (reverse Info-virtual-index-nodes
)))
3432 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3433 (or filename Info-current-file
) nodename
))
3434 (insert "Info Virtual Index\n")
3435 (insert "******************\n\n")
3436 (insert "This is a list of search results produced by\n"
3437 "‘Info-virtual-index’ for the current manual.\n\n")
3438 (insert "* Menu:\n\n")
3439 (dolist (nodeinfo nodes
)
3440 (when (equal (car (nth 0 nodeinfo
)) (or filename Info-current-file
))
3442 (format "* %-20s %s.\n"
3443 (format "*Index for ‘%s’*::" (cdr (nth 0 nodeinfo
)))
3444 (cdr (nth 0 nodeinfo
)))))))))
3446 (defun Info-virtual-index (topic)
3447 "Show a node with all lines in the index containing a string TOPIC.
3448 Like `Info-index' but displays a node with index search results.
3449 Give an empty topic name to go to the node with links to previous
3451 ;; `interactive' is a copy from `Info-index'
3454 (let ((completion-ignore-case t
)
3455 (Info-complete-menu-buffer (clone-buffer))
3456 (Info-complete-nodes (Info-index-nodes))
3457 (Info-history-list nil
))
3458 (if (equal Info-current-file
"dir")
3459 (error "The Info directory node has no index; use m to select a manual"))
3461 (with-current-buffer Info-complete-menu-buffer
3463 (completing-read "Index topic: " 'Info-complete-menu-item
))
3464 (kill-buffer Info-complete-menu-buffer
)))))
3465 (if (equal topic
"")
3466 (Info-find-node Info-current-file
"*Index*")
3467 (unless (assoc (cons Info-current-file topic
) Info-virtual-index-nodes
)
3468 (let ((orignode Info-current-node
)
3469 (ohist-list Info-history-list
))
3470 ;; Reuse `Info-index' to set `Info-index-alternatives'.
3472 (push (cons (cons Info-current-file topic
) Info-index-alternatives
)
3473 Info-virtual-index-nodes
)
3474 ;; Clean up unnecessary side-effects of `Info-index'.
3475 (setq Info-history-list ohist-list
)
3476 (Info-goto-node orignode
)
3478 (Info-find-node Info-current-file
(format "*Index for ‘%s’*" topic
))))
3480 (add-to-list 'Info-virtual-files
3481 '("\\`\\*Apropos\\*\\'"
3482 (toc-nodes . Info-apropos-toc-nodes
)
3483 (find-file . Info-apropos-find-file
)
3484 (find-node . Info-apropos-find-node
)
3488 (defvar Info-apropos-file
"*Apropos*"
3489 "Info file name of the virtual manual for matches of `info-apropos'.")
3491 (defvar Info-apropos-nodes nil
3492 "Alist of cached apropos matched nodes.
3493 Each element is (NODENAME STRING MATCHES) where
3494 NODENAME is the name of the node that holds the search result,
3495 STRING is the search string given as an argument to `info-apropos',
3496 MATCHES is a list of index matches found by `Info-apropos-matches'.")
3498 (defun Info-apropos-toc-nodes (filename)
3499 "Apropos-specific implementation of `Info-toc-nodes'."
3500 (let ((nodes (mapcar #'car
(reverse Info-apropos-nodes
))))
3502 ("Top" nil nil
,nodes
)
3503 ,@(mapcar (lambda (node) `(,node
"Top" nil nil
)) nodes
))))
3505 (defun Info-apropos-find-file (filename &optional _noerror
)
3506 "Apropos-specific implementation of `Info-find-file'."
3509 (defun Info-apropos-find-node (_filename nodename
&optional _no-going-back
)
3510 "Apropos-specific implementation of `Info-find-node-2'."
3511 (if (equal nodename
"Top")
3512 ;; Generate Top menu
3513 (let ((nodes (reverse Info-apropos-nodes
)))
3514 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3515 Info-apropos-file nodename
))
3516 (insert "Apropos Index\n")
3517 (insert "*************\n\n")
3518 (insert "This is a list of search results produced by ‘info-apropos’.\n\n")
3519 (insert "* Menu:\n\n")
3520 (dolist (nodeinfo nodes
)
3521 (insert (format "* %-20s %s.\n"
3522 (format "%s::" (nth 0 nodeinfo
))
3523 (nth 1 nodeinfo
)))))
3524 ;; Else, Generate Index-like menu of matches
3525 (let* ((nodeinfo (assoc nodename Info-apropos-nodes
))
3526 (matches (nth 2 nodeinfo
)))
3528 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3529 Info-apropos-file nodename
))
3530 (insert "Apropos Index\n")
3531 (insert "*************\n\n")
3532 (insert "Index entries that match ‘" (nth 1 nodeinfo
) "’:\n\n")
3533 (insert "\0\b[index\0\b]\n")
3535 (insert "No matches found.\n")
3536 (insert "* Menu:\n\n")
3537 (dolist (entry matches
)
3538 (insert (format "* %-38s (%s)%s.%s\n"
3539 (format "%s [%s]:" (nth 1 entry
) (nth 0 entry
))
3543 (format " (line %s)" (nth 3 entry
))
3546 (defun Info-apropos-matches (string)
3547 "Collect STRING matches from all known Info files on your system.
3548 Return a list of matches where each element is in the format
3549 \((FILENAME INDEXTEXT NODENAME LINENUMBER))."
3550 (unless (string= string
"")
3551 (let ((pattern (format "\n\\* +\\([^\n]*\\(%s\\)[^\n]*\\):[ \t]+\\([^\n]+\\)\\.\\(?:[ \t\n]*(line +\\([0-9]+\\))\\)?"
3552 (regexp-quote string
)))
3553 (ohist Info-history
)
3554 (ohist-list Info-history-list
)
3555 (current-node Info-current-node
)
3556 (current-file Info-current-file
)
3557 manuals matches node nodes
)
3558 (let ((Info-fontify-maximum-menu-size nil
))
3560 ;; current-node and current-file are nil when they invoke info-apropos
3561 ;; as the first Info command, i.e. info-apropos loads info.el. In that
3562 ;; case, we use (DIR)Top instead, to avoid signaling an error after
3563 ;; the search is complete.
3564 (when (null current-node
)
3565 (setq current-file Info-current-file
)
3566 (setq current-node Info-current-node
))
3567 (message "Searching indices...")
3568 (goto-char (point-min))
3569 (re-search-forward "\\* Menu: *\n" nil t
)
3570 (while (re-search-forward "\\*.*: *(\\([^)]+\\))" nil t
)
3571 ;; Make sure we don't have duplicates in `manuals',
3572 ;; so that the following dolist loop runs faster.
3573 (cl-pushnew (match-string 1) manuals
:test
#'equal
))
3574 (dolist (manual (nreverse manuals
))
3575 (message "Searching %s" manual
)
3577 (if (setq nodes
(Info-index-nodes (Info-find-file manual
)))
3579 (Info-find-node manual
(car nodes
))
3582 (goto-char (point-min))
3583 (while (re-search-forward pattern nil t
)
3584 (let ((entry (match-string-no-properties 1))
3585 (nodename (match-string-no-properties 3))
3586 (line (match-string-no-properties 4)))
3587 (add-text-properties
3588 (- (match-beginning 2) (match-beginning 1))
3589 (- (match-end 2) (match-beginning 1))
3590 '(face info-index-match
) entry
)
3591 (setq matches
(cons (list manual entry nodename line
)
3593 (setq nodes
(cdr nodes
) node
(car nodes
)))
3594 (Info-goto-node node
))))
3596 (message "%s" (if (eq (car-safe err
) 'error
)
3599 (Info-find-node current-file current-node
)
3600 (setq Info-history ohist
3601 Info-history-list ohist-list
)
3602 (message "Searching indices...done")
3603 (or (nreverse matches
) t
))))
3606 (defun info-apropos (string)
3607 "Grovel indices of all known Info files on your system for STRING.
3608 Build a menu of the possible matches."
3609 (interactive "sIndex apropos: ")
3610 (if (equal string
"")
3611 (Info-find-node Info-apropos-file
"Top")
3612 (let* ((nodes Info-apropos-nodes
) nodename
)
3613 (while (and nodes
(not (equal string
(nth 1 (car nodes
)))))
3614 (setq nodes
(cdr nodes
)))
3616 (Info-find-node Info-apropos-file
(car (car nodes
)))
3617 (setq nodename
(format "Index for ‘%s’" string
))
3618 (push (list nodename string
(Info-apropos-matches string
))
3620 (Info-find-node Info-apropos-file nodename
)))))
3622 (add-to-list 'Info-virtual-files
3623 '("\\`\\*Finder.*\\*\\'"
3624 (find-file . Info-finder-find-file
)
3625 (find-node . Info-finder-find-node
)
3628 (defvar Info-finder-file
"*Finder*"
3629 "Info file name of the virtual Info keyword finder manual.")
3631 (defun Info-finder-find-file (filename &optional _noerror
)
3632 "Finder-specific implementation of `Info-find-file'."
3635 (defvar finder-known-keywords
)
3636 (declare-function find-library-name
"find-func" (library))
3637 (declare-function finder-unknown-keywords
"finder" ())
3638 (declare-function lm-commentary
"lisp-mnt" (&optional file
))
3639 (defvar finder-keywords-hash
)
3640 (defvar package--builtins
) ; finder requires package
3642 (defun info--prettify-description (desc)
3646 (if (equal ?.
(char-before))
3648 (goto-char (point-min))
3649 (or (let (case-fold-search) (looking-at-p "\\.\\|[[:upper:]]"))
3650 (capitalize-word 1))
3654 (defun Info-finder-find-node (_filename nodename
&optional _no-going-back
)
3655 "Finder-specific implementation of `Info-find-node-2'."
3658 ((equal nodename
"Top")
3659 ;; Display Top menu with descriptions of the keywords
3660 (insert (format "\n\^_\nFile: %s, Node: %s, Up: (dir)\n\n"
3661 Info-finder-file nodename
))
3662 (insert "Finder Keywords\n")
3663 (insert "***************\n\n")
3664 (insert "* Menu:\n\n")
3665 (dolist (assoc (append '((all .
"All package info")
3666 (unknown .
"Unknown keywords"))
3667 finder-known-keywords
))
3668 (let ((keyword (car assoc
)))
3669 (insert (format "* %s %s.\n"
3670 (concat (symbol-name keyword
) ": "
3671 "Keyword " (symbol-name keyword
) ".")
3672 (info--prettify-description (cdr assoc
)))))))
3673 ((equal nodename
"Keyword unknown")
3674 ;; Display unknown keywords
3675 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3676 Info-finder-file nodename
))
3677 (insert "Finder Unknown Keywords\n")
3678 (insert "***********************\n\n")
3679 (insert "* Menu:\n\n")
3682 (insert (format "* %-14s %s.\n"
3683 (concat (symbol-name (car assoc
)) ": "
3684 "Keyword " (symbol-name (car assoc
)) ".")
3686 (finder-unknown-keywords)))
3687 ((equal nodename
"Keyword all")
3688 ;; Display all package info.
3689 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3690 Info-finder-file nodename
))
3691 (insert "Finder Package Info\n")
3692 (insert "*******************\n\n")
3693 (insert "* Menu:\n\n")
3695 (dolist (package package--builtins
)
3696 (setq desc
(cdr-safe package
))
3697 (when (vectorp desc
)
3698 (insert (format "* %-16s %s.\n"
3699 (concat (symbol-name (car package
)) "::")
3700 (info--prettify-description (aref desc
2))))))))
3701 ((string-match "\\`Keyword " nodename
)
3702 (setq nodename
(substring nodename
(match-end 0)))
3703 ;; Display packages that match the keyword
3704 ;; or the list of keywords separated by comma.
3705 (insert (format "\n\^_\nFile: %s, Node: Keyword %s, Up: Top\n\n"
3706 Info-finder-file nodename
))
3707 (insert "Finder Packages\n")
3708 (insert "***************\n\n")
3710 "The following packages match the keyword ‘" nodename
"’:\n\n")
3711 (insert "* Menu:\n\n")
3713 (mapcar #'intern
(if (string-match-p "," nodename
)
3714 (split-string nodename
",[ \t\n]*" t
)
3717 (dolist (keyword keywords
)
3718 (push (copy-tree (gethash keyword finder-keywords-hash
)) hits
))
3719 (setq hits
(delete-dups (apply #'append hits
))
3720 ;; Not a meaningful package.
3721 hits
(delete 'emacs hits
)
3722 hits
(sort hits
(lambda (a b
) (string< (symbol-name a
)
3724 (dolist (package hits
)
3725 (setq desc
(cdr-safe (assq package package--builtins
)))
3726 (when (vectorp desc
)
3727 (insert (format "* %-16s %s.\n"
3728 (concat (symbol-name package
) "::")
3729 (info--prettify-description (aref desc
2))))))))
3731 ;; Display commentary section
3732 (insert (format "\n\^_\nFile: %s, Node: %s, Up: Top\n\n"
3733 Info-finder-file nodename
))
3734 (insert "Package Description\n")
3735 (insert "*******************\n\n")
3737 "Description of the package ‘" nodename
"’:\n\n")
3738 ;; This assumes that a file named package.el exists,
3739 ;; which is not always true. E.g. for the nxml package,
3740 ;; there is no "nxml.el" (it's nxml-mode.el).
3741 ;; But package.el makes the same assumption.
3742 ;; I think nxml is the only exception - maybe it should be just be renamed.
3743 (let ((str (ignore-errors (lm-commentary (find-library-name nodename
)))))
3745 (insert "Can't find package description.\n\n")
3749 (goto-char (point-min))
3750 (delete-blank-lines)
3751 (goto-char (point-max))
3752 (delete-blank-lines)
3753 (goto-char (point-min))
3754 (while (re-search-forward "^;+ ?" nil t
)
3755 (replace-match "" nil nil
))
3756 (buffer-string))))))))
3759 (defun info-finder (&optional keywords
)
3760 "Display descriptions of the keywords in the Finder virtual manual.
3761 In interactive use, a prefix argument directs this command to read
3762 a list of keywords separated by comma. After that, it displays a node
3763 with a list of packages that contain all specified keywords."
3765 (when current-prefix-arg
3768 (completing-read-multiple
3769 "Keywords (separated by comma): "
3770 (mapcar #'symbol-name
(mapcar #'car
(append finder-known-keywords
3771 (finder-unknown-keywords))))
3775 (Info-find-node Info-finder-file
(mapconcat 'identity keywords
", "))
3776 (Info-find-node Info-finder-file
"Top")))
3779 (defun Info-undefined ()
3780 "Make command be undefined in Info."
3785 "Enter the Info tutorial."
3787 (delete-other-windows)
3788 (Info-find-node "info"
3789 (if (< (window-height) 23)
3793 (defun Info-summary ()
3794 "Display a brief summary of all Info commands."
3796 (save-window-excursion
3797 (switch-to-buffer "*Help*")
3798 (setq buffer-read-only nil
)
3800 (insert (documentation 'Info-mode
))
3802 (goto-char (point-min))
3804 (while (progn (setq flag
(not (pos-visible-in-window-p (point-max))))
3805 (message (if flag
"Type Space to see more"
3806 "Type Space to return to Info"))
3807 (if (not (eq ?\s
(setq ch
(read-event))))
3808 (progn (setq unread-command-events
(list ch
)) nil
)
3811 (bury-buffer "*Help*")))
3813 (defun Info-get-token (pos start all
&optional errorstring
)
3814 "Return the token around POS.
3815 POS must be somewhere inside the token.
3816 START is a regular expression which will match the
3817 beginning of the tokens delimited string.
3818 ALL is a regular expression with a single
3819 parenthesized subpattern which is the token to be
3820 returned. E.g. '{\(.*\)}' would return any string
3821 enclosed in braces around POS.
3822 ERRORSTRING optional fourth argument, controls action on no match:
3825 a string: signal an error, using that string."
3826 (let ((case-fold-search t
))
3829 ;; First look for a match for START that goes across POS.
3830 (while (and (not (bobp)) (> (point) (- pos
(length start
)))
3831 (not (looking-at start
)))
3833 ;; If we did not find one, search back for START
3834 ;; (this finds only matches that end at or before POS).
3835 (or (looking-at start
)
3838 (re-search-backward start
(max (point-min) (- pos
200)) 'yes
)))
3840 (while (and (re-search-forward all
(min (point-max) (+ pos
200)) 'yes
)
3841 (not (setq found
(and (<= (match-beginning 0) pos
)
3842 (> (match-end 0) pos
))))))
3843 (if (and found
(<= (match-beginning 0) pos
)
3844 (> (match-end 0) pos
))
3845 (match-string-no-properties 1)
3846 (cond ((null errorstring
)
3852 (error "No %s around position %d" errorstring pos
))))))))
3854 (defun Info-mouse-follow-nearest-node (click)
3855 "\\<Info-mode-map>Follow a node reference near point.
3856 Like \\[Info-menu], \\[Info-follow-reference], \\[Info-next], \\[Info-prev] or \\[Info-up] command, depending on where you click.
3857 At end of the node's text, moves to the next node, or up if none."
3859 (mouse-set-point click
)
3860 (and (not (Info-follow-nearest-node))
3861 (save-excursion (forward-line 1) (eobp))
3862 (Info-next-preorder)))
3864 (defun Info-follow-nearest-node (&optional fork
)
3865 "Follow a node reference near point.
3866 If point is on a reference, follow that reference. Otherwise,
3867 if point is in a menu item description, follow that menu item.
3869 If FORK is non-nil (interactively with a prefix arg), show the node in
3871 If FORK is a string, it is the name to use for the new buffer."
3873 (or (Info-try-follow-nearest-node fork
)
3874 (when (save-excursion
3875 (search-backward "\n* menu:" nil t
))
3878 (while (not (or (bobp) (looking-at "[^ \t]\\|[ \t]*$")))
3879 (beginning-of-line 0))
3880 (when (looking-at "\\* +\\([^\t\n]*\\):")
3882 (Info-extract-menu-item (match-string-no-properties 1)) fork
)
3884 (and (eq this-command
'Info-mouse-follow-nearest-node
)
3885 ;; Don't raise an error when mouse-1 is bound to this - it's
3886 ;; often used to simply select the window or frame.
3887 (eq 'mouse-1
(event-basic-type last-input-event
)))
3888 (user-error "Point neither on reference nor in menu item description")))
3890 ;; Common subroutine.
3891 (defun Info-try-follow-nearest-node (&optional fork
)
3892 "Follow a node reference near point. Return non-nil if successful.
3893 If FORK is non-nil, it is passed to `Info-goto-node'."
3896 ((setq node
(Info-get-token (point) "[hf]t?tps?://"
3897 "\\([hf]t?tps?://[^ \t\n\"`‘({<>})’']+\\)"))
3900 ((setq node
(Info-get-token (point) "\\*note[ \n\t]+"
3901 "\\*note[ \n\t]+\\([^:]*\\):\\(:\\|[ \n\t]*(\\)?"))
3902 (Info-follow-reference node fork
))
3904 ((setq node
(Info-get-token (point) "(" "\\(([0-9]+)\\)"))
3905 (let ((old-point (point)) new-point
)
3907 (goto-char (point-min))
3908 (when (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t
)
3909 (setq new-point
(if (< old-point
(point))
3910 ;; Go to footnote reference
3911 (and (search-forward node nil t
)
3912 ;; Put point at beginning of link
3913 (match-beginning 0))
3914 ;; Go to footnote definition
3915 (search-backward node nil t
)))))
3918 (goto-char new-point
)
3921 ;; menu item: node name
3922 ((setq node
(Info-get-token (point) "\\* +" "\\* +\\([^:]*\\)::"))
3923 (Info-goto-node node fork
))
3924 ;; menu item: node name or index entry
3925 ((Info-get-token (point) "\\* +" "\\* +\\(.*\\): ")
3928 (setq node
(Info-extract-menu-node-name nil
(Info-index-node)))
3929 (Info-goto-node node fork
))
3930 ((setq node
(Info-get-token (point) "Up: " "Up: \\([^,\n\t]*\\)"))
3931 (Info-goto-node node fork
))
3932 ((setq node
(Info-get-token (point) "Next: " "Next: \\([^,\n\t]*\\)"))
3933 (Info-goto-node node fork
))
3934 ((setq node
(Info-get-token (point) "File: " "File: \\([^,\n\t]*\\)"))
3935 (Info-goto-node "Top" fork
))
3936 ((setq node
(Info-get-token (point) "Prev: " "Prev: \\([^,\n\t]*\\)"))
3937 (Info-goto-node node fork
)))
3940 (defun Info-mouse-follow-link (click)
3941 "Follow a link where you click."
3943 (let* ((position (event-start click
))
3944 (posn-string (and position
(posn-string position
)))
3945 (link-args (if posn-string
3946 (get-text-property (cdr posn-string
)
3949 (get-char-property (posn-point position
)
3951 (cond ((stringp link-args
)
3952 (Info-goto-node link-args
))
3953 ;; These special values of the `link-args' property are used
3954 ;; for navigation; see `Info-fontify-node'.
3955 ((eq link-args
'prev
) (Info-prev))
3956 ((eq link-args
'next
) (Info-next))
3957 ((eq link-args
'up
) (Info-up)))))
3960 (defvar Info-mode-map
3961 (let ((map (make-keymap)))
3962 (suppress-keymap map
)
3963 (define-key map
"." 'beginning-of-buffer
)
3964 (define-key map
" " 'Info-scroll-up
)
3965 (define-key map
[?\S-\
] 'Info-scroll-down
)
3966 (define-key map
"\C-m" 'Info-follow-nearest-node
)
3967 (define-key map
"\t" 'Info-next-reference
)
3968 (define-key map
"\e\t" 'Info-prev-reference
)
3969 (define-key map
[backtab] 'Info-prev-reference)
3970 (define-key map "1" 'Info-nth-menu-item)
3971 (define-key map "2" 'Info-nth-menu-item)
3972 (define-key map "3" 'Info-nth-menu-item)
3973 (define-key map "4" 'Info-nth-menu-item)
3974 (define-key map "5" 'Info-nth-menu-item)
3975 (define-key map "6" 'Info-nth-menu-item)
3976 (define-key map "7" 'Info-nth-menu-item)
3977 (define-key map "8" 'Info-nth-menu-item)
3978 (define-key map "9" 'Info-nth-menu-item)
3979 (define-key map "0" 'undefined)
3980 (define-key map "?" 'Info-summary)
3981 (define-key map "]" 'Info-forward-node)
3982 (define-key map "[" 'Info-backward-node)
3983 (define-key map "<" 'Info-top-node)
3984 (define-key map ">" 'Info-final-node)
3985 (define-key map "b" 'beginning-of-buffer)
3986 (put 'beginning-of-buffer :advertised-binding "b")
3987 (define-key map "d" 'Info-directory)
3988 (define-key map "e" 'end-of-buffer)
3989 (define-key map "f" 'Info-follow-reference)
3990 (define-key map "g" 'Info-goto-node)
3991 (define-key map "h" 'Info-help)
3992 ;; This is for compatibility with standalone info (>~ version 5.2).
3993 ;; Though for some time, standalone info had H and h reversed.
3994 ;; See <http://debbugs.gnu.org/16455>.
3995 (define-key map "H" 'describe-mode)
3996 (define-key map "i" 'Info-index)
3997 (define-key map "I" 'Info-virtual-index)
3998 (define-key map "l" 'Info-history-back)
3999 (define-key map "L" 'Info-history)
4000 (define-key map "m" 'Info-menu)
4001 (define-key map "n" 'Info-next)
4002 (define-key map "p" 'Info-prev)
4003 (define-key map "q" 'Info-exit)
4004 (define-key map "r" 'Info-history-forward)
4005 (define-key map "s" 'Info-search)
4006 (define-key map "S" 'Info-search-case-sensitively)
4007 (define-key map "\M-n" 'clone-buffer)
4008 (define-key map "t" 'Info-top-node)
4009 (define-key map "T" 'Info-toc)
4010 (define-key map "u" 'Info-up)
4011 ;; `w' for consistency with `dired-copy-filename-as-kill'.
4012 (define-key map "w" 'Info-copy-current-node-name)
4013 (define-key map "c" 'Info-copy-current-node-name)
4014 ;; `^' for consistency with `dired-up-directory'.
4015 (define-key map "^" 'Info-up)
4016 (define-key map "," 'Info-index-next)
4017 (define-key map "\177" 'Info-scroll-down)
4018 (define-key map [mouse-2] 'Info-mouse-follow-nearest-node)
4019 (define-key map [follow-link] 'mouse-face)
4020 (define-key map [XF86Back] 'Info-history-back)
4021 (define-key map [XF86Forward] 'Info-history-forward)
4023 "Keymap containing Info commands.")
4026 (defun Info-check-pointer (item)
4027 "Non-nil if ITEM is present in this node."
4029 (Info-extract-pointer item)
4033 Info-mode-menu Info-mode-map
4034 "Menu for Info files."
4036 ["Up" Info-up :active (Info-check-pointer "up")
4037 :help "Go up in the Info tree"]
4038 ["Next" Info-next :active (Info-check-pointer "next")
4039 :help "Go to the next node"]
4040 ["Previous" Info-prev :active (Info-check-pointer "prev[ious]*")
4041 :help "Go to the previous node"]
4042 ["Backward" Info-backward-node
4043 :help "Go backward one node, considering all as a sequence"]
4044 ["Forward" Info-forward-node
4045 :help "Go forward one node, considering all as a sequence"]
4046 ["Beginning" beginning-of-buffer
4047 :help "Go to beginning of this node"]
4048 ["Top" Info-top-node
4049 :help "Go to top node of file"]
4050 ["Final Node" Info-final-node
4051 :help "Go to final node in this file"]
4052 ("Menu Item" ["You should never see this" report-emacs-bug t])
4053 ("Reference" ["You should never see this" report-emacs-bug t])
4054 ["Search..." Info-search
4055 :help "Search for regular expression in this Info file"]
4056 ["Search Next" Info-search-next
4057 :help "Search for another occurrence of regular expression"]
4058 ["Go to Node..." Info-goto-node
4059 :help "Go to a named node"]
4060 ["Back in history" Info-history-back :active Info-history
4061 :help "Go back in history to the last node you were at"]
4062 ["Forward in history" Info-history-forward :active Info-history-forward
4063 :help "Go forward in history"]
4064 ["History" Info-history :active Info-history-list
4065 :help "Go to menu of visited nodes"]
4066 ["Table of Contents" Info-toc
4067 :help "Go to table of contents"]
4069 ["Lookup a String..." Info-index
4070 :help "Look for a string in the index items"]
4071 ["Next Matching Item" Info-index-next :active Info-index-alternatives
4072 :help "Look for another occurrence of previous item"]
4073 ["Lookup a string and display index of results..." Info-virtual-index
4074 :help "Look for a string in the index items and display node with results"]
4075 ["Lookup a string in all indices..." info-apropos
4076 :help "Look for a string in the indices of all manuals"])
4077 ["Copy Node Name" Info-copy-current-node-name
4078 :help "Copy the name of the current node into the kill ring"]
4079 ["Clone Info buffer" clone-buffer
4080 :help "Create a twin copy of the current Info buffer."]
4081 ["Exit" Info-exit :help "Stop reading Info"]))
4084 (defvar info-tool-bar-map
4085 (let ((map (make-sparse-keymap)))
4086 (tool-bar-local-item-from-menu 'Info-history-back "left-arrow" map Info-mode-map
4090 (tool-bar-local-item-from-menu 'Info-history-forward "right-arrow" map Info-mode-map
4094 (define-key-after map [separator-1] menu-bar-separator)
4095 (tool-bar-local-item-from-menu 'Info-prev "prev-node" map Info-mode-map
4097 (tool-bar-local-item-from-menu 'Info-next "next-node" map Info-mode-map
4099 (tool-bar-local-item-from-menu 'Info-up "up-node" map Info-mode-map
4101 (define-key-after map [separator-2] menu-bar-separator)
4102 (tool-bar-local-item-from-menu 'Info-top-node "home" map Info-mode-map
4104 (tool-bar-local-item-from-menu 'Info-goto-node "jump-to" map Info-mode-map)
4105 (define-key-after map [separator-3] menu-bar-separator)
4106 (tool-bar-local-item-from-menu 'Info-index "index" map Info-mode-map
4108 (tool-bar-local-item-from-menu 'Info-search "search" map Info-mode-map
4110 (tool-bar-local-item-from-menu 'Info-exit "exit" map Info-mode-map
4114 (defvar Info-menu-last-node nil)
4115 ;; Last node the menu was created for.
4116 ;; Value is a list, (FILE-NAME NODE-NAME).
4118 (defun Info-menu-update ()
4119 "Update the Info menu for the current node."
4121 (if (or (not (derived-mode-p 'Info-mode))
4122 (equal (list Info-current-file Info-current-node)
4123 Info-menu-last-node))
4125 ;; Update menu menu.
4126 (let* ((Info-complete-menu-buffer (current-buffer))
4127 (items (nreverse (condition-case nil
4128 (Info-complete-menu-item "" nil t)
4132 (while (and items (< number 9))
4133 (setq current (car items)
4136 (setq entries (cons `[,current
4137 (Info-menu ,current)
4138 :keys ,(format "%d" number)]
4141 (setq entries (cons ["Other..." Info-menu t] entries)))
4143 (setq entries (list ["No menu" nil nil] nil :active)))
4144 (easy-menu-change '("Info") "Menu Item" (nreverse entries)))
4145 ;; Update reference menu. Code stolen from `Info-follow-reference'.
4147 str i entries current
4149 (case-fold-search t))
4151 (goto-char (point-min))
4152 (while (re-search-forward "\\*note[ \n\t]+\\([^:]*\\):" nil t)
4153 (setq str (match-string 1))
4155 (while (setq i (string-match "[ \n\t]+" str i))
4156 (setq str (concat (substring str 0 i) " "
4157 (substring str (match-end 0))))
4161 (while (and items (< number 9))
4162 (setq current (car items)
4165 (setq entries (cons `[,current
4166 (Info-follow-reference ,current)
4170 (setq entries (cons ["Other..." Info-follow-reference t]
4173 (setq entries (list ["No references" nil nil] nil :active)))
4174 (easy-menu-change '("Info") "Reference" (nreverse entries)))
4175 ;; Update last seen node.
4176 (setq Info-menu-last-node (list Info-current-file Info-current-node)))
4177 ;; Try to avoid entering infinite beep mode in case of errors.
4181 (defun Info-copy-current-node-name (&optional arg)
4182 "Put the name of the current Info node into the kill ring.
4183 The name of the Info file is prepended to the node name in parentheses.
4184 With a zero prefix arg, put the name inside a function call to `info'."
4186 (unless Info-current-node
4187 (user-error "No current Info node"))
4188 (let ((node (if (stringp Info-current-file)
4189 (concat "(" (file-name-sans-extension
4190 (file-name-nondirectory Info-current-file))
4192 Info-current-node))))
4193 (if (zerop (prefix-numeric-value arg))
4194 (setq node (concat "(info \"" node "\")")))
4195 (unless (stringp Info-current-file)
4196 (setq node (format "(Info-find-node '%S '%S)"
4197 Info-current-file Info-current-node)))
4199 (message "%s" node)))
4202 ;; Info mode is suitable only for specially formatted data.
4203 (put 'Info-mode 'mode-class 'special)
4204 (put 'Info-mode 'no-clone-indirect t)
4206 (defvar tool-bar-map)
4207 (defvar bookmark-make-record-function)
4209 (defvar Info-mode-syntax-table
4210 (let ((st (copy-syntax-table text-mode-syntax-table)))
4211 ;; Use punctuation syntax for apostrophe because of
4212 ;; extensive use of quotes like `this' in Info manuals.
4213 (modify-syntax-entry ?' "." st)
4215 "Syntax table used in `Info-mode'.")
4217 (defface Info-quoted
4218 '((t :family "courier"))
4219 "Face used for quoted elements.")
4221 (defvar Info-mode-font-lock-keywords
4222 '(("‘\\([^’]*\\)’" (1 'Info-quoted))))
4224 ;; Autoload cookie needed by desktop.el
4226 (define-derived-mode Info-mode nil "Info" ;FIXME: Derive from special-mode?
4227 "Info mode provides commands for browsing through the Info documentation tree.
4228 Documentation in Info is divided into \"nodes\", each of which discusses
4229 one topic and contains references to other nodes which discuss related
4230 topics. Info has commands to follow the references and show you other nodes.
4233 \\[Info-help] Invoke the Info tutorial.
4234 \\[Info-exit] Quit Info: reselect previously selected buffer.
4236 Selecting other nodes:
4237 \\[Info-mouse-follow-nearest-node]
4238 Follow a node reference you click on.
4239 This works with menu items, cross references, and
4240 the \"next\", \"previous\" and \"up\", depending on where you click.
4241 \\[Info-follow-nearest-node] Follow a node reference near point, like \\[Info-mouse-follow-nearest-node].
4242 \\[Info-next] Move to the \"next\" node of this node.
4243 \\[Info-prev] Move to the \"previous\" node of this node.
4244 \\[Info-up] Move \"up\" from this node.
4245 \\[Info-menu] Pick menu item specified by name (or abbreviation).
4246 Picking a menu item causes another node to be selected.
4247 \\[Info-directory] Go to the Info directory node.
4248 \\[Info-top-node] Go to the Top node of this file.
4249 \\[Info-final-node] Go to the final node in this file.
4250 \\[Info-backward-node] Go backward one node, considering all nodes as forming one sequence.
4251 \\[Info-forward-node] Go forward one node, considering all nodes as forming one sequence.
4252 \\[Info-next-reference] Move cursor to next cross-reference or menu item.
4253 \\[Info-prev-reference] Move cursor to previous cross-reference or menu item.
4254 \\[Info-follow-reference] Follow a cross reference. Reads name of reference.
4255 \\[Info-history-back] Move back in history to the last node you were at.
4256 \\[Info-history-forward] Move forward in history to the node you returned from after using \\[Info-history-back].
4257 \\[Info-history] Go to menu of visited nodes.
4258 \\[Info-toc] Go to table of contents of the current Info file.
4260 Moving within a node:
4261 \\[Info-scroll-up] Normally, scroll forward a full screen.
4262 Once you scroll far enough in a node that its menu appears on the
4263 screen but after point, the next scroll moves into its first
4264 subnode. When after all menu items (or if there is no menu),
4265 move up to the parent node.
4266 \\[Info-scroll-down] Normally, scroll backward. If the beginning of the buffer is
4267 already visible, try to go to the previous menu entry, or up
4269 \\[beginning-of-buffer] Go to beginning of node.
4272 \\[Info-search] Search through this Info file for specified regexp,
4273 and select the node in which the next occurrence is found.
4274 \\[Info-search-case-sensitively] Search through this Info file for specified regexp case-sensitively.
4275 \\[isearch-forward], \\[isearch-forward-regexp] Use Isearch to search through multiple Info nodes.
4276 \\[Info-index] Search for a topic in this manual's Index and go to index entry.
4277 \\[Info-index-next] (comma) Move to the next match from a previous \\<Info-mode-map>\\[Info-index] command.
4278 \\[Info-virtual-index] Look for a string and display the index node with results.
4279 \\[info-apropos] Look for a string in the indices of all manuals.
4280 \\[Info-goto-node] Move to node specified by name.
4281 You may include a filename as well, as (FILENAME)NODENAME.
4282 1 .. 9 Pick first ... ninth item in node's menu.
4283 Every third `*' is highlighted to help pick the right number.
4284 \\[Info-copy-current-node-name] Put name of current Info node in the kill ring.
4285 \\[clone-buffer] Select a new cloned Info buffer in another window.
4286 \\[universal-argument] \\[info] Move to new Info file with completion.
4287 \\[universal-argument] N \\[info] Select Info buffer with prefix number in the name *info*<N>."
4288 :syntax-table Info-mode-syntax-table
4289 :abbrev-table text-mode-abbrev-table
4291 (add-hook 'activate-menubar-hook 'Info-menu-update nil t)
4292 (setq case-fold-search t)
4293 (setq buffer-read-only t)
4294 (setq Info-tag-table-marker (make-marker))
4295 (if Info-use-header-line ; do not override global header lines
4296 (setq header-line-format
4297 '(:eval (get-text-property (point-min) 'header-line))))
4298 (setq-local tool-bar-map info-tool-bar-map)
4299 ;; This is for the sake of the invisible text we use handling titles.
4300 (setq-local line-move-ignore-invisible t)
4301 (setq-local desktop-save-buffer 'Info-desktop-buffer-misc-data)
4302 (setq-local widen-automatically nil)
4303 (add-hook 'kill-buffer-hook 'Info-kill-buffer nil t)
4304 (add-hook 'clone-buffer-hook 'Info-clone-buffer nil t)
4305 (add-hook 'change-major-mode-hook 'font-lock-defontify nil t)
4306 (add-hook 'isearch-mode-hook 'Info-isearch-start nil t)
4307 (setq-local isearch-search-fun-function #'Info-isearch-search)
4308 (setq-local isearch-wrap-function #'Info-isearch-wrap)
4309 (setq-local isearch-push-state-function #'Info-isearch-push-state)
4310 (setq-local isearch-filter-predicate #'Info-isearch-filter)
4311 (setq-local revert-buffer-function #'Info-revert-buffer-function)
4312 (setq-local font-lock-defaults '(Info-mode-font-lock-keywords t t))
4313 (Info-set-mode-line)
4314 (setq-local bookmark-make-record-function #'Info-bookmark-make-record))
4316 ;; When an Info buffer is killed, make sure the associated tags buffer
4318 (defun Info-kill-buffer ()
4319 (and (derived-mode-p 'Info-mode)
4320 Info-tag-table-buffer
4321 (kill-buffer Info-tag-table-buffer)))
4323 ;; Placed on `clone-buffer-hook'.
4324 (defun Info-clone-buffer ()
4325 (when (bufferp Info-tag-table-buffer)
4326 (setq Info-tag-table-buffer
4327 (with-current-buffer Info-tag-table-buffer (clone-buffer))))
4328 (let ((m Info-tag-table-marker))
4330 (setq Info-tag-table-marker
4331 (if (and (marker-position m) (bufferp Info-tag-table-buffer))
4332 (with-current-buffer Info-tag-table-buffer
4333 (copy-marker (marker-position m)))
4336 (define-obsolete-variable-alias 'Info-edit-map 'Info-edit-mode-map "24.1")
4337 (defvar Info-edit-mode-map (let ((map (make-sparse-keymap)))
4338 (set-keymap-parent map text-mode-map)
4339 (define-key map "\C-c\C-c" 'Info-cease-edit)
4341 "Local keymap used within `e' command of Info.")
4343 (make-obsolete-variable 'Info-edit-mode-map
4344 "editing Info nodes by hand is not recommended."
4347 ;; Info-edit mode is suitable only for specially formatted data.
4348 (put 'Info-edit-mode 'mode-class 'special)
4350 (define-derived-mode Info-edit-mode text-mode "Info Edit"
4351 "Major mode for editing the contents of an Info node.
4352 Like text mode with the addition of `Info-cease-edit'
4353 which returns to Info mode for browsing."
4354 (setq buffer-read-only nil)
4355 (force-mode-line-update)
4356 (buffer-enable-undo (current-buffer)))
4358 (make-obsolete 'Info-edit-mode
4359 "editing Info nodes by hand is not recommended." "24.4")
4362 "Edit the contents of this Info node."
4365 (message "%s" (substitute-command-keys
4366 "Editing: Type \\<Info-edit-mode-map>\\[Info-cease-edit] to return to info")))
4368 (put 'Info-edit 'disabled "Editing Info nodes by hand is not recommended.
4369 This feature will be removed in future.")
4371 (make-obsolete 'Info-edit
4372 "editing Info nodes by hand is not recommended." "24.4")
4374 (defun Info-cease-edit ()
4375 "Finish editing Info node; switch back to Info proper."
4377 ;; Do this first, so nothing has changed if user C-g's at query.
4378 (and (buffer-modified-p)
4379 (y-or-n-p "Save the file? ")
4382 (force-mode-line-update)
4383 (and (marker-position Info-tag-table-marker)
4385 (message "Tags may have changed. Use Info-tagify if necessary")))
4387 (make-obsolete 'Info-cease-edit
4388 "editing Info nodes by hand is not recommended." "24.4")
4390 (defvar Info-file-list-for-emacs
4391 '("ediff" "eudc" "forms" "gnus" "info" ("Info" . "info") ("mh" . "mh-e")
4392 "sc" "message" ("dired" . "dired-x") "viper" "vip" "idlwave"
4393 ("c" . "ccmode") ("c++" . "ccmode") ("objc" . "ccmode")
4394 ("java" . "ccmode") ("idl" . "ccmode") ("pike" . "ccmode")
4395 ("skeleton" . "autotype") ("auto-insert" . "autotype")
4396 ("copyright" . "autotype") ("executable" . "autotype")
4397 ("time-stamp" . "autotype") ("quickurl" . "autotype")
4398 ("tempo" . "autotype") ("hippie-expand" . "autotype")
4399 ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
4400 ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
4401 "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
4402 ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
4403 ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
4404 ("rfc2045" . "emacs-mime")
4405 ("rfc2231" . "emacs-mime") ("rfc2047" . "emacs-mime")
4406 ("rfc2045" . "emacs-mime") ("rfc1843" . "emacs-mime")
4407 ("ietf-drums" . "emacs-mime") ("quoted-printable" . "emacs-mime")
4408 ("binhex" . "emacs-mime") ("uudecode" . "emacs-mime")
4409 ("mailcap" . "emacs-mime") ("mm" . "emacs-mime")
4410 ("mml" . "emacs-mime")
4412 "List of Info files that describe Emacs commands.
4413 An element can be a file name, or a list of the form (PREFIX . FILE)
4414 where PREFIX is a name prefix and FILE is the file to look in.
4415 If the element is just a file name, the file name also serves as the prefix.")
4417 (defun Info-find-emacs-command-nodes (command)
4418 "Return a list of locations documenting COMMAND.
4419 The `info-file' property of COMMAND says which Info manual to search.
4420 If COMMAND has no property, the variable `Info-file-list-for-emacs'
4421 defines heuristics for which Info manual to try.
4422 The locations are of the format used in the variable `Info-history', i.e.
4423 \(FILENAME NODENAME BUFFERPOS), where BUFFERPOS is the line number
4424 in the first element of the returned list (which is treated specially in
4425 `Info-goto-emacs-command-node'), and 0 for the rest elements of a list."
4426 (let ((where '()) line-number
4427 (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
4428 "\\( <[0-9]+>\\)?:\\s *\\(.*\\)\\."
4429 "\\(?:[ \t\n]+(line +\\([0-9]+\\))\\)?"))
4430 (info-file "emacs")) ;default
4431 ;; Determine which Info file this command is documented in.
4432 (if (get command 'info-file)
4433 (setq info-file (get command 'info-file))
4434 ;; If it doesn't say explicitly, test its name against
4435 ;; various prefixes that we know.
4436 (let ((file-list Info-file-list-for-emacs))
4438 (let* ((elt (car file-list))
4439 (name (if (consp elt)
4442 (file (if (consp elt) (cdr elt) elt))
4443 (case-fold-search nil)
4444 (regexp (concat "\\`" (regexp-quote name)
4446 (if (string-match regexp (symbol-name command))
4447 (setq info-file file file-list nil))
4448 (setq file-list (cdr file-list))))))
4449 (Info-find-node info-file "Top")
4450 ;; Bind Info-history to nil, to prevent the index nodes from
4451 ;; getting into the node history.
4452 (let ((Info-history nil)
4453 (Info-history-list nil)
4454 node (nodes (Info-index-nodes)))
4455 (Info-goto-node (car nodes))
4458 (goto-char (point-min))
4459 (while (re-search-forward cmd-desc nil t)
4461 (cons (list Info-current-file
4462 (match-string-no-properties 2)
4465 (setq line-number (and (match-beginning 3)
4466 (string-to-number (match-string 3)))))
4467 (and (setq nodes (cdr nodes) node (car nodes))))
4468 (Info-goto-node node)))
4469 (if (and line-number where)
4470 (cons (list (nth 0 (car where)) (nth 1 (car where)) line-number)
4474 ;;;###autoload (put 'Info-goto-emacs-command-node 'info-file (purecopy "emacs"))
4476 (defun Info-goto-emacs-command-node (command)
4477 "Go to the Info node in the Emacs manual for command COMMAND.
4478 The command is found by looking up in Emacs manual's indices
4479 or in another manual found via COMMAND's `info-file' property or
4480 the variable `Info-file-list-for-emacs'.
4481 COMMAND must be a symbol or string."
4482 (interactive "CFind documentation for command: ")
4483 ;; If command is given as a string, convert it to a symbol.
4484 (if (stringp command)
4485 (setq command (intern command)))
4486 (or (commandp command)
4487 (signal 'wrong-type-argument (list 'commandp command)))
4488 (let ((where (Info-find-emacs-command-nodes command)))
4490 (let ((num-matches (length where)))
4491 ;; Get Info running, and pop to it in another window.
4492 (save-window-excursion
4494 (or (derived-mode-p 'Info-mode) (pop-to-buffer "*info*"))
4495 ;; Bind Info-history to nil, to prevent the last Index node
4496 ;; visited by Info-find-emacs-command-nodes from being
4497 ;; pushed onto the history.
4498 (let ((Info-history nil) (Info-history-list nil)
4499 (line-number (nth 2 (car where))))
4500 (Info-find-node (nth 0 (car where)) (nth 1 (car where)))
4501 (if (and (integerp line-number) (> line-number 0))
4502 (forward-line (1- line-number))))
4503 (if (> num-matches 1)
4505 ;; (car where) will be pushed onto Info-history
4506 ;; when/if they go to another node. Put the other
4507 ;; nodes that were found on the history.
4508 (setq Info-history (nconc (cdr where) Info-history))
4509 (message "Found %d other entr%s. Use %s to see %s."
4511 (if (> num-matches 2) "ies" "y")
4512 (substitute-command-keys "\\[Info-history-back]")
4513 (if (> num-matches 2) "them" "it")))))
4514 (error "Couldn't find documentation for %s" command))))
4516 ;;;###autoload (put 'Info-goto-emacs-key-command-node 'info-file (purecopy "emacs"))
4518 (defun Info-goto-emacs-key-command-node (key)
4519 "Go to the node in the Emacs manual which describes the command bound to KEY.
4521 Interactively, if the binding is `execute-extended-command', a command is read.
4522 The command is found by looking up in Emacs manual's indices
4523 or in another manual found via COMMAND's `info-file' property or
4524 the variable `Info-file-list-for-emacs'."
4525 (interactive "kFind documentation for key: ")
4526 (let ((command (key-binding key)))
4527 (cond ((null command)
4528 (message "%s is undefined" (key-description key)))
4529 ((and (called-interactively-p 'interactive)
4530 (eq command 'execute-extended-command))
4531 (Info-goto-emacs-command-node
4532 (read-command "Find documentation for command: ")))
4534 (Info-goto-emacs-command-node command)))))
4536 (defvar Info-link-keymap
4537 (let ((keymap (make-sparse-keymap)))
4538 (define-key keymap [header-line down-mouse-1] 'mouse-drag-header-line)
4539 (define-key keymap [header-line mouse-1] 'mouse-select-window)
4540 (define-key keymap [header-line mouse-2] 'Info-mouse-follow-link)
4541 (define-key keymap [mouse-2] 'Info-mouse-follow-link)
4542 (define-key keymap [follow-link] 'mouse-face)
4544 "Keymap to put on Info links.
4545 This is used for the \"Next\", \"Prev\", and \"Up\" links in the
4546 first line or header line, and for breadcrumb links.")
4548 (defun Info-breadcrumbs ()
4549 (let ((nodes (Info-toc-nodes Info-current-file))
4550 (node Info-current-node)
4552 (depth Info-breadcrumbs-depth)
4555 ;; Get ancestors from the cached parent-children node info
4556 (while (and (not (equal "Top" node)) (> depth 0))
4557 (setq node (nth 1 (assoc node nodes)))
4558 (if node (push node crumbs))
4559 (setq depth (1- depth)))
4562 (when Info-use-header-line
4563 ;; Let it disappear if crumbs is nil.
4564 (nconc crumbs (list Info-current-node)))
4565 (when (or Info-use-header-line crumbs)
4566 ;; Add top node (and continuation if needed).
4568 (cons "Top" (if (member (pop crumbs) '(nil "Top"))
4569 crumbs (cons nil crumbs))))
4570 ;; Eliminate duplicate.
4572 (dolist (node crumbs)
4574 (if (not (equal node "Top")) node
4576 (if (stringp Info-current-file)
4577 (file-name-sans-extension
4578 (file-name-nondirectory Info-current-file))
4579 ;; Some legacy code can still use a symbol.
4580 Info-current-file)))))
4583 (if (null line) "" " > ")
4586 ((equal node Info-current-node)
4587 ;; No point linking to ourselves.
4588 (propertize text 'font-lock-face 'info-header-node))
4591 'mouse-face 'highlight
4592 'font-lock-face 'info-header-xref
4593 'help-echo "mouse-2: Go to node"
4594 'keymap Info-link-keymap
4595 'link-args text)))))))
4596 (setq line (concat line "\n")))
4597 ;; (font-lock-append-text-property 0 (length line)
4598 ;; 'font-lock-face 'header-line line)
4601 (defun Info-fontify-node ()
4604 (let* ((inhibit-read-only t)
4605 (case-fold-search t)
4607 (not-fontified-p ; the node hasn't already been fontified
4608 (not (let ((where (next-single-property-change (point-min)
4610 (and where (not (= where (point-max)))))))
4611 (fontify-visited-p ; visited nodes need to be re-fontified
4612 (and Info-fontify-visited-nodes
4613 ;; Don't take time to refontify visited nodes in huge nodes
4614 Info-fontify-maximum-menu-size
4615 (or (eq Info-fontify-maximum-menu-size t)
4616 (< (- (point-max) (point-min))
4617 Info-fontify-maximum-menu-size))))
4620 ;; Fontify header line
4621 (goto-char (point-min))
4622 (when (and not-fontified-p (looking-at "^\\(File: [^,: \t]+,?[ \t]+\\)?"))
4623 (goto-char (match-end 0))
4624 (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
4625 (goto-char (match-end 0))
4626 (let* ((nbeg (match-beginning 2))
4627 (nend (match-end 2))
4628 (tbeg (match-beginning 1))
4629 (tag (match-string 1)))
4630 (if (string-equal (downcase tag) "node")
4631 (put-text-property nbeg nend 'font-lock-face 'info-header-node)
4632 (put-text-property nbeg nend 'font-lock-face 'info-header-xref)
4633 (put-text-property tbeg nend 'mouse-face 'highlight)
4634 (put-text-property tbeg nend
4636 (concat "mouse-2: Go to node "
4637 (buffer-substring nbeg nend)))
4638 ;; Set up the text property keymap. Depending on
4639 ;; `Info-use-header-line', it is either used in the
4640 ;; buffer, or copied to the header line. A symbol value
4641 ;; of the `link-args' property is handled specially by
4642 ;; `Info-mouse-follow-link'.
4643 (put-text-property tbeg nend 'keymap Info-link-keymap)
4644 (put-text-property tbeg nend 'link-args
4645 (intern (downcase tag))))))
4647 ;; (when (> Info-breadcrumbs-depth 0)
4648 ;; (insert (Info-breadcrumbs)))
4650 ;; Treat header line.
4651 (when Info-use-header-line
4652 (goto-char (point-min))
4653 (let* ((header-end (line-end-position))
4655 ;; If we find neither Next: nor Prev: link, show the entire
4656 ;; node header. Otherwise, don't show the File: and Node:
4657 ;; parts, to avoid wasting precious space on information that
4658 ;; is available in the mode line.
4659 (if (re-search-forward
4660 "\\(next\\|up\\|prev[ious]*\\): "
4663 (goto-char (match-beginning 1))
4664 (buffer-substring (point) header-end))
4665 (if (re-search-forward "node:[ \t]*[^ \t]+[ \t]*"
4667 (concat "No next, prev or up links -- "
4668 (buffer-substring (point) header-end))
4669 (buffer-substring (point) header-end)))))
4670 (put-text-property (point-min) (1+ (point-min))
4672 (replace-regexp-in-string
4674 ;; Preserve text properties on duplicated `%'.
4675 (lambda (s) (concat s s)) header))
4676 ;; Hide the part of the first line
4677 ;; that is in the header, if it is just part.
4679 ((> Info-breadcrumbs-depth 0)
4680 (let ((ov (make-overlay (point-min) (1+ header-end))))
4681 (overlay-put ov 'display (Info-breadcrumbs))
4682 (overlay-put ov 'evaporate t)))
4684 ;; Hide the punctuation at the end, too.
4685 (skip-chars-backward " \t,")
4686 (put-text-property (point) header-end 'invisible t)
4687 ;; Hide the suffix of the Info file name.
4689 (if (re-search-forward
4690 (format "File: %s\\([^,\n\t]+\\),"
4691 (if (stringp Info-current-file)
4692 (file-name-sans-extension
4693 (file-name-nondirectory Info-current-file))
4696 (put-text-property (match-beginning 1) (match-end 1)
4700 (goto-char (point-min))
4701 (when (and font-lock-mode not-fontified-p)
4702 (while (and (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*\\*+\\|==+\\|--+\\|\\.\\.+\\)$"
4704 ;; Only consider it as an underlined title if the ASCII
4705 ;; underline has the same size as the text. A typical
4706 ;; counter example is when a continuation "..." is alone
4708 (= (string-width (match-string 1))
4709 (string-width (match-string 2))))
4710 (let* ((c (preceding-char))
4712 (cond ((= c ?*) 'info-title-1)
4713 ((= c ?=) 'info-title-2)
4714 ((= c ?-) 'info-title-3)
4715 (t 'info-title-4))))
4716 (put-text-property (match-beginning 1) (match-end 1)
4717 'font-lock-face face))
4718 ;; This is a serious problem for trying to handle multiple
4719 ;; frame types at once. We want this text to be invisible
4720 ;; on frames that can display the font above.
4721 (when (memq (framep (selected-frame)) '(x pc w32 ns))
4722 (add-text-properties (1- (match-beginning 2)) (match-end 2)
4723 '(invisible t front-sticky nil rear-nonsticky t)))))
4725 ;; Fontify cross references
4726 (goto-char (point-min))
4727 (when (or not-fontified-p fontify-visited-p)
4728 (while (re-search-forward "\\(\\*Note[ \n\t]+\\)\\([^:]*\\)\\(:[ \t]*\\([^.,:(]*\\)\\(\\(([^)]*)\\)[^.,:]*\\)?[,:]?\n?\\)" nil t)
4729 (let ((start (match-beginning 0))
4732 (when not-fontified-p
4733 (when Info-hide-note-references
4734 (when (and (not (eq Info-hide-note-references 'hide))
4735 (> (line-number-at-pos) 4)) ; Skip breadcrumbs
4736 ;; *Note is often used where *note should have been
4738 (skip-syntax-backward " ")
4739 (when (memq (char-before) '(?\( ?\[ ?\{))
4740 ;; Check whether the paren is preceded by
4741 ;; an end of sentence
4742 (skip-syntax-backward " ("))
4744 (cond ((save-match-data (looking-back "\\<see"
4747 ((save-match-data (looking-back "\\<in"
4750 ((memq (char-before) '(nil ?\. ?! ??))
4754 (search-forward "\n\n" start t)))
4758 (add-text-properties
4760 (or (save-match-data
4761 ;; Don't hide \n after *Note
4762 (let ((start1 (match-beginning 1)))
4763 (if (string-match "\n" (match-string 1))
4764 (+ start1 (match-beginning 0)))))
4767 `(display ,other-tag front-sticky nil rear-nonsticky t)
4768 '(invisible t front-sticky nil rear-nonsticky t))))
4769 (add-text-properties
4770 (match-beginning 2) (match-end 2)
4772 'help-echo (if (or (match-end 5)
4773 (not (equal (match-string 4) "")))
4774 (concat "mouse-2: go to " (or (match-string 5)
4776 "mouse-2: go to this node")
4777 'mouse-face 'highlight)))
4778 (when (or not-fontified-p fontify-visited-p)
4779 (setq rbeg (match-beginning 2)
4784 ;; Display visited nodes in a different face
4785 (if (and Info-fontify-visited-nodes
4787 (let* ((node (replace-regexp-in-string
4789 (replace-regexp-in-string
4791 (or (match-string-no-properties 5)
4792 (and (not (equal (match-string 4) ""))
4793 (match-string-no-properties 4))
4794 (match-string-no-properties 2)))))
4796 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4797 (file (if external-link-p
4798 (file-name-nondirectory
4799 (match-string-no-properties 1 node))
4801 (hl Info-history-list)
4804 (setq node (if (equal (match-string 2 node) "")
4806 (match-string-no-properties 2 node))))
4808 (if (and (string-equal node (nth 1 (car hl)))
4810 (if (and external-link-p
4811 (stringp (caar hl)))
4812 (file-name-nondirectory
4815 (setq res (car hl) hl nil)
4816 (setq hl (cdr hl))))
4817 res))) 'info-xref-visited 'info-xref))
4818 ;; For multiline ref, unfontify newline and surrounding whitespace
4822 (while (re-search-forward "\\s-*\n\\s-*" rend t nil)
4823 (remove-text-properties (match-beginning 0)
4825 '(font-lock-face t))))))
4826 (when not-fontified-p
4827 (when (memq Info-hide-note-references '(t hide))
4828 (add-text-properties (match-beginning 3) (match-end 3)
4829 '(invisible t front-sticky nil rear-nonsticky t))
4830 ;; Unhide the file name of the external reference in parens
4831 (if (and (match-string 6) (not (eq Info-hide-note-references 'hide)))
4832 (remove-text-properties (match-beginning 6) (match-end 6)
4833 '(invisible t front-sticky nil rear-nonsticky t)))
4834 ;; Unhide newline because hidden newlines cause too long lines
4836 (let ((beg3 (match-beginning 3))
4837 (end3 (match-end 3)))
4838 (if (and (string-match "\n[ \t]*" (match-string 3))
4839 (not (save-match-data
4841 (goto-char (1+ end3))
4842 (looking-at "[.)]*$")))))
4843 (remove-text-properties (+ beg3 (match-beginning 0))
4844 (+ beg3 (match-end 0))
4845 '(invisible t front-sticky nil rear-nonsticky t))))))
4846 (when (and Info-refill-paragraphs Info-hide-note-references)
4847 (push (set-marker (make-marker) start)
4848 paragraph-markers))))))
4850 ;; Refill paragraphs (experimental feature)
4851 (when (and not-fontified-p
4852 Info-refill-paragraphs
4854 (let ((fill-nobreak-invisible t)
4855 (fill-individual-varying-indent nil)
4856 (paragraph-start "\f\\|[ \t]*[-*]\\|[ \t]*$")
4857 (paragraph-separate ".*\\.[ \t]*\n[ \t]\\|[ \t]*[-*]\\|[ \t\f]*$")
4858 (adaptive-fill-mode nil))
4859 (goto-char (point-max))
4860 (dolist (m paragraph-markers)
4864 (let ((beg (point)))
4865 (when (zerop (forward-paragraph))
4866 (fill-individual-paragraphs beg (point) nil nil)
4868 (set-marker m nil))))
4870 ;; Fontify menu items
4871 (goto-char (point-min))
4872 (when (and (or not-fontified-p fontify-visited-p)
4873 (search-forward "\n* Menu:" nil t)
4874 ;; Don't take time to annotate huge menus
4875 Info-fontify-maximum-menu-size
4876 (or (eq Info-fontify-maximum-menu-size t)
4877 (< (- (point-max) (point))
4878 Info-fontify-maximum-menu-size)))
4881 (while (re-search-forward
4882 (concat "^\\* Menu:\\|\\(?:^\\* +\\(" Info-menu-entry-name-re "\\)\\(:"
4883 Info-node-spec-re "\\([ \t]*\\)\\)\\)")
4885 (when (match-beginning 1)
4886 (when not-fontified-p
4888 (if (and (<= n 9) (zerop (% n 3))) ; visual aids to help with 1-9 keys
4889 (put-text-property (match-beginning 0)
4890 (1+ (match-beginning 0))
4891 'font-lock-face 'info-menu-star)))
4892 (when not-fontified-p
4893 (add-text-properties
4894 (match-beginning 1) (match-end 1)
4896 'help-echo (if (and (match-end 3)
4897 (not (equal (match-string 3) "")))
4898 (concat "mouse-2: go to " (match-string 3))
4899 "mouse-2: go to this node")
4900 'mouse-face 'highlight)))
4901 (when (or not-fontified-p fontify-visited-p)
4903 (match-beginning 1) (match-end 1)
4905 ;; Display visited menu items in a different face
4906 (if (and Info-fontify-visited-nodes
4908 (let* ((node (if (equal (match-string 3) "")
4909 (match-string-no-properties 1)
4910 (match-string-no-properties 3)))
4912 (string-match "(\\([^)]+\\))\\([^)]*\\)" node))
4913 (file (if external-link-p
4914 (file-name-nondirectory
4915 (match-string-no-properties 1 node))
4917 (hl Info-history-list)
4920 (setq node (if (equal (match-string 2 node) "")
4922 (match-string-no-properties 2 node))))
4924 (if (and (string-equal node (nth 1 (car hl)))
4926 (if (and external-link-p
4927 (stringp (caar hl)))
4928 (file-name-nondirectory
4931 (setq res (car hl) hl nil)
4932 (setq hl (cdr hl))))
4933 res))) 'info-xref-visited 'info-xref)))
4934 (when (and not-fontified-p
4935 (memq Info-hide-note-references '(t hide))
4936 (not (Info-index-node)))
4937 (put-text-property (match-beginning 2) (1- (match-end 6))
4939 ;; Unhide the file name in parens
4940 (if (and (match-end 4) (not (eq (char-after (match-end 4)) ?.)))
4941 (remove-text-properties (match-beginning 4) (match-end 4)
4943 ;; We need a stretchable space like :align-to but with
4945 (put-text-property (1- (match-end 6)) (match-end 6) 'display
4946 (if (>= 22 (- (match-end 1)
4947 (match-beginning 0)))
4948 '(space :align-to 24)
4950 (setq cont (looking-at "."))
4951 (while (and (= (forward-line 1) 0)
4952 (looking-at "\\([ \t]+\\)[^*\n]"))
4953 (put-text-property (match-beginning 1) (1- (match-end 1))
4955 (put-text-property (1- (match-end 1)) (match-end 1)
4958 '(space :align-to 26)
4959 '(space :align-to 24)))
4962 ;; Fontify menu headers
4963 ;; Add the face `info-menu-header' to any header before a menu entry
4964 (goto-char (point-min))
4965 (when (and not-fontified-p (re-search-forward "^\\* Menu:" nil t))
4966 (put-text-property (match-beginning 0) (match-end 0)
4967 'font-lock-face 'info-menu-header)
4968 (while (re-search-forward "\n\n\\([^*\n ].*\\)\n\n?[*]" nil t)
4969 (put-text-property (match-beginning 1) (match-end 1)
4970 'font-lock-face 'info-menu-header)))
4972 ;; Hide index line numbers
4973 (goto-char (point-min))
4974 (when (and not-fontified-p (Info-index-node))
4975 (while (re-search-forward "[ \t\n]*(line +[0-9]+)" nil t)
4976 (put-text-property (match-beginning 0) (match-end 0)
4979 ;; Fontify http and ftp references
4980 (goto-char (point-min))
4981 (when not-fontified-p
4982 (while (re-search-forward "\\(https?\\|ftp\\)://[^ \t\n\"`‘({<>})’']+"
4984 (add-text-properties (match-beginning 0) (match-end 0)
4985 '(font-lock-face info-xref
4986 mouse-face highlight
4987 help-echo "mouse-2: go to this URL"))))
4989 ;; Fontify footnotes
4990 (goto-char (point-min))
4991 (when (and not-fontified-p (re-search-forward "^[ \t]*-+ Footnotes -+$" nil t))
4992 (let ((limit (point)))
4993 (goto-char (point-min))
4994 (while (re-search-forward "\\(([0-9]+)\\)" nil t)
4995 (add-text-properties (match-beginning 0) (match-end 0)
4996 `(font-lock-face info-xref
4998 mouse-face highlight
5000 ,(if (< (point) limit)
5001 "mouse-2: go to footnote definition"
5002 "mouse-2: go to footnote reference"))))))
5004 ;; Hide empty lines at the end of the node.
5005 (goto-char (point-max))
5006 (skip-chars-backward "\n")
5007 (when (< (point) (1- (point-max)))
5008 (put-text-property (point) (1- (point-max)) 'invisible t))
5010 (set-buffer-modified-p nil))))
5012 ;;; Speedbar support:
5013 ;; These functions permit speedbar to display the "tags" in the
5014 ;; current Info node.
5015 (eval-when-compile (require 'speedbar)) ; for speedbar-with-writable
5017 (declare-function speedbar-add-expansion-list "speedbar" (new-list))
5018 (declare-function speedbar-center-buffer-smartly "speedbar" ())
5019 (declare-function speedbar-change-expand-button-char "speedbar" (char))
5020 (declare-function speedbar-change-initial-expansion-list "speedbar" (new-default))
5021 (declare-function speedbar-delete-subblock "speedbar" (indent))
5022 (declare-function speedbar-make-specialized-keymap "speedbar" ())
5023 (declare-function speedbar-make-tag-line "speedbar"
5024 (exp-button-type exp-button-char exp-button-function
5025 exp-button-data tag-button tag-button-function
5026 tag-button-data tag-button-face depth))
5028 (defvar Info-speedbar-key-map nil
5029 "Keymap used when in the Info display mode.")
5031 (defun Info-install-speedbar-variables ()
5032 "Install those variables used by speedbar to enhance Info."
5033 (if Info-speedbar-key-map
5035 (setq Info-speedbar-key-map (speedbar-make-specialized-keymap))
5037 ;; Basic tree features
5038 (define-key Info-speedbar-key-map "e" 'speedbar-edit-line)
5039 (define-key Info-speedbar-key-map "\C-m" 'speedbar-edit-line)
5040 (define-key Info-speedbar-key-map "+" 'speedbar-expand-line)
5041 (define-key Info-speedbar-key-map "-" 'speedbar-contract-line)
5044 (speedbar-add-expansion-list '("Info" Info-speedbar-menu-items
5045 Info-speedbar-key-map
5046 Info-speedbar-hierarchy-buttons)))
5048 (defvar Info-speedbar-menu-items
5049 '(["Browse Node" speedbar-edit-line t]
5050 ["Expand Node" speedbar-expand-line
5051 (save-excursion (beginning-of-line)
5052 (looking-at "[0-9]+: *.\\+. "))]
5053 ["Contract Node" speedbar-contract-line
5054 (save-excursion (beginning-of-line)
5055 (looking-at "[0-9]+: *.-. "))]
5057 "Additional menu-items to add to speedbar frame.")
5059 ;; Make sure our special speedbar major mode is loaded
5060 (if (featurep 'speedbar)
5061 (Info-install-speedbar-variables)
5062 (add-hook 'speedbar-load-hook 'Info-install-speedbar-variables))
5064 ;;; Info hierarchy display method
5066 (defun Info-speedbar-browser ()
5067 "Initialize speedbar to display an Info node browser.
5068 This will add a speedbar major display mode."
5071 ;; Make sure that speedbar is active
5072 (speedbar-frame-mode 1)
5073 ;; Now, throw us into Info mode on speedbar.
5074 (speedbar-change-initial-expansion-list "Info")
5077 ;; speedbar loads dframe at runtime.
5078 (declare-function dframe-select-attached-frame "dframe" (&optional frame))
5079 (declare-function dframe-current-frame "dframe" (frame-var desired-major-mode))
5081 (defun Info-speedbar-hierarchy-buttons (_directory depth &optional node)
5082 "Display an Info directory hierarchy in speedbar.
5083 DIRECTORY is the current directory in the attached frame.
5084 DEPTH is the current indentation depth.
5085 NODE is an optional argument that is used to represent the
5086 specific node to expand."
5088 (save-excursion (goto-char (point-min))
5089 (let ((case-fold-search t))
5090 (looking-at "Info Nodes:"))))
5091 ;; Update our "current node" maybe?
5093 ;; We cannot use the generic list code, that depends on all leaves
5094 ;; being known at creation time.
5096 (speedbar-with-writable (insert "Info Nodes:\n")))
5097 (let ((completions nil))
5098 (speedbar-select-attached-frame)
5099 (save-window-excursion
5101 (Info-speedbar-fetch-file-nodes (or node '"(dir)top"))))
5102 (select-frame (speedbar-current-frame))
5104 (speedbar-with-writable
5105 (dolist (completion completions)
5106 (speedbar-make-tag-line 'bracket ?+ 'Info-speedbar-expand-node
5109 'Info-speedbar-goto-node
5115 (defun Info-speedbar-goto-node (_text node _indent)
5116 "When user clicks on TEXT, go to an info NODE.
5117 The INDENT level is ignored."
5118 (speedbar-select-attached-frame)
5119 (let* ((buff (or (get-buffer "*info*")
5120 (progn (info) (get-buffer "*info*"))))
5121 (bwin (get-buffer-window buff 0)))
5124 (select-window bwin)
5125 (raise-frame (window-frame bwin)))
5126 (if speedbar-power-click
5127 (switch-to-buffer-other-frame buff)
5128 (speedbar-select-attached-frame)
5129 (switch-to-buffer buff)))
5130 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" node))
5131 (error "Invalid node %s" node)
5132 (Info-find-node (match-string 1 node) (match-string 2 node))
5133 ;; If we do a find-node, and we were in info mode, restore
5134 ;; the old default method. Once we are in info mode, it makes
5135 ;; sense to return to whatever method the user was using before.
5136 (if (string= speedbar-initial-expansion-list-name "Info")
5137 (speedbar-change-initial-expansion-list
5138 speedbar-previously-used-expansion-list-name)))))
5140 (defun Info-speedbar-expand-node (text token indent)
5141 "Expand the node the user clicked on.
5142 TEXT is the text of the button we clicked on, a + or - item.
5143 TOKEN is data related to this node (NAME . FILE).
5144 INDENT is the current indentation depth."
5145 (cond ((string-match "+" text) ;we have to expand this file
5146 (speedbar-change-expand-button-char ?-)
5147 (if (speedbar-with-writable
5149 (end-of-line) (forward-char 1)
5150 (Info-speedbar-hierarchy-buttons nil (1+ indent) token)))
5151 (speedbar-change-expand-button-char ?-)
5152 (speedbar-change-expand-button-char ??)))
5153 ((string-match "-" text) ;we have to contract this node
5154 (speedbar-change-expand-button-char ?+)
5155 (speedbar-delete-subblock indent))
5156 (t (error "Ooops... not sure what to do")))
5157 (speedbar-center-buffer-smartly))
5159 (defun Info-speedbar-fetch-file-nodes (nodespec)
5160 "Fetch the subnodes from the info NODESPEC.
5161 NODESPEC is a string of the form: (file)node."
5162 ;; Set up a buffer we can use to fake-out Info.
5163 (with-current-buffer (get-buffer-create " *info-browse-tmp*")
5164 (if (not (derived-mode-p 'Info-mode))
5166 ;; Get the node into this buffer
5167 (if (not (string-match "^(\\([^)]+\\))\\([^.]+\\)$" nodespec))
5168 (error "Invalid node specification %s" nodespec)
5169 (Info-find-node (match-string 1 nodespec) (match-string 2 nodespec)))
5170 ;; Scan the created buffer
5171 (goto-char (point-min))
5172 (let ((completions nil)
5173 (case-fold-search t)
5174 (thisfile (progn (string-match "^(\\([^)]+\\))" nodespec)
5175 (match-string 1 nodespec))))
5176 ;; Always skip the first one...
5177 (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5178 (while (re-search-forward "\n\\* \\([^:\t\n]*\\):" nil t)
5179 (let ((name (match-string 1)))
5181 (if (looking-at " *\\(([^)]+)[^.\n]+\\)\\.")
5183 (if (looking-at " *\\(([^)]+)\\)\\.")
5184 (concat (match-string 1) "Top")
5185 (concat "(" thisfile ")"
5186 (if (looking-at " \\([^.]+\\).")
5190 (nreverse completions))))
5192 ;;; Info mode node listing
5193 ;; This is called by `speedbar-add-localized-speedbar-support'
5194 (defun Info-speedbar-buttons (_buffer)
5195 "Create a speedbar display to help navigation in an Info file.
5196 BUFFER is the buffer speedbar is requesting buttons for."
5197 (if (save-excursion (goto-char (point-min))
5198 (let ((case-fold-search t))
5199 (not (looking-at "Info Nodes:"))))
5201 (Info-speedbar-hierarchy-buttons nil 0))
5203 ;; FIXME: Really? Why here?
5204 (add-to-list 'debug-ignored-errors 'search-failed)
5206 ;;;; Desktop support
5208 (defun Info-desktop-buffer-misc-data (_desktop-dirname)
5209 "Auxiliary information to be saved in desktop file."
5210 (list Info-current-file
5212 ;; Additional data as an association list.
5215 (cons 'history Info-history))
5216 (and (Info-virtual-fun
5217 'slow Info-current-file Info-current-node)
5220 (defun Info-restore-desktop-buffer (_desktop-buffer-file-name
5222 desktop-buffer-misc)
5223 "Restore an Info buffer specified in a desktop file."
5224 (let* ((file (nth 0 desktop-buffer-misc))
5225 (node (nth 1 desktop-buffer-misc))
5226 (data (nth 2 desktop-buffer-misc))
5227 (hist (assq 'history data))
5228 (slow (assq 'slow data)))
5229 ;; Don't restore nodes slow to regenerate.
5231 (when (and file node)
5232 (when desktop-buffer-name
5233 (set-buffer (get-buffer-create desktop-buffer-name))
5235 (Info-find-node file node)
5237 (setq Info-history (cdr hist)))
5238 (current-buffer)))))
5240 (add-to-list 'desktop-buffer-mode-handlers
5241 '(Info-mode . Info-restore-desktop-buffer))
5243 ;;;; Bookmark support
5244 (declare-function bookmark-make-record-default
5245 "bookmark" (&optional no-file no-context posn))
5246 (declare-function bookmark-prop-get "bookmark" (bookmark prop))
5247 (declare-function bookmark-default-handler "bookmark" (bmk))
5248 (declare-function bookmark-get-bookmark-record "bookmark" (bmk))
5250 (defun Info-bookmark-make-record ()
5251 "This implements the `bookmark-make-record-function' type (which see)
5253 (let* ((file (and (stringp Info-current-file)
5254 (file-name-sans-extension
5255 (file-name-nondirectory Info-current-file))))
5256 (bookmark-name (if file
5257 (concat "(" file ") " Info-current-node)
5259 (defaults (delq nil (list bookmark-name file Info-current-node))))
5261 ,@(bookmark-make-record-default 'no-file)
5262 (filename . ,Info-current-file)
5263 (info-node . ,Info-current-node)
5264 (handler . Info-bookmark-jump)
5265 (defaults . ,defaults))))
5268 (defun Info-bookmark-jump (bmk)
5269 "This implements the `handler' function interface for the record
5270 type returned by `Info-bookmark-make-record', which see."
5271 (let* ((file (bookmark-prop-get bmk 'filename))
5272 (info-node (bookmark-prop-get bmk 'info-node))
5273 (buf (save-window-excursion ;FIXME: doesn't work with frames!
5274 (Info-find-node file info-node) (current-buffer))))
5275 ;; Use bookmark-default-handler to move to the appropriate location
5277 (bookmark-default-handler
5278 `("" (buffer . ,buf) . ,(bookmark-get-bookmark-record bmk)))))
5282 (defun info-display-manual (manual)
5283 "Display an Info buffer displaying MANUAL.
5284 If there is an existing Info buffer for MANUAL, display it.
5285 Otherwise, visit the manual in a new Info buffer. In interactive
5286 use, a prefix argument directs this command to limit the
5287 completion alternatives to currently visited manuals."
5292 (completing-read "Manual name: "
5293 (info--manual-names current-prefix-arg)
5295 (let ((blist (buffer-list))
5296 (manual-re (concat "\\(/\\|\\`\\)" manual "\\(\\.\\|\\'\\)"))
5297 (case-fold-search t)
5299 (dolist (buffer blist)
5300 (with-current-buffer buffer
5301 (when (and (eq major-mode 'Info-mode)
5302 (stringp Info-current-file)
5303 (string-match manual-re Info-current-file))
5307 (switch-to-buffer found)
5309 (info (Info-find-file manual)
5310 (generate-new-buffer-name "*info*")))))
5312 (defun info--manual-names (visited-only)
5314 (dolist (buffer (buffer-list))
5315 (with-current-buffer buffer
5316 (and (eq major-mode 'Info-mode)
5317 (stringp Info-current-file)
5318 (not (string= (substring (buffer-name) 0 1) " "))
5319 (push (file-name-sans-extension
5320 (file-name-nondirectory Info-current-file))
5322 (delete-dups (append (nreverse names)
5323 (when (not visited-only)
5326 (apply-partially #'Info-read-node-name-2
5328 (mapcar #'car Info-suffix-list))))))))
5332 ;;; info.el ends here